Skip to content
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

Support zero-length slices in native #364

Merged
merged 1 commit into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/scheduler/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

### Patch

- Support zero-length slices in native
- Fix board API feature gates for AES-128-CCM and AES-256-GCM
- Remove unreachable `multivalue` feature gates
- Correctly gate events of nested APIs
Expand Down
12 changes: 10 additions & 2 deletions crates/scheduler/src/applet/store/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,19 @@ impl StoreApi for Store {
// when running the applet in Wasm. Native applets are meant for performance.
impl MemoryApi for Memory {
fn get(&self, ptr: u32, len: u32) -> Result<&[u8], Trap> {
Ok(unsafe { core::slice::from_raw_parts(ptr as *const u8, len as usize) })
match (ptr, len) {
(_, 0) => Ok(&[]),
(0, _) => Err(Trap),
_ => Ok(unsafe { core::slice::from_raw_parts(ptr as *const u8, len as usize) }),
}
}

fn get_mut(&self, ptr: u32, len: u32) -> Result<&mut [u8], Trap> {
Ok(unsafe { core::slice::from_raw_parts_mut(ptr as *mut u8, len as usize) })
match (ptr, len) {
(_, 0) => Ok(&mut []),
(0, _) => Err(Trap),
_ => Ok(unsafe { core::slice::from_raw_parts_mut(ptr as *mut u8, len as usize) }),
}
}

fn alloc(&mut self, size: u32, align: u32) -> Result<u32, Trap> {
Expand Down