Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

235 lines
7.1 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (C) 1999-2000 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: OSInd.h
  6. * Content: OS indirection functions to abstract OS specific items.
  7. *
  8. * History:
  9. * Date By Reason
  10. * ==== == ======
  11. * 07/12/99 jtk Created
  12. * 09/21/99 rodtoll Fixed for retail build
  13. * 08/28/2000 masonb Voice Merge: Fix for code that only defines one of DEBUG, DBG, _DEBUG
  14. * 08/28/2000 masonb Voice Merge: Added IsUnicodePlatform macro
  15. *
  16. ***************************************************************************/
  17. #ifndef __OSIND_H__
  18. #define __OSIND_H__
  19. #include "CallStack.h"
  20. #include "ClassBilink.h"
  21. //**********************************************************************
  22. // Constant definitions
  23. //**********************************************************************
  24. //
  25. // defines for resource tracking
  26. //
  27. // Make sure all variations of DEBUG are defined if any one is
  28. #if defined(DEBUG) || defined(DBG) || defined(_DEBUG)
  29. #if !defined(DBG)
  30. #define DBG
  31. #endif
  32. #if !defined(DEBUG)
  33. #define DEBUG
  34. #endif
  35. #if !defined(_DEBUG)
  36. #define _DEBUG
  37. #endif
  38. #endif
  39. #ifdef DEBUG
  40. #define DN_MEMORY_TRACKING
  41. #define DN_CRITICAL_SECTION_TRACKING
  42. #endif // DEBUG
  43. #define DN_MEMORY_CALL_STACK_DEPTH 12
  44. #define DN_CRITICAL_SECTION_CALL_STACK_DEPTH 10
  45. //
  46. // debug value for invalid thread ID
  47. //
  48. #define DN_INVALID_THREAD_ID -1
  49. //**********************************************************************
  50. // Macro definitions
  51. //**********************************************************************
  52. //**********************************************************************
  53. // Structure definitions
  54. //**********************************************************************
  55. //
  56. // critical section
  57. //
  58. typedef struct
  59. {
  60. CRITICAL_SECTION CriticalSection;
  61. #ifdef DN_CRITICAL_SECTION_TRACKING
  62. UINT_PTR OwningThreadID;
  63. UINT_PTR MaxLockCount;
  64. UINT_PTR LockCount;
  65. CCallStack< DN_CRITICAL_SECTION_CALL_STACK_DEPTH > CallStack;
  66. CCallStack< DN_CRITICAL_SECTION_CALL_STACK_DEPTH > AllocCallStack;
  67. CBilink blCritSec;
  68. #endif // DN_CRITICAL_SECTION_TRACKING
  69. } DNCRITICAL_SECTION;
  70. //
  71. // DirectNet time variable. Currently 64-bit, but can be made larger
  72. //
  73. typedef union
  74. {
  75. UINT_PTR Time64;
  76. struct
  77. {
  78. DWORD TimeLow;
  79. DWORD TimeHigh;
  80. } Time32;
  81. } DN_TIME;
  82. //**********************************************************************
  83. // Variable definitions
  84. //**********************************************************************
  85. extern HANDLE g_hMemoryHeap;
  86. //**********************************************************************
  87. // Function prototypes
  88. //**********************************************************************
  89. //
  90. // initialization functions
  91. //
  92. BOOL DNOSIndirectionInit( void );
  93. void DNOSIndirectionDeinit( void );
  94. //
  95. // Function to get OS version. Supported returns:
  96. // VER_PLATFORM_WIN32_WINDOWS - Win9x
  97. // VER_PLATFORM_WIN32_NT - WinNT
  98. // VER_PLATFORM_WIN32s - Win32s on Win3.1
  99. // VER_PLATFORM_WIN32_CE - WinCE
  100. //
  101. UINT_PTR DNGetOSType( void );
  102. BOOL DNOSIsXPOrGreater( void );
  103. HINSTANCE DNGetApplicationInstance( void );
  104. PSECURITY_ATTRIBUTES DNGetNullDacl();
  105. #define IsUnicodePlatform (DNGetOSType() == VER_PLATFORM_WIN32_NT)
  106. #define GETTIMESTAMP() timeGetTime()
  107. //
  108. // time functions
  109. //
  110. void DNTimeGet( DN_TIME *const pTimeDestination );
  111. INT_PTR DNTimeCompare( const DN_TIME *const pTime1, const DN_TIME *const pTime2 );
  112. void DNTimeAdd( const DN_TIME *const pTime1, const DN_TIME *const pTime2, DN_TIME *const pTimeResult );
  113. void DNTimeSubtract( const DN_TIME *const pTime1, const DN_TIME *const pTime2, DN_TIME *const pTimeResult );
  114. //
  115. // CriticalSection functions
  116. //
  117. #ifdef DN_CRITICAL_SECTION_TRACKING
  118. #define DNEnterCriticalSection( arg ) DNCSTrackEnterCriticalSection( arg )
  119. #define DNLeaveCriticalSection( arg ) DNCSTrackLeaveCriticalSection( arg )
  120. #define AssertCriticalSectionIsTakenByThisThread( pCS, Flag ) DNCSTrackCriticalSectionIsTakenByThisThread( pCS, Flag )
  121. #define DebugSetCriticalSectionRecursionCount( pCS, Count ) DNCSTrackSetCriticalSectionRecursionCount( pCS, Count )
  122. void DNCSTrackEnterCriticalSection( DNCRITICAL_SECTION *const pCriticalSection );
  123. void DNCSTrackLeaveCriticalSection( DNCRITICAL_SECTION *const pCriticalSection );
  124. void DNCSTrackSetCriticalSectionRecursionCount( DNCRITICAL_SECTION *const pCriticalSection, const UINT_PTR RecursionCount );
  125. void DNCSTrackCriticalSectionIsTakenByThisThread( const DNCRITICAL_SECTION *const pCriticalSection, const BOOL fFlag );
  126. #else // DN_CRITICAL_SECTION_TRACKING
  127. #define AssertCriticalSectionIsTakenByThisThread( pCS, Flag )
  128. #define DebugSetCriticalSectionRecursionCount( pCS, Count )
  129. #define DNEnterCriticalSection( arg ) EnterCriticalSection( &((arg)->CriticalSection) )
  130. #define DNLeaveCriticalSection( arg ) LeaveCriticalSection( &((arg)->CriticalSection) )
  131. #endif // DN_CRITICAL_SECTION_TRACKING
  132. BOOL DNInitializeCriticalSection( DNCRITICAL_SECTION *const pCriticalSection );
  133. void DNDeleteCriticalSection( DNCRITICAL_SECTION *const pCriticalSection );
  134. #ifdef DN_MEMORY_TRACKING
  135. #define DNMalloc( size ) DNMemoryTrackHeapAlloc( size )
  136. #define DNRealloc( pMemory, size ) DNMemoryTrackHeapReAlloc( pMemory, size )
  137. #define DNFree( pData ) DNMemoryTrackHeapFree( pData )
  138. void *DNMemoryTrackHeapAlloc( const UINT_PTR MemorySize );
  139. void *DNMemoryTrackHeapReAlloc( void *const pMemory, const UINT_PTR MemorySize );
  140. void DNMemoryTrackHeapFree( void *const pMemory );
  141. void DNMemoryTrackDisplayMemoryLeaks( void );
  142. void DNMemoryTrackingValidateMemory( void );
  143. #else // DN_MEMORY_TRACKING
  144. #define DNMalloc( size ) HeapAlloc( g_hMemoryHeap, 0, size )
  145. #define DNRealloc( pMemory, size ) HeapReAlloc( g_hMemoryHeap, 0, pMemory, size )
  146. #define DNFree( pData ) HeapFree( g_hMemoryHeap, 0, pData )
  147. #endif // DN_MEMORY_TRACKING
  148. //
  149. // Memory functions
  150. //
  151. //**********************************************************************
  152. // ------------------------------
  153. // operator new - allocate memory for a C++ class
  154. //
  155. // Entry: Size of memory to allocate
  156. //
  157. // Exit: Pointer to memory
  158. // NULL = no memory available
  159. //
  160. // Notes: This function is for classes only and will ASSERT on zero sized
  161. // allocations! This function also doesn't do the whole proper class
  162. // thing of checking for replacement 'new handlers' and will not throw
  163. // an exception if allocation fails.
  164. // ------------------------------
  165. inline void* __cdecl operator new( size_t size )
  166. {
  167. return DNMalloc( size );
  168. }
  169. //**********************************************************************
  170. //**********************************************************************
  171. // ------------------------------
  172. // operator delete - deallocate memory for a C++ class
  173. //
  174. // Entry: Pointer to memory
  175. //
  176. // Exit: Nothing
  177. //
  178. // Notes: This function is for classes only and will ASSERT on NULL frees!
  179. // ------------------------------
  180. inline void __cdecl operator delete( void *pData )
  181. {
  182. //
  183. // Voice and lobby currently try allocating 0 byte buffers, can't disable this check yet.
  184. //
  185. if( pData == NULL )
  186. return;
  187. DNFree( pData );
  188. }
  189. //**********************************************************************
  190. #endif // __OSIND_H__