Skip to content

Commit f82b7cb

Browse files
committed
Auto merge of #38231 - vadimcn:errormode, r=alexcrichton
Prevent Windows from displaying UI on errors. Otherwise tests like run-pass/out-of-stack get wedged on Windows error reporting dialog (unless error reporting has been disabled, of course).
2 parents c79d0b4 + 6404143 commit f82b7cb

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/bootstrap/job.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ type LPVOID = *mut u8;
5151
type JOBOBJECTINFOCLASS = i32;
5252
type SIZE_T = usize;
5353
type LARGE_INTEGER = i64;
54+
type UINT = u32;
5455
type ULONG_PTR = usize;
5556
type ULONGLONG = u64;
5657

@@ -59,6 +60,8 @@ const DUPLICATE_SAME_ACCESS: DWORD = 0x2;
5960
const PROCESS_DUP_HANDLE: DWORD = 0x40;
6061
const JobObjectExtendedLimitInformation: JOBOBJECTINFOCLASS = 9;
6162
const JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE: DWORD = 0x2000;
63+
const SEM_FAILCRITICALERRORS: UINT = 0x0001;
64+
const SEM_NOGPFAULTERRORBOX: UINT = 0x0002;
6265

6366
extern "system" {
6467
fn CreateJobObjectW(lpJobAttributes: *mut u8, lpName: *const u8) -> HANDLE;
@@ -79,6 +82,7 @@ extern "system" {
7982
JobObjectInformationClass: JOBOBJECTINFOCLASS,
8083
lpJobObjectInformation: LPVOID,
8184
cbJobObjectInformationLength: DWORD) -> BOOL;
85+
fn SetErrorMode(mode: UINT) -> UINT;
8286
}
8387

8488
#[repr(C)]
@@ -115,6 +119,13 @@ struct JOBOBJECT_BASIC_LIMIT_INFORMATION {
115119
}
116120

117121
pub unsafe fn setup() {
122+
// Tell Windows to not show any UI on errors (such as not finding a required dll
123+
// during startup or terminating abnormally). This is important for running tests,
124+
// since some of them use abnormal termination by design.
125+
// This mode is inherited by all child processes.
126+
let mode = SetErrorMode(SEM_NOGPFAULTERRORBOX); // read inherited flags
127+
SetErrorMode(mode | SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
128+
118129
// Create a new job object for us to use
119130
let job = CreateJobObjectW(0 as *mut _, 0 as *const _);
120131
assert!(job != 0 as *mut _, "{}", io::Error::last_os_error());

0 commit comments

Comments
 (0)