Skip to content

Commit 33217d2

Browse files
authored
bpo-31701: faulthandler: ignore MSC and COM Windows exception (#3929) (#4416)
(cherry picked from commit 6e3d6b5)
1 parent f35076a commit 33217d2

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
@@ -755,6 +755,22 @@ def test_raise_exception(self):
755755
3,
756756
name)
757757

758+
@unittest.skipUnless(MS_WINDOWS, 'specific to Windows')
759+
def test_ignore_exception(self):
760+
for exc_code in (
761+
0xE06D7363, # MSC exception ("Emsc")
762+
0xE0434352, # COM Callable Runtime exception ("ECCR")
763+
):
764+
code = f"""
765+
import faulthandler
766+
faulthandler.enable()
767+
faulthandler._raise_exception({exc_code})
768+
"""
769+
code = dedent(code)
770+
output, exitcode = self.get_output(code)
771+
self.assertEqual(output, [])
772+
self.assertEqual(exitcode, exc_code)
773+
758774
@unittest.skipUnless(MS_WINDOWS, 'specific to Windows')
759775
def test_raise_nonfatal_exception(self):
760776
# 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
@@ -366,16 +366,32 @@ faulthandler_fatal_error(int signum)
366366
}
367367

368368
#ifdef MS_WINDOWS
369+
static int
370+
faulthandler_ignore_exception(DWORD code)
371+
{
372+
/* bpo-30557: ignore exceptions which are not errors */
373+
if (!(code & 0x80000000)) {
374+
return 1;
375+
}
376+
/* bpo-31701: ignore MSC and COM exceptions
377+
E0000000 + code */
378+
if (code == 0xE06D7363 /* MSC exception ("Emsc") */
379+
|| code == 0xE0434352 /* COM Callable Runtime exception ("ECCR") */) {
380+
return 1;
381+
}
382+
/* Interesting exception: log it with the Python traceback */
383+
return 0;
384+
}
385+
369386
static LONG WINAPI
370387
faulthandler_exc_handler(struct _EXCEPTION_POINTERS *exc_info)
371388
{
372389
const int fd = fatal_error.fd;
373390
DWORD code = exc_info->ExceptionRecord->ExceptionCode;
374391
DWORD flags = exc_info->ExceptionRecord->ExceptionFlags;
375392

376-
/* bpo-30557: only log fatal exceptions */
377-
if (!(code & 0x80000000)) {
378-
/* call the next exception handler */
393+
if (faulthandler_ignore_exception(code)) {
394+
/* ignore the exception: call the next exception handler */
379395
return EXCEPTION_CONTINUE_SEARCH;
380396
}
381397

0 commit comments

Comments
 (0)