From: Sir Richard Date: Wed, 10 Mar 2010 04:59:39 +0000 (+0000) Subject: [CSRSS]: Split off CSRSS into a more Windows-friendly model. CSRSS.EXE is simply... X-Git-Tag: backups/header-work@57446~158^2~48 X-Git-Url: https://git.reactos.org/?p=reactos.git;a=commitdiff_plain;h=1cd9cb22ef37cc00493017c1fc00af6fd7cb946d [CSRSS]: Split off CSRSS into a more Windows-friendly model. CSRSS.EXE is simply a stub which loads CSRSRV.DLL, where all the actual code is present. [CSRSRV]: Mostly moved all the current CSRSS code into CSRSRV, with some very minor changes to get it workking. [CSRSRV]: Add some more code from Alex's CSRSRV, such as thread dereferencing/deallocation, hacked to work. [CSRSRV]: Make CsrTerminateProcess destroy each CSR thread in that process, otherwise we were always leaking a handle, so processes never died. Because of this, primary tokens would remain "in use", and when umpnpmgr attempted to do a "Create Process as User" for the second+ time, the call would fail since the token from the first process was still around. This fixed that regression from the mailing list. svn path=/trunk/; revision=46051 --- diff --git a/reactos/boot/bootdata/packages/reactos.dff b/reactos/boot/bootdata/packages/reactos.dff index c8be7bd6a18..e5fb874f849 100644 --- a/reactos/boot/bootdata/packages/reactos.dff +++ b/reactos/boot/bootdata/packages/reactos.dff @@ -670,6 +670,7 @@ boot\bootdata\bootcdregtest\regtest.cmd 7 optional ; Subsystems subsystems\win32\csrss\csrss.exe 1 subsystems\win32\csrss\win32csr\win32csr.dll 1 +subsystems\win32\csrss\csrsrv\csrsrv.dll 1 subsystems\ntvdm\ntvdm.exe 1 subsystems\win32\win32k\win32k.sys 1 diff --git a/reactos/subsystems/win32/csrss/api/handle.c b/reactos/subsystems/win32/csrss/csrsrv/api/handle.c similarity index 99% rename from reactos/subsystems/win32/csrss/api/handle.c rename to reactos/subsystems/win32/csrss/csrsrv/api/handle.c index 391896ed28f..eb6c12c0531 100644 --- a/reactos/subsystems/win32/csrss/api/handle.c +++ b/reactos/subsystems/win32/csrss/csrsrv/api/handle.c @@ -9,7 +9,7 @@ /* INCLUDES ******************************************************************/ -#include +#include #define NDEBUG #include diff --git a/reactos/subsystems/win32/csrss/api/process.c b/reactos/subsystems/win32/csrss/csrsrv/api/process.c similarity index 94% rename from reactos/subsystems/win32/csrss/api/process.c rename to reactos/subsystems/win32/csrss/csrsrv/api/process.c index 9bd3cd6ff26..423424b86e3 100644 --- a/reactos/subsystems/win32/csrss/api/process.c +++ b/reactos/subsystems/win32/csrss/csrsrv/api/process.c @@ -8,7 +8,7 @@ /* INCLUDES ******************************************************************/ -#include +#include #define NDEBUG #include @@ -153,6 +153,65 @@ CsrInsertThread(IN PCSRSS_PROCESS_DATA Process, #define CsrAcquireProcessLock() LOCK #define CsrReleaseProcessLock() UNLOCK +VOID +NTAPI +CsrDeallocateThread(IN PCSR_THREAD CsrThread) +{ + /* Free the process object from the heap */ + RtlFreeHeap(CsrHeap, 0, CsrThread); +} + +VOID +NTAPI +CsrRemoveThread(IN PCSR_THREAD CsrThread) +{ + /* Remove it from the List */ + RemoveEntryList(&CsrThread->Link); + + /* Decreate the thread count of the process */ + CsrThread->Process->ThreadCount--; + + /* Remove it from the Hash List as well */ + if (CsrThread->HashLinks.Flink) RemoveEntryList(&CsrThread->HashLinks); + + /* Check if this is the last Thread */ + if (!CsrThread->Process->ThreadCount) + { + /* Check if it's not already been marked for deletion */ + if (!(CsrThread->Process->Flags & CsrProcessLastThreadTerminated)) + { + /* Let everyone know this process is about to lose the thread */ + //CsrThread->Process->Flags |= CsrProcessLastThreadTerminated; + + /* Reference the Process */ + //CsrLockedDereferenceProcess(CsrThread->Process); + } + } + + /* Mark the thread for deletion */ + CsrThread->Flags |= CsrThreadInTermination; +} + +VOID +NTAPI +CsrThreadRefcountZero(IN PCSR_THREAD CsrThread) +{ + /* Remove this thread */ + CsrRemoveThread(CsrThread); + + /* Release the Process Lock */ + //CsrReleaseProcessLock(); + + /* Close the NT Thread Handle */ + if (CsrThread->ThreadHandle) NtClose(CsrThread->ThreadHandle); + + /* De-allocate the CSR Thread Object */ + CsrDeallocateThread(CsrThread); + + /* Remove a reference from the process */ + //CsrDereferenceProcess(CsrProcess); +} + NTSTATUS NTAPI CsrCreateThreadData(IN PCSRSS_PROCESS_DATA CsrProcess, @@ -933,8 +992,21 @@ CSR_API(CsrCreateThread) CSR_API(CsrTerminateProcess) { + PLIST_ENTRY NextEntry; + PCSR_THREAD Thread; Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE); + + NextEntry = ProcessData->ThreadList.Flink; + while (NextEntry != &ProcessData->ThreadList) + { + Thread = CONTAINING_RECORD(NextEntry, CSR_THREAD, Link); + NextEntry = NextEntry->Flink; + + CsrThreadRefcountZero(Thread); + + } + ProcessData->Terminated = TRUE; return STATUS_SUCCESS; diff --git a/reactos/subsystems/win32/csrss/api/user.c b/reactos/subsystems/win32/csrss/csrsrv/api/user.c similarity index 98% rename from reactos/subsystems/win32/csrss/api/user.c rename to reactos/subsystems/win32/csrss/csrsrv/api/user.c index d89e463cecc..de4e49f66e1 100644 --- a/reactos/subsystems/win32/csrss/api/user.c +++ b/reactos/subsystems/win32/csrss/csrsrv/api/user.c @@ -11,7 +11,7 @@ /* INCLUDES ******************************************************************/ -#include +#include #define NDEBUG #include diff --git a/reactos/subsystems/win32/csrss/api/wapi.c b/reactos/subsystems/win32/csrss/csrsrv/api/wapi.c similarity index 99% rename from reactos/subsystems/win32/csrss/api/wapi.c rename to reactos/subsystems/win32/csrss/csrsrv/api/wapi.c index a37e601ee8a..88005c6fe7b 100644 --- a/reactos/subsystems/win32/csrss/api/wapi.c +++ b/reactos/subsystems/win32/csrss/csrsrv/api/wapi.c @@ -10,7 +10,7 @@ /* INCLUDES ******************************************************************/ -#include +#include #define NDEBUG diff --git a/reactos/subsystems/win32/csrss/csrsrv/csrsrv.rbuild b/reactos/subsystems/win32/csrss/csrsrv/csrsrv.rbuild new file mode 100644 index 00000000000..5cd35e28f40 --- /dev/null +++ b/reactos/subsystems/win32/csrss/csrsrv/csrsrv.rbuild @@ -0,0 +1,20 @@ + + + + + . + . + include + include/reactos/subsys + ntdll + pseh + smdll + + handle.c + process.c + user.c + wapi.c + + init.c + srv.h + diff --git a/reactos/subsystems/win32/csrss/csrsrv/csrsrv.rc b/reactos/subsystems/win32/csrss/csrsrv/csrsrv.rc new file mode 100644 index 00000000000..658072d09b8 --- /dev/null +++ b/reactos/subsystems/win32/csrss/csrsrv/csrsrv.rc @@ -0,0 +1,5 @@ +#define REACTOS_VERSION_DLL +#define REACTOS_STR_FILE_DESCRIPTION "ReactOS CSR Core Server\0" +#define REACTOS_STR_INTERNAL_NAME "csrsrv\0" +#define REACTOS_STR_ORIGINAL_FILENAME "csrsrv.dll\0" +#include diff --git a/reactos/subsystems/win32/csrss/csrsrv/csrsrv.spec b/reactos/subsystems/win32/csrss/csrsrv/csrsrv.spec new file mode 100644 index 00000000000..c394d83df49 --- /dev/null +++ b/reactos/subsystems/win32/csrss/csrsrv/csrsrv.spec @@ -0,0 +1,35 @@ +;@ stdcall CsrAddStaticServerThread(ptr ptr long) +;@ stdcall CsrCallServerFromServer(ptr ptr) +;@ stdcall CsrConnectToUser() +;@ stdcall CsrCreateProcess(ptr ptr ptr ptr long ptr) +;@ stdcall CsrCreateRemoteThread(ptr ptr) +;@ stdcall CsrCreateThread(ptr ptr ptr) +;@ stdcall CsrCreateWait(ptr ptr ptr ptr ptr ptr) +;@ stdcall CsrDebugProcess(ptr) +;@ stdcall CsrDebugProcessStop(ptr) +;@ stdcall CsrDereferenceProcess(ptr) +;@ stdcall CsrDereferenceThread(ptr) +;@ stdcall CsrDereferenceWait(ptr) +;@ stdcall CsrDestroyProcess(ptr long) +;@ stdcall CsrDestroyThread(ptr) +;@ stdcall CsrExecServerThread(ptr long) +;@ stdcall CsrGetProcessLuid(ptr ptr) +;@ stdcall CsrImpersonateClient(ptr) +;@ stdcall CsrLockProcessByClientId(ptr ptr) +;@ stdcall CsrLockThreadByClientId(ptr ptr) +;@ stdcall CsrMoveSatisfiedWait(ptr ptr) +;@ stdcall CsrNotifyWait(ptr long ptr ptr) +;@ stdcall CsrPopulateDosDevices() +;@ stdcall CsrQueryApiPort() +;@ stdcall CsrReferenceThread(ptr) +;@ stdcall CsrRevertToSelf() +@ stdcall CsrServerInitialization(long ptr) +;@ stdcall CsrSetBackgroundPriority(ptr) +;@ stdcall CsrSetCallingSpooler(long) +;@ stdcall CsrSetForegroundPriority(ptr) +;@ stdcall CsrShutdownProcesses(ptr long) +;@ stdcall CsrUnhandledExceptionFilter(ptr) +;@ stdcall CsrUnlockProcess(ptr) +;@ stdcall CsrUnlockThread(ptr) +;@ stdcall CsrValidateMessageBuffer(ptr ptr long long) +;@ stdcall CsrValidateMessageString(ptr ptr) diff --git a/reactos/subsystems/win32/csrss/init.c b/reactos/subsystems/win32/csrss/csrsrv/init.c similarity index 82% rename from reactos/subsystems/win32/csrss/init.c rename to reactos/subsystems/win32/csrss/csrsrv/init.c index 2314ab4b8a8..59b69c54e37 100644 --- a/reactos/subsystems/win32/csrss/init.c +++ b/reactos/subsystems/win32/csrss/csrsrv/init.c @@ -1,47 +1,128 @@ -/* $Id$ - * - * reactos/subsys/csrss/init.c - * - * Initialize the CSRSS subsystem server process. - * - * ReactOS Operating System - * +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS CSR Sub System + * FILE: subsys/csr/csrsrv/init.c + * PURPOSE: CSR Server DLL Initialization + * PROGRAMMERS: ReactOS Portable Systems Group */ -/* INCLUDES ******************************************************************/ - -#include +/* INCLUDES *******************************************************************/ +#include "srv.h" #define NDEBUG #include -/* GLOBALS ******************************************************************/ +/* DATA ***********************************************************************/ HANDLE CsrHeap = (HANDLE) 0; - HANDLE CsrObjectDirectory = (HANDLE) 0; - UNICODE_STRING CsrDirectoryName; - extern HANDLE CsrssApiHeap; - static unsigned InitCompleteProcCount; static CSRPLUGIN_INIT_COMPLETE_PROC *InitCompleteProcs = NULL; - static unsigned HardErrorProcCount; static CSRPLUGIN_HARDERROR_PROC *HardErrorProcs = NULL; - HANDLE hSbApiPort = (HANDLE) 0; - HANDLE hBootstrapOk = (HANDLE) 0; - HANDLE hSmApiPort = (HANDLE) 0; - HANDLE hApiPort = (HANDLE) 0; -/********************************************************************** - * CsrpAddInitCompleteProc/1 - */ +/* PRIVATE FUNCTIONS **********************************************************/ + +ULONG +InitializeVideoAddressSpace(VOID) +{ + OBJECT_ATTRIBUTES ObjectAttributes; + UNICODE_STRING PhysMemName = RTL_CONSTANT_STRING(L"\\Device\\PhysicalMemory"); + NTSTATUS Status; + HANDLE PhysMemHandle; + PVOID BaseAddress; + LARGE_INTEGER Offset; + SIZE_T ViewSize; + CHAR IVTAndBda[1024+256]; + + /* Open the physical memory section */ + InitializeObjectAttributes(&ObjectAttributes, + &PhysMemName, + 0, + NULL, + NULL); + Status = ZwOpenSection(&PhysMemHandle, + SECTION_ALL_ACCESS, + &ObjectAttributes); + if (!NT_SUCCESS(Status)) + { + DPRINT1("Couldn't open \\Device\\PhysicalMemory\n"); + return 0; + } + + /* Map the BIOS and device registers into the address space */ + Offset.QuadPart = 0xa0000; + ViewSize = 0x100000 - 0xa0000; + BaseAddress = (PVOID)0xa0000; + Status = ZwMapViewOfSection(PhysMemHandle, + NtCurrentProcess(), + &BaseAddress, + 0, + ViewSize, + &Offset, + &ViewSize, + ViewUnmap, + 0, + PAGE_EXECUTE_READWRITE); + if (!NT_SUCCESS(Status)) + { + DPRINT1("Couldn't map physical memory (%x)\n", Status); + ZwClose(PhysMemHandle); + return 0; + } + + /* Close physical memory section handle */ + ZwClose(PhysMemHandle); + + if (BaseAddress != (PVOID)0xa0000) + { + DPRINT1("Couldn't map physical memory at the right address (was %x)\n", + BaseAddress); + return 0; + } + + /* Allocate some low memory to use for the non-BIOS + * parts of the v86 mode address space + */ + BaseAddress = (PVOID)0x1; + ViewSize = 0xa0000 - 0x1000; + Status = ZwAllocateVirtualMemory(NtCurrentProcess(), + &BaseAddress, + 0, + &ViewSize, + MEM_COMMIT, + PAGE_EXECUTE_READWRITE); + if (!NT_SUCCESS(Status)) + { + DPRINT1("Failed to allocate virtual memory (Status %x)\n", Status); + return 0; + } + if (BaseAddress != (PVOID)0x0) + { + DPRINT1("Failed to allocate virtual memory at right address (was %x)\n", + BaseAddress); + return 0; + } + + /* Get the real mode IVT and BDA from the kernel */ + Status = NtVdmControl(VdmInitialize, IVTAndBda); + if (!NT_SUCCESS(Status)) + { + DPRINT1("NtVdmControl failed (status %x)\n", Status); + return 0; + } + + /* Return success */ + return 1; +} + + static NTSTATUS FASTCALL CsrpAddInitCompleteProc(CSRPLUGIN_INIT_COMPLETE_PROC Proc) { @@ -513,48 +594,6 @@ CsrpRegisterSubsystem (int argc, char ** argv, char ** envp) return Status; } -/********************************************************************** - * EnvpToUnicodeString/2 - */ -static ULONG FASTCALL -EnvpToUnicodeString (char ** envp, PUNICODE_STRING UnicodeEnv) -{ - ULONG CharCount = 0; - ULONG Index = 0; - ANSI_STRING AnsiEnv; - - UnicodeEnv->Buffer = NULL; - - for (Index=0; NULL != envp[Index]; Index++) - { - CharCount += strlen (envp[Index]); - ++ CharCount; - } - ++ CharCount; - - AnsiEnv.Buffer = RtlAllocateHeap (RtlGetProcessHeap(), 0, CharCount); - if (NULL != AnsiEnv.Buffer) - { - - PCHAR WritePos = AnsiEnv.Buffer; - - for (Index=0; NULL != envp[Index]; Index++) - { - strcpy (WritePos, envp[Index]); - WritePos += strlen (envp[Index]) + 1; - } - - /* FIXME: the last (double) nullterm should perhaps not be included in Length - * but only in MaximumLength. -Gunnar */ - AnsiEnv.Buffer [CharCount-1] = '\0'; - AnsiEnv.Length = CharCount; - AnsiEnv.MaximumLength = CharCount; - - RtlAnsiStringToUnicodeString (UnicodeEnv, & AnsiEnv, TRUE); - RtlFreeHeap (RtlGetProcessHeap(), 0, AnsiEnv.Buffer); - } - return CharCount; -} /********************************************************************** * CsrpLoadKernelModeDriver/3 */ @@ -565,26 +604,26 @@ CsrpLoadKernelModeDriver (int argc, char ** argv, char ** envp) WCHAR Data [MAX_PATH + 1]; ULONG DataLength = sizeof Data; ULONG DataType = 0; - UNICODE_STRING Environment; + //UNICODE_STRING Environment; - DPRINT("SM: %s called\n", __FUNCTION__); + DPRINT1("SM: %s called\n", __FUNCTION__); - EnvpToUnicodeString (envp, & Environment); + //EnvpToUnicodeString (envp, & Environment); Status = SmLookupSubsystem (L"Kmode", Data, & DataLength, & DataType, - Environment.Buffer); - RtlFreeUnicodeString (& Environment); + NULL); + //RtlFreeUnicodeString (& Environment); if((STATUS_SUCCESS == Status) && (DataLength > sizeof Data[0])) { WCHAR ImagePath [MAX_PATH + 1] = {0}; UNICODE_STRING ModuleName; - wcscpy (ImagePath, L"\\??\\"); - wcscat (ImagePath, Data); + wcscpy (ImagePath, L"\\??\\c:\\reactos\\system32\\win32k.sys"); +// wcscat (ImagePath, Data); RtlInitUnicodeString (& ModuleName, ImagePath); Status = NtSetSystemInformation(/* FIXME: SystemLoadAndCallImage */ SystemExtendServiceTableInformation, @@ -592,7 +631,7 @@ CsrpLoadKernelModeDriver (int argc, char ** argv, char ** envp) sizeof ModuleName); if(!NT_SUCCESS(Status)) { - DPRINT("WIN: %s: loading Kmode failed (Status=0x%08lx)\n", + DPRINT1("WIN: %s: loading Kmode failed (Status=0x%08lx)\n", __FUNCTION__, Status); } } @@ -718,22 +757,12 @@ struct { {TRUE, CsrpRunWinlogon, "run WinLogon"}, }; -/********************************************************************** - * NAME - * CsrServerInitialization - * - * DESCRIPTION - * Initialize the Win32 environment subsystem server. - * - * RETURN VALUE - * TRUE: Initialization OK; otherwise FALSE. - */ -BOOL WINAPI -CsrServerInitialization ( - int argc, - char ** argv, - char ** envp - ) +/* PUBLIC FUNCTIONS ***********************************************************/ + +NTSTATUS +NTAPI +CsrServerInitialization(ULONG ArgumentCount, + PCHAR Arguments[]) { UINT i = 0; NTSTATUS Status = STATUS_SUCCESS; @@ -742,7 +771,7 @@ CsrServerInitialization ( for (i=0; i < (sizeof InitRoutine / sizeof InitRoutine[0]); i++) { - Status = InitRoutine[i].EntryPoint(argc,argv,envp); + Status = InitRoutine[i].EntryPoint(ArgumentCount,Arguments,NULL); if(!NT_SUCCESS(Status)) { DPRINT1("CSR: %s: failed to %s (Status=%08lx)\n", @@ -758,9 +787,23 @@ CsrServerInitialization ( if (CallInitComplete()) { Status = SmCompleteSession (hSmApiPort,hSbApiPort,hApiPort); - return TRUE; + return STATUS_SUCCESS; } - return FALSE; + + return STATUS_UNSUCCESSFUL; +} + +BOOL +NTAPI +DllMainCRTStartup(HANDLE hDll, + DWORD dwReason, + LPVOID lpReserved) +{ + /* We don't do much */ + UNREFERENCED_PARAMETER(hDll); + UNREFERENCED_PARAMETER(dwReason); + UNREFERENCED_PARAMETER(lpReserved); + return TRUE; } /* EOF */ diff --git a/reactos/subsystems/win32/csrss/csrss.h b/reactos/subsystems/win32/csrss/csrsrv/srv.h similarity index 71% rename from reactos/subsystems/win32/csrss/csrss.h rename to reactos/subsystems/win32/csrss/csrsrv/srv.h index 447c2e03521..cc11b70603c 100644 --- a/reactos/subsystems/win32/csrss/csrss.h +++ b/reactos/subsystems/win32/csrss/csrsrv/srv.h @@ -1,14 +1,16 @@ /* PSDK/NDK Headers */ +#define NTOS_MODE_USER #include #define WIN32_NO_STATUS #include -#define NTOS_MODE_USER +#include #include -#include +/* CSR Header */ +//#include -/* Build Number */ -#include +/* PSEH for SEH Support */ +#include /* Subsystem Manager Header */ #include @@ -17,5 +19,3 @@ #include #include #include - -/* EOF */ diff --git a/reactos/subsystems/win32/csrss/csrss.c b/reactos/subsystems/win32/csrss/csrss.c index 07027c75f17..c5f574584fb 100644 --- a/reactos/subsystems/win32/csrss/csrss.c +++ b/reactos/subsystems/win32/csrss/csrss.c @@ -1,62 +1,70 @@ -/* $Id$ - * - * csrss.c - Client/Server Runtime subsystem - * - * ReactOS Operating System - * - * -------------------------------------------------------------------- - * - * This program 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 program 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 program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * -------------------------------------------------------------------- +/* + * PROJECT: ReactOS Client Server Runtime SubSystem (CSRSS) + * LICENSE: BSD - See COPYING.ARM in root directory + * FILE: subsystems/win32/csrss/csrss.c + * PURPOSE: Main Executable Code + * PROGRAMMERS: Alex Ionescu + * ReactOS Portable Systems Group */ -#include +/* INCLUDES *******************************************************************/ +#define WIN32_NO_STATUS +#include +#include +#include #define NDEBUG #include -int _cdecl _main(int argc, - char *argv[], - char *envp[], - int DebugFlag) +/* FUNCTIONS ******************************************************************/ + +VOID +NTAPI +CsrpSetDefaultProcessHardErrorMode(VOID) +{ + ULONG DefaultHardErrorMode = 0; + + /* Disable hard errors */ + NtSetInformationProcess(NtCurrentProcess(), + ProcessDefaultHardErrorMode, + &DefaultHardErrorMode, + sizeof(DefaultHardErrorMode)); +} + +int +_cdecl +_main(int argc, + char *argv[], + char *envp[], + int DebugFlag) { - NTSTATUS Status = STATUS_SUCCESS; - - //PrintString("ReactOS Client/Server Run-Time (Build %s)\n", - //KERNEL_VERSION_BUILD_STR); - - /*================================================================== - * Initialize the Win32 environment subsystem server. - *================================================================*/ - if (CsrServerInitialization (argc, argv, envp) == TRUE) - { - /* - * Terminate the current thread only. - */ - Status = NtTerminateThread (NtCurrentThread(), 0); - } - else - { - DisplayString (L"CSR: CsrServerInitialization failed.\n"); - /* - * Tell the SM we failed. - */ - Status = NtTerminateProcess (NtCurrentProcess(), 0); - } - return (int) Status; + KPRIORITY BasePriority = (8 + 1) + 4; + NTSTATUS Status; + + /* Set the Priority */ + NtSetInformationProcess(NtCurrentProcess(), + ProcessBasePriority, + &BasePriority, + sizeof(KPRIORITY)); + + /* Initialize CSR through CSRSRV */ + Status = CsrServerInitialization(argc, argv); + if (!NT_SUCCESS(Status)) + { + /* Kill us */ + DPRINT1("CSRSS: CsrServerInitialization failed:% lx\n", Status); + NtTerminateProcess(NtCurrentProcess(), Status); + } + + /* Disable errors */ + CsrpSetDefaultProcessHardErrorMode(); + + /* If this is Session 0, make sure killing us bugchecks the system */ + if (!NtCurrentPeb()->SessionId) RtlSetProcessIsCritical(TRUE, NULL, FALSE); + + /* Kill this thread. CSRSRV keeps us going */ + NtTerminateThread (NtCurrentThread(), Status); + return 0; } /* EOF */ diff --git a/reactos/subsystems/win32/csrss/csrss.rbuild b/reactos/subsystems/win32/csrss/csrss.rbuild index f3c9df8c87d..438b2e6574a 100644 --- a/reactos/subsystems/win32/csrss/csrss.rbuild +++ b/reactos/subsystems/win32/csrss/csrss.rbuild @@ -9,21 +9,14 @@ -fms-extensions nt ntdll - smdll - - handle.c - process.c - user.c - wapi.c - - csrss.h + csrsrv csrss.c - init.c - print.c - video.c csrss.rc + + + diff --git a/reactos/subsystems/win32/csrss/include/api.h b/reactos/subsystems/win32/csrss/include/api.h index 4a17341f37f..463ee50c002 100644 --- a/reactos/subsystems/win32/csrss/include/api.h +++ b/reactos/subsystems/win32/csrss/include/api.h @@ -13,6 +13,14 @@ #include +typedef enum _CSR_THREAD_FLAGS +{ + CsrThreadAltertable = 0x1, + CsrThreadInTermination = 0x2, + CsrThreadTerminated = 0x4, + CsrThreadIsServerThread = 0x10 +} CSR_THREAD_FLAGS, *PCSR_THREAD_FLAGS; + typedef enum _SHUTDOWN_RESULT { CsrShutdownCsrProcess = 1, @@ -179,7 +187,7 @@ NTSTATUS FASTCALL CsrRegisterObjectDefinitions(PCSRSS_OBJECT_DEFINITION NewDefin NTSTATUS WINAPI CsrInsertObject( PCSRSS_PROCESS_DATA ProcessData, PHANDLE Handle, Object_t *Object, DWORD Access, BOOL Inheritable ); NTSTATUS WINAPI CsrDuplicateHandleTable(PCSRSS_PROCESS_DATA SourceProcessData, PCSRSS_PROCESS_DATA TargetProcessData); NTSTATUS WINAPI CsrGetObject( PCSRSS_PROCESS_DATA ProcessData, HANDLE Handle, Object_t **Object, DWORD Access ); -BOOL WINAPI CsrServerInitialization (int,char**,char**); +NTSTATUS NTAPI CsrServerInitialization(ULONG ArgumentCount, PCHAR Arguments[]); NTSTATUS WINAPI CsrReleaseObjectByPointer(Object_t *Object); NTSTATUS WINAPI CsrReleaseObject( PCSRSS_PROCESS_DATA ProcessData, HANDLE Object ); NTSTATUS WINAPI CsrVerifyObject( PCSRSS_PROCESS_DATA ProcessData, HANDLE Object ); diff --git a/reactos/subsystems/win32/csrss/print.c b/reactos/subsystems/win32/csrss/print.c deleted file mode 100644 index 3e5949d073a..00000000000 --- a/reactos/subsystems/win32/csrss/print.c +++ /dev/null @@ -1,61 +0,0 @@ -/* $Id$ - * - * smss.c - Session Manager - * - * ReactOS Operating System - * - * -------------------------------------------------------------------- - * - * This program 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 program 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 program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * -------------------------------------------------------------------- - * - * 19990529 (Emanuele Aliberti) - * Compiled successfully with egcs 1.1.2 - */ - -#include - -#define NDEBUG -#include - -VOID WINAPI DisplayString(LPCWSTR lpwString) -{ - UNICODE_STRING us; - - RtlInitUnicodeString (&us, lpwString); - ZwDisplayString (&us); -} - -VOID WINAPI 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); -} - -/* EOF */ diff --git a/reactos/subsystems/win32/csrss/video.c b/reactos/subsystems/win32/csrss/video.c deleted file mode 100644 index 8282c15bd7a..00000000000 --- a/reactos/subsystems/win32/csrss/video.c +++ /dev/null @@ -1,111 +0,0 @@ -/* - * PROJECT: ReactOS Client/Server Runtime subsystem - * LICENSE: GPL v2 or later - See COPYING in the top level directory - * FILE: subsystems/win32/csrss/video.c - * PURPOSE: Video memory initialization. - * PROGRAMMERS: ReactOS Development Team - */ - -/* INCLUDES ******************************************************************/ - -#include - -#define NDEBUG -#include - -/* FUNCTIONS *****************************************************************/ - -ULONG -InitializeVideoAddressSpace(VOID) -{ - OBJECT_ATTRIBUTES ObjectAttributes; - UNICODE_STRING PhysMemName = RTL_CONSTANT_STRING(L"\\Device\\PhysicalMemory"); - NTSTATUS Status; - HANDLE PhysMemHandle; - PVOID BaseAddress; - LARGE_INTEGER Offset; - SIZE_T ViewSize; - CHAR IVTAndBda[1024+256]; - - /* Open the physical memory section */ - InitializeObjectAttributes(&ObjectAttributes, - &PhysMemName, - 0, - NULL, - NULL); - Status = ZwOpenSection(&PhysMemHandle, - SECTION_ALL_ACCESS, - &ObjectAttributes); - if (!NT_SUCCESS(Status)) - { - DPRINT1("Couldn't open \\Device\\PhysicalMemory\n"); - return 0; - } - - /* Map the BIOS and device registers into the address space */ - Offset.QuadPart = 0xa0000; - ViewSize = 0x100000 - 0xa0000; - BaseAddress = (PVOID)0xa0000; - Status = ZwMapViewOfSection(PhysMemHandle, - NtCurrentProcess(), - &BaseAddress, - 0, - ViewSize, - &Offset, - &ViewSize, - ViewUnmap, - 0, - PAGE_EXECUTE_READWRITE); - if (!NT_SUCCESS(Status)) - { - DPRINT1("Couldn't map physical memory (%x)\n", Status); - ZwClose(PhysMemHandle); - return 0; - } - - /* Close physical memory section handle */ - ZwClose(PhysMemHandle); - - if (BaseAddress != (PVOID)0xa0000) - { - DPRINT1("Couldn't map physical memory at the right address (was %x)\n", - BaseAddress); - return 0; - } - - /* Allocate some low memory to use for the non-BIOS - * parts of the v86 mode address space - */ - BaseAddress = (PVOID)0x1; - ViewSize = 0xa0000 - 0x1000; - Status = ZwAllocateVirtualMemory(NtCurrentProcess(), - &BaseAddress, - 0, - &ViewSize, - MEM_COMMIT, - PAGE_EXECUTE_READWRITE); - if (!NT_SUCCESS(Status)) - { - DPRINT1("Failed to allocate virtual memory (Status %x)\n", Status); - return 0; - } - if (BaseAddress != (PVOID)0x0) - { - DPRINT1("Failed to allocate virtual memory at right address (was %x)\n", - BaseAddress); - return 0; - } - - /* Get the real mode IVT and BDA from the kernel */ - Status = NtVdmControl(VdmInitialize, IVTAndBda); - if (!NT_SUCCESS(Status)) - { - DPRINT1("NtVdmControl failed (status %x)\n", Status); - return 0; - } - - /* Return success */ - return 1; -} - -/* EOF */