Skip to content

Commit e95c5f0

Browse files
jonchamUnityAlex
authored andcommitted
Fix abort behavior on Windows
We statically link the C runtime on Windows and abort handlers are part of the C runtime. This means that Unity's abort handler is not connected to the C runtime in Mono, and when an abort happens we get the default behavior instead of proper chaining/handling to our bug reporter. RaiseException and SEH is process wide. Use RaiseException to force crash instead of abort.
1 parent 74e3a74 commit e95c5f0

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

mono/eglib/goutput.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
#include <stdlib.h>
3232
#include <glib.h>
3333

34+
#ifdef G_OS_WIN32
35+
#include <windows.h>
36+
#endif
37+
3438
/* The current fatal levels, error is always fatal */
3539
static GLogLevelFlags fatal = G_LOG_LEVEL_ERROR;
3640
static GLogFunc default_log_func;
@@ -376,7 +380,11 @@ g_log_default_handler (const gchar *log_domain, GLogLevelFlags log_level, const
376380
if (log_level & fatal) {
377381
fflush (stdout);
378382
fflush (stderr);
383+
#ifdef G_OS_WIN32
384+
RaiseException (0xE0000001, EXCEPTION_NONCONTINUABLE, 0, NULL);
385+
#else
379386
g_assert_abort ();
387+
#endif
380388
}
381389
}
382390

mono/utils/mono-log-common.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <sys/time.h>
2626
#else
2727
#include <process.h>
28+
#include <Windows.h>
2829
#endif
2930
#include "mono-logger-internals.h"
3031
#include "mono-proclib.h"
@@ -132,8 +133,13 @@ mono_log_write_logfile (const char *log_domain, GLogLevelFlags level, mono_bool
132133

133134
fflush(logFile);
134135

135-
if (level & G_LOG_LEVEL_ERROR)
136+
if (level & G_LOG_LEVEL_ERROR) {
137+
#ifdef HOST_WIN32
138+
RaiseException (0xE0000001, EXCEPTION_NONCONTINUABLE, 0, NULL);
139+
#else
136140
g_assert_abort ();
141+
#endif
142+
}
137143
}
138144

139145
/**

0 commit comments

Comments
 (0)