Add SEH to more functions, clean up some things, initialize profiling stuff (not yet enabled), and fix Registry Object re/defrecenging bug (Jim -- please retest). Thanks to Thomas for Security fixes and Iocompletion SEH + CM fix.
Modified: branches/alex_devel_branch/reactos/include/ddk/setypes.h
Modified: branches/alex_devel_branch/reactos/include/ntos/security.h
Modified: branches/alex_devel_branch/reactos/ntoskrnl/cm/regobj.c
Modified: branches/alex_devel_branch/reactos/ntoskrnl/ex/event.c
Modified: branches/alex_devel_branch/reactos/ntoskrnl/ex/evtpair.c
Modified: branches/alex_devel_branch/reactos/ntoskrnl/ex/init.c
Modified: branches/alex_devel_branch/reactos/ntoskrnl/ex/mutant.c
Modified: branches/alex_devel_branch/reactos/ntoskrnl/ex/profile.c
Modified: branches/alex_devel_branch/reactos/ntoskrnl/ex/sem.c
Modified: branches/alex_devel_branch/reactos/ntoskrnl/ex/timer.c
Modified: branches/alex_devel_branch/reactos/ntoskrnl/include/internal/ob.h
Modified: branches/alex_devel_branch/reactos/ntoskrnl/include/internal/se.h
Modified: branches/alex_devel_branch/reactos/ntoskrnl/io/iocomp.c
Modified: branches/alex_devel_branch/reactos/ntoskrnl/kd/kdebug.c
Modified: branches/alex_devel_branch/reactos/ntoskrnl/ke/profile.c
Modified: branches/alex_devel_branch/reactos/ntoskrnl/ob/object.c
Modified: branches/alex_devel_branch/reactos/ntoskrnl/ps/thread.c
Modified: branches/alex_devel_branch/reactos/ntoskrnl/se/acl.c
Modified: branches/alex_devel_branch/reactos/ntoskrnl/se/luid.c
Modified: branches/alex_devel_branch/reactos/ntoskrnl/se/sd.c
Modified: branches/alex_devel_branch/reactos/ntoskrnl/se/sid.c
Modified: branches/alex_devel_branch/reactos/ntoskrnl/se/token.c
Modified: branches/alex_devel_branch/reactos/w32api/include/ddk/ntifs.h
Modified: branches/alex_devel_branch/reactos/w32api/include/winnt.h

Modified: branches/alex_devel_branch/reactos/include/ddk/setypes.h
--- branches/alex_devel_branch/reactos/include/ddk/setypes.h	2005-03-04 19:07:02 UTC (rev 13820)
+++ branches/alex_devel_branch/reactos/include/ddk/setypes.h	2005-03-04 20:56:32 UTC (rev 13821)
@@ -98,37 +98,36 @@
 } SEP_AUDIT_POLICY, *PSEP_AUDIT_POLICY;
  
 typedef struct _TOKEN {
-  TOKEN_SOURCE		TokenSource;               /* 0x00 */
-  LUID				TokenId;                   /* 0x10 */
-  LUID				AuthenticationId;          /* 0x18 */
-  LUID              ParentTokenId;             /* 0x20 */
-  LARGE_INTEGER		ExpirationTime;            /* 0x28 */
-  struct _ERESOURCE *TokenLock;                /* 0x30 */
-  ULONG             Padding;                   /* 0x34 */
-  SEP_AUDIT_POLICY  AuditPolicy;               /* 0x38 */
-  LUID				ModifiedId;                /* 0x40 */
-  ULONG             SessionId;                 /* 0x48 */
-  ULONG				UserAndGroupCount;         /* 0x4C */
-  ULONG             RestrictedSidCount;        /* 0x50 */
-  ULONG				PrivilegeCount;            /* 0x54 */
-  ULONG				VariableLength;            /* 0x58 */
-  ULONG				DynamicCharged;            /* 0x5C */
-  ULONG				DynamicAvailable;          /* 0x60 */
-  ULONG				DefaultOwnerIndex;         /* 0x64 */
-  PSID_AND_ATTRIBUTES UserAndGroups;           /* 0x68 */
-  PSID_AND_ATTRIBUTES RestrictedSids;          /* 0x6C */
-  PSID				PrimaryGroup;              /* 0x70 */
-  PLUID_AND_ATTRIBUTES Privileges;             /* 0x74 */
-  PULONG            DynamicPart;               /* 0x78 */
-  PACL				DefaultDacl;               /* 0x7C */
-  TOKEN_TYPE		TokenType;                 /* 0x80 */
-  SECURITY_IMPERSONATION_LEVEL	ImpersonationLevel;  /* 0x84 */
-  ULONG				TokenFlags;                /* 0x88 */
-  ULONG			    TokenInUse;                /* 0x8C */
-  PVOID				ProxyData;                 /* 0x90 */
-  PVOID				AuditData;                 /* 0x94 */
-  LUID              OriginatingLogonSession;   /* 0x98 */
-  UCHAR				VariablePart[1];           /* 0xA0 */
+  TOKEN_SOURCE TokenSource;                         /* 0x00 */
+  LUID TokenId;                                     /* 0x10 */
+  LUID AuthenticationId;                            /* 0x18 */
+  LUID ParentTokenId;                               /* 0x20 */
+  LARGE_INTEGER ExpirationTime;                     /* 0x28 */
+  struct _ERESOURCE *TokenLock;                     /* 0x30 */
+  SEP_AUDIT_POLICY  AuditPolicy;                    /* 0x38 */
+  LUID ModifiedId;                                  /* 0x40 */
+  ULONG SessionId;                                  /* 0x48 */
+  ULONG UserAndGroupCount;                          /* 0x4C */
+  ULONG RestrictedSidCount;                         /* 0x50 */
+  ULONG PrivilegeCount;                             /* 0x54 */
+  ULONG VariableLength;                             /* 0x58 */
+  ULONG DynamicCharged;                             /* 0x5C */
+  ULONG DynamicAvailable;                           /* 0x60 */
+  ULONG DefaultOwnerIndex;                          /* 0x64 */
+  PSID_AND_ATTRIBUTES UserAndGroups;                /* 0x68 */
+  PSID_AND_ATTRIBUTES RestrictedSids;               /* 0x6C */
+  PSID PrimaryGroup;                                /* 0x70 */
+  PLUID_AND_ATTRIBUTES Privileges;                  /* 0x74 */
+  PULONG DynamicPart;                               /* 0x78 */
+  PACL DefaultDacl;                                 /* 0x7C */
+  TOKEN_TYPE TokenType;                             /* 0x80 */
+  SECURITY_IMPERSONATION_LEVEL ImpersonationLevel;  /* 0x84 */
+  ULONG TokenFlags;                                 /* 0x88 */
+  BOOLEAN TokenInUse;                               /* 0x8C */
+  PVOID ProxyData;                                  /* 0x90 */
+  PVOID AuditData;                                  /* 0x94 */
+  LUID OriginatingLogonSession;                     /* 0x98 */
+  ULONG VariablePart;                               /* 0xA0 */
 } TOKEN, *PTOKEN;
 
 typedef PVOID PACCESS_TOKEN;

