kernel32: Init TimezoneInformation registry.
[wine.git] / dlls / kernel32 / kernel_main.c
blobd3420ece06bbf60b09b32f682ba7fbe9324abcc3
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "config.h"
22 #include "wine/port.h"
24 #include <assert.h>
25 #include <ctype.h>
26 #include <stdarg.h>
27 #include <string.h>
28 #include <signal.h>
30 #include "windef.h"
31 #include "winbase.h"
32 #include "wincon.h"
33 #include "winternl.h"
35 #include "wine/library.h"
36 #include "kernel_private.h"
37 #include "console_private.h"
38 #include "wine/debug.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(process);
42 extern int CDECL __wine_set_signal_handler(unsigned, int (*)(unsigned));
44 /***********************************************************************
45 * set_entry_point
47 static void set_entry_point( HMODULE module, const char *name, DWORD rva )
49 IMAGE_EXPORT_DIRECTORY *exports;
50 DWORD exp_size;
52 if ((exports = RtlImageDirectoryEntryToData( module, TRUE,
53 IMAGE_DIRECTORY_ENTRY_EXPORT, &exp_size )))
55 DWORD *functions = (DWORD *)((char *)module + exports->AddressOfFunctions);
56 const WORD *ordinals = (const WORD *)((const char *)module + exports->AddressOfNameOrdinals);
57 const DWORD *names = (const DWORD *)((const char *)module + exports->AddressOfNames);
58 int min = 0, max = exports->NumberOfNames - 1;
60 while (min <= max)
62 int res, pos = (min + max) / 2;
63 const char *ename = (const char *)module + names[pos];
64 if (!(res = strcmp( ename, name )))
66 WORD ordinal = ordinals[pos];
67 assert( ordinal < exports->NumberOfFunctions );
68 TRACE( "setting %s at %p to %08x\n", name, &functions[ordinal], rva );
69 functions[ordinal] = rva;
70 return;
72 if (res > 0) max = pos - 1;
73 else min = pos + 1;
79 /***********************************************************************
80 * KERNEL process initialisation routine
82 static BOOL process_attach( HMODULE module )
84 RTL_USER_PROCESS_PARAMETERS *params = NtCurrentTeb()->Peb->ProcessParameters;
86 NtQuerySystemInformation( SystemBasicInformation, &system_info, sizeof(system_info), NULL );
88 /* Setup registry locale information */
89 LOCALE_InitRegistry();
91 /* Setup registry timezone information */
92 TIMEZONE_InitRegistry();
94 /* Setup computer name */
95 COMPUTERNAME_Init();
97 CONSOLE_Init(params);
99 /* copy process information from ntdll */
100 ENV_CopyStartupInformation();
102 if (!(GetVersion() & 0x80000000))
104 /* Securom checks for this one when version is NT */
105 set_entry_point( module, "FT_Thunk", 0 );
107 else
109 LDR_MODULE *ldr;
111 if (LdrFindEntryForAddress( GetModuleHandleW( 0 ), &ldr ) || !(ldr->Flags & LDR_WINE_INTERNAL))
112 LoadLibraryA( "krnl386.exe16" );
115 /* finish the process initialisation for console bits, if needed */
116 __wine_set_signal_handler(SIGINT, CONSOLE_HandleCtrlC);
118 if (params->ConsoleHandle == KERNEL32_CONSOLE_ALLOC)
120 HMODULE mod = GetModuleHandleA(0);
121 if (RtlImageNtHeader(mod)->OptionalHeader.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CUI)
122 AllocConsole();
124 /* else TODO for DETACHED_PROCESS:
125 * 1/ inherit console + handles
126 * 2/ create std handles, if handles are not inherited
127 * TBD when not using wineserver handles for console handles
130 return TRUE;
133 /***********************************************************************
134 * KERNEL initialisation routine
136 BOOL WINAPI DllMain( HINSTANCE hinst, DWORD reason, LPVOID reserved )
138 switch(reason)
140 case DLL_PROCESS_ATTACH:
141 DisableThreadLibraryCalls( hinst );
142 return process_attach( hinst );
143 case DLL_PROCESS_DETACH:
144 WritePrivateProfileSectionW( NULL, NULL, NULL );
145 CONSOLE_Exit();
146 break;
148 return TRUE;
151 /***********************************************************************
152 * MulDiv (KERNEL32.@)
153 * RETURNS
154 * Result of multiplication and division
155 * -1: Overflow occurred or Divisor was 0
157 INT WINAPI MulDiv( INT nMultiplicand, INT nMultiplier, INT nDivisor)
159 LONGLONG ret;
161 if (!nDivisor) return -1;
163 /* We want to deal with a positive divisor to simplify the logic. */
164 if (nDivisor < 0)
166 nMultiplicand = - nMultiplicand;
167 nDivisor = -nDivisor;
170 /* If the result is positive, we "add" to round. else, we subtract to round. */
171 if ( ( (nMultiplicand < 0) && (nMultiplier < 0) ) ||
172 ( (nMultiplicand >= 0) && (nMultiplier >= 0) ) )
173 ret = (((LONGLONG)nMultiplicand * nMultiplier) + (nDivisor/2)) / nDivisor;
174 else
175 ret = (((LONGLONG)nMultiplicand * nMultiplier) - (nDivisor/2)) / nDivisor;
177 if ((ret > 2147483647) || (ret < -2147483647)) return -1;
178 return ret;
182 /******************************************************************************
183 * GetTickCount64 (KERNEL32.@)
185 ULONGLONG WINAPI DECLSPEC_HOTPATCH GetTickCount64(void)
187 LARGE_INTEGER counter, frequency;
189 NtQueryPerformanceCounter( &counter, &frequency );
190 return counter.QuadPart * 1000 / frequency.QuadPart;
194 /***********************************************************************
195 * GetTickCount (KERNEL32.@)
197 * Get the number of milliseconds the system has been running.
199 * PARAMS
200 * None.
202 * RETURNS
203 * The current tick count.
205 * NOTES
206 * The value returned will wrap around every 2^32 milliseconds.
208 DWORD WINAPI DECLSPEC_HOTPATCH GetTickCount(void)
210 return GetTickCount64();
213 /******************************************************************************
214 * GetSystemRegistryQuota (KERNEL32.@)
216 BOOL WINAPI GetSystemRegistryQuota(PDWORD pdwQuotaAllowed, PDWORD pdwQuotaUsed)
218 FIXME("(%p, %p) faking reported quota values\n", pdwQuotaAllowed, pdwQuotaUsed);
220 if (pdwQuotaAllowed)
221 *pdwQuotaAllowed = 2 * 1000 * 1000 * 1000; /* 2 GB */
223 if (pdwQuotaUsed)
224 *pdwQuotaUsed = 100 * 1000 * 1000; /* 100 MB */
226 return TRUE;