- Some NDK fixes when compiling with PSDK.
- Commit the new CSR (csrsrv and csrss). Compiles and passes PREfast
with msvc 2005. Does not link yet. Is not complete yet (3 missing
functions). Does not build with mingw yet. Code is probably still buggy.
Work in other areas is needed as well. I'm comitting this under
recommendation from Emanuele. See status.h for more info.
- Thanks to Emanuele and Filip which have helped with this patch.
Modified: trunk/reactos/include/ndk/extypes.h
Modified: trunk/reactos/include/ndk/ldrfuncs.h
Modified: trunk/reactos/include/ndk/rtltypes.h
Deleted: trunk/reactos/include/subsys/csr/protocol.h
Modified: trunk/reactos/include/subsys/csr/server.h
Deleted: trunk/reactos/subsys/csr/args.c
Deleted: trunk/reactos/subsys/csr/csr.h
Added: trunk/reactos/subsys/csr/csrsrv/api.c
Modified: trunk/reactos/subsys/csr/csrsrv/csrsrv.def
Deleted: trunk/reactos/subsys/csr/csrsrv/debug.c
Deleted: trunk/reactos/subsys/csr/csrsrv/dllmain.c
Modified: trunk/reactos/subsys/csr/csrsrv/init.c
Modified: trunk/reactos/subsys/csr/csrsrv/process.c
Modified: trunk/reactos/subsys/csr/csrsrv/server.c
Modified: trunk/reactos/subsys/csr/csrsrv/session.c
Modified: trunk/reactos/subsys/csr/csrsrv/srv.h
Added: trunk/reactos/subsys/csr/csrsrv/status.h
Modified: trunk/reactos/subsys/csr/csrsrv/thread.c
Modified: trunk/reactos/subsys/csr/csrsrv/wait.c
Modified: trunk/reactos/subsys/csr/main.c
_____
Modified: trunk/reactos/include/ndk/extypes.h
--- trunk/reactos/include/ndk/extypes.h 2005-09-27 01:57:27 UTC (rev
18117)
+++ trunk/reactos/include/ndk/extypes.h 2005-09-27 04:53:33 UTC (rev
18118)
@@ -13,7 +13,7 @@
/* DEPENDENCIES
**************************************************************/
#include <cfg.h>
/* FIXME: this needs be implemented in the w32api ddk */
-#ifdef _MSC_VER
+#if defined(_MSC_VER) && !defined(NTOS_MODE_USER)
#include <ntimage.h>
#endif
#include "cmtypes.h"
_____
Modified: trunk/reactos/include/ndk/ldrfuncs.h
--- trunk/reactos/include/ndk/ldrfuncs.h 2005-09-27 01:57:27 UTC
(rev 18117)
+++ trunk/reactos/include/ndk/ldrfuncs.h 2005-09-27 04:53:33 UTC
(rev 18118)
@@ -12,7 +12,7 @@
/* DEPENDENCIES
**************************************************************/
#include "ldrtypes.h"
/* FIXME: this needs be implemented in the w32api ddk */
-#ifdef _MSC_VER
+#if defined(_MSC_VER) && !defined(NTOS_MODE_USER)
#include <ntimage.h>
#endif
_____
Modified: trunk/reactos/include/ndk/rtltypes.h
--- trunk/reactos/include/ndk/rtltypes.h 2005-09-27 01:57:27 UTC
(rev 18117)
+++ trunk/reactos/include/ndk/rtltypes.h 2005-09-27 04:53:33 UTC
(rev 18118)
@@ -393,6 +393,14 @@
typedef OSVERSIONINFOEXW RTL_OSVERSIONINFOEXW;
typedef LPOSVERSIONINFOEXW PRTL_OSVERSIONINFOEXW;
+typedef EXCEPTION_DISPOSITION
+(*PEXCEPTION_HANDLER)(
+ struct _EXCEPTION_RECORD*,
+ PVOID,
+ struct _CONTEXT*,
+ PVOID
+);
+
typedef struct _RTL_HEAP_PARAMETERS
{
ULONG Length;
_____
Deleted: trunk/reactos/include/subsys/csr/protocol.h
--- trunk/reactos/include/subsys/csr/protocol.h 2005-09-27 01:57:27 UTC
(rev 18117)
+++ trunk/reactos/include/subsys/csr/protocol.h 2005-09-27 04:53:33 UTC
(rev 18118)
@@ -1,37 +0,0 @@
-#ifndef __INCLUDE_CSR_PROTOCOL_H
-#define __INCLUDE_CSR_PROTOCOL_H
-
-typedef ULONG CSR_API_NUMBER;
-
-#define MAKE_CSR_OPCODE(s,m) ((s) << 16) + (m)
-
-//
-// Shared CSR Message Header for all CSR Servers
-// Gary Nebbett - Alex Ionescu
-//
-typedef struct _CSR_PORT_MESSAGE_HEADER
-{
- //
- // LPC Header
- //
- PORT_MESSAGE PortHeader;
-
- //
- // Buffer allocated with CsrAllocateCaptureBuffer.
- // Sent as 2nd parameter to CsrClientCallServer.
- //
- PVOID CsrCaptureData;
-
- //
- // CSR API Message ID and Return Value
- //
- CSR_API_NUMBER Opcode;
- ULONG Status;
- ULONG Reserved;
-
- //
- // Server-defined union of supported structures
- //
-} CSR_PORT_MESSAGE_HEADER, * PCSR_PORT_MESSAGE_HEADER;
-
-#endif /* ndef __INCLUDE_CSR_PROTOCOL_H */
_____
Modified: trunk/reactos/include/subsys/csr/server.h
--- trunk/reactos/include/subsys/csr/server.h 2005-09-27 01:57:27 UTC
(rev 18117)
+++ trunk/reactos/include/subsys/csr/server.h 2005-09-27 04:53:33 UTC
(rev 18118)
@@ -1,106 +1,306 @@
-#if !defined(__INCLUDE_CSR_SERVER_H)
-#define __INCLUDE_CSR_SERVER_H
+#ifndef _CSRSERVER_H
+#define _CSRSERVER_H
#define CSR_SRV_SERVER 0
-typedef struct _CSR_SESSION
+typedef enum _CSR_PROCESS_FLAGS
{
- ULONG SessionId;
- HANDLE Heap;
- PVOID ServerData;
+ CsrProcessTerminating = 0x1,
+ CsrProcessSkipShutdown = 0x2,
+ CsrProcessCreateNewGroup = 0x100,
+ CsrProcessTerminated = 0x200,
+ CsrProcessLastThreadTerminated = 0x400,
+ CsrProcessIsConsoleApp = 0x800
+} CSR_PROCESS_FLAGS, *PCSR_PROCESS_FLAGS;
-} CSR_SESSION, * PCSR_SESSION;
+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,
+ CsrShutdownNonCsrProcess,
+ CsrShutdownCancelled
+} SHUTDOWN_RESULT, *PSHUTDOWN_RESULT;
+typedef enum _CSR_SHUTDOWN_FLAGS
+{
+ CsrShutdownSystem = 4,
+ CsrShutdownOther = 8
+} CSR_SHUTDOWN_FLAGS, *PCSR_SHUTDOWN_FLAGS;
+
+typedef enum _CSR_DEBUG_FLAGS
+{
+ CsrDebugOnlyThisProcess = 1,
+ CsrDebugProcessChildren = 2
+} CSR_PROCESS_DEBUG_FLAGS, *PCSR_PROCESS_DEBUG_FLAGS;
+
+typedef struct _CSR_NT_SESSION
+{
+ ULONG ReferenceCount;
+ LIST_ENTRY SessionList;
+ ULONG SessionId;
+} CSR_NT_SESSION, *PCSR_NT_SESSION;
+
typedef struct _CSR_PROCESS
{
- CLIENT_ID ClientId;
- LIST_ENTRY ListLink;
- LIST_ENTRY ThreadList;
- PCSR_SESSION NtSession;
- ULONG ExpectedVersion;
- HANDLE ClientPort;
- ULONG_PTR ClientViewBase;
- ULONG_PTR ClientViewBounds;
- HANDLE ProcessHandle;
- ULONG SequenceNumber;
- ULONG Flags;
- ULONG DebugFlags;
- ULONG ReferenceCount;
- ULONG ProcessGroupId;
- ULONG ProcessGroupSequence;
- ULONG fVDM;
- ULONG ThreadCount;
- ULONG PriorityClass;
- ULONG Reserved;
- ULONG ShutdownLevel;
- ULONG ShutdownFlags;
- PVOID ServerData;
-
-} CSR_PROCESS, * PCSR_PROCESS;
+ CLIENT_ID ClientId;
+ LIST_ENTRY ListLink;
+ LIST_ENTRY ThreadList;
+ struct _CSR_PROCESS *Parent;
+ PCSR_NT_SESSION NtSession;
+ ULONG ExpectedVersion;
+ HANDLE ClientPort;
+ ULONG_PTR ClientViewBase;
+ ULONG_PTR ClientViewBounds;
+ HANDLE ProcessHandle;
+ ULONG SequenceNumber;
+ ULONG Flags;
+ ULONG DebugFlags;
+ CLIENT_ID DebugCid;
+ ULONG ReferenceCount;
+ ULONG ProcessGroupId;
+ ULONG ProcessGroupSequence;
+ ULONG fVDM;
+ ULONG ThreadCount;
+ ULONG PriorityClass;
+ ULONG Reserved;
+ ULONG ShutdownLevel;
+ ULONG ShutdownFlags;
+ PVOID ServerData[];
+} CSR_PROCESS, *PCSR_PROCESS;
-struct _CSR_WAIT;
-
typedef struct _CSR_THREAD
{
- LARGE_INTEGER CreateTime;
- LIST_ENTRY Link;
- LIST_ENTRY HashLinks;
- CLIENT_ID ClientId;
- PCSR_PROCESS Process;
- struct _CSR_WAIT *WaitBlock;
- HANDLE ThreadHandle;
- ULONG Flags;
- ULONG ReferenceCount;
- ULONG ImpersonationCount;
-
-} CSR_THREAD, * PCSR_THREAD;
+ LARGE_INTEGER CreateTime;
+ LIST_ENTRY Link;
+ LIST_ENTRY HashLinks;
+ CLIENT_ID ClientId;
+ PCSR_PROCESS Process;
+ struct _CSR_WAIT_BLOCK *WaitBlock;
+ HANDLE ThreadHandle;
+ ULONG Flags;
+ ULONG ReferenceCount;
+ ULONG ImpersonationCount;
+} CSR_THREAD, *PCSR_THREAD;
-typedef struct _CSR_WAIT
+typedef
+NTSTATUS
+(*PCSR_CONNECT_CALLBACK)(
+ IN PCSR_PROCESS CsrProcess,
+ IN OUT PVOID ConnectionInfo,
+ IN OUT PULONG ConnectionInfoLength
+);
+
+typedef
+VOID
+(*PCSR_DISCONNECT_CALLBACK)(IN PCSR_PROCESS CsrProcess);
+
+typedef
+NTSTATUS
+(*PCSR_NEWPROCESS_CALLBACK)(
+ IN PCSR_PROCESS Parent,
+ IN PCSR_PROCESS CsrProcess
+);
+
+typedef
+VOID
+(*PCSR_HARDERROR_CALLBACK)(
+ IN PCSR_THREAD CsrThread,
+ IN PHARDERROR_MSG HardErrorMessage
+);
+
+typedef
+ULONG
+(*PCSR_SHUTDOWNPROCESS_CALLBACK)(
+ IN PCSR_PROCESS CsrProcess,
+ IN ULONG Flags,
+ IN BOOLEAN FirstPhase
+);
+
+/* FIXME: Put into public NDK Header */
+typedef ULONG CSR_API_NUMBER;
+
+#define CSR_MAKE_OPCODE(s,m) ((s) << 16) | (m)
+#define CSR_API_ID_FROM_OPCODE(n) ((ULONG)((USHORT)(n)))
+#define CSR_SERVER_ID_FROM_OPCODE(n) (ULONG)((n) >> 16)
+
+typedef struct _CSR_CONNECTION_INFO
{
- PCSR_THREAD CsrThread;
+ ULONG Unknown[2];
+ HANDLE ObjectDirectory;
+ PVOID SharedSectionBase;
+ PVOID SharedSectionHeap;
+ PVOID SharedSectionData;
+ ULONG DebugFlags;
+ ULONG Unknown2[3];
+ HANDLE ProcessId;
+} CSR_CONNECTION_INFO, *PCSR_CONNECTION_INFO;
-} CSR_WAIT, * PCSR_WAIT;
+typedef struct _CSR_CLIENT_CONNECT
+{
+ ULONG ServerId;
+ PVOID ConnectionInfo;
+ ULONG ConnectionInfoSize;
+} CSR_CLIENT_CONNECT, *PCSR_CLIENT_CONNECT;
+typedef struct _CSR_API_MESSAGE
+{
+ PORT_MESSAGE Header;
+ union
+ {
+ CSR_CONNECTION_INFO ConnectionInfo;
+ struct
+ {
+ PVOID CsrCaptureData;
+ CSR_API_NUMBER Opcode;
+ ULONG Status;
+ ULONG Reserved;
+ union
+ {
+ CSR_CLIENT_CONNECT CsrClientConnect;
+ };
+ };
+ };
+} CSR_API_MESSAGE, *PCSR_API_MESSAGE;
-typedef VOID (CALLBACK * CSR_SERVER_THREAD)(PVOID);
+typedef struct _CSR_CAPTURE_BUFFER
+{
+ ULONG Size;
+ struct _CSR_CAPTURE_BUFFER *PreviousCaptureBuffer;
+ ULONG PointerCount;
+ ULONG_PTR BufferEnd;
+} CSR_CAPTURE_BUFFER, *PCSR_CAPTURE_BUFFER;
-/* symbols exported by native DLL csrsrv.dll */
+/* Private data resumes here */
+typedef
+NTSTATUS
+(NTAPI *PCSR_API_ROUTINE)(
+ IN OUT PCSR_API_MESSAGE ApiMessage,
+ IN OUT PULONG Reply
+);
-NTSTATUS STDCALL CsrAddStaticServerThread(CSR_SERVER_THREAD);
-NTSTATUS STDCALL CsrCallServerFromServer();
-NTSTATUS STDCALL CsrCreateProcess(PCSR_SESSION,PCSR_PROCESS*);
-NTSTATUS STDCALL CsrCreateRemoteThread();
-NTSTATUS STDCALL CsrCreateSession(PCSR_SESSION*);
-NTSTATUS STDCALL CsrCreateThread(PCSR_PROCESS,PCSR_THREAD*);
-NTSTATUS STDCALL CsrCreateWait(PCSR_THREAD,PCSR_WAIT*);
-NTSTATUS STDCALL CsrDebugProcess(PCSR_PROCESS);
-NTSTATUS STDCALL CsrDebugProcessStop(PCSR_PROCESS);
-NTSTATUS STDCALL CsrDereferenceProcess(PCSR_PROCESS);
-NTSTATUS STDCALL CsrDereferenceThread(PCSR_THREAD);
-NTSTATUS STDCALL CsrDereferenceWait(PCSR_WAIT);
-NTSTATUS STDCALL CsrDestroyProcess(PCSR_PROCESS);
-NTSTATUS STDCALL CsrDestroySession (PCSR_SESSION);
-NTSTATUS STDCALL CsrDestroyThread(PCSR_THREAD);
-NTSTATUS STDCALL CsrExecServerThread();
-NTSTATUS STDCALL CsrGetProcessLuid(PCSR_PROCESS,PLUID);
-NTSTATUS STDCALL CsrImpersonateClient();
-NTSTATUS STDCALL CsrLockProcessByClientId();
-NTSTATUS STDCALL CsrLockThreadByClientId();
-NTSTATUS STDCALL CsrMoveSatisfiedWait(PCSR_WAIT);
-NTSTATUS STDCALL CsrNotifyWait(PCSR_WAIT);
-HANDLE STDCALL CsrQueryApiPort(VOID);
-NTSTATUS STDCALL CsrReferenceThread(PCSR_THREAD);
-NTSTATUS STDCALL CsrRevertToSelf();
-NTSTATUS STDCALL CsrServerInitialization(ULONG,LPWSTR*);
-NTSTATUS STDCALL CsrSetBackgroundPriority();
-NTSTATUS STDCALL CsrSetCallingSpooler();
-NTSTATUS STDCALL CsrSetForegroundPriority();
-NTSTATUS STDCALL CsrShutdownProcesses(PCSR_SESSION);
-NTSTATUS STDCALL CsrUnhandledExceptionFilter();
-NTSTATUS STDCALL CsrUnlockProcess(PCSR_PROCESS);
-NTSTATUS STDCALL CsrUnlockThread(PCSR_THREAD);
-NTSTATUS STDCALL CsrValidateMessageBuffer();
-NTSTATUS STDCALL CsrValidateMessageString();
+typedef struct _CSR_SERVER_DLL
+{
+ ULONG Length;
+ HANDLE Event;
+ ANSI_STRING Name;
+ HANDLE ServerHandle;
+ ULONG ServerId;
+ ULONG Unknown;
+ ULONG ApiBase;
+ ULONG HighestApiSupported;
+ PCSR_API_ROUTINE *DispatchTable;
+ PBOOLEAN ValidTable;
+ PCHAR *NameTable;
+ ULONG SizeOfProcessData;
+ PCSR_CONNECT_CALLBACK ConnectCallback;
+ PCSR_DISCONNECT_CALLBACK DisconnectCallback;
+ PCSR_HARDERROR_CALLBACK HardErrorCallback;
+ PVOID SharedSection;
+ PCSR_NEWPROCESS_CALLBACK NewProcessCallback;
+ PCSR_SHUTDOWNPROCESS_CALLBACK ShutdownProcessCallback;
+ ULONG Unknown2[3];
+} CSR_SERVER_DLL, *PCSR_SERVER_DLL;
-#endif /* ndef __INCLUDE_CSR_SERVER_H */
+typedef
+NTSTATUS
+(NTAPI *PCSR_SERVER_DLL_INIT_CALLBACK)(IN PCSR_SERVER_DLL ServerDll);
+
+typedef
+BOOLEAN
+(*CSR_WAIT_FUNCTION)(
+ IN PLIST_ENTRY WaitList,
+ IN PCSR_THREAD WaitThread,
+ IN PCSR_API_MESSAGE WaitApiMessage,
+ IN PVOID WaitContext,
+ IN PVOID WaitArgument1,
+ IN PVOID WaitArgument2,
+ IN ULONG WaitFlags
+);
+
+typedef struct _CSR_WAIT_BLOCK
+{
+ ULONG Size;
+ LIST_ENTRY WaitList;
+ LIST_ENTRY UserWaitList;
+ PVOID WaitContext;
+ PCSR_THREAD WaitThread;
+ CSR_WAIT_FUNCTION WaitFunction;
+ CSR_API_MESSAGE WaitApiMessage;
+} CSR_WAIT_BLOCK, *PCSR_WAIT_BLOCK;
+
+/* FIXME: Put into new SM headers */
+typedef struct _SB_CREATE_SESSION
+{
+ ULONG SessionId;
+ RTL_USER_PROCESS_INFORMATION ProcessInfo;
+} SB_CREATE_SESSION, *PSB_CREATE_SESSION;
+
+typedef struct _SB_TERMINATE_SESSION
+{
+ ULONG SessionId;
+} SB_TERMINATE_SESSION, *PSB_TERMINATE_SESSION;
+
+typedef struct _SB_FOREIGN_SESSION_COMPLETE
+{
+ ULONG SessionId;
+} SB_FOREIGN_SESSION_COMPLETE, *PSB_FOREIGN_SESSION_COMPLETE;
+
+typedef struct _SB_CREATE_PROCESS
+{
+ ULONG SessionId;
+} SB_CREATE_PROCESS, *PSB_CREATE_PROCESS;
+
+typedef struct _SB_CONNECTION_INFO
+{
+ ULONG SubsystemId;
+} SB_CONNECTION_INFO, *PSB_CONNECTION_INFO;
+
+typedef struct _SB_API_MESSAGE
+{
+ PORT_MESSAGE Header;
+ union
+ {
+ SB_CONNECTION_INFO ConnectionInfo;
+ struct
+ {
+ ULONG Opcode;
+ NTSTATUS Status;
+ union
+ {
+ SB_CREATE_SESSION SbCreateSession;
+ SB_TERMINATE_SESSION SbTerminateSession;
+ SB_FOREIGN_SESSION_COMPLETE SbForeignSessionComplete;
+ SB_CREATE_PROCESS SbCreateProcess;
+ };
+ };
+ };
+} SB_API_MESSAGE, *PSB_API_MESSAGE;
+
+typedef
+BOOLEAN
+(NTAPI *PSB_API_ROUTINE)(IN PSB_API_MESSAGE ApiMessage);
+
+NTSTATUS
+NTAPI
+SmSessionComplete(
+ IN HANDLE hApiPort,
+ IN ULONG SessionId,
+ IN NTSTATUS Status
+);
+
+NTSTATUS
+NTAPI
+SmConnectToSm(
+ IN PUNICODE_STRING SbApiPortName OPTIONAL,
+ IN HANDLE hSbApiPort OPTIONAL,
+ IN ULONG SubsystemType OPTIONAL,
+ OUT PHANDLE hSmApiPort
+);
+#endif
_____
Deleted: trunk/reactos/subsys/csr/args.c
--- trunk/reactos/subsys/csr/args.c 2005-09-27 01:57:27 UTC (rev
18117)
+++ trunk/reactos/subsys/csr/args.c 2005-09-27 04:53:33 UTC (rev
18118)
@@ -1,126 +0,0 @@
-/* $Id$
- *
- * args.c - Client/Server Runtime - command line parsing
- *
- * 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
- * Library 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 "csr.h"
-
-#define NDEBUG
-#include <debug.h>
-
-/**********************************************************************
- * NAME PRIVATE
- * CsrParseCommandLine/2
- */
-NTSTATUS FASTCALL CsrParseCommandLine (PPEB Peb,
- PCOMMAND_LINE_ARGUMENT Argument)
-{
- HANDLE ProcessHeap = Peb->ProcessHeap;
- PRTL_USER_PROCESS_PARAMETERS RtlProcessParameters =
RtlNormalizeProcessParams (Peb->ProcessParameters);
- INT i = 0;
- INT afterlastspace = 0;
-
-
- DPRINT("CSR: %s called\n", __FUNCTION__);
-
- RtlZeroMemory (Argument, sizeof (COMMAND_LINE_ARGUMENT));
-
- Argument->Vector = (PWSTR *) RtlAllocateHeap (ProcessHeap,
- 0,
-
(CSRP_MAX_ARGUMENT_COUNT * sizeof Argument->Vector[0]));
- if(NULL == Argument->Vector)
- {
- DPRINT("CSR: %s: no memory for Argument->Vector\n",
__FUNCTION__);
- return STATUS_NO_MEMORY;
- }
-
- Argument->Buffer.Length =
- Argument->Buffer.MaximumLength =
- RtlProcessParameters->CommandLine.Length
- + sizeof Argument->Buffer.Buffer [0]; /* zero terminated */
- Argument->Buffer.Buffer =
- (PWSTR) RtlAllocateHeap (ProcessHeap,
- 0,
- Argument->Buffer.MaximumLength);
- if(NULL == Argument->Buffer.Buffer)
- {
- DPRINT("CSR: %s: no memory for Argument->Buffer.Buffer\n",
__FUNCTION__);
- return STATUS_NO_MEMORY;
- }
-
- RtlCopyMemory (Argument->Buffer.Buffer,
- RtlProcessParameters->CommandLine.Buffer,
- RtlProcessParameters->CommandLine.Length);
-
- while (Argument->Buffer.Buffer [i])
- {
- if (Argument->Buffer.Buffer[i] == L' ')
- {
- Argument->Count ++;
- Argument->Buffer.Buffer [i] = L'\0';
- Argument->Vector [Argument->Count - 1] = &
(Argument->Buffer.Buffer [afterlastspace]);
- i++;
- while (Argument->Buffer.Buffer [i] == L' ')
- {
- i++;
- }
- afterlastspace = i;
- }
- else
- {
- i++;
- }
- }
-
- if (Argument->Buffer.Buffer [afterlastspace] != L'\0')
- {
- Argument->Count ++;
- Argument->Buffer.Buffer [i] = L'\0';
- Argument->Vector [Argument->Count - 1] = &
(Argument->Buffer.Buffer [afterlastspace]);
- }
-#if !defined(NDEBUG)
- for (i=0; i<Argument->Count; i++)
- {
- DPRINT("CSR: Argument[%d] = '%S'\n", i, Argument->Vector
[i]);
- }
-#endif
- return STATUS_SUCCESS;
-}
-/**********************************************************************
- * NAME PRIVATE
- * CsrFreeCommandLine/2
- */
-
-VOID FASTCALL CsrFreeCommandLine (PPEB Peb,
- PCOMMAND_LINE_ARGUMENT Argument)
-{
- DPRINT("CSR: %s called\n", __FUNCTION__);
-
- RtlFreeHeap (Peb->ProcessHeap,
- 0,
- Argument->Vector);
- RtlFreeHeap (Peb->ProcessHeap,
- 0,
- Argument->Buffer.Buffer);
-}
-/* EOF */
_____
Deleted: trunk/reactos/subsys/csr/csr.h
--- trunk/reactos/subsys/csr/csr.h 2005-09-27 01:57:27 UTC (rev
18117)
+++ trunk/reactos/subsys/csr/csr.h 2005-09-27 04:53:33 UTC (rev
18118)
@@ -1,34 +0,0 @@
-#if !defined(_INCLUDE_CSR_H)
-#define _INCLUDE_CSR_H
-
-/* PSDK/NDK Headers */
-#include <stdio.h>
-#include <windows.h>
-
-#define NTOS_MODE_USER
-#include <ndk/ntndk.h>
-
-#include <csr/server.h>
-
-
-#define CSRSS_ARGUMENT_SIZE 16
-
-/* args.c */
-#define CSRP_MAX_ARGUMENT_COUNT 512
-
-typedef struct _COMMAND_LINE_ARGUMENT
-{
- ULONG Count;
- UNICODE_STRING Buffer;
- PWSTR * Vector;
-
-} COMMAND_LINE_ARGUMENT, *PCOMMAND_LINE_ARGUMENT;
-
-NTSTATUS FASTCALL CsrParseCommandLine (PPEB,PCOMMAND_LINE_ARGUMENT);
-VOID FASTCALL CsrFreeCommandLine (PPEB,PCOMMAND_LINE_ARGUMENT);
-
-/* csrsrv.dll */
-NTSTATUS STDCALL CsrServerInitialization (ULONG,LPWSTR*);
-
-#endif /* !def _INCLUDE_CSR_H */
-
_____
Added: trunk/reactos/subsys/csr/csrsrv/api.c
--- trunk/reactos/subsys/csr/csrsrv/api.c 2005-09-27 01:57:27 UTC
(rev 18117)
+++ trunk/reactos/subsys/csr/csrsrv/api.c 2005-09-27 04:53:33 UTC
(rev 18118)
@@ -0,0 +1,1412 @@
+/*
+ * COPYRIGHT: See COPYING in the top level directory
+ * PROJECT: ReactOS CSR Sub System
+ * FILE: subsys/csr/csrsrv/api.c
+ * PURPOSE: CSR Server DLL API LPC Implementation
+ * PROGRAMMERS: Alex Ionescu (alex(a)relsoft.net)
+ */
+
+/* INCLUDES
******************************************************************/
+
+#include "srv.h"
+
+#define NDEBUG
+#include <debug.h>
+
+/* DATA
**********************************************************************/
+BOOLEAN (*CsrClientThreadSetup)(VOID) = NULL;
+ULONG CsrMaxApiRequestThreads;
+UNICODE_STRING CsrSbApiPortName;
+UNICODE_STRING CsrApiPortName;
+HANDLE CsrSbApiPort;
+HANDLE CsrApiPort;
+PCSR_THREAD CsrSbApiRequestThreadPtr;
+ULONG CsrpStaticThreadCount;
+ULONG CsrpDynamicThreadTotal;
+
+/* PRIVATE FUNCTIONS
*********************************************************/
+
+/*++
+ * @name CsrCheckRequestThreads
+ *
+ * The CsrCheckRequestThreads routine checks if there are no more
threads
+ * to handle CSR API Requests, and creates a new thread if possible, to
+ * avoid starvation.
+ *
+ * @param None.
+ *
+ * @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL
+ * if a new thread couldn't be created.
+ *
+ * @remarks None.
+ *
+ *--*/
+NTSTATUS
+NTAPI
+CsrCheckRequestThreads(VOID)
+{
+ HANDLE hThread;
+ CLIENT_ID ClientId;
+ NTSTATUS Status;
+
+ /* Decrease the count, and see if we're out */
+ if (!(InterlockedDecrement(&CsrpStaticThreadCount)))
+ {
+ /* Check if we've still got space for a Dynamic Thread */
+ if (CsrpDynamicThreadTotal < CsrMaxApiRequestThreads)
+ {
+ /* Create a new dynamic thread */
+ Status = RtlCreateUserThread(NtCurrentProcess(),
+ NULL,
+ TRUE,
+ 0,
+ 0,
+ 0,
+ CsrApiRequestThread,
+ NULL,
+ &hThread,
+ &ClientId);
+ /* Check success */
+ if(NT_SUCCESS(Status))
+ {
+ /* Increase the thread counts */
+ CsrpStaticThreadCount++;
+ CsrpDynamicThreadTotal++;
+
+ /* Add a new server thread */
+ if (CsrAddStaticServerThread(hThread,
+ &ClientId,
+ CsrThreadIsServerThread))
+ {
+ /* Activate it */
+ NtResumeThread(hThread,NULL);
+ }
+ else
+ {
+ /* Failed to create a new static thread */
+ CsrpStaticThreadCount--;
+ CsrpDynamicThreadTotal--;
+
+ /* Terminate it */
+ NtTerminateThread(hThread,0);
+ NtClose(hThread);
+
+ /* Return */
+ return STATUS_UNSUCCESSFUL;
+ }
+ }
+ }
+ }
+
+ /* Success */
+ return STATUS_SUCCESS;
+}
+
+/*++
+ * @name CsrSbApiPortInitialize
+ *
+ * The CsrSbApiPortInitialize routine initializes the LPC Port used for
+ * communications with the Session Manager (SM) and initializes the
static
+ * thread that will handle connection requests and APIs.
+ *
+ * @param None
+ *
+ * @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL
+ * othwerwise.
+ *
+ * @remarks None.
+ *
+ *--*/
+NTSTATUS
+NTAPI
+CsrSbApiPortInitialize(VOID)
+{
+ ULONG Size;
+ PSECURITY_DESCRIPTOR PortSd;
+ OBJECT_ATTRIBUTES ObjectAttributes;
+ NTSTATUS Status;
+ HANDLE hRequestThread;
+ CLIENT_ID ClientId;
+
+ /* Calculate how much space we'll need for the Port Name */
+ Size = CsrDirectoryName.Length + sizeof(SB_PORT_NAME) +
sizeof(WCHAR);
+
+ /* Allocate space for it, and create it */
+ CsrSbApiPortName.Buffer = RtlAllocateHeap(CsrHeap, 0, Size);
+ CsrSbApiPortName.Length = 0;
+ CsrSbApiPortName.MaximumLength = (USHORT)Size;
+ RtlAppendUnicodeStringToString(&CsrSbApiPortName,
&CsrDirectoryName);
+ RtlAppendUnicodeToString(&CsrSbApiPortName, UNICODE_PATH_SEP);
+ RtlAppendUnicodeToString(&CsrSbApiPortName, SB_PORT_NAME);
+
+ /* Create Security Descriptor for this Port */
+ CsrCreateLocalSystemSD(&PortSd);
+
+ /* Initialize the Attributes */
+ InitializeObjectAttributes(&ObjectAttributes,
+ &CsrSbApiPortName,
+ 0,
+ PortSd,
+ NULL);
+
+ /* Create the Port Object */
+ Status = NtCreatePort(&CsrSbApiPort,
+ &ObjectAttributes,
+ sizeof(SB_CONNECTION_INFO),
+ sizeof(SB_API_MESSAGE),
+ 32 * sizeof(SB_API_MESSAGE));
+ if(!NT_SUCCESS(Status))
+ {
+
+ }
+
+ /* Create the Thread to handle the API Requests */
+ Status = RtlCreateUserThread(NtCurrentProcess(),
+ NULL,
+ TRUE,
+ 0,
+ 0,
+ 0,
+ (PVOID)CsrSbApiRequestThread,
+ NULL,
+ &hRequestThread,
+ &ClientId);
+ if(!NT_SUCCESS(Status))
+ {
+
+ }
+
+ /* Add it as a Static Server Thread */
+ CsrSbApiRequestThreadPtr = CsrAddStaticServerThread(hRequestThread,
+ &ClientId,
+ 0);
+
+ /* Activate it */
+ return NtResumeThread(hRequestThread, NULL);
+}
+
+/*++
+ * @name CsrApiPortInitialize
+ *
+ * The CsrApiPortInitialize routine initializes the LPC Port used for
+ * communications with the Client/Server Runtime (CSR) and initializes
the
+ * static thread that will handle connection requests and APIs.
+ *
+ * @param None
+ *
+ * @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL
+ * othwerwise.
+ *
+ * @remarks None.
+ *
+ *--*/
+NTSTATUS
+NTAPI
+CsrApiPortInitialize(VOID)
+{
+ ULONG Size;
+ OBJECT_ATTRIBUTES ObjectAttributes;
+ NTSTATUS Status;
+ HANDLE hRequestEvent, hThread;
+ CLIENT_ID ClientId;
+ PLIST_ENTRY ListHead, NextEntry;
+ PCSR_THREAD ServerThread;
+
+ /* Calculate how much space we'll need for the Port Name */
+ Size = CsrDirectoryName.Length + sizeof(CSR_PORT_NAME) +
sizeof(WCHAR);
+
+ /* Allocate space for it, and create it */
+ CsrApiPortName.Buffer = RtlAllocateHeap(CsrHeap, 0, Size);
+ CsrApiPortName.Length = 0;
+ CsrApiPortName.MaximumLength = (USHORT)Size;
+ RtlAppendUnicodeStringToString(&CsrApiPortName, &CsrDirectoryName);
+ RtlAppendUnicodeToString(&CsrApiPortName, UNICODE_PATH_SEP);
+ RtlAppendUnicodeToString(&CsrApiPortName, CSR_PORT_NAME);
+
+ /* FIXME: Create a Security Descriptor */
+
+ /* Initialize the Attributes */
+ InitializeObjectAttributes(&ObjectAttributes,
+ &CsrApiPortName,
+ 0,
+ NULL,
+ NULL /* FIXME*/);
+
+ /* Create the Port Object */
+ Status = NtCreatePort(&CsrApiPort,
+ &ObjectAttributes,
+ sizeof(CSR_CONNECTION_INFO),
+ sizeof(CSR_API_MESSAGE),
+ 16 * PAGE_SIZE);
+ if(!NT_SUCCESS(Status))
+ {
+
+ }
+
+ /* Create the event the Port Thread will use */
+ Status = NtCreateEvent(&hRequestEvent,
+ EVENT_ALL_ACCESS,
+ NULL,
+ SynchronizationEvent,
+ FALSE);
+ if(!NT_SUCCESS(Status))
+ {
+
+ }
+
+ /* Create the Request Thread */
+ Status = RtlCreateUserThread(NtCurrentProcess(),
+ NULL,
+ TRUE,
+ 0,
+ 0,
+ 0,
+ (PVOID)CsrApiRequestThread,
+ (PVOID)hRequestEvent,
+ &hThread,
+ &ClientId);
+ if(!NT_SUCCESS(Status))
+ {
+
+ }
+
+ /* Add this as a static thread to CSRSRV */
+ CsrAddStaticServerThread(hThread, &ClientId,
CsrThreadIsServerThread);
+
+ /* Get the Thread List Pointers */
+ ListHead = &CsrRootProcess->ThreadList;
+ NextEntry = ListHead->Flink;
+
+ /* Start looping the list */
+ while (NextEntry != ListHead)
+ {
+ /* Get the Thread */
+ ServerThread = CONTAINING_RECORD(NextEntry, CSR_THREAD, Link);
+
+ /* Start it up */
+ Status = NtResumeThread(ServerThread->ThreadHandle, NULL);
+
+ /* Is this a Server Thread? */
+ if (ServerThread->Flags & CsrThreadIsServerThread)
+ {
+ /* If so, then wait for it to initialize */
+ NtWaitForSingleObject(hRequestEvent, FALSE, NULL);
+ }
+
+ /* Next thread */
+ NextEntry = NextEntry->Flink;
+ }
+
+ /* We don't need this anymore */
+ NtClose(hRequestEvent);
+
+ /* Return */
+ return Status;
+}
+
+/*++
+ * @name CsrApiRequestThread
+ *
+ * The CsrApiRequestThread routine handles incoming messages or
connection
+ * requests on the CSR API LPC Port.
+ *
+ * @param Parameter
+ * System-default user-defined parameter. Unused.
+ *
+ * @return The thread exit code, if the thread is terminated.
+ *
+ * @remarks Before listening on the port, the routine will first
attempt
+ * to connect to the user subsystem.
+ *
+ *--*/
+NTSTATUS
+NTAPI
+CsrApiRequestThread(IN PVOID Parameter)
+{
+ PTEB Teb = NtCurrentTeb();
+ LARGE_INTEGER TimeOut;
+ PCSR_THREAD CurrentThread;
+ NTSTATUS Status;
+ PCSR_API_MESSAGE ReplyMsg = NULL;
+ CSR_API_MESSAGE ReceiveMsg;
+ PCSR_THREAD CsrThread;
+ PCSR_PROCESS CsrProcess;
+ PHARDERROR_MSG HardErrorMsg;
+ PVOID PortContext;
+ ULONG MessageType;
+ ULONG i;
+ PCSR_SERVER_DLL ServerDll;
+ PCLIENT_DIED_MSG ClientDiedMsg;
+ PDBGKM_MSG DebugMessage;
+ ULONG ServerId, ApiId;
[truncated at 1000 lines; 8012 more skipped]