Modified: branches/alex_devel_branch/reactos/include/ntos/security.h
--- branches/alex_devel_branch/reactos/include/ntos/security.h	2005-03-04 19:07:02 UTC (rev 13820)
+++ branches/alex_devel_branch/reactos/include/ntos/security.h	2005-03-04 20:56:32 UTC (rev 13821)
@@ -153,8 +153,9 @@
 #define TOKEN_ADJUST_PRIVILEGES		(0x0020L)
 #define TOKEN_ADJUST_GROUPS		(0x0040L)
 #define TOKEN_ADJUST_DEFAULT		(0x0080L)
+#define TOKEN_ADJUST_SESSIONID		(0x0100L)
 
-#define TOKEN_ALL_ACCESS		(0xf00ffL)
+#define TOKEN_ALL_ACCESS		(0xf01ffL)
 #define TOKEN_READ			(0x20008L)
 #define TOKEN_WRITE			(0x200e0L)
 #define TOKEN_EXECUTE			(0x20000L)
@@ -339,6 +340,20 @@
   SID_AND_ATTRIBUTES Groups[ANYSIZE_ARRAY];
 } TOKEN_GROUPS, *PTOKEN_GROUPS, *LPTOKEN_GROUPS;
 
+typedef struct _TOKEN_GROUPS_AND_PRIVILEGES
+{
+  ULONG SidCount;
+  ULONG SidLength;
+  PSID_AND_ATTRIBUTES Sids;
+  ULONG RestrictedSidCount;
+  ULONG RestrictedSidLength;
+  PSID_AND_ATTRIBUTES RestrictedSids;
+  ULONG PrivilegeCount;
+  ULONG PrivilegeLength;
+  PLUID_AND_ATTRIBUTES Privileges;
+  LUID AuthenticationId;
+} TOKEN_GROUPS_AND_PRIVILEGES, *PTOKEN_GROUPS_AND_PRIVILEGES;
+
 typedef struct _TOKEN_PRIVILEGES
 {
   DWORD PrivilegeCount;

Modified: branches/alex_devel_branch/reactos/ntoskrnl/cm/regobj.c
--- branches/alex_devel_branch/reactos/ntoskrnl/cm/regobj.c	2005-03-04 19:07:02 UTC (rev 13820)
+++ branches/alex_devel_branch/reactos/ntoskrnl/cm/regobj.c	2005-03-04 20:56:32 UTC (rev 13821)
@@ -212,11 +212,6 @@
 	      return(STATUS_REPARSE);
 	    }
 	}
-
-      ObReferenceObjectByPointer(FoundObject,
-				 STANDARD_RIGHTS_REQUIRED,
-				 NULL,
-				 UserMode);
     }
 
   DPRINT("CmiObjectParse: %s\n", FoundObject->Name);

Modified: branches/alex_devel_branch/reactos/ntoskrnl/ex/event.c
--- branches/alex_devel_branch/reactos/ntoskrnl/ex/event.c	2005-03-04 19:07:02 UTC (rev 13820)
+++ branches/alex_devel_branch/reactos/ntoskrnl/ex/event.c	2005-03-04 20:56:32 UTC (rev 13821)
@@ -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 *****************************************************************/
@@ -38,7 +38,7 @@
 {
     /* Create the Event Object Type */
     ExEventObjectType = ExAllocatePool(NonPagedPool,sizeof(OBJECT_TYPE));
-    RtlpCreateUnicodeString(&ExEventObjectType->TypeName, L"Event", NonPagedPool);
+    RtlInitUnicodeString(&ExEventObjectType->TypeName, L"Event");
     ExEventObjectType->Tag = TAG('E', 'V', 'T', 'T');
     ExEventObjectType->PeakObjects = 0;
     ExEventObjectType->PeakHandles = 0;
@@ -73,14 +73,14 @@
     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);
    
-   /* Check for Success */
+    /* Check for Success */
     if(NT_SUCCESS(Status)) {
         
         /* Clear the Event and Dereference */
@@ -110,9 +110,10 @@
     NTSTATUS Status = STATUS_SUCCESS;
    
     PAGED_CODE();
+    DPRINT("NtCreateEvent(0x%x, 0x%x, 0x%x)\n", EventHandle, DesiredAccess, ObjectAttributes);
  
     /* Check Output Safety */
-    if(PreviousMode == UserMode) {
+    if(PreviousMode != KernelMode) {
         
         _SEH_TRY {
             
@@ -188,11 +189,11 @@
     KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
     NTSTATUS Status = STATUS_SUCCESS;
    
-    PAGED_CODE();
+    PAGED_CODE();    
     DPRINT("NtOpenEvent(0x%x, 0x%x, 0x%x)\n", EventHandle, DesiredAccess, ObjectAttributes);
 
     /* Check Output Safety */
-    if(PreviousMode == UserMode) {
+    if(PreviousMode != KernelMode) {
         
         _SEH_TRY {
             
@@ -315,10 +316,13 @@
              OUT PULONG ReturnLength  OPTIONAL)
 {
     PKEVENT Event;
-    KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
+    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,
@@ -381,7 +385,6 @@
     NTSTATUS Status = STATUS_SUCCESS;
    
     PAGED_CODE();
-
     DPRINT("NtResetEvent(EventHandle 0%x PreviousState 0%x)\n",
             EventHandle, PreviousState);
 
@@ -449,10 +452,9 @@
     NTSTATUS Status = STATUS_SUCCESS;
    
     PAGED_CODE();
+    DPRINT("NtSetEvent(EventHandle 0%x PreviousState 0%x)\n",
+           EventHandle, PreviousState);
 
-    DPRINT1("NtSetEvent(EventHandle 0%x PreviousState 0%x)\n",
-            EventHandle, PreviousState);
-
     /* Check buffer validity */
     if(PreviousState != NULL && PreviousMode == UserMode) {
         

Modified: branches/alex_devel_branch/reactos/ntoskrnl/ex/evtpair.c
--- branches/alex_devel_branch/reactos/ntoskrnl/ex/evtpair.c	2005-03-04 19:07:02 UTC (rev 13820)
+++ branches/alex_devel_branch/reactos/ntoskrnl/ex/evtpair.c	2005-03-04 20:56:32 UTC (rev 13821)
@@ -4,7 +4,8 @@
  * FILE:            ntoskrnl/ex/evtpair.c
  * PURPOSE:         Support for event pairs
  *
- * PROGRAMMERS:     Alex Ionescu (Commented, reorganized, removed Thread Pair, used KeInitializeEventPair, added SEH)
+ * PROGRAMMERS:     Alex Ionescu (Commented, reorganized, removed Thread Pair, used
+ *                                KeInitializeEventPair, added SEH)
  *                  David Welch (welch@mcmail.com)
  *                  Skywing (skywing@valhallalegends.com)
  */
@@ -34,7 +35,7 @@
 {
     /* Create the Event Pair Object Type */
     ExEventPairObjectType = ExAllocatePool(NonPagedPool,sizeof(OBJECT_TYPE));
-    RtlpCreateUnicodeString(&ExEventPairObjectType->TypeName, L"EventPair", NonPagedPool);
+    RtlInitUnicodeString(&ExEventPairObjectType->TypeName, L"EventPair");
     ExEventPairObjectType->Tag = TAG('E', 'v', 'P', 'a');
     ExEventPairObjectType->PeakObjects = 0;
     ExEventPairObjectType->PeakHandles = 0;
@@ -67,7 +68,8 @@
     KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
     NTSTATUS Status = STATUS_SUCCESS;
     
-    DPRINT1("NtCreateEventPair: %x\n", EventPairHandle);
+    PAGED_CODE();
+    DPRINT("NtCreateEventPair: %x\n", EventPairHandle);
    
     /* Check Output Safety */
     if(PreviousMode == UserMode) {
@@ -87,7 +89,7 @@
     }
     
     /* Create the Object */
-    DPRINT1("Creating EventPair\n");
+    DPRINT("Creating EventPair\n");
     Status = ObCreateObject(PreviousMode,
                             ExEventPairObjectType,
                             ObjectAttributes,
@@ -102,7 +104,7 @@
     if(NT_SUCCESS(Status)) {
         
         /* Initalize the Event */
-        DPRINT1("Initializing EventPair\n");
+        DPRINT("Initializing EventPair\n");
         KeInitializeEventPair(EventPair);
         
         /* Insert it */
@@ -133,7 +135,6 @@
     return Status;
 }
 
-
 NTSTATUS 
 STDCALL
 NtOpenEventPair(OUT PHANDLE EventPairHandle,
@@ -143,6 +144,8 @@
     HANDLE hEventPair;
     KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
     NTSTATUS Status = STATUS_SUCCESS;
+    
+    PAGED_CODE();
    
     /* Check Output Safety */
     if(PreviousMode == UserMode) {
@@ -196,8 +199,9 @@
     PKEVENT_PAIR EventPair;
     KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
     NTSTATUS Status;
-
-    DPRINT1("NtSetHighEventPair(EventPairHandle %x)\n", EventPairHandle);
+    
+    PAGED_CODE();
+    DPRINT("NtSetHighEventPair(EventPairHandle %x)\n", EventPairHandle);
    
     /* Open the Object */
     Status = ObReferenceObjectByHandle(EventPairHandle,
@@ -221,7 +225,6 @@
     return Status;
 }
 
-
 NTSTATUS
 STDCALL
 NtSetHighWaitLowEventPair(IN HANDLE EventPairHandle)
@@ -229,9 +232,10 @@
     PKEVENT_PAIR EventPair;
     KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
     NTSTATUS Status;
-
-    DPRINT1("NtSetHighWaitLowEventPair(EventPairHandle %x)\n", EventPairHandle);
     
+    PAGED_CODE();
+    DPRINT("NtSetHighWaitLowEventPair(EventPairHandle %x)\n", EventPairHandle);
+    
     /* Open the Object */
     Status = ObReferenceObjectByHandle(EventPairHandle,
                                        SYNCHRONIZE,
@@ -266,8 +270,12 @@
 NtSetLowEventPair(IN HANDLE EventPairHandle)
 {
     PKEVENT_PAIR EventPair;
-    KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
+    KPROCESSOR_MODE PreviousMode;
     NTSTATUS Status;
+    
+    PAGED_CODE();
+    
+    PreviousMode = ExGetPreviousMode();
 
     DPRINT1("NtSetHighEventPair(EventPairHandle %x)\n", EventPairHandle);
    
@@ -300,9 +308,10 @@
     PKEVENT_PAIR EventPair;
     KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
     NTSTATUS Status;
-
-    DPRINT1("NtSetHighWaitLowEventPair(EventPairHandle %x)\n", EventPairHandle);
     
+    PAGED_CODE();
+    DPRINT("NtSetHighWaitLowEventPair(EventPairHandle %x)\n", EventPairHandle);
+    
     /* Open the Object */
     Status = ObReferenceObjectByHandle(EventPairHandle,
                                        SYNCHRONIZE,
@@ -340,9 +349,10 @@
     PKEVENT_PAIR EventPair;
     KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
     NTSTATUS Status;
-
-    DPRINT1("NtSetHighWaitLowEventPair(EventPairHandle %x)\n", EventPairHandle);
     
+    PAGED_CODE();
+    DPRINT("NtSetHighWaitLowEventPair(EventPairHandle %x)\n", EventPairHandle);
+    
     /* Open the Object */
     Status = ObReferenceObjectByHandle(EventPairHandle,
                                        SYNCHRONIZE,
@@ -376,9 +386,10 @@
     PKEVENT_PAIR EventPair;
     KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
     NTSTATUS Status;
-
-    DPRINT1("NtSetHighWaitLowEventPair(EventPairHandle %x)\n", EventPairHandle);
     
+    PAGED_CODE();
+    DPRINT("NtSetHighWaitLowEventPair(EventPairHandle %x)\n", EventPairHandle);
+    
     /* Open the Object */
     Status = ObReferenceObjectByHandle(EventPairHandle,
                                        SYNCHRONIZE,
@@ -386,7 +397,7 @@
                                        PreviousMode,
                                        (PVOID*)&EventPair,
                                        NULL);
-    
+
     /* Check for Success */
     if(NT_SUCCESS(Status)) {
                

Modified: branches/alex_devel_branch/reactos/ntoskrnl/ex/init.c
--- branches/alex_devel_branch/reactos/ntoskrnl/ex/init.c	2005-03-04 19:07:02 UTC (rev 13820)
+++ branches/alex_devel_branch/reactos/ntoskrnl/ex/init.c	2005-03-04 20:56:32 UTC (rev 13821)
@@ -27,6 +27,9 @@
 extern ULONG_PTR LastKernelAddress;
 extern LOADER_MODULE KeLoaderModules[64];
 extern PRTL_MESSAGE_RESOURCE_DATA KiBugCodeMessages;
+extern LIST_ENTRY KiProfileListHead;
+extern LIST_ENTRY KiProfileSourceListHead;
+extern KSPIN_LOCK KiProfileLock;
 
 /* FUNCTIONS ****************************************************************/
 
@@ -408,13 +411,18 @@
     
     /* Initialize the kernel debugger */
     KdInitSystem (1, (PLOADER_PARAMETER_BLOCK)&KeLoaderBlock);
-
+    
     /* Initialize the Dispatcher, Clock and Bug Check Mechanisms. */
     KeInit2();
 
     /* Bring back the IRQL to Passive */
     KeLowerIrql(PASSIVE_LEVEL);
     
+    /* Initialize Profiling */
+    InitializeListHead(&KiProfileListHead);
+    InitializeListHead(&KiProfileSourceListHead);
+    KeInitializeSpinLock(&KiProfileLock);
+    
     /* Cache the Bugcheck Message Strings. Prepare the Lookup Data */
     ResourceInfo.Type = 11;
     ResourceInfo.Name = 1;

Modified: branches/alex_devel_branch/reactos/ntoskrnl/ex/mutant.c
--- branches/alex_devel_branch/reactos/ntoskrnl/ex/mutant.c	2005-03-04 19:07:02 UTC (rev 13820)
+++ branches/alex_devel_branch/reactos/ntoskrnl/ex/mutant.c	2005-03-04 20:56:32 UTC (rev 13821)
@@ -4,8 +4,7 @@
  * FILE:            ntoskrnl/ex/mutant.c
  * PURPOSE:         Executive Management of Mutants
  * 
- * PROGRAMMERS:     
- *                  Alex Ionescu - Fix tab/space mismatching, tiny fixes to query function and
+ * PROGRAMMERS:     Alex Ionescu - Fix tab/space mismatching, tiny fixes to query function and
  *                                 add more debug output.
  *                  David Welch (welch@cwcom.net)
  */
@@ -55,7 +54,7 @@
     ExMutantObjectType = ExAllocatePoolWithTag(NonPagedPool, sizeof(OBJECT_TYPE), TAG('M', 't', 'n', 't'));
 
     /* Create the Object Type */
-    RtlpCreateUnicodeString(&ExMutantObjectType->TypeName, L"Mutant", NonPagedPool);
+    RtlInitUnicodeString(&ExMutantObjectType->TypeName, L"Mutant");
     ExMutantObjectType->Tag = TAG('M', 't', 'n', 't');
     ExMutantObjectType->PeakObjects = 0;
     ExMutantObjectType->PeakHandles = 0;
@@ -92,6 +91,7 @@
     PKMUTANT Mutant;
     NTSTATUS Status = STATUS_SUCCESS;
     
+    PAGED_CODE();
     DPRINT("NtCreateMutant(0x%x, 0x%x, 0x%x)\n", MutantHandle, DesiredAccess, ObjectAttributes);
   
     /* Check Output Safety */
@@ -157,7 +157,6 @@
     return Status;
 }
 
-
 /*
  * @implemented
  */
@@ -171,8 +170,7 @@
     KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
     NTSTATUS Status = STATUS_SUCCESS;
   
-   PAGED_CODE();
-
+    PAGED_CODE();
     DPRINT("NtOpenMutant(0x%x, 0x%x, 0x%x)\n", MutantHandle, DesiredAccess, ObjectAttributes);
 
     /* Check Output Safety */
@@ -235,6 +233,8 @@
     NTSTATUS Status = STATUS_SUCCESS;
     PMUTANT_BASIC_INFORMATION BasicInfo = (PMUTANT_BASIC_INFORMATION)MutantInformation;
     
+    PAGED_CODE();
+    
     /* Check buffers and parameters */
     DefaultQueryInfoBufferCheck(MutantInformationClass,
                                 ExMutantInfoClass,
@@ -245,11 +245,9 @@
                                 &Status);
     if(!NT_SUCCESS(Status)) {
         
-        DPRINT1("NtQueryMutant() failed, Status: 0x%x\n", Status);
+        DPRINT("NtQueryMutant() failed, Status: 0x%x\n", Status);
         return Status;
     }
-   
-   PAGED_CODE();
 
     /* Open the Object */
     Status = ObReferenceObjectByHandle(MutantHandle,
@@ -264,7 +262,7 @@
          _SEH_TRY {
              
             /* Fill out the Basic Information Requested */
-            DPRINT1("Returning Mutant Information\n");
+            DPRINT("Returning Mutant Information\n");
             BasicInfo->CurrentCount = KeReadStateMutant(Mutant);
             BasicInfo->OwnedByCaller = (Mutant->OwnerThread == KeGetCurrentThread());
             BasicInfo->AbandonedState = Mutant->Abandoned;
@@ -300,7 +298,6 @@
     NTSTATUS Status = STATUS_SUCCESS;
    
     PAGED_CODE();
-
     DPRINT("NtReleaseMutant(MutantHandle 0%x PreviousCount 0%x)\n", 
             MutantHandle, 
             PreviousCount);
@@ -333,9 +330,11 @@
     /* Check for Success and release if such */
     if(NT_SUCCESS(Status)) {
         
+        LONG Prev;
+        
         /* Save the Old State */
-        DPRINT1("Releasing Mutant\n");
-        LONG Prev = KeReleaseMutant(Mutant, MUTANT_INCREMENT, FALSE, FALSE);
+        DPRINT("Releasing Mutant\n");
+        Prev = KeReleaseMutant(Mutant, MUTANT_INCREMENT, FALSE, FALSE);
         ObDereferenceObject(Mutant);
 
         /* Return it */        

Modified: branches/alex_devel_branch/reactos/ntoskrnl/ex/profile.c
--- branches/alex_devel_branch/reactos/ntoskrnl/ex/profile.c	2005-03-04 19:07:02 UTC (rev 13820)
+++ branches/alex_devel_branch/reactos/ntoskrnl/ex/profile.c	2005-03-04 20:56:32 UTC (rev 13821)
@@ -80,7 +80,7 @@
     
     /* Create the Object Type */
     ExProfileObjectType = ExAllocatePool(NonPagedPool,sizeof(OBJECT_TYPE));
-    RtlpCreateUnicodeString(&ExProfileObjectType->TypeName, L"Profile", NonPagedPool);  
+    RtlInitUnicodeString(&ExProfileObjectType->TypeName, L"Profile");
     ExProfileObjectType->Tag = TAG('P', 'R', 'O', 'F');
     ExProfileObjectType->PeakObjects = 0;
     ExProfileObjectType->PeakHandles = 0;
@@ -121,7 +121,7 @@
     NTSTATUS Status = STATUS_SUCCESS;
   
     PAGED_CODE();
-  
+
     /* Easy way out */
     if(BufferSize == 0) return STATUS_INVALID_PARAMETER_7;
 
@@ -234,9 +234,9 @@
                           OUT PLARGE_INTEGER PerformanceFrequency OPTIONAL)
 {
     KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
+    LARGE_INTEGER PerfFrequency;
     NTSTATUS Status = STATUS_SUCCESS;
-    LARGE_INTEGER PerfFrequency;
-  
+    
     /* Check the Parameters for validity */
     if(PreviousMode != KernelMode) {
         
@@ -287,7 +287,7 @@
     NTSTATUS Status;
   
     PAGED_CODE();
-  
+
     /* Get the Object */
     Status = ObReferenceObjectByHandle(ProfileHandle,
                                        PROFILE_CONTROL,
@@ -405,9 +405,9 @@
 NtQueryIntervalProfile(IN  KPROFILE_SOURCE ProfileSource,
                        OUT PULONG Interval)
 {
-    KPROCESSOR_MODE PreviousMode= ExGetPreviousMode();
+    KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
+    ULONG ReturnInterval;
     NTSTATUS Status = STATUS_SUCCESS;
-    ULONG ReturnInterval;
   
     PAGED_CODE();
     

Modified: branches/alex_devel_branch/reactos/ntoskrnl/ex/sem.c
--- branches/alex_devel_branch/reactos/ntoskrnl/ex/sem.c	2005-03-04 19:07:02 UTC (rev 13820)
+++ branches/alex_devel_branch/reactos/ntoskrnl/ex/sem.c	2005-03-04 20:56:32 UTC (rev 13821)
@@ -37,7 +37,7 @@
     
     /* Create the Semaphore Object */
     ExSemaphoreObjectType = ExAllocatePool(NonPagedPool, sizeof(OBJECT_TYPE));
-    RtlpCreateUnicodeString(&ExSemaphoreObjectType->TypeName, L"Semaphore", NonPagedPool);
+    RtlInitUnicodeString(&ExSemaphoreObjectType->TypeName, L"Semaphore");
     ExSemaphoreObjectType->Tag = TAG('S', 'E', 'M', 'T');
     ExSemaphoreObjectType->PeakObjects = 0;
     ExSemaphoreObjectType->PeakHandles = 0;
@@ -78,7 +78,7 @@
     PAGED_CODE();
 
     /* Check Output Safety */
-    if(PreviousMode == UserMode) {
+    if(PreviousMode != KernelMode) {
         
         _SEH_TRY {
             
@@ -148,7 +148,6 @@
     return Status;
 }
 
-
 /*
  * @implemented
  */
@@ -221,11 +220,10 @@
 {
     PKSEMAPHORE Semaphore;
     KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
-    PSEMAPHORE_BASIC_INFORMATION BasicInfo = (PSEMAPHORE_BASIC_INFORMATION)SemaphoreInformation;
     NTSTATUS Status = STATUS_SUCCESS;
 
     PAGED_CODE();
-               
+
     /* Check buffers and class validity */
     DefaultQueryInfoBufferCheck(SemaphoreInformationClass,
                                 ExSemaphoreInfoClass,
@@ -254,7 +252,9 @@
    
         _SEH_TRY {
             
-             /* Return the basic information */             
+            PSEMAPHORE_BASIC_INFORMATION BasicInfo = (PSEMAPHORE_BASIC_INFORMATION)SemaphoreInformation;
+            
+            /* Return the basic information */
             BasicInfo->CurrentCount = KeReadStateSemaphore(Semaphore);
             BasicInfo->MaximumCount = Semaphore->Limit;
 
@@ -284,12 +284,12 @@
                    IN LONG ReleaseCount,
                    OUT PLONG PreviousCount  OPTIONAL)
 {
-    KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();;
+    KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
     PKSEMAPHORE Semaphore;
     NTSTATUS Status = STATUS_SUCCESS; 
    
     PAGED_CODE();
-
+    
     /* Check buffer validity */
     if(PreviousCount != NULL && PreviousMode == UserMode) {
         

Modified: branches/alex_devel_branch/reactos/ntoskrnl/ex/timer.c
--- branches/alex_devel_branch/reactos/ntoskrnl/ex/timer.c	2005-03-04 19:07:02 UTC (rev 13820)
+++ branches/alex_devel_branch/reactos/ntoskrnl/ex/timer.c	2005-03-04 20:56:32 UTC (rev 13821)
@@ -1,5 +1,4 @@
-/* $Id: nttimer.c 12779 2005-01-04 04:45:00Z gdalsnes $
- *
+/*
  * COPYRIGHT:       See COPYING in the top level directory
  * PROJECT:         ReactOS kernel
  * FILE:            ntoskrnl/ex/timer.c
@@ -124,9 +123,9 @@
                          PVOID* SystemArguemnt2)
 {
     PETIMER Timer;
+    KIRQL OldIrql;
     PETHREAD CurrentThread = PsGetCurrentThread();
-    KIRQL OldIrql;
-    
+
     /* We need to find out which Timer we are */
     Timer = CONTAINING_RECORD(Apc, ETIMER, TimerApc);
     DPRINT("ExpTimerApcKernelRoutine(Apc: %x. Timer: %x)\n", Apc, Timer);
@@ -176,7 +175,7 @@
     ExTimerType = ExAllocatePool(NonPagedPool, sizeof(OBJECT_TYPE));
 
     /* Create the Executive Timer Object */
-    RtlpCreateUnicodeString(&ExTimerType->TypeName, L"Timer", NonPagedPool);
+    RtlInitUnicodeString(&ExTimerType->TypeName, L"Timer");
     ExTimerType->Tag = TAG('T', 'I', 'M', 'T');
     ExTimerType->PeakObjects = 0;
     ExTimerType->PeakHandles = 0;
@@ -209,7 +208,7 @@
               OUT PBOOLEAN CurrentState OPTIONAL)
 {
     PETIMER Timer;
-    KPROCESSOR_MODE PreviousMode;
+    KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
     BOOLEAN State;
     KIRQL OldIrql;
     PETHREAD TimerThread;
@@ -217,9 +216,6 @@
     NTSTATUS Status = STATUS_SUCCESS;
     
     PAGED_CODE();
-    
-    PreviousMode = ExGetPreviousMode();
-   
     DPRINT("NtCancelTimer(0x%x, 0x%x)\n", TimerHandle, CurrentState);
    
     /* Check Parameter Validity */
@@ -301,10 +297,15 @@
 
         /* Make sure it's safe to write to the handle */
         if(CurrentState != NULL) {
+            
             _SEH_TRY {
+                
                 *CurrentState = State;
+                
             } _SEH_HANDLE {
+                
                 Status = _SEH_GetExceptionCode();
+                
             } _SEH_END;
         }
     }
@@ -323,28 +324,27 @@
 {
     PETIMER Timer;
     HANDLE hTimer;
-    KPROCESSOR_MODE PreviousMode;
+    KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
     NTSTATUS Status = STATUS_SUCCESS;
     
     PAGED_CODE();
-    
-    PreviousMode = ExGetPreviousMode();
-   
     DPRINT("NtCreateTimer(Handle: %x, Type: %d)\n", TimerHandle, TimerType);
 
     /* Check Parameter Validity */
     if (PreviousMode != KernelMode) {
+        
         _SEH_TRY {
+            
             ProbeForWrite(TimerHandle,
                           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 */   
@@ -388,9 +388,13 @@
   
         /* Make sure it's safe to write to the handle */
         _SEH_TRY {
+            
             *TimerHandle = hTimer;
+            
         } _SEH_HANDLE {
+            
             Status = _SEH_GetExceptionCode();
+            
         } _SEH_END;
     }
 
@@ -406,28 +410,28 @@
             IN POBJECT_ATTRIBUTES ObjectAttributes)
 {
     HANDLE hTimer;
-    KPROCESSOR_MODE PreviousMode;
+    KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
     NTSTATUS Status = STATUS_SUCCESS;
     
     PAGED_CODE();
-    
-    PreviousMode = ExGetPreviousMode();
-
     DPRINT("NtOpenTimer(TimerHandle: %x)\n", TimerHandle);
 
     /* Check Parameter Validity */
     if (PreviousMode != KernelMode) {
+        
         _SEH_TRY {
+            
             ProbeForWrite(TimerHandle,
                           sizeof(HANDLE),
                           sizeof(ULONG));
+            
         } _SEH_HANDLE {
+            
             Status = _SEH_GetExceptionCode();
+            
         } _SEH_END;
      
-        if(!NT_SUCCESS(Status)) {
-            return Status;
-        }
+        if(!NT_SUCCESS(Status)) return Status;
     }
 
     /* Open the Timer */
@@ -444,9 +448,13 @@
         
         /* Make sure it's safe to write to the handle */
         _SEH_TRY {
+            
             *TimerHandle = hTimer;
+            
         } _SEH_HANDLE {
+            
             Status = _SEH_GetExceptionCode();
+            
         } _SEH_END;
     }
 
@@ -464,14 +472,11 @@
              OUT PULONG ReturnLength  OPTIONAL)
 {
     PETIMER Timer;
-    KPROCESSOR_MODE PreviousMode;
+    KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
     NTSTATUS Status = STATUS_SUCCESS;
     PTIMER_BASIC_INFORMATION BasicInfo = (PTIMER_BASIC_INFORMATION)TimerInformation;
     
     PAGED_CODE();
-    
-    PreviousMode = ExGetPreviousMode();
-
     DPRINT("NtQueryTimer(TimerHandle: %x, Class: %d)\n", TimerHandle, TimerInformationClass);
 
     /* Check Validity */
@@ -501,7 +506,7 @@
 
         /* Return the Basic Information */
         _SEH_TRY {
-
+           
             /* FIXME: Interrupt correction based on Interrupt Time */
             DPRINT("Returning Information for Timer: %x. Time Remaining: %d\n", Timer, Timer->KeTimer.DueTime.QuadPart);
             BasicInfo->TimeRemaining.QuadPart = Timer->KeTimer.DueTime.QuadPart;
@@ -511,7 +516,8 @@
 
         } _SEH_HANDLE {
             
-                  Status = _SEH_GetExceptionCode();
+            Status = _SEH_GetExceptionCode();
+                  
         } _SEH_END;
         
         /* Dereference Object */
@@ -535,41 +541,40 @@
     PETIMER Timer;
     KIRQL OldIrql;
     BOOLEAN State;
-    KPROCESSOR_MODE PreviousMode;
-    PETHREAD CurrentThread;
+    KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
+    PETHREAD CurrentThread = PsGetCurrentThread();
     LARGE_INTEGER TimerDueTime;
     PETHREAD TimerThread;
     BOOLEAN KillTimer = FALSE;
     NTSTATUS Status = STATUS_SUCCESS;
     
     PAGED_CODE();
-    
-    PreviousMode = ExGetPreviousMode();
-    CurrentThread = PsGetCurrentThread();
-
     DPRINT("NtSetTimer(TimerHandle: %x, DueTime: %d, Apc: %x, Period: %d)\n", TimerHandle, DueTime->QuadPart, TimerApcRoutine, Period);
 
     /* Check Parameter Validity */
     if (PreviousMode != KernelMode) {
+        
         _SEH_TRY {
+            
             ProbeForRead(DueTime,
                          sizeof(LARGE_INTEGER),
                          sizeof(ULONG));
             TimerDueTime = *DueTime;
             
             if(PreviousState != NULL) {
+                
                 ProbeForWrite(PreviousState,
                               sizeof(BOOLEAN),
                               sizeof(BOOLEAN));
             }
             
         } _SEH_HANDLE {
+            
             Status = _SEH_GetExceptionCode();
+            
         } _SEH_END;
      
-        if(!NT_SUCCESS(Status)) {
-            return Status;
-        }
+        if(!NT_SUCCESS(Status)) return Status;        
     }
     
     /* Get the Timer Object */   
@@ -685,10 +690,15 @@
 
         /* Make sure it's safe to write to the handle */
         if(PreviousState != NULL) {
+            
             _SEH_TRY {
+                
                 *PreviousState = State;
+                
             } _SEH_HANDLE {
+                
                 Status = _SEH_GetExceptionCode();
+                
             } _SEH_END;
         }
     }

Modified: branches/alex_devel_branch/reactos/ntoskrnl/include/internal/ob.h
--- branches/alex_devel_branch/reactos/ntoskrnl/include/internal/ob.h	2005-03-04 19:07:02 UTC (rev 13820)
+++ branches/alex_devel_branch/reactos/ntoskrnl/include/internal/ob.h	2005-03-04 20:56:32 UTC (rev 13821)
@@ -326,7 +326,7 @@
   HANDLE RootDirectory;
   ULONG Attributes;
   PSECURITY_DESCRIPTOR SecurityDescriptor;
-  /* PVOID SecurityQualityOfService; */
+  PSECURITY_QUALITY_OF_SERVICE SecurityQualityOfService;
 } CAPTURED_OBJECT_ATTRIBUTES, *PCAPTURED_OBJECT_ATTRIBUTES;
 
 NTSTATUS

Modified: branches/alex_devel_branch/reactos/ntoskrnl/include/internal/se.h
--- branches/alex_devel_branch/reactos/ntoskrnl/include/internal/se.h	2005-03-04 19:07:02 UTC (rev 13820)
+++ branches/alex_devel_branch/reactos/ntoskrnl/include/internal/se.h	2005-03-04 20:56:32 UTC (rev 13821)
@@ -148,7 +148,61 @@
 		  ULONG PrivilegeControl,
 		  KPROCESSOR_MODE PreviousMode);
 
+NTSTATUS
+SepCaptureSecurityQualityOfService(IN POBJECT_ATTRIBUTES ObjectAttributes  OPTIONAL,
+                                   IN KPROCESSOR_MODE AccessMode,
+                                   IN POOL_TYPE PoolType,
+                                   IN BOOLEAN CaptureIfKernel,
+                                   OUT PSECURITY_QUALITY_OF_SERVICE *CapturedSecurityQualityOfService,
+                                   OUT PBOOLEAN Present);
 
+VOID
+SepReleaseSecurityQualityOfService(IN PSECURITY_QUALITY_OF_SERVICE CapturedSecurityQualityOfService  OPTIONAL,
+                                   IN KPROCESSOR_MODE AccessMode,
+                                   IN BOOLEAN CaptureIfKernel);
+
+NTSTATUS
+SepCaptureSid(IN PSID InputSid,
+              IN KPROCESSOR_MODE AccessMode,
+              IN POOL_TYPE PoolType,
+              IN BOOLEAN CaptureIfKernel,
+              OUT PSID *CapturedSid);
+
+VOID
+SepReleaseSid(IN PSID CapturedSid,
+              IN KPROCESSOR_MODE AccessMode,
+              IN BOOLEAN CaptureIfKernel);
+
+NTSTATUS
+SepCaptureAcl(IN PACL InputAcl,
+              IN KPROCESSOR_MODE AccessMode,
+              IN POOL_TYPE PoolType,
+              IN BOOLEAN CaptureIfKernel,
+              OUT PACL *CapturedAcl);
+
+VOID
+SepReleaseAcl(IN PACL CapturedAcl,
+              IN KPROCESSOR_MODE AccessMode,
+              IN BOOLEAN CaptureIfKernel);
+
+#define SepAcquireTokenLockExclusive(Token)                                    \
+  do {                                                                         \
+    KeEnterCriticalRegion();                                                   \
+    ExAcquireResourceExclusive(((PTOKEN)Token)->TokenLock, TRUE);              \
+  while(0)
+
+#define SepAcquireTokenLockShared(Token)                                       \
+  do {                                                                         \
+    KeEnterCriticalRegion();                                                   \
+    ExAcquireResourceShared(((PTOKEN)Token)->TokenLock, TRUE);                 \
+  while(0)
+
+#define SepReleaseTokenLock(Token)                                             \
+  do {                                                                         \
+    ExReleaseResource(((PTOKEN)Token)->TokenLock);                             \
+    KeLeaveCriticalRegion();                                                   \
[truncated at 1000 lines; 2559 more skipped]