From cc9a74a21878192c095fef01b87554cc932eed9e Mon Sep 17 00:00:00 2001 From: Ludwig Nussel Date: Sun, 1 Nov 2009 19:58:03 +0000 Subject: [PATCH] Define stack sizes at central place also reverts bug 4282 as stack is included in bss already so nothing that needs fixing --- code/qcommon/vm.c | 8 ++------ code/qcommon/vm_interpreted.c | 6 ++---- code/qcommon/vm_local.h | 9 ++++++++- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/code/qcommon/vm.c b/code/qcommon/vm.c index 82c08139..c420f814 100644 --- a/code/qcommon/vm.c +++ b/code/qcommon/vm.c @@ -357,8 +357,6 @@ intptr_t QDECL VM_DllSyscall( intptr_t arg, ... ) { } -#define STACK_SIZE 0x20000 - /* ================= VM_LoadQVM @@ -427,7 +425,7 @@ vmHeader_t *VM_LoadQVM( vm_t *vm, qboolean alloc ) { // round up to next power of 2 so all data operations can // be mask protected dataLength = header.h->dataLength + header.h->litLength + - header.h->bssLength + STACK_SIZE; + header.h->bssLength; for ( i = 0 ; dataLength > ( 1 << i ) ; i++ ) { } dataLength = 1 << i; @@ -606,7 +604,7 @@ vm_t *VM_Create( const char *module, intptr_t (*systemCalls)(intptr_t *), // the stack is implicitly at the end of the image vm->programStack = vm->dataMask + 1; - vm->stackBottom = vm->programStack - STACK_SIZE; + vm->stackBottom = vm->programStack - PROGRAM_STACK_SIZE; Com_Printf("%s loaded in %d bytes on the hunk\n", module, remaining - Hunk_MemoryRemaining()); @@ -730,8 +728,6 @@ an OP_ENTER instruction, which will subtract space for locals from sp ============== */ -#define MAX_STACK 256 -#define STACK_MASK (MAX_STACK-1) intptr_t QDECL VM_Call( vm_t *vm, int callnum, ... ) { vm_t *oldVM; diff --git a/code/qcommon/vm_interpreted.c b/code/qcommon/vm_interpreted.c index d348ee6b..a4690aa0 100644 --- a/code/qcommon/vm_interpreted.c +++ b/code/qcommon/vm_interpreted.c @@ -311,13 +311,11 @@ an OP_ENTER instruction, which will subtract space for locals from sp ============== */ -#define MAX_STACK 256 -#define STACK_MASK (MAX_STACK-1) #define DEBUGSTR va("%s%i", VM_Indent(vm), opStack-stack ) int VM_CallInterpreted( vm_t *vm, int *args ) { - int stack[MAX_STACK]; + int stack[OPSTACK_SIZE]; int *opStack; int programCounter; int programStack; @@ -392,7 +390,7 @@ nextInstruction2: if ( opStack < stack ) { Com_Error( ERR_DROP, "VM opStack underflow" ); } - if ( opStack >= stack+MAX_STACK ) { + if ( opStack >= stack+OPSTACK_SIZE ) { Com_Error( ERR_DROP, "VM opStack overflow" ); } diff --git a/code/qcommon/vm_local.h b/code/qcommon/vm_local.h index d7e3f419..df60ac51 100644 --- a/code/qcommon/vm_local.h +++ b/code/qcommon/vm_local.h @@ -22,6 +22,14 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include "q_shared.h" #include "qcommon.h" +#define OPSTACK_SIZE 256 +#define OPSTACK_MASK (OPSTACK_SIZE-1) + +// don't change +// Hardcoded in q3asm an reserved at end of bss +#define PROGRAM_STACK_SIZE 0x10000 +#define PROGRAM_STACK_MASK (PROGRAM_STACK_SIZE-1) + typedef enum { OP_UNDEF, @@ -180,4 +188,3 @@ vmSymbol_t *VM_ValueToFunctionSymbol( vm_t *vm, int value ); int VM_SymbolToValue( vm_t *vm, const char *symbol ); const char *VM_ValueToSymbol( vm_t *vm, int value ); void VM_LogSyscalls( int *args ); -