From 75ae9119e6af3301e0f16c53f11e11739cc167ea Mon Sep 17 00:00:00 2001 From: Zack Middleton Date: Fri, 19 Nov 2021 13:45:35 -0500 Subject: [PATCH] Fix passing arguments to VM dylib on Apple M1 The engine function pointer to vmMain used variadic arguments but the vmMain function in the dylib has explicit arguments. Evidently the arguments are stored on the stack and/or registers differently. Found by fretn. --- code/qcommon/qcommon.h | 4 +++- code/qcommon/vm_local.h | 2 +- code/sys/sys_main.c | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/code/qcommon/qcommon.h b/code/qcommon/qcommon.h index bd490382..137fa43d 100644 --- a/code/qcommon/qcommon.h +++ b/code/qcommon/qcommon.h @@ -355,6 +355,8 @@ typedef enum { TRAP_TESTPRINTFLOAT } sharedTraps_t; +typedef intptr_t (QDECL *vmMainProc)(int callNum, int arg0, int arg1, int arg2, int arg3, int arg4, int arg5, int arg6, int arg7, int arg8, int arg9, int arg10, int arg11); + void VM_Init( void ); vm_t *VM_Create( const char *module, intptr_t (*systemCalls)(intptr_t *), vmInterpret_t interpret ); @@ -1080,7 +1082,7 @@ NON-PORTABLE SYSTEM SERVICES void Sys_Init (void); // general development dll loading for virtual machine testing -void * QDECL Sys_LoadGameDll( const char *name, intptr_t (QDECL **entryPoint)(int, ...), +void * QDECL Sys_LoadGameDll( const char *name, vmMainProc *entryPoint, intptr_t (QDECL *systemcalls)(intptr_t, ...) ); void Sys_UnloadDll( void *dllHandle ); diff --git a/code/qcommon/vm_local.h b/code/qcommon/vm_local.h index 07e89675..f649cf81 100644 --- a/code/qcommon/vm_local.h +++ b/code/qcommon/vm_local.h @@ -154,7 +154,7 @@ struct vm_s { // for dynamic linked modules void *dllHandle; - intptr_t (QDECL *entryPoint)( int callNum, ... ); + vmMainProc entryPoint; void (*destroy)(vm_t* self); // for interpreted modules diff --git a/code/sys/sys_main.c b/code/sys/sys_main.c index 40b07e5d..ae46c705 100644 --- a/code/sys/sys_main.c +++ b/code/sys/sys_main.c @@ -579,7 +579,7 @@ Used to load a development dll instead of a virtual machine ================= */ void *Sys_LoadGameDll(const char *name, - intptr_t (QDECL **entryPoint)(int, ...), + vmMainProc *entryPoint, intptr_t (*systemcalls)(intptr_t, ...)) { void *libHandle;