ntdll: Set the address space limit before running application code.

This commit is contained in:
Alexandre Julliard 2013-04-04 13:00:47 +02:00
parent 4e25cd462e
commit cd03a51e7d
3 changed files with 27 additions and 10 deletions

View File

@ -2703,7 +2703,6 @@ void WINAPI LdrInitializeThunk( void *kernel_start, ULONG_PTR unknown2,
WINE_MODREF *wm;
LPCWSTR load_path;
PEB *peb = NtCurrentTeb()->Peb;
IMAGE_NT_HEADERS *nt = RtlImageNtHeader( peb->ImageBaseAddress );
if (main_exe_file) NtClose( main_exe_file ); /* at this point the main module is created */
@ -2721,6 +2720,7 @@ void WINAPI LdrInitializeThunk( void *kernel_start, ULONG_PTR unknown2,
if (!peb->ProcessParameters->WindowTitle.Buffer)
peb->ProcessParameters->WindowTitle = wm->ldr.FullDllName;
version_init( wm->ldr.FullDllName.Buffer );
virtual_set_large_address_space();
LdrQueryImageFileExecutionOptions( &peb->ProcessParameters->ImagePathName, globalflagW,
REG_DWORD, &peb->NtGlobalFlag, sizeof(peb->NtGlobalFlag), NULL );
@ -2742,7 +2742,7 @@ void WINAPI LdrInitializeThunk( void *kernel_start, ULONG_PTR unknown2,
status = wine_call_on_stack( attach_process_dlls, wm, NtCurrentTeb()->Tib.StackBase );
if (status != STATUS_SUCCESS) goto error;
virtual_release_address_space( nt->FileHeader.Characteristics & IMAGE_FILE_LARGE_ADDRESS_AWARE );
virtual_release_address_space();
virtual_clear_thread_stack();
wine_switch_to_stack( start_process, kernel_start, NtCurrentTeb()->Tib.StackBase );

View File

@ -171,7 +171,8 @@ extern NTSTATUS virtual_handle_fault( LPCVOID addr, DWORD err ) DECLSPEC_HIDDEN;
extern BOOL virtual_check_buffer_for_read( const void *ptr, SIZE_T size ) DECLSPEC_HIDDEN;
extern BOOL virtual_check_buffer_for_write( void *ptr, SIZE_T size ) DECLSPEC_HIDDEN;
extern void VIRTUAL_SetForceExec( BOOL enable ) DECLSPEC_HIDDEN;
extern void virtual_release_address_space( BOOL free_high_mem ) DECLSPEC_HIDDEN;
extern void virtual_release_address_space(void) DECLSPEC_HIDDEN;
extern void virtual_set_large_address_space(void) DECLSPEC_HIDDEN;
extern struct _KUSER_SHARED_DATA *user_shared_data DECLSPEC_HIDDEN;
/* completion */

View File

@ -1815,22 +1815,21 @@ static int free_reserved_memory( void *base, size_t size, void *arg )
*
* Release some address space once we have loaded and initialized the app.
*/
void virtual_release_address_space( BOOL free_high_mem )
void virtual_release_address_space(void)
{
struct free_range range;
sigset_t sigset;
if (user_space_limit == address_space_limit) return; /* no need to free anything */
if (is_win64) return;
server_enter_uninterrupted_section( &csVirtual, &sigset );
/* no large address space on win9x */
if (free_high_mem && NtCurrentTeb()->Peb->OSPlatformId == VER_PLATFORM_WIN32_NT)
range.base = (char *)0x82000000;
range.limit = user_space_limit;
if (range.limit > range.base)
{
range.base = (char *)0x82000000;
range.limit = address_space_limit;
while (wine_mmap_enum_reserved_areas( free_reserved_memory, &range, 1 )) /* nothing */;
user_space_limit = working_set_limit = address_space_limit;
}
else
{
@ -1845,6 +1844,23 @@ void virtual_release_address_space( BOOL free_high_mem )
}
/***********************************************************************
* virtual_set_large_address_space
*
* Enable use of a large address space when allowed by the application.
*/
void virtual_set_large_address_space(void)
{
IMAGE_NT_HEADERS *nt = RtlImageNtHeader( NtCurrentTeb()->Peb->ImageBaseAddress );
if (!(nt->FileHeader.Characteristics & IMAGE_FILE_LARGE_ADDRESS_AWARE)) return;
/* no large address space on win9x */
if (NtCurrentTeb()->Peb->OSPlatformId != VER_PLATFORM_WIN32_NT) return;
user_space_limit = working_set_limit = address_space_limit;
}
/***********************************************************************
* NtAllocateVirtualMemory (NTDLL.@)
* ZwAllocateVirtualMemory (NTDLL.@)