Skip to content

bpo-31701: faulthandler: ignore MSC and COM Windows exception #3929

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 9, 2017
Merged
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
16 changes: 16 additions & 0 deletions Lib/test/test_faulthandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,22 @@ def test_raise_exception(self):
3,
name)

@unittest.skipUnless(MS_WINDOWS, 'specific to Windows')
def test_ignore_exception(self):
for exc_code in (
0xE06D7363, # MSC exception ("Emsc")
0xE0434352, # COM Callable Runtime exception ("ECCR")
):
code = f"""
import faulthandler
faulthandler.enable()
faulthandler._raise_exception({exc_code})
"""
code = dedent(code)
output, exitcode = self.get_output(code)
self.assertEqual(output, [])
self.assertEqual(exitcode, exc_code)

@unittest.skipUnless(MS_WINDOWS, 'specific to Windows')
def test_raise_nonfatal_exception(self):
# These exceptions are not strictly errors. Letting
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
On Windows, faulthandler.enable() now ignores MSC and COM exceptions.
22 changes: 19 additions & 3 deletions Modules/faulthandler.c
Original file line number Diff line number Diff line change
Expand Up @@ -360,16 +360,32 @@ faulthandler_fatal_error(int signum)
}

#ifdef MS_WINDOWS
static int
faulthandler_ignore_exception(DWORD code)
{
/* bpo-30557: ignore exceptions which are not errors */
if (!(code & 0x80000000)) {
return 1;
}
/* bpo-31701: ignore MSC and COM exceptions
E0000000 + code */
if (code == 0xE06D7363 /* MSC exception ("Emsc") */
|| code == 0xE0434352 /* COM Callable Runtime exception ("ECCR") */) {
return 1;
}
/* Interesting exception: log it with the Python traceback */
return 0;
}

static LONG WINAPI
faulthandler_exc_handler(struct _EXCEPTION_POINTERS *exc_info)
{
const int fd = fatal_error.fd;
DWORD code = exc_info->ExceptionRecord->ExceptionCode;
DWORD flags = exc_info->ExceptionRecord->ExceptionFlags;

/* bpo-30557: only log fatal exceptions */
if (!(code & 0x80000000)) {
/* call the next exception handler */
if (faulthandler_ignore_exception(code)) {
/* ignore the exception: call the next exception handler */
return EXCEPTION_CONTINUE_SEARCH;
}

Expand Down