Commit 5dc2d7fc authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

block: include left and right padding when memory mapping

This avoids reallocating and copying the block in block_Realloc() in
some cases.
parent af8f9bb6
...@@ -319,6 +319,10 @@ block_t *block_mmap_Alloc (void *addr, size_t length) ...@@ -319,6 +319,10 @@ block_t *block_mmap_Alloc (void *addr, size_t length)
if (addr == MAP_FAILED) if (addr == MAP_FAILED)
return NULL; return NULL;
long page_mask = sysconf(_SC_PAGESIZE) - 1;
size_t left = ((uintptr_t)addr) & page_mask;
size_t right = (-length) & page_mask;
block_t *block = malloc (sizeof (*block)); block_t *block = malloc (sizeof (*block));
if (block == NULL) if (block == NULL)
{ {
...@@ -326,7 +330,9 @@ block_t *block_mmap_Alloc (void *addr, size_t length) ...@@ -326,7 +330,9 @@ block_t *block_mmap_Alloc (void *addr, size_t length)
return NULL; return NULL;
} }
block_Init (block, addr, length); block_Init (block, ((char *)addr) - left, left + length + right);
block->p_buffer = addr;
block->i_buffer = length;
block->pf_release = block_mmap_Release; block->pf_release = block_mmap_Release;
return block; return block;
} }
......
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