Skip to content

Commit cc16122

Browse files
committed
Prevent Windows from displaying UI on errors.
1 parent 7846610 commit cc16122

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/bootstrap/job.rs

Lines changed: 10 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,12 @@ 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+
SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
127+
118128
// Create a new job object for us to use
119129
let job = CreateJobObjectW(0 as *mut _, 0 as *const _);
120130
assert!(job != 0 as *mut _, "{}", io::Error::last_os_error());

0 commit comments

Comments
 (0)