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.

198 lines
7.5 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name
  4. gdxlocal.h
  5. Abstract:
  6. Author:
  7. Mark Enstrom (marke) 23-Jun-1996
  8. Enviornment:
  9. User Mode
  10. Revision History:
  11. --*/
  12. extern PGDI_SHARED_MEMORY pGdiSharedMemory;
  13. extern PDEVCAPS pGdiDevCaps;
  14. extern PENTRY pGdiSharedHandleTable;
  15. extern W32PID gW32PID;
  16. #define HANDLE_TO_INDEX(h) (ULONG)h & 0x0000ffff
  17. HANDLE GdiFixUpHandle(HANDLE h);
  18. /******************************Public*Macro********************************\
  19. *
  20. * PSHARED_GET_VALIDATE
  21. *
  22. * Validate all handle information, return user pointer if the handle
  23. * is valid or NULL otherwise.
  24. *
  25. * Arguments:
  26. *
  27. * p - pointer to assign to pUser is successful
  28. * h - handle to object
  29. * iType - handle type
  30. *
  31. \**************************************************************************/
  32. #define PSHARED_GET_VALIDATE(p,h,iType) \
  33. { \
  34. UINT uiIndex = HANDLE_TO_INDEX(h); \
  35. p = NULL; \
  36. \
  37. if (uiIndex < MAX_HANDLE_COUNT) \
  38. { \
  39. PENTRY pentry = &pGdiSharedHandleTable[uiIndex]; \
  40. \
  41. if ( \
  42. (pentry->Objt == iType) && \
  43. (pentry->FullUnique == ((ULONG)h >> 16)) && \
  44. (pentry->ObjectOwner.Share.Pid == gW32PID) \
  45. ) \
  46. { \
  47. p = pentry->pUser; \
  48. } \
  49. } \
  50. }
  51. #define VALIDATE_HANDLE(bRet, h,iType) \
  52. { \
  53. UINT uiIndex = HANDLE_TO_INDEX(h); \
  54. bRet = FALSE; \
  55. \
  56. if (uiIndex < MAX_HANDLE_COUNT) \
  57. { \
  58. PENTRY pentry = &pGdiSharedHandleTable[uiIndex]; \
  59. \
  60. if ( \
  61. (pentry->Objt == iType) && \
  62. (pentry->FullUnique == ((ULONG)h >> 16)) && \
  63. ((pentry->ObjectOwner.Share.Pid == gW32PID) || \
  64. (pentry->ObjectOwner.Share.Pid == 0)) \
  65. ) \
  66. { \
  67. bRet = TRUE; \
  68. } \
  69. } \
  70. }
  71. /******************************Public*Macros******************************\
  72. * FIXUP_HANDLE(h) and FIXUP_HANDLEZ(h)
  73. *
  74. * check to see if the handle has been truncated.
  75. * FIXUP_HANDLEZ() adds an extra check to allow NULL.
  76. *
  77. * Arguments:
  78. * h - handle to be checked and fix
  79. *
  80. * Return Value:
  81. *
  82. * History:
  83. *
  84. * 25-Jan-1996 -by- Lingyun Wang [lingyunw]
  85. *
  86. \**************************************************************************/
  87. #define HANDLE_FIXUP 0
  88. #if DBG
  89. extern INT gbCheckHandleLevel;
  90. #endif
  91. #define NEEDS_FIXING(h) (!((ULONG)h & 0xffff0000))
  92. #if DBG
  93. #define HANDLE_WARNING() \
  94. { \
  95. if (gbCheckHandleLevel == 1) \
  96. { \
  97. WARNING ("truncated handle\n"); \
  98. } \
  99. ASSERTGDI (gbCheckHandleLevel != 2, "truncated handle\n"); \
  100. }
  101. #else
  102. #define HANDLE_WARNING()
  103. #endif
  104. #if DBG
  105. #define CHECK_HANDLE_WARNING(h, bZ) \
  106. { \
  107. BOOL bFIX = NEEDS_FIXING(h); \
  108. \
  109. if (bZ) bFIX = h && bFIX; \
  110. \
  111. if (bFIX) \
  112. { \
  113. if (gbCheckHandleLevel == 1) \
  114. { \
  115. WARNING ("truncated handle\n"); \
  116. } \
  117. ASSERTGDI (gbCheckHandleLevel != 2, "truncated handle\n"); \
  118. } \
  119. }
  120. #else
  121. #define CHECK_HANDLE_WARNING(h,bZ)
  122. #endif
  123. #if HANDLE_FIXUP
  124. #define FIXUP_HANDLE(h) \
  125. { \
  126. if (NEEDS_FIXING(h)) \
  127. { \
  128. HANDLE_WARNING(); \
  129. h = GdiFixUpHandle(h); \
  130. } \
  131. }
  132. #else
  133. #define FIXUP_HANDLE(h) \
  134. { \
  135. CHECK_HANDLE_WARNING(h,FALSE); \
  136. }
  137. #endif
  138. #if HANDLE_FIXUP
  139. #define FIXUP_HANDLEZ(h) \
  140. { \
  141. if (h && NEEDS_FIXING(h)) \
  142. { \
  143. HANDLE_WARNING(); \
  144. h = GdiFixUpHandle(h); \
  145. } \
  146. }
  147. #else
  148. #define FIXUP_HANDLEZ(h) \
  149. { \
  150. CHECK_HANDLE_WARNING(h,TRUE); \
  151. }
  152. #endif
  153. #define FIXUP_HANDLE_NOW(h) \
  154. { \
  155. if (NEEDS_FIXING(h)) \
  156. { \
  157. HANDLE_WARNING(); \
  158. h = GdiFixUpHandle(h); \
  159. } \
  160. }