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 d19a473f..9d98b999 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 33961353f1d7e0590c83927e632a6d43b2a81fa2 Mon Sep 17 00:00:00 2001 +From a955d4d49edc6bbd44ee168f42cd1773f4868533 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 75e6319c007..9ddd9a3a218 100644 +index 4b952b765d7..6a24eb0fa8e 100644 --- a/dlls/ntdll/unix/virtual.c +++ b/dlls/ntdll/unix/virtual.c -@@ -1306,6 +1306,7 @@ static void* try_map_free_area( void *base, void *end, ptrdiff_t step, +@@ -1382,6 +1382,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 75e6319c007..9ddd9a3a218 100644 return NULL; -- -2.43.0 +2.49.0 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 a5ab820b..d5472cdf 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 d853eba76fd849e21b5cb4ce0a3f113ba9beea87 Mon Sep 17 00:00:00 2001 +From c86b01cc0809af60b05bcc8ce66a6001cd4b993b 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 9ddd9a3a218..30d0df85fba 100644 +index 6a24eb0fa8e..a36c919d47f 100644 --- a/dlls/ntdll/unix/virtual.c +++ b/dlls/ntdll/unix/virtual.c -@@ -210,7 +210,11 @@ static BYTE *pages_vprot; +@@ -221,7 +221,11 @@ static BYTE *pages_vprot; #endif static struct file_view *view_block_start, *view_block_end, *next_free_view; @@ -24,5 +24,5 @@ index 9ddd9a3a218..30d0df85fba 100644 static void *preload_reserve_end; static BOOL force_exec_prot; /* whether to force PROT_EXEC on all PROT_READ mmaps */ -- -2.43.0 +2.49.0 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 7065c772..eda495ab 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 4c246e61f0de05a8b80e7a5d5ff2edcd21036fec Mon Sep 17 00:00:00 2001 +From e5c4a6bd332d7d125e9db79fa29b14e55e3a1ee5 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. @@ -12,14 +12,14 @@ are from higher memory than they expect. Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=48175 Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=46568 --- - dlls/ntdll/unix/virtual.c | 410 +++++++++++++++----------------------- - 1 file changed, 164 insertions(+), 246 deletions(-) + dlls/ntdll/unix/virtual.c | 402 +++++++++++++++----------------------- + 1 file changed, 162 insertions(+), 240 deletions(-) diff --git a/dlls/ntdll/unix/virtual.c b/dlls/ntdll/unix/virtual.c -index 1a3d527f186..ec72d692c3a 100644 +index a36c919d47f..2f682e70ec2 100644 --- a/dlls/ntdll/unix/virtual.c +++ b/dlls/ntdll/unix/virtual.c -@@ -1269,43 +1269,15 @@ static struct file_view *find_view_range( const void *addr, size_t size ) +@@ -1324,43 +1324,15 @@ static struct file_view *find_view_range( const void *addr, size_t size ) } @@ -71,7 +71,7 @@ index 1a3d527f186..ec72d692c3a 100644 /*********************************************************************** * try_map_free_area -@@ -1338,112 +1310,6 @@ static void* try_map_free_area( void *base, void *end, ptrdiff_t step, +@@ -1393,112 +1365,6 @@ static void* try_map_free_area( void *base, void *end, ptrdiff_t step, } @@ -184,7 +184,7 @@ index 1a3d527f186..ec72d692c3a 100644 /*********************************************************************** * remove_reserved_area * -@@ -1553,8 +1419,7 @@ static void free_view( struct file_view *view ) +@@ -1613,8 +1479,7 @@ static void free_view( struct file_view *view ) */ static void unregister_view( struct file_view *view ) { @@ -194,7 +194,7 @@ index 1a3d527f186..ec72d692c3a 100644 wine_rb_remove( &views_tree, &view->entry ); } -@@ -1582,8 +1447,7 @@ static void delete_view( struct file_view *view ) /* [in] View */ +@@ -1642,8 +1507,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 ); @@ -204,7 +204,7 @@ index 1a3d527f186..ec72d692c3a 100644 } -@@ -1855,89 +1719,176 @@ static inline void *unmap_extra_space( void *ptr, size_t total_size, size_t want +@@ -1919,89 +1783,176 @@ static inline void *unmap_extra_space( void *ptr, size_t total_size, size_t want return ptr; } @@ -362,8 +362,8 @@ index 1a3d527f186..ec72d692c3a 100644 - - if (start >= limit_high) continue; - if (end <= limit_low) return NULL; -- if (start < limit_low) start = limit_low; -- if (end > limit_high) end = limit_high; +- if (start < limit_low) start = (void *)ROUND_SIZE( 0, limit_low, host_page_mask ); +- if (end > limit_high) end = ROUND_ADDR( limit_high, host_page_mask ); - ptr = find_reserved_free_area_outside_preloader( start, end, size, top_down, align_mask ); - if (ptr) break; - } @@ -396,8 +396,8 @@ index 1a3d527f186..ec72d692c3a 100644 + + TRACE("range %p-%p.\n", base, end); + -+ if (base < limit_low) base = limit_low; -+ if (end > limit_high) end = limit_high; ++ if (base < limit_low) base = (void *)ROUND_SIZE( 0, limit_low, host_page_mask ); ++ if (end > limit_high) end = ROUND_ADDR( limit_high, host_page_mask ); + if (base > end || end - base < size) continue; + + if (reserve_end >= base) @@ -407,8 +407,8 @@ index 1a3d527f186..ec72d692c3a 100644 - - if (start >= limit_high) return NULL; - if (end <= limit_low) continue; -- if (start < limit_low) start = limit_low; -- if (end > limit_high) end = limit_high; +- if (start < limit_low) start = (void *)ROUND_SIZE( 0, limit_low, host_page_mask ); +- if (end > limit_high) end = ROUND_ADDR( limit_high, host_page_mask ); - ptr = find_reserved_free_area_outside_preloader( start, end, size, top_down, align_mask ); - if (ptr) break; + if (reserve_end >= end) @@ -442,31 +442,24 @@ index 1a3d527f186..ec72d692c3a 100644 } /*********************************************************************** -@@ -2041,48 +1992,13 @@ static NTSTATUS map_view( struct file_view **view_ret, void *base, size_t size, - } - else - { -- void *start = address_space_start; -- void *end = min( user_space_limit, host_addr_space_limit ); -- size_t view_size, unmap_size; +@@ -2112,43 +2063,12 @@ static NTSTATUS map_view( struct file_view **view_ret, void *base, size_t size, + void *start = address_space_start; + void *end = min( user_space_limit, host_addr_space_limit ); + size_t host_size = ROUND_SIZE( 0, size, host_page_mask ); +- size_t unmap_size, view_size = host_size + align_mask + 1; - -+ limit_high = limit_high ? min( limit_high + 1, (UINT_PTR)user_space_limit) : (UINT_PTR)user_space_limit; -+ if (limit_low < (ULONG_PTR)address_space_start) limit_low = (ULONG_PTR)address_space_start; - if (!align_mask) align_mask = granularity_mask; -- view_size = size + align_mask + 1; -- -- if (limit_low && (void *)limit_low > start) start = (void *)limit_low; -- if (limit_high && (void *)limit_high < end) end = (char *)limit_high + 1; -- -- if ((ptr = map_reserved_area( start, end, size, top_down, get_unix_prot(vprot), align_mask ))) + if (limit_low && (void *)limit_low > start) start = (void *)limit_low; + if (limit_high && (void *)limit_high < end) end = (char *)limit_high + 1; + +- if ((ptr = map_reserved_area( start, end, host_size, top_down, get_unix_prot(vprot), align_mask ))) - { - TRACE( "got mem in reserved area %p-%p\n", ptr, (char *)ptr + size ); - goto done; - } - +- - if (start > address_space_start || end < host_addr_space_limit || top_down) - { -- if (!(ptr = map_free_area( start, end, size, top_down, get_unix_prot(vprot), align_mask ))) +- if (!(ptr = map_free_area( start, end, host_size, top_down, get_unix_prot(vprot), align_mask ))) - return STATUS_NO_MEMORY; - TRACE( "got mem with map_free_area %p-%p\n", ptr, (char *)ptr + size ); - goto done; @@ -487,15 +480,15 @@ index 1a3d527f186..ec72d692c3a 100644 - unmap_size = unmap_area_above_user_limit( ptr, view_size ); - if (unmap_size) munmap( ptr, unmap_size ); - } -- ptr = unmap_extra_space( ptr, view_size, size, align_mask ); -+ if (!(ptr = alloc_free_area( (void *)limit_low, (void *)limit_high, size, top_down, get_unix_prot( vprot ), align_mask ))) +- ptr = unmap_extra_space( ptr, view_size, host_size, align_mask ); ++ if (!(ptr = alloc_free_area( start, end, host_size, top_down, get_unix_prot( vprot ), align_mask ))) + return STATUS_NO_MEMORY; } -done: status = create_view( view_ret, ptr, size, vprot ); if (status != STATUS_SUCCESS) unmap_area( ptr, size ); return status; -@@ -3275,6 +3191,7 @@ static unsigned int virtual_map_section( HANDLE handle, PVOID *addr_ptr, ULONG_P +@@ -3413,6 +3333,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 ); @@ -503,7 +496,7 @@ index 1a3d527f186..ec72d692c3a 100644 return res; } -@@ -6394,6 +6311,7 @@ NTSTATUS WINAPI NtWow64AllocateVirtualMemory64( HANDLE process, ULONG64 *ret, UL +@@ -6624,6 +6545,7 @@ NTSTATUS WINAPI NtWow64AllocateVirtualMemory64( HANDLE process, ULONG64 *ret, UL *ret = (ULONG_PTR)base; *size_ptr = size; } @@ -512,5 +505,5 @@ index 1a3d527f186..ec72d692c3a 100644 } -- -2.45.2 +2.49.0 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 79898855..a111af30 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,17 +1,17 @@ -From 844ba5e56a7231f65b65cabf06fe44ee49876aa0 Mon Sep 17 00:00:00 2001 +From 09d76a4049ee4cc8bce4ffafc349da326fc058e0 Mon Sep 17 00:00:00 2001 From: Paul Gofman Date: Fri, 1 Dec 2023 14:55:20 -0600 Subject: [PATCH] ntdll: Exclude natively mapped areas from free areas list. --- - dlls/ntdll/unix/virtual.c | 106 ++++++++++++++++++++++++++++++++++---- - 1 file changed, 97 insertions(+), 9 deletions(-) + dlls/ntdll/unix/virtual.c | 105 ++++++++++++++++++++++++++++++++++---- + 1 file changed, 96 insertions(+), 9 deletions(-) diff --git a/dlls/ntdll/unix/virtual.c b/dlls/ntdll/unix/virtual.c -index ec72d692c3a..30d43afc076 100644 +index 2f682e70ec2..6170363f0a0 100644 --- a/dlls/ntdll/unix/virtual.c +++ b/dlls/ntdll/unix/virtual.c -@@ -127,6 +127,7 @@ struct file_view +@@ -135,6 +135,7 @@ struct file_view #define VPROT_SYSTEM 0x0200 /* system view (underlying mmap not under our control) */ #define VPROT_PLACEHOLDER 0x0400 #define VPROT_FREE_PLACEHOLDER 0x0800 @@ -19,7 +19,7 @@ index ec72d692c3a..30d43afc076 100644 /* Conversion from VPROT_* to Win32 flags */ static const BYTE VIRTUAL_Win32Flags[16] = -@@ -175,6 +176,8 @@ static void *working_set_limit = (void *)0x7fff0000; +@@ -191,6 +192,8 @@ static void *working_set_limit = (void *)0x7fff0000; static void *host_addr_space_limit; /* top of the host virtual address space */ static struct file_view *arm64ec_view; @@ -28,7 +28,7 @@ index ec72d692c3a..30d43afc076 100644 ULONG_PTR user_space_wow_limit = 0; struct _KUSER_SHARED_DATA *user_shared_data = (void *)0x7ffe0000; -@@ -1157,7 +1160,9 @@ static void dump_view( struct file_view *view ) +@@ -1212,7 +1215,9 @@ static void dump_view( struct file_view *view ) BYTE prot = get_page_vprot( addr ); TRACE( "View: %p - %p", addr, addr + view->size - 1 ); @@ -39,7 +39,7 @@ index ec72d692c3a..30d43afc076 100644 TRACE( " (builtin image)\n" ); else if (view->protect & VPROT_FREE_PLACEHOLDER) TRACE( " (placeholder)\n" ); -@@ -1277,6 +1282,8 @@ struct alloc_area +@@ -1332,6 +1337,8 @@ struct alloc_area int unix_prot; BOOL top_down; UINT_PTR align_mask; @@ -48,7 +48,7 @@ index ec72d692c3a..30d43afc076 100644 }; /*********************************************************************** -@@ -1285,9 +1292,14 @@ struct alloc_area +@@ -1340,9 +1347,13 @@ struct alloc_area * Try mmaping some expected free memory region, eventually stepping and * retrying inside it, and return where it actually succeeded, or NULL. */ @@ -60,12 +60,11 @@ index ec72d692c3a..30d43afc076 100644 + size_t abs_step = step > 0 ? step : -step; + size_t size = area->size; + int unix_prot = area->unix_prot; -+ void *ptr; + while (start && base <= start && (char*)start + size <= (char*)end) { if (anon_mmap_tryfixed( start, size, unix_prot, 0 ) != MAP_FAILED) return start; -@@ -1298,12 +1310,19 @@ static void* try_map_free_area( void *base, void *end, ptrdiff_t step, +@@ -1353,12 +1364,19 @@ static void* try_map_free_area( void *base, void *end, ptrdiff_t step, strerror(errno), start, (char *)start + size, unix_prot ); return NULL; } @@ -86,7 +85,7 @@ index ec72d692c3a..30d43afc076 100644 } return NULL; -@@ -1727,11 +1746,11 @@ static void *try_map_free_area_range( struct alloc_area *area, char *start, char +@@ -1791,11 +1809,11 @@ static void *try_map_free_area_range( struct alloc_area *area, char *start, char { if (end - start < area->size) return NULL; alloc_start = ROUND_ADDR( end - area->size, area->align_mask ); @@ -100,7 +99,7 @@ index ec72d692c3a..30d43afc076 100644 } static void *alloc_free_area_in_range( struct alloc_area *area, char *base, char *end ) -@@ -1821,9 +1840,10 @@ static void *alloc_free_area( char *limit_low, char *limit_high, size_t size, BO +@@ -1885,9 +1903,10 @@ static void *alloc_free_area( char *limit_low, char *limit_high, size_t size, BO struct range_entry *range, *ranges_start, *ranges_end; char *reserve_start, *reserve_end; struct alloc_area area; @@ -112,7 +111,7 @@ index ec72d692c3a..30d43afc076 100644 TRACE("limit %p-%p, size %p, top_down %#x.\n", limit_low, limit_high, (void *)size, top_down); -@@ -1888,6 +1908,50 @@ static void *alloc_free_area( char *limit_low, char *limit_high, size_t size, BO +@@ -1952,6 +1971,50 @@ static void *alloc_free_area( char *limit_low, char *limit_high, size_t size, BO if ((result = alloc_free_area_in_range( &area, base, end ))) break; } @@ -163,7 +162,7 @@ index ec72d692c3a..30d43afc076 100644 return result; } -@@ -1947,6 +2011,17 @@ failed: +@@ -2012,6 +2075,17 @@ failed: return status; } @@ -181,10 +180,10 @@ index ec72d692c3a..30d43afc076 100644 /*********************************************************************** * map_view * -@@ -1997,7 +2072,15 @@ static NTSTATUS map_view( struct file_view **view_ret, void *base, size_t size, - if (!align_mask) align_mask = granularity_mask; +@@ -2067,7 +2141,15 @@ static NTSTATUS map_view( struct file_view **view_ret, void *base, size_t size, + if (limit_high && (void *)limit_high < end) end = (char *)limit_high + 1; - if (!(ptr = alloc_free_area( (void *)limit_low, (void *)limit_high, size, top_down, get_unix_prot( vprot ), align_mask ))) + if (!(ptr = alloc_free_area( start, end, host_size, top_down, get_unix_prot( vprot ), align_mask ))) - return STATUS_NO_MEMORY; + { + WARN("Allocation failed, clearing native views.\n"); @@ -198,7 +197,7 @@ index ec72d692c3a..30d43afc076 100644 } status = create_view( view_ret, ptr, size, vprot ); if (status != STATUS_SUCCESS) unmap_area( ptr, size ); -@@ -4346,7 +4429,12 @@ void virtual_set_force_exec( BOOL enable ) +@@ -4503,7 +4585,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 */ @@ -213,5 +212,5 @@ index ec72d692c3a..30d43afc076 100644 mprotect_range( view->base, view->size, commit, 0 ); } -- -2.45.2 +2.49.0 diff --git a/patches/ntdll-ForceBottomUpAlloc/definition b/patches/ntdll-ForceBottomUpAlloc/definition index c58d53a5..646add00 100644 --- a/patches/ntdll-ForceBottomUpAlloc/definition +++ b/patches/ntdll-ForceBottomUpAlloc/definition @@ -1,3 +1,2 @@ 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) -Disabled: true