fn enter_wasm<T>(store: &mut StoreContextMut<'_, T>) -> Result<(), Trap> {
    let stack_pointer = psm::stack_pointer() as usize;

    // Determine the stack pointer where, after which, any wasm code will
    // immediately trap. This is checked on the entry to all wasm functions.
    //
    // Note that this isn't 100% precise. We are requested to give wasm
    // `max_wasm_stack` bytes, but what we're actually doing is giving wasm
    // probably a little less than `max_wasm_stack` because we're
    // calculating the limit relative to this function's approximate stack
    // pointer. Wasm will be executed on a frame beneath this one (or next
    // to it). In any case it's expected to be at most a few hundred bytes
    // of slop one way or another. When wasm is typically given a MB or so
    // (a million bytes) the slop shouldn't matter too much.
    //
    // After we've got the stack limit then we store it into the `stack_limit`
    // variable. Note that the store is an atomic swap to ensure that we can
    // consume any previously-sent interrupt requests. If we found that wasm was
    // previously interrupted then we immediately return a trap (after resetting
    // the stack limit). Otherwise we're good to keep on going.
    //
    // Note the usage of `Relaxed` memory orderings here. This is specifically
    // an optimization in the `Drop` below where a `Relaxed` store is speedier
    // than a `SeqCst` store. The rationale for `Relaxed` here is that the
    // atomic orderings here aren't actually protecting any memory, we're just
    // trying to be atomic with respect to this one location in memory (for when
    // `InterruptHandle` sends us a signal). Due to the lack of needing to
    // synchronize with any other memory it's hoped that the choice of `Relaxed`
    // here should be correct for our use case.
    let wasm_stack_limit = stack_pointer - store.engine().config().max_wasm_stack;
    let interrupts = store.0.interrupts();
    match interrupts.stack_limit.swap(wasm_stack_limit, Relaxed) {
        wasmtime_environ::INTERRUPTED => {
            // This means that an interrupt happened before we actually
            // called this function, which means that we're now
            // considered interrupted.
            interrupts.stack_limit.store(usize::max_value(), Relaxed);
            return Err(Trap::new_wasm(
                None,
                wasmtime_environ::ir::TrapCode::Interrupt,
                backtrace::Backtrace::new_unresolved(),
            ));
        }
        n => debug_assert_eq!(usize::max_value(), n),
    }
    store
        .0
        .externref_activations_table()
        .set_stack_canary(Some(stack_pointer));

    Ok(())
}
/// This function is called to register state within `Store` whenever
/// WebAssembly is entered for the first time within the `Store`. This isn't
/// called when wasm is called recursively within the `Store`.
///
/// This function sets up various limits such as:
///
/// * The stack limit. This is what ensures that we limit the stack space
///   allocated by WebAssembly code and it's relative to the initial stack
///   pointer that called into wasm.
///
/// * Stack canaries for externref gc tracing. Currently the implementation
///   relies on walking frames but the stack walker isn't always 100% reliable,
///   so a canary is used to ensure that if the canary is seen then it's
///   guaranteed all wasm frames have been walked.
///
/// This function may fail if the the stack limit can't be set because an
/// interrupt already happened.
This function is called to register state within `Store` whenever
WebAssembly is entered for the first time within the `Store`. This isn't
called when wasm is called recursively within the `Store`.

This function sets up various limits such as.

The stack limit. This is what ensures that we limit the stack space
allocated by WebAssembly code and it's relative to the initial stack
pointer that called into wasm.

Stack canaries for externref gc tracing. Currently the implementation
relies on walking frames but the stack walker isn't always 100% reliable,
so a canary is used to ensure that if the canary is seen then it's
guaranteed all wasm frames have been walked.

