1 #![cfg_attr(test, allow(dead_code))]
9 pub unsafe fn new() -> Handler {
10 // This API isn't available on XP, so don't panic in that case and just
11 // pray it works out ok.
12 if c::SetThreadStackGuarantee(&mut 0x5000) == 0
13 && c::GetLastError() as u32 != c::ERROR_CALL_NOT_IMPLEMENTED as u32
15 panic!("failed to reserve stack space for exception handling");
21 extern "system" fn vectored_handler(ExceptionInfo: *mut c::EXCEPTION_POINTERS) -> c::LONG {
23 let rec = &(*(*ExceptionInfo).ExceptionRecord);
24 let code = rec.ExceptionCode;
26 if code == c::EXCEPTION_STACK_OVERFLOW {
28 "\nthread '{}' has overflowed its stack\n",
29 thread::current().name().unwrap_or("<unknown>")
32 c::EXCEPTION_CONTINUE_SEARCH
36 pub unsafe fn init() {
37 if c::AddVectoredExceptionHandler(0, vectored_handler).is_null() {
38 panic!("failed to install exception handler");
40 // Set the thread stack guarantee for the main thread.
41 let _h = Handler::new();