Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions mono/mini/exceptions-amd64.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@ static MonoW32ExceptionHandler fpe_handler;
static MonoW32ExceptionHandler ill_handler;
static MonoW32ExceptionHandler segv_handler;

static LPTOP_LEVEL_EXCEPTION_FILTER old_handler;
LPTOP_LEVEL_EXCEPTION_FILTER mono_old_win_toplevel_exception_filter;
guint64 mono_win_chained_exception_filter_result;
gboolean mono_win_chained_exception_filter_didrun;

#define W32_SEH_HANDLE_EX(_ex) \
if (_ex##_handler) _ex##_handler(0, er, sctx)
if (_ex##_handler) _ex##_handler(0, ep, sctx)

/*
* Unhandled Exception Filter
Expand All @@ -54,6 +56,7 @@ LONG CALLBACK seh_handler(EXCEPTION_POINTERS* ep)
MonoContext* sctx;
LONG res;

mono_win_chained_exception_filter_didrun = FALSE;
res = EXCEPTION_CONTINUE_EXECUTION;

er = ep->ExceptionRecord;
Expand Down Expand Up @@ -114,17 +117,20 @@ LONG CALLBACK seh_handler(EXCEPTION_POINTERS* ep)

g_free (sctx);

if (mono_win_chained_exception_filter_didrun)
res = mono_win_chained_exception_filter_result;

return res;
}

void win32_seh_init()
{
old_handler = SetUnhandledExceptionFilter(seh_handler);
mono_old_win_toplevel_exception_filter = SetUnhandledExceptionFilter(seh_handler);
}

void win32_seh_cleanup()
{
if (old_handler) SetUnhandledExceptionFilter(old_handler);
if (mono_old_win_toplevel_exception_filter) SetUnhandledExceptionFilter(mono_old_win_toplevel_exception_filter);
}

void win32_seh_set_handler(int type, MonoW32ExceptionHandler handler)
Expand Down
14 changes: 10 additions & 4 deletions mono/mini/exceptions-x86.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,16 @@ static MonoW32ExceptionHandler fpe_handler;
static MonoW32ExceptionHandler ill_handler;
static MonoW32ExceptionHandler segv_handler;

static LPTOP_LEVEL_EXCEPTION_FILTER old_handler;
LPTOP_LEVEL_EXCEPTION_FILTER mono_old_win_toplevel_exception_filter;
guint64 mono_win_chained_exception_filter_result;
gboolean mono_win_chained_exception_filter_didrun;

#ifndef PROCESS_CALLBACK_FILTER_ENABLED
# define PROCESS_CALLBACK_FILTER_ENABLED 1
#endif

#define W32_SEH_HANDLE_EX(_ex) \
if (_ex##_handler) _ex##_handler(0, er, sctx)
if (_ex##_handler) _ex##_handler(0, ep, sctx)

/*
* mono_win32_get_handle_stackoverflow (void):
Expand Down Expand Up @@ -176,6 +178,7 @@ LONG CALLBACK seh_handler(EXCEPTION_POINTERS* ep)
struct sigcontext* sctx;
LONG res;

mono_win_chained_exception_filter_didrun = FALSE;
res = EXCEPTION_CONTINUE_EXECUTION;

er = ep->ExceptionRecord;
Expand Down Expand Up @@ -228,6 +231,9 @@ LONG CALLBACK seh_handler(EXCEPTION_POINTERS* ep)

g_free (sctx);

if (mono_win_chained_exception_filter_didrun)
res = mono_win_chained_exception_filter_result;

return res;
}

Expand All @@ -237,12 +243,12 @@ void win32_seh_init()
if (!restore_stack)
restore_stack = mono_win32_get_handle_stackoverflow ();

old_handler = SetUnhandledExceptionFilter(seh_handler);
mono_old_win_toplevel_exception_filter = SetUnhandledExceptionFilter(seh_handler);
}

void win32_seh_cleanup()
{
if (old_handler) SetUnhandledExceptionFilter(old_handler);
if (mono_old_win_toplevel_exception_filter) SetUnhandledExceptionFilter(mono_old_win_toplevel_exception_filter);
}

void win32_seh_set_handler(int type, MonoW32ExceptionHandler handler)
Expand Down
19 changes: 19 additions & 0 deletions mono/mini/mini-windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@

#include "jit-icalls.h"

extern LPTOP_LEVEL_EXCEPTION_FILTER mono_old_win_toplevel_exception_filter;
extern guint64 mono_win_chained_exception_filter_result;
extern gboolean mono_win_chained_exception_filter_didrun;

void
mono_runtime_install_handlers (void)
{
Expand All @@ -71,9 +75,24 @@ mono_runtime_cleanup_handlers (void)
#endif
}


/* mono_chain_signal:
*
* Call the original signal handler for the signal given by the arguments, which
* should be the same as for a signal handler. Returns TRUE if the original handler
* was called, false otherwise.
*/
gboolean
SIG_HANDLER_SIGNATURE (mono_chain_signal)
{
int signal = _dummy;
GET_CONTEXT;

if (mono_old_win_toplevel_exception_filter) {
mono_win_chained_exception_filter_didrun = TRUE;
mono_win_chained_exception_filter_result = (*mono_old_win_toplevel_exception_filter)(info);
return TRUE;
}
return FALSE;
}

Expand Down
5 changes: 3 additions & 2 deletions mono/mini/mini-x86.c
Original file line number Diff line number Diff line change
Expand Up @@ -6458,7 +6458,8 @@ gboolean
mono_arch_is_single_step_event (void *info, void *sigctx)
{
#ifdef TARGET_WIN32
EXCEPTION_RECORD* einfo = (EXCEPTION_RECORD*)info; /* Sometimes the address is off by 4 */
EXCEPTION_RECORD* einfo = ((EXCEPTION_POINTERS*)info)->ExceptionRecord; /* Sometimes the address is off by 4 */

if ((einfo->ExceptionInformation[1] >= ss_trigger_page && (guint8*)einfo->ExceptionInformation[1] <= (guint8*)ss_trigger_page + 128))
return TRUE;
else
Expand All @@ -6477,7 +6478,7 @@ gboolean
mono_arch_is_breakpoint_event (void *info, void *sigctx)
{
#ifdef TARGET_WIN32
EXCEPTION_RECORD* einfo = (EXCEPTION_RECORD*)info; /* Sometimes the address is off by 4 */
EXCEPTION_RECORD* einfo = ((EXCEPTION_POINTERS*)info)->ExceptionRecord; /* Sometimes the address is off by 4 */
if ((einfo->ExceptionInformation[1] >= bp_trigger_page && (guint8*)einfo->ExceptionInformation[1] <= (guint8*)bp_trigger_page + 128))
return TRUE;
else
Expand Down
3 changes: 2 additions & 1 deletion mono/mini/mini-x86.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
#include <signal.h>
#endif

typedef void (* MonoW32ExceptionHandler) (int _dummy, EXCEPTION_RECORD *info, void *context);
typedef void (* MonoW32ExceptionHandler) (int _dummy, EXCEPTION_POINTERS *info, void *context);

void win32_seh_init(void);
void win32_seh_cleanup(void);
void win32_seh_set_handler(int type, MonoW32ExceptionHandler handler);
Expand Down
2 changes: 1 addition & 1 deletion mono/mini/mini.h
Original file line number Diff line number Diff line change
Expand Up @@ -2416,7 +2416,7 @@ gboolean mono_gdb_render_native_backtraces (void) MONO_INTERNAL;
#define SIG_HANDLER_SIGNATURE(ftn) ftn (int _dummy, siginfo_t *info, void *context)
#define SIG_HANDLER_PARAMS _dummy, info, context
#elif defined(HOST_WIN32)
#define SIG_HANDLER_SIGNATURE(ftn) ftn (int _dummy, EXCEPTION_RECORD *info, void *context)
#define SIG_HANDLER_SIGNATURE(ftn) ftn (int _dummy, EXCEPTION_POINTERS *info, void *context)
#define SIG_HANDLER_PARAMS _dummy, info, context
#elif defined(__HAIKU__)
#define SIG_HANDLER_SIGNATURE(ftn) ftn (int _dummy, void *userData, vregs regs)
Expand Down