File tree 3 files changed +26
-3
lines changed
3 files changed +26
-3
lines changed Original file line number Diff line number Diff line change @@ -1519,7 +1519,7 @@ extern "C" {
1519
1519
1520
1520
#[ link( name = "llvm-wrapper" , kind = "static" ) ]
1521
1521
extern "C" {
1522
- pub fn LLVMRustInstallFatalErrorHandler ( ) ;
1522
+ pub fn LLVMRustInstallErrorHandlers ( ) ;
1523
1523
pub fn LLVMRustDisableSystemDialogsOnCrash ( ) ;
1524
1524
1525
1525
// Create and destroy contexts.
Original file line number Diff line number Diff line change @@ -49,7 +49,7 @@ unsafe fn configure_llvm(sess: &Session) {
49
49
let mut llvm_c_strs = Vec :: with_capacity ( n_args + 1 ) ;
50
50
let mut llvm_args = Vec :: with_capacity ( n_args + 1 ) ;
51
51
52
- llvm:: LLVMRustInstallFatalErrorHandler ( ) ;
52
+ llvm:: LLVMRustInstallErrorHandlers ( ) ;
53
53
// On Windows, an LLVM assertion will open an Abort/Retry/Ignore dialog
54
54
// box for the purpose of launching a debugger. However, on CI this will
55
55
// cause it to hang until it times out, which can take several hours.
Original file line number Diff line number Diff line change 25
25
26
26
#include < iostream>
27
27
28
+ // for raw `write` in the bad-alloc handler
29
+ #ifdef _MSC_VER
30
+ #include < io.h>
31
+ #else
32
+ #include < unistd.h>
33
+ #endif
34
+
28
35
// ===----------------------------------------------------------------------===
29
36
//
30
37
// This file defines alternate interfaces to core functions that are more
@@ -88,8 +95,24 @@ static void FatalErrorHandler(void *UserData,
88
95
exit (101 );
89
96
}
90
97
91
- extern " C" void LLVMRustInstallFatalErrorHandler () {
98
+ // Custom error handler for bad-alloc LLVM errors.
99
+ //
100
+ // It aborts the process without any further allocations, similar to LLVM's
101
+ // default except that may be configured to `throw std::bad_alloc()` instead.
102
+ static void BadAllocErrorHandler (void *UserData,
103
+ const char * Reason,
104
+ bool GenCrashDiag) {
105
+ const char *OOM = " rustc-LLVM ERROR: out of memory\n " ;
106
+ write (2 , OOM, strlen (OOM));
107
+ write (2 , Reason, strlen (Reason));
108
+ write (2 , " \n " , 1 );
109
+ abort ();
110
+ }
111
+
112
+ extern " C" void LLVMRustInstallErrorHandlers () {
92
113
install_fatal_error_handler (FatalErrorHandler);
114
+ install_bad_alloc_error_handler (BadAllocErrorHandler);
115
+ install_out_of_memory_new_handler ();
93
116
}
94
117
95
118
extern " C" void LLVMRustDisableSystemDialogsOnCrash () {
You can’t perform that action at this time.
0 commit comments