Commit 72b97eeb authored by Alexandre Julliard's avatar Alexandre Julliard

ntdll: Add a helper function for memory allocations through mmap().

parent 74deee7d
......@@ -85,7 +85,6 @@
#define WIN32_NO_STATUS
#include "windef.h"
#include "winnt.h"
#include "wine/library.h"
#include "wine/server.h"
#include "wine/debug.h"
#include "unix_private.h"
......@@ -914,8 +913,8 @@ static BOOL add_fd_to_cache( HANDLE handle, int fd, enum server_fd_type type,
if (!entry) fd_cache[0] = fd_cache_initial_block;
else
{
void *ptr = wine_anon_mmap( NULL, FD_CACHE_BLOCK_SIZE * sizeof(union fd_cache_entry),
PROT_READ | PROT_WRITE, 0 );
void *ptr = anon_mmap_alloc( FD_CACHE_BLOCK_SIZE * sizeof(union fd_cache_entry),
PROT_READ | PROT_WRITE );
if (ptr == MAP_FAILED) return FALSE;
fd_cache[entry] = ptr;
}
......
......@@ -177,6 +177,7 @@ extern NTSTATUS alloc_object_attributes( const OBJECT_ATTRIBUTES *attr, struct o
data_size_t *ret_len ) DECLSPEC_HIDDEN;
extern void *anon_mmap_fixed( void *start, size_t size, int prot, int flags ) DECLSPEC_HIDDEN;
extern void *anon_mmap_alloc( size_t size, int prot ) DECLSPEC_HIDDEN;
extern void virtual_init(void) DECLSPEC_HIDDEN;
extern NTSTATUS virtual_map_ntdll( int fd, void **module ) DECLSPEC_HIDDEN;
extern ULONG_PTR get_system_affinity_mask(void) DECLSPEC_HIDDEN;
......
......@@ -217,6 +217,13 @@ void *anon_mmap_fixed( void *start, size_t size, int prot, int flags )
return mmap( start, size, prot, MAP_PRIVATE | MAP_ANON | MAP_FIXED | flags, -1, 0 );
}
/* allocate anonymous mmap() memory at any address */
void *anon_mmap_alloc( size_t size, int prot )
{
return mmap( NULL, size, prot, MAP_PRIVATE | MAP_ANON, -1, 0 );
}
static void mmap_add_reserved_area( void *addr, SIZE_T size )
{
struct reserved_area *area;
......@@ -756,7 +763,7 @@ static BOOL alloc_pages_vprot( const void *addr, size_t size )
for (i = idx >> pages_vprot_shift; i < (end + pages_vprot_mask) >> pages_vprot_shift; i++)
{
if (pages_vprot[i]) continue;
if ((ptr = wine_anon_mmap( NULL, pages_vprot_mask + 1, PROT_READ | PROT_WRITE, 0 )) == (void *)-1)
if ((ptr = anon_mmap_alloc( pages_vprot_mask + 1, PROT_READ | PROT_WRITE )) == MAP_FAILED)
return FALSE;
pages_vprot[i] = ptr;
}
......@@ -1299,8 +1306,8 @@ static struct file_view *alloc_view(void)
}
if (view_block_start == view_block_end)
{
void *ptr = wine_anon_mmap( NULL, view_block_size, PROT_READ | PROT_WRITE, 0 );
if (ptr == (void *)-1) return NULL;
void *ptr = anon_mmap_alloc( view_block_size, PROT_READ | PROT_WRITE );
if (ptr == MAP_FAILED) return NULL;
view_block_start = ptr;
view_block_end = view_block_start + view_block_size / sizeof(*view_block_start);
}
......@@ -1746,7 +1753,7 @@ static NTSTATUS map_view( struct file_view **view_ret, void *base, size_t size,
for (;;)
{
if ((ptr = wine_anon_mmap( NULL, view_size, get_unix_prot(vprot), 0 )) == (void *)-1)
if ((ptr = anon_mmap_alloc( view_size, get_unix_prot(vprot) )) == MAP_FAILED)
{
if (errno == ENOMEM) return STATUS_NO_MEMORY;
return STATUS_INVALID_PARAMETER;
......@@ -2405,9 +2412,9 @@ void virtual_init(void)
if (mmap_enum_reserved_areas( alloc_virtual_heap, &alloc_views, 1 ))
mmap_remove_reserved_area( alloc_views.base, alloc_views.size );
else
alloc_views.base = wine_anon_mmap( NULL, alloc_views.size, PROT_READ | PROT_WRITE, 0 );
alloc_views.base = anon_mmap_alloc( alloc_views.size, PROT_READ | PROT_WRITE );
assert( alloc_views.base != (void *)-1 );
assert( alloc_views.base != MAP_FAILED );
view_block_start = alloc_views.base;
view_block_end = view_block_start + view_block_size / sizeof(*view_block_start);
free_ranges = (void *)((char *)alloc_views.base + view_block_size);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment