-
Notifications
You must be signed in to change notification settings - Fork 735
Copy only received bytes from socket recv buffer into the app buffer #1497
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
Copy only received bytes from socket recv buffer into the app buffer #1497
Conversation
9346122 to
a8b45fb
Compare
|
LGTM |
|
LGTM |
loganek
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, just left one minor comment. Thanks.
| return __WASI_EINVAL; | ||
| } | ||
|
|
||
| if (size_to_copy == 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wonder if we need this check given that we already have this check in L1893
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah you're right. It saves one validate_app_addr call but then maybe it's preferred that if we pass in an invalid app addr, we always return __WASI_EINVAL even if the size_to_copy is 0
|
@wenyongh The failing macos-latest check is unrelated to the change. Is it OK to merge / or can the check be retried? I don't have permissions to trigger the workflow manually |
Implement more socket APIs, refer to #1336 and below PRs: - Implement wasi_addr_resolve function (#1319) - Fix socket-api byte order issue when host/network order are the same (#1327) - Enhance sock_addr_local syscall (#1320) - Implement sock_addr_remote syscall (#1360) - Add support for IPv6 in WAMR (#1411) - Implement ns lookup allowlist (#1420) - Implement sock_send_to and sock_recv_from system calls (#1457) - Added http downloader and multicast socket options (#1467) - Fix `bind()` calls to receive the correct size of `sockaddr` structure (#1490) - Assert on correct parameters (#1505) - Copy only received bytes from socket recv buffer into the app buffer (#1497) Co-authored-by: Marcin Kolny <[email protected]> Co-authored-by: Marcin Kolny <[email protected]> Co-authored-by: Callum Macmillan <[email protected]>
…ytecodealliance#1497) **What** * Updated `copy_buffer_to_iovec_app` so that it copies as much of the buffer into the iovec as specified * Throw invalid value when allocating an iovec of size 0 **Why** * A bug found from TCP client example which allocates 1024 for the iovec size (where the buf size is also 1024) but received bytes is passed in as the `buf_size` argument to `copy_buffer_to_iovec_app`. This would return early after hitting this check `buf + data->buf_len > buf_begin + buf_size`. However, if the amount to copy is less than the iovec size, we should copy that much of the buf size. Eg TCP client sample receives 27(?) bytes at a time, and this copies 27 bytes into the iovec of size 1024 * The TCP client example attempts to recv bytes of size 0, this attempts to wasm malloc size 0, which outputs a warning. We should early return if recv bytes of size 0
Implement more socket APIs, refer to bytecodealliance#1336 and below PRs: - Implement wasi_addr_resolve function (bytecodealliance#1319) - Fix socket-api byte order issue when host/network order are the same (bytecodealliance#1327) - Enhance sock_addr_local syscall (bytecodealliance#1320) - Implement sock_addr_remote syscall (bytecodealliance#1360) - Add support for IPv6 in WAMR (bytecodealliance#1411) - Implement ns lookup allowlist (bytecodealliance#1420) - Implement sock_send_to and sock_recv_from system calls (bytecodealliance#1457) - Added http downloader and multicast socket options (bytecodealliance#1467) - Fix `bind()` calls to receive the correct size of `sockaddr` structure (bytecodealliance#1490) - Assert on correct parameters (bytecodealliance#1505) - Copy only received bytes from socket recv buffer into the app buffer (bytecodealliance#1497) Co-authored-by: Marcin Kolny <[email protected]> Co-authored-by: Marcin Kolny <[email protected]> Co-authored-by: Callum Macmillan <[email protected]>
What
copy_buffer_to_iovec_appso that it copies as much of the buffer into the iovec as specifiedWhy
buf_sizeargument tocopy_buffer_to_iovec_app. This would return early after hitting this checkbuf + data->buf_len > buf_begin + buf_size. However, if the amount to copy is less than the iovec size, we should copy that much of the buf size. Eg TCP client sample receives 27(?) bytes at a time, and this copies 27 bytes into the iovec of size 1024