[Pixman] [PATCH v2 1/3] utils.[ch]: add FENCE_MALLOC_ACTIVE
Pekka Paalanen
ppaalanen at gmail.com
Fri Aug 28 04:53:36 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.
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 at collabora.co.uk>
---
test/utils.c | 6 +++---
test/utils.h | 11 +++++++++++
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
*/
--
2.4.6
More information about the Pixman
mailing list