1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// This module provides a *very* basic panic runtime for LLVM execution
// tests involving panics.
//
// Note that this is strictly for *execution testing* and is not used in
// production! See `crate::emit::test::PanicTestPreludeCodegen` and
// `crate::emit::test::Emission::exec_panicking` for the test harness.
//
// The progam entry point should be invoked via the `trampoline` function
// which launches the program. Calls to `panic_exit` will exit the program
// and make `trampoline` return prematurely. Note that the runtime will
// perform a direct jump to the exit and no unrolling is performed. This
// is fine for our use case since stack frames from hugr-llvm generated
// bytecode don't require cleanup. However, using `panic_exit` to jump over
// Rust frames is undefined behaviour.
//
// Note that the implementation relies on setjmp-longjmp (SJLJ) jumping to
// exit the program. As SJLJ is not available in Rust, this had to be
// implemented in C in linked into the Rust binary.
// Runs the `entry` function inside the panic runtime.
//
// # Safety
//
// `jmp_buf` must have size of at least `jmp_buf_size()`.
void
// Exits a program launched by `trampoline`.
//
// This function will never return. Also copies the first `msg_limit`
// characters of the string `msg` into `msg_buf`.
//
// # Safety
//
// Calls to this function are only allowed within stack frames that were
// launched by `trampoline`. Furthermore, `panic_exit` may only be used
// to jump over C or LLVM execution engine frames. Using `panic_exit` to
// jump over Rust frames is undefined behaviour.
//
// `jmp_buf` must be the same buffer given to `trampoline` and `msg_buf`
// must have size of at least `msg_limit`.
void
// Minimum size that needs to be alloced for jump buffers passed to
// `trampoline` and `panic_exit`.
size_t