Skip to content

Commit f9a450b

Browse files
committed
Add missing unsafe block
1 parent b711bca commit f9a450b

File tree

1 file changed

+32
-29
lines changed

1 file changed

+32
-29
lines changed

src/bootstrap/src/utils/job.rs

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -59,38 +59,41 @@ mod for_windows {
5959
use crate::Build;
6060

6161
pub unsafe fn setup(build: &mut Build) {
62-
// Enable the Windows Error Reporting dialog which msys disables,
63-
// so we can JIT debug rustc
64-
let mode = SetErrorMode(THREAD_ERROR_MODE::default());
65-
let mode = THREAD_ERROR_MODE(mode);
66-
SetErrorMode(mode & !SEM_NOGPFAULTERRORBOX);
62+
// SAFETY: pretty much everything below is unsafe
63+
unsafe {
64+
// Enable the Windows Error Reporting dialog which msys disables,
65+
// so we can JIT debug rustc
66+
let mode = SetErrorMode(THREAD_ERROR_MODE::default());
67+
let mode = THREAD_ERROR_MODE(mode);
68+
SetErrorMode(mode & !SEM_NOGPFAULTERRORBOX);
6769

68-
// Create a new job object for us to use
69-
let job = CreateJobObjectW(None, PCWSTR::null()).unwrap();
70+
// Create a new job object for us to use
71+
let job = CreateJobObjectW(None, PCWSTR::null()).unwrap();
7072

71-
// Indicate that when all handles to the job object are gone that all
72-
// process in the object should be killed. Note that this includes our
73-
// entire process tree by default because we've added ourselves and our
74-
// children will reside in the job by default.
75-
let mut info = JOBOBJECT_EXTENDED_LIMIT_INFORMATION::default();
76-
info.BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE;
77-
if build.config.low_priority {
78-
info.BasicLimitInformation.LimitFlags |= JOB_OBJECT_LIMIT_PRIORITY_CLASS;
79-
info.BasicLimitInformation.PriorityClass = BELOW_NORMAL_PRIORITY_CLASS.0;
80-
}
81-
let r = SetInformationJobObject(
82-
job,
83-
JobObjectExtendedLimitInformation,
84-
&info as *const _ as *const c_void,
85-
mem::size_of_val(&info) as u32,
86-
);
87-
assert!(r.is_ok(), "{}", io::Error::last_os_error());
73+
// Indicate that when all handles to the job object are gone that all
74+
// process in the object should be killed. Note that this includes our
75+
// entire process tree by default because we've added ourselves and our
76+
// children will reside in the job by default.
77+
let mut info = JOBOBJECT_EXTENDED_LIMIT_INFORMATION::default();
78+
info.BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE;
79+
if build.config.low_priority {
80+
info.BasicLimitInformation.LimitFlags |= JOB_OBJECT_LIMIT_PRIORITY_CLASS;
81+
info.BasicLimitInformation.PriorityClass = BELOW_NORMAL_PRIORITY_CLASS.0;
82+
}
83+
let r = SetInformationJobObject(
84+
job,
85+
JobObjectExtendedLimitInformation,
86+
&info as *const _ as *const c_void,
87+
size_of_val(&info) as u32,
88+
);
89+
assert!(r.is_ok(), "{}", io::Error::last_os_error());
8890

89-
// Assign our process to this job object.
90-
let r = AssignProcessToJobObject(job, GetCurrentProcess());
91-
if r.is_err() {
92-
CloseHandle(job).ok();
93-
return;
91+
// Assign our process to this job object.
92+
let r = AssignProcessToJobObject(job, GetCurrentProcess());
93+
if r.is_err() {
94+
CloseHandle(job).ok();
95+
return;
96+
}
9497
}
9598

9699
// Note: we intentionally leak the job object handle. When our process exits

0 commit comments

Comments
 (0)