osx : malloc.h => malloc/malloc.h

This commit is contained in:
hymei
2022-06-05 01:12:37 +03:00
committed by nillerusr
parent 4e4039d756
commit ff588a8810
40 changed files with 152 additions and 52 deletions
+5 -1
View File
@@ -17,7 +17,11 @@
#endif
#include <assert.h>
#ifdef OSX
#include <malloc/malloc.h>
#else
#include <malloc.h>
#endif
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
@@ -319,7 +323,7 @@ static SpewRetval_t _SpewMessage( SpewType_t spewType, const char *pGroupName, i
g_pSpewInfo = &spewInfo;
ret = s_SpewOutputFunc( spewType, pTempBuffer );
g_pSpewInfo = (int)NULL;
g_pSpewInfo = NULL;
switch (ret)
{
+4
View File
@@ -7,7 +7,11 @@
#include "pch_tier0.h"
#include "tier0/mem.h"
#ifdef OSX
#include <malloc/malloc.h>
#else
#include <malloc.h>
#endif
#include "tier0/dbg.h"
#include "tier0/minidump.h"
+4
View File
@@ -7,7 +7,11 @@
#include "pch_tier0.h"
#include "mem_helpers.h"
#include <string.h>
#ifdef OSX
#include <malloc/malloc.h>
#else
#include <malloc.h>
#endif
bool g_bInitMemory = true;
+24 -12
View File
@@ -10,7 +10,11 @@
#if !defined(STEAM) && !defined(NO_MALLOC_OVERRIDE)
#ifdef OSX
#include <malloc/malloc.h>
#else
#include <malloc.h>
#endif
#include <string.h>
#include "tier0/dbg.h"
#include "tier0/memalloc.h"
@@ -269,7 +273,7 @@ struct DbgMemHeader_t
: CrtDbgMemHeader_t
#endif
{
unsigned nLogicalSize;
size_t nLogicalSize;
byte reserved[12]; // MS allocator always returns mem aligned on 16 bytes, which some of our code depends on
};
@@ -634,11 +638,11 @@ private:
const char *FindOrCreateFilename( const char *pFileName );
// Updates stats
void RegisterAllocation( const char *pFileName, int nLine, int nLogicalSize, int nActualSize, unsigned nTime );
void RegisterDeallocation( const char *pFileName, int nLine, int nLogicalSize, int nActualSize, unsigned nTime );
void RegisterAllocation( const char *pFileName, int nLine, size_t nLogicalSize, size_t nActualSize, unsigned nTime );
void RegisterDeallocation( const char *pFileName, int nLine, size_t nLogicalSize, size_t nActualSize, unsigned nTime );
void RegisterAllocation( MemInfo_t &info, int nLogicalSize, int nActualSize, unsigned nTime );
void RegisterDeallocation( MemInfo_t &info, int nLogicalSize, int nActualSize, unsigned nTime );
void RegisterAllocation( MemInfo_t &info, size_t nLogicalSize, size_t nActualSize, unsigned nTime );
void RegisterDeallocation( MemInfo_t &info, size_t nLogicalSize, size_t nActualSize, unsigned nTime );
// Gets the allocation file name
const char *GetAllocatonFileName( void *pMem );
@@ -1056,21 +1060,21 @@ CDbgMemAlloc::MemInfo_t &CDbgMemAlloc::FindOrCreateEntry( const char *pFileName,
//-----------------------------------------------------------------------------
// Updates stats
//-----------------------------------------------------------------------------
void CDbgMemAlloc::RegisterAllocation( const char *pFileName, int nLine, int nLogicalSize, int nActualSize, unsigned nTime )
void CDbgMemAlloc::RegisterAllocation( const char *pFileName, int nLine, size_t nLogicalSize, size_t nActualSize, unsigned nTime )
{
HEAP_LOCK();
RegisterAllocation( m_GlobalInfo, nLogicalSize, nActualSize, nTime );
RegisterAllocation( FindOrCreateEntry( pFileName, nLine ), nLogicalSize, nActualSize, nTime );
}
void CDbgMemAlloc::RegisterDeallocation( const char *pFileName, int nLine, int nLogicalSize, int nActualSize, unsigned nTime )
void CDbgMemAlloc::RegisterDeallocation( const char *pFileName, int nLine, size_t nLogicalSize, size_t nActualSize, unsigned nTime )
{
HEAP_LOCK();
RegisterDeallocation( m_GlobalInfo, nLogicalSize, nActualSize, nTime );
RegisterDeallocation( FindOrCreateEntry( pFileName, nLine ), nLogicalSize, nActualSize, nTime );
}
void CDbgMemAlloc::RegisterAllocation( MemInfo_t &info, int nLogicalSize, int nActualSize, unsigned nTime )
void CDbgMemAlloc::RegisterAllocation( MemInfo_t &info, size_t nLogicalSize, size_t nActualSize, unsigned nTime )
{
++info.m_nCurrentCount;
++info.m_nTotalCount;
@@ -1107,7 +1111,7 @@ void CDbgMemAlloc::RegisterAllocation( MemInfo_t &info, int nLogicalSize, int nA
info.m_nTime += nTime;
}
void CDbgMemAlloc::RegisterDeallocation( MemInfo_t &info, int nLogicalSize, int nActualSize, unsigned nTime )
void CDbgMemAlloc::RegisterDeallocation( MemInfo_t &info, size_t nLogicalSize, size_t nActualSize, unsigned nTime )
{
// Check for decrementing these counters below zero. The checks
// must be done here because these unsigned counters will wrap-around and
@@ -1117,7 +1121,7 @@ void CDbgMemAlloc::RegisterDeallocation( MemInfo_t &info, int nLogicalSize, int
// It is technically legal for code to request allocations of zero bytes, and there are a number of places in our code
// that do. So only assert that nLogicalSize >= 0. http://stackoverflow.com/questions/1087042/c-new-int0-will-it-allocate-memory
Assert( nLogicalSize >= 0 );
Assert( info.m_nCurrentSize >= (size_t)nLogicalSize );
Assert( info.m_nCurrentSize >= nLogicalSize );
--info.m_nCurrentCount;
info.m_nCurrentSize -= nLogicalSize;
@@ -1250,8 +1254,8 @@ void CDbgMemAlloc::Free( void *pMem, const char * /*pFileName*/, int nLine )
return;
}
int nOldLogicalSize = InternalLogicalSize( pMem );
int nOldSize = InternalMSize( pMem );
size_t nOldLogicalSize = InternalLogicalSize( pMem );
size_t nOldSize = InternalMSize( pMem );
const char *pOldFileName = GetAllocatonFileName( pMem );
int oldLine = GetAllocatonLineNumber( pMem );
@@ -1832,6 +1836,10 @@ static inline void unprotect_malloc_zone( malloc_zone_t *malloc_zone )
// The version check may not be necessary, but we know it was RW before that.
if ( malloc_zone->version >= 8 )
{
#ifdef __arm64__
// MoeMod : this is required for Apple Silicon
pthread_jit_write_protect_np(false);
#endif
vm_protect( mach_task_self(), (uintptr_t)malloc_zone, sizeof( malloc_zone_t ), 0, VM_PROT_READ | VM_PROT_WRITE );
}
}
@@ -1841,6 +1849,10 @@ static inline void protect_malloc_zone( malloc_zone_t *malloc_zone )
if ( malloc_zone->version >= 8 )
{
vm_protect( mach_task_self(), (uintptr_t)malloc_zone, sizeof( malloc_zone_t ), 0, VM_PROT_READ );
#ifdef __arm64__
// MoeMod : this is required for Apple Silicon
pthread_jit_write_protect_np(true);
#endif
}
}
+4
View File
@@ -20,7 +20,11 @@
#define VA_RESERVE_FLAGS (MEM_RESERVE|MEM_LARGE_PAGES)
#endif
#ifdef OSX
#include <malloc/malloc.h>
#else
#include <malloc.h>
#endif
#include "tier0/valve_minmax_off.h" // GCC 4.2.2 headers screw up our min/max defs.
#include <algorithm>
+6 -2
View File
@@ -18,7 +18,11 @@
#endif
#endif
#ifdef OSX
#include <malloc/malloc.h>
#else
#include <malloc.h>
#endif
#include <algorithm>
#include "tier0/dbg.h"
#include "tier0/memalloc.h"
@@ -253,8 +257,8 @@ public:
virtual bool IsDebugHeap() { return false; }
virtual void GetActualDbgInfo( const char *&pFileName, int &nLine ) {}
virtual void RegisterAllocation( const char *pFileName, int nLine, int nLogicalSize, int nActualSize, unsigned nTime ) {}
virtual void RegisterDeallocation( const char *pFileName, int nLine, int nLogicalSize, int nActualSize, unsigned nTime ) {}
virtual void RegisterAllocation( const char *pFileName, int nLine, size_t nLogicalSize, size_t nActualSize, unsigned nTime ) {}
virtual void RegisterDeallocation( const char *pFileName, int nLine, size_t nLogicalSize, size_t nActualSize, unsigned nTime ) {}
virtual int GetVersion() { return MEMALLOC_VERSION; }
+4 -4
View File
@@ -102,8 +102,8 @@ private:
void GetActualDbgInfo( const char *&pFileName, int &nLine );
// Updates stats
void RegisterAllocation( const char *pFileName, int nLine, int nLogicalSize, int nActualSize, unsigned nTime );
void RegisterDeallocation( const char *pFileName, int nLine, int nLogicalSize, int nActualSize, unsigned nTime );
void RegisterAllocation( const char *pFileName, int nLine, size_t nLogicalSize, size_t nActualSize, unsigned nTime );
void RegisterDeallocation( const char *pFileName, int nLine, size_t nLogicalSize, size_t nActualSize, unsigned nTime );
HeapSuffix_t *Suffix( HeapPrefix_t *pPrefix );
void *AllocationStart( HeapPrefix_t *pBase );
@@ -460,12 +460,12 @@ void CValidateAlloc::GetActualDbgInfo( const char *&pFileName, int &nLine )
}
// Updates stats
void CValidateAlloc::RegisterAllocation( const char *pFileName, int nLine, int nLogicalSize, int nActualSize, unsigned nTime )
void CValidateAlloc::RegisterAllocation( const char *pFileName, int nLine, size_t nLogicalSize, size_t nActualSize, unsigned nTime )
{
g_pActualAlloc->RegisterAllocation( pFileName, nLine, nLogicalSize, nActualSize, nTime );
}
void CValidateAlloc::RegisterDeallocation( const char *pFileName, int nLine, int nLogicalSize, int nActualSize, unsigned nTime )
void CValidateAlloc::RegisterDeallocation( const char *pFileName, int nLine, size_t nLogicalSize, size_t nActualSize, unsigned nTime )
{
g_pActualAlloc->RegisterDeallocation( pFileName, nLine, nLogicalSize, nActualSize, nTime );
}
+4
View File
@@ -30,7 +30,11 @@
#include <stdio.h>
#include <ctype.h>
#include <math.h>
#ifdef OSX
#include <malloc/malloc.h>
#else
#include <malloc.h>
#endif
#include <memory.h>
#include <ctype.h>
#include <limits.h>
+7 -3
View File
@@ -679,13 +679,17 @@ PLATFORM_INTERFACE void Plat_SetWatchdogHandlerFunction( Plat_WatchDogHandlerFun
// memory logging this functionality is portable code, except for the way in which it hooks
// malloc/free. glibc contains the ability for the app to install hooks into malloc/free.
#ifdef OSX
#include <malloc/malloc.h>
#else
#include <malloc.h>
#endif
#include <tier1/utlintrusivelist.h>
#include <execinfo.h>
#include <tier1/utlvector.h>
#define MEMALLOC_HASHSIZE 8193
typedef uint32 ptrint_t;
typedef uintp ptrint_t;
@@ -993,7 +997,7 @@ static inline bool SortLessFunc( CLinuxMallocContext * const &left, CLinuxMalloc
void DumpMemoryLog( int nThresh )
{
AUTO_LOCK( s_MemoryMutex );
EndWatchdogTimer();
Plat_EndWatchdogTimer();
RemoveHooks();
std::vector<CLinuxMallocContext *> memList;
@@ -1028,7 +1032,7 @@ void DumpMemoryLog( int nThresh )
void DumpChangedMemory( int nThresh )
{
AUTO_LOCK( s_MemoryMutex );
EndWatchdogTimer();
Plat_EndWatchdogTimer();
RemoveHooks();
std::vector<CLinuxMallocContext *> memList;