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
58
59
60
61
62
63
64
65
66
67
68
69
70
//! Per-thread storage for uncaught exceptions reported from foreign plugins.
//!
//! When a C# trampoline catches an unhandled exception it calls back into Rust via
//! the [`TRAMPOLINE_UNCAUGHT_EXCEPTION`](super::trampoline::TRAMPOLINE_UNCAUGHT_EXCEPTION)
//! callback. The callback stashes the message into a thread-local; every generated
//! `plugin!` method then calls [`panic_on_uncaught`] right after its FFI invocation
//! so the exception surfaces as a Rust panic on the calling thread.
//!
//! Generated wrappers must call [`clear`] before the invocation to drop any stale
//! value left over from a previous panic that was swallowed by `catch_unwind`.
use RefCell;
thread_local!
/// Drops any pending uncaught-exception message on the current thread.
/// Removes and returns the pending uncaught-exception message for the current thread.
/// Stores `msg` as the current thread's pending uncaught-exception message.
/// Panics with the pending uncaught-exception message, if any.
///
/// Generated `plugin!` method wrappers call this right after invoking the FFI
/// function so that exceptions caught by the plugin's outer try/catch propagate
/// as a Rust panic on the caller's thread.
/// C ABI callback registered with foreign plugins as the uncaught-exception sink.
///
/// `ctx` is ignored (callers may pass null). `message` is a UTF-8 byte slice of
/// length `len`, not null-terminated.
///
/// # Safety
///
/// `message` must point to at least `len` valid bytes for the duration of the call.
pub unsafe extern "C"
/// Returns the function pointer for [`uncaught_exception_callback`] cast to `*const u8`,
/// suitable for passing to a plugin's trampoline register fn.