Alex Ionescu <ionucu@videotron.ca>
 
	Dispatcher Objects Rewrite (minus Queues, coming in next patch).
	Global Changes:
 
		- Use KOBJECT enumerations for all objects, remove obsoleted ros-internal enumeration.
		- Reformatting, commenting, and addition of Debug Prints for easier debugging
		- Properly create Executive Objects. They don't need a creation routine.
		- Make sure to properly lock and release the Dispatcher Database.
 
	Mutex/Mutant:
 
		- Correct MUTANT_BASIC_INFORMATION
		- Return previous state in Kernel Functions, intead of 1 or 0 all the time.
		- Initialize listhead properly
		- Removed code duplication between mutant and mutex release.
		- Fix bugs in release
		- Add proper exeption if the mutex is not owned.
 
	Kernel Queues:
 
		- Optimize the code
		- Use Inserted Flag
 
	Timers:
 
		- Some changes in setting the default data to allow KiInsertTimer to be called internally 
		  by the wait code in the next patch.
 
	Events:
 
		- Optimize and simplify KeInitializeEvent
		- Implement KeInitializeEventPair
		- Fix KePulseEvent. It was completely messed up and also used unneeded Interlocked function.
		- Fix KeResetEvent. It was not locking the dispatcher lock but using Interlocked.
		- Fix KeSetEvent. It was not differentiating between Notification and Sycronization events 
		  and also signaling the Event even if nobody was waiting on it.
 
	Semaphores:
 
		- Fix KeReleaseSemaphore. It was not checking if nobody was waiting on it before unwaiting the thread.
		- Fix not releasing dispatcher database before raising an exception.
		- Add check to NtCreateSemaphore to make sure the counts make sense.
 
	Event Pairs:
 
		- Remove Thread Event Pair. They are only used for NT4 QuickLPC which is obsoleted.
		- Use KeInitializeEventPair
Modified: trunk/reactos/include/ddk/iotypes.h
Modified: trunk/reactos/include/ntos/zwtypes.h
Modified: trunk/reactos/ntoskrnl/ex/event.c
Modified: trunk/reactos/ntoskrnl/ex/evtpair.c
Modified: trunk/reactos/ntoskrnl/ex/mutant.c
Modified: trunk/reactos/ntoskrnl/ex/rundown.c
Modified: trunk/reactos/ntoskrnl/ex/sem.c
Modified: trunk/reactos/ntoskrnl/ex/timer.c
Deleted: trunk/reactos/ntoskrnl/include/internal/id.h
Modified: trunk/reactos/ntoskrnl/include/internal/ke.h
Modified: trunk/reactos/ntoskrnl/include/ntoskrnl.h
Modified: trunk/reactos/ntoskrnl/io/create.c
Modified: trunk/reactos/ntoskrnl/io/driver.c
Modified: trunk/reactos/ntoskrnl/io/wmi.c
Modified: trunk/reactos/ntoskrnl/ke/device.c
Modified: trunk/reactos/ntoskrnl/ke/event.c
Modified: trunk/reactos/ntoskrnl/ke/kqueue.c
Modified: trunk/reactos/ntoskrnl/ke/mutex.c
Modified: trunk/reactos/ntoskrnl/ke/queue.c
Modified: trunk/reactos/ntoskrnl/ke/sem.c
Modified: trunk/reactos/ntoskrnl/ke/timer.c
Modified: trunk/reactos/ntoskrnl/ke/wait.c
Modified: trunk/reactos/ntoskrnl/ps/process.c
Modified: trunk/reactos/tools/nci/sysfuncs.lst

Modified: trunk/reactos/include/ddk/iotypes.h
--- trunk/reactos/include/ddk/iotypes.h	2005-03-14 01:47:18 UTC (rev 14044)
+++ trunk/reactos/include/ddk/iotypes.h	2005-03-14 02:08:17 UTC (rev 14045)
@@ -886,6 +886,8 @@
 #endif
 
 #define IO_TYPE_DRIVER 4L
+#define IO_TYPE_FILE 0x0F5L
+
 #define DRVO_UNLOAD_INVOKED 0x1L
 #define DRVO_LEGACY_DRIVER  0x2L
 #define DRVO_BUILTIN_DRIVER 0x4L

Modified: trunk/reactos/include/ntos/zwtypes.h
--- trunk/reactos/include/ntos/zwtypes.h	2005-03-14 01:47:18 UTC (rev 14044)
+++ trunk/reactos/include/ntos/zwtypes.h	2005-03-14 02:08:17 UTC (rev 14045)
@@ -58,6 +58,7 @@
   ProfileTime
 } KPROFILE_SOURCE;
 
