about summary refs log tree commit diff
path: root/src/libstd/sys/windows
diff options
context:
space:
mode:
authorAmanieu d'Antras <amanieu@gmail.com>2016-01-09 18:20:33 +0000
committerAmanieu d'Antras <amanieu@gmail.com>2016-01-12 01:55:45 +0000
commit757f57bb1eef755474cbb71945ed6370890dd936 (patch)
tree0ea5fcaf8b512548c82b027c387ce820bd593712 /src/libstd/sys/windows
parentd70ab2bdf16c22b9f3ff0230089b44855e3f1593 (diff)
downloadrust-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.rs22
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 {