()
| 6 | |
| 7 | #[test] |
| 8 | fn host_always_has_some_stack() -> Result<()> { |
| 9 | static HITS: AtomicUsize = AtomicUsize::new(0); |
| 10 | // assume hosts always have at least 128k of stack |
| 11 | const HOST_STACK: usize = 128 * 1024; |
| 12 | |
| 13 | let mut store = if cfg!(target_arch = "x86_64") { |
| 14 | let mut config = Config::new(); |
| 15 | // Force cranelift-based libcalls to show up by ensuring that platform |
| 16 | // support is turned off. |
| 17 | unsafe { |
| 18 | config.cranelift_flag_set("has_avx", "false"); |
| 19 | config.cranelift_flag_set("has_sse42", "false"); |
| 20 | config.cranelift_flag_set("has_sse41", "false"); |
| 21 | config.cranelift_flag_set("has_ssse3", "false"); |
| 22 | config.cranelift_flag_set("has_sse3", "false"); |
| 23 | } |
| 24 | Store::new(&Engine::new(&config)?, ()) |
| 25 | } else { |
| 26 | Store::<()>::default() |
| 27 | }; |
| 28 | |
| 29 | // Create a module that's infinitely recursive, but calls the host on each |
| 30 | // level of wasm stack to always test how much host stack we have left. |
| 31 | // |
| 32 | // Each of the function exports of this module calls out to the host in a |
| 33 | // different way, and each one is tested below to make sure that the way of |
| 34 | // exiting out to the host is tested thoroughly. |
| 35 | let module = Module::new( |
| 36 | store.engine(), |
| 37 | r#" |
| 38 | (module |
| 39 | (import "" "" (func $host1)) |
| 40 | (import "" "" (func $host2)) |
| 41 | |
| 42 | ;; exit via wasm-to-native trampoline |
| 43 | (func $recursive1 (export "f1") |
| 44 | call $host1 |
| 45 | call $recursive1) |
| 46 | |
| 47 | ;; exit via wasm-to-array trampoline |
| 48 | (func $recursive2 (export "f2") |
| 49 | call $host2 |
| 50 | call $recursive2) |
| 51 | |
| 52 | ;; exit via a wasmtime-based libcall |
| 53 | (memory 1) |
| 54 | (func $recursive3 (export "f3") |
| 55 | (drop (memory.grow (i32.const 0))) |
| 56 | call $recursive3) |
| 57 | |
| 58 | ;; exit via a cranelift-based libcall |
| 59 | (func $recursive4 (export "f4") |
| 60 | (drop (call $f32_ceil (f32.const 0))) |
| 61 | call $recursive4) |
| 62 | (func $f32_ceil (param f32) (result f32) |
| 63 | (f32.ceil (local.get 0))) |
| 64 | ) |
| 65 | "#, |
nothing calls this directly
no test coverage detected