+
 // file disposition values
 
 #define FILE_SUPERSEDE                  0x0000
@@ -1271,9 +1272,9 @@
 
 typedef struct _MUTANT_BASIC_INFORMATION
 {
-  LONG Count;
-  BOOLEAN Owned;
-  BOOLEAN Abandoned;
+  LONG CurrentCount;
+  BOOLEAN OwnedByCaller;
+  BOOLEAN AbandonedState;
 } MUTANT_BASIC_INFORMATION, *PMUTANT_BASIC_INFORMATION;
 
 

Modified: trunk/reactos/ntoskrnl/ex/event.c
--- trunk/reactos/ntoskrnl/ex/event.c	2005-03-14 01:47:18 UTC (rev 14044)
+++ trunk/reactos/ntoskrnl/ex/event.c	2005-03-14 02:08:17 UTC (rev 14045)
@@ -1,11 +1,11 @@
-/* $Id:$
- * 
+/* 
  * COPYRIGHT:       See COPYING in the top level directory
  * PROJECT:         ReactOS kernel
  * FILE:            ntoskrnl/nt/event.c
  * PURPOSE:         Named event support
  * 
- * PROGRAMMERS:     Philip Susi and David Welch
+ * PROGRAMMERS:     Alex Ionescu(alex@relsoft.net) - Fixed bugs/commented
+ *                  Philip Susi and David Welch
  */
 
 /* INCLUDES *****************************************************************/
@@ -19,300 +19,287 @@
 POBJECT_TYPE EXPORTED ExEventObjectType = NULL;
 
 static 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};
+    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[] =
-{
-  ICI_SQ_SAME( sizeof(EVENT_BASIC_INFORMATION), sizeof(ULONG), ICIF_QUERY ), /* EventBasicInformation */
+static const INFORMATION_CLASS_INFO ExEventInfoClass[] = {
+    
+    /* EventBasicInformation */
+    ICI_SQ_SAME( sizeof(EVENT_BASIC_INFORMATION), sizeof(ULONG), ICIF_QUERY),
 };
 
 /* FUNCTIONS *****************************************************************/
 
-NTSTATUS STDCALL
-NtpCreateEvent(PVOID ObjectBody,
-	       PVOID Parent,
-	       PWSTR RemainingPath,
-	       POBJECT_ATTRIBUTES ObjectAttributes)
-{
-  DPRINT("NtpCreateEvent(ObjectBody %x, Parent %x, RemainingPath %S)\n",
-	 ObjectBody, Parent, RemainingPath);
-
-  if (RemainingPath != NULL && wcschr(RemainingPath+1, '\\') != NULL)
-    {
-      return(STATUS_UNSUCCESSFUL);
-    }
-
-  return(STATUS_SUCCESS);
-}
-
-
-VOID INIT_FUNCTION
+VOID 
+INIT_FUNCTION
 ExpInitializeEventImplementation(VOID)
 {
-   ExEventObjectType = ExAllocatePool(NonPagedPool,sizeof(OBJECT_TYPE));
-   
-   RtlpCreateUnicodeString(&ExEventObjectType->TypeName, L"Event", NonPagedPool);
-   
-   ExEventObjectType->Tag = TAG('E', 'V', 'T', 'T');
-   ExEventObjectType->PeakObjects = 0;
-   ExEventObjectType->PeakHandles = 0;
-   ExEventObjectType->TotalObjects = 0;
-   ExEventObjectType->TotalHandles = 0;
-   ExEventObjectType->PagedPoolCharge = 0;
-   ExEventObjectType->NonpagedPoolCharge = sizeof(KEVENT);
-   ExEventObjectType->Mapping = &ExpEventMapping;
-   ExEventObjectType->Dump = NULL;
-   ExEventObjectType->Open = NULL;
-   ExEventObjectType->Close = NULL;
-   ExEventObjectType->Delete = NULL;
-   ExEventObjectType->Parse = NULL;
-   ExEventObjectType->Security = NULL;
-   ExEventObjectType->QueryName = NULL;
-   ExEventObjectType->OkayToClose = NULL;
-   ExEventObjectType->Create = NtpCreateEvent;
-   ExEventObjectType->DuplicationNotify = NULL;
-
-   ObpCreateTypeObject(ExEventObjectType);
+    /* Create the Event Object Type */
+    ExEventObjectType = ExAllocatePool(NonPagedPool,sizeof(OBJECT_TYPE));
+    RtlInitUnicodeString(&ExEventObjectType->TypeName, L"Event");
+    ExEventObjectType->Tag = TAG('E', 'V', 'T', 'T');
+    ExEventObjectType->PeakObjects = 0;
+    ExEventObjectType->PeakHandles = 0;
+    ExEventObjectType->TotalObjects = 0;
+    ExEventObjectType->TotalHandles = 0;
+    ExEventObjectType->PagedPoolCharge = 0;
+    ExEventObjectType->NonpagedPoolCharge = sizeof(KEVENT);
+    ExEventObjectType->Mapping = &ExpEventMapping;
+    ExEventObjectType->Dump = NULL;
+    ExEventObjectType->Open = NULL;
+    ExEventObjectType->Close = NULL;
+    ExEventObjectType->Delete = NULL;
+    ExEventObjectType->Parse = NULL;
+    ExEventObjectType->Security = NULL;
+    ExEventObjectType->QueryName = NULL;
+    ExEventObjectType->OkayToClose = NULL;
+    ExEventObjectType->Create = NULL;
+    ExEventObjectType->DuplicationNotify = NULL;
+    ObpCreateTypeObject(ExEventObjectType);
 }
 
-
 /*
  * @implemented
  */
-NTSTATUS STDCALL
+NTSTATUS 
+STDCALL
 NtClearEvent(IN HANDLE EventHandle)
 {
-   PKEVENT Event;
-   NTSTATUS Status;
+    PKEVENT Event;
+    NTSTATUS Status;
+    
+    PAGED_CODE();
    
-   PAGED_CODE();
+    /* Reference the Object */
+    Status = ObReferenceObjectByHandle(EventHandle,
+                                       EVENT_MODIFY_STATE,
+                                       ExEventObjectType,
+                                       ExGetPreviousMode(),
+                                       (PVOID*)&Event,
+                                       NULL);
    
-   Status = ObReferenceObjectByHandle(EventHandle,
-				      EVENT_MODIFY_STATE,
-				      ExEventObjectType,
-				      ExGetPreviousMode(),
-				      (PVOID*)&Event,
-				      NULL);
-   if(NT_SUCCESS(Status))
-   {
-     KeClearEvent(Event);
-     ObDereferenceObject(Event);
-   }
+    /* Check for Success */
+    if(NT_SUCCESS(Status)) {
+        
+        /* Clear the Event and Dereference */
+        KeClearEvent(Event);
+        ObDereferenceObject(Event);
+    }
    
-   return Status;
+    /* Return Status */
+    return Status;
 }
 
 
 /*
  * @implemented
  */
-NTSTATUS STDCALL
+NTSTATUS 
+STDCALL
 NtCreateEvent(OUT PHANDLE EventHandle,
-	      IN ACCESS_MASK DesiredAccess,
-	      IN POBJECT_ATTRIBUTES ObjectAttributes  OPTIONAL,
-	      IN EVENT_TYPE EventType,
-	      IN BOOLEAN InitialState)
+              IN ACCESS_MASK DesiredAccess,
+              IN POBJECT_ATTRIBUTES ObjectAttributes  OPTIONAL,
+              IN EVENT_TYPE EventType,
+              IN BOOLEAN InitialState)
 {
-   KPROCESSOR_MODE PreviousMode;
-   PKEVENT Event;
-   HANDLE hEvent;
-   NTSTATUS Status = STATUS_SUCCESS;
+    KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
+    PKEVENT Event;
+    HANDLE hEvent;
+    NTSTATUS Status = STATUS_SUCCESS;
    
-   PAGED_CODE();
+    PAGED_CODE();
+    DPRINT("NtCreateEvent(0x%x, 0x%x, 0x%x)\n", EventHandle, DesiredAccess, ObjectAttributes);
  
-   PreviousMode = ExGetPreviousMode();
- 
-   if(PreviousMode == UserMode)
-   {
-     _SEH_TRY
-     {
-       ProbeForWrite(EventHandle,
-                     sizeof(HANDLE),
-                     sizeof(ULONG));
-     }
-     _SEH_HANDLE
-     {
-       Status = _SEH_GetExceptionCode();
-     }
-     _SEH_END;
+    /* Check Output Safety */
+    if(PreviousMode != KernelMode) {
+        
+        _SEH_TRY {
+            
+            ProbeForWrite(EventHandle,
+                          sizeof(HANDLE),
+                          sizeof(ULONG));
+        } _SEH_HANDLE {
+            
+            Status = _SEH_GetExceptionCode();
+        
+        } _SEH_END;
      
-     if(!NT_SUCCESS(Status))
-     {
-       return Status;
-     }
-   }
+        if(!NT_SUCCESS(Status)) return Status;
+    }
+    
+    /* Create the Object */
+    Status = ObCreateObject(PreviousMode,
+                            ExEventObjectType,
+                            ObjectAttributes,
+                            PreviousMode,
+                            NULL,
+                            sizeof(KEVENT),
+                            0,
+                            0,
+                            (PVOID*)&Event);
+    
+    /* Check for Success */
+    if(NT_SUCCESS(Status)) {
+        
+        /* Initalize the Event */
+        KeInitializeEvent(Event,
+                          EventType,
+                          InitialState);
+        
+        /* Insert it */
+        Status = ObInsertObject((PVOID)Event,
+                                 NULL,
+                                 DesiredAccess,
+                                 0,
+                                 NULL,
+                                 &hEvent);
+        ObDereferenceObject(Event);
  
-   Status = ObCreateObject(PreviousMode,
-                           ExEventObjectType,
-                           ObjectAttributes,
-                           PreviousMode,
-                           NULL,
-                           sizeof(KEVENT),
-                           0,
-                           0,
-                           (PVOID*)&Event);
-   if(NT_SUCCESS(Status))
-   {
-     KeInitializeEvent(Event,
-                       EventType,
-                       InitialState);
- 
- 
-     Status = ObInsertObject((PVOID)Event,
-                             NULL,
-                             DesiredAccess,
-                             0,
-                             NULL,
-                             &hEvent);
-     ObDereferenceObject(Event);
- 
-     if(NT_SUCCESS(Status))
-     {
-       _SEH_TRY
-       {
-         *EventHandle = hEvent;
-       }
-       _SEH_HANDLE
-       {
-         Status = _SEH_GetExceptionCode();
-       }
-       _SEH_END;
-     }
-   }
- 
-   return Status;
+        /* Check for success and return handle */
+        if(NT_SUCCESS(Status)) {
+            
+            _SEH_TRY {
+                
+                *EventHandle = hEvent;
+            
+            } _SEH_HANDLE {
+                
+                Status = _SEH_GetExceptionCode();
+                
+            } _SEH_END;
+        }
+    }
+
+    /* Return Status */
+    return Status;
 }
 
