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

This commit is contained in:
hymei 2022-02-23 19:56:29 +08:00 committed by nillerusr
parent 4e4039d756
commit ff588a8810
40 changed files with 152 additions and 52 deletions

View File

@ -10,7 +10,6 @@
#include "bitmap/imageformat.h" #include "bitmap/imageformat.h"
#include "basetypes.h" #include "basetypes.h"
#include "tier0/dbg.h" #include "tier0/dbg.h"
#include <malloc.h>
#include <memory.h> #include <memory.h>
#include "mathlib/mathlib.h" #include "mathlib/mathlib.h"
#include "mathlib/vector.h" #include "mathlib/vector.h"

View File

@ -11,7 +11,6 @@
#include "bitmap/imageformat.h" #include "bitmap/imageformat.h"
#include "basetypes.h" #include "basetypes.h"
#include "tier0/dbg.h" #include "tier0/dbg.h"
#include <malloc.h>
#include <memory.h> #include <memory.h>
#include "nvtc.h" #include "nvtc.h"
#include "mathlib/mathlib.h" #include "mathlib/mathlib.h"

View File

@ -8,7 +8,6 @@
#include "bitmap/imageformat.h" #include "bitmap/imageformat.h"
#include "basetypes.h" #include "basetypes.h"
#include "tier0/dbg.h" #include "tier0/dbg.h"
#include <malloc.h>
#include <memory.h> #include <memory.h>
#include "mathlib/mathlib.h" #include "mathlib/mathlib.h"
#include "mathlib/vector.h" #include "mathlib/vector.h"

View File

@ -7,7 +7,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include "tier0/dbg.h" #include "tier0/dbg.h"
#include <malloc.h>
#include "filesystem.h" #include "filesystem.h"
#include "bitmap/tgawriter.h" #include "bitmap/tgawriter.h"
#include "tier1/utlbuffer.h" #include "tier1/utlbuffer.h"

View File

@ -6,7 +6,11 @@
// //
//=============================================================================// //=============================================================================//
#include <stdio.h> #include <stdio.h>
#ifdef OSX
#include <malloc/malloc.h>
#else
#include <malloc.h> #include <malloc.h>
#endif
#include "ObjectList.h" #include "ObjectList.h"
#include "tier1/strtools.h" #include "tier1/strtools.h"

View File

@ -3,6 +3,8 @@
#ifdef ANDROID #ifdef ANDROID
#include <sys/cdefs.h> #include <sys/cdefs.h>
#elif defined(OSX)
#include <stdint.h>
#else #else
#include <bits/wordsize.h> #include <bits/wordsize.h>
#endif #endif

View File

@ -16,7 +16,11 @@
#include <characterset.h> #include <characterset.h>
#include <bitbuf.h> #include <bitbuf.h>
#include "common.h" #include "common.h"
#ifdef OSX
#include <malloc/malloc.h>
#else
#include <malloc.h> #include <malloc.h>
#endif
#include "traceinit.h" #include "traceinit.h"
#include <filesystem.h> #include <filesystem.h>
#include "filesystem_engine.h" #include "filesystem_engine.h"

View File

@ -14,7 +14,11 @@
#include "filesystem.h" #include "filesystem.h"
#include "filesystem_engine.h" #include "filesystem_engine.h"
#include "materialsystem/imaterial.h" #include "materialsystem/imaterial.h"
#ifdef OSX
#include <malloc/malloc.h>
#else
#include <malloc.h> #include <malloc.h>
#endif
#include "utldict.h" #include "utldict.h"
// memdbgon must be the last include file in a .cpp file!!! // memdbgon must be the last include file in a .cpp file!!!

View File

@ -6,7 +6,6 @@
//=============================================================================// //=============================================================================//
#include <stdlib.h> #include <stdlib.h>
#include <malloc.h>
#include <string.h> #include <string.h>
#include "materialsystem/imaterialproxy.h" #include "materialsystem/imaterialproxy.h"
#include "materialproxyfactory.h" #include "materialproxyfactory.h"

View File

@ -5,7 +5,11 @@
// $NoKeywords: $ // $NoKeywords: $
// //
//=============================================================================// //=============================================================================//
#ifdef OSX
#include <malloc/malloc.h>
#else
#include <malloc.h> #include <malloc.h>
#endif
#include <string.h> #include <string.h>
#include <assert.h> #include <assert.h>
#include "packed_entity.h" #include "packed_entity.h"

