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.

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