Skip to content

Commit 7befb46

Browse files
authored
[3.14] gh-151278: Fix test_faulthandler on UBSan (#151279) (#151282)
gh-151278: Fix test_faulthandler on UBSan (#151279) * Py_FatalError() no longer calls _PyFaulthandler_Fini() if it doesn't hold the GIL. * Skip test_faulthandler tests raising signals if run with UBSan. * Enable test_faulthandler in GitHub Action "Reusable Sanitizer". (cherry picked from commit e60c42d)
1 parent bc75e47 commit 7befb46

2 files changed

Lines changed: 12 additions & 5 deletions

File tree

Lib/test/test_faulthandler.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@
3333
CURRENT_THREAD_HEADER = fr'{CURRENT_THREAD_ID} \(most recent call first\):'
3434

3535

36+
def skip_if_sanitizer_signal(signame):
37+
return support.skip_if_sanitizer(f"TSAN/UBSan itercepts {signame}",
38+
thread=True, ub=True)
39+
40+
3641
def expected_traceback(lineno1, lineno2, header, min_count=1):
3742
regex = header
3843
regex += ' File "<string>", line %s in func\n' % lineno1
@@ -247,7 +252,7 @@ def test_fatal_error_c_thread(self):
247252
func='faulthandler_fatal_error_thread',
248253
py_fatal_error=True)
249254

250-
@support.skip_if_sanitizer("TSAN itercepts SIGABRT", thread=True)
255+
@skip_if_sanitizer_signal("SIGABRT")
251256
def test_sigabrt(self):
252257
self.check_fatal_error("""
253258
import faulthandler
@@ -259,7 +264,7 @@ def test_sigabrt(self):
259264

260265
@unittest.skipIf(sys.platform == 'win32',
261266
"SIGFPE cannot be caught on Windows")
262-
@support.skip_if_sanitizer("TSAN itercepts SIGFPE", thread=True)
267+
@skip_if_sanitizer_signal("SIGFPE")
263268
def test_sigfpe(self):
264269
self.check_fatal_error("""
265270
import faulthandler
@@ -271,7 +276,7 @@ def test_sigfpe(self):
271276

272277
@unittest.skipIf(_testcapi is None, 'need _testcapi')
273278
@unittest.skipUnless(hasattr(signal, 'SIGBUS'), 'need signal.SIGBUS')
274-
@support.skip_if_sanitizer("TSAN itercepts SIGBUS", thread=True)
279+
@skip_if_sanitizer_signal("SIGBUS")
275280
@skip_segfault_on_android
276281
def test_sigbus(self):
277282
self.check_fatal_error("""
@@ -286,7 +291,7 @@ def test_sigbus(self):
286291

287292
@unittest.skipIf(_testcapi is None, 'need _testcapi')
288293
@unittest.skipUnless(hasattr(signal, 'SIGILL'), 'need signal.SIGILL')
289-
@support.skip_if_sanitizer("TSAN itercepts SIGILL", thread=True)
294+
@skip_if_sanitizer_signal("SIGILL")
290295
@skip_segfault_on_android
291296
def test_sigill(self):
292297
self.check_fatal_error("""

Python/pylifecycle.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3362,7 +3362,9 @@ fatal_error(int fd, int header, const char *prefix, const char *msg,
33623362
This function already did its best to display a traceback.
33633363
Disable faulthandler to prevent writing a second traceback
33643364
on abort(). */
3365-
_PyFaulthandler_Fini();
3365+
if (has_tstate_and_gil) {
3366+
_PyFaulthandler_Fini();
3367+
}
33663368

33673369
/* Check if the current Python thread hold the GIL */
33683370
if (has_tstate_and_gil) {

0 commit comments

Comments
 (0)