@@ -61,38 +61,41 @@ mod for_windows {
6161 use crate :: Build ;
6262
6363 pub unsafe fn setup ( build : & mut Build ) {
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 ) ;
64+ // SAFETY: pretty much everything below is unsafe
65+ unsafe {
66+ // Enable the Windows Error Reporting dialog which msys disables,
67+ // so we can JIT debug rustc
68+ let mode = SetErrorMode ( THREAD_ERROR_MODE :: default ( ) ) ;
69+ let mode = THREAD_ERROR_MODE ( mode) ;
70+ SetErrorMode ( mode & !SEM_NOGPFAULTERRORBOX ) ;
6971
70- // Create a new job object for us to use
71- let job = CreateJobObjectW ( None , PCWSTR :: null ( ) ) . unwrap ( ) ;
72+ // Create a new job object for us to use
73+ let job = CreateJobObjectW ( None , PCWSTR :: null ( ) ) . unwrap ( ) ;
7274
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( ) ) ;
75+ // Indicate that when all handles to the job object are gone that all
76+ // process in the object should be killed. Note that this includes our
77+ // entire process tree by default because we've added ourselves and our
78+ // children will reside in the job by default.
79+ let mut info = JOBOBJECT_EXTENDED_LIMIT_INFORMATION :: default ( ) ;
80+ info. BasicLimitInformation . LimitFlags = JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE ;
81+ if build. config . low_priority {
82+ info. BasicLimitInformation . LimitFlags |= JOB_OBJECT_LIMIT_PRIORITY_CLASS ;
83+ info. BasicLimitInformation . PriorityClass = BELOW_NORMAL_PRIORITY_CLASS . 0 ;
84+ }
85+ let r = SetInformationJobObject (
86+ job,
87+ JobObjectExtendedLimitInformation ,
88+ & info as * const _ as * const c_void ,
89+ size_of_val ( & info) as u32 ,
90+ ) ;
91+ assert ! ( r. is_ok( ) , "{}" , io:: Error :: last_os_error( ) ) ;
9092
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 ;
93+ // Assign our process to this job object.
94+ let r = AssignProcessToJobObject ( job, GetCurrentProcess ( ) ) ;
95+ if r. is_err ( ) {
96+ CloseHandle ( job) . ok ( ) ;
97+ return ;
98+ }
9699 }
97100
98101 // Note: we intentionally leak the job object handle. When our process exits
0 commit comments