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.

406 lines
8.6 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. EventSup.c
  5. Abstract:
  6. This module implements the Named Pipe Event support routines.
  7. Author:
  8. Gary Kimura [GaryKi] 30-Aug-1990
  9. Revision History:
  10. --*/
  11. #include "NpProcs.h"
  12. //
  13. // The debug trace level
  14. //
  15. #define Dbg (DEBUG_TRACE_EVENTSUP)
  16. //
  17. // The following variable is exported from the kernel and is needed by npfs to
  18. // determine if an event was handed down.
  19. //
  20. extern POBJECT_TYPE *ExEventObjectType;
  21. #ifdef ALLOC_PRAGMA
  22. #pragma alloc_text (PAGE, NpAddEventTableEntry)
  23. #pragma alloc_text (PAGE, NpDeleteEventTableEntry)
  24. #pragma alloc_text (PAGE, NpGetNextEventTableEntry)
  25. #pragma alloc_text (PAGE, NpEventTableCompareRoutine)
  26. #pragma alloc_text (PAGE, NpEventTableAllocate)
  27. #pragma alloc_text (PAGE, NpEventTableDeallocate)
  28. #endif
  29. NTSTATUS
  30. NpAddEventTableEntry (
  31. IN PEVENT_TABLE EventTable,
  32. IN PCCB Ccb,
  33. IN NAMED_PIPE_END NamedPipeEnd,
  34. IN HANDLE EventHandle,
  35. IN ULONG KeyValue,
  36. IN PEPROCESS Process,
  37. IN KPROCESSOR_MODE PreviousMode,
  38. OUT PEVENT_TABLE_ENTRY *ppEventTableEntry
  39. )
  40. /*++
  41. Routine Description:
  42. This routine adds a new entry into the event table. If an entry already
  43. exists it overwrites the existing entry.
  44. Arguments:
  45. EventTable - Supplies the event table being modified
  46. Ccb - Supplies a pointer to the ccb to store in event table entry
  47. NamedPipeEnd - Indicates the server or client end for the event
  48. EventHandle - Supplies the handle to the event being added. The object
  49. is referenced by this procedure
  50. KeyValue - Supplies a key value to associate with the event
  51. Process - Supplies a pointer to the process adding the event
  52. PreviousMode - Supplies the mode of the user initiating the action
  53. Return Value:
  54. PEVENT_TABLE_ENTRY - Returns a pointer to the newly added event.
  55. This is an actual pointer to the table entry.
  56. This procedure also will raise status if the event handle cannot be
  57. accessed by the caller
  58. --*/
  59. {
  60. NTSTATUS Status;
  61. KIRQL OldIrql;
  62. EVENT_TABLE_ENTRY Template;
  63. PEVENT_TABLE_ENTRY EventTableEntry;
  64. PVOID Event;
  65. DebugTrace(+1, Dbg, "NpAddEventTableEntry, EventTable = %08lx\n", EventTable);
  66. //
  67. // Reference the event object by handle.
  68. //
  69. if (!NT_SUCCESS(Status = ObReferenceObjectByHandle( EventHandle,
  70. EVENT_MODIFY_STATE,
  71. *ExEventObjectType,
  72. PreviousMode,
  73. &Event,
  74. NULL ))) {
  75. return Status;
  76. }
  77. //
  78. // Set up the template event entry to lookup
  79. //
  80. Template.Ccb = Ccb;
  81. Template.NamedPipeEnd = NamedPipeEnd;
  82. Template.EventHandle = EventHandle;
  83. Template.Event = Event;
  84. Template.KeyValue = KeyValue;
  85. Template.Process = Process;
  86. //
  87. // Now insert this new entry into the event table
  88. //
  89. EventTableEntry = RtlInsertElementGenericTable( &EventTable->Table,
  90. &Template,
  91. sizeof(EVENT_TABLE_ENTRY),
  92. NULL );
  93. if (EventTableEntry == NULL) {
  94. ObDereferenceObject (Event);
  95. return STATUS_INSUFFICIENT_RESOURCES;
  96. }
  97. //
  98. // Copy over the template again just in case we were given an
  99. // old entry
  100. //
  101. *EventTableEntry = Template;
  102. DebugTrace(-1, Dbg, "NpAddEventTableEntry -> %08lx\n", EventTableEntry);
  103. //
  104. // And now return to our caller
  105. //
  106. *ppEventTableEntry = EventTableEntry;
  107. return STATUS_SUCCESS;
  108. }
  109. VOID
  110. NpDeleteEventTableEntry (
  111. IN PEVENT_TABLE EventTable,
  112. IN PEVENT_TABLE_ENTRY Template
  113. )
  114. /*++
  115. Routine Description:
  116. This routine removes an entry from the event table, it also dereferences
  117. the event object that was referenced when the object was inserted
  118. Arguments:
  119. EventTable - Supplies a pointer to the event table being modified
  120. Template - Supplies a copy of the event table entry we are lookin up.
  121. Note that this can also be a pointer to the actual event table entry.
  122. Return Value:
  123. None.
  124. --*/
  125. {
  126. KIRQL OldIrql;
  127. DebugTrace(+1, Dbg, "NpDeleteEventTableEntry, EventTable = %08lx\n", EventTable);
  128. //
  129. // Only do the work if we are given a non null template
  130. //
  131. if (!ARGUMENT_PRESENT(Template)) {
  132. DebugTrace(-1, Dbg, "NpDeleteEventTableEntry -> VOID\n", 0);
  133. return;
  134. }
  135. //
  136. // Dereference the event object
  137. //
  138. ObDereferenceObject(Template->Event);
  139. //
  140. // Now remove this element from the generic table
  141. //
  142. (VOID)RtlDeleteElementGenericTable( &EventTable->Table,
  143. Template );
  144. DebugTrace(-1, Dbg, "NpDeleteEventTableEntry -> VOID\n", 0);
  145. //
  146. // And now return to our caller
  147. //
  148. return;
  149. }
  150. PEVENT_TABLE_ENTRY
  151. NpGetNextEventTableEntry (
  152. IN PEVENT_TABLE EventTable,
  153. IN PVOID *RestartKey
  154. )
  155. /*++
  156. Routine Description:
  157. This routine enumerates the events stored within an event table.
  158. Arguments:
  159. EventTable - Supplies a pointer to the event being enumerated
  160. Restart - Indicates if the enumeration should restart or continue
  161. Return Value:
  162. PEVENT_TABLE_ENTRY - Returns a pointer to the next event table entry
  163. in the table, or NULL if the enumeration is complete.
  164. --*/
  165. {
  166. KIRQL OldIrql;
  167. PEVENT_TABLE_ENTRY EventTableEntry;
  168. DebugTrace(+1, Dbg, "NpGetNextEventTableEntry, EventTable = %08lx\n", EventTable);
  169. //
  170. // Lookup the next element in the table
  171. //
  172. EventTableEntry = RtlEnumerateGenericTableWithoutSplaying( &EventTable->Table, RestartKey );
  173. DebugTrace(-1, Dbg, "NpGetNextEventTableEntry -> %08lx\n", EventTableEntry);
  174. //
  175. // And now return to our caller
  176. //
  177. return EventTableEntry;
  178. }
  179. //
  180. // Local support routines
  181. //
  182. RTL_GENERIC_COMPARE_RESULTS
  183. NpEventTableCompareRoutine (
  184. IN PRTL_GENERIC_TABLE EventTable,
  185. IN PVOID FirstStruct,
  186. IN PVOID SecondStruct
  187. )
  188. /*++
  189. Routine Description:
  190. This routine is the comparsion routine for the Event Table which is
  191. implemented as a generic table.
  192. Arguments:
  193. EventTable - Supplies a pointer to the event table which is involved
  194. in this action
  195. FirstStruct - Supplies a pointer to the first event table entry to examine
  196. SecondStruct - Supplies a pointer to the second event table entry to
  197. examine
  198. Return Value:
  199. RTL_GENERIC_COMPARE_RESULTS - GenericLessThan if FirstEntry is less than
  200. SecondEntry, GenericGreaterThan if FirstEntry is greater than
  201. SecondEntry, and GenericEqual otherwise.
  202. --*/
  203. {
  204. PEVENT_TABLE_ENTRY FirstEntry = FirstStruct;
  205. PEVENT_TABLE_ENTRY SecondEntry = SecondStruct;
  206. UNREFERENCED_PARAMETER( EventTable );
  207. //
  208. // We'll compare first the pointer to the ccb and then compare the
  209. // pipe end types. This will guarantee a unique ordering based on
  210. // the pipe instance and pipe end (i.e., server and client end).
  211. //
  212. if (FirstEntry->Ccb < SecondEntry->Ccb) {
  213. return GenericLessThan;
  214. } else if (FirstEntry->Ccb > SecondEntry->Ccb) {
  215. return GenericGreaterThan;
  216. } else if (FirstEntry->NamedPipeEnd < SecondEntry->NamedPipeEnd) {
  217. return GenericLessThan;
  218. } else if (FirstEntry->NamedPipeEnd > SecondEntry->NamedPipeEnd) {
  219. return GenericGreaterThan;
  220. } else {
  221. return GenericEqual;
  222. }
  223. }
  224. //
  225. // Local support routines
  226. //
  227. PVOID
  228. NpEventTableAllocate (
  229. IN PRTL_GENERIC_TABLE EventTable,
  230. IN CLONG ByteSize
  231. )
  232. /*++
  233. Routine Description:
  234. This routine is the generic allocation routine for the event table.
  235. Arguments:
  236. EventTable - Supplies a pointer to the event table being used
  237. ByteSize - Supplies the size, in bytes, to allocate.
  238. Return Value:
  239. PVOID - Returns a pointer to the newly allocated buffer.
  240. --*/
  241. {
  242. return NpAllocateNonPagedPoolWithQuota( ByteSize, 'gFpN' );
  243. }
  244. //
  245. // Local support routines
  246. //
  247. VOID
  248. NpEventTableDeallocate (
  249. IN PRTL_GENERIC_TABLE EventTable,
  250. IN PVOID Buffer
  251. )
  252. /*++
  253. Routine Description:
  254. This routine is the generic deallocation routine for the event table.
  255. Arguments:
  256. EventTable - Supplies a pointer to the event table being used
  257. Buffer - Supplies the buffer being deallocated
  258. Return Value:
  259. None.
  260. --*/
  261. {
  262. UNREFERENCED_PARAMETER( EventTable );
  263. NpFreePool( Buffer );
  264. return;
  265. }