3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * PURPOSE: Interface to csrss
6 * FILE: subsys/win32k/ntuser/csr.c
7 * PROGRAMER: Ge van Geldorp (ge@gse.nl)
15 static HANDLE WindowsApiPort
= NULL
;
16 PEPROCESS CsrProcess
= NULL
;
22 UNICODE_STRING PortName
;
23 ULONG ConnectInfoLength
;
24 SECURITY_QUALITY_OF_SERVICE Qos
;
26 RtlInitUnicodeString(&PortName
, L
"\\Windows\\ApiPort");
27 ConnectInfoLength
= 0;
28 Qos
.Length
= sizeof(Qos
);
29 Qos
.ImpersonationLevel
= SecurityDelegation
;
30 Qos
.ContextTrackingMode
= SECURITY_STATIC_TRACKING
;
31 Qos
.EffectiveOnly
= FALSE
;
33 Status
= ZwConnectPort(&WindowsApiPort
,
41 if (! NT_SUCCESS(Status
))
46 CsrProcess
= PsGetCurrentProcess();
48 return STATUS_SUCCESS
;
53 co_CsrNotify(PCSR_API_MESSAGE Request
)
58 if (NULL
== CsrProcess
)
60 return STATUS_INVALID_PORT_HANDLE
;
63 Request
->Header
.u2
.ZeroInit
= 0;
64 Request
->Header
.u1
.s1
.DataLength
= sizeof(CSR_API_MESSAGE
) - sizeof(PORT_MESSAGE
);
65 Request
->Header
.u1
.s1
.TotalLength
= sizeof(CSR_API_MESSAGE
);
67 /* Switch to the process in which the WindowsApiPort handle is valid */
68 OldProcess
= PsGetCurrentProcess();
69 if (CsrProcess
!= OldProcess
)
71 KeAttachProcess(&CsrProcess
->Pcb
);
76 Status
= ZwRequestWaitReplyPort(WindowsApiPort
,
82 if (CsrProcess
!= OldProcess
)
87 if (NT_SUCCESS(Status
))
89 Status
= Request
->Status
;
98 CsrInsertObject(HANDLE ObjectHandle
,
99 ACCESS_MASK DesiredAccess
,
103 HANDLE CsrProcessHandle
;
104 OBJECT_ATTRIBUTES ObjectAttributes
;
108 Cid
.UniqueProcess
= CsrProcess
->UniqueProcessId
;
109 Cid
.UniqueThread
= 0;
111 /* Empty Attributes */
112 InitializeObjectAttributes(&ObjectAttributes
,
118 /* Get a Handle to Csrss */
119 Status
= ZwOpenProcess(&CsrProcessHandle
,
124 if ((NT_SUCCESS(Status
)))
126 /* Duplicate the Handle */
127 Status
= ZwDuplicateObject(NtCurrentProcess(),
135 /* Close our handle to CSRSS */
136 ZwClose(CsrProcessHandle
);
143 CsrCloseHandle(HANDLE Handle
)
146 PEPROCESS OldProcess
;
148 /* Switch to the process in which the handle is valid */
149 OldProcess
= PsGetCurrentProcess();
150 if (CsrProcess
!= OldProcess
)
152 KeAttachProcess(&CsrProcess
->Pcb
);
155 Status
= ZwClose(Handle
);
157 if (CsrProcess
!= OldProcess
)