SM - clean, simplify, make more readable
authorEmanuele Aliberti <ea@iol.it>
Sat, 12 Feb 2005 09:08:52 +0000 (09:08 +0000)
committerEmanuele Aliberti <ea@iol.it>
Sat, 12 Feb 2005 09:08:52 +0000 (09:08 +0000)
- split initialization in more files to make it more readable
- cleaned up some code
- simplified some code
- documented some todos

svn path=/trunk/; revision=13500

17 files changed:
reactos/subsys/smss/client.c
reactos/subsys/smss/debug.c
reactos/subsys/smss/init.c
reactos/subsys/smss/initdosdev.c [new file with mode: 0644]
reactos/subsys/smss/initenv.c [new file with mode: 0644]
reactos/subsys/smss/initheap.c [new file with mode: 0644]
reactos/subsys/smss/initmv.c [new file with mode: 0644]
reactos/subsys/smss/initobdir.c [new file with mode: 0644]
reactos/subsys/smss/initpage.c [new file with mode: 0644]
reactos/subsys/smss/initreg.c [new file with mode: 0644]
reactos/subsys/smss/initrun.c [new file with mode: 0644]
reactos/subsys/smss/initss.c [new file with mode: 0644]
reactos/subsys/smss/initwkdll.c [new file with mode: 0644]
reactos/subsys/smss/makefile
reactos/subsys/smss/smapi.c
reactos/subsys/smss/smss.c
reactos/subsys/smss/smss.h

index def3407..b25535e 100644 (file)
@@ -25,7 +25,6 @@
  */\r
 #define NTOS_MODE_USER\r
 #include <ntos.h>\r
-#include <sm/api.h>\r
 #include "smss.h"\r
 \r
 /* Private ADT */\r
@@ -51,14 +50,37 @@ struct _SM_CLIENT_DIRECTORY
 } SmpClientDirectory;\r
 \r
 /**********************************************************************\r
- *     SmpInitializeClientManagement/0\r
+ *     SmInitializeClientManagement/0\r
  */\r
-VOID STDCALL\r
-SmpInitializeClientManagement (VOID)\r
+NTSTATUS\r
+SmInitializeClientManagement (VOID)\r
 {\r
        RtlInitializeCriticalSection(& SmpClientDirectory.Lock);\r
        SmpClientDirectory.Count = 0;\r
        SmpClientDirectory.Client = NULL;\r
+       return STATUS_SUCCESS;\r
+}\r
+\r
+/**********************************************************************\r
+ *     SmpLookupClient/1\r
+ */\r
+PSM_CLIENT_DATA STDCALL\r
+SmpLookupClient (USHORT SubsystemId)\r
+{\r
+       PSM_CLIENT_DATA Client = NULL;\r
+\r
+       if (SmpClientDirectory.Count > 0)\r
+       {\r
+               RtlEnterCriticalSection (& SmpClientDirectory.Lock);\r
+               Client = SmpClientDirectory.Client;\r
+               while (NULL != Client->Next)\r
+               {\r
+                       if (SubsystemId == Client->SubsystemId) break;\r
+                       Client = Client->Next;\r
+               }\r
+               RtlLeaveCriticalSection (& SmpClientDirectory.Lock);\r
+       }\r
+       return Client;\r
 }\r
 \r
 /**********************************************************************\r
@@ -69,6 +91,14 @@ SmpCreateClient(SM_PORT_MESSAGE Request)
 {\r
        PSM_CLIENT_DATA pClient = NULL;\r
 \r
+       /*\r
+        * Check if a client for the ID already exist.\r
+        */\r
+       if (SmpLookupClient(0)) //FIXME\r
+       {\r
+               DbgPrint("SMSS: %s: attempt to register again subsystem %d.\n",__FUNCTION__,0);\r
+               return STATUS_UNSUCCESSFUL;\r
+       }\r
        /*\r
         * Allocate the storage for client data\r
         */\r
@@ -79,6 +109,8 @@ SmpCreateClient(SM_PORT_MESSAGE Request)
        /*\r
         * Initialize the client data\r
         */\r
+//     pClient->SubsystemId = Request->Subsystem;\r
+       pClient->Initialized = FALSE;\r
        // TODO\r
        /*\r
         * Insert the new descriptor in the\r
index e199361..e7848df 100644 (file)
@@ -1,6 +1,6 @@
 /* $Id: smss.c 12852 2005-01-06 13:58:04Z mf $\r
  *\r
- * client.c - Session Manager client Management\r
+ * debug.c - Session Manager debug messages switch and router\r
  * \r
  * ReactOS Operating System\r
  * \r
@@ -36,8 +36,8 @@ HANDLE DbgUiApiPort = INVALID_HANDLE_VALUE;
 \r
 /* FUNCTIONS *********************************************************/\r
 \r
-NTSTATUS STDCALL\r
-SmpInitializeDbgSs (VOID)\r
+NTSTATUS\r
+SmInitializeDbgSs (VOID)\r
 {\r
   NTSTATUS Status;\r
   UNICODE_STRING UnicodeString;\r
index 83ce1e2..4b24771 100644 (file)
  * MA 02139, USA.  
  *
  * --------------------------------------------------------------------
- * 
- *     19990530 (Emanuele Aliberti)
- *             Compiled successfully with egcs 1.1.2
  */
 
-/* INCLUDES *****************************************************************/
-
-#include <ntos.h>
-#include <ntdll/rtl.h>
-#include <ntdll/ldr.h>
-#include <rosrtl/string.h>
-#include <sm/api.h>
 #include "smss.h"
+#include <rosrtl/string.h>
 
-#define NDEBUG
+//#define NDEBUG
 #include <debug.h>
 
-/* GLOBALS ******************************************************************/
-
-HANDLE SmpHeap = NULL;
-
-PWSTR SmSystemEnvironment = NULL;
-
 
 /* FUNCTIONS ****************************************************************/
 
-static NTSTATUS STDCALL
-SmObjectDirectoryQueryRoutine(PWSTR ValueName,
-                             ULONG ValueType,
-                             PVOID ValueData,
-                             ULONG ValueLength,
-                             PVOID Context,
-                             PVOID EntryContext)
-{
-  OBJECT_ATTRIBUTES ObjectAttributes;
-  UNICODE_STRING UnicodeString;
-  HANDLE WindowsDirectory;
-  NTSTATUS Status = STATUS_SUCCESS;
-
-#ifndef NDEBUG
-  DbgPrint("ValueName '%S'  Type %lu  Length %lu\n", ValueName, ValueType, ValueLength);
-  DbgPrint("ValueData '%S'\n", (PWSTR)ValueData);
-#endif
-  if (ValueType != REG_SZ)
-    {
-      return(STATUS_SUCCESS);
-    }
-
-  RtlInitUnicodeString(&UnicodeString,
-                      (PWSTR)ValueData);
-
-  InitializeObjectAttributes(&ObjectAttributes,
-                            &UnicodeString,
-                            0,
-                            NULL,
-                            NULL);
-
-  Status = ZwCreateDirectoryObject(&WindowsDirectory,
-                                  0,
-                                  &ObjectAttributes);
-
-  return(Status);
-}
-
-
-static NTSTATUS
-SmCreateObjectDirectories(VOID)
-{
-  RTL_QUERY_REGISTRY_TABLE QueryTable[2];
-  NTSTATUS Status;
-
-  RtlZeroMemory(&QueryTable,
-               sizeof(QueryTable));
-
-  QueryTable[0].Name = L"ObjectDirectories";
-  QueryTable[0].QueryRoutine = SmObjectDirectoryQueryRoutine;
-
-  Status = RtlQueryRegistryValues(RTL_REGISTRY_CONTROL,
-                                 L"\\Session Manager",
-                                 QueryTable,
-                                 NULL,
-                                 NULL);
-
-  return(Status);
-}
-
-
-static NTSTATUS STDCALL
-SmDosDevicesQueryRoutine(PWSTR ValueName,
-                        ULONG ValueType,
-                        PVOID ValueData,
-                        ULONG ValueLength,
-                        PVOID Context,
-                        PVOID EntryContext)
-{
-  OBJECT_ATTRIBUTES ObjectAttributes;
-  UNICODE_STRING DeviceName;
-  UNICODE_STRING LinkName;
-  HANDLE LinkHandle;
-  WCHAR LinkBuffer[80];
-  NTSTATUS Status;
-
-  DPRINT("ValueName '%S'  Type %lu  Length %lu\n", ValueName, ValueType, ValueLength);
-  DPRINT("ValueData '%S'\n", (PWSTR)ValueData);
-
-  if (ValueType != REG_SZ)
-    {
-      return(STATUS_SUCCESS);
-    }
-
-  swprintf(LinkBuffer,
-          L"\\??\\%s",
-          ValueName);
-  RtlInitUnicodeString(&LinkName,
-                      LinkBuffer);
-  RtlInitUnicodeString(&DeviceName,
-                      (PWSTR)ValueData);
-
-  DPRINT("SM: Linking %wZ --> %wZ\n",
-             &LinkName,
-             &DeviceName);
-
-  /* create symbolic link */
-  InitializeObjectAttributes(&ObjectAttributes,
-                            &LinkName,
-                            OBJ_PERMANENT,
-                            NULL,
-                            NULL);
-  Status = NtCreateSymbolicLinkObject(&LinkHandle,
-                                     SYMBOLIC_LINK_ALL_ACCESS,
-                                     &ObjectAttributes,
-                                     &DeviceName);
-  if (!NT_SUCCESS(Status))
-    {
-      DPRINT1("SmDosDevicesQueryRoutine: NtCreateSymbolicLink( %wZ --> %wZ ) failed!\n",
-                 &LinkName,
-                 &DeviceName);
-    }
-  NtClose(LinkHandle);
-
-  return(Status);
-}
-
-
-static NTSTATUS
-SmInitDosDevices(VOID)
-{
-  RTL_QUERY_REGISTRY_TABLE QueryTable[2];
-  NTSTATUS Status;
-
-  RtlZeroMemory(&QueryTable,
-               sizeof(QueryTable));
-
-  QueryTable[0].QueryRoutine = SmDosDevicesQueryRoutine;
-
-  Status = RtlQueryRegistryValues(RTL_REGISTRY_CONTROL,
-                                 L"\\Session Manager\\DOS Devices",
-                                 QueryTable,
-                                 NULL,
-                                 NULL);
-  return(Status);
-}
-
-
-static NTSTATUS STDCALL
-SmRunBootAppsQueryRoutine(PWSTR ValueName,
-                         ULONG ValueType,
-                         PVOID ValueData,
-                         ULONG ValueLength,
-                         PVOID Context,
-                         PVOID EntryContext)
-{
-  PRTL_USER_PROCESS_PARAMETERS ProcessParameters;
-  RTL_PROCESS_INFO ProcessInfo;
-  UNICODE_STRING ImagePathString;
-  UNICODE_STRING CommandLineString;
-  WCHAR Description[256];
-  WCHAR ImageName[256];
-  WCHAR ImagePath[256];
-  WCHAR CommandLine[256];
-  PWSTR p1, p2;
-  ULONG len;
-  NTSTATUS Status;
-
-  DPRINT("ValueName '%S'  Type %lu  Length %lu\n", ValueName, ValueType, ValueLength);
-  DPRINT("ValueData '%S'\n", (PWSTR)ValueData);
-
-  if (ValueType != REG_SZ)
-    {
-      return(STATUS_SUCCESS);
-    }
-
-  /* Extract the description */
-  p1 = wcschr((PWSTR)ValueData, L' ');
-  len = p1 - (PWSTR)ValueData;
-  memcpy(Description,ValueData, len * sizeof(WCHAR));
-  Description[len] = 0;
-
-  /* Extract the image name */
-  p1++;
-  p2 = wcschr(p1, L' ');
-  if (p2 != NULL)
-    len = p2 - p1;
-  else
-    len = wcslen(p1);
-  memcpy(ImageName, p1, len * sizeof(WCHAR));
-  ImageName[len] = 0;
-
-  /* Extract the command line */
-  if (p2 == NULL)
-    {
-      CommandLine[0] = 0;
-    }
-  else
-    {
-      p2++;
-      wcscpy(CommandLine, p2);
-    }
-
-  DPRINT("Running %S...\n", Description);
-  DPRINT("ImageName: '%S'\n", ImageName);
-  DPRINT("CommandLine: '%S'\n", CommandLine);
-
-  /* initialize executable path */
-  wcscpy(ImagePath, L"\\SystemRoot\\system32\\");
-  wcscat(ImagePath, ImageName);
-  wcscat(ImagePath, L".exe");
-
-  RtlInitUnicodeString(&ImagePathString,
-                      ImagePath);
-
-  RtlInitUnicodeString(&CommandLineString,
-                      CommandLine);
-
-  RtlCreateProcessParameters(&ProcessParameters,
-                            &ImagePathString,
-                            NULL,
-                            NULL,
-                            &CommandLineString,
-                            NULL,
-                            NULL,
-                            NULL,
-                            NULL,
-                            NULL);
-
-  Status = RtlCreateUserProcess(&ImagePathString,
-                               OBJ_CASE_INSENSITIVE,
-                               ProcessParameters,
-                               NULL,
-                               NULL,
-                               NULL,
-                               FALSE,
-                               NULL,
-                               NULL,
-                               &ProcessInfo);
-  if (!NT_SUCCESS(Status))
-    {
-      DPRINT1("Running %s failed (Status %lx)\n", Description, Status);
-      return(STATUS_SUCCESS);
-    }
-
-  RtlDestroyProcessParameters(ProcessParameters);
-
-  /* Wait for process termination */
-  NtWaitForSingleObject(ProcessInfo.ProcessHandle,
-                       FALSE,
-                       NULL);
-
-  NtClose(ProcessInfo.ThreadHandle);
-  NtClose(ProcessInfo.ProcessHandle);
-
-  return(STATUS_SUCCESS);
-}
-
-
-/*
- * Run native applications listed in the registry.
- *
- *  Key:
- *    \Registry\Machine\SYSTEM\CurrentControlSet\Control\Session Manager
- *
- *  Value (format: "<description> <executable> <command line>":
- *    BootExecute = "autocheck autochk *"
- */
-static NTSTATUS
-SmRunBootApps(VOID)
-{
-  RTL_QUERY_REGISTRY_TABLE QueryTable[2];
-  NTSTATUS Status;
-
-  RtlZeroMemory(&QueryTable,
-               sizeof(QueryTable));
-
-  QueryTable[0].Name = L"BootExecute";
-  QueryTable[0].QueryRoutine = SmRunBootAppsQueryRoutine;
-
-  Status = RtlQueryRegistryValues(RTL_REGISTRY_CONTROL,
-                                 L"\\Session Manager",
-                                 QueryTable,
-                                 NULL,
-                                 NULL);
-  if (!NT_SUCCESS(Status))
-    {
-      DPRINT1("SmRunBootApps: RtlQueryRegistryValues() failed! (Status %lx)\n", Status);
-    }
-
-  return(Status);
-}
-
-
-static NTSTATUS
-SmProcessFileRenameList(VOID)
-{
-  DPRINT("SmProcessFileRenameList() called\n");
-
-  /* FIXME: implement it! */
-
-  DPRINT("SmProcessFileRenameList() done\n");
-
-  return(STATUS_SUCCESS);
-}
-
-
-static NTSTATUS STDCALL
-SmKnownDllsQueryRoutine(PWSTR ValueName,
-                       ULONG ValueType,
-                       PVOID ValueData,
-                       ULONG ValueLength,
-                       PVOID Context,
-                       PVOID EntryContext)
-{
-  OBJECT_ATTRIBUTES ObjectAttributes;
-  IO_STATUS_BLOCK IoStatusBlock;
-  UNICODE_STRING ImageName;
-  HANDLE FileHandle;
-  HANDLE SectionHandle;
-  NTSTATUS Status;
-
-  DPRINT("ValueName '%S'  Type %lu  Length %lu\n", ValueName, ValueType, ValueLength);
-  DPRINT("ValueData '%S'  Context %p  EntryContext %p\n", (PWSTR)ValueData, Context, EntryContext);
-
-  /* Ignore the 'DllDirectory' value */
-  if (!_wcsicmp(ValueName, L"DllDirectory"))
-    return STATUS_SUCCESS;
-
-  /* Open the DLL image file */
-  RtlInitUnicodeString(&ImageName,
-                      ValueData);
-  InitializeObjectAttributes(&ObjectAttributes,
-                            &ImageName,
-                            OBJ_CASE_INSENSITIVE,
-                            (HANDLE)Context,
-                            NULL);
-  Status = NtOpenFile(&FileHandle,
-                     SYNCHRONIZE | FILE_EXECUTE,
-                     &ObjectAttributes,
-                     &IoStatusBlock,
-                     FILE_SHARE_READ,
-                     FILE_SYNCHRONOUS_IO_NONALERT | FILE_NON_DIRECTORY_FILE);
-  if (!NT_SUCCESS(Status))
-    {
-      DPRINT1("NtOpenFile() failed (Status %lx)\n", Status);
-      return STATUS_SUCCESS;
-    }
-
-  DPRINT("Opened file %wZ successfully\n", &ImageName);
-
-  /* Check for valid image checksum */
-  Status = LdrVerifyImageMatchesChecksum (FileHandle,
-                                         0,
-                                         0,
-                                         0);
-  if (Status == STATUS_IMAGE_CHECKSUM_MISMATCH)
-    {
-      /* Raise a hard error (crash the system/BSOD) */
-      NtRaiseHardError (Status,
-                       0,
-                       0,
-                       0,
-                       0,
-                       0);
-    }
-  else if (!NT_SUCCESS(Status))
-    {
-      DPRINT1("Failed to check the image checksum\n");
-
-      NtClose(SectionHandle);
-      NtClose(FileHandle);
-
-      return STATUS_SUCCESS;
-    }
-
-  InitializeObjectAttributes(&ObjectAttributes,
-                            &ImageName,
-                            OBJ_CASE_INSENSITIVE | OBJ_PERMANENT,
-                            (HANDLE)EntryContext,
-                            NULL);
-  Status = NtCreateSection(&SectionHandle,
-                          SECTION_ALL_ACCESS,
-                          &ObjectAttributes,
-                          NULL,
-                          PAGE_EXECUTE,
-                          SEC_IMAGE,
-                          FileHandle);
-  if (NT_SUCCESS(Status))
-    {
-      DPRINT("Created section successfully\n");
-      NtClose(SectionHandle);
-    }
-
-  NtClose(FileHandle);
-
-  return STATUS_SUCCESS;
-}
-
-
-static NTSTATUS
-SmLoadKnownDlls(VOID)
-{
-  RTL_QUERY_REGISTRY_TABLE QueryTable[2];
-  OBJECT_ATTRIBUTES ObjectAttributes;
-  IO_STATUS_BLOCK IoStatusBlock;
-  UNICODE_STRING DllDosPath;
-  UNICODE_STRING DllNtPath;
-  UNICODE_STRING Name;
-  HANDLE ObjectDirHandle;
-  HANDLE FileDirHandle;
-  HANDLE SymlinkHandle;
-  NTSTATUS Status;
-
-  DPRINT("SmLoadKnownDlls() called\n");
-
-  /* Create 'KnownDlls' object directory */
-  RtlInitUnicodeString(&Name,
-                      L"\\KnownDlls");
-  InitializeObjectAttributes(&ObjectAttributes,
-                            &Name,
-                            OBJ_PERMANENT | OBJ_CASE_INSENSITIVE | OBJ_OPENIF,
-                            NULL,
-                            NULL);
-  Status = NtCreateDirectoryObject(&ObjectDirHandle,
-                                  DIRECTORY_ALL_ACCESS,
-                                  &ObjectAttributes);
-  if (!NT_SUCCESS(Status))
-    {
-      DPRINT1("NtCreateDirectoryObject() failed (Status %lx)\n", Status);
-      return Status;
-    }
-
-  RtlInitUnicodeString(&DllDosPath, NULL);
-
-  RtlZeroMemory(&QueryTable,
-               sizeof(QueryTable));
-
-  QueryTable[0].Name = L"DllDirectory";
-  QueryTable[0].Flags = RTL_QUERY_REGISTRY_DIRECT;
-  QueryTable[0].EntryContext = &DllDosPath;
-
-  Status = RtlQueryRegistryValues(RTL_REGISTRY_CONTROL,
-                                 L"\\Session Manager\\KnownDlls",
-                                 QueryTable,
-                                 NULL,
-                                 SmSystemEnvironment);
-  if (!NT_SUCCESS(Status))
-    {
-      DPRINT1("RtlQueryRegistryValues() failed (Status %lx)\n", Status);
-      return Status;
-    }
-
-  DPRINT("DllDosPath: '%wZ'\n", &DllDosPath);
-
-  if (!RtlDosPathNameToNtPathName_U(DllDosPath.Buffer,
-                                   &DllNtPath,
-                                   NULL,
-                                   NULL))
-    {
-      DPRINT1("RtlDosPathNameToNtPathName_U() failed\n");
-      return STATUS_OBJECT_NAME_INVALID;
-    }
-
-  DPRINT("DllNtPath: '%wZ'\n", &DllNtPath);
-
-  /* Open the dll path directory */
-  InitializeObjectAttributes(&ObjectAttributes,
-                            &DllNtPath,
-                            OBJ_CASE_INSENSITIVE,
-                            NULL,
-                            NULL);
-  Status = NtOpenFile(&FileDirHandle,
-                     SYNCHRONIZE | FILE_READ_DATA,
-                     &ObjectAttributes,
-                     &IoStatusBlock,
-                     FILE_SHARE_READ | FILE_SHARE_WRITE,
-                     FILE_SYNCHRONOUS_IO_NONALERT | FILE_DIRECTORY_FILE);
-  if (!NT_SUCCESS(Status))
-    {
-      DPRINT1("NtOpenFile(%wZ) failed (Status %lx)\n", &DllNtPath, Status);
-      return Status;
-    }
-
-  /* Link 'KnownDllPath' the dll path directory */
-  RtlInitUnicodeString(&Name,
-                      L"KnownDllPath");
-  InitializeObjectAttributes(&ObjectAttributes,
-                            &Name,
-                            OBJ_PERMANENT | OBJ_CASE_INSENSITIVE | OBJ_OPENIF,
-                            ObjectDirHandle,
-                            NULL);
-  Status = NtCreateSymbolicLinkObject(&SymlinkHandle,
-                                     SYMBOLIC_LINK_ALL_ACCESS,
-                                     &ObjectAttributes,
-                                     &DllDosPath);
-  if (!NT_SUCCESS(Status))
-    {
-      DPRINT1("NtCreateSymbolicLink() failed (Status %lx)\n", Status);
-      return Status;
-    }
-
-  NtClose(SymlinkHandle);
-
-  RtlZeroMemory(&QueryTable,
-               sizeof(QueryTable));
-
-  QueryTable[0].QueryRoutine = SmKnownDllsQueryRoutine;
-  QueryTable[0].EntryContext = ObjectDirHandle;
-
-  Status = RtlQueryRegistryValues(RTL_REGISTRY_CONTROL,
-                                 L"\\Session Manager\\KnownDlls",
-                                 QueryTable,
-                                 (PVOID)FileDirHandle,
-                                 NULL);
-  if (!NT_SUCCESS(Status))
-    {
-      DPRINT1("RtlQueryRegistryValues() failed (Status %lx)\n", Status);
-    }
-
-  DPRINT("SmLoadKnownDlls() done\n");
-
-  return Status;
-}
-
-
-static NTSTATUS STDCALL
-SmPagingFilesQueryRoutine(PWSTR ValueName,
-                         ULONG ValueType,
-                         PVOID ValueData,
-                         ULONG ValueLength,
-                         PVOID Context,
-                         PVOID EntryContext)
-{
-  UNICODE_STRING FileName;
-  LARGE_INTEGER InitialSize;
-  LARGE_INTEGER MaximumSize;
-  NTSTATUS Status;
-  LPWSTR p;
-
-  DPRINT("ValueName '%S'  Type %lu  Length %lu\n", ValueName, ValueType, ValueLength);
-  DPRINT("ValueData '%S'\n", (PWSTR)ValueData);
-
-  if (ValueType != REG_SZ)
-    {
-      return(STATUS_SUCCESS);
-    }
-
-  /*
-   * Format: "<path>[ <initial_size>[ <maximum_size>]]"
-   */
-  if ((p = wcschr(ValueData, ' ')) != NULL)
-    {
-      *p = L'\0';
-      InitialSize.QuadPart = wcstoul(p + 1, &p, 0) * 256 * 4096;
-      if (*p == ' ')
-       {
-         MaximumSize.QuadPart = wcstoul(p + 1, NULL, 0) * 256 * 4096;
-       }
-      else
-       MaximumSize = InitialSize;
-    }
-  else
-    {
-      InitialSize.QuadPart = 50 * 4096;
-      MaximumSize.QuadPart = 80 * 4096;
-    }
-
-  if (!RtlDosPathNameToNtPathName_U ((LPWSTR)ValueData,
-                                    &FileName,
-                                    NULL,
-                                    NULL))
-    {
-      return (STATUS_SUCCESS);
-    }
-
-  DPRINT("SMSS: Created paging file %wZ with size %dKB\n",
-        &FileName, InitialSize.QuadPart / 1024);
-  Status = NtCreatePagingFile(&FileName,
-                             &InitialSize,
-                             &MaximumSize,
-                             0);
-
-  RtlFreeUnicodeString(&FileName);
-
-  return(STATUS_SUCCESS);
-}
-
-
 static NTSTATUS
-SmCreatePagingFiles(VOID)
-{
-  RTL_QUERY_REGISTRY_TABLE QueryTable[2];
-  NTSTATUS Status;
-
-  /*
-   * Disable paging file on MiniNT/Live CD.
-   */
-  if (RtlCheckRegistryKey(RTL_REGISTRY_CONTROL, L"MiniNT") == STATUS_SUCCESS)
-    {
-      return STATUS_SUCCESS;
-    }
-
-  RtlZeroMemory(&QueryTable,
-               sizeof(QueryTable));
-
-  QueryTable[0].Name = L"PagingFiles";
-  QueryTable[0].QueryRoutine = SmPagingFilesQueryRoutine;
-
-  Status = RtlQueryRegistryValues(RTL_REGISTRY_CONTROL,
-                                 L"\\Session Manager\\Memory Management",
-                                 QueryTable,
-                                 NULL,
-                                 NULL);
-
-  return(Status);
-}
-
-
-static NTSTATUS STDCALL
-SmEnvironmentQueryRoutine(PWSTR ValueName,
-                         ULONG ValueType,
-                         PVOID ValueData,
-                         ULONG ValueLength,
-                         PVOID Context,
-                         PVOID EntryContext)
-{
-  UNICODE_STRING EnvVariable;
-  UNICODE_STRING EnvValue;
-
-  DPRINT("ValueName '%S'  Type %lu  Length %lu\n", ValueName, ValueType, ValueLength);
-  DPRINT("ValueData '%S'\n", (PWSTR)ValueData);
-
-  if (ValueType != REG_SZ)
-    {
-      return(STATUS_SUCCESS);
-    }
-
-  RtlInitUnicodeString(&EnvVariable,
-                      ValueName);
-  RtlInitUnicodeString(&EnvValue,
-                      (PWSTR)ValueData);
-  RtlSetEnvironmentVariable(Context,
-                           &EnvVariable,
-                           &EnvValue);
-
-  return(STATUS_SUCCESS);
-}
-
-
-static NTSTATUS
-SmSetEnvironmentVariables(VOID)
-{
-  RTL_QUERY_REGISTRY_TABLE QueryTable[2];
-  UNICODE_STRING EnvVariable;
-  UNICODE_STRING EnvValue;
-  WCHAR ValueBuffer[MAX_PATH];
-  NTSTATUS Status;
-
-  /*
-   * The following environment variables must be set prior to reading
-   * other variables from the registry.
-   *
-   * Variables (example):
-   *    SystemRoot = "C:\reactos"
-   *    SystemDrive = "C:"
-   */
-
-  /* Copy system root into value buffer */
-  wcscpy(ValueBuffer,
-        SharedUserData->NtSystemRoot);
-
-  /* Set SystemRoot = "C:\reactos" */
-  RtlRosInitUnicodeStringFromLiteral(&EnvVariable,
-                      L"SystemRoot");
-  RtlInitUnicodeString(&EnvValue,
-                      ValueBuffer);
-  RtlSetEnvironmentVariable(&SmSystemEnvironment,
-                           &EnvVariable,
-                           &EnvValue);
-
-  /* Cut off trailing path */
-  ValueBuffer[2] = 0;
-
-  /* Set SystemDrive = "C:" */
-  RtlRosInitUnicodeStringFromLiteral(&EnvVariable,
-                      L"SystemDrive");
-  RtlInitUnicodeString(&EnvValue,
-                      ValueBuffer);
-  RtlSetEnvironmentVariable(&SmSystemEnvironment,
-                           &EnvVariable,
-                           &EnvValue);
-
-  /* Read system environment from the registry. */
-  RtlZeroMemory(&QueryTable,
-               sizeof(QueryTable));
-
-  QueryTable[0].QueryRoutine = SmEnvironmentQueryRoutine;
-
-  Status = RtlQueryRegistryValues(RTL_REGISTRY_CONTROL,
-                                 L"\\Session Manager\\Environment",
-                                 QueryTable,
-                                 &SmSystemEnvironment,
-                                 SmSystemEnvironment);
-
-  return(Status);
-}
-
-
-static NTSTATUS
-SmLoadSubsystems(VOID)
-{
-  SYSTEM_LOAD_AND_CALL_IMAGE ImageInfo;
-  NTSTATUS Status;
-
-  /* Load kernel mode subsystem (aka win32k.sys) */
-  RtlRosInitUnicodeStringFromLiteral(&ImageInfo.ModuleName,
-                      L"\\SystemRoot\\system32\\win32k.sys");
-
-  Status = NtSetSystemInformation(SystemLoadAndCallImage,
-                                 &ImageInfo,
-                                 sizeof(SYSTEM_LOAD_AND_CALL_IMAGE));
-
-  DPRINT("SMSS: Loaded win32k.sys (Status %lx)\n", Status);
-#if 0
-  if (!NT_SUCCESS(Status))
-    {
-      return(Status);
-    }
-#endif
-
-  /* FIXME: load more subsystems (csrss!) */
-
-  return(Status);
-}
-
-
-static VOID
-SignalInitEvent()
+SmpSignalInitEvent(VOID)
 {
   NTSTATUS Status;
   OBJECT_ATTRIBUTES ObjectAttributes;
@@ -809,269 +67,58 @@ SignalInitEvent()
       /* We don't really care if this fails */
       DPRINT1("SM: Failed to open ReactOS init notification event\n");
     }
+  return Status;
 }
 
