Leaked source code of windows server 2003
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.

341 lines
10 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (C) 1999-2002 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/1999 jtk Created
  12. * 10/16/2001 vanceo Added AssertNoCriticalSectionsTakenByThisThread capability
  13. *
  14. ***************************************************************************/
  15. #ifndef __OSIND_H__
  16. #define __OSIND_H__
  17. #include "CallStack.h"
  18. #include "ClassBilink.h"
  19. #include "HandleTracking.h"
  20. #include "CritsecTracking.h"
  21. #include "MemoryTracking.h"
  22. //**********************************************************************
  23. // Constant definitions
  24. //**********************************************************************
  25. #define GUID_STRING_LEN 39
  26. //**********************************************************************
  27. // Macro definitions
  28. //**********************************************************************
  29. #ifndef OFFSETOF
  30. #define OFFSETOF(s,m) ( ( INT_PTR ) ( ( PVOID ) &( ( (s*) 0 )->m ) ) )
  31. #endif // OFFSETOF
  32. #ifndef LENGTHOF
  33. #define LENGTHOF( arg ) ( sizeof( arg ) / sizeof( arg[ 0 ] ) )
  34. #endif // OFFSETOF
  35. #ifndef _MIN
  36. #define _MIN(a, b) ((a) < (b) ? (a) : (b))
  37. #endif // _MIN
  38. #ifndef _MAX
  39. #define _MAX(a, b) ((a) > (b) ? (a) : (b))
  40. #endif // _MAX
  41. //**********************************************************************
  42. // Structure definitions
  43. //**********************************************************************
  44. //**********************************************************************
  45. // Variable definitions
  46. //**********************************************************************
  47. //**********************************************************************
  48. // Function prototypes
  49. //**********************************************************************
  50. //
  51. // initialization functions
  52. //
  53. BOOL DNOSIndirectionInit( DWORD_PTR dwpMaxMemUsage );
  54. void DNOSIndirectionDeinit( void );
  55. #ifndef DPNBUILD_NOPARAMVAL
  56. extern BOOL IsValidStringA( const CHAR * const swzString );
  57. #define DNVALID_STRING_A(a) IsValidStringA(a)
  58. extern BOOL IsValidStringW( const WCHAR * const szString );
  59. #define DNVALID_STRING_W(a) IsValidStringW(a)
  60. #define DNVALID_WRITEPTR(a,b) (!IsBadWritePtr(a,b))
  61. #define DNVALID_READPTR(a,b) (!IsBadReadPtr(a,b))
  62. #endif // ! DPNBUILD_NOPARAMVAL
  63. //
  64. // Function to get OS version. Supported returns:
  65. // VER_PLATFORM_WIN32_WINDOWS - Win9x
  66. // VER_PLATFORM_WIN32_NT - WinNT
  67. // VER_PLATFORM_WIN32s - Win32s on Win3.1
  68. // VER_PLATFORM_WIN32_CE - WinCE
  69. //
  70. #if ((! defined(WINCE)) && (! defined(_XBOX)))
  71. UINT_PTR DNGetOSType( void );
  72. #endif // ! WINCE and ! _XBOX
  73. struct in_addr;
  74. typedef struct in_addr IN_ADDR;
  75. void DNinet_ntow( IN_ADDR sin, WCHAR* pwsz );
  76. #ifdef WINNT
  77. BOOL DNOSIsXPOrGreater( void );
  78. #endif // WINNT
  79. #ifndef DPNBUILD_NOSERIALSP
  80. // Used only by serial provider
  81. HINSTANCE DNGetApplicationInstance( void );
  82. #endif // ! DPNBUILD_NOSERIALSP
  83. #ifdef WINNT
  84. PSECURITY_ATTRIBUTES DNGetNullDacl();
  85. #else
  86. #define DNGetNullDacl() 0
  87. #endif // WINNT
  88. #ifndef VER_PLATFORM_WIN32_CE
  89. #define VER_PLATFORM_WIN32_CE 3
  90. #endif // VER_PLATFORM_WIN32_CE
  91. #if ((defined(WINCE)) || (defined(_XBOX)))
  92. #define IsUnicodePlatform TRUE
  93. #else // ! WINCE and ! _XBOX
  94. #define IsUnicodePlatform (DNGetOSType() == VER_PLATFORM_WIN32_NT || DNGetOSType() == VER_PLATFORM_WIN32_CE)
  95. #endif // ! WINCE and ! _XBOX
  96. #ifdef WINCE
  97. #define GETTIMESTAMP() GetTickCount()
  98. #else
  99. #define GETTIMESTAMP() timeGetTime()
  100. #endif // WINCE
  101. DWORD DNGetRandomNumber();
  102. //
  103. // Interlocked functions (not actually interlocked when DPNBUILD_ONLYONETHREAD)
  104. //
  105. #ifdef DPNBUILD_ONLYONETHREAD
  106. inline LONG DNInterlockedIncrement( IN OUT LONG volatile *Addend )
  107. {
  108. return ++(*Addend);
  109. }
  110. inline LONG DNInterlockedDecrement( IN OUT LONG volatile *Addend )
  111. {
  112. return --(*Addend);
  113. }
  114. inline LONG DNInterlockedExchange( IN OUT LONG volatile *Target, IN LONG Value )
  115. {
  116. LONG Previous;
  117. Previous = *Target;
  118. *Target = Value;
  119. return Previous;
  120. }
  121. inline LONG DNInterlockedExchangeAdd( IN OUT LONG volatile *Addend, IN LONG Value )
  122. {
  123. LONG Previous;
  124. Previous = *Addend;
  125. *Addend = Previous + Value;
  126. return Previous;
  127. }
  128. inline LONG DNInterlockedCompareExchange( IN OUT LONG volatile *Destination, IN LONG Exchange, IN LONG Comperand )
  129. {
  130. LONG Previous;
  131. Previous = *Destination;
  132. if (Previous == Comperand)
  133. {
  134. *Destination = Exchange;
  135. }
  136. return Previous;
  137. }
  138. inline PVOID DNInterlockedCompareExchangePointer( IN OUT PVOID volatile *Destination, IN PVOID Exchange, IN PVOID Comperand )
  139. {
  140. PVOID Previous;
  141. Previous = *Destination;
  142. if (Previous == Comperand)
  143. {
  144. *Destination = Exchange;
  145. }
  146. return Previous;
  147. }
  148. inline PVOID DNInterlockedExchangePointer( IN OUT PVOID volatile *Target, IN PVOID Value )
  149. {
  150. PVOID Previous;
  151. Previous = *Target;
  152. *Target = Value;
  153. return Previous;
  154. }
  155. #else // ! DPNBUILD_ONLYONETHREAD
  156. /*
  157. #ifdef WINCE
  158. #if defined(_ARM_)
  159. #define InterlockedExchangeAdd \
  160. ((long (*)(long *target, long increment))(PUserKData+0x3C0))
  161. #elif defined(_X86_)
  162. LONG WINAPI InterlockedExchangeAdd( LPLONG Addend, LONG Increment );
  163. #else
  164. #error("Unknown platform")
  165. #endif // Platform
  166. #endif // WINCE
  167. */
  168. #define DNInterlockedIncrement( Addend ) InterlockedIncrement( Addend )
  169. #define DNInterlockedDecrement( Addend ) InterlockedDecrement( Addend )
  170. #define DNInterlockedExchange( Target, Value ) InterlockedExchange( Target, Value )
  171. #define DNInterlockedExchangeAdd( Target, Value ) InterlockedExchangeAdd( Target, Value )
  172. #ifdef WINCE
  173. // NOTE: Params 2 and 3 reversed intentionally, CE is that way
  174. #define DNInterlockedCompareExchange( Destination, Exchange, Comperand ) InterlockedTestExchange( Destination, Comperand, Exchange )
  175. #else // !WINCE
  176. #define DNInterlockedCompareExchange( Destination, Exchange, Comperand ) InterlockedCompareExchange( Destination, Exchange, Comperand )
  177. #endif // WINCE
  178. #define DNInterlockedCompareExchangePointer( Destination, Exchange, Comperand ) InterlockedCompareExchangePointer( Destination, Exchange, Comperand )
  179. #define DNInterlockedExchangePointer( Target, Value ) InterlockedExchangePointer( Target, Value )
  180. #endif // ! DPNBUILD_ONLYONETHREAD
  181. // Special initialize to set spin count, avoid out-of-memory exceptions at Enter/Leave
  182. BOOL DNOSInitializeCriticalSection( CRITICAL_SECTION* pCriticalSection );
  183. #ifdef WINNT
  184. #define GLOBALIZE_STR _T("Global\\")
  185. #else
  186. #define GLOBALIZE_STR _T("")
  187. #endif // WINNT
  188. #if defined(WINCE) && !defined(WINCE_ON_DESKTOP)
  189. #define _TWINCE(x) __T(x)
  190. #else
  191. #define _TWINCE(x) x
  192. #endif // WINCE
  193. //
  194. // Memory functions
  195. //
  196. #ifdef DPNBUILD_LIBINTERFACE
  197. #define new __wont_compile_dont_use_new_operator__
  198. #define delete __wont_compile_dont_use_delete_operator__
  199. #else // ! DPNBUILD_LIBINTERFACE
  200. //**********************************************************************
  201. // ------------------------------
  202. // operator new - allocate memory for a C++ class
  203. //
  204. // Entry: Size of memory to allocate
  205. //
  206. // Exit: Pointer to memory
  207. // NULL = no memory available
  208. //
  209. // Notes: This function is for classes only and will ASSERT on zero sized
  210. // allocations! This function also doesn't do the whole proper class
  211. // thing of checking for replacement 'new handlers' and will not throw
  212. // an exception if allocation fails.
  213. // ------------------------------
  214. inline void* __cdecl operator new( size_t size )
  215. {
  216. return DNMalloc( size );
  217. }
  218. //**********************************************************************
  219. //**********************************************************************
  220. // ------------------------------
  221. // operator delete - deallocate memory for a C++ class
  222. //
  223. // Entry: Pointer to memory
  224. //
  225. // Exit: Nothing
  226. //
  227. // Notes: This function is for classes only and will ASSERT on NULL frees!
  228. // ------------------------------
  229. inline void __cdecl operator delete( void *pData )
  230. {
  231. //
  232. // Voice and lobby currently try allocating 0 byte buffers, can't disable this check yet.
  233. //
  234. if( pData == NULL )
  235. return;
  236. DNFree( pData );
  237. }
  238. //**********************************************************************
  239. #endif // ! DPNBUILD_LIBINTERFACE
  240. #ifdef WINCE
  241. #ifdef DBG
  242. UINT DNGetProfileInt(LPCTSTR lpszSection, LPCTSTR lpszEntry, int nDefault);
  243. #endif // DBG
  244. #ifndef WINCE_ON_DESKTOP
  245. HANDLE WINAPI OpenEvent(IN DWORD dwDesiredAccess, IN BOOL bInheritHandle, IN LPCWSTR lpName);
  246. HANDLE WINAPI OpenFileMapping(IN DWORD dwDesiredAccess, IN BOOL bInheritHandle, IN LPCWSTR lpName);
  247. HANDLE WINAPI OpenMutex(IN DWORD dwDesiredAccess, IN BOOL bInheritHandle, IN LPCWSTR lpName);
  248. #endif // !WINCE_ON_DESKTOP
  249. #define WaitForSingleObjectEx(handle, time, fAlertable) WaitForSingleObject(handle, time)
  250. #define WaitForMultipleObjectsEx(count, handles, waitall, time, fAlertable) WaitForMultipleObjects(count, handles, waitall, time)
  251. #ifndef WINCE_ON_DESKTOP
  252. #define GetWindowLongPtr(a, b) GetWindowLong(a, b)
  253. #define GWLP_USERDATA GWL_USERDATA
  254. #define SetWindowLongPtr(a, b, c) SetWindowLong(a, b, c)
  255. #endif // WINCE_ON_DESKTOP
  256. #define SleepEx(a, b) Sleep(a)
  257. #ifndef MUTEX_ALL_ACCESS
  258. #define MUTEX_ALL_ACCESS 0
  259. #endif // MUTEX_ALL_ACCESS
  260. #ifndef NORMAL_PRIORITY_CLASS
  261. #define NORMAL_PRIORITY_CLASS 0
  262. #endif // NORMAL_PRIORITY_CLASS
  263. #else // ! WINCE
  264. #ifdef DBG
  265. #if ((defined(_XBOX)) && (! defined(XBOX_ON_DESKTOP)))
  266. UINT DNGetProfileInt(LPCTSTR lpszSection, LPCTSTR lpszEntry, int nDefault);
  267. #else // ! _XBOX or XBOX_ON_DESKTOP
  268. #define DNGetProfileInt(lpszSection, lpszEntry, nDefault) GetProfileInt(lpszSection, lpszEntry, nDefault)
  269. #endif// ! _XBOX or XBOX_ON_DESKTOP
  270. #endif // DBG
  271. #endif // ! WINCE
  272. #if ((defined(WINCE)) || (defined(DPNBUILD_LIBINTERFACE)))
  273. HRESULT DNCoCreateGuid(GUID* pguid);
  274. #else // ! WINCE and ! DPNBUILD_LIBINTERFACE
  275. #define DNCoCreateGuid CoCreateGuid
  276. #endif // ! WINCE and ! DPNBUILD_LIBINTERFACE
  277. #ifdef _XBOX
  278. #define swprintf wsprintfW
  279. #endif // _XBOX
  280. #endif // __OSIND_H__