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.

593 lines
15 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. sf001cIgnoreCorruptionAsserts
  229. } SystemFunction001Commands;
  230. #ifdef STATS
  231. void I_RpcGetStats(DWORD *pdwStat1, DWORD *pdwStat2, DWORD *pdwStat3, DWORD *pdwStat4);
  232. #endif
  233. #define RpcpItoa(Value, Buffer, Radix) \
  234. _itoa(Value, Buffer, Radix)
  235. #define RpcpItow(Value, Buffer, Radix) \
  236. _itow(Value, Buffer, Radix)
  237. #define RpcpCharacter(Buffer, Character) \
  238. wcschr(Buffer, Character)
  239. #define RpcpStringPrintfA sprintf
  240. #define RpcpStringConcatenate(FirstString, SecondString) \
  241. wcscat(FirstString, (const wchar_t *) SecondString)
  242. LONG
  243. I_RpcSetNDRSlot(
  244. IN void *NewSlot
  245. );
  246. void *
  247. I_RpcGetNDRSlot(
  248. void
  249. );
  250. long
  251. NDRCCopyContextHandle (
  252. IN void *SourceBinding,
  253. OUT void **DestinationBinding
  254. );
  255. BOOL CheckVerificationTrailer (
  256. IN void *BufferStart,
  257. IN void *BufferEnd,
  258. IN void *RpcMessage
  259. );
  260. #if defined(_M_IA64) || defined(_M_AMD64)
  261. #define CONTEXT_HANDLE_BEFORE_MARSHAL_MARKER ((PVOID)0xbaadbeefbaadbeef)
  262. #define CONTEXT_HANDLE_AFTER_MARSHAL_MARKER ((PVOID)0xdeaddeaddeaddead)
  263. #else
  264. #define CONTEXT_HANDLE_BEFORE_MARSHAL_MARKER ((PVOID)0xbaadbeef)
  265. #define CONTEXT_HANDLE_AFTER_MARSHAL_MARKER ((PVOID)0xdeaddead)
  266. #endif
  267. #define ANSI_strtol strtol
  268. #define PrintToConsole printf /* Use only in test applications */
  269. #if defined(_M_IA64) || defined(_M_AMD64)
  270. // uncomment this to disable locator support for IA64 or amd64
  271. //#define NO_LOCATOR_CODE
  272. //#define APPLETALK_ON
  273. //#define NETBIOS_ON
  274. //#define NCADG_MQ_ON
  275. //#define SPX_ON
  276. //#define IPX_ON
  277. #else
  278. #define APPLETALK_ON
  279. //#define NETBIOS_ON
  280. //#define NCADG_MQ_ON
  281. #define SPX_ON
  282. //#define IPX_ON
  283. #endif
  284. #if !defined(SPX_ON) && !defined(IPX_ON)
  285. #define SPX_IPX_OFF
  286. #endif
  287. #ifdef DEBUGRPC
  288. #define PrintToDebugger DbgPrint
  289. #define RpcpBreakPoint() DebugBreak()
  290. // ASSERT defined by system
  291. extern BOOL ValidateError(
  292. IN unsigned int Status,
  293. IN unsigned int Count,
  294. IN const int ErrorList[]);
  295. //
  296. // The syntax of VALIDATE is the following:
  297. //
  298. // VALIDATE (ErrorCode)
  299. // {
  300. // List of allowed errors
  301. // } END_VALIDATE;
  302. //
  303. // The code will assert on a checked build if ErrorCode is not in the list.
  304. //
  305. #define VALIDATE(_myValueToValidate) \
  306. { int _myTempValueToValidate = (_myValueToValidate); \
  307. static const int _myValidateArray[] =
  308. #define END_VALIDATE ; \
  309. if (ValidateError(_myTempValueToValidate,\
  310. sizeof(_myValidateArray)/sizeof(int), \
  311. _myValidateArray) == 0) ASSERT(0);}
  312. //
  313. // The syntax of CORRUPTION_VALIDATE is the following:
  314. //
  315. // VALIDATE (ErrorCode)
  316. // {
  317. // List of allowed errors
  318. // }
  319. // CORRUPTION_VALIDATE
  320. // {
  321. // List of allowed corruption-related errors
  322. // } CORRUPTION_END_VALIDATE;
  323. //
  324. // The code will assert on a checked build if ErrorCode is not in the allowed list
  325. // and there is no corruption injection enabled, or corruption injection is enabled
  326. // and the ErrorCode is also not in the corruption-related list.
  327. //
  328. #define CORRUPTION_VALIDATE ; \
  329. static const int _myCorruptionValidateArray[] =
  330. #define CORRUPTION_END_VALIDATE ; \
  331. if (ValidateError(_myTempValueToValidate,\
  332. sizeof(_myValidateArray)/sizeof(int), \
  333. _myValidateArray) == 0 && \
  334. (!gfRpcVerifierCorruptionExpected || \
  335. ValidateError(_myTempValueToValidate,\
  336. sizeof(_myCorruptionValidateArray)/sizeof(int), \
  337. _myCorruptionValidateArray) == 0 \
  338. ) \
  339. ) ASSERT(0); }
  340. //
  341. // The syntax of NO_CORRUPTION_VALIDATE is the following:
  342. //
  343. // NO_CORRUPTION_VALIDATE (ErrorCode)
  344. // {
  345. // List of allowed errors
  346. // } NO_CORRUPTION_END_VALIDATE;
  347. //
  348. // The code will assert on a checked build if ErrorCode is not in the list and
  349. // corruption injection is not enabled.
  350. //
  351. #define NO_CORRUPTION_VALIDATE(_myValueToValidate) \
  352. { int _myTempValueToValidate = (_myValueToValidate); \
  353. static const int _myValidateArray[] =
  354. #define NO_CORRUPTION_END_VALIDATE ; \
  355. if ( \
  356. !gfRpcVerifierCorruptionExpected && \
  357. ValidateError(_myTempValueToValidate,\
  358. sizeof(_myValidateArray)/sizeof(int), \
  359. _myValidateArray) == 0 \
  360. ) ASSERT(0); }
  361. #else // DEBUGRPC
  362. // PrintToDebugger defined only on debug builds...
  363. #define RpcpBreakPoint()
  364. /* Does nothing on retail systems */
  365. #define VALIDATE(_myValueToValidate) { int _bogusarray1[] =
  366. #define END_VALIDATE ; }
  367. #define CORRUPTION_VALIDATE ; } ; { int _bogusarray2[] =
  368. #define CORRUPTION_END_VALIDATE ; }
  369. #define NO_CORRUPTION_VALIDATE(_myValueToValidate) { int _bogusarray1[] =
  370. #define NO_CORRUPTION_END_VALIDATE ; }
  371. #endif // DEBUGRPC
  372. // List Operations
  373. //
  374. #define RpcpInitializeListHead(ListHead) InitializeListHead(ListHead)
  375. #define RpcpIsListEmpty(ListHead) IsListEmpty(ListHead)
  376. PLIST_ENTRY
  377. RpcpfRemoveHeadList(
  378. PLIST_ENTRY ListHead
  379. );
  380. #define RpcpRemoveHeadList(ListHead) RemoveHeadList(ListHead)
  381. PLIST_ENTRY
  382. RpcpfRemoveTailList(
  383. PLIST_ENTRY ListHead
  384. );
  385. #define RpcpRemoveTailList(ListHead) RemoveTailList(ListHead)
  386. VOID
  387. RpcpfRemoveEntryList(
  388. PLIST_ENTRY Entry
  389. );
  390. #define RpcpRemoveEntryList(Entry) RemoveEntryList(Entry)
  391. VOID
  392. RpcpfInsertTailList(
  393. PLIST_ENTRY ListHead,
  394. PLIST_ENTRY Entry
  395. );
  396. #define RpcpInsertTailList(ListHead,Entry) InsertTailList(ListHead,Entry)
  397. VOID
  398. RpcpfInsertHeadList(
  399. PLIST_ENTRY ListHead,
  400. PLIST_ENTRY Entry
  401. );
  402. #define RpcpInsertHeadList(ListHead,Entry) InsertHeadList(ListHead,Entry)
  403. #ifdef __cplusplus
  404. }
  405. #endif
  406. //
  407. // Don't read this part. These are needed to support macros
  408. // used in the past. Please use the supported versions above.
  409. //
  410. #define PAPI __RPC_FAR
  411. // Some old C++ compiler the runtime once used didn't allocate
  412. // the this pointer before calling the constructor. If you
  413. // have such a compiler now, I'm very sorry for you.
  414. #define ALLOCATE_THIS(class)
  415. #define ALLOCATE_THIS_PLUS(class, amt, errptr, errcode)
  416. #ifdef __cplusplus
  417. #define START_C_EXTERN extern "C" {
  418. #define END_C_EXTERN }
  419. #else
  420. #define START_C_EXTERN
  421. #define END_C_EXTERN
  422. #endif
  423. // These must always evaluate "con" even on retail systems.
  424. #ifdef DEBUGRPC
  425. #define EVAL_AND_ASSERT(con) ASSERT(con)
  426. #else
  427. #define EVAL_AND_ASSERT(con) (con)
  428. #endif
  429. #define RequestGlobalMutex GlobalMutexRequest
  430. #define ClearGlobalMutex GlobalMutexClear
  431. #define RpcItoa RpcpItoa
  432. // Double check basic stuff.
  433. #if !defined(TRUE) || \
  434. !defined(FALSE) || \
  435. !defined(ASSERT) || \
  436. !defined(VALIDATE) || \
  437. !defined(IN) || \
  438. !defined(OUT) || \
  439. !defined(CONST) || \
  440. !defined(UNALIGNED) || \
  441. !defined(UNUSED)
  442. #error "Some basic macro is not defined"
  443. #endif
  444. //
  445. // External NDR routines that may be used by the runtime.
  446. //
  447. extern long
  448. NdrCheckAsyncPipeStatus(
  449. IN char * AsyncHandle,
  450. OUT long * pState );
  451. #endif /* __SYSINC_H__ */