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.

1418 lines
30 KiB

  1. /********************************************************************/
  2. /** Microsoft LAN Manager **/
  3. /** Copyright(c) Microsoft Corp., 1990-1992 **/
  4. /********************************************************************/
  5. /* :ts=4 */
  6. //** cxport.h - Common transport environment include file.
  7. //
  8. // This file defines the structures and external declarations needed
  9. // to use the common transport environment.
  10. //
  11. #ifndef _CXPORT_H_INCLUDED_
  12. #define _CXPORT_H_INCLUDED_
  13. #pragma warning(push)
  14. #pragma warning(disable:4115) // named type definition in parentheses
  15. //
  16. // Typedefs used in this file
  17. //
  18. #ifndef CTE_TYPEDEFS_DEFINED
  19. #define CTE_TYPEDEFS_DEFINED 1
  20. typedef unsigned long ulong;
  21. typedef unsigned short ushort;
  22. typedef unsigned char uchar;
  23. typedef unsigned int uint;
  24. #endif // CTE_TYPEDEFS_DEFINED
  25. #ifdef NT
  26. //////////////////////////////////////////////////////////////////////////////
  27. //
  28. // Following are the NT environment definitions
  29. //
  30. //////////////////////////////////////////////////////////////////////////////
  31. //
  32. // Structure manipulation macros
  33. //
  34. #ifndef offsetof
  35. #define offsetof(type, field) FIELD_OFFSET(type, field)
  36. #endif
  37. #define STRUCT_OF(type, address, field) CONTAINING_RECORD(address, type, field)
  38. //
  39. //* CTE Initialization.
  40. //
  41. //++
  42. //
  43. // int
  44. // CTEInitialize(
  45. // void
  46. // );
  47. //
  48. // Routine Description:
  49. //
  50. // Initializes the Common Transport Environment. All users of the CTE
  51. // must call this routine during initialization before calling any
  52. // other CTE routines.
  53. //
  54. // Arguments:
  55. //
  56. // None.
  57. //
  58. // Return Value:
  59. //
  60. // Returns zero on failure, non-zero if it succeeds.
  61. //
  62. //--
  63. extern int
  64. CTEInitialize(
  65. void
  66. );
  67. //
  68. //* Lock related definitions.
  69. //
  70. typedef KSPIN_LOCK CTELock;
  71. typedef KIRQL CTELockHandle;
  72. #define DEFINE_LOCK_STRUCTURE(x) CTELock x;
  73. #define LOCK_STRUCTURE_SIZE sizeof(CTELock)
  74. #define EXTERNAL_LOCK(x) extern CTELock x;
  75. //++
  76. //
  77. // VOID
  78. // CTEInitLock(
  79. // CTELOCK *SpinLock
  80. // );
  81. //
  82. // Routine Description:
  83. //
  84. // Initializes a spin lock.
  85. //
  86. // Arguments:
  87. //
  88. // SpinLock - Supplies a pointer to the lock structure.
  89. //
  90. // Return Value:
  91. //
  92. // None.
  93. //
  94. //--
  95. #define CTEInitLock(l) KeInitializeSpinLock(l)
  96. #if MILLEN
  97. VOID TcpipMillenGetLock(CTELock *pLock);
  98. VOID TcpipMillenFreeLock(CTELock *pLock);
  99. #define CTEGetLock(l, h) TcpipMillenGetLock(l); *(h) = 0
  100. #define CTEGetLockAtDPC(l) TcpipMillenGetLock(l)
  101. #define CTEFreeLock(l, h) TcpipMillenFreeLock(l)
  102. #define CTEFreeLockFromDPC(l) TcpipMillenFreeLock(l)
  103. #else // MILLEN
  104. //++
  105. //
  106. // VOID
  107. // CTEGetLock(
  108. // CTELock *SpinLock,
  109. // CTELockHandle *OldIrqlLevel
  110. // );
  111. //
  112. // Routine Description:
  113. //
  114. // Acquires a spin lock
  115. //
  116. // Arguments:
  117. //
  118. // SpinLock - A pointer to the lock structure.
  119. // OldIrqlLevel - A pointer to a variable to receive the old IRQL level .
  120. //
  121. // Return Value:
  122. //
  123. // None.
  124. //
  125. //--
  126. #define CTEGetLock(l, h) KeAcquireSpinLock((l),(h))
  127. //++
  128. //
  129. // VOID
  130. // CTEGetLockAtDPC(
  131. // CTELock *SpinLock
  132. // );
  133. //
  134. // Routine Description:
  135. //
  136. // Acquires a spin lock when the processor is already running at
  137. // DISPATCH_LEVEL.
  138. //
  139. // Arguments:
  140. //
  141. // SpinLock - A pointer to the lock structure.
  142. //
  143. // Return Value:
  144. //
  145. // None.
  146. //
  147. //--
  148. #define CTEGetLockAtDPC(l) KeAcquireSpinLockAtDpcLevel((l))
  149. //++
  150. //
  151. // VOID
  152. // CTEFreeLock(
  153. // CTELock *SpinLock,
  154. // CTELockHandle OldIrqlLevel
  155. // );
  156. //
  157. // Routine Description:
  158. //
  159. // Releases a spin lock
  160. //
  161. // Arguments:
  162. //
  163. // SpinLock - A pointer to the lock variable.
  164. // OldIrqlLevel - The IRQL level to restore.
  165. //
  166. // Return Value:
  167. //
  168. // None.
  169. //
  170. //--
  171. #define CTEFreeLock(l, h) KeReleaseSpinLock((l),(h))
  172. //++
  173. //
  174. // VOID
  175. // CTEFreeLockFromDPC(
  176. // CTELock *SpinLock
  177. // );
  178. //
  179. // Routine Description:
  180. //
  181. // Releases a spin lock
  182. //
  183. // Arguments:
  184. //
  185. // SpinLock - A pointer to the lock variable.
  186. //
  187. // Return Value:
  188. //
  189. // None.
  190. //
  191. //--
  192. #define CTEFreeLockFromDPC(l) KeReleaseSpinLockFromDpcLevel((l))
  193. #endif // !MILLEN
  194. //
  195. // Interlocked counter management routines.
  196. //
  197. //++
  198. //
  199. // ulong
  200. // CTEInterlockedAddUlong(
  201. // ulong *AddendPtr,
  202. // ulong Increment,
  203. // CTELock *LockPtr
  204. // );
  205. //
  206. // Routine Description:
  207. //
  208. // Adds an increment to an unsigned long quantity using a spinlock
  209. // for synchronization.
  210. //
  211. // Arguments:
  212. //
  213. // AddendPtr - A pointer to the quantity to be updated.
  214. // LockPtr - A pointer to the spinlock used to synchronize the operation.
  215. //
  216. // Return Value:
  217. //
  218. // The initial value of the Added variable.
  219. //
  220. // Notes:
  221. //
  222. // It is not permissible to mix calls to CTEInterlockedAddULong with
  223. // calls to the CTEInterlockedIncrement/DecrementLong routines on the
  224. // same value.
  225. //
  226. //--
  227. #define CTEInterlockedAddUlong(AddendPtr, Increment, LockPtr) \
  228. ExInterlockedAddUlong(AddendPtr, Increment, LockPtr)
  229. //++
  230. //
  231. // ulong
  232. // CTEInterlockedExchangeAdd(
  233. // ulong *AddendPtr,
  234. // ulong Increment,
  235. // );
  236. //
  237. // Routine Description:
  238. //
  239. // Adds an increment to an unsigned long quantity without using a spinlock.
  240. //
  241. // Arguments:
  242. //
  243. // AddendPtr - A pointer to the quantity to be updated.
  244. // Increment - The amount to be added to *AddendPtr
  245. //
  246. // Return Value:
  247. //
  248. // The initial value of the Added variable.
  249. //
  250. // Notes:
  251. //
  252. //--
  253. #define CTEInterlockedExchangeAdd(AddendPtr, Increment) \
  254. InterlockedExchangeAdd(AddendPtr, Increment)
  255. //++
  256. //
  257. // long
  258. // CTEInterlockedDecrementLong(
  259. // ulong *AddendPtr
  260. // );
  261. //
  262. // Routine Description:
  263. //
  264. // Decrements a long quantity atomically
  265. //
  266. // Arguments:
  267. //
  268. // AddendPtr - A pointer to the quantity to be decremented
  269. //
  270. // Return Value:
  271. //
  272. // < 0 if Addend is < 0 after decrement.
  273. // == 0 if Addend is = 0 after decrement.
  274. // > 0 if Addend is > 0 after decrement.
  275. //
  276. // Notes:
  277. //
  278. // It is not permissible to mix calls to CTEInterlockedAddULong with
  279. // calls to the CTEInterlockedIncrement/DecrementLong routines on the
  280. // same value.
  281. //
  282. //--
  283. #define CTEInterlockedDecrementLong(AddendPtr) \
  284. InterlockedDecrement( (PLONG) (AddendPtr))
  285. //++
  286. //
  287. // long
  288. // CTEInterlockedIncrementLong(
  289. // ulong *AddendPtr
  290. // );
  291. //
  292. // Routine Description:
  293. //
  294. // Increments a long quantity atomically
  295. //
  296. // Arguments:
  297. //
  298. // AddendPtr - A pointer to the quantity to be incremented.
  299. //
  300. // Return Value:
  301. //
  302. // < 0 if Addend is < 0 after decrement.
  303. // == 0 if Addend is = 0 after decrement.
  304. // > 0 if Addend is > 0 after decrement.
  305. //
  306. // Notes:
  307. //
  308. // It is not permissible to mix calls to CTEInterlockedAddULong with
  309. // calls to the CTEInterlockedIncrement/DecrementLong routines on the
  310. // same value.
  311. //
  312. //--
  313. #define CTEInterlockedIncrementLong(AddendPtr) \
  314. InterlockedIncrement((PLONG) (AddendPtr))
  315. //
  316. // Large Integer manipulation routines.
  317. //
  318. typedef ULARGE_INTEGER CTEULargeInt;
  319. //++
  320. //
  321. // ulong
  322. // CTEEnlargedUnsignedDivide(
  323. // CTEULargeInt Dividend,
  324. // ulong Divisor,
  325. // ulong *Remainder
  326. // );
  327. //
  328. // Routine Description:
  329. //
  330. // Divides an unsigned large integer quantity by an unsigned long quantity
  331. // to yield an unsigned long quotient and an unsigned long remainder.
  332. //
  333. // Arguments:
  334. //
  335. // Dividend - The dividend value.
  336. // Divisor - The divisor value.
  337. // Remainder - A pointer to a variable to receive the remainder.
  338. //
  339. // Return Value:
  340. //
  341. // The unsigned long quotient of the division.
  342. //
  343. //--
  344. #define CTEEnlargedUnsignedDivide(Dividend, Divisor, Remainder) \
  345. RtlEnlargedUnsignedDivide (Dividend, Divisor, Remainder)
  346. //
  347. //* String definitions and manipulation routines
  348. //
  349. //
  350. //++
  351. //
  352. // BOOLEAN
  353. // CTEInitString(
  354. // PNDIS_STRING DestinationString,
  355. // char *SourceString
  356. // );
  357. //
  358. // Routine Description:
  359. //
  360. // Converts a C style ASCII string to an NDIS_STRING. Resources needed for
  361. // the NDIS_STRING are allocated and must be freed by a call to
  362. // CTEFreeString.
  363. //
  364. // Arguments:
  365. //
  366. // DestinationString - A pointer to an NDIS_STRING variable with no
  367. // associated data buffer.
  368. //
  369. // SourceString - The C style ASCII string source.
  370. //
  371. //
  372. // Return Value:
  373. //
  374. // TRUE if the initialization succeeded. FALSE otherwise.
  375. //
  376. //--
  377. BOOLEAN
  378. CTEInitString(
  379. PUNICODE_STRING DestinationString,
  380. char *SourceString
  381. );
  382. //++
  383. //
  384. // BOOLEAN
  385. // CTEAllocateString(
  386. // PNDIS_STRING String,
  387. // unsigned short Length
  388. // );
  389. //
  390. // Routine Description:
  391. //
  392. // Allocates a data buffer for Length characters in an uninitialized
  393. // NDIS_STRING. The allocated space must be freed by a call to
  394. // CTEFreeString.
  395. //
  396. //
  397. // Arguments:
  398. //
  399. // String - A pointer to an NDIS_STRING variable with no
  400. // associated data buffer.
  401. //
  402. // MaximumLength - The maximum length of the string. The unit of this
  403. // value is system dependent.
  404. //
  405. // Return Value:
  406. //
  407. // TRUE if the initialization succeeded. FALSE otherwise.
  408. //
  409. //--
  410. BOOLEAN
  411. CTEAllocateString(
  412. PUNICODE_STRING String,
  413. unsigned short Length
  414. );
  415. //++
  416. //
  417. // VOID
  418. // CTEFreeString(
  419. // PNDIS_STRING String,
  420. // );
  421. //
  422. // Routine Description:
  423. //
  424. // Frees the string buffer associated with an NDIS_STRING. The buffer must
  425. // have been allocated by a previous call to CTEInitString.
  426. //
  427. // Arguments:
  428. //
  429. // String - A pointer to an NDIS_STRING variable.
  430. //
  431. //
  432. // Return Value:
  433. //
  434. // None.
  435. //
  436. //--
  437. #define CTEFreeString(String) ExFreePool((String)->Buffer)
  438. //++
  439. //
  440. // unsigned short
  441. // CTELengthString(
  442. // PNDIS_STRING String
  443. // );
  444. //
  445. // Routine Description:
  446. //
  447. // Calculates the length of an NDIS_STRING.
  448. //
  449. // Arguments:
  450. //
  451. // The string to test.
  452. //
  453. // Return Value:
  454. //
  455. // The length of the string parameter. The unit of this value is
  456. // system dependent.
  457. //
  458. //--
  459. #define CTELengthString(String) ((String)->Length)
  460. //++
  461. //
  462. // BOOLEAN
  463. // CTEEqualString(
  464. // CTEString *String1,
  465. // CTEString *String2
  466. // );
  467. //
  468. // Routine Description:
  469. //
  470. // Compares two NDIS_STRINGs for case-sensitive equality
  471. //
  472. // Arguments:
  473. //
  474. // String1 - A pointer to the first string to compare.
  475. // String2 - A pointer to the second string to compare.
  476. //
  477. // Return Value:
  478. //
  479. // TRUE if the strings are equivalent. FALSE otherwise.
  480. //
  481. //--
  482. #define CTEEqualString(S1, S2) RtlEqualUnicodeString(S1, S2, FALSE)
  483. //++
  484. //
  485. // VOID
  486. // CTECopyString(
  487. // CTEString *DestinationString,
  488. // CTEString *SourceString
  489. // );
  490. //
  491. // Routine Description:
  492. //
  493. // Copies one NDIS_STRING to another. Behavior is undefined if the
  494. // destination is not long enough to hold the source.
  495. //
  496. // Arguments:
  497. //
  498. // DestinationString - A pointer to the destination string.
  499. // SourceString - A pointer to the source string.
  500. //
  501. // Return Value:
  502. //
  503. // None.
  504. //
  505. //--
  506. #define CTECopyString(D, S) RtlCopyUnicodeString(D, S)
  507. //
  508. //* Delayed event definitions
  509. //
  510. // Delayed events are events scheduled that can be scheduled to
  511. // occur 'later', without a timeout. They happen as soon as the system
  512. // is ready for them. The caller specifies a parameter that will be
  513. // passed to the event proc when the event is called.
  514. //
  515. // In the NT environmnet, delayed events are implemented using Executive
  516. // worker threads.
  517. //
  518. // NOTE: The event handler routine may not block.
  519. //
  520. #pragma warning(push)
  521. #pragma warning(disable:4115) //named type definition in parenthesis
  522. typedef void (*CTEEventRtn)(struct CTEEvent *, void *);
  523. #pragma warning(pop)
  524. struct CTEEvent {
  525. uint ce_scheduled;
  526. CTELock ce_lock;
  527. CTEEventRtn ce_handler; // Procedure to be called.
  528. void *ce_arg; // Argument to pass to handler.
  529. WORK_QUEUE_ITEM ce_workitem; // Kernel ExWorkerThread queue item.
  530. }; /* CTEEvent */
  531. typedef struct CTEEvent CTEEvent;
  532. //++
  533. //
  534. // void
  535. // CTEInitEvent(
  536. // IN CTEEvent *Event,
  537. // IN CTEEventRtn *Handler
  538. // );
  539. //
  540. // Routine Description:
  541. //
  542. // Initializes a delayed event structure.
  543. //
  544. // Arguments:
  545. //
  546. // Event - Pointer to a CTE Event variable
  547. // Handler - Pointer to the function to be called when the event is
  548. // scheduled.
  549. //
  550. // Return Value:
  551. //
  552. // None.
  553. //
  554. //--
  555. extern void
  556. CTEInitEvent(
  557. IN CTEEvent *Event,
  558. IN CTEEventRtn Handler
  559. );
  560. //++
  561. //
  562. // int
  563. // CTEScheduleCriticalEvent(
  564. // IN CTEEvent *Event,
  565. // IN void *Argument
  566. // );
  567. //
  568. // Routine Description:
  569. //
  570. // Schedules a routine to be executed later in a different context. In the
  571. // NT environment, the event is implemented as a kernel DPC using CriticalWorkerQueue.
  572. //
  573. // Arguments:
  574. //
  575. // Event - Pointer to a CTE Event variable
  576. // Argument - An argument to pass to the event handler when it is called
  577. //
  578. // Return Value:
  579. //
  580. // 0 if the event could not be scheduled. Nonzero otherwise.
  581. //
  582. //--
  583. int
  584. CTEScheduleCriticalEvent(
  585. IN CTEEvent *Event,
  586. IN void *Argument OPTIONAL
  587. );
  588. //++
  589. //
  590. // int
  591. // CTEScheduleEvent(
  592. // IN CTEEvent *Event,
  593. // IN void *Argument
  594. // );
  595. //
  596. // Routine Description:
  597. //
  598. // See CTEScheduleDelayedEvent right below, this function
  599. // is exactly the same.
  600. //--
  601. int
  602. CTEScheduleEvent(
  603. IN CTEEvent *Event,
  604. IN void *Argument OPTIONAL
  605. );
  606. // int
  607. // CTEScheduleDelayedEvent(
  608. // IN CTEEvent *Event,
  609. // IN void *Argument
  610. // );
  611. //
  612. // Routine Description:
  613. //
  614. // Schedules a routine to be executed later in a different context. In the
  615. // NT environment, the event is implemented as a kernel DPC, using DealyedWorkerQueue.
  616. //
  617. // Arguments:
  618. //
  619. // Event - Pointer to a CTE Event variable
  620. // Argument - An argument to pass to the event handler when it is called
  621. //
  622. // Return Value:
  623. //
  624. // 0 if the event could not be scheduled. Nonzero otherwise.
  625. //
  626. //--
  627. int
  628. CTEScheduleDelayedEvent(
  629. IN CTEEvent *Event,
  630. IN void *Argument OPTIONAL
  631. );
  632. #if MILLEN
  633. #define CTEScheduleDelayedEvent CTEScheduleEvent
  634. #endif // MILLEN
  635. //++
  636. //
  637. // int
  638. // CTECancelEvent(
  639. // IN CTEEvent *Event
  640. // );
  641. //
  642. // Routine Description:
  643. //
  644. // Cancels a previously scheduled delayed event routine.
  645. //
  646. // Arguments:
  647. //
  648. // Event - Pointer to a CTE Event variable
  649. //
  650. // Return Value:
  651. //
  652. // 0 if the event couldn't be cancelled. Nonzero otherwise.
  653. //
  654. // Notes:
  655. //
  656. // In the NT environment, a delayed event cannot be cancelled.
  657. //
  658. //--
  659. #define CTECancelEvent(Event) 0
  660. //
  661. //* Timer related declarations
  662. //
  663. struct CTETimer {
  664. uint t_running;
  665. CTELock t_lock;
  666. CTEEventRtn t_handler;
  667. void *t_arg;
  668. #if !MILLEN
  669. KDPC t_dpc; // DPC for this timer.
  670. KTIMER t_timer; // Kernel timer structure.
  671. #else
  672. NDIS_TIMER t_timer;
  673. #endif
  674. }; /* CTETimer */
  675. typedef struct CTETimer CTETimer;
  676. //++
  677. //
  678. // void
  679. // CTEInitTimer(
  680. // IN CTETimer *Timer
  681. // );
  682. //
  683. // Routine Description:
  684. //
  685. // Initializes a CTE Timer structure. This routine must be used
  686. // once on every timer before it is set. It may not be invoked on
  687. // a running timer.
  688. //
  689. // Arguments:
  690. //
  691. // Timer - Pointer to the CTE Timer to be initialized.
  692. //
  693. // Return Value:
  694. //
  695. // 0 if the timer could not be initialized. Nonzero otherwise.
  696. //
  697. //--
  698. extern void
  699. CTEInitTimer(
  700. IN CTETimer *Timer
  701. );
  702. //++
  703. //
  704. // extern void *
  705. // CTEStartTimer(
  706. // IN CTETimer *Timer
  707. // );
  708. //
  709. // Routine Description:
  710. //
  711. // This routine starts a CTE timer running.
  712. //
  713. // Arguments:
  714. //
  715. // Timer - Pointer to the CTE Timer to start.
  716. // DueTime - The time in milliseconds from the present at which the
  717. // timer will be due.
  718. // Handler - The function to call when the timer expires.
  719. // Context - A value to pass to the Handler routine.
  720. //
  721. // Return Value:
  722. //
  723. // NULL if the timer could not be started. Non-NULL otherwise.
  724. //
  725. // Notes:
  726. //
  727. // In the NT environment, the first argument to the Handler function is
  728. // a pointer to the timer structure, not to a CTEEvent structure.
  729. //
  730. //--
  731. extern void *
  732. CTEStartTimer(
  733. IN CTETimer *Timer,
  734. IN unsigned long DueTime,
  735. IN CTEEventRtn Handler,
  736. IN void *Context OPTIONAL
  737. );
  738. //++
  739. //
  740. // int
  741. // CTEStopTimer(
  742. // IN CTETimer *Timer
  743. // );
  744. //
  745. // Routine Description:
  746. //
  747. // Cancels a running CTE timer.
  748. //
  749. // Arguments:
  750. //
  751. // Timer - Pointer to the CTE Timer to be cancelled.
  752. //
  753. // Return Value:
  754. //
  755. // 0 if the timer could not be cancelled. Nonzero otherwise.
  756. //
  757. // Notes:
  758. //
  759. // Calling this function on a timer that is not active has no effect.
  760. // If this routine fails, the timer may be in the process of expiring
  761. // or may have already expired. In either case, the caller must
  762. // sychronize with the Handler function as appropriate.
  763. //
  764. //--
  765. #if !MILLEN
  766. #define CTEStopTimer(Timer) ((int) KeCancelTimer(&((Timer)->t_timer)))
  767. #else
  768. extern int
  769. CTEStopTimer(
  770. IN CTETimer *Timer
  771. );
  772. #endif
  773. //++
  774. //
  775. // unsigned long
  776. // CTESystemUpTime(
  777. // void
  778. // );
  779. //
  780. // Routine Description:
  781. //
  782. // Returns the time in milliseconds that the system has been running.
  783. //
  784. // Arguments:
  785. //
  786. // None.
  787. //
  788. // Return Value:
  789. //
  790. // The time in milliseconds.
  791. //
  792. //--
  793. extern unsigned long
  794. CTESystemUpTime(
  795. void
  796. );
  797. //
  798. //* Memory allocation functions.
  799. //
  800. // There are only two main functions, CTEAllocMem and CTEFreeMem. Locks
  801. // should not be held while calling these functions, and it is possible
  802. // that they may yield when called, particularly in the VxD environment.
  803. //
  804. // In the VxD environment there is a third auxillary function CTERefillMem,
  805. // used to refill the VxD heap manager.
  806. //
  807. //++
  808. //
  809. // void *
  810. // CTEAllocMem(
  811. // ulong Size
  812. // );
  813. //
  814. // Routine Description:
  815. //
  816. // Allocates a block of memory from nonpaged pool.
  817. //
  818. // Arguments:
  819. //
  820. // Size - The size in bytes to allocate.
  821. //
  822. // Return Value:
  823. //
  824. // A pointer to the allocated block, or NULL.
  825. //
  826. //--
  827. #define CTEAllocMem(Size) ExAllocatePoolWithTag(NonPagedPool, (Size), ' ETC')
  828. //++
  829. //
  830. // void
  831. // CTEFreeMem(
  832. // void *MemoryPtr
  833. // );
  834. //
  835. // Routine Description:
  836. //
  837. // Frees a block of memory allocated with CTEAllocMem.
  838. //
  839. // Arguments:
  840. //
  841. // MemoryPtr - A pointer to the memory to be freed.
  842. //
  843. // Return Value:
  844. //
  845. // None.
  846. //
  847. //--
  848. #define CTEFreeMem(MemoryPtr) ExFreePool((MemoryPtr));
  849. // Routine to Refill memory. Not used in NT environment.
  850. #define CTERefillMem()
  851. //
  852. //* Memory manipulation routines.
  853. //
  854. //++
  855. //
  856. // void
  857. // CTEMemCopy(
  858. // void *Source,
  859. // void *Destination,
  860. // unsigned long Length
  861. // );
  862. //
  863. // RoutineDescription:
  864. //
  865. // Copies data from one buffer to another.
  866. //
  867. // Arguments:
  868. //
  869. // Source - Source buffer.
  870. // Destination - Destination buffer,
  871. // Length - Number of bytes to copy.
  872. //
  873. // Return Value:
  874. //
  875. // None.
  876. //
  877. //--
  878. #define CTEMemCopy(Dst, Src, Len) RtlCopyMemory((Dst), (Src), (Len))
  879. //++
  880. //
  881. // void
  882. // CTEMemSet(
  883. // void *Destination,
  884. // unsigned char *Fill
  885. // unsigned long Length
  886. // );
  887. //
  888. // RoutineDescription:
  889. //
  890. // Sets the bytes of the destination buffer to a specific value.
  891. //
  892. // Arguments:
  893. //
  894. // Destination - Buffer to fill.
  895. // Fill - Value with which to fill buffer.
  896. // Length - Number of bytes of buffer to fill.
  897. //
  898. // Return Value:
  899. //
  900. // None.
  901. //
  902. //--
  903. #define CTEMemSet(Dst, Fill, Len) RtlFillMemory((Dst), (Len), (Fill))
  904. //++
  905. //
  906. // unsigned long
  907. // CTEMemCmp(
  908. // void *Source1,
  909. // void *Source2,
  910. // unsigned long Length
  911. // );
  912. //
  913. // RoutineDescription:
  914. //
  915. // Compares Length bytes of Source1 to Source2 for equality.
  916. //
  917. // Arguments:
  918. //
  919. // Source1 - First source buffer.
  920. // Source2 - Second source buffer,
  921. // Length - Number of bytes of Source1 to compare against Source2.
  922. //
  923. // Return Value:
  924. //
  925. // Zero if the data in the two buffers are equal for Length bytes.
  926. // NonZero otherwise.
  927. //
  928. //--
  929. #define CTEMemCmp(Src1, Src2, Len) \
  930. ((RtlCompareMemory((Src1), (Src2), (Len)) == (Len)) ? 0 : 1)
  931. //
  932. //* Blocking routines. These routines allow a limited blocking capability.
  933. //
  934. struct CTEBlockStruc {
  935. uint cbs_status;
  936. KEVENT cbs_event;
  937. }; /* CTEBlockStruc */
  938. typedef struct CTEBlockStruc CTEBlockStruc;
  939. struct CTEBlockTracker {
  940. LIST_ENTRY cbt_link;
  941. PKTHREAD cbt_thread;
  942. void* cbt_context;
  943. };
  944. typedef struct CTEBlockTracker CTEBlockTracker;
  945. //++
  946. //
  947. // VOID
  948. // CTEInitBlockStruc(
  949. // IN CTEBlockStruc *BlockEvent
  950. // );
  951. //
  952. // Routine Description:
  953. //
  954. // Initializes a CTE blocking structure
  955. //
  956. // Arguments:
  957. //
  958. // BlockEvent - Pointer to the variable to intialize.
  959. //
  960. // Return Value:
  961. //
  962. // None.
  963. //
  964. //--
  965. #define CTEInitBlockStruc(Event) \
  966. { \
  967. (Event)->cbs_status = NDIS_STATUS_SUCCESS; \
  968. KeInitializeEvent( \
  969. &((Event)->cbs_event), \
  970. SynchronizationEvent, \
  971. FALSE \
  972. ); \
  973. }
  974. //++
  975. //
  976. // VOID
  977. // CTEInitBlockStrucEx(
  978. // IN CTEBlockStruc *BlockEvent
  979. // );
  980. //
  981. // Routine Description:
  982. //
  983. // Initializes a CTE blocking structure
  984. //
  985. // Arguments:
  986. //
  987. // BlockEvent - Pointer to the variable to intialize.
  988. //
  989. // Return Value:
  990. //
  991. // None.
  992. //
  993. //--
  994. #define CTEInitBlockStrucEx(Event) \
  995. { \
  996. (Event)->cbs_status = NDIS_STATUS_SUCCESS; \
  997. KeInitializeEvent( \
  998. &((Event)->cbs_event), \
  999. NotificationEvent, \
  1000. FALSE \
  1001. ); \
  1002. }
  1003. //++
  1004. //
  1005. // uint
  1006. // CTEBlock(
  1007. // IN CTEBlockStruc *BlockEvent
  1008. // );
  1009. //
  1010. // uint
  1011. // CTEBlockWithTracker(
  1012. // IN CTEBlockStruc *BlockEvent,
  1013. // IN CTEBlockTracker *BlockTracker,
  1014. // IN void *Context
  1015. // );
  1016. //
  1017. // Routine Descriptions:
  1018. //
  1019. // Block the current thread of execution on the occurrence of an event.
  1020. // CTEBlockWithTracker also queues a record of the blocking request.
  1021. //
  1022. // Arguments:
  1023. //
  1024. // BlockEvent - Pointer to the event on which to block.
  1025. // BlockTracker - Pointer to space to be used for tracking the request.
  1026. // Context - Optional context to be stored with the tracking structure.
  1027. //
  1028. // Return Value:
  1029. //
  1030. // The status value provided by the signaller of the event.
  1031. //
  1032. //--
  1033. extern uint
  1034. CTEBlock(
  1035. IN CTEBlockStruc *BlockEvent
  1036. );
  1037. extern uint
  1038. CTEBlockWithTracker(
  1039. IN CTEBlockStruc *BlockEvent,
  1040. IN CTEBlockTracker *BlockTracker,
  1041. IN void *Context
  1042. );
  1043. //++
  1044. //
  1045. // extern void
  1046. // CTEInsertBlockTracker(
  1047. // IN CTEBlockTracker *BlockTracker,
  1048. // IN void *Context
  1049. // );
  1050. //
  1051. // extern void
  1052. // CTERemoveBlockTracker(
  1053. // IN CTEBlockTracker *BlockTracker
  1054. // );
  1055. //
  1056. // Routine Descriptions:
  1057. //
  1058. // Insert and remove records from the global list of blocking requests.
  1059. //
  1060. // Arguments:
  1061. //
  1062. // BlockTracker - Space to be used for tracking the blocking request.
  1063. // Context - Optional context to be stored with the tracking structure.
  1064. //
  1065. // Return Value:
  1066. //
  1067. // None.
  1068. //
  1069. //--
  1070. extern void
  1071. CTEInsertBlockTracker(
  1072. IN CTEBlockTracker *BlockTracker,
  1073. IN void *Context
  1074. );
  1075. extern void
  1076. CTERemoveBlockTracker(
  1077. IN CTEBlockTracker *BlockTracker
  1078. );
  1079. //++
  1080. //
  1081. // VOID
  1082. // CTESignal(
  1083. // IN CTEBlockStruc *BlockEvent,
  1084. // IN uint Status
  1085. // );
  1086. //
  1087. // Routine Description:
  1088. //
  1089. // Releases one thread of execution blocking on an event. Any other
  1090. // threads blocked on the event remain blocked.
  1091. //
  1092. // Arguments:
  1093. //
  1094. // BlockEvent - Pointer to the event to signal.
  1095. // Status - Status to return to the blocking thread.
  1096. //
  1097. // Return Value:
  1098. //
  1099. // None.
  1100. //
  1101. //--
  1102. extern void
  1103. CTESignal(
  1104. IN CTEBlockStruc *BlockEvent,
  1105. IN uint Status
  1106. );
  1107. //++
  1108. //
  1109. // VOID
  1110. // CTEClearSignal(
  1111. // IN CTEBlockStruc *BlockEvent
  1112. // );
  1113. //
  1114. // Routine Description:
  1115. //
  1116. // Returns the event structure to the unsignaled state.
  1117. //
  1118. // Arguments:
  1119. //
  1120. // BlockEvent - Pointer to the event to be cleared.
  1121. //
  1122. // Return Value:
  1123. //
  1124. // None.
  1125. //
  1126. //--
  1127. #define CTEClearSignal(Event) KeResetEvent(&((Event)->cbs_event))
  1128. //
  1129. // Event Logging routines.
  1130. //
  1131. // NOTE: These definitions are tentative and subject to change!!!!!!
  1132. //
  1133. #define CTE_MAX_EVENT_LOG_DATA_SIZE \
  1134. ( ( ERROR_LOG_MAXIMUM_SIZE - sizeof(IO_ERROR_LOG_PACKET) + \
  1135. sizeof(ULONG) \
  1136. ) & 0xFFFFFFFC \
  1137. )
  1138. //
  1139. //
  1140. // Routine Description:
  1141. //
  1142. // This function allocates an I/O error log record, fills it in and
  1143. // writes it to the I/O error log.
  1144. //
  1145. //
  1146. // Arguments:
  1147. //
  1148. // LoggerId - Pointer to the driver object logging this event.
  1149. //
  1150. // EventCode - Identifies the error message.
  1151. //
  1152. // UniqueEventValue - Identifies this instance of a given error message.
  1153. //
  1154. // NumStrings - Number of unicode strings in strings list.
  1155. //
  1156. // DataSize - Number of bytes of data.
  1157. //
  1158. // Strings - Array of pointers to unicode strings (PWCHAR').
  1159. //
  1160. // Data - Binary dump data for this message, each piece being
  1161. // aligned on word boundaries.
  1162. //
  1163. // Return Value:
  1164. //
  1165. // TDI_SUCCESS - The error was successfully logged.
  1166. // TDI_BUFFER_TOO_SMALL - The error data was too large to be logged.
  1167. // TDI_NO_RESOURCES - Unable to allocate memory.
  1168. //
  1169. // Notes:
  1170. //
  1171. // This code is paged and may not be called at raised IRQL.
  1172. //
  1173. LONG
  1174. CTELogEvent(
  1175. IN PVOID LoggerId,
  1176. IN ULONG EventCode,
  1177. IN ULONG UniqueEventValue,
  1178. IN USHORT NumStrings,
  1179. IN PVOID StringsList, OPTIONAL
  1180. IN ULONG DataSize,
  1181. IN PVOID Data OPTIONAL
  1182. );
  1183. //
  1184. // Debugging routines.
  1185. //
  1186. #if DBG
  1187. #ifndef DEBUG
  1188. #define DEBUG 1
  1189. #endif
  1190. #endif //DBG
  1191. #ifdef DEBUG
  1192. #define DEBUGCHK DbgBreakPoint()
  1193. #define DEBUGSTRING(v, s) uchar v[] = s
  1194. #define CTECheckMem(s)
  1195. #define CTEPrint(String) DbgPrint(String)
  1196. #define CTEPrintNum(Num) DbgPrint("%d", Num)
  1197. #define CTEPrintCRLF() DbgPrint("\n");
  1198. #define CTEStructAssert(s, t) if ((s)->t##_sig != t##_signature) {\
  1199. CTEPrint("Structure assertion failure for type " #t " in file " __FILE__ " line ");\
  1200. CTEPrintNum(__LINE__);\
  1201. CTEPrintCRLF();\
  1202. DEBUGCHK;\
  1203. }
  1204. #define CTEAssert(c) if (!(c)) {\
  1205. CTEPrint("Assertion failure in file " __FILE__ " line ");\
  1206. CTEPrintNum(__LINE__);\
  1207. CTEPrintCRLF();\
  1208. DEBUGCHK;\
  1209. }
  1210. #else // DEBUG
  1211. #define DEBUGCHK
  1212. #define DEBUGSTRING(v,s)
  1213. #define CTECheckMem(s)
  1214. #define CTEStructAssert(s,t )
  1215. #define CTEAssert(c)
  1216. #define CTEPrint(s)
  1217. #define CTEPrintNum(Num)
  1218. #define CTEPrintCRLF()
  1219. #endif // DEBUG
  1220. //* Request completion routine definition.
  1221. typedef void (*CTEReqCmpltRtn)(void *, unsigned int , unsigned int);
  1222. //* Defintion of CTEUnload
  1223. #define CTEUnload(Name)
  1224. //* Definition of a load/unload notification procedure handler.
  1225. typedef void (*CTENotifyRtn)(uchar *);
  1226. //* Defintion of set load and unload notification handlers.
  1227. #define CTESetLoadNotifyProc(Handler)
  1228. #define CTESetUnloadNotifyProc(Handler)
  1229. #else // NT
  1230. /////////////////////////////////////////////////////////////////////////////
  1231. //
  1232. // Definitions for additional environments go here
  1233. //
  1234. /////////////////////////////////////////////////////////////////////////////
  1235. #error Environment specific definitions missing
  1236. #endif // NT
  1237. /*INC*/
  1238. #pragma warning(pop)
  1239. #endif // _CXPORT_H_INCLUDED_