Sync with trunk head (part 1 of x)
[reactos.git] / subsystems / csr / main.c
1 /* $Id$
2 * --------------------------------------------------------------------
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 *
18 * --------------------------------------------------------------------
19 */
20 /*
21 * COPYRIGHT: See COPYING in the top level directory
22 * PROJECT: ReactOS CSR Sub System
23 * FILE: subsys/csr/csrss.c
24 * PURPOSE: CSR Executable
25 * PROGRAMMERS: Alex Ionescu (alex@relsoft.net)
26 */
27
28 /* INCLUDES ******************************************************************/
29
30 #define WIN32_NO_STATUS
31 #include <windows.h>
32 #define NTOS_MODE_USER
33 #include <ndk/ntndk.h>
34 #include <csr/server.h>
35
36 #define NDEBUG
37 #include <debug.h>
38
39 /* PRIVATE FUNCTIONS *********************************************************/
40
41 VOID
42 NTAPI
43 CsrpSetDefaultProcessHardErrorMode (VOID)
44 {
45 ULONG DefaultHardErrorMode = 0;
46
47 /* Disable hard errors */
48 NtSetInformationProcess(NtCurrentProcess(),
49 ProcessDefaultHardErrorMode,
50 &DefaultHardErrorMode,
51 sizeof(DefaultHardErrorMode));
52 }
53
54 /*
55 * Note: Standard entrypoint for Native C Programs.
56 * The OS backend (NtProcessStartup) which calls this routine is
57 * implemented in a CRT-like static library (much like mainCRTStartup).
58 * Do NOT manually add the NtProcessStartup entrypoint or anything else.
59 */
60 int
61 _cdecl
62 _main(int argc,
63 char *argv[],
64 char *envp[],
65 int DebugFlag)
66 {
67 KPRIORITY BasePriority = (8 + 1) + 4;
68 NTSTATUS Status;
69 ULONG Response;
70 UNREFERENCED_PARAMETER(envp);
71 UNREFERENCED_PARAMETER(DebugFlag);
72
73
74 /* Set the Priority */
75 NtSetInformationProcess(NtCurrentProcess(),
76 ProcessBasePriority,
77 &BasePriority,
78 sizeof(KPRIORITY));
79
80 /* Give us IOPL so that we can access the VGA registers */
81 Status = NtSetInformationProcess(NtCurrentProcess(),
82 ProcessUserModeIOPL,
83 NULL,
84 0);
85 if (!NT_SUCCESS(Status))
86 {
87 /* Raise a hard error */
88 DPRINT1("CSRSS: Could not raise IOPL: %x\n", Status);
89 Status = NtRaiseHardError(STATUS_IO_PRIVILEGE_FAILED,
90 0,
91 0,
92 NULL,
93 OptionOk,
94 &Response);
95 }
96
97 /* Initialize CSR through CSRSRV */
98 Status = CsrServerInitialization(argc, argv);
99 if (!NT_SUCCESS(Status))
100 {
101 /* Kill us */
102 DPRINT1("CSRSS: CsrServerInitialization failed:% lx\n", Status);
103 NtTerminateProcess (NtCurrentProcess(), Status);
104 }
105
106 /* Disable errors */
107 CsrpSetDefaultProcessHardErrorMode();
108
109 /* If this is Session 0, make sure killing us bugchecks the system */
110 if (!NtCurrentPeb()->SessionId) RtlSetProcessIsCritical(TRUE, NULL, FALSE);
111
112 /* Kill this thread. CSRSRV keeps us going */
113 NtTerminateThread (NtCurrentThread(), Status);
114 return 0;
115 }
116
117 /* EOF */