View File

@ -32,7 +32,11 @@
#ifdef _DEBUG #ifdef _DEBUG
#ifdef OSX
#include <malloc/malloc.h>
#else
#include <malloc.h> #include <malloc.h>
#endif
#endif // _DEBUG #endif // _DEBUG
static ConVar sv_useexplicitdelete( "sv_useexplicitdelete", "1", FCVAR_DEVELOPMENTONLY, "Explicitly delete dormant client entities caused by AllowImmediateReuse()." ); static ConVar sv_useexplicitdelete( "sv_useexplicitdelete", "1", FCVAR_DEVELOPMENTONLY, "Explicitly delete dormant client entities caused by AllowImmediateReuse()." );

View File

@ -133,7 +133,14 @@ void Hunk_Print()
void Memory_Init( void ) void Memory_Init( void )
{ {
MEM_ALLOC_CREDIT(); MEM_ALLOC_CREDIT();
#ifdef PLATFORM_64BITS
// Seems to need to be larger to not get exhausted on
// 64-bit. Perhaps because of larger pointer sizes.
int nMaxBytes = 128*1024*1024;
#else
int nMaxBytes = 48*1024*1024; int nMaxBytes = 48*1024*1024;
#endif
const int nMinCommitBytes = 0x8000; const int nMinCommitBytes = 0x8000;
#ifndef HUNK_USE_16MB_PAGE #ifndef HUNK_USE_16MB_PAGE
const int nInitialCommit = 0x280000; const int nInitialCommit = 0x280000;

View File

@ -17,7 +17,7 @@
#include "materialsystem/imaterialproxyfactory.h" #include "materialsystem/imaterialproxyfactory.h"
#include "IHardwareConfigInternal.h" #include "IHardwareConfigInternal.h"
#include "utlsymbol.h" #include "utlsymbol.h"
#include <malloc.h> #include <stdlib.h>
#include "filesystem.h" #include "filesystem.h"
#include <KeyValues.h> #include <KeyValues.h>
#include "mempool.h" #include "mempool.h"

View File

@ -17,7 +17,11 @@
#include "materialsystem/imaterialproxyfactory.h" #include "materialsystem/imaterialproxyfactory.h"
#include "IHardwareConfigInternal.h" #include "IHardwareConfigInternal.h"
#include "utlsymbol.h" #include "utlsymbol.h"
#ifdef OSX
#include <malloc/malloc.h>
#else
#include <malloc.h> #include <malloc.h>
#endif
#include "filesystem.h" #include "filesystem.h"
#include <KeyValues.h> #include <KeyValues.h>
#include "mempool.h" #include "mempool.h"

View File

@ -7,7 +7,6 @@
#include "materialsystem_global.h" #include "materialsystem_global.h"
#include "shaderapi/ishaderapi.h" #include "shaderapi/ishaderapi.h"
#include "shadersystem.h" #include "shadersystem.h"
#include <malloc.h>
#include "filesystem.h" #include "filesystem.h"
// memdbgon must be the last include file in a .cpp file!!! // memdbgon must be the last include file in a .cpp file!!!

View File

@ -16,7 +16,11 @@
#include "windows.h" #include "windows.h"
#endif #endif
#ifdef OSX
#include <malloc/malloc.h>
#else
#include <malloc.h> #include <malloc.h>
#endif
#include <string.h> #include <string.h>
#include "crtmemdebug.h" #include "crtmemdebug.h"

View File

@ -42,7 +42,6 @@ mat_fullbright 1 doesn't work properly on alpha materials in testroom_standards
#include "colorformatdx8.h" #include "colorformatdx8.h"
#include "texturedx8.h" #include "texturedx8.h"
#include "textureheap.h" #include "textureheap.h"
#include <malloc.h>
#include "interface.h" #include "interface.h"
#include "utlrbtree.h" #include "utlrbtree.h"
#include "utlsymbol.h" #include "utlsymbol.h"

View File

@ -9,7 +9,6 @@
//#include <stdafx.h> //#include <stdafx.h>
#include <stdlib.h> #include <stdlib.h>
#include <malloc.h>
#include "builddisp.h" #include "builddisp.h"
#include "collisionutils.h" #include "collisionutils.h"
#include "tier1/strtools.h" #include "tier1/strtools.h"

View File

@ -512,7 +512,7 @@ inline const char *CSaveRestoreSegment::StringFromSymbol( int token )
/// compilers. Either way, there's no portable intrinsic. /// compilers. Either way, there's no portable intrinsic.
// Newer GCC versions provide this in this header, older did by default. // Newer GCC versions provide this in this header, older did by default.
#if !defined( _rotr ) && defined( COMPILER_GCC ) && !defined( __arm__ ) #if !defined( _rotr ) && defined( COMPILER_GCC ) && !defined( __arm__ ) && !defined( __arm64__ )
#include <x86intrin.h> #include <x86intrin.h>
#endif #endif

View File

@ -96,8 +96,8 @@ public:
virtual bool IsDebugHeap() = 0; virtual bool IsDebugHeap() = 0;
virtual void GetActualDbgInfo( const char *&pFileName, int &nLine ) = 0; virtual void GetActualDbgInfo( const char *&pFileName, int &nLine ) = 0;
virtual void RegisterAllocation( const char *pFileName, int nLine, int nLogicalSize, int nActualSize, unsigned nTime ) = 0; virtual void RegisterAllocation( const char *pFileName, int nLine, size_t nLogicalSize, size_t nActualSize, unsigned nTime ) = 0;
virtual void RegisterDeallocation( const char *pFileName, int nLine, int nLogicalSize, int nActualSize, unsigned nTime ) = 0; virtual void RegisterDeallocation( const char *pFileName, int nLine, size_t nLogicalSize, size_t nActualSize, unsigned nTime ) = 0;
virtual int GetVersion() = 0; virtual int GetVersion() = 0;
@ -473,9 +473,14 @@ inline void MemAlloc_CheckAlloc( void *ptr, size_t nSize )
} }
#if defined( OSX ) #if defined( OSX )
// Mac always aligns allocs, don't need to call posix_memalign which doesn't exist in 10.5.8 which TF2 still needs to run on inline void *memalign(size_t alignment, size_t size) {
//inline void *memalign(size_t alignment, size_t size) {void *pTmp=NULL; posix_memalign(&pTmp, alignment, size); return pTmp;} // MoeMod : 64bit fix
inline void *memalign(size_t alignment, size_t size) {void *pTmp=NULL; pTmp = malloc(size); MemAlloc_CheckAlloc( pTmp, size ); return pTmp;} if(alignment < sizeof(void *))
alignment = sizeof(void *);
void *pTmp = nullptr;
posix_memalign(&pTmp, alignment, size);
return pTmp;
}
#endif #endif
inline void *_aligned_malloc( size_t nSize, size_t align ) { void *ptr = memalign( align, nSize ); MemAlloc_CheckAlloc( ptr, nSize ); return ptr; } inline void *_aligned_malloc( size_t nSize, size_t align ) { void *ptr = memalign( align, nSize ); MemAlloc_CheckAlloc( ptr, nSize ); return ptr; }

