Skip to content

Update zephyr file socket branch#4406

Merged
lum1n0us merged 9 commits intobytecodealliance:dev/zephyr_file_socketfrom
lum1n0us:update_zephyr_file_socket
Jun 26, 2025
Merged

Update zephyr file socket branch#4406
lum1n0us merged 9 commits intobytecodealliance:dev/zephyr_file_socketfrom
lum1n0us:update_zephyr_file_socket

Conversation

@lum1n0us
Copy link
Copy Markdown
Contributor

@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
Copy Markdown
Contributor 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.

Comment thread core/iwasm/common/wasm_application.c Outdated
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
Copy Markdown
Contributor 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
Copy Markdown
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
Copy Markdown
Contributor 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.

// 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
Copy Markdown
Contributor 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
Copy Markdown
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
Copy Markdown
Contributor 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
Copy Markdown
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.

Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Contributor

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.

GET_FILE_SYSTEM_DESCRIPTOR(old_handle->fd, ptr);

char *path = strdup(new_path);
char *path = duplicate_string(new_path);
Copy link
Copy Markdown
Contributor 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

// va_end(args);

return ret;
// return ret;
Copy link
Copy Markdown
Contributor 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
lum1n0us added a commit to lum1n0us/wasm-micro-runtime that referenced this pull request Aug 1, 2025
* Added os_is_* methods for stdin/stdout/stderr.
Fixed issues in os_renameat
* Zephyr platform fixes for WASI sockets
Addressed numerous of build warnings on Zephyr
* Updated `os_writev` to use `fwrite` for STDOUT/STDERR
* Temporarily reverted change to `writev` to work around an issue.
* Fixes: fstat, fstatat, and unlink
* Add initial support for directories in os_openat. 
Partial implementation — just avoids a hard fault.

Signed-off-by: Stephen Berard <stephen.berard@outlook.com>
Co-authored-by: Dan Kouba <dan@atym.io>
lum1n0us added a commit that referenced this pull request Aug 12, 2025
* Added os_is_* methods for stdin/stdout/stderr.
Fixed issues in os_renameat
* Zephyr platform fixes for WASI sockets
Addressed numerous of build warnings on Zephyr
* Updated `os_writev` to use `fwrite` for STDOUT/STDERR
* Temporarily reverted change to `writev` to work around an issue.
* Fixes: fstat, fstatat, and unlink
* Add initial support for directories in os_openat. 
Partial implementation — just avoids a hard fault.

Signed-off-by: Stephen Berard <stephen.berard@outlook.com>
Co-authored-by: Dan Kouba <dan@atym.io>
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