@@ -59,38 +59,41 @@ mod for_windows {
59
59
use crate :: Build ;
60
60
61
61
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 ) ;
67
69
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 ( ) ;
70
72
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( ) ) ;
88
90
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
+ }
94
97
}
95
98
96
99
// Note: we intentionally leak the job object handle. When our process exits
0 commit comments