-
Notifications
You must be signed in to change notification settings - Fork 15
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
fix: partial workaround for high address support #62
Conversation
Some SDKs, like the js-sdk, store block index information in the top 16 bits of the 64-bit memory address. This is incompatible with the JS-PDK at present, since we truncate addresses to 32 bits. In advance of BigInt support in Javy/quickjs-wasm-sys, expose memory offset and lengths as JS Float values. This leans on the JS convention of storing (up to 53 bits of) integer data losslessly in an f64. This gives us 5 bits of block index for the JS-SDK, enough room for *slaps roof of memory allocator* 31 allocations in this bad boy (before requiring an extism memory reset.) QuickJS itself supports bigint, so it's a matter of looping that functionality out through quickjs-sys. (I haven't been able to find a technical reason this wasn't done initially, though that doesn't mean there aren't reasons!)
🤣 |
@@ -442,47 +442,63 @@ fn build_memory(context: &JSContextRef) -> anyhow::Result<JSValueRef> { | |||
let data = data.as_bytes()?; | |||
let m = extism_pdk::Memory::from_bytes(data)?; | |||
let mut mem = HashMap::new(); | |||
let offset = JSValue::Int(m.offset() as i32); | |||
let len = JSValue::Int(m.len() as i32); | |||
let offset = JSValue::Float(m.offset() as f64); |
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.
Looks good and makes sense to me, but only really in the context of this PR. I think a single comment here about why we're packing the offset into a float may be helpful.
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.
Excellent point – added a note!
6497fc3
to
03fb8cd
Compare
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.
Looks good!
Thanks for the reviews, all! |
Some SDKs, like the js-sdk, store block index information in the top 16 bits of the 64-bit memory address. This is incompatible with the JS-PDK at present, since we truncate addresses to 32 bits. In advance of BigInt support in Javy/quickjs-wasm-sys, expose memory offset and lengths as JS Float values. This leans on the JS convention of storing (up to 53 bits of) integer data losslessly in an f64.
This gives us 5 bits of block index for the JS-SDK, enough room for slaps roof of memory allocator 32 allocations in this bad boy (before requiring an extism memory reset.)
QuickJS itself supports bigint, so it's a matter of looping that functionality out through quickjs-sys. (I haven't been able to find a technical reason this wasn't done initially, though that doesn't mean there aren't reasons!)