This function may fail if the the stack limit can't be set because an
interrupt already happened.
This function is called to register state within ` Store ` whenever WebAssembly is entered for the first time within the ` Store ` . This isn ' t called when wasm is called recursively within the ` Store ` . This function sets up various limits such as . The stack limit . This is what ensures that we limit the stack space allocated by WebAssembly code and it ' s relative to the initial stack pointer that called into wasm . Stack canaries for externref gc tracing . Currently the implementation relies on walking frames but the stack walker isn ' t always 100% reliable so a canary is used to ensure that if the canary is seen then it ' s guaranteed all wasm frames have been walked . This function may fail if the the stack limit can ' t be set because an interrupt already happened .
fn enter_wasm<T>(store: &mut StoreContextMut<'_, T>) -> Result<(), Trap> {
    let stack_pointer = psm::stack_pointer() as usize;
    // Determine the stack pointer where, after which, any wasm code will
    // immediately trap. This is checked on the entry to all wasm functions.
    //
    // Note that this isn't 100% precise. We are requested to give wasm
    // `max_wasm_stack` bytes, but what we're actually doing is giving wasm
    // probably a little less than `max_wasm_stack` because we're
    // calculating the limit relative to this function's approximate stack
    // pointer. Wasm will be executed on a frame beneath this one (or next
    // to it). In any case it's expected to be at most a few hundred bytes
    // of slop one way or another. When wasm is typically given a MB or so
    // (a million bytes) the slop shouldn't matter too much.
    //
    // After we've got the stack limit then we store it into the `stack_limit`
    // variable. Note that the store is an atomic swap to ensure that we can
    // consume any previously-sent interrupt requests. If we found that wasm was
    // previously interrupted then we immediately return a trap (after resetting
    // the stack limit). Otherwise we're good to keep on going.
    //
    // Note the usage of `Relaxed` memory orderings here. This is specifically
    // an optimization in the `Drop` below where a `Relaxed` store is speedier
    // than a `SeqCst` store. The rationale for `Relaxed` here is that the
    // atomic orderings here aren't actually protecting any memory, we're just
    // trying to be atomic with respect to this one location in memory (for when
    // `InterruptHandle` sends us a signal). Due to the lack of needing to
    // synchronize with any other memory it's hoped that the choice of `Relaxed`
    // here should be correct for our use case.
    let wasm_stack_limit = stack_pointer - store.engine().config().max_wasm_stack;
    let interrupts = store.0.interrupts();
    match interrupts.stack_limit.swap(wasm_stack_limit, Relaxed) {
        wasmtime_environ::INTERRUPTED => {
            // This means that an interrupt happened before we actually
            // called this function, which means that we're now
            // considered interrupted.
            interrupts.stack_limit.store(usize::max_value(), Relaxed);
            return Err(Trap::new_wasm(
                None,
                wasmtime_environ::ir::TrapCode::Interrupt,
                backtrace::Backtrace::new_unresolved(),
            ));
        }
        n => debug_assert_eq!(usize::max_value(), n),
    }
    store
        .0
        .externref_activations_table()
        .set_stack_canary(Some(stack_pointer));
    Ok(())
}
fn enter_wasm < T > ( store : & mut StoreContextMut < ' _ , T > ) -> Result < ( ) , Trap > { let stack_pointer = psm :: stack_pointer ( ) as usize ; // Determine the stack pointer where, after which, any wasm code will // immediately trap. This is checked on the entry to all wasm functions. // // Note that this isn't 100% precise. We are requested to give wasm // `max_wasm_stack` bytes, but what we're actually doing is giving wasm // probably a little less than `max_wasm_stack` because we're // calculating the limit relative to this function's approximate stack // pointer. Wasm will be executed on a frame beneath this one (or next // to it). In any case it's expected to be at most a few hundred bytes // of slop one way or another. When wasm is typically given a MB or so // (a million bytes) the slop shouldn't matter too much. // // After we've got the stack limit then we store it into the `stack_limit` // variable. Note that the store is an atomic swap to ensure that we can // consume any previously-sent interrupt requests. If we found that wasm was // previously interrupted then we immediately return a trap (after resetting // the stack limit). Otherwise we're good to keep on going. // // Note the usage of `Relaxed` memory orderings here. This is specifically // an optimization in the `Drop` below where a `Relaxed` store is speedier // than a `SeqCst` store. The rationale for `Relaxed` here is that the // atomic orderings here aren't actually protecting any memory, we're just // trying to be atomic with respect to this one location in memory (for when // `InterruptHandle` sends us a signal). Due to the lack of needing to // synchronize with any other memory it's hoped that the choice of `Relaxed` // here should be correct for our use case. let wasm_stack_limit = stack_pointer - store . engine ( ) . config ( ) . max_wasm_stack ; let interrupts = store . 0 . interrupts ( ) ; match interrupts . stack_limit . swap ( wasm_stack_limit , Relaxed ) { wasmtime_environ :: INTERRUPTED => { // This means that an interrupt happened before we actually // called this function, which means that we're now // considered interrupted. interrupts . stack_limit . store ( usize :: max_value ( ) , Relaxed ) ; return Err ( Trap :: new_wasm ( None , wasmtime_environ :: ir :: TrapCode :: Interrupt , backtrace :: Backtrace :: new_unresolved ( ) , ) ) ; } n => debug_assert_eq ! ( usize max_value ( ) n ) , } store . 0 . externref_activations_table ( ) . set_stack_canary ( Some ( stack_pointer ) ) ; Ok ( ( ) ) }
This function is called to register state within `Store` whenever
WebAssembly is entered for the first time within the `Store`.
This function is called to register state within ` Store ` whenever WebAssembly is entered for the first time within the ` Store ` .
store
&mut StoreContextMut<'_, T>
store
&mut StoreContextMut<'_, T>