diff --git a/patches/ntdll-ForceBottomUpAlloc/0001-ntdll-Increase-step-after-failed-map-attempt-in-try_.patch b/patches/ntdll-ForceBottomUpAlloc/0001-ntdll-Increase-step-after-failed-map-attempt-in-try_.patch index 1d03a31e..be8b2fdb 100644 --- a/patches/ntdll-ForceBottomUpAlloc/0001-ntdll-Increase-step-after-failed-map-attempt-in-try_.patch +++ b/patches/ntdll-ForceBottomUpAlloc/0001-ntdll-Increase-step-after-failed-map-attempt-in-try_.patch @@ -1,4 +1,4 @@ -From 5814a4b9c7d4dec027b0c2dd29822664aa56ada1 Mon Sep 17 00:00:00 2001 +From 5a81a28605ec0b32b020c84032e3f4a35d0e4768 Mon Sep 17 00:00:00 2001 From: Paul Gofman Date: Tue, 14 Jan 2020 21:39:23 +0300 Subject: [PATCH] ntdll: Increase step after failed map attempt in @@ -9,10 +9,10 @@ Subject: [PATCH] ntdll: Increase step after failed map attempt in 1 file changed, 1 insertion(+) diff --git a/dlls/ntdll/unix/virtual.c b/dlls/ntdll/unix/virtual.c -index 84a4e331ad7..a63882023e6 100644 +index 2e61e8ba22f..039007f6a9b 100644 --- a/dlls/ntdll/unix/virtual.c +++ b/dlls/ntdll/unix/virtual.c -@@ -1327,6 +1327,7 @@ static void* try_map_free_area( void *base, void *end, ptrdiff_t step, +@@ -1336,6 +1336,7 @@ static void* try_map_free_area( void *base, void *end, ptrdiff_t step, step == 0) break; start = (char *)start + step; @@ -21,5 +21,5 @@ index 84a4e331ad7..a63882023e6 100644 return NULL; -- -2.38.1 +2.40.1 diff --git a/patches/ntdll-ForceBottomUpAlloc/0002-ntdll-Increase-free-ranges-view-block-size-on-64-bit.patch b/patches/ntdll-ForceBottomUpAlloc/0002-ntdll-Increase-free-ranges-view-block-size-on-64-bit.patch index da2bdc2c..93d177ca 100644 --- a/patches/ntdll-ForceBottomUpAlloc/0002-ntdll-Increase-free-ranges-view-block-size-on-64-bit.patch +++ b/patches/ntdll-ForceBottomUpAlloc/0002-ntdll-Increase-free-ranges-view-block-size-on-64-bit.patch @@ -1,4 +1,4 @@ -From b1e6d32e7dc3bac93419f3a573f509ee6e1177b2 Mon Sep 17 00:00:00 2001 +From b7c39298824976bbbc8788b60aa4195f3815d3b9 Mon Sep 17 00:00:00 2001 From: Paul Gofman Date: Thu, 23 Jul 2020 18:40:39 +0300 Subject: [PATCH] ntdll: Increase free ranges view block size on 64 bit. @@ -8,10 +8,10 @@ Subject: [PATCH] ntdll: Increase free ranges view block size on 64 bit. 1 file changed, 4 insertions(+) diff --git a/dlls/ntdll/unix/virtual.c b/dlls/ntdll/unix/virtual.c -index a63882023e6..83909f57d4a 100644 +index 039007f6a9b..82a0a91cf14 100644 --- a/dlls/ntdll/unix/virtual.c +++ b/dlls/ntdll/unix/virtual.c -@@ -205,7 +205,11 @@ static BYTE *pages_vprot; +@@ -212,7 +212,11 @@ static BYTE *pages_vprot; #endif static struct file_view *view_block_start, *view_block_end, *next_free_view; @@ -24,5 +24,5 @@ index a63882023e6..83909f57d4a 100644 static void *preload_reserve_end; static BOOL force_exec_prot; /* whether to force PROT_EXEC on all PROT_READ mmaps */ -- -2.38.1 +2.40.1 diff --git a/patches/ntdll-ForceBottomUpAlloc/0003-ntdll-Force-virtual-memory-allocation-order.patch b/patches/ntdll-ForceBottomUpAlloc/0003-ntdll-Force-virtual-memory-allocation-order.patch index dcfa9088..69eb2b3d 100644 --- a/patches/ntdll-ForceBottomUpAlloc/0003-ntdll-Force-virtual-memory-allocation-order.patch +++ b/patches/ntdll-ForceBottomUpAlloc/0003-ntdll-Force-virtual-memory-allocation-order.patch @@ -1,4 +1,4 @@ -From c3252fd68ecdcc0186b4d284df1b36ea11ca7d7f Mon Sep 17 00:00:00 2001 +From 76467d83722de864a4fa856a3c294c999468954e Mon Sep 17 00:00:00 2001 From: Paul Gofman Date: Mon, 25 Nov 2019 12:19:20 +0300 Subject: [PATCH] ntdll: Force virtual memory allocation order. @@ -16,10 +16,10 @@ Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=46568 1 file changed, 227 insertions(+), 223 deletions(-) diff --git a/dlls/ntdll/unix/virtual.c b/dlls/ntdll/unix/virtual.c -index 83909f57d4a..4bce8f2f806 100644 +index 82a0a91cf14..b189ded181b 100644 --- a/dlls/ntdll/unix/virtual.c +++ b/dlls/ntdll/unix/virtual.c -@@ -1266,44 +1266,15 @@ static struct file_view *find_view_range( const void *addr, size_t size ) +@@ -1275,44 +1275,15 @@ static struct file_view *find_view_range( const void *addr, size_t size ) return NULL; } @@ -72,7 +72,7 @@ index 83909f57d4a..4bce8f2f806 100644 /*********************************************************************** * try_map_free_area -@@ -1337,110 +1308,6 @@ static void* try_map_free_area( void *base, void *end, ptrdiff_t step, +@@ -1346,110 +1317,6 @@ static void* try_map_free_area( void *base, void *end, ptrdiff_t step, return NULL; } @@ -183,7 +183,7 @@ index 83909f57d4a..4bce8f2f806 100644 /*********************************************************************** * add_reserved_area * -@@ -1608,8 +1475,7 @@ static void free_view( struct file_view *view ) +@@ -1617,8 +1484,7 @@ static void free_view( struct file_view *view ) */ static void unregister_view( struct file_view *view ) { @@ -193,7 +193,7 @@ index 83909f57d4a..4bce8f2f806 100644 wine_rb_remove( &views_tree, &view->entry ); } -@@ -1636,8 +1502,7 @@ static void delete_view( struct file_view *view ) /* [in] View */ +@@ -1646,8 +1512,7 @@ static void delete_view( struct file_view *view ) /* [in] View */ static void register_view( struct file_view *view ) { wine_rb_put( &views_tree, view->base, &view->entry ); @@ -203,7 +203,7 @@ index 83909f57d4a..4bce8f2f806 100644 } -@@ -1906,55 +1771,229 @@ static inline void *unmap_extra_space( void *ptr, size_t total_size, size_t want +@@ -1916,55 +1781,229 @@ static inline void *unmap_extra_space( void *ptr, size_t total_size, size_t want return ptr; } @@ -241,7 +241,10 @@ index 83909f57d4a..4bce8f2f806 100644 + + if (area->map_area_end <= (char *)start) + return 0; -+ + +- if (start < address_space_start) start = address_space_start; +- if (is_beyond_limit( start, size, alloc->limit )) end = alloc->limit; +- if (start >= end) return 0; + if ((ULONG_PTR)area->map_area_end < area->size) + return 1; + @@ -255,10 +258,7 @@ index 83909f57d4a..4bce8f2f806 100644 + alloc_start, area->size, area->unix_prot ))) + return 1; + } - -- if (start < address_space_start) start = address_space_start; -- if (is_beyond_limit( start, size, alloc->limit )) end = alloc->limit; -- if (start >= end) return 0; ++ + if (intersect_end - intersect_start >= area->size) + { + alloc_start = ROUND_ADDR( intersect_end - area->size, align_mask ); @@ -467,7 +467,7 @@ index 83909f57d4a..4bce8f2f806 100644 /*********************************************************************** * map_fixed_area * -@@ -2019,6 +2058,8 @@ static NTSTATUS map_view( struct file_view **view_ret, void *base, size_t size, +@@ -2029,6 +2068,8 @@ static NTSTATUS map_view( struct file_view **view_ret, void *base, size_t size, void *ptr; NTSTATUS status; @@ -475,9 +475,9 @@ index 83909f57d4a..4bce8f2f806 100644 + if (alloc_type & MEM_REPLACE_PLACEHOLDER) { - if ((*view_ret = find_view( base, 0 ))) -@@ -2044,6 +2085,8 @@ static NTSTATUS map_view( struct file_view **view_ret, void *base, size_t size, - return STATUS_INVALID_PARAMETER; + if (!(*view_ret = find_view( base, 0 ))) +@@ -2059,6 +2100,8 @@ static NTSTATUS map_view( struct file_view **view_ret, void *base, size_t size, + return STATUS_SUCCESS; } + if (!align_mask) align_mask = granularity_mask; @@ -485,7 +485,7 @@ index 83909f57d4a..4bce8f2f806 100644 if (base) { if (is_beyond_limit( base, size, address_space_limit )) -@@ -2052,52 +2095,10 @@ static NTSTATUS map_view( struct file_view **view_ret, void *base, size_t size, +@@ -2069,52 +2112,10 @@ static NTSTATUS map_view( struct file_view **view_ret, void *base, size_t size, if (status != STATUS_SUCCESS) return status; ptr = base; } @@ -540,7 +540,7 @@ index 83909f57d4a..4bce8f2f806 100644 status = create_view( view_ret, ptr, size, vprot ); if (status != STATUS_SUCCESS) unmap_area( ptr, size ); return status; -@@ -2758,6 +2759,7 @@ static NTSTATUS virtual_map_section( HANDLE handle, PVOID *addr_ptr, ULONG_PTR z +@@ -3044,6 +3045,7 @@ static unsigned int virtual_map_section( HANDLE handle, PVOID *addr_ptr, ULONG_P done: server_leave_uninterrupted_section( &virtual_mutex, &sigset ); if (needs_close) close( unix_handle ); @@ -548,7 +548,7 @@ index 83909f57d4a..4bce8f2f806 100644 return res; } -@@ -2826,6 +2828,7 @@ void virtual_init(void) +@@ -3112,6 +3114,7 @@ void virtual_init(void) if (preload_reserve_start) address_space_start = min( address_space_start, preload_reserve_start ); } @@ -556,7 +556,7 @@ index 83909f57d4a..4bce8f2f806 100644 } /* try to find space in a reserved area for the views and pages protection table */ -@@ -5579,6 +5582,7 @@ NTSTATUS WINAPI NtWow64AllocateVirtualMemory64( HANDLE process, ULONG64 *ret, UL +@@ -5796,6 +5799,7 @@ NTSTATUS WINAPI NtWow64AllocateVirtualMemory64( HANDLE process, ULONG64 *ret, UL *ret = (ULONG_PTR)base; *size_ptr = size; } @@ -565,5 +565,5 @@ index 83909f57d4a..4bce8f2f806 100644 } -- -2.38.1 +2.40.1 diff --git a/patches/ntdll-ForceBottomUpAlloc/0004-ntdll-Exclude-natively-mapped-areas-from-free-areas-.patch b/patches/ntdll-ForceBottomUpAlloc/0004-ntdll-Exclude-natively-mapped-areas-from-free-areas-.patch index 99b32e67..4fecff0d 100644 --- a/patches/ntdll-ForceBottomUpAlloc/0004-ntdll-Exclude-natively-mapped-areas-from-free-areas-.patch +++ b/patches/ntdll-ForceBottomUpAlloc/0004-ntdll-Exclude-natively-mapped-areas-from-free-areas-.patch @@ -1,25 +1,35 @@ -From d29a79d8cca2220c838fbbea6ea81b9f73070ba5 Mon Sep 17 00:00:00 2001 +From bd1c2ee8168bc923e3040af04ea3bebc8c021ea5 Mon Sep 17 00:00:00 2001 From: Paul Gofman Date: Tue, 2 Jun 2020 21:06:33 +0300 Subject: [PATCH] ntdll: Exclude natively mapped areas from free areas list. --- - dlls/ntdll/unix/virtual.c | 118 ++++++++++++++++++++++++++++++++------ - 1 file changed, 100 insertions(+), 18 deletions(-) + dlls/ntdll/unix/virtual.c | 126 ++++++++++++++++++++++++++++++++------ + 1 file changed, 107 insertions(+), 19 deletions(-) diff --git a/dlls/ntdll/unix/virtual.c b/dlls/ntdll/unix/virtual.c -index 4bce8f2f806..3c1bf6edc30 100644 +index b189ded181b..00569e5e24c 100644 --- a/dlls/ntdll/unix/virtual.c +++ b/dlls/ntdll/unix/virtual.c -@@ -125,6 +125,7 @@ struct file_view +@@ -130,6 +130,7 @@ C_ASSERT( offsetof( struct file_view, entry ) == 0 ); #define VPROT_SYSTEM 0x0200 /* system view (underlying mmap not under our control) */ - #define VPROT_PLACEHOLDER 0x0400 - #define VPROT_FROMPLACEHOLDER 0x0800 + #define VPROT_PLACEHOLDER 0x0400 + #define VPROT_FREE_PLACEHOLDER 0x0800 +#define VPROT_NATIVE 0x1000 /* Conversion from VPROT_* to Win32 flags */ static const BYTE VIRTUAL_Win32Flags[16] = -@@ -1119,7 +1120,9 @@ static void dump_view( struct file_view *view ) +@@ -184,6 +185,9 @@ static void *working_set_limit = (void *)0x7fff0000; + + static UINT64 *arm64ec_map; + ++static const ptrdiff_t max_try_map_step = 0x40000000; ++static BOOL increase_try_map_step = TRUE; ++ + struct _KUSER_SHARED_DATA *user_shared_data = (void *)0x7ffe0000; + + /* TEB allocation blocks */ +@@ -1164,7 +1168,9 @@ static void dump_view( struct file_view *view ) BYTE prot = get_page_vprot( addr ); TRACE( "View: %p - %p", addr, addr + view->size - 1 ); @@ -28,9 +38,9 @@ index 4bce8f2f806..3c1bf6edc30 100644 + TRACE(" (native)\n"); + else if (view->protect & VPROT_SYSTEM) TRACE( " (builtin image)\n" ); - else if (view->protect & VPROT_PLACEHOLDER) + else if (view->protect & VPROT_FREE_PLACEHOLDER) TRACE( " (placeholder)\n" ); -@@ -1274,6 +1277,8 @@ struct alloc_area +@@ -1283,6 +1289,8 @@ struct alloc_area int unix_prot; BOOL top_down; UINT_PTR align_mask; @@ -39,7 +49,7 @@ index 4bce8f2f806..3c1bf6edc30 100644 }; /*********************************************************************** -@@ -1282,21 +1287,28 @@ struct alloc_area +@@ -1291,27 +1299,35 @@ struct alloc_area * Try mmaping some expected free memory region, eventually stepping and * retrying inside it, and return where it actually succeeded, or NULL. */ @@ -73,7 +83,15 @@ index 4bce8f2f806..3c1bf6edc30 100644 if ((step > 0 && (char *)end - (char *)start < step) || (step < 0 && (char *)start - (char *)base < -step) || step == 0) -@@ -1797,9 +1809,9 @@ static int alloc_area_in_reserved_or_between_callback( void *start, SIZE_T size, + break; + start = (char *)start + step; +- step *= 2; ++ if (increase_try_map_step && llabs(step) < max_try_map_step) ++ step *= 2; + } + + return NULL; +@@ -1807,9 +1823,9 @@ static int alloc_area_in_reserved_or_between_callback( void *start, SIZE_T size, assert(intersect_start <= intersect_end); if (area->map_area_end - intersect_end >= area->size) { @@ -86,7 +104,7 @@ index 4bce8f2f806..3c1bf6edc30 100644 return 1; } -@@ -1838,8 +1850,8 @@ static int alloc_area_in_reserved_or_between_callback( void *start, SIZE_T size, +@@ -1848,8 +1864,8 @@ static int alloc_area_in_reserved_or_between_callback( void *start, SIZE_T size, if (intersect_start - area->map_area_start >= area->size) { alloc_start = ROUND_ADDR( area->map_area_start + align_mask, align_mask ); @@ -97,7 +115,7 @@ index 4bce8f2f806..3c1bf6edc30 100644 return 1; } -@@ -1900,8 +1912,7 @@ static void *alloc_free_area_in_range( struct alloc_area *area, char *base, char +@@ -1910,8 +1926,7 @@ static void *alloc_free_area_in_range( struct alloc_area *area, char *base, char if (start >= area->map_area_end || start < area->map_area_start) return NULL; @@ -107,7 +125,7 @@ index 4bce8f2f806..3c1bf6edc30 100644 } else { -@@ -1911,8 +1922,7 @@ static void *alloc_free_area_in_range( struct alloc_area *area, char *base, char +@@ -1921,8 +1936,7 @@ static void *alloc_free_area_in_range( struct alloc_area *area, char *base, char || area->map_area_end - start < area->size) return NULL; @@ -117,15 +135,15 @@ index 4bce8f2f806..3c1bf6edc30 100644 } } -@@ -1922,6 +1932,7 @@ static void *alloc_free_area( void *limit, size_t size, BOOL top_down, int unix_ - char *reserve_start, *reserve_end; +@@ -1933,6 +1947,7 @@ static void *alloc_free_area( void *limit, size_t size, BOOL top_down, int unix_ struct alloc_area area; char *base, *end; -+ NTSTATUS status; int ranges_inc; ++ UINT status; TRACE("limit %p, size %p, top_down %#x.\n", limit, (void *)size, top_down); -@@ -1991,7 +2002,58 @@ static void *alloc_free_area( void *limit, size_t size, BOOL top_down, int unix_ + +@@ -2001,7 +2016,58 @@ static void *alloc_free_area( void *limit, size_t size, BOOL top_down, int unix_ if ((area.result = alloc_free_area_in_range( &area, base, end ))) break; } @@ -177,7 +195,7 @@ index 4bce8f2f806..3c1bf6edc30 100644 + } + if ((status = create_view( &next, native_mapped_start, native_mapped_end - native_mapped_start, + VPROT_SYSTEM | VPROT_NATIVE ))) -+ ERR("Could not cretae view for natively mapped area, status %#x.\n", status); ++ ERR("Could not create view for natively mapped area, status %#x.\n", status); + } + } + @@ -185,7 +203,7 @@ index 4bce8f2f806..3c1bf6edc30 100644 } /*********************************************************************** -@@ -2045,6 +2107,17 @@ static NTSTATUS map_fixed_area( void *base, size_t size, unsigned int vprot ) +@@ -2055,6 +2121,17 @@ static NTSTATUS map_fixed_area( void *base, size_t size, unsigned int vprot ) return STATUS_SUCCESS; } @@ -203,20 +221,22 @@ index 4bce8f2f806..3c1bf6edc30 100644 /*********************************************************************** * map_view * -@@ -2097,7 +2170,11 @@ static NTSTATUS map_view( struct file_view **view_ret, void *base, size_t size, +@@ -2114,7 +2191,13 @@ static NTSTATUS map_view( struct file_view **view_ret, void *base, size_t size, } else if (!(ptr = alloc_free_area( (void *)limit, size, top_down, get_unix_prot( vprot ), align_mask ))) { - return STATUS_NO_MEMORY; -+ WARN("Allocation failed, clearing native views.\n"); ++ WARN( "Allocation failed, clearing native views.\n" ); + + clear_native_views(); -+ if (!(ptr = alloc_free_area( (void *)limit, size, top_down, get_unix_prot( vprot ), align_mask ))) -+ return STATUS_NO_MEMORY; ++ if (!is_win64) increase_try_map_step = FALSE; ++ ptr = alloc_free_area( (void *)limit, size, top_down, get_unix_prot( vprot ), align_mask ); ++ if (!is_win64) increase_try_map_step = TRUE; ++ if (!ptr) return STATUS_NO_MEMORY; } status = create_view( view_ret, ptr, size, vprot ); if (status != STATUS_SUCCESS) unmap_area( ptr, size ); -@@ -3835,7 +3912,12 @@ void virtual_set_force_exec( BOOL enable ) +@@ -4106,7 +4189,12 @@ void virtual_set_force_exec( BOOL enable ) WINE_RB_FOR_EACH_ENTRY( view, &views_tree, struct file_view, entry ) { /* file mappings are always accessible */ @@ -231,5 +251,5 @@ index 4bce8f2f806..3c1bf6edc30 100644 mprotect_range( view->base, view->size, commit, 0 ); } -- -2.38.1 +2.40.1 diff --git a/patches/ntdll-ForceBottomUpAlloc/definition b/patches/ntdll-ForceBottomUpAlloc/definition index c40f34f1..92b63d54 100644 --- a/patches/ntdll-ForceBottomUpAlloc/definition +++ b/patches/ntdll-ForceBottomUpAlloc/definition @@ -1,4 +1,3 @@ Fixes: [48175] AION (64 bit) - crashes in crysystem.dll.CryFree() due to high memory pointers allocated Fixes: [46568] 64-bit msxml6.dll from Microsoft Core XML Services 6.0 redist package fails to load (Wine doesn't respect 44-bit user-mode VA limitation from Windows < 8.1) Depends: ntdll-Placeholders -Disabled: True