scripts

misc scripts and tools
git clone git://git.2f30.org/scripts
Log | Files | Refs

commit 29bc2555e84b030a3e8602bd5234f78bd30d825f
parent 55d0caa0cd80f1787d3e22dc807c4456064a9dce
Author: sin <sin@2f30.org>
Date:   Fri,  2 Aug 2013 12:01:02 +0100

Use mmap_aligned() instead of sbrk_aligned()

Diffstat:
Mrandom/rballoc.c | 13++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/random/rballoc.c b/random/rballoc.c @@ -94,17 +94,16 @@ alloc_object(size_t siz) } static inline void * -sbrk_aligned(size_t align, size_t siz) +mmap_aligned(size_t align, size_t siz) { void *p; if ((align - 1) & align) return NULL; - sd.base = sbrk(siz + align); - if (sd.base == (void *)-1) + p = mmap(0, siz + align, PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANON, -1, 0); + if (p == MAP_FAILED) return NULL; - sd.siz += siz + align; - p = sd.base; p = (void *)(((uintptr_t)p + align) & ~(align - 1)); return p; } @@ -130,7 +129,7 @@ aligned_malloc(size_t align, size_t siz) unlock(&rblock); return NULL; } - p = sbrk_aligned(align, siz); + p = mmap_aligned(align, siz); if (!p) { unlock(&rblock); return NULL; @@ -190,7 +189,7 @@ realloc(void *oldp, size_t siz) unlock(&rblock); return NULL; } - newan->buf = sbrk_aligned(MINALIGNMENT, siz); + newan->buf = mmap_aligned(MINALIGNMENT, siz); if (!newan->buf) { free_object(newan, sizeof(*newan)); unlock(&rblock);