mirror of
https://github.com/python/cpython.git
synced 2025-07-09 20:35:26 +00:00
gh-128627: Emscripten: Fix address calculation for wasm-gc trampoline (#128782)
Modifies the memory calculation to divide the entire memory address by 4, not just the base address.
This commit is contained in:
parent
298dda5770
commit
960936fe90
3 changed files with 9 additions and 11 deletions
|
@ -26,11 +26,9 @@ EM_JS(CountArgsFunc, _PyEM_GetCountArgsPtr, (), {
|
|||
// Binary module for the checks. It has to be done in web assembly because
|
||||
// clang/llvm have no support yet for the reference types yet. In fact, the wasm
|
||||
// binary toolkit doesn't yet support the ref.test instruction either. To
|
||||
// convert the following module to the binary, my approach is to find and
|
||||
// replace "ref.test $type" -> "drop i32.const n" on the source text. This
|
||||
// results in the bytes "0x1a, 0x41, n" where we need the bytes "0xfb, 0x14, n"
|
||||
// so doing a find and replace on the output from "0x1a, 0x41" -> "0xfb, 0x14"
|
||||
// gets us the output we need.
|
||||
// convert the following textual wasm to a binary, you can build wabt from this
|
||||
// branch: https://github.com/WebAssembly/wabt/pull/2529 and then use that
|
||||
// wat2wasm binary.
|
||||
//
|
||||
// (module
|
||||
// (type $type0 (func (param) (result i32)))
|
||||
|
@ -154,15 +152,15 @@ addOnPreRun(() => {
|
|||
let ptr = 0;
|
||||
try {
|
||||
const mod = new WebAssembly.Module(code);
|
||||
const inst = new WebAssembly.Instance(mod, {e: {t: wasmTable}});
|
||||
const inst = new WebAssembly.Instance(mod, { e: { t: wasmTable } });
|
||||
ptr = addFunction(inst.exports.f);
|
||||
} catch(e) {
|
||||
} catch (e) {
|
||||
// If something goes wrong, we'll null out _PyEM_CountFuncParams and fall
|
||||
// back to the JS trampoline.
|
||||
}
|
||||
Module._PyEM_CountArgsPtr = ptr;
|
||||
const offset = HEAP32[__PyEM_EMSCRIPTEN_COUNT_ARGS_OFFSET/4];
|
||||
HEAP32[__PyRuntime/4 + offset] = ptr;
|
||||
const offset = HEAP32[__PyEM_EMSCRIPTEN_COUNT_ARGS_OFFSET / 4];
|
||||
HEAP32[(__PyRuntime + offset) / 4] = ptr;
|
||||
});
|
||||
);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue