RtlUnicodeStringToCountedOemString() is now "pass"ed
[reactos.git] / subsys / csrss / init.c
1 /* $Id$
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   RtlInitUnicodeStringFromLiteral(&DeviceName, L"\\??\\DISPLAY1");
89   InitializeObjectAttributes(&ObjectAttributes,
90                              &DeviceName,
91                              0,
92                              NULL,
93                              NULL);
94   Status = NtOpenFile(&VideoHandle,
95                       FILE_ALL_ACCESS,
96                       &ObjectAttributes,
97                       &Iosb,
98                       0,
99                       0);
100   if (NT_SUCCESS(Status))
101     {
102       NtClose(VideoHandle);
103     }
104 }
105
106
107 /**********************************************************************
108  * NAME
109  *      CsrServerInitialization
110  *
111  * DESCRIPTION
112  *      Create a directory object (\windows) and two named LPC ports:
113  *
114  *      1. \windows\ApiPort
115  *      2. \windows\SbApiPort
116  *
117  * RETURN VALUE
118  *      TRUE: Initialization OK; otherwise FALSE.
119  */
120 BOOL
121 STDCALL
122 CsrServerInitialization (
123         ULONG ArgumentCount,
124         PWSTR *ArgumentArray
125         )
126 {
127    NTSTATUS             Status;
128    OBJECT_ATTRIBUTES    ObAttributes;
129    UNICODE_STRING PortName;
130    OBJECT_ATTRIBUTES RefreshEventAttr;
131    UNICODE_STRING RefreshEventName;
132    HANDLE RefreshEventHandle;
133
134    Status = CsrParseCommandLine (ArgumentCount, ArgumentArray);
135    if (!NT_SUCCESS(Status))
136      {
137         PrintString("CSR: Unable to parse the command line (Status: %x)\n", Status);
138         return(FALSE);
139      }
140
141    CsrInitVideo();
142
143    /* NEW NAMED PORT: \ApiPort */
144    RtlInitUnicodeStringFromLiteral(&PortName, L"\\Windows\\ApiPort");
145    InitializeObjectAttributes(&ObAttributes,
146                               &PortName,
147                               0,
148                               NULL,
149                               NULL);
150
151    Status = NtCreatePort(&ApiPortHandle,
152                          &ObAttributes,
153                          260,
154                          328,
155                          0);
156    if (!NT_SUCCESS(Status))
157      {
158         PrintString("CSR: Unable to create \\ApiPort (Status %x)\n", Status);
159         return(FALSE);
160      }
161    CsrssApiHeap = RtlCreateHeap(HEAP_GROWABLE,
162                                 NULL,
163                                 65536,
164                                 65536,
165                                 NULL,
166                                 NULL);
167    if (CsrssApiHeap == NULL)
168      {
169         PrintString("CSR: Failed to create private heap, aborting\n");
170         return FALSE;
171      }
172
173    CsrInitConsoleSupport();
174    Status = RtlCreateUserThread(NtCurrentProcess(),
175                                 NULL,
176                                 FALSE,
177                                 0,
178                                 NULL,
179                                 NULL,
180                                 (PTHREAD_START_ROUTINE)Thread_Api,
181                                 ApiPortHandle,
182                                 NULL,
183                                 NULL);
184    if (!NT_SUCCESS(Status))
185      {
186         PrintString("CSR: Unable to create server thread\n");
187         NtClose(ApiPortHandle);
188         return FALSE;
189      }
190    RtlInitUnicodeStringFromLiteral( &RefreshEventName, L"\\TextConsoleRefreshEvent" );
191    InitializeObjectAttributes( &RefreshEventAttr, &RefreshEventName, 0, NULL, NULL );
192    Status = NtCreateEvent( &RefreshEventHandle, STANDARD_RIGHTS_ALL, &RefreshEventAttr, FALSE, FALSE );
193    if( !NT_SUCCESS( Status ) )
194      {
195        PrintString( "CSR: Unable to create refresh event!\n" );
196        return FALSE;
197      }
198    Status = RtlCreateUserThread( NtCurrentProcess(), NULL, FALSE, 0, NULL, NULL, (PTHREAD_START_ROUTINE)Console_Api, (PVOID) RefreshEventHandle, NULL, NULL );
199    if( !NT_SUCCESS( Status ) )
200      {
201        PrintString( "CSR: Unable to create console thread\n" );
202        return FALSE;
203      }
204
205    InitializeVideoAddressSpace();
206
207    W32kInitialize();
208
209    return TRUE;
210 }
211
212 /* EOF */