Index: iface/native/makefile
===================================================================
--- iface/native/makefile	(revision 12839)
+++ iface/native/makefile	(working copy)
@@ -1,4 +1,4 @@
-# $Id: makefile,v 1.14 2004/07/21 18:17:50 chorns Exp $
+# $Id$
 #
 # ReactOS Operating System
 #
@@ -14,7 +14,7 @@
 SYSTEM_CALLS_DB = sysfuncs.lst
 NTDLL_STUBS = ../../lib/ntdll/napi.c
 KERNEL_SERVICE_TABLE = ../../include/ntdll/napi.h
-KERNEL_ZW_CALLS = ../../ntoskrnl/nt/zw.c
+KERNEL_ZW_CALLS = ../../ntoskrnl/ke/zw.c
 NAPI_FILES = $(NTDLL_STUBS) $(KERNEL_SERVICE_TABLE) $(KERNEL_ZW_CALLS)
 
 BASE_CFLAGS = -I../../include
Index: iface/native/sysfuncs.lst
===================================================================
--- iface/native/sysfuncs.lst	(revision 12839)
+++ iface/native/sysfuncs.lst	(working copy)
@@ -232,10 +232,4 @@
 NtWriteRequestData ZwWriteRequestData 6
 NtWriteVirtualMemory ZwWriteVirtualMemory 5
 NtW32Call ZwW32Call 5
-NtCreateChannel ZwCreateChannel 2
-NtListenChannel ZwListenChannel 2
-NtOpenChannel ZwOpenChannel 2
-NtReplyWaitSendChannel ZwReplyWaitSendChannel 3
-NtSendWaitReplyChannel ZwSendWaitReplyChannel 4
-NtSetContextChannel ZwSetContextChannel 1
 NtYieldExecution ZwYieldExecution 0
Index: include/ddk/ketypes.h
===================================================================
--- include/ddk/ketypes.h	(revision 12839)
+++ include/ddk/ketypes.h	(working copy)
@@ -99,6 +99,10 @@
   BOOLEAN Busy;
 } KDEVICE_QUEUE, *PKDEVICE_QUEUE;
 
+/*
+ * Size of the profile hash table.
+ */
+#define PROFILE_HASH_TABLE_SIZE      (32)
 
 #include <pshpack2.h>
 
