initial comit
[reactos.git] / os2 / server / os2ss.cpp
1 /* $Id: os2ss.cpp,v 1.1 2002/03/23 19:23:28 robertk 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
14
15 /* server variables */
16
17 int NumProcesses;
18
19
20
21 /* Native image's entry point */
22
23 void NtProcessStartup (PPEB Peb)
24 {
25 PRTL_USER_PROCESS_PARAMETERS ProcParams;
26 PWSTR ArgBuffer;
27 PWSTR *argv;
28 ULONG argc = 0;
29 int i = 0;
30 int afterlastspace = 0;
31 OBJECT_ATTRIBUTES ObjectAttributes;
32 HANDLE CsrssInitEvent;
33 UNICODE_STRING UnicodeString;
34 NTSTATUS Status;
35
36 ProcParams = RtlNormalizeProcessParams (Peb->ProcessParameters);
37
38 argv = (PWSTR *)RtlAllocateHeap (Peb->ProcessHeap,
39 0, 512 * sizeof(PWSTR));
40 ArgBuffer = (PWSTR)RtlAllocateHeap (Peb->ProcessHeap,
41 0,
42 ProcParams->CommandLine.Length + sizeof(WCHAR));
43 memcpy (ArgBuffer,
44 ProcParams->CommandLine.Buffer,
45 ProcParams->CommandLine.Length + sizeof(WCHAR));
46
47 while (ArgBuffer[i])
48 {
49 if (ArgBuffer[i] == L' ')
50 {
51 argc++;
52 ArgBuffer[i] = L'\0';
53 argv[argc-1] = &(ArgBuffer[afterlastspace]);
54 i++;
55 while (ArgBuffer[i] == L' ')
56 i++;
57 afterlastspace = i;
58 }
59 else
60 {
61 i++;
62 }
63 }
64
65 if (ArgBuffer[afterlastspace] != L'\0')
66 {
67 argc++;
68 ArgBuffer[i] = L'\0';
69 argv[argc-1] = &(ArgBuffer[afterlastspace]);
70 }
71
72 RtlInitUnicodeString(&UnicodeString,
73 L"\\CsrssInitDone");
74 InitializeObjectAttributes(&ObjectAttributes,
75 &UnicodeString,
76 EVENT_ALL_ACCESS,
77 0,
78 NULL);
79 Status = NtOpenEvent(&CsrssInitEvent,
80 EVENT_ALL_ACCESS,
81 &ObjectAttributes);
82 if (!NT_SUCCESS(Status))
83 {
84 DbgPrint("CSR: Failed to open csrss notification event\n");
85 }
86 if (CsrServerInitialization (argc, argv) == TRUE)
87 {
88
89 NtSetEvent(CsrssInitEvent,
90 NULL);
91
92 RtlFreeHeap (Peb->ProcessHeap,
93 0, argv);
94 RtlFreeHeap (Peb->ProcessHeap,
95 0,
96 ArgBuffer);
97
98 /* terminate the current thread only */
99 NtTerminateThread( NtCurrentThread(), 0 );
100 }
101 else
102 {
103 DisplayString( L"CSR: Subsystem initialization failed.\n" );
104
105 RtlFreeHeap (Peb->ProcessHeap,
106 0, argv);
107 RtlFreeHeap (Peb->ProcessHeap,
108 0,
109 ArgBuffer);
110
111 /*
112 * Tell SM we failed.
113 */
114 NtTerminateProcess( NtCurrentProcess(), 0 );
115 }