aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Python/pylifecycle.c
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2022-11-10 04:34:57 -0800
committerGitHub <noreply@github.com>2022-11-10 12:34:57 +0000
commit1e197e63e21f77b102ff2601a549dda4b6439455 (patch)
tree5d8524091404607c838bb9a0ea168c8d9c28fd6a /Python/pylifecycle.c
parentdbf2faf579b4094387d65ee41f049456ca67c446 (diff)
downloadcpython-1e197e63e21f77b102ff2601a549dda4b6439455.tar.gz
cpython-1e197e63e21f77b102ff2601a549dda4b6439455.zip
GH-96421: Insert shim frame on entry to interpreter (GH-96319)
* Adds EXIT_INTERPRETER instruction to exit PyEval_EvalDefault() * Simplifies RETURN_VALUE, YIELD_VALUE and RETURN_GENERATOR instructions as they no longer need to check for entry frames.
Diffstat (limited to 'Python/pylifecycle.c')
-rw-r--r--Python/pylifecycle.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c
index 51192bd5bb9..13519762fa8 100644
--- a/Python/pylifecycle.c
+++ b/Python/pylifecycle.c
@@ -29,6 +29,7 @@
#include "pycore_tuple.h" // _PyTuple_InitTypes()
#include "pycore_typeobject.h" // _PyTypes_InitTypes()
#include "pycore_unicodeobject.h" // _PyUnicode_InitTypes()
+#include "opcode.h"
extern void _PyIO_Fini(void);
@@ -779,6 +780,21 @@ pycore_init_types(PyInterpreterState *interp)
return _PyStatus_OK();
}
+static const uint8_t INTERPRETER_TRAMPOLINE_INSTRUCTIONS[] = {
+ /* Put a NOP at the start, so that the IP points into
+ * the code, rather than before it */
+ NOP, 0,
+ INTERPRETER_EXIT, 0,
+ /* RESUME at end makes sure that the frame appears incomplete */
+ RESUME, 0
+};
+
+static const _PyShimCodeDef INTERPRETER_TRAMPOLINE_CODEDEF = {
+ INTERPRETER_TRAMPOLINE_INSTRUCTIONS,
+ sizeof(INTERPRETER_TRAMPOLINE_INSTRUCTIONS),
+ 1,
+ "<interpreter trampoline>"
+};
static PyStatus
pycore_init_builtins(PyThreadState *tstate)
@@ -812,7 +828,10 @@ pycore_init_builtins(PyThreadState *tstate)
PyObject *object__getattribute__ = _PyType_Lookup(&PyBaseObject_Type, &_Py_ID(__getattribute__));
assert(object__getattribute__);
interp->callable_cache.object__getattribute__ = object__getattribute__;
-
+ interp->interpreter_trampoline = _Py_MakeShimCode(&INTERPRETER_TRAMPOLINE_CODEDEF);
+ if (interp->interpreter_trampoline == NULL) {
+ return _PyStatus_ERR("failed to create interpreter trampoline.");
+ }
if (_PyBuiltins_AddExceptions(bimod) < 0) {
return _PyStatus_ERR("failed to add exceptions to builtins");
}