mirror of
https://github.com/reactos/reactos.git
synced 2024-09-06 19:02:32 +00:00
![Hermès Bélusca-Maïto](/assets/img/avatar_default.png)
- Use the new subsystems header winmsg.h - Use the new USER_API_MESSAGE structure, and adapt co_CsrNotify in consequence. - Code formatting. [KERNEL32] - Use the new subsystems headers basemsg.h, conmsg.h, winmsg.h, etc... [NTDLL] - Code formatting only. svn path=/branches/ros-csrss/; revision=57628
167 lines
3.9 KiB
C
167 lines
3.9 KiB
C
/*
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
* PROJECT: ReactOS kernel
|
|
* PURPOSE: Interface to csrss
|
|
* FILE: subsys/win32k/ntuser/csr.c
|
|
* PROGRAMER: Ge van Geldorp (ge@gse.nl)
|
|
*/
|
|
|
|
#include <win32k.h>
|
|
|
|
static HANDLE WindowsApiPort = NULL;
|
|
PEPROCESS CsrProcess = NULL;
|
|
|
|
NTSTATUS FASTCALL
|
|
CsrInit(void)
|
|
{
|
|
NTSTATUS Status;
|
|
UNICODE_STRING PortName;
|
|
ULONG ConnectInfoLength;
|
|
SECURITY_QUALITY_OF_SERVICE Qos;
|
|
|
|
RtlInitUnicodeString(&PortName, L"\\Windows\\ApiPort");
|
|
ConnectInfoLength = 0;
|
|
Qos.Length = sizeof(Qos);
|
|
Qos.ImpersonationLevel = SecurityDelegation;
|
|
Qos.ContextTrackingMode = SECURITY_STATIC_TRACKING;
|
|
Qos.EffectiveOnly = FALSE;
|
|
|
|
Status = ZwConnectPort(&WindowsApiPort,
|
|
&PortName,
|
|
&Qos,
|
|
NULL,
|
|
NULL,
|
|
NULL,
|
|
NULL,
|
|
&ConnectInfoLength);
|
|
if (!NT_SUCCESS(Status))
|
|
{
|
|
return Status;
|
|
}
|
|
|
|
CsrProcess = PsGetCurrentProcess();
|
|
|
|
return STATUS_SUCCESS;
|
|
}
|
|
|
|
|
|
NTSTATUS FASTCALL
|
|
co_CsrNotify(IN OUT PCSR_API_MESSAGE ApiMessage,
|
|
IN ULONG DataLength)
|
|
{
|
|
NTSTATUS Status;
|
|
PEPROCESS OldProcess;
|
|
|
|
if (NULL == CsrProcess)
|
|
{
|
|
return STATUS_INVALID_PORT_HANDLE;
|
|
}
|
|
|
|
/* Fill out the Port Message Header */
|
|
ApiMessage->Header.u2.ZeroInit = 0;
|
|
ApiMessage->Header.u1.s1.TotalLength =
|
|
FIELD_OFFSET(CSR_API_MESSAGE, Data) + DataLength;
|
|
/* FIELD_OFFSET(CSR_API_MESSAGE, Data) <= sizeof(CSR_API_MESSAGE) - sizeof(ApiMessage->Data) */
|
|
ApiMessage->Header.u1.s1.DataLength =
|
|
ApiMessage->Header.u1.s1.TotalLength - sizeof(PORT_MESSAGE);
|
|
|
|
/* Switch to the process in which the WindowsApiPort handle is valid */
|
|
OldProcess = PsGetCurrentProcess();
|
|
if (CsrProcess != OldProcess)
|
|
{
|
|
KeAttachProcess(&CsrProcess->Pcb);
|
|
}
|
|
|
|
UserLeaveCo();
|
|
|
|
Status = ZwRequestWaitReplyPort(WindowsApiPort,
|
|
&ApiMessage->Header,
|
|
&ApiMessage->Header);
|
|
|
|
UserEnterCo();
|
|
|
|
if (CsrProcess != OldProcess)
|
|
{
|
|
KeDetachProcess();
|
|
}
|
|
|
|
if (NT_SUCCESS(Status))
|
|
{
|
|
Status = ApiMessage->Status;
|
|
}
|
|
|
|
return Status;
|
|
}
|
|
|
|
|
|
NTSTATUS
|
|
APIENTRY
|
|
CsrInsertObject(HANDLE ObjectHandle,
|
|
ACCESS_MASK DesiredAccess,
|
|
PHANDLE Handle)
|
|
{
|
|
NTSTATUS Status;
|
|
HANDLE CsrProcessHandle;
|
|
OBJECT_ATTRIBUTES ObjectAttributes;
|
|
CLIENT_ID Cid;
|
|
|
|
/* Put CSR'S CID */
|
|
Cid.UniqueProcess = CsrProcess->UniqueProcessId;
|
|
Cid.UniqueThread = 0;
|
|
|
|
/* Empty Attributes */
|
|
InitializeObjectAttributes(&ObjectAttributes,
|
|
NULL,
|
|
0,
|
|
NULL,
|
|
NULL);
|
|
|
|
/* Get a Handle to Csrss */
|
|
Status = ZwOpenProcess(&CsrProcessHandle,
|
|
PROCESS_DUP_HANDLE,
|
|
&ObjectAttributes,
|
|
&Cid);
|
|
|
|
if ((NT_SUCCESS(Status)))
|
|
{
|
|
/* Duplicate the Handle */
|
|
Status = ZwDuplicateObject(NtCurrentProcess(),
|
|
ObjectHandle,
|
|
CsrProcessHandle,
|
|
Handle,
|
|
DesiredAccess,
|
|
OBJ_INHERIT,
|
|
0);
|
|
|
|
/* Close our handle to CSRSS */
|
|
ZwClose(CsrProcessHandle);
|
|
}
|
|
|
|
return Status;
|
|
}
|
|
|
|
NTSTATUS FASTCALL
|
|
CsrCloseHandle(HANDLE Handle)
|
|
{
|
|
NTSTATUS Status;
|
|
PEPROCESS OldProcess;
|
|
|
|
/* Switch to the process in which the handle is valid */
|
|
OldProcess = PsGetCurrentProcess();
|
|
if (CsrProcess != OldProcess)
|
|
{
|
|
KeAttachProcess(&CsrProcess->Pcb);
|
|
}
|
|
|
|
Status = ZwClose(Handle);
|
|
|
|
if (CsrProcess != OldProcess)
|
|
{
|
|
KeDetachProcess();
|
|
}
|
|
|
|
return Status;
|
|
}
|
|
|
|
/* EOF */
|