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.

160 lines
4.9 KiB

  1. DECLARE_HANDLE(HDD_OBJ);
  2. #ifndef W32PID
  3. #define W32PID ULONG
  4. #endif
  5. /*****************************Struct***************************************\
  6. *
  7. * DD_BASEOBJECT
  8. *
  9. \**************************************************************************/
  10. typedef struct _DD_BASEOBJECT
  11. {
  12. HANDLE hHmgr;
  13. ULONG ulShareCount;
  14. USHORT cExclusiveLock;
  15. USHORT BaseFlags;
  16. ULONG_PTR Tid;
  17. } DD_BASEOBJECT, *PDD_BASEOBJECT, *PDD_OBJ;
  18. /*****************************Struct***************************************\
  19. *
  20. * OBJECTOWNER
  21. *
  22. * Description:
  23. *
  24. * This object is used for shared and exclusive object ownership
  25. *
  26. * Fields for shared Object:
  27. *
  28. * Pid : 31
  29. * Lock : 1
  30. *
  31. \**************************************************************************/
  32. //
  33. // The lock and the Pid share the same DWORD.
  34. //
  35. // It seems that this is safe from the word tearing problem on the Alpha architecture
  36. // due to the fact that we always use the InterlockedCompareExchange loop for
  37. // the Lock and we require that the lock is set when setting the Pid.
  38. //
  39. typedef struct _DD_OBJECTOWNER_S
  40. {
  41. ULONG Lock:1;
  42. W32PID Pid_Shifted:31; // The lowest two bits of the PID are
  43. // reserved for application use. However,
  44. // the second bit is used by the
  45. // OBJECT_OWNER_xxxx constants and so we
  46. // use 31 bits for the Pid_Shifted field.
  47. // WARNING: do not access this field directly,
  48. // but rather via the macros below.
  49. } DD_OBJECTOWNER_S, *PDD_OBJECTOWNER_S;
  50. typedef union _DD_OBJECTOWNER
  51. {
  52. DD_OBJECTOWNER_S Share;
  53. ULONG ulObj;
  54. } DD_OBJECTOWNER, *PDD_OBJECTOWNER;
  55. #define OBJECT_OWNER_ERROR ( 0x80000022)
  56. #define OBJECT_OWNER_PUBLIC ( 0x00000000)
  57. #define OBJECT_OWNER_CURRENT ( 0x80000002)
  58. #define OBJECT_OWNER_NONE ( 0x80000012)
  59. // Note: when accessing the Pid_Shifted field the compiler will shift the
  60. // value by one bit to account for the field being only in the upper 31
  61. // bits of the OBJECTOWNER_S structure. For example, if the OBJECTOWNER_S
  62. // is 8, the Pid_Shifted would be only 4. However, since we are really
  63. // interested in the upper 31 bits of the PID, this shifting is not
  64. // appropriate (we need masking instead). I'm not aware of any compiler
  65. // primitives that will accomplish this and will use the macros below
  66. // instead.
  67. #define DD_LOCK_MASK 0x00000001
  68. #define DD_PID_MASK 0xfffffffe
  69. #define DD_PID_BITS 0xfffffffc // The actual bits used by the PID
  70. #define DD_W32GetCurrentPID() (W32PID)(HandleToUlong(PsGetCurrentProcessId()) & DD_PID_BITS)
  71. #define DD_W32GetCurrentTID() (W32PID)HandleToUlong(PsGetCurrentThreadId())
  72. #define DD_OBJECTOWNER_PID(ObjectOwner) \
  73. ((W32PID) ((ObjectOwner).ulObj & DD_PID_MASK))
  74. #define DD_SET_OBJECTOWNER_PID(ObjectOwner, Pid) \
  75. ((ObjectOwner).ulObj) = ((ObjectOwner).ulObj & DD_LOCK_MASK) | ((Pid) & DD_PID_MASK);
  76. /*****************************Struct***************************************\
  77. *
  78. * ENTRY
  79. *
  80. * Description:
  81. *
  82. * This object is allocated for each entry in the handle manager and
  83. * keeps track of object owners, reference counts, pointers, and handle
  84. * objt and iuniq
  85. *
  86. * Fields:
  87. *
  88. * einfo - pointer to object or next free handle
  89. * ObjectOwner - lock object
  90. * ObjectInfo - Object Type, Unique and flags
  91. * dwReserved -
  92. *
  93. \**************************************************************************/
  94. typedef union _DD_EINFO
  95. {
  96. PDD_OBJ pobj; // Pointer to object
  97. HDD_OBJ hFree; // Next entry in free list
  98. } DD_EINFO;
  99. typedef UCHAR DD_OBJTYPE;
  100. typedef struct _DD_ENTRY
  101. {
  102. DD_EINFO einfo;
  103. DD_OBJECTOWNER ObjectOwner;
  104. USHORT FullUnique;
  105. DD_OBJTYPE Objt;
  106. UCHAR Flags;
  107. ULONG_PTR dwReserved;
  108. } DD_ENTRY, *PDD_ENTRY;
  109. // entry.Flags flags
  110. #define DD_HMGR_ENTRY_UNDELETABLE 0x0001
  111. /*********************************Class************************************\
  112. * class OBJECT
  113. *
  114. * Basic engine object. All objects managed by the handle manager are
  115. * derived from this.
  116. *
  117. * History:
  118. * Sat 11-Dec-1993 -by- Patrick Haluptzok [patrickh]
  119. * Move the lock counts and owning tid to the object.
  120. *
  121. * 18-Dec-1989 -by- Donald Sidoroff [donalds]
  122. * Wrote it.
  123. \**************************************************************************/
  124. class DD_OBJECT : public _DD_BASEOBJECT /* obj */
  125. {
  126. public:
  127. DD_OBJECT() {}
  128. ~DD_OBJECT() {}
  129. //
  130. // Number of exclusive references by tid.
  131. //
  132. LONG cExclusiveLockGet() { return(cExclusiveLock); }
  133. LONG cShareLockGet() { return(ulShareCount); }
  134. HANDLE hGet() { return(hHmgr); }
  135. };