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
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, 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-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"
|
2002-09-13 00:07:02 +02:00
|
|
|
#include "winternl.h"
|
2005-08-10 12:59:19 +02:00
|
|
|
#include "wownt32.h"
|
2000-06-03 06:49:40 +02:00
|
|
|
|
2002-05-16 22:32:16 +02:00
|
|
|
#include "wine/library.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"
|
2007-05-07 17:10:18 +02:00
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(process);
|
2000-06-03 06:49:40 +02:00
|
|
|
|
2008-12-16 16:37:46 +01:00
|
|
|
extern int CDECL __wine_set_signal_handler(unsigned, int (*)(unsigned));
|
2000-06-03 06:49:40 +02:00
|
|
|
|
2007-07-11 14:04:54 +02:00
|
|
|
static ULONGLONG server_start_time;
|
|
|
|
|
2007-05-07 17:10:18 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* set_entry_point
|
|
|
|
*/
|
|
|
|
static void set_entry_point( HMODULE module, const char *name, DWORD rva )
|
|
|
|
{
|
|
|
|
IMAGE_EXPORT_DIRECTORY *exports;
|
|
|
|
DWORD exp_size;
|
|
|
|
|
|
|
|
if ((exports = RtlImageDirectoryEntryToData( module, TRUE,
|
|
|
|
IMAGE_DIRECTORY_ENTRY_EXPORT, &exp_size )))
|
|
|
|
{
|
|
|
|
DWORD *functions = (DWORD *)((char *)module + exports->AddressOfFunctions);
|
|
|
|
const WORD *ordinals = (const WORD *)((const char *)module + exports->AddressOfNameOrdinals);
|
|
|
|
const DWORD *names = (const DWORD *)((const char *)module + exports->AddressOfNames);
|
|
|
|
int min = 0, max = exports->NumberOfNames - 1;
|
|
|
|
|
|
|
|
while (min <= max)
|
|
|
|
{
|
|
|
|
int res, pos = (min + max) / 2;
|
|
|
|
const char *ename = (const char *)module + names[pos];
|
|
|
|
if (!(res = strcmp( ename, name )))
|
|
|
|
{
|
|
|
|
WORD ordinal = ordinals[pos];
|
|
|
|
assert( ordinal < exports->NumberOfFunctions );
|
|
|
|
TRACE( "setting %s at %p to %08x\n", name, &functions[ordinal], rva );
|
|
|
|
functions[ordinal] = rva;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (res > 0) max = pos - 1;
|
|
|
|
else min = pos + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-06-03 06:49:40 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* KERNEL process initialisation routine
|
|
|
|
*/
|
2007-05-07 17:10:18 +02:00
|
|
|
static BOOL process_attach( HMODULE module )
|
2000-06-03 06:49:40 +02:00
|
|
|
{
|
2007-07-11 14:04:54 +02:00
|
|
|
SYSTEM_TIMEOFDAY_INFORMATION ti;
|
2006-07-13 14:04:40 +02:00
|
|
|
RTL_USER_PROCESS_PARAMETERS *params = NtCurrentTeb()->Peb->ProcessParameters;
|
2004-06-15 02:52:03 +02:00
|
|
|
|
2007-07-11 14:04:54 +02:00
|
|
|
NtQuerySystemInformation( SystemTimeOfDayInformation, &ti, sizeof(ti), NULL );
|
|
|
|
server_start_time = ti.liKeBootTime.QuadPart;
|
|
|
|
|
2003-10-14 07:32:30 +02:00
|
|
|
/* Setup registry locale information */
|
|
|
|
LOCALE_InitRegistry();
|
2000-07-12 00:08:43 +02:00
|
|
|
|
2002-11-15 02:01:47 +01:00
|
|
|
/* Setup computer name */
|
|
|
|
COMPUTERNAME_Init();
|
2004-03-20 03:28:51 +01:00
|
|
|
|
2010-08-30 22:19:18 +02:00
|
|
|
CONSOLE_Init(params);
|
2006-07-13 14:04:40 +02:00
|
|
|
|
2003-06-18 05:23:22 +02:00
|
|
|
/* copy process information from ntdll */
|
|
|
|
ENV_CopyStartupInformation();
|
2002-11-15 02:01:47 +01:00
|
|
|
|
2007-05-07 17:10:18 +02:00
|
|
|
if (!(GetVersion() & 0x80000000))
|
|
|
|
{
|
|
|
|
/* Securom checks for this one when version is NT */
|
|
|
|
set_entry_point( module, "FT_Thunk", 0 );
|
|
|
|
}
|
2010-03-01 11:34:34 +01:00
|
|
|
else LoadLibraryA( "krnl386.exe16" );
|
2001-03-04 02:06:07 +01:00
|
|
|
|
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);
|
|
|
|
|
2010-08-30 22:19:18 +02:00
|
|
|
if (params->ConsoleHandle == KERNEL32_CONSOLE_ALLOC)
|
2002-07-31 21:19:36 +02:00
|
|
|
{
|
|
|
|
HMODULE mod = GetModuleHandleA(0);
|
|
|
|
if (RtlImageNtHeader(mod)->OptionalHeader.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CUI)
|
|
|
|
AllocConsole();
|
|
|
|
}
|
2006-02-05 12:24:43 +01:00
|
|
|
/* else TODO for DETACHED_PROCESS:
|
|
|
|
* 1/ inherit console + handles
|
|
|
|
* 2/ create std handles, if handles are not inherited
|
|
|
|
* TBD when not using wineserver handles for console handles
|
|
|
|
*/
|
2003-06-18 05:23:22 +02:00
|
|
|
|
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:
|
2009-12-29 16:24:00 +01:00
|
|
|
DisableThreadLibraryCalls( hinst );
|
2007-05-07 17:10:18 +02:00
|
|
|
return process_attach( hinst );
|
2000-06-03 06:49:40 +02:00
|
|
|
case DLL_PROCESS_DETACH:
|
2009-10-08 19:11:58 +02:00
|
|
|
WritePrivateProfileSectionW( NULL, NULL, NULL );
|
2010-09-10 21:50:19 +02:00
|
|
|
CONSOLE_Exit();
|
2000-06-03 06:49:40 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
2000-08-06 04:42:46 +02:00
|
|
|
|
2004-04-28 05:53:19 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* MulDiv (KERNEL32.@)
|
|
|
|
* RETURNS
|
|
|
|
* Result of multiplication and division
|
|
|
|
* -1: Overflow occurred or Divisor was 0
|
|
|
|
*/
|
|
|
|
INT WINAPI MulDiv( INT nMultiplicand, INT nMultiplier, INT nDivisor)
|
|
|
|
{
|
|
|
|
LONGLONG ret;
|
|
|
|
|
|
|
|
if (!nDivisor) return -1;
|
|
|
|
|
|
|
|
/* We want to deal with a positive divisor to simplify the logic. */
|
|
|
|
if (nDivisor < 0)
|
|
|
|
{
|
|
|
|
nMultiplicand = - nMultiplicand;
|
|
|
|
nDivisor = -nDivisor;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If the result is positive, we "add" to round. else, we subtract to round. */
|
|
|
|
if ( ( (nMultiplicand < 0) && (nMultiplier < 0) ) ||
|
|
|
|
( (nMultiplicand >= 0) && (nMultiplier >= 0) ) )
|
|
|
|
ret = (((LONGLONG)nMultiplicand * nMultiplier) + (nDivisor/2)) / nDivisor;
|
|
|
|
else
|
|
|
|
ret = (((LONGLONG)nMultiplicand * nMultiplier) - (nDivisor/2)) / nDivisor;
|
|
|
|
|
|
|
|
if ((ret > 2147483647) || (ret < -2147483647)) return -1;
|
|
|
|
return ret;
|
|
|
|
}
|
2005-07-14 12:32:46 +02:00
|
|
|
|
|
|
|
|
2007-07-11 14:04:54 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* GetTickCount64 (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
ULONGLONG WINAPI GetTickCount64(void)
|
|
|
|
{
|
|
|
|
LARGE_INTEGER now;
|
|
|
|
|
|
|
|
NtQuerySystemTime( &now );
|
|
|
|
return (now.QuadPart - server_start_time) / 10000;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-07-14 12:32:46 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* GetTickCount (KERNEL32.@)
|
|
|
|
*
|
|
|
|
* Get the number of milliseconds the system has been running.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* None.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* The current tick count.
|
|
|
|
*
|
|
|
|
* NOTES
|
2008-03-17 21:51:39 +01:00
|
|
|
* The value returned will wrap around every 2^32 milliseconds.
|
|
|
|
* Under Windows, tick 0 is the moment at which the system is rebooted.
|
|
|
|
* Under Wine, tick 0 begins at the moment the wineserver process is started.
|
2005-07-14 12:32:46 +02:00
|
|
|
*/
|
|
|
|
DWORD WINAPI GetTickCount(void)
|
|
|
|
{
|
2007-07-11 14:04:54 +02:00
|
|
|
return GetTickCount64();
|
2005-07-14 12:32:46 +02:00
|
|
|
}
|
2010-10-11 12:16:16 +02:00
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* GetSystemRegistryQuota (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI GetSystemRegistryQuota(PDWORD pdwQuotaAllowed, PDWORD pdwQuotaUsed)
|
|
|
|
{
|
|
|
|
FIXME("(%p, %p) faking reported quota values\n", pdwQuotaAllowed, pdwQuotaUsed);
|
|
|
|
|
|
|
|
if (pdwQuotaAllowed)
|
|
|
|
*pdwQuotaAllowed = 2 * 1000 * 1000 * 1000; /* 2 GB */
|
|
|
|
|
|
|
|
if (pdwQuotaUsed)
|
|
|
|
*pdwQuotaUsed = 100 * 1000 * 1000; /* 100 MB */
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|