summaryrefslogtreecommitdiff
path: root/lib/builtins/enable_execute_stack.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/builtins/enable_execute_stack.c')
-rw-r--r--lib/builtins/enable_execute_stack.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/builtins/enable_execute_stack.c b/lib/builtins/enable_execute_stack.c
index 63d836b31..23e494051 100644
--- a/lib/builtins/enable_execute_stack.c
+++ b/lib/builtins/enable_execute_stack.c
@@ -10,7 +10,9 @@
#include "int_lib.h"
+#ifndef _WIN32
#include <sys/mman.h>
+#endif
/* #include "config.h"
* FIXME: CMake - include when cmake system is ready.
@@ -18,9 +20,14 @@
*/
#define HAVE_SYSCONF 1
+#ifdef _WIN32
+#include <windef.h>
+#include <winbase.h>
+#else
#ifndef __APPLE__
#include <unistd.h>
#endif /* __APPLE__ */
+#endif /* _WIN32 */
#if __LP64__
#define TRAMPOLINE_SIZE 48
@@ -40,6 +47,12 @@ COMPILER_RT_ABI void
__enable_execute_stack(void* addr)
{
+#if _WIN32
+ MEMORY_BASIC_INFORMATION mbi;
+ if (!VirtualQuery (addr, &mbi, sizeof(mbi)))
+ return; /* We should probably assert here because there is no return value */
+ VirtualProtect (mbi.BaseAddress, mbi.RegionSize, PAGE_EXECUTE_READWRITE, &mbi.Protect);
+#else
#if __APPLE__
/* On Darwin, pagesize is always 4096 bytes */
const uintptr_t pageSize = 4096;
@@ -55,4 +68,5 @@ __enable_execute_stack(void* addr)
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);
+#endif
}