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.

948 lines
36 KiB

  1. /************************************************************************/
  2. /* */
  3. /* OBJECT.H -- General Object Manager Definitions */
  4. /* */
  5. /************************************************************************/
  6. /* Author: Gene Apperson */
  7. /* Copyright: 1991 Microsoft */
  8. /************************************************************************/
  9. /* File Description: */
  10. /* */
  11. /* */
  12. /************************************************************************/
  13. /* Revision History: */
  14. /* */
  15. /* */
  16. /************************************************************************/
  17. // This file may have been implicitly included if the client included KERNEL32.H
  18. // If so, we don't need to define and declare everything again. We match this
  19. // directive at the bottom of the file.
  20. #ifndef typObjAny
  21. /* ------------------------------------------------------------ */
  22. /* Object Type Codes */
  23. /* ------------------------------------------------------------ */
  24. #define typObjSemaphore 1
  25. #define typObjEvent 2
  26. #define typObjMutex 3
  27. #define typObjCrst 4
  28. #define typObjTimer 5
  29. #define typObjProcess 6
  30. #define typObjThread 7
  31. #define typObjFile 8
  32. #define typObjChange 9
  33. #define typObjConsole 10
  34. #define typObjIO 11
  35. #define typObjConScreenbuf 12
  36. #define typObjMapFile 13
  37. #define typObjSerial 14
  38. #define typObjDevIOCtl 15
  39. #define typObjPipe 16
  40. #define typObjMailslot 17
  41. #define typObjToolhelp 18
  42. #define typObjSocket 19
  43. #define typObjR0ObjExt 20
  44. #define typObjMsgIndicator 21
  45. #ifdef WOW32_EXTENSIONS
  46. #define typObjTDBX 22
  47. #endif
  48. #define typObjAny 0xffffffff
  49. #define typObjNone 0
  50. // to let us determine what type of object were dealing with in a
  51. // wait condition
  52. #define typObjFirstSync typObjSemaphore
  53. #define typObjLastSync typObjTimer
  54. #define typObjFirstWait typObjProcess
  55. #define typObjLastWait typObjIO
  56. #define typObjMaxValid typObjMsgIndicator
  57. #define typObjShiftAdjust (-1)
  58. /* ------------------------------------------------------------ */
  59. /* Common Object Definition */
  60. /* ------------------------------------------------------------ */
  61. // This structure defines a generic object. There is an instance
  62. // of this structure at the head of all objects in the system. The
  63. // generic object manipulation functions operate on fields in this
  64. // structure and call on the object specific manipulation functions
  65. // based on the object type when necessary.
  66. // IMPORTANT NOTE: all synchronization objects contain a field called
  67. // pwnWait which must be at the same offset for all types. Since
  68. // we are constrained by NT compatibility to keep critical section
  69. // structures a certain size, you cannot change this structure
  70. // without ensuring that this field is at the same offset in all
  71. // sync objects and that critical sections are NT compatible in
  72. // size.
  73. typedef struct _obj {
  74. BYTE typObj; // object type
  75. BYTE objFlags; // object flags
  76. WORD cntUses; // count of this objects usage
  77. } OBJ;
  78. typedef OBJ *POBJ;
  79. #define fObjTypeSpecific 0x80 // meaning depends on object type
  80. #define fObjTypeSpecific2 0x40 // meaning depends on object type
  81. #define fObjTypeSpecific3 0x20 // meaning depends on object type
  82. // type-specific objFlag bits.
  83. #define fNewCrstBlock fObjTypeSpecific // (typObjCrst) high bit for thread blocked while crst owned
  84. #define fEvtManualReset fObjTypeSpecific // (typObjEvent) set for manual reset
  85. #define fTimerRing3 fObjTypeSpecific2 // (typObjTimer) timer has ring-3 completion
  86. // Every object type contains a nested generic object as its first member
  87. #define COMMON_OBJECT OBJ objBase;
  88. // This is a generic non-synchronization object which can be waited on
  89. // all of them include a pointer to an event object which is created when
  90. // they are.
  91. #define COMMON_NSOBJECT OBJ objBase; \
  92. struct _evt *psyncEvt; // here's the embedded event
  93. // This is the external object structure which is used to
  94. // supply a Win32 handle to an external component's structure.
  95. // e.g. Winsock socket handles
  96. typedef struct _external_obj {
  97. COMMON_OBJECT // it is an object
  98. DWORD context; // typically a pointer for use by the external component
  99. } EXTERNAL_OBJ, * PEXTERNAL_OBJ;
  100. /* ------------------------------------------------------------ */
  101. /* Synchronization Object & Structure Definition */
  102. /* ------------------------------------------------------------ */
  103. #define fWaitDefault 0 // default flags
  104. #define fWaitAllFlag 1 // set for wait all, clear for wait any
  105. #define fWaitCrst 2 // special critical section wait
  106. typedef struct _wnod {
  107. struct _wnod *pwnNext; // pointer to next in circular list
  108. struct _wnod *pwnCirc; // pointer to wait node in next circular list
  109. struct TDBX *ptdbxWait; // thread waiting
  110. struct _synco *pobjWait; // object being waited on
  111. } WNOD;
  112. // Every object name is stored in a structure like this one. Each hash table entry
  113. // points to a forward linked list of these structures.
  114. typedef struct _objnamestruct {
  115. struct _objnamestruct *NextOName; // next in hash list
  116. OBJ *ObjPtr; // named object this refers to
  117. char NameStr[1]; // name string
  118. } OBJNAME;
  119. // This is a generic synchronization object which is a subset of the other
  120. // synchronization objects
  121. typedef struct _synco {
  122. COMMON_OBJECT
  123. WNOD *pwnWait; // pointer to the wait node for this object
  124. LONG cntCur; // current count to test state, != 0 is signaled
  125. OBJNAME *NameStruct; // name structure for this object
  126. } SYNCO;
  127. // A semaphore object
  128. // IMPORTANT NOTE: This structure must fit inside the NT KSEMAPHORE type, where
  129. // sizeof(KSEMAPHORE) is 20.
  130. typedef struct _sem {
  131. COMMON_OBJECT
  132. WNOD *pwnWait; // pointer to the wait node for this object
  133. LONG cntCur; // current count of semaphore availability
  134. OBJNAME *NameStruct; // name structure for this object
  135. LONG cntMax; // maximum allowed count
  136. } SEM;
  137. // A Mutex
  138. typedef struct _mutx {
  139. COMMON_OBJECT
  140. WNOD *pwnWait; // pointer to the wait node for this object
  141. LONG cntCur; // current count of object
  142. OBJNAME *NameStruct; // name structure for this object
  143. struct TDBX *ptdbxOwner; // owner thread
  144. struct _mutx *SysMutexLst; // system list of mutexes
  145. } MUTX;
  146. typedef MUTX *PMUTX;
  147. // This structure defines a critical section. Although it has the
  148. // typObj field, a critical section is not a true object. This limitation
  149. // is to provide structure size compatibility with NT.
  150. // IMPORTANT NOTE: Since the pwnWait is at a specific offset in order
  151. // to use generic sync object functions, it is important not to
  152. // reorder this structure's members unless absolutely necessary.
  153. // If you do, be sure to look at the OBJ data type and other
  154. // synchronization object types.
  155. typedef struct _crst {
  156. BYTE typObj; // type of object
  157. BYTE objFlags; // object flags
  158. WORD objPadding; // OBJ.cntUses not needed
  159. LONG cntRecur; // recursion count of ownership
  160. struct TDBX *ptdbxOwner; // owner thread of this critical section
  161. struct TDBX *ptdbxWait; // pointer to the first waiting TDB
  162. LONG cntCur; // count of critical section ownership
  163. struct _crst *SysCrstLst; // system list of critical sections
  164. LST *pdbLst; // list of owning processes
  165. struct _crstexport *pextcrst; // pointer to external critical section
  166. } CRST;
  167. // This is the exported critical section structure which is used to
  168. // indirectly access the internal critical section structure and cleanup.
  169. typedef struct _crstexport {
  170. COMMON_OBJECT // it is an object
  171. CRST *crstInternal; // pointer to internal critical section
  172. } CRST_EXPORT;
  173. // This structure and defines make up an event object.
  174. // IMPORTANT NOTE: This structure must fit inside the NT KEVENT type, where
  175. // sizeof(KEVENT) is 16.
  176. typedef struct _evt {
  177. COMMON_OBJECT
  178. WNOD *pwnWait; // pointer to the wait node for this object
  179. LONG cntCur; // signaled state
  180. OBJNAME *NameStruct; // name structure for this object
  181. } EVT;
  182. typedef EVT *PEVT;
  183. // so we have access to generic NSOBJ's data structure
  184. typedef struct _nsobj {
  185. COMMON_NSOBJECT
  186. } NSOBJ;
  187. #define LCRST_DEFINED // disable duplicate definition in syslevel.h
  188. // Include heirarchical critical section support
  189. #include <syslevel.h>
  190. // This is a heirarchical critical section used to ensure
  191. // deadlock resistant code
  192. typedef struct _lcrst {
  193. CRST cstSync;
  194. #ifdef SYSLEVELCHECK
  195. SYSLVL slLevel;
  196. #endif
  197. } LCRST;
  198. typedef LCRST *LPLCRST;
  199. typedef struct _createdata16 {
  200. LPVOID pProcessInfo; // LPPROCESS_INFORMATION
  201. LPVOID pStartupInfo; // LPSTARTUPINFO
  202. LPVOID pCmdLine; // points to command line
  203. } CREATEDATA16;
  204. // Include the TIB definition
  205. #include <k32share.h>
  206. #include <apc.h>
  207. #define TLS_MINIMUM_AVAILABLE_GLOBAL 8
  208. // Thread Data Block structure.
  209. //
  210. // !!!! BUGBUG !!!!
  211. // This definition is duplicated in object.inc and core\inc\object16.inc
  212. //
  213. typedef struct _tdb
  214. {
  215. COMMON_NSOBJECT // standard waitable non-synchronization object
  216. #ifdef WOW
  217. TIB * ptib; // Thread Information Block--from k32share.h
  218. #else // WOW
  219. TIB tib; // Thread Information Block--from k32share.h
  220. #endif ; else WOW
  221. // opengl32 depend on TslArray at offset 0x88 from pTIB. Someone has remove the ppdbProc
  222. // and wnodLst probably for good reasons. But to keep apps happy, we will add 2 dowords back
  223. // currently sizeof(TIB)==56
  224. //struct _pdb* ppdbProc; // DON'T MOVE THIS RELATIVE TO tib!! (for M3 NTcompat)
  225. DWORD cntHandles; // count of handles to this thread
  226. WORD selEmul; // selector to 80x87 emulator data area
  227. WORD selTib; // selector to the TIB for this process
  228. DWORD dwStatus; // thread status/termination code
  229. DWORD flFlags; // state of thread
  230. DWORD dwPad1; // just to pad
  231. //WNLST wnodLst; // embedded structure for synchronization
  232. //
  233. // keep R0ThreadHandle offset at 0x54 for Javasup.vxd
  234. //
  235. DWORD R0ThreadHandle; // ring 0 thread handle
  236. // Warning !!! move dwPad2 below cus SAS 6.12 hardcoded pStackBase at offset 0x54 from
  237. // pTib. It also used the defunc field pStackTerm ( now dwPad2 ). Whoever gave this
  238. // internal structure to SAS is a bonehead.
  239. // Break SAS and see what happen
  240. WORD wMacroThunkSelStack16; // Used to be TIBSTRUCT.selStack16
  241. WORD wPad;
  242. VOID * pvMapSSTable; //Table of 16-bit ss's for flat thunks
  243. DWORD dwCurSS; //Current default 16-bit ss for flat thunks
  244. DWORD dwCurNegBase; //negative base of current default ss
  245. VOID * pvThunkConnectList; //head of list of in-progress thunk handshakes
  246. VOID * pvExcept16; //Head of 16-bit thread exception handler chain
  247. PCONTEXT tdb_pcontext; // pointer to context. if 0, goto ring 0
  248. HANDLE tdb_ihteDebugger; // thread handle for debugger
  249. struct _der * tdb_pderDebugger; // pointer to debugger control block
  250. DWORD ercError; // extended error code for last thread error
  251. VOID * pvEmulData; // Pointer to emulator data area
  252. VOID * pStackBase; // stack object base address
  253. struct TDBX * ptdbx; // ring 0 per thread data pointer
  254. // wnodLst is 8 bytes, tib has grown, only need 4 bytes here
  255. DWORD dwPad2; // just to pad, see comment on ppdbProc.
  256. LPVOID TlsArray[TLS_MINIMUM_AVAILABLE+TLS_MINIMUM_AVAILABLE_GLOBAL]; // thread local storage array
  257. LONG tpDeltaPri; // delta from base priority class
  258. TPITERM tdb_tpiterm;// tpi and termination data union
  259. struct _createdata16 * pCreateData16; // ptr to creat data for 16-bit creat
  260. DWORD dwAPISuspendCount; // suspend/resume api count
  261. LPSTR lpLoadLibExDir; // ptr to LoadLibraryEx() dir
  262. // For 16-bit threads only
  263. WORD wSSBig; // selector of optional Big Stack
  264. WORD wPad2;
  265. DWORD lp16SwitchRec;
  266. DWORD tdb_htoEndTask;
  267. DWORD tdb_cMustCompletely;
  268. #ifdef DEBUG
  269. DWORD apiTraceReenterCount; // api trace reenter count
  270. PWORD pSavedRip; // pointer to saved rip string from 16 bit krnl
  271. LPVOID
  272. TlsSetCallerArray[TLS_MINIMUM_AVAILABLE+TLS_MINIMUM_AVAILABLE_GLOBAL]; // caller's to TlsSetValue
  273. #endif
  274. #ifdef WOW
  275. HANDLE hTerminate;
  276. #endif
  277. } TDB;
  278. typedef TDB *PTDB;
  279. #define TDBSTUBSIZE sizeof(TDB)
  280. /* Flags for fields of TDB.flFlags
  281. */
  282. #define fCreateThreadEvent 0x00000001
  283. #define fCancelExceptionAbort 0x00000002
  284. #define fOnTempStack 0x00000004
  285. #define fGrowableStack 0x00000008
  286. #define fDelaySingleStep 0x00000010
  287. #define fOpenExeAsImmovableFile 0x00000020
  288. #define fCreateSuspended 0x00000040
  289. #define fStackOverflow 0x00000080
  290. #define fNestedCleanAPCs 0x00000100
  291. #define fWasOemNowAnsi 0x00000200
  292. #define fOKToSetThreadOem 0x00000400
  293. #define fTermCleanupStack 0x00000800
  294. #define fInCreateProcess 0x00001000
  295. #define fHoldDisplay 0x00002000
  296. #define fHoldSystem 0x00004000
  297. /* Flags for fields of PDB.flFlags
  298. */
  299. #define fDebugSingle 0x00000001
  300. #define fCreateProcessEvent 0x00000002
  301. #define fExitProcessEvent 0x00000004
  302. #define fWin16Process 0x00000008
  303. #define fDosProcess 0x00000010
  304. #define fConsoleProcess 0x00000020
  305. #define fFileApisAreOem 0x00000040
  306. #define fNukeProcess 0x00000080
  307. #define fServiceProcess 0x00000100
  308. #define fProcessCreated 0x00000200
  309. #define fDllRedirection 0x00000400
  310. #define fLoginScriptHack 0x00000800 //DOS app loaded into existing console and TSR'd
  311. /* These bits can be in either the TDB or the PDB
  312. */
  313. #define fSignaled 0x80000000
  314. #define fInitError 0x40000000
  315. #define fTerminated 0x20000000
  316. #define fTerminating 0x10000000
  317. #define fFaulted 0x08000000
  318. #define fTHISFLAGISFREE 0x04000000
  319. #define fNearlyTerminating 0x00800000
  320. #define fDebugEventPending 0x00400000
  321. #define fSendDLLNotifications 0x00200000
  322. /* Process Data Block Structure and support defines and structures.
  323. */
  324. typedef VOID (KERNENTRY *PFN_CONTROL)(DWORD CtrlType);
  325. /* Environment data block for various per-process data including arguments,
  326. ** current directories, handles, and environment strings. This data block
  327. ** resides in the scratch heap.
  328. */
  329. typedef struct _edb {
  330. char * pchEnv; /* environment block (preceded by PchEnvHdr) */
  331. DWORD unused; /* was cbEnvMax */
  332. char * szCmdA; /* command line (ANSI copy)*/
  333. char * szDir; /* current directory of process */
  334. STARTUPINFO * lpStartupInfo; /* pointer to startup information */
  335. HANDLE hStdIn; /* handle of standard in */
  336. HANDLE hStdOut; /* handle of standard out */
  337. HANDLE hStdErr; /* handle of standard error */
  338. HANDLE hProc; /* handle to the owning process. */
  339. struct _console * pInheritedConsole; /* Console to inherit if needed */
  340. DWORD ctrlType; /* ctrlNone, ctrlC, ctrlBreak */
  341. SEM * psemCtrl; /* Protects access to control data */
  342. EVT * pevtCtrl; /* Control C or Break event */
  343. TDB * ptdbCtrl; /* Control handler thread */
  344. PFN_CONTROL * rgpfnCtrl; /* Array of Control C or Break handlers */
  345. int cpfnCtrlMac; /* Last item in array */
  346. int cpfnCtrlMax; /* Size of array */
  347. char * rgszDirs[26]; /* array of drive directories */
  348. LPWSTR szCmdW; /* command line (Unicode copy)*/
  349. char * szDirO; /* current directory OEM copy*/
  350. } EDB;
  351. // We need a fake DOS MCB structure at the start of our Win32 environment
  352. // block, because this block also doubles as the DOS environment for Win16
  353. // apps.
  354. struct _dosMCB {
  355. BYTE type; // Set to 'M'
  356. BYTE owner_lo; // Owner PSP
  357. BYTE owner_hi;
  358. BYTE size_lo; // Size (in paragraphs)
  359. BYTE size_hi;
  360. BYTE unused[11];
  361. };
  362. // PCHENVHDR: This header structure must precede the environment strings
  363. // block pointed to by _edb->pchEnv. It contains the info about the
  364. // block allocation.
  365. typedef struct _pchEnvHdr {
  366. DWORD dwSig; /* Signature: must be PCHENVHDR_SIG */
  367. DWORD cbReserved; /* # of bytes reserved (must be page-size divisible) */
  368. DWORD cbCommitted; /* # of bytes committed (must be page-size divisible) */
  369. struct _pdb * ppdb; /* PDB32 who's context this belongs to. */
  370. struct _dosMCB MCB; /* Fake DOS MCB for compatibility */
  371. // Do not add any fields after the MCB. The MCB must immediately precede
  372. // the environment strings for compatibility.
  373. } PCHENVHDR, *LPPCHENVHDR;
  374. #define PCHENVHDR_SIG 0x45484350 /* 'PCHE' */
  375. // MODREF - a double, doubly linked list of module references.
  376. // Each loaded module has its own MODREF record. Follow the
  377. // nextMod element to get a list of modules owned by the process.
  378. // Follow the nextPdb element to get a list of PDBs that refer
  379. // to this module.
  380. #define fModRecycle 0x8000 /* This modules read only sections
  381. ** should be recycled in context (i.e. before they go away)
  382. */
  383. #define fModRetain 0x400 /* Used to prevent child from getting
  384. ** freed before the parent
  385. */
  386. #define fModRefSnapped 0x200 /* This module's IATs are fixed up
  387. ** in this context (so what is
  388. ** 'fModFixupIAT' below?)
  389. */
  390. #define fModPrivateResource 0x100/* the resource object has been privatized
  391. ** in this process. Attaches should not be
  392. ** made to the resource object.
  393. */
  394. #define fModFixupIAT 0x80 /* the IAT has been already fixed
  395. ** up for debugging
  396. */
  397. #define fModNoThrdNotify 0x40 /* doesn't need thread notifications */
  398. #define fModHasStaticTLS 0x20 /* this module has static TLS */
  399. #define fModRefShared 0x10 /* this MODREF is in a shared arena */
  400. #define fModAttach 0x8 /* process attach notification has been sent
  401. ** to this module in this process context
  402. */
  403. #define fModDebug 0x4 /* debug notification has been sent
  404. ** to the debugger for this module
  405. */
  406. #define fModPrivate 0x2 /* the module has been privatized in this
  407. ** process. Attaches should not be made.
  408. */
  409. #define fModBusy 0x1 /* set to detect dependency loops */
  410. #define MOD_USAGE_MAX 0xffff
  411. typedef struct _tagMODREF {
  412. struct _tagMODREF
  413. * nextMod, // next module in this process
  414. * prevMod,
  415. * nextPdb, // next process linked to this mod
  416. * prevPdb;
  417. IMTE imte; // index in module table
  418. WORD usage; // reference count this process to this module
  419. WORD flags; // fModFlags as set above
  420. WORD cntRefs; // count of implicit references
  421. struct _pdb *ppdb; // process that owns module
  422. struct _tagMODREF *refs[1]; // implicit refs of this module, variable length
  423. // Must be last item in structure
  424. } MODREF;
  425. // Entrypoints into WSOCK32.DLL
  426. struct socket_epts {
  427. DWORD recv;
  428. DWORD arecv;
  429. DWORD send;
  430. DWORD asend;
  431. DWORD close;
  432. };
  433. #define MAX_PROCESS_DWORD 1
  434. typedef struct _pdb {
  435. COMMON_NSOBJECT // standard waitable non-synchronization object
  436. DWORD dwReserved1; // so that other offsets don't change
  437. DWORD dwReserved2; // so that other offsets don't change
  438. DWORD dwStatus; // process termination status code
  439. DWORD wasDwImageBase; // Points to header of process (MZ + stub)
  440. struct heapinfo_s *hheapLocal; // DON'T MOVE THIS!!! handle to heap in private memeory
  441. DWORD hContext; // handle to process' private memory context
  442. DWORD flFlags; // debugging and inheritance flags
  443. PVOID pPsp; // linear address of PSP
  444. WORD selPsp; // selector of the PSP for the process
  445. SHORT imte; // index to module table entry for this process
  446. SHORT cntThreads; // number of threads in this process
  447. SHORT cntThreadsNotTerminated; // threads not past termination code
  448. SHORT cntFreeLibRecurse; // keep track of recursion into FreeLibrary
  449. SHORT R0ThreadCount; // ring 0 version of same
  450. HANDLE hheapShared; // handle to heap in shared memory
  451. DWORD hTaskWin16; // associated Win16 task handle
  452. struct fvd_s * pFvd; // ptr to memory mapped file view descriptors
  453. EDB * pedb; // pointer to environment data block
  454. struct _htb * phtbHandles;
  455. struct _pdb * ppdbParent; // pointer to PDB of parent process
  456. MODREF * plstMod; // pointer to process module table list
  457. struct _lst * plstTdb; // pointer to list of process threads
  458. struct _dee * pdb_pdeeDebuggee; // pointer to debuggee control block
  459. struct lhandle_s *plhFree; // Local heap free handle list head ptr
  460. DWORD pid; // id, same as initial thread id
  461. LCRST crstLoadLock; // per-process load synch (hierarchical)
  462. struct _console * pConsole; // pointer to Console for this process
  463. DWORD TlsIdxMask[((TLS_MINIMUM_AVAILABLE+31)/32)]; // mask of used TLS idxs
  464. DWORD adw[MAX_PROCESS_DWORD]; // free-form storage
  465. struct _pdb * ppdbPGroup; // process group this process belongs to (default 0)
  466. MODREF * pModExe; // parent EXE ModRef record
  467. LPTOP_LEVEL_EXCEPTION_FILTER pExceptionFilter; // set by SetUnhandledExceptionFilter
  468. LONG pcPriClassBase; // priority value of this processes' pri class
  469. struct heapinfo_s *hhi_procfirst; // linked list of heaps for this process
  470. struct lharray_s *plhBlock; // local heap lhandle blocks
  471. struct socket_epts * psock_epts; // socket entrypoints
  472. struct _console * pconsoleProvider; // pconsole that winoldapp is providing.
  473. WORD wEnvSel; // selman alloced DOS environment selector
  474. WORD wErrorMode; // handling of critical errors
  475. PEVT pevtLoadFinished; // waiting for load to be finished
  476. WORD hUTState; // UT info
  477. BYTE bProcessAcpiFlags; // ACPI flags for this process, see def below
  478. BYTE bPad3;
  479. LPCSTR lpCmdLineNoQuote; // Optional unquoted command line (apphack)
  480. } PDB;
  481. //
  482. // Flags def for bProcessAcpiFlags
  483. //
  484. #define PROCESS_ACPI_FLAGS_WAKEUP_LT_DONT_CARE 0x00
  485. #define PROCESS_ACPI_FLAGS_WAKEUP_LT_LOWEST_LATENCY 0x01
  486. #define PDBSTUBSIZE sizeof(PDB)
  487. typedef PDB *PPDB;
  488. /* File Data Block Structure.
  489. */
  490. /* SPECIAL NOTE on memory mapped files and cached file handles
  491. * CreateFile(filename, FILE_FLAG_MM_CACHED_FILE_HANDLE);
  492. * In this case the caller indicates an intention to later
  493. * call CreateFileMapping(hFile, ...) and desires that the file
  494. * handle we will using be a cached file handle.
  495. * So we store away the filename and fsAccessDos in the FDB and
  496. * in CreateFileMapping() retrieve the filename and flgs for use
  497. * in implementing cached file handles, where extended handles are
  498. * not available. eg. real-mode netware drivers
  499. */
  500. typedef struct _cfh_id {
  501. DWORD fsAccessDos; /* dos openfile flgs: used for cached fh
  502. * of memory mapped files
  503. */
  504. LPSTR lpFilename; /* filename stored only for
  505. * cached Memory mapped files
  506. * win32 loader modules and
  507. * delete_on_close
  508. */
  509. } CFH_ID;
  510. typedef struct _fdb {
  511. COMMON_NSOBJECT // standard waitable non-synchronization object
  512. WORD hdevDos; /* DOS device handle */
  513. WORD wDupSrcPSPSel; /* NETX: if inter-process dup'ed
  514. * holds the PSP dup'ed from so that
  515. * PSP will remain around till this
  516. * handle gets closed.
  517. */
  518. CFH_ID cfhid;
  519. DWORD devNode; // The devvice node where the handle lives on
  520. DWORD dwCountRequestDeviceWakeup;
  521. } FDB, *PFDB;
  522. /*
  523. * Spl value for FDB.fsAccessDos to indicate that filename stored should be
  524. * deleted on close.
  525. */
  526. #define DELETE_ON_CLOSE_FILENAME -1
  527. /* Find Change Notify Data Block Structure.
  528. */
  529. typedef struct _fcndb {
  530. COMMON_NSOBJECT // base of every ns object structure
  531. DWORD hChangeInt; /* internal change handle */
  532. } FCNDB;
  533. typedef FCNDB *PFCNDB;
  534. /* Pipe Data Block Structure.
  535. */
  536. typedef struct _pipdb {
  537. COMMON_OBJECT // base of every object structure
  538. BYTE * hMem; // Mem handle of pipe
  539. DWORD hNmPipe; // Named pipe handle (hInvalid if anon)
  540. DWORD rdRef; // Ref count on read handle
  541. DWORD wrRef; // Ref count on write handle
  542. DWORD pszByt; // Size of hMem (pipe) in bytes
  543. DWORD wPtr; // write pointer (offset in hMem)
  544. // Pointer to last byte written
  545. DWORD rPtr; // read pointer (offset in hMem)
  546. // Pointer to next byte to read
  547. EVT * wBlkEvnt; // write event handle (waiting for room to write)
  548. EVT * rBlkEvnt; // read event handle (waiting for data to read)
  549. } PIPDB;
  550. /* MailSlot Data Block Structure.
  551. */
  552. typedef struct _msdb {
  553. COMMON_OBJECT // base of every object structure
  554. LPSTR lpMSName; // Pnt to name of mailslot (== 0 for
  555. // read (CreateMailslot) handle)
  556. DWORD hMSDos; // INT 21 mailslot handle (== 0xFFFFFFFF
  557. // for write (CreateFile) handle)
  558. } MSDB;
  559. /* ToolHelp Data Block Structure.
  560. */
  561. typedef struct _tlhpdb {
  562. COMMON_OBJECT // base of every object structure
  563. DWORD ClassEntryCnt;
  564. BYTE * ClassEntryList; // actually (CLASSENTRY32 *)
  565. DWORD HeapListCnt;
  566. BYTE * HeapList; // actually (HEAPLIST32 *)
  567. DWORD ProcessEntryCnt;
  568. BYTE * ProcessEntryList; // actually (PROCESSENTRY32 *)
  569. DWORD ThreadEntryCnt;
  570. BYTE * ThreadEntryList; // actually (TREADENTRY32 *)
  571. DWORD ModuleEntryCnt;
  572. BYTE * ModuleEntryList; // actually (MODULEENTRY32 *)
  573. } TLHPDB;
  574. /* Device IO Control Object
  575. */
  576. typedef struct _diodb {
  577. COMMON_OBJECT // base of every object structure
  578. DWORD pDDB; /* VxD/device DDB */
  579. LPSTR lpUnloadOnCloseModuleName; /* delete_on_close for a vxd */
  580. char DDB_Name[8];
  581. } DIODB;
  582. /* Serial Data Block Structure
  583. */
  584. #define OVERLAPPED_OPEN 1
  585. #define READEVENT_INUSE 2
  586. #define WRITEEVENT_INUSE 4
  587. typedef struct _sdb {
  588. COMMON_OBJECT // base of every object structure
  589. DWORD SerialHandle;
  590. EVT * pWriteEvent;
  591. EVT * pReadEvent;
  592. EVT * pWaitEvent;
  593. DWORD Flags;
  594. DWORD DevNode;
  595. DWORD dwCountRequestDeviceWakeup;
  596. } SDB;
  597. typedef VOID (CALLBACK *PTIMER_APC_ROUTINE)(LPVOID,ULONG,LONG);
  598. // Timer object.
  599. //
  600. // Notes:
  601. // The timerdb must ALWAYS be pagelocked. This is consistent
  602. // with the requirement that the structure passed to KeSetTimer
  603. // be pagelocked. Furthermore, we use the non-preemptibility of
  604. // of ring-0 code to serialize access to many parts of the structure
  605. // (due to the fact that much of this code has to run at event time.)
  606. // This non-preemptibility is guaranteed only if the structure is
  607. // locked.
  608. //
  609. // Timers can be created at ring-0 or ring-3. If a timer is created at
  610. // ring-3, the memory is always allocated and deallocated by kernel32.
  611. // Kernel32 also makes sure that an explicit canceltimer is always done
  612. // on the timer before it is finally freed - we depend on this fact
  613. // to do the proper cleanup for timerr3apc's.
  614. //
  615. // Timers created at ring-3 can be passed to Ke* routines.
  616. //
  617. // Timers created at ring-0 cannot be passed to SetWaitableTimer() at
  618. // ring-3. (There are some nasty cleanup problems associated with this
  619. // due to the fact that ring-0 timers are freed by the device driver
  620. // with no notification given to the system.)
  621. //
  622. // We use the cntUses field to determine whether a timer was created
  623. // at ring 3.
  624. //
  625. // Synchronization:
  626. //
  627. // typObj Static, none needed
  628. // objFlags
  629. // fTimerIsRing3 by being in a no-preempt section
  630. // cntUses Used by handle manager
  631. // pwnWait WaitR0
  632. // cntCur WaitR0 [w/ one exception: see [1])
  633. // NameStruct Krn32Lock - used only at ring3
  634. // lpNextTimerDb by being in a no-preempt section
  635. // hTimeout by being in a no-preempt section
  636. // DueTime by being in a no-preempt section
  637. // Completion by being in a no-preempt section
  638. // lPeriod by being in a no-preempt section
  639. //
  640. // [1] Because KeSetTimer has to unsignal the timer, and be
  641. // able to do it at event time, it pokes a zero directly
  642. // into cntCur. But this is ok because the only code
  643. // that signals timers is TimerDoTimeout which is
  644. // non-preemptive.
  645. //
  646. // Flag descriptions:
  647. //
  648. // fTimerIsEventHandle
  649. // hTimeout - a timeout handle
  650. //
  651. // fTimerIsRing3
  652. // If the COMPLETION is non-null, this bit indicates whether the
  653. // COMPLETION points to a TIMERR3APC (ring-3 completion) or a KDPC
  654. // (ring-0 completion.) The value of this bit is undefined at any
  655. // other time.
  656. //
  657. // Field descriptions:
  658. //
  659. // <common-obj and common-sync stuff omitted>
  660. //
  661. // lpNextTimerDb:
  662. // All active timers that were set with fResume TRUE are linked into
  663. // TimerSysLst (for the purpose of knowing how to program the power
  664. // timer.) This field is NULL when the timer is inactive or active
  665. // without fResume.
  666. //
  667. // hTimeout:
  668. // If the timer is active, this field contains the handle to the
  669. // underlying VMM hTimeout. If the timer is inactive, this
  670. // field is NULL. If the timer is in the in-progress state,
  671. // this field is undefined (actually points to a stale VMM timeout
  672. // handle!)
  673. //
  674. //
  675. // DueTime:
  676. // If the timer is active, contains the absolute time that the
  677. // timer is due to go off. Expressed as a FILETIME converted from
  678. // GetSystemTime. Undefined if the timer isn't active.
  679. //
  680. // Completion:
  681. // Then contains either:
  682. // NULL - no completion was set
  683. // LPTIMERR3APC - if fTimerIsRing3 is set
  684. // PKDPC - if fTimerIsRing3 is not set.
  685. //
  686. // Note that it is normal for a timer to be inactive and contain
  687. // a pointer to a TIMERR3APC structure. This case occurs when
  688. // a timer set with a ring-3 completion fires normally. The
  689. // TIMERR3APC structure is kept around so that a subsequent
  690. // CancelWaitableTimer() can retrieve the underlying apc handle
  691. // embedded in it.
  692. //
  693. // lPeriod:
  694. // Contains either 0 for a one-shot timer or a positive value
  695. // (the firing period in milliseconds.)
  696. typedef struct _timerdb {
  697. COMMON_OBJECT // standard waitable non-synchronization object
  698. // These fields have to appear in this form because a timer is a sync object.
  699. WNOD *pwnWait; // pointer to the wait node for this object
  700. LONG cntCur; // signaled state
  701. OBJNAME *NameStruct; // name structure for this object
  702. // These fields are timer-specific.
  703. struct _timerdb *lpNextTimerDb; //Link in TimerSysLst (can be NULL)
  704. DWORD hTimeout;
  705. FILETIME DueTime;
  706. DWORD Completion;
  707. LONG lPeriod; //Optional period
  708. // Try not to add new fields. This structure cannot exceed 40 bytes
  709. // or we break compatibility with NT's Ke api. If you try to hang
  710. // another structure off it, remember that the Ke*Timer apis can't
  711. // allocate memory from the heap (system meltdown if these apis
  712. // are called at event time on a system that's paging thru DOS.)
  713. } TIMERDB, *LPTIMERDB;
  714. //
  715. // A dynamic extension to the timerdb that's used whenever a ring-3 timer
  716. // is armed with a completion function. This structure must live in locked
  717. // memory.
  718. //
  719. // Access to this structure is serialized by being in a no-preempt section.
  720. // There are no semaphores guarding it.
  721. //
  722. // This structure is allocated whenever SetWaitableTimer() is called on a
  723. // timer with a non-null completion function. It's stored in the Completion
  724. // field and the fTimerIsRing3 bit is set to indicate that this a TIMERR3APC
  725. // (opposed to a ring-0 DPC.)
  726. //
  727. // This structure is detached from the timerdb on the next call to
  728. // CancelWaitableTimer(). It's also usually freed at this time except
  729. // if a cancel occurs after the last apc has been delivered but TimerApcHandler
  730. // hasn't yet set fHandlerDone to indicate that's it finished using the
  731. // structure. In this case, we can't free it so we instead link it onto
  732. // the TimerDisposalWaitingList. When fHandlerDone does become TRUE,
  733. // it will be available for pickup the next time we need one of these
  734. // structures.
  735. //
  736. // The automatic rearming of a periodic timer reuses the existing
  737. // TIMERR3APC. It checks the fHandleDone: if the handler hasn't
  738. // finished (or begun) on the previous apc, we don't schedule a new
  739. // one (as per specs).
  740. //
  741. // Fields:
  742. // cRef - reference count
  743. // pfnCompletion - Ptr to ring-3 completion (never NULL)
  744. // lpCompletionArg - uninterpreted argument to pfnCompletion
  745. // R0ThreadHandle - thread that called SetWaitableTimer()
  746. // DueTime - trigger time to pass to pfnCompletion. This
  747. // field isn't set until the timer goes off.
  748. // dwApcHandle - if apc has been queued, contains the underlying
  749. // apc handle. NULL otherwise. This apc handle gets
  750. // freed at the same time we free the TIMERR3APC
  751. // (or in the case of a periodic timer, when we
  752. // reuse the structure for the next arming.)
  753. // lpNext - Used for linking in TimerDisposalWaitingList,
  754. // undefined otherwise.
  755. //
  756. //
  757. //
  758. typedef struct _timerr3apc {
  759. DWORD cRef;
  760. PTIMER_APC_ROUTINE pfnCompletion; //completion routine
  761. LPVOID lpCompletionArg; //arg to pass to pfnCompletion
  762. DWORD ApcTdbx; //thread that set the timer
  763. FILETIME DueTime; //the DueTime passed to completion
  764. DWORD dwApcHandle; //underlying apc handle
  765. struct _timerr3apc *lpNext; //next ptr
  766. LPTIMERDB lpTimerDB; // back pointer to my TimerDB
  767. } TIMERR3APC, *LPTIMERR3APC;
  768. // Ring 0 External Object.
  769. //
  770. // Kernel object used to store data about an externally allocated object. VxDs
  771. // can use the VWIN32_AllocExternalHandle service to make a Win32 handle for
  772. // one of their data structures and return the handle back to a Win32 app.
  773. // An application may use this handle to communicate with the VxD, ideally
  774. // through the DeviceIoControl interface. The VxD can get back to the original
  775. // object by using the VWIN32_UseExternalObject service. When the VxD is
  776. // through using the object, it must call VWIN32_UnuseExternalObject.
  777. //
  778. // Because the handle returned by VWIN32_AllocExternalHandle is a standard
  779. // Win32 handle, all of the standard Win32 handle services, such as
  780. // DuplicateHandle, will work with it. In addition, when a process terminates,
  781. // the object cleanup is automatically performed. Thus, a VxD doesn't have to
  782. // watch process notification messages just to check if a per-process data
  783. // structure should be cleaned-up.
  784. //
  785. // When allocating the Win32 handle, the VxD provides a virtual table (vtbl) of
  786. // functions to invoke whenever type specific handle operations are performed.
  787. // For example, when the usage count of an object goes to zero, the vtbl is
  788. // used to notify the VxD that the external object should be released.
  789. struct _R0OBJTYPETABLE; // Forward reference (in vwin32.h)
  790. typedef struct _r0objext {
  791. COMMON_NSOBJECT
  792. DWORD cntExternalUses;
  793. struct _R0OBJTYPETABLE* pR0ObjTypeTable;
  794. LPVOID pR0ObjBody;
  795. ULONG devNode;
  796. } R0OBJEXT, * PR0OBJEXT;
  797. //
  798. // objTypMsgIndicator
  799. //
  800. typedef struct _MsgIndicatorDb {
  801. COMMON_NSOBJECT
  802. ULONG ulMsgCount;
  803. } MSGINDICATORDB, *PMSGINDICATORDB;
  804. /* ------------------------------------------------------------ */
  805. /* Function Prototypes
  806. /* ------------------------------------------------------------ */
  807. GLOBAL VOID KERNENTRY UseObject (VOID *); // incs usage count
  808. GLOBAL OBJ * KERNENTRY NewObject (DWORD, BYTE); // allocates generic obj of size and type
  809. GLOBAL VOID KERNENTRY DisposeObject (OBJ *); // deallocates generic object
  810. GLOBAL BOOL KERNENTRY FUnuseObject (VOID *); // decs usage count
  811. GLOBAL OBJ * KERNENTRY PobjDupObject (OBJ *, PDB *, PDB *); // duplicates pointer to object
  812. GLOBAL VOID KERNENTRY LockObject(OBJ *);
  813. GLOBAL VOID KERNENTRY UnlockObject(OBJ *);
  814. GLOBAL MODREF * KERNENTRY MRAlloc(IMTE imte, PDB *ppdb);
  815. #endif
  816. /* ------------------------------------------------------------ */
  817. /* ------------------------------------------------------------ */
  818. /* ------------------------------------------------------------ */
  819. /* ------------------------------------------------------------ */
  820. /* ------------------------------------------------------------ */
  821. /****************************************************************/