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.

175 lines
6.7 KiB

  1. /************************************************************************/
  2. /* */
  3. /* HANDLE.H -- Handle Table Declarations */
  4. /* */
  5. /************************************************************************/
  6. /* Author: Gene Apperson */
  7. /* Copyright: 1991 Microsoft */
  8. /************************************************************************/
  9. /* File Description: */
  10. /* */
  11. /* */
  12. /************************************************************************/
  13. /* Revision History: */
  14. /* */
  15. /* 03/13/92 (GeneA): changed default size of handle table from 32 to */
  16. /* 48. Added FGetDosHandles prototype */
  17. /* */
  18. /************************************************************************/
  19. /* ------------------------------------------------------------ */
  20. /* rghte[x].flFlags bits */
  21. /* ------------------------------------------------------------ */
  22. #define fhteInherit 0x80000000 /* Is inheritable */
  23. #define fhteDevObj 0x40000000 /* Device (file or console) */
  24. #define mhteSpecific 0x0000ffff // SPECIFIC_RIGHTS_ALL
  25. #define mhteStandard 0x001f0000 // STANDARD_RIGHTS_ALL
  26. #define mhteSystem 0xff000000
  27. #define fhteStdRequire 0x000f0000 // STANDARD_RIGHTS_REQUIRED
  28. #define fhteSynch 0x00100000 // SYNCHRONIZE
  29. // Following specific rights are used by file/device object types.
  30. #define fhteDevShrRead 0x00000001
  31. #define fhteDevShrWrite 0x00000002
  32. #define fhteDevAccRead 0x00000020
  33. #define fhteDevAttrWrite 0x00000100 // FILE_WRITE_ATTRIBUTES
  34. #define fhteDevAccWrite 0x00000110
  35. #define fhteDevAccAll 0x00000130
  36. #define fhteDevAccAny 0x00000000
  37. #define fhteDevOverlapped 0x00001000
  38. #define mhteDevAcc 0x00000130
  39. #define mhteDevShr 0x00000003
  40. #define flMaskAll 0xffffffff
  41. //
  42. // MapHandle argument values.
  43. //
  44. // Object type values.
  45. //
  46. #define typSemaphore (1 << (typObjShiftAdjust + typObjSemaphore))
  47. #define typEvent (1 << (typObjShiftAdjust + typObjEvent))
  48. #define typMutex (1 << (typObjShiftAdjust + typObjMutex))
  49. #define typCrst (1 << (typObjShiftAdjust + typObjCrst))
  50. #define typProcess (1 << (typObjShiftAdjust + typObjProcess))
  51. #define typThread (1 << (typObjShiftAdjust + typObjThread))
  52. #define typFile (1 << (typObjShiftAdjust + typObjFile))
  53. #define typChange (1 << (typObjShiftAdjust + typObjChange))
  54. #define typIO (1 << (typObjShiftAdjust + typObjIO))
  55. #define typConsole (1 << (typObjShiftAdjust + typObjConsole))
  56. #define typConScreenbuf (1 << (typObjShiftAdjust + typObjConScreenbuf))
  57. #define typMapFile (1 << (typObjShiftAdjust + typObjMapFile))
  58. #define typSerial (1 << (typObjShiftAdjust + typObjSerial))
  59. #define typDevIOCtl (1 << (typObjShiftAdjust + typObjDevIOCtl))
  60. #define typPipe (1 << (typObjShiftAdjust + typObjPipe))
  61. #define typMailslot (1 << (typObjShiftAdjust + typObjMailslot))
  62. #define typToolhelp (1 << (typObjShiftAdjust + typObjToolhelp))
  63. #define typSocket (1 << (typObjShiftAdjust + typObjSocket))
  64. #define typTimer (1 << (typObjShiftAdjust + typObjTimer))
  65. #define typR0ObjExt (1 << (typObjShiftAdjust + typObjR0ObjExt))
  66. #define typMsgIndicator ( 1<<(typObjShiftAdjust + typObjMsgIndicator))
  67. #define typAny (~(0xffffffff << (1 + typObjShiftAdjust + typObjMaxValid)))
  68. #define typNone 0
  69. #define typMask typAny
  70. #define typSTDIN (typFile | typPipe | typSocket | typConsole)
  71. #define typSTDOUT (typFile | typPipe | typSocket | typConScreenbuf)
  72. //
  73. // Boolean flag to MapHandle (snuck inside objType parameter) to prevent the
  74. // object from being freed until UnlockObject() is called.
  75. //
  76. #define objLOCK 0x80000000
  77. // Handles are derived by left-shifting ihte's by this many bits.
  78. // This corresponds to the number of low bits reserved by NT.
  79. #define IHTETOHANDLESHIFT 2
  80. /* ------------------------------------------------------------ */
  81. /* */
  82. /* ------------------------------------------------------------ */
  83. #define chteInit 16
  84. #define chteInc 16
  85. #define ihteInvalid 0xFFFFFFFF
  86. #define ihteCurProc 0x7FFFFFFF
  87. #define ihteCurThread 0xFFFFFFFE
  88. #define hInvalid ((HANDLE)ihteInvalid)
  89. #define hCurProc ((HANDLE)ihteCurProc)
  90. #define hCurThread ((HANDLE)ihteCurThread)
  91. /* Maximum value for a normal handle (handles above this value
  92. * are either global or special.)
  93. */
  94. #define hMaxValid 0x00FFFFFF
  95. #define ihteMaxValid (hMaxValid >> IHTETOHANDLESHIFT)
  96. /* Making this non-zero will keep us from allocating handle 0 */
  97. #define ihteDosMax 1
  98. typedef struct _hte {
  99. DWORD flFlags;
  100. OBJ * pobj;
  101. } HTE;
  102. typedef struct _htb {
  103. DWORD chteMax;
  104. HTE rghte[1];
  105. } HTB;
  106. // Handles are considered global if the high byte is equal to the high byte
  107. // of GLOBALHANDLEMASK.
  108. //
  109. // When handles are converted to ihtes, they are just right-shifted like
  110. // any other. That is, if n == IHTETOHANDLESHIFT, global ihtes have 0's
  111. // in the top n bits, the high byte of GLOBALHANDLEMASK in the next 8 bits.
  112. // The low n bits of the mask must be zero because those bits are lost
  113. // when handles are converted to ihtes.
  114. #define GLOBALHANDLEMASK (0x453a4d3cLU)
  115. // IHTEFROMHANDLEEX() uses a compare against a single watermark to
  116. // distinguish special handle values from local and global handles.
  117. // Thus, it's essential that global handles be numerically less
  118. // than any special handle value.
  119. /* ------------------------------------------------------------ */
  120. /* Function Prototypes */
  121. /* ------------------------------------------------------------ */
  122. GLOBAL HTB * KERNENTRY PhtbCreate (PDB *);
  123. GLOBAL VOID KERNENTRY PhtbDestroy(PDB *);
  124. GLOBAL DWORD KERNENTRY FlFlagsFromHnd (PDB *, HANDLE);
  125. GLOBAL HANDLE KERNENTRY AllocHandle(PDB *, OBJ *, DWORD);
  126. GLOBAL BOOL KERNENTRY FreeHandle(PDB *, HANDLE);
  127. GLOBAL VOID * KERNENTRY MapHandle(HANDLE, DWORD, DWORD);
  128. GLOBAL VOID * KERNENTRY MapHandleWithContext(PPDB,HANDLE,DWORD,DWORD);
  129. GLOBAL HANDLE KERNENTRY PreAllocHandle(PDB *);
  130. GLOBAL HANDLE KERNENTRY SetPreAllocHandle(PDB *, HANDLE, OBJ *, DWORD);
  131. GLOBAL VOID KERNENTRY FreePreAllocHandle(PDB *, HANDLE);
  132. GLOBAL VOID KERNENTRY CloseProcessHandles (PDB *);
  133. GLOBAL VOID KERNENTRY CloseDOSHandles (VOID);
  134. GLOBAL BOOL KERNENTRY FInheritHandles (PDB *, PDB *);
  135. GLOBAL VOID KERNENTRY CloseConsoleHandles (PDB *);
  136. GLOBAL DWORD KERNENTRY FlValidateSecurity(SECURITY_ATTRIBUTES *);
  137. GLOBAL BOOL KERNENTRY FGetDosHandles(PDB *);
  138. GLOBAL HANDLE KERNENTRY SearchForHandle(PDB *, OBJ *, DWORD);
  139. GLOBAL HANDLE KERNENTRY ConvertToGlobalHandle(HANDLE);
  140. /* ------------------------------------------------------------ */
  141. /************************************************************************/