View File

@ -29,7 +29,11 @@
#include <wchar.h> #include <wchar.h>
#endif #endif
#include <string.h> #include <string.h>
#ifdef OSX
#include <malloc/malloc.h>
#else
#include <malloc.h> #include <malloc.h>
#endif
#include "commonmacros.h" #include "commonmacros.h"
#include "memalloc.h" #include "memalloc.h"

View File

@ -458,7 +458,7 @@ inline void CAlignedMemPool<ITEM_SIZE, ALIGNMENT, CHUNK_SIZE, CAllocator, COMPAC
template <int ITEM_SIZE, int ALIGNMENT, int CHUNK_SIZE, class CAllocator, int COMPACT_THRESHOLD > template <int ITEM_SIZE, int ALIGNMENT, int CHUNK_SIZE, class CAllocator, int COMPACT_THRESHOLD >
inline int __cdecl CAlignedMemPool<ITEM_SIZE, ALIGNMENT, CHUNK_SIZE, CAllocator, COMPACT_THRESHOLD>::CompareChunk( void * const *ppLeft, void * const *ppRight ) inline int __cdecl CAlignedMemPool<ITEM_SIZE, ALIGNMENT, CHUNK_SIZE, CAllocator, COMPACT_THRESHOLD>::CompareChunk( void * const *ppLeft, void * const *ppRight )
{ {
return ((unsigned)*ppLeft) - ((unsigned)*ppRight); return (int)(((uintp)*ppLeft) - ((uintp)*ppRight));
} }
template <int ITEM_SIZE, int ALIGNMENT, int CHUNK_SIZE, class CAllocator, int COMPACT_THRESHOLD > template <int ITEM_SIZE, int ALIGNMENT, int CHUNK_SIZE, class CAllocator, int COMPACT_THRESHOLD >

