Skip to content

Commit 6e3d6b5

Browse files
authored
bpo-31701: faulthandler: ignore MSC and COM Windows exception (#3929)
bpo-31701: On Windows, faulthandler.enable() now ignores MSC and COM exceptions.
1 parent c0cabc2 commit 6e3d6b5

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

Lib/test/test_faulthandler.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,22 @@ def test_raise_exception(self):
748748
3,
749749
name)
750750

751+
@unittest.skipUnless(MS_WINDOWS, 'specific to Windows')
752+
def test_ignore_exception(self):
753+
for exc_code in (
754+
0xE06D7363, # MSC exception ("Emsc")
755+
0xE0434352, # COM Callable Runtime exception ("ECCR")
756+
):
757+
code = f"""
758+
import faulthandler
759+
faulthandler.enable()
760+
faulthandler._raise_exception({exc_code})
761+
"""
762+
code = dedent(code)
763+
output, exitcode = self.get_output(code)
764+
self.assertEqual(output, [])
765+
self.assertEqual(exitcode, exc_code)
766+
751767
@unittest.skipUnless(MS_WINDOWS, 'specific to Windows')
752768
def test_raise_nonfatal_exception(self):
753769
# These exceptions are not strictly errors. Letting
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
On Windows, faulthandler.enable() now ignores MSC and COM exceptions.

Modules/faulthandler.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -360,16 +360,32 @@ faulthandler_fatal_error(int signum)
360360
}
361361

362362
#ifdef MS_WINDOWS
363+
static int
364+
faulthandler_ignore_exception(DWORD code)
365+
{
366+
/* bpo-30557: ignore exceptions which are not errors */
367+
if (!(code & 0x80000000)) {
368+
return 1;
369+
}
370+
/* bpo-31701: ignore MSC and COM exceptions
371+
E0000000 + code */
372+
if (code == 0xE06D7363 /* MSC exception ("Emsc") */
373+
|| code == 0xE0434352 /* COM Callable Runtime exception ("ECCR") */) {
374+
return 1;
375+
}
376+
/* Interesting exception: log it with the Python traceback */
377+
return 0;
378+
}
379+
363380
static LONG WINAPI
364381
faulthandler_exc_handler(struct _EXCEPTION_POINTERS *exc_info)
365382
{
366383
const int fd = fatal_error.fd;
367384
DWORD code = exc_info->ExceptionRecord->ExceptionCode;
368385
DWORD flags = exc_info->ExceptionRecord->ExceptionFlags;
369386

370-
/* bpo-30557: only log fatal exceptions */
371-
if (!(code & 0x80000000)) {
372-
/* call the next exception handler */
387+
if (faulthandler_ignore_exception(code)) {
388+
/* ignore the exception: call the next exception handler */
373389
return EXCEPTION_CONTINUE_SEARCH;
374390
}
375391

0 commit comments

Comments
 (0)