Ruben Van Boxem
2012-Jan-07 19:42 UTC
[LLVMdev] [PATCH][Compiler-rt] Windows implementation of mmap functionality in clear_cache_test and enable_execute_stack_test
Hi, Attached is a patch for compiler-rt to allow it to compile with MinGW-w64 on Windows. Results aren't that bad. x86 GCC and Clang do everything right, all tests pass. x86_64 GCC fails a lot of tests. This is 99% sure a codegen issue. 38 - fixunssfti_test (Failed) 74 - fixunsdfti_test (Failed) x86_64 Clang fails these tests: 2 - udivmodti4_test (SEGFAULT) 6 - fixdfti_test (Failed) 8 - negti2_test (SEGFAULT) 9 - cmpti2_test (SEGFAULT) 10 - mulvti3_test (SEGFAULT) 12 - fixunsxfti_test (Failed) 14 - negvti2_test (SEGFAULT) 16 - ucmpti2_test (SEGFAULT) 19 - popcountti2_test (SEGFAULT) 23 - shlti3_test (SEGFAULT) 29 - floatuntisf_test (SEGFAULT) 31 - powixf2_test (SEGFAULT) 34 - floattisf_test (SEGFAULT) 38 - fixunssfti_test (Failed) 39 - parityti2_test (SEGFAULT) 45 - multi3_test (SEGFAULT) 47 - clzti2_test (SEGFAULT) 53 - ffsti2_test (SEGFAULT) 55 - fixsfti_test (Failed) 56 - absvti2_test (SEGFAULT) 57 - ashrti3_test (SEGFAULT) 62 - addvti3_test (SEGFAULT) 64 - floatuntidf_test (SEGFAULT) 65 - umodti3_test (SEGFAULT) 66 - ctzti2_test (SEGFAULT) 67 - floatuntixf_test (SEGFAULT) 69 - floattidf_test (SEGFAULT) 70 - modti3_test (SEGFAULT) 73 - floattixf_test (SEGFAULT) 74 - fixunsdfti_test (Failed) 75 - subvti3_test (SEGFAULT) 80 - lshrti3_test (SEGFAULT) 83 - udivti3_test (SEGFAULT) 86 - fixxfti_test (Failed) 88 - divti3_test (SEGFAULT) I'll be happy to provide any helpful info (as in, correctly generated object files or something) Everything passes on x86. Please apply at your leisure! Thanks! Ruben -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120107/85859e08/attachment.html> -------------- next part -------------- Index: test/Unit/clear_cache_test.c ==================================================================--- test/Unit/clear_cache_test.c (revision 147731) +++ test/Unit/clear_cache_test.c (working copy) @@ -11,12 +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); int func1() @@ -31,14 +39,23 @@ -unsigned char execution_buffer[128]; + int main() { + unsigned char execution_buffer[128]; // 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 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 @@ -53,7 +70,8 @@ __clear_cache(execution_buffer, &execution_buffer[128]); pfunc f2 = (pfunc)(uintptr_t)execution_buffer; if ( (*f2)() != 2 ) - return 1; + { + return 1;} return 0; } Index: test/Unit/enable_execute_stack_test.c ==================================================================--- test/Unit/enable_execute_stack_test.c (revision 147731) +++ test/Unit/enable_execute_stack_test.c (working copy) @@ -11,12 +11,27 @@ #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) ) + abort(); +} +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); Index: lib/int_endianness.h ==================================================================--- lib/int_endianness.h (revision 147731) +++ lib/int_endianness.h (working copy) @@ -80,6 +80,11 @@ #endif /* GNU/Linux */ +#if defined(_WIN32) +#define _YUGA_LITTLE_ENDIAN 1 +#define _YUGA_BIG_ENDIAN 0 +#endif /* Windows */ + /* . */ #if !defined(_YUGA_LITTLE_ENDIAN) || !defined(_YUGA_BIG_ENDIAN)
Anton Korobeynikov
2012-Jan-07 20:09 UTC
[LLVMdev] [llvm-commits] [PATCH][Compiler-rt] Windows implementation of mmap functionality in clear_cache_test and enable_execute_stack_test
Hello Ruben> Please apply at your leisure! Thanks!Will you please fix the code to use the same coding style as everything else around? Thanks! -- With best regards, Anton Korobeynikov Faculty of Mathematics and Mechanics, Saint Petersburg State University
Ruben Van Boxem
2012-Jan-07 20:23 UTC
[LLVMdev] [llvm-commits] [PATCH][Compiler-rt] Windows implementation of mmap functionality in clear_cache_test and enable_execute_stack_test
---------- Forwarded message ---------- From: Ruben Van Boxem <vanboxem.ruben at gmail.com> Date: 2012/1/7 Subject: Re: [llvm-commits] [PATCH][Compiler-rt] Windows implementation of mmap functionality in clear_cache_test and enable_execute_stack_test To: Anton Korobeynikov <anton at korobeynikov.info> 2012/1/7 Anton Korobeynikov <anton at korobeynikov.info>> Hello Ruben > > > Please apply at your leisure! Thanks! > Will you please fix the code to use the same coding style as > everything else around? >I see I missed some curly braces. I also modified spacing a tiny bit. If you mean anything else, I cannot see what's out of style. Thanks for the prompt response, Ruben -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120107/be5d1002/attachment.html> -------------- next part -------------- Index: test/Unit/clear_cache_test.c ==================================================================--- test/Unit/clear_cache_test.c (revision 147731) +++ test/Unit/clear_cache_test.c (working copy) @@ -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,7 +47,15 @@ // 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 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 Index: test/Unit/enable_execute_stack_test.c ==================================================================--- test/Unit/enable_execute_stack_test.c (revision 147731) +++ test/Unit/enable_execute_stack_test.c (working copy) @@ -11,12 +11,27 @@ #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); +} +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); Index: lib/int_endianness.h ==================================================================--- lib/int_endianness.h (revision 147731) +++ lib/int_endianness.h (working copy) @@ -80,6 +80,13 @@ #endif /* GNU/Linux */ +#if defined(_WIN32) + +#define _YUGA_LITTLE_ENDIAN 1 +#define _YUGA_BIG_ENDIAN 0 + +#endif /* Windows */ + /* . */ #if !defined(_YUGA_LITTLE_ENDIAN) || !defined(_YUGA_BIG_ENDIAN)
Anton Korobeynikov
2012-Jan-07 22:14 UTC
[LLVMdev] [llvm-commits] [PATCH][Compiler-rt] Windows implementation of mmap functionality in clear_cache_test and enable_execute_stack_test
Hi Ruben,> I see I missed some curly braces. I also modified spacing a tiny bit.Doesn't seem so. E.g. you have: + if ( !VirtualQuery(addr, &b, sizeof(b)) ) + exit(1); + if( !VirtualProtect(b.BaseAddress, b.RegionSize, PAGE_EXECUTE_READWRITE, &b.Protect) ) Add space after "if". Do not put spaces after "(" and before ")". Same for other places in the file. -- With best regards, Anton Korobeynikov Faculty of Mathematics and Mechanics, Saint Petersburg State University
Maybe Matching Threads
- [LLVMdev] [PATCH][Compiler-rt] Windows implementation of mmap functionality in clear_cache_test and enable_execute_stack_test
- [LLVMdev] [llvm-commits] [PATCH][Compiler-rt] Windows implementation of mmap functionality in clear_cache_test and enable_execute_stack_test
- [LLVMdev] [llvm-commits] [PATCH][Compiler-rt] Windows implementation of mmap functionality in clear_cache_test and enable_execute_stack_test
- [LLVMdev] compiler-rt on Windows
- [LLVMdev] [llvm-commits] [PATCH][Compiler-rt] Windows implementation of mmap functionality in clear_cache_test and enable_execute_stack_test