aboutsummaryrefslogtreecommitdiff
path: root/test/builtins
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2015-02-10 07:45:43 +0000
committerDimitry Andric <dim@FreeBSD.org>2015-02-10 07:45:43 +0000
commit476c4db3dc56bee43df384704c75ccc71cfa7a1d (patch)
tree5d0dcec3cc12fc53532fc84029892b98711a2596 /test/builtins
parentca9211ecdede9bdedb812b2243a4abdb8dacd1b9 (diff)
downloadsrc-476c4db3dc56bee43df384704c75ccc71cfa7a1d.tar.gz
src-476c4db3dc56bee43df384704c75ccc71cfa7a1d.zip
Import compiler-rt trunk r228651.vendor/compiler-rt/compiler-rt-r228651
Notes
Notes: svn path=/vendor/compiler-rt/dist/; revision=278497 svn path=/vendor/compiler-rt/compiler-rt-r228651/; revision=278498; tag=vendor/compiler-rt/compiler-rt-r228651
Diffstat (limited to 'test/builtins')
-rw-r--r--test/builtins/Unit/clear_cache_test.c19
-rw-r--r--test/builtins/Unit/enable_execute_stack_test.c20
2 files changed, 28 insertions, 11 deletions
diff --git a/test/builtins/Unit/clear_cache_test.c b/test/builtins/Unit/clear_cache_test.c
index 3507fd80b288..3c893018545f 100644
--- a/test/builtins/Unit/clear_cache_test.c
+++ b/test/builtins/Unit/clear_cache_test.c
@@ -38,7 +38,18 @@ int func2()
return 2;
}
-
+void *__attribute__((noinline))
+memcpy_f(void *dst, const void *src, size_t n) {
+// ARM and MIPS nartually align functions, but use the LSB for ISA selection
+// (THUMB, MIPS16/uMIPS respectively). Ensure that the ISA bit is ignored in
+// the memcpy
+#if defined(__arm__) || defined(__mips__)
+ return (void *)((uintptr_t)memcpy(dst, (void *)((uintptr_t)src & ~1), n) |
+ ((uintptr_t)src & 1));
+#else
+ return memcpy(dst, (void *)((uintptr_t)src), n);
+#endif
+}
unsigned char execution_buffer[128];
@@ -59,16 +70,14 @@ int main()
return 1;
// verify you can copy and execute a function
- memcpy(execution_buffer, (void *)(uintptr_t)&func1, 128);
+ pfunc f1 = (pfunc)memcpy_f(execution_buffer, func1, 128);
__clear_cache(execution_buffer, &execution_buffer[128]);
- pfunc f1 = (pfunc)(uintptr_t)execution_buffer;
if ((*f1)() != 1)
return 1;
// verify you can overwrite a function with another
- memcpy(execution_buffer, (void *)(uintptr_t)&func2, 128);
+ pfunc f2 = (pfunc)memcpy_f(execution_buffer, func2, 128);
__clear_cache(execution_buffer, &execution_buffer[128]);
- pfunc f2 = (pfunc)(uintptr_t)execution_buffer;
if ((*f2)() != 2)
return 1;
diff --git a/test/builtins/Unit/enable_execute_stack_test.c b/test/builtins/Unit/enable_execute_stack_test.c
index c0f67b337939..38a142afb24d 100644
--- a/test/builtins/Unit/enable_execute_stack_test.c
+++ b/test/builtins/Unit/enable_execute_stack_test.c
@@ -45,8 +45,18 @@ int func2()
return 2;
}
-
-
+void *__attribute__((noinline))
+memcpy_f(void *dst, const void *src, size_t n) {
+// ARM and MIPS nartually align functions, but use the LSB for ISA selection
+// (THUMB, MIPS16/uMIPS respectively). Ensure that the ISA bit is ignored in
+// the memcpy
+#if defined(__arm__) || defined(__mips__)
+ return (void *)((uintptr_t)memcpy(dst, (void *)((uintptr_t)src & ~1), n) |
+ ((uintptr_t)src & 1));
+#else
+ return memcpy(dst, (void *)((uintptr_t)src), n);
+#endif
+}
int main()
{
@@ -55,16 +65,14 @@ int main()
__enable_execute_stack(execution_buffer);
// verify you can copy and execute a function
- memcpy(execution_buffer, (void *)(uintptr_t)&func1, 128);
+ pfunc f1 = (pfunc)memcpy_f(execution_buffer, func1, 128);
__clear_cache(execution_buffer, &execution_buffer[128]);
- pfunc f1 = (pfunc)(uintptr_t)execution_buffer;
if ((*f1)() != 1)
return 1;
// verify you can overwrite a function with another
- memcpy(execution_buffer, (void *)(uintptr_t)&func2, 128);
+ pfunc f2 = (pfunc)memcpy_f(execution_buffer, func2, 128);
__clear_cache(execution_buffer, &execution_buffer[128]);
- pfunc f2 = (pfunc)(uintptr_t)execution_buffer;
if ((*f2)() != 2)
return 1;