ReactOS 0.4.16-dev-303-g11d5cb8
evtpair.c
Go to the documentation of this file.
1/*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Kernel
4 * FILE: ntoskrnl/ex/evtpair.c
5 * PURPOSE: Support for event pairs
6 * PROGRAMMERS: Alex Ionescu (alex@relsoft.net)
7 * Thomas Weidenmueller
8 */
9
10/* INCLUDES *****************************************************************/
11
12#include <ntoskrnl.h>
13#define NDEBUG
14#include <debug.h>
15
16/* GLOBALS *******************************************************************/
17
19
21{
26};
27
28/* FUNCTIONS *****************************************************************/
29
30CODE_SEG("INIT")
34{
35 OBJECT_TYPE_INITIALIZER ObjectTypeInitializer;
38 DPRINT("Creating Event Pair Object Type\n");
39
40 /* Create the Event Pair Object Type */
41 RtlZeroMemory(&ObjectTypeInitializer, sizeof(ObjectTypeInitializer));
42 RtlInitUnicodeString(&Name, L"EventPair");
43 ObjectTypeInitializer.Length = sizeof(ObjectTypeInitializer);
44 ObjectTypeInitializer.DefaultNonPagedPoolCharge = sizeof(KEVENT_PAIR);
45 ObjectTypeInitializer.GenericMapping = ExEventPairMapping;
46 ObjectTypeInitializer.PoolType = NonPagedPool;
47 ObjectTypeInitializer.ValidAccessMask = EVENT_PAIR_ALL_ACCESS;
48 ObjectTypeInitializer.UseDefaultObject = TRUE;
49 ObjectTypeInitializer.InvalidAttributes = OBJ_OPENLINK;
50 Status = ObCreateObjectType(&Name, &ObjectTypeInitializer, NULL, &ExEventPairObjectType);
51 if (!NT_SUCCESS(Status)) return FALSE;
52 return TRUE;
53}
54
60{
61 PKEVENT_PAIR EventPair;
62 HANDLE hEventPair;
65 PAGED_CODE();
66 DPRINT("NtCreateEventPair: 0x%p\n", EventPairHandle);
67
68 /* Check if we were called from user-mode */
70 {
71 /* Enter SEH Block */
73 {
74 /* Check handle pointer */
75 ProbeForWriteHandle(EventPairHandle);
76 }
78 {
79 /* Return the exception code */
81 }
83 }
84
85 /* Create the Object */
86 DPRINT("Creating EventPair\n");
91 NULL,
92 sizeof(KEVENT_PAIR),
93 0,
94 0,
95 (PVOID*)&EventPair);
96
97 /* Check for Success */
98 if (NT_SUCCESS(Status))
99 {
100 /* Initialize the Event */
101 DPRINT("Initializing EventPair\n");
102 KeInitializeEventPair(EventPair);
103
104 /* Insert it */
105 Status = ObInsertObject((PVOID)EventPair,
106 NULL,
108 0,
109 NULL,
110 &hEventPair);
111
112 /* Check for success */
113 if (NT_SUCCESS(Status))
114 {
115 /* Enter SEH */
117 {
118 /* Return the handle */
119 *EventPairHandle = hEventPair;
120 }
122 {
123 /* Get the exception code */
125 }
126 _SEH2_END;
127 }
128 }
129
130 /* Return Status */
131 return Status;
132}
133
135NTAPI
139{
140 HANDLE hEventPair;
143 PAGED_CODE();
144
145 /* Check if we were called from user-mode */
147 {
148 /* Enter SEH Block */
150 {
151 /* Check handle pointer */
152 ProbeForWriteHandle(EventPairHandle);
153 }
155 {
156 /* Return the exception code */
158 }
159 _SEH2_END;
160 }
161
162 /* Open the Object */
166 NULL,
168 NULL,
169 &hEventPair);
170
171 /* Check for success */
172 if (NT_SUCCESS(Status))
173 {
174 /* Enter SEH */
176 {
177 /* Return the handle */
178 *EventPairHandle = hEventPair;
179 }
181 {
182 /* Get the exception code */
184 }
185 _SEH2_END;
186 }
187
188 /* Return status */
189 return Status;
190}
191
193NTAPI
195{
196 PKEVENT_PAIR EventPair;
199 PAGED_CODE();
200 DPRINT("NtSetHighEventPair(EventPairHandle 0x%p)\n", EventPairHandle);
201
202 /* Open the Object */
203 Status = ObReferenceObjectByHandle(EventPairHandle,
207 (PVOID*)&EventPair,
208 NULL);
209
210 /* Check for Success */
211 if(NT_SUCCESS(Status))
212 {
213 /* Set the Event */
215
216 /* Dereference Object */
217 ObDereferenceObject(EventPair);
218 }
219
220 /* Return status */
221 return Status;
222}
223
225NTAPI
227{
228 PKEVENT_PAIR EventPair;
231 PAGED_CODE();
232 DPRINT("NtSetHighWaitLowEventPair(Handle 0x%p)\n", EventPairHandle);
233
234 /* Open the Object */
235 Status = ObReferenceObjectByHandle(EventPairHandle,
239 (PVOID*)&EventPair,
240 NULL);
241
242 /* Check for Success */
243 if(NT_SUCCESS(Status))
244 {
245 /* Set the Event */
247
248 /* Wait for the Other one */
252 FALSE,
253 NULL);
254
255 /* Dereference Object */
256 ObDereferenceObject(EventPair);
257 }
258
259 /* Return status */
260 return Status;
261}
262
264NTAPI
266{
267 PKEVENT_PAIR EventPair;
270 PAGED_CODE();
271 DPRINT1("NtSetHighEventPair(EventPairHandle 0x%p)\n", EventPairHandle);
272
273 /* Open the Object */
274 Status = ObReferenceObjectByHandle(EventPairHandle,
278 (PVOID*)&EventPair,
279 NULL);
280
281 /* Check for Success */
282 if(NT_SUCCESS(Status))
283 {
284 /* Set the Event */
286
287 /* Dereference Object */
288 ObDereferenceObject(EventPair);
289 }
290
291 /* Return status */
292 return Status;
293}
294
296NTAPI
298{
299 PKEVENT_PAIR EventPair;
302 PAGED_CODE();
303 DPRINT("NtSetHighWaitLowEventPair(Handle 0x%p)\n", EventPairHandle);
304
305 /* Open the Object */
306 Status = ObReferenceObjectByHandle(EventPairHandle,
310 (PVOID*)&EventPair,
311 NULL);
312
313 /* Check for Success */
314 if(NT_SUCCESS(Status))
315 {
316 /* Set the Event */
318
319 /* Wait for the Other one */
323 FALSE,
324 NULL);
325
326 /* Dereference Object */
327 ObDereferenceObject(EventPair);
328 }
329
330 /* Return status */
331 return Status;
332}
333
334
336NTAPI
338{
339 PKEVENT_PAIR EventPair;
342 PAGED_CODE();
343 DPRINT("NtSetHighWaitLowEventPair(Handle 0x%p)\n", EventPairHandle);
344
345 /* Open the Object */
346 Status = ObReferenceObjectByHandle(EventPairHandle,
350 (PVOID*)&EventPair,
351 NULL);
352
353 /* Check for Success */
354 if(NT_SUCCESS(Status))
355 {
356 /* Wait for the Event */
360 FALSE,
361 NULL);
362
363 /* Dereference Object */
364 ObDereferenceObject(EventPair);
365 }
366
367 /* Return status */
368 return Status;
369}
370
372NTAPI
374{
375 PKEVENT_PAIR EventPair;
378
379 PAGED_CODE();
380 DPRINT("NtSetHighWaitLowEventPair(Handle 0x%p)\n", EventPairHandle);
381
382 /* Open the Object */
383 Status = ObReferenceObjectByHandle(EventPairHandle,
387 (PVOID*)&EventPair,
388 NULL);
389
390 /* Check for Success */
391 if(NT_SUCCESS(Status))
392 {
393 /* Wait for the Event */
397 FALSE,
398 NULL);
399
400 /* Dereference Object */
401 ObDereferenceObject(EventPair);
402 }
403
404 /* Return status */
405 return Status;
406}
407
408/* EOF */
#define PAGED_CODE()
#define CODE_SEG(...)
unsigned char BOOLEAN
struct NameRec_ * Name
Definition: cdprocs.h:460
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define KeWaitForSingleObject(pEvt, foo, a, b, c)
Definition: env_spec_w32.h:478
#define KeSetEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:476
#define NonPagedPool
Definition: env_spec_w32.h:307
NTSTATUS NTAPI NtSetLowWaitHighEventPair(IN HANDLE EventPairHandle)
Definition: evtpair.c:297
POBJECT_TYPE ExEventPairObjectType
Definition: evtpair.c:18
NTSTATUS NTAPI NtWaitHighEventPair(IN HANDLE EventPairHandle)
Definition: evtpair.c:373
NTSTATUS NTAPI NtSetLowEventPair(IN HANDLE EventPairHandle)
Definition: evtpair.c:265
NTSTATUS NTAPI NtSetHighWaitLowEventPair(IN HANDLE EventPairHandle)
Definition: evtpair.c:226
NTSTATUS NTAPI NtOpenEventPair(OUT PHANDLE EventPairHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes)
Definition: evtpair.c:136
GENERIC_MAPPING ExEventPairMapping
Definition: evtpair.c:20
BOOLEAN NTAPI ExpInitializeEventPairImplementation(VOID)
Definition: evtpair.c:33
NTSTATUS NTAPI NtSetHighEventPair(IN HANDLE EventPairHandle)
Definition: evtpair.c:194
NTSTATUS NTAPI NtWaitLowEventPair(IN HANDLE EventPairHandle)
Definition: evtpair.c:337
NTSTATUS NTAPI NtCreateEventPair(OUT PHANDLE EventPairHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes)
Definition: evtpair.c:57
#define ExGetPreviousMode
Definition: ex.h:140
Status
Definition: gdiplustypes.h:25
LONG NTAPI ExSystemExceptionFilter(VOID)
Definition: harderr.c:349
#define OBJ_OPENLINK
Definition: winternl.h:230
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:90
#define KernelMode
Definition: asm.h:34
#define EVENT_PAIR_ALL_ACCESS
Definition: extypes.h:125
struct _KEVENT_PAIR KEVENT_PAIR
#define SYNCHRONIZE
Definition: nt_native.h:61
ULONG ACCESS_MASK
Definition: nt_native.h:40
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define STANDARD_RIGHTS_READ
Definition: nt_native.h:65
#define STANDARD_RIGHTS_WRITE
Definition: nt_native.h:66
#define STANDARD_RIGHTS_EXECUTE
Definition: nt_native.h:67
VOID NTAPI KeInitializeEventPair(PKEVENT_PAIR EventPair)
PVOID *typedef PHANDLE
Definition: ntsecpkg.h:455
#define L(x)
Definition: ntvdm.h:50
NTSTATUS NTAPI ObInsertObject(IN PVOID Object, IN PACCESS_STATE AccessState OPTIONAL, IN ACCESS_MASK DesiredAccess, IN ULONG ObjectPointerBias, OUT PVOID *NewObject OPTIONAL, OUT PHANDLE Handle)
Definition: obhandle.c:2935
NTSTATUS NTAPI ObOpenObjectByName(IN POBJECT_ATTRIBUTES ObjectAttributes, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, IN PACCESS_STATE PassedAccessState, IN ACCESS_MASK DesiredAccess, IN OUT PVOID ParseContext, OUT PHANDLE Handle)
Definition: obhandle.c:2532
NTSTATUS NTAPI ObCreateObject(IN KPROCESSOR_MODE ProbeMode OPTIONAL, IN POBJECT_TYPE Type, IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, IN KPROCESSOR_MODE AccessMode, IN OUT PVOID ParseContext OPTIONAL, IN ULONG ObjectSize, IN ULONG PagedPoolCharge OPTIONAL, IN ULONG NonPagedPoolCharge OPTIONAL, OUT PVOID *Object)
Definition: oblife.c:1039
NTSTATUS NTAPI ObCreateObjectType(IN PUNICODE_STRING TypeName, IN POBJECT_TYPE_INITIALIZER ObjectTypeInitializer, IN PVOID Reserved, OUT POBJECT_TYPE *ObjectType)
Definition: oblife.c:1136
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
Definition: obref.c:494
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:165
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:66
#define _SEH2_END
Definition: pseh2_64.h:155
#define _SEH2_TRY
Definition: pseh2_64.h:55
#define _SEH2_YIELD(__stmt)
Definition: pseh2_64.h:168
#define ProbeForWriteHandle(Ptr)
Definition: probe.h:43
#define DPRINT
Definition: sndvol32.h:73
KEVENT HighEvent
Definition: ketypes.h:979
KEVENT LowEvent
Definition: ketypes.h:978
GENERIC_MAPPING GenericMapping
Definition: obtypes.h:358
ULONG DefaultNonPagedPoolCharge
Definition: obtypes.h:365
#define NTAPI
Definition: typedefs.h:36
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define IN
Definition: typedefs.h:39
#define OUT
Definition: typedefs.h:40
_Must_inspect_result_ _In_ WDFDEVICE _In_ ULONG _In_ ACCESS_MASK DesiredAccess
Definition: wdfdevice.h:2658
#define EVENT_INCREMENT
Definition: iotypes.h:597
@ WrEventPair
Definition: ketypes.h:429
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
#define ObDereferenceObject
Definition: obfuncs.h:203
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103