View File

@ -8,7 +8,11 @@
#if !defined(_STATIC_LINKED) || defined(_SHARED_LIB) #if !defined(_STATIC_LINKED) || defined(_SHARED_LIB)
#ifdef OSX
#include <malloc/malloc.h>
#else
#include <malloc.h> #include <malloc.h>
#endif
#include "vallocator.h" #include "vallocator.h"
#include "basetypes.h" #include "basetypes.h"

View File

@ -19,7 +19,11 @@
#include <stdio.h> #include <stdio.h>
#include <ctype.h> #include <ctype.h>
#include <math.h> #include <math.h>
#ifdef OSX
#include <malloc/malloc.h>
#else
#include <malloc.h> #include <malloc.h>
#endif
#include <memory.h> #include <memory.h>
#include <ctype.h> #include <ctype.h>

View File

@ -15,7 +15,6 @@
#include "optimize.h" #include "optimize.h"
#include "mathlib/mathlib.h" #include "mathlib/mathlib.h"
#include "mathlib/vector.h" #include "mathlib/vector.h"
#include <malloc.h>
#include "mathlib/vmatrix.h" #include "mathlib/vmatrix.h"
#include "studiorendercontext.h" #include "studiorendercontext.h"
#include "tier2/tier2.h" #include "tier2/tier2.h"

View File

