Created
March 4, 2016 10:20
-
-
Save feliwir/edf03083871ff97beddb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void* asjit::jitcode(dasm_State **state) | |
{ | |
size_t sz; | |
void* buf; | |
dasm_link(state, &sz); | |
#ifdef _WIN32 | |
buf = VirtualAlloc(0, sz, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); | |
#else | |
buf = mmap(0, sz, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); | |
#endif | |
dasm_encode(state, buf); | |
#ifdef _WIN32 | |
{DWORD dwOld; VirtualProtect(buf, sz, PAGE_EXECUTE_READ, &dwOld); } | |
#else | |
mprotect(buf, sz, PROT_READ | PROT_EXEC); | |
#endif | |
return buf; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment