Skip to content

implement memory.fill and memory.copy#4

Open
zeldovich wants to merge 1 commit intosecure-foundations:mainfrom
zeldovich:memops
Open

implement memory.fill and memory.copy#4
zeldovich wants to merge 1 commit intosecure-foundations:mainfrom
zeldovich:memops

Conversation

@zeldovich
Copy link

This adds support for memory.copy and memory.fill opcodes that are used by recent WASM toolchains, including clang.

@jaybosamiya
Copy link
Member

Thanks Nickolai! Similar to #5 (comment) it'd be helpful to know the version so I can do a quick test before merging.

I think the code in this PR generally seems reasonable but OOB traps are a concern that I have for both of the operations (ref. https://webassembly.github.io/spec/core/exec/instructions.html#xref-syntax-instructions-syntax-instr-memory-mathsf-memory-copy-x-1-x-2) that might need to be fixed before merging.

@zeldovich
Copy link
Author

Here's a small test case that demonstrates what this PR enables, on Arch Linux:

% cat example.c
void _start(void) {
  char buf[256];
  __builtin_memset(buf, 0, sizeof(buf));
}
% clang --version
clang version 21.1.8
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
% clang --target=wasm32 -nostdlib -o example.wasm example.c && wasm-strip example.wasm
%

this uses wasm-strip to get around the names section issue fixed by PR #5.

On the current latest rWasm, I get:

% cargo run example.wasm
...
Finished reading
Error:
   0: Invalid saturation trunctation 0xb

Location:
   src/parser.rs:563

Backtrace omitted. Run with RUST_BACKTRACE=1 environment variable to display it.
Run with RUST_BACKTRACE=full to include source snippets.
% 

with this PR's change, I get:

% cargo run example.wasm
...
Finished reading
Finished parsing
Finished generating
Finished reformatting
Finished
% 

@zeldovich
Copy link
Author

Regarding OOB traps, I was expecting this would be handled by Vec's index_mut and copy_within trapping, but maybe there's something more subtle going on with how rWasm expect to trap OOB operations.

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