pub unsafe fn register_hook<S, H>(signals: &S, hook: H) -> ExceptionHookIdExpand description
Registers a exception hook.
The hook will be invoked from a signal handler when any of the specified signals are raised.
If multiple exception hooks are registered for one signal, they will be
invoked in reverse order of registration until one of them returns true.
If all hooks return false, whatever signal action was installed prior to
any hooks being registered will be taken. In the case of the prior signal
action being the default signal handler, this is implemented by reinstalling
SIG_DFL and then returning, which should re-trigger the exception and dump
core.
Hooks will be called only when the signal’s subtype code indicates that it
was triggered synchronously by a hardware exception. In particular, hooks
will not run for any signal which was delivered using kill(2). Hooks
therefore do not need to worry about async-signal safety and can do things
like allocate memory without risking deadlocks.
The returned ExceptionHookId can later be used to unregister the hook.
§Safety
In isolation, this call is always safe. The function is declared as
unsafe in order to simplify reasoning about the soundness of unsafe code
which potentially triggers exceptions. Making the registration of exception
hooks an unsafe operation means that unsafe code can rely on knowing exactly
what will happen when an exception occurs, without having to account for the
possibility that untrusted safe code may have installed a rogue exception
hook.