1 #![cfg_attr(test, allow(dead_code))]
4 use crate::sys_common::util::report_overflow;
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 if c::GetLastError() as u32 != c::ERROR_CALL_NOT_IMPLEMENTED as u32 {
14 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 {
29 c::EXCEPTION_CONTINUE_SEARCH
33 pub unsafe fn init() {
34 if c::AddVectoredExceptionHandler(0, vectored_handler).is_null() {
35 panic!("failed to install exception handler");
37 // Set the thread stack guarantee for the main thread.
38 let _h = Handler::new();