Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-99377: Add audit events for thread creation and clear#99378

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
zooba merged 6 commits intopython:mainfromzooba:gh-99377
Nov 16, 2022
Merged
Show file tree
Hide file tree
Changes from1 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
PrevPrevious commit
NextNext commit
Tries raising the event from a different place, and adds id
  • Loading branch information
@zooba
zooba committedNov 15, 2022
commit9d69a0e774708908af03adb3aa65e99c9fd1047d
17 changes: 9 additions & 8 deletionsDoc/c-api/init.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1239,23 +1239,24 @@ All of the following functions must be called after :c:func:`Py_Initialize`.
The global interpreter lock need not be held, but may be held if it is
necessary to serialize calls to this function.

.. audit-event:: cpython.PyThreadState_New"" c.PyThreadState_New
.. audit-event:: cpython.PyThreadState_Newid c.PyThreadState_New

Raise an auditing event ``cpython.PyThreadState_New`` with no arguments.
The event will be raised from the creating thread, not the new thread.
Raise an auditing event ``cpython.PyThreadState_New`` with Python's thread
id as the argument. The event will be raised from the thread creating the new
``PyThreadState``, which may not be the new thread.


.. c:function:: void PyThreadState_Clear(PyThreadState *tstate)

Reset all information in a thread state object. The global interpreter lock
must be held.

.. audit-event:: cpython.PyThreadState_Clear"" c.PyThreadState_Clear
.. audit-event:: cpython.PyThreadState_Clearid c.PyThreadState_Clear

Raise an auditing event ``cpython.PyThreadState_Clear`` withno arguments.
The event may be raised from a different thread than the one being
cleared. Exceptions raised from a hook will be treated as unraisable and
will not abort the operation.
Raise an auditing event ``cpython.PyThreadState_Clear`` withPython's
thread id as the argument.The event may be raised from a different thread
than the one beingcleared. Exceptions raised from a hook will be treated
as unraisable andwill not abort the operation.

.. versionchanged:: 3.9
This function now calls the :c:member:`PyThreadState.on_delete` callback.
Expand Down
22 changes: 15 additions & 7 deletionsPython/pystate.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -821,11 +821,6 @@ new_threadstate(PyInterpreterState *interp)
PyThreadState *tstate;
_PyRuntimeState *runtime = interp->runtime;

PyThreadState *ts = _PyThreadState_GET();
if (ts && _PySys_Audit(ts, "cpython.PyThreadState_New", NULL) < 0) {
return NULL;
}

// We don't need to allocate a thread state for the main interpreter
// (the common case), but doing it later for the other case revealed a
// reentrancy problem (deadlock). So for now we always allocate before
Expand DownExpand Up@@ -883,14 +878,27 @@ PyThreadState_New(PyInterpreterState *interp)
PyThreadState *tstate = new_threadstate(interp);
if (tstate) {
_PyThreadState_SetCurrent(tstate);
if (PySys_Audit("cpython.PyThreadState_New", "K", tstate->id) < 0) {
PyThreadState_Clear(tstate);
_PyThreadState_DeleteCurrent(tstate);
return NULL;
}
}
return tstate;
}

PyThreadState *
_PyThreadState_Prealloc(PyInterpreterState *interp)
{
return new_threadstate(interp);
PyThreadState *tstate = new_threadstate(interp);
if (tstate) {
if (PySys_Audit("cpython.PyThreadState_New", "K", tstate->id) < 0) {
PyThreadState_Clear(tstate);
_PyThreadState_DeleteCurrent(tstate);
return NULL;
}
}
return tstate;
}

// We keep this around for (accidental) stable ABI compatibility.
Expand DownExpand Up@@ -1038,7 +1046,7 @@ _PyInterpreterState_ClearModules(PyInterpreterState *interp)
void
PyThreadState_Clear(PyThreadState *tstate)
{
if (PySys_Audit("cpython.PyThreadState_Clear",NULL) < 0) {
if (PySys_Audit("cpython.PyThreadState_Clear","K", tstate->id) < 0) {
PyErr_WriteUnraisable(NULL);
}

Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp