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