Fixed atom test to work on Windows.
[wine] / dlls / kernel / kernel_main.c
1 /*
2  * Kernel initialization code
3  *
4  * Copyright 2000 Alexandre Julliard
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include "config.h"
22 #include "wine/port.h"
23
24 #include <assert.h>
25 #include <ctype.h>
26 #include <string.h>
27 #include <sys/stat.h>
28 #include <signal.h>
29
30 #include "winbase.h"
31 #include "wincon.h"
32 #include "winternl.h"
33
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"
43
44 extern void LOCALE_Init(void);
45 extern BOOL RELAY_Init(void);
46
47 extern  int __wine_set_signal_handler(unsigned, int (*)(unsigned));
48
49 extern int main_create_flags;
50
51 /***********************************************************************
52  *           KERNEL process initialisation routine
53  */
54 static BOOL process_attach(void)
55 {
56     HMODULE16 hModule;
57
58     /* Get the umask */
59     FILE_umask = umask(0777);
60     umask( FILE_umask );
61
62     /* Setup codepage info */
63     LOCALE_Init();
64
65     /* Initialize relay entry points */
66     if (!RELAY_Init()) return FALSE;
67
68     /* Initialize DOS memory */
69     if (!DOSMEM_Init(0)) return FALSE;
70
71     if ((hModule = LoadLibrary16( "krnl386.exe" )) >= 32)
72     {
73         /* Initialize special KERNEL entry points */
74
75         /* Initialize KERNEL.178 (__WINFLAGS) with the correct flags value */
76         NE_SetEntryPoint( hModule, 178, GetWinFlags16() );
77
78         /* Initialize KERNEL.454/455 (__FLATCS/__FLATDS) */
79         NE_SetEntryPoint( hModule, 454, wine_get_cs() );
80         NE_SetEntryPoint( hModule, 455, wine_get_ds() );
81
82         /* Initialize KERNEL.THHOOK */
83         TASK_InstallTHHook(MapSL((SEGPTR)GetProcAddress16( hModule, (LPCSTR)332 )));
84
85         /* Initialize the real-mode selector entry points */
86 #define SET_ENTRY_POINT( num, addr ) \
87     NE_SetEntryPoint( hModule, (num), GLOBAL_CreateBlock( GMEM_FIXED, \
88                       DOSMEM_MapDosToLinear(addr), 0x10000, hModule, \
89                       WINE_LDT_FLAGS_DATA ))
90
91         SET_ENTRY_POINT( 174, 0xa0000 );  /* KERNEL.174: __A000H */
92         SET_ENTRY_POINT( 181, 0xb0000 );  /* KERNEL.181: __B000H */
93         SET_ENTRY_POINT( 182, 0xb8000 );  /* KERNEL.182: __B800H */
94         SET_ENTRY_POINT( 195, 0xc0000 );  /* KERNEL.195: __C000H */
95         SET_ENTRY_POINT( 179, 0xd0000 );  /* KERNEL.179: __D000H */
96         SET_ENTRY_POINT( 190, 0xe0000 );  /* KERNEL.190: __E000H */
97         NE_SetEntryPoint( hModule, 183, DOSMEM_0000H );       /* KERNEL.183: __0000H */
98         NE_SetEntryPoint( hModule, 173, DOSMEM_BiosSysSeg );  /* KERNEL.173: __ROMBIOS */
99         NE_SetEntryPoint( hModule, 193, DOSMEM_BiosDataSeg ); /* KERNEL.193: __0040H */
100         NE_SetEntryPoint( hModule, 194, DOSMEM_BiosSysSeg );  /* KERNEL.194: __F000H */
101 #undef SET_ENTRY_POINT
102     }
103
104     /* Force loading of some dlls */
105     LoadLibrary16( "system" );
106
107     /* Create 16-bit task */
108     TASK_CreateMainTask();
109
110     /* Create the shared heap for broken win95 native dlls */
111     HeapCreate( HEAP_SHARED, 0, 0 );
112
113     /* finish the process initialisation for console bits, if needed */
114     __wine_set_signal_handler(SIGINT, CONSOLE_HandleCtrlC);
115
116     if (main_create_flags & CREATE_NEW_CONSOLE)
117     {
118         HMODULE mod = GetModuleHandleA(0);
119         if (RtlImageNtHeader(mod)->OptionalHeader.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CUI)
120             AllocConsole();
121     }
122     if (main_create_flags & CREATE_NEW_PROCESS_GROUP)
123         SetConsoleCtrlHandler(NULL, TRUE);
124
125     return TRUE;
126 }
127
128 /***********************************************************************
129  *           KERNEL initialisation routine
130  */
131 BOOL WINAPI MAIN_KernelInit( HINSTANCE hinst, DWORD reason, LPVOID reserved )
132 {
133     switch(reason)
134     {
135     case DLL_PROCESS_ATTACH:
136         return process_attach();
137     case DLL_PROCESS_DETACH:
138         WriteOutProfiles16();
139         break;
140     }
141     return TRUE;
142 }
143
144 /***********************************************************************
145  *              EnableDos (KERNEL.41)
146  *              DisableDos (KERNEL.42)
147  *              GetLastDiskChange (KERNEL.98)
148  *              ValidateCodeSegments (KERNEL.100)
149  *              KbdRst (KERNEL.123)
150  *              EnableKernel (KERNEL.124)
151  *              DisableKernel (KERNEL.125)
152  *              ValidateFreeSpaces (KERNEL.200)
153  *              K237 (KERNEL.237)
154  *              BUNNY_351 (KERNEL.351)
155  *              PIGLET_361 (KERNEL.361)
156  *
157  * Entry point for kernel functions that do nothing.
158  */
159 LONG WINAPI KERNEL_nop(void)
160 {
161     return 0;
162 }
163
164 /***********************************************************************
165  *              SwitchToThread (KERNEL32.@)
166  */
167
168 BOOL WINAPI SwitchToThread(void)
169 {
170     Sleep(0);
171     return 1;
172 }