about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJubilee Young <workingjubilee@gmail.com>2024-07-17 00:08:05 -0700
committerJubilee Young <workingjubilee@gmail.com>2024-07-17 00:08:05 -0700
commitd47cb26ddd6574de6c81caf9fdaadef1a108628a (patch)
tree4fa196573d8a682e85d456330bb13a5522bab146
parent6ed563d49144f38b1066716833baf505646b274c (diff)
downloadrust-d47cb26ddd6574de6c81caf9fdaadef1a108628a.tar.gz
rust-d47cb26ddd6574de6c81caf9fdaadef1a108628a.zip
unix: unsafe-wrap install_main_guard_default
-rw-r--r--library/std/src/sys/pal/unix/stack_overflow.rs21
1 files changed, 12 insertions, 9 deletions
diff --git a/library/std/src/sys/pal/unix/stack_overflow.rs b/library/std/src/sys/pal/unix/stack_overflow.rs
index 0e15049be9a..0db08c1a926 100644
--- a/library/std/src/sys/pal/unix/stack_overflow.rs
+++ b/library/std/src/sys/pal/unix/stack_overflow.rs
@@ -419,6 +419,7 @@ mod imp {
         Some(stackaddr - page_size..stackaddr)
     }
 
+    #[forbid(unsafe_op_in_unsafe_fn)]
     unsafe fn install_main_guard_default(page_size: usize) -> Option<Range<usize>> {
         // Reallocate the last page of the stack.
         // This ensures SIGBUS will be raised on
@@ -429,19 +430,21 @@ mod imp {
         // read/write permissions and only then mprotect() it to
         // no permissions at all. See issue #50313.
         let stackptr = stack_start_aligned(page_size)?;
-        let result = mmap64(
-            stackptr,
-            page_size,
-            PROT_READ | PROT_WRITE,
-            MAP_PRIVATE | MAP_ANON | MAP_FIXED,
-            -1,
-            0,
-        );
+        let result = unsafe {
+            mmap64(
+                stackptr,
+                page_size,
+                PROT_READ | PROT_WRITE,
+                MAP_PRIVATE | MAP_ANON | MAP_FIXED,
+                -1,
+                0,
+            )
+        };
         if result != stackptr || result == MAP_FAILED {
             panic!("failed to allocate a guard page: {}", io::Error::last_os_error());
         }
 
-        let result = mprotect(stackptr, page_size, PROT_NONE);
+        let result = unsafe { mprotect(stackptr, page_size, PROT_NONE) };
         if result != 0 {
             panic!("failed to protect the guard page: {}", io::Error::last_os_error());
         }