-
 /*
  * @implemented
  */
-NTSTATUS STDCALL
+NTSTATUS 
+STDCALL
 NtOpenEvent(OUT PHANDLE EventHandle,
-	    IN ACCESS_MASK DesiredAccess,
-	    IN POBJECT_ATTRIBUTES ObjectAttributes)
+            IN ACCESS_MASK DesiredAccess,
+            IN POBJECT_ATTRIBUTES ObjectAttributes)
 {
-   HANDLE hEvent;
-   KPROCESSOR_MODE PreviousMode;
-   NTSTATUS Status = STATUS_SUCCESS;
+    HANDLE hEvent;
+    KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
+    NTSTATUS Status = STATUS_SUCCESS;
    
-   PAGED_CODE();
-   
-   DPRINT("NtOpenEvent(0x%x, 0x%x, 0x%x)\n", EventHandle, DesiredAccess, ObjectAttributes);
+    PAGED_CODE();    
+    DPRINT("NtOpenEvent(0x%x, 0x%x, 0x%x)\n", EventHandle, DesiredAccess, ObjectAttributes);
 
-   PreviousMode = ExGetPreviousMode();
-   
-   if(PreviousMode == UserMode)
-   {
-     _SEH_TRY
-     {
-       ProbeForWrite(EventHandle,
-                     sizeof(HANDLE),
-                     sizeof(ULONG));
-     }
-     _SEH_HANDLE
-     {
-       Status = _SEH_GetExceptionCode();
-     }
-     _SEH_END;
+    /* Check Output Safety */
+    if(PreviousMode != KernelMode) {
+        
+        _SEH_TRY {
+            
+            ProbeForWrite(EventHandle,
+                          sizeof(HANDLE),
+                          sizeof(ULONG));
+        } _SEH_HANDLE {
+            
+            Status = _SEH_GetExceptionCode();
+        
+        } _SEH_END;
      
-     if(!NT_SUCCESS(Status))
-     {
-       return Status;
-     }
-   }
-
-   Status = ObOpenObjectByName(ObjectAttributes,
-			       ExEventObjectType,
-			       NULL,
-			       PreviousMode,
-			       DesiredAccess,
-			       NULL,
-			       &hEvent);
+        if(!NT_SUCCESS(Status)) return Status;
+    }
+    
+    /* Open the Object */
+    Status = ObOpenObjectByName(ObjectAttributes,
+                                ExEventObjectType,
+                                NULL,
+                                PreviousMode,
+                                DesiredAccess,
+                                NULL,
+                                &hEvent);
              
-   if(NT_SUCCESS(Status))
-   {
-     _SEH_TRY
-     {
-       *EventHandle = hEvent;
-     }
-     _SEH_HANDLE
-     {
-       Status = _SEH_GetExceptionCode();
-     }
-     _SEH_END;
-   }
+    /* Check for success and return handle */
+    if(NT_SUCCESS(Status)) {
+            
+        _SEH_TRY {
+            
+            *EventHandle = hEvent;
+                
+        } _SEH_HANDLE {
+            
+            Status = _SEH_GetExceptionCode();
+            
+        } _SEH_END;
+    }
    
-   return Status;
+    /* Return status */
+    return Status;
 }
 
