summaryrefslogtreecommitdiff
path: root/headers.c
diff options
context:
space:
mode:
authorIvan Maidanski <ivmai@mail.ru>2014-03-30 12:31:49 +0400
committerIvan Maidanski <ivmai@mail.ru>2014-03-30 12:31:49 +0400
commit180b56cc54c765a8ba0283f718cdf64f45090ccf (patch)
treeed04e52a26b5b6825315f238c202913130cfc597 /headers.c
parent5a4bcb2aa28f7af312922b1ecbb2f729c94caab1 (diff)
downloadbdwgc-180b56cc54c765a8ba0283f718cdf64f45090ccf.tar.gz
Fix GET_MEM argument rounding in GC_scratch_alloc and similar
(Prevent abort in GC_unix_mmap_get_mem if the allocation size is not a multiple of a page size.) * backgraph.c (new_back_edges, push_in_progress): Use ROUNDUP_PAGESIZE_IF_MMAP() to adjust GET_MEM() argument (when needed). * headers.c (GC_scratch_alloc): Likewise. * misc.c (GC_envfile_init): Likewise. * include/private/gc_priv.h (ROUNDUP_PAGESIZE_IF_MMAP): New macro. * include/private/gcconfig.h (MMAP_SUPPORTED): Move definition from os_dep.c (as needed for ROUNDUP_PAGESIZE_IF_MMAP() definition). * include/private/gcconfig.h (GET_MEM): Refine comment (regarding its argument).
Diffstat (limited to 'headers.c')
-rw-r--r--headers.c12
1 files changed, 4 insertions, 8 deletions
diff --git a/headers.c b/headers.c
index 69f15751..ea83378e 100644
--- a/headers.c
+++ b/headers.c
@@ -129,25 +129,21 @@ GC_INNER ptr_t GC_scratch_alloc(size_t bytes)
if (bytes_to_get <= bytes) {
/* Undo the damage, and get memory directly */
- bytes_to_get = bytes;
-# ifdef USE_MMAP
- bytes_to_get = ROUNDUP_PAGESIZE(bytes_to_get);
-# endif
+ bytes_to_get = ROUNDUP_PAGESIZE_IF_MMAP(bytes);
result = (ptr_t)GET_MEM(bytes_to_get);
GC_add_to_our_memory(result, bytes_to_get);
scratch_free_ptr -= bytes;
GC_scratch_last_end_ptr = result + bytes;
return(result);
}
+
+ bytes_to_get = ROUNDUP_PAGESIZE_IF_MMAP(bytes_to_get); /* for safety */
result = (ptr_t)GET_MEM(bytes_to_get);
GC_add_to_our_memory(result, bytes_to_get);
if (result == 0) {
WARN("Out of memory - trying to allocate less\n", 0);
scratch_free_ptr -= bytes;
- bytes_to_get = bytes;
-# ifdef USE_MMAP
- bytes_to_get = ROUNDUP_PAGESIZE(bytes_to_get);
-# endif
+ bytes_to_get = ROUNDUP_PAGESIZE_IF_MMAP(bytes);
result = (ptr_t)GET_MEM(bytes_to_get);
GC_add_to_our_memory(result, bytes_to_get);
return result;