@ -17,7 +17,11 @@
#endif #endif
#include <assert.h> #include <assert.h>
#ifdef OSX
#include <malloc/malloc.h>
#else
#include <malloc.h> #include <malloc.h>
#endif
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <stdarg.h> #include <stdarg.h>
@ -319,7 +323,7 @@ static SpewRetval_t _SpewMessage( SpewType_t spewType, const char *pGroupName, i
g_pSpewInfo = &spewInfo; g_pSpewInfo = &spewInfo;
ret = s_SpewOutputFunc( spewType, pTempBuffer ); ret = s_SpewOutputFunc( spewType, pTempBuffer );
g_pSpewInfo = (int)NULL; g_pSpewInfo = NULL;
switch (ret) switch (ret)
{ {

View File

@ -7,7 +7,11 @@
#include "pch_tier0.h" #include "pch_tier0.h"
#include "tier0/mem.h" #include "tier0/mem.h"
#ifdef OSX
#include <malloc/malloc.h>
#else
#include <malloc.h> #include <malloc.h>
#endif
#include "tier0/dbg.h" #include "tier0/dbg.h"
#include "tier0/minidump.h" #include "tier0/minidump.h"

View File

@ -7,7 +7,11 @@
#include "pch_tier0.h" #include "pch_tier0.h"
#include "mem_helpers.h" #include "mem_helpers.h"
#include <string.h> #include <string.h>
#ifdef OSX
#include <malloc/malloc.h>
#else
#include <malloc.h> #include <malloc.h>
#endif
bool g_bInitMemory = true; bool g_bInitMemory = true;

View File

@ -10,7 +10,11 @@
#if !defined(STEAM) && !defined(NO_MALLOC_OVERRIDE) #if !defined(STEAM) && !defined(NO_MALLOC_OVERRIDE)
#ifdef OSX
#include <malloc/malloc.h>
#else
#include <malloc.h> #include <malloc.h>
#endif
#include <string.h> #include <string.h>
#include "tier0/dbg.h" #include "tier0/dbg.h"
#include "tier0/memalloc.h" #include "tier0/memalloc.h"
@ -269,7 +273,7 @@ struct DbgMemHeader_t
: CrtDbgMemHeader_t : CrtDbgMemHeader_t
#endif #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 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 ); const char *FindOrCreateFilename( const char *pFileName );
// Updates stats // Updates stats
void RegisterAllocation( 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, int nLogicalSize, int 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 RegisterAllocation( MemInfo_t &info, size_t nLogicalSize, size_t nActualSize, unsigned nTime );
void RegisterDeallocation( MemInfo_t &info, int nLogicalSize, int nActualSize, unsigned nTime ); void RegisterDeallocation( MemInfo_t &info, size_t nLogicalSize, size_t nActualSize, unsigned nTime );
// Gets the allocation file name // Gets the allocation file name
const char *GetAllocatonFileName( void *pMem ); const char *GetAllocatonFileName( void *pMem );
@ -1056,21 +1060,21 @@ CDbgMemAlloc::MemInfo_t &CDbgMemAlloc::FindOrCreateEntry( const char *pFileName,
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Updates stats // 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(); HEAP_LOCK();
RegisterAllocation( m_GlobalInfo, nLogicalSize, nActualSize, nTime ); RegisterAllocation( m_GlobalInfo, nLogicalSize, nActualSize, nTime );
RegisterAllocation( FindOrCreateEntry( pFileName, nLine ), 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(); HEAP_LOCK();
RegisterDeallocation( m_GlobalInfo, nLogicalSize, nActualSize, nTime ); RegisterDeallocation( m_GlobalInfo, nLogicalSize, nActualSize, nTime );
RegisterDeallocation( FindOrCreateEntry( pFileName, nLine ), 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_nCurrentCount;
++info.m_nTotalCount; ++info.m_nTotalCount;
@ -1107,7 +1111,7 @@ void CDbgMemAlloc::RegisterAllocation( MemInfo_t &info, int nLogicalSize, int nA
info.m_nTime += nTime; 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 // Check for decrementing these counters below zero. The checks
// must be done here because these unsigned counters will wrap-around and // 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 // 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 // that do. So only assert that nLogicalSize >= 0. http://stackoverflow.com/questions/1087042/c-new-int0-will-it-allocate-memory
Assert( nLogicalSize >= 0 ); Assert( nLogicalSize >= 0 );
Assert( info.m_nCurrentSize >= (size_t)nLogicalSize ); Assert( info.m_nCurrentSize >= nLogicalSize );
--info.m_nCurrentCount; --info.m_nCurrentCount;
info.m_nCurrentSize -= nLogicalSize; info.m_nCurrentSize -= nLogicalSize;
@ -1250,8 +1254,8 @@ void CDbgMemAlloc::Free( void *pMem, const char * /*pFileName*/, int nLine )
return; return;
} }
int nOldLogicalSize = InternalLogicalSize( pMem ); size_t nOldLogicalSize = InternalLogicalSize( pMem );
int nOldSize = InternalMSize( pMem ); size_t nOldSize = InternalMSize( pMem );
const char *pOldFileName = GetAllocatonFileName( pMem ); const char *pOldFileName = GetAllocatonFileName( pMem );
int oldLine = GetAllocatonLineNumber( 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. // The version check may not be necessary, but we know it was RW before that.
if ( malloc_zone->version >= 8 ) 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 ); 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 ) if ( malloc_zone->version >= 8 )
{ {
vm_protect( mach_task_self(), (uintptr_t)malloc_zone, sizeof( malloc_zone_t ), 0, VM_PROT_READ ); 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
} }
} }

View File

@ -20,7 +20,11 @@
#define VA_RESERVE_FLAGS (MEM_RESERVE|MEM_LARGE_PAGES) #define VA_RESERVE_FLAGS (MEM_RESERVE|MEM_LARGE_PAGES)
#endif #endif
#ifdef OSX
#include <malloc/malloc.h>
#else
#include <malloc.h> #include <malloc.h>
#endif
#include "tier0/valve_minmax_off.h" // GCC 4.2.2 headers screw up our min/max defs. #include "tier0/valve_minmax_off.h" // GCC 4.2.2 headers screw up our min/max defs.
#include <algorithm> #include <algorithm>

View File

@ -18,7 +18,11 @@
#endif #endif
#endif #endif
#ifdef OSX
#include <malloc/malloc.h>
#else
#include <malloc.h> #include <malloc.h>
#endif
#include <algorithm> #include <algorithm>
#include "tier0/dbg.h" #include "tier0/dbg.h"
#include "tier0/memalloc.h" #include "tier0/memalloc.h"
@ -253,8 +257,8 @@ public:
virtual bool IsDebugHeap() { return false; } virtual bool IsDebugHeap() { return false; }
virtual void GetActualDbgInfo( const char *&pFileName, int &nLine ) {} virtual void GetActualDbgInfo( const char *&pFileName, int &nLine ) {}
virtual void RegisterAllocation( 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, int nLogicalSize, int 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; } virtual int GetVersion() { return MEMALLOC_VERSION; }

View File

@ -102,8 +102,8 @@ private:
void GetActualDbgInfo( const char *&pFileName, int &nLine ); void GetActualDbgInfo( const char *&pFileName, int &nLine );
// Updates stats // Updates stats
void RegisterAllocation( 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, int nLogicalSize, int nActualSize, unsigned nTime ); void RegisterDeallocation( const char *pFileName, int nLine, size_t nLogicalSize, size_t nActualSize, unsigned nTime );
HeapSuffix_t *Suffix( HeapPrefix_t *pPrefix ); HeapSuffix_t *Suffix( HeapPrefix_t *pPrefix );
void *AllocationStart( HeapPrefix_t *pBase ); void *AllocationStart( HeapPrefix_t *pBase );
@ -460,12 +460,12 @@ void CValidateAlloc::GetActualDbgInfo( const char *&pFileName, int &nLine )
} }
// Updates stats // 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 ); 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 ); g_pActualAlloc->RegisterDeallocation( pFileName, nLine, nLogicalSize, nActualSize, nTime );
} }