Index: ntoskrnl/inbv/inbv.c
===================================================================
--- ntoskrnl/inbv/inbv.c	(revision 12839)
+++ ntoskrnl/inbv/inbv.c	(working copy)
@@ -1,4 +1,4 @@
-/* $Id: inbv.c,v 1.8 2004/08/15 16:39:03 chorns Exp $
+/* $Id$
  *
  * COPYRIGHT:      See COPYING in the top level directory
  * PROJECT:        ReactOS kernel
@@ -217,3 +217,18 @@
   IN ULONG Color)
 {
 }
+
+NTSTATUS
+STDCALL
+NtDisplayString(IN PUNICODE_STRING DisplayString)
+{
+   ANSI_STRING AnsiString;
+
+   RtlUnicodeStringToAnsiString (&AnsiString, DisplayString, TRUE);
+
+   HalDisplayString (AnsiString.Buffer);
+
+   RtlFreeAnsiString (&AnsiString);
+
+   return(STATUS_SUCCESS);
+}
Index: ntoskrnl/Makefile
===================================================================
--- ntoskrnl/Makefile	(revision 12839)
+++ ntoskrnl/Makefile	(working copy)
@@ -77,22 +77,6 @@
 #
 include Makefile.$(ARCH)
 
-# System API (Nt/Zw)
-OBJECTS_NT = \
-	nt/channel.o \
-	nt/efi.o \
-	nt/evtpair.o \
-	nt/mutant.o \
-	nt/misc.o \
-	nt/nt.o \
-	nt/ntevent.o \
-	nt/ntsem.o \
-	nt/nttimer.o \
-	nt/plugplay.o \
-	nt/profile.o \
-	nt/vdm.o \
-	nt/zw.o
-
 # Run-Time Library (Rtl)
 OBJECTS_RTL = \
 	rtl/atom.o \
@@ -136,7 +120,8 @@
 	ke/sem.o \
 	ke/spinlock.o \
 	ke/timer.o \
-	ke/wait.o
+	ke/wait.o \
+	ke/zw.o
 
 # Memory Manager (Mm)
 OBJECTS_MM = \
@@ -188,6 +173,7 @@
 	io/deviface.o \
 	io/dir.o \
 	io/driver.o \
+	io/efi.o \
 	io/errlog.o \
 	io/error.o \
 	io/event.o \
@@ -206,6 +192,7 @@
 	io/npipe.o \
 	io/page.o \
 	io/parttab.o \
+	io/plugplay.o \
 	io/process.o \
 	io/pnpnotify.o \
 	io/pnpdma.o \
@@ -259,20 +246,26 @@
 OBJECTS_EX = \
 	ex/btree.o \
 	ex/callback.o \
+	ex/event.o \
+	ex/evtpair.o \
 	ex/fmutex.o \
 	ex/hashtab.o \
 	ex/init.o \
 	ex/interlck.o \
 	ex/list.o \
 	ex/lookas.o \
+	ex/mutant.o \
 	ex/napi.o \
 	ex/power.o \
+	ex/profile.o \
 	ex/resource.o \
 	ex/rundown.o \
 	ex/stree.o \
+	ex/sem.o \
 	ex/synch.o \
 	ex/sysinfo.o \
 	ex/time.o \
+	ex/timer.o \
 	ex/util.o \
 	ex/uuid.o \
 	ex/win32k.o \
@@ -371,7 +364,7 @@
 OBJECTS_INBV = \
 	inbv/inbv.o
 
-DEP_OBJECTS := $(OBJECTS_NT) $(OBJECTS_MM) $(OBJECTS_ARCH) \
+DEP_OBJECTS := $(OBJECTS_MM) $(OBJECTS_ARCH) \
 	$(OBJECTS_IO) $(OBJECTS_KE) $(OBJECTS_OB) \
 	$(OBJECTS_PS) $(OBJECTS_EX) $(OBJECTS_CC) $(OBJECTS_FS) $(OBJECTS_SE) \
 	$(OBJECTS_DBG) $(OBJECTS_CM) $(OBJECTS_LDR) $(OBJECTS_LPC) \
@@ -475,12 +468,6 @@
 		-o $(OBJECTS_PATH)/lpc.o \
 		$(OBJECTS_LPC)
 
-$(OBJECTS_PATH)/nt.o: $(OBJECTS_NT)
-	$(LD) \
-		-r \
-		-o $(OBJECTS_PATH)/nt.o \
-		$(OBJECTS_NT)
-
 $(OBJECTS_PATH)/po.o: $(OBJECTS_PO)
 	$(LD) \
 		-r \
@@ -519,7 +506,6 @@
 	$(OBJECTS_PATH)/kd.o \
 	$(OBJECTS_PATH)/ldr.o \
 	$(OBJECTS_PATH)/mm.o \
-	$(OBJECTS_PATH)/nt.o \
 	$(OBJECTS_PATH)/ob.o \
 	$(OBJECTS_PATH)/po.o \
 	$(OBJECTS_PATH)/ps.o \
Index: ntoskrnl/include/ntoskrnl.h
===================================================================
--- ntoskrnl/include/ntoskrnl.h	(revision 12839)
+++ ntoskrnl/include/ntoskrnl.h	(working copy)
@@ -48,7 +48,6 @@
 #include <internal/kd.h>
 #include <internal/ex.h>
 #include <internal/ob.h>
-#include <internal/nt.h>
 #include "internal/xhal.h"
 #include <internal/v86m.h>
 #include <internal/ifs.h>
Index: ntoskrnl/include/internal/ke.h
===================================================================
--- ntoskrnl/include/internal/ke.h	(revision 12839)
+++ ntoskrnl/include/internal/ke.h	(working copy)
@@ -63,8 +63,58 @@
 
 /* next file ***************************************************************/
 
