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.

148 lines
4.9 KiB

  1. /*++
  2. Copyright (c) 1999-2001 Microsoft Corporation
  3. Module Name:
  4. nt4hack.h
  5. Abstract:
  6. Random typedefs and macros stolen from the NT5 header files to
  7. make this driver build with the NT4 header files.
  8. Author:
  9. Keith Moore (keithmo) 09-Aug-1999
  10. Revision History:
  11. --*/
  12. #ifndef _NT4HACK_H_
  13. #define _NT4HACK_H_
  14. #ifdef __cplusplus
  15. extern "C" {
  16. #endif
  17. //
  18. // Typedefs and constants missing from the NT4 header files.
  19. //
  20. #ifdef TARGET_NT4
  21. #include <basetsd.h>
  22. #define C_ASSERT(e) typedef char __C_ASSERT__[(e)?1:-1]
  23. #ifdef __cplusplus
  24. #define EXTERN_C extern "C"
  25. #else
  26. #define EXTERN_C extern
  27. #endif
  28. #define ANSI_NULL ((CHAR)0)
  29. #endif // TARGET_NT4
  30. //
  31. // Wrap ExInterlockedCompareExchange64() and InterlockedCompareExchange()
  32. // so they'll look the same on NT4 and NT5.
  33. //
  34. #ifdef TARGET_NT4
  35. #define UlInterlockedCompareExchange64(pDest, pExch, pComp, pLock) \
  36. (LONGLONG)ExInterlockedCompareExchange64( \
  37. (PULONGLONG)(pDest), \
  38. (PULONGLONG)(pExch), \
  39. (PULONGLONG)(pComp), \
  40. (pLock) \
  41. )
  42. #define UlInterlockedCompareExchange(pDest, Exch, Comp) \
  43. (LONG)InterlockedCompareExchange( \
  44. (PVOID *)(pDest), \
  45. (PVOID)(Exch), \
  46. (PVOID)(Comp) \
  47. )
  48. #else // !TARGET_NT4
  49. #define UlInterlockedCompareExchange64(pDest, pExch, pComp, pLock) \
  50. (LONGLONG)ExInterlockedCompareExchange64( \
  51. (PLONGLONG)(pDest), \
  52. (PLONGLONG)(pExch), \
  53. (PLONGLONG)(pComp), \
  54. (pLock) \
  55. )
  56. #define UlInterlockedCompareExchange(pDest, Exch, Comp) \
  57. (LONG)InterlockedCompareExchange( \
  58. (LONG *)(pDest), \
  59. (LONG)(Exch), \
  60. (LONG)(Comp) \
  61. )
  62. #endif // TARGET_NT4
  63. //
  64. // NT5 introduced the OBJ_KERNEL_HANDLE object attribute, which is
  65. // a Very Good Thing. We'd like to use it everywhere we create
  66. // handles, but unfortunately NT4 does not support it.
  67. //
  68. // Here, we make an attempt to hide this.
  69. //
  70. #ifdef TARGET_NT4
  71. #define UL_KERNEL_HANDLE 0
  72. #define UlAttachToSystemProcess() \
  73. do \
  74. { \
  75. ASSERT( g_pUlSystemProcess != NULL ); \
  76. if (g_pUlSystemProcess != (PKPROCESS)PsGetCurrentProcess()) \
  77. { \
  78. KeAttachProcess( g_pUlSystemProcess ); \
  79. } \
  80. } while (FALSE)
  81. #define UlDetachFromSystemProcess() \
  82. do \
  83. { \
  84. ASSERT( g_pUlSystemProcess != NULL ); \
  85. if (g_pUlSystemProcess != (PKPROCESS)PsGetCurrentProcess()) \
  86. { \
  87. KeDetachProcess(); \
  88. } \
  89. } while (FALSE)
  90. #else // !TARGET_NT4
  91. #define UL_KERNEL_HANDLE OBJ_KERNEL_HANDLE
  92. #define UlAttachToSystemProcess() ASSERT( g_pUlSystemProcess != NULL )
  93. #define UlDetachFromSystemProcess() ASSERT( g_pUlSystemProcess != NULL )
  94. #endif // TARGET_NT4
  95. //
  96. // Close a system handle, attaching to and detaching from the system
  97. // process if necessary. Uses the above macros to hide the attach/detach.
  98. //
  99. #define UlCloseSystemHandle( handle ) \
  100. do \
  101. { \
  102. UlAttachToSystemProcess(); \
  103. (VOID)ZwClose( handle ); \
  104. UlDetachFromSystemProcess(); \
  105. } while (FALSE)
  106. #ifdef __cplusplus
  107. }; // extern "C"
  108. #endif
  109. #endif // _NT4HACK_H_