- Create KD branch. All debugging support is removed in this branch (no symbols,...
[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 #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
71 /* Set the Priority */
72 NtSetInformationProcess(NtCurrentProcess(),
73 ProcessBasePriority,
74 &BasePriority,
75 sizeof(KPRIORITY));
76
77 /* Give us IOPL so that we can access the VGA registers */
78 Status = NtSetInformationProcess(NtCurrentProcess(),
79 ProcessUserModeIOPL,
80 NULL,
81 0);
82 if (NT_SUCCESS(Status))
83 {
84 /* Raise a hard error */
85 DPRINT1("CSRSS: Could not raise IOPL: %x\n", Status);
86 Status = NtRaiseHardError(STATUS_IO_PRIVILEGE_FAILED,
87 0,
88 0,
89 NULL,
90 OptionOk,
91 &Response);
92 }
93
94 /* Initialize CSR through CSRSRV */
95 Status = CsrServerInitialization(argc, argv);
96 if (!NT_SUCCESS(Status))
97 {
98 /* Kill us */
99 DPRINT1("CSRSS: CsrServerInitialization failed:% lx\n", Status);
100 NtTerminateProcess (NtCurrentProcess(), Status);
101 }
102
103 /* Disable errors */
104 CsrpSetDefaultProcessHardErrorMode();
105
106 /* If this is Session 0, make sure killing us bugchecks the system */
107 if (!NtCurrentPeb()->SessionId) RtlSetProcessIsCritical(TRUE, NULL, FALSE);
108
109 /* Kill this thread. CSRSRV keeps us going */
110 NtTerminateThread (NtCurrentThread(), Status);
111 return 0;
112 }
113
114 /* EOF */