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
32 #include "kernel_private.h"
33 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(process
);
37 static STARTUPINFOA startup_infoA
;
39 /***********************************************************************
43 static void set_entry_point( HMODULE module
, const char *name
, DWORD rva
)
45 IMAGE_EXPORT_DIRECTORY
*exports
;
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;
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
];
65 TRACE( "setting %s at %p to %08x\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
, NULL
);
71 if (res
> 0) max
= pos
- 1;
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
;
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 startup_infoA
.hStdInput
= rupp
->hStdInput
? rupp
->hStdInput
: INVALID_HANDLE_VALUE
;
112 startup_infoA
.hStdOutput
= rupp
->hStdOutput
? rupp
->hStdOutput
: INVALID_HANDLE_VALUE
;
113 startup_infoA
.hStdError
= rupp
->hStdError
? rupp
->hStdError
: INVALID_HANDLE_VALUE
;
118 /***********************************************************************
119 * KERNEL process initialisation routine
121 static BOOL
process_attach( HMODULE module
)
123 RtlSetUnhandledExceptionFilter( UnhandledExceptionFilter
);
125 NtQuerySystemInformation( SystemBasicInformation
, &system_info
, sizeof(system_info
), NULL
);
130 if (!(GetVersion() & 0x80000000))
132 /* Securom checks for this one when version is NT */
133 set_entry_point( module
, "FT_Thunk", 0 );
137 LDR_DATA_TABLE_ENTRY
*ldr
;
139 if (LdrFindEntryForAddress( GetModuleHandleW( 0 ), &ldr
) || !(ldr
->Flags
& LDR_WINE_INTERNAL
))
140 LoadLibraryA( "krnl386.exe16" );
146 /***********************************************************************
147 * KERNEL initialisation routine
149 BOOL WINAPI
DllMain( HINSTANCE hinst
, DWORD reason
, LPVOID reserved
)
153 case DLL_PROCESS_ATTACH
:
154 DisableThreadLibraryCalls( hinst
);
155 return process_attach( hinst
);
156 case DLL_PROCESS_DETACH
:
157 WritePrivateProfileSectionW( NULL
, NULL
, NULL
);
163 /***********************************************************************
164 * MulDiv (KERNEL32.@)
166 * Result of multiplication and division
167 * -1: Overflow occurred or Divisor was 0
169 INT WINAPI
MulDiv( INT nMultiplicand
, INT nMultiplier
, INT nDivisor
)
173 if (!nDivisor
) return -1;
175 /* We want to deal with a positive divisor to simplify the logic. */
178 nMultiplicand
= - nMultiplicand
;
179 nDivisor
= -nDivisor
;
182 /* If the result is positive, we "add" to round. else, we subtract to round. */
183 if ( ( (nMultiplicand
< 0) && (nMultiplier
< 0) ) ||
184 ( (nMultiplicand
>= 0) && (nMultiplier
>= 0) ) )
185 ret
= (((LONGLONG
)nMultiplicand
* nMultiplier
) + (nDivisor
/2)) / nDivisor
;
187 ret
= (((LONGLONG
)nMultiplicand
* nMultiplier
) - (nDivisor
/2)) / nDivisor
;
189 if ((ret
> 2147483647) || (ret
< -2147483647)) return -1;
193 /******************************************************************************
194 * GetSystemRegistryQuota (KERNEL32.@)
196 BOOL WINAPI
GetSystemRegistryQuota(PDWORD pdwQuotaAllowed
, PDWORD pdwQuotaUsed
)
198 FIXME("(%p, %p) faking reported quota values\n", pdwQuotaAllowed
, pdwQuotaUsed
);
201 *pdwQuotaAllowed
= 2 * 1000 * 1000 * 1000; /* 2 GB */
204 *pdwQuotaUsed
= 100 * 1000 * 1000; /* 100 MB */