3 * init.c - VMS Enviroment Subsystem Server - Initialization
5 * ReactOS Operating System
7 * --------------------------------------------------------------------
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.
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.
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,
24 * --------------------------------------------------------------------
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
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
40 /**********************************************************************
42 *********************************************************************/
44 VmsSbApiPortThread (PVOID x
)
46 HANDLE Port
= (HANDLE
) x
;
47 NTSTATUS Status
= STATUS_SUCCESS
;
48 LPC_MAX_MESSAGE ConnectionRequest
= {{0}};
50 DPRINT("VMS: %s: called\n", __FUNCTION__
);
52 Status
= NtListenPort (Port
, & ConnectionRequest
.Header
);
53 if(!NT_SUCCESS(Status
))
55 DPRINT("VMS: %s: NtListenPort failed (Status=0x%08lx)\n",
56 __FUNCTION__
, Status
);
58 DPRINT("VMS: %s received a connection request\n", __FUNCTION__
);
59 Status
= NtAcceptConnectPort (& SmVmsSbApiPort
,
61 & ConnectionRequest
.Header
,
65 if(!NT_SUCCESS(Status
))
67 DPRINT("VMS: %s: NtAcceptConnectPort failed (Status=0x%08lx)\n",
68 __FUNCTION__
, Status
);
70 DPRINT("VMS: %s accepted the connection request\n", __FUNCTION__
);
71 Status
= NtCompleteConnectPort (SmVmsSbApiPort
);
72 if(!NT_SUCCESS(Status
))
74 DPRINT("VMS: %s: NtCompleteConnectPort failed (Status=0x%08lx)\n",
75 __FUNCTION__
, Status
);
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__
);
88 NtTerminateThread (NtCurrentThread(), Status
);
90 /**********************************************************************
92 *********************************************************************/
94 VmsApiPortThread (PVOID x
)
96 HANDLE Port
= (HANDLE
) x
;
97 NTSTATUS Status
= STATUS_SUCCESS
;
99 DPRINT("VMS: %s: called\n", __FUNCTION__
);
104 NtTerminateThread (NtCurrentThread(), Status
);
107 /**********************************************************************
109 * VmspCreateObDirectory/1
111 static NTSTATUS FASTCALL
112 VmspCreateObDirectory (PWSTR DirectoryName
)
114 UNICODE_STRING usDirectoryName
= {0};
115 OBJECT_ATTRIBUTES DirectoryAttributes
= {0};
116 NTSTATUS Status
= STATUS_SUCCESS
;
117 HANDLE hDirectory
= (HANDLE
) 0;
119 DPRINT("VMS: %s called\n", __FUNCTION__
);
121 RtlInitUnicodeString (& usDirectoryName
,
123 InitializeObjectAttributes (& DirectoryAttributes
,
126 Status
= NtCreateDirectoryObject (& hDirectory
,
127 DIRECTORY_CREATE_SUBDIRECTORY
,
128 & DirectoryAttributes
);
129 if(!NT_SUCCESS(Status
))
131 DPRINT("VMS: %s: NtCreateDirectoryObject failed (Status=0x%08lx)\n",
132 __FUNCTION__
, Status
);
135 NtClose (hDirectory
);
136 return STATUS_SUCCESS
;
139 /**********************************************************************
143 static NTSTATUS STDCALL
144 VmspCreatePort (IN OUT PHANDLE pPortHandle
,
146 IN ULONG MaxDataSize
,
147 IN ULONG MaxMessageSize
,
148 IN PTHREAD_START_ROUTINE ListeningThread
)
150 UNICODE_STRING usPortName
= {0};
151 OBJECT_ATTRIBUTES PortAttributes
= {0};
152 NTSTATUS Status
= STATUS_SUCCESS
;
154 DPRINT("VMS: %s called\n", __FUNCTION__
);
156 if(NULL
== ListeningThread
)
158 return STATUS_INVALID_PARAMETER
;
161 RtlInitUnicodeString (& usPortName
, PortName
);
162 Status
= NtCreatePort (pPortHandle
,
167 if(!NT_SUCCESS(Status
))
169 DPRINT("VMS: %s: NtCreatePort failed (Status=0x%08lx)\n", __FUNCTION__
, Status
);
172 Status
= RtlCreateUserThread (NtCurrentProcess(),
179 if(!NT_SUCCESS(Status
))
181 DPRINT("VMS: %s: RtlCreateUserThread failed (Status=0x%08lx)\n", __FUNCTION__
, Status
);
187 /**********************************************************************
188 * VmsInitializeServer/0
191 VmsInitializeServer(VOID
)
193 NTSTATUS Status
= STATUS_SUCCESS
;
194 WCHAR NameBuffer
[32];
196 DPRINT("VMS: %s called\n", __FUNCTION__
);
198 /* Create the \VMS directory */
199 wcscpy (NameBuffer
, L
"\\VMS");
200 Status
= VmspCreateObDirectory (NameBuffer
);
201 if(!NT_SUCCESS(Status
))
203 DPRINT("VMS: %s: VmspCreateObDirectory failed!\n", __FUNCTION__
);
205 /* Create the \VMS\SbApiPort port */
206 wcscat (NameBuffer
, L
"\\SbApiPort");
207 Status
= VmspCreatePort (& VmsSbApiPort
,
212 if(!NT_SUCCESS(Status
))
214 DPRINT("VMS %s: VmspCreatePort failed (Status=%08lx)\n",
215 __FUNCTION__
, Status
);
218 OBJECT_ATTRIBUTES EventAttributes
;
220 InitializeObjectAttributes (& EventAttributes
,
225 Status
= NtCreateEvent (& SmCalledBack
,
228 SynchronizationEvent
,
230 if(!NT_SUCCESS(Status
))
232 DPRINT("VMS: %s: NtCreateEvent failed (Status=0x%08lx)\n",
233 __FUNCTION__
, Status
);
236 UNICODE_STRING VmsSbApiPortName
;
238 RtlInitUnicodeString (& VmsSbApiPortName
, NameBuffer
);
239 Status
= SmConnectApiPort (& VmsSbApiPortName
,
243 if(!NT_SUCCESS(Status
))
245 DPRINT("VMS: %s: SmConnectApiPort failed (Status=0x%08lx)\n",
246 __FUNCTION__
, Status
);
249 Status
= NtWaitForSingleObject (SmCalledBack
,
252 /* OK initialize the VMS subsystem */
253 wcscpy (& NameBuffer
[4], L
"\\ApiPort");
254 Status
= VmspCreatePort (& VmsApiPort
,
261 wcscpy (& NameBuffer
[4], L
"\\Session");
262 Status
= VmspCreateObDirectory (NameBuffer
);
265 Status
= SmCompleteSession (SmApiPort
,
272 return STATUS_SUCCESS
;