2000-06-03 06:49:40 +02:00
|
|
|
/*
|
|
|
|
* Kernel initialization code
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* Copyright 2000 Alexandre Julliard
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2000-06-03 06:49:40 +02:00
|
|
|
*/
|
|
|
|
|
2001-07-18 23:04:23 +02:00
|
|
|
#include "config.h"
|
2002-08-29 01:42:34 +02:00
|
|
|
#include "wine/port.h"
|
2001-07-18 23:04:23 +02:00
|
|
|
|
2000-06-03 06:49:40 +02:00
|
|
|
#include <assert.h>
|
2000-10-17 02:27:47 +02:00
|
|
|
#include <ctype.h>
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2001-01-26 21:43:40 +01:00
|
|
|
#include <string.h>
|
2002-03-29 19:17:35 +01:00
|
|
|
#include <sys/stat.h>
|
2002-07-31 20:46:09 +02:00
|
|
|
#include <signal.h>
|
2000-06-03 06:49:40 +02:00
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "windef.h"
|
2000-06-03 06:49:40 +02:00
|
|
|
#include "winbase.h"
|
2002-07-31 21:19:36 +02:00
|
|
|
#include "wincon.h"
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "winreg.h"
|
2002-09-13 00:07:02 +02:00
|
|
|
#include "winternl.h"
|
2000-06-03 06:49:40 +02:00
|
|
|
|
2001-07-18 23:04:23 +02:00
|
|
|
#include "wine/winbase16.h"
|
2002-05-16 22:32:16 +02:00
|
|
|
#include "wine/library.h"
|
2002-03-29 19:17:35 +01:00
|
|
|
#include "file.h"
|
2001-07-18 23:04:23 +02:00
|
|
|
#include "global.h"
|
|
|
|
#include "miscemu.h"
|
2000-06-03 06:49:40 +02:00
|
|
|
#include "module.h"
|
|
|
|
#include "task.h"
|
2003-05-13 02:49:49 +02:00
|
|
|
#include "thread.h"
|
|
|
|
#include "stackframe.h"
|
2002-09-04 20:41:03 +02:00
|
|
|
#include "wincon.h"
|
2003-08-25 02:56:37 +02:00
|
|
|
#include "kernel_private.h"
|
2002-09-04 20:41:03 +02:00
|
|
|
#include "console_private.h"
|
2000-06-03 06:49:40 +02:00
|
|
|
|
2003-10-14 07:32:30 +02:00
|
|
|
extern void LOCALE_InitRegistry(void);
|
2002-11-15 02:01:47 +01:00
|
|
|
extern void COMPUTERNAME_Init(void);
|
2000-07-25 18:42:25 +02:00
|
|
|
|
2002-07-31 20:46:09 +02:00
|
|
|
extern int __wine_set_signal_handler(unsigned, int (*)(unsigned));
|
2003-06-18 05:23:22 +02:00
|
|
|
/* memory/environ.c */
|
|
|
|
extern void ENV_CopyStartupInformation(void);
|
2000-06-03 06:49:40 +02:00
|
|
|
|
2002-07-31 21:19:36 +02:00
|
|
|
extern int main_create_flags;
|
|
|
|
|
2003-08-13 01:50:54 +02:00
|
|
|
static CRITICAL_SECTION ldt_section;
|
|
|
|
static CRITICAL_SECTION_DEBUG critsect_debug =
|
|
|
|
{
|
|
|
|
0, 0, &ldt_section,
|
|
|
|
{ &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
|
|
|
|
0, 0, { 0, (DWORD)(__FILE__ ": ldt_section") }
|
|
|
|
};
|
|
|
|
static CRITICAL_SECTION ldt_section = { &critsect_debug, -1, 0, 0, 0, 0 };
|
2003-02-26 21:34:45 +01:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* locking for LDT routines
|
|
|
|
*/
|
|
|
|
static void ldt_lock(void)
|
|
|
|
{
|
2003-06-23 20:12:28 +02:00
|
|
|
RtlEnterCriticalSection( &ldt_section );
|
2003-02-26 21:34:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void ldt_unlock(void)
|
|
|
|
{
|
2003-06-23 20:12:28 +02:00
|
|
|
RtlLeaveCriticalSection( &ldt_section );
|
2003-02-26 21:34:45 +01:00
|
|
|
}
|
|
|
|
|
2003-05-13 02:49:49 +02:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* KERNEL thread initialisation routine
|
|
|
|
*/
|
|
|
|
static void thread_attach(void)
|
|
|
|
{
|
|
|
|
/* allocate the 16-bit stack (FIXME: should be done lazily) */
|
|
|
|
HGLOBAL16 hstack = K32WOWGlobalAlloc16( GMEM_FIXED, 0x10000 );
|
|
|
|
NtCurrentTeb()->stack_sel = GlobalHandleToSel16( hstack );
|
|
|
|
NtCurrentTeb()->cur_stack = MAKESEGPTR( NtCurrentTeb()->stack_sel,
|
|
|
|
0x10000 - sizeof(STACK16FRAME) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* KERNEL thread finalisation routine
|
|
|
|
*/
|
|
|
|
static void thread_detach(void)
|
|
|
|
{
|
|
|
|
/* free the 16-bit stack */
|
|
|
|
K32WOWGlobalFree16( NtCurrentTeb()->stack_sel );
|
|
|
|
NtCurrentTeb()->cur_stack = 0;
|
2003-08-23 02:03:40 +02:00
|
|
|
if (!(NtCurrentTeb()->tibflags & TEBF_WIN32)) TASK_ExitTask();
|
2003-05-13 02:49:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-06-03 06:49:40 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* KERNEL process initialisation routine
|
|
|
|
*/
|
|
|
|
static BOOL process_attach(void)
|
|
|
|
{
|
|
|
|
HMODULE16 hModule;
|
|
|
|
|
2002-03-29 19:17:35 +01:00
|
|
|
/* Get the umask */
|
|
|
|
FILE_umask = umask(0777);
|
|
|
|
umask( FILE_umask );
|
|
|
|
|
2003-10-14 07:32:30 +02:00
|
|
|
/* Setup registry locale information */
|
|
|
|
LOCALE_InitRegistry();
|
2000-07-12 00:08:43 +02:00
|
|
|
|
2003-08-25 02:56:37 +02:00
|
|
|
/* Initialize 16-bit thunking entry points */
|
|
|
|
if (!WOWTHUNK_Init()) return FALSE;
|
2000-12-12 01:50:19 +01:00
|
|
|
|
2000-06-03 06:49:40 +02:00
|
|
|
/* Initialize DOS memory */
|
|
|
|
if (!DOSMEM_Init(0)) return FALSE;
|
|
|
|
|
2002-11-15 02:01:47 +01:00
|
|
|
/* Setup computer name */
|
|
|
|
COMPUTERNAME_Init();
|
2003-06-18 05:23:22 +02:00
|
|
|
|
|
|
|
/* copy process information from ntdll */
|
|
|
|
ENV_CopyStartupInformation();
|
2002-11-15 02:01:47 +01:00
|
|
|
|
2002-10-02 04:36:20 +02:00
|
|
|
if ((hModule = LoadLibrary16( "krnl386.exe" )) >= 32)
|
|
|
|
{
|
|
|
|
/* Initialize special KERNEL entry points */
|
2000-06-03 06:49:40 +02:00
|
|
|
|
2002-10-02 04:36:20 +02:00
|
|
|
/* Initialize KERNEL.178 (__WINFLAGS) with the correct flags value */
|
|
|
|
NE_SetEntryPoint( hModule, 178, GetWinFlags16() );
|
2000-06-03 06:49:40 +02:00
|
|
|
|
2002-10-02 04:36:20 +02:00
|
|
|
/* Initialize KERNEL.454/455 (__FLATCS/__FLATDS) */
|
|
|
|
NE_SetEntryPoint( hModule, 454, wine_get_cs() );
|
|
|
|
NE_SetEntryPoint( hModule, 455, wine_get_ds() );
|
2000-06-03 06:49:40 +02:00
|
|
|
|
2002-10-02 04:36:20 +02:00
|
|
|
/* Initialize KERNEL.THHOOK */
|
|
|
|
TASK_InstallTHHook(MapSL((SEGPTR)GetProcAddress16( hModule, (LPCSTR)332 )));
|
2000-06-03 06:49:40 +02:00
|
|
|
|
2002-10-02 04:36:20 +02:00
|
|
|
/* Initialize the real-mode selector entry points */
|
2000-06-03 06:49:40 +02:00
|
|
|
#define SET_ENTRY_POINT( num, addr ) \
|
|
|
|
NE_SetEntryPoint( hModule, (num), GLOBAL_CreateBlock( GMEM_FIXED, \
|
|
|
|
DOSMEM_MapDosToLinear(addr), 0x10000, hModule, \
|
2000-11-14 02:54:49 +01:00
|
|
|
WINE_LDT_FLAGS_DATA ))
|
2000-06-03 06:49:40 +02:00
|
|
|
|
2002-10-02 04:36:20 +02:00
|
|
|
SET_ENTRY_POINT( 174, 0xa0000 ); /* KERNEL.174: __A000H */
|
|
|
|
SET_ENTRY_POINT( 181, 0xb0000 ); /* KERNEL.181: __B000H */
|
|
|
|
SET_ENTRY_POINT( 182, 0xb8000 ); /* KERNEL.182: __B800H */
|
|
|
|
SET_ENTRY_POINT( 195, 0xc0000 ); /* KERNEL.195: __C000H */
|
|
|
|
SET_ENTRY_POINT( 179, 0xd0000 ); /* KERNEL.179: __D000H */
|
|
|
|
SET_ENTRY_POINT( 190, 0xe0000 ); /* KERNEL.190: __E000H */
|
|
|
|
NE_SetEntryPoint( hModule, 183, DOSMEM_0000H ); /* KERNEL.183: __0000H */
|
|
|
|
NE_SetEntryPoint( hModule, 173, DOSMEM_BiosSysSeg ); /* KERNEL.173: __ROMBIOS */
|
|
|
|
NE_SetEntryPoint( hModule, 193, DOSMEM_BiosDataSeg ); /* KERNEL.193: __0040H */
|
|
|
|
NE_SetEntryPoint( hModule, 194, DOSMEM_BiosSysSeg ); /* KERNEL.194: __F000H */
|
2000-06-03 06:49:40 +02:00
|
|
|
#undef SET_ENTRY_POINT
|
|
|
|
|
2003-08-19 05:27:45 +02:00
|
|
|
/* Force loading of some dlls */
|
|
|
|
LoadLibrary16( "system.drv" );
|
|
|
|
}
|
2000-06-03 06:49:40 +02:00
|
|
|
|
2001-03-04 02:06:07 +01:00
|
|
|
/* Create the shared heap for broken win95 native dlls */
|
|
|
|
HeapCreate( HEAP_SHARED, 0, 0 );
|
|
|
|
|
2003-02-26 21:34:45 +01:00
|
|
|
/* initialize LDT locking */
|
|
|
|
wine_ldt_init_locking( ldt_lock, ldt_unlock );
|
|
|
|
|
2002-09-04 20:41:03 +02:00
|
|
|
/* finish the process initialisation for console bits, if needed */
|
2002-07-31 20:46:09 +02:00
|
|
|
__wine_set_signal_handler(SIGINT, CONSOLE_HandleCtrlC);
|
|
|
|
|
2002-07-31 21:19:36 +02:00
|
|
|
if (main_create_flags & CREATE_NEW_CONSOLE)
|
|
|
|
{
|
|
|
|
HMODULE mod = GetModuleHandleA(0);
|
|
|
|
if (RtlImageNtHeader(mod)->OptionalHeader.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CUI)
|
|
|
|
AllocConsole();
|
|
|
|
}
|
2003-06-18 05:23:22 +02:00
|
|
|
else if (!(main_create_flags & DETACHED_PROCESS))
|
|
|
|
{
|
|
|
|
/* 1/ shall inherit console + handles
|
|
|
|
* 2/ shall create std handles, if handles are not inherited
|
|
|
|
* TBD when not using wineserver handles for console handles
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
2002-09-04 20:41:03 +02:00
|
|
|
if (main_create_flags & CREATE_NEW_PROCESS_GROUP)
|
|
|
|
SetConsoleCtrlHandler(NULL, TRUE);
|
2002-07-31 21:19:36 +02:00
|
|
|
|
2003-09-18 06:28:22 +02:00
|
|
|
/* Create 16-bit task */
|
2003-05-13 02:49:49 +02:00
|
|
|
thread_attach();
|
2003-09-18 06:28:22 +02:00
|
|
|
TASK_CreateMainTask();
|
2000-06-03 06:49:40 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* KERNEL initialisation routine
|
|
|
|
*/
|
2003-10-10 02:50:56 +02:00
|
|
|
BOOL WINAPI DllMain( HINSTANCE hinst, DWORD reason, LPVOID reserved )
|
2000-06-03 06:49:40 +02:00
|
|
|
{
|
|
|
|
switch(reason)
|
|
|
|
{
|
|
|
|
case DLL_PROCESS_ATTACH:
|
2000-08-21 05:33:31 +02:00
|
|
|
return process_attach();
|
2003-05-13 02:49:49 +02:00
|
|
|
case DLL_THREAD_ATTACH:
|
|
|
|
thread_attach();
|
|
|
|
break;
|
|
|
|
case DLL_THREAD_DETACH:
|
|
|
|
thread_detach();
|
|
|
|
break;
|
2000-06-03 06:49:40 +02:00
|
|
|
case DLL_PROCESS_DETACH:
|
2000-08-21 05:33:31 +02:00
|
|
|
WriteOutProfiles16();
|
2000-06-03 06:49:40 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
2000-08-06 04:42:46 +02:00
|
|
|
|
|
|
|
/***********************************************************************
|
2001-07-02 21:59:40 +02:00
|
|
|
* EnableDos (KERNEL.41)
|
|
|
|
* DisableDos (KERNEL.42)
|
|
|
|
* GetLastDiskChange (KERNEL.98)
|
|
|
|
* ValidateCodeSegments (KERNEL.100)
|
|
|
|
* KbdRst (KERNEL.123)
|
|
|
|
* EnableKernel (KERNEL.124)
|
|
|
|
* DisableKernel (KERNEL.125)
|
|
|
|
* ValidateFreeSpaces (KERNEL.200)
|
|
|
|
* K237 (KERNEL.237)
|
|
|
|
* BUNNY_351 (KERNEL.351)
|
|
|
|
* PIGLET_361 (KERNEL.361)
|
2000-08-06 04:42:46 +02:00
|
|
|
*
|
|
|
|
* Entry point for kernel functions that do nothing.
|
|
|
|
*/
|
2001-05-24 21:32:00 +02:00
|
|
|
LONG WINAPI KERNEL_nop(void)
|
2001-01-02 21:00:37 +01:00
|
|
|
{
|
2001-05-24 21:32:00 +02:00
|
|
|
return 0;
|
2001-01-02 21:00:37 +01:00
|
|
|
}
|
2002-08-16 03:38:20 +02:00
|
|
|
|
2002-08-17 02:21:53 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* SwitchToThread (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
|
|
|
|
BOOL WINAPI SwitchToThread(void)
|
2002-08-16 03:38:20 +02:00
|
|
|
{
|
|
|
|
Sleep(0);
|
|
|
|
return 1;
|
|
|
|
}
|