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