mirror of
https://gitlab.winehq.org/wine/wine-staging.git
synced 2024-11-21 16:46:54 -08:00
Updated ntdll-ForceBottomUpAlloc patchset.
This commit is contained in:
parent
f6356a2c93
commit
ab4391f61b
@ -1,19 +1,18 @@
|
||||
From ff02cbe4aea411563e0a9d22ed832acc2747d5b7 Mon Sep 17 00:00:00 2001
|
||||
From d28a26a59e9837191cc48854d5dad16eba532f04 Mon Sep 17 00:00:00 2001
|
||||
From: Paul Gofman <pgofman@codeweavers.com>
|
||||
Date: Tue, 14 Jan 2020 21:39:23 +0300
|
||||
Subject: [PATCH 1/4] ntdll: Increase step after failed map attempt in
|
||||
Subject: [PATCH] ntdll: Increase step after failed map attempt in
|
||||
try_map_free_area().
|
||||
|
||||
Signed-off-by: Paul Gofman <pgofman@codeweavers.com>
|
||||
---
|
||||
dlls/ntdll/unix/virtual.c | 1 +
|
||||
1 file changed, 1 insertion(+)
|
||||
|
||||
diff --git a/dlls/ntdll/unix/virtual.c b/dlls/ntdll/unix/virtual.c
|
||||
index b469e9df4a1..52915e07323 100644
|
||||
index d79e3de662e..f8f317a6483 100644
|
||||
--- a/dlls/ntdll/unix/virtual.c
|
||||
+++ b/dlls/ntdll/unix/virtual.c
|
||||
@@ -1080,6 +1080,7 @@ static void* try_map_free_area( void *base, void *end, ptrdiff_t step,
|
||||
@@ -1073,6 +1073,7 @@ static void* try_map_free_area( void *base, void *end, ptrdiff_t step,
|
||||
step == 0)
|
||||
break;
|
||||
start = (char *)start + step;
|
||||
|
@ -1,15 +1,14 @@
|
||||
From 01730a2261a59a2826a652360b69dd3c74917fa6 Mon Sep 17 00:00:00 2001
|
||||
From 266f5082387ec92cb79a2ec3ce71d956cf05190d Mon Sep 17 00:00:00 2001
|
||||
From: Paul Gofman <pgofman@codeweavers.com>
|
||||
Date: Thu, 23 Jul 2020 18:40:39 +0300
|
||||
Subject: [PATCH] ntdll: Increase free ranges view block size on 64 bit.
|
||||
|
||||
Signed-off-by: Paul Gofman <pgofman@codeweavers.com>
|
||||
---
|
||||
dlls/ntdll/unix/virtual.c | 4 ++++
|
||||
1 file changed, 4 insertions(+)
|
||||
|
||||
diff --git a/dlls/ntdll/unix/virtual.c b/dlls/ntdll/unix/virtual.c
|
||||
index f7eab895f58..54ad53ea088 100644
|
||||
index f8f317a6483..4ca033b0e19 100644
|
||||
--- a/dlls/ntdll/unix/virtual.c
|
||||
+++ b/dlls/ntdll/unix/virtual.c
|
||||
@@ -183,7 +183,11 @@ static BYTE *pages_vprot;
|
||||
@ -25,5 +24,5 @@ index f7eab895f58..54ad53ea088 100644
|
||||
static void *preload_reserve_end;
|
||||
static BOOL force_exec_prot; /* whether to force PROT_EXEC on all PROT_READ mmaps */
|
||||
--
|
||||
2.28.0
|
||||
2.26.2
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
From 1823294e18c99c17f3085486f12dcd2c6f8555b6 Mon Sep 17 00:00:00 2001
|
||||
From 43fc939825dd5d4d2fdbfd98f849d71eaebfa8d0 Mon Sep 17 00:00:00 2001
|
||||
From: Paul Gofman <pgofman@codeweavers.com>
|
||||
Date: Mon, 25 Nov 2019 12:19:20 +0300
|
||||
Subject: [PATCH 3/4] ntdll: Force virtual memory allocation order.
|
||||
Subject: [PATCH] ntdll: Force virtual memory allocation order.
|
||||
|
||||
Windows allocates virtual memory strictly bottom up or
|
||||
top down depending on the requested flags. Modern Linux
|
||||
@ -11,16 +11,15 @@ 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
|
||||
Signed-off-by: Paul Gofman <pgofman@codeweavers.com>
|
||||
---
|
||||
dlls/ntdll/unix/virtual.c | 417 ++++++++++++++++++--------------------
|
||||
1 file changed, 201 insertions(+), 216 deletions(-)
|
||||
dlls/ntdll/unix/virtual.c | 418 ++++++++++++++++++--------------------
|
||||
1 file changed, 202 insertions(+), 216 deletions(-)
|
||||
|
||||
diff --git a/dlls/ntdll/unix/virtual.c b/dlls/ntdll/unix/virtual.c
|
||||
index 924dff973ce..e7dfc516538 100644
|
||||
index 4ca033b0e19..5bb9511be6d 100644
|
||||
--- a/dlls/ntdll/unix/virtual.c
|
||||
+++ b/dlls/ntdll/unix/virtual.c
|
||||
@@ -1020,44 +1020,6 @@ static struct file_view *find_view_range( const void *addr, size_t size )
|
||||
@@ -1013,44 +1013,6 @@ static struct file_view *find_view_range( const void *addr, size_t size )
|
||||
}
|
||||
|
||||
|
||||
@ -65,7 +64,7 @@ index 924dff973ce..e7dfc516538 100644
|
||||
/***********************************************************************
|
||||
* try_map_free_area
|
||||
*
|
||||
@@ -1090,110 +1052,6 @@ static void* try_map_free_area( void *base, void *end, ptrdiff_t step,
|
||||
@@ -1083,110 +1045,6 @@ static void* try_map_free_area( void *base, void *end, ptrdiff_t step,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -176,7 +175,7 @@ index 924dff973ce..e7dfc516538 100644
|
||||
/***********************************************************************
|
||||
* add_reserved_area
|
||||
*
|
||||
@@ -1351,8 +1209,7 @@ static void delete_view( struct file_view *view ) /* [in] View */
|
||||
@@ -1344,8 +1202,7 @@ static void delete_view( struct file_view *view ) /* [in] View */
|
||||
{
|
||||
if (!(view->protect & VPROT_SYSTEM)) unmap_area( view->base, view->size );
|
||||
set_page_vprot( view->base, view->size, 0 );
|
||||
@ -186,7 +185,7 @@ index 924dff973ce..e7dfc516538 100644
|
||||
wine_rb_remove( &views_tree, &view->entry );
|
||||
*(struct file_view **)view = next_free_view;
|
||||
next_free_view = view;
|
||||
@@ -1400,8 +1257,7 @@ static NTSTATUS create_view( struct file_view **view_ret, void *base, size_t siz
|
||||
@@ -1393,8 +1250,7 @@ static NTSTATUS create_view( struct file_view **view_ret, void *base, size_t siz
|
||||
set_page_vprot( base, size, vprot );
|
||||
|
||||
wine_rb_put( &views_tree, view->base, &view->entry );
|
||||
@ -196,7 +195,7 @@ index 924dff973ce..e7dfc516538 100644
|
||||
|
||||
*view_ret = view;
|
||||
|
||||
@@ -1646,54 +1502,219 @@ static inline void *unmap_extra_space( void *ptr, size_t total_size, size_t want
|
||||
@@ -1619,54 +1475,220 @@ static inline void *unmap_extra_space( void *ptr, size_t total_size, size_t want
|
||||
return ptr;
|
||||
}
|
||||
|
||||
@ -247,27 +246,24 @@ index 924dff973ce..e7dfc516538 100644
|
||||
+ intersect_end = min((char *)end, area->map_area_end);
|
||||
+
|
||||
+ assert(ROUND_ADDR(intersect_start, granularity_mask) == intersect_start);
|
||||
+ assert(ROUND_ADDR(intersect_end + granularity_mask - 1, granularity_mask) == intersect_end);
|
||||
+ assert(ROUND_ADDR(intersect_end + granularity_mask, granularity_mask) == intersect_end);
|
||||
+ assert(ROUND_ADDR(area->map_area_end, granularity_mask) == area->map_area_end);
|
||||
+
|
||||
+ alloc_start = ROUND_ADDR( (char *)area->map_area_end - size, granularity_mask );
|
||||
+
|
||||
+ if (alloc_start >= intersect_end)
|
||||
+ if (area->map_area_end - intersect_end >= area->size)
|
||||
{
|
||||
- if (preload_reserve_start <= start) return 0; /* no space in that area */
|
||||
- if (preload_reserve_start < end) end = preload_reserve_start;
|
||||
+ if ((area->result = try_map_free_area( area->map_area_start, alloc_start + size, area->step,
|
||||
+ alloc_start = ROUND_ADDR( (char *)area->map_area_end - size, granularity_mask );
|
||||
+ if ((area->result = try_map_free_area( intersect_end, alloc_start + size, area->step,
|
||||
+ alloc_start, area->size, area->unix_prot )))
|
||||
+ return 1;
|
||||
}
|
||||
- else if (preload_reserve_start <= start) start = preload_reserve_end;
|
||||
- else
|
||||
+
|
||||
+ alloc_start = ROUND_ADDR( intersect_end - area->size, granularity_mask );
|
||||
+ if (alloc_start >= intersect_start)
|
||||
{
|
||||
- /* range is split in two by the preloader reservation, try first part */
|
||||
- if ((alloc->result = find_reserved_free_area( start, preload_reserve_start, alloc->size,
|
||||
- alloc->top_down )))
|
||||
+ if (intersect_end - intersect_start >= area->size)
|
||||
+ {
|
||||
+ alloc_start = ROUND_ADDR( intersect_end - area->size, granularity_mask );
|
||||
+ if ((area->result = anon_mmap_fixed( alloc_start, area->size,
|
||||
+ area->unix_prot, 0 )) != alloc_start)
|
||||
+ ERR("Could not map in reserved area, alloc_start %p, size %p.\n",
|
||||
@ -291,10 +287,14 @@ index 924dff973ce..e7dfc516538 100644
|
||||
+ intersect_end = min((char *)end, area->map_area_end);
|
||||
+
|
||||
+ assert(ROUND_ADDR(intersect_start, granularity_mask) == intersect_start);
|
||||
+ assert(ROUND_ADDR(intersect_end + granularity_mask - 1, granularity_mask) == intersect_end);
|
||||
+ assert(ROUND_ADDR(intersect_end + granularity_mask, granularity_mask) == intersect_end);
|
||||
+ assert(ROUND_ADDR(area->map_area_start, granularity_mask) == area->map_area_start);
|
||||
+
|
||||
+ if (intersect_start - area->map_area_start >= area->size)
|
||||
+ {
|
||||
{
|
||||
- /* range is split in two by the preloader reservation, try first part */
|
||||
- if ((alloc->result = find_reserved_free_area( start, preload_reserve_start, alloc->size,
|
||||
- alloc->top_down )))
|
||||
+ if ((area->result = try_map_free_area( area->map_area_start, intersect_start, area->step,
|
||||
+ area->map_area_start, area->size, area->unix_prot )))
|
||||
return 1;
|
||||
@ -446,7 +446,7 @@ index 924dff973ce..e7dfc516538 100644
|
||||
/***********************************************************************
|
||||
* map_fixed_area
|
||||
*
|
||||
@@ -1765,48 +1786,11 @@ static NTSTATUS map_view( struct file_view **view_ret, void *base, size_t size,
|
||||
@@ -1738,48 +1760,11 @@ static NTSTATUS map_view( struct file_view **view_ret, void *base, size_t size,
|
||||
if (status != STATUS_SUCCESS) return status;
|
||||
ptr = base;
|
||||
}
|
||||
@ -498,7 +498,7 @@ index 924dff973ce..e7dfc516538 100644
|
||||
status = create_view( view_ret, ptr, size, vprot );
|
||||
if (status != STATUS_SUCCESS) unmap_area( ptr, size );
|
||||
return status;
|
||||
@@ -2453,6 +2437,7 @@ void virtual_init(void)
|
||||
@@ -2409,6 +2394,7 @@ void virtual_init(void)
|
||||
if (preload_reserve_start)
|
||||
address_space_start = min( address_space_start, preload_reserve_start );
|
||||
}
|
||||
|
@ -1,16 +1,14 @@
|
||||
From 479dfa05cc83b7ae8ab0f40862e74efedd98df48 Mon Sep 17 00:00:00 2001
|
||||
From 14825c31d376ab5e55991fd459583e3afd3dfcde Mon Sep 17 00:00:00 2001
|
||||
From: Paul Gofman <pgofman@codeweavers.com>
|
||||
Date: Tue, 2 Jun 2020 21:06:33 +0300
|
||||
Subject: [PATCH 4/4] ntdll: Exclude natively mapped areas from free areas
|
||||
list.
|
||||
Subject: [PATCH] ntdll: Exclude natively mapped areas from free areas list.
|
||||
|
||||
Signed-off-by: Paul Gofman <pgofman@codeweavers.com>
|
||||
---
|
||||
dlls/ntdll/unix/virtual.c | 130 ++++++++++++++++++++++++++++++--------
|
||||
1 file changed, 103 insertions(+), 27 deletions(-)
|
||||
dlls/ntdll/unix/virtual.c | 137 ++++++++++++++++++++++++++++++--------
|
||||
1 file changed, 109 insertions(+), 28 deletions(-)
|
||||
|
||||
diff --git a/dlls/ntdll/unix/virtual.c b/dlls/ntdll/unix/virtual.c
|
||||
index e7dfc516538..dad12b5a9f2 100644
|
||||
index 5bb9511be6d..f5281128543 100644
|
||||
--- a/dlls/ntdll/unix/virtual.c
|
||||
+++ b/dlls/ntdll/unix/virtual.c
|
||||
@@ -103,6 +103,7 @@ struct file_view
|
||||
@ -21,7 +19,7 @@ index e7dfc516538..dad12b5a9f2 100644
|
||||
|
||||
/* Conversion from VPROT_* to Win32 flags */
|
||||
static const BYTE VIRTUAL_Win32Flags[16] =
|
||||
@@ -877,7 +878,9 @@ static void dump_view( struct file_view *view )
|
||||
@@ -870,7 +871,9 @@ static void dump_view( struct file_view *view )
|
||||
BYTE prot = get_page_vprot( addr );
|
||||
|
||||
TRACE( "View: %p - %p", addr, addr + view->size - 1 );
|
||||
@ -32,7 +30,7 @@ index e7dfc516538..dad12b5a9f2 100644
|
||||
TRACE( " (builtin image)\n" );
|
||||
else if (view->protect & SEC_IMAGE)
|
||||
TRACE( " (image)\n" );
|
||||
@@ -1019,6 +1022,16 @@ static struct file_view *find_view_range( const void *addr, size_t size )
|
||||
@@ -1012,6 +1015,16 @@ static struct file_view *find_view_range( const void *addr, size_t size )
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -49,7 +47,7 @@ index e7dfc516538..dad12b5a9f2 100644
|
||||
|
||||
/***********************************************************************
|
||||
* try_map_free_area
|
||||
@@ -1026,21 +1039,27 @@ static struct file_view *find_view_range( const void *addr, size_t size )
|
||||
@@ -1019,21 +1032,27 @@ static struct file_view *find_view_range( const void *addr, size_t size )
|
||||
* Try mmaping some expected free memory region, eventually stepping and
|
||||
* retrying inside it, and return where it actually succeeded, or NULL.
|
||||
*/
|
||||
@ -82,7 +80,7 @@ index e7dfc516538..dad12b5a9f2 100644
|
||||
if ((step > 0 && (char *)end - (char *)start < step) ||
|
||||
(step < 0 && (char *)start - (char *)base < -step) ||
|
||||
step == 0)
|
||||
@@ -1502,15 +1521,6 @@ static inline void *unmap_extra_space( void *ptr, size_t total_size, size_t want
|
||||
@@ -1475,15 +1494,6 @@ static inline void *unmap_extra_space( void *ptr, size_t total_size, size_t want
|
||||
return ptr;
|
||||
}
|
||||
|
||||
@ -98,18 +96,18 @@ index e7dfc516538..dad12b5a9f2 100644
|
||||
static int CDECL alloc_area_in_reserved_or_between_callback( void *start, SIZE_T size, void *arg )
|
||||
{
|
||||
char *intersect_start, *intersect_end;
|
||||
@@ -1536,8 +1546,8 @@ static int CDECL alloc_area_in_reserved_or_between_callback( void *start, SIZE_T
|
||||
|
||||
if (alloc_start >= intersect_end)
|
||||
@@ -1509,8 +1519,8 @@ static int CDECL alloc_area_in_reserved_or_between_callback( void *start, SIZE_T
|
||||
if (area->map_area_end - intersect_end >= area->size)
|
||||
{
|
||||
- if ((area->result = try_map_free_area( area->map_area_start, alloc_start + size, area->step,
|
||||
alloc_start = ROUND_ADDR( (char *)area->map_area_end - size, granularity_mask );
|
||||
- if ((area->result = try_map_free_area( intersect_end, alloc_start + size, area->step,
|
||||
- alloc_start, area->size, area->unix_prot )))
|
||||
+ if ((area->result = try_map_free_area( area, area->map_area_start,
|
||||
+ if ((area->result = try_map_free_area( area, intersect_end,
|
||||
+ alloc_start + size, alloc_start )))
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -1571,8 +1581,8 @@ static int CDECL alloc_area_in_reserved_or_between_callback( void *start, SIZE_T
|
||||
@@ -1545,8 +1555,8 @@ static int CDECL alloc_area_in_reserved_or_between_callback( void *start, SIZE_T
|
||||
|
||||
if (intersect_start - area->map_area_start >= area->size)
|
||||
{
|
||||
@ -120,7 +118,7 @@ index e7dfc516538..dad12b5a9f2 100644
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -1627,8 +1637,7 @@ static void *alloc_free_area_in_range( struct alloc_area *area, char *base, char
|
||||
@@ -1601,8 +1611,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;
|
||||
|
||||
@ -130,7 +128,7 @@ index e7dfc516538..dad12b5a9f2 100644
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1637,8 +1646,7 @@ static void *alloc_free_area_in_range( struct alloc_area *area, char *base, char
|
||||
@@ -1611,8 +1620,7 @@ static void *alloc_free_area_in_range( struct alloc_area *area, char *base, char
|
||||
|| area->map_area_end - start < area->size)
|
||||
return NULL;
|
||||
|
||||
@ -140,7 +138,7 @@ index e7dfc516538..dad12b5a9f2 100644
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1648,6 +1656,7 @@ static void *alloc_free_area( void *limit, size_t size, BOOL top_down, int unix_
|
||||
@@ -1622,6 +1630,7 @@ static void *alloc_free_area( void *limit, size_t size, BOOL top_down, int unix_
|
||||
char *reserve_start, *reserve_end;
|
||||
struct alloc_area area;
|
||||
char *base, *end;
|
||||
@ -148,7 +146,7 @@ index e7dfc516538..dad12b5a9f2 100644
|
||||
int ranges_inc;
|
||||
|
||||
TRACE("limit %p, size %p, top_down %#x.\n", limit, (void *)size, top_down);
|
||||
@@ -1703,16 +1712,67 @@ static void *alloc_free_area( void *limit, size_t size, BOOL top_down, int unix_
|
||||
@@ -1677,16 +1686,67 @@ static void *alloc_free_area( void *limit, size_t size, BOOL top_down, int unix_
|
||||
{
|
||||
/* range is split in two by the preloader reservation, try first part. */
|
||||
if ((area.result = alloc_free_area_in_range( &area, base, reserve_start )))
|
||||
@ -219,7 +217,7 @@ index e7dfc516538..dad12b5a9f2 100644
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
@@ -1766,6 +1826,17 @@ static NTSTATUS map_fixed_area( void *base, size_t size, unsigned int vprot )
|
||||
@@ -1740,6 +1800,17 @@ static NTSTATUS map_fixed_area( void *base, size_t size, unsigned int vprot )
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
@ -237,7 +235,7 @@ index e7dfc516538..dad12b5a9f2 100644
|
||||
/***********************************************************************
|
||||
* map_view
|
||||
*
|
||||
@@ -1789,7 +1860,12 @@ static NTSTATUS map_view( struct file_view **view_ret, void *base, size_t size,
|
||||
@@ -1763,7 +1834,12 @@ static NTSTATUS map_view( struct file_view **view_ret, void *base, size_t size,
|
||||
else if (!(ptr = alloc_free_area( (void*)(get_zero_bits_64_mask( zero_bits_64 )
|
||||
& (UINT_PTR)user_space_limit), size, top_down, get_unix_prot( vprot ) )))
|
||||
{
|
||||
@ -251,6 +249,20 @@ index e7dfc516538..dad12b5a9f2 100644
|
||||
}
|
||||
status = create_view( view_ret, ptr, size, vprot );
|
||||
if (status != STATUS_SUCCESS) unmap_area( ptr, size );
|
||||
@@ -3222,7 +3298,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 */
|
||||
- BYTE commit = is_view_valloc( view ) ? 0 : VPROT_COMMITTED;
|
||||
+ BYTE commit;
|
||||
+
|
||||
+ if (view->protect & VPROT_NATIVE)
|
||||
+ continue;
|
||||
+
|
||||
+ commit = is_view_valloc( view ) ? 0 : VPROT_COMMITTED;
|
||||
|
||||
mprotect_range( view->base, view->size, commit, 0 );
|
||||
}
|
||||
--
|
||||
2.26.2
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user