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 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
) - LPC_MESSAGE_BASE_SIZE
;
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
);
66 Status
= ZwRequestWaitReplyPort(WindowsApiPort
,
69 if (CsrProcess
!= OldProcess
)
74 if (NT_SUCCESS(Status
))
76 Status
= Request
->Status
;
84 CsrInsertObject(HANDLE ObjectHandle
,
85 ACCESS_MASK DesiredAccess
,
89 HANDLE CsrProcessHandle
;
90 OBJECT_ATTRIBUTES ObjectAttributes
;
94 Cid
.UniqueProcess
= CsrProcess
->UniqueProcessId
;
97 /* Empty Attributes */
98 InitializeObjectAttributes(&ObjectAttributes
,
104 /* Get a Handle to Csrss */
105 Status
= ZwOpenProcess(&CsrProcessHandle
,
110 if ((NT_SUCCESS(Status
)))
112 /* Duplicate the Handle */
113 Status
= ZwDuplicateObject(NtCurrentProcess(),
121 /* Close our handle to CSRSS */
122 ZwClose(CsrProcessHandle
);
129 CsrCloseHandle(HANDLE Handle
)
132 PEPROCESS OldProcess
;
134 /* Switch to the process in which the handle is valid */
135 OldProcess
= PsGetCurrentProcess();
136 if (CsrProcess
!= OldProcess
)
138 KeAttachProcess(&CsrProcess
->Pcb
);
141 Status
= ZwClose(Handle
);
143 if (CsrProcess
!= OldProcess
)