started moving tags to a private internal header
[reactos.git] / vms / server / init.c
1 /* $Id: $
2 *
3 * init.c - VMS Enviroment Subsystem Server - Initialization
4 *
5 * ReactOS Operating System
6 *
7 * --------------------------------------------------------------------
8 *
9 * This software is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of the
12 * License, or (at your option) any later version.
13 *
14 * This software is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this software; see the file COPYING.LIB. If not, write
21 * to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge,
22 * MA 02139, USA.
23 *
24 * --------------------------------------------------------------------
25 */
26 #include "vmsss.h"
27
28 //#define NDEBUG
29 #include <debug.h>
30
31
32 HANDLE VmsSbApiPort = (HANDLE) 0; // \VMS\SbApiPort
33 HANDLE SmCalledBack = (HANDLE) 0; // signalled when SM connects to \VMS\SbApiPort
34 HANDLE SmVmsSbApiPort = (HANDLE) 0; // server side (our one) port for SM conn request
35 HANDLE SmApiPort = (HANDLE) 0; // client side of \SmApiPort
36
37 HANDLE VmsSessionPort = (HANDLE) 0; // pseudo terminals call here for a new session
38 HANDLE VmsApiPort = (HANDLE) 0; // VMS processes call here for system calls
39
40 /**********************************************************************
41 * SB API Port Thread
42 *********************************************************************/
43 static VOID STDCALL
44 VmsSbApiPortThread (PVOID x)
45 {
46 HANDLE Port = (HANDLE) x;
47 NTSTATUS Status = STATUS_SUCCESS;
48 LPC_MAX_MESSAGE ConnectionRequest = {{0}};
49
50 DPRINT("VMS: %s: called\n", __FUNCTION__);
51
52 Status = NtListenPort (Port, & ConnectionRequest.Header);
53 if(!NT_SUCCESS(Status))
54 {
55 DPRINT("VMS: %s: NtListenPort failed (Status=0x%08lx)\n",
56 __FUNCTION__, Status);
57 }else{
58 DPRINT("VMS: %s received a connection request\n", __FUNCTION__);
59 Status = NtAcceptConnectPort (& SmVmsSbApiPort,
60 0,
61 & ConnectionRequest.Header,
62 TRUE, /* accept it */
63 NULL,
64 NULL);
65 if(!NT_SUCCESS(Status))
66 {
67 DPRINT("VMS: %s: NtAcceptConnectPort failed (Status=0x%08lx)\n",
68 __FUNCTION__, Status);
69 }else{
70 DPRINT("VMS: %s accepted the connection request\n", __FUNCTION__);
71 Status = NtCompleteConnectPort (SmVmsSbApiPort);
72 if(!NT_SUCCESS(Status))
73 {
74 DPRINT("VMS: %s: NtCompleteConnectPort failed (Status=0x%08lx)\n",
75 __FUNCTION__, Status);
76 }else{
77 DPRINT("VMS: %s completed the connection request\n", __FUNCTION__);
78 Status = NtSetEvent (SmCalledBack, NULL);
79 DPRINT("VMS: %s signalled the main thread to initialize the subsystem\n", __FUNCTION__);
80 DPRINT("VMS: %s enters main loop\n", __FUNCTION__);
81 while (TRUE)
82 {
83 }
84 }
85 }
86 }
87 NtClose (Port);
88 NtTerminateThread (NtCurrentThread(), Status);
89 }
90 /**********************************************************************
91 * API Port Thread
92 *********************************************************************/
93 static VOID STDCALL
94 VmsApiPortThread (PVOID x)
95 {
96 HANDLE Port = (HANDLE) x;
97 NTSTATUS Status = STATUS_SUCCESS;
98
99 DPRINT("VMS: %s: called\n", __FUNCTION__);
100 while (TRUE)
101 {
102 }
103 NtClose (Port);
104 NtTerminateThread (NtCurrentThread(), Status);
105 }
106
107 /**********************************************************************
108 * NAME PRIVATE
109 * VmspCreateObDirectory/1
110 */
111 static NTSTATUS FASTCALL
112 VmspCreateObDirectory (PWSTR DirectoryName)
113 {
114 UNICODE_STRING usDirectoryName = {0};
115 OBJECT_ATTRIBUTES DirectoryAttributes = {0};
116 NTSTATUS Status = STATUS_SUCCESS;
117 HANDLE hDirectory = (HANDLE) 0;
118
119 DPRINT("VMS: %s called\n", __FUNCTION__);
120
121 RtlInitUnicodeString (& usDirectoryName,
122 DirectoryName);
123 InitializeObjectAttributes (& DirectoryAttributes,
124 & usDirectoryName,
125 0, NULL, NULL);
126 Status = NtCreateDirectoryObject (& hDirectory,
127 DIRECTORY_CREATE_SUBDIRECTORY,
128 & DirectoryAttributes);
129 if(!NT_SUCCESS(Status))
130 {
131 DPRINT("VMS: %s: NtCreateDirectoryObject failed (Status=0x%08lx)\n",
132 __FUNCTION__, Status);
133 return Status;
134 }
135 NtClose (hDirectory);
136 return STATUS_SUCCESS;
137 }
138
139 /**********************************************************************
140 * NAME PRIVATE
141 * VmspCreatePort/1
142 */
143 static NTSTATUS STDCALL
144 VmspCreatePort (IN OUT PHANDLE pPortHandle,
145 IN PWSTR PortName,
146 IN ULONG MaxDataSize,
147 IN ULONG MaxMessageSize,
148 IN PTHREAD_START_ROUTINE ListeningThread)
149 {
150 UNICODE_STRING usPortName = {0};
151 OBJECT_ATTRIBUTES PortAttributes = {0};
152 NTSTATUS Status = STATUS_SUCCESS;
153
154 DPRINT("VMS: %s called\n", __FUNCTION__);
155
156 if(NULL == ListeningThread)
157 {
158 return STATUS_INVALID_PARAMETER;
159 }
160
161 RtlInitUnicodeString (& usPortName, PortName);
162 Status = NtCreatePort (pPortHandle,
163 & PortAttributes,
164 MaxDataSize,
165 MaxMessageSize,
166 0);
167 if(!NT_SUCCESS(Status))
168 {
169 DPRINT("VMS: %s: NtCreatePort failed (Status=0x%08lx)\n", __FUNCTION__, Status);
170 return Status;
171 }
172 Status = RtlCreateUserThread (NtCurrentProcess(),
173 NULL,
174 FALSE,
175 0, 0, 0,
176 ListeningThread,
177 pPortHandle,
178 NULL, NULL);
179 if(!NT_SUCCESS(Status))
180 {
181 DPRINT("VMS: %s: RtlCreateUserThread failed (Status=0x%08lx)\n", __FUNCTION__, Status);
182 return Status;
183 }
184 return Status;
185 }
186
187 /**********************************************************************
188 * VmsInitializeServer/0
189 */
190 NTSTATUS
191 VmsInitializeServer(VOID)
192 {
193 NTSTATUS Status = STATUS_SUCCESS;
194 WCHAR NameBuffer [32];
195
196 DPRINT("VMS: %s called\n", __FUNCTION__);
197
198 /* Create the \VMS directory */
199 wcscpy (NameBuffer, L"\\VMS");
200 Status = VmspCreateObDirectory (NameBuffer);
201 if(!NT_SUCCESS(Status))
202 {
203 DPRINT("VMS: %s: VmspCreateObDirectory failed!\n", __FUNCTION__);
204 }else{
205 /* Create the \VMS\SbApiPort port */
206 wcscat (NameBuffer, L"\\SbApiPort");
207 Status = VmspCreatePort (& VmsSbApiPort,
208 NameBuffer,
209 0x104,
210 0x148,
211 VmsSbApiPortThread);
212 if(!NT_SUCCESS(Status))
213 {
214 DPRINT("VMS %s: VmspCreatePort failed (Status=%08lx)\n",
215 __FUNCTION__, Status);
216 return Status;
217 }else{
218 OBJECT_ATTRIBUTES EventAttributes;
219
220 InitializeObjectAttributes (& EventAttributes,
221 NULL,
222 0,
223 NULL,
224 NULL);
225 Status = NtCreateEvent (& SmCalledBack,
226 EVENT_ALL_ACCESS,
227 & EventAttributes,
228 SynchronizationEvent,
229 FALSE);
230 if(!NT_SUCCESS(Status))
231 {
232 DPRINT("VMS: %s: NtCreateEvent failed (Status=0x%08lx)\n",
233 __FUNCTION__, Status);
234 return Status;
235 }else{
236 UNICODE_STRING VmsSbApiPortName;
237
238 RtlInitUnicodeString (& VmsSbApiPortName, NameBuffer);
239 Status = SmConnectApiPort (& VmsSbApiPortName,
240 VmsSbApiPort,
241 77, /* VMS CUI */
242 & SmApiPort);
243 if(!NT_SUCCESS(Status))
244 {
245 DPRINT("VMS: %s: SmConnectApiPort failed (Status=0x%08lx)\n",
246 __FUNCTION__, Status);
247 return Status;
248 }else{
249 Status = NtWaitForSingleObject (SmCalledBack,
250 FALSE,
251 INFINITE);
252 /* OK initialize the VMS subsystem */
253 wcscpy (& NameBuffer[4], L"\\ApiPort");
254 Status = VmspCreatePort (& VmsApiPort,
255 NameBuffer,
256 0x104,
257 0x148,
258 VmsApiPortThread);
259 /* TODO */
260
261 wcscpy (& NameBuffer[4], L"\\Session");
262 Status = VmspCreateObDirectory (NameBuffer);
263 /* TODO */
264
265 Status = SmCompleteSession (SmApiPort,
266 VmsSbApiPort,
267 VmsApiPort);
268 }
269 }
270 }
271 }
272 return STATUS_SUCCESS;
273 }
274
275 /* EOF */