2005-01-06 13:58:04 +00:00
|
|
|
/* $Id$
|
2004-05-28 21:33:41 +00:00
|
|
|
*
|
|
|
|
* 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 <w32k.h>
|
|
|
|
|
2005-06-29 07:09:25 +00:00
|
|
|
#define NDEBUG
|
|
|
|
#include <debug.h>
|
|
|
|
|
2004-05-28 21:33:41 +00:00
|
|
|
static HANDLE WindowsApiPort = NULL;
|
2004-11-20 16:46:06 +00:00
|
|
|
PEPROCESS CsrProcess = NULL;
|
2005-09-07 21:25:42 +00:00
|
|
|
|
2004-05-28 21:33:41 +00:00
|
|
|
NTSTATUS FASTCALL
|
|
|
|
CsrInit(void)
|
|
|
|
{
|
2005-09-07 21:25:42 +00:00
|
|
|
NTSTATUS Status;
|
|
|
|
UNICODE_STRING PortName;
|
|
|
|
ULONG ConnectInfoLength;
|
2009-01-16 21:03:10 +00:00
|
|
|
SECURITY_QUALITY_OF_SERVICE Qos;
|
2005-09-07 21:25:42 +00:00
|
|
|
|
|
|
|
RtlInitUnicodeString(&PortName, L"\\Windows\\ApiPort");
|
|
|
|
ConnectInfoLength = 0;
|
2009-01-16 21:03:10 +00:00
|
|
|
Qos.Length = sizeof(Qos);
|
|
|
|
Qos.ImpersonationLevel = SecurityDelegation;
|
|
|
|
Qos.ContextTrackingMode = SECURITY_STATIC_TRACKING;
|
|
|
|
Qos.EffectiveOnly = FALSE;
|
|
|
|
|
2005-09-07 21:25:42 +00:00
|
|
|
Status = ZwConnectPort(&WindowsApiPort,
|
|
|
|
&PortName,
|
2009-01-16 21:03:10 +00:00
|
|
|
&Qos,
|
2005-09-07 21:25:42 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
&ConnectInfoLength);
|
|
|
|
if (! NT_SUCCESS(Status))
|
|
|
|
{
|
2004-05-28 21:33:41 +00:00
|
|
|
return Status;
|
2005-09-07 21:25:42 +00:00
|
|
|
}
|
2004-05-28 21:33:41 +00:00
|
|
|
|
2005-09-07 21:25:42 +00:00
|
|
|
CsrProcess = PsGetCurrentProcess();
|
2004-05-28 21:33:41 +00:00
|
|
|
|
2005-09-07 21:25:42 +00:00
|
|
|
return STATUS_SUCCESS;
|
2004-05-28 21:33:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NTSTATUS FASTCALL
|
2005-09-05 21:19:23 +00:00
|
|
|
co_CsrNotify(PCSR_API_MESSAGE Request)
|
2004-05-28 21:33:41 +00:00
|
|
|
{
|
2005-09-07 21:25:42 +00:00
|
|
|
NTSTATUS Status;
|
|
|
|
PEPROCESS OldProcess;
|
2004-05-28 21:33:41 +00:00
|
|
|
|
2005-09-07 21:25:42 +00:00
|
|
|
if (NULL == CsrProcess)
|
|
|
|
{
|
2004-05-28 21:33:41 +00:00
|
|
|
return STATUS_INVALID_PORT_HANDLE;
|
2005-09-07 21:25:42 +00:00
|
|
|
}
|
2004-05-28 21:33:41 +00:00
|
|
|
|
2006-10-30 19:12:17 +00:00
|
|
|
Request->Header.u2.ZeroInit = 0;
|
2005-09-07 21:25:42 +00:00
|
|
|
Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE);
|
|
|
|
Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE);
|
2004-05-28 21:33:41 +00:00
|
|
|
|
2005-09-07 21:25:42 +00:00
|
|
|
/* Switch to the process in which the WindowsApiPort handle is valid */
|
|
|
|
OldProcess = PsGetCurrentProcess();
|
|
|
|
if (CsrProcess != OldProcess)
|
|
|
|
{
|
2005-06-25 20:05:56 +00:00
|
|
|
KeAttachProcess(&CsrProcess->Pcb);
|
2005-09-07 21:25:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
UserLeaveCo();
|
|
|
|
|
|
|
|
Status = ZwRequestWaitReplyPort(WindowsApiPort,
|
|
|
|
&Request->Header,
|
|
|
|
&Request->Header);
|
|
|
|
|
|
|
|
UserEnterCo();
|
|
|
|
|
|
|
|
if (CsrProcess != OldProcess)
|
|
|
|
{
|
2004-05-28 21:33:41 +00:00
|
|
|
KeDetachProcess();
|
2005-09-07 21:25:42 +00:00
|
|
|
}
|
2004-05-28 21:33:41 +00:00
|
|
|
|
2005-09-07 21:25:42 +00:00
|
|
|
if (NT_SUCCESS(Status))
|
|
|
|
{
|
Large change to modify NTDLL'S CSR Functions to be compatible with NT. They are external and we should at least try to match the number of arguments (one vs eight? come on!). Because this is also the direction that Emanuele wants to be taking, the whole external calling interface was modified to be more compatible with NT (although internally it still isn't, and does not have a reason to be). API Names are now generated by a macro from the Server ID, like Emanuele and I noticed from traces, and I've entirely removed the concept of a reply structure. CSRSS uses full-duplex one-way structures, not dual-strutures (this would've been incompatible with the external interface anyways). I don't seem to have introduced any new bugs (console-ROS works great for me, as does the GUI), but there is still a chance some obscure bug might happen, so please bear with me, I had to hand-edit over 250 calls. Also, this now allows full removal of ntdll headers and the next commits will clean this up
svn path=/trunk/; revision=16213
2005-06-22 04:02:32 +00:00
|
|
|
Status = Request->Status;
|
2005-09-07 21:25:42 +00:00
|
|
|
}
|
2004-05-28 21:33:41 +00:00
|
|
|
|
2005-09-07 21:25:42 +00:00
|
|
|
return Status;
|
2004-05-28 21:33:41 +00:00
|
|
|
}
|
|
|
|
|
2006-07-06 01:44:01 +00:00
|
|
|
|
2005-05-19 23:26:56 +00:00
|
|
|
NTSTATUS
|
2008-11-29 22:48:58 +00:00
|
|
|
APIENTRY
|
2005-05-19 23:26:56 +00:00
|
|
|
CsrInsertObject(HANDLE ObjectHandle,
|
2004-11-20 16:46:06 +00:00
|
|
|
ACCESS_MASK DesiredAccess,
|
|
|
|
PHANDLE Handle)
|
|
|
|
{
|
2005-09-07 21:25:42 +00:00
|
|
|
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)))
|
|
|
|
{
|
2005-05-20 00:17:35 +00:00
|
|
|
/* Duplicate the Handle */
|
|
|
|
Status = ZwDuplicateObject(NtCurrentProcess(),
|
|
|
|
ObjectHandle,
|
|
|
|
CsrProcessHandle,
|
|
|
|
Handle,
|
|
|
|
DesiredAccess,
|
2005-12-10 17:09:35 +00:00
|
|
|
OBJ_INHERIT,
|
2005-05-20 00:17:35 +00:00
|
|
|
0);
|
2005-09-07 21:25:42 +00:00
|
|
|
|
2005-05-20 00:17:35 +00:00
|
|
|
/* Close our handle to CSRSS */
|
|
|
|
ZwClose(CsrProcessHandle);
|
2005-09-07 21:25:42 +00:00
|
|
|
}
|
2004-11-20 16:46:06 +00:00
|
|
|
|
2005-09-07 21:25:42 +00:00
|
|
|
return Status;
|
2004-11-20 16:46:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS FASTCALL
|
|
|
|
CsrCloseHandle(HANDLE Handle)
|
|
|
|
{
|
2005-09-07 21:25:42 +00:00
|
|
|
NTSTATUS Status;
|
|
|
|
PEPROCESS OldProcess;
|
2005-05-08 02:11:54 +00:00
|
|
|
|
2005-09-07 21:25:42 +00:00
|
|
|
/* Switch to the process in which the handle is valid */
|
|
|
|
OldProcess = PsGetCurrentProcess();
|
|
|
|
if (CsrProcess != OldProcess)
|
|
|
|
{
|
2005-06-25 20:05:56 +00:00
|
|
|
KeAttachProcess(&CsrProcess->Pcb);
|
2005-09-07 21:25:42 +00:00
|
|
|
}
|
2004-11-20 16:46:06 +00:00
|
|
|
|
2005-09-07 21:25:42 +00:00
|
|
|
Status = ZwClose(Handle);
|
2004-11-20 16:46:06 +00:00
|
|
|
|
2005-09-07 21:25:42 +00:00
|
|
|
if (CsrProcess != OldProcess)
|
|
|
|
{
|
2004-11-20 16:46:06 +00:00
|
|
|
KeDetachProcess();
|
2005-09-07 21:25:42 +00:00
|
|
|
}
|
2004-11-20 16:46:06 +00:00
|
|
|
|
2005-09-07 21:25:42 +00:00
|
|
|
return Status;
|
2004-11-20 16:46:06 +00:00
|
|
|
}
|
|
|
|
|
2004-05-28 21:33:41 +00:00
|
|
|
/* EOF */
|