Make child processes inherit command-line options through the
[wine.git] / loader / main.c
blob1652e5e58cc0387dba0751deeee92e4d46936535
1 /*
2 * Main initialization code
3 */
5 #include <assert.h>
6 #include <stdlib.h>
7 #include <sys/types.h>
8 #include <sys/stat.h>
9 #include <fcntl.h>
10 #include <unistd.h>
11 #include <string.h>
12 #include <errno.h>
13 #include "windef.h"
14 #include "wingdi.h"
15 #include "wine/winbase16.h"
16 #include "wine/winuser16.h"
17 #include "bitmap.h"
18 #include "comm.h"
19 #include "neexe.h"
20 #include "main.h"
21 #include "menu.h"
22 #include "message.h"
23 #include "dialog.h"
24 #include "drive.h"
25 #include "queue.h"
26 #include "sysmetrics.h"
27 #include "file.h"
28 #include "heap.h"
29 #include "keyboard.h"
30 #include "mouse.h"
31 #include "input.h"
32 #include "display.h"
33 #include "miscemu.h"
34 #include "options.h"
35 #include "process.h"
36 #include "spy.h"
37 #include "tweak.h"
38 #include "user.h"
39 #include "cursoricon.h"
40 #include "global.h"
41 #include "dce.h"
42 #include "shell.h"
43 #include "win.h"
44 #include "winproc.h"
45 #include "syslevel.h"
46 #include "services.h"
47 #include "winsock.h"
48 #include "selectors.h"
49 #include "thread.h"
50 #include "task.h"
51 #include "debugtools.h"
52 #include "psdrv.h"
53 #include "win16drv.h"
54 #include "callback.h"
55 #include "server.h"
56 #include "loadorder.h"
58 DEFAULT_DEBUG_CHANNEL(server);
60 /***********************************************************************
61 * Main initialisation routine
63 BOOL MAIN_MainInit( char *argv[] )
65 /* store the program name */
66 argv0 = argv[0];
68 /* Create the initial process */
69 if (!PROCESS_Init()) return FALSE;
71 /* Parse command line arguments */
72 OPTIONS_ParseOptions( argv );
73 MAIN_WineInit();
75 /* Load the configuration file */
76 if (!PROFILE_LoadWineIni()) return FALSE;
78 /* Initialise DOS drives */
79 if (!DRIVE_Init()) return FALSE;
81 /* Initialise DOS directories */
82 if (!DIR_Init()) return FALSE;
84 /* Registry initialisation */
85 SHELL_LoadRegistry();
87 /* Global boot finished, the rest is process-local */
88 CLIENT_BootDone( TRACE_ON(server) );
90 /* Initialize module loadorder */
91 if (!MODULE_InitLoadOrder()) return FALSE;
93 return TRUE;
96 /***********************************************************************
97 * KERNEL initialisation routine
99 BOOL WINAPI MAIN_KernelInit(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
101 static BOOL initDone = FALSE;
103 HMODULE16 hModule;
105 if ( initDone ) return TRUE;
106 initDone = TRUE;
108 /* Initialize DOS memory */
109 if (!DOSMEM_Init(0)) return FALSE;
111 if (!LoadLibrary16( "KRNL386.EXE" )) return FALSE;
113 /* Initialize special KERNEL entry points */
114 hModule = GetModuleHandle16( "KERNEL" );
115 if ( hModule )
117 /* Initialize KERNEL.178 (__WINFLAGS) with the correct flags value */
118 NE_SetEntryPoint( hModule, 178, GetWinFlags16() );
120 /* Initialize KERNEL.454/455 (__FLATCS/__FLATDS) */
121 NE_SetEntryPoint( hModule, 454, __get_cs() );
122 NE_SetEntryPoint( hModule, 455, __get_ds() );
124 /* Initialize KERNEL.THHOOK */
125 TASK_InstallTHHook((THHOOK *)PTR_SEG_TO_LIN(
126 (SEGPTR)NE_GetEntryPoint( hModule, 332 )));
128 /* Initialize the real-mode selector entry points */
129 #define SET_ENTRY_POINT( num, addr ) \
130 NE_SetEntryPoint( hModule, (num), GLOBAL_CreateBlock( GMEM_FIXED, \
131 DOSMEM_MapDosToLinear(addr), 0x10000, hModule, \
132 FALSE, FALSE, FALSE, NULL ))
134 SET_ENTRY_POINT( 183, 0x00000 ); /* KERNEL.183: __0000H */
135 SET_ENTRY_POINT( 174, 0xa0000 ); /* KERNEL.174: __A000H */
136 SET_ENTRY_POINT( 181, 0xb0000 ); /* KERNEL.181: __B000H */
137 SET_ENTRY_POINT( 182, 0xb8000 ); /* KERNEL.182: __B800H */
138 SET_ENTRY_POINT( 195, 0xc0000 ); /* KERNEL.195: __C000H */
139 SET_ENTRY_POINT( 179, 0xd0000 ); /* KERNEL.179: __D000H */
140 SET_ENTRY_POINT( 190, 0xe0000 ); /* KERNEL.190: __E000H */
141 NE_SetEntryPoint( hModule, 173, DOSMEM_BiosSysSeg ); /* KERNEL.173: __ROMBIOS */
142 NE_SetEntryPoint( hModule, 193, DOSMEM_BiosDataSeg ); /* KERNEL.193: __0040H */
143 NE_SetEntryPoint( hModule, 194, DOSMEM_BiosSysSeg ); /* KERNEL.194: __F000H */
144 #undef SET_ENTRY_POINT
147 /* Initialize relay code */
148 if (!RELAY_Init()) return FALSE;
150 /* Initialize communications */
151 COMM_Init();
153 /* Initialize IO-port permissions */
154 IO_port_init();
156 /* Read DOS config.sys */
157 if (!DOSCONF_ReadConfig()) return FALSE;
159 return TRUE;
163 /***********************************************************************
164 * ExitKernel16 (KERNEL.2)
166 * Clean-up everything and exit the Wine process.
169 void WINAPI ExitKernel16( void )
171 /* Do the clean-up stuff */
173 WriteOutProfiles16();
174 TerminateProcess( GetCurrentProcess(), 0 );