summaryrefslogtreecommitdiff
path: root/source/sw_protect.c
diff options
context:
space:
mode:
Diffstat (limited to 'source/sw_protect.c')
-rw-r--r--source/sw_protect.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/source/sw_protect.c b/source/sw_protect.c
new file mode 100644
index 0000000..7c6e5c2
--- /dev/null
+++ b/source/sw_protect.c
@@ -0,0 +1,34 @@
+#include "q_shared.h"
+
+#ifdef _WIN32
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+#else
+#include <unistd.h>
+#include <sys/mman.h>
+#endif
+
+/*
+================
+Sys_MakeCodeWriteable
+================
+*/
+void Sys_MakeCodeWriteable (unsigned long startaddr, unsigned long length) {
+#ifdef _WIN32
+ DWORD flOldProtect;
+
+ if (!VirtualProtect((LPVOID)startaddr, length, PAGE_READWRITE, &flOldProtect))
+ Com_Error(ERR_FATAL, "Protection change failed\n");
+#else
+ int r;
+ unsigned long addr;
+ int psize = getpagesize();
+
+ addr = (startaddr & ~(psize-1)) - psize;
+
+ r = mprotect((char*)addr, length + startaddr - addr + psize, 7);
+ if (r < 0)
+ Com_Error( ERR_FATAL, "Protection change failed\n");
+#endif
+}
+