8000 gh-133157: remove usage of `_Py_NO_SANITIZE_UNDEFINED` in `faulthandl… · python/cpython@0a160bf · GitHub
[go: up one dir, main page]

Skip to content

Commit 0a160bf

Browse files
authored
gh-133157: remove usage of _Py_NO_SANITIZE_UNDEFINED in faulthandler (#134047)
In `faulthandler_sigfpe()`, instead of using 1/0 arithmetic, we explicitly raise SIGFPE. We also remove `faulthandler._read_null()` since reading from NULL is an undefined behavior and `faulthandler` should not check for low-level C undefined behaviors.
1 parent 22e4a40 commit 0a160bf

File tree

2 files changed

+2
-52
lines changed

2 files changed

+2
-52
lines changed

Lib/test/test_faulthandler.py

-23
Original file line numberDiff line numberDiff line change
@@ -166,29 +166,6 @@ def check_windows_exception(self, code, line_number, name_regex, **kw):
166166
fatal_error = 'Windows fatal exception: %s' % name_regex
167167
self.check_error(code, line_number, fatal_error, **kw)
168168

169-
@unittest.skipIf(sys.platform.startswith('aix'),
170-
"the first page of memory is a mapped read-only on AIX")
171-
def test_read_null(self):
172-
if not MS_WINDOWS:
173-
self.check_fatal_error("""
174-
import faulthandler
175-
faulthandler.enable()
176-
faulthandler._read_null()
177-
""",
178-
3,
179-
# Issue #12700: Read NULL raises SIGILL on Mac OS X Lion
180-
'(?:Segmentation fault'
181-
'|Bus error'
182-
'|Illegal instruction)')
183-
else:
184-
self.check_windows_exception("""
185-
import faulthandler
186-
faulthandler.enable()
187-
faulthandler._read_null()
188-
""",
189-
3,
190-
'access violation')
191-
192169
@skip_segfault_on_android
193170
def test_sigsegv(self):
194171
self.check_fatal_error("""

Modules/faulthandler.c

+2-29
Original file line numberDiff line numberDiff line change
@@ -1069,18 +1069,6 @@ faulthandler_suppress_crash_report(void)
10691069
#endif
10701070
}
10711071

1072-
static PyObject* _Py_NO_SANITIZE_UNDEFINED
1073-
faulthandler_read_null(PyObject *self, PyObject *args)
1074-
{
1075-
volatile int *x;
1076-
volatile int y;
1077-
1078-
faulthandler_suppress_crash_report();
1079-
x = NULL;
1080-
y = *x;
1081-
return PyLong_FromLong(y);
1082-
1083-
}
10841072

10851073
static void
10861074
faulthandler_raise_sigsegv(void)
@@ -1158,23 +1146,12 @@ faulthandler_fatal_error_c_thread(PyObject *self, PyObject *args)
11581146
Py_RETURN_NONE;
11591147
}
11601148

1161-
static PyObject* _Py_NO_SANITIZE_UNDEFINED
1149+
static PyObject*
11621150
faulthandler_sigfpe(PyObject *self, PyObject *Py_UNUSED(dummy))
11631151
{
11641152
faulthandler_suppress_crash_report();
1165-
1166-
/* Do an integer division by zero: raise a SIGFPE on Intel CPU, but not on
1167-
PowerPC. Use volatile to disable compile-time optimizations. */
1168-
volatile int x = 1, y = 0, z;
1169-
z = x / y;
1170-
1171-
/* If the division by zero didn't raise a SIGFPE (e.g. on PowerPC),
1172-
raise it manually. */
11731153
raise(SIGFPE);
1174-
1175-
/* This line is never reached, but we pretend to make something with z
1176-
to silence a compiler warning. */
1177-
return PyLong_FromLong(z);
1154+
Py_UNREACHABLE();
11781155
}
11791156

11801157
static PyObject *
@@ -1316,10 +1293,6 @@ static PyMethodDef module_methods[] = {
13161293
"Unregister the handler of the signal "
13171294
"'signum' registered by register().")},
13181295
#endif
1319-
{"_read_null", faulthandler_read_null, METH_NOARGS,
1320-
PyDoc_STR("_read_null($module, /)\n--\n\n"
1321-
"Read from NULL, raise "
1322-
"a SIGSEGV or SIGBUS signal depending on the platform.")},
13231296
{"_sigsegv", faulthandler_sigsegv, METH_VARARGS,
13241297
PyDoc_STR("_sigsegv($module, release_gil=False, /)\n--\n\n"
13251298
"Raise a SIGSEGV signal.")},

0 commit comments

Comments
 (0)
0