Fix aligned memalloc crash when compiled with LTCG

Crash occurred as the arguments to the alloc/free callbacks would involve the 'this' pointer, and therefore, the registers would shift and misalign. The fix is to just make the functions static and call the pointers directly from the singleton exposed by the engine. Additional cleanup has been performed by adding typedefs for the function pointers.
This commit is contained in:
Kawe Mazidjatari 2023-07-09 20:03:57 +02:00
parent a90302f09f
commit 248efc114b
2 changed files with 9 additions and 6 deletions

View File

@ -7,12 +7,15 @@
class CAlignedMemAlloc
{
public:
void* Alloc(size_t nSize, size_t nAlignment = 0);
void Free(void* pMem);
static void* Alloc(size_t nSize, size_t nAlignment = 0);
static void Free(void* pMem);
private:
void* m_pAllocCallback;
void* m_pFreeCallback;
typedef void* (*FnAlloc_t)(size_t nSize, size_t nAlignment);
typedef void (*FnFree_t)(void* pMem);
FnAlloc_t m_pAllocCallback;
FnFree_t m_pFreeCallback;
};
extern CAlignedMemAlloc* g_pAlignedMemAlloc;

View File

@ -13,7 +13,7 @@
//-----------------------------------------------------------------------------
void* CAlignedMemAlloc::Alloc(size_t nSize, size_t nAlignment)
{
return ((void* (*)(size_t, size_t))m_pAllocCallback)(nSize, nAlignment);
return g_pAlignedMemAlloc->m_pAllocCallback(nSize, nAlignment);
}
//-----------------------------------------------------------------------------
@ -22,7 +22,7 @@ void* CAlignedMemAlloc::Alloc(size_t nSize, size_t nAlignment)
//-----------------------------------------------------------------------------
void CAlignedMemAlloc::Free(void* pMem)
{
((void (*)(void*))m_pFreeCallback)(pMem);
g_pAlignedMemAlloc->m_pFreeCallback(pMem);
}
CAlignedMemAlloc* g_pAlignedMemAlloc;