+typedef struct _KPROCESS_PROFILE
+/*
+ * List of the profile data structures associated with a process.
+ */
+{
+  LIST_ENTRY ProfileListHead;
+  LIST_ENTRY ListEntry;
+  HANDLE Pid;
+} KPROCESS_PROFILE, *PKPROCESS_PROFILE;
 
+typedef struct _KPROFILE
+/*
+ * Describes a contiguous region of process memory that is being profiled.
+ */
+{
+  CSHORT Type;
+  CSHORT Name;
 
+  /* Entry in the list of profile data structures for this process. */
+  LIST_ENTRY ListEntry; 
+
+  /* Base of the region being profiled. */
+  PVOID Base;
+
+  /* Size of the region being profiled. */
+  ULONG Size;
+
+  /* Shift of offsets from the region to buckets in the profiling buffer. */
+  ULONG BucketShift;
+
+  /* MDL which described the buffer that receives profiling data. */
+  struct _MDL *BufferMdl;
+
+  /* System alias for the profiling buffer. */
+  PULONG Buffer;
+
+  /* Size of the buffer for profiling data. */
+  ULONG BufferSize;
+
+  /* 
+   * Mask of processors for which profiling data should be collected. 
+   * Currently unused.
+   */
+  ULONG ProcessorMask;
+
+  /* TRUE if profiling has been started for this region. */
+  BOOLEAN Started;
+
+  /* Pointer (and reference) to the process which is being profiled. */
+  struct _EPROCESS *Process;
+} KPROFILE, *PKPROFILE;
+
 VOID STDCALL 
 DbgBreakPointNoBugCheck(VOID);
 
@@ -81,6 +131,14 @@
 	IN KPROFILE_SOURCE		Source
 );
 
+VOID KiAddProfileEventToProcess(PLIST_ENTRY ListHead, PVOID Eip);
+VOID KiAddProfileEvent(KPROFILE_SOURCE Source, ULONG Eip);
+VOID KiInsertProfileIntoProcess(PLIST_ENTRY ListHead, PKPROFILE Profile);
+VOID KiInsertProfile(PKPROFILE Profile);
+VOID KiRemoveProfile(PKPROFILE Profile);
+VOID STDCALL KiDeleteProfile(PVOID ObjectBody);
+
+
 VOID STDCALL KeUpdateSystemTime(PKTRAP_FRAME TrapFrame, KIRQL Irql);
 VOID STDCALL KeUpdateRunTime(PKTRAP_FRAME TrapFrame, KIRQL Irql);
 
Index: ntoskrnl/include/internal/ntoskrnl.h
===================================================================
--- ntoskrnl/include/internal/ntoskrnl.h	(revision 12839)
+++ ntoskrnl/include/internal/ntoskrnl.h	(working copy)
@@ -37,9 +37,13 @@
 //extern GDT_DESCRIPTOR KiGdt[256];
 
 
-VOID NtInitializeEventImplementation(VOID);
-VOID NtInit(VOID);
-
+VOID ExpInitializeEventImplementation(VOID);
+VOID ExpInitializeEventImplementation(VOID);
+VOID ExpInitializeEventPairImplementation(VOID);
+VOID ExpInitializeSemaphoreImplementation(VOID);
+VOID ExpInitializeMutantImplementation(VOID);
+VOID ExpInitializeTimerImplementation(VOID);
+VOID ExpInitializeProfileImplementation(VOID);
 /*
  * Initalization functions (called once by main())
  */
Index: ntoskrnl/include/internal/port.h
===================================================================
--- ntoskrnl/include/internal/port.h	(revision 12839)
+++ ntoskrnl/include/internal/port.h	(working copy)
@@ -134,11 +134,11 @@
 /* Code in ntoskrnl/lpc/port.c */
 
 NTSTATUS STDCALL
