mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-03-21 09:51:41 +00:00
[gamecode] Save and restore data stack in call stack
This fixes the issue of the data stack not being restored properly because the returning function needs to return a value from its local variables (stored on the stack) and accessing stack data below the stack pointer is a bad idea (sure, no interrupts yet, but who knows...).
This commit is contained in:
parent
8e5c2c6534
commit
213434b705
2 changed files with 8 additions and 0 deletions
|
@ -1802,6 +1802,7 @@ typedef struct strref_s strref_t;
|
|||
|
||||
typedef struct {
|
||||
pr_uint_t staddr; ///< Return statement.
|
||||
pr_uint_t stack_ptr; ///< data stack on entry to function
|
||||
bfunction_t *func; ///< Calling function.
|
||||
strref_t *tstr; ///< Linked list of temporary strings.
|
||||
} prstack_t;
|
||||
|
|
|
@ -143,6 +143,9 @@ PR_PushFrame (progs_t *pr)
|
|||
frame = pr->pr_stack + pr->pr_depth++;
|
||||
|
||||
frame->staddr = pr->pr_xstatement;
|
||||
if (pr->globals.stack) {
|
||||
frame->stack_ptr = *pr->globals.stack;
|
||||
}
|
||||
frame->func = pr->pr_xfunction;
|
||||
frame->tstr = pr->pr_xtstr;
|
||||
|
||||
|
@ -179,6 +182,10 @@ PR_PopFrame (progs_t *pr)
|
|||
pr->pr_xfunction = frame->func;
|
||||
pr->pr_xstatement = frame->staddr;
|
||||
pr->pr_xtstr = frame->tstr;
|
||||
// restore data stack (discard any locals)
|
||||
if (pr->globals.stack) {
|
||||
*pr->globals.stack = frame->stack_ptr;
|
||||
}
|
||||
}
|
||||
|
||||
static __attribute__((pure)) long
|
||||
|
|
Loading…
Reference in a new issue