+typedef NTSTATUS (* SM_INIT_ROUTINE)(VOID);
+
+struct {
+       BOOL Required;
+       SM_INIT_ROUTINE EntryPoint;
+       PCHAR ErrorMessage;
+} InitRoutine [] = {
+       {TRUE,  SmCreateHeap,                 "create private heap, aborting"},
+       {TRUE,  SmCreateObjectDirectories,    "create object directories"},
+       {TRUE,  SmCreateApiPort,              "create \\SmApiPort"},
+       {TRUE,  SmCreateEnvironment,          "create the system environment"},
+       {TRUE,  SmSetEnvironmentVariables,    "set system environment variables"},
+       {TRUE,  SmInitDosDevices,             "create dos device links"},
+       {TRUE,  SmRunBootApplications,        "run boot applications"},
+       {TRUE,  SmProcessFileRenameList,      "process the file rename list"},
+       {FALSE, SmLoadKnownDlls,              "preload system DLLs"},
+       {TRUE,  SmCreatePagingFiles,          "create paging files"},
+       {TRUE,  SmInitializeRegistry,         "initialize the registry"},
+       {FALSE, SmUpdateEnvironment,          "update environment variables"},
+       {TRUE,  SmInitializeClientManagement, "initialize client management"},
+       {TRUE,  SmLoadSubsystems,             "load subsystems"},
+       {FALSE, SmpSignalInitEvent,           "open ReactOS init notification event"},
+       {TRUE,  SmRunCsrss,                   "run csrss"},
+       {TRUE,  SmRunWinlogon,                "run winlogon"},
+       {TRUE,  SmInitializeDbgSs,            "initialize DbgSs"}
+};
 
 NTSTATUS
 InitSessionManager(HANDLE Children[])
 {
+  int i;
   NTSTATUS Status;
-  UNICODE_STRING UnicodeString;
-  OBJECT_ATTRIBUTES ObjectAttributes;
-  PRTL_USER_PROCESS_PARAMETERS ProcessParameters;
-  RTL_PROCESS_INFO ProcessInfo;
-  HANDLE CsrssInitEvent;
-  WCHAR UnicodeBuffer[MAX_PATH];
-
-  /* Create our own heap */
-  SmpHeap = RtlCreateHeap(HEAP_GROWABLE,
-                          NULL,
-                          65536,
-                          65536,
-                          NULL,
-                          NULL);
-  if (NULL == SmpHeap)
-    {
-      DbgPrint("SMSS: %s: failed to create private heap, aborting\n",__FUNCTION__);
-      return STATUS_UNSUCCESSFUL;
-    }
-
 
-  /* Create object directories */
-  Status = SmCreateObjectDirectories();
-  if (!NT_SUCCESS(Status))
+  for (i=0; i < (sizeof InitRoutine / sizeof InitRoutine[0]); i++)
+  {
+    Status = InitRoutine[i].EntryPoint();
+    if(!NT_SUCCESS(Status))
     {
-      DPRINT1("SM: Failed to create object directories (Status %lx)\n", Status);
-      return(Status);
+      DPRINT1("SM: %s: failed to %s (Status=%lx)\n", 
+       __FUNCTION__,
+       InitRoutine[i].ErrorMessage,
+       Status);
+      if (InitRoutine[i].Required)
+      {
+        return(Status);
+      }
     }
+  }
 
-  /* Create the \SmApiPort object (LPC) */
-  Status = SmpCreateApiPort();
-  if (!NT_SUCCESS(Status))
-    {
-      DPRINT1("SM: Failed to create SmApiPort (Status %lx)\n", Status);
-      return(Status);
-    }
-
-  /* Create the system environment */
-  Status = RtlCreateEnvironment(FALSE,
-                               &SmSystemEnvironment);
-  if (!NT_SUCCESS(Status))
-    {
-      DPRINT1("SM: Failed to create the system environment (Status %lx)\n", Status);
-      return(Status);
-    }
-
-  /* Set environment variables */
-  Status = SmSetEnvironmentVariables();
-  if (!NT_SUCCESS(Status))
-    {
-      DPRINT1("SM: Failed to set system environment variables (Status %lx)\n", Status);
-      return(Status);
-    }
-
-  /* Define symbolic links to kernel devices (MS-DOS names) */
-  Status = SmInitDosDevices();
-  if (!NT_SUCCESS(Status))
-    {
-      DPRINT1("SM: Failed to create dos device links (Status %lx)\n", Status);
-      return(Status);
-    }
-
-  /* Run all programs in the boot execution list */
-  Status = SmRunBootApps();
-  if (!NT_SUCCESS(Status))
-    {
-      DPRINT1("SM: Failed to run boot applications (Status %lx)\n", Status);
-      return(Status);
-    }
-
-  /* Process the file rename list */
-  Status = SmProcessFileRenameList();
-  if (!NT_SUCCESS(Status))
-    {
-      DPRINT1("SM: Failed to process the file rename list (Status %lx)\n", Status);
-      return(Status);
-    }
-
-  DPRINT("SM: loading well-known DLLs\n");
-
-  /* Load the well known DLLs */
-  Status = SmLoadKnownDlls();
-  if (!NT_SUCCESS(Status))
-    {
-      DPRINT1("SM: Failed to preload system DLLs (Status %lx)\n", Status);
-      /* Don't crash ReactOS if DLLs cannot be loaded */
-    }
-
-  DPRINT("SM: creating system paging files\n");
-
-  /* Create paging files */
-  Status = SmCreatePagingFiles();
-  if (!NT_SUCCESS(Status))
-    {
-      DPRINT1("SM: Failed to create paging files (Status %lx)\n", Status);
-      return(Status);
-    }
-
-  DPRINT("SM: initializing registry\n");
-
-  /* Load remaining registry hives */
-  NtInitializeRegistry(FALSE);
-
-  /* Set environment variables from registry */
-#if 0
-  Status = SmUpdateEnvironment();
-  if (!NT_SUCCESS(Status))
-    {
-      DPRINT1("SM: Failed to update environment variables (Status %lx)\n", Status);
-      return(Status);
-    }
-#endif
-
-  /*
-   * Initialize SM client management:
-   * this MUST be done before any
-   * subsystem server is run.
-   */
-  SmpInitializeClientManagement();
-
-  DPRINT("SM: loading subsystems\n");
-
-  /* Load the subsystems */
-  Status = SmLoadSubsystems();
-  if (!NT_SUCCESS(Status))
-    {
-      DPRINT1("SM: Failed to load subsystems (Status %lx)\n", Status);
-      return(Status);
-    }
-
-
-  SignalInitEvent();
-
-
-  DPRINT("SM: initializing csrss\n");
-
-  /* Run csrss.exe */
-  RtlRosInitUnicodeStringFromLiteral(&UnicodeString,
-                                 L"\\CsrssInitDone");
-  InitializeObjectAttributes(&ObjectAttributes,
-                            &UnicodeString,
-                            EVENT_ALL_ACCESS,
-                            0,
-                            NULL);
-  Status = NtCreateEvent(&CsrssInitEvent,
-                        EVENT_ALL_ACCESS,
-                        &ObjectAttributes,
-                        NotificationEvent,
-                        FALSE);
-  if (!NT_SUCCESS(Status))
-    {
-      DbgPrint("Failed to create csrss notification event\n");
-    }
-
-  /*
-   * Start the Win32 subsystem (csrss.exe)
-   */
-
-  /* initialize executable path */
-  wcscpy(UnicodeBuffer, L"\\??\\");
-  wcscat(UnicodeBuffer, SharedUserData->NtSystemRoot);
-  wcscat(UnicodeBuffer, L"\\system32\\csrss.exe");
-  RtlInitUnicodeString(&UnicodeString,
-                      UnicodeBuffer);
-
-  RtlCreateProcessParameters(&ProcessParameters,
-                            &UnicodeString,
-                            NULL,
-                            NULL,
-                            NULL,
-                            SmSystemEnvironment,
-                            NULL,
-                            NULL,
-                            NULL,
-                            NULL);
-
-  Status = RtlCreateUserProcess(&UnicodeString,
-                               OBJ_CASE_INSENSITIVE,
-                               ProcessParameters,
-                               NULL,
-                               NULL,
-                               NULL,
-                               FALSE,
-                               NULL,
-                               NULL,
-                               &ProcessInfo);
-
-  RtlDestroyProcessParameters (ProcessParameters);
-
-  if (!NT_SUCCESS(Status))
-    {
-      DisplayString(L"SM: Loading csrss.exe failed!\n");
-      return(Status);
-    }
-
-  NtWaitForSingleObject(CsrssInitEvent,
-                       FALSE,
-                       NULL);
-
-  Children[CHILD_CSRSS] = ProcessInfo.ProcessHandle;
-
-  /*
-   * Start the logon process (winlogon.exe)
-   */
-
-  DPRINT("SM: starting winlogon\n");
-
-  /* initialize executable path */
-  wcscpy(UnicodeBuffer, L"\\??\\");
-  wcscat(UnicodeBuffer, SharedUserData->NtSystemRoot);
-  wcscat(UnicodeBuffer, L"\\system32\\winlogon.exe");
-  RtlInitUnicodeString(&UnicodeString,
-                      UnicodeBuffer);
-
-  RtlCreateProcessParameters(&ProcessParameters,
-                            &UnicodeString,
-                            NULL,
-                            NULL,
-                            NULL,
-                            SmSystemEnvironment,
-                            NULL,
-                            NULL,
-                            NULL,
-                            NULL);
-
-  Status = RtlCreateUserProcess(&UnicodeString,
-                               OBJ_CASE_INSENSITIVE,
-                               ProcessParameters,
-                               NULL,
-                               NULL,
-                               NULL,
-                               FALSE,
-                               NULL,
-                               NULL,
-                               &ProcessInfo);
-
-  RtlDestroyProcessParameters(ProcessParameters);
-
-  if (!NT_SUCCESS(Status))
-    {
-      DisplayString(L"SM: Loading winlogon.exe failed!\n");
-      NtTerminateProcess(Children[CHILD_CSRSS],
-                        0);
-      return(Status);
-    }
-  Children[CHILD_WINLOGON] = ProcessInfo.ProcessHandle;
-
-  /* Initialize the DBGSS */
-  Status = SmpInitializeDbgSs();
-  if (!NT_SUCCESS(Status))
-    {
-      DisplayString(L"SM: DbgSs initialization failed!\n");
-      NtTerminateProcess(Children[CHILD_WINLOGON],0);
-      NtTerminateProcess(Children[CHILD_CSRSS],0);
-      return(Status);
-    }
 
   return(STATUS_SUCCESS);
 }
