mirror of
https://github.com/nillerusr/source-engine.git
synced 2026-08-07 17:29:36 +00:00
Merge branch 'master' into windows
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
//
|
||||
// Generated from the TEXTINCLUDE 2 resource.
|
||||
//
|
||||
#include "afxres.h"
|
||||
#include "Windows.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#undef APSTUDIO_READONLY_SYMBOLS
|
||||
|
||||
+48
-32
@@ -20,11 +20,23 @@
|
||||
|
||||
const tchar* GetProcessorVendorId();
|
||||
|
||||
static bool cpuid(unsigned long function, unsigned long& out_eax, unsigned long& out_ebx, unsigned long& out_ecx, unsigned long& out_edx)
|
||||
static bool cpuid(uint32 function, uint32& out_eax, uint32& out_ebx, uint32& out_ecx, uint32& out_edx)
|
||||
{
|
||||
#if defined (__arm__) || defined( _X360 )
|
||||
#if defined (__arm__) || defined (__aarch64__) || defined( _X360 )
|
||||
return false;
|
||||
#elif defined(GNUC)
|
||||
|
||||
#if defined(PLATFORM_64BITS)
|
||||
asm("mov %%rbx, %%rsi\n\t"
|
||||
"cpuid\n\t"
|
||||
"xchg %%rsi, %%rbx"
|
||||
: "=a" (out_eax),
|
||||
"=S" (out_ebx),
|
||||
"=c" (out_ecx),
|
||||
"=d" (out_edx)
|
||||
: "a" (function)
|
||||
);
|
||||
#else
|
||||
asm("mov %%ebx, %%esi\n\t"
|
||||
"cpuid\n\t"
|
||||
"xchg %%esi, %%ebx"
|
||||
@@ -34,7 +46,9 @@ static bool cpuid(unsigned long function, unsigned long& out_eax, unsigned long&
|
||||
"=d" (out_edx)
|
||||
: "a" (function)
|
||||
);
|
||||
#endif
|
||||
return true;
|
||||
|
||||
#elif defined(_WIN64)
|
||||
int pCPUInfo[4];
|
||||
__cpuid( pCPUInfo, (int)function );
|
||||
@@ -45,7 +59,7 @@ static bool cpuid(unsigned long function, unsigned long& out_eax, unsigned long&
|
||||
return true;
|
||||
#else
|
||||
bool retval = true;
|
||||
unsigned long local_eax, local_ebx, local_ecx, local_edx;
|
||||
uint32 local_eax, local_ebx, local_ecx, local_edx;
|
||||
_asm pushad;
|
||||
|
||||
__try
|
||||
@@ -83,7 +97,7 @@ static bool CheckMMXTechnology(void)
|
||||
#if defined( _X360 ) || defined( _PS3 )
|
||||
return true;
|
||||
#else
|
||||
unsigned long eax,ebx,edx,unused;
|
||||
uint32 eax,ebx,edx,unused;
|
||||
if ( !cpuid(1,eax,ebx,unused,edx) )
|
||||
return false;
|
||||
|
||||
@@ -142,7 +156,7 @@ static bool IsWin98OrOlder()
|
||||
|
||||
static bool CheckSSETechnology(void)
|
||||
{
|
||||
#if defined( __ARM__ )
|
||||
#if defined(__SANITIZE_ADDRESS__) || defined (__arm__)
|
||||
return false;
|
||||
#elif defined( _X360 ) || defined( _PS3 )
|
||||
return true;
|
||||
@@ -151,7 +165,7 @@ static bool CheckSSETechnology(void)
|
||||
return false;
|
||||
}
|
||||
|
||||
unsigned long eax,ebx,edx,unused;
|
||||
uint32 eax,ebx,edx,unused;
|
||||
if ( !cpuid(1,eax,ebx,unused,edx) ) {
|
||||
return false;
|
||||
}
|
||||
@@ -162,10 +176,10 @@ static bool CheckSSETechnology(void)
|
||||
|
||||
static bool CheckSSE2Technology(void)
|
||||
{
|
||||
#if defined( _X360 ) || defined( _PS3 )
|
||||
#if defined( _X360 ) || defined( _PS3 ) || defined(__SANITIZE_ADDRESS__) || defined (__arm__)
|
||||
return false;
|
||||
#else
|
||||
unsigned long eax,ebx,edx,unused;
|
||||
uint32 eax,ebx,edx,unused;
|
||||
if ( !cpuid(1,eax,ebx,unused,edx) )
|
||||
return false;
|
||||
|
||||
@@ -175,10 +189,10 @@ static bool CheckSSE2Technology(void)
|
||||
|
||||
bool CheckSSE3Technology(void)
|
||||
{
|
||||
#if defined( _X360 ) || defined( _PS3 )
|
||||
#if defined( _X360 ) || defined( _PS3 ) || defined(__SANITIZE_ADDRESS__) || defined (__arm__)
|
||||
return false;
|
||||
#else
|
||||
unsigned long eax,ebx,edx,ecx;
|
||||
uint32 eax,ebx,edx,ecx;
|
||||
if( !cpuid(1,eax,ebx,ecx,edx) )
|
||||
return false;
|
||||
|
||||
@@ -188,12 +202,12 @@ bool CheckSSE3Technology(void)
|
||||
|
||||
bool CheckSSSE3Technology(void)
|
||||
{
|
||||
#if defined( _X360 ) || defined( _PS3 )
|
||||
#if defined( _X360 ) || defined( _PS3 ) || defined(__SANITIZE_ADDRESS__) || defined (__arm__)
|
||||
return false;
|
||||
#else
|
||||
// SSSE 3 is implemented by both Intel and AMD
|
||||
// detection is done the same way for both vendors
|
||||
unsigned long eax,ebx,edx,ecx;
|
||||
uint32 eax,ebx,edx,ecx;
|
||||
if( !cpuid(1,eax,ebx,ecx,edx) )
|
||||
return false;
|
||||
|
||||
@@ -203,13 +217,13 @@ bool CheckSSSE3Technology(void)
|
||||
|
||||
bool CheckSSE41Technology(void)
|
||||
{
|
||||
#if defined( _X360 ) || defined( _PS3 )
|
||||
#if defined( _X360 ) || defined( _PS3 ) || defined(__SANITIZE_ADDRESS__) || defined (__arm__)
|
||||
return false;
|
||||
#else
|
||||
// SSE 4.1 is implemented by both Intel and AMD
|
||||
// detection is done the same way for both vendors
|
||||
|
||||
unsigned long eax,ebx,edx,ecx;
|
||||
uint32 eax,ebx,edx,ecx;
|
||||
if( !cpuid(1,eax,ebx,ecx,edx) )
|
||||
return false;
|
||||
|
||||
@@ -219,7 +233,7 @@ bool CheckSSE41Technology(void)
|
||||
|
||||
bool CheckSSE42Technology(void)
|
||||
{
|
||||
#if defined( _X360 ) || defined( _PS3 )
|
||||
#if defined( _X360 ) || defined( _PS3 ) || defined(__SANITIZE_ADDRESS__) || defined (__arm__)
|
||||
return false;
|
||||
#else
|
||||
// SSE4.2 is an Intel-only feature
|
||||
@@ -228,7 +242,7 @@ bool CheckSSE42Technology(void)
|
||||
if ( 0 != V_tier0_stricmp( pchVendor, "GenuineIntel" ) )
|
||||
return false;
|
||||
|
||||
unsigned long eax,ebx,edx,ecx;
|
||||
uint32 eax,ebx,edx,ecx;
|
||||
if( !cpuid(1,eax,ebx,ecx,edx) )
|
||||
return false;
|
||||
|
||||
@@ -239,7 +253,7 @@ bool CheckSSE42Technology(void)
|
||||
|
||||
bool CheckSSE4aTechnology( void )
|
||||
{
|
||||
#if defined( _X360 ) || defined( _PS3 )
|
||||
#if defined( _X360 ) || defined( _PS3 ) || defined(__SANITIZE_ADDRESS__) || defined (__arm__)
|
||||
return false;
|
||||
#else
|
||||
// SSE 4a is an AMD-only feature
|
||||
@@ -248,7 +262,7 @@ bool CheckSSE4aTechnology( void )
|
||||
if ( 0 != V_tier0_stricmp( pchVendor, "AuthenticAMD" ) )
|
||||
return false;
|
||||
|
||||
unsigned long eax,ebx,edx,ecx;
|
||||
uint32 eax,ebx,edx,ecx;
|
||||
if( !cpuid( 0x80000001,eax,ebx,ecx,edx) )
|
||||
return false;
|
||||
|
||||
@@ -259,10 +273,10 @@ bool CheckSSE4aTechnology( void )
|
||||
|
||||
static bool Check3DNowTechnology(void)
|
||||
{
|
||||
#if defined( _X360 ) || defined( _PS3 )
|
||||
#if defined( _X360 ) || defined( _PS3 ) || defined (__arm__) || defined(__SANITIZE_ADDRESS__)
|
||||
return false;
|
||||
#else
|
||||
unsigned long eax, unused;
|
||||
uint32 eax, unused;
|
||||
if ( !cpuid(0x80000000,eax,unused,unused,unused) )
|
||||
return false;
|
||||
|
||||
@@ -279,10 +293,10 @@ static bool Check3DNowTechnology(void)
|
||||
|
||||
static bool CheckCMOVTechnology()
|
||||
{
|
||||
#if defined( _X360 ) || defined( _PS3 )
|
||||
#if defined( _X360 ) || defined( _PS3 ) || defined (__arm__) || defined(__SANITIZE_ADDRESS__)
|
||||
return false;
|
||||
#else
|
||||
unsigned long eax,ebx,edx,unused;
|
||||
uint32 eax,ebx,edx,unused;
|
||||
if ( !cpuid(1,eax,ebx,unused,edx) )
|
||||
return false;
|
||||
|
||||
@@ -292,10 +306,10 @@ static bool CheckCMOVTechnology()
|
||||
|
||||
static bool CheckFCMOVTechnology(void)
|
||||
{
|
||||
#if defined( _X360 ) || defined( _PS3 )
|
||||
#if defined( _X360 ) || defined( _PS3 ) || defined (__arm__) || defined(__SANITIZE_ADDRESS__)
|
||||
return false;
|
||||
#else
|
||||
unsigned long eax,ebx,edx,unused;
|
||||
uint32 eax,ebx,edx,unused;
|
||||
if ( !cpuid(1,eax,ebx,unused,edx) )
|
||||
return false;
|
||||
|
||||
@@ -305,10 +319,10 @@ static bool CheckFCMOVTechnology(void)
|
||||
|
||||
static bool CheckRDTSCTechnology(void)
|
||||
{
|
||||
#if defined( _X360 ) || defined( _PS3 )
|
||||
#if defined( _X360 ) || defined( _PS3 ) || defined (__arm__) || defined(__SANITIZE_ADDRESS__)
|
||||
return false;
|
||||
#else
|
||||
unsigned long eax,ebx,edx,unused;
|
||||
uint32 eax,ebx,edx,unused;
|
||||
if ( !cpuid(1,eax,ebx,unused,edx) )
|
||||
return false;
|
||||
|
||||
@@ -321,11 +335,13 @@ const tchar* GetProcessorVendorId()
|
||||
{
|
||||
#if defined( _X360 ) || defined( _PS3 )
|
||||
return "PPC";
|
||||
#elif defined ( __arm__ )
|
||||
return "ARM";
|
||||
#else
|
||||
unsigned long unused, VendorIDRegisters[3];
|
||||
uint32 unused, VendorIDRegisters[3];
|
||||
|
||||
static tchar VendorID[13];
|
||||
|
||||
|
||||
memset( VendorID, 0, sizeof(VendorID) );
|
||||
if ( !cpuid(0,unused, VendorIDRegisters[0], VendorIDRegisters[2], VendorIDRegisters[1] ) )
|
||||
{
|
||||
@@ -363,7 +379,7 @@ static bool HTSupported(void)
|
||||
const unsigned int EXT_FAMILY_ID = 0x0f00000; // EAX[23:20] - Bit 23 thru 20 contains extended family processor id
|
||||
const unsigned int PENTIUM4_ID = 0x0f00; // Pentium 4 family processor id
|
||||
|
||||
unsigned long unused,
|
||||
uint32 unused,
|
||||
reg_eax = 0,
|
||||
reg_edx = 0,
|
||||
vendor_id[3] = {0, 0, 0};
|
||||
@@ -375,7 +391,7 @@ static bool HTSupported(void)
|
||||
|
||||
// Check to see if this is a Pentium 4 or later processor
|
||||
if (((reg_eax & FAMILY_ID) == PENTIUM4_ID) || (reg_eax & EXT_FAMILY_ID))
|
||||
if (vendor_id[0] == 'uneG' && vendor_id[1] == 'Ieni' && vendor_id[2] == 'letn')
|
||||
if (vendor_id[0] == 0x756E6547 && vendor_id[1] == 0x49656E69 && vendor_id[2] == 0x6C65746E)
|
||||
return (reg_edx & HT_BIT) != 0; // Genuine Intel Processor with Hyper-Threading Technology
|
||||
|
||||
return false; // This is not a genuine Intel processor.
|
||||
@@ -391,7 +407,7 @@ static uint8 LogicalProcessorsPerPackage(void)
|
||||
// EBX[23:16] indicate number of logical processors per package
|
||||
const unsigned NUM_LOGICAL_BITS = 0x00FF0000;
|
||||
|
||||
unsigned long unused, reg_ebx = 0;
|
||||
uint32 unused, reg_ebx = 0;
|
||||
|
||||
if ( !HTSupported() )
|
||||
return 1;
|
||||
@@ -580,7 +596,7 @@ const CPUInformation* GetCPUInformation()
|
||||
pi.m_szProcessorID = (tchar*)GetProcessorVendorId();
|
||||
pi.m_bHT = HTSupported();
|
||||
|
||||
unsigned long eax, ebx, edx, ecx;
|
||||
uint32 eax, ebx, edx, ecx;
|
||||
if (cpuid(1, eax, ebx, ecx, edx))
|
||||
{
|
||||
pi.m_nModel = eax; // full CPU model info
|
||||
|
||||
+11
-1
@@ -99,6 +99,15 @@ uint64 GetCPUFreqFromPROC()
|
||||
|
||||
uint64 CalculateCPUFreq()
|
||||
{
|
||||
#ifdef __APPLE__
|
||||
uint64 freq_hz = 0;
|
||||
size_t freq_size = sizeof(freq_hz);
|
||||
int retval = sysctlbyname("hw.cpufrequency_max", &freq_hz, &freq_size, NULL, 0);
|
||||
// MoeMod : TODO dont know how to get freq on Apple Silicon
|
||||
if(!freq_hz)
|
||||
freq_hz = 3200000000;
|
||||
return freq_hz;
|
||||
#else
|
||||
// Try to open cpuinfo_max_freq. If the kernel was built with cpu scaling support disabled, this will fail.
|
||||
FILE *fp = fopen( "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq", "r" );
|
||||
if ( fp )
|
||||
@@ -118,8 +127,9 @@ uint64 CalculateCPUFreq()
|
||||
return retVal * 1000;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef __arm__
|
||||
#if !defined(__arm__) && !defined(__aarch64__)
|
||||
// Compute the period. Loop until we get 3 consecutive periods that
|
||||
// are the same to within a small error. The error is chosen
|
||||
// to be +/- 0.02% on a P-200.
|
||||
|
||||
+85
-9
@@ -14,10 +14,15 @@
|
||||
#define WIN_32_LEAN_AND_MEAN
|
||||
#include <windows.h> // Currently needed for IsBadReadPtr and IsBadWritePtr
|
||||
#pragma comment(lib,"user32.lib") // For MessageBox
|
||||
#include <time.h>
|
||||
#endif
|
||||
|
||||
#include <assert.h>
|
||||
#ifdef OSX
|
||||
#include <malloc/malloc.h>
|
||||
#else
|
||||
#include <malloc.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
@@ -45,12 +50,82 @@
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
class CDbgLogger : public IDbgLogger
|
||||
{
|
||||
public:
|
||||
CDbgLogger();
|
||||
~CDbgLogger();
|
||||
|
||||
void Init(const char *logfile);
|
||||
void Write(const char *data);
|
||||
|
||||
private:
|
||||
FILE *file;
|
||||
float flStartTime;
|
||||
bool bShouldLog;
|
||||
};
|
||||
|
||||
|
||||
CDbgLogger::CDbgLogger()
|
||||
{
|
||||
bShouldLog = false;
|
||||
flStartTime = Plat_FloatTime();
|
||||
}
|
||||
|
||||
void CDbgLogger::Init(const char *logfile)
|
||||
{
|
||||
time_t timeCur;
|
||||
struct tm tmStruct;
|
||||
|
||||
char szTime[256];
|
||||
|
||||
bShouldLog = true;
|
||||
|
||||
time( &timeCur );
|
||||
Plat_gmtime( &timeCur, &tmStruct );
|
||||
Plat_ctime( &timeCur, szTime, sizeof(szTime) );
|
||||
|
||||
file = fopen(logfile, "w+");
|
||||
fprintf(file, ">>> Engine started at %s\n", szTime);
|
||||
fflush(file);
|
||||
}
|
||||
|
||||
CDbgLogger::~CDbgLogger()
|
||||
{
|
||||
if( !bShouldLog )
|
||||
return;
|
||||
|
||||
time_t timeCur;
|
||||
struct tm tmStruct;
|
||||
|
||||
char szTime[256];
|
||||
|
||||
time( &timeCur );
|
||||
Plat_gmtime( &timeCur, &tmStruct );
|
||||
Plat_ctime( &timeCur, szTime, sizeof(szTime) );
|
||||
|
||||
fprintf(file, "\n>>> Engine closed at %s\n", szTime);
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
void CDbgLogger::Write(const char *data)
|
||||
{
|
||||
if( !bShouldLog )
|
||||
return;
|
||||
|
||||
fprintf(file, "[%.4f] ", Plat_FloatTime() - flStartTime);
|
||||
fprintf(file, "%s", data);
|
||||
fflush(file);
|
||||
}
|
||||
|
||||
static CDbgLogger g_DbgLogger;
|
||||
IDbgLogger *DebugLogger() { return &g_DbgLogger; }
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// internal structures
|
||||
//-----------------------------------------------------------------------------
|
||||
enum
|
||||
{
|
||||
enum
|
||||
{
|
||||
MAX_GROUP_NAME_LENGTH = 48
|
||||
};
|
||||
|
||||
@@ -148,7 +223,7 @@ struct SpewInfo_t
|
||||
int m_nSpewOutputLevel;
|
||||
};
|
||||
|
||||
CThreadLocalPtr<SpewInfo_t> g_pSpewInfo;
|
||||
CTHREADLOCALPTR(SpewInfo_t) g_pSpewInfo;
|
||||
|
||||
|
||||
// Standard groups
|
||||
@@ -272,7 +347,7 @@ DBG_INTERFACE void _SpewInfo( SpewType_t type, const tchar* pFile, int line )
|
||||
|
||||
static SpewRetval_t _SpewMessage( SpewType_t spewType, const char *pGroupName, int nLevel, const Color *pColor, const tchar* pMsgFormat, va_list args )
|
||||
{
|
||||
tchar pTempBuffer[5020];
|
||||
tchar pTempBuffer[8192];
|
||||
|
||||
assert( _tcslen( pMsgFormat ) < sizeof( pTempBuffer) ); // check that we won't artifically truncate the string
|
||||
|
||||
@@ -285,7 +360,7 @@ static SpewRetval_t _SpewMessage( SpewType_t spewType, const char *pGroupName, i
|
||||
|
||||
if ( len == -1 )
|
||||
return SPEW_ABORT;
|
||||
|
||||
|
||||
/* Create the message.... */
|
||||
int val= _vsntprintf( &pTempBuffer[len], sizeof( pTempBuffer ) - len - 1, pMsgFormat, args );
|
||||
if ( val == -1 )
|
||||
@@ -299,10 +374,10 @@ static SpewRetval_t _SpewMessage( SpewType_t spewType, const char *pGroupName, i
|
||||
{
|
||||
len += _stprintf( &pTempBuffer[len], _T("\n") );
|
||||
}
|
||||
|
||||
|
||||
assert( len < sizeof(pTempBuffer)/sizeof(pTempBuffer[0]) - 1 ); /* use normal assert here; to avoid recursion. */
|
||||
assert( s_SpewOutputFunc );
|
||||
|
||||
|
||||
/* direct it to the appropriate target(s) */
|
||||
SpewRetval_t ret;
|
||||
assert( g_pSpewInfo == NULL );
|
||||
@@ -314,12 +389,13 @@ static SpewRetval_t _SpewMessage( SpewType_t spewType, const char *pGroupName, i
|
||||
};
|
||||
|
||||
#ifdef ANDROID
|
||||
__android_log_print( ANDROID_LOG_INFO, "SRCENG", "%s", pTempBuffer );
|
||||
__android_log_print( ANDROID_LOG_INFO, "SRCENG", "%s", pTempBuffer );
|
||||
#endif
|
||||
g_DbgLogger.Write( pTempBuffer );
|
||||
|
||||
g_pSpewInfo = &spewInfo;
|
||||
ret = s_SpewOutputFunc( spewType, pTempBuffer );
|
||||
g_pSpewInfo = (int)NULL;
|
||||
g_pSpewInfo = NULL;
|
||||
|
||||
switch (ret)
|
||||
{
|
||||
|
||||
@@ -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"
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
|
||||
#if ( (!defined( POSIX )||defined(_GAMECONSOLE)) && (defined(_DEBUG) || defined(USE_MEM_DEBUG) ) )
|
||||
#define MEM_IMPL_TYPE_DBG 1
|
||||
#else
|
||||
#define MEM_IMPL_TYPE_STD 1
|
||||
#endif
|
||||
+24
-12
@@ -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 __aarch64__
|
||||
// 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 __aarch64__
|
||||
// MoeMod : this is required for Apple Silicon
|
||||
pthread_jit_write_protect_np(true);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+6
-2
@@ -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>
|
||||
@@ -309,8 +313,8 @@ public:
|
||||
virtual void InitDebugInfo( void *pvDebugInfo, const char *pchRootFileName, 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 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; }
|
||||
|
||||
|
||||
+6
-2
@@ -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; }
|
||||
|
||||
|
||||
@@ -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 );
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
+1839
-983
File diff suppressed because it is too large
Load Diff
+3
-3
@@ -135,7 +135,7 @@ void ValidateBuckets()
|
||||
}
|
||||
}
|
||||
|
||||
unsigned PopThreadFunc( void *)
|
||||
uintp PopThreadFunc( void *)
|
||||
{
|
||||
ThreadSetDebugName( "PopThread" );
|
||||
g_nPopThreads++;
|
||||
@@ -165,7 +165,7 @@ unsigned PopThreadFunc( void *)
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned PushThreadFunc( void * )
|
||||
uintp PushThreadFunc( void * )
|
||||
{
|
||||
ThreadSetDebugName( "PushThread" );
|
||||
g_nPushThreads++;
|
||||
@@ -306,7 +306,7 @@ void PushPopInterleavedTest()
|
||||
TestEnd();
|
||||
}
|
||||
|
||||
unsigned PushPopInterleavedTestThreadFunc( void * )
|
||||
uintp PushPopInterleavedTestThreadFunc( void * )
|
||||
{
|
||||
ThreadSetDebugName( "PushPopThread" );
|
||||
g_nThreads++;
|
||||
|
||||
+1
-1
@@ -1543,7 +1543,7 @@ void* VCR_CreateThread(
|
||||
void *lpStartAddress,
|
||||
void *lpParameter,
|
||||
unsigned long dwCreationFlags,
|
||||
unsigned long *lpThreadID )
|
||||
uintp *lpThreadID )
|
||||
{
|
||||
unsigned dwThreadID = 0;
|
||||
|
||||
|
||||
@@ -859,7 +859,7 @@ void* VCR_CreateThread(
|
||||
void *lpStartAddress,
|
||||
void *lpParameter,
|
||||
unsigned long dwCreationFlags,
|
||||
unsigned long *lpThreadID )
|
||||
uintp *lpThreadID )
|
||||
{
|
||||
return CreateSimpleThread( (ThreadFunc_t)lpStartAddress, lpParameter, lpThreadID, 0 );
|
||||
}
|
||||
|
||||
+1
-1
@@ -1516,7 +1516,7 @@ void CVProfile::Term()
|
||||
{
|
||||
delete [] m_pBudgetGroups[i].m_pName;
|
||||
}
|
||||
delete m_pBudgetGroups;
|
||||
delete[] m_pBudgetGroups;
|
||||
m_nBudgetGroupNames = m_nBudgetGroupNamesAllocated = 0;
|
||||
m_pBudgetGroups = NULL;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user