summaryrefslogtreecommitdiff
path: root/src/lib/eo/eo_add_fallback.c
diff options
context:
space:
mode:
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>2018-01-12 02:59:34 +0900
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2018-01-12 03:02:43 +0900
commitf32f0d89f4c42080ff28d2b5a201f6ce8e0206b1 (patch)
tree95e23ee1b442d3602f1b9bc0d18f1ae94bd7a420 /src/lib/eo/eo_add_fallback.c
parentfb048e73120b39095cc87aa4f8d7f3d397a93c56 (diff)
mmap memory allocation - do not used when under valgrind
we can't sensibly use things like massif to track memory if we bypass itr with mmaping -1 fd anonymous memory... so if built with valgrind support and running under valgrind, use malloc/calloc and free so these tools actually do something useful for these bits of memory.
Diffstat (limited to 'src/lib/eo/eo_add_fallback.c')
-rw-r--r--src/lib/eo/eo_add_fallback.c39
1 files changed, 27 insertions, 12 deletions
diff --git a/src/lib/eo/eo_add_fallback.c b/src/lib/eo/eo_add_fallback.c
index c38a827..f3a82f2 100644
--- a/src/lib/eo/eo_add_fallback.c
+++ b/src/lib/eo/eo_add_fallback.c
@@ -2,6 +2,11 @@
2# include <config.h> 2# include <config.h>
3#endif 3#endif
4 4
5#ifdef HAVE_VALGRIND
6# include <valgrind.h>
7# include <memcheck.h>
8#endif
9
5#if defined HAVE_DLADDR && ! defined _WIN32 10#if defined HAVE_DLADDR && ! defined _WIN32
6# include <dlfcn.h> 11# include <dlfcn.h>
7#endif 12#endif
@@ -32,20 +37,26 @@ static void *
32_eo_call_stack_mem_alloc(size_t size) 37_eo_call_stack_mem_alloc(size_t size)
33{ 38{
34#ifdef HAVE_MMAP 39#ifdef HAVE_MMAP
35 // allocate eo call stack via mmped anon segment if on linux - more 40# ifdef HAVE_VALGRIND
36 // secure and safe. also gives page aligned memory allowing madvise 41 if (RUNNING_ON_VALGRIND) return calloc(1, size);
37 void *ptr; 42 else
38 size_t newsize; 43# endif
39 newsize = MEM_PAGE_SIZE * ((size + MEM_PAGE_SIZE - 1) /
40 MEM_PAGE_SIZE);
41 ptr = mmap(NULL, newsize, PROT_READ | PROT_WRITE,
42 MAP_PRIVATE | MAP_ANON, -1, 0);
43 if (ptr == MAP_FAILED)
44 { 44 {
45 ERR("eo call stack mmap failed."); 45 // allocate eo call stack via mmped anon segment if on linux - more
46 return NULL; 46 // secure and safe. also gives page aligned memory allowing madvise
47 void *ptr;
48 size_t newsize;
49 newsize = MEM_PAGE_SIZE * ((size + MEM_PAGE_SIZE - 1) /
50 MEM_PAGE_SIZE);
51 ptr = mmap(NULL, newsize, PROT_READ | PROT_WRITE,
52 MAP_PRIVATE | MAP_ANON, -1, 0);
53 if (ptr == MAP_FAILED)
54 {
55 ERR("eo call stack mmap failed.");
56 return NULL;
57 }
58 return ptr;
47 } 59 }
48 return ptr;
49#else 60#else
50 //in regular cases just use malloc 61 //in regular cases just use malloc
51 return calloc(1, size); 62 return calloc(1, size);
@@ -56,6 +67,10 @@ static void
56_eo_call_stack_mem_free(void *ptr, size_t size) 67_eo_call_stack_mem_free(void *ptr, size_t size)
57{ 68{
58#ifdef HAVE_MMAP 69#ifdef HAVE_MMAP
70# ifdef HAVE_VALGRIND
71 if (RUNNING_ON_VALGRIND) free(ptr);
72 else
73# endif
59 munmap(ptr, size); 74 munmap(ptr, size);
60#else 75#else
61 (void) size; 76 (void) size;