urcu-bp: add mremap wrapper for non-linux systems
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 29 Jun 2011 20:38:06 +0000 (16:38 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 29 Jun 2011 20:38:06 +0000 (16:38 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
urcu-bp.c

index 2973574436b7977e491df3a6634e5c99d2ea2a85..2b531a3ca679ae95a00e21f773b8d70044e47b4a 100644 (file)
--- a/urcu-bp.c
+++ b/urcu-bp.c
 #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
This page took 0.025894 seconds and 4 git commands to generate.