[gamecode] Initialize .stack if it's available

And implement bounds checks for adjstk.
This commit is contained in:
Bill Currie 2022-01-21 20:33:15 +09:00
parent 9199a0ee54
commit 7a5ee6a55a
2 changed files with 19 additions and 5 deletions

View file

@ -1897,6 +1897,21 @@ pr_stack_pop (progs_t *pr)
return stk;
}
static void
pr_stack_adjust (progs_t *pr, int mode, int offset)
{
// keep the stack 16-byte aligned
if (mode || (offset & 3)) {
PR_RunError (pr, "invalid stack adjustment: %d, %d", mode, offset);
}
pr_ptr_t stack = *pr->globals.stack;
if (pr_boundscheck->int_val) {
check_stack_pointer (pr, stack + offset, 0);
}
*pr->globals.stack = stack + offset;
}
static void
pr_with (progs_t *pr, const dstatement_t *st)
{
@ -2769,11 +2784,7 @@ pr_exec_ruamoko (progs_t *pr, int exitdepth)
case OP_NOP:
break;
case OP_ADJSTK:
if (st->a || (st->b & 3)) {
PR_RunError (pr, "invalid stack adjustment: %d, %d",
st->a, (short) st->b);
}
*pr->globals.stack += (short) st->b;
pr_stack_adjust (pr, st->a, (short) st->b);
break;
case OP_LDCONST:
PR_RunError (pr, "OP_LDCONST not implemented");

View file

@ -226,6 +226,9 @@ PR_LoadProgsFile (progs_t *pr, QFile *file, int size)
pr->stack_bottom = pr->stack - pr->pr_globals;
pr->globals_size = (pr_type_t *) ((byte *) pr->stack + pr->stack_size)
- pr->pr_globals;
if (pr->globals.stack && pr->stack_bottom) {
*pr->globals.stack = pr->globals_size;
}
if (pr->zone) {
PR_Zone_Init (pr);