- Set default opStack size to 256

- Fix integer wraparound. opStack offset in rbx will always be >= 0
This commit is contained in:
Thilo Schulz 2011-05-16 18:17:01 +00:00
parent 5aa3da2f84
commit c7a68bf283
2 changed files with 15 additions and 13 deletions

View file

@ -22,7 +22,9 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include "q_shared.h" #include "q_shared.h"
#include "qcommon.h" #include "qcommon.h"
#define OPSTACK_SIZE 1024 // don't change, this is hardcoded into x86 VMs, opStack protection relies
// on this
#define OPSTACK_SIZE 256
#define OPSTACK_MASK (OPSTACK_SIZE-1) #define OPSTACK_MASK (OPSTACK_SIZE-1)
// don't change // don't change

View file

@ -70,15 +70,15 @@ static void VM_Destroy_Compiled(vm_t* self);
| |
+- r8 +- r8
eax scratch eax scratch
bl opStack offset rbx/bl opStack offset
ecx scratch (required for shifts) ecx scratch (required for shifts)
edx scratch (required for divisions) edx scratch (required for divisions)
rsi scratch rsi scratch
rdi program frame pointer (programStack) rdi program frame pointer (programStack)
r8 pointer data (vm->dataBase) r8 pointer data (vm->dataBase)
r9 opStack data base (vm->opStack + OPSTACK_SIZE / 2) r9 opStack data base (opStack)
r10 start of generated code r10 start of generated code
*/ */
@ -1080,7 +1080,7 @@ int VM_CallCompiled( vm_t *vm, int *args ) {
opStack = PADP(stack, 4); opStack = PADP(stack, 4);
__asm__ __volatile__ ( __asm__ __volatile__ (
" movq $-0x80,%%rbx \r\n" \ " movq $0x0,%%rbx \r\n" \
" movl %5,%%edi \r\n" \ " movl %5,%%edi \r\n" \
" movq %4,%%r8 \r\n" \ " movq %4,%%r8 \r\n" \
" movq %3,%%r9 \r\n" \ " movq %3,%%r9 \r\n" \
@ -1091,10 +1091,10 @@ int VM_CallCompiled( vm_t *vm, int *args ) {
" movl %%edi, %0 \r\n" \ " movl %%edi, %0 \r\n" \
" movq %%rbx, %1 \r\n" \ " movq %%rbx, %1 \r\n" \
: "=g" (programStack), "=g" (opStackRet) : "=g" (programStack), "=g" (opStackRet)
: "g" (entryPoint), "g" (((intptr_t ) opStack) + OPSTACK_SIZE / 2), "g" (vm->dataBase), "g" (programStack) : "g" (entryPoint), "g" (opStack), "g" (vm->dataBase), "g" (programStack)
: "%rsi", "%rdi", "%rax", "%rbx", "%rcx", "%rdx", "%r8", "%r9", "%r10", "%r15", "%xmm0" : "%rsi", "%rdi", "%rax", "%rbx", "%rcx", "%rdx", "%r8", "%r9", "%r10", "%r15", "%xmm0"
); );
if(opStackRet != -(OPSTACK_SIZE / 2) + 4 || *opStack != 0xDEADBEEF) if(opStackRet != 4 || *opStack != 0xDEADBEEF)
Com_Error(ERR_DROP, "opStack corrupted in compiled code (offset %ld)", opStackRet); Com_Error(ERR_DROP, "opStack corrupted in compiled code (offset %ld)", opStackRet);
if ( programStack != stackOnEntry - 48 ) { if ( programStack != stackOnEntry - 48 ) {