|
417 | 417 | (assert_trap (invoke "i64.atomic.rmw16.cmpxchg_u" (i32.const 1) (i64.const 0) (i64.const 0)) "unaligned atomic")
|
418 | 418 | (assert_trap (invoke "i64.atomic.rmw32.cmpxchg_u" (i32.const 1) (i64.const 0) (i64.const 0)) "unaligned atomic")
|
419 | 419 |
|
| 420 | +;; wait/notify |
420 | 421 | (module
|
421 | 422 | (memory 1 1 shared)
|
422 | 423 |
|
|
431 | 432 | )
|
432 | 433 |
|
433 | 434 | (invoke "init" (i64.const 0xffffffffffff))
|
| 435 | + |
| 436 | +;; wait returns immediately if values do not match |
434 | 437 | (assert_return (invoke "memory.atomic.wait32" (i32.const 0) (i32.const 0) (i64.const 0)) (i32.const 1))
|
435 | 438 | (assert_return (invoke "memory.atomic.wait64" (i32.const 0) (i64.const 0) (i64.const 0)) (i32.const 1))
|
| 439 | + |
| 440 | +;; notify always returns |
| 441 | +(assert_return (invoke "memory.atomic.notify" (i32.const 0) (i32.const 0)) (i32.const 0)) |
| 442 | + |
| 443 | +;; OOB wait and notify always trap |
| 444 | +(assert_trap (invoke "memory.atomic.wait32" (i32.const 65536) (i32.const 0) (i64.const 0)) "out of bounds memory access") |
| 445 | +(assert_trap (invoke "memory.atomic.wait64" (i32.const 65536) (i64.const 0) (i64.const 0)) "out of bounds memory access") |
| 446 | + |
| 447 | +;; in particular, notify always traps even if waking 0 threads |
| 448 | +(assert_trap (invoke "memory.atomic.notify" (i32.const 65536) (i32.const 0)) "out of bounds memory access") |
| 449 | + |
| 450 | +;; similarly, unaligned wait and notify always trap |
| 451 | +(assert_trap (invoke "memory.atomic.wait32" (i32.const 65531) (i32.const 0) (i64.const 0)) "unaligned atomic") |
| 452 | +(assert_trap (invoke "memory.atomic.wait64" (i32.const 65524) (i64.const 0) (i64.const 0)) "unaligned atomic") |
| 453 | + |
| 454 | +(assert_trap (invoke "memory.atomic.notify" (i32.const 65531) (i32.const 0)) "unaligned atomic") |
| 455 | + |
| 456 | +;; atomic.wait traps on unshared memory even if it wouldn't block |
| 457 | +(module |
| 458 | + (memory 1 1) |
| 459 | + |
| 460 | + (func (export "init") (param $value i64) (i64.store (i32.const 0) (local.get $value))) |
| 461 | + |
| 462 | + (func (export "memory.atomic.notify") (param $addr i32) (param $count i32) (result i32) |
| 463 | + (memory.atomic.notify (local.get 0) (local.get 1))) |
| 464 | + (func (export "memory.atomic.wait32") (param $addr i32) (param $expected i32) (param $timeout i64) (result i32) |
| 465 | + (memory.atomic.wait32 (local.get 0) (local.get 1) (local.get 2))) |
| 466 | + (func (export "memory.atomic.wait64") (param $addr i32) (param $expected i64) (param $timeout i64) (result i32) |
| 467 | + (memory.atomic.wait64 (local.get 0) (local.get 1) (local.get 2))) |
| 468 | +) |
| 469 | + |
| 470 | +(invoke "init" (i64.const 0xffffffffffff)) |
| 471 | + |
| 472 | +(assert_trap (invoke "memory.atomic.wait32" (i32.const 0) (i32.const 0) (i64.const 0)) "expected shared memory") |
| 473 | +(assert_trap (invoke "memory.atomic.wait64" (i32.const 0) (i64.const 0) (i64.const 0)) "expected shared memory") |
| 474 | + |
| 475 | +;; notify still works |
436 | 476 | (assert_return (invoke "memory.atomic.notify" (i32.const 0) (i32.const 0)) (i32.const 0))
|
437 | 477 |
|
| 478 | +;; OOB and unaligned notify still trap |
| 479 | +(assert_trap (invoke "memory.atomic.notify" (i32.const 65536) (i32.const 0)) "out of bounds memory access") |
| 480 | +(assert_trap (invoke "memory.atomic.notify" (i32.const 65531) (i32.const 0)) "unaligned atomic") |
| 481 | + |
| 482 | + |
438 | 483 | ;; unshared memory is OK
|
439 | 484 | (module
|
440 | 485 | (memory 1 1)
|
|
488 | 533 | (func (drop (i64.atomic.rmw32.cmpxchg_u (i32.const 0) (i64.const 0) (i64.const 0))))
|
489 | 534 | )
|
490 | 535 |
|
| 536 | +;; atomic.fence: no memory is ok |
| 537 | +(module |
| 538 | + (func (export "fence") (atomic.fence)) |
| 539 | +) |
| 540 | + |
| 541 | +(assert_return (invoke "fence")) |
| 542 | + |
491 | 543 | ;; Fails with no memory
|
492 | 544 | (assert_invalid (module (func (drop (memory.atomic.notify (i32.const 0) (i32.const 0))))) "unknown memory")
|
493 | 545 | (assert_invalid (module (func (drop (memory.atomic.wait32 (i32.const 0) (i32.const 0) (i64.const 0))))) "unknown memory")
|
|
0 commit comments