Fully disable memory expansion

The game's memalloc does not support memory expansion, the base expansion function couldn't be shadowed properly without linker errors. However we want to make sure no instances of it get compiled into the module, ever. Therefore, the duplicate symbol is kept in memoverride (_expand_base), and the only usage has been removed from LZHAM's 'lzham_mem'. If a linkage is attempted to anything utilizing '_expand', a linker error will be emitted and no image will be generated.
This commit is contained in:
Kawe Mazidjatari 2023-07-03 00:25:15 +02:00
parent 46390ba875
commit 789ecbc234
2 changed files with 17 additions and 29 deletions

View File

@ -91,19 +91,9 @@ namespace lzham
else else
{ {
void* p_final_block = p; void* p_final_block = p;
#ifdef WIN32
p_new = _expand(p, size);
#else
p_new = NULL; p_new = NULL;
#endif
if (p_new) if (movable)
{
LZHAM_ASSERT( (reinterpret_cast<ptr_bits_t>(p_new) & (LZHAM_MIN_ALLOC_ALIGNMENT - 1)) == 0 );
p_final_block = p_new;
}
else if (movable)
{ {
p_new = realloc(p, size); p_new = realloc(p, size);

View File

@ -48,24 +48,6 @@ void operator delete(void* const pBlock) throw()
return free(pBlock); return free(pBlock);
} }
//-------------------------------------------------------------------------
void* __cdecl _expand(void* const pBlock, size_t const nNewSize, int const nBlockUse)
{
// Expanding isn't supported!!!
Assert(0);
return NULL;
}
#if (defined(_DEBUG) || defined(USE_MEM_DEBUG))
void* __cdecl _expand_dbg(void* pBlock, size_t nNewSize, int nBlockUse,
const char* const pFileName, int nLine)
{
NOTE_UNUSED(pFileName);
NOTE_UNUSED(nLine);
return _expand(pBlock, nNewSize, nBlockUse);
}
#endif // _DEBUG || USE_MEM_DEBUG
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
extern "C" extern "C"
{ {
@ -128,6 +110,13 @@ extern "C"
#endif // !_DEBUG && !USE_MEM_DEBUG #endif // !_DEBUG && !USE_MEM_DEBUG
} }
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
void* __cdecl _expand_base(void* const pBlock, size_t const nNewSize, int const nBlockUse)
{
// Expanding isn't supported!!!
Assert(0);
return NULL;
}
//-------------------------------------------------------------------------
__declspec(noinline) size_t __cdecl _msize(void* const pBlock) __declspec(noinline) size_t __cdecl _msize(void* const pBlock)
{ {
InitAllocator(); InitAllocator();
@ -240,6 +229,15 @@ extern "C"
MemAllocSingleton()->InternalFree(pBlock, "tier0_static128", 0); MemAllocSingleton()->InternalFree(pBlock, "tier0_static128", 0);
} }
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
void* __cdecl _expand_dbg(void* pBlock, size_t nNewSize, int nBlockUse,
const char* const pFileName, int nLine)
{
NOTE_UNUSED(pFileName);
NOTE_UNUSED(nLine);
return _expand_base(pBlock, nNewSize, nBlockUse);
}
//-------------------------------------------------------------------------
__declspec(noinline) size_t __cdecl _msize_dbg(void* const pBlock, int const) __declspec(noinline) size_t __cdecl _msize_dbg(void* const pBlock, int const)
{ {
return _msize(pBlock); return _msize(pBlock);