mirror of
https://github.com/VSadov/Satori.git
synced 2025-06-10 01:50:53 +09:00
[wasm] Automate patching the emsdk installation to add controlled indeterminism. (#75532)
This commit is contained in:
parent
67d2570ccf
commit
2bc4f61536
3 changed files with 47 additions and 7 deletions
|
@ -83,14 +83,10 @@ and change the
|
||||||
This will hopefully cause the failure to happen reliably.
|
This will hopefully cause the failure to happen reliably.
|
||||||
|
|
||||||
There is another random number generator in `upstream/emscripten/src/deterministic.js`
|
There is another random number generator in `upstream/emscripten/src/deterministic.js`
|
||||||
which needs the same treatment:
|
which needs the same treatment.
|
||||||
```
|
|
||||||
var randomBuffer3 = new Uint8Array(2);
|
|
||||||
crypto.getRandomValues(randomBuffer3);
|
|
||||||
|
|
||||||
var MAGIC = (randomBuffer3 [0] << 8) | randomBuffer3 [1];
|
Running `make patch-deterministic` in `src/mono/wasm` will patch the
|
||||||
console.log ("SEED2: " + MAGIC);
|
emscripten installation in `src/mono/wasm/emsdk` with these changes.
|
||||||
```
|
|
||||||
|
|
||||||
# Debugging signature mismatch errors
|
# Debugging signature mismatch errors
|
||||||
|
|
||||||
|
|
|
@ -140,3 +140,6 @@ build-dbg-proxy:
|
||||||
$(DOTNET) build $(TOP)/src/mono/wasm/debugger/BrowserDebugHost $(MSBUILD_ARGS)
|
$(DOTNET) build $(TOP)/src/mono/wasm/debugger/BrowserDebugHost $(MSBUILD_ARGS)
|
||||||
build-dbg-testsuite:
|
build-dbg-testsuite:
|
||||||
$(DOTNET) build $(TOP)/src/mono/wasm/debugger/DebuggerTestSuite $(MSBUILD_ARGS)
|
$(DOTNET) build $(TOP)/src/mono/wasm/debugger/DebuggerTestSuite $(MSBUILD_ARGS)
|
||||||
|
|
||||||
|
patch-deterministic:
|
||||||
|
cd emsdk/upstream/emscripten/ && patch -p1 < ../../../runtime/deterministic.diff
|
||||||
|
|
41
src/mono/wasm/runtime/deterministic.diff
Normal file
41
src/mono/wasm/runtime/deterministic.diff
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
diff --git a/src/deterministic.js b/src/deterministic.js
|
||||||
|
index 0b894b4ac..05f50abba 100644
|
||||||
|
--- a/src/deterministic.js
|
||||||
|
+++ b/src/deterministic.js
|
||||||
|
@@ -4,7 +4,13 @@
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
-var MAGIC = 0;
|
||||||
|
+var randomBuffer3 = new Uint8Array(2);
|
||||||
|
+crypto.getRandomValues(randomBuffer3);
|
||||||
|
+
|
||||||
|
+var MAGIC = (randomBuffer3 [0] << 8) | randomBuffer3 [1];
|
||||||
|
+console.log ("SEED2: " + MAGIC);
|
||||||
|
+
|
||||||
|
+//var MAGIC = 0;
|
||||||
|
Math.random = () => {
|
||||||
|
MAGIC = Math.pow(MAGIC + 1.8912, 3) % 1;
|
||||||
|
return MAGIC;
|
||||||
|
diff --git a/src/library.js b/src/library.js
|
||||||
|
index 603f94dbf..698e9fe29 100644
|
||||||
|
--- a/src/library.js
|
||||||
|
+++ b/src/library.js
|
||||||
|
@@ -2196,6 +2196,17 @@ mergeInto(LibraryManager.library, {
|
||||||
|
// TODO: consider allowing the API to get a parameter for the number of
|
||||||
|
// bytes.
|
||||||
|
$getRandomDevice: function() {
|
||||||
|
+ var randomBuffer2 = new Uint8Array(2);
|
||||||
|
+ crypto.getRandomValues(randomBuffer2);
|
||||||
|
+
|
||||||
|
+ if (FS.seed2 == null)
|
||||||
|
+ FS.seed2 = (randomBuffer2 [0] << 8) | randomBuffer2 [1];
|
||||||
|
+ console.log('SEED: ' + FS.seed2);
|
||||||
|
+ return function() {
|
||||||
|
+ FS.seed2 = FS.seed2 * 16807 % 2147483647;
|
||||||
|
+ return FS.seed2;
|
||||||
|
+ };
|
||||||
|
+
|
||||||
|
if (typeof crypto == 'object' && typeof crypto['getRandomValues'] == 'function') {
|
||||||
|
// for modern web browsers
|
||||||
|
var randomBuffer = new Uint8Array(1);
|
Loading…
Add table
Add a link
Reference in a new issue