-NiInitializePort (IN OUT  PEPORT	Port,
+LpcpInitializePort (IN OUT  PEPORT	Port,
 		  IN      USHORT        Type,
 		  IN      PEPORT        Parent OPTIONAL);
 NTSTATUS
-NiInitPort (VOID);
+LpcpInitSystem (VOID);
 
 extern POBJECT_TYPE	LpcPortObjectType;
 extern ULONG		LpcpNextMessageId;
Index: ntoskrnl/ke/profile.c
===================================================================
--- ntoskrnl/ke/profile.c	(revision 12839)
+++ ntoskrnl/ke/profile.c	(working copy)
@@ -1,4 +1,4 @@
-/* $Id: profile.c,v 1.2 2004/08/15 16:39:05 chorns Exp $
+/* $Id$
  *
  * FILE:            ntoskrnl/ke/profile.c
  * PURPOSE:         Kernel Profiling
@@ -11,6 +11,242 @@
 #define NDEBUG
 #include <internal/debug.h>
 
+extern LIST_ENTRY ProcessProfileListHashTable[PROFILE_HASH_TABLE_SIZE];
+extern LIST_ENTRY SystemProfileList;
+extern KSPIN_LOCK ProfileListLock;
+extern BOOLEAN ProfileInitDone;
+
+/* FUNCTIONS *****************************************************************/
+
+VOID
+KiAddProfileEventToProcess(PLIST_ENTRY ListHead, PVOID Eip)
+     /*
+      * Add a profile event to the profile objects for a particular process
+      * or the system
+      */
+{
+  PKPROFILE current;
+  PLIST_ENTRY current_entry;
+
+  current_entry = ListHead->Flink;
+  while (current_entry != ListHead)
+    {
+      current = CONTAINING_RECORD(current_entry, KPROFILE, ListEntry);
+
+      if (current->Base > Eip)
+	{
+	  return;
+	}
+
+      if (current->Base <= Eip && ((char*)current->Base + current->Size) > (char*)Eip &&
+	  current->Started)
+	{
+	  ULONG Bucket;
+
+	  Bucket = ((ULONG)((char*)Eip - (char*)current->Base)) >> current->BucketShift;
+
+	  if ((Bucket*4) < current->BufferSize)
+	    {
+	      current->Buffer[Bucket]++;
+	    }
+	}
+
+      current_entry = current_entry->Flink;
+    }
+}
+
+VOID
+KiAddProfileEvent(KPROFILE_SOURCE Source, ULONG Eip)
+     /*
+      * Add a profile event 
+      */
+{
+  HANDLE Pid;
+  PKPROCESS_PROFILE current;
+  PLIST_ENTRY current_entry;
+  PLIST_ENTRY ListHead;
+
+  if (!ProfileInitDone)
+    {
+      return;
+    }
+
+  Pid = PsGetCurrentProcessId();
+  ListHead = 
+    ProcessProfileListHashTable[(ULONG)Pid % PROFILE_HASH_TABLE_SIZE].Flink;
+
+  KeAcquireSpinLockAtDpcLevel(&ProfileListLock);
+
+  current_entry = ListHead;
+  while (current_entry != ListHead)
+    {
+      current = CONTAINING_RECORD(current_entry, KPROCESS_PROFILE, ListEntry);
+
+      if (current->Pid == Pid)
+	{
+	  KiAddProfileEventToProcess(&current->ProfileListHead, (PVOID)Eip);
+	  break;
+	}
+
+      current_entry = current_entry->Flink;
+    }
+
+  KiAddProfileEventToProcess(&SystemProfileList, (PVOID)Eip);
+
+  KeReleaseSpinLockFromDpcLevel(&ProfileListLock);
+}
+
+VOID
+KiInsertProfileIntoProcess(PLIST_ENTRY ListHead, PKPROFILE Profile)
+     /*
+      * Insert a profile object into the list for a process or the system
+      */
+{
+  PKPROFILE current;
+  PLIST_ENTRY current_entry;
+
+  current_entry = ListHead;
+  while (current_entry != ListHead)
+    {
+      current = CONTAINING_RECORD(current_entry, KPROFILE, ListEntry);
+
+      if (current->Base > Profile->Base)
+	{
+	  Profile->ListEntry.Flink = current_entry;
+	  Profile->ListEntry.Blink = current_entry->Blink;
+	  current_entry->Blink->Flink = &Profile->ListEntry;
+	  current_entry->Blink = &Profile->ListEntry;
+	  return;
+	}
+
+      current_entry = current_entry->Flink;
+    }
+  InsertTailList(ListHead, &Profile->ListEntry);
+}
+
+VOID
+KiInsertProfile(PKPROFILE Profile)
+     /*
+      * Insert a profile into the relevant data structures
+      */
+{
+  KIRQL oldIrql;
+
+  KeAcquireSpinLock(&ProfileListLock, &oldIrql);
+
+  if (Profile->Process == NULL)
+    {
+      KiInsertProfileIntoProcess(&SystemProfileList, Profile);
+    }
+  else
+    {
+      ULONG Pid;
+      PKPROCESS_PROFILE current;
+      PLIST_ENTRY current_entry;
+      PLIST_ENTRY ListHead;
+
+      Pid = Profile->Process->UniqueProcessId;
+      ListHead = &ProcessProfileListHashTable[Pid % PROFILE_HASH_TABLE_SIZE];
+
+      current_entry = ListHead;
+      while(current_entry != ListHead)
+	{
+	  current = CONTAINING_RECORD(current_entry, KPROCESS_PROFILE, 
+				      ListEntry);
+
+	  if (current->Pid == (HANDLE)Pid)
+	    {
+	      KiInsertProfileIntoProcess(&current->ProfileListHead, Profile);
+	      KeReleaseSpinLock(&ProfileListLock, oldIrql);
+	      return;
+	    }
+
+	  current_entry = current_entry->Flink;
+	}
+
+      current = ExAllocatePool(NonPagedPool, sizeof(KPROCESS_PROFILE));
+
+      current->Pid = (HANDLE)Pid;
+      InitializeListHead(&current->ProfileListHead);
+      InsertTailList(ListHead, &current->ListEntry);
+
+      KiInsertProfileIntoProcess(&current->ProfileListHead, Profile);
+    }
+
+  KeReleaseSpinLock(&ProfileListLock, oldIrql);
+}
+
+VOID KiRemoveProfile(PKPROFILE Profile)
+{
+  KIRQL oldIrql;
+
+  KeAcquireSpinLock(&ProfileListLock, &oldIrql);
+
+  if (Profile->Process == NULL)
+    {
+      RemoveEntryList(&Profile->ListEntry);
+    }
+  else
+    {
+      ULONG Pid;
+      PLIST_ENTRY ListHead;
+      PKPROCESS_PROFILE current;
+      PLIST_ENTRY current_entry;
+      
+      RemoveEntryList(&Profile->ListEntry);
+
+      Pid = Profile->Process->UniqueProcessId;
+      ListHead = &ProcessProfileListHashTable[Pid % PROFILE_HASH_TABLE_SIZE];
+
+      current_entry = ListHead;
+      while(current_entry != ListHead)
+	{
+	  current = CONTAINING_RECORD(current_entry, KPROCESS_PROFILE, 
+				      ListEntry);
+
+	  if (current->Pid == (HANDLE)Pid)
+	    {
+	      if (IsListEmpty(&current->ProfileListHead))
+		{
+		  RemoveEntryList(&current->ListEntry);
+		  ExFreePool(current);
+		}
+	      KeReleaseSpinLock(&ProfileListLock, oldIrql);
+	      return;
+	    }
+
+	  current_entry = current_entry->Flink;
+	}
+      KEBUGCHECK(0);
+    }
+
+  KeReleaseSpinLock(&ProfileListLock, oldIrql);
+}
+
+VOID STDCALL
+KiDeleteProfile(PVOID ObjectBody)
+{
+  PKPROFILE Profile;
+
+  Profile = (PKPROFILE)ObjectBody;
+
+  KiRemoveProfile(Profile);
+  if (Profile->Process != NULL)
+    {
+      ObDereferenceObject(Profile->Process);
+      Profile->Process = NULL;
+    }
+
+  if (Profile->BufferMdl->MappedSystemVa != NULL)
+    {	     
+      MmUnmapLockedPages(Profile->BufferMdl->MappedSystemVa, 
+			 Profile->BufferMdl);
+    }
+  MmUnlockPages(Profile->BufferMdl);
+  ExFreePool(Profile->BufferMdl);
+  Profile->BufferMdl = NULL;
+}
+
 /*
  * @unimplemented
  */
Index: ntoskrnl/ke/main.c
===================================================================
--- ntoskrnl/ke/main.c	(revision 12839)
+++ ntoskrnl/ke/main.c	(working copy)
@@ -534,7 +534,6 @@
   IoInit();
   PoInit();
   CmInitializeRegistry();
-  NtInit();
   MmInit3();
   CcInit();
   KdInit2();
Index: ntoskrnl/Makefile.i386
===================================================================
--- ntoskrnl/Makefile.i386	(revision 12839)
+++ ntoskrnl/Makefile.i386	(working copy)
@@ -22,6 +22,7 @@
 	ke/i386/tskswitch.o \
 	ke/i386/v86m.o \
 	ke/i386/v86m_sup.o \
+	ke/i386/vdm.o \
 	ke/i386/bios.o \
 	ke/i386/i386-mcount.o \
 	ke/i386/gdt.o \
Index: ntoskrnl/ex/init.c
===================================================================
--- ntoskrnl/ex/init.c	(revision 12839)
+++ ntoskrnl/ex/init.c	(working copy)
@@ -44,6 +44,13 @@
 ExInit3 (VOID)
 {
   ExInitializeWorkerThreads();
+  ExpInitializeEventImplementation();
+  ExpInitializeEventPairImplementation();
+  ExpInitializeMutantImplementation();
+  ExpInitializeSemaphoreImplementation();
+  ExpInitializeTimerImplementation();
+  LpcpInitSystem();
+  ExpInitializeProfileImplementation();
   ExpWin32kInit();
   ExpInitUuids();
 }
Index: ntoskrnl/lpc/create.c
===================================================================
--- ntoskrnl/lpc/create.c	(revision 12839)
+++ ntoskrnl/lpc/create.c	(working copy)
@@ -159,7 +159,7 @@
       return (Status);
     }
 
