From cc161225bd4ddf271a8c4fbc8bbe6ea3e7729f00 Mon Sep 17 00:00:00 2001 From: Vadim Chugunov Date: Wed, 7 Dec 2016 15:50:48 -0800 Subject: [PATCH 1/2] Prevent Windows from displaying UI on errors. --- src/bootstrap/job.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/bootstrap/job.rs b/src/bootstrap/job.rs index b4d7aff97da6..b030538e9792 100644 --- a/src/bootstrap/job.rs +++ b/src/bootstrap/job.rs @@ -51,6 +51,7 @@ type JOBOBJECTINFOCLASS = i32; type SIZE_T = usize; type LARGE_INTEGER = i64; +type UINT = u32; type ULONG_PTR = usize; type ULONGLONG = u64; @@ -59,6 +60,8 @@ const PROCESS_DUP_HANDLE: DWORD = 0x40; const JobObjectExtendedLimitInformation: JOBOBJECTINFOCLASS = 9; const JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE: DWORD = 0x2000; +const SEM_FAILCRITICALERRORS: UINT = 0x0001; +const SEM_NOGPFAULTERRORBOX: UINT = 0x0002; extern "system" { fn CreateJobObjectW(lpJobAttributes: *mut u8, lpName: *const u8) -> HANDLE; @@ -79,6 +82,7 @@ fn SetInformationJobObject(hJob: HANDLE, JobObjectInformationClass: JOBOBJECTINFOCLASS, lpJobObjectInformation: LPVOID, cbJobObjectInformationLength: DWORD) -> BOOL; + fn SetErrorMode(mode: UINT) -> UINT; } #[repr(C)] @@ -115,6 +119,12 @@ struct JOBOBJECT_BASIC_LIMIT_INFORMATION { } pub unsafe fn setup() { + // Tell Windows to not show any UI on errors (such as not finding a required dll + // during startup or terminating abnormally). This is important for running tests, + // since some of them use abnormal termination by design. + // This mode is inherited by all child processes. + SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX); + // Create a new job object for us to use let job = CreateJobObjectW(0 as *mut _, 0 as *const _); assert!(job != 0 as *mut _, "{}", io::Error::last_os_error()); From 6404143d8a36c9076cac89b3c386051b130f54c1 Mon Sep 17 00:00:00 2001 From: Vadim Chugunov Date: Wed, 7 Dec 2016 18:05:20 -0800 Subject: [PATCH 2/2] Preserve inherited mode flags. --- src/bootstrap/job.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/bootstrap/job.rs b/src/bootstrap/job.rs index b030538e9792..c3859275e6fb 100644 --- a/src/bootstrap/job.rs +++ b/src/bootstrap/job.rs @@ -123,7 +123,8 @@ pub unsafe fn setup() { // during startup or terminating abnormally). This is important for running tests, // since some of them use abnormal termination by design. // This mode is inherited by all child processes. - SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX); + let mode = SetErrorMode(SEM_NOGPFAULTERRORBOX); // read inherited flags + SetErrorMode(mode | SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX); // Create a new job object for us to use let job = CreateJobObjectW(0 as *mut _, 0 as *const _);