mirror of
https://github.com/python/cpython.git
synced 2026-03-30 16:41:06 +00:00
gh-141976: Check stack bounds in JIT optimizer (GH-142201)
This commit is contained in:
parent
2dac9e6016
commit
b3bf212898
6 changed files with 212 additions and 6 deletions
|
|
@ -144,10 +144,6 @@ incorrect_keys(PyObject *obj, uint32_t version)
|
|||
|
||||
#define CURRENT_FRAME_IS_INIT_SHIM() (ctx->frame->code == ((PyCodeObject *)&_Py_InitCleanup))
|
||||
|
||||
#define WITHIN_STACK_BOUNDS() \
|
||||
(CURRENT_FRAME_IS_INIT_SHIM() || (STACK_LEVEL() >= 0 && STACK_LEVEL() <= STACK_SIZE()))
|
||||
|
||||
|
||||
#define GETLOCAL(idx) ((ctx->frame->locals[idx]))
|
||||
|
||||
#define REPLACE_OP(INST, OP, ARG, OPERAND) \
|
||||
|
|
@ -192,6 +188,27 @@ incorrect_keys(PyObject *obj, uint32_t version)
|
|||
|
||||
#define JUMP_TO_LABEL(label) goto label;
|
||||
|
||||
static int
|
||||
check_stack_bounds(JitOptContext *ctx, JitOptRef *stack_pointer, int offset, int opcode)
|
||||
{
|
||||
int stack_level = (int)(stack_pointer + (offset) - ctx->frame->stack);
|
||||
int should_check = !CURRENT_FRAME_IS_INIT_SHIM() ||
|
||||
(opcode == _RETURN_VALUE) ||
|
||||
(opcode == _RETURN_GENERATOR) ||
|
||||
(opcode == _YIELD_VALUE);
|
||||
if (should_check && (stack_level < 0 || stack_level > STACK_SIZE())) {
|
||||
ctx->contradiction = true;
|
||||
ctx->done = true;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define CHECK_STACK_BOUNDS(offset) \
|
||||
if (check_stack_bounds(ctx, stack_pointer, offset, opcode)) { \
|
||||
break; \
|
||||
} \
|
||||
|
||||
static int
|
||||
optimize_to_bool(
|
||||
_PyUOpInstruction *this_instr,
|
||||
|
|
|
|||
173
Python/optimizer_cases.c.h
generated
173
Python/optimizer_cases.c.h
generated
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue