tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

memory-fill.js (1586B)


      1 // |jit-test| heavy; allow-oom; skip-if: !canRunHugeMemoryTests()
      2 
      3 // Also see memory-fill-shared.js
      4 
      5 try {
      6    var ins = new WebAssembly.Instance(new WebAssembly.Module(wasmTextToBinary(`
      7 (module
      8  (memory (export "mem") i64 65537)
      9  (func (export "f") (param $p i64) (param $c i32) (param $n i64)
     10    (memory.fill (local.get $p) (local.get $c) (local.get $n))))`)));
     11 } catch (e) {
     12    if (e instanceof WebAssembly.RuntimeError && String(e).match(/too many memory pages/)) {
     13        quit(0);
     14    }
     15    throw e;
     16 }
     17 
     18 var mem = new Uint8Array(ins.exports.mem.buffer);
     19 
     20 // Fill above 4GB
     21 doit(mem, 0x100000100, 37, 14);
     22 
     23 // Fill OOB above 4GB
     24 assertErrorMessage(() => ins.exports.f(0x10000FFFFn, 66, 14n),
     25                   WebAssembly.RuntimeError,
     26                   /out of bounds/);
     27 assertEq(mem[0x10000FFFF], 0);
     28 assertEq(mem[mem.length-1], 0);
     29 
     30 // Fill across 4GB
     31 doit(mem, 0x100000000 - 16, 42, 32);
     32 
     33 // Fill more than 4GB...
     34 ins.exports.f(0n, 86, 65536n*65537n);
     35 assertEq(mem[mem.length-1], 86);
     36 assertEq(mem[0], 86);
     37 
     38 // Fill OOB more than 4GB
     39 assertErrorMessage(() => ins.exports.f(1n, 75, 65536n*65537n),
     40                   WebAssembly.RuntimeError,
     41                   /out of bounds/);
     42 assertEq(mem[1], 86);
     43 assertEq(mem[mem.length-1], 86);
     44 
     45 function doit(mem, addr, c, n) {
     46    assertEq(mem[addr-1], 0);
     47    assertEq(mem[addr], 0);
     48    assertEq(mem[addr + n - 1], 0);
     49    assertEq(mem[addr + n], 0);
     50    ins.exports.f(BigInt(addr), c, BigInt(n));
     51    assertEq(mem[addr-1], 0);
     52    assertEq(mem[addr], c);
     53    assertEq(mem[addr + n - 1], c);
     54    assertEq(mem[addr + n], 0);
     55 }