- 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.

svn path=/trunk/; revision=18118
This commit is contained in:
Alex Ionescu
2005-09-27 04:53:33 +00:00
parent 29322a96bc
commit 322841976a
20 changed files with 7003 additions and 1720 deletions
+1 -1
View File
@@ -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"
+1 -1
View File
@@ -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
+8
View File
@@ -393,6 +393,14 @@ typedef LPOSVERSIONINFOW PRTL_OSVERSIONINFOW;
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;
-37
View File
@@ -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 */
+286 -86
View File
@@ -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;
struct _CSR_WAIT;
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;
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
-126
View File
@@ -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 */
-34
View File
@@ -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 */
File diff suppressed because it is too large Load Diff
+37 -36
View File
@@ -1,37 +1,38 @@
; $Id$
LIBRARY csrsrv.dll
LIBRARY CSRSRV
EXPORTS
CsrAddStaticServerThread@4
CsrCallServerFromServer@0
CsrCreateProcess@8
CsrCreateRemoteThread@0
CsrCreateThread@8
CsrCreateWait@8
CsrDebugProcess@4
CsrDebugProcessStop@4
CsrDereferenceProcess@4
CsrDereferenceThread@4
CsrDereferenceWait@4
CsrDestroyProcess@4
CsrDestroyThread@4
CsrExecServerThread@0
CsrGetProcessLuid@8
CsrImpersonateClient@0
CsrLockProcessByClientId@0
CsrLockThreadByClientId@0
CsrMoveSatisfiedWait@4
CsrNotifyWait@4
CsrQueryApiPort@0
CsrReferenceThread@4
CsrRevertToSelf@0
CsrServerInitialization@8
CsrSetBackgroundPriority@0
CsrSetCallingSpooler@0
CsrSetForegroundPriority@0
CsrShutdownProcesses@4
CsrUnhandledExceptionFilter@0
CsrUnlockProcess@4
CsrUnlockThread@4
CsrValidateMessageBuffer@0
CsrValidateMessageString@0
; EOF
CsrAddStaticServerThread
CsrCallServerFromServer
CsrConnectToUser
CsrCreateProcess
CsrCreateRemoteThread
CsrCreateThread
CsrCreateWait
CsrDebugProcess
CsrDebugProcessStop
CsrDereferenceProcess
CsrDereferenceThread
CsrDereferenceWait
CsrDestroyProcess
CsrDestroyThread
CsrExecServerThread
CsrGetProcessLuid
CsrImpersonateClient
CsrLockProcessByClientId
CsrLockThreadByClientId
CsrMoveSatisfiedWait
CsrNotifyWait
CsrPopulateDosDevices
CsrQueryApiPort
CsrReferenceThread
CsrRevertToSelf
CsrServerInitialization
CsrSetBackgroundPriority
CsrSetCallingSpooler
CsrSetForegroundPriority
CsrShutdownProcesses
CsrUnhandledExceptionFilter
CsrUnlockProcess
CsrUnlockThread
CsrValidateMessageBuffer
CsrValidateMessageString
-53
View File
@@ -1,53 +0,0 @@
/* $Id$
*
* subsys/csr/csrsrv/debug.c - CSR server - debugging management
*
* 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 "srv.h"
//#define NDEBUG
#include <debug.h>
/*=====================================================================
* PUBLIC API
*===================================================================*/
NTSTATUS STDCALL CsrDebugProcess (PCSR_PROCESS pCsrProcess)
{
NTSTATUS Status = STATUS_NOT_IMPLEMENTED;
DPRINT("CSRSRV: %s(%08lx) called\n", __FUNCTION__, pCsrProcess);
return Status;
}
NTSTATUS STDCALL CsrDebugProcessStop (PCSR_PROCESS pCsrProcess)
{
NTSTATUS Status = STATUS_NOT_IMPLEMENTED;
DPRINT("CSRSRV: %s(%08lx) called\n", __FUNCTION__, pCsrProcess);
return Status;
}
/* EOF */
-33
View File
@@ -1,33 +0,0 @@
/* $Id$
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
* FILE: subsys/csr/csrsrv/dllmain.c
* PURPOSE: DLL entry point
*/
/* INCLUDES ******************************************************************/
#include "srv.h"
#define NDEBUG
#include <debug.h>
HANDLE CsrSrvDllHandle = 0;
/* FUNCTIONS *****************************************************************/
BOOL STDCALL
DllMain(HANDLE hDll,
DWORD dwReason,
LPVOID lpReserved)
{
if (DLL_PROCESS_ATTACH == dwReason)
{
CsrSrvDllHandle = hDll;
}
return TRUE;
}
/* EOF */
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+323 -150
View File
@@ -1,178 +1,351 @@
/* $Id$
*
* subsys/csr/csrsrv/session.c - CSR server - session management
*
* 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.
*
* --------------------------------------------------------------------
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS CSR Sub System
* FILE: subsys/csr/csrsrv/session.c
* PURPOSE: CSR Server DLL Session Implementation
* PROGRAMMERS: Alex Ionescu ([email protected])
*/
/* INCLUDES ******************************************************************/
#include "srv.h"
//#define NDEBUG
#define NDEBUG
#include <debug.h>
//TODO: when CsrSrvSessionsFlag is FALSE, create just one session and
//TODO: fail for more sessions requests.
/* DATA **********************************************************************/
RTL_CRITICAL_SECTION CsrNtSessionLock;
LIST_ENTRY CsrNtSessionList;
HANDLE CsrSmApiPort;
/* LOCALS */
struct {
RTL_CRITICAL_SECTION Lock;
HANDLE Heap;
ULONG LastUnusedId;
} Session;
NTSTATUS STDCALL CsrSrvInitializeSession (VOID)
PSB_API_ROUTINE CsrServerSbApiDispatch[5] =
{
NTSTATUS Status = STATUS_NOT_IMPLEMENTED;
CsrSbCreateSession,
CsrSbForeignSessionComplete,
CsrSbForeignSessionComplete,
CsrSbCreateProcess,
NULL
};
DPRINT("CSRSRV: %s called\n", __FUNCTION__);
Status = RtlInitializeCriticalSection (& Session.Lock);
if (NT_SUCCESS(Status))
{
Session.Heap = RtlCreateHeap (HEAP_GROWABLE,
NULL,
65536,
65536,
NULL,
NULL);
if (NULL == Session.Heap)
{
RtlDeleteCriticalSection (& Session.Lock);
Status = STATUS_NO_MEMORY;
}
Session.LastUnusedId = 0;
}
return Status;
PCHAR CsrServerSbApiName[5] =
{
"SbCreateSession",
"SbTerminateSEssion",
"SbForeignSessionComplete",
"SbCreateProcess",
"Unknown Csr Sb Api Number"
};
/* PRIVATE FUNCTIONS *********************************************************/
/*++
* @name CsrInitializeNtSessions
*
* The CsrInitializeNtSessions routine sets up support for CSR Sessions.
*
* @param None
*
* @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL
* othwerwise.
*
* @remarks None.
*
*--*/
NTSTATUS
NTAPI
CsrInitializeNtSessions(VOID)
{
NTSTATUS Status;
DPRINT("CSRSRV: %s called\n", __FUNCTION__);
/* Initialize the Session List */
InitializeListHead(&CsrNtSessionList);
/* Initialize the Session Lock */
Status = RtlInitializeCriticalSection(&CsrNtSessionLock);
return Status;
}
static NTSTATUS STDCALL CsrpCreateSessionDirectories (PCSR_SESSION pCsrSession)
/*++
* @name CsrAllocateNtSession
*
* The CsrAllocateNtSession routine allocates a new CSR NT Session.
*
* @param SessionId
* Session ID of the CSR NT Session to allocate.
*
* @return Pointer to the newly allocated CSR NT Session.
*
* @remarks None.
*
*--*/
PCSR_NT_SESSION
NTAPI
CsrAllocateNtSession(ULONG SessionId)
{
NTSTATUS Status = STATUS_SUCCESS;
CHAR SessionIdBuffer [8];
ANSI_STRING SessionIdNameA;
UNICODE_STRING SessionIdNameW;
UNICODE_STRING SessionDirectoryName;
OBJECT_ATTRIBUTES DirectoryAttributes;
HANDLE DirectoryHAndle;
PCSR_NT_SESSION NtSession;
DPRINT("CSRSRV: %s(%08lx) called\n", __FUNCTION__, pCsrSession);
/* Allocate an NT Session Object */
NtSession = RtlAllocateHeap(CsrHeap,
0,
sizeof(CSR_NT_SESSION));
sprintf (SessionIdBuffer, "\\Sessions\\%ld", pCsrSession->SessionId);
RtlInitAnsiString (& SessionIdNameA, SessionIdBuffer);
RtlAnsiStringToUnicodeString (& SessionIdNameW, & SessionIdNameA, TRUE);
RtlCopyUnicodeString (& SessionDirectoryName, & CsrSrvOption.NameSpace.Root);
RtlAppendUnicodeStringToString (& SessionDirectoryName, & SessionIdNameW);
/* Setup the Session Object */
if (NtSession)
{
NtSession->SessionId = SessionId;
NtSession->ReferenceCount = 1;
DPRINT("CSRSRV: %s(%08lx): %S\n", __FUNCTION__, pCsrSession,
SessionDirectoryName.Buffer);
/* Insert it into the Session List */
CsrAcquireNtSessionLock();
InsertHeadList(&CsrNtSessionList, &NtSession->SessionList);
CsrReleaseNtSessionLock();
}
InitializeObjectAttributes (& DirectoryAttributes,
& SessionDirectoryName,
OBJ_OPENIF,
NULL,
NULL);
Status = NtCreateDirectoryObject (& DirectoryHAndle,
(DIRECTORY_CREATE_OBJECT|DIRECTORY_CREATE_SUBDIRECTORY),
& DirectoryAttributes);
if (NT_SUCCESS(Status))
{
DPRINT1("CSRSRV: session %ld root directory not created (Status=%08lx)\n",
pCsrSession->SessionId, Status);
}
// TODO
return Status;
/* Return the Session (or NULL) */
return NtSession;
}
static NTSTATUS STDCALL CsrpDestroySessionDirectories (PCSR_SESSION pCsrSession)
/*++
* @name CsrReferenceNtSession
*
* The CsrReferenceNtSession increases the reference count of a CSR NT Session.
*
* @param Session
* Pointer to the CSR NT Session to reference.
*
* @return None.
*
* @remarks None.
*
*--*/
VOID
NTAPI
CsrReferenceNtSession(PCSR_NT_SESSION Session)
{
DPRINT("CSRSRV: %s called\n", __FUNCTION__);
return STATUS_NOT_IMPLEMENTED;
/* Acquire the lock */
CsrAcquireNtSessionLock();
/* Increase the reference count */
Session->ReferenceCount++;
/* Release the lock */
CsrReleaseNtSessionLock();
}
/*=====================================================================
* PUBLIC API
*===================================================================*/
NTSTATUS STDCALL CsrDestroySession (PCSR_SESSION pCsrSession)
/*++
* @name CsrDereferenceNtSession
*
* The CsrDereferenceNtSession decreases the reference count of a
* CSR NT Session.
*
* @param Session
* Pointer to the CSR NT Session to reference.
*
* @param ExitStatus
* If this is the last reference to the session, this argument
* specifies the exit status.
*
* @return None.
*
* @remarks CsrDereferenceNtSession will complete the session if
* the last reference to it has been closed.
*
*--*/
VOID
NTAPI
CsrDereferenceNtSession(PCSR_NT_SESSION Session,
NTSTATUS ExitStatus)
{
NTSTATUS Status = STATUS_SUCCESS;
/* Acquire the lock */
CsrAcquireNtSessionLock();
DPRINT("CSRSRV: %s(%08lx) called\n", __FUNCTION__, pCsrSession);
if (NULL == pCsrSession)
{
Status = STATUS_INVALID_PARAMETER;
} else {
Status = CsrShutdownProcesses (pCsrSession);
Status = CsrpDestroySessionDirectories (pCsrSession);
RtlDestroyHeap (pCsrSession->Heap);
RtlFreeHeap (Session.Heap, 0, pCsrSession);
}
return Status;
/* Dereference the Session Object */
if (!(--Session->ReferenceCount))
{
/* Remove it from the list */
RemoveEntryList(&Session->SessionList);
/* Release the lock */
CsrReleaseNtSessionLock();
/* Tell SM that we're done here */
SmSessionComplete(CsrSmApiPort, Session->SessionId, ExitStatus);
/* Free the Session Object */
RtlFreeHeap(CsrHeap, 0, Session);
}
else
{
/* Release the lock, the Session is still active */
CsrReleaseNtSessionLock();
}
}
NTSTATUS STDCALL CsrCreateSession (PCSR_SESSION * ppCsrSession)
{
NTSTATUS Status = STATUS_SUCCESS;
PCSR_SESSION pCsrSession = NULL;
DPRINT("CSRSRV: %s called\n", __FUNCTION__);
if (NULL == ppCsrSession)
{
Status = STATUS_INVALID_PARAMETER;
} else {
RtlEnterCriticalSection (& Session.Lock);
pCsrSession = RtlAllocateHeap (Session.Heap,
HEAP_ZERO_MEMORY,
sizeof (CSR_SESSION));
if (NULL == pCsrSession)
{
Status = STATUS_NO_MEMORY;
} else {
pCsrSession->SessionId = Session.LastUnusedId ++;
Status = CsrpCreateSessionDirectories (pCsrSession);
if(NT_SUCCESS(Status))
{
pCsrSession->Heap = RtlCreateHeap(HEAP_GROWABLE,
NULL,
65536,
65536,
NULL,
NULL);
if (NULL == pCsrSession->Heap)
{
Status = STATUS_NO_MEMORY;
CsrpDestroySessionDirectories (pCsrSession);
-- Session.LastUnusedId;
}
}
}
RtlLeaveCriticalSection (& Session.Lock);
}
return Status;
/* SESSION MANAGER FUNCTIONS**************************************************/
/*++
* @name CsrSbCreateSession
*
* The CsrSbCreateSession API is called by the Session Manager whenever a new
* session is created.
*
* @param ApiMessage
* Pointer to the Session Manager API Message.
*
* @return TRUE in case of success, FALSE othwerwise.
*
* @remarks The CsrSbCreateSession routine will initialize a new CSR NT
* Session and allocate a new CSR Process for the subsystem process.
*
*--*/
BOOLEAN
NTAPI
CsrSbCreateSession(IN PSB_API_MESSAGE ApiMessage)
{
PSB_CREATE_SESSION CreateSession = &ApiMessage->SbCreateSession;
HANDLE hProcess, hThread;
PCSR_PROCESS CsrProcess;
NTSTATUS Status;
KERNEL_USER_TIMES KernelTimes;
PCSR_THREAD CsrThread;
PVOID ProcessData;
ULONG i;
/* Save the Process and Thread Handles */
hProcess = CreateSession->ProcessInfo.ProcessHandle;
hThread = CreateSession->ProcessInfo.ThreadHandle;
/* Lock the Processes */
CsrAcquireProcessLock();
/* Allocate a new process */
if (!(CsrProcess = CsrAllocateProcess()))
{
/* Fail */
ApiMessage->Status = STATUS_NO_MEMORY;
CsrReleaseProcessLock();
return TRUE;
}
/* Setup Process Data */
CsrProcess->ClientId = CreateSession->ProcessInfo.ClientId;
CsrProcess->ProcessHandle = hProcess;
/* Set the exception port */
Status = NtSetInformationProcess(hProcess,
ProcessExceptionPort,
&CsrApiPort,
sizeof(HANDLE));
/* Check for success */
if (!NT_SUCCESS(Status))
{
/* Fail the request */
CsrDeallocateProcess(CsrProcess);
CsrReleaseProcessLock();
/* Strange as it seems, NTSTATUSes are actually returned */
return (BOOLEAN)STATUS_NO_MEMORY;
}
/* Get the Create Time */
Status = NtQueryInformationThread(hThread,
ThreadTimes,
&KernelTimes,
sizeof(KERNEL_USER_TIMES),
NULL);
/* Check for success */
if (!NT_SUCCESS(Status))
{
/* Fail the request */
CsrDeallocateProcess(CsrProcess);
CsrReleaseProcessLock();
return (BOOLEAN)Status;
}
/* Allocate a new Thread */
if (!(CsrThread = CsrAllocateThread(CsrProcess)))
{
/* Fail the request */
CsrDeallocateProcess(CsrProcess);
ApiMessage->Status = STATUS_NO_MEMORY;
CsrReleaseProcessLock();
return TRUE;
}
/* Setup the Thread Object */
CsrThread->CreateTime = KernelTimes.CreateTime;
CsrThread->ClientId = CreateSession->ProcessInfo.ClientId;
CsrThread->ThreadHandle = hThread;
CsrThread->Flags = 0;
/* Insert it into the Process List */
CsrInsertThread(CsrProcess, CsrThread);
/* Allocate a new Session */
CsrProcess->NtSession = CsrAllocateNtSession(CreateSession->SessionId);
/* Set the Process Priority */
CsrSetBackgroundPriority(CsrProcess);
/* Get the first data location */
ProcessData = &CsrProcess->ServerData[CSR_SERVER_DLL_MAX];
/* Loop every DLL */
for (i = 0; i < CSR_SERVER_DLL_MAX; i++)
{
/* Check if the DLL is loaded and has Process Data */
if (CsrLoadedServerDll[i] && CsrLoadedServerDll[i]->SizeOfProcessData)
{
/* Write the pointer to the data */
CsrProcess->ServerData[i] = ProcessData;
/* Move to the next data location */
ProcessData = (PVOID)((ULONG_PTR)ProcessData +
CsrLoadedServerDll[i]->SizeOfProcessData);
}
else
{
/* Nothing for this Process */
CsrProcess->ServerData[i] = NULL;
}
}
/* Insert the Process */
CsrInsertProcess(NULL, NULL, CsrProcess);
/* Activate the Thread */
ApiMessage->Status = NtResumeThread(hThread, NULL);
/* Release lock and return */
CsrReleaseProcessLock();
return TRUE;
}
/*++
* @name CsrSbForeignSessionComplete
*
* The CsrSbForeignSessionComplete API is called by the Session Manager
* whenever a foreign session is completed (ie: terminated).
*
* @param ApiMessage
* Pointer to the Session Manager API Message.
*
* @return TRUE in case of success, FALSE othwerwise.
*
* @remarks The CsrSbForeignSessionComplete API is not yet implemented.
*
*--*/
BOOLEAN
NTAPI
CsrSbForeignSessionComplete(IN PSB_API_MESSAGE ApiMessage)
{
/* Deprecated/Unimplemented in NT */
ApiMessage->Status = STATUS_NOT_IMPLEMENTED;
return TRUE;
}
/* EOF */
+329 -53
View File
@@ -1,72 +1,348 @@
#if !defined(_INCLUDE_CSR_CSRSRV_SRV_H)
#define _INCLUDE_CSR_CSRSRV_SRV_H
#ifndef _CSRSRV_H
#define _CSRSRV_H
/* PSDK/NDK Headers */
#define NTOS_MODE_USER
#include <stdio.h>
#include <windows.h>
#define NTOS_MODE_USER
#include <ndk/ntndk.h>
/* CSR Headers */
/* CSR Header */
#include <csr/server.h>
/* Maximum number of hosted servers, included the one in csrsrv.dll */
/* PSEH for SEH Support */
#include <pseh/pseh.h>
/* DEFINES *******************************************************************/
#define CSR_SERVER_DLL_MAX 4
typedef enum {
CSRSST_NONE=0,
CSRSST_TEXT,
CSRSST_WINDOWS,
CSRSST_MAX
} CSR_SUBSYSTEM_TYPE, * PCSR_SUBSYSTEM_TYPE;
#define CsrAcquireProcessLock() \
RtlEnterCriticalSection(&CsrProcessLock);
typedef struct _CSR_SERVER_DLL
{
USHORT ServerIndex;
USHORT Unused;
UNICODE_STRING DllName;
UNICODE_STRING DllEntryPoint;
} CSR_SERVER_DLL, * PCSR_SERVER_DLL;
#define CsrReleaseProcessLock() \
RtlLeaveCriticalSection(&CsrProcessLock);
/* dllmain.c */
extern HANDLE CsrSrvDllHandle;
#define CsrAcquireWaitLock() \
RtlEnterCriticalSection(&CsrWaitListsLock);
/* process.c */
#define CsrReleaseWaitLock() \
RtlLeaveCriticalSection(&CsrWaitListsLock);
/* server.c */
typedef struct
{
struct {
UNICODE_STRING Root;
HANDLE RootHandle;
} NameSpace;
CSR_SUBSYSTEM_TYPE SubSystemType;
struct {
USHORT RequestCount;
USHORT MaxRequestCount;
} Threads;
struct {
BOOL ProfileControl;
BOOL Windows;
BOOL Sessions;
} Flag;
USHORT PortSharedSectionSize;
struct {
USHORT InteractiveDesktopHeapSize;
USHORT NonInteractiveDesktopHeapSize;
} Heap;
} CSRSRV_OPTION, * PCSRSRV_OPTION;
#define CsrAcquireNtSessionLock() \
RtlEnterCriticalSection(&CsrNtSessionLock)
extern CSRSRV_OPTION CsrSrvOption;
extern HANDLE CsrSrvApiPortHandle;
#define CsrReleaseNtSessionLock() \
RtlLeaveCriticalSection(&CsrNtSessionLock)
NTSTATUS STDCALL CsrSrvRegisterServerDll (PCSR_SERVER_DLL);
NTSTATUS STDCALL CsrSrvBootstrap (VOID);
#define CsrHashThread(t) \
(HandleToUlong(t)&(256 - 1))
/* session.c */
NTSTATUS STDCALL CsrSrvInitializeSession (VOID);
#define SM_REG_KEY \
L"\\Registry\\Machine\\System\\CurrentControlSet\\Control\\Session Manager"
#define SESSION_ROOT L"\\Sessions"
#define GLOBAL_ROOT L"\\GLOBAL??"
#define SYMLINK_NAME L"SymbolicLink"
#define SB_PORT_NAME L"SbAbiPort"
#define CSR_PORT_NAME L"ApiPort"
#define UNICODE_PATH_SEP L"\\"
#endif /* !def _INCLUDE_CSR_CSRSRV_SRV_H */
/* DATA **********************************************************************/
extern ULONG CsrTotalPerProcessDataLength;
extern ULONG CsrMaxApiRequestThreads;
extern PCSR_SERVER_DLL CsrLoadedServerDll[CSR_SERVER_DLL_MAX];
extern PCSR_PROCESS CsrRootProcess;
extern UNICODE_STRING CsrSbApiPortName;
extern UNICODE_STRING CsrApiPortName;
extern HANDLE CsrSbApiPort;
extern HANDLE CsrSmApiPort;
extern HANDLE CsrApiPort;
extern HANDLE CsrHeap;
extern RTL_CRITICAL_SECTION CsrProcessLock;
extern RTL_CRITICAL_SECTION CsrWaitListsLock;
extern LIST_ENTRY CsrThreadHashTable[256];
extern HANDLE CsrInitializationEvent;
extern SYSTEM_BASIC_INFORMATION CsrNtSysInfo;
extern UNICODE_STRING CsrDirectoryName;
extern HANDLE CsrObjectDirectory;
extern PSB_API_ROUTINE CsrServerSbApiDispatch[5];
/* FUNCTIONS *****************************************************************/
/* FIXME: Public APIs should go in the CSR Server Include */
NTSTATUS
NTAPI
CsrLoadServerDll(
IN PCHAR DllString,
IN PCHAR EntryPoint,
IN ULONG ServerId
);
NTSTATUS
NTAPI
CsrCreateSessionObjectDirectory(IN ULONG SessionId);
NTSTATUS
NTAPI
CsrCreateObjectDirectory(IN PCHAR ObjectDirectory);
NTSTATUS
NTAPI
CsrSrvCreateSharedSection(IN PCHAR ParameterValue);
NTSTATUS
NTAPI
CsrInitializeNtSessions(VOID);
NTSTATUS
NTAPI
CsrInitializeProcesses(VOID);
NTSTATUS
NTAPI
CsrApiPortInitialize(VOID);
NTSTATUS
NTAPI
CsrSbApiPortInitialize(VOID);
BOOLEAN
NTAPI
CsrSbCreateSession(IN PSB_API_MESSAGE ApiMessage);
BOOLEAN
NTAPI
CsrSbForeignSessionComplete(IN PSB_API_MESSAGE ApiMessage);
BOOLEAN
NTAPI
CsrSbCreateProcess(IN PSB_API_MESSAGE ApiMessage);
PCSR_PROCESS
NTAPI
CsrAllocateProcess(VOID);
PCSR_THREAD
NTAPI
CsrAllocateThread(IN PCSR_PROCESS CsrProcess);
VOID
NTAPI
CsrInsertThread(
IN PCSR_PROCESS Process,
IN PCSR_THREAD Thread
);
VOID
NTAPI
CsrSetBackgroundPriority(IN PCSR_PROCESS CsrProcess);
VOID
NTAPI
CsrDeallocateProcess(IN PCSR_PROCESS CsrProcess);
NTSTATUS
NTAPI
CsrGetProcessLuid(
HANDLE hProcess,
PLUID Luid
);
BOOLEAN
NTAPI
CsrImpersonateClient(IN PCSR_THREAD CsrThread);
BOOLEAN
NTAPI
CsrRevertToSelf(VOID);
PCSR_THREAD
NTAPI
CsrLocateThreadByClientId(
OUT PCSR_PROCESS *Process,
IN PCLIENT_ID ClientId
);
VOID
NTAPI
CsrDereferenceNtSession(
IN PCSR_NT_SESSION Session,
NTSTATUS ExitStatus
);
VOID
NTAPI
CsrReferenceNtSession(PCSR_NT_SESSION Session);
VOID
NTAPI
CsrLockedDereferenceThread(PCSR_THREAD CsrThread);
VOID
NTAPI
CsrLockedDereferenceProcess(PCSR_PROCESS CsrProcess);
NTSTATUS
NTAPI
CsrLockProcessByClientId(
IN HANDLE Pid,
OUT PCSR_PROCESS *CsrProcess OPTIONAL
);
NTSTATUS
NTAPI
CsrUnlockProcess(PCSR_PROCESS CsrProcess);
NTSTATUS
NTAPI
CsrSrvClientConnect(
IN OUT PCSR_API_MESSAGE ApiMessage,
IN OUT PULONG Reply
);
NTSTATUS
NTAPI
CsrSrvUnusedFunction(
IN OUT PCSR_API_MESSAGE ApiMessage,
IN OUT PULONG Reply
);
NTSTATUS
NTAPI
CsrSrvIdentifyAlertableThread(
IN OUT PCSR_API_MESSAGE ApiMessage,
IN OUT PULONG Reply
);
NTSTATUS
NTAPI
CsrSrvSetPriorityClass(
IN OUT PCSR_API_MESSAGE ApiMessage,
IN OUT PULONG Reply
);
NTSTATUS
NTAPI
CsrServerDllInitialization(IN PCSR_SERVER_DLL LoadedServerDll);
VOID
NTAPI
CsrDereferenceThread(PCSR_THREAD CsrThread);
VOID
NTAPI
CsrSbApiRequestThread(IN PVOID Parameter);
NTSTATUS
NTAPI
CsrApiRequestThread(IN PVOID Parameter);
PCSR_THREAD
NTAPI
CsrAddStaticServerThread(
IN HANDLE hThread,
IN PCLIENT_ID ClientId,
IN ULONG ThreadFlags
);
PCSR_THREAD
NTAPI
CsrConnectToUser(VOID);
PCSR_THREAD
NTAPI
CsrLocateThreadInProcess(
IN PCSR_PROCESS CsrProcess OPTIONAL,
IN PCLIENT_ID Cid
);
NTSTATUS
NTAPI
CsrSbApiHandleConnectionRequest(IN PSB_API_MESSAGE Message);
NTSTATUS
NTAPI
CsrApiHandleConnectionRequest(IN PCSR_API_MESSAGE ApiMessage);
NTSTATUS
NTAPI
CsrSrvAttachSharedSection(
IN PCSR_PROCESS CsrProcess OPTIONAL,
OUT PCSR_CONNECTION_INFO ConnectInfo
);
VOID
NTAPI
CsrReleaseCapturedArguments(IN PCSR_API_MESSAGE ApiMessage);
BOOLEAN
NTAPI
CsrNotifyWaitBlock(
IN PCSR_WAIT_BLOCK WaitBlock,
IN PLIST_ENTRY WaitList,
IN PVOID WaitArgument1,
IN PVOID WaitArgument2,
IN ULONG WaitFlags,
IN BOOLEAN DereferenceThread
);
VOID
NTAPI
CsrDereferenceProcess(PCSR_PROCESS CsrProcess);
VOID
NTAPI
CsrInsertProcess(
IN PCSR_PROCESS Parent OPTIONAL,
IN PCSR_PROCESS CurrentProcess OPTIONAL,
IN PCSR_PROCESS CsrProcess
);
NTSTATUS
NTAPI
CsrPopulateDosDevicesDirectory(
IN HANDLE DosDevicesDirectory,
IN PPROCESS_DEVICEMAP_INFORMATION DeviceMap
);
BOOLEAN
NTAPI
CsrValidateMessageBuffer(
IN PCSR_API_MESSAGE ApiMessage,
IN PVOID *Buffer,
IN ULONG ArgumentSize,
IN ULONG ArgumentCount
);
NTSTATUS
NTAPI
CsrCreateLocalSystemSD(OUT PSECURITY_DESCRIPTOR *LocalSystemSd);
NTSTATUS
NTAPI
CsrDestroyThread(IN PCLIENT_ID Cid);
NTSTATUS
NTAPI
CsrDestroyProcess(
IN PCLIENT_ID Cid,
IN NTSTATUS ExitStatus
);
_SEH_FILTER(CsrUnhandledExceptionFilter);
VOID
NTAPI
CsrProcessRefcountZero(IN PCSR_PROCESS CsrProcess);
VOID
NTAPI
CsrThreadRefcountZero(IN PCSR_THREAD CsrThread);
NTSTATUS
NTAPI
CsrSetDirectorySecurity(IN HANDLE ObjectDirectory);
#endif
+111
View File
@@ -0,0 +1,111 @@
/*
* CSRSRV Status
*/
/* Organization
*
* api.c - Handles the LPC Reply/Request Threads which wait on Sb and Csr APIs.
* Also in charge of creating those threads and setting up the ports.
* Finally, it provides external APIs for validating the API buffers
* and doing server-to-server API calls.
*
* init.c - Handles initialization of CSRSRV, including command-line parsing,
* loading the Server DLLs, creating the Session Directories, setting
* up the DosDevices Object Directory, and initializing each component.
*
* process.c - Handles all internal functions dealing with the CSR Process Object,
* including de/allocation, de/referencing, un/locking, prority, and
* lookups. Also handles all external APIs which touch the CSR Process Object.
*
* server.c - Handles all internal functions related to loading and managing Server
* DLLs, as well as the routines handling the Shared Static Memory Section.
* Holds the API Dispatch/Valid/Name Tables and the public CSR_SERVER API
* interface. Also home of the SEH handler.
*
* session.c - Handles all internal functions dealing with the CSR Session Object,
* including de/allocation, de/referencing, and un/locking. Holds the SB API
* Dispatch/Name Tables and the public CsrSv API Interface for commmunication
* with the Session Manager.
*
* thread.c - Handles all internal functions dealing with the CSR Thread Object,
* including de/allocation, de/referencing, un/locking, impersonation, and
* lookups. Also handles all external APIs which touch the CSR Thread Object.
*
* wait.c - Handles all internal functions dealing with the CSR Wait Object,
* including de/allocation, de/referencing and un/locking. Also implements
* the external Wait API for creating, removing and/or notifying waits.
*/
/* Exported APIs, their location, and their status
* CsrAddStaticServerThread 753E679E 1 - server.c - IMPLEMENTED
* CsrCallServerFromServer 753E4FD9 2 - api.c - IMPLEMENTED
* CsrConnectToUser 753E4E48 3 - api.c - IMPLEMENTED
* CsrCreateProcess 753E6FD3 4 - process.c - IMPLEMENTED
* CsrCreateRemoteThread 753E73BD 5 - thread.c - IMPLEMENTED
* CsrCreateThread 753E72DA 6 - thread.c - IMPLEMENTED
* CsrCreateWait 753E770E 7 - wait.c - IMPLEMENTED
* CsrDebugProcess 753E7682 8 - process.c - IMPLEMENTED
* CsrDebugProcessStop 753E768A 9 - process.c - IMPLEMENTED
* CsrDereferenceProcess 753E6281 10 - process.c - IMPLEMENTED
* CsrDereferenceThread 753E6964 11 - thread.c - IMPLEMENTED
* CsrDereferenceWait 753E7886 12 - wait.c - IMPLEMENTED
* CsrDestroyProcess 753E7225 13 - process.c - IMPLEMENTED
* CsrDestroyThread 753E7478 14 - thread.c - IMPLEMENTED
* CsrExecServerThread 753E6841 15 - thread.c - IMPLEMENTED
* CsrGetProcessLuid 753E632F 16 - process.c - IMPLEMENTED
* CsrImpersonateClient 753E60F8 17 - thread.c - IMPLEMENTED
* CsrLockProcessByClientId 753E668F 18 - process.c - IMPLEMENTED
* CsrLockThreadByClientId 753E6719 19 - thread.c - IMPLEMENTED
* CsrMoveSatisfiedWait 753E7909 20 - wait.c - IMPLEMENTED
* CsrNotifyWait 753E782F 21 - wait.c - IMPLEMENTED
* CsrPopulateDosDevices 753E37A5 22 - init.c - IMPLEMENTED
* CsrQueryApiPort 753E4E42 23 - api.c - IMPLEMENTED
* CsrReferenceThread 753E61E5 24 - thread.c - IMPLEMENTED
* CsrRevertToSelf 753E615A 25 - thread.c - IMPLEMENTED
* CsrServerInitialization 753E3D75 26 - server.c - IMPLEMENTED
* CsrSetBackgroundPriority 753E5E87 27 - process.c - IMPLEMENTED
* CsrSetCallingSpooler 753E6425 28 - server.c - IMPLEMENTED
* CsrSetForegroundPriority 753E5E67 29 - process.c - IMPLEMENTED
* CsrShutdownProcesses 753E7547 30 - process.c - IMPLEMENTED
* CsrUnhandledExceptionFilter 753E3FE3 31 - server.c - IMPLEMENTED
* CsrUnlockProcess 753E66FD 32 - process.c - IMPLEMENTED
* CsrUnlockThread 753E7503 33 - thread.c - IMPLEMENTED
* CsrValidateMessageBuffer 753E528D 34 - api.c - IMPLEMENTED
* CsrValidateMessageString 753E5323 35 - api.c - UNIMPLEMENTED
*/
/* Public CSR API Interface Status (server.c)
* CsrSrvClientConnect - IMPLEMENTED
* CsrSrvUnusedFunction - IMPLEMENTED
* CsrSrvIdentifyAlertableThread - IMPLEMENTED
* CsrSrvSetPriorityClass - IMPLEMENTED
*/
/* Public SB API Interface Status (session.c)
* CsrSbCreateSession - IMPLEMENTED
* CsrSbForeignSessionComplete - IMPLEMENTED
* CsrSbTerminateSession - IMPLEMENTED
* CsrSbCreateProcess - UNIMPLEMENTED
*/
/* What's missing:
*
* - SMSS needs to be partly re-written to match some things done here.
* Among other things, SmConnectToSm, SmCompleteSession and the other
* Sm* Exported APIs have to be properly implemented, as well as the
* callback calling and SM LPC APIs. [NOT DONE]
*
* - NTDLL needs to get the Csr* routines properly implemented. [DONE!]
*
* - KERNEL32, USER32 need to register with their servers properly.
* Additionally, user32 needs to have ClientThreadStartup implemented
* properly and do the syscall NtUserInitialize (I think) which also
* needs to be implemented in win32k.sys. All this should be less then
* 100 lines of code. [KERNEL32 50% DONE, USER32 NOT DONE]
*
* - The skeleton code for winsrv and basesrv which connects with CSR/CSRSRV
* needs to be written. [NOT DONE]
*
* - The kernel's LPC implementation needs to be made compatible. [NOT DONE]
*/
File diff suppressed because it is too large Load Diff
+431 -52
View File
@@ -1,72 +1,451 @@
/* $Id$
*
* subsys/csr/csrsrv/wait.c - CSR server - wait management
*
* 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.
*
* --------------------------------------------------------------------
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS CSR Sub System
* FILE: subsys/csr/csrsrv/wait.c
* PURPOSE: CSR Server DLL Wait Implementation
* PROGRAMMERS: Emanuele Aliberti
* Alex Ionescu ([email protected])
*/
/* INCLUDES ******************************************************************/
#include "srv.h"
//#define NDEBUG
#define NDEBUG
#include <debug.h>
/*=====================================================================
* PUBLIC API
*===================================================================*/
/* DATA **********************************************************************/
NTSTATUS STDCALL CsrCreateWait (PCSR_THREAD pCsrThread, PCSR_WAIT * ppCsrWait)
RTL_CRITICAL_SECTION CsrWaitListsLock;
/* PRIVATE FUNCTIONS *********************************************************/
/*++
* @name CsrInitializeWait
*
* The CsrInitializeWait routine initializes a CSR Wait Object.
*
* @param WaitFunction
* Pointer to the function that will handle this wait.
*
* @param CsrWaitThread
* Pointer to the CSR Thread that will perform the wait.
*
* @param WaitApiMessage
* Pointer to the CSR API Message associated to this wait.
*
* @param WaitContext
* Pointer to a user-defined parameter associated to this wait.
*
* @param NewWaitBlock
* Pointed to the initialized CSR Wait Block for this wait.
*
* @return TRUE in case of success, FALSE othwerwise.
*
* @remarks None.
*
*--*/
BOOLEAN
NTAPI
CsrInitializeWait(IN CSR_WAIT_FUNCTION WaitFunction,
IN PCSR_THREAD CsrWaitThread,
IN OUT PCSR_API_MESSAGE WaitApiMessage,
IN PVOID WaitContext,
OUT PCSR_WAIT_BLOCK *NewWaitBlock)
{
NTSTATUS Status = STATUS_NOT_IMPLEMENTED;
DPRINT("CSRSRV: %s called\n", __FUNCTION__);
return Status;
ULONG Size;
PCSR_WAIT_BLOCK WaitBlock;
/* Calculate the size of the wait block */
Size = sizeof(CSR_WAIT_BLOCK) -
sizeof(WaitBlock->WaitApiMessage) +
WaitApiMessage->Header.u1.s1.TotalLength;
/* Allocate the Wait Block */
if (!(WaitBlock = RtlAllocateHeap(CsrHeap, 0, Size)))
{
/* Fail */
WaitApiMessage->Status = STATUS_NO_MEMORY;
return FALSE;
}
/* Initialize it */
WaitBlock->Size = Size;
WaitBlock->WaitThread = CsrWaitThread;
WaitBlock->WaitContext = WaitContext;
WaitBlock->WaitFunction = WaitFunction;
InitializeListHead(&WaitBlock->UserWaitList);
InitializeListHead(&WaitBlock->WaitList);
/* Copy the message */
RtlMoveMemory(&WaitBlock->WaitApiMessage,
WaitApiMessage,
WaitApiMessage->Header.u1.s1.TotalLength);
/* Return the block */
*NewWaitBlock = WaitBlock;
return TRUE;
}
NTSTATUS STDCALL CsrDereferenceWait (PCSR_WAIT pCsrWait)
/*++
* @name CsrNotifyWaitBlock
*
* The CsrNotifyWaitBlock routine calls the wait function for a registered
* CSR Wait Block, and replies to the attached CSR API Message, if any.
*
* @param WaitBlock
* Pointer to the CSR Wait Block
*
* @param WaitList
* Pointer to the wait list for this wait.
*
* @param WaitArgument[1-2]
* User-defined values to pass to the wait function.
*
* @param WaitFlags
* Wait flags for this wait.
*
* @param DereferenceThread
* Specifies whether the CSR Thread should be dereferenced at the
* end of this wait.
*
* @return TRUE in case of success, FALSE otherwise.
*
* @remarks After a wait block is notified, the wait function becomes invalid.
*
*--*/
BOOLEAN
NTAPI
CsrNotifyWaitBlock(IN PCSR_WAIT_BLOCK WaitBlock,
IN PLIST_ENTRY WaitList,
IN PVOID WaitArgument1,
IN PVOID WaitArgument2,
IN ULONG WaitFlags,
IN BOOLEAN DereferenceThread)
{
NTSTATUS Status = STATUS_NOT_IMPLEMENTED;
DPRINT("CSRSRV: %s called\n", __FUNCTION__);
return Status;
/* Call the wait function */
if ((WaitBlock->WaitFunction)(WaitList,
WaitBlock->WaitThread,
&WaitBlock->WaitApiMessage,
WaitBlock->WaitContext,
WaitArgument1,
WaitArgument2,
WaitFlags))
{
/* The wait is done, clear the block */
WaitBlock->WaitThread->WaitBlock = NULL;
/* Check for captured arguments */
if (WaitBlock->WaitApiMessage.CsrCaptureData)
{
/* Release them */
CsrReleaseCapturedArguments(&WaitBlock->WaitApiMessage);
}
/* Reply to the port */
NtReplyPort(WaitBlock->WaitThread->Process->ClientPort,
(PPORT_MESSAGE)&WaitBlock->WaitApiMessage);
/* Check if we should dereference the thread */
if (DereferenceThread)
{
/* Remove it from the Wait List */
if (WaitBlock->WaitList.Flink)
{
RemoveEntryList(&WaitBlock->WaitList);
}
/* Remove it from the User Wait List */
if (WaitBlock->UserWaitList.Flink)
{
RemoveEntryList(&WaitBlock->UserWaitList);
}
/* Dereference teh thread */
CsrDereferenceThread(WaitBlock->WaitThread);
/* Free the wait block */
RtlFreeHeap(CsrHeap, 0, WaitBlock);
}
else
{
/* The wait is complete, but the thread is being kept alive */
WaitBlock->WaitFunction = NULL;
}
/* The wait suceeded*/
return TRUE;
}
/* The wait failed */
return FALSE;
}
NTSTATUS STDCALL CsrMoveSatisfiedWait (PCSR_WAIT pCsrWait)
/* PUBLIC FUNCTIONS **********************************************************/
/*++
* @name CsrCreateWait
* @implemented NT4
*
* The CsrCreateWait routine creates a CSR Wait.
*
* @param WaitList
* Pointer to a list entry of the waits to associate.
*
* @param WaitFunction
* Pointer to the function that will handle this wait.
*
* @param CsrWaitThread
* Pointer to the CSR Thread that will perform the wait.
*
* @param WaitApiMessage
* Pointer to the CSR API Message associated to this wait.
*
* @param WaitContext
* Pointer to a user-defined parameter associated to this wait.
*
* @param UserWaitList
* Pointer to a list entry of the user-defined waits to associate.
*
* @return TRUE in case of success, FALSE otherwise.
*
* @remarks None.
*
*--*/
BOOLEAN
NTAPI
CsrCreateWait(IN PLIST_ENTRY WaitList,
IN CSR_WAIT_FUNCTION WaitFunction,
IN PCSR_THREAD CsrWaitThread,
IN OUT PCSR_API_MESSAGE WaitApiMessage,
IN PVOID WaitContext,
IN PLIST_ENTRY UserWaitList OPTIONAL)
{
NTSTATUS Status = STATUS_NOT_IMPLEMENTED;
DPRINT("CSRSRV: %s called\n", __FUNCTION__);
return Status;
PCSR_WAIT_BLOCK WaitBlock;
/* Initialize the wait */
if (!CsrInitializeWait(WaitFunction,
CsrWaitThread,
WaitApiMessage,
WaitContext,
&WaitBlock))
{
return FALSE;
}
/* Acquire the Wait Lock */
CsrAcquireWaitLock();
/* Make sure the thread wasn't destroyed */
if (CsrWaitThread && (CsrWaitThread->Flags & CsrThreadTerminated))
{
/* Fail the wait */
CsrWaitThread->WaitBlock = NULL;
RtlFreeHeap(CsrHeap, 0, WaitBlock);
CsrReleaseWaitLock();
return FALSE;
}
/* Insert the wait in the queue */
InsertTailList(WaitList, &WaitBlock->WaitList);
/* Insert the User Wait too, if one was given */
if (UserWaitList) InsertTailList(UserWaitList, &WaitBlock->UserWaitList);
/* Return */
CsrReleaseWaitLock();
return TRUE;
}
NTSTATUS STDCALL CsrNotifyWait (PCSR_WAIT pCsrWait)
/*++
* @name CsrDereferenceWait
* @implemented NT4
*
* The CsrDereferenceWait routine derefences a CSR Wait Block.
*
* @param WaitList
* Pointer to the Wait List associated to the wait.
* @return None.
*
* @remarks None.
*
*--*/
VOID
NTAPI
CsrDereferenceWait(IN PLIST_ENTRY WaitList)
{
NTSTATUS Status = STATUS_NOT_IMPLEMENTED;
DPRINT("CSRSRV: %s called\n", __FUNCTION__);
return Status;
PLIST_ENTRY ListHead, NextEntry;
PCSR_WAIT_BLOCK WaitBlock;
/* Acquire the Process and Wait Locks */
CsrAcquireProcessLock();
CsrAcquireWaitLock();
/* Set the list pointers */
ListHead = WaitList;
NextEntry = ListHead->Flink;
/* Start the loop */
while (NextEntry != ListHead)
{
/* Get the wait block */
WaitBlock = CONTAINING_RECORD(NextEntry, CSR_WAIT_BLOCK, WaitList);
/* Move to the next entry */
NextEntry = NextEntry->Flink;
/* Check if there's no Wait Routine */
if (!WaitBlock->WaitFunction)
{
/* Remove it from the Wait List */
if (WaitBlock->WaitList.Flink)
{
RemoveEntryList(&WaitBlock->WaitList);
}
/* Remove it from the User Wait List */
if (WaitBlock->UserWaitList.Flink)
{
RemoveEntryList(&WaitBlock->UserWaitList);
}
/* Dereference the thread waiting on it */
CsrDereferenceThread(WaitBlock->WaitThread);
/* Free the block */
RtlFreeHeap(CsrHeap, 0, WaitBlock);
}
}
/* Release the locks */
CsrReleaseWaitLock();
CsrReleaseProcessLock();
}
/*++
* @name CsrMoveSatisfiedWait
* @implemented NT5
*
* The CsrMoveSatisfiedWait routine moves satisfied waits from a wait list
* to another list entry.
*
* @param NewEntry
* Pointer to a list entry where the satisfied waits will be added.
*
* @param WaitList
* Pointer to a list entry to analyze for satisfied waits.
*
* @return None.
*
* @remarks None.
*
*--*/
VOID
NTAPI
CsrMoveSatisfiedWait(IN PLIST_ENTRY NewEntry,
IN PLIST_ENTRY WaitList)
{
PLIST_ENTRY ListHead, NextEntry;
PCSR_WAIT_BLOCK WaitBlock;
/* Acquire the Wait Lock */
CsrAcquireWaitLock();
/* Set the List pointers */
ListHead = WaitList;
NextEntry = ListHead->Flink;
/* Start looping */
while (NextEntry != ListHead)
{
/* Get the Wait block */
WaitBlock = CONTAINING_RECORD(NextEntry, CSR_WAIT_BLOCK, WaitList);
/* Go to the next entry */
NextEntry = NextEntry->Flink;
/* Check if there is a Wait Callback */
if (WaitBlock->WaitFunction)
{
/* Remove it from the Wait Block Queue */
RemoveEntryList(&WaitBlock->WaitList);
/* Insert the new entry */
InsertTailList(&WaitBlock->WaitList, NewEntry);
}
}
/* Release the wait lock */
CsrReleaseWaitLock();
}
/*++
* @name CsrNotifyWait
* @implemented NT4
*
* The CsrNotifyWait notifies a CSR Wait Block.
*
* @param WaitList
* Pointer to the list entry for this wait.
*
* @param WaitType
* Type of the wait to perform, either WaitAny or WaitAll.
*
* @param WaitArgument[1-2]
* User-defined argument to pass on to the wait function.
*
* @return TRUE in case of success, FALSE othwerwise.
*
* @remarks None.
*
*--*/
BOOLEAN
NTAPI
CsrNotifyWait(IN PLIST_ENTRY WaitList,
IN ULONG WaitType,
IN PVOID WaitArgument1,
IN PVOID WaitArgument2)
{
PLIST_ENTRY ListHead, NextEntry;
PCSR_WAIT_BLOCK WaitBlock;
BOOLEAN NotifySuccess = FALSE;
/* Acquire the Wait Lock */
CsrAcquireWaitLock();
/* Set the List pointers */
ListHead = WaitList;
NextEntry = ListHead->Flink;
/* Start looping */
while (NextEntry != ListHead)
{
/* Get the Wait block */
WaitBlock = CONTAINING_RECORD(NextEntry, CSR_WAIT_BLOCK, WaitList);
/* Go to the next entry */
NextEntry = NextEntry->Flink;
/* Check if there is a Wait Callback */
if (WaitBlock->WaitFunction)
{
/* Notify the Waiter */
NotifySuccess |= CsrNotifyWaitBlock(WaitBlock,
WaitList,
WaitArgument1,
WaitArgument2,
0,
FALSE);
/* We've already done a wait, so leave unless this is a Wait All */
if (WaitType != WaitAll) break;
}
}
/* Release the wait lock and return */
CsrReleaseWaitLock();
return NotifySuccess;
}
/* EOF */
+72 -89
View File
@@ -1,104 +1,87 @@
/* $Id$
*
* main.c - Client/Server Runtime - entry point
*
* 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.
*
* --------------------------------------------------------------------
*
* 19990417 (Emanuele Aliberti)
* Do nothing native application skeleton
* 19990528 (Emanuele Aliberti)
* Compiled successfully with egcs 1.1.2
* 19990605 (Emanuele Aliberti)
* First standalone run under ReactOS (it
* actually does nothing but running).
* 20050329 (Emanuele Aliberti)
* C/S run-time moved to CSRSRV.DLL
* Win32 emulation moved to server DLLs basesrv+winsrv
* (previously code was already in win32csr.dll)
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS CSR Sub System
* FILE: subsys/csr/csrss.c
* PURPOSE: CSR Executable
* PROGRAMMERS: Alex Ionescu ([email protected])
*/
#include "csr.h"
/* INCLUDES ******************************************************************/
#include <windows.h>
#define NTOS_MODE_USER
#include <ndk/ntndk.h>
#define NDEBUG
#include <debug.h>
COMMAND_LINE_ARGUMENT Argument;
/* PRIVATE FUNCTIONS *********************************************************/
/* never fail or so */
VOID STDCALL CsrpSetDefaultProcessHardErrorMode (VOID)
VOID
NTAPI
CsrpSetDefaultProcessHardErrorMode (VOID)
{
DWORD DefaultHardErrorMode = 0;
NtSetInformationProcess (NtCurrentProcess(),
ProcessDefaultHardErrorMode,
& DefaultHardErrorMode,
sizeof DefaultHardErrorMode);
ULONG DefaultHardErrorMode = 0;
/* Disable hard errors */
NtSetInformationProcess(NtCurrentProcess(),
ProcessDefaultHardErrorMode,
&DefaultHardErrorMode,
sizeof(DefaultHardErrorMode);
}
/* Native process' entry point */
VOID STDCALL NtProcessStartup (PPEB Peb)
int
_cdecl
main(int argc,
char *argv[],
char *envp[],
int DebugFlag)
{
NTSTATUS Status = STATUS_SUCCESS;
KPRIORITY BasePriority = (8 + 1) + 4;
NTSTATUS Status;
ULONG Response;
/*
* Parse the command line.
*/
Status = CsrParseCommandLine (Peb, & Argument);
if (STATUS_SUCCESS != Status)
{
DPRINT1("CSR: %s: CsrParseCommandLine failed (Status=0x%08lx)\n",
__FUNCTION__, Status);
}
/*
* Initialize the environment subsystem server.
*/
Status = CsrServerInitialization (Argument.Count, Argument.Vector);
if (!NT_SUCCESS(Status))
{
/* FATAL! */
DPRINT1("CSR: %s: CSRSRV!CsrServerInitialization failed (Status=0x%08lx)\n",
__FUNCTION__, Status);
/* Set the Priority */
NtSetInformationProcess(NtCurrentProcess(),
ProcessBasePriority,
&BasePriority,
sizeof(KPRIORITY));
CsrFreeCommandLine (Peb, & Argument);
/*
* Tell the SM we failed. If we are a required
* subsystem, SM will halt the system.
*/
NtTerminateProcess (NtCurrentProcess(), Status);
}
/*
* The server booted OK: never stop on error!
*/
CsrpSetDefaultProcessHardErrorMode ();
/*
* Cleanup command line
*/
CsrFreeCommandLine (Peb, & Argument);
/*
* Terminate the current thread only (server's
* threads that serve the LPC port continue
* running and keep the process alive).
*/
NtTerminateThread (NtCurrentThread(), Status);
/* Give us IOPL so that we can access the VGA registers */
Status = NtSetInformationProcess(NtCurrentProcess(),
ProcessUserModeIOPL,
NULL,
0);
if (NT_SUCCESS(Status))
{
/* Raise a hard error */
DPRINT1("CSRSS: Could not raise IOPL: %x\n", Status);
Status = NtRaiseHardError(STATUS_IO_PRIVILEGE_FAILED,
0,
0,
NULL,
OptionOk,
&Response);
}
/* 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 */