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.

510 lines
12 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1991 - 1999
  6. //
  7. // File: sysinc.h
  8. //
  9. //--------------------------------------------------------------------------
  10. /* --------------------------------------------------------------------
  11. File : sysinc.h
  12. Description :
  13. This file includes all of the system include files necessary for a
  14. specific version of the runtime. In addition, it defines some system
  15. dependent debugging options.
  16. ***** If you are adding are changing something for a specific *****
  17. ***** system you MUST 1) make the change for all the defined *****
  18. ***** systems and 2) add a comment if needed in the template for *****
  19. ***** future systems. *****
  20. History :
  21. mikemon 08-01-91 Created.
  22. mikemon 10-31-91 Moved system dependent stuff from util.hxx to
  23. here.
  24. mariogo 10-19-94 Order conquered chaos and the world rejoiced
  25. -------------------------------------------------------------------- */
  26. #ifndef __SYSINC_H__
  27. #define __SYSINC_H__
  28. // Some system indepentent macros
  29. #ifndef DEBUGRPC
  30. #define INTERNAL_FUNCTION static
  31. #define INTERNAL_VARIABLE static
  32. #else
  33. #define INTERNAL_FUNCTION
  34. #define INTERNAL_VARIABLE
  35. #endif // ! DEBUGRPC
  36. // The following functions are can be implemented as macros
  37. // or functions for system type.
  38. // extern void *
  39. // RpcpFarAllocate (
  40. // IN unsigned int Length
  41. // );
  42. // extern void
  43. // RpcpFarFree (
  44. // IN void * Object
  45. // );
  46. // extern int
  47. // RpcpStringCompare (
  48. // IN RPC_CHAR * FirstString,
  49. // IN RPC_CHAR * SecondString
  50. // );
  51. // extern int
  52. // RpcpStringNCompare (
  53. // IN RPC_CHAR * FirstString,
  54. // IN RPC_CHAR * SecondString,
  55. // IN unsigned int Length
  56. // );
  57. // extern RPC_CHAR *
  58. // RpcpStringCopy (
  59. // OUT RPC_CHAR * Destination,
  60. // IN RPC_CHAR * Source
  61. // );
  62. // extern RPC_CHAR *
  63. // RpcpStringCat (
  64. // OUT RPC_CHAR * Destination,
  65. // IN CONST RPC_CHAR * Source
  66. // );
  67. // extern int
  68. // RpcpStringLength (
  69. // IN RPC_CHAR * WideCharString
  70. // );
  71. // extern void
  72. // RpcpMemoryMove (
  73. // OUT void * Destination,
  74. // IN void * Source,
  75. // IN unsigned int Length
  76. // );
  77. // extern void *
  78. // RpcpMemoryCopy (
  79. // OUT void * Destination,
  80. // IN void * Source,
  81. // IN unsigned int Length
  82. // );
  83. // extern void *
  84. // RpcpMemorySet (
  85. // OUT void * Buffer,
  86. // IN unsigned char Value,
  87. // IN unsigned int Length
  88. // );
  89. // extern char *
  90. // RpcpItoa(
  91. // IN int Value,
  92. // OUT char *Buffer,
  93. // IN int Radix);
  94. // extern int
  95. // RpcpStringPrintfA(
  96. // OUT char *Buffer,
  97. // IN char *Format,
  98. // ...);
  99. // extern void
  100. // PrintToDebugger(
  101. // IN char *Format,
  102. // ...);
  103. // extern void
  104. // RpcpBreakPoint(
  105. // );
  106. #ifdef __cplusplus
  107. extern "C" {
  108. #endif
  109. extern void GlobalMutexRequestExternal(void);
  110. extern void GlobalMutexClearExternal(void);
  111. #ifdef __cplusplus
  112. } // extern "C"
  113. #endif
  114. #include<nt.h>
  115. #include<ntrtl.h>
  116. #include<nturtl.h>
  117. #include<stdio.h>
  118. #include<string.h>
  119. #include<memory.h>
  120. #include<malloc.h>
  121. #include<stdlib.h>
  122. #ifndef WIN32_LEAN_AND_MEAN
  123. #define WIN32_LEAN_AND_MEAN
  124. #endif
  125. #include<windows.h>
  126. #ifdef __cplusplus
  127. extern "C" {
  128. #endif
  129. #if DBG
  130. #define DEBUGRPC
  131. #endif
  132. #if DBG
  133. #undef ASSERT
  134. #define ASSERT( exp ) \
  135. if (!(exp)) { RtlAssert( #exp, __FILE__, __LINE__, NULL ); DebugBreak(); }
  136. #endif
  137. #define NO_RETURN { ASSERT(0); }
  138. #define ASSUME(exp) ASSERT(exp)
  139. #define FORCE_INLINE inline
  140. #ifndef FORCE_VTABLES
  141. #define NO_VTABLE __declspec(novtable)
  142. #else
  143. #define NO_VTABLE
  144. #endif
  145. #define RPC_DELAYED_INITIALIZATION 1
  146. // flag to preallocate the events on some critical sections
  147. #ifndef PREALLOCATE_EVENT_MASK
  148. #define PREALLOCATE_EVENT_MASK 0x80000000 // Defined only in dll\resource.c
  149. #endif // PREALLOCATE_EVENT_MASK
  150. #define RPC_CHAR WCHAR
  151. #define RPC_SCHAR RPC_CHAR
  152. #define RPC_CONST_CHAR(character) ((RPC_CHAR) L##character)
  153. #define RPC_CONST_STRING(string) ((const RPC_CHAR *) L##string)
  154. #define RPC_CONST_SSTRING(string) RPC_CONST_STRING(string)
  155. #define RPC_STRING_LITERAL(string) ((RPC_CHAR *) L##string)
  156. #define RPC_T(string) (L##string)
  157. #define UNUSED(_x_) ((void)(_x_))
  158. #define MAX_DLLNAME_LENGTH 256
  159. #if DBG
  160. #define ASSERT_VALID(c) ((c)->AssertValid())
  161. #define ASSERT_VALID1(c, p1) ((c)->AssertValid(p1))
  162. #else
  163. #define ASSERT_VALID
  164. #define ASSERT_VALID1
  165. #endif
  166. #define LOCALE_US (MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT))
  167. #define RpcpFarAllocate(Length) \
  168. ((void *) new char[Length])
  169. #define RpcpFarFree(Object) \
  170. (delete Object)
  171. #define RpcpStringSCompare(FirstString, SecondString) \
  172. lstrcmp((const wchar_t *) FirstString, (const wchar_t *) SecondString)
  173. #define RpcpStringCompare(FirstString, SecondString) \
  174. _wcsicmp((const wchar_t *) FirstString, (const wchar_t *) SecondString)
  175. #define RpcpStringNCompare(FirstString, SecondString, Length) \
  176. _wcsnicmp((const wchar_t*) FirstString, (const wchar_t *) SecondString, \
  177. (size_t) Length)
  178. // always compares ASCII
  179. #define RpcpStringCompareA(FirstString, SecondString) \
  180. _stricmp((const char *) FirstString, (const char *) SecondString)
  181. #define RpcpStringNCompareA(FirstString, SecondString, Size) \
  182. _strnicmp((const char *) FirstString, (const char *) SecondString, Size)
  183. #define RpcpStringCompareInt(FirstString, SecondString) \
  184. (CompareStringW(LOCALE_US, NORM_IGNORECASE, \
  185. (const wchar_t *) FirstString, -1, (const wchar_t *) SecondString, -1) != CSTR_EQUAL)
  186. #define RpcpStringCompareIntA(FirstString, SecondString) \
  187. (CompareStringA(LOCALE_US, NORM_IGNORECASE, \
  188. FirstString, -1, SecondString, -1) != CSTR_EQUAL)
  189. #define RpcpStringCopy(Destination, Source) \
  190. wcscpy((wchar_t *) Destination, (const wchar_t *) Source)
  191. #define RpcpStringNCopy(DestinationString, SourceString, Length) \
  192. wcsncpy((wchar_t *) DestinationString, (wchar_t *) SourceString, Length)
  193. #define RpcpStringCat(Destination, Source) \
  194. wcscat((wchar_t *) Destination, (const wchar_t *) Source)
  195. #define RpcpStringLength(String) \
  196. wcslen((const wchar_t *) String)
  197. #define RpcpStrStr(String1, String2) \
  198. wcsstr((const wchar_t *) String1, (const wchar_t *) String2)
  199. #define RpcpStringLengthA(String) \
  200. strlen(String)
  201. #define RpcpStringToLower(String) \
  202. _wcslwr(String)
  203. #define RpcpMemoryCompare(FirstBuffer, SecondBuffer, Length) \
  204. memcmp(FirstBuffer, SecondBuffer, Length)
  205. #define RpcpMemoryCopy(Destination, Source, Length) \
  206. RtlCopyMemory(Destination, Source, Length)
  207. #define RpcpMemoryMove(Destination, Source, Length) \
  208. RtlMoveMemory(Destination, Source, Length)
  209. #define RpcpMemorySet(Buffer, Value, Length) \
  210. RtlFillMemory(Buffer, Length, Value)
  211. #if defined(TYPE_ALIGNMENT)
  212. #undef TYPE_ALIGNMENT
  213. #endif
  214. #define TYPE_ALIGNMENT(x) __alignof(x)
  215. void
  216. RpcpRaiseException (
  217. IN long exception
  218. );
  219. RPC_CHAR * __cdecl RpcpStringReverse (RPC_CHAR *string);
  220. void * I_RpcBCacheAllocate (IN unsigned int size);
  221. void I_RpcBCacheFree (IN void * obj);
  222. void I_RpcDoCellUnitTest(IN OUT void *p);
  223. // some test hook definitions
  224. typedef enum tagSystemFunction001Commands
  225. {
  226. sf001cHttpSetInChannelTarget,
  227. sf001cHttpSetOutChannelTarget
  228. } SystemFunction001Commands;
  229. #ifdef STATS
  230. void I_RpcGetStats(DWORD *pdwStat1, DWORD *pdwStat2, DWORD *pdwStat3, DWORD *pdwStat4);
  231. #endif
  232. #define RpcpItoa(Value, Buffer, Radix) \
  233. _itoa(Value, Buffer, Radix)
  234. #define RpcpItow(Value, Buffer, Radix) \
  235. _itow(Value, Buffer, Radix)
  236. #define RpcpCharacter(Buffer, Character) \
  237. wcschr(Buffer, Character)
  238. #define RpcpStringPrintfA sprintf
  239. #define RpcpStringConcatenate(FirstString, SecondString) \
  240. wcscat(FirstString, (const wchar_t *) SecondString)
  241. LONG
  242. I_RpcSetNDRSlot(
  243. IN void *NewSlot
  244. );
  245. void *
  246. I_RpcGetNDRSlot(
  247. void
  248. );
  249. long
  250. NDRCCopyContextHandle (
  251. IN void *SourceBinding,
  252. OUT void **DestinationBinding
  253. );
  254. #if defined(_M_IA64) || defined(_M_AMD64)
  255. #define CONTEXT_HANDLE_BEFORE_MARSHAL_MARKER ((PVOID)0xbaadbeefbaadbeef)
  256. #define CONTEXT_HANDLE_AFTER_MARSHAL_MARKER ((PVOID)0xdeaddeaddeaddead)
  257. #else
  258. #define CONTEXT_HANDLE_BEFORE_MARSHAL_MARKER ((PVOID)0xbaadbeef)
  259. #define CONTEXT_HANDLE_AFTER_MARSHAL_MARKER ((PVOID)0xdeaddead)
  260. #endif
  261. #define ANSI_strtol strtol
  262. #define PrintToConsole printf /* Use only in test applications */
  263. #if defined(_M_IA64) || defined(_M_AMD64)
  264. // uncomment this to disable locator support for IA64 or amd64
  265. //#define NO_LOCATOR_CODE
  266. //#define APPLETALK_ON
  267. //#define NETBIOS_ON
  268. //#define NCADG_MQ_ON
  269. //#define SPX_ON
  270. //#define IPX_ON
  271. #else
  272. #define APPLETALK_ON
  273. //#define NETBIOS_ON
  274. //#define NCADG_MQ_ON
  275. #define SPX_ON
  276. //#define IPX_ON
  277. #endif
  278. #if !defined(SPX_ON) && !defined(IPX_ON)
  279. #define SPX_IPX_OFF
  280. #endif
  281. #ifdef DEBUGRPC
  282. #define PrintToDebugger DbgPrint
  283. #define RpcpBreakPoint() DebugBreak()
  284. // ASSERT defined by system
  285. extern BOOL ValidateError(
  286. IN unsigned int Status,
  287. IN unsigned int Count,
  288. IN const int ErrorList[]);
  289. #define VALIDATE(_myValueToValidate) \
  290. { int _myTempValueToValidate = (_myValueToValidate); \
  291. static const int _myValidateArray[] =
  292. #define END_VALIDATE ; \
  293. if (ValidateError(_myTempValueToValidate,\
  294. sizeof(_myValidateArray)/sizeof(int), \
  295. _myValidateArray) == 0) ASSERT(0);}
  296. #else
  297. // PrintToDebugger defined only on debug builds...
  298. #define RpcpBreakPoint()
  299. /* Does nothing on retail systems */
  300. #define VALIDATE(_myValueToValidate) { int _bogusarray[] =
  301. #define END_VALIDATE ; }
  302. #endif
  303. // List Operations
  304. //
  305. #define RpcpInitializeListHead(ListHead) InitializeListHead(ListHead)
  306. #define RpcpIsListEmpty(ListHead) IsListEmpty(ListHead)
  307. PLIST_ENTRY
  308. RpcpfRemoveHeadList(
  309. PLIST_ENTRY ListHead
  310. );
  311. #define RpcpRemoveHeadList(ListHead) RemoveHeadList(ListHead)
  312. PLIST_ENTRY
  313. RpcpfRemoveTailList(
  314. PLIST_ENTRY ListHead
  315. );
  316. #define RpcpRemoveTailList(ListHead) RemoveTailList(ListHead)
  317. VOID
  318. RpcpfRemoveEntryList(
  319. PLIST_ENTRY Entry
  320. );
  321. #define RpcpRemoveEntryList(Entry) RemoveEntryList(Entry)
  322. VOID
  323. RpcpfInsertTailList(
  324. PLIST_ENTRY ListHead,
  325. PLIST_ENTRY Entry
  326. );
  327. #define RpcpInsertTailList(ListHead,Entry) InsertTailList(ListHead,Entry)
  328. VOID
  329. RpcpfInsertHeadList(
  330. PLIST_ENTRY ListHead,
  331. PLIST_ENTRY Entry
  332. );
  333. #define RpcpInsertHeadList(ListHead,Entry) InsertHeadList(ListHead,Entry)
  334. #ifdef __cplusplus
  335. }
  336. #endif
  337. //
  338. // Don't read this part. These are needed to support macros
  339. // used in the past. Please use the supported versions above.
  340. //
  341. #define PAPI __RPC_FAR
  342. // Some old C++ compiler the runtime once used didn't allocate
  343. // the this pointer before calling the constructor. If you
  344. // have such a compiler now, I'm very sorry for you.
  345. #define ALLOCATE_THIS(class)
  346. #define ALLOCATE_THIS_PLUS(class, amt, errptr, errcode)
  347. #ifdef __cplusplus
  348. #define START_C_EXTERN extern "C" {
  349. #define END_C_EXTERN }
  350. #else
  351. #define START_C_EXTERN
  352. #define END_C_EXTERN
  353. #endif
  354. // These must always evaluate "con" even on retail systems.
  355. #ifdef DEBUGRPC
  356. #define EVAL_AND_ASSERT(con) ASSERT(con)
  357. #else
  358. #define EVAL_AND_ASSERT(con) (con)
  359. #endif
  360. #define RequestGlobalMutex GlobalMutexRequest
  361. #define ClearGlobalMutex GlobalMutexClear
  362. #define RpcItoa RpcpItoa
  363. // Double check basic stuff.
  364. #if !defined(TRUE) || \
  365. !defined(FALSE) || \
  366. !defined(ASSERT) || \
  367. !defined(VALIDATE) || \
  368. !defined(IN) || \
  369. !defined(OUT) || \
  370. !defined(CONST) || \
  371. !defined(UNALIGNED) || \
  372. !defined(UNUSED)
  373. #error "Some basic macro is not defined"
  374. #endif
  375. #endif /* __SYSINC_H__ */