-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
Make MagicBuffer and ZeroCopyBuf work with SharedArrayBuffers #12678
Comments
I've been thinking some more about this, and even in the case where the const buffer = new Uint8Array(1024);
Deno.core.opSync("op_zerocopy_alias_test", buffer, buffer); fn op_zerocopy_alias_test(
_state: &mut OpState,
mut buf1: serde_v8::Buffer,
mut buf2: serde_v8::Buffer,
) -> Result<(), AnyError> {
let mut_slice1: &mut [u8] = &mut *buf1;
let mut_slice2: &mut [u8] = &mut *buf2;
println!("Address of mut_slice1: {:?}", mut_slice1.as_ptr());
println!("Address of mut_slice2: {:?}", mut_slice2.as_ptr());
Ok(())
} So Note that here using two It isn't easy to trigger this UB in Deno, since AFAIK no ops take two buffers, but some runs of this (very contrived) code should be able to trigger it: const buffer = new Uint8Array(1024);
// We don't await!
fetch("https://example.com", { method: "POST", body: buffer });
new TextEncoder().encodeInto("some string", buffer); |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions. |
Stalebot, you are supposed to close |
#11040 is currently in the process of implementing the ability to share
SharedArrayBuffer
s across workers, and code implemented in JS and WASM will be able to immediately benefit from it. However, as per #11040 (comment), many of the ops that useMagicBuffer
are written assuming that the buffer can only be modified from the current thread/worker, and need to be reviewed and fixed before those APIs can be used with shared memory. Even worse, as per denoland/rusty_v8#711 it seems that the Rust binding forBackingStore
is unsound when the backing store is shared, soZeroCopyBuf
would be unsound too.Therefore, it seems like we should disable the deserialization of shared typed arrays into
MagicBuffer
s for the time being, and at some later point we can figure how to rewriteMagicBuffer
andZeroCopyBuf
using the newBackingStore
API.The text was updated successfully, but these errors were encountered: