Rebase against 48020f4846cca1a02f4e1dc037e2cc2068df5e9c.

This commit is contained in:
Zebediah Figura
2020-06-02 18:20:16 -05:00
parent 676f261e5e
commit a4d98c48f9
27 changed files with 312 additions and 335 deletions

View File

@@ -1,4 +1,4 @@
From 7dd611828bb181c29d20544c7dcae8f52215ae70 Mon Sep 17 00:00:00 2001
From ca116113c19ee17d2e8283abe4edf27f76df2148 Mon Sep 17 00:00:00 2001
From: Paul Gofman <gofmanp@gmail.com>
Date: Thu, 9 Jan 2020 15:05:09 +0300
Subject: [PATCH] ntdll: Stop search on mmap() error in try_map_free_area().
@@ -6,14 +6,14 @@ Subject: [PATCH] ntdll: Stop search on mmap() error in try_map_free_area().
The anon mmap errors do not depend on start address hint. Ignoring them
makes the search take incredible time until it fails.
---
dlls/ntdll/virtual.c | 10 ++++++++--
dlls/ntdll/unix/virtual.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/dlls/ntdll/virtual.c b/dlls/ntdll/virtual.c
index c6f3c1685e0..37f83efa8fc 100644
--- a/dlls/ntdll/virtual.c
+++ b/dlls/ntdll/virtual.c
@@ -767,8 +767,14 @@ static void* try_map_free_area( void *base, void *end, ptrdiff_t step,
diff --git a/dlls/ntdll/unix/virtual.c b/dlls/ntdll/unix/virtual.c
index 0346d0d9753..c29f695d694 100644
--- a/dlls/ntdll/unix/virtual.c
+++ b/dlls/ntdll/unix/virtual.c
@@ -1016,8 +1016,14 @@ static void* try_map_free_area( void *base, void *end, ptrdiff_t step,
return start;
TRACE( "Found free area is already mapped, start %p.\n", start );

View File

@@ -1,4 +1,4 @@
From dae806ca4aa1d25e65539f33b784791a9b357a77 Mon Sep 17 00:00:00 2001
From b2c9894cd6a81eaa9f7dd4bce3f9cbfbec17d021 Mon Sep 17 00:00:00 2001
From: Paul Gofman <gofmanp@gmail.com>
Date: Thu, 16 Jan 2020 16:09:24 +0300
Subject: [PATCH] ntdll: Use MAP_FIXED_NOREPLACE flag in try_map_free_area() if
@@ -7,14 +7,14 @@ Subject: [PATCH] ntdll: Use MAP_FIXED_NOREPLACE flag in try_map_free_area() if
Avoids actual mapping followed by unmapping back if the memory range is
already mapped.
---
dlls/ntdll/virtual.c | 12 +++++++++---
dlls/ntdll/unix/virtual.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/dlls/ntdll/virtual.c b/dlls/ntdll/virtual.c
index 37f83efa8fc..4ee30af6548 100644
--- a/dlls/ntdll/virtual.c
+++ b/dlls/ntdll/virtual.c
@@ -759,22 +759,28 @@ static struct wine_rb_entry *find_view_inside_range( void **base_ptr, void **end
diff --git a/dlls/ntdll/unix/virtual.c b/dlls/ntdll/unix/virtual.c
index c29f695d694..8d3e25481ec 100644
--- a/dlls/ntdll/unix/virtual.c
+++ b/dlls/ntdll/unix/virtual.c
@@ -1008,22 +1008,28 @@ static struct wine_rb_entry *find_view_inside_range( void **base_ptr, void **end
static void* try_map_free_area( void *base, void *end, ptrdiff_t step,
void *start, size_t size, int unix_prot )
{

View File

@@ -1,4 +1,4 @@
From 15fdb467ef17b05df48abe7f5f23e718ce876d57 Mon Sep 17 00:00:00 2001
From 9f7320fe58c85f1b53301c2c9a2a80fa8d4ed228 Mon Sep 17 00:00:00 2001
From: Paul Gofman <gofmanp@gmail.com>
Date: Mon, 25 Nov 2019 12:19:20 +0300
Subject: [PATCH] ntdll: Force bottom up allocation order for 64 bit arch
@@ -7,14 +7,14 @@ Subject: [PATCH] ntdll: Force bottom up allocation order for 64 bit arch
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=48175
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=46568
---
dlls/ntdll/virtual.c | 12 ++++++++++--
dlls/ntdll/unix/virtual.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/dlls/ntdll/virtual.c b/dlls/ntdll/virtual.c
index 4ee30af6548..ba9ecd5a5b1 100644
--- a/dlls/ntdll/virtual.c
+++ b/dlls/ntdll/virtual.c
@@ -1492,13 +1492,19 @@ static NTSTATUS map_view( struct file_view **view_ret, void *base, size_t size,
diff --git a/dlls/ntdll/unix/virtual.c b/dlls/ntdll/unix/virtual.c
index 8d3e25481ec..dc20e827141 100644
--- a/dlls/ntdll/unix/virtual.c
+++ b/dlls/ntdll/unix/virtual.c
@@ -1715,13 +1715,19 @@ static NTSTATUS map_view( struct file_view **view_ret, void *base, size_t size,
}
else
{
@@ -32,10 +32,10 @@ index 4ee30af6548..ba9ecd5a5b1 100644
+ alloc.limit = min(alloc.limit, (void *)0x7ffffe000000);
+ }
+
if (unix_funcs->mmap_enum_reserved_areas( alloc_reserved_area_callback, &alloc, top_down ))
if (mmap_enum_reserved_areas( alloc_reserved_area_callback, &alloc, top_down ))
{
ptr = alloc.result;
@@ -1508,7 +1514,7 @@ static NTSTATUS map_view( struct file_view **view_ret, void *base, size_t size,
@@ -1731,7 +1737,7 @@ static NTSTATUS map_view( struct file_view **view_ret, void *base, size_t size,
goto done;
}
@@ -43,8 +43,8 @@ index 4ee30af6548..ba9ecd5a5b1 100644
+ if (is_win64 || zero_bits_64)
{
if (!(ptr = map_free_area( address_space_start, alloc.limit, size,
top_down, VIRTUAL_GetUnixProt(vprot) )))
@@ -1517,6 +1523,8 @@ static NTSTATUS map_view( struct file_view **view_ret, void *base, size_t size,
top_down, get_unix_prot(vprot) )))
@@ -1740,6 +1746,8 @@ static NTSTATUS map_view( struct file_view **view_ret, void *base, size_t size,
goto done;
}
@@ -52,7 +52,7 @@ index 4ee30af6548..ba9ecd5a5b1 100644
+
for (;;)
{
if ((ptr = wine_anon_mmap( NULL, view_size, VIRTUAL_GetUnixProt(vprot), 0 )) == (void *)-1)
if ((ptr = wine_anon_mmap( NULL, view_size, get_unix_prot(vprot), 0 )) == (void *)-1)
--
2.26.2

View File

@@ -1,18 +1,18 @@
From a95074355fd65c1396ac0fbd9fbc1c2c151b434b Mon Sep 17 00:00:00 2001
From e521333684d1286fff7b6625515d13ad6f3fcba3 Mon Sep 17 00:00:00 2001
From: Paul Gofman <gofmanp@gmail.com>
Date: Tue, 14 Jan 2020 21:39:23 +0300
Subject: [PATCH] ntdll: Increase step after failed map attempt in
try_map_free_area().
---
dlls/ntdll/virtual.c | 1 +
dlls/ntdll/unix/virtual.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/dlls/ntdll/virtual.c b/dlls/ntdll/virtual.c
index ba9ecd5a5b1..86062cd4546 100644
--- a/dlls/ntdll/virtual.c
+++ b/dlls/ntdll/virtual.c
@@ -787,6 +787,7 @@ static void* try_map_free_area( void *base, void *end, ptrdiff_t step,
diff --git a/dlls/ntdll/unix/virtual.c b/dlls/ntdll/unix/virtual.c
index dc20e827141..720d45ecb9f 100644
--- a/dlls/ntdll/unix/virtual.c
+++ b/dlls/ntdll/unix/virtual.c
@@ -1036,6 +1036,7 @@ static void* try_map_free_area( void *base, void *end, ptrdiff_t step,
step == 0)
break;
start = (char *)start + step;

View File

@@ -1,17 +1,17 @@
From d757532f375dee8d7b717e546ef14406ebbc3653 Mon Sep 17 00:00:00 2001
From df7b650d5e17afa411024b88d1920d0910947a6b Mon Sep 17 00:00:00 2001
From: Paul Gofman <pgofman@codeweavers.com>
Date: Tue, 14 Jan 2020 21:42:21 +0300
Subject: [PATCH] ntdll: Use free area list for virtual memory allocation.
---
dlls/ntdll/virtual.c | 319 +++++++++++++++++++++++++++----------------
1 file changed, 204 insertions(+), 115 deletions(-)
dlls/ntdll/unix/virtual.c | 318 ++++++++++++++++++++++++--------------
1 file changed, 204 insertions(+), 114 deletions(-)
diff --git a/dlls/ntdll/virtual.c b/dlls/ntdll/virtual.c
index 86062cd4546..81592a84715 100644
--- a/dlls/ntdll/virtual.c
+++ b/dlls/ntdll/virtual.c
@@ -190,7 +190,11 @@ static BYTE *pages_vprot;
diff --git a/dlls/ntdll/unix/virtual.c b/dlls/ntdll/unix/virtual.c
index 720d45ecb9f..e323f4290bf 100644
--- a/dlls/ntdll/unix/virtual.c
+++ b/dlls/ntdll/unix/virtual.c
@@ -192,7 +192,11 @@ static BYTE *pages_vprot;
#endif
static struct file_view *view_block_start, *view_block_end, *next_free_view;
@@ -23,7 +23,7 @@ index 86062cd4546..81592a84715 100644
static void *preload_reserve_start;
static void *preload_reserve_end;
static BOOL use_locks;
@@ -235,13 +239,13 @@ static struct range_entry *free_ranges_lower_bound( void *addr )
@@ -528,13 +532,13 @@ static struct range_entry *free_ranges_lower_bound( void *addr )
*
* Updates the free_ranges after a new view has been created.
*/
@@ -40,7 +40,7 @@ index 86062cd4546..81592a84715 100644
/* free_ranges initial value is such that the view is either inside range or before another one. */
assert( range != free_ranges_end );
assert( range->end > view_base || next != free_ranges_end );
@@ -252,7 +256,7 @@ static void free_ranges_insert_view( struct file_view *view )
@@ -545,7 +549,7 @@ static void free_ranges_insert_view( struct file_view *view )
(range->end == view_base && next->base >= view_end))
{
/* on Win64, assert that it's correctly aligned so we're not going to be in trouble later */
@@ -49,7 +49,7 @@ index 86062cd4546..81592a84715 100644
WARN( "range %p - %p is already mapped\n", view_base, view_end );
return;
}
@@ -292,6 +296,12 @@ static void free_ranges_insert_view( struct file_view *view )
@@ -585,6 +589,12 @@ static void free_ranges_insert_view( struct file_view *view )
}
}
@@ -62,7 +62,7 @@ index 86062cd4546..81592a84715 100644
/***********************************************************************
* free_ranges_remove_view
@@ -322,6 +332,7 @@ static void free_ranges_remove_view( struct file_view *view )
@@ -615,6 +625,7 @@ static void free_ranges_remove_view( struct file_view *view )
return;
}
#endif
@@ -70,7 +70,7 @@ index 86062cd4546..81592a84715 100644
/* free_ranges initial value is such that the view is either inside range or before another one. */
assert( range != free_ranges_end );
@@ -712,44 +723,6 @@ static struct file_view *find_view_range( const void *addr, size_t size )
@@ -961,44 +972,6 @@ static struct file_view *find_view_range( const void *addr, size_t size )
}
@@ -115,7 +115,7 @@ index 86062cd4546..81592a84715 100644
/***********************************************************************
* try_map_free_area
*
@@ -793,65 +766,11 @@ static void* try_map_free_area( void *base, void *end, ptrdiff_t step,
@@ -1042,65 +1015,11 @@ static void* try_map_free_area( void *base, void *end, ptrdiff_t step,
return NULL;
}
@@ -181,27 +181,27 @@ index 86062cd4546..81592a84715 100644
*/
static void *find_reserved_free_area( void *base, void *end, size_t size, int top_down )
{
@@ -1065,8 +984,7 @@ static void delete_view( struct file_view *view ) /* [in] View */
@@ -1314,8 +1233,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 );
- if (unix_funcs->mmap_is_in_reserved_area( view->base, view->size ))
- if (mmap_is_in_reserved_area( view->base, view->size ))
- free_ranges_remove_view( view );
+ free_ranges_remove_view( view );
wine_rb_remove( &views_tree, &view->entry );
*(struct file_view **)view = next_free_view;
next_free_view = view;
@@ -1114,8 +1032,7 @@ static NTSTATUS create_view( struct file_view **view_ret, void *base, size_t siz
@@ -1363,8 +1281,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 );
- if (unix_funcs->mmap_is_in_reserved_area( view->base, view->size ))
- if (mmap_is_in_reserved_area( view->base, view->size ))
- free_ranges_insert_view( view );
+ free_ranges_insert_view( view );
*view_ret = view;
@@ -1373,6 +1290,7 @@ struct alloc_area
@@ -1596,6 +1513,7 @@ struct alloc_area
int top_down;
void *limit;
void *result;
@@ -209,7 +209,7 @@ index 86062cd4546..81592a84715 100644
};
/***********************************************************************
@@ -1414,6 +1332,179 @@ static int CDECL alloc_reserved_area_callback( void *start, SIZE_T size, void *a
@@ -1637,6 +1555,179 @@ static int CDECL alloc_reserved_area_callback( void *start, SIZE_T size, void *a
return 0;
}
@@ -357,7 +357,7 @@ index 86062cd4546..81592a84715 100644
+ if (!start || start >= end || (char *)end - (char *)start < size)
+ continue;
+ }
+ unix_funcs->mmap_enum_reserved_areas( alloc_area_in_reserved_or_between_callback, &area, top_down );
+ mmap_enum_reserved_areas( alloc_area_in_reserved_or_between_callback, &area, top_down );
+ if (area.result)
+ return area.result;
+
@@ -389,11 +389,11 @@ index 86062cd4546..81592a84715 100644
/***********************************************************************
* map_fixed_area
*
@@ -1499,11 +1590,15 @@ static NTSTATUS map_view( struct file_view **view_ret, void *base, size_t size,
@@ -1722,11 +1813,15 @@ static NTSTATUS map_view( struct file_view **view_ret, void *base, size_t size,
alloc.size = size;
alloc.top_down = top_down;
alloc.limit = (void*)(get_zero_bits_64_mask( zero_bits_64 ) & (UINT_PTR)user_space_limit);
+ alloc.unix_prot = VIRTUAL_GetUnixProt(vprot);
+ alloc.unix_prot = get_unix_prot( vprot );
- if (is_win64 && !top_down)
+ if (is_win64 || zero_bits_64)
@@ -407,16 +407,15 @@ index 86062cd4546..81592a84715 100644
+ goto done;
}
if (unix_funcs->mmap_enum_reserved_areas( alloc_reserved_area_callback, &alloc, top_down ))
@@ -1514,16 +1609,6 @@ static NTSTATUS map_view( struct file_view **view_ret, void *base, size_t size,
return STATUS_INVALID_PARAMETER;
if (mmap_enum_reserved_areas( alloc_reserved_area_callback, &alloc, top_down ))
@@ -1738,15 +1833,6 @@ static NTSTATUS map_view( struct file_view **view_ret, void *base, size_t size,
goto done;
}
-
- if (is_win64 || zero_bits_64)
- {
- if (!(ptr = map_free_area( address_space_start, alloc.limit, size,
- top_down, VIRTUAL_GetUnixProt(vprot) )))
- top_down, get_unix_prot(vprot) )))
- return STATUS_NO_MEMORY;
- TRACE( "got mem with map_free_area %p-%p\n", ptr, (char *)ptr + size );
- goto done;
@@ -425,7 +424,7 @@ index 86062cd4546..81592a84715 100644
view_size = size + granularity_mask + 1;
for (;;)
@@ -2256,10 +2341,14 @@ void virtual_init(void)
@@ -2466,10 +2552,14 @@ void virtual_init(void)
pages_vprot = (void *)((char *)alloc_views.base + 2 * view_block_size);
wine_rb_init( &views_tree, compare_view );
@@ -441,7 +440,7 @@ index 86062cd4546..81592a84715 100644
+
/* make the DOS area accessible (except the low 64K) to hide bugs in broken apps like Excel 2003 */
size = (char *)address_space_start - (char *)0x10000;
if (size && unix_funcs->mmap_is_in_reserved_area( (void*)0x10000, size ) == 1)
if (size && mmap_is_in_reserved_area( (void*)0x10000, size ) == 1)
--
2.26.2

View File

@@ -1,18 +1,18 @@
From 0c26b2508ad1fc3c5bfb8eb775fb21febfeb4c0e Mon Sep 17 00:00:00 2001
From 81a8c626f834f3b2195980e84e2f5fc0a5b1e0e6 Mon Sep 17 00:00:00 2001
From: Paul Gofman <pgofman@codeweavers.com>
Date: Tue, 2 Jun 2020 21:06:33 +0300
Subject: [PATCH] ntdll: Permanently exclude natively mapped areas from free
areas list.
---
dlls/ntdll/virtual.c | 25 +++++++++++++++++++++++++
dlls/ntdll/unix/virtual.c | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/dlls/ntdll/virtual.c b/dlls/ntdll/virtual.c
index 81592a84715..6c6efea0285 100644
--- a/dlls/ntdll/virtual.c
+++ b/dlls/ntdll/virtual.c
@@ -112,6 +112,9 @@ static const BYTE VIRTUAL_Win32Flags[16] =
diff --git a/dlls/ntdll/unix/virtual.c b/dlls/ntdll/unix/virtual.c
index e323f4290bf..778f5d8c3b8 100644
--- a/dlls/ntdll/unix/virtual.c
+++ b/dlls/ntdll/unix/virtual.c
@@ -123,6 +123,9 @@ static const BYTE VIRTUAL_Win32Flags[16] =
static struct wine_rb_tree views_tree;
@@ -22,7 +22,7 @@ index 81592a84715..6c6efea0285 100644
static RTL_CRITICAL_SECTION csVirtual;
static RTL_CRITICAL_SECTION_DEBUG critsect_debug =
{
@@ -755,6 +758,13 @@ static void* try_map_free_area( void *base, void *end, ptrdiff_t step,
@@ -1004,6 +1007,13 @@ static void* try_map_free_area( void *base, void *end, ptrdiff_t step,
if (ptr != (void *)-1)
munmap( ptr, size );
@@ -36,7 +36,7 @@ index 81592a84715..6c6efea0285 100644
if ((step > 0 && (char *)end - (char *)start < step) ||
(step < 0 && (char *)start - (char *)base < -step) ||
step == 0)
@@ -1594,9 +1604,24 @@ static NTSTATUS map_view( struct file_view **view_ret, void *base, size_t size,
@@ -1817,9 +1827,24 @@ static NTSTATUS map_view( struct file_view **view_ret, void *base, size_t size,
if (is_win64 || zero_bits_64)
{