summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authornjn <njn@a5019735-40e9-0310-863c-91ae7b9d1cf9>2009-04-15 05:35:00 +0000
committernjn <njn@a5019735-40e9-0310-863c-91ae7b9d1cf9>2009-04-15 05:35:00 +0000
commit9a55ee834027e19034e609f8f6bd29f32a95bf57 (patch)
treee7d0ecf6694782c580674a1d1416f8deb97729b1 /tests
parent70ecd6b5b70d11104cc130eff7b3344df83aff3d (diff)
These three files should have been added in r9537.
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@9544 a5019735-40e9-0310-863c-91ae7b9d1cf9
Diffstat (limited to 'tests')
-rw-r--r--tests/asm.h19
-rw-r--r--tests/malloc.h27
-rw-r--r--tests/sys_mman.h31
3 files changed, 77 insertions, 0 deletions
diff --git a/tests/asm.h b/tests/asm.h
new file mode 100644
index 00000000..d64a893f
--- /dev/null
+++ b/tests/asm.h
@@ -0,0 +1,19 @@
+// Header to factor out platform differences in asm code.
+
+// On Darwin, all symbols get an underscore prepended when compiled. If we
+// use any such symbols in asm code, we need to add that underscore. So in
+// general, any symbol named in asm code should be wrapped by VG_SYM.
+
+// This one is for use in inline asm in C files.
+#if defined(VGO_darwin)
+#define VG_SYM(x) "_"#x
+#else
+#define VG_SYM(x) #x
+#endif
+
+// This one is for use in asm files.
+#if defined(VGO_darwin)
+#define VG_SYM_ASM(x) _#x
+#else
+#define VG_SYM_ASM(x) x
+#endif
diff --git a/tests/malloc.h b/tests/malloc.h
new file mode 100644
index 00000000..0179b387
--- /dev/null
+++ b/tests/malloc.h
@@ -0,0 +1,27 @@
+// Replacement for malloc.h which factors out platform differences.
+
+#include <stdlib.h>
+#if defined(VGO_darwin)
+# include <malloc/malloc.h>
+#else
+# include <malloc.h>
+#endif
+
+#include <assert.h>
+
+// Allocates a 16-aligned block. Asserts if the allocation fails.
+__attribute__((unused))
+static void* memalign16(size_t szB)
+{
+ void* x;
+#if defined(VGO_darwin)
+ // Darwin lacks memalign, but its malloc is always 16-aligned anyway.
+ x = malloc(szB);
+#else
+ x = memalign(16, szB);
+#endif
+ assert(x);
+ assert(0 == ((16-1) & (unsigned long)x));
+ return x;
+}
+
diff --git a/tests/sys_mman.h b/tests/sys_mman.h
new file mode 100644
index 00000000..7ac64d54
--- /dev/null
+++ b/tests/sys_mman.h
@@ -0,0 +1,31 @@
+// Replacement for sys/mman.h which factors out platform differences.
+
+#include <sys/mman.h>
+
+#if defined(VGO_darwin)
+# define MAP_ANONYMOUS MAP_ANON
+#endif
+
+
+#include <assert.h>
+#include <unistd.h>
+
+// Map a page, then unmap it, then return that address. That
+// guarantees to give an address which will fault when accessed,
+// without making any assumptions about the layout of the address
+// space.
+
+__attribute__((unused))
+static void* get_unmapped_page(void)
+{
+ void* ptr;
+ int r;
+ long pagesz = sysconf(_SC_PAGE_SIZE);
+ assert(pagesz == 4096 || pagesz == 65536);
+ ptr = mmap(0, pagesz, PROT_READ, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
+ assert(ptr != (void*)-1);
+ r = munmap(ptr, pagesz);
+ assert(r == 0);
+ return ptr;
+}
+