[Pixman] [RFC PATCH 1/3] utils.[ch]: add FENCE_MALLOC_ACTIVE
Pekka Paalanen
ppaalanen at gmail.com
Fri May 8 05:45:35 PDT 2015
From: Pekka Paalanen <pekka.paalanen at collabora.co.uk>
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.
Signed-off-by: Pekka Paalanen <pekka.paalanen at collabora.co.uk>
---
test/utils.c | 6 +++---
test/utils.h | 9 +++++++++
2 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/test/utils.c b/test/utils.c
index 5663aec..f506875 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 defined (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..6b88bf2 100644
--- a/test/utils.h
+++ b/test/utils.h
@@ -86,6 +86,15 @@ 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
+#endif
+
/* Allocate memory that is bounded by protected pages,
* so that out-of-bounds access will cause segfaults
*/
--
2.3.6
More information about the Pixman
mailing list