remove whitespace from end of lines
[reactos.git] / reactos / subsys / win32k / ntuser / csr.c
1 /* $Id$
2 *
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)
8 */
9
10 #include <w32k.h>
11
12 static HANDLE WindowsApiPort = NULL;
13 PEPROCESS CsrProcess = NULL;
14
15 NTSTATUS FASTCALL
16 CsrInit(void)
17 {
18 NTSTATUS Status;
19 UNICODE_STRING PortName;
20 ULONG ConnectInfoLength;
21
22 RtlInitUnicodeString(&PortName, L"\\Windows\\ApiPort");
23 ConnectInfoLength = 0;
24 Status = ZwConnectPort(&WindowsApiPort,
25 &PortName,
26 NULL,
27 NULL,
28 NULL,
29 NULL,
30 NULL,
31 &ConnectInfoLength);
32 if (! NT_SUCCESS(Status))
33 {
34 return Status;
35 }
36
37 CsrProcess = PsGetCurrentProcess();
38
39 return STATUS_SUCCESS;
40 }
41
42
43 NTSTATUS FASTCALL
44 CsrNotify(PCSRSS_API_REQUEST Request, PCSRSS_API_REPLY Reply)
45 {
46 NTSTATUS Status;
47 PEPROCESS OldProcess;
48
49 if (NULL == CsrProcess)
50 {
51 return STATUS_INVALID_PORT_HANDLE;
52 }
53
54 Request->Header.DataSize = sizeof(CSRSS_API_REQUEST) - LPC_MESSAGE_BASE_SIZE;
55 Request->Header.MessageSize = sizeof(CSRSS_API_REQUEST);
56
57 /* Switch to the process in which the WindowsApiPort handle is valid */
58 OldProcess = PsGetCurrentProcess();
59 if (CsrProcess != OldProcess)
60 {
61 KeAttachProcess(CsrProcess);
62 }
63 Status = ZwRequestWaitReplyPort(WindowsApiPort,
64 &Request->Header,
65 &Reply->Header);
66 if (CsrProcess != OldProcess)
67 {
68 KeDetachProcess();
69 }
70
71 if (NT_SUCCESS(Status))
72 {
73 Status = Reply->Status;
74 }
75
76 return Status;
77 }
78
79 NTSTATUS STDCALL
80 CsrInsertObject(PVOID Object,
81 PACCESS_STATE PassedAccessState,
82 ACCESS_MASK DesiredAccess,
83 ULONG AdditionalReferences,
84 PVOID* ReferencedObject,
85 PHANDLE Handle)
86 {
87 NTSTATUS Status;
88 PEPROCESS OldProcess;
89
90 /* Switch to the process in which the handle is valid */
91 OldProcess = PsGetCurrentProcess();
92 if (CsrProcess != OldProcess)
93 {
94 KeAttachProcess(CsrProcess);
95 }
96
97 Status = ObInsertObject(Object,
98 PassedAccessState,
99 DesiredAccess,
100 AdditionalReferences,
101 ReferencedObject,
102 Handle);
103
104 if (CsrProcess != OldProcess)
105 {
106 KeDetachProcess();
107 }
108
109 return Status;
110 }
111
112 NTSTATUS FASTCALL
113 CsrCloseHandle(HANDLE Handle)
114 {
115 NTSTATUS Status;
116 PEPROCESS OldProcess;
117
118 /* Switch to the process in which the handle is valid */
119 OldProcess = PsGetCurrentProcess();
120 if (CsrProcess != OldProcess)
121 {
122 KeAttachProcess(CsrProcess);
123 }
124
125 Status = ZwClose(Handle);
126
127 if (CsrProcess != OldProcess)
128 {
129 KeDetachProcess();
130 }
131
132 return Status;
133 }
134
135 /* EOF */