summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPekka Paalanen <pekka.paalanen@collabora.co.uk>2015-05-07 14:21:30 +0300
committerPekka Paalanen <pekka.paalanen@collabora.co.uk>2015-09-01 17:05:58 +0300
commitc70ddd5c9e12d87ff461d73a6f53b00d52925cf5 (patch)
treecda248189ccd42cd42c68fe66f0f271c475554ac
parenta82e519944e5d1af41cc94a14d9ae1fe0e430e68 (diff)
utils.[ch]: add FENCE_MALLOC_ACTIVE
Define a new token to simplify checking whether fence_malloc() actually can catch out-of-bounds access. This will be used in the future to skip tests that rely on fence_malloc checking functionality. Changes in v2: - #define FENCE_MALLOC_ACTIVE always, but change its value to help catch use of it without including utils.h Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk> Reviewed-by: Ben Avison <bavison@riscosopen.org>
-rw-r--r--test/utils.c6
-rw-r--r--test/utils.h11
2 files changed, 14 insertions, 3 deletions
diff --git a/test/utils.c b/test/utils.c
index 5663aec..e872791 100644
--- a/test/utils.c
+++ b/test/utils.c
@@ -377,7 +377,7 @@ typedef struct
int n_bytes;
} info_t;
-#if defined(HAVE_MPROTECT) && defined(HAVE_GETPAGESIZE) && defined(HAVE_SYS_MMAN_H) && defined(HAVE_MMAP)
+#if FENCE_MALLOC_ACTIVE
/* This is apparently necessary on at least OS X */
#ifndef MAP_ANONYMOUS
@@ -445,7 +445,7 @@ fence_free (void *data)
munmap (info->addr, info->n_bytes);
}
-#else
+#else /* FENCE_MALLOC_ACTIVE */
void *
fence_malloc (int64_t len)
@@ -459,7 +459,7 @@ fence_free (void *data)
free (data);
}
-#endif
+#endif /* FENCE_MALLOC_ACTIVE */
uint8_t *
make_random_bytes (int n_bytes)
diff --git a/test/utils.h b/test/utils.h
index fc10524..6018354 100644
--- a/test/utils.h
+++ b/test/utils.h
@@ -86,6 +86,17 @@ is_little_endian (void)
void
image_endian_swap (pixman_image_t *img);
+#if defined (HAVE_MPROTECT) && defined (HAVE_GETPAGESIZE) && \
+ defined (HAVE_SYS_MMAN_H) && defined (HAVE_MMAP)
+/* fence_malloc and friends have working fence implementation.
+ * Without this, fence_malloc still allocs but does not catch
+ * out-of-bounds accesses.
+ */
+#define FENCE_MALLOC_ACTIVE 1
+#else
+#define FENCE_MALLOC_ACTIVE 0
+#endif
+
/* Allocate memory that is bounded by protected pages,
* so that out-of-bounds access will cause segfaults
*/