mirror of
https://github.com/reactos/reactos.git
synced 2024-08-21 19:03:01 +00:00
[CSRSRV], [WIN32CSR]
- Move code for managing console handles from csrsrv to win32csr, where the rest of the console code is. No changes in functionality intended. - Unify the csrsrv->win32csr callbacks (now numbering 4) into one table to avoid excessive code duplication. svn path=/trunk/; revision=47314
This commit is contained in:
parent
a2c5273653
commit
7d27afbe96
|
@ -18,6 +18,9 @@
|
|||
#define CsrAcquireProcessLock() LOCK
|
||||
#define CsrReleaseProcessLock() UNLOCK
|
||||
|
||||
extern NTSTATUS CallProcessInherit(PCSRSS_PROCESS_DATA, PCSRSS_PROCESS_DATA);
|
||||
extern NTSTATUS CallProcessDeleted(PCSRSS_PROCESS_DATA);
|
||||
|
||||
/* GLOBALS *******************************************************************/
|
||||
|
||||
static ULONG NrProcess;
|
||||
|
@ -157,7 +160,7 @@ NTSTATUS WINAPI CsrFreeProcessData(HANDLE Pid)
|
|||
{
|
||||
DPRINT("CsrFreeProcessData pid: %d\n", Pid);
|
||||
Process = pProcessData->Process;
|
||||
CsrReleaseConsole(pProcessData);
|
||||
CallProcessDeleted(pProcessData);
|
||||
if (pProcessData->CsrSectionViewBase)
|
||||
{
|
||||
NtUnmapViewOfSection(NtCurrentProcess(), pProcessData->CsrSectionViewBase);
|
||||
|
@ -205,7 +208,7 @@ CSR_API(CsrCreateProcess)
|
|||
NewProcessData->bInheritHandles = Request->Data.CreateProcessRequest.bInheritHandles;
|
||||
if (Request->Data.CreateProcessRequest.bInheritHandles)
|
||||
{
|
||||
Status = CsrDuplicateHandleTable(ProcessData, NewProcessData);
|
||||
Status = CallProcessInherit(ProcessData, NewProcessData);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -343,134 +346,4 @@ CSR_API(CsrSetShutdownParameters)
|
|||
return(STATUS_SUCCESS);
|
||||
}
|
||||
|
||||
CSR_API(CsrGetInputHandle)
|
||||
{
|
||||
Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE);
|
||||
Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE);
|
||||
|
||||
if (ProcessData->Console)
|
||||
{
|
||||
Request->Status = CsrInsertObject(ProcessData,
|
||||
&Request->Data.GetInputHandleRequest.InputHandle,
|
||||
(Object_t *)ProcessData->Console,
|
||||
Request->Data.GetInputHandleRequest.Access,
|
||||
Request->Data.GetInputHandleRequest.Inheritable);
|
||||
}
|
||||
else
|
||||
{
|
||||
Request->Data.GetInputHandleRequest.InputHandle = INVALID_HANDLE_VALUE;
|
||||
Request->Status = STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
return Request->Status;
|
||||
}
|
||||
|
||||
CSR_API(CsrGetOutputHandle)
|
||||
{
|
||||
Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE);
|
||||
Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE);
|
||||
|
||||
if (ProcessData->Console)
|
||||
{
|
||||
RtlEnterCriticalSection(&ProcessDataLock);
|
||||
Request->Status = CsrInsertObject(ProcessData,
|
||||
&Request->Data.GetOutputHandleRequest.OutputHandle,
|
||||
&ProcessData->Console->ActiveBuffer->Header,
|
||||
Request->Data.GetOutputHandleRequest.Access,
|
||||
Request->Data.GetOutputHandleRequest.Inheritable);
|
||||
RtlLeaveCriticalSection(&ProcessDataLock);
|
||||
}
|
||||
else
|
||||
{
|
||||
Request->Data.GetOutputHandleRequest.OutputHandle = INVALID_HANDLE_VALUE;
|
||||
Request->Status = STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
return Request->Status;
|
||||
}
|
||||
|
||||
CSR_API(CsrCloseHandle)
|
||||
{
|
||||
Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE);
|
||||
Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE);
|
||||
|
||||
return CsrReleaseObject(ProcessData, Request->Data.CloseHandleRequest.Handle);
|
||||
}
|
||||
|
||||
CSR_API(CsrVerifyHandle)
|
||||
{
|
||||
Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE);
|
||||
Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE);
|
||||
|
||||
Request->Status = CsrVerifyObject(ProcessData, Request->Data.VerifyHandleRequest.Handle);
|
||||
if (!NT_SUCCESS(Request->Status))
|
||||
{
|
||||
DPRINT("CsrVerifyObject failed, status=%x\n", Request->Status);
|
||||
}
|
||||
|
||||
return Request->Status;
|
||||
}
|
||||
|
||||
CSR_API(CsrDuplicateHandle)
|
||||
{
|
||||
ULONG_PTR Index;
|
||||
PCSRSS_HANDLE Entry;
|
||||
DWORD DesiredAccess;
|
||||
|
||||
Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE);
|
||||
Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE);
|
||||
|
||||
Index = (ULONG_PTR)Request->Data.DuplicateHandleRequest.Handle >> 2;
|
||||
RtlEnterCriticalSection(&ProcessData->HandleTableLock);
|
||||
if (Index >= ProcessData->HandleTableSize
|
||||
|| (Entry = &ProcessData->HandleTable[Index])->Object == NULL)
|
||||
{
|
||||
DPRINT1("Couldn't dup invalid handle %p\n", Request->Data.DuplicateHandleRequest.Handle);
|
||||
RtlLeaveCriticalSection(&ProcessData->HandleTableLock);
|
||||
return STATUS_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
if (Request->Data.DuplicateHandleRequest.Options & DUPLICATE_SAME_ACCESS)
|
||||
{
|
||||
DesiredAccess = Entry->Access;
|
||||
}
|
||||
else
|
||||
{
|
||||
DesiredAccess = Request->Data.DuplicateHandleRequest.Access;
|
||||
/* Make sure the source handle has all the desired flags */
|
||||
if (~Entry->Access & DesiredAccess)
|
||||
{
|
||||
DPRINT1("Handle %p only has access %X; requested %X\n",
|
||||
Request->Data.DuplicateHandleRequest.Handle, Entry->Access, DesiredAccess);
|
||||
RtlLeaveCriticalSection(&ProcessData->HandleTableLock);
|
||||
return STATUS_INVALID_PARAMETER;
|
||||
}
|
||||
}
|
||||
|
||||
Request->Status = CsrInsertObject(ProcessData,
|
||||
&Request->Data.DuplicateHandleRequest.Handle,
|
||||
Entry->Object,
|
||||
DesiredAccess,
|
||||
Request->Data.DuplicateHandleRequest.Inheritable);
|
||||
if (NT_SUCCESS(Request->Status)
|
||||
&& Request->Data.DuplicateHandleRequest.Options & DUPLICATE_CLOSE_SOURCE)
|
||||
{
|
||||
/* Close the original handle. This cannot drop the count to 0, since a new handle now exists */
|
||||
_InterlockedDecrement(&Entry->Object->ReferenceCount);
|
||||
Entry->Object = NULL;
|
||||
}
|
||||
|
||||
RtlLeaveCriticalSection(&ProcessData->HandleTableLock);
|
||||
return Request->Status;
|
||||
}
|
||||
|
||||
CSR_API(CsrGetInputWaitHandle)
|
||||
{
|
||||
Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE);
|
||||
Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE);
|
||||
|
||||
Request->Data.GetConsoleInputWaitHandle.InputWaitHandle = ProcessData->ConsoleEvent;
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
/* EOF */
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
<library>pseh</library>
|
||||
<library>smdll</library>
|
||||
<directory name="api">
|
||||
<file>handle.c</file>
|
||||
<file>process.c</file>
|
||||
<file>user.c</file>
|
||||
<file>wapi.c</file>
|
||||
|
|
|
@ -18,10 +18,8 @@ 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;
|
||||
static unsigned ServerProcCount;
|
||||
static CSRPLUGIN_SERVER_PROCS *ServerProcs = NULL;
|
||||
HANDLE hSbApiPort = (HANDLE) 0;
|
||||
HANDLE hBootstrapOk = (HANDLE) 0;
|
||||
HANDLE hSmApiPort = (HANDLE) 0;
|
||||
|
@ -124,60 +122,32 @@ InitializeVideoAddressSpace(VOID)
|
|||
|
||||
|
||||
static NTSTATUS FASTCALL
|
||||
CsrpAddInitCompleteProc(CSRPLUGIN_INIT_COMPLETE_PROC Proc)
|
||||
CsrpAddServerProcs(CSRPLUGIN_SERVER_PROCS *Procs)
|
||||
{
|
||||
CSRPLUGIN_INIT_COMPLETE_PROC *NewProcs;
|
||||
CSRPLUGIN_SERVER_PROCS *NewProcs;
|
||||
|
||||
DPRINT("CSR: %s called\n", __FUNCTION__);
|
||||
|
||||
NewProcs = RtlAllocateHeap(CsrssApiHeap, 0,
|
||||
(InitCompleteProcCount + 1)
|
||||
* sizeof(CSRPLUGIN_INIT_COMPLETE_PROC));
|
||||
(ServerProcCount + 1)
|
||||
* sizeof(CSRPLUGIN_SERVER_PROCS));
|
||||
if (NULL == NewProcs)
|
||||
{
|
||||
return STATUS_NO_MEMORY;
|
||||
}
|
||||
if (0 != InitCompleteProcCount)
|
||||
if (0 != ServerProcCount)
|
||||
{
|
||||
RtlCopyMemory(NewProcs, InitCompleteProcs,
|
||||
InitCompleteProcCount * sizeof(CSRPLUGIN_INIT_COMPLETE_PROC));
|
||||
RtlFreeHeap(CsrssApiHeap, 0, InitCompleteProcs);
|
||||
RtlCopyMemory(NewProcs, ServerProcs,
|
||||
ServerProcCount * sizeof(CSRPLUGIN_SERVER_PROCS));
|
||||
RtlFreeHeap(CsrssApiHeap, 0, ServerProcs);
|
||||
}
|
||||
NewProcs[InitCompleteProcCount] = Proc;
|
||||
InitCompleteProcs = NewProcs;
|
||||
InitCompleteProcCount++;
|
||||
NewProcs[ServerProcCount] = *Procs;
|
||||
ServerProcs = NewProcs;
|
||||
ServerProcCount++;
|
||||
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
static NTSTATUS FASTCALL
|
||||
CsrpAddHardErrorProc(CSRPLUGIN_HARDERROR_PROC Proc)
|
||||
{
|
||||
CSRPLUGIN_HARDERROR_PROC *NewProcs;
|
||||
|
||||
DPRINT("CSR: %s called\n", __FUNCTION__);
|
||||
|
||||
NewProcs = RtlAllocateHeap(CsrssApiHeap, 0,
|
||||
(HardErrorProcCount + 1)
|
||||
* sizeof(CSRPLUGIN_HARDERROR_PROC));
|
||||
if (NULL == NewProcs)
|
||||
{
|
||||
return STATUS_NO_MEMORY;
|
||||
}
|
||||
if (0 != HardErrorProcCount)
|
||||
{
|
||||
RtlCopyMemory(NewProcs, HardErrorProcs,
|
||||
HardErrorProcCount * sizeof(CSRPLUGIN_HARDERROR_PROC));
|
||||
RtlFreeHeap(CsrssApiHeap, 0, HardErrorProcs);
|
||||
}
|
||||
|
||||
NewProcs[HardErrorProcCount] = Proc;
|
||||
HardErrorProcs = NewProcs;
|
||||
HardErrorProcCount++;
|
||||
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
/**********************************************************************
|
||||
* CallInitComplete/0
|
||||
*/
|
||||
|
@ -190,13 +160,9 @@ CallInitComplete(void)
|
|||
DPRINT("CSR: %s called\n", __FUNCTION__);
|
||||
|
||||
Ok = TRUE;
|
||||
if (0 != InitCompleteProcCount)
|
||||
for (i = 0; i < ServerProcCount && Ok; i++)
|
||||
{
|
||||
for (i = 0; i < InitCompleteProcCount && Ok; i++)
|
||||
{
|
||||
Ok = (*(InitCompleteProcs[i]))();
|
||||
}
|
||||
RtlFreeHeap(CsrssApiHeap, 0, InitCompleteProcs);
|
||||
Ok = (*ServerProcs[i].InitCompleteProc)();
|
||||
}
|
||||
|
||||
return Ok;
|
||||
|
@ -212,17 +178,44 @@ CallHardError(IN PCSRSS_PROCESS_DATA ProcessData,
|
|||
DPRINT("CSR: %s called\n", __FUNCTION__);
|
||||
|
||||
Ok = TRUE;
|
||||
if (0 != HardErrorProcCount)
|
||||
for (i = 0; i < ServerProcCount && Ok; i++)
|
||||
{
|
||||
for (i = 0; i < HardErrorProcCount && Ok; i++)
|
||||
{
|
||||
Ok = (*(HardErrorProcs[i]))(ProcessData, HardErrorMessage);
|
||||
}
|
||||
Ok = (*ServerProcs[i].HardErrorProc)(ProcessData, HardErrorMessage);
|
||||
}
|
||||
|
||||
return Ok;
|
||||
}
|
||||
|
||||
NTSTATUS
|
||||
CallProcessInherit(IN PCSRSS_PROCESS_DATA SourceProcessData,
|
||||
IN PCSRSS_PROCESS_DATA TargetProcessData)
|
||||
{
|
||||
NTSTATUS Status = STATUS_SUCCESS;
|
||||
unsigned i;
|
||||
|
||||
DPRINT("CSR: %s called\n", __FUNCTION__);
|
||||
|
||||
for (i = 0; i < ServerProcCount && NT_SUCCESS(Status); i++)
|
||||
Status = (*ServerProcs[i].ProcessInheritProc)(SourceProcessData, TargetProcessData);
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
NTSTATUS
|
||||
CallProcessDeleted(IN PCSRSS_PROCESS_DATA ProcessData)
|
||||
{
|
||||
NTSTATUS Status = STATUS_SUCCESS;
|
||||
unsigned i;
|
||||
|
||||
DPRINT("CSR: %s called\n", __FUNCTION__);
|
||||
|
||||
for (i = 0; i < ServerProcCount && NT_SUCCESS(Status); i++)
|
||||
Status = (*ServerProcs[i].ProcessDeletedProc)(ProcessData);
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
|
||||
ULONG
|
||||
InitializeVideoAddressSpace(VOID);
|
||||
|
||||
|
@ -313,9 +306,7 @@ CsrpInitWin32Csr (int argc, char ** argv, char ** envp)
|
|||
CSRPLUGIN_INITIALIZE_PROC InitProc;
|
||||
CSRSS_EXPORTED_FUNCS Exports;
|
||||
PCSRSS_API_DEFINITION ApiDefinitions;
|
||||
PCSRSS_OBJECT_DEFINITION ObjectDefinitions;
|
||||
CSRPLUGIN_INIT_COMPLETE_PROC InitCompleteProc;
|
||||
CSRPLUGIN_HARDERROR_PROC HardErrorProc;
|
||||
CSRPLUGIN_SERVER_PROCS ServerProcs;
|
||||
|
||||
DPRINT("CSR: %s called\n", __FUNCTION__);
|
||||
|
||||
|
@ -331,14 +322,8 @@ CsrpInitWin32Csr (int argc, char ** argv, char ** envp)
|
|||
{
|
||||
return Status;
|
||||
}
|
||||
Exports.CsrInsertObjectProc = CsrInsertObject;
|
||||
Exports.CsrGetObjectProc = CsrGetObject;
|
||||
Exports.CsrReleaseObjectByPointerProc = CsrReleaseObjectByPointer;
|
||||
Exports.CsrReleaseObjectProc = CsrReleaseObject;
|
||||
Exports.CsrReleaseConsoleProc = CsrReleaseConsole;
|
||||
Exports.CsrEnumProcessesProc = CsrEnumProcesses;
|
||||
if (! (*InitProc)(&ApiDefinitions, &ObjectDefinitions, &InitCompleteProc,
|
||||
&HardErrorProc, &Exports, CsrssApiHeap))
|
||||
if (! (*InitProc)(&ApiDefinitions, &ServerProcs, &Exports, CsrssApiHeap))
|
||||
{
|
||||
return STATUS_UNSUCCESSFUL;
|
||||
}
|
||||
|
@ -348,17 +333,7 @@ CsrpInitWin32Csr (int argc, char ** argv, char ** envp)
|
|||
{
|
||||
return Status;
|
||||
}
|
||||
Status = CsrRegisterObjectDefinitions(ObjectDefinitions);
|
||||
if (! NT_SUCCESS(Status))
|
||||
{
|
||||
return Status;
|
||||
}
|
||||
if (NULL != InitCompleteProc)
|
||||
{
|
||||
Status = CsrpAddInitCompleteProc(InitCompleteProc);
|
||||
}
|
||||
if (HardErrorProc) Status = CsrpAddHardErrorProc(HardErrorProc);
|
||||
|
||||
Status = CsrpAddServerProcs(&ServerProcs);
|
||||
return Status;
|
||||
}
|
||||
|
||||
|
@ -371,12 +346,6 @@ CSRSS_API_DEFINITION NativeDefinitions[] =
|
|||
CSRSS_DEFINE_API(REGISTER_SERVICES_PROCESS, CsrRegisterServicesProcess),
|
||||
CSRSS_DEFINE_API(GET_SHUTDOWN_PARAMETERS, CsrGetShutdownParameters),
|
||||
CSRSS_DEFINE_API(SET_SHUTDOWN_PARAMETERS, CsrSetShutdownParameters),
|
||||
CSRSS_DEFINE_API(GET_INPUT_HANDLE, CsrGetInputHandle),
|
||||
CSRSS_DEFINE_API(GET_OUTPUT_HANDLE, CsrGetOutputHandle),
|
||||
CSRSS_DEFINE_API(CLOSE_HANDLE, CsrCloseHandle),
|
||||
CSRSS_DEFINE_API(VERIFY_HANDLE, CsrVerifyHandle),
|
||||
CSRSS_DEFINE_API(DUPLICATE_HANDLE, CsrDuplicateHandle),
|
||||
CSRSS_DEFINE_API(GET_INPUT_WAIT_HANDLE, CsrGetInputWaitHandle),
|
||||
{ 0, 0, NULL }
|
||||
};
|
||||
|
||||
|
|
|
@ -71,8 +71,8 @@ typedef struct _CSRSS_HANDLE
|
|||
|
||||
typedef struct _CSRSS_PROCESS_DATA
|
||||
{
|
||||
PCSRSS_CONSOLE Console;
|
||||
PCSRSS_CONSOLE ParentConsole;
|
||||
struct tagCSRSS_CONSOLE *Console;
|
||||
struct tagCSRSS_CONSOLE *ParentConsole;
|
||||
BOOL bInheritHandles;
|
||||
RTL_CRITICAL_SECTION HandleTableLock;
|
||||
ULONG HandleTableSize;
|
||||
|
|
|
@ -21,29 +21,11 @@
|
|||
#include <windows.h>
|
||||
#include "api.h"
|
||||
|
||||
typedef NTSTATUS (WINAPI *CSRSS_INSERT_OBJECT_PROC)(PCSRSS_PROCESS_DATA ProcessData,
|
||||
PHANDLE Handle,
|
||||
Object_t *Object,
|
||||
DWORD Access,
|
||||
BOOL Inheritable);
|
||||
typedef NTSTATUS (WINAPI *CSRSS_GET_OBJECT_PROC)(PCSRSS_PROCESS_DATA ProcessData,
|
||||
HANDLE Handle,
|
||||
Object_t **Object,
|
||||
DWORD Access);
|
||||
typedef NTSTATUS (WINAPI *CSRSS_RELEASE_OBJECT_BY_POINTER_PROC)(Object_t *Object);
|
||||
typedef NTSTATUS (WINAPI *CSRSS_RELEASE_OBJECT_PROC)(PCSRSS_PROCESS_DATA ProcessData,
|
||||
HANDLE Object );
|
||||
typedef NTSTATUS (WINAPI *CSRSS_RELEASE_CONSOLE_PROC)(PCSRSS_PROCESS_DATA ProcessData);
|
||||
typedef NTSTATUS (WINAPI *CSRSS_ENUM_PROCESSES_PROC)(CSRSS_ENUM_PROCESS_PROC EnumProc,
|
||||
PVOID Context);
|
||||
|
||||
typedef struct tagCSRSS_EXPORTED_FUNCS
|
||||
{
|
||||
CSRSS_INSERT_OBJECT_PROC CsrInsertObjectProc;
|
||||
CSRSS_GET_OBJECT_PROC CsrGetObjectProc;
|
||||
CSRSS_RELEASE_OBJECT_BY_POINTER_PROC CsrReleaseObjectByPointerProc;
|
||||
CSRSS_RELEASE_OBJECT_PROC CsrReleaseObjectProc;
|
||||
CSRSS_RELEASE_CONSOLE_PROC CsrReleaseConsoleProc;
|
||||
CSRSS_ENUM_PROCESSES_PROC CsrEnumProcessesProc;
|
||||
} CSRSS_EXPORTED_FUNCS, *PCSRSS_EXPORTED_FUNCS;
|
||||
|
||||
|
@ -52,10 +34,21 @@ typedef BOOL (WINAPI *CSRPLUGIN_INIT_COMPLETE_PROC)(void);
|
|||
typedef BOOL (WINAPI *CSRPLUGIN_HARDERROR_PROC)(IN PCSRSS_PROCESS_DATA ProcessData,
|
||||
IN PHARDERROR_MSG HardErrorMessage);
|
||||
|
||||
typedef NTSTATUS (WINAPI *CSRPLUGIN_PROCESS_INHERIT_PROC)(IN PCSRSS_PROCESS_DATA SourceProcessData,
|
||||
IN PCSRSS_PROCESS_DATA TargetProcessData);
|
||||
|
||||
typedef NTSTATUS (WINAPI *CSRPLUGIN_PROCESS_DELETED_PROC)(IN PCSRSS_PROCESS_DATA ProcessData);
|
||||
|
||||
typedef struct tagCSRSS_SERVER_PROCS
|
||||
{
|
||||
CSRPLUGIN_INIT_COMPLETE_PROC InitCompleteProc;
|
||||
CSRPLUGIN_HARDERROR_PROC HardErrorProc;
|
||||
CSRPLUGIN_PROCESS_INHERIT_PROC ProcessInheritProc;
|
||||
CSRPLUGIN_PROCESS_DELETED_PROC ProcessDeletedProc;
|
||||
} CSRPLUGIN_SERVER_PROCS, *PCSRPLUGIN_SERVER_PROCS;
|
||||
|
||||
typedef BOOL (WINAPI *CSRPLUGIN_INITIALIZE_PROC)(PCSRSS_API_DEFINITION *ApiDefinitions,
|
||||
PCSRSS_OBJECT_DEFINITION *ObjectDefinitions,
|
||||
CSRPLUGIN_INIT_COMPLETE_PROC *InitCompleteProc,
|
||||
CSRPLUGIN_HARDERROR_PROC *HardErrorProc,
|
||||
PCSRPLUGIN_SERVER_PROCS ServerProcs,
|
||||
PCSRSS_EXPORTED_FUNCS Exports,
|
||||
HANDLE CsrssApiHeap);
|
||||
|
||||
|
|
|
@ -24,6 +24,12 @@ static CSRSS_EXPORTED_FUNCS CsrExports;
|
|||
|
||||
static CSRSS_API_DEFINITION Win32CsrApiDefinitions[] =
|
||||
{
|
||||
CSRSS_DEFINE_API(GET_INPUT_HANDLE, CsrGetInputHandle),
|
||||
CSRSS_DEFINE_API(GET_OUTPUT_HANDLE, CsrGetOutputHandle),
|
||||
CSRSS_DEFINE_API(CLOSE_HANDLE, CsrCloseHandle),
|
||||
CSRSS_DEFINE_API(VERIFY_HANDLE, CsrVerifyHandle),
|
||||
CSRSS_DEFINE_API(DUPLICATE_HANDLE, CsrDuplicateHandle),
|
||||
CSRSS_DEFINE_API(GET_INPUT_WAIT_HANDLE, CsrGetInputWaitHandle),
|
||||
CSRSS_DEFINE_API(WRITE_CONSOLE, CsrWriteConsole),
|
||||
CSRSS_DEFINE_API(READ_CONSOLE, CsrReadConsole),
|
||||
CSRSS_DEFINE_API(ALLOC_CONSOLE, CsrAllocConsole),
|
||||
|
@ -108,7 +114,7 @@ Win32CsrInsertObject(PCSRSS_PROCESS_DATA ProcessData,
|
|||
DWORD Access,
|
||||
BOOL Inheritable)
|
||||
{
|
||||
return (CsrExports.CsrInsertObjectProc)(ProcessData, Handle, Object, Access, Inheritable);
|
||||
return CsrInsertObject(ProcessData, Handle, Object, Access, Inheritable);
|
||||
}
|
||||
|
||||
NTSTATUS FASTCALL
|
||||
|
@ -117,7 +123,7 @@ Win32CsrGetObject(PCSRSS_PROCESS_DATA ProcessData,
|
|||
Object_t **Object,
|
||||
DWORD Access)
|
||||
{
|
||||
return (CsrExports.CsrGetObjectProc)(ProcessData, Handle, Object, Access);
|
||||
return CsrGetObject(ProcessData, Handle, Object, Access);
|
||||
}
|
||||
|
||||
NTSTATUS FASTCALL
|
||||
|
@ -129,7 +135,7 @@ Win32CsrLockObject(PCSRSS_PROCESS_DATA ProcessData,
|
|||
{
|
||||
NTSTATUS Status;
|
||||
|
||||
Status = (CsrExports.CsrGetObjectProc)(ProcessData, Handle, Object, Access);
|
||||
Status = CsrGetObject(ProcessData, Handle, Object, Access);
|
||||
if (! NT_SUCCESS(Status))
|
||||
{
|
||||
return Status;
|
||||
|
@ -137,7 +143,7 @@ Win32CsrLockObject(PCSRSS_PROCESS_DATA ProcessData,
|
|||
|
||||
if ((*Object)->Type != Type)
|
||||
{
|
||||
(CsrExports.CsrReleaseObjectByPointerProc)(*Object);
|
||||
CsrReleaseObjectByPointer(*Object);
|
||||
return STATUS_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
|
@ -150,26 +156,26 @@ VOID FASTCALL
|
|||
Win32CsrUnlockObject(Object_t *Object)
|
||||
{
|
||||
LeaveCriticalSection(&(Object->Lock));
|
||||
(CsrExports.CsrReleaseObjectByPointerProc)(Object);
|
||||
CsrReleaseObjectByPointer(Object);
|
||||
}
|
||||
|
||||
NTSTATUS FASTCALL
|
||||
Win32CsrReleaseObjectByPointer(Object_t *Object)
|
||||
{
|
||||
return (CsrExports.CsrReleaseObjectByPointerProc)(Object);
|
||||
return CsrReleaseObjectByPointer(Object);
|
||||
}
|
||||
|
||||
NTSTATUS FASTCALL
|
||||
Win32CsrReleaseObject(PCSRSS_PROCESS_DATA ProcessData,
|
||||
HANDLE Object)
|
||||
{
|
||||
return (CsrExports.CsrReleaseObjectProc)(ProcessData, Object);
|
||||
return CsrReleaseObject(ProcessData, Object);
|
||||
}
|
||||
|
||||
NTSTATUS FASTCALL
|
||||
Win32CsrReleaseConsole(PCSRSS_PROCESS_DATA ProcessData)
|
||||
{
|
||||
return (CsrExports.CsrReleaseConsoleProc)(ProcessData);
|
||||
return CsrReleaseConsole(ProcessData);
|
||||
}
|
||||
|
||||
NTSTATUS FASTCALL
|
||||
|
@ -189,9 +195,7 @@ Win32CsrInitComplete(void)
|
|||
|
||||
BOOL WINAPI
|
||||
Win32CsrInitialization(PCSRSS_API_DEFINITION *ApiDefinitions,
|
||||
PCSRSS_OBJECT_DEFINITION *ObjectDefinitions,
|
||||
CSRPLUGIN_INIT_COMPLETE_PROC *InitComplete,
|
||||
CSRPLUGIN_HARDERROR_PROC *HardError,
|
||||
PCSRPLUGIN_SERVER_PROCS ServerProcs,
|
||||
PCSRSS_EXPORTED_FUNCS Exports,
|
||||
HANDLE CsrssApiHeap)
|
||||
{
|
||||
|
@ -203,11 +207,13 @@ Win32CsrInitialization(PCSRSS_API_DEFINITION *ApiDefinitions,
|
|||
|
||||
PrivateCsrssManualGuiCheck(0);
|
||||
CsrInitConsoleSupport();
|
||||
CsrRegisterObjectDefinitions(Win32CsrObjectDefinitions);
|
||||
|
||||
*ApiDefinitions = Win32CsrApiDefinitions;
|
||||
*ObjectDefinitions = Win32CsrObjectDefinitions;
|
||||
*InitComplete = Win32CsrInitComplete;
|
||||
*HardError = Win32CsrHardError;
|
||||
ServerProcs->InitCompleteProc = Win32CsrInitComplete;
|
||||
ServerProcs->HardErrorProc = Win32CsrHardError;
|
||||
ServerProcs->ProcessInheritProc = CsrDuplicateHandleTable;
|
||||
ServerProcs->ProcessDeletedProc = CsrReleaseConsole;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
/* INCLUDES ******************************************************************/
|
||||
|
||||
#include <srv.h>
|
||||
#include <w32csr.h>
|
||||
|
||||
#define NDEBUG
|
||||
#include <debug.h>
|
||||
|
@ -42,7 +42,7 @@ CsrRegisterObjectDefinitions(
|
|||
NewCount++;
|
||||
}
|
||||
|
||||
New = RtlAllocateHeap(CsrssApiHeap,
|
||||
New = RtlAllocateHeap(Win32CsrApiHeap,
|
||||
0,
|
||||
(ObjectDefinitionsCount + NewCount)
|
||||
* sizeof(CSRSS_OBJECT_DEFINITION));
|
||||
|
@ -57,7 +57,7 @@ CsrRegisterObjectDefinitions(
|
|||
RtlCopyMemory(New,
|
||||
ObjectDefinitions,
|
||||
ObjectDefinitionsCount * sizeof(CSRSS_OBJECT_DEFINITION));
|
||||
RtlFreeHeap(CsrssApiHeap, 0, ObjectDefinitions);
|
||||
RtlFreeHeap(Win32CsrApiHeap, 0, ObjectDefinitions);
|
||||
}
|
||||
|
||||
RtlCopyMemory(New + ObjectDefinitionsCount,
|
||||
|
@ -171,7 +171,7 @@ CsrReleaseConsole(
|
|||
if (HandleTable[i].Object != NULL)
|
||||
CsrReleaseObjectByPointer(HandleTable[i].Object);
|
||||
}
|
||||
RtlFreeHeap(CsrssApiHeap, 0, HandleTable);
|
||||
RtlFreeHeap(Win32CsrApiHeap, 0, HandleTable);
|
||||
|
||||
if (Console != NULL)
|
||||
{
|
||||
|
@ -208,7 +208,7 @@ CsrInsertObject(
|
|||
}
|
||||
if (i >= ProcessData->HandleTableSize)
|
||||
{
|
||||
Block = RtlAllocateHeap(CsrssApiHeap,
|
||||
Block = RtlAllocateHeap(Win32CsrApiHeap,
|
||||
HEAP_ZERO_MEMORY,
|
||||
(ProcessData->HandleTableSize + 64) * sizeof(CSRSS_HANDLE));
|
||||
if (Block == NULL)
|
||||
|
@ -220,7 +220,7 @@ CsrInsertObject(
|
|||
ProcessData->HandleTable,
|
||||
ProcessData->HandleTableSize * sizeof(CSRSS_HANDLE));
|
||||
Block = _InterlockedExchangePointer((void* volatile)&ProcessData->HandleTable, Block);
|
||||
RtlFreeHeap( CsrssApiHeap, 0, Block );
|
||||
RtlFreeHeap( Win32CsrApiHeap, 0, Block );
|
||||
ProcessData->HandleTableSize += 64;
|
||||
}
|
||||
ProcessData->HandleTable[i].Object = Object;
|
||||
|
@ -249,7 +249,7 @@ CsrDuplicateHandleTable(
|
|||
|
||||
/* we are called from CreateProcessData, it isn't necessary to lock the target process data */
|
||||
|
||||
TargetProcessData->HandleTable = RtlAllocateHeap(CsrssApiHeap,
|
||||
TargetProcessData->HandleTable = RtlAllocateHeap(Win32CsrApiHeap,
|
||||
HEAP_ZERO_MEMORY,
|
||||
SourceProcessData->HandleTableSize
|
||||
* sizeof(CSRSS_HANDLE));
|
||||
|
@ -289,4 +289,132 @@ CsrVerifyObject(
|
|||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
CSR_API(CsrGetInputHandle)
|
||||
{
|
||||
Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE);
|
||||
Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE);
|
||||
|
||||
if (ProcessData->Console)
|
||||
{
|
||||
Request->Status = CsrInsertObject(ProcessData,
|
||||
&Request->Data.GetInputHandleRequest.InputHandle,
|
||||
(Object_t *)ProcessData->Console,
|
||||
Request->Data.GetInputHandleRequest.Access,
|
||||
Request->Data.GetInputHandleRequest.Inheritable);
|
||||
}
|
||||
else
|
||||
{
|
||||
Request->Data.GetInputHandleRequest.InputHandle = INVALID_HANDLE_VALUE;
|
||||
Request->Status = STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
return Request->Status;
|
||||
}
|
||||
|
||||
CSR_API(CsrGetOutputHandle)
|
||||
{
|
||||
Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE);
|
||||
Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE);
|
||||
|
||||
if (ProcessData->Console)
|
||||
{
|
||||
Request->Status = CsrInsertObject(ProcessData,
|
||||
&Request->Data.GetOutputHandleRequest.OutputHandle,
|
||||
&ProcessData->Console->ActiveBuffer->Header,
|
||||
Request->Data.GetOutputHandleRequest.Access,
|
||||
Request->Data.GetOutputHandleRequest.Inheritable);
|
||||
}
|
||||
else
|
||||
{
|
||||
Request->Data.GetOutputHandleRequest.OutputHandle = INVALID_HANDLE_VALUE;
|
||||
Request->Status = STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
return Request->Status;
|
||||
}
|
||||
|
||||
CSR_API(CsrCloseHandle)
|
||||
{
|
||||
Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE);
|
||||
Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE);
|
||||
|
||||
return CsrReleaseObject(ProcessData, Request->Data.CloseHandleRequest.Handle);
|
||||
}
|
||||
|
||||
CSR_API(CsrVerifyHandle)
|
||||
{
|
||||
Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE);
|
||||
Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE);
|
||||
|
||||
Request->Status = CsrVerifyObject(ProcessData, Request->Data.VerifyHandleRequest.Handle);
|
||||
if (!NT_SUCCESS(Request->Status))
|
||||
{
|
||||
DPRINT("CsrVerifyObject failed, status=%x\n", Request->Status);
|
||||
}
|
||||
|
||||
return Request->Status;
|
||||
}
|
||||
|
||||
CSR_API(CsrDuplicateHandle)
|
||||
{
|
||||
ULONG_PTR Index;
|
||||
PCSRSS_HANDLE Entry;
|
||||
DWORD DesiredAccess;
|
||||
|
||||
Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE);
|
||||
Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE);
|
||||
|
||||
Index = (ULONG_PTR)Request->Data.DuplicateHandleRequest.Handle >> 2;
|
||||
RtlEnterCriticalSection(&ProcessData->HandleTableLock);
|
||||
if (Index >= ProcessData->HandleTableSize
|
||||
|| (Entry = &ProcessData->HandleTable[Index])->Object == NULL)
|
||||
{
|
||||
DPRINT1("Couldn't dup invalid handle %p\n", Request->Data.DuplicateHandleRequest.Handle);
|
||||
RtlLeaveCriticalSection(&ProcessData->HandleTableLock);
|
||||
return STATUS_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
if (Request->Data.DuplicateHandleRequest.Options & DUPLICATE_SAME_ACCESS)
|
||||
{
|
||||
DesiredAccess = Entry->Access;
|
||||
}
|
||||
else
|
||||
{
|
||||
DesiredAccess = Request->Data.DuplicateHandleRequest.Access;
|
||||
/* Make sure the source handle has all the desired flags */
|
||||
if (~Entry->Access & DesiredAccess)
|
||||
{
|
||||
DPRINT1("Handle %p only has access %X; requested %X\n",
|
||||
Request->Data.DuplicateHandleRequest.Handle, Entry->Access, DesiredAccess);
|
||||
RtlLeaveCriticalSection(&ProcessData->HandleTableLock);
|
||||
return STATUS_INVALID_PARAMETER;
|
||||
}
|
||||
}
|
||||
|
||||
Request->Status = CsrInsertObject(ProcessData,
|
||||
&Request->Data.DuplicateHandleRequest.Handle,
|
||||
Entry->Object,
|
||||
DesiredAccess,
|
||||
Request->Data.DuplicateHandleRequest.Inheritable);
|
||||
if (NT_SUCCESS(Request->Status)
|
||||
&& Request->Data.DuplicateHandleRequest.Options & DUPLICATE_CLOSE_SOURCE)
|
||||
{
|
||||
/* Close the original handle. This cannot drop the count to 0, since a new handle now exists */
|
||||
_InterlockedDecrement(&Entry->Object->ReferenceCount);
|
||||
Entry->Object = NULL;
|
||||
}
|
||||
|
||||
RtlLeaveCriticalSection(&ProcessData->HandleTableLock);
|
||||
return Request->Status;
|
||||
}
|
||||
|
||||
CSR_API(CsrGetInputWaitHandle)
|
||||
{
|
||||
Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE);
|
||||
Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE);
|
||||
|
||||
Request->Data.GetConsoleInputWaitHandle.InputWaitHandle = ProcessData->ConsoleEvent;
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
/* EOF */
|
|
@ -22,6 +22,7 @@
|
|||
<file>dllmain.c</file>
|
||||
<file>exitros.c</file>
|
||||
<file>guiconsole.c</file>
|
||||
<file>handle.c</file>
|
||||
<file>harderror.c</file>
|
||||
<file>tuiconsole.c</file>
|
||||
<file>appswitch.c</file>
|
||||
|
|
|
@ -1 +1 @@
|
|||
@ stdcall Win32CsrInitialization(ptr ptr ptr ptr ptr ptr)
|
||||
@ stdcall Win32CsrInitialization(ptr ptr ptr ptr)
|
||||
|
|
Loading…
Reference in a new issue