1 /* $Id: init.c,v 1.3 2002/10/29 04:45:54 rex Exp $
3 * PROJECT : ReactOS / POSIX+ Environment Subsystem Server
4 * FILE : reactos/subsys/psx/server/srv/init.c
5 * DESCRIPTION: POSIX+ server initialization.
7 * AUTHOR : Emanuele Aliberti <eal@users.sf.net>
9 * --------------------------------------------------------------------
11 * This software is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation; either version 2 of the
14 * License, or (at your option) any later version.
16 * This software is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this software; see the file COPYING. If not, write
23 * to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge,
26 * --------------------------------------------------------------------
31 #ifdef __PSXSS_ON_W32__
35 /*** GLOBALS *********************************************************/
43 { INVALID_HANDLE_VALUE
,
44 L
"\\"PSX_NS_SUBSYSTEM_DIRECTORY_NAME
,
47 { INVALID_HANDLE_VALUE
,
48 L
"\\"PSX_NS_SUBSYSTEM_DIRECTORY_NAME
"\\"PSX_NS_SESSION_DIRECTORY_NAME
,
51 { INVALID_HANDLE_VALUE
,
52 L
"\\"PSX_NS_SUBSYSTEM_DIRECTORY_NAME
"\\"PSX_NS_SYSTEM_DIRECTORY_NAME
,
58 { INVALID_HANDLE_VALUE
,
59 L
"\\"PSX_NS_SUBSYSTEM_DIRECTORY_NAME
"\\"PSX_NS_API_PORT_NAME
,
63 { INVALID_HANDLE_VALUE
,
64 L
"\\"PSX_NS_SUBSYSTEM_DIRECTORY_NAME
"\\"PSX_NS_SBAPI_PORT_NAME
,
68 { INVALID_HANDLE_VALUE
,
69 L
"\\"PSX_NS_SUBSYSTEM_DIRECTORY_NAME
"\\"PSX_NS_SESSIONAPI_PORT_NAME
,
76 /*** FUNCTIONS *******************************************************/
78 /**********************************************************************
79 * PdxInitializeHeap/0 PRIVATE
82 * Initialize the PSX server process' heap.
84 PRIVATE HANDLE STDCALL
85 PdxInitializeHeap (VOID
)
87 return Server
.Heap
= (HANDLE
)NtCurrentPeb()->ProcessHeap
;
89 /**********************************************************************
90 * PdxCreateDirectory/1 PRIVATE
93 * Create a directory in the system name space.
95 PRIVATE NTSTATUS STDCALL
100 OBJECT_ATTRIBUTES ObjectAttributes
;
103 RtlCreateUnicodeString (
104 & Server
.Directory
[ulIndex
].usName
,
105 Server
.Directory
[ulIndex
].wsName
107 InitializeObjectAttributes (
109 & Server
.Directory
[ulIndex
].usName
,
114 Status
= NtCreateDirectoryObject(
115 & Server
.Directory
[ulIndex
].hObject
,
116 DIRECTORY_ALL_ACCESS
,
119 if (!NT_SUCCESS(Status
))
122 L
"PSXSS: %s directory creation failed (Status = %08x)",
123 Server
.Directory
[ulIndex
].wsName
,
130 /**********************************************************************
131 * PdxInitializeDirectories/0 PRIVATE
134 * Create the directories used by the POSIX+ subsystem
135 * components in the system name space.
137 PRIVATE NTSTATUS STDCALL
138 PdxInitializeDirectories (VOID
)
144 (ulIndex
< (sizeof Server
.Directory
/ sizeof Server
.Directory
[0]));
147 Status
= PdxCreateDirectory (ulIndex
);
148 if (!NT_SUCCESS(Status
)) return Status
;
150 return STATUS_SUCCESS
;
152 /**********************************************************************
153 * PdxInitializeListener/1 PRIVATE
156 * Initialize a thread to make an LPC port listen.
158 PRIVATE NTSTATUS STDCALL
159 PdxInitializeListener (ULONG ulIndex
)
162 OBJECT_ATTRIBUTES Oa
;
165 RtlInitUnicodeString (
166 & Server
.Port
[ulIndex
].usName
,
167 Server
.Port
[ulIndex
].wsName
169 InitializeObjectAttributes(
171 & Server
.Port
[ulIndex
].usName
,
176 /* Create the listening LPC port */
177 Status
= NtCreatePort (
178 & Server
.Port
[ulIndex
].hObject
,
184 if (!NT_SUCCESS(Status
))
187 L
"PSXSS: Unable to create port \"%s\": Status %08x\n",
188 Server
.Port
[ulIndex
].wsName
,
193 * Create the server thread that will process
194 * messages sent to this port.
196 for ( ulThreadIndex
= 0;
197 (ulThreadIndex
< PSXSS_THREADS_PER_PORT
);
201 #ifdef __PSXSS_ON_W32__
202 Server
.Port
[ulIndex
].ThreadInfo
[ulThreadIndex
].hObject
=
206 (PTHREAD_START_ROUTINE
) Server
.Port
[ulIndex
].EntryPoint
,
209 & Server
.Port
[ulIndex
].ThreadInfo
[ulThreadIndex
].Id
211 if (NULL
== Server
.Port
[ulIndex
].ThreadInfo
[ulThreadIndex
].hObject
)
213 if (!NT_SUCCESS(Status
))
217 L
"PSXSS: Unable to create a server thread for port \"%s\": Status %08x\n",
218 Server
.Port
[ulIndex
].wsName
,
221 NtClose (Server
.Port
[ulIndex
].hObject
);
225 return STATUS_SUCCESS
;
227 /**********************************************************************
228 * PsxInitializeListeners/0 PRIVATE
231 * Initialize the LPC ports and associate threads.
233 PRIVATE NTSTATUS STDCALL
234 PdxInitializeListeners (VOID
)
240 (ulIndex
< (sizeof Server
.Port
/ sizeof Server
.Port
[0]));
243 Status
= PdxInitializeListener (ulIndex
);
244 if (!NT_SUCCESS(Status
)) return Status
;
246 return STATUS_SUCCESS
;
248 /**********************************************************************
249 * PdxRunServer/0 PRIVATE
252 * Wake up all suspended threads.
254 PRIVATE NTSTATUS STDCALL
262 (ulIndex
< (sizeof Server
.Port
/ sizeof Server
.Port
[0]));
265 for (ulThreadIndex
= 0;
266 (ulThreadIndex
< PSXSS_THREADS_PER_PORT
);
270 #ifdef __PSXSS_ON_W32__
271 if (0xFFFFFFFF == ResumeThread (Server
.Port
[ulIndex
].ThreadInfo
[ulThreadIndex
].hObject
))
273 Status
= NtResumeThread (Server
.Port
[ulIndex
].ThreadInfo
[ulThreadIndex
].hObject
, NULL
);
274 if (!NT_SUCCESS(Status
))
278 L
"PSXSS: "__FUNCTION__
": NtResumeThread failed with Status = %08x",
285 return STATUS_SUCCESS
;
287 /**********************************************************************
288 * PsxServerInitialization/2
291 * Initialize the PSX server process.
294 PsxServerInitialization (
295 IN ULONG ArgumentCount
,
296 IN PWSTR
*ArgumentArray
302 PdxInitializeHeap ();
303 /* Initialize POSIX+ and Sessions */
304 Status
= PdxInitializeDirectories ();
305 if (!NT_SUCCESS(Status
)) return Status
;
306 /* LPCs dispatchers */
307 Status
= PdxInitializeListeners ();
308 if (!NT_SUCCESS(Status
)) return Status
;
309 /* Terminal manager */
310 Status
= PsxInitializeSessions ();
311 if (!NT_SUCCESS(Status
)) return Status
;
312 /* Process manager */
313 Status
= PsxInitializeProcesses ();
314 if (!NT_SUCCESS(Status
)) return Status
;
316 Status
= PdxRunServer ();