Release 20030408.
[wine/gsoc-2012-control.git] / dlls / kernel / kernel_main.c
blob442d059befe3d8c7af4db0942fa6e35422c3fe8c
1 /*
2 * Kernel initialization code
4 * Copyright 2000 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "config.h"
22 #include "wine/port.h"
24 #include <assert.h>
25 #include <ctype.h>
26 #include <string.h>
27 #include <sys/stat.h>
28 #include <signal.h>
30 #include "winbase.h"
31 #include "wincon.h"
32 #include "winternl.h"
34 #include "wine/winbase16.h"
35 #include "wine/library.h"
36 #include "file.h"
37 #include "global.h"
38 #include "miscemu.h"
39 #include "module.h"
40 #include "task.h"
41 #include "wincon.h"
42 #include "console_private.h"
44 extern void LOCALE_Init(void);
45 extern BOOL RELAY_Init(void);
46 extern void COMPUTERNAME_Init(void);
48 extern int __wine_set_signal_handler(unsigned, int (*)(unsigned));
50 extern int main_create_flags;
52 static CRITICAL_SECTION ldt_section = CRITICAL_SECTION_INIT("ldt_section");
54 /***********************************************************************
55 * locking for LDT routines
57 static void ldt_lock(void)
59 EnterCriticalSection( &ldt_section );
62 static void ldt_unlock(void)
64 LeaveCriticalSection( &ldt_section );
67 /***********************************************************************
68 * KERNEL process initialisation routine
70 static BOOL process_attach(void)
72 HMODULE16 hModule;
74 /* Get the umask */
75 FILE_umask = umask(0777);
76 umask( FILE_umask );
78 /* Setup codepage info */
79 LOCALE_Init();
81 /* Initialize relay entry points */
82 if (!RELAY_Init()) return FALSE;
84 /* Initialize DOS memory */
85 if (!DOSMEM_Init(0)) return FALSE;
87 /* Setup computer name */
88 COMPUTERNAME_Init();
90 if ((hModule = LoadLibrary16( "krnl386.exe" )) >= 32)
92 /* Initialize special KERNEL entry points */
94 /* Initialize KERNEL.178 (__WINFLAGS) with the correct flags value */
95 NE_SetEntryPoint( hModule, 178, GetWinFlags16() );
97 /* Initialize KERNEL.454/455 (__FLATCS/__FLATDS) */
98 NE_SetEntryPoint( hModule, 454, wine_get_cs() );
99 NE_SetEntryPoint( hModule, 455, wine_get_ds() );
101 /* Initialize KERNEL.THHOOK */
102 TASK_InstallTHHook(MapSL((SEGPTR)GetProcAddress16( hModule, (LPCSTR)332 )));
104 /* Initialize the real-mode selector entry points */
105 #define SET_ENTRY_POINT( num, addr ) \
106 NE_SetEntryPoint( hModule, (num), GLOBAL_CreateBlock( GMEM_FIXED, \
107 DOSMEM_MapDosToLinear(addr), 0x10000, hModule, \
108 WINE_LDT_FLAGS_DATA ))
110 SET_ENTRY_POINT( 174, 0xa0000 ); /* KERNEL.174: __A000H */
111 SET_ENTRY_POINT( 181, 0xb0000 ); /* KERNEL.181: __B000H */
112 SET_ENTRY_POINT( 182, 0xb8000 ); /* KERNEL.182: __B800H */
113 SET_ENTRY_POINT( 195, 0xc0000 ); /* KERNEL.195: __C000H */
114 SET_ENTRY_POINT( 179, 0xd0000 ); /* KERNEL.179: __D000H */
115 SET_ENTRY_POINT( 190, 0xe0000 ); /* KERNEL.190: __E000H */
116 NE_SetEntryPoint( hModule, 183, DOSMEM_0000H ); /* KERNEL.183: __0000H */
117 NE_SetEntryPoint( hModule, 173, DOSMEM_BiosSysSeg ); /* KERNEL.173: __ROMBIOS */
118 NE_SetEntryPoint( hModule, 193, DOSMEM_BiosDataSeg ); /* KERNEL.193: __0040H */
119 NE_SetEntryPoint( hModule, 194, DOSMEM_BiosSysSeg ); /* KERNEL.194: __F000H */
120 #undef SET_ENTRY_POINT
123 /* Force loading of some dlls */
124 LoadLibrary16( "system" );
126 /* Create 16-bit task */
127 TASK_CreateMainTask();
129 /* Create the shared heap for broken win95 native dlls */
130 HeapCreate( HEAP_SHARED, 0, 0 );
132 /* initialize LDT locking */
133 wine_ldt_init_locking( ldt_lock, ldt_unlock );
135 /* finish the process initialisation for console bits, if needed */
136 __wine_set_signal_handler(SIGINT, CONSOLE_HandleCtrlC);
138 if (main_create_flags & CREATE_NEW_CONSOLE)
140 HMODULE mod = GetModuleHandleA(0);
141 if (RtlImageNtHeader(mod)->OptionalHeader.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CUI)
142 AllocConsole();
144 if (main_create_flags & CREATE_NEW_PROCESS_GROUP)
145 SetConsoleCtrlHandler(NULL, TRUE);
147 return TRUE;
150 /***********************************************************************
151 * KERNEL initialisation routine
153 BOOL WINAPI MAIN_KernelInit( HINSTANCE hinst, DWORD reason, LPVOID reserved )
155 switch(reason)
157 case DLL_PROCESS_ATTACH:
158 return process_attach();
159 case DLL_PROCESS_DETACH:
160 WriteOutProfiles16();
161 break;
163 return TRUE;
166 /***********************************************************************
167 * EnableDos (KERNEL.41)
168 * DisableDos (KERNEL.42)
169 * GetLastDiskChange (KERNEL.98)
170 * ValidateCodeSegments (KERNEL.100)
171 * KbdRst (KERNEL.123)
172 * EnableKernel (KERNEL.124)
173 * DisableKernel (KERNEL.125)
174 * ValidateFreeSpaces (KERNEL.200)
175 * K237 (KERNEL.237)
176 * BUNNY_351 (KERNEL.351)
177 * PIGLET_361 (KERNEL.361)
179 * Entry point for kernel functions that do nothing.
181 LONG WINAPI KERNEL_nop(void)
183 return 0;
186 /***********************************************************************
187 * SwitchToThread (KERNEL32.@)
190 BOOL WINAPI SwitchToThread(void)
192 Sleep(0);
193 return 1;