You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: tests/all/epoch_mmu.rs
+38-1Lines changed: 38 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
#![cfg(not(miri))]
2
2
3
3
use object::{Object,ObjectSection};
4
-
use wasmtime::{Config,Engine};
4
+
use wasmtime::{Config,Engine,Instance,Module,Store};
5
5
use wasmtime_environ::obj::ELF_WASMTIME_EPOCH_CHECKS;
6
6
7
7
/// Asserts that each epoch-check offset encoded into the binary points to the
@@ -49,3 +49,40 @@ fn epoch_check_offsets() {
49
49
"There should be 2 epoch checks (function prologue & loop backedge). The offset after the prologue's dead load should be 15, and the one after the loop's backedge should be 18."
50
50
);
51
51
}
52
+
53
+
/// Runs a wasm function that loops forever with MMU-based epoch interruption
54
+
/// enabled. Incrementing the epoch past the deadline triggers the signal
55
+
/// handler (`trap_handler`) which converts the SIGSEGV into a trap.
56
+
#[test]
57
+
fnepoch_mmu_trap_via_signal_handler(){
58
+
letmut config = Config::new();
59
+
config.epoch_interruption_via_mmu(true);
60
+
let engine = Engine::new(&config).unwrap();
61
+
let module = Module::new(
62
+
&engine,
63
+
r#"(module
64
+
(memory 0)
65
+
(func (export "answer") (result i32)
66
+
i32.const 42
67
+
)
68
+
)"#,
69
+
)
70
+
.unwrap();
71
+
72
+
// Trap as soon as the first epoch check is encountered, in the function
73
+
// prologue. Recall that MMU-based epochs don't operate based on a numeric
74
+
// deadline but on an external entity protecting the memory page, typically
75
+
// on a timer.
76
+
letmut store = Store::new(&engine,());
77
+
store.epoch_deadline_trap();// Allegedly the default.
78
+
// Protect that page:
79
+
store.end_mmu_epoch();
80
+
81
+
let instance = Instance::new(&mut store,&module,&[]).unwrap();
0 commit comments