utils.[ch]: add FENCE_MALLOC_ACTIVE
authorPekka Paalanen <pekka.paalanen@collabora.co.uk>
Thu, 7 May 2015 11:21:30 +0000 (14:21 +0300)
committerPekka Paalanen <pekka.paalanen@collabora.co.uk>
Tue, 1 Sep 2015 14:05:58 +0000 (17:05 +0300)
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>
test/utils.c
test/utils.h

index 5663aecbe48e7a8330074c1a4e0d948a81a3aada..e872791ac379413ea9d1cb7af3e76d91cd88dff0 100644 (file)
@@ -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)
index fc105243b910f21a17afc22c31f3eb3fd44ea0ac..60183547437f71e619ed9051d5add0c704c63dd4 100644 (file)
@@ -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
  */