[3.14] gh-136870: fix data races in instrumentation of bytecode (GH-136994) (#137082)

Co-authored-by: Kumar Aditya <kumaraditya@python.org>
Co-authored-by: Zachary Ware <zach@python.org>
This commit is contained in:
Miss Islington (bot) 2025-07-28 21:39:44 +02:00 committed by GitHub
parent 47a2109c1a
commit 909a534cb2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 13 additions and 8 deletions

View file

@ -1190,9 +1190,10 @@ call_instrumentation_vector(
break;
}
else {
LOCK_CODE(code);
PyInterpreterState *interp = tstate->interp;
_PyEval_StopTheWorld(interp);
remove_tools(code, offset, event, 1 << tool);
UNLOCK_CODE();
_PyEval_StartTheWorld(interp);
}
}
}
@ -1381,9 +1382,10 @@ _Py_call_instrumentation_line(PyThreadState *tstate, _PyInterpreterFrame* frame,
}
else {
/* DISABLE */
LOCK_CODE(code);
PyInterpreterState *interp = tstate->interp;
_PyEval_StopTheWorld(interp);
remove_line_tools(code, i, 1 << tool);
UNLOCK_CODE();
_PyEval_StartTheWorld(interp);
}
} while (tools);
Py_DECREF(line_obj);
@ -1438,9 +1440,10 @@ _Py_call_instrumentation_instruction(PyThreadState *tstate, _PyInterpreterFrame*
}
else {
/* DISABLE */
LOCK_CODE(code);
PyInterpreterState *interp = tstate->interp;
_PyEval_StopTheWorld(interp);
remove_per_instruction_tools(code, offset, 1 << tool);
UNLOCK_CODE();
_PyEval_StartTheWorld(interp);
}
}
Py_DECREF(offset_obj);
@ -2995,9 +2998,10 @@ branch_handler_vectorcall(
// Orphaned NOT_TAKEN -- Jump removed by the compiler
return res;
}
LOCK_CODE(code);
PyInterpreterState *interp = _PyInterpreterState_GET();
_PyEval_StopTheWorld(interp);
remove_tools(code, offset, other_event, 1 << self->tool_id);
UNLOCK_CODE();
_PyEval_StartTheWorld(interp);
}
return res;
}