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 clock related functions in wasi #307

Merged
merged 1 commit into from
Nov 26, 2024

Conversation

zherczeg
Copy link
Collaborator

Improve pointer handling of wasi functions.

uint64_t newOffset = argv[3].asI32();

uvwasi_filesize_t out_addr = *(instance->memory(0)->buffer() + newOffset);
uvwasi_filesize_t* file_size = reinterpret_cast<uvwasi_filesize_t*>(get_memory_pointer(instance, argv[3], sizeof(uvwasi_filesize_t)));
Copy link
Collaborator

Choose a reason for hiding this comment

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

What if get_memory_pointer returns a nullptr here?
In WASI functions, when accessing memory, is range always correct?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There is a trick here. All uvwasi functions checks that the input pointers are non NULL:
https://github.com/nodejs/uvwasi/blob/83dd1fc85077346b1f49a8f3f7a6db96cc0d299d/src/uvwasi.c#L1573

So we turn all invalid pointers to null, and that is checked by uvwasi, and it returns with its expected error code. This will even work, if uvwasi changes the return code.


char** uvEnviron = reinterpret_cast<char**>(instance->memory(0)->buffer() + env);
char* uvEnvironBuf = reinterpret_cast<char*>(instance->memory(0)->buffer() + environBuf);
TemporaryData pointers(count * sizeof(void*));
Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems that TemporaryData structure is used only here,
so what about simply allocating a temporal buffer inside this environ_get function?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

#308 should also use this. Sharing code should reduce the possible errors.

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

@zherczeg
Copy link
Collaborator Author

It looks like macos fails with "Error: The brew link step did not complete successfully".

@clover2123
Copy link
Collaborator

It looks like macos fails with "Error: The brew link step did not complete successfully".

This might be triggered by pkg-config installation in macos-latest env.
How about skipping pkg-config install in macos-latest(build-on-macos-arm64) ?

Improve pointer handling of wasi functions.

Signed-off-by: Zoltan Herczeg [email protected]
@zherczeg
Copy link
Collaborator Author

Thank you for the suggestion! The patch is working now

Copy link
Collaborator

@clover2123 clover2123 left a comment

Choose a reason for hiding this comment

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

LGTM

@clover2123 clover2123 merged commit 20d770b into Samsung:main Nov 26, 2024
15 checks passed
@zherczeg zherczeg deleted the clock_time_get branch November 26, 2024 05:27
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