summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAnton Korobeynikov <asl@math.spbu.ru>2012-01-12 21:13:48 +0000
committerAnton Korobeynikov <asl@math.spbu.ru>2012-01-12 21:13:48 +0000
commit7e8904f4b2b6b084ea2b4203d62554b42c068296 (patch)
tree95ede3683ba84c6ba495a4bb0dd43bae926db261 /test
parent8bcc6b93abafee3cb15e20fda0f1e1d4967bb80e (diff)
downloadcompiler-rt-7e8904f4b2b6b084ea2b4203d62554b42c068296.tar.gz
compiler-rt-7e8904f4b2b6b084ea2b4203d62554b42c068296.tar.bz2
compiler-rt-7e8904f4b2b6b084ea2b4203d62554b42c068296.tar.xz
Add some basic mingw support.
Patch by Ruben Van Boxem! git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@148048 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test')
-rw-r--r--test/Unit/clear_cache_test.c25
-rw-r--r--test/Unit/enable_execute_stack_test.c25
2 files changed, 41 insertions, 9 deletions
diff --git a/test/Unit/clear_cache_test.c b/test/Unit/clear_cache_test.c
index 52672395..3507fd80 100644
--- a/test/Unit/clear_cache_test.c
+++ b/test/Unit/clear_cache_test.c
@@ -11,11 +11,20 @@
#include <stdio.h>
#include <string.h>
#include <stdint.h>
+#if defined(_WIN32)
+#include <windows.h>
+void __clear_cache(void* start, void* end)
+{
+ if (!FlushInstructionCache(GetCurrentProcess(), start, end-start))
+ exit(1);
+}
+#else
#include <sys/mman.h>
+extern void __clear_cache(void* start, void* end);
+#endif
-extern void __clear_cache(void* start, void* end);
typedef int (*pfunc)(void);
@@ -38,21 +47,29 @@ int main()
// make executable the page containing execution_buffer
char* start = (char*)((uintptr_t)execution_buffer & (-4095));
char* end = (char*)((uintptr_t)(&execution_buffer[128+4096]) & (-4095));
- if ( mprotect(start, end-start, PROT_READ|PROT_WRITE|PROT_EXEC) != 0 )
+#if defined(_WIN32)
+ DWORD dummy_oldProt;
+ MEMORY_BASIC_INFORMATION b;
+ if (!VirtualQuery(start, &b, sizeof(b)))
+ return 1;
+ if (!VirtualProtect(b.BaseAddress, b.RegionSize, PAGE_EXECUTE_READWRITE, &b.Protect))
+#else
+ if (mprotect(start, end-start, PROT_READ|PROT_WRITE|PROT_EXEC) != 0)
+#endif
return 1;
// verify you can copy and execute a function
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;
diff --git a/test/Unit/enable_execute_stack_test.c b/test/Unit/enable_execute_stack_test.c
index ae4c320a..c0f67b33 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;