diff options
| author | Amanieu d'Antras <amanieu@gmail.com> | 2016-01-09 18:20:33 +0000 |
|---|---|---|
| committer | Amanieu d'Antras <amanieu@gmail.com> | 2016-01-12 01:55:45 +0000 |
| commit | 757f57bb1eef755474cbb71945ed6370890dd936 (patch) | |
| tree | 0ea5fcaf8b512548c82b027c387ce820bd593712 /src/libstd/sys/windows | |
| parent | d70ab2bdf16c22b9f3ff0230089b44855e3f1593 (diff) | |
| download | rust-757f57bb1eef755474cbb71945ed6370890dd936.tar.gz rust-757f57bb1eef755474cbb71945ed6370890dd936.zip | |
Add set_oom_handler and use it print a message when out of memory
Diffstat (limited to 'src/libstd/sys/windows')
| -rw-r--r-- | src/libstd/sys/windows/mod.rs | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/src/libstd/sys/windows/mod.rs b/src/libstd/sys/windows/mod.rs index 7e5342a3fd4..7e4db3d89a3 100644 --- a/src/libstd/sys/windows/mod.rs +++ b/src/libstd/sys/windows/mod.rs @@ -20,6 +20,7 @@ use num::Zero; use os::windows::ffi::{OsStrExt, OsStringExt}; use path::PathBuf; use time::Duration; +use alloc::oom; #[macro_use] pub mod compat; @@ -42,7 +43,26 @@ pub mod thread_local; pub mod time; pub mod stdio; -pub fn init() {} +// See comment in sys/unix/mod.rs +fn oom_handler() -> ! { + use intrinsics; + use ptr; + let msg = "fatal runtime error: out of memory\n"; + unsafe { + // WriteFile silently fails if it is passed an invalid handle, so there + // is no need to check the result of GetStdHandle. + c::WriteFile(c::GetStdHandle(c::STD_ERROR_HANDLE), + msg.as_ptr() as c::LPVOID, + msg.len() as DWORD, + ptr::null_mut(), + ptr::null_mut()); + intrinsics::abort(); + } +} + +pub fn init() { + oom::set_oom_handler(oom_handler); +} pub fn decode_error_kind(errno: i32) -> ErrorKind { match errno as c::DWORD { |
