summaryrefslogtreecommitdiff
path: root/rts
diff options
context:
space:
mode:
authorTamar Christina <tamar@zhox.com>2018-12-31 22:49:49 +0000
committerMarge Bot <ben+marge-bot@smart-cactus.org>2019-03-19 23:10:23 -0400
commitd94ca74f2c083c86be1799bf1534db078ab611a6 (patch)
tree0e8b7c096d3057eb1938bdfed603f1e15124603f /rts
parent71648c35ad243396433d017da9ce18bea603d1ce (diff)
downloadhaskell-d94ca74f2c083c86be1799bf1534db078ab611a6.tar.gz
err: clean up error handler
Diffstat (limited to 'rts')
-rw-r--r--rts/win32/veh_excn.c49
1 files changed, 30 insertions, 19 deletions
diff --git a/rts/win32/veh_excn.c b/rts/win32/veh_excn.c
index 2d9de52199..b86abe64b0 100644
--- a/rts/win32/veh_excn.c
+++ b/rts/win32/veh_excn.c
@@ -92,14 +92,9 @@
// Registered exception handler
PVOID __hs_handle = NULL;
LPTOP_LEVEL_EXCEPTION_FILTER oldTopFilter = NULL;
-bool crash_dump = false;
-bool filter_called = false;
long WINAPI __hs_exception_handler(struct _EXCEPTION_POINTERS *exception_data)
{
- if (!crash_dump && filter_called)
- return EXCEPTION_CONTINUE_EXECUTION;
-
long action = EXCEPTION_CONTINUE_SEARCH;
int exit_code = EXIT_FAILURE;
ULONG_PTR what;
@@ -107,7 +102,9 @@ long WINAPI __hs_exception_handler(struct _EXCEPTION_POINTERS *exception_data)
// When the system unwinds the VEH stack after having handled an excn,
// return immediately.
- if ((exception_data->ExceptionRecord->ExceptionFlags & EH_UNWINDING) == 0)
+ if (exception_data
+ && exception_data->ExceptionRecord
+ && (exception_data->ExceptionRecord->ExceptionFlags & EH_UNWINDING) ==0)
{
// Error handling cases covered by this implementation.
switch (exception_data->ExceptionRecord->ExceptionCode) {
@@ -122,20 +119,31 @@ long WINAPI __hs_exception_handler(struct _EXCEPTION_POINTERS *exception_data)
action = EXCEPTION_CONTINUE_EXECUTION;
break;
case EXCEPTION_ACCESS_VIOLATION:
- what = exception_data->ExceptionRecord->ExceptionInformation[0];
- fprintf(stderr, "Access violation in generated code"
- " when %s 0x%" PRIxPTR "\n"
- , what == 0 ? "reading"
- : what == 1 ? "writing"
- : what == 8 ? "executing data at"
- : "?"
- , (uintptr_t) exception_data
- ->ExceptionRecord
- ->ExceptionInformation[1]
+ {
+ if (exception_data->ExceptionRecord->NumberParameters < 2)
+ {
+ fprintf(stderr, "Access violation in generated code. "
+ "Empty exception record.");
+ }
+ else
+ {
+ what = exception_data->ExceptionRecord
+ ->ExceptionInformation[0];
+ fprintf(stderr, "Access violation in generated code"
+ " when %s 0x%" PRIxPTR "\n"
+ , what == 0 ? "reading"
+ : what == 1 ? "writing"
+ : what == 8 ? "executing data at"
+ : "?"
+ , (uintptr_t) exception_data
+ ->ExceptionRecord
+ ->ExceptionInformation[1]
);
+ }
action = EXCEPTION_CONTINUE_EXECUTION;
exit_code = SIGSEGV;
break;
+ }
default:;
}
@@ -154,19 +162,22 @@ long WINAPI __hs_exception_handler(struct _EXCEPTION_POINTERS *exception_data)
return action;
}
+/* Registered top level exception filter. We're not very interested in handling
+ the error here, that's why we have __hs_exception_handler, but we do want
+ to register the fact that the filter was called. This allows us to prevent
+ continuing to run when the exception was completely unhandled.
+ EXCEPTION_CONTINUE_EXECUTION is returned so that the OS gives the VEH
+ handlers a chance to run. */
long WINAPI __hs_exception_filter(struct _EXCEPTION_POINTERS *exception_data)
{
- filter_called = true;
long result = EXCEPTION_CONTINUE_EXECUTION;
if (oldTopFilter)
{
result = (*oldTopFilter)(exception_data);
if (EXCEPTION_CONTINUE_SEARCH == result)
result = EXCEPTION_CONTINUE_EXECUTION;
- return result;
}
- crash_dump = true;
return result;
}