View File

@ -30,7 +30,11 @@
#include <stdio.h> #include <stdio.h>
#include <ctype.h> #include <ctype.h>
#include <math.h> #include <math.h>
#ifdef OSX
#include <malloc/malloc.h>
#else
#include <malloc.h> #include <malloc.h>
#endif
#include <memory.h> #include <memory.h>
#include <ctype.h> #include <ctype.h>
#include <limits.h> #include <limits.h>

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 // 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. // 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> #include <malloc.h>
#endif
#include <tier1/utlintrusivelist.h> #include <tier1/utlintrusivelist.h>
#include <execinfo.h> #include <execinfo.h>
#include <tier1/utlvector.h> #include <tier1/utlvector.h>
#define MEMALLOC_HASHSIZE 8193 #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 ) void DumpMemoryLog( int nThresh )
{ {
AUTO_LOCK( s_MemoryMutex ); AUTO_LOCK( s_MemoryMutex );
EndWatchdogTimer(); Plat_EndWatchdogTimer();
RemoveHooks(); RemoveHooks();
std::vector<CLinuxMallocContext *> memList; std::vector<CLinuxMallocContext *> memList;
@ -1028,7 +1032,7 @@ void DumpMemoryLog( int nThresh )
void DumpChangedMemory( int nThresh ) void DumpChangedMemory( int nThresh )
{ {
AUTO_LOCK( s_MemoryMutex ); AUTO_LOCK( s_MemoryMutex );
EndWatchdogTimer(); Plat_EndWatchdogTimer();
RemoveHooks(); RemoveHooks();
std::vector<CLinuxMallocContext *> memList; std::vector<CLinuxMallocContext *> memList;

View File

@ -6,7 +6,11 @@
#include "mempool.h" #include "mempool.h"
#include <stdio.h> #include <stdio.h>
#ifdef OSX
#include <malloc/malloc.h>
#else
#include <malloc.h> #include <malloc.h>
#endif
#include <memory.h> #include <memory.h>
#include "tier0/dbg.h" #include "tier0/dbg.h"
#include <ctype.h> #include <ctype.h>

View File

@ -26,7 +26,11 @@
#include <assert.h> #include <assert.h>
#include <stdio.h> #include <stdio.h>
#include <stdarg.h> #include <stdarg.h>
#ifdef OSX
#include <malloc/malloc.h>
#else
#include <malloc.h> #include <malloc.h>
#endif
#include <tier0/dbg.h> #include <tier0/dbg.h>
#include <tier1/utlhandletable.h> #include <tier1/utlhandletable.h>
#include "vgui_internal.h" #include "vgui_internal.h"

View File

@ -9,7 +9,11 @@
#include <stdio.h> #include <stdio.h>
#include <ctype.h> #include <ctype.h>
#include <assert.h> #include <assert.h>
#ifdef OSX
#include <malloc/malloc.h>
#else
#include <malloc.h> #include <malloc.h>
#endif
#include <vgui/IPanel.h> #include <vgui/IPanel.h>
#include <vgui/ISurface.h> #include <vgui/ISurface.h>

View File

@ -10,7 +10,11 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <math.h> #include <math.h>
#ifdef OSX
#include <malloc/malloc.h>
#else
#include <malloc.h> #include <malloc.h>
#endif
#include "vgui_surfacelib/BitmapFont.h" #include "vgui_surfacelib/BitmapFont.h"
#include "vgui_surfacelib/FontManager.h" #include "vgui_surfacelib/FontManager.h"
#include <tier0/dbg.h> #include <tier0/dbg.h>

View File

@ -12,7 +12,11 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <math.h> #include <math.h>
#ifdef OSX
#include <malloc/malloc.h>
#else
#include <malloc.h> #include <malloc.h>
#endif
#include <tier0/dbg.h> #include <tier0/dbg.h>
#include <vgui/ISurface.h> #include <vgui/ISurface.h>
#include <utlbuffer.h> #include <utlbuffer.h>

View File

@ -48,7 +48,11 @@ ILauncherMgr *g_pLauncherMgr = NULL;
#include "mathlib/vmatrix.h" #include "mathlib/vmatrix.h"
#include <tier0/vprof.h> #include <tier0/vprof.h>
#include "materialsystem/itexture.h" #include "materialsystem/itexture.h"
#ifdef OSX
#include <malloc/malloc.h>
#else
#include <malloc.h> #include <malloc.h>
#endif
#include "../vgui2/src/VPanel.h" #include "../vgui2/src/VPanel.h"
#include <vgui/IInputInternal.h> #include <vgui/IInputInternal.h>
#if defined( _X360 ) #if defined( _X360 )
@ -142,7 +146,7 @@ CMatSystemSurface g_MatSystemSurface;
EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CMatSystemSurface, ISurface, EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CMatSystemSurface, ISurface,
VGUI_SURFACE_INTERFACE_VERSION, g_MatSystemSurface ); VGUI_SURFACE_INTERFACE_VERSION, g_MatSystemSurface );
#ifdef LINUX #if defined(LINUX) || defined(OSX)
CUtlDict< CMatSystemSurface::font_entry, unsigned short > CMatSystemSurface::m_FontData; CUtlDict< CMatSystemSurface::font_entry, unsigned short > CMatSystemSurface::m_FontData;
#endif #endif
@ -403,7 +407,7 @@ InitReturnVal_t CMatSystemSurface::Init( void )
FontManager().SetLanguage( "english" ); FontManager().SetLanguage( "english" );
} }
#ifdef LINUX #if defined(LINUX) || defined(OSX)
FontManager().SetFontDataHelper( &CMatSystemSurface::FontDataHelper ); FontManager().SetFontDataHelper( &CMatSystemSurface::FontDataHelper );
#endif #endif
@ -1903,16 +1907,7 @@ bool CMatSystemSurface::AddCustomFontFile( const char *fontName, const char *fon
} }
Assert( success ); Assert( success );
return success; return success;
#elif OSX #elif defined(LINUX) || defined(OSX)
FSRef ref;
OSStatus err = FSPathMakeRef( (const UInt8*)fullPath, &ref, NULL );
if ( err == noErr )
err = ATSFontActivateFromFileReference( &ref, kATSFontContextLocal, kATSFontFormatUnspecified, NULL, kATSOptionFlagsDefault, NULL );
return err == noErr;
#elif LINUX
int size; int size;
if ( CMatSystemSurface::FontDataHelper( fontName, size, fontFileName ) ) if ( CMatSystemSurface::FontDataHelper( fontName, size, fontFileName ) )
@ -1926,7 +1921,7 @@ bool CMatSystemSurface::AddCustomFontFile( const char *fontName, const char *fon
#endif #endif
} }
#ifdef LINUX #if defined(LINUX) || defined(OSX)
static void RemoveSpaces( CUtlString &str ) static void RemoveSpaces( CUtlString &str )
{ {