diff --git a/reactos/subsys/smss/initdosdev.c b/reactos/subsys/smss/initdosdev.c
new file mode 100644 (file)
index 0000000..7103ff6
--- /dev/null
@@ -0,0 +1,109 @@
+/* $Id: init.c 13449 2005-02-06 21:55:07Z ea $\r
+ *\r
+ * initdosdev.c - Define symbolic links to kernel devices (MS-DOS names)\r
+ * \r
+ * ReactOS Operating System\r
+ * \r
+ * --------------------------------------------------------------------\r
+ *\r
+ * This software is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License as\r
+ * published by the Free Software Foundation; either version 2 of the\r
+ * License, or (at your option) any later version.\r
+ *\r
+ * This software is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
+ * General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this software; see the file COPYING.LIB. If not, write\r
+ * to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge,\r
+ * MA 02139, USA.  \r
+ *\r
+ * --------------------------------------------------------------------\r
+ */\r
+\r
+#include "smss.h"\r
+\r
+//#define NDEBUG\r
+#include <debug.h>\r
+\r
+static NTSTATUS STDCALL\r
+SmpDosDevicesQueryRoutine(PWSTR ValueName,\r
+                        ULONG ValueType,\r
+                        PVOID ValueData,\r
+                        ULONG ValueLength,\r
+                        PVOID Context,\r
+                        PVOID EntryContext)\r
+{\r
+  OBJECT_ATTRIBUTES ObjectAttributes;\r
+  UNICODE_STRING DeviceName;\r
+  UNICODE_STRING LinkName;\r
+  HANDLE LinkHandle;\r
+  WCHAR LinkBuffer[80];\r
+  NTSTATUS Status;\r
+\r
+  DPRINT("ValueName '%S'  Type %lu  Length %lu\n", ValueName, ValueType, ValueLength);\r
+  DPRINT("ValueData '%S'\n", (PWSTR)ValueData);\r
+\r
+  if (ValueType != REG_SZ)\r
+    {\r
+      return(STATUS_SUCCESS);\r
+    }\r
+\r
+  swprintf(LinkBuffer,\r
+          L"\\??\\%s",\r
+          ValueName);\r
+  RtlInitUnicodeString(&LinkName,\r
+                      LinkBuffer);\r
+  RtlInitUnicodeString(&DeviceName,\r
+                      (PWSTR)ValueData);\r
+\r
+  DPRINT("SM: Linking %wZ --> %wZ\n",\r
+             &LinkName,\r
+             &DeviceName);\r
+\r
+  /* create symbolic link */\r
+  InitializeObjectAttributes(&ObjectAttributes,\r
+                            &LinkName,\r
+                            OBJ_PERMANENT,\r
+                            NULL,\r
+                            NULL);\r
+  Status = NtCreateSymbolicLinkObject(&LinkHandle,\r
+                                     SYMBOLIC_LINK_ALL_ACCESS,\r
+                                     &ObjectAttributes,\r
+                                     &DeviceName);\r
+  if (!NT_SUCCESS(Status))\r
+    {\r
+      DPRINT1("%s: NtCreateSymbolicLink( %wZ --> %wZ ) failed!\n",\r
+                 __FUNCTION__,\r
+                 &LinkName,\r
+                 &DeviceName);\r
+    }\r
+  NtClose(LinkHandle);\r
+\r
+  return(Status);\r
+}\r
+\r
+\r
+NTSTATUS\r
+SmInitDosDevices(VOID)\r
+{\r
+  RTL_QUERY_REGISTRY_TABLE QueryTable[2];\r
+  NTSTATUS Status;\r
+\r
+  RtlZeroMemory(&QueryTable,\r
+               sizeof(QueryTable));\r
+\r
+  QueryTable[0].QueryRoutine = SmpDosDevicesQueryRoutine;\r
+\r
+  Status = RtlQueryRegistryValues(RTL_REGISTRY_CONTROL,\r
+                                 L"\\Session Manager\\DOS Devices",\r
+                                 QueryTable,\r
+                                 NULL,\r
+                                 NULL);\r
+  return(Status);\r
+}\r
+\r
+/* EOF */\r
diff --git a/reactos/subsys/smss/initenv.c b/reactos/subsys/smss/initenv.c
new file mode 100644 (file)
index 0000000..e9d5135
--- /dev/null
@@ -0,0 +1,139 @@
+/* $Id: init.c 13449 2005-02-06 21:55:07Z ea $\r
+ *\r
+ * initenv.c - Environment initialization\r
+ * \r
+ * ReactOS Operating System\r
+ * \r
+ * --------------------------------------------------------------------\r
+ *\r
+ * This software is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License as\r
+ * published by the Free Software Foundation; either version 2 of the\r
+ * License, or (at your option) any later version.\r
+ *\r
+ * This software is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
+ * General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this software; see the file COPYING.LIB. If not, write\r
+ * to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge,\r
+ * MA 02139, USA.  \r
+ *\r
+ * --------------------------------------------------------------------\r
+ */\r
+\r
+#include "smss.h"\r
+\r
+//#define NDEBUG\r
+#include <debug.h>\r
+\r
+/* GLOBALS */\r
+\r
+PWSTR SmSystemEnvironment = NULL;\r
+\r
+\r
+/* FUNCTIONS */\r
+\r
+NTSTATUS \r
+SmCreateEnvironment(VOID)\r
+{\r
+  return RtlCreateEnvironment(FALSE, &SmSystemEnvironment);\r
+}\r
+\r
+\r
+static NTSTATUS\r
+SmpSetEnvironmentVariable(PVOID Context,\r
+                         PWSTR ValueName,\r
+                         PVOID ValueData)\r
+{\r
+  UNICODE_STRING EnvVariable;\r
+  UNICODE_STRING EnvValue;\r
+\r
+  RtlInitUnicodeString(&EnvVariable,\r
+                      ValueName);\r
+  RtlInitUnicodeString(&EnvValue,\r
+                      (PWSTR)ValueData);\r
+  RtlSetEnvironmentVariable(Context,\r
+                           &EnvVariable,\r
+                           &EnvValue);\r
+\r
+  return(STATUS_SUCCESS);\r
+}\r
+\r
+\r
+static NTSTATUS STDCALL\r
+SmpEnvironmentQueryRoutine(PWSTR ValueName,\r
+                         ULONG ValueType,\r
+                         PVOID ValueData,\r
+                         ULONG ValueLength,\r
+                         PVOID Context,\r
+                         PVOID EntryContext)\r
+{\r
+  DPRINT("ValueName '%S'  Type %lu  Length %lu\n", ValueName, ValueType, ValueLength);\r
+  DPRINT("ValueData '%S'\n", (PWSTR)ValueData);\r
+\r
+  if (ValueType != REG_SZ)\r
+    {\r
+      return(STATUS_SUCCESS);\r
+    }\r
+  return SmpSetEnvironmentVariable(Context,ValueName,ValueData);\r
+}\r
+\r
+\r
+NTSTATUS\r
+SmSetEnvironmentVariables(VOID)\r
+{\r
+  RTL_QUERY_REGISTRY_TABLE QueryTable[2];\r
+  WCHAR ValueBuffer[MAX_PATH];\r
+  NTSTATUS Status;\r
+\r
+  /*\r
+   * The following environment variables must be set prior to reading\r
+   * other variables from the registry.\r
+   *\r
+   * Variables (example):\r
+   *    SystemRoot = "C:\reactos"\r
+   *    SystemDrive = "C:"\r
+   */\r
+\r
+  /* Copy system root into value buffer */\r
+  wcscpy(ValueBuffer,\r
+        SharedUserData->NtSystemRoot);\r
+\r
+  /* Set SystemRoot = "C:\reactos" */\r
+  SmpSetEnvironmentVariable(&SmSystemEnvironment,L"SystemRoot",ValueBuffer);\r
+\r
+  /* Cut off trailing path */\r
+  ValueBuffer[2] = 0;\r
+\r
+  /* Set SystemDrive = "C:" */\r
+  SmpSetEnvironmentVariable(&SmSystemEnvironment,L"SystemDrive",ValueBuffer);\r
+\r
+  /* Read system environment from the registry. */\r
+  RtlZeroMemory(&QueryTable,\r
+               sizeof(QueryTable));\r
+\r
+  QueryTable[0].QueryRoutine = SmpEnvironmentQueryRoutine;\r
+\r
+  Status = RtlQueryRegistryValues(RTL_REGISTRY_CONTROL,\r
+                                 L"\\Session Manager\\Environment",\r
+                                 QueryTable,\r
+                                 &SmSystemEnvironment,\r
+                                 SmSystemEnvironment);\r
+\r
+  return(Status);\r
+}\r
+\r
+/**********************************************************************\r
+ *  Set environment variables from registry\r
+ */\r
+NTSTATUS\r
+SmUpdateEnvironment(VOID)\r
+{\r
+       /* TODO */\r
+       return STATUS_SUCCESS;\r
+}\r
+\r
+/* EOF */\r
diff --git a/reactos/subsys/smss/initheap.c b/reactos/subsys/smss/initheap.c
new file mode 100644 (file)
index 0000000..3d5ec19
--- /dev/null
@@ -0,0 +1,47 @@
+/* $Id: init.c 13449 2005-02-06 21:55:07Z ea $\r
+ *\r
+ * initenv.c - Create the SM private heap\r
+ * \r
+ * ReactOS Operating System\r
+ * \r
+ * --------------------------------------------------------------------\r
+ *\r
+ * This software is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License as\r
+ * published by the Free Software Foundation; either version 2 of the\r
+ * License, or (at your option) any later version.\r
+ *\r
+ * This software is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
+ * General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this software; see the file COPYING.LIB. If not, write\r
+ * to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge,\r
+ * MA 02139, USA.  \r
+ *\r
+ * --------------------------------------------------------------------\r
+ */\r
+\r
+#include "smss.h"\r
+\r
+//#define NDEBUG\r
+#include <debug.h>\r
+\r
+HANDLE SmpHeap = NULL;\r
+\r
+NTSTATUS\r
+SmCreateHeap(VOID)\r
+{\r
+  /* Create our own heap */\r
+  SmpHeap = RtlCreateHeap(HEAP_GROWABLE,\r
+                          NULL,\r
+                          65536,\r
+                          65536,\r
+                          NULL,\r
+                          NULL);\r
+  return (NULL == SmpHeap) ? STATUS_UNSUCCESSFUL : STATUS_SUCCESS;\r
+}\r
+\r
+/* EOF */\r
diff --git a/reactos/subsys/smss/initmv.c b/reactos/subsys/smss/initmv.c
new file mode 100644 (file)
index 0000000..71878f8
--- /dev/null
@@ -0,0 +1,44 @@
+/* $Id: init.c 13449 2005-02-06 21:55:07Z ea $\r
+ *\r
+ * initmv.c - Process the file rename list\r
+ * \r
+ * ReactOS Operating System\r
+ * \r
+ * --------------------------------------------------------------------\r
+ *\r
+ * This software is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License as\r
+ * published by the Free Software Foundation; either version 2 of the\r
+ * License, or (at your option) any later version.\r
+ *\r
+ * This software is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
+ * General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this software; see the file COPYING.LIB. If not, write\r
+ * to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge,\r
+ * MA 02139, USA.  \r
+ *\r
+ * --------------------------------------------------------------------\r
+ */\r
+\r
+#include "smss.h"\r
+\r
+//#define NDEBUG\r
+#include <debug.h>\r
+\r
+NTSTATUS\r
+SmProcessFileRenameList(VOID)\r
+{\r
+  DPRINT("SmProcessFileRenameList() called\n");\r
+\r
+  /* FIXME: implement it! */\r
+\r
+  DPRINT("SmProcessFileRenameList() done\n");\r
+\r
+  return(STATUS_SUCCESS);\r
+}\r
+\r
+/* EOF */\r
diff --git a/reactos/subsys/smss/initobdir.c b/reactos/subsys/smss/initobdir.c
new file mode 100644 (file)
index 0000000..8557051
--- /dev/null
@@ -0,0 +1,93 @@
+/* $Id: init.c 13449 2005-02-06 21:55:07Z ea $\r
+ *\r
+ * initobdir.c - Session Manager object directories\r
+ * \r
+ * ReactOS Operating System\r
+ * \r
+ * --------------------------------------------------------------------\r
+ *\r
+ * This software is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License as\r
+ * published by the Free Software Foundation; either version 2 of the\r
+ * License, or (at your option) any later version.\r
+ *\r
+ * This software is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
+ * General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this software; see the file COPYING.LIB. If not, write\r
+ * to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge,\r
+ * MA 02139, USA.  \r
+ *\r
+ * --------------------------------------------------------------------\r
+ */\r
+\r
+\r
+#include "smss.h"\r
+\r
+//#define NDEBUG\r
+#include <debug.h>\r
+\r
+static NTSTATUS STDCALL\r
+SmpObjectDirectoryQueryRoutine(PWSTR ValueName,\r
+                             ULONG ValueType,\r
+                             PVOID ValueData,\r
+                             ULONG ValueLength,\r
+                             PVOID Context,\r
+                             PVOID EntryContext)\r
+{\r
+  OBJECT_ATTRIBUTES ObjectAttributes;\r
+  UNICODE_STRING UnicodeString;\r
+  HANDLE WindowsDirectory;\r
+  NTSTATUS Status = STATUS_SUCCESS;\r
+\r
+#ifndef NDEBUG\r
+  DbgPrint("ValueName '%S'  Type %lu  Length %lu\n", ValueName, ValueType, ValueLength);\r
+  DbgPrint("ValueData '%S'\n", (PWSTR)ValueData);\r
+#endif\r
+  if (ValueType != REG_SZ)\r
+    {\r
+      return(STATUS_SUCCESS);\r
+    }\r
+\r
+  RtlInitUnicodeString(&UnicodeString,\r
+                      (PWSTR)ValueData);\r
+\r
+  InitializeObjectAttributes(&ObjectAttributes,\r
+                            &UnicodeString,\r
+                            0,\r
+                            NULL,\r
+                            NULL);\r
+\r
+  Status = ZwCreateDirectoryObject(&WindowsDirectory,\r
+                                  0,\r
+                                  &ObjectAttributes);\r
+\r
+  return(Status);\r
+}\r
+\r
+\r
+NTSTATUS\r
+SmCreateObjectDirectories(VOID)\r
+{\r
+  RTL_QUERY_REGISTRY_TABLE QueryTable[2];\r
+  NTSTATUS Status;\r
+\r
+  RtlZeroMemory(&QueryTable,\r
+               sizeof(QueryTable));\r
+\r
+  QueryTable[0].Name = L"ObjectDirectories";\r
+  QueryTable[0].QueryRoutine = SmpObjectDirectoryQueryRoutine;\r
+\r
+  Status = RtlQueryRegistryValues(RTL_REGISTRY_CONTROL,\r
+                                 L"\\Session Manager",\r
+                                 QueryTable,\r
+                                 NULL,\r
+                                 NULL);\r
+\r
+  return(Status);\r
+}\r
+\r
+/* EOF */\r
diff --git a/reactos/subsys/smss/initpage.c b/reactos/subsys/smss/initpage.c
new file mode 100644 (file)
index 0000000..c5e1785
--- /dev/null
@@ -0,0 +1,127 @@
+/* $Id: init.c 13449 2005-02-06 21:55:07Z ea $\r
+ *\r
+ * initpage.c - \r
+ * \r
+ * ReactOS Operating System\r
+ * \r
+ * --------------------------------------------------------------------\r
+ *\r
+ * This software is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License as\r
+ * published by the Free Software Foundation; either version 2 of the\r
+ * License, or (at your option) any later version.\r
+ *\r
+ * This software is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
+ * General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this software; see the file COPYING.LIB. If not, write\r
+ * to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge,\r
+ * MA 02139, USA.  \r
+ *\r
+ * --------------------------------------------------------------------\r
+ */\r
+#include "smss.h"\r
+#include <rosrtl/string.h>\r
+#include <wchar.h>\r
+\r
+//#define NDEBUG\r
+#include <debug.h>\r
+\r
+static NTSTATUS STDCALL\r
+SmpPagingFilesQueryRoutine(PWSTR ValueName,\r
+                         ULONG ValueType,\r
+                         PVOID ValueData,\r
+                         ULONG ValueLength,\r
+                         PVOID Context,\r
+                         PVOID EntryContext)\r
+{\r
+  UNICODE_STRING FileName;\r
+  LARGE_INTEGER InitialSize;\r
+  LARGE_INTEGER MaximumSize;\r
+  NTSTATUS Status;\r
+  LPWSTR p;\r
+\r
+  DPRINT("ValueName '%S'  Type %lu  Length %lu\n", ValueName, ValueType, ValueLength);\r
+  DPRINT("ValueData '%S'\n", (PWSTR)ValueData);\r
+\r
+  if (ValueType != REG_SZ)\r
+    {\r
+      return(STATUS_SUCCESS);\r
+    }\r
+\r
+  /*\r
+   * Format: "<path>[ <initial_size>[ <maximum_size>]]"\r
+   */\r
+  if ((p = wcschr(ValueData, ' ')) != NULL)\r
+    {\r
+      *p = L'\0';\r
+      InitialSize.QuadPart = wcstoul(p + 1, &p, 0) * 256 * 4096;\r
+      if (*p == ' ')\r
+       {\r
+         MaximumSize.QuadPart = wcstoul(p + 1, NULL, 0) * 256 * 4096;\r
+       }\r
+      else\r
+       MaximumSize = InitialSize;\r
+    }\r
+  else\r
+    {\r
+      InitialSize.QuadPart = 50 * 4096;\r
+      MaximumSize.QuadPart = 80 * 4096;\r
+    }\r
+\r
+  if (!RtlDosPathNameToNtPathName_U ((LPWSTR)ValueData,\r
+                                    &FileName,\r
+                                    NULL,\r
+                                    NULL))\r
+    {\r
+      return (STATUS_SUCCESS);\r
+    }\r
+\r
+  DPRINT("SMSS: Created paging file %wZ with size %dKB\n",\r
+        &FileName, InitialSize.QuadPart / 1024);\r
+  Status = NtCreatePagingFile(&FileName,\r
+                             &InitialSize,\r
+                             &MaximumSize,\r
+                             0);\r
+\r
+  RtlFreeUnicodeString(&FileName);\r
+\r
+  return(STATUS_SUCCESS);\r
+}\r
+\r
+\r
+NTSTATUS\r
+SmCreatePagingFiles(VOID)\r
+{\r
+  RTL_QUERY_REGISTRY_TABLE QueryTable[2];\r
+  NTSTATUS Status;\r
+\r
+  DPRINT("SM: creating system paging files\n");\r
+  /*\r
+   * Disable paging file on MiniNT/Live CD.\r
+   */\r
+  if (RtlCheckRegistryKey(RTL_REGISTRY_CONTROL, L"MiniNT") == STATUS_SUCCESS)\r
+    {\r
+      return STATUS_SUCCESS;\r
+    }\r
+\r
+  RtlZeroMemory(&QueryTable,\r
+               sizeof(QueryTable));\r
+\r
+  QueryTable[0].Name = L"PagingFiles";\r
+  QueryTable[0].QueryRoutine = SmpPagingFilesQueryRoutine;\r
+\r
+  Status = RtlQueryRegistryValues(RTL_REGISTRY_CONTROL,\r
+                                 L"\\Session Manager\\Memory Management",\r
+                                 QueryTable,\r
+                                 NULL,\r
+                                 NULL);\r
+\r
+  return(Status);\r
+}\r
+\r
+\r
+/* EOF */\r
diff --git a/reactos/subsys/smss/initreg.c b/reactos/subsys/smss/initreg.c
new file mode 100644 (file)
index 0000000..7feab51
--- /dev/null
@@ -0,0 +1,41 @@
+/* $Id: init.c 13449 2005-02-06 21:55:07Z ea $\r
+ *\r
+ * initenv.c - Environment initialization\r
+ * \r
+ * ReactOS Operating System\r
+ * \r
+ * --------------------------------------------------------------------\r
+ *\r
+ * This software is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License as\r
+ * published by the Free Software Foundation; either version 2 of the\r
+ * License, or (at your option) any later version.\r
+ *\r
+ * This software is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
+ * General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this software; see the file COPYING.LIB. If not, write\r
+ * to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge,\r
+ * MA 02139, USA.  \r
+ *\r
+ * --------------------------------------------------------------------\r
+ */\r
+\r
+#include "smss.h"\r
+\r
+//#define NDEBUG\r
+#include <debug.h>\r
+\r
+NTSTATUS\r
+SmInitializeRegistry(VOID)\r
+{\r
+  DPRINT("SM: %s: initializing registry\n", __FUNCTION__);\r
+\r
+  /* Load remaining registry hives */\r
+  return NtInitializeRegistry(FALSE);\r
+}\r
+\r
+/* EOF */\r
diff --git a/reactos/subsys/smss/initrun.c b/reactos/subsys/smss/initrun.c
new file mode 100644 (file)
index 0000000..eb09646
--- /dev/null
@@ -0,0 +1,183 @@
+/* $Id: init.c 13449 2005-02-06 21:55:07Z ea $\r
+ *\r
+ * initrun.c - Run all programs in the boot execution list\r
+ * \r
+ * ReactOS Operating System\r
+ * \r
+ * --------------------------------------------------------------------\r
+ *\r
+ * This software is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License as\r
+ * published by the Free Software Foundation; either version 2 of the\r
+ * License, or (at your option) any later version.\r
+ *\r
+ * This software is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
+ * General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this software; see the file COPYING.LIB. If not, write\r
+ * to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge,\r
+ * MA 02139, USA.  \r
+ *\r
+ * --------------------------------------------------------------------\r
+ */\r
+\r
+#include "smss.h"\r
+\r
+//#define NDEBUG\r
+#include <debug.h>\r
+\r
+HANDLE Children[2] = {0, 0}; /* csrss, winlogon */\r
+\r
+\r
+static NTSTATUS STDCALL\r
+SmpRunBootAppsQueryRoutine(PWSTR ValueName,\r
+                         ULONG ValueType,\r
+                         PVOID ValueData,\r
+                         ULONG ValueLength,\r
+                         PVOID Context,\r
+                         PVOID EntryContext)\r
+{\r
+  PRTL_USER_PROCESS_PARAMETERS ProcessParameters;\r
+  RTL_PROCESS_INFO ProcessInfo;\r
+  UNICODE_STRING ImagePathString;\r
+  UNICODE_STRING CommandLineString;\r
+  WCHAR Description[256];\r
+  WCHAR ImageName[256];\r
+  WCHAR ImagePath[256];\r
+  WCHAR CommandLine[256];\r
+  PWSTR p1, p2;\r
+  ULONG len;\r
+  NTSTATUS Status;\r
+\r
+  DPRINT("ValueName '%S'  Type %lu  Length %lu\n", ValueName, ValueType, ValueLength);\r
+  DPRINT("ValueData '%S'\n", (PWSTR)ValueData);\r
+\r
+  if (ValueType != REG_SZ)\r
+    {\r
+      return(STATUS_SUCCESS);\r
+    }\r
+\r
+  /* Extract the description */\r
+  p1 = wcschr((PWSTR)ValueData, L' ');\r
+  len = p1 - (PWSTR)ValueData;\r
+  memcpy(Description,ValueData, len * sizeof(WCHAR));\r
+  Description[len] = 0;\r
+\r
+  /* Extract the image name */\r
+  p1++;\r
+  p2 = wcschr(p1, L' ');\r
+  if (p2 != NULL)\r
+    len = p2 - p1;\r
+  else\r
+    len = wcslen(p1);\r
+  memcpy(ImageName, p1, len * sizeof(WCHAR));\r
+  ImageName[len] = 0;\r
+\r
+  /* Extract the command line */\r
+  if (p2 == NULL)\r
+    {\r
+      CommandLine[0] = 0;\r
+    }\r
+  else\r
+    {\r
+      p2++;\r
+      wcscpy(CommandLine, p2);\r
+    }\r
+\r
+  DPRINT("Running %S...\n", Description);\r
+  DPRINT("ImageName: '%S'\n", ImageName);\r
+  DPRINT("CommandLine: '%S'\n", CommandLine);\r
+\r
+  /* initialize executable path */\r
+  wcscpy(ImagePath, L"\\SystemRoot\\system32\\");\r
+  wcscat(ImagePath, ImageName);\r
+  wcscat(ImagePath, L".exe");\r
+\r
+  RtlInitUnicodeString(&ImagePathString,\r
+                      ImagePath);\r
+\r
+  RtlInitUnicodeString(&CommandLineString,\r
+                      CommandLine);\r
+\r
+  RtlCreateProcessParameters(&ProcessParameters,\r
+                            &ImagePathString,\r
+                            NULL,\r
+                            NULL,\r
+                            &CommandLineString,\r
+                            NULL,\r
+                            NULL,\r
+                            NULL,\r
+                            NULL,\r
+                            NULL);\r
+\r
+  Status = RtlCreateUserProcess(&ImagePathString,\r
+                               OBJ_CASE_INSENSITIVE,\r
+                               ProcessParameters,\r
+                               NULL,\r
+                               NULL,\r
+                               NULL,\r
+                               FALSE,\r
+                               NULL,\r
+                               NULL,\r
+                               &ProcessInfo);\r
+  if (!NT_SUCCESS(Status))\r
+    {\r
+      DPRINT1("Running %s failed (Status %lx)\n", Description, Status);\r
+      return(STATUS_SUCCESS);\r
+    }\r
+\r
+  RtlDestroyProcessParameters(ProcessParameters);\r
+\r
+  /* Wait for process termination */\r
+  NtWaitForSingleObject(ProcessInfo.ProcessHandle,\r
+                       FALSE,\r
+                       NULL);\r
+\r
+  NtClose(ProcessInfo.ThreadHandle);\r
+  NtClose(ProcessInfo.ProcessHandle);\r
+\r
+  return(STATUS_SUCCESS);\r
+}\r
+\r
+\r
+/*\r
+ * Run native applications listed in the registry.\r
+ *\r
+ *  Key:\r
+ *    \Registry\Machine\SYSTEM\CurrentControlSet\Control\Session Manager\r
+ *\r
+ *  Value (format: "<description> <executable> <command line>":\r
+ *    BootExecute = "autocheck autochk *"\r
+ */\r
+NTSTATUS\r
+SmRunBootApplications(VOID)\r
+{\r
+  RTL_QUERY_REGISTRY_TABLE QueryTable[2];\r
+  NTSTATUS Status;\r
+\r
+  RtlZeroMemory(&QueryTable,\r
+               sizeof(QueryTable));\r
+\r
+  QueryTable[0].Name = L"BootExecute";\r
+  QueryTable[0].QueryRoutine = SmpRunBootAppsQueryRoutine;\r
+\r
+  Status = RtlQueryRegistryValues(RTL_REGISTRY_CONTROL,\r
+                                 L"\\Session Manager",\r
+                                 QueryTable,\r
+                                 NULL,\r
+                                 NULL);\r
+  if (!NT_SUCCESS(Status))\r
+    {\r
+      DPRINT1("%s: RtlQueryRegistryValues() failed! (Status %lx)\n", \r
+       __FUNCTION__,\r
+       Status);\r
+    }\r
+\r
+  return(Status);\r
+}\r
+\r
+\r
+/* EOF */\r
diff --git a/reactos/subsys/smss/initss.c b/reactos/subsys/smss/initss.c
new file mode 100644 (file)
index 0000000..6894c13
--- /dev/null
@@ -0,0 +1,220 @@
+/* $Id: init.c 13449 2005-02-06 21:55:07Z ea $\r
+ *\r
+ * initss.c - Load the subsystems\r
+ * \r
+ * ReactOS Operating System\r
+ * \r
+ * --------------------------------------------------------------------\r
+ *\r
+ * This software is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License as\r
+ * published by the Free Software Foundation; either version 2 of the\r
+ * License, or (at your option) any later version.\r
+ *\r
+ * This software is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
+ * General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this software; see the file COPYING.LIB. If not, write\r
+ * to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge,\r
+ * MA 02139, USA.  \r
+ *\r
+ * --------------------------------------------------------------------\r
+ */\r
+\r
+\r
+#include "smss.h"\r
+#include <rosrtl/string.h>\r
+\r
+//#define NDEBUG\r
+#include <debug.h>\r
+\r
+/* TODO: this file should be totally rewritten\r
+ *\r
+ * a) look if a special option is set for smss.exe in\r
+ *    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\r
+ *\r
+ * b) make smss register with itself for IMAGE_SUBSYSTEM_NATIVE\r
+ *    (programmatically)\r
+ *\r
+ * c) make smss load win32k.sys as set in Kmode key\r
+ *    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\SubSystems\r
+ *\r
+ * d) make smss initialize Debug (DBGSS) and Windows (CSRSS) as described\r
+ *    in the registry key Required="Debug Windows"\r
+ *    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\SubSystems\r
+ *\r
+ * e) make optional subsystems loadable (again: they must be described in the registry\r
+ *    key Optional="Posix Os2" to be allowed to run)\r
+ */\r
+NTSTATUS\r
+SmLoadSubsystems(VOID)\r
+{\r
+  SYSTEM_LOAD_AND_CALL_IMAGE ImageInfo;\r
+  NTSTATUS Status;\r
+\r
+  DPRINT("SM: loading subsystems\n");\r
+\r
+  /* Load kernel mode subsystem (aka win32k.sys) */\r
+  RtlRosInitUnicodeStringFromLiteral(&ImageInfo.ModuleName,\r
+                      L"\\SystemRoot\\system32\\win32k.sys");\r
+\r
+  Status = NtSetSystemInformation(SystemLoadAndCallImage,\r
+                                 &ImageInfo,\r
+                                 sizeof(SYSTEM_LOAD_AND_CALL_IMAGE));\r
+\r
+  DPRINT("SMSS: Loaded win32k.sys (Status %lx)\n", Status);\r
+#if 0\r
+  if (!NT_SUCCESS(Status))\r
+    {\r
+      return(Status);\r
+    }\r
+#endif\r
+\r
+  /* FIXME: load more subsystems (csrss!) */\r
+\r
+  return(Status);\r
+}\r
+\r
+NTSTATUS\r
+SmRunCsrss(VOID)\r
+{\r
+  NTSTATUS Status;\r
+  UNICODE_STRING UnicodeString;\r
+  OBJECT_ATTRIBUTES ObjectAttributes;\r
+  PRTL_USER_PROCESS_PARAMETERS ProcessParameters;\r
+  RTL_PROCESS_INFO ProcessInfo;\r
+  HANDLE CsrssInitEvent;\r
+  WCHAR UnicodeBuffer[MAX_PATH];\r
+\r
+  DPRINT("SM: initializing csrss\n");\r
+\r
+  /* Run csrss.exe */\r
+  RtlRosInitUnicodeStringFromLiteral(&UnicodeString,\r
+                                 L"\\CsrssInitDone");\r
+  InitializeObjectAttributes(&ObjectAttributes,\r
+                            &UnicodeString,\r
+                            EVENT_ALL_ACCESS,\r
+                            0,\r
+                            NULL);\r
+  Status = NtCreateEvent(&CsrssInitEvent,\r
+                        EVENT_ALL_ACCESS,\r
+                        &ObjectAttributes,\r
+                        NotificationEvent,\r
+                        FALSE);\r
+  if (!NT_SUCCESS(Status))\r
+    {\r
+      DbgPrint("Failed to create csrss notification event\n");\r
+    }\r
+\r
+  /*\r
+   * Start the Win32 subsystem (csrss.exe)\r
+   */\r
+\r
+  /* initialize executable path */\r
+  wcscpy(UnicodeBuffer, L"\\??\\");\r
+  wcscat(UnicodeBuffer, SharedUserData->NtSystemRoot);\r
+  wcscat(UnicodeBuffer, L"\\system32\\csrss.exe");\r
+  RtlInitUnicodeString(&UnicodeString,\r
+                      UnicodeBuffer);\r
+\r
+  RtlCreateProcessParameters(&ProcessParameters,\r
+                            &UnicodeString,\r
+                            NULL,\r
+                            NULL,\r
+                            NULL,\r
+                            SmSystemEnvironment,\r
+                            NULL,\r
+                            NULL,\r
+                            NULL,\r
+                            NULL);\r
+\r
+  Status = RtlCreateUserProcess(&UnicodeString,\r
+                               OBJ_CASE_INSENSITIVE,\r
+                               ProcessParameters,\r
+                               NULL,\r
+                               NULL,\r
+                               NULL,\r
+                               FALSE,\r
+                               NULL,\r
+                               NULL,\r
+                               &ProcessInfo);\r
+\r
+  RtlDestroyProcessParameters (ProcessParameters);\r
+\r
+  if (!NT_SUCCESS(Status))\r
+    {\r
+      DPRINT("SM: %s: Loading csrss.exe failed!\n", __FUNCTION__);\r
+      return(Status);\r
+    }\r
+\r
+  Status = NtWaitForSingleObject(CsrssInitEvent,\r
+                       FALSE,\r
+                       NULL);\r
+\r
+  Children[CHILD_CSRSS] = ProcessInfo.ProcessHandle;\r
+\r
+  return Status;\r
+}\r
+\r
+NTSTATUS\r
+SmRunWinlogon(VOID)\r
+{\r
+  NTSTATUS Status;\r
+  UNICODE_STRING UnicodeString;\r
+  PRTL_USER_PROCESS_PARAMETERS ProcessParameters;\r
+  RTL_PROCESS_INFO ProcessInfo;\r
+  WCHAR UnicodeBuffer[MAX_PATH];\r
+\r
+  /*\r
+   * Start the logon process (winlogon.exe)\r
+   */\r
+\r
+  DPRINT("SM: starting winlogon\n");\r
+\r
+  /* initialize executable path */\r
+  wcscpy(UnicodeBuffer, L"\\??\\");\r
+  wcscat(UnicodeBuffer, SharedUserData->NtSystemRoot);\r
+  wcscat(UnicodeBuffer, L"\\system32\\winlogon.exe");\r
+  RtlInitUnicodeString(&UnicodeString,\r
+                      UnicodeBuffer);\r
+\r
+  RtlCreateProcessParameters(&ProcessParameters,\r
+                            &UnicodeString,\r
+                            NULL,\r
+                            NULL,\r
+                            NULL,\r
+                            SmSystemEnvironment,\r
+                            NULL,\r
+                            NULL,\r
+                            NULL,\r
+                            NULL);\r
+\r
+  Status = RtlCreateUserProcess(&UnicodeString,\r
+                               OBJ_CASE_INSENSITIVE,\r
+                               ProcessParameters,\r
+                               NULL,\r
+                               NULL,\r
+                               NULL,\r
+                               FALSE,\r
+                               NULL,\r
+                               NULL,\r
+                               &ProcessInfo);\r
+\r
+  RtlDestroyProcessParameters(ProcessParameters);\r
+\r
+  if (!NT_SUCCESS(Status))\r
+    {\r
+      DPRINT("SM: %s: Loading winlogon.exe failed!\n", __FUNCTION__);\r
+      NtTerminateProcess(Children[CHILD_CSRSS],\r
+                        0);\r
+      return(Status);\r
+    }\r
+  Children[CHILD_WINLOGON] = ProcessInfo.ProcessHandle;\r
+\r
+  return Status;\r
+}\r
+\r
+/* EOF */\r
diff --git a/reactos/subsys/smss/initwkdll.c b/reactos/subsys/smss/initwkdll.c
new file mode 100644 (file)
index 0000000..ed67dbc
--- /dev/null
@@ -0,0 +1,254 @@
+/* $Id: init.c 13449 2005-02-06 21:55:07Z ea $\r
+ *\r
+ * initwkdll.c - Load the well known DLLs\r
+ * \r
+ * ReactOS Operating System\r
+ * \r
+ * --------------------------------------------------------------------\r
+ *\r
+ * This software is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License as\r
+ * published by the Free Software Foundation; either version 2 of the\r
+ * License, or (at your option) any later version.\r
+ *\r
+ * This software is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
+ * General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this software; see the file COPYING.LIB. If not, write\r
+ * to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge,\r
+ * MA 02139, USA.  \r
+ *\r
+ * --------------------------------------------------------------------\r
+ */\r
+\r
+#include "smss.h"\r
+\r
+//#define NDEBUG\r
+#include <debug.h>\r
+\r
+static NTSTATUS STDCALL\r
+SmpKnownDllsQueryRoutine(PWSTR ValueName,\r
+                       ULONG ValueType,\r
+                       PVOID ValueData,\r
+                       ULONG ValueLength,\r
+                       PVOID Context,\r
+                       PVOID EntryContext)\r
+{\r
+  OBJECT_ATTRIBUTES ObjectAttributes;\r
+  IO_STATUS_BLOCK IoStatusBlock;\r
+  UNICODE_STRING ImageName;\r
+  HANDLE FileHandle;\r
+  HANDLE SectionHandle;\r
+  NTSTATUS Status;\r
+\r
+  DPRINT("ValueName '%S'  Type %lu  Length %lu\n", ValueName, ValueType, ValueLength);\r
+  DPRINT("ValueData '%S'  Context %p  EntryContext %p\n", (PWSTR)ValueData, Context, EntryContext);\r
+\r
+  /* Ignore the 'DllDirectory' value */\r
+  if (!_wcsicmp(ValueName, L"DllDirectory"))\r
+    return STATUS_SUCCESS;\r
+\r
+  /* Open the DLL image file */\r
+  RtlInitUnicodeString(&ImageName,\r
+                      ValueData);\r
+  InitializeObjectAttributes(&ObjectAttributes,\r
+                            &ImageName,\r
+                            OBJ_CASE_INSENSITIVE,\r
+                            (HANDLE)Context,\r
+                            NULL);\r
+  Status = NtOpenFile(&FileHandle,\r
+                     SYNCHRONIZE | FILE_EXECUTE,\r
+                     &ObjectAttributes,\r
+                     &IoStatusBlock,\r
+                     FILE_SHARE_READ,\r
+                     FILE_SYNCHRONOUS_IO_NONALERT | FILE_NON_DIRECTORY_FILE);\r
+  if (!NT_SUCCESS(Status))\r
+    {\r
+      DPRINT1("NtOpenFile() failed (Status %lx)\n", Status);\r
+      return STATUS_SUCCESS;\r
+    }\r
+\r
+  DPRINT("Opened file %wZ successfully\n", &ImageName);\r
+\r
+  /* Check for valid image checksum */\r
+  Status = LdrVerifyImageMatchesChecksum (FileHandle,\r
+                                         0,\r
+                                         0,\r
+                                         0);\r
+  if (Status == STATUS_IMAGE_CHECKSUM_MISMATCH)\r
+    {\r
+      /* Raise a hard error (crash the system/BSOD) */\r
+      NtRaiseHardError (Status,\r
+                       0,\r
+                       0,\r
+                       0,\r
+                       0,\r
+                       0);\r
+    }\r
+  else if (!NT_SUCCESS(Status))\r
+    {\r
+      DPRINT1("Failed to check the image checksum\n");\r
+\r
+      NtClose(SectionHandle);\r
+      NtClose(FileHandle);\r
+\r
+      return STATUS_SUCCESS;\r
+    }\r
+\r
+  InitializeObjectAttributes(&ObjectAttributes,\r
+                            &ImageName,\r
+                            OBJ_CASE_INSENSITIVE | OBJ_PERMANENT,\r
+                            (HANDLE)EntryContext,\r
+                            NULL);\r
+  Status = NtCreateSection(&SectionHandle,\r
+                          SECTION_ALL_ACCESS,\r
+                          &ObjectAttributes,\r
+                          NULL,\r
+                          PAGE_EXECUTE,\r
+                          SEC_IMAGE,\r
+                          FileHandle);\r
+  if (NT_SUCCESS(Status))\r
+    {\r
+      DPRINT("Created section successfully\n");\r
+      NtClose(SectionHandle);\r
+    }\r
+\r
+  NtClose(FileHandle);\r
+\r
+  return STATUS_SUCCESS;\r
+}\r
+\r
+\r
+NTSTATUS\r
+SmLoadKnownDlls(VOID)\r
+{\r
+  RTL_QUERY_REGISTRY_TABLE QueryTable[2];\r
+  OBJECT_ATTRIBUTES ObjectAttributes;\r
+  IO_STATUS_BLOCK IoStatusBlock;\r
+  UNICODE_STRING DllDosPath;\r
+  UNICODE_STRING DllNtPath;\r
+  UNICODE_STRING Name;\r
+  HANDLE ObjectDirHandle;\r
+  HANDLE FileDirHandle;\r
+  HANDLE SymlinkHandle;\r
+  NTSTATUS Status;\r
+\r
+\r
+  DPRINT("SM: loading well-known DLLs\n");\r
+\r
+  DPRINT("SmLoadKnownDlls() called\n");\r
+\r
+  /* Create 'KnownDlls' object directory */\r
+  RtlInitUnicodeString(&Name,\r
+                      L"\\KnownDlls");\r
+  InitializeObjectAttributes(&ObjectAttributes,\r
+                            &Name,\r
+                            OBJ_PERMANENT | OBJ_CASE_INSENSITIVE | OBJ_OPENIF,\r
+                            NULL,\r
+                            NULL);\r
+  Status = NtCreateDirectoryObject(&ObjectDirHandle,\r
+                                  DIRECTORY_ALL_ACCESS,\r
+                                  &ObjectAttributes);\r
+  if (!NT_SUCCESS(Status))\r
+    {\r
+      DPRINT1("NtCreateDirectoryObject() failed (Status %lx)\n", Status);\r
+      return Status;\r
+    }\r
+\r
+  RtlInitUnicodeString(&DllDosPath, NULL);\r
+\r
+  RtlZeroMemory(&QueryTable,\r
+               sizeof(QueryTable));\r
+\r
+  QueryTable[0].Name = L"DllDirectory";\r
+  QueryTable[0].Flags = RTL_QUERY_REGISTRY_DIRECT;\r
+  QueryTable[0].EntryContext = &DllDosPath;\r
+\r
+  Status = RtlQueryRegistryValues(RTL_REGISTRY_CONTROL,\r
+                                 L"\\Session Manager\\KnownDlls",\r
+                                 QueryTable,\r
+                                 NULL,\r
+                                 SmSystemEnvironment);\r
+  if (!NT_SUCCESS(Status))\r
+    {\r
+      DPRINT1("RtlQueryRegistryValues() failed (Status %lx)\n", Status);\r
+      return Status;\r
+    }\r
+\r
+  DPRINT("DllDosPath: '%wZ'\n", &DllDosPath);\r
+\r
+  if (!RtlDosPathNameToNtPathName_U(DllDosPath.Buffer,\r
+                                   &DllNtPath,\r
+                                   NULL,\r
+                                   NULL))\r
+    {\r
+      DPRINT1("RtlDosPathNameToNtPathName_U() failed\n");\r
+      return STATUS_OBJECT_NAME_INVALID;\r
+    }\r
+\r
+  DPRINT("DllNtPath: '%wZ'\n", &DllNtPath);\r
+\r
+  /* Open the dll path directory */\r
+  InitializeObjectAttributes(&ObjectAttributes,\r
+                            &DllNtPath,\r
+                            OBJ_CASE_INSENSITIVE,\r
+                            NULL,\r
+                            NULL);\r
+  Status = NtOpenFile(&FileDirHandle,\r
+                     SYNCHRONIZE | FILE_READ_DATA,\r
+                     &ObjectAttributes,\r
+                     &IoStatusBlock,\r
+                     FILE_SHARE_READ | FILE_SHARE_WRITE,\r
+                     FILE_SYNCHRONOUS_IO_NONALERT | FILE_DIRECTORY_FILE);\r
+  if (!NT_SUCCESS(Status))\r
+    {\r
+      DPRINT1("NtOpenFile(%wZ) failed (Status %lx)\n", &DllNtPath, Status);\r
+      return Status;\r
+    }\r
+\r
+  /* Link 'KnownDllPath' the dll path directory */\r
+  RtlInitUnicodeString(&Name,\r
+                      L"KnownDllPath");\r
+  InitializeObjectAttributes(&ObjectAttributes,\r
+                            &Name,\r
+                            OBJ_PERMANENT | OBJ_CASE_INSENSITIVE | OBJ_OPENIF,\r
+                            ObjectDirHandle,\r
+                            NULL);\r
+  Status = NtCreateSymbolicLinkObject(&SymlinkHandle,\r
+                                     SYMBOLIC_LINK_ALL_ACCESS,\r
+                                     &ObjectAttributes,\r
+                                     &DllDosPath);\r
+  if (!NT_SUCCESS(Status))\r
+    {\r
+      DPRINT1("NtCreateSymbolicLink() failed (Status %lx)\n", Status);\r
+      return Status;\r
+    }\r
+\r
+  NtClose(SymlinkHandle);\r
+\r
+  RtlZeroMemory(&QueryTable,\r
+               sizeof(QueryTable));\r
+\r
+  QueryTable[0].QueryRoutine = SmpKnownDllsQueryRoutine;\r
+  QueryTable[0].EntryContext = ObjectDirHandle;\r
+\r
+  Status = RtlQueryRegistryValues(RTL_REGISTRY_CONTROL,\r
+                                 L"\\Session Manager\\KnownDlls",\r
+                                 QueryTable,\r
+                                 (PVOID)FileDirHandle,\r
+                                 NULL);\r
+  if (!NT_SUCCESS(Status))\r
+    {\r
+      DPRINT1("RtlQueryRegistryValues() failed (Status %lx)\n", Status);\r
+    }\r
+\r
+  DPRINT("SmLoadKnownDlls() done\n");\r
+\r
+  return Status;\r
+}\r
+\r
+\r
+/* EOF */\r
index 92ecef1..12af5d6 100644 (file)
@@ -15,7 +15,12 @@ TARGET_CFLAGS = -D__NTAPP__
 # require os code to explicitly request A/W version of structs/functions
 TARGET_CFLAGS += -D_DISABLE_TIDENTS -Wall -Werror
 
