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.

1210 lines
41 KiB

  1. /*++
  2. Copyright (c) 1998-2002 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. #define UL_DEFAULT_ERROR_ON_EXCEPTION STATUS_INVALID_PARAMETER
  14. #if DBG
  15. //
  16. // Initialization/termination functions.
  17. //
  18. VOID
  19. UlDbgInitializeDebugData(
  20. VOID
  21. );
  22. VOID
  23. UlDbgTerminateDebugData(
  24. VOID
  25. );
  26. //
  27. // Driver entry/exit notifications.
  28. //
  29. VOID
  30. UlDbgEnterDriver(
  31. IN PCSTR pFunctionName,
  32. IN PIRP pIrp OPTIONAL,
  33. IN PCSTR pFileName,
  34. IN USHORT LineNumber
  35. );
  36. VOID
  37. UlDbgLeaveDriver(
  38. IN PCSTR pFunctionName,
  39. IN PCSTR pFileName,
  40. IN USHORT LineNumber
  41. );
  42. #define UL_ENTER_DRIVER( function, pirp ) \
  43. UlDbgEnterDriver( \
  44. (function), \
  45. (pirp), \
  46. __FILE__, \
  47. __LINE__ \
  48. )
  49. #define UL_LEAVE_DRIVER( function ) \
  50. UlDbgLeaveDriver( \
  51. (function), \
  52. __FILE__, \
  53. __LINE__ \
  54. )
  55. //
  56. // An instrumented resource.
  57. //
  58. #define MAX_RESOURCE_NAME_LENGTH 64
  59. typedef struct _UL_ERESOURCE
  60. {
  61. //
  62. // The actual resource.
  63. //
  64. // N.B. This must be the first entry in the structure to make the
  65. // debugger extension work properly!
  66. //
  67. ERESOURCE Resource;
  68. //
  69. // Links onto the global resource list.
  70. //
  71. LIST_ENTRY GlobalResourceListEntry;
  72. //
  73. // Pointer to the thread that owns this lock exclusively.
  74. //
  75. PETHREAD pExclusiveOwner;
  76. PETHREAD pPreviousOwner;
  77. //
  78. // The number of times this lock has been acquired recursively (in
  79. // exclusive acquisition case.)
  80. //
  81. LONG ExclusiveRecursionCount;
  82. //
  83. // Statistics.
  84. //
  85. LONG ExclusiveCount;
  86. LONG SharedCount;
  87. LONG ReleaseCount;
  88. //
  89. // The object that created this lock
  90. //
  91. ULONG OwnerTag;
  92. //
  93. // The name of the resource, for display purposes.
  94. //
  95. UCHAR ResourceName[MAX_RESOURCE_NAME_LENGTH];
  96. } UL_ERESOURCE, *PUL_ERESOURCE;
  97. NTSTATUS
  98. UlDbgInitializeResource(
  99. IN PUL_ERESOURCE pResource,
  100. IN PCSTR pResourceName,
  101. IN ULONG_PTR Parameter,
  102. IN ULONG OwnerTag,
  103. IN PCSTR pFileName,
  104. IN USHORT LineNumber
  105. );
  106. NTSTATUS
  107. UlDbgDeleteResource(
  108. IN PUL_ERESOURCE pResource,
  109. IN PCSTR pFileName,
  110. IN USHORT LineNumber
  111. );
  112. BOOLEAN
  113. UlDbgAcquireResourceExclusive(
  114. IN PUL_ERESOURCE pResource,
  115. IN BOOLEAN Wait,
  116. IN PCSTR pFileName,
  117. IN USHORT LineNumber
  118. );
  119. BOOLEAN
  120. UlDbgAcquireResourceShared(
  121. IN PUL_ERESOURCE pResource,
  122. IN BOOLEAN Wait,
  123. IN PCSTR pFileName,
  124. IN USHORT LineNumber
  125. );
  126. VOID
  127. UlDbgReleaseResource(
  128. IN PUL_ERESOURCE pResource,
  129. IN PCSTR pFileName,
  130. IN USHORT LineNumber
  131. );
  132. VOID
  133. UlDbgConvertExclusiveToShared(
  134. IN PUL_ERESOURCE pResource,
  135. IN PCSTR pFileName,
  136. IN USHORT LineNumber
  137. );
  138. BOOLEAN
  139. UlDbgTryToAcquireResourceExclusive(
  140. IN PUL_ERESOURCE pResource,
  141. IN PCSTR pFileName,
  142. IN USHORT LineNumber
  143. );
  144. BOOLEAN
  145. UlDbgResourceOwnedExclusive(
  146. IN PUL_ERESOURCE pResource
  147. );
  148. BOOLEAN
  149. UlDbgResourceUnownedExclusive(
  150. IN PUL_ERESOURCE pResource
  151. );
  152. PDRIVER_CANCEL
  153. UlDbgIoSetCancelRoutine(
  154. PIRP pIrp,
  155. PDRIVER_CANCEL pCancelRoutine
  156. );
  157. #define UlInitializeResource( resource, name, param, tag ) \
  158. UlDbgInitializeResource( \
  159. (resource), \
  160. (name), \
  161. (ULONG_PTR)(param), \
  162. (tag), \
  163. __FILE__, \
  164. __LINE__ \
  165. )
  166. #define UlDeleteResource( resource ) \
  167. UlDbgDeleteResource( \
  168. (resource), \
  169. __FILE__, \
  170. __LINE__ \
  171. )
  172. #define UlAcquireResourceExclusive( resource, wait ) \
  173. UlDbgAcquireResourceExclusive( \
  174. (resource), \
  175. (wait), \
  176. __FILE__, \
  177. __LINE__ \
  178. )
  179. #define UlAcquireResourceShared( resource, wait ) \
  180. UlDbgAcquireResourceShared( \
  181. (resource), \
  182. (wait), \
  183. __FILE__, \
  184. __LINE__ \
  185. )
  186. #define UlReleaseResource( resource ) \
  187. UlDbgReleaseResource( \
  188. (resource), \
  189. __FILE__, \
  190. __LINE__ \
  191. )
  192. #define UlConvertExclusiveToShared( resource ) \
  193. UlDbgConvertExclusiveToShared( \
  194. (resource), \
  195. __FILE__, \
  196. __LINE__ \
  197. )
  198. #define UlTryToAcquireResourceExclusive( resource ) \
  199. UlDbgTryToAcquireResourceExclusive( \
  200. (resource), \
  201. __FILE__, \
  202. __LINE__ \
  203. )
  204. #define IS_RESOURCE_INITIALIZED( resource ) \
  205. ((resource)->Resource.SystemResourcesList.Flink != NULL)
  206. //
  207. // An instrumented push lock.
  208. //
  209. #define MAX_PUSHLOCK_NAME_LENGTH 64
  210. typedef struct _UL_PUSH_LOCK
  211. {
  212. //
  213. // The actual push lock.
  214. //
  215. // N.B. This must be the first entry in the structure to make the
  216. // debugger extension work properly!
  217. //
  218. EX_PUSH_LOCK PushLock;
  219. //
  220. // Links onto the global push lock list.
  221. //
  222. LIST_ENTRY GlobalPushLockListEntry;
  223. //
  224. // Pointer to the thread that owns this lock exclusively.
  225. //
  226. PETHREAD pExclusiveOwner;
  227. PETHREAD pPreviousOwner;
  228. //
  229. // Statistics.
  230. //
  231. LONG ExclusiveCount;
  232. LONG SharedCount;
  233. LONG ReleaseCount;
  234. //
  235. // The object that created this lock
  236. //
  237. ULONG OwnerTag;
  238. //
  239. // The name of the push lock, for display purposes.
  240. //
  241. UCHAR PushLockName[MAX_PUSHLOCK_NAME_LENGTH];
  242. } UL_PUSH_LOCK, *PUL_PUSH_LOCK;
  243. VOID
  244. UlDbgInitializePushLock(
  245. IN PUL_PUSH_LOCK pPushLock,
  246. IN PCSTR pPushLockName,
  247. IN ULONG_PTR Parameter,
  248. IN ULONG OwnerTag,
  249. IN PCSTR pFileName,
  250. IN USHORT LineNumber
  251. );
  252. VOID
  253. UlDbgDeletePushLock(
  254. IN PUL_PUSH_LOCK pPushLock,
  255. IN PCSTR pFileName,
  256. IN USHORT LineNumber
  257. );
  258. VOID
  259. UlDbgAcquirePushLockExclusive(
  260. IN PUL_PUSH_LOCK pPushLock,
  261. IN PCSTR pFileName,
  262. IN USHORT LineNumber
  263. );
  264. VOID
  265. UlDbgReleasePushLockExclusive(
  266. IN PUL_PUSH_LOCK pPushLock,
  267. IN PCSTR pFileName,
  268. IN USHORT LineNumber
  269. );
  270. VOID
  271. UlDbgAcquirePushLockShared(
  272. IN PUL_PUSH_LOCK pPushLock,
  273. IN PCSTR pFileName,
  274. IN USHORT LineNumber
  275. );
  276. VOID
  277. UlDbgReleasePushLockShared(
  278. IN PUL_PUSH_LOCK pPushLock,
  279. IN PCSTR pFileName,
  280. IN USHORT LineNumber
  281. );
  282. VOID
  283. UlDbgReleasePushLock(
  284. IN PUL_PUSH_LOCK pPushLock,
  285. IN PCSTR pFileName,
  286. IN USHORT LineNumber
  287. );
  288. BOOLEAN
  289. UlDbgPushLockOwnedExclusive(
  290. IN PUL_PUSH_LOCK pPushLock
  291. );
  292. BOOLEAN
  293. UlDbgPushLockUnownedExclusive(
  294. IN PUL_PUSH_LOCK pPushLock
  295. );
  296. #define UlInitializePushLock( pushlock, name, param, tag ) \
  297. UlDbgInitializePushLock( \
  298. (pushlock), \
  299. (name), \
  300. (ULONG_PTR)(param), \
  301. (tag), \
  302. __FILE__, \
  303. __LINE__ \
  304. )
  305. #define UlDeletePushLock( pushlock ) \
  306. UlDbgDeletePushLock( \
  307. (pushlock), \
  308. __FILE__, \
  309. __LINE__ \
  310. )
  311. #define UlAcquirePushLockExclusive( pushlock ) \
  312. UlDbgAcquirePushLockExclusive( \
  313. (pushlock), \
  314. __FILE__, \
  315. __LINE__ \
  316. )
  317. #define UlReleasePushLockExclusive( pushlock ) \
  318. UlDbgReleasePushLockExclusive( \
  319. (pushlock), \
  320. __FILE__, \
  321. __LINE__ \
  322. )
  323. #define UlAcquirePushLockShared( pushlock ) \
  324. UlDbgAcquirePushLockShared( \
  325. (pushlock), \
  326. __FILE__, \
  327. __LINE__ \
  328. )
  329. #define UlReleasePushLockShared( pushlock ) \
  330. UlDbgReleasePushLockShared( \
  331. (pushlock), \
  332. __FILE__, \
  333. __LINE__ \
  334. )
  335. #define UlReleasePushLock( pushlock ) \
  336. UlDbgReleasePushLock( \
  337. (pushlock), \
  338. __FILE__, \
  339. __LINE__ \
  340. )
  341. //
  342. // An instrumented spinlock.
  343. //
  344. typedef struct _UL_SPIN_LOCK // SpinLock
  345. {
  346. //
  347. // The actual lock.
  348. //
  349. // N.B. This must be the first entry in the structure to make the
  350. // debugger extension work properly!
  351. //
  352. KSPIN_LOCK KSpinLock;
  353. //
  354. // The name of the spinlock, for display purposes.
  355. //
  356. PCSTR pSpinLockName;
  357. //
  358. // Pointer to the thread that owns this lock.
  359. //
  360. PETHREAD pOwnerThread;
  361. //
  362. // Statistics.
  363. //
  364. PCSTR pLastAcquireFileName;
  365. PCSTR pLastReleaseFileName;
  366. USHORT LastAcquireLineNumber;
  367. USHORT LastReleaseLineNumber;
  368. ULONG OwnerProcessor;
  369. LONG Acquisitions;
  370. LONG Releases;
  371. LONG AcquisitionsAtDpcLevel;
  372. LONG ReleasesFromDpcLevel;
  373. LONG Spare;
  374. } UL_SPIN_LOCK, *PUL_SPIN_LOCK;
  375. #define KSPIN_LOCK_FROM_UL_SPIN_LOCK( pLock ) \
  376. &((pLock)->KSpinLock)
  377. VOID
  378. UlDbgInitializeSpinLock(
  379. IN PUL_SPIN_LOCK pSpinLock,
  380. IN PCSTR pSpinLockName,
  381. IN PCSTR pFileName,
  382. IN USHORT LineNumber
  383. );
  384. VOID
  385. UlDbgAcquireSpinLock(
  386. IN PUL_SPIN_LOCK pSpinLock,
  387. OUT PKIRQL pOldIrql,
  388. IN PCSTR pFileName,
  389. IN USHORT LineNumber
  390. );
  391. VOID
  392. UlDbgReleaseSpinLock(
  393. IN PUL_SPIN_LOCK pSpinLock,
  394. IN KIRQL OldIrql,
  395. IN PCSTR pFileName,
  396. IN USHORT LineNumber
  397. );
  398. VOID
  399. UlDbgAcquireSpinLockAtDpcLevel(
  400. IN PUL_SPIN_LOCK pSpinLock,
  401. IN PCSTR pFileName,
  402. IN USHORT LineNumber
  403. );
  404. VOID
  405. UlDbgReleaseSpinLockFromDpcLevel(
  406. IN PUL_SPIN_LOCK pSpinLock,
  407. IN PCSTR pFileName,
  408. IN USHORT LineNumber
  409. );
  410. VOID
  411. UlDbgAcquireInStackQueuedSpinLock(
  412. IN PUL_SPIN_LOCK pSpinLock,
  413. OUT PKLOCK_QUEUE_HANDLE pLockHandle,
  414. IN PCSTR pFileName,
  415. IN USHORT LineNumber
  416. );
  417. VOID
  418. UlDbgReleaseInStackQueuedSpinLock(
  419. IN PUL_SPIN_LOCK pSpinLock,
  420. IN PKLOCK_QUEUE_HANDLE pLockHandle,
  421. IN PCSTR pFileName,
  422. IN USHORT LineNumber
  423. );
  424. VOID
  425. UlDbgAcquireInStackQueuedSpinLockAtDpcLevel(
  426. IN PUL_SPIN_LOCK pSpinLock,
  427. OUT PKLOCK_QUEUE_HANDLE pLockHandle,
  428. IN PCSTR pFileName,
  429. IN USHORT LineNumber
  430. );
  431. VOID
  432. UlDbgReleaseInStackQueuedSpinLockFromDpcLevel(
  433. IN PUL_SPIN_LOCK pSpinLock,
  434. IN PKLOCK_QUEUE_HANDLE pLockHandle,
  435. IN PCSTR pFileName,
  436. IN USHORT LineNumber
  437. );
  438. BOOLEAN
  439. UlDbgSpinLockOwned(
  440. IN PUL_SPIN_LOCK pSpinLock
  441. );
  442. BOOLEAN
  443. UlDbgSpinLockUnowned(
  444. IN PUL_SPIN_LOCK pSpinLock
  445. );
  446. #define UlInitializeSpinLock( spinlock, name ) \
  447. UlDbgInitializeSpinLock( \
  448. (spinlock), \
  449. (name), \
  450. __FILE__, \
  451. __LINE__ \
  452. )
  453. #define UlAcquireSpinLock( spinlock, oldirql ) \
  454. UlDbgAcquireSpinLock( \
  455. (spinlock), \
  456. (oldirql), \
  457. __FILE__, \
  458. __LINE__ \
  459. )
  460. #define UlReleaseSpinLock( spinlock, oldirql ) \
  461. UlDbgReleaseSpinLock( \
  462. (spinlock), \
  463. (oldirql), \
  464. __FILE__, \
  465. __LINE__ \
  466. )
  467. #define UlAcquireSpinLockAtDpcLevel( spinlock ) \
  468. UlDbgAcquireSpinLockAtDpcLevel( \
  469. (spinlock), \
  470. __FILE__, \
  471. __LINE__ \
  472. )
  473. #define UlReleaseSpinLockFromDpcLevel( spinlock ) \
  474. UlDbgReleaseSpinLockFromDpcLevel( \
  475. (spinlock), \
  476. __FILE__, \
  477. __LINE__ \
  478. )
  479. #define UlAcquireInStackQueuedSpinLock( spinlock, lockhandle ) \
  480. UlDbgAcquireInStackQueuedSpinLock( \
  481. (spinlock), \
  482. (lockhandle), \
  483. __FILE__, \
  484. __LINE__ \
  485. )
  486. #define UlReleaseInStackQueuedSpinLock( spinlock, lockhandle ) \
  487. UlDbgReleaseInStackQueuedSpinLock( \
  488. (spinlock), \
  489. (lockhandle), \
  490. __FILE__, \
  491. __LINE__ \
  492. )
  493. #define UlAcquireInStackQueuedSpinLockAtDpcLevel( spinlock, lockhandle ) \
  494. UlDbgAcquireInStackQueuedSpinLockAtDpcLevel( \
  495. (spinlock), \
  496. (lockhandle), \
  497. __FILE__, \
  498. __LINE__ \
  499. )
  500. #define UlReleaseInStackQueuedSpinLockFromDpcLevel( spinlock, lockhandle ) \
  501. UlDbgReleaseInStackQueuedSpinLockFromDpcLevel( \
  502. (spinlock), \
  503. (lockhandle), \
  504. __FILE__, \
  505. __LINE__ \
  506. )
  507. #define DEBUG
  508. #if !TRACE_TO_STRING_LOG
  509. # define WriteGlobalStringLog DbgPrint
  510. #endif
  511. VOID
  512. UlDbgPrettyPrintBuffer(
  513. IN const UCHAR* pBuffer,
  514. IN ULONG_PTR BufferSize
  515. );
  516. //
  517. // Debug pool allocator.
  518. //
  519. PVOID
  520. UlDbgAllocatePool (
  521. IN POOL_TYPE PoolType,
  522. IN SIZE_T NumberOfBytes,
  523. IN ULONG Tag,
  524. IN PCSTR pFileName,
  525. IN USHORT LineNumber,
  526. IN PEPROCESS pProcess
  527. );
  528. VOID
  529. UlDbgFreePool (
  530. IN PVOID pPointer,
  531. IN ULONG Tag,
  532. IN PCSTR pFileName,
  533. IN USHORT LineNumber,
  534. IN POOL_TYPE PoolType,
  535. IN SIZE_T NumberOfBytes,
  536. IN PEPROCESS pProcess
  537. );
  538. #define UL_ALLOCATE_POOL( type, len, tag ) \
  539. UlDbgAllocatePool( \
  540. (type), \
  541. (len), \
  542. (tag), \
  543. __FILE__, \
  544. __LINE__, \
  545. NULL \
  546. )
  547. #define UL_FREE_POOL( ptr, tag ) \
  548. UlDbgFreePool( \
  549. (ptr), \
  550. (tag), \
  551. __FILE__, \
  552. __LINE__, \
  553. PagedPool, \
  554. 0, \
  555. NULL \
  556. )
  557. #define UL_ALLOCATE_POOL_WITH_QUOTA(type, len, tag, process) \
  558. UlDbgAllocatePool( \
  559. (type), \
  560. (len), \
  561. (tag), \
  562. __FILE__, \
  563. __LINE__, \
  564. (process) \
  565. )
  566. #define UL_FREE_POOL_WITH_QUOTA( ptr, tag, type, len, process ) \
  567. UlDbgFreePool( \
  568. (ptr), \
  569. (tag), \
  570. __FILE__, \
  571. __LINE__, \
  572. (type), \
  573. (len), \
  574. (process) \
  575. )
  576. //
  577. // Exception filter.
  578. //
  579. LONG
  580. UlDbgExceptionFilter(
  581. IN PEXCEPTION_POINTERS pExceptionPointers,
  582. IN PCSTR pFileName,
  583. IN USHORT LineNumber
  584. );
  585. #define UL_EXCEPTION_FILTER() \
  586. UlDbgExceptionFilter( \
  587. GetExceptionInformation(), \
  588. (PCSTR)__FILE__, \
  589. (USHORT)__LINE__ \
  590. )
  591. //
  592. // Exception warning converter.
  593. //
  594. NTSTATUS
  595. UlDbgConvertExceptionCode(
  596. IN NTSTATUS status,
  597. IN PCSTR pFileName,
  598. IN USHORT LineNumber
  599. );
  600. #define UL_CONVERT_EXCEPTION_CODE(status) \
  601. (NT_WARNING(status) ? \
  602. UlDbgConvertExceptionCode( \
  603. (status), \
  604. (PCSTR)__FILE__, \
  605. (USHORT)__LINE__ ) \
  606. : \
  607. (status))
  608. //
  609. // Invalid completion routine for catching incomplete IRP contexts.
  610. //
  611. VOID
  612. UlDbgInvalidCompletionRoutine(
  613. IN PVOID pCompletionContext,
  614. IN NTSTATUS Status,
  615. IN ULONG_PTR Information
  616. );
  617. //
  618. // Error handlers.
  619. //
  620. NTSTATUS
  621. UlDbgStatus(
  622. IN NTSTATUS Status,
  623. IN PCSTR pFileName,
  624. IN USHORT LineNumber
  625. );
  626. VOID
  627. UlDbgBreakOnError(
  628. PCSTR pFilename,
  629. ULONG LineNumber
  630. );
  631. #if KERNEL_PRIV
  632. #define RETURN(status) \
  633. return UlDbgStatus( \
  634. (status), \
  635. (PCSTR) __FILE__, \
  636. (USHORT) __LINE__ \
  637. )
  638. #define CHECK_STATUS(status) \
  639. UlDbgStatus( \
  640. (status), \
  641. (PCSTR)__FILE__, \
  642. (USHORT)__LINE__ \
  643. )
  644. #endif // KERNEL_PRIV
  645. //
  646. // Random structure dumpers.
  647. //
  648. VOID
  649. UlDbgDumpRequestBuffer(
  650. IN struct _UL_REQUEST_BUFFER *pBuffer,
  651. IN PCSTR pName
  652. );
  653. VOID
  654. UlDbgDumpHttpConnection(
  655. IN struct _UL_HTTP_CONNECTION *pConnection,
  656. IN PCSTR pName
  657. );
  658. //
  659. // IO wrappers.
  660. //
  661. PIRP
  662. UlDbgAllocateIrp(
  663. IN CCHAR StackSize,
  664. IN BOOLEAN ChargeQuota,
  665. IN PCSTR pFileName,
  666. IN USHORT LineNumber
  667. );
  668. VOID
  669. UlDbgFreeIrp(
  670. IN PIRP pIrp,
  671. IN PCSTR pFileName,
  672. IN USHORT LineNumber
  673. );
  674. NTSTATUS
  675. UlDbgCallDriver(
  676. IN PDEVICE_OBJECT pDeviceObject,
  677. IN OUT PIRP pIrp,
  678. IN PCSTR pFileName,
  679. IN USHORT LineNumber
  680. );
  681. VOID
  682. UlDbgCompleteRequest(
  683. IN PIRP pIrp,
  684. IN CCHAR PriorityBoost,
  685. IN PCSTR pFileName,
  686. IN USHORT LineNumber
  687. );
  688. #define UlAllocateIrp( stack, quota ) \
  689. UlDbgAllocateIrp( \
  690. (stack), \
  691. (quota), \
  692. (PCSTR)__FILE__, \
  693. (USHORT)__LINE__ \
  694. )
  695. #define UlFreeIrp( pirp ) \
  696. UlDbgFreeIrp( \
  697. (pirp), \
  698. (PCSTR)__FILE__, \
  699. (USHORT)__LINE__ \
  700. )
  701. #define UlCallDriver( pdevice, pirp ) \
  702. UlDbgCallDriver( \
  703. (pdevice), \
  704. (pirp), \
  705. (PCSTR)__FILE__, \
  706. (USHORT)__LINE__ \
  707. )
  708. #define UlCompleteRequest( pirp, boost ) \
  709. UlDbgCompleteRequest( \
  710. (pirp), \
  711. (boost), \
  712. (PCSTR)__FILE__, \
  713. (USHORT)__LINE__ \
  714. )
  715. PMDL
  716. UlDbgAllocateMdl(
  717. IN PVOID VirtualAddress,
  718. IN ULONG Length,
  719. IN BOOLEAN SecondaryBuffer,
  720. IN BOOLEAN ChargeQuota,
  721. IN OUT PIRP Irp,
  722. IN PCSTR pFileName,
  723. IN USHORT LineNumber
  724. );
  725. VOID
  726. UlDbgFreeMdl(
  727. IN PMDL Mdl,
  728. IN PCSTR pFileName,
  729. IN USHORT LineNumber
  730. );
  731. #define UlAllocateMdl( add, len, second, quota, irp ) \
  732. UlDbgAllocateMdl( \
  733. (add), \
  734. (len), \
  735. (second), \
  736. (quota), \
  737. (irp), \
  738. (PCSTR)__FILE__, \
  739. (USHORT)__LINE__ \
  740. )
  741. #define UlFreeMdl( mdl ) \
  742. UlDbgFreeMdl( \
  743. (mdl), \
  744. (PCSTR)__FILE__, \
  745. (USHORT)__LINE__ \
  746. )
  747. // #define SPECIAL_MDL_FLAG 0x8000
  748. PCSTR
  749. UlDbgFindFilePart(
  750. IN PCSTR pPath
  751. );
  752. //
  753. // List Manipulation
  754. //
  755. #define UlRemoveEntryList(pEntry) \
  756. do { \
  757. ASSERT(NULL != (pEntry)); \
  758. ASSERT(NULL != (pEntry)); \
  759. ASSERT(NULL != (pEntry)->Flink); \
  760. ASSERT(NULL != (pEntry)->Blink); \
  761. RemoveEntryList(pEntry); \
  762. (pEntry)->Flink = (pEntry)->Blink = NULL; \
  763. } while (0, 0)
  764. #define UlIoSetCancelRoutine UlDbgIoSetCancelRoutine
  765. #else // !DBG -----------------------------------------------------------
  766. //
  767. // Disable all of the above.
  768. //
  769. #define UL_ENTER_DRIVER( function, pirp ) NOP_FUNCTION
  770. #define UL_LEAVE_DRIVER( function ) NOP_FUNCTION
  771. #define UL_ERESOURCE ERESOURCE
  772. #define PUL_ERESOURCE PERESOURCE
  773. #define UlInitializeResource( resource, name, param, tag ) \
  774. ExInitializeResourceLite( (resource) )
  775. #define UlDeleteResource( resource ) \
  776. ExDeleteResourceLite( (resource) )
  777. #define UlAcquireResourceExclusive( resource, wait ) \
  778. do \
  779. { \
  780. KeEnterCriticalRegion(); \
  781. ExAcquireResourceExclusiveLite( (resource), (wait) ); \
  782. } while (0, 0)
  783. #define UlAcquireResourceShared( resource, wait ) \
  784. do \
  785. { \
  786. KeEnterCriticalRegion(); \
  787. ExAcquireResourceSharedLite( (resource), (wait) ); \
  788. } while (0, 0)
  789. #define UlReleaseResource( resource ) \
  790. do \
  791. { \
  792. ExReleaseResourceLite( (resource) ); \
  793. KeLeaveCriticalRegion(); \
  794. } while (0, 0)
  795. #define UlConvertExclusiveToShared( resource ) \
  796. ExConvertExclusiveToSharedLite( (resource) )
  797. __inline
  798. BOOLEAN
  799. UlTryToAcquireResourceExclusive(
  800. IN PERESOURCE Resource
  801. )
  802. {
  803. BOOLEAN fLocked;
  804. KeEnterCriticalRegion();
  805. fLocked = ExAcquireResourceExclusiveLite( Resource, FALSE );
  806. if (! fLocked )
  807. KeLeaveCriticalRegion();
  808. return fLocked;
  809. }
  810. #define IS_RESOURCE_INITIALIZED( resource ) \
  811. ((resource)->SystemResourcesList.Flink != NULL)
  812. #define UL_PUSH_LOCK EX_PUSH_LOCK
  813. #define PUL_PUSH_LOCK PEX_PUSH_LOCK
  814. #define UlInitializePushLock( pushlock, name, param, tag ) \
  815. ExInitializePushLock( (pushlock) )
  816. #define UlDeletePushLock( pushlock ) NOP_FUNCTION
  817. #define UlAcquirePushLockExclusive( pushlock ) \
  818. do \
  819. { \
  820. KeEnterCriticalRegion(); \
  821. ExAcquirePushLockExclusive( (pushlock) ); \
  822. } while (0, 0)
  823. #define UlReleasePushLockExclusive( pushlock ) \
  824. do \
  825. { \
  826. ExReleasePushLockExclusive( (pushlock) ); \
  827. KeLeaveCriticalRegion(); \
  828. } while (0, 0)
  829. #define UlAcquirePushLockShared( pushlock ) \
  830. do \
  831. { \
  832. KeEnterCriticalRegion(); \
  833. ExAcquirePushLockShared( (pushlock) ); \
  834. } while (0, 0)
  835. #define UlReleasePushLockShared( pushlock ) \
  836. do \
  837. { \
  838. ExReleasePushLockShared( (pushlock) ); \
  839. KeLeaveCriticalRegion(); \
  840. } while (0, 0)
  841. #define UlReleasePushLock( pushlock ) \
  842. do \
  843. { \
  844. ExReleasePushLock( (pushlock) ); \
  845. KeLeaveCriticalRegion(); \
  846. } while (0, 0)
  847. #define UL_SPIN_LOCK KSPIN_LOCK
  848. #define PUL_SPIN_LOCK PKSPIN_LOCK
  849. #define KSPIN_LOCK_FROM_UL_SPIN_LOCK( pLock ) (pLock)
  850. #define UlInitializeSpinLock( spinlock, name ) \
  851. KeInitializeSpinLock( (spinlock) )
  852. #define UlAcquireSpinLock( spinlock, oldirql ) \
  853. KeAcquireSpinLock( (spinlock), (oldirql) )
  854. #define UlReleaseSpinLock( spinlock, oldirql ) \
  855. KeReleaseSpinLock( (spinlock), (oldirql) )
  856. #define UlAcquireSpinLockAtDpcLevel( spinlock ) \
  857. KeAcquireSpinLockAtDpcLevel( (spinlock) )
  858. #define UlReleaseSpinLockFromDpcLevel( spinlock ) \
  859. KeReleaseSpinLockFromDpcLevel( (spinlock) )
  860. #define UlAcquireInStackQueuedSpinLock( spinlock, lockhandle ) \
  861. KeAcquireInStackQueuedSpinLock( (spinlock), (lockhandle) )
  862. #define UlReleaseInStackQueuedSpinLock( spinlock, lockhandle ) \
  863. KeReleaseInStackQueuedSpinLock( (lockhandle) )
  864. #define KeAcquireInStackQueueddSpinLockAtDpcLevel( spinlock, lockhandle ) \
  865. KeAcquireInStackQueuedSpinLockAtDpcLevel( (spinlock), (lockhandle) )
  866. #define UlReleaseInStackQueuedSpinLockFromDpcLevel( spinlock, lockhandle ) \
  867. KeReleaseInStackQueuedSpinLockFromDpcLevel( (lockhandle) )
  868. #define UlDbgPrettyPrintBuffer(pBuffer, BufferSize) NOP_FUNCTION
  869. #define UL_ALLOCATE_POOL( type, len, tag ) \
  870. ExAllocatePoolWithTagPriority( \
  871. (type), \
  872. (len), \
  873. (tag), \
  874. (LowPoolPriority) \
  875. )
  876. #define UL_FREE_POOL( ptr, tag ) \
  877. MyFreePoolWithTag( \
  878. (ptr), \
  879. (tag) \
  880. )
  881. __inline
  882. PVOID
  883. UlAllocatePoolWithQuota(
  884. POOL_TYPE PoolType,
  885. SIZE_T Length,
  886. ULONG Tag,
  887. PEPROCESS pProcess
  888. )
  889. {
  890. PVOID p;
  891. if (PsChargeProcessPoolQuota(
  892. pProcess,
  893. PoolType,
  894. Length) == STATUS_SUCCESS)
  895. {
  896. if ((p = ExAllocatePoolWithTagPriority(
  897. PoolType,
  898. Length,
  899. Tag,
  900. LowPoolPriority)) != NULL)
  901. {
  902. return p;
  903. }
  904. PsReturnPoolQuota(pProcess, PoolType, Length);
  905. }
  906. return NULL;
  907. }
  908. #define UL_ALLOCATE_POOL_WITH_QUOTA(type, len, tag, process) \
  909. UlAllocatePoolWithQuota( \
  910. (type), \
  911. (len), \
  912. (tag), \
  913. (process) \
  914. )
  915. #define UL_FREE_POOL_WITH_QUOTA( ptr, tag, type, len, process ) \
  916. do \
  917. { \
  918. PsReturnPoolQuota( \
  919. (process), \
  920. (type), \
  921. (len)); \
  922. MyFreePoolWithTag( \
  923. (ptr), \
  924. (tag) \
  925. ); \
  926. } while (0, 0)
  927. #define UL_EXCEPTION_FILTER() EXCEPTION_EXECUTE_HANDLER
  928. #define UL_CONVERT_EXCEPTION_CODE(status) \
  929. (NT_WARNING(status) ? UL_DEFAULT_ERROR_ON_EXCEPTION : (status))
  930. #if KERNEL_PRIV
  931. # define RETURN(status) return (status)
  932. # define CHECK_STATUS(Status) NOP_FUNCTION
  933. #endif
  934. #define UlAllocateIrp( stack, quota ) \
  935. IoAllocateIrp( (stack), (quota) )
  936. #define UlFreeIrp( pirp ) \
  937. IoFreeIrp( (pirp) )
  938. #define UlCallDriver( pdevice, pirp ) \
  939. IoCallDriver( (pdevice), (pirp) )
  940. #define UlCompleteRequest( pirp, boost ) \
  941. IoCompleteRequest( (pirp), (boost) )
  942. #define UlAllocateMdl( add, len, second, quota, irp ) \
  943. IoAllocateMdl( \
  944. (add), \
  945. (len), \
  946. (second), \
  947. (quota), \
  948. (irp) \
  949. )
  950. #define UlFreeMdl( mdl ) \
  951. IoFreeMdl( (mdl) )
  952. #define UlRemoveEntryList(pEntry) \
  953. RemoveEntryList(pEntry)
  954. #define UlIoSetCancelRoutine \
  955. IoSetCancelRoutine
  956. #endif // DBG
  957. // Allocation wrapper helpers
  958. #define UL_ALLOCATE_STRUCT_WITH_SPACE(pt,ot,cb,t) \
  959. (ot *)(UL_ALLOCATE_POOL(pt,ALIGN_UP(sizeof(ot),PVOID)+(cb),t))
  960. #define UL_ALLOCATE_STRUCT(pt,ot,t) \
  961. (ot *)(UL_ALLOCATE_POOL(pt,sizeof(ot),t))
  962. #define UL_ALLOCATE_ARRAY(pt,et,c,t) \
  963. (et *)(UL_ALLOCATE_POOL(pt,sizeof(et)*(c),t))
  964. #define UL_FREE_POOL_WITH_SIG(p,sig) \
  965. do { \
  966. PREFAST_ASSUME(NULL != (p), "Callers check this"); \
  967. (p)->Signature = MAKE_FREE_SIGNATURE(sig); \
  968. UL_FREE_POOL(p,sig); \
  969. (p) = NULL; \
  970. } while (0)
  971. #define HAS_VALID_SIGNATURE(p, sig) \
  972. ( (NULL != (p)) && ((sig) == (p)->Signature) )
  973. #endif // _DEBUG_H_