tor-browser

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

runtime.js (15216B)


      1 // |jit-test| skip-if: !wasmCustomPageSizesEnabled()
      2 
      3 // Test access to an index from a local.
      4 {
      5  let instance = wasmEvalText(`(module
      6      (memory i32 10 10 (pagesize 1))
      7      (func (export "f") (param i32) (result i32)
      8        (i32.store (local.get 0) (i32.const 42))
      9        (i32.load (local.get 0))
     10      )
     11    )
     12  `);
     13 
     14  assertEq(instance.exports.f(5), 42);
     15 }
     16 
     17 // Test constant memory access.
     18 {
     19  let instance = wasmEvalText(`(module
     20      (memory i32 10 10 (pagesize 1))
     21      (func (export "f") (result i32)
     22        (i32.store (i32.const 5) (i32.const 42))
     23        (i32.load (i32.const 5))
     24      )
     25    )
     26  `);
     27 
     28  assertEq(instance.exports.f(), 42);
     29 }
     30 
     31 // Test bounds checks with various offsets.
     32 {
     33  let instance = wasmEvalText(`(module
     34      (memory i32 10 10 (pagesize 1))
     35      (func (export "f") (param i32)
     36        (i32.store8 offset=1 (local.get 0) (i32.const 42))
     37      )
     38    )
     39  `);
     40 
     41  instance.exports.f(1);
     42  instance.exports.f(8);
     43  assertErrorMessage(() => instance.exports.f(9), WebAssembly.RuntimeError, "index out of bounds");
     44  assertErrorMessage(() => instance.exports.f(10), WebAssembly.RuntimeError, "index out of bounds");
     45 }
     46 
     47 {
     48  let instance = wasmEvalText(`(module
     49      (memory i32 20 20 (pagesize 1))
     50      (func (export "f") (param i32)
     51        (i32.store8 offset=17 (local.get 0) (i32.const 42))
     52      )
     53    )
     54  `);
     55 
     56  instance.exports.f(0);
     57  instance.exports.f(2);
     58  assertErrorMessage(() => instance.exports.f(3), WebAssembly.RuntimeError, "index out of bounds");
     59  assertErrorMessage(() => instance.exports.f(10), WebAssembly.RuntimeError, "index out of bounds");
     60  assertErrorMessage(() => instance.exports.f(19), WebAssembly.RuntimeError, "index out of bounds");
     61 }
     62 
     63 {
     64  let instance = wasmEvalText(`(module
     65      (memory i32 20 20 (pagesize 1))
     66      (func (export "f") (param i32)
     67        (i32.store offset=2 (local.get 0) (i32.const 42))
     68      )
     69    )
     70  `);
     71 
     72  instance.exports.f(0);
     73  instance.exports.f(14);
     74  assertErrorMessage(() => instance.exports.f(15), WebAssembly.RuntimeError, "index out of bounds");
     75  assertErrorMessage(() => instance.exports.f(19), WebAssembly.RuntimeError, "index out of bounds");
     76 }
     77 
     78 // Test bounds checks with various access sizes.
     79 {
     80  let instance = wasmEvalText(`(module
     81      (memory i32 10 10 (pagesize 1))
     82      (func (export "f") (param i32)
     83        (i32.store8 (local.get 0) (i32.const 42))
     84      )
     85    )
     86  `);
     87 
     88  instance.exports.f(1);
     89  instance.exports.f(3);
     90  instance.exports.f(9);
     91  assertErrorMessage(() => instance.exports.f(10), WebAssembly.RuntimeError, "index out of bounds");
     92 }
     93 
     94 {
     95  let instance = wasmEvalText(`(module
     96      (memory i32 10 10 (pagesize 1))
     97      (func (export "f") (param i32)
     98        (i32.store16 (local.get 0) (i32.const 42))
     99      )
    100    )
    101  `);
    102 
    103  instance.exports.f(1);
    104  instance.exports.f(3);
    105  assertErrorMessage(() => instance.exports.f(9), WebAssembly.RuntimeError, "index out of bounds");
    106  assertErrorMessage(() => instance.exports.f(10), WebAssembly.RuntimeError, "index out of bounds");
    107 }
    108 
    109 {
    110  let instance = wasmEvalText(`(module
    111      (memory i32 10 10 (pagesize 1))
    112      (func (export "f") (param i32)
    113        (i32.store (local.get 0) (i32.const 42))
    114      )
    115    )
    116  `);
    117 
    118  instance.exports.f(1);
    119  instance.exports.f(6);
    120  assertErrorMessage(() => instance.exports.f(7), WebAssembly.RuntimeError, "index out of bounds");
    121  assertErrorMessage(() => instance.exports.f(8), WebAssembly.RuntimeError, "index out of bounds");
    122  assertErrorMessage(() => instance.exports.f(9), WebAssembly.RuntimeError, "index out of bounds");
    123  assertErrorMessage(() => instance.exports.f(10), WebAssembly.RuntimeError, "index out of bounds");
    124 }
    125 
    126 {
    127  let instance = wasmEvalText(`(module
    128      (memory i32 10 10 (pagesize 1))
    129      (func (export "f") (param i32)
    130        (i64.store (local.get 0) (i64.const 42))
    131      )
    132    )
    133  `);
    134 
    135  instance.exports.f(1);
    136  instance.exports.f(2);
    137  assertErrorMessage(() => instance.exports.f(3), WebAssembly.RuntimeError, "index out of bounds");
    138  assertErrorMessage(() => instance.exports.f(4), WebAssembly.RuntimeError, "index out of bounds");
    139  assertErrorMessage(() => instance.exports.f(5), WebAssembly.RuntimeError, "index out of bounds");
    140  assertErrorMessage(() => instance.exports.f(6), WebAssembly.RuntimeError, "index out of bounds");
    141  assertErrorMessage(() => instance.exports.f(7), WebAssembly.RuntimeError, "index out of bounds");
    142  assertErrorMessage(() => instance.exports.f(8), WebAssembly.RuntimeError, "index out of bounds");
    143  assertErrorMessage(() => instance.exports.f(9), WebAssembly.RuntimeError, "index out of bounds");
    144  assertErrorMessage(() => instance.exports.f(10), WebAssembly.RuntimeError, "index out of bounds");
    145 }
    146 
    147 {
    148  let instance = wasmEvalText(`(module
    149      (memory i32 20 20 (pagesize 1))
    150      (func (export "f") (param i32) (result i32)
    151        (i32x4.extract_lane 0 (v128.load (local.get 0)))
    152      )
    153    )
    154  `);
    155 
    156  instance.exports.f(1);
    157  instance.exports.f(4);
    158  assertErrorMessage(() => instance.exports.f(5), WebAssembly.RuntimeError, "index out of bounds");
    159  assertErrorMessage(() => instance.exports.f(10), WebAssembly.RuntimeError, "index out of bounds");
    160  assertErrorMessage(() => instance.exports.f(15), WebAssembly.RuntimeError, "index out of bounds");
    161  assertErrorMessage(() => instance.exports.f(20), WebAssembly.RuntimeError, "index out of bounds");
    162 }
    163 
    164 {
    165  let instance = wasmEvalText(`(module
    166      (memory i32 0 0 (pagesize 1))
    167      (func (export "f") (param i32)
    168        (i64.store8 (local.get 0) (i64.const 42))
    169      )
    170    )
    171  `);
    172 
    173  assertErrorMessage(() => instance.exports.f(0), WebAssembly.RuntimeError, "index out of bounds");
    174  assertErrorMessage(() => instance.exports.f(1), WebAssembly.RuntimeError, "index out of bounds");
    175 }
    176 
    177 {
    178  let instance = wasmEvalText(`(module
    179      (memory i32 0 0 (pagesize 1))
    180      (func (export "f") (param i32)
    181        (i64.store16 (local.get 0) (i64.const 42))
    182      )
    183    )
    184  `);
    185 
    186  assertErrorMessage(() => instance.exports.f(0), WebAssembly.RuntimeError, "index out of bounds");
    187  assertErrorMessage(() => instance.exports.f(1), WebAssembly.RuntimeError, "index out of bounds");
    188 }
    189 
    190 {
    191  let instance = wasmEvalText(`(module
    192      (memory i32 0 0 (pagesize 1))
    193      (func (export "f") (param i32)
    194        (i32.store (local.get 0) (i32.const 42))
    195      )
    196    )
    197  `);
    198 
    199  assertErrorMessage(() => instance.exports.f(0), WebAssembly.RuntimeError, "index out of bounds");
    200  assertErrorMessage(() => instance.exports.f(1), WebAssembly.RuntimeError, "index out of bounds");
    201 }
    202 
    203 {
    204  let instance = wasmEvalText(`(module
    205      (memory i32 0 0 (pagesize 1))
    206      (func (export "f") (param i32)
    207        (i64.store (local.get 0) (i64.const 42))
    208      )
    209    )
    210  `);
    211 
    212  assertErrorMessage(() => instance.exports.f(0), WebAssembly.RuntimeError, "index out of bounds");
    213  assertErrorMessage(() => instance.exports.f(1), WebAssembly.RuntimeError, "index out of bounds");
    214 }
    215 
    216 {
    217  let instance = wasmEvalText(`(module
    218      (memory i64 0 0 (pagesize 1))
    219      (func (export "f") (param i64) (result i32)
    220        (i32x4.extract_lane 0 (v128.load (local.get 0)))
    221      )
    222    )
    223  `);
    224 
    225  assertErrorMessage(() => instance.exports.f(0n), WebAssembly.RuntimeError, "index out of bounds");
    226  assertErrorMessage(() => instance.exports.f(1n), WebAssembly.RuntimeError, "index out of bounds");
    227  assertErrorMessage(() => instance.exports.f(2n), WebAssembly.RuntimeError, "index out of bounds");
    228 }
    229 
    230 {
    231  let instance = wasmEvalText(`(module
    232      (memory i32 1 1 (pagesize 1))
    233      (func (export "f") (param i32)
    234        (i64.store16 (local.get 0) (i64.const 42))
    235      )
    236    )
    237  `);
    238 
    239  assertErrorMessage(() => instance.exports.f(0), WebAssembly.RuntimeError, "index out of bounds");
    240  assertErrorMessage(() => instance.exports.f(1), WebAssembly.RuntimeError, "index out of bounds");
    241  assertErrorMessage(() => instance.exports.f(2), WebAssembly.RuntimeError, "index out of bounds");
    242 }
    243 
    244 {
    245  let instance = wasmEvalText(`(module
    246      (memory i32 2 2 (pagesize 1))
    247      (func (export "f") (param i32)
    248        (i64.store16 (local.get 0) (i64.const 42))
    249      )
    250    )
    251  `);
    252 
    253  instance.exports.f(0);
    254  assertErrorMessage(() => instance.exports.f(1), WebAssembly.RuntimeError, "index out of bounds");
    255  assertErrorMessage(() => instance.exports.f(2), WebAssembly.RuntimeError, "index out of bounds");
    256 }
    257 
    258 {
    259  let instance = wasmEvalText(`(module
    260      (memory i32 4 4 (pagesize 1))
    261      (func (export "f") (param i32)
    262        (i64.store32 (local.get 0) (i64.const 42))
    263      )
    264    )
    265  `);
    266 
    267  instance.exports.f(0);
    268  assertErrorMessage(() => instance.exports.f(1), WebAssembly.RuntimeError, "index out of bounds");
    269  assertErrorMessage(() => instance.exports.f(2), WebAssembly.RuntimeError, "index out of bounds");
    270 }
    271 
    272 {
    273  let instance = wasmEvalText(`(module
    274      (memory i32 8 8 (pagesize 1))
    275      (func (export "f") (param i32)
    276        (i64.store (local.get 0) (i64.const 42))
    277      )
    278    )
    279  `);
    280 
    281  instance.exports.f(0);
    282  assertErrorMessage(() => instance.exports.f(1), WebAssembly.RuntimeError, "index out of bounds");
    283  assertErrorMessage(() => instance.exports.f(2), WebAssembly.RuntimeError, "index out of bounds");
    284 }
    285 
    286 {
    287  let instance = wasmEvalText(`(module
    288      (memory i64 16 16 (pagesize 1))
    289      (func (export "f") (param i64) (result i32)
    290        (i32x4.extract_lane 0 (v128.load (local.get 0)))
    291      )
    292    )
    293  `);
    294 
    295  instance.exports.f(0n);
    296  assertErrorMessage(() => instance.exports.f(1n), WebAssembly.RuntimeError, "index out of bounds");
    297  assertErrorMessage(() => instance.exports.f(2n), WebAssembly.RuntimeError, "index out of bounds");
    298 }
    299 
    300 // Test ARM-related cases
    301 {
    302  let instance = wasmEvalText(`(module
    303      (memory i32 69648 69648 (pagesize 1))
    304      (func (export "f") (param i32)
    305        (i32.store8 (local.get 0) (i32.const 42))
    306      )
    307    )
    308  `);
    309 
    310  instance.exports.f(0)
    311  instance.exports.f(69647)
    312  assertErrorMessage(() => instance.exports.f(69648), WebAssembly.RuntimeError, "index out of bounds");
    313  assertErrorMessage(() => instance.exports.f(69649), WebAssembly.RuntimeError, "index out of bounds");
    314 }
    315 
    316 {
    317  let instance = wasmEvalText(`(module
    318      (memory i64 69648 69648 (pagesize 1))
    319      (func (export "f") (param i64)
    320        (i32.store8 (local.get 0) (i32.const 42))
    321      )
    322    )
    323  `);
    324 
    325  instance.exports.f(0n)
    326  instance.exports.f(69647n)
    327  assertErrorMessage(() => instance.exports.f(69648n), WebAssembly.RuntimeError, "index out of bounds");
    328  assertErrorMessage(() => instance.exports.f(69649n), WebAssembly.RuntimeError, "index out of bounds");
    329 }
    330 
    331 // Test bounds checking under 4GB.
    332 {
    333  let instance = wasmEvalText(`(module
    334      (memory i64 5000 10000 (pagesize 1))
    335      (func (export "f")
    336        (i32.store (i64.const 11000) (i32.const 42))
    337      )
    338    )
    339  `);
    340 
    341  assertErrorMessage(() => instance.exports.f(), WebAssembly.RuntimeError, "index out of bounds");
    342 }
    343 
    344 {
    345  let instance = wasmEvalText(`(module
    346      (memory i64 5000 (pagesize 1))
    347      (func (export "f")
    348        (i32.store (i64.const 11000) (i32.const 42))
    349      )
    350    )
    351  `);
    352 
    353  assertErrorMessage(() => instance.exports.f(), WebAssembly.RuntimeError, "index out of bounds");
    354 }
    355 
    356 {
    357  let instance = wasmEvalText(`(module
    358      (memory i64 5000 128000 (pagesize 1))
    359      (func (export "f")
    360        (i32.store (i64.const 64000) (i32.const 42))
    361      )
    362    )
    363  `);
    364 
    365  assertErrorMessage(() => instance.exports.f(), WebAssembly.RuntimeError, "index out of bounds");
    366 }
    367 
    368 {
    369  let instance = wasmEvalText(`(module
    370      (memory i64 5000 10000 (pagesize 1))
    371      (func (export "f")
    372        (i32.store (i64.const 6000) (i32.const 42))
    373      )
    374    )
    375  `);
    376 
    377  assertErrorMessage(() => instance.exports.f(), WebAssembly.RuntimeError, "index out of bounds");
    378 }
    379 
    380 {
    381  let instance = wasmEvalText(`(module
    382      (memory i32 5000 10000 (pagesize 1))
    383      (func (export "f")
    384        (i32.store (i32.const 11000) (i32.const 42))
    385      )
    386    )
    387  `);
    388 
    389  assertErrorMessage(() => instance.exports.f(), WebAssembly.RuntimeError, "index out of bounds");
    390 }
    391 
    392 {
    393  let instance = wasmEvalText(`(module
    394      (memory i32 5000 128000 (pagesize 1))
    395      (func (export "f")
    396        (i32.store (i32.const 64000) (i32.const 42))
    397      )
    398    )
    399  `);
    400 
    401  assertErrorMessage(() => instance.exports.f(), WebAssembly.RuntimeError, "index out of bounds");
    402 }
    403 
    404 {
    405  let instance = wasmEvalText(`(module
    406      (memory i32 5000 10000 (pagesize 1))
    407      (func (export "f")
    408        (i32.store (i32.const 6000) (i32.const 42))
    409      )
    410    )
    411  `);
    412 
    413  assertErrorMessage(() => instance.exports.f(), WebAssembly.RuntimeError, "index out of bounds");
    414 }
    415 
    416 if (getBuildConfiguration("x86")) {
    417  assertErrorMessage(
    418    () => wasmEvalText(`(module
    419        (memory i32 4294967295 4294967295 (pagesize 1))
    420        (func (export "f") (param i32)
    421          (i32.store8 (local.get 0) (i32.const 42))
    422        )
    423      )
    424    `),
    425    WebAssembly.RuntimeError,
    426    "too many memory pages"
    427  );
    428 } else {
    429  {
    430    let instance = wasmEvalText(`(module
    431        (memory i32 4294967295 4294967295 (pagesize 1))
    432        (func (export "f") (param i32)
    433          (i32.store8 (local.get 0) (i32.const 42))
    434        )
    435      )
    436    `);
    437 
    438    instance.exports.f(1);
    439    instance.exports.f(3000);
    440    instance.exports.f(4294967292);
    441    instance.exports.f(4294967293);
    442    instance.exports.f(4294967294);
    443    assertErrorMessage(() => instance.exports.f(4294967295), WebAssembly.RuntimeError, "index out of bounds");
    444  }
    445 
    446  {
    447    let instance = wasmEvalText(`(module
    448        (memory i32 4294967295 4294967295 (pagesize 1))
    449        (func (export "f") (param i32)
    450          (i32.store16 (local.get 0) (i32.const 42))
    451        )
    452      )
    453    `);
    454 
    455    instance.exports.f(1);
    456    instance.exports.f(3000);
    457    instance.exports.f(4294967292);
    458    instance.exports.f(4294967293);
    459    assertErrorMessage(() => instance.exports.f(4294967294), WebAssembly.RuntimeError, "index out of bounds");
    460    assertErrorMessage(() => instance.exports.f(4294967295), WebAssembly.RuntimeError, "index out of bounds");
    461  }
    462 
    463  {
    464    let instance = wasmEvalText(`(module
    465        (memory i32 4294967295 (pagesize 1))
    466        (func (export "f") (param i32)
    467          (i32.store16 (local.get 0) (i32.const 42))
    468        )
    469      )
    470    `);
    471 
    472    instance.exports.f(1);
    473    instance.exports.f(3000);
    474    instance.exports.f(4294967292);
    475    instance.exports.f(4294967293);
    476    assertErrorMessage(() => instance.exports.f(4294967294), WebAssembly.RuntimeError, "index out of bounds");
    477    assertErrorMessage(() => instance.exports.f(4294967295), WebAssembly.RuntimeError, "index out of bounds");
    478  }
    479 }
    480 
    481 // Ensure bounds checking above 4GB works as expected.
    482 if (getBuildConfiguration("x86")) {
    483  assertErrorMessage(
    484    () => wasmEvalText(`(module
    485        (memory i64 4294967299 4294967299 (pagesize 1))
    486        (func (export "f")
    487          (i32.store (i64.const 4294967300) (i32.const 42))
    488        )
    489      )
    490    `),
    491    WebAssembly.RuntimeError,
    492    "too many memory pages"
    493  );
    494 } else {
    495  let instance = wasmEvalText(`(module
    496      (memory i64 4294967299 4294967299 (pagesize 1))
    497      (func (export "f")
    498        (i32.store (i64.const 4294967300) (i32.const 42))
    499      )
    500    )
    501  `);
    502 
    503  assertErrorMessage(() => instance.exports.f(), WebAssembly.RuntimeError, "index out of bounds");
    504 }