2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * PURPOSE: Interface to csrss
5 * FILE: subsys/win32k/ntuser/csr.c
6 * PROGRAMER: Ge van Geldorp (ge@gse.nl)
11 static HANDLE WindowsApiPort
= NULL
;
12 PEPROCESS CsrProcess
= NULL
;
18 UNICODE_STRING PortName
;
19 ULONG ConnectInfoLength
;
20 SECURITY_QUALITY_OF_SERVICE Qos
;
22 RtlInitUnicodeString(&PortName
, L
"\\Windows\\ApiPort");
23 ConnectInfoLength
= 0;
24 Qos
.Length
= sizeof(Qos
);
25 Qos
.ImpersonationLevel
= SecurityDelegation
;
26 Qos
.ContextTrackingMode
= SECURITY_STATIC_TRACKING
;
27 Qos
.EffectiveOnly
= FALSE
;
29 Status
= ZwConnectPort(&WindowsApiPort
,
37 if (! NT_SUCCESS(Status
))
42 CsrProcess
= PsGetCurrentProcess();
44 return STATUS_SUCCESS
;
49 co_CsrNotify(PCSR_API_MESSAGE Request
)
54 if (NULL
== CsrProcess
)
56 return STATUS_INVALID_PORT_HANDLE
;
59 Request
->Header
.u2
.ZeroInit
= 0;
60 Request
->Header
.u1
.s1
.DataLength
= sizeof(CSR_API_MESSAGE
) - sizeof(PORT_MESSAGE
);
61 Request
->Header
.u1
.s1
.TotalLength
= sizeof(CSR_API_MESSAGE
);
63 /* Switch to the process in which the WindowsApiPort handle is valid */
64 OldProcess
= PsGetCurrentProcess();
65 if (CsrProcess
!= OldProcess
)
67 KeAttachProcess(&CsrProcess
->Pcb
);
72 Status
= ZwRequestWaitReplyPort(WindowsApiPort
,
78 if (CsrProcess
!= OldProcess
)
83 if (NT_SUCCESS(Status
))
85 Status
= Request
->Status
;
94 CsrInsertObject(HANDLE ObjectHandle
,
95 ACCESS_MASK DesiredAccess
,
99 HANDLE CsrProcessHandle
;
100 OBJECT_ATTRIBUTES ObjectAttributes
;
104 Cid
.UniqueProcess
= CsrProcess
->UniqueProcessId
;
105 Cid
.UniqueThread
= 0;
107 /* Empty Attributes */
108 InitializeObjectAttributes(&ObjectAttributes
,
114 /* Get a Handle to Csrss */
115 Status
= ZwOpenProcess(&CsrProcessHandle
,
120 if ((NT_SUCCESS(Status
)))
122 /* Duplicate the Handle */
123 Status
= ZwDuplicateObject(NtCurrentProcess(),
131 /* Close our handle to CSRSS */
132 ZwClose(CsrProcessHandle
);
139 CsrCloseHandle(HANDLE Handle
)
142 PEPROCESS OldProcess
;
144 /* Switch to the process in which the handle is valid */
145 OldProcess
= PsGetCurrentProcess();
146 if (CsrProcess
!= OldProcess
)
148 KeAttachProcess(&CsrProcess
->Pcb
);
151 Status
= ZwClose(Handle
);
153 if (CsrProcess
!= OldProcess
)