1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-07-04 23:36:00 +02:00

Fixed crash related to global var alignment

This commit is contained in:
Brian Fiete 2020-04-03 12:32:42 -07:00
parent 2c6a72ba68
commit aaccaa97e2
5 changed files with 40 additions and 10 deletions

View file

@ -12,7 +12,6 @@
USING_NS_BF;
#ifdef DEF_BF_ALLOCDEBUG
//////////////////////////////////////////////////////////////////////////
@ -190,7 +189,7 @@ void StompInit()
gStompInside = false;
}
static void* StompAlloc(int size)
void* StompAlloc(int size)
{
//return malloc(size);
@ -222,7 +221,7 @@ static void* StompAlloc(int size)
gStompInside = false;
}
static void StompFree(void* addr)
void StompFree(void* addr)
{
if (gSA_CritSect == NULL)
StompInit();
@ -328,6 +327,8 @@ void DbgHeapFree(const void* ptr, const char* fileName, int lineNum)
assert("Not found" == 0);
}
#ifdef DEF_BF_ALLOCDEBUG
void DbgHeapCheck()
{
for (int i = 0; i < (int) gDbgHeapRecords.size(); i++)
@ -391,7 +392,7 @@ void* __cdecl operator new(std::size_t size)
#ifdef USE_STOMP
return StompAlloc((int)size);
#else
return DbgHeapAlloc(size, fileName, lineNum);
return DbgHeapAlloc(size, "", 0);
#endif
}
@ -427,7 +428,7 @@ void operator delete(void* ptr)
#ifdef USE_STOMP
StompFree(ptr);
#else
DbgHeapFree(ptr, fileName, lineNum);
DbgHeapFree(ptr, "", 0);
#endif
}
@ -436,7 +437,7 @@ void operator delete[](void* ptr)
#ifdef USE_STOMP
StompFree(ptr);
#else
DbgHeapFree(ptr, fileName, lineNum);
DbgHeapFree(ptr, "", 0);
#endif
}

View file

@ -85,3 +85,6 @@ void BpDump();
#define BP_ALLOC_RAW_T(T)
#endif
void* StompAlloc(int size);
void StompFree(void* addr);

View file

@ -5,11 +5,17 @@
#include "../Common.h"
//#define BUMPALLOC_TRACKALLOCS
//#define BUMPALLOC_STOMPALLOC
#ifdef BUMPALLOC_ETW_TRACING
#include "VSCustomNativeHeapEtwProvider.h"
#endif
#ifdef BUMPALLOC_STOMPALLOC
void* StompAlloc(int size);
void StompFree(void* addr);
#endif
#ifdef BUMPALLOC_TRACKALLOCS
#include "Dictionary.h"
#endif
@ -74,7 +80,11 @@ public:
mCurAlloc = NULL;
mCurPtr = (uint8*)(intptr)ALLOC_SIZE;
for (auto ptr : mPools)
#ifdef BUMPALLOC_STOMPALLOC
StompFree(ptr);
#else
free(ptr);
#endif
mPools.Clear();
mSizes.Clear();
mCurChunkNum = -1;
@ -130,7 +140,11 @@ public:
int curSize = (int)(mCurPtr - mCurAlloc);
mPrevSizes += curSize;
mSizes.push_back(curSize);
mCurAlloc = (uint8*)malloc(ALLOC_SIZE);
#ifdef BUMPALLOC_STOMPALLOC
mCurAlloc = (uint8*)StompAlloc(ALLOC_SIZE);
#else
mCurAlloc = (uint8*)malloc(ALLOC_SIZE);
#endif
memset(mCurAlloc, 0, ALLOC_SIZE);
mPools.push_back(mCurAlloc);
mCurPtr = mCurAlloc;
@ -205,7 +219,11 @@ public:
if (wantSize > ALLOC_SIZE / 2)
{
#ifdef BUMPALLOC_STOMPALLOC
uint8* bigData = (uint8*)StompAlloc((int)wantSize);
#else
uint8* bigData = (uint8*)malloc(wantSize);
#endif
memset(bigData, 0, wantSize);
mPools.push_back(bigData);
return bigData;