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
This commit is contained in:
Emanuele Aliberti 2005-02-12 09:08:52 +00:00
parent 165794f5c8
commit 3cc5374fe1
17 changed files with 1406 additions and 1079 deletions

View file

@ -25,7 +25,6 @@
*/
#define NTOS_MODE_USER
#include <ntos.h>
#include <sm/api.h>
#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

View file

@ -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;

File diff suppressed because it is too large Load diff

View file

@ -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 <debug.h>
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 */

View file

@ -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 <debug.h>
/* 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 */

View file

@ -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 <debug.h>
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 */

View file

@ -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 <debug.h>
NTSTATUS
SmProcessFileRenameList(VOID)
{
DPRINT("SmProcessFileRenameList() called\n");
/* FIXME: implement it! */
DPRINT("SmProcessFileRenameList() done\n");
return(STATUS_SUCCESS);
}
/* EOF */

View file

@ -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 <debug.h>
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 */

View file

@ -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 <rosrtl/string.h>
#include <wchar.h>
//#define NDEBUG
#include <debug.h>
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: "<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);
}
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 */

View file

@ -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 <debug.h>
NTSTATUS
SmInitializeRegistry(VOID)
{
DPRINT("SM: %s: initializing registry\n", __FUNCTION__);
/* Load remaining registry hives */
return NtInitializeRegistry(FALSE);
}
/* EOF */

View file

@ -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 <debug.h>
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: "<description> <executable> <command line>":
* 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 */

View file

@ -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 <rosrtl/string.h>
//#define NDEBUG
#include <debug.h>
/* 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 */

View file

@ -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 <debug.h>
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 */

View 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

View 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;

View file

@ -22,60 +22,32 @@
* 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;
}

View 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
/* 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_ */