8000 bpo-32280: Store `_PyRuntime` in a named section by maxbelanger · Pull Request #4802 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-32280: Store _PyRuntime in a named section #4802

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 1 commit into from
Jun 3, 2021
Merged
Changes from all commits
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
bpo-32280: Store _PyRuntime in a named section
  • Loading branch information
pablogsal committed Jun 3, 2021
commit ffcd44cff5486265edae6f2f25d6043c4302a0be
30 changes: 28 additions & 2 deletions Python/pylifecycle.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -34,7 +38,6 @@
(PyObject_TypeCheck((op), &PyWindowsConsoleIO_Type))
#endif


#define PUTS(fd, str) _Py_write_noraise(fd, str, (int)strlen(str))


Expand All @@ -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
Expand Down
0