Sha256: 6791fe0dda9456b3becf989cbc89bc45ae27302e633572a57bbf10a57b830076

Contents?: true

Size: 1.57 KB

Versions: 38

Compression:

Stored size: 1.57 KB

Contents

extern crate psm;

use std::panic;

const CHAIN_DEPTH: usize = 16;

psm::psm_stack_manipulation! {
    yes {
        use std::alloc;
        const STACK_ALIGN: usize = 4096;
        // Generating backraces (because of RUST_BACKTRACE) create a few quite large frames, so it is
        // important, that all frames have sufficient amount of available memory to not run over the
        // stack...
        const FRAME_SIZE: usize = 4096 * 10;

        fn panic_chain(depth: usize) {
            if depth == 0 {
                panic!("full chain!");
            } else {
                unsafe {
                    let layout = alloc::Layout::from_size_align(FRAME_SIZE, STACK_ALIGN).unwrap();
                    let new_stack = alloc::alloc(layout);
                    assert!(!new_stack.is_null(), "allocations must succeed!");
                    let p = psm::on_stack(new_stack, FRAME_SIZE, || {
                        panic::catch_unwind(|| {
                            panic_chain(depth - 1);
                        })
                    });
                    alloc::dealloc(new_stack, layout);
                    p.map_err(panic::resume_unwind).unwrap()
                }
            }
        }

        fn main() {
            panic_chain(CHAIN_DEPTH);
        }

        #[test]
        fn run_example() {
            assert!(panic::catch_unwind(|| {
                panic_chain(CHAIN_DEPTH);
            }).is_err(), "Panic did not propagate!");
        }
    }

    no {
        fn main() {
            eprintln!("Stack manipulation not supported by this target");
        }
    }
}

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
wasmtime-29.0.0 ./ext/cargo-vendor/psm-0.1.24/examples/panics.rs
wasmtime-28.0.0 ./ext/cargo-vendor/psm-0.1.24/examples/panics.rs
wasmtime-27.0.0 ./ext/cargo-vendor/psm-0.1.24/examples/panics.rs
wasmtime-26.0.0 ./ext/cargo-vendor/psm-0.1.23/examples/panics.rs
wasmtime-25.0.2 ./ext/cargo-vendor/psm-0.1.21/examples/panics.rs
wasmtime-25.0.1 ./ext/cargo-vendor/psm-0.1.21/examples/panics.rs
wasmtime-25.0.0 ./ext/cargo-vendor/psm-0.1.21/examples/panics.rs
wasmtime-24.0.0 ./ext/cargo-vendor/psm-0.1.21/examples/panics.rs
wasmtime-23.0.2 ./ext/cargo-vendor/psm-0.1.21/examples/panics.rs
wasmtime-22.0.0 ./ext/cargo-vendor/psm-0.1.21/examples/panics.rs
wasmtime-21.0.1 ./ext/cargo-vendor/psm-0.1.21/examples/panics.rs
wasmtime-20.0.2 ./ext/cargo-vendor/psm-0.1.21/examples/panics.rs
wasmtime-20.0.0 ./ext/cargo-vendor/psm-0.1.21/examples/panics.rs
wasmtime-18.0.3 ./ext/cargo-vendor/psm-0.1.21/examples/panics.rs
wasmtime-17.0.1 ./ext/cargo-vendor/psm-0.1.21/examples/panics.rs
wasmtime-17.0.0 ./ext/cargo-vendor/psm-0.1.21/examples/panics.rs
wasmtime-16.0.0 ./ext/cargo-vendor/psm-0.1.21/examples/panics.rs
wasmtime-15.0.1 ./ext/cargo-vendor/psm-0.1.21/examples/panics.rs
wasmtime-15.0.0 ./ext/cargo-vendor/psm-0.1.21/examples/panics.rs
wasmtime-14.0.4 ./ext/cargo-vendor/psm-0.1.21/examples/panics.rs