Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement fd_fdstat_get #309

Merged
merged 1 commit into from
Dec 9, 2024
Merged

Implement fd_fdstat_get #309

merged 1 commit into from
Dec 9, 2024

Conversation

zherczeg
Copy link
Collaborator

@zherczeg zherczeg commented Dec 2, 2024

Improve other WASI functions as well.

class TemporaryData {
public:
TemporaryData(size_t size)
{
/* Check that more memory is requested than the maximum provided by malloc. */
if (size > ((~static_cast<size_t>(0)) / sizeof(T))) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this case possible?
It seems that this case would rarely happen, and not a intended operation.
So what about checking it simply with ASSERT?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The size comes from WebAssembly, it can intentionally be a bad value (security). On 32 bit, the value can overflow and cause a crash.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, then what about using std::numeric_limits<size_t> here?
It could be more intuitive I think

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! I have updated the patch

@clover2123
Copy link
Collaborator

Regarding TemporaryData structure, there is a vector structure VectorWithInlineStorage that handles exactly the same operation.
How about using this vector?

walrus/src/util/Vector.h

Lines 551 to 555 in 20d770b

class VectorWithInlineStorage {
public:
VectorWithInlineStorage()
: m_useExternalStorage(false)
, m_size(0)

@zherczeg zherczeg changed the title Implement fd_fdstat_get. Implement fd_fdstat_get Dec 4, 2024
@zherczeg
Copy link
Collaborator Author

zherczeg commented Dec 4, 2024

I have tried to use VectorWithInlineStorage, but it throws exceptions on allocation failures. Shall I add try-catch blocks to handle this?

@clover2123
Copy link
Collaborator

I have tried to use VectorWithInlineStorage, but it throws exceptions on allocation failures. Shall I add try-catch blocks to handle this?

That would be more complicated, IMHO it's better to use specific TemporaryData structure here

Improve other WASI functions as well.

Signed-off-by: Zoltan Herczeg [email protected]
@clover2123 clover2123 merged commit ed31dc5 into Samsung:main Dec 9, 2024
15 checks passed
@zherczeg zherczeg deleted the fd_fdstat_get branch December 9, 2024 08:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants