-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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): support raw pointer arguments #16826
Conversation
This will be problematic if/when I get my Fast API void pointer CL merged to V8, as we'll probably want to use pointers to represent that... Except! Yes, this is good. Represent Uint8Array's pointer using |
@@ -2065,7 +2065,7 @@ fn op_ffi_call_nonblocking<'scope>( | |||
#[op(fast)] | |||
fn op_ffi_ptr_of<FP>( | |||
state: &mut deno_core::OpState, | |||
buf: &[u8], | |||
buf: *const u8, |
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.
Consider using *mut u8
, not because we're going to do mutation but because we want this to be from an ArrayBuffer which are always mut.
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.
*const u8
does not suggest that the pointed value is not mutable. You can safely cast it to *mut u8
. It's just a hint that we are only dealing with the non-mut reference in the current context.
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.
Yes, I'm just thinking that there might be a day when *const u8
is needed to stand in for some V8 API type with Fast API support that offers a pointer without mutable access. Admittedly this is quite an unlikely thing scenario, but still a theoretical possibility.
I guess another way to go about this would use some transparent newtype like to tell the various pointer types apart in the ops macro:
#[repr(transparent)]
struct Uint8ArrayPointer(*const u8)
But yeah, since this is an unlikely scenario it doesn't really matter.
@aapoalas IMO i'd be nice to have a magic type |
Yeah. One thing that we will need to be careful about is the "substitution safety" required by V8's external pointer table, see this code comment and Samuel Groß's comment on it: https://chromium-review.googlesource.com/c/v8/v8/+/3957815/18/include/v8-internal.h#387 It's a bit of a complicated situation that probably cannot be resolved easily but should be taken up as a future goal. The reason for aiming for this is that pointer swapping enables memory corruption attacks, which may at worst lead to exploits and sandbox escapes, as opposed to just segfaulting. |
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.
LGTM
See #16814 (comment). Allows nullable buffers in low-level ops like FFI: ```rust fn op_ffi_ptr_of<FP>( state: &mut OpState, buf: *const u8, out: &mut [u32], ) where FP: FfiPermissions + 'static { // .. } ```
See #16814 (comment). Allows nullable buffers in low-level ops like FFI: