From f08f1ef0d646fd46f02f8b30fb269a30a8425c05 Mon Sep 17 00:00:00 2001 From: Kit o' Rifty Date: Sun, 5 May 2024 14:17:59 -0700 Subject: [PATCH] Fix passing variant_t parameters + fix codegen stack on Win64 (#2117) * Fix 64-bit JIT not allocating stack space for params on stack Fix wrong cond check for passing objects by value * Fix wrong FireOutput detour proto on win64 --- extensions/bintools/jit_call_x64.cpp | 10 +++++++++- extensions/sdktools/output.cpp | 2 +- extensions/sdktools/outputnatives.cpp | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/extensions/bintools/jit_call_x64.cpp b/extensions/bintools/jit_call_x64.cpp index a867aa2b..d4044980 100644 --- a/extensions/bintools/jit_call_x64.cpp +++ b/extensions/bintools/jit_call_x64.cpp @@ -787,7 +787,7 @@ inline void Write_PushObject(JitWriter *jit, const SourceHook::PassInfo *info, u return; #elif defined PLATFORM_WINDOWS - if (info->size < 64 && (info->size & (info->size - 1)) == 0) + if (info->size > 8 || (info->size & (info->size - 1)) != 0) goto push_byref; else { SourceHook::PassInfo podInfo; @@ -1055,7 +1055,11 @@ void *JIT_CallCompile(CallWrapper *pWrapper, FuncAddrMethod method) int numWords; #endif +#ifdef PLATFORM_POSIX g_StackUsage = 0; +#elif defined PLATFORM_WINDOWS + g_StackUsage = 32; // Shadow space +#endif writer.outbase = NULL; writer.outptr = NULL; @@ -1155,8 +1159,12 @@ skip_retbuffer: #endif /* Clean up the calling stack */ +#ifdef PLATFORM_POSIX if (hasParams && g_StackUsage) +#endif + { Write_RectifyStack(jit, g_StackAlign); + } /* Copy the return type to the return buffer if the function is not void */ if (pRet && !Needs_Retbuf) diff --git a/extensions/sdktools/output.cpp b/extensions/sdktools/output.cpp index 25e44dbc..0daee969 100644 --- a/extensions/sdktools/output.cpp +++ b/extensions/sdktools/output.cpp @@ -73,7 +73,7 @@ bool EntityOutputManager::IsEnabled() return enabled; } -#ifdef PLATFORM_WINDOWS +#if defined PLATFORM_WINDOWS && defined PLATFORM_X86 DETOUR_DECL_MEMBER8(FireOutput, void, int, what, int, the, int, hell, int, msvc, void *, variant_t, CBaseEntity *, pActivator, CBaseEntity *, pCaller, float, fDelay) { bool fireOutput = g_OutputManager.FireEventDetour((void *)this, pActivator, pCaller, fDelay); diff --git a/extensions/sdktools/outputnatives.cpp b/extensions/sdktools/outputnatives.cpp index 823cdfc2..fb16deed 100644 --- a/extensions/sdktools/outputnatives.cpp +++ b/extensions/sdktools/outputnatives.cpp @@ -311,7 +311,7 @@ static cell_t FireEntityOutput(IPluginContext *pContext, const cell_t *params) { return pContext->ThrowNativeError("\"FireEntityOutput\" not supported by this mod"); } -#ifdef PLATFORM_WINDOWS +#if defined PLATFORM_WINDOWS && defined PLATFORM_X86 int iMaxParam = 8; //Instead of being one param, MSVC broke variant_t param into 5 params.. PassInfo pass[8];