-
 /*
  * @implemented
  */
-NTSTATUS STDCALL
+NTSTATUS 
+STDCALL
 NtPulseEvent(IN HANDLE EventHandle,
-	     OUT PLONG PreviousState  OPTIONAL)
+             OUT PLONG PreviousState OPTIONAL)
 {
-   PKEVENT Event;
-   KPROCESSOR_MODE PreviousMode;
-   NTSTATUS Status = STATUS_SUCCESS;
+    PKEVENT Event;
+    KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
+    NTSTATUS Status = STATUS_SUCCESS;
    
-   PAGED_CODE();
+    PAGED_CODE();
+    DPRINT("NtPulseEvent(EventHandle 0%x PreviousState 0%x)\n",
+            EventHandle, PreviousState);
 
-   DPRINT("NtPulseEvent(EventHandle 0%x PreviousState 0%x)\n",
-	  EventHandle, PreviousState);
+    /* Check buffer validity */
+    if(PreviousState && PreviousMode == UserMode) {
+        
+        _SEH_TRY {
+            
+            ProbeForWrite(PreviousState,
+                          sizeof(LONG),
+                          sizeof(ULONG));
+         } _SEH_HANDLE {
+             
+            Status = _SEH_GetExceptionCode();
+            
+        } _SEH_END;
 
-   PreviousMode = ExGetPreviousMode();
-   
-   if(PreviousState != NULL && PreviousMode == UserMode)
-   {
-     _SEH_TRY
-     {
-       ProbeForWrite(PreviousState,
-                     sizeof(LONG),
-                     sizeof(ULONG));
-     }
-     _SEH_HANDLE
-     {
-       Status = _SEH_GetExceptionCode();
-     }
-     _SEH_END;
+        if(!NT_SUCCESS(Status)) return Status;
+    }
+    
+    /* Open the Object */
+    Status = ObReferenceObjectByHandle(EventHandle,
+                                       EVENT_MODIFY_STATE,
+                                       ExEventObjectType,
+                                       PreviousMode,
+                                       (PVOID*)&Event,
+                                       NULL);
+    
+    /* Check for success */
+    if(NT_SUCCESS(Status)) {
+        
+        /* Pulse the Event */
+        LONG Prev = KePulseEvent(Event, EVENT_INCREMENT, FALSE);
+        ObDereferenceObject(Event);
      
-     if(!NT_SUCCESS(Status))
-     {
-       return Status;
-     }
+        /* Return it */        
+        if(PreviousState) {
+            
+            _SEH_TRY {
+                
+                *PreviousState = Prev;
+            
+            } _SEH_HANDLE {
+                
+                Status = _SEH_GetExceptionCode();
+            
+            } _SEH_END;
+        }
    }
 
-   Status = ObReferenceObjectByHandle(EventHandle,
-				      EVENT_MODIFY_STATE,
-				      ExEventObjectType,
-				      PreviousMode,
-				      (PVOID*)&Event,
-				      NULL);
-   if(NT_SUCCESS(Status))
-   {
-     LONG Prev = KePulseEvent(Event, EVENT_INCREMENT, FALSE);
-     ObDereferenceObject(Event);
-     
-     if(PreviousState != NULL)
-     {
-       _SEH_TRY
-       {
-         *PreviousState = Prev;
-       }
-       _SEH_HANDLE
-       {
-         Status = _SEH_GetExceptionCode();
-       }
-       _SEH_END;
-     }
-   }
-
+   /* Return Status */
    return Status;
 }
 
@@ -320,230 +307,203 @@
 /*
  * @implemented
  */
-NTSTATUS STDCALL
+NTSTATUS 
+STDCALL
 NtQueryEvent(IN HANDLE EventHandle,
-	     IN EVENT_INFORMATION_CLASS EventInformationClass,
-	     OUT PVOID EventInformation,
-	     IN ULONG EventInformationLength,
-	     OUT PULONG ReturnLength  OPTIONAL)
+             IN EVENT_INFORMATION_CLASS EventInformationClass,
+             OUT PVOID EventInformation,
+             IN ULONG EventInformationLength,
+             OUT PULONG ReturnLength  OPTIONAL)
 {
-   PKEVENT Event;
-   KPROCESSOR_MODE PreviousMode;
-   NTSTATUS Status = STATUS_SUCCESS;
+    PKEVENT Event;
+    KPROCESSOR_MODE PreviousMode  = ExGetPreviousMode();
+    NTSTATUS Status = STATUS_SUCCESS;
+    PEVENT_BASIC_INFORMATION BasicInfo = (PEVENT_BASIC_INFORMATION)EventInformation;
+    
+    PAGED_CODE();
+    DPRINT("NtQueryEvent(0x%x, 0x%x, 0x%x)\n", EventHandle, EventInformationClass);
+    
+    /* Check buffers and class validity */
+    DefaultQueryInfoBufferCheck(EventInformationClass,
+                                ExEventInfoClass,
+                                EventInformation,
+                                EventInformationLength,
+                                ReturnLength,
+                                PreviousMode,
+                                &Status);
+    if(!NT_SUCCESS(Status)) {
+        
+        /* Invalid buffers */
+        DPRINT("NtQuerySemaphore() failed, Status: 0x%x\n", Status);
+        return Status;
+    }
    
-   PAGED_CODE();
+    /* Get the Object */
+    Status = ObReferenceObjectByHandle(EventHandle,
+                                       EVENT_QUERY_STATE,
+                                       ExEventObjectType,
+                                       PreviousMode,
+                                       (PVOID*)&Event,
+                                       NULL);
+    
+    /* Check for success */
+    if(NT_SUCCESS(Status)) {
 
-   PreviousMode = ExGetPreviousMode();
-   
-   DefaultQueryInfoBufferCheck(EventInformationClass,
-                               ExEventInfoClass,
-                               EventInformation,
-                               EventInformationLength,
-                               ReturnLength,
-                               PreviousMode,
-                               &Status);
-   if(!NT_SUCCESS(Status))
-   {
-     DPRINT1("NtQueryEvent() failed, Status: 0x%x\n", Status);
-     return Status;
-   }
+        _SEH_TRY {
+            
+            /* Return Event Type and State */
+            BasicInfo->EventType = Event->Header.Type;
+            BasicInfo->EventState = KeReadStateEvent(Event);
 
-   Status = ObReferenceObjectByHandle(EventHandle,
-				      EVENT_QUERY_STATE,
-				      ExEventObjectType,
-				      PreviousMode,
-				      (PVOID*)&Event,
-				      NULL);
-   if(NT_SUCCESS(Status))
-   {
-     switch(EventInformationClass)
-     {
-       case EventBasicInformation:
-       {
-         PEVENT_BASIC_INFORMATION BasicInfo = (PEVENT_BASIC_INFORMATION)EventInformation;
-         
-         _SEH_TRY
-         {
-           if (Event->Header.Type == InternalNotificationEvent)
-             BasicInfo->EventType = NotificationEvent;
-           else
-             BasicInfo->EventType = SynchronizationEvent;
-           BasicInfo->EventState = KeReadStateEvent(Event);
-
-           if(ReturnLength != NULL)
-           {
-             *ReturnLength = sizeof(EVENT_BASIC_INFORMATION);
-           }
-         }
-         _SEH_HANDLE
-         {
-           Status = _SEH_GetExceptionCode();
-         }
-         _SEH_END;
-         break;
-       }
-
-       default:
-         Status = STATUS_NOT_IMPLEMENTED;
-         break;
-     }
-
-     ObDereferenceObject(Event);
+            /* Return length */
+            if(ReturnLength) *ReturnLength = sizeof(EVENT_BASIC_INFORMATION);
+            
+        } _SEH_HANDLE {
+            
+            Status = _SEH_GetExceptionCode();
+            
+        } _SEH_END;
+     
+        /* Dereference the Object */
+        ObDereferenceObject(Event);
    }
 
+   /* Return status */
    return Status;
 }
 
-
 /*
  * @implemented
  */
-NTSTATUS STDCALL
+NTSTATUS 
+STDCALL
 NtResetEvent(IN HANDLE EventHandle,
-	     OUT PLONG PreviousState  OPTIONAL)
+             OUT PLONG PreviousState OPTIONAL)
 {
-   PKEVENT Event;
-   KPROCESSOR_MODE PreviousMode;
-   NTSTATUS Status = STATUS_SUCCESS;
+    PKEVENT Event;
+    KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
+    NTSTATUS Status = STATUS_SUCCESS;
    
-   PAGED_CODE();
+    PAGED_CODE();
+    DPRINT("NtResetEvent(EventHandle 0%x PreviousState 0%x)\n",
+            EventHandle, PreviousState);
 
-   DPRINT("NtResetEvent(EventHandle 0%x PreviousState 0%x)\n",
-	  EventHandle, PreviousState);
+    /* Check buffer validity */
+    if(PreviousState && PreviousMode == UserMode) {
+        
+        _SEH_TRY {
+            
+            ProbeForWrite(PreviousState,
+                          sizeof(LONG),
+                          sizeof(ULONG));
+         } _SEH_HANDLE {
+             
+            Status = _SEH_GetExceptionCode();
+            
+        } _SEH_END;
 
-   PreviousMode = ExGetPreviousMode();
+        if(!NT_SUCCESS(Status)) return Status;
+    }
 
-   if(PreviousState != NULL && PreviousMode == UserMode)
-   {
-     _SEH_TRY
-     {
-       ProbeForWrite(PreviousState,
-                     sizeof(LONG),
-                     sizeof(ULONG));
-     }
-     _SEH_HANDLE
-     {
-       Status = _SEH_GetExceptionCode();
-     }
-     _SEH_END;
+    /* Open the Object */
+    Status = ObReferenceObjectByHandle(EventHandle,
+                                       EVENT_MODIFY_STATE,
+                                       ExEventObjectType,
+                                       PreviousMode,
+                                       (PVOID*)&Event,
+                                       NULL);
+    
+    /* Check for success */
+    if(NT_SUCCESS(Status)) {
+        
+        /* Reset the Event */
+        LONG Prev = KeResetEvent(Event);
+        ObDereferenceObject(Event);
      
-     if(!NT_SUCCESS(Status))
-     {
-       return Status;
-     }
+        /* Return it */        
+        if(PreviousState) {
+            
+            _SEH_TRY {
+                
+                *PreviousState = Prev;
+            
+            } _SEH_HANDLE {
+                
+                Status = _SEH_GetExceptionCode();
+            
+            } _SEH_END;
+        }
    }
 
-   Status = ObReferenceObjectByHandle(EventHandle,
-				      EVENT_MODIFY_STATE,
-				      ExEventObjectType,
-				      PreviousMode,
-				      (PVOID*)&Event,
-				      NULL);
-   if(NT_SUCCESS(Status))
-   {
-     LONG Prev = KeResetEvent(Event);
-     ObDereferenceObject(Event);
-     
-     if(PreviousState != NULL)
-     {
-       _SEH_TRY
-       {
-         *PreviousState = Prev;
-       }
-       _SEH_HANDLE
-       {
-         Status = _SEH_GetExceptionCode();
-       }
-       _SEH_END;
-     }
-   }
-
+   /* Return Status */
    return Status;
 }
 
-
 /*
  * @implemented
  */
-NTSTATUS STDCALL
+NTSTATUS 
+STDCALL
 NtSetEvent(IN HANDLE EventHandle,
-	   OUT PLONG PreviousState  OPTIONAL)
+           OUT PLONG PreviousState  OPTIONAL)
 {
-   PKEVENT Event;
-   KPROCESSOR_MODE PreviousMode;
-   NTSTATUS Status = STATUS_SUCCESS;
+    PKEVENT Event;
+    KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
+    NTSTATUS Status = STATUS_SUCCESS;
    
-   PAGED_CODE();
+    PAGED_CODE();
+    DPRINT("NtSetEvent(EventHandle 0%x PreviousState 0%x)\n",
+           EventHandle, PreviousState);
 
-   DPRINT("NtSetEvent(EventHandle 0%x PreviousState 0%x)\n",
-	  EventHandle, PreviousState);
+    /* Check buffer validity */
+    if(PreviousState != NULL && PreviousMode == UserMode) {
+        
+        _SEH_TRY {
+            
+            ProbeForWrite(PreviousState,
+                          sizeof(LONG),
+                          sizeof(ULONG));
+         } _SEH_HANDLE {
+             
+            Status = _SEH_GetExceptionCode();
+            
+        } _SEH_END;
 
-   PreviousMode = ExGetPreviousMode();
+        if(!NT_SUCCESS(Status)) return Status;
+    }
 
-   if(PreviousState != NULL && PreviousMode == UserMode)
-   {
-     _SEH_TRY
-     {
-       ProbeForWrite(PreviousState,
-                     sizeof(LONG),
-                     sizeof(ULONG));
-     }
-     _SEH_HANDLE
-     {
-       Status = _SEH_GetExceptionCode();
-     }
-     _SEH_END;
-     
-     if(!NT_SUCCESS(Status))
-     {
-       return Status;
-     }
-   }
+    /* Open the Object */
+    Status = ObReferenceObjectByHandle(EventHandle,
+                                       EVENT_MODIFY_STATE,
+                                       ExEventObjectType,
+                                       PreviousMode,
+                                       (PVOID*)&Event,
+                                       NULL);
+    
+    /* Check for success */
+    if(NT_SUCCESS(Status)) {
 
-   Status = ObReferenceObjectByHandle(EventHandle,
-				      EVENT_MODIFY_STATE,
-				      ExEventObjectType,
-				      PreviousMode,
-				      (PVOID*)&Event,
-				      NULL);
-   if(NT_SUCCESS(Status))
-   {
-     LONG Prev = KeSetEvent(Event, EVENT_INCREMENT, FALSE);
-     ObDereferenceObject(Event);
+        /* Set the Event */
+        LONG Prev = KeSetEvent(Event, EVENT_INCREMENT, FALSE);
+        ObDereferenceObject(Event);
 
-     if(PreviousState != NULL)
-     {
-       _SEH_TRY
-       {
-         *PreviousState = Prev;
-       }
-       _SEH_HANDLE
-       {
-         Status = _SEH_GetExceptionCode();
-       }
-       _SEH_END;
-     }
+        /* Return it */        
+        if(PreviousState) {
+            
+            _SEH_TRY {
+                
+                *PreviousState = Prev;
+            
+            } _SEH_HANDLE {
+                
+                Status = _SEH_GetExceptionCode();
+            
+            } _SEH_END;
+        }
    }
 
+   /* Return Status */
    return Status;
 }
 
-
-/*
- * @unimplemented
- */
-NTSTATUS
-STDCALL
-NtTraceEvent(
-	IN ULONG TraceHandle,
-	IN ULONG Flags,
-	IN ULONG TraceHeaderLength,
-	IN struct _EVENT_TRACE_HEADER* TraceHeader
-	)
-{
-	UNIMPLEMENTED;
-	return STATUS_NOT_IMPLEMENTED;
-}
-
-
 /* EOF */

Modified: trunk/reactos/ntoskrnl/ex/evtpair.c
--- trunk/reactos/ntoskrnl/ex/evtpair.c	2005-03-14 01:47:18 UTC (rev 14044)
+++ trunk/reactos/ntoskrnl/ex/evtpair.c	2005-03-14 02:08:17 UTC (rev 14045)
@@ -1,11 +1,12 @@
-/* $Id: evtpair.c 12779 2005-01-04 04:45:00Z gdalsnes $
- *
+/*
  * COPYRIGHT:       See COPYING in the top level directory
  * PROJECT:         ReactOS kernel
  * FILE:            ntoskrnl/ex/evtpair.c
  * PURPOSE:         Support for event pairs
  *
- * PROGRAMMERS:     David Welch (welch@mcmail.com)
+ * PROGRAMMERS:     Alex Ionescu (Commented, reorganized, removed Thread Pair, used
+ *                                KeInitializeEventPair, added SEH)
+ *                  David Welch (welch@mcmail.com)
  *                  Skywing (skywing@valhallalegends.com)
  */
 
@@ -15,588 +16,404 @@
 #define NDEBUG
 #include <internal/debug.h>
 
-#ifndef NTSYSAPI
-#define NTSYSAPI
[truncated at 1000 lines; 4192 more skipped]