Skip to content
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

gh-125604: Move _Py_AuditHookEntry, etc. Out of pycore_runtime.h #125605

Merged
merged 11 commits into from
Oct 18, 2024

Conversation

ericsnowcurrently
Copy link
Member

@ericsnowcurrently ericsnowcurrently commented Oct 16, 2024

This is essentially a cleanup, moving a handful of API declarations to the header files where they fit best, creating new ones when needed.

We do the following:

  • add pycore_debugger_utils.h and move _Py_DebugOffsets, etc. there
  • inline struct _getargs_runtime_state and struct _gilstate_runtime_state in _PyRuntimeState
  • move struct _reftracer_runtime_state to the existing pycore_object_state.h
  • add pycore_audit.h and move to it _Py_AuditHookEntry , _PySys_Audit(), and _PySys_ClearAuditHooks
  • add audit.h and cpython/audit.h and move the existing audit-related API there
  • move the perfmap/trampoline API from cpython/sysmodule.h to cpython/ceval.h, and remove the now-empty cpython/sysmodule.h

@pablogsal, I'd love to know if you're okay with us moving _Py_DebugOffsets like I have. Would it break anything? Would the separate header be inconvenient for external tools or will it make no difference? Also, do you think the name of the new header is okay?

@zooba, are you okay with us moving all the audit API into the new *audit.h header files like I have?

@ericsnowcurrently
Copy link
Member Author

FYI, I was considering adding in the small GENERATE_DEBUG_SECTION() refactor @1st1 does in gh-124640, putting it in the new pycore_debugger_utils.h, but figured we can do that separately (or keep it in gh-124640.

@pablogsal
Copy link
Member

@pablogsal, I'd love to know if you're okay with us moving _Py_DebugOffsets like I have. Would it break anything? Would the separate header be inconvenient for external tools or will it make no difference? Also, do you think the name of the new header is okay?

I am fine with moving the definition to a separate header, this is also more convenient for tools to copy-paste. :)

FYI, I was considering adding in the small GENERATE_DEBUG_SECTION() refactor @1st1 does in gh-124640, putting it in the new pycore_debugger_utils.h, but figured we can do that separately (or keep it in gh-124640.

I was planning to do this independently if #124640 (I did that change in the PR 😉 ) takes time to land so I will build on top of this.

@ericsnowcurrently
Copy link
Member Author

this is also more convenient for tools to copy-paste. :)

I had a gut feeling something like that was the case. :)

@zooba
Copy link
Member

zooba commented Oct 16, 2024

Provided the audit machinery doesn't gain accessible entry points (which basically means they all exist in the one source unit, via headers is okay), I don't mind where it lives.

If the functions or structure layouts are discoverable at runtime, it makes it much easier to create a bypass. We call an internal-only version of the function so that it's harder to shim it. Just don't make that any more accessible.

@ericsnowcurrently
Copy link
Member Author

I'll merge this tomorrow, unless there are any objections. If this is blocking anyone, feel free to merge it before I get to it.

@@ -0,0 +1,269 @@
#ifndef Py_INTERNAL_DEBUGGER_UTILS_H
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to rename the file pycore_debug_offsets.h instead. "debug utils" is vague.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was going to point out that there are other debugger-related things that would go there, but your suggestion looks very correct to me. 😄 Thanks! I'll change it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ericsnowcurrently ericsnowcurrently merged commit 6d93690 into python:main Oct 18, 2024
57 checks passed
@ericsnowcurrently ericsnowcurrently deleted the debug-offsets branch October 18, 2024 15:30
@Coffigny94

This comment was marked as spam.

@Coffigny94

This comment was marked as spam.

ebonnal pushed a commit to ebonnal/cpython that referenced this pull request Jan 12, 2025
pythongh-125605)

This is essentially a cleanup, moving a handful of API declarations to the header files where they fit best, creating new ones when needed.

We do the following:

* add pycore_debug_offsets.h and move _Py_DebugOffsets, etc. there
* inline struct _getargs_runtime_state and struct _gilstate_runtime_state in _PyRuntimeState
* move struct _reftracer_runtime_state to the existing pycore_object_state.h
* add pycore_audit.h and move to it _Py_AuditHookEntry , _PySys_Audit(), and _PySys_ClearAuditHooks
* add audit.h and cpython/audit.h and move the existing audit-related API there
*move the perfmap/trampoline API from cpython/sysmodule.h to cpython/ceval.h, and remove the now-empty cpython/sysmodule.h
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants