tor-browser

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

memory-copy-shared.js (1975B)


      1 // |jit-test| heavy; allow-oom; slow; skip-if: !canRunHugeMemoryTests()
      2 
      3 // This is just like memory-copy.js, but it is marked slow because the
      4 // C++-UB-safe operations we use for out-of-line copies on shared memory are slow
      5 // and the >4GB copy takes a long time.
      6 
      7 var HEAPMIN=65538;
      8 var HEAPMAX=65540;
      9 var PAGESIZE=65536;
     10 
     11 try {
     12    var ins = new WebAssembly.Instance(new WebAssembly.Module(wasmTextToBinary(`
     13 (module
     14  (memory (export "mem") i64 ${HEAPMIN} ${HEAPMAX} shared)
     15  (func (export "f") (param $dst i64) (param $src i64) (param $n i64)
     16    (memory.copy (local.get $dst) (local.get $src) (local.get $n))))`)));
     17 } catch (e) {
     18    if (e instanceof WebAssembly.RuntimeError && String(e).match(/too many memory pages/)) {
     19        quit(0);
     20    }
     21    throw e;
     22 }
     23 
     24 var mem = new Uint8Array(ins.exports.mem.buffer);
     25 var lowbase = 0xffff_1000;
     26 var highbase = 0x1_0000_8000;
     27 for ( let n=0; n < 256; n++ ) {
     28    mem[n + lowbase] = n + 1;
     29    mem[n + highbase] = n + 1;
     30 }
     31 
     32 // Copy from above 4GB to below
     33 doit(0, highbase, 60);
     34 
     35 // Copy from above 4GB with OOB to below
     36 assertErrorMessage(() => ins.exports.f(0n, BigInt(HEAPMIN*PAGESIZE-32768), 65536n),
     37                   WebAssembly.RuntimeError,
     38                   /out of bounds/);
     39 
     40 // Copy from below 4GB to above
     41 doit(0x1_0000_0100, lowbase, 60);
     42 
     43 // Copy from below 4GB to above with OOB
     44 assertErrorMessage(() => ins.exports.f(BigInt(HEAPMIN*PAGESIZE-32768), BigInt(lowbase), 65536n),
     45                   WebAssembly.RuntimeError,
     46                   /out of bounds/);
     47 
     48 // Copy across the 4GB boundary
     49 doit(0xffff_ff80, lowbase, 256);
     50 
     51 // Copy more than 4GB.  Note overlap prevents full correctness checking.
     52 ins.exports.f(BigInt(PAGESIZE), 0n, BigInt(PAGESIZE*(HEAPMIN-1)));
     53 for ( let i=0 ; i < PAGESIZE; i++ )
     54    assertEq(mem[i + PAGESIZE], mem[i]);
     55 
     56 function doit(dst, src, n) {
     57    ins.exports.f(BigInt(dst), BigInt(src), BigInt(n));
     58    for ( let i=0 ; i < n; i++ )
     59        assertEq(mem[dst + i], mem[src + i]);
     60 }