8000 gh-111178: fix UBSan failures for `Python/legacy_tracing.c` by picnixz · Pull Request #131611 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-111178: fix UBSan failures for Python/legacy_tracing.c #131611

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 7 commits into from
Mar 24, 2025
Merged
Changes from 1 commit
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
Next Next commit
fix UBSan failures for legacy_tracing.c
  • Loading branch information
picnixz committed Mar 20, 2025
commit 77b2576e88d3dfb9fb11fff684a65526c68e3ca8
47 changes: 27 additions & 20 deletions Python/legacy_tracing.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ typedef struct _PyLegacyEventHandler {
int event;
} _PyLegacyEventHandler;

#define _PyLegacyEventHandler_CAST(op) ((_PyLegacyEventHandler *)(op))

#ifdef Py_GIL_DISABLED
#define LOCK_SETUP() PyMutex_Lock(&_PyRuntime.ceval.sys_trace_profile_mutex);
#define UNLOCK_SETUP() PyMutex_Unlock(&_PyRuntime.ceval.sys_trace_profile_mutex);
Expand Down Expand Up @@ -54,51 +56,56 @@ call_profile_func(_PyLegacyEventHandler *self, PyObject *arg)

static PyObject *
sys_profile_start(
_PyLegacyEventHandler *self, PyObject *const *args,
PyObject *op, PyObject *const *args,
size_t nargsf, PyObject *kwnames
) {
assert(kwnames == NULL);
assert(PyVectorcall_NARGS(nargsf) == 2);
_PyLegacyEventHandler *self = _PyLegacyEventHandler_CAST(op);
return call_profile_func(self, Py_None);
}

static PyObject *
sys_profile_throw(
_PyLegacyEventHandler *self, PyObject *const *args,
PyObject *op, PyObject *const *args,
size_t nargsf, PyObject *kwnames
) {
assert(kwnames == NULL);
assert(PyVectorcall_NARGS(nargsf) == 3);
_PyLegacyEventHandler *self = _PyLegacyEventHandler_CAST(op);
return call_profile_func(self, Py_None);
}

static PyObject *
sys_profile_return(
_PyLegacyEventHandler *self, PyObject *const *args,
PyObject *op, PyObject *const *args,
size_t nargsf, PyObject *kwnames
) {
assert(kwnames == NULL);
assert(PyVectorcall_NARGS(nargsf) == 3);
_PyLegacyEventHandler *self = _PyLegacyEventHandler_CAST(op);
return call_profile_func(self, args[2]);
}

static PyObject *
sys_profile_unwind(
_PyLegacyEventHandler *self, PyObject *const *args,
PyObject *op, PyObject *const *args,
size_t nargsf, PyObject *kwnames
) {
assert(kwnames == NULL);
assert(PyVectorcall_NARGS(nargsf) == 3);
return call_profile_func(self, NULL);
_PyLegacyEventHandler *self = _PyLegacyEventHandler_CAST(op);
return call_profile_func(self, NULL);
}

static PyObject *
sys_profile_call_or_return(
_PyLegacyEventHandler *self, PyObject *const *args,
PyObject *op, PyObject *const *args,
size_t nargsf, PyObject *kwnames
) {
assert(kwnames == NULL);
assert(PyVectorcall_NARGS(nargsf) == 4);
_PyLegacyEventHandler *self = _PyLegacyEventHandler_CAST(op);
PyObject *callable = args[2];
if (PyCFunction_Check(callable)) {
return call_profile_func(self, callable);
Expand Down Expand Up @@ -428,38 +435,38 @@ setup_profile(PyThreadState *tstate, Py_tracefunc func, PyObject *arg, PyObject
if (!tstate->interp->sys_profile_initialized) {
tstate->interp->sys_profile_initialized = true;
if (set_callbacks(PY_MONITORING_SYS_PROFILE_ID,
(vectorcallfunc)sys_profile_start, PyTrace_CALL,
PY_MONITORING_EVENT_PY_START, PY_MONITORING_EVENT_PY_RESUME)) {
sys_profile_start, PyTrace_CALL,
PY_MONITORING_EVENT_PY_START, PY_MONITORING_EVENT_PY_RESUME)) {
return -1;
}
if (set_callbacks(PY_MONITORING_SYS_PROFILE_ID,
(vectorcallfunc)sys_profile_throw, PyTrace_CALL,
PY_MONITORING_EVENT_PY_THROW, -1)) {
sys_profile_throw, PyTrace_CALL,
PY_MONITORING_EVENT_PY_THROW, -1)) {
return -1;
}
if (set_callbacks(PY_MONITORING_SYS_PROFILE_ID,
(vectorcallfunc)sys_profile_return, PyTrace_RETURN,
PY_MONITORING_EVENT_PY_RETURN, PY_MONITORING_EVENT_PY_YIELD)) {
sys_profile_return, PyTrace_RETURN,
PY_MONITORING_EVENT_PY_RETURN, PY_MONITORING_EVENT_PY_YIELD)) {
return -1;
}
if (set_callbacks(PY_MONITORING_SYS_PROFILE_ID,
(vectorcallfunc)sys_profile_unwind, PyTrace_RETURN,
PY_MONITORING_EVENT_PY_UNWIND, -1)) {
sys_profile_unwind, PyTrace_RETURN,
PY_MONITORING_EVENT_PY_UNWIND, -1)) {
return -1;
}
if (set_callbacks(PY_MONITORING_SYS_PROFILE_ID,
(vectorcallfunc)sys_profile_call_or_return, PyTrace_C_CALL,
PY_MONITORING_EVENT_CALL, -1)) {
sys_profile_call_or_return, PyTrace_C_CALL,
PY_MONITORING_EVENT_CALL, -1)) {
return -1;
}
if (set_callbacks(PY_MONITORING_SYS_PROFILE_ID,
(vectorcallfunc)sys_profile_call_or_return, PyTrace_C_RETURN,
PY_MONITORING_EVENT_C_RETURN, -1)) {
sys_profile_call_or_return, PyTrace_C_RETURN,
PY_MONITORING_EVENT_C_RETURN, -1)) {
return -1;
}
if (set_callbacks(PY_MONITORING_SYS_PROFILE_ID,
(vectorcallfunc)sys_profile_call_or_return, PyTrace_C_EXCEPTION,
PY_MONITORING_EVENT_C_RAISE, -1)) {
sys_profile_call_or_return, PyTrace_C_EXCEPTION,
PY_MONITORING_EVENT_C_RAISE, -1)) {
return -1;
}
}
Expand Down
0