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
;
25 RtlInitUnicodeString(&PortName
, L
"\\Windows\\ApiPort");
26 ConnectInfoLength
= 0;
27 Status
= ZwConnectPort(&WindowsApiPort
,
35 if (! NT_SUCCESS(Status
))
40 CsrProcess
= PsGetCurrentProcess();
42 return STATUS_SUCCESS
;
47 co_CsrNotify(PCSR_API_MESSAGE Request
)
52 if (NULL
== CsrProcess
)
54 return STATUS_INVALID_PORT_HANDLE
;
57 Request
->Header
.u1
.s1
.DataLength
= sizeof(CSR_API_MESSAGE
) - sizeof(PORT_MESSAGE
);
58 Request
->Header
.u1
.s1
.TotalLength
= sizeof(CSR_API_MESSAGE
);
60 /* Switch to the process in which the WindowsApiPort handle is valid */
61 OldProcess
= PsGetCurrentProcess();
62 if (CsrProcess
!= OldProcess
)
64 KeAttachProcess(&CsrProcess
->Pcb
);
69 Status
= ZwRequestWaitReplyPort(WindowsApiPort
,
75 if (CsrProcess
!= OldProcess
)
80 if (NT_SUCCESS(Status
))
82 Status
= Request
->Status
;
90 CsrInsertObject(HANDLE ObjectHandle
,
91 ACCESS_MASK DesiredAccess
,
95 HANDLE CsrProcessHandle
;
96 OBJECT_ATTRIBUTES ObjectAttributes
;
100 Cid
.UniqueProcess
= CsrProcess
->UniqueProcessId
;
101 Cid
.UniqueThread
= 0;
103 /* Empty Attributes */
104 InitializeObjectAttributes(&ObjectAttributes
,
110 /* Get a Handle to Csrss */
111 Status
= ZwOpenProcess(&CsrProcessHandle
,
116 if ((NT_SUCCESS(Status
)))
118 /* Duplicate the Handle */
119 Status
= ZwDuplicateObject(NtCurrentProcess(),
127 /* Close our handle to CSRSS */
128 ZwClose(CsrProcessHandle
);
135 CsrCloseHandle(HANDLE Handle
)
138 PEPROCESS OldProcess
;
140 /* Switch to the process in which the handle is valid */
141 OldProcess
= PsGetCurrentProcess();
142 if (CsrProcess
!= OldProcess
)
144 KeAttachProcess(&CsrProcess
->Pcb
);
147 Status
= ZwClose(Handle
);
149 if (CsrProcess
!= OldProcess
)