29 #include "../../idlib/precompiled.h"
47 #pragma comment (lib, "wbemuuid.lib")
61 sys_timeBase = timeGetTime();
77 MEMORYSTATUSEX statex;
78 statex.dwLength =
sizeof ( statex );
79 GlobalMemoryStatusEx (&statex);
80 int physRam = statex.ullTotalPhys / ( 1024 * 1024 );
82 physRam = ( physRam + 8 ) & ~15;
94 DWORDLONG lpFreeBytesAvailable;
95 DWORDLONG lpTotalNumberOfBytes;
96 DWORDLONG lpTotalNumberOfFreeBytes;
99 if ( ::GetDiskFreeSpaceEx( path, (PULARGE_INTEGER)&lpFreeBytesAvailable, (PULARGE_INTEGER)&lpTotalNumberOfBytes, (PULARGE_INTEGER)&lpTotalNumberOfFreeBytes ) ) {
100 ret = ( double )( lpFreeBytesAvailable ) / ( 1024.0 * 1024.0 );
116 unsigned int retSize = 64;
118 CComPtr<IWbemLocator> spLoc =
NULL;
119 HRESULT hr = CoCreateInstance( CLSID_WbemLocator, 0, CLSCTX_SERVER, IID_IWbemLocator, (
LPVOID * ) &spLoc );
120 if ( hr != S_OK || spLoc ==
NULL ) {
124 CComBSTR bstrNamespace( _T(
"\\\\.\\root\\CIMV2" ) );
125 CComPtr<IWbemServices> spServices;
128 hr = spLoc->ConnectServer( bstrNamespace,
NULL,
NULL, 0,
NULL, 0, 0, &spServices );
129 if ( hr != WBEM_S_NO_ERROR ) {
134 hr = CoSetProxyBlanket( spServices, RPC_C_AUTHN_WINNT, RPC_C_AUTHZ_NONE,
NULL, RPC_C_AUTHN_LEVEL_CALL, RPC_C_IMP_LEVEL_IMPERSONATE,
NULL, EOAC_NONE );
140 CComPtr<IEnumWbemClassObject> spEnumInst =
NULL;
141 hr = spServices->CreateInstanceEnum( CComBSTR(
"Win32_VideoController" ), WBEM_FLAG_SHALLOW,
NULL, &spEnumInst );
142 if ( hr != WBEM_S_NO_ERROR || spEnumInst ==
NULL ) {
146 ULONG uNumOfInstances = 0;
147 CComPtr<IWbemClassObject> spInstance =
NULL;
148 hr = spEnumInst->Next( 10000, 1, &spInstance, &uNumOfInstances );
150 if ( hr == S_OK && spInstance ) {
153 hr = spInstance->Get( CComBSTR( _T(
"AdapterRAM" ) ), 0, &varSize, 0, 0 );
155 retSize = varSize.intVal / ( 1024 * 1024 );
156 if ( retSize == 0 ) {
174 MEMORYSTATUSEX statex;
175 unsigned __int64 work;
177 memset( &statex,
sizeof( statex ), 0 );
178 statex.dwLength =
sizeof( statex );
179 GlobalMemoryStatusEx( &statex );
181 memset( &stats, 0,
sizeof( stats ) );
185 work = statex.ullTotalPhys >> 20;
188 work = statex.ullAvailPhys >> 20;
191 work = statex.ullAvailPageFile >> 20;
194 work = statex.ullTotalPageFile >> 20;
197 work = statex.ullTotalVirtual >> 20;
200 work = statex.ullAvailVirtual >> 20;
203 work = statex.ullAvailExtendedVirtual >> 20;
213 return ( VirtualLock( ptr, (SIZE_T)bytes ) !=
FALSE );
222 return ( VirtualUnlock( ptr, (SIZE_T)bytes ) !=
FALSE );
231 ::SetProcessWorkingSetSize( GetCurrentProcess(), minBytes, maxBytes );
240 static char s_userName[1024];
241 unsigned long size =
sizeof( s_userName );
244 if ( !GetUserName( s_userName, &size ) ) {
245 strcpy( s_userName,
"player" );
248 if ( !s_userName[0] ) {
249 strcpy( s_userName,
"player" );
265 #define PROLOGUE_SIGNATURE 0x00EC8B55
270 UNDNAME_NO_ACCESS_SPECIFIERS |
271 UNDNAME_NO_FUNCTION_RETURNS |
272 UNDNAME_NO_ALLOCATION_MODEL |
273 UNDNAME_NO_ALLOCATION_LANGUAGE |
274 UNDNAME_NO_MEMBER_TYPE;
276 #if defined(_DEBUG) && 1
278 typedef struct symbol_s {
281 struct symbol_s * next;
284 typedef struct module_s {
288 struct module_s * next;
298 void SkipRestOfLine(
const char **ptr ) {
299 while( (**ptr) !=
'\0' && (**ptr) !=
'\n' && (**ptr) !=
'\r' ) {
302 while( (**ptr) ==
'\n' || (**ptr) ==
'\r' ) {
312 void SkipWhiteSpace(
const char **ptr ) {
313 while( (**ptr) ==
' ' ) {
323 int ParseHexNumber(
const char **ptr ) {
325 while( (**ptr) >=
'0' && (**ptr) <=
'9' || (**ptr) >=
'a' && (**ptr) <=
'f' ) {
327 if ( **ptr >=
'0' && **ptr <=
'9' ) {
328 n |= ( (**ptr) -
'0' );
330 n |= 10 + ( (**ptr) -
'a' );
344 MEMORY_BASIC_INFORMATION mbi;
346 VirtualQuery( (
void*)addr, &mbi,
sizeof(mbi) );
348 GetModuleFileName( (HMODULE)mbi.AllocationBase, moduleName,
sizeof( moduleName ) );
350 char *ext = moduleName + strlen( moduleName );
351 while( ext > moduleName && *ext !=
'.' ) {
354 if ( ext == moduleName ) {
355 strcat( moduleName,
".map" );
357 strcpy( ext,
".map" );
360 module_t *module = (module_t *) malloc(
sizeof( module_t ) );
361 module->name = (
char *) malloc( strlen( moduleName ) + 1 );
362 strcpy( module->name, moduleName );
363 module->address = (
int)mbi.AllocationBase;
364 module->symbols =
NULL;
365 module->next = modules;
368 FILE *fp = fopen( moduleName,
"rb" );
373 int pos = ftell( fp );
378 char *text = (
char *) malloc( length+1 );
379 fread( text, 1, length, fp );
383 const char *ptr = text;
386 while( *ptr !=
'\0' ) {
387 SkipWhiteSpace( &ptr );
389 SkipRestOfLine( &ptr );
392 SkipRestOfLine( &ptr );
401 while( *ptr !=
'\0' ) {
403 SkipWhiteSpace( &ptr );
405 ParseHexNumber( &ptr );
411 ParseHexNumber( &ptr );
413 SkipWhiteSpace( &ptr );
417 while( *ptr !=
'\0' && *ptr !=
' ' ) {
418 symbolName[symbolLength++] = *ptr++;
419 if ( symbolLength >=
sizeof( symbolName ) - 1 ) {
423 symbolName[symbolLength++] =
'\0';
425 SkipWhiteSpace( &ptr );
428 symbolAddress = ParseHexNumber( &ptr );
430 SkipRestOfLine( &ptr );
432 symbol = (symbol_t *) malloc(
sizeof( symbol_t ) );
433 symbol->name = (
char *) malloc( symbolLength );
434 strcpy( symbol->name, symbolName );
435 symbol->address = symbolAddress;
436 symbol->next = module->symbols;
437 module->symbols = symbol;
452 for ( m = modules; m !=
NULL; m = modules ) {
454 for ( s = m->symbols; s !=
NULL; s = m->symbols ) {
455 m->symbols = s->next;
471 MEMORY_BASIC_INFORMATION mbi;
475 VirtualQuery( (
void*)addr, &mbi,
sizeof(mbi) );
477 for ( m = modules; m !=
NULL; m = m->next ) {
478 if ( m->address == (
int) mbi.AllocationBase ) {
487 for ( s = m->symbols; s !=
NULL; s = s->next ) {
488 if ( s->address == addr ) {
491 if ( UnDecorateSymbolName( s->name, undName,
sizeof(undName),
UNDECORATE_FLAGS ) ) {
496 for (
int i = 0;
i < funcName.
Length();
i++ ) {
497 if ( funcName[
i] ==
'(' ) {
507 sprintf( funcName,
"0x%08x", addr );
511 #elif defined(_DEBUG)
513 DWORD lastAllocationBase = -1;
525 MEMORY_BASIC_INFORMATION mbi;
527 if ( lastAllocationBase != -1 ) {
531 VirtualQuery( (
void*)addr, &mbi,
sizeof(mbi) );
533 GetModuleFileName( (HMODULE)mbi.AllocationBase, moduleName,
sizeof( moduleName ) );
534 _splitpath( moduleName,
NULL,
NULL, modShortNameBuf,
NULL );
535 lastModule = modShortNameBuf;
537 processHandle = GetCurrentProcess();
538 if ( !SymInitialize( processHandle,
NULL,
FALSE ) ) {
541 if ( !SymLoadModule( processHandle,
NULL, moduleName,
NULL, (
DWORD)mbi.AllocationBase, 0 ) ) {
542 SymCleanup( processHandle );
546 SymSetOptions( SymGetOptions() & ~SYMOPT_UNDNAME );
548 lastAllocationBase = (
DWORD) mbi.AllocationBase;
557 SymUnloadModule( GetCurrentProcess(), lastAllocationBase );
558 SymCleanup( GetCurrentProcess() );
559 lastAllocationBase = -1;
568 MEMORY_BASIC_INFORMATION mbi;
570 VirtualQuery( (
void*)addr, &mbi,
sizeof(mbi) );
572 if ( (
DWORD) mbi.AllocationBase != lastAllocationBase ) {
577 PIMAGEHLP_SYMBOL pSymbol = (PIMAGEHLP_SYMBOL)&symbolBuffer[0];
578 pSymbol->SizeOfStruct =
sizeof(symbolBuffer);
579 pSymbol->MaxNameLength = 1023;
580 pSymbol->Address = 0;
584 DWORD symDisplacement = 0;
585 if ( SymGetSymFromAddr( processHandle, addr, &symDisplacement, pSymbol ) ) {
588 if ( UnDecorateSymbolName( pSymbol->Name, undName,
sizeof(undName),
UNDECORATE_FLAGS ) ) {
591 funcName = pSymbol->Name;
597 FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
600 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
605 LocalFree( lpMsgBuf );
608 sprintf( funcName,
"0x%08x", addr );
638 sprintf( funcName,
"0x%08x", addr );
651 temp = (long)(*(
long*)midPtPtr);
702 m_ebp = *((
long*)m_ebp);
703 m_ebp = *((
long*)m_ebp);
705 for ( i = 0; i < callStackSize; i++ ) {
707 if ( callStack[i] == 0 ) {
710 m_ebp = *((
long*)m_ebp);
715 while( i < callStackSize ) {
728 idStr module, funcName;
731 for ( i = callStackSize-1; i >= 0; i-- ) {
733 index +=
sprintf(
string+index,
" -> %s", funcName.
c_str() );
765 for ( i = depth-1; i >= 0; i-- ) {
766 index +=
sprintf(
string+index,
" -> 0x%08x", callStack[i] );
char * Sys_GetCurrentUser(void)
void Sys_SetPhysicalWorkMemory(int minBytes, int maxBytes)
unsigned long sys_timeBase
void Sym_GetFuncInfo(long addr, idStr &module, idStr &funcName)
void Sys_GetCurrentMemoryStatus(sysMemoryStats_t &stats)
int Sys_GetDriveFreeSpace(const char *path)
address_t GetCallerAddr(long _ebp)
typedef HANDLE(WINAPI *PFNWGLCREATEBUFFERREGIONARBPROC)(HDC hDC
GLint GLint GLsizei GLsizei GLsizei depth
GLenum GLsizei const GLvoid * string
const int UNDECORATE_FLAGS
bool Sys_LockMemory(void *ptr, int bytes)
int Cmpn(const char *text, int n) const
void Sys_GetCallStack(address_t *callStack, const int callStackSize)
const char * Sys_GetCallStackCurStr(int depth)
#define PROLOGUE_SIGNATURE
const char * Sys_GetCallStackStr(const address_t *callStack, const int callStackSize)
int Sys_Milliseconds(void)
GLenum const GLvoid * addr
int Sys_GetVideoRam(void)
void Sys_ShutdownSymbols(void)
GLsizei const GLcharARB const GLint * length
typedef LPVOID(WINAPI *PFNWGLCREATEIMAGEBUFFERI3DPROC)(HDC hDC
const char * c_str(void) const
const char * Sys_GetCallStackCurAddressStr(int depth)
int Sys_GetSystemRam(void)
address_t GetFuncAddr(address_t midPtPtr)
int sprintf(idStr &string, const char *fmt,...)
bool Sys_UnlockMemory(void *ptr, int bytes)
LPDIRECTSOUND IUnknown FAR *typedef HRESULT(FAR PASCAL *LPEAXDIRECTSOUNDCREATE)(GUID *