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.

981 lines
32 KiB

  1. /*++
  2. Copyright (c) 1998-2001 Microsoft Corporation
  3. Module Name:
  4. debug.h
  5. Abstract:
  6. This module contains debug-specific declarations.
  7. Author:
  8. Keith Moore (keithmo) 10-Jun-1998
  9. Revision History:
  10. --*/
  11. #ifndef _DEBUG_H_
  12. #define _DEBUG_H_
  13. #ifdef __cplusplus
  14. extern "C" {
  15. #endif
  16. #define UL_DEFAULT_ERROR_ON_EXCEPTION STATUS_INVALID_PARAMETER
  17. // BUGBUG: should not need to declare these functions ourselves.
  18. // Declared in ntddk.h but not in ntosp.h.
  19. NTKERNELAPI
  20. VOID
  21. ExConvertExclusiveToSharedLite(
  22. IN PERESOURCE Resource
  23. );
  24. #undef UL_TRY_RESOURCE_EXCLUSIVE
  25. #ifdef UL_TRY_RESOURCE_EXCLUSIVE
  26. // ExTryToAcquireResourceExclusiveLite is not currently exported
  27. // from ntoskrnl
  28. NTKERNELAPI
  29. BOOLEAN
  30. ExTryToAcquireResourceExclusiveLite(
  31. IN PERESOURCE Resource
  32. );
  33. #endif // UL_TRY_RESOURCE_EXCLUSIVE
  34. #if DBG
  35. //
  36. // Initialization/termination functions.
  37. //
  38. VOID
  39. UlDbgInitializeDebugData(
  40. VOID
  41. );
  42. VOID
  43. UlDbgTerminateDebugData(
  44. VOID
  45. );
  46. //
  47. // Driver entry/exit notifications.
  48. //
  49. VOID
  50. UlDbgEnterDriver(
  51. IN PSTR pFunctionName,
  52. IN PIRP pIrp OPTIONAL,
  53. IN PSTR pFileName,
  54. IN USHORT LineNumber
  55. );
  56. VOID
  57. UlDbgLeaveDriver(
  58. IN PSTR pFunctionName,
  59. IN PSTR pFileName,
  60. IN USHORT LineNumber
  61. );
  62. #define UL_ENTER_DRIVER( function, pirp ) \
  63. UlDbgEnterDriver( \
  64. (function), \
  65. (pirp), \
  66. __FILE__, \
  67. __LINE__ \
  68. )
  69. #define UL_LEAVE_DRIVER( function ) \
  70. UlDbgLeaveDriver( \
  71. (function), \
  72. __FILE__, \
  73. __LINE__ \
  74. )
  75. //
  76. // An instrumented resource.
  77. //
  78. #define MAX_RESOURCE_NAME_LENGTH 64
  79. typedef struct _UL_ERESOURCE
  80. {
  81. //
  82. // The actual resource.
  83. //
  84. // N.B. This must be the first entry in the structure to make the
  85. // debugger extension work properly!
  86. //
  87. ERESOURCE Resource;
  88. //
  89. // Links onto the global resource list.
  90. //
  91. LIST_ENTRY GlobalResourceListEntry;
  92. //
  93. // Pointer to the thread that owns this lock exclusively.
  94. //
  95. PETHREAD pExclusiveOwner;
  96. PETHREAD pPreviousOwner;
  97. //
  98. // Statistics.
  99. //
  100. LONG ExclusiveCount;
  101. LONG SharedCount;
  102. LONG ReleaseCount;
  103. //
  104. // The object that created this lock
  105. //
  106. ULONG OwnerTag;
  107. //
  108. // The name of the resource, for display purposes.
  109. //
  110. UCHAR ResourceName[MAX_RESOURCE_NAME_LENGTH];
  111. } UL_ERESOURCE, *PUL_ERESOURCE;
  112. NTSTATUS
  113. UlDbgInitializeResource(
  114. IN PUL_ERESOURCE pResource,
  115. IN PSTR pResourceName,
  116. IN ULONG_PTR Parameter,
  117. IN ULONG OwnerTag,
  118. IN PSTR pFileName,
  119. IN USHORT LineNumber
  120. );
  121. NTSTATUS
  122. UlDbgDeleteResource(
  123. IN PUL_ERESOURCE pResource,
  124. IN PSTR pFileName,
  125. IN USHORT LineNumber
  126. );
  127. BOOLEAN
  128. UlDbgAcquireResourceExclusive(
  129. IN PUL_ERESOURCE pResource,
  130. IN BOOLEAN Wait,
  131. IN PSTR pFileName,
  132. IN USHORT LineNumber
  133. );
  134. BOOLEAN
  135. UlDbgAcquireResourceShared(
  136. IN PUL_ERESOURCE pResource,
  137. IN BOOLEAN Wait,
  138. IN PSTR pFileName,
  139. IN USHORT LineNumber
  140. );
  141. VOID
  142. UlDbgReleaseResource(
  143. IN PUL_ERESOURCE pResource,
  144. IN PSTR pFileName,
  145. IN USHORT LineNumber
  146. );
  147. VOID
  148. UlDbgConvertExclusiveToShared( \
  149. IN PUL_ERESOURCE pResource,
  150. IN PSTR pFileName,
  151. IN USHORT LineNumber
  152. );
  153. #ifdef UL_TRY_RESOURCE_EXCLUSIVE
  154. BOOLEAN
  155. UlDbgTryToAcquireResourceExclusive( \
  156. IN PUL_ERESOURCE pResource,
  157. IN PSTR pFileName,
  158. IN USHORT LineNumber
  159. );
  160. #endif // UL_TRY_RESOURCE_EXCLUSIVE
  161. BOOLEAN
  162. UlDbgResourceOwnedExclusive(
  163. IN PUL_ERESOURCE pResource
  164. );
  165. BOOLEAN
  166. UlDbgResourceUnownedExclusive(
  167. IN PUL_ERESOURCE pResource
  168. );
  169. #define UlInitializeResource( resource, name, param, tag ) \
  170. UlDbgInitializeResource( \
  171. (resource), \
  172. (name), \
  173. (ULONG_PTR)(param), \
  174. (tag), \
  175. __FILE__, \
  176. __LINE__ \
  177. )
  178. #define UlDeleteResource( resource ) \
  179. UlDbgDeleteResource( \
  180. (resource), \
  181. __FILE__, \
  182. __LINE__ \
  183. )
  184. #define UlAcquireResourceExclusive( resource, wait ) \
  185. UlDbgAcquireResourceExclusive( \
  186. (resource), \
  187. (wait), \
  188. __FILE__, \
  189. __LINE__ \
  190. )
  191. #define UlAcquireResourceShared( resource, wait ) \
  192. UlDbgAcquireResourceShared( \
  193. (resource), \
  194. (wait), \
  195. __FILE__, \
  196. __LINE__ \
  197. )
  198. #define UlReleaseResource( resource ) \
  199. UlDbgReleaseResource( \
  200. (resource), \
  201. __FILE__, \
  202. __LINE__ \
  203. )
  204. #define UlConvertExclusiveToShared( resource ) \
  205. UlDbgConvertExclusiveToShared( \
  206. (resource), \
  207. __FILE__, \
  208. __LINE__ \
  209. )
  210. #ifdef UL_TRY_RESOURCE_EXCLUSIVE
  211. #define UlTryToAcquireResourceExclusive( resource ) \
  212. UlDbgTryToAcquireResourceExclusive( \
  213. (resource), \
  214. __FILE__, \
  215. __LINE__ \
  216. )
  217. #endif // UL_TRY_RESOURCE_EXCLUSIVE
  218. #define IS_RESOURCE_INITIALIZED( resource ) \
  219. ((resource)->Resource.SystemResourcesList.Flink != NULL)
  220. //
  221. // An instrumented spinlock.
  222. //
  223. typedef struct _UL_SPIN_LOCK // SpinLock
  224. {
  225. //
  226. // The actual lock.
  227. //
  228. // N.B. This must be the first entry in the structure to make the
  229. // debugger extension work properly!
  230. //
  231. KSPIN_LOCK KSpinLock;
  232. //
  233. // The name of the spinlock, for display purposes.
  234. //
  235. PSTR pSpinLockName;
  236. //
  237. // Pointer to the thread that owns this lock.
  238. //
  239. PETHREAD pOwnerThread;
  240. //
  241. // Statistics.
  242. //
  243. PSTR pLastAcquireFileName;
  244. PSTR pLastReleaseFileName;
  245. USHORT LastAcquireLineNumber;
  246. USHORT LastReleaseLineNumber;
  247. ULONG OwnerProcessor;
  248. LONG Acquisitions;
  249. LONG Releases;
  250. LONG AcquisitionsAtDpcLevel;
  251. LONG ReleasesFromDpcLevel;
  252. LONG Spare;
  253. } UL_SPIN_LOCK, *PUL_SPIN_LOCK;
  254. #define KSPIN_LOCK_FROM_UL_SPIN_LOCK( pLock ) \
  255. &((pLock)->KSpinLock)
  256. VOID
  257. UlDbgInitializeSpinLock(
  258. IN PUL_SPIN_LOCK pSpinLock,
  259. IN PSTR pSpinLockName,
  260. IN PSTR pFileName,
  261. IN USHORT LineNumber
  262. );
  263. VOID
  264. UlDbgAcquireSpinLock(
  265. IN PUL_SPIN_LOCK pSpinLock,
  266. OUT PKIRQL pOldIrql,
  267. IN PSTR pFileName,
  268. IN USHORT LineNumber
  269. );
  270. VOID
  271. UlDbgReleaseSpinLock(
  272. IN PUL_SPIN_LOCK pSpinLock,
  273. IN KIRQL OldIrql,
  274. IN PSTR pFileName,
  275. IN USHORT LineNumber
  276. );
  277. VOID
  278. UlDbgAcquireSpinLockAtDpcLevel(
  279. IN PUL_SPIN_LOCK pSpinLock,
  280. IN PSTR pFileName,
  281. IN USHORT LineNumber
  282. );
  283. VOID
  284. UlDbgReleaseSpinLockFromDpcLevel(
  285. IN PUL_SPIN_LOCK pSpinLock,
  286. IN PSTR pFileName,
  287. IN USHORT LineNumber
  288. );
  289. VOID
  290. UlDbgAcquireInStackQueuedSpinLock(
  291. IN PUL_SPIN_LOCK pSpinLock,
  292. OUT PKLOCK_QUEUE_HANDLE pLockHandle,
  293. IN PSTR pFileName,
  294. IN USHORT LineNumber
  295. );
  296. VOID
  297. UlDbgReleaseInStackQueuedSpinLock(
  298. IN PUL_SPIN_LOCK pSpinLock,
  299. IN PKLOCK_QUEUE_HANDLE pLockHandle,
  300. IN PSTR pFileName,
  301. IN USHORT LineNumber
  302. );
  303. VOID
  304. UlDbgAcquireInStackQueuedSpinLockAtDpcLevel(
  305. IN PUL_SPIN_LOCK pSpinLock,
  306. OUT PKLOCK_QUEUE_HANDLE pLockHandle,
  307. IN PSTR pFileName,
  308. IN USHORT LineNumber
  309. );
  310. VOID
  311. UlDbgReleaseInStackQueuedSpinLockFromDpcLevel(
  312. IN PUL_SPIN_LOCK pSpinLock,
  313. IN PKLOCK_QUEUE_HANDLE pLockHandle,
  314. IN PSTR pFileName,
  315. IN USHORT LineNumber
  316. );
  317. BOOLEAN
  318. UlDbgSpinLockOwned(
  319. IN PUL_SPIN_LOCK pSpinLock
  320. );
  321. BOOLEAN
  322. UlDbgSpinLockUnowned(
  323. IN PUL_SPIN_LOCK pSpinLock
  324. );
  325. #define UlInitializeSpinLock( spinlock, name ) \
  326. UlDbgInitializeSpinLock( \
  327. (spinlock), \
  328. (name), \
  329. __FILE__, \
  330. __LINE__ \
  331. )
  332. #define UlAcquireSpinLock( spinlock, oldirql ) \
  333. UlDbgAcquireSpinLock( \
  334. (spinlock), \
  335. (oldirql), \
  336. __FILE__, \
  337. __LINE__ \
  338. )
  339. #define UlReleaseSpinLock( spinlock, oldirql ) \
  340. UlDbgReleaseSpinLock( \
  341. (spinlock), \
  342. (oldirql), \
  343. __FILE__, \
  344. __LINE__ \
  345. )
  346. #define UlAcquireSpinLockAtDpcLevel( spinlock ) \
  347. UlDbgAcquireSpinLockAtDpcLevel( \
  348. (spinlock), \
  349. __FILE__, \
  350. __LINE__ \
  351. )
  352. #define UlReleaseSpinLockFromDpcLevel( spinlock ) \
  353. UlDbgReleaseSpinLockFromDpcLevel( \
  354. (spinlock), \
  355. __FILE__, \
  356. __LINE__ \
  357. )
  358. #define UlAcquireInStackQueuedSpinLock( spinlock, lockhandle ) \
  359. UlDbgAcquireInStackQueuedSpinLock( \
  360. (spinlock), \
  361. (lockhandle), \
  362. __FILE__, \
  363. __LINE__ \
  364. )
  365. #define UlReleaseInStackQueuedSpinLock( spinlock, lockhandle ) \
  366. UlDbgReleaseInStackQueuedSpinLock( \
  367. (spinlock), \
  368. (lockhandle), \
  369. __FILE__, \
  370. __LINE__ \
  371. )
  372. #define UlAcquireInStackQueuedSpinLockAtDpcLevel( spinlock, lockhandle ) \
  373. UlDbgAcquireInStackQueuedSpinLockAtDpcLevel( \
  374. (spinlock), \
  375. (lockhandle), \
  376. __FILE__, \
  377. __LINE__ \
  378. )
  379. #define UlReleaseInStackQueuedSpinLockFromDpcLevel( spinlock, lockhandle ) \
  380. UlDbgReleaseInStackQueuedSpinLockFromDpcLevel( \
  381. (spinlock), \
  382. (lockhandle), \
  383. __FILE__, \
  384. __LINE__ \
  385. )
  386. //
  387. // Debug spew control.
  388. // If you change or add a flag, please update the FlagTable
  389. // in ul\util\tul.c.
  390. //
  391. #undef IF_DEBUG
  392. #define IF_DEBUG(a) \
  393. if ( ((UL_DEBUG_ ## a) & g_UlDebug) != 0 )
  394. #define IF_DEBUG2(a, b) \
  395. if ( (((UL_DEBUG_ ## a) | (UL_DEBUG_ ## b)) & g_UlDebug) \
  396. == ((UL_DEBUG_ ## a) | (UL_DEBUG_ ## b)) )
  397. #define UL_DEBUG_OPEN_CLOSE 0x00000001
  398. #define UL_DEBUG_SEND_RESPONSE 0x00000002
  399. #define UL_DEBUG_SEND_BUFFER 0x00000004
  400. #define UL_DEBUG_TDI 0x00000008
  401. #define UL_DEBUG_FILE_CACHE 0x00000010
  402. #define UL_DEBUG_CONFIG_GROUP_FNC 0x00000020
  403. #define UL_DEBUG_CONFIG_GROUP_TREE 0x00000040
  404. #define UL_DEBUG_REFCOUNT 0x00000080
  405. #define UL_DEBUG_HTTP_IO 0x00000100
  406. #define UL_DEBUG_ROUTING 0x00000200
  407. #define UL_DEBUG_URI_CACHE 0x00000400
  408. #define UL_DEBUG_PARSER 0x00000800
  409. #define UL_DEBUG_SITE 0x00001000
  410. #define UL_DEBUG_WORK_ITEM 0x00002000
  411. #define UL_DEBUG_FILTER 0x00004000
  412. #define UL_DEBUG_LOGGING 0x00008000
  413. #define UL_DEBUG_TC 0x00010000
  414. #define UL_DEBUG_OPAQUE_ID 0x00020000
  415. #define UL_DEBUG_PERF_COUNTERS 0x00040000
  416. #define UL_DEBUG_LKRHASH 0x00080000
  417. #define UL_DEBUG_TIMEOUTS 0x00100000
  418. #define UL_DEBUG_LIMITS 0x00200000
  419. #define UL_DEBUG_LARGE_MEM 0x00400000
  420. #define UL_DEBUG_IOCTL 0x00800000
  421. #define UL_DEBUG_VERBOSE 0x40000000
  422. #define DEBUG
  423. //
  424. // Tracing.
  425. //
  426. extern ULONG g_UlDebug;
  427. #define UlTrace(a, _b_) \
  428. do \
  429. { \
  430. IF_DEBUG(##a) \
  431. { \
  432. DbgPrint _b_ ; \
  433. } \
  434. } while (FALSE)
  435. #define UlTrace2(a1, a2, _b_) \
  436. do \
  437. { \
  438. IF_DEBUG2(##a1, ##a2) \
  439. { \
  440. DbgPrint _b_ ; \
  441. } \
  442. } while (FALSE)
  443. #define UlTraceVerbose(a, _b_) UlTrace2(a, VERBOSE, _b_)
  444. ULONG
  445. UlDbgPrettyPrintBuffer(
  446. const UCHAR* pBuffer,
  447. ULONG BufferSize
  448. );
  449. //
  450. // Debug pool allocator.
  451. //
  452. PVOID
  453. UlDbgAllocatePool (
  454. IN POOL_TYPE PoolType,
  455. IN SIZE_T NumberOfBytes,
  456. IN ULONG Tag,
  457. IN PSTR pFileName,
  458. IN USHORT LineNumber
  459. );
  460. VOID
  461. UlDbgFreePool (
  462. IN PVOID pPointer,
  463. IN ULONG Tag
  464. );
  465. #define UL_ALLOCATE_POOL( type, len, tag ) \
  466. UlDbgAllocatePool( \
  467. (type), \
  468. (len), \
  469. (tag), \
  470. __FILE__, \
  471. __LINE__ \
  472. )
  473. #define UL_FREE_POOL( ptr, tag ) \
  474. UlDbgFreePool( \
  475. (ptr), \
  476. (tag) \
  477. )
  478. //
  479. // Exception filter.
  480. //
  481. LONG
  482. UlDbgExceptionFilter(
  483. IN PEXCEPTION_POINTERS pExceptionPointers,
  484. IN PSTR pFileName,
  485. IN USHORT LineNumber
  486. );
  487. #define UL_EXCEPTION_FILTER() \
  488. UlDbgExceptionFilter( \
  489. GetExceptionInformation(), \
  490. (PSTR)__FILE__, \
  491. (USHORT)__LINE__ \
  492. )
  493. //
  494. // Exception warning converter.
  495. //
  496. NTSTATUS
  497. UlDbgConvertExceptionCode(
  498. IN NTSTATUS status,
  499. IN PSTR pFileName,
  500. IN USHORT LineNumber
  501. );
  502. #define UL_CONVERT_EXCEPTION_CODE(status) \
  503. (NT_WARNING(status) ? \
  504. UlDbgConvertExceptionCode( \
  505. (status), \
  506. (PSTR)__FILE__, \
  507. (USHORT)__LINE__ ) \
  508. : \
  509. (status))
  510. //
  511. // Invalid completion routine for catching incomplete IRP contexts.
  512. //
  513. VOID
  514. UlDbgInvalidCompletionRoutine(
  515. IN PVOID pCompletionContext,
  516. IN NTSTATUS Status,
  517. IN ULONG_PTR Information
  518. );
  519. //
  520. // Error handlers.
  521. //
  522. NTSTATUS
  523. UlDbgStatus(
  524. IN NTSTATUS Status,
  525. IN PSTR pFileName,
  526. IN USHORT LineNumber
  527. );
  528. #define RETURN(status) \
  529. return UlDbgStatus( \
  530. (status), \
  531. __FILE__, \
  532. __LINE__ \
  533. )
  534. #define CHECK_STATUS(status) \
  535. UlDbgStatus( \
  536. (status), \
  537. (PSTR)__FILE__, \
  538. (USHORT)__LINE__ \
  539. )
  540. //
  541. // Random structure dumpers.
  542. //
  543. VOID
  544. UlDbgDumpRequestBuffer(
  545. IN struct _UL_REQUEST_BUFFER *pBuffer,
  546. IN PSTR pName
  547. );
  548. VOID
  549. UlDbgDumpHttpConnection(
  550. IN struct _UL_HTTP_CONNECTION *pConnection,
  551. IN PSTR pName
  552. );
  553. //
  554. // IO wrappers.
  555. //
  556. PIRP
  557. UlDbgAllocateIrp(
  558. IN CCHAR StackSize,
  559. IN BOOLEAN ChargeQuota,
  560. IN PSTR pFileName,
  561. IN USHORT LineNumber
  562. );
  563. VOID
  564. UlDbgFreeIrp(
  565. IN PIRP pIrp,
  566. IN PSTR pFileName,
  567. IN USHORT LineNumber
  568. );
  569. NTSTATUS
  570. UlDbgCallDriver(
  571. IN PDEVICE_OBJECT pDeviceObject,
  572. IN OUT PIRP pIrp,
  573. IN PSTR pFileName,
  574. IN USHORT LineNumber
  575. );
  576. VOID
  577. UlDbgCompleteRequest(
  578. IN PIRP pIrp,
  579. IN CCHAR PriorityBoost,
  580. IN PSTR pFileName,
  581. IN USHORT LineNumber
  582. );
  583. #define UlAllocateIrp( stack, quota ) \
  584. UlDbgAllocateIrp( \
  585. (stack), \
  586. (quota), \
  587. (PSTR)__FILE__, \
  588. (USHORT)__LINE__ \
  589. )
  590. #define UlFreeIrp( pirp ) \
  591. UlDbgFreeIrp( \
  592. (pirp), \
  593. (PSTR)__FILE__, \
  594. (USHORT)__LINE__ \
  595. )
  596. #define UlCallDriver( pdevice, pirp ) \
  597. UlDbgCallDriver( \
  598. (pdevice), \
  599. (pirp), \
  600. (PSTR)__FILE__, \
  601. (USHORT)__LINE__ \
  602. )
  603. #define UlCompleteRequest( pirp, boost ) \
  604. UlDbgCompleteRequest( \
  605. (pirp), \
  606. (boost), \
  607. (PSTR)__FILE__, \
  608. (USHORT)__LINE__ \
  609. )
  610. PMDL
  611. UlDbgAllocateMdl(
  612. IN PVOID VirtualAddress,
  613. IN ULONG Length,
  614. IN BOOLEAN SecondaryBuffer,
  615. IN BOOLEAN ChargeQuota,
  616. IN OUT PIRP Irp,
  617. IN PSTR pFileName,
  618. IN USHORT LineNumber
  619. );
  620. VOID
  621. UlDbgFreeMdl(
  622. IN PMDL Mdl,
  623. IN PSTR pFileName,
  624. IN USHORT LineNumber
  625. );
  626. #define UlAllocateMdl( add, len, second, quota, irp ) \
  627. UlDbgAllocateMdl( \
  628. (add), \
  629. (len), \
  630. (second), \
  631. (quota), \
  632. (irp), \
  633. (PSTR)__FILE__, \
  634. (USHORT)__LINE__ \
  635. )
  636. #define UlFreeMdl( mdl ) \
  637. UlDbgFreeMdl( \
  638. (mdl), \
  639. (PSTR)__FILE__, \
  640. (USHORT)__LINE__ \
  641. )
  642. // #define SPECIAL_MDL_FLAG 0x8000
  643. //
  644. // List Manipulation
  645. //
  646. #define UlRemoveEntryList(pEntry) { \
  647. ASSERT(NULL != (pEntry)); \
  648. ASSERT(NULL != (pEntry)->Flink); \
  649. ASSERT(NULL != (pEntry)->Blink); \
  650. RemoveEntryList(pEntry); \
  651. (pEntry)->Flink = (pEntry)->Blink = NULL; \
  652. }
  653. #else // !DBG -----------------------------------------------------------
  654. //
  655. // Disable all of the above.
  656. //
  657. #define UL_ENTER_DRIVER( function, pirp )
  658. #define UL_LEAVE_DRIVER( function )
  659. #define UL_ERESOURCE ERESOURCE
  660. #define PUL_ERESOURCE PERESOURCE
  661. #define UlInitializeResource( resource, name, param, tag ) \
  662. ExInitializeResourceLite( (resource) )
  663. #define UlDeleteResource( resource ) \
  664. ExDeleteResourceLite( (resource) )
  665. #define UlAcquireResourceExclusive( resource, wait ) \
  666. do \
  667. { \
  668. KeEnterCriticalRegion(); \
  669. ExAcquireResourceExclusiveLite( (resource), (wait) ); \
  670. } while (FALSE)
  671. #define UlAcquireResourceShared( resource, wait ) \
  672. do \
  673. { \
  674. KeEnterCriticalRegion(); \
  675. ExAcquireResourceSharedLite( (resource), (wait) ); \
  676. } while (FALSE)
  677. #define UlReleaseResource( resource ) \
  678. do \
  679. { \
  680. ExReleaseResourceLite( (resource) ); \
  681. KeLeaveCriticalRegion(); \
  682. } while (FALSE)
  683. #define UlConvertExclusiveToShared( resource ) \
  684. ExConvertExclusiveToSharedLite( (resource) )
  685. #ifdef UL_TRY_RESOURCE_EXCLUSIVE
  686. __inline
  687. NTKERNELAPI
  688. BOOLEAN
  689. UlTryToAcquireResourceExclusive(
  690. IN PERESOURCE Resource
  691. )
  692. {
  693. BOOLEAN fLocked;
  694. KeEnterCriticalRegion();
  695. fLocked = ExTryToAcquireResourceExclusiveLite( Resource );
  696. if (! fLocked )
  697. KeLeaveCriticalRegion();
  698. return fLocked;
  699. }
  700. #endif // UL_TRY_RESOURCE_EXCLUSIVE
  701. #define IS_RESOURCE_INITIALIZED( resource ) \
  702. ((resource)->SystemResourcesList.Flink != NULL)
  703. #define UL_SPIN_LOCK KSPIN_LOCK
  704. #define PUL_SPIN_LOCK PKSPIN_LOCK
  705. #define KSPIN_LOCK_FROM_UL_SPIN_LOCK( pLock ) (pLock)
  706. #define UlInitializeSpinLock( spinlock, name ) \
  707. KeInitializeSpinLock( (spinlock) )
  708. #define UlAcquireSpinLock( spinlock, oldirql ) \
  709. KeAcquireSpinLock( (spinlock), (oldirql) )
  710. #define UlReleaseSpinLock( spinlock, oldirql ) \
  711. KeReleaseSpinLock( (spinlock), (oldirql) )
  712. #define UlAcquireSpinLockAtDpcLevel( spinlock ) \
  713. KeAcquireSpinLockAtDpcLevel( (spinlock) )
  714. #define UlReleaseSpinLockFromDpcLevel( spinlock ) \
  715. KeReleaseSpinLockFromDpcLevel( (spinlock) )
  716. #define UlAcquireInStackQueuedSpinLock( spinlock, lockhandle ) \
  717. KeAcquireInStackQueuedSpinLock( (spinlock), (lockhandle) )
  718. #define UlReleaseInStackQueuedSpinLock( spinlock, lockhandle ) \
  719. KeReleaseInStackQueuedSpinLock( (lockhandle) )
  720. #define KeAcquireInStackQueueddSpinLockAtDpcLevel( spinlock, lockhandle ) \
  721. KeAcquireInStackQueuedSpinLockAtDpcLevel( (spinlock), (lockhandle) )
  722. #define UlReleaseInStackQueuedSpinLockFromDpcLevel( spinlock, lockhandle ) \
  723. KeReleaseInStackQueuedSpinLockFromDpcLevel( (lockhandle) )
  724. #undef IF_DEBUG
  725. #define IF_DEBUG(a) if (FALSE)
  726. #define IF_DEBUG2(a, b) if (FALSE)
  727. #define DEBUG if ( FALSE )
  728. #define UlTrace(a, _b_) ((void) 0)
  729. #define UlTrace2(a1, a2, _b_) ((void) 0)
  730. #define UlTraceVerbose(a, _b_) ((void) 0)
  731. #define UlDbgPrettyPrintBuffer(pBuffer, BufferSize) ((void) 0)
  732. #define UL_ALLOCATE_POOL( type, len, tag ) \
  733. ExAllocatePoolWithTag( \
  734. (type), \
  735. (len), \
  736. (tag) \
  737. )
  738. #define UL_FREE_POOL( ptr, tag ) \
  739. MyFreePoolWithTag( \
  740. (ptr), \
  741. (tag) \
  742. )
  743. #define UL_EXCEPTION_FILTER() EXCEPTION_EXECUTE_HANDLER
  744. #define UL_CONVERT_EXCEPTION_CODE(status) \
  745. (NT_WARNING(status) ? UL_DEFAULT_ERROR_ON_EXCEPTION : (status))
  746. #define RETURN(status) return (status)
  747. #define CHECK_STATUS(Status)
  748. #define UlAllocateIrp( stack, quota ) \
  749. IoAllocateIrp( (stack), (quota) )
  750. #define UlFreeIrp( pirp ) \
  751. IoFreeIrp( (pirp) )
  752. #define UlCallDriver( pdevice, pirp ) \
  753. IoCallDriver( (pdevice), (pirp) )
  754. #define UlCompleteRequest( pirp, boost ) \
  755. IoCompleteRequest( (pirp), (boost) )
  756. #define UlAllocateMdl( add, len, second, quota, irp ) \
  757. IoAllocateMdl( \
  758. (add), \
  759. (len), \
  760. (second), \
  761. (quota), \
  762. (irp) \
  763. )
  764. #define UlFreeMdl( mdl ) \
  765. IoFreeMdl( \
  766. (mdl) \
  767. )
  768. #define UlRemoveEntryList(pEntry) \
  769. RemoveEntryList(pEntry)
  770. #endif // DBG
  771. // BUGBUG: ALIGN_UP(PVOID) won't work. It needs to be the type of
  772. // the first entry of the following data (paulmcd 4/29/99)
  773. #define UL_ALLOCATE_STRUCT_WITH_SPACE(pt,ot,cb,t) \
  774. (ot *)(UL_ALLOCATE_POOL(pt,ALIGN_UP(sizeof(ot),PVOID)+(cb),t))
  775. #define UL_ALLOCATE_STRUCT(pt,ot,t) \
  776. (ot *)(UL_ALLOCATE_POOL(pt,sizeof(ot),t))
  777. #define UL_ALLOCATE_ARRAY(pt,et,c,t) \
  778. (et *)(UL_ALLOCATE_POOL(pt,sizeof(et)*(c),t))
  779. #define UL_FREE_POOL_WITH_SIG(a,t) \
  780. do { \
  781. (a)->Signature = MAKE_FREE_TAG(t); \
  782. UL_FREE_POOL(a,t); \
  783. (a) = NULL; \
  784. } while (0)
  785. #ifdef __cplusplus
  786. }; // extern "C"
  787. #endif
  788. #endif // _DEBUG_H_