temporarily disable -Werror for tools, there seem to be differences between versions...
[reactos.git] / os2 / server / os2ss.cpp
1 /* $Id: os2ss.cpp,v 1.2 2003/01/07 16:23:12 robd Exp $
2 *
3 * reactos/subsys/csrss/api/process.c
4 *
5 * "\windows\ApiPort" port process management functions
6 *
7 * ReactOS Operating System
8 */
9 // TODO: Rewrite the whole file. This is just a copy
10
11 #include <ddk/ntddk.h>
12 #include <ntdll/rtl.h>
13 #include <ntos/synch.h>
14
15 extern "C" {
16 BOOL CsrServerInitialization(ULONG ArgumentCount, PWSTR *ArgumentArray);
17 VOID DisplayString(LPCWSTR lpwString);
18 //BOOL STDCALL CsrServerInitialization (ULONG ArgumentCount, PWSTR *ArgumentArray);
19 //VOID STDCALL DisplayString(LPCWSTR lpwString);
20 //VOID STDCALL PrintString (char* fmt, ...);
21 //NTSTATUS STDCALL NtDisplayString(IN PUNICODE_STRING DisplayString);
22
23 void
24 DisplayString(LPCWSTR lpwString)
25 {
26 UNICODE_STRING us;
27
28 RtlInitUnicodeString(&us, lpwString);
29 NtDisplayString(&us);
30 }
31
32 /*
33 void
34 PrintString(char* fmt,...)
35 {
36 char buffer[512];
37 va_list ap;
38 UNICODE_STRING UnicodeString;
39 ANSI_STRING AnsiString;
40
41 va_start(ap, fmt);
42 vsprintf(buffer, fmt, ap);
43 va_end(ap);
44
45 RtlInitAnsiString(&AnsiString, buffer);
46 RtlAnsiStringToUnicodeString(&UnicodeString,
47 &AnsiString,
48 TRUE);
49 NtDisplayString(&UnicodeString);
50 RtlFreeUnicodeString(&UnicodeString);
51 }
52 */
53
54 }
55
56 /* server variables */
57
58 int NumProcesses;
59
60
61
62 /* Native image's entry point */
63
64 void NtProcessStartup (PPEB Peb)
65 {
66 PRTL_USER_PROCESS_PARAMETERS ProcParams;
67 PWSTR ArgBuffer;
68 PWSTR *argv;
69 ULONG argc = 0;
70 int i = 0;
71 int afterlastspace = 0;
72 OBJECT_ATTRIBUTES ObjectAttributes;
73 HANDLE CsrssInitEvent;
74 UNICODE_STRING UnicodeString;
75 NTSTATUS Status;
76
77 ProcParams = RtlNormalizeProcessParams (Peb->ProcessParameters);
78
79 argv = (PWSTR *)RtlAllocateHeap (Peb->ProcessHeap,
80 0, 512 * sizeof(PWSTR));
81 ArgBuffer = (PWSTR)RtlAllocateHeap (Peb->ProcessHeap,
82 0,
83 ProcParams->CommandLine.Length + sizeof(WCHAR));
84 memcpy (ArgBuffer,
85 ProcParams->CommandLine.Buffer,
86 ProcParams->CommandLine.Length + sizeof(WCHAR));
87
88 while (ArgBuffer[i])
89 {
90 if (ArgBuffer[i] == L' ')
91 {
92 argc++;
93 ArgBuffer[i] = L'\0';
94 argv[argc-1] = &(ArgBuffer[afterlastspace]);
95 i++;
96 while (ArgBuffer[i] == L' ')
97 i++;
98 afterlastspace = i;
99 }
100 else
101 {
102 i++;
103 }
104 }
105
106 if (ArgBuffer[afterlastspace] != L'\0')
107 {
108 argc++;
109 ArgBuffer[i] = L'\0';
110 argv[argc-1] = &(ArgBuffer[afterlastspace]);
111 }
112
113 RtlInitUnicodeString(&UnicodeString,
114 L"\\CsrssInitDone");
115 InitializeObjectAttributes(&ObjectAttributes,
116 &UnicodeString,
117 EVENT_ALL_ACCESS,
118 0,
119 NULL);
120 Status = NtOpenEvent(&CsrssInitEvent,
121 EVENT_ALL_ACCESS,
122 &ObjectAttributes);
123 if (!NT_SUCCESS(Status))
124 {
125 DbgPrint("CSR: Failed to open csrss notification event\n");
126 }
127 if (CsrServerInitialization (argc, argv) == TRUE)
128 {
129
130 NtSetEvent(CsrssInitEvent,
131 NULL);
132
133 RtlFreeHeap (Peb->ProcessHeap,
134 0, argv);
135 RtlFreeHeap (Peb->ProcessHeap,
136 0,
137 ArgBuffer);
138
139 /* terminate the current thread only */
140 NtTerminateThread( NtCurrentThread(), 0 );
141 }
142 else
143 {
144 DisplayString( L"CSR: Subsystem initialization failed.\n" );
145
146 RtlFreeHeap (Peb->ProcessHeap,
147 0, argv);
148 RtlFreeHeap (Peb->ProcessHeap,
149 0,
150 ArgBuffer);
151
152 /*
153 * Tell SM we failed.
154 */
155 NtTerminateProcess( NtCurrentProcess(), 0 );
156 }
157 }