• R/O
  • SSH
  • HTTPS

eirdebug: Commit


Commit MetaInfo

Revision5 (tree)
Zeit2018-02-12 08:45:48
Autorquiret

Log Message

- fixed up dbgheap.cpp to compile for Linux (does not mean that it will work anyway!!!)

Ändern Zusammenfassung

Diff

--- dbgheap.cpp (revision 4)
+++ dbgheap.cpp (revision 5)
@@ -13,12 +13,14 @@
1313
1414 #ifdef _DEBUG_TRACE_LIBRARY_
1515 #include "dbgtrace.h"
16-#endif //_DEBUG_TRACE_LIBRARY_
16+#endif //_DEBUG_TRACE_LIBRARY_
17+
18+#include <string.h>
19+#include <stdio.h>
20+#include <stdarg.h>
21+
22+#include <sdk/MacroUtils.h>
1723
18-#ifndef AINLINE
19-#define AINLINE __forceinline
20-#endif //AINLINE
21-
2224 /*
2325 DebugHeap memory debugging environment
2426
@@ -90,8 +92,12 @@
9092 #endif //MEM_INTERRUPT
9193
9294 typedef NativePageAllocator DebugFullPageHeapAllocator;
93-
94-SYSTEM_INFO g_systemInfo;
95+
96+#ifdef _WIN32
97+SYSTEM_INFO g_systemInfo;
98+#elif defined(__linux__)
99+unsigned long g_pageSize;
100+#endif //_WIN32
95101 DebugFullPageHeapAllocator *_nativeAlloc = NULL;
96102 pfnMemoryAllocWatch _memAllocWatchCallback = NULL;
97103
@@ -98,9 +104,15 @@
98104 #ifdef USE_FULL_PAGE_HEAP
99105
100106 // Since we know that memory is allocated along pages, we can check for
101-// invalid pointers given to the manager.
102-#define PAGE_MEM_ADJUST( ptr ) (void*)( (char*)ptr - ( (size_t)ptr % g_systemInfo.dwPageSize ) )
107+// invalid pointers given to the manager.
108+#ifdef _WIN32
109+#define _PAGE_SIZE_ACTUAL ( g_systemInfo.dwPageSize )
110+#elif defined(__linux__)
111+#define _PAGE_SIZE_ACTUAL ( g_pageSize )
112+#endif //CROSS PLATFORM MACRO
103113
114+#define PAGE_MEM_ADJUST( ptr ) (void*)( (char*)ptr - ( (size_t)ptr % _PAGE_SIZE_ACTUAL ) )
115+
104116 inline static void* _win32_allocMemPage( size_t memSize )
105117 {
106118 DebugFullPageHeapAllocator::pageHandle *handle = _nativeAlloc->Allocate( NULL, memSize );
@@ -141,7 +153,7 @@
141153 #define PAGE_MEM_ACTIVE_DEBUG_PATTERN 0x11
142154 #endif //PAGE_MEM_ACTIVE_DEBUG_PATTERN
143155
144-#define MEM_PAGE_MOD( bytes ) ( ( (bytes) + g_systemInfo.dwPageSize - 1 ) / g_systemInfo.dwPageSize )
156+#define MEM_PAGE_MOD( bytes ) ( ( (bytes) + _PAGE_SIZE_ACTUAL - 1 ) / _PAGE_SIZE_ACTUAL )
145157
146158 #pragma pack(1)
147159 struct _memIntro
@@ -171,7 +183,7 @@
171183
172184 inline static size_t _win32_getRealPageSize( size_t objSize )
173185 {
174- return ( MEM_PAGE_MOD( _getMetaSize( objSize ) ) * g_systemInfo.dwPageSize );
186+ return ( MEM_PAGE_MOD( _getMetaSize( objSize ) ) * _PAGE_SIZE_ACTUAL );
175187 }
176188
177189 inline static void* _win32_allocMem( size_t memSize )
@@ -363,10 +375,14 @@
363375 va_list argv;
364376
365377 va_start( argv, fmt );
366- _vsnprintf( buf, sizeof( buf ), fmt, argv );
378+ vsnprintf( buf, sizeof( buf ), fmt, argv );
367379 va_end( argv );
368-
369- OutputDebugStringA( buf );
380+
381+#ifdef _WIN32
382+ OutputDebugStringA( buf );
383+#elif defined(__linux__)
384+ printf( "%s\n", buf );
385+#endif //CROSS PLATFORM CODE
370386 }
371387 #endif //PAGE_HEAP_MEMORY_STATS
372388
@@ -400,16 +416,16 @@
400416 #ifdef PAGE_HEAP_MEMORY_STATS
401417 if ( blockCount != 0 )
402418 {
403- OutputDebugStringW( L"Heap Memory Leak Protocol:\n" );
419+ OutputDebugStringFormat( "Heap Memory Leak Protocol:\n" );
404420 OutputDebugStringFormat(
405421 "* leaked memory: %u\n" \
406422 "* blocks/pages allocated: %u/%u [%u]\n",
407423 memLeaked,
408- blockCount, pageCount, blockCount * g_systemInfo.dwPageSize
424+ blockCount, pageCount, blockCount * _PAGE_SIZE_ACTUAL
409425 );
410426 }
411427 else
412- OutputDebugStringW( L"No memory leaks detected." );
428+ OutputDebugStringFormat( "No memory leaks detected." );
413429 #endif //PAGE_HEAP_MEMORY_STATS
414430 }
415431
@@ -812,7 +828,7 @@
812828 return mem;
813829 }
814830
815-void* operator new( size_t memSize, const std::nothrow_t ) noexcept
831+void* operator new( size_t memSize, const std::nothrow_t& ) noexcept
816832 {
817833 MEM_INTERRUPT( memSize != 0 );
818834
@@ -831,7 +847,7 @@
831847 return mem;
832848 }
833849
834-void* operator new[]( size_t memSize, const std::nothrow_t ) noexcept
850+void* operator new[]( size_t memSize, const std::nothrow_t& ) noexcept
835851 {
836852 MEM_INTERRUPT( memSize != 0 );
837853
@@ -883,8 +899,12 @@
883899 // Call it before CRT initialization.
884900 void DbgHeap_Init( void )
885901 {
886-#ifdef USE_HEAP_DEBUGGING
887- GetSystemInfo( &g_systemInfo );
902+#ifdef USE_HEAP_DEBUGGING
903+#ifdef _WIN32
904+ GetSystemInfo( &g_systemInfo );
905+#elif defined(__linux__)
906+ g_pageSize = (unsigned long)sysconf(_SC_PAGESIZE);
907+#endif //CROSS PLATFORM CODE
888908
889909 // Initialize watch callbacks.
890910 _memAllocWatchCallback = NULL;
@@ -961,8 +981,12 @@
961981 // Alternative entry point.
962982 extern "C"
963983 {
964-#ifdef _DEBUGSDK_CRT_STARTUP
965-extern int mainCRTStartup( void );
984+#ifdef _DEBUGSDK_CRT_STARTUP
985+#ifdef _WIN32
986+extern int mainCRTStartup( void );
987+#elif defined(__linux__)
988+extern int _start( void );
989+#endif //CROSS PLATFORM CODE
966990 #elif defined(_DEBUGSDK_WIN32_STARTUP)
967991 extern int _WinMainCRTStartup( void );
968992 #elif defined(_DEBUGSDK_WIN32DLL_STARTUP)
@@ -973,10 +997,12 @@
973997 extern BOOL WINAPI _DllMainCRTStartup(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved);
974998 #endif
975999 }
976-
977-#define ENTRYPOINTCALL __stdcall
9781000
9791001 #ifdef _WIN32
1002+#define ENTRYPOINTCALL __stdcall
1003+#else
1004+#define ENTRYPOINTCALL
1005+#endif //CROSS PLATFORM MACRO
9801006
9811007 #ifdef _DEBUGSDK_CRT_STARTUP
9821008 extern "C" int ENTRYPOINTCALL _DebugInit( void )
@@ -996,8 +1022,12 @@
9961022 DbgTrace_Init( stackSpace );
9971023 #endif
9981024
999-#ifdef _DEBUGSDK_CRT_STARTUP
1000- int ret = mainCRTStartup();
1025+#ifdef _DEBUGSDK_CRT_STARTUP
1026+#ifdef _WIN32
1027+ int ret = mainCRTStartup();
1028+#elif defined(__linux__)
1029+ int ret = _start();
1030+#endif //CROSS PLATFORM CODE
10011031 #elif defined(_DEBUGSDK_WIN32_STARTUP)
10021032 int ret = _WinMainCRTStartup();
10031033 #elif defined(_DEBUGSDK_WIN32DLL_STARTUP)
@@ -1012,5 +1042,3 @@
10121042 DbgHeap_Shutdown();
10131043 return ret;
10141044 }
1015-
1016-#endif //_WIN32
--- dbgheap.h (revision 4)
+++ dbgheap.h (revision 5)
@@ -22,15 +22,17 @@
2222
2323 #include <exception>
2424 #include <new>
25-
25+
26+#ifdef _MSC_VER
2627 #pragma warning(push)
27-#pragma warning(disable: 4290)
28+#pragma warning(disable: 4290)
29+#endif //_MSC_VER
2830
2931 // Global allocator
3032 void* operator new( size_t memSize );
31-void* operator new( size_t memSize, const std::nothrow_t nothrow ) noexcept;
33+void* operator new( size_t memSize, const std::nothrow_t& nothrow ) noexcept;
3234 void* operator new[]( size_t memSize );
33-void* operator new[]( size_t memSize, const std::nothrow_t nothrow ) noexcept;
35+void* operator new[]( size_t memSize, const std::nothrow_t& nothrow ) noexcept;
3436 void operator delete( void *ptr ) noexcept;
3537 void operator delete[]( void *ptr ) noexcept;
3638
@@ -39,9 +41,11 @@
3941 void* DbgRealloc( void *ptr, size_t size );
4042 bool DbgAllocGetSize( void *ptr, size_t& sizeOut );
4143 void DbgFree( void *ptr );
44+
45+#ifdef _MSC_VER
46+#pragma warning(pop)
47+#endif //_MSC_VER
4248
43-#pragma warning(pop)
44-
4549 #endif //USE_HEAP_DEBUGGING
4650
4751 typedef void (*pfnMemoryAllocWatch)( void *memPtr, size_t memSize );
Show on old repository browser