From 3cc5374fe177632e2a68b5c17eef6ca7a037808c Mon Sep 17 00:00:00 2001 From: Emanuele Aliberti Date: Sat, 12 Feb 2005 09:08:52 +0000 Subject: [PATCH] SM - clean, simplify, make more readable - 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 --- reactos/subsys/smss/client.c | 40 +- reactos/subsys/smss/debug.c | 6 +- reactos/subsys/smss/init.c | 1041 ++---------------------------- reactos/subsys/smss/initdosdev.c | 109 ++++ reactos/subsys/smss/initenv.c | 139 ++++ reactos/subsys/smss/initheap.c | 47 ++ reactos/subsys/smss/initmv.c | 44 ++ reactos/subsys/smss/initobdir.c | 93 +++ reactos/subsys/smss/initpage.c | 127 ++++ reactos/subsys/smss/initreg.c | 41 ++ reactos/subsys/smss/initrun.c | 183 ++++++ reactos/subsys/smss/initss.c | 220 +++++++ reactos/subsys/smss/initwkdll.c | 254 ++++++++ reactos/subsys/smss/makefile | 7 +- reactos/subsys/smss/smapi.c | 10 +- reactos/subsys/smss/smss.c | 48 +- reactos/subsys/smss/smss.h | 76 ++- 17 files changed, 1406 insertions(+), 1079 deletions(-) create mode 100644 reactos/subsys/smss/initdosdev.c create mode 100644 reactos/subsys/smss/initenv.c create mode 100644 reactos/subsys/smss/initheap.c create mode 100644 reactos/subsys/smss/initmv.c create mode 100644 reactos/subsys/smss/initobdir.c create mode 100644 reactos/subsys/smss/initpage.c create mode 100644 reactos/subsys/smss/initreg.c create mode 100644 reactos/subsys/smss/initrun.c create mode 100644 reactos/subsys/smss/initss.c create mode 100644 reactos/subsys/smss/initwkdll.c diff --git a/reactos/subsys/smss/client.c b/reactos/subsys/smss/client.c index def34074c4c..b25535e5c85 100644 --- a/reactos/subsys/smss/client.c +++ b/reactos/subsys/smss/client.c @@ -25,7 +25,6 @@ */ #define NTOS_MODE_USER #include -#include #include "smss.h" /* Private ADT */ @@ -51,14 +50,37 @@ struct _SM_CLIENT_DIRECTORY } SmpClientDirectory; /********************************************************************** - * SmpInitializeClientManagement/0 + * SmInitializeClientManagement/0 */ -VOID STDCALL -SmpInitializeClientManagement (VOID) +NTSTATUS +SmInitializeClientManagement (VOID) { RtlInitializeCriticalSection(& SmpClientDirectory.Lock); SmpClientDirectory.Count = 0; SmpClientDirectory.Client = NULL; + return STATUS_SUCCESS; +} + +/********************************************************************** + * SmpLookupClient/1 + */ +PSM_CLIENT_DATA STDCALL +SmpLookupClient (USHORT SubsystemId) +{ + PSM_CLIENT_DATA Client = NULL; + + if (SmpClientDirectory.Count > 0) + { + RtlEnterCriticalSection (& SmpClientDirectory.Lock); + Client = SmpClientDirectory.Client; + while (NULL != Client->Next) + { + if (SubsystemId == Client->SubsystemId) break; + Client = Client->Next; + } + RtlLeaveCriticalSection (& SmpClientDirectory.Lock); + } + return Client; } /********************************************************************** @@ -69,6 +91,14 @@ SmpCreateClient(SM_PORT_MESSAGE Request) { PSM_CLIENT_DATA pClient = NULL; + /* + * Check if a client for the ID already exist. + */ + if (SmpLookupClient(0)) //FIXME + { + DbgPrint("SMSS: %s: attempt to register again subsystem %d.\n",__FUNCTION__,0); + return STATUS_UNSUCCESSFUL; + } /* * Allocate the storage for client data */ @@ -79,6 +109,8 @@ SmpCreateClient(SM_PORT_MESSAGE Request) /* * Initialize the client data */ +// pClient->SubsystemId = Request->Subsystem; + pClient->Initialized = FALSE; // TODO /* * Insert the new descriptor in the diff --git a/reactos/subsys/smss/debug.c b/reactos/subsys/smss/debug.c index e1993610e21..e7848df3d62 100644 --- a/reactos/subsys/smss/debug.c +++ b/reactos/subsys/smss/debug.c @@ -1,6 +1,6 @@ /* $Id: smss.c 12852 2005-01-06 13:58:04Z mf $ * - * client.c - Session Manager client Management + * debug.c - Session Manager debug messages switch and router * * ReactOS Operating System * @@ -36,8 +36,8 @@ HANDLE DbgUiApiPort = INVALID_HANDLE_VALUE; /* FUNCTIONS *********************************************************/ -NTSTATUS STDCALL -SmpInitializeDbgSs (VOID) +NTSTATUS +SmInitializeDbgSs (VOID) { NTSTATUS Status; UNICODE_STRING UnicodeString; diff --git a/reactos/subsys/smss/init.c b/reactos/subsys/smss/init.c index 83ce1e2ef6a..4b24771b353 100644 --- a/reactos/subsys/smss/init.c +++ b/reactos/subsys/smss/init.c @@ -22,761 +22,19 @@ * MA 02139, USA. * * -------------------------------------------------------------------- - * - * 19990530 (Emanuele Aliberti) - * Compiled successfully with egcs 1.1.2 */ -/* INCLUDES *****************************************************************/ - -#include -#include -#include -#include -#include #include "smss.h" +#include -#define NDEBUG +//#define NDEBUG #include -/* 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: " ": - * 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: "[ [ ]]" - */ - 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,270 +67,59 @@ 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) + for (i=0; i < (sizeof InitRoutine / sizeof InitRoutine[0]); i++) + { + Status = InitRoutine[i].EntryPoint(); + if(!NT_SUCCESS(Status)) { - DbgPrint("SMSS: %s: failed to create private heap, aborting\n",__FUNCTION__); - return STATUS_UNSUCCESSFUL; + DPRINT1("SM: %s: failed to %s (Status=%lx)\n", + __FUNCTION__, + InitRoutine[i].ErrorMessage, + Status); + if (InitRoutine[i].Required) + { + return(Status); + } } + } - /* Create object directories */ - Status = SmCreateObjectDirectories(); - if (!NT_SUCCESS(Status)) - { - DPRINT1("SM: Failed to create object directories (Status %lx)\n", Status); - 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 index 00000000000..7103ff6cf88 --- /dev/null +++ b/reactos/subsys/smss/initdosdev.c @@ -0,0 +1,109 @@ +/* $Id: init.c 13449 2005-02-06 21:55:07Z ea $ + * + * initdosdev.c - Define symbolic links to kernel devices (MS-DOS names) + * + * ReactOS Operating System + * + * -------------------------------------------------------------------- + * + * This software is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING.LIB. If not, write + * to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, + * MA 02139, USA. + * + * -------------------------------------------------------------------- + */ + +#include "smss.h" + +//#define NDEBUG +#include + +static NTSTATUS STDCALL +SmpDosDevicesQueryRoutine(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("%s: NtCreateSymbolicLink( %wZ --> %wZ ) failed!\n", + __FUNCTION__, + &LinkName, + &DeviceName); + } + NtClose(LinkHandle); + + return(Status); +} + + +NTSTATUS +SmInitDosDevices(VOID) +{ + RTL_QUERY_REGISTRY_TABLE QueryTable[2]; + NTSTATUS Status; + + RtlZeroMemory(&QueryTable, + sizeof(QueryTable)); + + QueryTable[0].QueryRoutine = SmpDosDevicesQueryRoutine; + + Status = RtlQueryRegistryValues(RTL_REGISTRY_CONTROL, + L"\\Session Manager\\DOS Devices", + QueryTable, + NULL, + NULL); + return(Status); +} + +/* EOF */ diff --git a/reactos/subsys/smss/initenv.c b/reactos/subsys/smss/initenv.c new file mode 100644 index 00000000000..e9d51357cdf --- /dev/null +++ b/reactos/subsys/smss/initenv.c @@ -0,0 +1,139 @@ +/* $Id: init.c 13449 2005-02-06 21:55:07Z ea $ + * + * initenv.c - Environment initialization + * + * ReactOS Operating System + * + * -------------------------------------------------------------------- + * + * This software is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING.LIB. If not, write + * to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, + * MA 02139, USA. + * + * -------------------------------------------------------------------- + */ + +#include "smss.h" + +//#define NDEBUG +#include + +/* GLOBALS */ + +PWSTR SmSystemEnvironment = NULL; + + +/* FUNCTIONS */ + +NTSTATUS +SmCreateEnvironment(VOID) +{ + return RtlCreateEnvironment(FALSE, &SmSystemEnvironment); +} + + +static NTSTATUS +SmpSetEnvironmentVariable(PVOID Context, + PWSTR ValueName, + PVOID ValueData) +{ + UNICODE_STRING EnvVariable; + UNICODE_STRING EnvValue; + + RtlInitUnicodeString(&EnvVariable, + ValueName); + RtlInitUnicodeString(&EnvValue, + (PWSTR)ValueData); + RtlSetEnvironmentVariable(Context, + &EnvVariable, + &EnvValue); + + return(STATUS_SUCCESS); +} + + +static NTSTATUS STDCALL +SmpEnvironmentQueryRoutine(PWSTR ValueName, + ULONG ValueType, + PVOID ValueData, + ULONG ValueLength, + PVOID Context, + PVOID EntryContext) +{ + DPRINT("ValueName '%S' Type %lu Length %lu\n", ValueName, ValueType, ValueLength); + DPRINT("ValueData '%S'\n", (PWSTR)ValueData); + + if (ValueType != REG_SZ) + { + return(STATUS_SUCCESS); + } + return SmpSetEnvironmentVariable(Context,ValueName,ValueData); +} + + +NTSTATUS +SmSetEnvironmentVariables(VOID) +{ + RTL_QUERY_REGISTRY_TABLE QueryTable[2]; + 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" */ + SmpSetEnvironmentVariable(&SmSystemEnvironment,L"SystemRoot",ValueBuffer); + + /* Cut off trailing path */ + ValueBuffer[2] = 0; + + /* Set SystemDrive = "C:" */ + SmpSetEnvironmentVariable(&SmSystemEnvironment,L"SystemDrive",ValueBuffer); + + /* Read system environment from the registry. */ + RtlZeroMemory(&QueryTable, + sizeof(QueryTable)); + + QueryTable[0].QueryRoutine = SmpEnvironmentQueryRoutine; + + Status = RtlQueryRegistryValues(RTL_REGISTRY_CONTROL, + L"\\Session Manager\\Environment", + QueryTable, + &SmSystemEnvironment, + SmSystemEnvironment); + + return(Status); +} + +/********************************************************************** + * Set environment variables from registry + */ +NTSTATUS +SmUpdateEnvironment(VOID) +{ + /* TODO */ + return STATUS_SUCCESS; +} + +/* EOF */ diff --git a/reactos/subsys/smss/initheap.c b/reactos/subsys/smss/initheap.c new file mode 100644 index 00000000000..3d5ec194850 --- /dev/null +++ b/reactos/subsys/smss/initheap.c @@ -0,0 +1,47 @@ +/* $Id: init.c 13449 2005-02-06 21:55:07Z ea $ + * + * initenv.c - Create the SM private heap + * + * ReactOS Operating System + * + * -------------------------------------------------------------------- + * + * This software is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING.LIB. If not, write + * to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, + * MA 02139, USA. + * + * -------------------------------------------------------------------- + */ + +#include "smss.h" + +//#define NDEBUG +#include + +HANDLE SmpHeap = NULL; + +NTSTATUS +SmCreateHeap(VOID) +{ + /* Create our own heap */ + SmpHeap = RtlCreateHeap(HEAP_GROWABLE, + NULL, + 65536, + 65536, + NULL, + NULL); + return (NULL == SmpHeap) ? STATUS_UNSUCCESSFUL : STATUS_SUCCESS; +} + +/* EOF */ diff --git a/reactos/subsys/smss/initmv.c b/reactos/subsys/smss/initmv.c new file mode 100644 index 00000000000..71878f88960 --- /dev/null +++ b/reactos/subsys/smss/initmv.c @@ -0,0 +1,44 @@ +/* $Id: init.c 13449 2005-02-06 21:55:07Z ea $ + * + * initmv.c - Process the file rename list + * + * ReactOS Operating System + * + * -------------------------------------------------------------------- + * + * This software is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING.LIB. If not, write + * to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, + * MA 02139, USA. + * + * -------------------------------------------------------------------- + */ + +#include "smss.h" + +//#define NDEBUG +#include + +NTSTATUS +SmProcessFileRenameList(VOID) +{ + DPRINT("SmProcessFileRenameList() called\n"); + + /* FIXME: implement it! */ + + DPRINT("SmProcessFileRenameList() done\n"); + + return(STATUS_SUCCESS); +} + +/* EOF */ diff --git a/reactos/subsys/smss/initobdir.c b/reactos/subsys/smss/initobdir.c new file mode 100644 index 00000000000..8557051eed6 --- /dev/null +++ b/reactos/subsys/smss/initobdir.c @@ -0,0 +1,93 @@ +/* $Id: init.c 13449 2005-02-06 21:55:07Z ea $ + * + * initobdir.c - Session Manager object directories + * + * ReactOS Operating System + * + * -------------------------------------------------------------------- + * + * This software is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING.LIB. If not, write + * to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, + * MA 02139, USA. + * + * -------------------------------------------------------------------- + */ + + +#include "smss.h" + +//#define NDEBUG +#include + +static NTSTATUS STDCALL +SmpObjectDirectoryQueryRoutine(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); +} + + +NTSTATUS +SmCreateObjectDirectories(VOID) +{ + RTL_QUERY_REGISTRY_TABLE QueryTable[2]; + NTSTATUS Status; + + RtlZeroMemory(&QueryTable, + sizeof(QueryTable)); + + QueryTable[0].Name = L"ObjectDirectories"; + QueryTable[0].QueryRoutine = SmpObjectDirectoryQueryRoutine; + + Status = RtlQueryRegistryValues(RTL_REGISTRY_CONTROL, + L"\\Session Manager", + QueryTable, + NULL, + NULL); + + return(Status); +} + +/* EOF */ diff --git a/reactos/subsys/smss/initpage.c b/reactos/subsys/smss/initpage.c new file mode 100644 index 00000000000..c5e17859f57 --- /dev/null +++ b/reactos/subsys/smss/initpage.c @@ -0,0 +1,127 @@ +/* $Id: init.c 13449 2005-02-06 21:55:07Z ea $ + * + * initpage.c - + * + * ReactOS Operating System + * + * -------------------------------------------------------------------- + * + * This software is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING.LIB. If not, write + * to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, + * MA 02139, USA. + * + * -------------------------------------------------------------------- + */ +#include "smss.h" +#include +#include + +//#define NDEBUG +#include + +static NTSTATUS STDCALL +SmpPagingFilesQueryRoutine(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: "[ [ ]]" + */ + 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); +} + + +NTSTATUS +SmCreatePagingFiles(VOID) +{ + RTL_QUERY_REGISTRY_TABLE QueryTable[2]; + NTSTATUS Status; + + DPRINT("SM: creating system paging files\n"); + /* + * 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 = SmpPagingFilesQueryRoutine; + + Status = RtlQueryRegistryValues(RTL_REGISTRY_CONTROL, + L"\\Session Manager\\Memory Management", + QueryTable, + NULL, + NULL); + + return(Status); +} + + +/* EOF */ diff --git a/reactos/subsys/smss/initreg.c b/reactos/subsys/smss/initreg.c new file mode 100644 index 00000000000..7feab51768f --- /dev/null +++ b/reactos/subsys/smss/initreg.c @@ -0,0 +1,41 @@ +/* $Id: init.c 13449 2005-02-06 21:55:07Z ea $ + * + * initenv.c - Environment initialization + * + * ReactOS Operating System + * + * -------------------------------------------------------------------- + * + * This software is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING.LIB. If not, write + * to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, + * MA 02139, USA. + * + * -------------------------------------------------------------------- + */ + +#include "smss.h" + +//#define NDEBUG +#include + +NTSTATUS +SmInitializeRegistry(VOID) +{ + DPRINT("SM: %s: initializing registry\n", __FUNCTION__); + + /* Load remaining registry hives */ + return NtInitializeRegistry(FALSE); +} + +/* EOF */ diff --git a/reactos/subsys/smss/initrun.c b/reactos/subsys/smss/initrun.c new file mode 100644 index 00000000000..eb096462b7e --- /dev/null +++ b/reactos/subsys/smss/initrun.c @@ -0,0 +1,183 @@ +/* $Id: init.c 13449 2005-02-06 21:55:07Z ea $ + * + * initrun.c - Run all programs in the boot execution list + * + * ReactOS Operating System + * + * -------------------------------------------------------------------- + * + * This software is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING.LIB. If not, write + * to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, + * MA 02139, USA. + * + * -------------------------------------------------------------------- + */ + +#include "smss.h" + +//#define NDEBUG +#include + +HANDLE Children[2] = {0, 0}; /* csrss, winlogon */ + + +static NTSTATUS STDCALL +SmpRunBootAppsQueryRoutine(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: " ": + * BootExecute = "autocheck autochk *" + */ +NTSTATUS +SmRunBootApplications(VOID) +{ + RTL_QUERY_REGISTRY_TABLE QueryTable[2]; + NTSTATUS Status; + + RtlZeroMemory(&QueryTable, + sizeof(QueryTable)); + + QueryTable[0].Name = L"BootExecute"; + QueryTable[0].QueryRoutine = SmpRunBootAppsQueryRoutine; + + Status = RtlQueryRegistryValues(RTL_REGISTRY_CONTROL, + L"\\Session Manager", + QueryTable, + NULL, + NULL); + if (!NT_SUCCESS(Status)) + { + DPRINT1("%s: RtlQueryRegistryValues() failed! (Status %lx)\n", + __FUNCTION__, + Status); + } + + return(Status); +} + + +/* EOF */ diff --git a/reactos/subsys/smss/initss.c b/reactos/subsys/smss/initss.c new file mode 100644 index 00000000000..6894c13f4d5 --- /dev/null +++ b/reactos/subsys/smss/initss.c @@ -0,0 +1,220 @@ +/* $Id: init.c 13449 2005-02-06 21:55:07Z ea $ + * + * initss.c - Load the subsystems + * + * ReactOS Operating System + * + * -------------------------------------------------------------------- + * + * This software is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING.LIB. If not, write + * to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, + * MA 02139, USA. + * + * -------------------------------------------------------------------- + */ + + +#include "smss.h" +#include + +//#define NDEBUG +#include + +/* TODO: this file should be totally rewritten + * + * a) look if a special option is set for smss.exe in + * HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options + * + * b) make smss register with itself for IMAGE_SUBSYSTEM_NATIVE + * (programmatically) + * + * c) make smss load win32k.sys as set in Kmode key + * HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\SubSystems + * + * d) make smss initialize Debug (DBGSS) and Windows (CSRSS) as described + * in the registry key Required="Debug Windows" + * HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\SubSystems + * + * e) make optional subsystems loadable (again: they must be described in the registry + * key Optional="Posix Os2" to be allowed to run) + */ +NTSTATUS +SmLoadSubsystems(VOID) +{ + SYSTEM_LOAD_AND_CALL_IMAGE ImageInfo; + NTSTATUS Status; + + DPRINT("SM: loading subsystems\n"); + + /* 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); +} + +NTSTATUS +SmRunCsrss(VOID) +{ + NTSTATUS Status; + UNICODE_STRING UnicodeString; + OBJECT_ATTRIBUTES ObjectAttributes; + PRTL_USER_PROCESS_PARAMETERS ProcessParameters; + RTL_PROCESS_INFO ProcessInfo; + HANDLE CsrssInitEvent; + WCHAR UnicodeBuffer[MAX_PATH]; + + 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)) + { + DPRINT("SM: %s: Loading csrss.exe failed!\n", __FUNCTION__); + return(Status); + } + + Status = NtWaitForSingleObject(CsrssInitEvent, + FALSE, + NULL); + + Children[CHILD_CSRSS] = ProcessInfo.ProcessHandle; + + return Status; +} + +NTSTATUS +SmRunWinlogon(VOID) +{ + NTSTATUS Status; + UNICODE_STRING UnicodeString; + PRTL_USER_PROCESS_PARAMETERS ProcessParameters; + RTL_PROCESS_INFO ProcessInfo; + WCHAR UnicodeBuffer[MAX_PATH]; + + /* + * 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)) + { + DPRINT("SM: %s: Loading winlogon.exe failed!\n", __FUNCTION__); + NtTerminateProcess(Children[CHILD_CSRSS], + 0); + return(Status); + } + Children[CHILD_WINLOGON] = ProcessInfo.ProcessHandle; + + return Status; +} + +/* EOF */ diff --git a/reactos/subsys/smss/initwkdll.c b/reactos/subsys/smss/initwkdll.c new file mode 100644 index 00000000000..ed67dbcdc81 --- /dev/null +++ b/reactos/subsys/smss/initwkdll.c @@ -0,0 +1,254 @@ +/* $Id: init.c 13449 2005-02-06 21:55:07Z ea $ + * + * initwkdll.c - Load the well known DLLs + * + * ReactOS Operating System + * + * -------------------------------------------------------------------- + * + * This software is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING.LIB. If not, write + * to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, + * MA 02139, USA. + * + * -------------------------------------------------------------------- + */ + +#include "smss.h" + +//#define NDEBUG +#include + +static NTSTATUS STDCALL +SmpKnownDllsQueryRoutine(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; +} + + +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("SM: loading well-known DLLs\n"); + + 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 = SmpKnownDllsQueryRoutine; + 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; +} + + +/* EOF */ diff --git a/reactos/subsys/smss/makefile b/reactos/subsys/smss/makefile index 92ecef1d8b0..12af5d6800f 100644 --- a/reactos/subsys/smss/makefile +++ b/reactos/subsys/smss/makefile @@ -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 diff --git a/reactos/subsys/smss/smapi.c b/reactos/subsys/smss/smapi.c index 0abb4a77471..1e132375c9a 100644 --- a/reactos/subsys/smss/smapi.c +++ b/reactos/subsys/smss/smapi.c @@ -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; diff --git a/reactos/subsys/smss/smss.c b/reactos/subsys/smss/smss.c index c51b66270dc..43c64e4a386 100644 --- a/reactos/subsys/smss/smss.c +++ b/reactos/subsys/smss/smss.c @@ -22,60 +22,32 @@ * MA 02139, USA. * * -------------------------------------------------------------------- - * - * 19990529 (Emanuele Aliberti) - * Compiled successfully with egcs 1.1.2 */ -#include -#include #include "smss.h" +//#include +#include #define NDEBUG #include - -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; } diff --git a/reactos/subsys/smss/smss.h b/reactos/subsys/smss/smss.h index 79b730adfbb..0a8a3d1dee5 100644 --- a/reactos/subsys/smss/smss.h +++ b/reactos/subsys/smss/smss.h @@ -1,56 +1,66 @@ #ifndef _SMSS_H_INCLUDED_ #define _SMSS_H_INCLUDED_ +#define NTOS_MODE_USER +#include +#include #define CHILD_CSRSS 0 #define CHILD_WINLOGON 1 - -/* GLOBAL VARIABLES ****/ - -//extern HANDLE SmApiPort; - - -/* FUNCTIONS ***********/ - /* init.c */ - extern HANDLE SmpHeap; +NTSTATUS InitSessionManager(HANDLE Children[]); -NTSTATUS -InitSessionManager(HANDLE Children[]); +/* initheap.c */ +NTSTATUS SmCreateHeap(VOID); +/* initenv.c */ +extern PWSTR SmSystemEnvironment; +NTSTATUS SmCreateEnvironment(VOID); +NTSTATUS SmSetEnvironmentVariables(VOID); +NTSTATUS SmUpdateEnvironment(VOID); -/* smss.c */ -void DisplayString (LPCWSTR lpwString); -void PrintString (char* fmt,...); +/* initobdir.c */ +NTSTATUS SmCreateObjectDirectories(VOID); + +/* initdosdev.c */ +NTSTATUS SmInitDosDevices(VOID); + +/* initrun.c */ +extern HANDLE Children[2]; +NTSTATUS SmRunBootApplications(VOID); + +/* initmv.c */ +NTSTATUS SmProcessFileRenameList(VOID); + +/* initwkdll.c */ +NTSTATUS SmLoadKnownDlls(VOID); + +/* initpage.c */ +NTSTATUS SmCreatePagingFiles(VOID); + +/* initreg.c */ +NTSTATUS SmInitializeRegistry(VOID); + +/* initss.c */ +NTSTATUS SmLoadSubsystems(VOID); +NTSTATUS SmRunCsrss(VOID); +NTSTATUS SmRunWinlogon(VOID); /* smapi.c */ - -NTSTATUS -SmpCreateApiPort(VOID); - -VOID STDCALL -SmpApiThread(HANDLE Port); +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_ */