diff options
author | MITSUNARI Shigeo <[email protected]> | 2017-04-10 17:50:01 +0900 |
---|---|---|
committer | MITSUNARI Shigeo <[email protected]> | 2017-04-10 17:50:01 +0900 |
commit | e10a7e7f7c27f8fd31496fadc05c6bfde1cd394a (patch) | |
tree | 323d2a0fd9e52c5d7117884e11b593fff45d937b /sample | |
parent | 4b235f70859f928ae40e88b9e6ea24322caf721c (diff) | |
download | xbyak-e10a7e7f7c27f8fd31496fadc05c6bfde1cd394a.tar.gz xbyak-e10a7e7f7c27f8fd31496fadc05c6bfde1cd394a.zip |
use VirtualProtect for recent vc
Diffstat (limited to 'sample')
-rw-r--r-- | sample/bf.cpp | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/sample/bf.cpp b/sample/bf.cpp index 29b9f3a..ce5c12e 100644 --- a/sample/bf.cpp +++ b/sample/bf.cpp @@ -152,17 +152,28 @@ public: void dump(const Xbyak::uint8 *code, size_t size) { - puts("#include <stdio.h>\nstatic int stack[128 * 1024];\nstatic const unsigned char code[] = {"); + puts("#include <stdio.h>\nstatic int stack[128 * 1024];"); +#ifdef _MSC_VER + printf("static __declspec(align(4096)) "); +#else + printf("static __attribute__((aligned(4096)))"); +#endif + puts("const unsigned char code[] = {"); for (size_t i = 0; i < size; i++) { printf("0x%02x,", code[i]); if ((i % 16) == 15) putchar('\n'); } puts("\n};"); -#ifndef _MSC_VER +#ifdef _MSC_VER + puts("#include <windows.h>"); +#else puts("#include <unistd.h>"); puts("#include <sys/mman.h>"); #endif - puts("main()\n{"); -#ifndef _MSC_VER + puts("int main()\n{"); +#ifdef _MSC_VER + puts("\tDWORD oldProtect;"); + puts("\tVirtualProtect((void*)code, sizeof(code), PAGE_EXECUTE_READWRITE, &oldProtect);"); +#else puts("\tlong pageSize = sysconf(_SC_PAGESIZE) - 1;"); puts("\tmprotect((void*)code, (sizeof(code) + pageSize) & ~pageSize, PROT_READ | PROT_EXEC);"); #endif |