[PATCH] Windows implementation of enable_execute_stack

Ruben Van Boxem vanboxem.ruben at gmail.com
Fri May 24 14:53:07 PDT 2013


Hi,

I submitted this patch a long while ago, together with a bunch of other
changes (some of which got applied back then).

If compiler-rt is in the LLVM tree, a Windows build chokes on this little
bit.

The relevant test passed back then, but I can't check this right now, as
LLVM is being difficult (some errors I need to figure out) and compiler-rt
has since moved to be a subproject requiring the LLVM tree to be built.


Please comment or apply. Thanks!

Ruben

PS: I'm not subscribed, please keep me in the CC list
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130524/e0b0ba23/attachment.html>
-------------- next part --------------
Index: lib/enable_execute_stack.c
===================================================================
--- lib/enable_execute_stack.c	(revision 182667)
+++ lib/enable_execute_stack.c	(working copy)
@@ -10,7 +10,11 @@
 
 #include "int_lib.h"
 
+#ifndef _WIN32
 #include <sys/mman.h>
+#else
+#include <windows.h>
+#endif
 
 /* #include "config.h"
  * FIXME: CMake - include when cmake system is ready.
@@ -38,7 +42,7 @@
 
 void __enable_execute_stack(void* addr)
 {
-
+#ifndef _WIN32
 #if __APPLE__
 	/* On Darwin, pagesize is always 4096 bytes */
 	const uintptr_t pageSize = 4096;
@@ -54,6 +58,14 @@
 	unsigned char* endPage = (unsigned char*)((p+TRAMPOLINE_SIZE+pageSize) & pageAlignMask);
 	size_t length = endPage - startPage;
 	(void) mprotect((void *)startPage, length, PROT_READ | PROT_WRITE | PROT_EXEC);
+#else
+    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);
+#endif /* _WIN32 */
 }
 
 


More information about the llvm-commits mailing list