-  Status = NiInitializePort (Port, EPORT_TYPE_SERVER_RQST_PORT, NULL);
+  Status = LpcpInitializePort (Port, EPORT_TYPE_SERVER_RQST_PORT, NULL);
   Port->MaxConnectInfoLength = PORT_MAX_DATA_LENGTH;
   Port->MaxDataLength = PORT_MAX_MESSAGE_LENGTH;
   Port->MaxPoolUsage = MaxPoolUsage;
Index: ntoskrnl/lpc/port.c
===================================================================
--- ntoskrnl/lpc/port.c	(revision 12839)
+++ ntoskrnl/lpc/port.c	(working copy)
@@ -35,7 +35,7 @@
 
 
 NTSTATUS INIT_FUNCTION
-NiInitPort (VOID)
+LpcpInitSystem (VOID)
 {
     /* Allocate Memory for the LPC Object */
     LpcPortObjectType = ExAllocatePool(NonPagedPool, sizeof(OBJECT_TYPE));
@@ -91,7 +91,7 @@
  *	otherwise.
  */
 NTSTATUS STDCALL
-NiInitializePort (IN OUT  PEPORT Port,
+LpcpInitializePort (IN OUT  PEPORT Port,
 		  IN      USHORT Type,
 		  IN      PEPORT Parent OPTIONAL)
 {
Index: ntoskrnl/lpc/connect.c
===================================================================
--- ntoskrnl/lpc/connect.c	(revision 12839)
+++ ntoskrnl/lpc/connect.c	(working copy)
@@ -78,7 +78,7 @@
     {
       return (Status);
     }
-  NiInitializePort(OurPort, EPORT_TYPE_CLIENT_COMM_PORT, NamedPort);
+  LpcpInitializePort(OurPort, EPORT_TYPE_CLIENT_COMM_PORT, NamedPort);
 
   /*
    * Allocate a request message.
@@ -592,7 +592,7 @@
 	  return(Status);
 	}
 
-      NiInitializePort(OurPort, EPORT_TYPE_SERVER_COMM_PORT, NamedPort);
+      LpcpInitializePort(OurPort, EPORT_TYPE_SERVER_COMM_PORT, NamedPort);
     }
 
   /*
