extism / js-pdk

Write Extism plugins in JavaScript & TypeScript
52 stars 16 forks source link

fix: partial workaround for high address support #62

Closed chrisdickinson closed 5 months ago

chrisdickinson commented 5 months ago

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!)

nilslice commented 5 months ago

slaps roof of memory allocator

🤣

chrisdickinson commented 5 months ago

Thanks for the reviews, all!