b18287eb4535eea3d4a6f5458877560bb4605c8f
[reactos.git] / reactos / subsys / csrss / init.c
1 /* $Id: init.c,v 1.19 2003/06/17 13:55:16 gvg Exp $
2 *
3 * reactos/subsys/csrss/init.c
4 *
5 * Initialize the CSRSS subsystem server process.
6 *
7 * ReactOS Operating System
8 *
9 */
10
11 /* INCLUDES ******************************************************************/
12
13 #include <ddk/ntddk.h>
14 #include <ntdll/rtl.h>
15 #include <csrss/csrss.h>
16 #include <win32k/win32k.h>
17
18 #include "api.h"
19
20 /* GLOBALS ******************************************************************/
21
22 /*
23 * Server's named ports.
24 */
25 static HANDLE ApiPortHandle;
26
27
28 HANDLE CsrInitEvent = INVALID_HANDLE_VALUE;
29 HANDLE CsrHeap = INVALID_HANDLE_VALUE;
30
31 HANDLE CsrObjectDirectory = INVALID_HANDLE_VALUE;
32 HANDLE CsrApiPort = INVALID_HANDLE_VALUE;
33 HANDLE CsrSbApiPort = INVALID_HANDLE_VALUE;
34
35 UNICODE_STRING CsrDirectoryName;
36
37 extern HANDLE CsrssApiHeap;
38
39 ULONG
40 InitializeVideoAddressSpace(VOID);
41
42 static NTSTATUS
43 CsrParseCommandLine (
44 ULONG ArgumentCount,
45 PWSTR *ArgumentArray
46 )
47 {
48 NTSTATUS Status;
49 OBJECT_ATTRIBUTES Attributes;
50 ANSI_STRING AnsiString;
51
52 ULONG i;
53
54 /* DbgPrint ("Arguments: %ld\n", ArgumentCount);
55 for (i = 0; i < ArgumentCount; i++)
56 {
57 DbgPrint ("Argument %ld: %S\n", i, ArgumentArray[i]);
58 }*/
59
60
61 /* create object directory ('\Windows') */
62 RtlCreateUnicodeString (&CsrDirectoryName,
63 L"\\Windows");
64
65 InitializeObjectAttributes (&Attributes,
66 &CsrDirectoryName,
67 0,
68 NULL,
69 NULL);
70
71 Status = NtCreateDirectoryObject(&CsrObjectDirectory,
72 0xF000F,
73 &Attributes);
74
75 return Status;
76 }
77
78
79 static VOID
80 CsrInitVideo(VOID)
81 {
82 OBJECT_ATTRIBUTES ObjectAttributes;
83 UNICODE_STRING DeviceName;
84 IO_STATUS_BLOCK Iosb;
85 HANDLE VideoHandle;
86 NTSTATUS Status;
87
88 InitializeVideoAddressSpace();
89
90 RtlInitUnicodeStringFromLiteral(&DeviceName, L"\\??\\DISPLAY1");
91 InitializeObjectAttributes(&ObjectAttributes,
92 &DeviceName,
93 0,
94 NULL,
95 NULL);
96 Status = NtOpenFile(&VideoHandle,
97 FILE_ALL_ACCESS,
98 &ObjectAttributes,
99 &Iosb,
100 0,
101 0);
102 if (NT_SUCCESS(Status))
103 {
104 NtClose(VideoHandle);
105 }
106 }
107
108
109 /**********************************************************************
110 * NAME
111 * CsrServerInitialization
112 *
113 * DESCRIPTION
114 * Create a directory object (\windows) and two named LPC ports:
115 *
116 * 1. \windows\ApiPort
117 * 2. \windows\SbApiPort
118 *
119 * RETURN VALUE
120 * TRUE: Initialization OK; otherwise FALSE.
121 */
122 BOOL
123 STDCALL
124 CsrServerInitialization (
125 ULONG ArgumentCount,
126 PWSTR *ArgumentArray
127 )
128 {
129 NTSTATUS Status;
130 OBJECT_ATTRIBUTES ObAttributes;
131 UNICODE_STRING PortName;
132 OBJECT_ATTRIBUTES RefreshEventAttr;
133 UNICODE_STRING RefreshEventName;
134 HANDLE RefreshEventHandle;
135
136 Status = CsrParseCommandLine (ArgumentCount, ArgumentArray);
137 if (!NT_SUCCESS(Status))
138 {
139 PrintString("CSR: Unable to parse the command line (Status: %x)\n", Status);
140 return(FALSE);
141 }
142
143 CsrInitVideo();
144
145 /* NEW NAMED PORT: \ApiPort */
146 RtlInitUnicodeStringFromLiteral(&PortName, L"\\Windows\\ApiPort");
147 InitializeObjectAttributes(&ObAttributes,
148 &PortName,
149 0,
150 NULL,
151 NULL);
152
153 Status = NtCreatePort(&ApiPortHandle,
154 &ObAttributes,
155 260,
156 328,
157 0);
158 if (!NT_SUCCESS(Status))
159 {
160 PrintString("CSR: Unable to create \\ApiPort (Status %x)\n", Status);
161 return(FALSE);
162 }
163 CsrssApiHeap = RtlCreateHeap(HEAP_GROWABLE,
164 NULL,
165 65536,
166 65536,
167 NULL,
168 NULL);
169 if (CsrssApiHeap == NULL)
170 {
171 PrintString("CSR: Failed to create private heap, aborting\n");
172 return FALSE;
173 }
174
175 CsrInitConsoleSupport();
176 Status = RtlCreateUserThread(NtCurrentProcess(),
177 NULL,
178 FALSE,
179 0,
180 NULL,
181 NULL,
182 (PTHREAD_START_ROUTINE)Thread_Api,
183 ApiPortHandle,
184 NULL,
185 NULL);
186 if (!NT_SUCCESS(Status))
187 {
188 PrintString("CSR: Unable to create server thread\n");
189 NtClose(ApiPortHandle);
190 return FALSE;
191 }
192 RtlInitUnicodeStringFromLiteral( &RefreshEventName, L"\\TextConsoleRefreshEvent" );
193 InitializeObjectAttributes( &RefreshEventAttr, &RefreshEventName, 0, NULL, NULL );
194 Status = NtCreateEvent( &RefreshEventHandle, STANDARD_RIGHTS_ALL, &RefreshEventAttr, FALSE, FALSE );
195 if( !NT_SUCCESS( Status ) )
196 {
197 PrintString( "CSR: Unable to create refresh event!\n" );
198 return FALSE;
199 }
200 Status = RtlCreateUserThread( NtCurrentProcess(), NULL, FALSE, 0, NULL, NULL, (PTHREAD_START_ROUTINE)Console_Api, (PVOID) RefreshEventHandle, NULL, NULL );
201 if( !NT_SUCCESS( Status ) )
202 {
203 PrintString( "CSR: Unable to create console thread\n" );
204 return FALSE;
205 }
206
207 W32kInitialize();
208
209 return TRUE;
210 }
211
212 /* EOF */