about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBadel2 <2badel2@gmail.com>2022-01-07 23:34:45 +0100
committerBadel2 <2badel2@gmail.com>2022-01-08 00:57:59 +0100
commit0c58586c9cbdd4db62c9c127ba89fd4d1d53acd7 (patch)
tree46ded2cdd828db2275849e3dcc7d2c0c98fae4c8
parent8ef3ce866e2f20bdcc567e2f7012f81ce2e60298 (diff)
Add safety comments to panic::(set/take/update)_hook
-rw-r--r--library/std/src/panicking.rs15
1 files changed, 15 insertions, 0 deletions
diff --git a/library/std/src/panicking.rs b/library/std/src/panicking.rs
index 19040cb12e0..44f573297ee 100644
--- a/library/std/src/panicking.rs
+++ b/library/std/src/panicking.rs
@@ -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 @@ where
         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;