Skip to content

Commit

Permalink
Fix return values in nested system calls from QVMs
Browse files Browse the repository at this point in the history
When the engine is compiled with Clang it appears that the return value
is being written to the WRONG address, either due to the vm_ variables being
changed (unexpectedly) elsewhere, or as a result of bad assembly assumptions;
having a stack variable pointing to where to write the return value seems
to do the trick.

This fixes the case where, for a trap_Register()-like call, weird numbers
are being returned when, during the process, an error message is printed
(which in Tremulous results in a QVM call and (nested) system call).
  • Loading branch information
/dev/humancontroller authored and zturtleman committed Mar 24, 2015
1 parent 33efe82 commit 1ce8ba0
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions code/qcommon/vm_x86.c
Expand Up @@ -412,23 +412,24 @@ static void DoSyscall(void)

if(vm_syscallNum < 0)
{
int *data;
int *data, *ret;
#if idx64
int index;
intptr_t args[MAX_VMSYSCALL_ARGS];
#endif

data = (int *) (savedVM->dataBase + vm_programStack + 4);
ret = &vm_opStackBase[vm_opStackOfs + 1];

#if idx64
args[0] = ~vm_syscallNum;
for(index = 1; index < ARRAY_LEN(args); index++)
args[index] = data[index];

vm_opStackBase[vm_opStackOfs + 1] = savedVM->systemCall(args);
*ret = savedVM->systemCall(args);
#else
data[0] = ~vm_syscallNum;
vm_opStackBase[vm_opStackOfs + 1] = savedVM->systemCall((intptr_t *) data);
*ret = savedVM->systemCall((intptr_t *) data);
#endif
}
else
Expand Down

0 comments on commit 1ce8ba0

Please sign in to comment.