diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2021-07-29 15:20:58 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-29 15:20:58 (GMT) |
commit | ebba286709bdb9401df8e5eb196b50008d3b09d2 (patch) | |
tree | b380eb43a0814089c966436909ee0b29fa2380f3 /Python/pylifecycle.c | |
parent | d20f1095a6a51ee8f41ef445a009d26256e1fa61 (diff) | |
download | cpython-ebba286709bdb9401df8e5eb196b50008d3b09d2.zip cpython-ebba286709bdb9401df8e5eb196b50008d3b09d2.tar.gz cpython-ebba286709bdb9401df8e5eb196b50008d3b09d2.tar.bz2 |
bpo-32280: Store _PyRuntime in a named section (GH-4802) (#27448)
This commit stores the _PyRuntime structure in a section of the same name. This allows a debugging or crash reporting tool to quickly locate this structure at runtime without requiring the symbol table.
Co-authored-by: Pablo Galindo <pablogsal@gmail.com>
(cherry picked from commit 35002aa8f62dda1f79035e9904abdf476683e9be)
Co-authored-by: Max Bélanger <aeromax@gmail.com>
Co-authored-by: Max Bélanger <aeromax@gmail.com>
Diffstat (limited to 'Python/pylifecycle.c')
-rw-r--r-- | Python/pylifecycle.c | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index 2dbebe4..d31a9c1 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -17,6 +17,10 @@ #include <locale.h> // setlocale() +#if defined(__APPLE__) +#include <mach-o/loader.h> +#endif + #ifdef HAVE_SIGNAL_H # include <signal.h> // SIG_IGN #endif @@ -34,7 +38,6 @@ (PyObject_TypeCheck((op), &PyWindowsConsoleIO_Type)) #endif - #define PUTS(fd, str) _Py_write_noraise(fd, str, (int)strlen(str)) @@ -59,7 +62,30 @@ static void wait_for_thread_shutdown(PyThreadState *tstate); static void call_ll_exitfuncs(_PyRuntimeState *runtime); int _Py_UnhandledKeyboardInterrupt = 0; -_PyRuntimeState _PyRuntime = _PyRuntimeState_INIT; + +/* The following places the `_PyRuntime` structure in a location that can be + * found without any external information. This is meant to ease access to the + * interpreter state for various runtime debugging tools, but is *not* an + * officially supported feature */ + +#if defined(MS_WINDOWS) + +#pragma section("PyRuntime", read, write) +__declspec(allocate("PyRuntime")) + +#elif defined(__APPLE__) + +__attribute__(( + section(SEG_DATA ",PyRuntime") +)) + +#endif + +_PyRuntimeState _PyRuntime +#if defined(__linux__) && (defined(__GNUC__) || defined(__clang__)) +__attribute__ ((section (".PyRuntime"))) +#endif += _PyRuntimeState_INIT; static int runtime_initialized = 0; PyStatus |