-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(cli-repl): patch WASM wrapper for pac-proxy-agent on s390x MONGOS…
…H-1858 (#2130) Work around justjake/quickjs-emscripten#123.
- Loading branch information
Showing
4 changed files
with
77 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import assert from 'assert'; | ||
|
||
const isBigEndian = | ||
new Int32Array(new Uint8Array([1, 0, 0, 0]).buffer)[0] !== 1; | ||
|
||
// The pac-proxy-agent module uses a WebAssembly agent under the hood for | ||
// safely evaluating JS. The interface for this doesn't properly account for | ||
// little-endian vs. big-endian host platform distinctions. | ||
|
||
// Official support for s390x may not be planned: https://github.com/justjake/quickjs-emscripten/issues/123 | ||
|
||
export let applyPacProxyS390XPatch: () => void; | ||
if (isBigEndian) { | ||
applyPacProxyS390XPatch = () => { | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const { | ||
ModuleMemory, | ||
} = require('@tootallnate/quickjs-emscripten/dist/memory'); | ||
|
||
const { toPointerArray } = ModuleMemory.prototype; | ||
{ | ||
// Consistency check: The version we are currently using is actually broken | ||
const HEAPU8 = new Uint8Array(4); | ||
toPointerArray.call( | ||
new ModuleMemory({ | ||
_malloc: () => 0, | ||
HEAPU8, | ||
}), | ||
[{ value: 0x01020304 }] | ||
); | ||
assert.deepStrictEqual([...HEAPU8], [1, 2, 3, 4]); // should be 4, 3, 2, 1 | ||
} | ||
|
||
ModuleMemory.prototype.toPointerArray = function ( | ||
handleArray: { value: number }[] | ||
) { | ||
return toPointerArray.call( | ||
this, | ||
handleArray.map(({ value }) => ({ | ||
value: | ||
((value & 0x000000ff) << 24) | | ||
((value & 0x0000ff00) << 8) | | ||
((value & 0x00ff0000) >> 8) | | ||
((value & 0xff000000) >> 24), | ||
})) | ||
); | ||
}; | ||
}; | ||
} else { | ||
applyPacProxyS390XPatch = () => { | ||
// no-op | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters