First patch to fix seriously broken ROS (thank Thomas). Work in progress, will be cleaned up at the end
Modified: trunk/reactos/lib/rtl/registry.c
Modified: trunk/reactos/ntoskrnl/ex/event.c
Modified: trunk/reactos/ntoskrnl/ke/i386/syscall.S
Modified: trunk/reactos/ntoskrnl/ldr/loader.c
Modified: trunk/reactos/ntoskrnl/ob/object.c
Modified: trunk/reactos/ntoskrnl/se/token.c
Modified: trunk/reactos/subsys/system/userinit/userinit.c
Modified: trunk/reactos/subsys/win32k/ntuser/desktop.c
Modified: trunk/reactos/subsys/win32k/ntuser/winsta.c
Modified: trunk/reactos/tools/helper.mk

Modified: trunk/reactos/lib/rtl/registry.c
--- trunk/reactos/lib/rtl/registry.c	2005-01-21 23:01:33 UTC (rev 13198)
+++ trunk/reactos/lib/rtl/registry.c	2005-01-21 23:35:19 UTC (rev 13199)
@@ -44,7 +44,7 @@
 
   if (RelativeTo & RTL_REGISTRY_HANDLE)
     {
-      Status = NtDuplicateObject(NtCurrentProcess(),
+      Status = ZwDuplicateObject(NtCurrentProcess(),
 				 (HANDLE)Path,
 				 NtCurrentProcess(),
 				 KeyHandle,
@@ -129,7 +129,7 @@
 
   if (Create == TRUE)
     {
-      Status = NtCreateKey(KeyHandle,
+      Status = ZwCreateKey(KeyHandle,
 			   KEY_ALL_ACCESS,
 			   &ObjectAttributes,
 			   0,
@@ -139,7 +139,7 @@
     }
   else
     {
-      Status = NtOpenKey(KeyHandle,
+      Status = ZwOpenKey(KeyHandle,
 			 KEY_ALL_ACCESS,
 			 &ObjectAttributes);
     }
@@ -165,7 +165,7 @@
   if (!NT_SUCCESS(Status))
     return(Status);
 
-  NtClose(KeyHandle);
+  ZwClose(KeyHandle);
 
   return(STATUS_SUCCESS);
 }
@@ -188,7 +188,7 @@
   if (!NT_SUCCESS(Status))
     return(Status);
 
-  NtClose(KeyHandle);
+  ZwClose(KeyHandle);
 
   return(STATUS_SUCCESS);
 }
@@ -216,10 +216,10 @@
   RtlInitUnicodeString(&Name,
 		       ValueName);
 
-  Status = NtDeleteValueKey(KeyHandle,
+  Status = ZwDeleteValueKey(KeyHandle,
 			    &Name);
 
-  NtClose(KeyHandle);
+  ZwClose(KeyHandle);
 
   return(Status);
 }
@@ -240,7 +240,7 @@
 
   DPRINT ("RtlFormatCurrentUserKeyPath() called\n");
 
-  Status = NtOpenThreadToken (NtCurrentThread (),
+  Status = ZwOpenThreadToken (NtCurrentThread (),
 			      TOKEN_READ,
 			      TRUE,
 			      &TokenHandle);
@@ -248,30 +248,30 @@
     {
       if (Status != STATUS_NO_TOKEN)
 	{
-	  DPRINT1 ("NtOpenThreadToken() failed (Status %lx)\n", Status);
+	  DPRINT1 ("ZwOpenThreadToken() failed (Status %lx)\n", Status);
 	  return Status;
 	}
 
-      Status = NtOpenProcessToken (NtCurrentProcess (),
+      Status = ZwOpenProcessToken (NtCurrentProcess (),
 				   TOKEN_READ,
 				   &TokenHandle);
       if (!NT_SUCCESS (Status))
 	{
-	  DPRINT1 ("NtOpenProcessToken() failed (Status %lx)\n", Status);
+	  DPRINT1 ("ZwOpenProcessToken() failed (Status %lx)\n", Status);
 	  return Status;
 	}
     }
 
   SidBuffer = (PSID_AND_ATTRIBUTES)Buffer;
-  Status = NtQueryInformationToken (TokenHandle,
+  Status = ZwQueryInformationToken (TokenHandle,
 				    TokenUser,
 				    (PVOID)SidBuffer,
 				    256,
 				    &Length);
-  NtClose (TokenHandle);
+  ZwClose (TokenHandle);
   if (!NT_SUCCESS(Status))
     {
-      DPRINT1 ("NtQueryInformationToken() failed (Status %lx)\n", Status);
+      DPRINT1 ("ZwQueryInformationToken() failed (Status %lx)\n", Status);
       return Status;
     }
 
@@ -329,7 +329,7 @@
 				 OBJ_CASE_INSENSITIVE,
 				 NULL,
 				 NULL);
-      Status = NtOpenKey(KeyHandle,
+      Status = ZwOpenKey(KeyHandle,
 			 DesiredAccess,
 			 &ObjectAttributes);
       RtlFreeUnicodeString(&KeyPath);
@@ -346,7 +346,7 @@
 			     OBJ_CASE_INSENSITIVE,
 			     NULL,
 			     NULL);
-  Status = NtOpenKey(KeyHandle,
+  Status = ZwOpenKey(KeyHandle,
 		     DesiredAccess,
 		     &ObjectAttributes);
 
@@ -403,7 +403,7 @@
       if (((QueryEntry->Flags & (RTL_QUERY_REGISTRY_SUBKEY | RTL_QUERY_REGISTRY_TOPKEY)) != 0) &&
 	  (BaseKeyHandle != CurrentKeyHandle))
 	{
-	  NtClose(CurrentKeyHandle);
+	  ZwClose(CurrentKeyHandle);
 	  CurrentKeyHandle = BaseKeyHandle;
 	}
 
@@ -418,7 +418,7 @@
 				     OBJ_CASE_INSENSITIVE,
 				     BaseKeyHandle,
 				     NULL);
-	  Status = NtOpenKey(&CurrentKeyHandle,
+	  Status = ZwOpenKey(&CurrentKeyHandle,
 			     KEY_ALL_ACCESS,
 			     &ObjectAttributes);
 	  if (!NT_SUCCESS(Status))
@@ -439,7 +439,7 @@
 	      break;
 	    }
 
-	  Status = NtQueryValueKey(CurrentKeyHandle,
+	  Status = ZwQueryValueKey(CurrentKeyHandle,
 				   &KeyName,
 				   KeyValuePartialInformation,
 				   ValueInfo,
@@ -601,7 +601,7 @@
 		  break;
 		}
 
-	      Status = NtQueryValueKey(CurrentKeyHandle,
+	      Status = ZwQueryValueKey(CurrentKeyHandle,
 				       &KeyName,
 				       KeyValuePartialInformation,
 				       ValueInfo,
@@ -725,7 +725,7 @@
 	      Index = 0;
 	      while (TRUE)
 		{
-		  Status = NtEnumerateValueKey(CurrentKeyHandle,
+		  Status = ZwEnumerateValueKey(CurrentKeyHandle,
 					       Index,
 					       KeyValueFullInformation,
 					       FullValueInfo,
@@ -848,9 +848,9 @@
     }
 
   if (CurrentKeyHandle != BaseKeyHandle)
-    NtClose(CurrentKeyHandle);
+    ZwClose(CurrentKeyHandle);
 
-  NtClose(BaseKeyHandle);
+  ZwClose(BaseKeyHandle);
 
   return(Status);
 }
@@ -881,14 +881,14 @@
   RtlInitUnicodeString(&Name,
 		       ValueName);
 
-  Status = NtSetValueKey(KeyHandle,
+  Status = ZwSetValueKey(KeyHandle,
 			 &Name,
 			 0,
 			 ValueType,
 			 ValueData,
 			 ValueLength);
   if (NT_SUCCESS(Status))
-    NtClose(KeyHandle);
+    ZwClose(KeyHandle);
 
   return(Status);
 }
@@ -908,7 +908,7 @@
   if (ObjectAttributes != NULL)
     ObjectAttributes->Attributes &= ~(OBJ_PERMANENT | OBJ_EXCLUSIVE);
 
-  return(NtCreateKey(KeyHandle,
+  return(ZwCreateKey(KeyHandle,
 		     DesiredAccess,
 		     ObjectAttributes,
 		     0,
@@ -941,7 +941,7 @@
 	return(STATUS_NO_MEMORY);
     }
 
-  Status = NtEnumerateKey(KeyHandle,
+  Status = ZwEnumerateKey(KeyHandle,
 			  Index,
 			  KeyBasicInformation,
 			  KeyInfo,
@@ -978,7 +978,7 @@
 NTSTATUS STDCALL
 RtlpNtMakeTemporaryKey(IN HANDLE KeyHandle)
 {
-  return(NtDeleteKey(KeyHandle));
+  return(ZwDeleteKey(KeyHandle));
 }
 
 
@@ -994,7 +994,7 @@
   if (ObjectAttributes != NULL)
     ObjectAttributes->Attributes &= ~(OBJ_PERMANENT | OBJ_EXCLUSIVE);
 
-  return(NtOpenKey(KeyHandle,
+  return(ZwOpenKey(KeyHandle,
 		   DesiredAccess,
 		   ObjectAttributes));
 }
@@ -1027,7 +1027,7 @@
   if (ValueInfo == NULL)
     return(STATUS_NO_MEMORY);
 
-  Status = NtQueryValueKey(KeyHandle,
+  Status = ZwQueryValueKey(KeyHandle,
 			   &ValueName,
 			   KeyValuePartialInformation,
 			   ValueInfo,
@@ -1068,7 +1068,7 @@
 
   RtlInitUnicodeString(&ValueName,
 		       NULL);
-  return(NtSetValueKey(KeyHandle,
+  return(ZwSetValueKey(KeyHandle,
 		       &ValueName,
 		       0,
 		       Type,

Modified: trunk/reactos/ntoskrnl/ex/event.c
--- trunk/reactos/ntoskrnl/ex/event.c	2005-01-21 23:01:33 UTC (rev 13198)
+++ trunk/reactos/ntoskrnl/ex/event.c	2005-01-21 23:35:19 UTC (rev 13199)
@@ -124,58 +124,77 @@
 	      IN EVENT_TYPE EventType,
 	      IN BOOLEAN InitialState)
 {
+/*
+ * @implemented
+ */
+NTSTATUS STDCALL
+NtCreateEvent(OUT PHANDLE EventHandle,
+	      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;
-   OBJECT_ATTRIBUTES SafeObjectAttributes;
-   
-   if (ObjectAttributes != NULL)
+   NTSTATUS Status = STATUS_SUCCESS;
+ 
+   PreviousMode = ExGetPreviousMode();
+ 
+   if(PreviousMode == UserMode)
+   {
+     _SEH_TRY
      {
-       Status = MmCopyFromCaller(&SafeObjectAttributes, ObjectAttributes,
-				 sizeof(OBJECT_ATTRIBUTES));
-       if (!NT_SUCCESS(Status))
-	 {
-	   return(Status);
-	 }
-       ObjectAttributes = &SafeObjectAttributes;
+       ProbeForWrite(EventHandle,
+                     sizeof(HANDLE),
+                     sizeof(ULONG));
      }
-
-   Status = ObCreateObject(ExGetPreviousMode(),
-			   ExEventObjectType,
-			   ObjectAttributes,
-			   ExGetPreviousMode(),
-			   NULL,
-			   sizeof(KEVENT),
-			   0,
-			   0,
-			   (PVOID*)&Event);
-   if (!NT_SUCCESS(Status))
+     _SEH_HANDLE
      {
-	return(Status);
+       Status = _SEH_GetExceptionCode();
      }
-   KeInitializeEvent(Event,
-		     EventType,
-		     InitialState);
-
-   Status = ObInsertObject ((PVOID)Event,
-			    NULL,
-			    DesiredAccess,
-			    0,
-			    NULL,
-			    &hEvent);
-   ObDereferenceObject(Event);
-   if (!NT_SUCCESS(Status))
+     _SEH_END;
+   }
+ 
+   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))
      {
-	return Status;
+       _SEH_TRY
+       {
+         *EventHandle = hEvent;
+       }
+       _SEH_HANDLE
+       {
+         Status = _SEH_GetExceptionCode();
+       }
+       _SEH_END;
      }
-
-   Status = MmCopyToCaller(EventHandle, &hEvent, sizeof(HANDLE));
-   if (!NT_SUCCESS(Status))
-     {
-	ZwClose(hEvent);
-	return(Status);
-     }
-   return(STATUS_SUCCESS);
+   }
+ 
+   return Status;
 }
 
 

Modified: trunk/reactos/ntoskrnl/ke/i386/syscall.S
--- trunk/reactos/ntoskrnl/ke/i386/syscall.S	2005-01-21 23:01:33 UTC (rev 13198)
+++ trunk/reactos/ntoskrnl/ke/i386/syscall.S	2005-01-21 23:35:19 UTC (rev 13199)
@@ -70,7 +70,7 @@
     movw %bx, %fs
     
     /* Save the previous exception list */
-    pushl %fs:KPCR_EXCEPTION_LIST                                       // + 0x2C
+    pushl %fs:KPCR_EXCEPTION_LIST                                      // + 0x2C
 
     /* Set the exception handler chain terminator */
     movl $0xffffffff, %fs:KPCR_EXCEPTION_LIST
@@ -79,11 +79,11 @@
     movl %fs:KPCR_CURRENT_THREAD, %esi
 
     /* Save the old previous mode */
-    pushl %ss:KTHREAD_PREVIOUS_MODE(%esi)                               // + 0x30
+    pushl %ss:KTHREAD_PREVIOUS_MODE(%esi)                              // + 0x30
     
     /* Set the new previous mode based on the saved CS selector */
     movl 0x24(%esp), %ebx
-    and $1, %ebx
+    andl $1, %ebx
     movb %bl, %ss:KTHREAD_PREVIOUS_MODE(%esi)
 
     /* Save other registers */
@@ -95,20 +95,14 @@
     pushl %gs                                                          // + 0x48
     sub $0x28, %esp                                                    // + 0x70
 
-#if 0
 #ifdef DBG
     /* Trick gdb 6 into backtracing over the system call */
-    /* FIXME: %ebp is *never* initialized */
     pushl 4(%ebp)    /* DebugEIP */                                    // + 0x74
     pushl (%ebp)     /* DebugEBP */                                    // + 0x78
 #else
     pushl 0x60(%esp) /* DebugEIP */                                    // + 0x74
     pushl %ebp       /* DebugEBP */                                    // + 0x78
 #endif
-#else
-    pushl $0         /* DebugEIP */                                    // + 0x74
-    pushl $0         /* DebugEBP */                                    // + 0x78
-#endif
 
     /* Load the segment registers */
     sti
@@ -320,7 +314,6 @@
 InvalidCall:
 
     /* Invalid System Call */
-    int $3
     movl $STATUS_INVALID_SYSTEM_SERVICE, %eax
     movl %eax, KTRAP_FRAME_EAX(%ebp)
     jmp _KiServiceExit

Modified: trunk/reactos/ntoskrnl/ldr/loader.c
--- trunk/reactos/ntoskrnl/ldr/loader.c	2005-01-21 23:01:33 UTC (rev 13198)
+++ trunk/reactos/ntoskrnl/ldr/loader.c	2005-01-21 23:35:19 UTC (rev 13199)
@@ -307,7 +307,7 @@
                              NULL,
                              NULL);
   CHECKPOINT;
-  Status = NtOpenFile(&FileHandle,
+  Status = ZwOpenFile(&FileHandle,
                       FILE_ALL_ACCESS,
                       &ObjectAttributes,
                       &IoStatusBlock,
@@ -322,7 +322,7 @@
   CHECKPOINT;
 
   /*  Get the size of the file  */
-  Status = NtQueryInformationFile(FileHandle,
+  Status = ZwQueryInformationFile(FileHandle,
                                   &IoStatusBlock,
                                   &FileStdInfo,
                                   sizeof(FileStdInfo),
@@ -348,7 +348,7 @@
   CHECKPOINT;
 
   /*  Load driver into memory chunk  */
-  Status = NtReadFile(FileHandle,
+  Status = ZwReadFile(FileHandle,
                       0, 0, 0,
                       &IoStatusBlock,
                       ModuleLoadBase,
@@ -363,7 +363,7 @@
     }
   CHECKPOINT;
 
-  NtClose(FileHandle);
+  ZwClose(FileHandle);
 
   Status = LdrProcessModule(ModuleLoadBase,
                             Filename,

Modified: trunk/reactos/ntoskrnl/ob/object.c
--- trunk/reactos/ntoskrnl/ob/object.c	2005-01-21 23:01:33 UTC (rev 13198)
+++ trunk/reactos/ntoskrnl/ob/object.c	2005-01-21 23:35:19 UTC (rev 13199)
@@ -601,7 +601,7 @@
 
   ASSERT_IRQL(APC_LEVEL);
   
-  if(AccessMode == UserMode && ObjectAttributes != NULL)
+  if(ObjectAttributesAccessMode == UserMode && ObjectAttributes != NULL)
   {
     Status = STATUS_SUCCESS;
     _SEH_TRY

Modified: trunk/reactos/ntoskrnl/se/token.c
--- trunk/reactos/ntoskrnl/se/token.c	2005-01-21 23:01:33 UTC (rev 13198)
+++ trunk/reactos/ntoskrnl/se/token.c	2005-01-21 23:35:19 UTC (rev 13199)
@@ -1579,7 +1579,6 @@
   HANDLE TokenHandle;
   PTOKEN AccessToken;
   NTSTATUS Status;
-  OBJECT_ATTRIBUTES SafeObjectAttributes;
   POBJECT_ATTRIBUTES ObjectAttributes;
   LUID TokenId;
   LUID ModifiedId;
@@ -1587,14 +1586,6 @@
   ULONG uLength;
   ULONG i;
 
-  Status = MmCopyFromCaller(&SafeObjectAttributes,
-			    UnsafeObjectAttributes,
-			    sizeof(OBJECT_ATTRIBUTES));
-  if (!NT_SUCCESS(Status))
-    return(Status);
-
-  ObjectAttributes = &SafeObjectAttributes;
-
   Status = ZwAllocateLocallyUniqueId(&TokenId);
   if (!NT_SUCCESS(Status))
     return(Status);

Modified: trunk/reactos/subsys/system/userinit/userinit.c
--- trunk/reactos/subsys/system/userinit/userinit.c	2005-01-21 23:01:33 UTC (rev 13198)
+++ trunk/reactos/subsys/system/userinit/userinit.c	2005-01-21 23:35:19 UTC (rev 13199)
@@ -143,6 +143,7 @@
 	LPSTR lpszCmdLine,
 	int nCmdShow)
 {
+  DPRINT1("Hello\n");
   SetUserSettings();
   StartShell();
   return 0;

Modified: trunk/reactos/subsys/win32k/ntuser/desktop.c
--- trunk/reactos/subsys/win32k/ntuser/desktop.c	2005-01-21 23:01:33 UTC (rev 13198)
+++ trunk/reactos/subsys/win32k/ntuser/desktop.c	2005-01-21 23:35:19 UTC (rev 13199)
@@ -596,7 +596,7 @@
    */
 
   Status = ObCreateObject(
-    ExGetPreviousMode(),
+    KernelMode,
     ExDesktopObjectType,
     &ObjectAttributes,
     ExGetPreviousMode(),

Modified: trunk/reactos/subsys/win32k/ntuser/winsta.c
--- trunk/reactos/subsys/win32k/ntuser/winsta.c	2005-01-21 23:01:33 UTC (rev 13198)
+++ trunk/reactos/subsys/win32k/ntuser/winsta.c	2005-01-21 23:35:19 UTC (rev 13199)
@@ -324,7 +324,7 @@
    DPRINT("Creating window station (%wZ)\n", &WindowStationName);
 
    Status = ObCreateObject(
-      ExGetPreviousMode(),
+      KernelMode,
       ExWindowStationObjectType,
       &ObjectAttributes,
       ExGetPreviousMode(),
@@ -336,7 +336,7 @@
 
    if (!NT_SUCCESS(Status))
    {
-      DPRINT("Failed creating window station (%wZ)\n", &WindowStationName);
+      DPRINT1("Failed creating window station (%wZ)\n", &WindowStationName);
       ExFreePool(WindowStationName.Buffer);
       SetLastNtError(STATUS_INSUFFICIENT_RESOURCES);
       return 0;

Modified: trunk/reactos/tools/helper.mk
--- trunk/reactos/tools/helper.mk	2005-01-21 23:01:33 UTC (rev 13198)
+++ trunk/reactos/tools/helper.mk	2005-01-21 23:35:19 UTC (rev 13199)
@@ -618,8 +618,10 @@
 # if needed, until their problems can be found
 #
 ifeq ($(OPTIMIZED), 1)
-  MK_CFLAGS += -O2 -Wno-strict-aliasing
-  MK_CPPFLAGS += -O2 -Wno-strict-aliasing
+  ifneq ($(TARGET_NAME), bootvid)
+    MK_CFLAGS += -O2 -Wno-strict-aliasing
+    MK_CPPFLAGS += -O2 -Wno-strict-aliasing
+  endif
 endif
 
 ifneq ($(TARGET_LIBS),)