Conversation
gkgoat1
left a comment
There was a problem hiding this comment.
I think a refactor is needed in this area, as the current implementation is incompatible with the WASIp1 ABI. See my comments for specific issues.
|
|
||
| // return opened fd | ||
| const return_ptr = @as(*i32, @ptrFromInt(@as(usize, @intCast(opened_fd_addr)) + linear_memory_offset)); | ||
| const return_ptr = @as(*usize, @ptrFromInt(@as(usize, @intCast(opened_fd_addr)) + linear_memory_offset)); |
There was a problem hiding this comment.
The WASIp1 ABI requires that fds be u32 in WASM; this may cause WASM-side memory corruption
| const port = 1234; | ||
| var ip_iovec_ptr = @as(*IoVec, @ptrFromInt(12 + linear_memory_offset)); | ||
| ip_iovec_ptr.buf = 8; | ||
| var ip_iovec_ptr = @as(*IoVec, @ptrFromInt(20 + linear_memory_offset)); |
There was a problem hiding this comment.
The WASIp1 ABI requires that fds be u32 in WASM; this is ABI-incompatible
| // fd_write | ||
| var buf_iovec = @as([*]IoVec, @ptrFromInt(12 + linear_memory_offset))[0..2]; | ||
| var buf = @as([*]u8, @ptrFromInt(28 + linear_memory_offset)); | ||
| var buf_iovec = @as([*]IoVec, @ptrFromInt(324 + linear_memory_offset))[0..2]; |
| } | ||
|
|
||
| pub export fn fd_write(fd: i32, buf_iovec_addr: i32, vec_len: i32, size_addr: i32) callconv(.C) WasiError { | ||
| pub export fn fd_write(fd: usize, buf_iovec_addr: i32, vec_len: i32, size_addr: i32) callconv(.C) WasiError { |
There was a problem hiding this comment.
The WASIp1 ABI requires that fds be u32 in WASM; the high bits of fd may be undefined depending on Wasker's behavior
|
Hi @gkgoat1
Is there any documentation that states that the type of file descriptors is u32? In wasi-libc, we see fd is defined as int32 like |
Yes; the two code snippets below (that you mentioned) are more than enough
|
|
Mewz's code and the two examples I provided define fd as an i32. However, didn't you say in your comment that fd should be a u32? |
In WASM, |
|
I understand |
The WASM spec uses the same type, i32, for signed and unsigned integers |
#3
There are a lot of modifications, so please help me out.