windowscodecs: Silence fixme for IID_CMetaBitmapRenderTarget.
[wine.git] / dlls / kernel32 / kernel_main.c
blobae16195a5503dc86067afca6b1993c4fb1f3c7f9
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 <ctype.h>
22 #include <stdarg.h>
23 #include <string.h>
24 #include <signal.h>
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winnls.h"
29 #include "wincon.h"
30 #include "winternl.h"
32 #include "kernel_private.h"
33 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(process);
37 static STARTUPINFOA startup_infoA;
39 /***********************************************************************
40 * set_entry_point
42 #ifdef __i386__
43 static void set_entry_point( HMODULE module, const char *name, DWORD rva )
45 IMAGE_EXPORT_DIRECTORY *exports;
46 DWORD exp_size;
48 if ((exports = RtlImageDirectoryEntryToData( module, TRUE,
49 IMAGE_DIRECTORY_ENTRY_EXPORT, &exp_size )))
51 DWORD *functions = (DWORD *)((char *)module + exports->AddressOfFunctions);
52 const WORD *ordinals = (const WORD *)((const char *)module + exports->AddressOfNameOrdinals);
53 const DWORD *names = (const DWORD *)((const char *)module + exports->AddressOfNames);
54 int min = 0, max = exports->NumberOfNames - 1;
56 while (min <= max)
58 int res, pos = (min + max) / 2;
59 const char *ename = (const char *)module + names[pos];
60 if (!(res = strcmp( ename, name )))
62 WORD ordinal = ordinals[pos];
63 DWORD oldprot;
65 TRACE( "setting %s at %p to %08lx\n", name, &functions[ordinal], rva );
66 VirtualProtect( functions + ordinal, sizeof(*functions), PAGE_READWRITE, &oldprot );
67 functions[ordinal] = rva;
68 VirtualProtect( functions + ordinal, sizeof(*functions), oldprot, &oldprot );
69 return;
71 if (res > 0) max = pos - 1;
72 else min = pos + 1;
76 #endif
79 /***********************************************************************
80 * GetStartupInfoA (KERNEL32.@)
82 VOID WINAPI GetStartupInfoA( LPSTARTUPINFOA info )
84 *info = startup_infoA;
87 static void copy_startup_info(void)
89 RTL_USER_PROCESS_PARAMETERS* rupp;
90 ANSI_STRING ansi;
92 RtlAcquirePebLock();
94 rupp = NtCurrentTeb()->Peb->ProcessParameters;
96 startup_infoA.cb = sizeof(startup_infoA);
97 startup_infoA.lpReserved = NULL;
98 startup_infoA.lpDesktop = !RtlUnicodeStringToAnsiString( &ansi, &rupp->Desktop, TRUE ) ? ansi.Buffer : NULL;
99 startup_infoA.lpTitle = !RtlUnicodeStringToAnsiString( &ansi, &rupp->WindowTitle, TRUE ) ? ansi.Buffer : NULL;
100 startup_infoA.dwX = rupp->dwX;
101 startup_infoA.dwY = rupp->dwY;
102 startup_infoA.dwXSize = rupp->dwXSize;
103 startup_infoA.dwYSize = rupp->dwYSize;
104 startup_infoA.dwXCountChars = rupp->dwXCountChars;
105 startup_infoA.dwYCountChars = rupp->dwYCountChars;
106 startup_infoA.dwFillAttribute = rupp->dwFillAttribute;
107 startup_infoA.dwFlags = rupp->dwFlags;
108 startup_infoA.wShowWindow = rupp->wShowWindow;
109 startup_infoA.cbReserved2 = rupp->RuntimeInfo.MaximumLength;
110 startup_infoA.lpReserved2 = rupp->RuntimeInfo.MaximumLength ? (void*)rupp->RuntimeInfo.Buffer : NULL;
111 if (rupp->dwFlags & STARTF_USESTDHANDLES)
113 startup_infoA.hStdInput = rupp->hStdInput;
114 startup_infoA.hStdOutput = rupp->hStdOutput;
115 startup_infoA.hStdError = rupp->hStdError;
117 else
119 startup_infoA.hStdInput = INVALID_HANDLE_VALUE;
120 startup_infoA.hStdOutput = INVALID_HANDLE_VALUE;
121 startup_infoA.hStdError = INVALID_HANDLE_VALUE;
123 RtlReleasePebLock();
126 /***********************************************************************
127 * KERNEL process initialisation routine
129 static BOOL process_attach( HMODULE module )
131 RtlSetUnhandledExceptionFilter( UnhandledExceptionFilter );
133 NtQuerySystemInformation( SystemBasicInformation, &system_info, sizeof(system_info), NULL );
134 kernelbase_global_data = KernelBaseGetGlobalData();
136 copy_startup_info();
138 #ifdef __i386__
139 if (!(GetVersion() & 0x80000000))
141 /* Securom checks for this one when version is NT */
142 set_entry_point( module, "FT_Thunk", 0 );
144 else
146 LDR_DATA_TABLE_ENTRY *ldr;
148 if (LdrFindEntryForAddress( GetModuleHandleW( 0 ), &ldr ) || !(ldr->Flags & LDR_WINE_INTERNAL))
149 LoadLibraryA( "krnl386.exe16" );
151 #endif
152 return TRUE;
155 /***********************************************************************
156 * KERNEL initialisation routine
158 BOOL WINAPI DllMain( HINSTANCE hinst, DWORD reason, LPVOID reserved )
160 switch(reason)
162 case DLL_PROCESS_ATTACH:
163 DisableThreadLibraryCalls( hinst );
164 return process_attach( hinst );
165 case DLL_PROCESS_DETACH:
166 WritePrivateProfileSectionW( NULL, NULL, NULL );
167 break;
169 return TRUE;
172 /***********************************************************************
173 * MulDiv (KERNEL32.@)
174 * RETURNS
175 * Result of multiplication and division
176 * -1: Overflow occurred or Divisor was 0
178 INT WINAPI MulDiv( INT nMultiplicand, INT nMultiplier, INT nDivisor)
180 LONGLONG ret;
182 if (!nDivisor) return -1;
184 /* We want to deal with a positive divisor to simplify the logic. */
185 if (nDivisor < 0)
187 nMultiplicand = - nMultiplicand;
188 nDivisor = -nDivisor;
191 /* If the result is positive, we "add" to round. else, we subtract to round. */
192 if ( ( (nMultiplicand < 0) && (nMultiplier < 0) ) ||
193 ( (nMultiplicand >= 0) && (nMultiplier >= 0) ) )
194 ret = (((LONGLONG)nMultiplicand * nMultiplier) + (nDivisor/2)) / nDivisor;
195 else
196 ret = (((LONGLONG)nMultiplicand * nMultiplier) - (nDivisor/2)) / nDivisor;
198 if ((ret > 2147483647) || (ret < -2147483647)) return -1;
199 return ret;
202 /******************************************************************************
203 * GetSystemRegistryQuota (KERNEL32.@)
205 BOOL WINAPI GetSystemRegistryQuota(PDWORD pdwQuotaAllowed, PDWORD pdwQuotaUsed)
207 FIXME("(%p, %p) faking reported quota values\n", pdwQuotaAllowed, pdwQuotaUsed);
209 if (pdwQuotaAllowed)
210 *pdwQuotaAllowed = 2 * 1000 * 1000 * 1000; /* 2 GB */
212 if (pdwQuotaUsed)
213 *pdwQuotaUsed = 100 * 1000 * 1000; /* 100 MB */
215 return TRUE;