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

Alexandre Julliard julliard at winehq.org
Thu Apr 4 13:54:15 CDT 2013


Module: wine
Branch: master
Commit: cd03a51e7ddcafb3cf98b6c1dd5469bb92b8adcd
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=cd03a51e7ddcafb3cf98b6c1dd5469bb92b8adcd

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Thu Apr  4 13:00:47 2013 +0200

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

---

 dlls/ntdll/loader.c     |    4 ++--
 dlls/ntdll/ntdll_misc.h |    3 ++-
 dlls/ntdll/virtual.c    |   30 +++++++++++++++++++++++-------
 3 files changed, 27 insertions(+), 10 deletions(-)

diff --git a/dlls/ntdll/loader.c b/dlls/ntdll/loader.c
index 28ed9f4..271907f 100644
--- a/dlls/ntdll/loader.c
+++ b/dlls/ntdll/loader.c
@@ -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 );
 
diff --git a/dlls/ntdll/ntdll_misc.h b/dlls/ntdll/ntdll_misc.h
index b4f7dbd..146ce50 100644
--- a/dlls/ntdll/ntdll_misc.h
+++ b/dlls/ntdll/ntdll_misc.h
@@ -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 */
diff --git a/dlls/ntdll/virtual.c b/dlls/ntdll/virtual.c
index a99bca4..7a07128 100644
--- a/dlls/ntdll/virtual.c
+++ b/dlls/ntdll/virtual.c
@@ -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
     {
@@ -1846,6 +1845,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.@)
  */




More information about the wine-cvs mailing list