summary refs log tree commit diff
path: root/src/libstd/sys/windows/stack_overflow.rs
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2015-07-27 13:41:35 -0700
committerAlex Crichton <alex@alexcrichton.com>2015-08-10 16:35:44 -0700
commit7a3fdfbf674a08b7f6fd32c9124e52924a2f9a1c (patch)
tree5553605e8d9ac7fc23cfec8f689f6c923e78abdd /src/libstd/sys/windows/stack_overflow.rs
parentd03456183e85fe7bd465bbe7c8f67885a2528444 (diff)
downloadrust-7a3fdfbf674a08b7f6fd32c9124e52924a2f9a1c.tar.gz
rust-7a3fdfbf674a08b7f6fd32c9124e52924a2f9a1c.zip
Remove morestack support
This commit removes all morestack support from the compiler which entails:

* Segmented stacks are no longer emitted in codegen.
* We no longer build or distribute libmorestack.a
* The `stack_exhausted` lang item is no longer required

The only current use of the segmented stack support in LLVM is to detect stack
overflow. This is no longer really required, however, because we already have
guard pages for all threads and registered signal handlers watching for a
segfault on those pages (to print out a stack overflow message). Additionally,
major platforms (aka Windows) already don't use morestack.

This means that Rust is by default less likely to catch stack overflows because
if a function takes up more than one page of stack space it won't hit the guard
page. This is what the purpose of morestack was (to catch this case), but it's
better served with stack probes which have more cross platform support and no
runtime support necessary. Until LLVM supports this for all platform it looks
like morestack isn't really buying us much.

cc #16012 (still need stack probes)
Closes #26458 (a drive-by fix to help diagnostics on stack overflow)
Diffstat (limited to 'src/libstd/sys/windows/stack_overflow.rs')
-rw-r--r--src/libstd/sys/windows/stack_overflow.rs102
1 files changed, 19 insertions, 83 deletions
diff --git a/src/libstd/sys/windows/stack_overflow.rs b/src/libstd/sys/windows/stack_overflow.rs
index bc8ee6619f1..f93f7c756de 100644
--- a/src/libstd/sys/windows/stack_overflow.rs
+++ b/src/libstd/sys/windows/stack_overflow.rs
@@ -8,108 +8,44 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-#[cfg(stage0)]
-use core::prelude::v1::*;
-
-use libc::types::os::arch::extra::{LPVOID, DWORD, LONG};
-use libc;
-use mem;
-use ptr;
+use libc::{self, LONG};
 use rt::util::report_overflow;
 use sys::c;
-use sys_common::stack;
 
-pub struct Handler {
-    _data: *mut libc::c_void
-}
+pub struct Handler;
 
 impl Handler {
     pub unsafe fn new() -> Handler {
-        make_handler()
+        // This API isn't available on XP, so don't panic in that case and just
+        // pray it works out ok.
+        if c::SetThreadStackGuarantee(&mut 0x5000) == 0 {
+            if libc::GetLastError() as u32 != libc::ERROR_CALL_NOT_IMPLEMENTED as u32 {
+                panic!("failed to reserve stack space for exception handling");
+            }
+        }
+        Handler
     }
 }
 
-impl Drop for Handler {
-    fn drop(&mut self) {}
-}
-
-// This is initialized in init() and only read from after
-static mut PAGE_SIZE: usize = 0;
-
-#[no_stack_check]
-extern "system" fn vectored_handler(ExceptionInfo: *mut EXCEPTION_POINTERS) -> LONG {
+extern "system" fn vectored_handler(ExceptionInfo: *mut c::EXCEPTION_POINTERS)
+                                    -> LONG {
     unsafe {
         let rec = &(*(*ExceptionInfo).ExceptionRecord);
         let code = rec.ExceptionCode;
 
-        if code != EXCEPTION_STACK_OVERFLOW {
-            return EXCEPTION_CONTINUE_SEARCH;
+        if code == c::EXCEPTION_STACK_OVERFLOW {
+            report_overflow();
         }
-
-        // We're calling into functions with stack checks,
-        // however stack checks by limit should be disabled on Windows
-        stack::record_sp_limit(0);
-
-        report_overflow();
-
-        EXCEPTION_CONTINUE_SEARCH
+        c::EXCEPTION_CONTINUE_SEARCH
     }
 }
 
 pub unsafe fn init() {
-    let mut info = mem::zeroed();
-    libc::GetSystemInfo(&mut info);
-    PAGE_SIZE = info.dwPageSize as usize;
-
-    if AddVectoredExceptionHandler(0, vectored_handler) == ptr::null_mut() {
+    if c::AddVectoredExceptionHandler(0, vectored_handler).is_null() {
         panic!("failed to install exception handler");
     }
-
-    mem::forget(make_handler());
-}
-
-pub unsafe fn cleanup() {
-}
-
-pub unsafe fn make_handler() -> Handler {
-    // This API isn't available on XP, so don't panic in that case and just pray
-    // it works out ok.
-    if c::SetThreadStackGuarantee(&mut 0x5000) == 0 {
-        if libc::GetLastError() as u32 != libc::ERROR_CALL_NOT_IMPLEMENTED as u32 {
-            panic!("failed to reserve stack space for exception handling");
-        }
-    }
-
-    Handler { _data: 0 as *mut libc::c_void }
-}
-
-#[repr(C)]
-pub struct EXCEPTION_RECORD {
-    pub ExceptionCode: DWORD,
-    pub ExceptionFlags: DWORD,
-    pub ExceptionRecord: *mut EXCEPTION_RECORD,
-    pub ExceptionAddress: LPVOID,
-    pub NumberParameters: DWORD,
-    pub ExceptionInformation: [LPVOID; EXCEPTION_MAXIMUM_PARAMETERS]
+    // Set the thread stack guarantee for the main thread.
+    let _h = Handler::new();
 }
 
-#[repr(C)]
-pub struct EXCEPTION_POINTERS {
-    pub ExceptionRecord: *mut EXCEPTION_RECORD,
-    pub ContextRecord: LPVOID
-}
-
-pub type PVECTORED_EXCEPTION_HANDLER = extern "system"
-        fn(ExceptionInfo: *mut EXCEPTION_POINTERS) -> LONG;
-
-pub type ULONG = libc::c_ulong;
-
-const EXCEPTION_CONTINUE_SEARCH: LONG = 0;
-const EXCEPTION_MAXIMUM_PARAMETERS: usize = 15;
-const EXCEPTION_STACK_OVERFLOW: DWORD = 0xc00000fd;
-
-extern "system" {
-    fn AddVectoredExceptionHandler(FirstHandler: ULONG,
-                                   VectoredHandler: PVECTORED_EXCEPTION_HANDLER)
-                                  -> LPVOID;
-}
+pub unsafe fn cleanup() {}