-TARGET_OBJECTS = $(TARGET_NAME).o init.o smapi.o client.o debug.o
+TARGET_OBJECTS = $(TARGET_NAME).o \
+                init.o initheap.o initenv.o initobdir.o initdosdev.o \
+                initrun.o initmv.o initwkdll.o initpage.o initss.o \
+                initreg.o \
+                smapi.o \
+                client.o debug.o
 
 include $(PATH_TO_TOP)/rules.mak
 
index 0abb4a7..1e13237 100644 (file)
@@ -19,7 +19,7 @@
 
 static HANDLE SmApiPort = INVALID_HANDLE_VALUE;
 
-/* SM API **********************************************************************/
+/* SM API *******************************************************************/
 
 #define SMAPI(n) \
 NTSTATUS FASTCALL n (PSM_PORT_MESSAGE Request)
@@ -128,14 +128,18 @@ SmpApiThread(HANDLE Port)
        }
 }
 
+
+/* LPC PORT INITIALIZATION **************************************************/
+
+
 /**********************************************************************
  * NAME
- *     SmpCreateApiPort/0
+ *     SmCreateApiPort/0
  *
  * DECRIPTION
  */
 NTSTATUS
-SmpCreateApiPort(VOID)
+SmCreateApiPort(VOID)
 {
   OBJECT_ATTRIBUTES ObjectAttributes;
   UNICODE_STRING UnicodeString;
index c51b662..43c64e4 100644 (file)
  * MA 02139, USA.  
  *
  * --------------------------------------------------------------------
- * 
- *     19990529 (Emanuele Aliberti)
- *             Compiled successfully with egcs 1.1.2
  */
-#include <ddk/ntddk.h>
-#include <sm/api.h>
 #include "smss.h"
+//#include <ntdll/rtl.h>
+#include <rosrtl/string.h>
 
 #define NDEBUG
 #include <debug.h>
 
-
-void
-DisplayString(LPCWSTR lpwString)
-{
-  UNICODE_STRING us;
-
-  RtlInitUnicodeString(&us, lpwString);
-  NtDisplayString(&us);
-}
-
-
-void
-PrintString(char* fmt,...)
-{
-  char buffer[512];
-  va_list ap;
-  UNICODE_STRING UnicodeString;
-  ANSI_STRING AnsiString;
-
-  va_start(ap, fmt);
-  vsprintf(buffer, fmt, ap);
-  va_end(ap);
-
-  RtlInitAnsiString(&AnsiString, buffer);
-  RtlAnsiStringToUnicodeString(&UnicodeString,
-                              &AnsiString,
-                              TRUE);
-  NtDisplayString(&UnicodeString);
-  RtlFreeUnicodeString(&UnicodeString);
-}
-
-
 /* Native image's entry point */
 
 VOID STDCALL
 NtProcessStartup(PPEB Peb)
 {
-  HANDLE Children[2]; /* csrss, winlogon */
   NTSTATUS Status;
 
   Status = InitSessionManager(Children);
   if (!NT_SUCCESS(Status))
     {
+      int i;
+      for (i=0; i < (sizeof Children / sizeof Children[0]); i++)
+      {
+        if (Children[i])
+        {
+          NtTerminateProcess(Children[i],0);
+        }
+      }
       DPRINT1("SM: Initialization failed!\n");
       goto ByeBye;
     }
index 79b730a..0a8a3d1 100644 (file)
@@ -1,56 +1,66 @@
 #ifndef _SMSS_H_INCLUDED_
 #define _SMSS_H_INCLUDED_
 
+#define NTOS_MODE_USER
+#include <ntos.h>
+#include <sm/api.h>
 
 #define CHILD_CSRSS     0
 #define CHILD_WINLOGON  1
 
+/* init.c */
+extern HANDLE SmpHeap;
+NTSTATUS InitSessionManager(HANDLE Children[]);
 
-/* GLOBAL VARIABLES ****/
-
-//extern HANDLE SmApiPort;
+/* initheap.c */
+NTSTATUS SmCreateHeap(VOID);
 
+/* initenv.c */
+extern PWSTR SmSystemEnvironment;
+NTSTATUS SmCreateEnvironment(VOID);
+NTSTATUS SmSetEnvironmentVariables(VOID);
+NTSTATUS SmUpdateEnvironment(VOID);
 
-/* FUNCTIONS ***********/
+/* initobdir.c */
+NTSTATUS SmCreateObjectDirectories(VOID);
 
-/* init.c */
+/* initdosdev.c */
+NTSTATUS SmInitDosDevices(VOID);
 
-extern HANDLE SmpHeap;
+/* initrun.c */
+extern HANDLE Children[2];
+NTSTATUS SmRunBootApplications(VOID);
 
-NTSTATUS
-InitSessionManager(HANDLE Children[]);
+/* initmv.c */
+NTSTATUS SmProcessFileRenameList(VOID);
 
+/* initwkdll.c */
+NTSTATUS SmLoadKnownDlls(VOID);
 
-/* smss.c */
-void DisplayString (LPCWSTR lpwString);
-void PrintString (char* fmt,...);
+/* initpage.c */
+NTSTATUS SmCreatePagingFiles(VOID);
 
-/* smapi.c */
+/* initreg.c */
+NTSTATUS SmInitializeRegistry(VOID);
 
-NTSTATUS
-SmpCreateApiPort(VOID);
+/* initss.c */
+NTSTATUS SmLoadSubsystems(VOID);
+NTSTATUS SmRunCsrss(VOID);
+NTSTATUS SmRunWinlogon(VOID);
 
-VOID STDCALL
-SmpApiThread(HANDLE Port);
+/* smapi.c */
+NTSTATUS SmCreateApiPort(VOID);
+VOID STDCALL SmpApiThread(HANDLE Port);
 
 /* client.c */
-
-VOID STDCALL
-SmpInitializeClientManagement(VOID);
-
-NTSTATUS STDCALL
-SmpCreateClient(SM_PORT_MESSAGE);
-
-NTSTATUS STDCALL
-SmpDestroyClient(ULONG);
+NTSTATUS SmInitializeClientManagement(VOID);
+NTSTATUS STDCALL SmpCreateClient(SM_PORT_MESSAGE);
+NTSTATUS STDCALL SmpDestroyClient(ULONG);
 
 /* debug.c */
-
 extern HANDLE DbgSsApiPort;
 extern HANDLE DbgUiApiPort;
-
-NTSTATUS STDCALL
-SmpInitializeDbgSs(VOID);
+NTSTATUS SmInitializeDbgSs(VOID);
 
 #endif /* _SMSS_H_INCLUDED_ */