- Fix some formatting.
[reactos.git] / reactos / ntoskrnl / ex / event.c
index e798ecd..6c0f9d0 100644 (file)
@@ -1,11 +1,10 @@
 /*
  * COPYRIGHT:       See COPYING in the top level directory
- * PROJECT:         ReactOS kernel
- * FILE:            ntoskrnl/nt/event.c
- * PURPOSE:         Named event support
- *
- * PROGRAMMERS:     Alex Ionescu(alex@relsoft.net) - Fixed bugs/commented
- *                  Philip Susi and David Welch
+ * PROJECT:         ReactOS Kernel
+ * FILE:            ntoskrnl/ex/event.c
+ * PURPOSE:         Event support
+ * PROGRAMMERS:     Alex Ionescu(alex@relsoft.net)
+ *                  Thomas Weidenmueller
  */
 
 /* INCLUDES *****************************************************************/
 
 POBJECT_TYPE ExEventObjectType = NULL;
 
-static GENERIC_MAPPING ExpEventMapping = {
+GENERIC_MAPPING ExpEventMapping =
+{
     STANDARD_RIGHTS_READ | SYNCHRONIZE | EVENT_QUERY_STATE,
     STANDARD_RIGHTS_WRITE | SYNCHRONIZE | EVENT_MODIFY_STATE,
     STANDARD_RIGHTS_EXECUTE | SYNCHRONIZE | EVENT_QUERY_STATE,
     EVENT_ALL_ACCESS};
 
-static const INFORMATION_CLASS_INFO ExEventInfoClass[] = {
-
+static const INFORMATION_CLASS_INFO ExEventInfoClass[] =
+{
     /* EventBasicInformation */
     ICI_SQ_SAME( sizeof(EVENT_BASIC_INFORMATION), sizeof(ULONG), ICIF_QUERY),
 };
@@ -38,35 +38,33 @@ static const INFORMATION_CLASS_INFO ExEventInfoClass[] = {
 
 VOID
 INIT_FUNCTION
-STDCALL
+NTAPI
 ExpInitializeEventImplementation(VOID)
 {
-  OBJECT_TYPE_INITIALIZER ObjectTypeInitializer;
-  UNICODE_STRING Name;
-
-  DPRINT("Creating Event Object Type\n");
-  
-  /* Create the Event Object Type */
-  RtlZeroMemory(&ObjectTypeInitializer, sizeof(ObjectTypeInitializer));
-  RtlInitUnicodeString(&Name, L"Event");
-  ObjectTypeInitializer.Length = sizeof(ObjectTypeInitializer);
-  ObjectTypeInitializer.DefaultNonPagedPoolCharge = sizeof(KEVENT);
-  ObjectTypeInitializer.GenericMapping = ExpEventMapping;
-  ObjectTypeInitializer.PoolType = NonPagedPool;
-  ObjectTypeInitializer.ValidAccessMask = EVENT_ALL_ACCESS;
-  ObpCreateTypeObject(&ObjectTypeInitializer, &Name, &ExEventObjectType);
+    OBJECT_TYPE_INITIALIZER ObjectTypeInitializer;
+    UNICODE_STRING Name;
+    DPRINT("Creating Event Object Type\n");
+
+    /* Create the Event Object Type */
+    RtlZeroMemory(&ObjectTypeInitializer, sizeof(ObjectTypeInitializer));
+    RtlInitUnicodeString(&Name, L"Event");
+    ObjectTypeInitializer.Length = sizeof(ObjectTypeInitializer);
+    ObjectTypeInitializer.DefaultNonPagedPoolCharge = sizeof(KEVENT);
+    ObjectTypeInitializer.GenericMapping = ExpEventMapping;
+    ObjectTypeInitializer.PoolType = NonPagedPool;
+    ObjectTypeInitializer.ValidAccessMask = EVENT_ALL_ACCESS;
+    ObpCreateTypeObject(&ObjectTypeInitializer, &Name, &ExEventObjectType);
 }
 
 /*
  * @implemented
  */
 NTSTATUS
-STDCALL
+NTAPI
 NtClearEvent(IN HANDLE EventHandle)
 {
     PKEVENT Event;
     NTSTATUS Status;
-
     PAGED_CODE();
 
     /* Reference the Object */
@@ -78,8 +76,8 @@ NtClearEvent(IN HANDLE EventHandle)
                                        NULL);
 
     /* Check for Success */
-    if(NT_SUCCESS(Status)) {
-
+    if(NT_SUCCESS(Status))
+    {
         /* Clear the Event and Dereference */
         KeClearEvent(Event);
         ObDereferenceObject(Event);
@@ -89,12 +87,11 @@ NtClearEvent(IN HANDLE EventHandle)
     return Status;
 }
 
-
 /*
  * @implemented
  */
 NTSTATUS
-STDCALL
+NTAPI
 NtCreateEvent(OUT PHANDLE EventHandle,
               IN ACCESS_MASK DesiredAccess,
               IN POBJECT_ATTRIBUTES ObjectAttributes  OPTIONAL,
@@ -105,22 +102,26 @@ NtCreateEvent(OUT PHANDLE EventHandle,
     PKEVENT Event;
     HANDLE hEvent;
     NTSTATUS Status = STATUS_SUCCESS;
-
     PAGED_CODE();
-    DPRINT("NtCreateEvent(0x%p, 0x%x, 0x%p)\n", EventHandle, DesiredAccess, ObjectAttributes);
-
-    /* Check Output Safety */
-    if(PreviousMode != KernelMode) {
-
-        _SEH_TRY {
-
+    DPRINT("NtCreateEvent(0x%p, 0x%x, 0x%p)\n",
+            EventHandle, DesiredAccess, ObjectAttributes);
+
+    /* Check if we were called from user-mode */
+    if(PreviousMode != KernelMode)
+    {
+        /* Enter SEH Block */
+        _SEH_TRY
+        {
+            /* Check handle pointer */
             ProbeForWriteHandle(EventHandle);
-        } _SEH_EXCEPT(_SEH_ExSystemExceptionFilter) {
-
+        }
+        _SEH_EXCEPT(_SEH_ExSystemExceptionFilter)
+        {
             Status = _SEH_GetExceptionCode();
+        }
+        _SEH_END;
 
-        } _SEH_END;
-
+        /* Bail out if pointer was invalid */
         if(!NT_SUCCESS(Status)) return Status;
     }
 
@@ -136,8 +137,8 @@ NtCreateEvent(OUT PHANDLE EventHandle,
                             (PVOID*)&Event);
 
     /* Check for Success */
-    if(NT_SUCCESS(Status)) {
-
+    if(NT_SUCCESS(Status))
+    {
         /* Initalize the Event */
         KeInitializeEvent(Event,
                           EventType,
@@ -153,17 +154,17 @@ NtCreateEvent(OUT PHANDLE EventHandle,
         ObDereferenceObject(Event);
 
         /* Check for success and return handle */
-        if(NT_SUCCESS(Status)) {
-
-            _SEH_TRY {
-
+        if(NT_SUCCESS(Status))
+        {
+            _SEH_TRY
+            {
                 *EventHandle = hEvent;
-
-            } _SEH_EXCEPT(_SEH_ExSystemExceptionFilter) {
-
+            }
+            _SEH_EXCEPT(_SEH_ExSystemExceptionFilter)
+            {
                 Status = _SEH_GetExceptionCode();
-
-            _SEH_END;
+            }
+            _SEH_END;
         }
     }
 
@@ -175,7 +176,7 @@ NtCreateEvent(OUT PHANDLE EventHandle,
  * @implemented
  */
 NTSTATUS
-STDCALL
+NTAPI
 NtOpenEvent(OUT PHANDLE EventHandle,
             IN ACCESS_MASK DesiredAccess,
             IN POBJECT_ATTRIBUTES ObjectAttributes)
@@ -183,22 +184,26 @@ NtOpenEvent(OUT PHANDLE EventHandle,
     HANDLE hEvent;
     KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
     NTSTATUS Status = STATUS_SUCCESS;
-
     PAGED_CODE();
-    DPRINT("NtOpenEvent(0x%p, 0x%x, 0x%p)\n", EventHandle, DesiredAccess, ObjectAttributes);
-
-    /* Check Output Safety */
-    if(PreviousMode != KernelMode) {
-
-        _SEH_TRY {
-
+    DPRINT("NtOpenEvent(0x%p, 0x%x, 0x%p)\n",
+            EventHandle, DesiredAccess, ObjectAttributes);
+
+    /* Check if we were called from user-mode */
+    if(PreviousMode != KernelMode)
+    {
+        /* Enter SEH Block */
+        _SEH_TRY
+        {
+            /* Check handle pointer */
             ProbeForWriteHandle(EventHandle);
-        } _SEH_EXCEPT(_SEH_ExSystemExceptionFilter) {
-
+        }
+        _SEH_EXCEPT(_SEH_ExSystemExceptionFilter)
+        {
             Status = _SEH_GetExceptionCode();
+        }
+        _SEH_END;
 
-        } _SEH_END;
-
+        /* Bail out if pointer was invalid */
         if(!NT_SUCCESS(Status)) return Status;
     }
 
@@ -211,18 +216,20 @@ NtOpenEvent(OUT PHANDLE EventHandle,
                                 NULL,
                                 &hEvent);
 
-    /* Check for success and return handle */
-    if(NT_SUCCESS(Status)) {
-
-        _SEH_TRY {
-
+    /* Check for success */
+    if(NT_SUCCESS(Status))
+    {
+        /* Enter SEH for return */
+        _SEH_TRY
+        {
+            /* Return the handle to the caller */
             *EventHandle = hEvent;
-
-        } _SEH_EXCEPT(_SEH_ExSystemExceptionFilter) {
-
+        }
+        _SEH_EXCEPT(_SEH_ExSystemExceptionFilter)
+        {
             Status = _SEH_GetExceptionCode();
-
-        _SEH_END;
+        }
+        _SEH_END;
     }
 
     /* Return status */
@@ -233,30 +240,33 @@ NtOpenEvent(OUT PHANDLE EventHandle,
  * @implemented
  */
 NTSTATUS
-STDCALL
+NTAPI
 NtPulseEvent(IN HANDLE EventHandle,
              OUT PLONG PreviousState OPTIONAL)
 {
     PKEVENT Event;
     KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
     NTSTATUS Status = STATUS_SUCCESS;
-
     PAGED_CODE();
     DPRINT("NtPulseEvent(EventHandle 0%x PreviousState 0%x)\n",
             EventHandle, PreviousState);
 
-    /* Check buffer validity */
-    if(PreviousState && PreviousMode != KernelMode) {
-
-        _SEH_TRY {
-
+    /* Check if we were called from user-mode */
+    if((PreviousState) && (PreviousMode != KernelMode))
+    {
+        /* Entry SEH Block */
+        _SEH_TRY
+        {
+            /* Make sure the state pointer is valid */
             ProbeForWriteLong(PreviousState);
-         } _SEH_EXCEPT(_SEH_ExSystemExceptionFilter) {
-
+        }
+        _SEH_EXCEPT(_SEH_ExSystemExceptionFilter)
+        {
             Status = _SEH_GetExceptionCode();
+        }
+        _SEH_END;
 
-        } _SEH_END;
-
+        /* Bail out if pointer was invalid */
         if(!NT_SUCCESS(Status)) return Status;
     }
 
@@ -269,24 +279,26 @@ NtPulseEvent(IN HANDLE EventHandle,
                                        NULL);
 
     /* Check for success */
-    if(NT_SUCCESS(Status)) {
-
+    if(NT_SUCCESS(Status))
+    {
         /* Pulse the Event */
         LONG Prev = KePulseEvent(Event, EVENT_INCREMENT, FALSE);
         ObDereferenceObject(Event);
 
-        /* Return it */
-        if(PreviousState) {
-
-            _SEH_TRY {
-
+        /* Check if caller wants the old state back */
+        if(PreviousState)
+        {
+            /* Entry SEH Block for return */
+            _SEH_TRY
+            {
+                /* Return previous state */
                 *PreviousState = Prev;
-
-            } _SEH_EXCEPT(_SEH_ExSystemExceptionFilter) {
-
+            }
+            _SEH_EXCEPT(_SEH_ExSystemExceptionFilter)
+            {
                 Status = _SEH_GetExceptionCode();
-
-            _SEH_END;
+            }
+            _SEH_END;
         }
    }
 
@@ -294,12 +306,11 @@ NtPulseEvent(IN HANDLE EventHandle,
    return Status;
 }
 
-
 /*
  * @implemented
  */
 NTSTATUS
-STDCALL
+NTAPI
 NtQueryEvent(IN HANDLE EventHandle,
              IN EVENT_INFORMATION_CLASS EventInformationClass,
              OUT PVOID EventInformation,
@@ -310,7 +321,6 @@ NtQueryEvent(IN HANDLE EventHandle,
     KPROCESSOR_MODE PreviousMode  = ExGetPreviousMode();
     NTSTATUS Status = STATUS_SUCCESS;
     PEVENT_BASIC_INFORMATION BasicInfo = (PEVENT_BASIC_INFORMATION)EventInformation;
-
     PAGED_CODE();
     DPRINT("NtQueryEvent(0x%p, 0x%x)\n", EventHandle, EventInformationClass);
 
@@ -322,8 +332,8 @@ NtQueryEvent(IN HANDLE EventHandle,
                                          EventInformationLength,
                                          ReturnLength,
                                          PreviousMode);
-    if(!NT_SUCCESS(Status)) {
-
+    if(!NT_SUCCESS(Status))
+    {
         /* Invalid buffers */
         DPRINT("NtQuerySemaphore() failed, Status: 0x%x\n", Status);
         return Status;
@@ -338,22 +348,23 @@ NtQueryEvent(IN HANDLE EventHandle,
                                        NULL);
 
     /* Check for success */
-    if(NT_SUCCESS(Status)) {
-
-        _SEH_TRY {
-
+    if(NT_SUCCESS(Status))
+    {
+        /* Entry SEH Block */
+        _SEH_TRY
+        {
             /* Return Event Type and State */
             BasicInfo->EventType = Event->Header.Type;
             BasicInfo->EventState = KeReadStateEvent(Event);
 
             /* Return length */
             if(ReturnLength) *ReturnLength = sizeof(EVENT_BASIC_INFORMATION);
-
-        } _SEH_EXCEPT(_SEH_ExSystemExceptionFilter) {
-
+        }
+        _SEH_EXCEPT(_SEH_ExSystemExceptionFilter)
+        {
             Status = _SEH_GetExceptionCode();
-
-        _SEH_END;
+        }
+        _SEH_END;
 
         /* Dereference the Object */
         ObDereferenceObject(Event);
@@ -367,30 +378,33 @@ NtQueryEvent(IN HANDLE EventHandle,
  * @implemented
  */
 NTSTATUS
-STDCALL
+NTAPI
 NtResetEvent(IN HANDLE EventHandle,
              OUT PLONG PreviousState OPTIONAL)
 {
     PKEVENT Event;
     KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
     NTSTATUS Status = STATUS_SUCCESS;
-
     PAGED_CODE();
     DPRINT("NtResetEvent(EventHandle 0%x PreviousState 0%x)\n",
             EventHandle, PreviousState);
 
-    /* Check buffer validity */
-    if(PreviousState && PreviousMode != KernelMode) {
-
-        _SEH_TRY {
-
+    /* Check if we were called from user-mode */
+    if((PreviousState) && (PreviousMode != KernelMode))
+    {
+        /* Entry SEH Block */
+        _SEH_TRY
+        {
+            /* Make sure the state pointer is valid */
             ProbeForWriteLong(PreviousState);
-         } _SEH_EXCEPT(_SEH_ExSystemExceptionFilter) {
-
+        }
+        _SEH_EXCEPT(_SEH_ExSystemExceptionFilter)
+        {
             Status = _SEH_GetExceptionCode();
+        }
+        _SEH_END;
 
-        } _SEH_END;
-
+        /* Bail out if pointer was invalid */
         if(!NT_SUCCESS(Status)) return Status;
     }
 
@@ -403,24 +417,26 @@ NtResetEvent(IN HANDLE EventHandle,
                                        NULL);
 
     /* Check for success */
-    if(NT_SUCCESS(Status)) {
-
+    if(NT_SUCCESS(Status))
+    {
         /* Reset the Event */
         LONG Prev = KeResetEvent(Event);
         ObDereferenceObject(Event);
 
-        /* Return it */
-        if(PreviousState) {
-
-            _SEH_TRY {
-
+        /* Check if caller wants the old state back */
+        if(PreviousState)
+        {
+            /* Entry SEH Block for return */
+            _SEH_TRY
+            {
+                /* Return previous state */
                 *PreviousState = Prev;
-
-            } _SEH_EXCEPT(_SEH_ExSystemExceptionFilter) {
-
+            }
+            _SEH_EXCEPT(_SEH_ExSystemExceptionFilter)
+            {
                 Status = _SEH_GetExceptionCode();
-
-            _SEH_END;
+            }
+            _SEH_END;
         }
    }
 
@@ -432,30 +448,33 @@ NtResetEvent(IN HANDLE EventHandle,
  * @implemented
  */
 NTSTATUS
-STDCALL
+NTAPI
 NtSetEvent(IN HANDLE EventHandle,
            OUT PLONG PreviousState  OPTIONAL)
 {
     PKEVENT Event;
     KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
     NTSTATUS Status = STATUS_SUCCESS;
-
     PAGED_CODE();
     DPRINT("NtSetEvent(EventHandle 0%x PreviousState 0%x)\n",
            EventHandle, PreviousState);
 
-    /* Check buffer validity */
-    if(PreviousState != NULL && PreviousMode != KernelMode) {
-
-        _SEH_TRY {
-
+    /* Check if we were called from user-mode */
+    if((PreviousState) && (PreviousMode != KernelMode))
+    {
+        /* Entry SEH Block */
+        _SEH_TRY
+        {
+            /* Make sure the state pointer is valid */
             ProbeForWriteLong(PreviousState);
-         } _SEH_EXCEPT(_SEH_ExSystemExceptionFilter) {
-
+        }
+        _SEH_EXCEPT(_SEH_ExSystemExceptionFilter)
+        {
             Status = _SEH_GetExceptionCode();
+        }
+        _SEH_END;
 
-        } _SEH_END;
-
+        /* Bail out if pointer was invalid */
         if(!NT_SUCCESS(Status)) return Status;
     }
 
@@ -468,24 +487,26 @@ NtSetEvent(IN HANDLE EventHandle,
                                        NULL);
 
     /* Check for success */
-    if(NT_SUCCESS(Status)) {
-
+    if(NT_SUCCESS(Status))
+    {
         /* Set the Event */
         LONG Prev = KeSetEvent(Event, EVENT_INCREMENT, FALSE);
         ObDereferenceObject(Event);
 
-        /* Return it */
-        if(PreviousState) {
-
-            _SEH_TRY {
-
+        /* Check if caller wants the old state back */
+        if(PreviousState)
+        {
+            /* Entry SEH Block for return */
+            _SEH_TRY
+            {
+                /* Return previous state */
                 *PreviousState = Prev;
-
-            } _SEH_EXCEPT(_SEH_ExSystemExceptionFilter) {
-
+            }
+            _SEH_EXCEPT(_SEH_ExSystemExceptionFilter)
+            {
                 Status = _SEH_GetExceptionCode();
-
-            _SEH_END;
+            }
+            _SEH_END;
         }
    }