From: Mathieu Desnoyers Date: Wed, 29 Jun 2011 20:38:06 +0000 (-0400) Subject: urcu-bp: add mremap wrapper for non-linux systems X-Git-Tag: v0.6.4~6 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=45a4872f3dfacfa47095c1044cabc5eb2a240696;p=userspace-rcu.git urcu-bp: add mremap wrapper for non-linux systems Signed-off-by: Mathieu Desnoyers --- diff --git a/urcu-bp.c b/urcu-bp.c index 2973574..2b531a3 100644 --- a/urcu-bp.c +++ b/urcu-bp.c @@ -45,6 +45,35 @@ #define MAP_ANONYMOUS MAP_ANON #endif +#ifndef __linux__ + +#define MREMAP_MAYMOVE 1 +#define MREMAP_FIXED 2 + +/* + * mremap wrapper for non-Linux systems. Maps a RW, anonymous private mapping. + * This is not generic. +*/ +void *mremap(void *old_address, size_t old_size, size_t new_size, int flags) +{ + void *new_arena; + + assert(flags & MREMAP_MAYMOVE); + assert(!(flags & MREMAP_FIXED)); + new_address = mmap(old_address, new_size, + PROT_READ | PROT_WRITE, + MAP_ANONYMOUS | MAP_PRIVATE, + -1, 0); + if (new_address == MAP_FAILED) + return MAP_FAILED; + if (old_address) { + memcpy(new_address, old_address, old_size); + munmap(old_address, old_size); + } + return new_address; +} +#endif + /* Sleep delay in us */ #define RCU_SLEEP_DELAY 1000 #define ARENA_INIT_ALLOC 16