Skip to content

Update zephyr file socket branch #4406

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

Conversation

lum1n0us
Copy link
Collaborator

@lum1n0us lum1n0us commented Jun 24, 2025

This is based on #4377.

@srberard Please help me confirm this update. This PR is supposed to contain all and only your latest modifications. If it is as expected, I will merge this PR while ignoring the CI results. I hope we can use new PRs to fix those CI failures.

srberard and others added 8 commits June 20, 2025 02:25
Fixed issues in os_renameat

Signed-off-by: Stephen Berard <stephen.berard@outlook.com>
Addressed numerous of build warnings on Zephyr

Signed-off-by: Stephen Berard <stephen.berard@outlook.com>
Signed-off-by: Stephen Berard <stephen.berard@outlook.com>
Signed-off-by: Stephen Berard <stephen.berard@outlook.com>
Partial implementation — just avoids a hard fault.
This was referenced Jun 24, 2025
@lum1n0us lum1n0us marked this pull request as draft June 24, 2025 05:26
Copy link
Collaborator Author

@lum1n0us lum1n0us left a comment

Choose a reason for hiding this comment

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

I just listed all my doubts. We can have a discussion, but please fix them in a new PR if you want to. I will merge this PR to the dev branch once its commits are confirmed.

@@ -289,6 +289,7 @@ wasm_application_execute_main(WASMModuleInstanceCommon *module_inst, int32 argc,
exec_env = wasm_runtime_get_exec_env_singleton(module_inst);
if (exec_env) {
wasm_runtime_dump_mem_consumption(exec_env);
(WASMModuleInstance *)module_inst->cur_exception
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

not finished.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @lum1n0us, I don't understand what you mean by the above. I don't believe this file was updated as part of this Zephyr work. Can you explain more what you would like to see changed here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I used to think it was a typo and that we should just remove it.

@@ -2212,7 +2212,7 @@ wasmtime_ssp_poll_oneoff(wasm_exec_env_t exec_env, struct fd_table *curfds,
if (error == 0) {
// Proper file descriptor on which we can poll().
pfds[i] = (os_poll_file_handle){
.fd = fos[i]->file_handle,
.fd = fos[i]->file_handle->fd,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

file_handle's type is os_file_handle which is typedef int os_file_handle. So a compilation error will be raised: error: invalid type argument of ‘->’ (have ‘os_file_handle’ {aka ‘int’}).

Copy link
Contributor

Choose a reason for hiding this comment

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

In #3633, @lucasAbadFr changed for Zephyr to be the following:

typedef struct zephyr_handle *os_file_handle;

I'll see what I can do to unify this better to align with the POSIX/Linux implementation.

if (dup == NULL) {
return NULL; // Allocation failed
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

May need memset to zero out the buffer.

Copy link
Contributor

Choose a reason for hiding this comment

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

It shouldn't be needed here. We allocate the string length plus 1 for the terminator. If the allocation fails, the malloc failed and the buffer was not allocated; NULL is returned to indicate error. If the malloc succeeded, memory is allocated and a memcpy is performed for the full length of the buffer (which is strlen + 1). This will copy the full string plus the NULL terminator. A memset prior would not cause an issue but would work done unnecessarily (perf impact).

In the code above, I'm using malloc when I should probably use os_malloc instead. Existing code uses the BH_MALLOC macro (which calls os_malloc). I've update the code to use this instead.

Choose a reason for hiding this comment

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

I just tested this change to BH_MALLOC and it results in a hard-fault on my device. I have not tracked down the root cause, however it appears to be when the duplicated string is accessed.

Choose a reason for hiding this comment

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

Apologies, the above can be ignored. My issue turned out to be something else memory related in my setup.

@@ -715,13 +802,18 @@ os_renameat(os_file_handle old_handle, const char *old_path,

GET_FILE_SYSTEM_DESCRIPTOR(old_handle->fd, ptr);

char *path = strdup(new_path);
char *path = duplicate_string(new_path);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

need to free path somewhere


return ret;
// return ret;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

need to remove commented code

@lum1n0us lum1n0us marked this pull request as ready for review June 26, 2025 05:47
@lum1n0us lum1n0us merged commit 442ea20 into bytecodealliance:dev/zephyr_file_socket Jun 26, 2025
37 of 357 checks passed
@lum1n0us lum1n0us deleted the update_zephyr_file_socket branch June 26, 2025 05:52
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.

3 participants