mirror of
https://github.com/rust-lang/rust
synced 2024-10-19 23:13:41 +00:00
Add safety comments to panic::(set/take/update)_hook
This commit is contained in:
parent
8ef3ce866e
commit
0c58586c9c
|
@ -124,6 +124,11 @@ pub fn set_hook(hook: Box<dyn Fn(&PanicInfo<'_>) + 'static + Sync + Send>) {
|
|||
panic!("cannot modify the panic hook from a panicking thread");
|
||||
}
|
||||
|
||||
// SAFETY:
|
||||
//
|
||||
// - `HOOK` can only be modified while holding write access to `HOOK_LOCK`.
|
||||
// - The argument of `Box::from_raw` is always a valid pointer that was created using
|
||||
// `Box::into_raw`.
|
||||
unsafe {
|
||||
let guard = HOOK_LOCK.write();
|
||||
let old_hook = HOOK;
|
||||
|
@ -173,6 +178,11 @@ pub fn take_hook() -> Box<dyn Fn(&PanicInfo<'_>) + 'static + Sync + Send> {
|
|||
panic!("cannot modify the panic hook from a panicking thread");
|
||||
}
|
||||
|
||||
// SAFETY:
|
||||
//
|
||||
// - `HOOK` can only be modified while holding write access to `HOOK_LOCK`.
|
||||
// - The argument of `Box::from_raw` is always a valid pointer that was created using
|
||||
// `Box::into_raw`.
|
||||
unsafe {
|
||||
let guard = HOOK_LOCK.write();
|
||||
let hook = HOOK;
|
||||
|
@ -229,6 +239,11 @@ pub fn update_hook<F>(hook_fn: F)
|
|||
panic!("cannot modify the panic hook from a panicking thread");
|
||||
}
|
||||
|
||||
// SAFETY:
|
||||
//
|
||||
// - `HOOK` can only be modified while holding write access to `HOOK_LOCK`.
|
||||
// - The argument of `Box::from_raw` is always a valid pointer that was created using
|
||||
// `Box::into_raw`.
|
||||
unsafe {
|
||||
let guard = HOOK_LOCK.write();
|
||||
let old_hook = HOOK;
|
||||
|
|
Loading…
Reference in a new issue