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