about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJakub Beránek <berykubik@gmail.com>2025-03-11 09:07:18 +0100
committerJakub Beránek <berykubik@gmail.com>2025-03-11 09:07:18 +0100
commited5877e0ada49a1f44f60f61c032520ec92b3607 (patch)
tree020f23640d21b8a7bcc7da1dcfe3e8ef0a1b4e71
parentb2de19e8acb938eb1c6c4e59f8a06655b299f6f9 (diff)
downloadrust-ed5877e0ada49a1f44f60f61c032520ec92b3607.tar.gz
rust-ed5877e0ada49a1f44f60f61c032520ec92b3607.zip
Add missing unsafe block
-rw-r--r--src/bootstrap/src/utils/job.rs61
1 files changed, 32 insertions, 29 deletions
diff --git a/src/bootstrap/src/utils/job.rs b/src/bootstrap/src/utils/job.rs
index 99fc3e2dc7b..4949518de79 100644
--- a/src/bootstrap/src/utils/job.rs
+++ b/src/bootstrap/src/utils/job.rs
@@ -61,38 +61,41 @@ mod for_windows {
     use crate::Build;
 
     pub unsafe fn setup(build: &mut Build) {
-        // Enable the Windows Error Reporting dialog which msys disables,
-        // so we can JIT debug rustc
-        let mode = SetErrorMode(THREAD_ERROR_MODE::default());
-        let mode = THREAD_ERROR_MODE(mode);
-        SetErrorMode(mode & !SEM_NOGPFAULTERRORBOX);
+        // SAFETY: pretty much everything below is unsafe
+        unsafe {
+            // Enable the Windows Error Reporting dialog which msys disables,
+            // so we can JIT debug rustc
+            let mode = SetErrorMode(THREAD_ERROR_MODE::default());
+            let mode = THREAD_ERROR_MODE(mode);
+            SetErrorMode(mode & !SEM_NOGPFAULTERRORBOX);
 
-        // Create a new job object for us to use
-        let job = CreateJobObjectW(None, PCWSTR::null()).unwrap();
+            // Create a new job object for us to use
+            let job = CreateJobObjectW(None, PCWSTR::null()).unwrap();
 
-        // Indicate that when all handles to the job object are gone that all
-        // process in the object should be killed. Note that this includes our
-        // entire process tree by default because we've added ourselves and our
-        // children will reside in the job by default.
-        let mut info = JOBOBJECT_EXTENDED_LIMIT_INFORMATION::default();
-        info.BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE;
-        if build.config.low_priority {
-            info.BasicLimitInformation.LimitFlags |= JOB_OBJECT_LIMIT_PRIORITY_CLASS;
-            info.BasicLimitInformation.PriorityClass = BELOW_NORMAL_PRIORITY_CLASS.0;
-        }
-        let r = SetInformationJobObject(
-            job,
-            JobObjectExtendedLimitInformation,
-            &info as *const _ as *const c_void,
-            size_of_val(&info) as u32,
-        );
-        assert!(r.is_ok(), "{}", io::Error::last_os_error());
+            // Indicate that when all handles to the job object are gone that all
+            // process in the object should be killed. Note that this includes our
+            // entire process tree by default because we've added ourselves and our
+            // children will reside in the job by default.
+            let mut info = JOBOBJECT_EXTENDED_LIMIT_INFORMATION::default();
+            info.BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE;
+            if build.config.low_priority {
+                info.BasicLimitInformation.LimitFlags |= JOB_OBJECT_LIMIT_PRIORITY_CLASS;
+                info.BasicLimitInformation.PriorityClass = BELOW_NORMAL_PRIORITY_CLASS.0;
+            }
+            let r = SetInformationJobObject(
+                job,
+                JobObjectExtendedLimitInformation,
+                &info as *const _ as *const c_void,
+                size_of_val(&info) as u32,
+            );
+            assert!(r.is_ok(), "{}", io::Error::last_os_error());
 
-        // Assign our process to this job object.
-        let r = AssignProcessToJobObject(job, GetCurrentProcess());
-        if r.is_err() {
-            CloseHandle(job).ok();
-            return;
+            // Assign our process to this job object.
+            let r = AssignProcessToJobObject(job, GetCurrentProcess());
+            if r.is_err() {
+                CloseHandle(job).ok();
+                return;
+            }
         }
 
         // Note: we intentionally leak the job object handle. When our process exits