dcbad0e31fe671e8d35188a9339d9f793e1e4fa7
[reactos.git] / reactos / ntoskrnl / ldr / init.c
1 /* $Id$
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: ntoskrnl/ldr/init.c
6 * PURPOSE: Loaders for PE executables
7 *
8 * PROGRAMMERS: Jean Michault
9 * Rex Jolliff (rex@lvcablemodem.com)
10 */
11
12 /* INCLUDES *****************************************************************/
13
14
15 #include <ntoskrnl.h>
16
17 #define NDEBUG
18 #include <internal/debug.h>
19
20 /* FUNCTIONS *****************************************************************/
21
22 INIT_FUNCTION
23 NTSTATUS
24 LdrLoadInitialProcess(PHANDLE ProcessHandle,
25 PHANDLE ThreadHandle)
26 {
27 UNICODE_STRING ImagePath = RTL_CONSTANT_STRING(L"\\SystemRoot\\system32\\smss.exe");
28 HANDLE SystemProcessHandle;
29 NTSTATUS Status;
30 PRTL_USER_PROCESS_PARAMETERS Params=NULL;
31 RTL_PROCESS_INFO Info;
32
33 Status = ObpCreateHandle(
34 PsGetCurrentProcess(),
35 PsInitialSystemProcess,
36 PROCESS_CREATE_PROCESS | PROCESS_CREATE_THREAD | PROCESS_QUERY_INFORMATION,
37 FALSE,
38 &SystemProcessHandle
39 );
40
41 if(!NT_SUCCESS(Status))
42 {
43 DPRINT1("Failed to create a handle for the system process!\n");
44 return Status;
45 }
46
47
48 Status = RtlCreateProcessParameters(
49 &Params,
50 &ImagePath,
51 NULL,
52 NULL,
53 NULL,
54 NULL,
55 NULL,
56 NULL,
57 NULL,
58 NULL
59 );
60
61 if(!NT_SUCCESS(Status))
62 {
63 DPRINT1("Failed to create ppb!\n");
64 ZwClose(SystemProcessHandle);
65 return Status;
66 }
67
68
69 DPRINT("Creating process\n");
70
71 Status = RtlCreateUserProcess(
72 &ImagePath,
73 OBJ_CASE_INSENSITIVE, //Valid are OBJ_INHERIT and OBJ_CASE_INSENSITIVE.
74 Params,
75 NULL,
76 NULL,
77 SystemProcessHandle,
78 FALSE,
79 NULL,
80 NULL,
81 &Info
82 );
83
84 ZwClose(SystemProcessHandle);
85 RtlDestroyProcessParameters(Params);
86
87 if (!NT_SUCCESS(Status))
88 {
89 DPRINT1("NtCreateProcess() failed (Status %lx)\n", Status);
90 return(Status);
91 }
92
93 ZwResumeThread(Info.ThreadHandle, NULL);
94
95 *ProcessHandle = Info.ProcessHandle;
96 *ThreadHandle= Info.ThreadHandle;
97
98 DPRINT("Process created successfully\n");
99
100 return(STATUS_SUCCESS);
101 }
102
103 /* EOF */