summaryrefslogtreecommitdiffstats
path: root/test/Unit/enable_execute_stack_test.c
diff options
context:
space:
mode:
authorandrew <andrew@FreeBSD.org>2012-07-30 10:58:13 +0000
committerandrew <andrew@FreeBSD.org>2012-07-30 10:58:13 +0000
commitcfeab007a554034f0b3ab4a677cf9dd2696c12f9 (patch)
tree40cc44a3d02ed86de24f2117a55680e4f0eb01a0 /test/Unit/enable_execute_stack_test.c
parent07af089f1449ec5506ca7ede5b593e11a0f48603 (diff)
downloadFreeBSD-src-cfeab007a554034f0b3ab4a677cf9dd2696c12f9.zip
FreeBSD-src-cfeab007a554034f0b3ab4a677cf9dd2696c12f9.tar.gz
Import compiler-rt r160957.
Diffstat (limited to 'test/Unit/enable_execute_stack_test.c')
-rw-r--r--test/Unit/enable_execute_stack_test.c25
1 files changed, 20 insertions, 5 deletions
diff --git a/test/Unit/enable_execute_stack_test.c b/test/Unit/enable_execute_stack_test.c
index ae4c320..c0f67b3 100644
--- a/test/Unit/enable_execute_stack_test.c
+++ b/test/Unit/enable_execute_stack_test.c
@@ -11,12 +11,27 @@
#include <stdio.h>
#include <string.h>
#include <stdint.h>
-#include <sys/mman.h>
-
-
+#if defined(_WIN32)
+#include <windows.h>
+void __clear_cache(void* start, void* end)
+{
+ if (!FlushInstructionCache(GetCurrentProcess(), start, end-start))
+ exit(1);
+}
+void __enable_execute_stack(void *addr)
+{
+ MEMORY_BASIC_INFORMATION b;
+ if (!VirtualQuery(addr, &b, sizeof(b)))
+ exit(1);
+ if (!VirtualProtect(b.BaseAddress, b.RegionSize, PAGE_EXECUTE_READWRITE, &b.Protect))
+ exit(1);
+}
+#else
+#include <sys/mman.h>
extern void __clear_cache(void* start, void* end);
extern void __enable_execute_stack(void* addr);
+#endif
typedef int (*pfunc)(void);
@@ -43,14 +58,14 @@ int main()
memcpy(execution_buffer, (void *)(uintptr_t)&func1, 128);
__clear_cache(execution_buffer, &execution_buffer[128]);
pfunc f1 = (pfunc)(uintptr_t)execution_buffer;
- if ( (*f1)() != 1 )
+ if ((*f1)() != 1)
return 1;
// verify you can overwrite a function with another
memcpy(execution_buffer, (void *)(uintptr_t)&func2, 128);
__clear_cache(execution_buffer, &execution_buffer[128]);
pfunc f2 = (pfunc)(uintptr_t)execution_buffer;
- if ( (*f2)() != 2 )
+ if ((*f2)() != 2)
return 1;
return 0;
OpenPOWER on IntegriCloud