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

feat(ops): fast calls for Wasm #16776

Merged
merged 9 commits into from
Nov 27, 2022
Merged

feat(ops): fast calls for Wasm #16776

merged 9 commits into from
Nov 27, 2022

Conversation

littledivy
Copy link
Member

@littledivy littledivy commented Nov 23, 2022

This PR introduces Wasm ops. These calls are optimized for entry from Wasm land.

The #[op(wasm)] attribute is opt-in.

Last parameter Option<&mut [u8]> is the memory slice of the Wasm module when entered from a Fast API call. Otherwise, the user is expected to implement logic to obtain the memory if None

#[op(wasm)]
pub fn op_args_get(
  offset: i32,
  buffer_offset: i32,
  memory: Option<&mut [u8]>,
) {
  // ...
}

ops/attrs.rs Outdated Show resolved Hide resolved
let ptr = backing_store.data().unwrap().as_ptr() as *mut u8;
let len = backing_store.byte_length();
// SAFETY: `ptr` is a valid pointer to `len` bytes.
unsafe { std::slice::from_raw_parts_mut(ptr, len) }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible that ptr is a null pointer? eg. Wasm module created with 0 length memory buffer?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@littledivy what's the answer here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quick test shows that it is not nullptr for an empty memory buffer.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it can be...idk...this is just an example

@littledivy littledivy changed the title [wip] feat(ops): Implement fast calls for Wasm feat(ops): Implement fast calls for Wasm Nov 27, 2022
@littledivy littledivy changed the title feat(ops): Implement fast calls for Wasm feat(ops): fast calls for Wasm Nov 27, 2022
@littledivy littledivy marked this pull request as ready for review November 27, 2022 07:27
@littledivy littledivy merged commit ca66978 into denoland:main Nov 27, 2022
kt3k pushed a commit that referenced this pull request Dec 1, 2022
This PR introduces Wasm ops. These calls are optimized for entry from
Wasm land.

The `#[op(wasm)]` attribute is opt-in. 

Last parameter `Option<&mut [u8]>` is the memory slice of the Wasm
module *when entered from a Fast API call*. Otherwise, the user is
expected to implement logic to obtain the memory if `None`

```rust
#[op(wasm)]
pub fn op_args_get(
  offset: i32,
  buffer_offset: i32,
  memory: Option<&mut [u8]>,
) {
  // ...
}
```
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