You've already forked wine-staging
mirror of
https://gitlab.winehq.org/wine/wine-staging.git
synced 2025-09-12 18:50:20 -07:00
Rebase against 1c586991c802a7368137ae2c0470880bb359de78.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
From e5c4a6bd332d7d125e9db79fa29b14e55e3a1ee5 Mon Sep 17 00:00:00 2001
|
||||
From 32419947818521387ec9de7b5ca92f9269819bd2 Mon Sep 17 00:00:00 2001
|
||||
From: Paul Gofman <pgofman@codeweavers.com>
|
||||
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 | 402 +++++++++++++++-----------------------
|
||||
1 file changed, 162 insertions(+), 240 deletions(-)
|
||||
dlls/ntdll/unix/virtual.c | 400 +++++++++++++++-----------------------
|
||||
1 file changed, 162 insertions(+), 238 deletions(-)
|
||||
|
||||
diff --git a/dlls/ntdll/unix/virtual.c b/dlls/ntdll/unix/virtual.c
|
||||
index a36c919d47f..2f682e70ec2 100644
|
||||
index 2353e51f5e8..a5270649c0d 100644
|
||||
--- a/dlls/ntdll/unix/virtual.c
|
||||
+++ b/dlls/ntdll/unix/virtual.c
|
||||
@@ -1324,43 +1324,15 @@ static struct file_view *find_view_range( const void *addr, size_t size )
|
||||
@@ -1492,43 +1492,15 @@ static struct file_view *find_view_range( const void *addr, size_t size )
|
||||
}
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ index a36c919d47f..2f682e70ec2 100644
|
||||
|
||||
/***********************************************************************
|
||||
* try_map_free_area
|
||||
@@ -1393,112 +1365,6 @@ static void* try_map_free_area( void *base, void *end, ptrdiff_t step,
|
||||
@@ -1561,112 +1533,6 @@ static void* try_map_free_area( void *base, void *end, ptrdiff_t step,
|
||||
}
|
||||
|
||||
|
||||
@@ -184,7 +184,7 @@ index a36c919d47f..2f682e70ec2 100644
|
||||
/***********************************************************************
|
||||
* remove_reserved_area
|
||||
*
|
||||
@@ -1613,8 +1479,7 @@ static void free_view( struct file_view *view )
|
||||
@@ -1781,8 +1647,7 @@ static void free_view( struct file_view *view )
|
||||
*/
|
||||
static void unregister_view( struct file_view *view )
|
||||
{
|
||||
@@ -194,7 +194,7 @@ index a36c919d47f..2f682e70ec2 100644
|
||||
wine_rb_remove( &views_tree, &view->entry );
|
||||
}
|
||||
|
||||
@@ -1642,8 +1507,7 @@ static void delete_view( struct file_view *view ) /* [in] View */
|
||||
@@ -1810,8 +1675,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 a36c919d47f..2f682e70ec2 100644
|
||||
}
|
||||
|
||||
|
||||
@@ -1919,89 +1783,176 @@ static inline void *unmap_extra_space( void *ptr, size_t total_size, size_t want
|
||||
@@ -2099,89 +1963,176 @@ static inline void *unmap_extra_space( void *ptr, size_t total_size, size_t want
|
||||
return ptr;
|
||||
}
|
||||
|
||||
@@ -223,18 +223,18 @@ index a36c919d47f..2f682e70ec2 100644
|
||||
+ char *alloc_start;
|
||||
|
||||
- if (preload_reserve_end >= end)
|
||||
+ if (area->top_down)
|
||||
{
|
||||
- {
|
||||
- if (preload_reserve_start <= start) return NULL; /* no space in that area */
|
||||
- if (preload_reserve_start < end) end = preload_reserve_start;
|
||||
- }
|
||||
- else if (preload_reserve_start <= start)
|
||||
+ if (area->top_down)
|
||||
{
|
||||
- if (preload_reserve_end > start) start = preload_reserve_end;
|
||||
+ if (end - start < area->size) return NULL;
|
||||
+ alloc_start = ROUND_ADDR( end - area->size, area->align_mask );
|
||||
+ return try_map_free_area( start, alloc_start + area->size, area->step, alloc_start, area->size, area->unix_prot );
|
||||
}
|
||||
- else if (preload_reserve_start <= start)
|
||||
- {
|
||||
- if (preload_reserve_end > start) start = preload_reserve_end;
|
||||
- }
|
||||
- else /* range is split in two by the preloader reservation, try both parts */
|
||||
+
|
||||
+ alloc_start = ROUND_ADDR( start + area->align_mask, area->align_mask );
|
||||
@@ -442,16 +442,16 @@ index a36c919d47f..2f682e70ec2 100644
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
@@ -2112,43 +2063,12 @@ static NTSTATUS map_view( struct file_view **view_ret, void *base, size_t size,
|
||||
@@ -2299,41 +2250,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;
|
||||
-
|
||||
|
||||
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 )))
|
||||
- if ((ptr = map_reserved_area( start, end, host_size, top_down, unix_prot, align_mask )))
|
||||
- {
|
||||
- TRACE( "got mem in reserved area %p-%p\n", ptr, (char *)ptr + size );
|
||||
- goto done;
|
||||
@@ -459,7 +459,7 @@ index a36c919d47f..2f682e70ec2 100644
|
||||
-
|
||||
- if (start > address_space_start || end < host_addr_space_limit || top_down)
|
||||
- {
|
||||
- if (!(ptr = map_free_area( start, end, host_size, top_down, get_unix_prot(vprot), align_mask )))
|
||||
- if (!(ptr = map_free_area( start, end, host_size, top_down, unix_prot, align_mask )))
|
||||
- return STATUS_NO_MEMORY;
|
||||
- TRACE( "got mem with map_free_area %p-%p\n", ptr, (char *)ptr + size );
|
||||
- goto done;
|
||||
@@ -467,11 +467,11 @@ index a36c919d47f..2f682e70ec2 100644
|
||||
-
|
||||
- for (;;)
|
||||
- {
|
||||
- if ((ptr = anon_mmap_alloc( view_size, get_unix_prot(vprot) )) == MAP_FAILED)
|
||||
- if ((ptr = anon_mmap_alloc( view_size, unix_prot )) == MAP_FAILED)
|
||||
- {
|
||||
- status = (errno == ENOMEM) ? STATUS_NO_MEMORY : STATUS_INVALID_PARAMETER;
|
||||
- ERR( "anon mmap error %s, size %p, unix_prot %#x\n",
|
||||
- strerror(errno), (void *)view_size, get_unix_prot( vprot ) );
|
||||
- strerror(errno), (void *)view_size, unix_prot );
|
||||
- return status;
|
||||
- }
|
||||
- TRACE( "got mem with anon mmap %p-%p\n", ptr, (char *)ptr + size );
|
||||
@@ -481,14 +481,12 @@ index a36c919d47f..2f682e70ec2 100644
|
||||
- if (unmap_size) munmap( ptr, unmap_size );
|
||||
- }
|
||||
- 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 )))
|
||||
+ if (!(ptr = alloc_free_area( start, end, host_size, top_down, unix_prot, align_mask )))
|
||||
+ return STATUS_NO_MEMORY;
|
||||
}
|
||||
-done:
|
||||
done:
|
||||
status = create_view( view_ret, ptr, size, vprot );
|
||||
if (status != STATUS_SUCCESS) unmap_area( ptr, size );
|
||||
return status;
|
||||
@@ -3413,6 +3333,7 @@ static unsigned int virtual_map_section( HANDLE handle, PVOID *addr_ptr, ULONG_P
|
||||
@@ -3602,6 +3524,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 );
|
||||
@@ -496,7 +494,7 @@ index a36c919d47f..2f682e70ec2 100644
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -6624,6 +6545,7 @@ NTSTATUS WINAPI NtWow64AllocateVirtualMemory64( HANDLE process, ULONG64 *ret, UL
|
||||
@@ -6875,6 +6798,7 @@ NTSTATUS WINAPI NtWow64AllocateVirtualMemory64( HANDLE process, ULONG64 *ret, UL
|
||||
*ret = (ULONG_PTR)base;
|
||||
*size_ptr = size;
|
||||
}
|
||||
@@ -505,5 +503,5 @@ index a36c919d47f..2f682e70ec2 100644
|
||||
}
|
||||
|
||||
--
|
||||
2.49.0
|
||||
2.47.2
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
From 09d76a4049ee4cc8bce4ffafc349da326fc058e0 Mon Sep 17 00:00:00 2001
|
||||
From f918a9c53c678d3234cc6b51083af524087966bb Mon Sep 17 00:00:00 2001
|
||||
From: Paul Gofman <pgofman@codeweavers.com>
|
||||
Date: Fri, 1 Dec 2023 14:55:20 -0600
|
||||
Subject: [PATCH] ntdll: Exclude natively mapped areas from free areas list.
|
||||
@@ -8,10 +8,10 @@ Subject: [PATCH] ntdll: Exclude natively mapped areas from free areas list.
|
||||
1 file changed, 96 insertions(+), 9 deletions(-)
|
||||
|
||||
diff --git a/dlls/ntdll/unix/virtual.c b/dlls/ntdll/unix/virtual.c
|
||||
index 2f682e70ec2..6170363f0a0 100644
|
||||
index a5270649c0d..0fe761a3b85 100644
|
||||
--- a/dlls/ntdll/unix/virtual.c
|
||||
+++ b/dlls/ntdll/unix/virtual.c
|
||||
@@ -135,6 +135,7 @@ struct file_view
|
||||
@@ -144,6 +144,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 2f682e70ec2..6170363f0a0 100644
|
||||
|
||||
/* Conversion from VPROT_* to Win32 flags */
|
||||
static const BYTE VIRTUAL_Win32Flags[16] =
|
||||
@@ -191,6 +192,8 @@ static void *working_set_limit = (void *)0x7fff0000;
|
||||
@@ -200,6 +201,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 2f682e70ec2..6170363f0a0 100644
|
||||
|
||||
ULONG_PTR user_space_wow_limit = 0;
|
||||
struct _KUSER_SHARED_DATA *user_shared_data = (void *)0x7ffe0000;
|
||||
@@ -1212,7 +1215,9 @@ static void dump_view( struct file_view *view )
|
||||
@@ -1380,7 +1383,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 2f682e70ec2..6170363f0a0 100644
|
||||
TRACE( " (builtin image)\n" );
|
||||
else if (view->protect & VPROT_FREE_PLACEHOLDER)
|
||||
TRACE( " (placeholder)\n" );
|
||||
@@ -1332,6 +1337,8 @@ struct alloc_area
|
||||
@@ -1500,6 +1505,8 @@ struct alloc_area
|
||||
int unix_prot;
|
||||
BOOL top_down;
|
||||
UINT_PTR align_mask;
|
||||
@@ -48,7 +48,7 @@ index 2f682e70ec2..6170363f0a0 100644
|
||||
};
|
||||
|
||||
/***********************************************************************
|
||||
@@ -1340,9 +1347,13 @@ struct alloc_area
|
||||
@@ -1508,9 +1515,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.
|
||||
*/
|
||||
@@ -64,7 +64,7 @@ index 2f682e70ec2..6170363f0a0 100644
|
||||
while (start && base <= start && (char*)start + size <= (char*)end)
|
||||
{
|
||||
if (anon_mmap_tryfixed( start, size, unix_prot, 0 ) != MAP_FAILED) return start;
|
||||
@@ -1353,12 +1364,19 @@ static void* try_map_free_area( void *base, void *end, ptrdiff_t step,
|
||||
@@ -1521,12 +1532,19 @@ static void* try_map_free_area( void *base, void *end, ptrdiff_t step,
|
||||
strerror(errno), start, (char *)start + size, unix_prot );
|
||||
return NULL;
|
||||
}
|
||||
@@ -85,7 +85,7 @@ index 2f682e70ec2..6170363f0a0 100644
|
||||
}
|
||||
|
||||
return NULL;
|
||||
@@ -1791,11 +1809,11 @@ static void *try_map_free_area_range( struct alloc_area *area, char *start, char
|
||||
@@ -1971,11 +1989,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 );
|
||||
@@ -99,7 +99,7 @@ index 2f682e70ec2..6170363f0a0 100644
|
||||
}
|
||||
|
||||
static void *alloc_free_area_in_range( struct alloc_area *area, char *base, char *end )
|
||||
@@ -1885,9 +1903,10 @@ static void *alloc_free_area( char *limit_low, char *limit_high, size_t size, BO
|
||||
@@ -2065,9 +2083,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;
|
||||
@@ -111,7 +111,7 @@ index 2f682e70ec2..6170363f0a0 100644
|
||||
|
||||
TRACE("limit %p-%p, size %p, top_down %#x.\n", limit_low, limit_high, (void *)size, top_down);
|
||||
|
||||
@@ -1952,6 +1971,50 @@ static void *alloc_free_area( char *limit_low, char *limit_high, size_t size, BO
|
||||
@@ -2132,6 +2151,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;
|
||||
}
|
||||
@@ -162,7 +162,7 @@ index 2f682e70ec2..6170363f0a0 100644
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -2012,6 +2075,17 @@ failed:
|
||||
@@ -2191,6 +2254,17 @@ failed:
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -180,24 +180,24 @@ index 2f682e70ec2..6170363f0a0 100644
|
||||
/***********************************************************************
|
||||
* map_view
|
||||
*
|
||||
@@ -2067,7 +2141,15 @@ static NTSTATUS map_view( struct file_view **view_ret, void *base, size_t size,
|
||||
@@ -2255,7 +2329,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( start, end, host_size, top_down, get_unix_prot( vprot ), align_mask )))
|
||||
if (!(ptr = alloc_free_area( start, end, host_size, top_down, unix_prot, align_mask )))
|
||||
- return STATUS_NO_MEMORY;
|
||||
+ {
|
||||
+ WARN("Allocation failed, clearing native views.\n");
|
||||
+
|
||||
+ clear_native_views();
|
||||
+ if (!is_win64) increase_try_map_step = FALSE;
|
||||
+ ptr = alloc_free_area( (void *)limit_low, (void *)limit_high, size, top_down, get_unix_prot( vprot ), align_mask );
|
||||
+ ptr = alloc_free_area( (void *)limit_low, (void *)limit_high, size, top_down, unix_prot, align_mask );
|
||||
+ if (!is_win64) increase_try_map_step = TRUE;
|
||||
+ if (!ptr) return STATUS_NO_MEMORY;
|
||||
+ }
|
||||
}
|
||||
done:
|
||||
status = create_view( view_ret, ptr, size, vprot );
|
||||
if (status != STATUS_SUCCESS) unmap_area( ptr, size );
|
||||
@@ -4503,7 +4585,12 @@ void virtual_set_force_exec( BOOL enable )
|
||||
@@ -4746,7 +4828,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 */
|
||||
@@ -212,5 +212,5 @@ index 2f682e70ec2..6170363f0a0 100644
|
||||
mprotect_range( view->base, view->size, commit, 0 );
|
||||
}
|
||||
--
|
||||
2.49.0
|
||||
2.47.2
|
||||
|
||||
|
@@ -1 +1 @@
|
||||
69e3a51b3dc50dd1697c64f7b2bcde54baa0a300
|
||||
1c586991c802a7368137ae2c0470880bb359de78
|
||||
|
Reference in New Issue
Block a user