[REACTOS]
[reactos.git] / reactos / deprecated / csr / main.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS CSR Sub System
4 * FILE: subsys/csr/csrss.c
5 * PURPOSE: CSR Executable
6 * PROGRAMMERS: Alex Ionescu (alex@relsoft.net)
7 */
8
9 /* INCLUDES ******************************************************************/
10
11 #define WIN32_NO_STATUS
12 #include <windows.h>
13 #define NTOS_MODE_USER
14 #include <ndk/ntndk.h>
15 #include <csr/server.h>
16
17 #define NDEBUG
18 #include <debug.h>
19
20 /* PRIVATE FUNCTIONS *********************************************************/
21
22 VOID
23 NTAPI
24 CsrpSetDefaultProcessHardErrorMode (VOID)
25 {
26 ULONG DefaultHardErrorMode = 0;
27
28 /* Disable hard errors */
29 NtSetInformationProcess(NtCurrentProcess(),
30 ProcessDefaultHardErrorMode,
31 &DefaultHardErrorMode,
32 sizeof(DefaultHardErrorMode));
33 }
34
35 /*
36 * Note: Standard entrypoint for Native C Programs.
37 * The OS backend (NtProcessStartup) which calls this routine is
38 * implemented in a CRT-like static library (much like mainCRTStartup).
39 * Do NOT manually add the NtProcessStartup entrypoint or anything else.
40 */
41 int
42 _cdecl
43 _main(int argc,
44 char *argv[],
45 char *envp[],
46 int DebugFlag)
47 {
48 KPRIORITY BasePriority = (8 + 1) + 4;
49 NTSTATUS Status;
50 ULONG Response;
51 UNREFERENCED_PARAMETER(envp);
52 UNREFERENCED_PARAMETER(DebugFlag);
53
54 /* Set the Priority */
55 NtSetInformationProcess(NtCurrentProcess(),
56 ProcessBasePriority,
57 &BasePriority,
58 sizeof(KPRIORITY));
59
60 /* Give us IOPL so that we can access the VGA registers */
61 Status = NtSetInformationProcess(NtCurrentProcess(),
62 ProcessUserModeIOPL,
63 NULL,
64 0);
65 if (!NT_SUCCESS(Status))
66 {
67 /* Raise a hard error */
68 DPRINT1("CSRSS: Could not raise IOPL: %x\n", Status);
69 Status = NtRaiseHardError(STATUS_IO_PRIVILEGE_FAILED,
70 0,
71 0,
72 NULL,
73 OptionOk,
74 &Response);
75 }
76
77 /* Initialize CSR through CSRSRV */
78 Status = CsrServerInitialization(argc, argv);
79 if (!NT_SUCCESS(Status))
80 {
81 /* Kill us */
82 DPRINT1("CSRSS: CsrServerInitialization failed:% lx\n", Status);
83 NtTerminateProcess(NtCurrentProcess(), Status);
84 }
85
86 /* Disable errors */
87 CsrpSetDefaultProcessHardErrorMode();
88
89 /* If this is Session 0, make sure killing us bugchecks the system */
90 if (!NtCurrentPeb()->SessionId) RtlSetProcessIsCritical(TRUE, NULL, FALSE);
91
92 /* Kill this thread. CSRSRV keeps us going */
93 NtTerminateThread(NtCurrentThread(), Status);
94 return 0;
95 }
96
97 /* EOF */