Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --- a/jit.c
- +++ b/jit.c
- @@ -3,7 +3,7 @@
- #include <stdlib.h>
- #include <stdint.h>
- #include <string.h>
- -#include <sys/mman.h>
- +#include <windows.h>
- #define PAGE_SIZE 4096
- @@ -15,21 +15,20 @@ struct asmbuf {
- struct asmbuf *
- asmbuf_create(void)
- {
- - int prot = PROT_READ | PROT_WRITE;
- - int flags = MAP_ANONYMOUS | MAP_PRIVATE;
- - return mmap(NULL, PAGE_SIZE, prot, flags, -1, 0);
- + return VirtualAlloc(NULL, PAGE_SIZE, MEM_COMMIT, PAGE_READWRITE);
- }
- void
- asmbuf_free(struct asmbuf *buf)
- {
- - munmap(buf, PAGE_SIZE);
- + VirtualFree(buf, PAGE_SIZE, MEM_RELEASE);
- }
- void
- asmbuf_finalize(struct asmbuf *buf)
- {
- - mprotect(buf, PAGE_SIZE, PROT_READ | PROT_EXEC);
- + DWORD old;
- + VirtualProtect(buf, PAGE_SIZE, PAGE_EXECUTE_READ, &old);
- }
- void
- @@ -50,7 +49,7 @@ int main(void)
- {
- /* Compile input program */
- struct asmbuf *buf = asmbuf_create();
- - asmbuf_ins(buf, 3, 0x4889f8); // mov %rdi, %rax
- + asmbuf_ins(buf, 3, 0x4889c8); // mov %rcx, %rax
- int c;
- while ((c = fgetc(stdin)) != '\n' && c != EOF) {
- if (c == ' ')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement