This commit is contained in:
rtldg 2025-03-07 14:47:30 +00:00
parent 5ece3fa663
commit 78129d665a
7 changed files with 31 additions and 11 deletions

View File

@ -193,7 +193,7 @@ public:
virtual void** GetStackArgumentPtr(CRegisters* pRegisters) = 0;
/*
Returns the number of bytes for the buffer to store all the arguments that are passed in a register in.
Returns the number of bytes for the buffer to store all the arguments that are passed in a register.
*/
virtual int GetArgRegisterSize() = 0;

View File

@ -62,7 +62,6 @@ public:
virtual void RestoreCallArguments(CRegisters* pRegisters) override;
protected:
std::uint32_t m_stackArgs;
};
#endif // _X86_64_SYSTEMV_DEFAULT_H

View File

@ -259,7 +259,7 @@ ICallingConvention *ConstructCallingConvention(HookSetup *setup)
#if defined(DYNAMICHOOKS_x86_64) && defined(PLATFORM_LINUX)
if (setup->returnType == ReturnType_Vector) {
returnType.size = 16;
returnType.size = 12;
returnType.custom_register = XMM0;
returnType.custom_register2 = XMM1;
}
@ -704,6 +704,7 @@ void CDynamicHooksSourcePawn::UpdateParamsFromStruct(HookParamsStruct *params)
size_t numArgs = argTypes.size();
size_t firstArg = 0;
// TODO: Linux64 will use RDI for retmem even if thiscall
// TODO: Support custom register for this ptr.
if (callConv == CallConv_THISCALL)
firstArg = 1;

View File

@ -291,6 +291,7 @@ cell_t Native_AddParam(IPluginContext *pContext, const cell_t *params)
info.flags = PASSFLAG_BYVAL;
}
// TODO: why?
// DynamicDetours doesn't expose the passflags concept like SourceHook.
// See if we're trying to set some invalid flags on detour arguments.
if(setup->hookMethod == Detour && (info.flags & ~PASSFLAG_BYVAL) > 0)

View File

@ -37,7 +37,7 @@ void * GetObjectAddr(HookParamType type, unsigned int flags, void **params, size
if (type == HookParamType_Object)
return (void *)((intptr_t)params + offset);
#elif POSIX
if (type == HookParamType_Object && !(flags & PASSFLAG_ODTOR)) //Objects are passed by rrefrence if they contain destructors.
if (type == HookParamType_Object && !(flags & PASSFLAG_ODTOR)) //Objects are passed by reference if they contain destructors.
return (void *)((intptr_t)params + offset);
#endif
return *(void **)((intptr_t)params + offset);
@ -62,7 +62,7 @@ size_t GetStackParamOffset(HookParamsStruct *paramStruct, unsigned int index)
continue;
}
#endif
#ifdef KE_ARCH_X64
#if defined(KE_ARCH_X64) && defined(WIN64)
offset += 8;
#else
offset += paramStruct->dg->params[i].size;

View File

@ -54,6 +54,7 @@ using namespace sp;
#ifdef KE_ARCH_X64
using namespace SourceHook::Asm;
#ifdef WIN32
SourceHook::Asm::x64JitWriter* GenerateThunk(HookSetup* hook)
{
auto masm = new x64JitWriter();
@ -130,6 +131,28 @@ SourceHook::Asm::x64JitWriter* GenerateThunk(HookSetup* hook)
masm->SetRE();
return masm;
}
#else
// linux64 thunker
SourceHook::Asm::x64JitWriter* GenerateThunk(HookSetup* hook)
{
auto masm = new x64JitWriter();
auto type = hook->returnType;
// Save our frame pointer.
// This also realigns the stack to 16 bytes.
masm->push(rbp);
masm->mov(rbp, rsp);
// Restore RSP and RBP
// (same as `mov rsp, rbp` + `pop rbp`)
masm->leave();
masm->retn();
masm->SetRE();
return masm;
}
#endif
#elif !defined( WIN32 )
void *GenerateThunk(HookSetup* hook)
{
@ -317,6 +340,7 @@ SourceHook::PassInfo::PassType GetParamTypePassType(HookParamType type)
size_t GetStackArgsSize(DHooksCallback *dg)
{
size_t res = GetParamsSize(dg);
#if defined(WIN32) || !defined(KE_ARCH_X64) // linux64 shall not pass
#ifdef WIN32
if(dg->returnType == ReturnType_Vector)//Account for result vector ptr.
#else
@ -325,6 +349,7 @@ size_t GetStackArgsSize(DHooksCallback *dg)
{
res += OBJECT_OFFSET;
}
#endif
return res;
}

View File

@ -133,12 +133,6 @@ struct ParamInfo
Register_t custom_register;
};
#ifdef WIN32
#define OBJECT_OFFSET sizeof(void *)
#else
#define OBJECT_OFFSET (sizeof(void *)*2)
#endif
class HookReturnStruct
{
public: