Advertisement
Guest User

windows.patch

a guest
Mar 17th, 2015
446
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 1.11 KB | None | 0 0
  1. --- a/jit.c
  2. +++ b/jit.c
  3. @@ -3,7 +3,7 @@
  4.  #include <stdlib.h>
  5.  #include <stdint.h>
  6.  #include <string.h>
  7. -#include <sys/mman.h>
  8. +#include <windows.h>
  9.  
  10.  #define PAGE_SIZE 4096
  11.  
  12. @@ -15,21 +15,20 @@ struct asmbuf {
  13.  struct asmbuf *
  14.  asmbuf_create(void)
  15.  {
  16. -    int prot = PROT_READ | PROT_WRITE;
  17. -    int flags = MAP_ANONYMOUS | MAP_PRIVATE;
  18. -    return mmap(NULL, PAGE_SIZE, prot, flags, -1, 0);
  19. +    return VirtualAlloc(NULL, PAGE_SIZE, MEM_COMMIT, PAGE_READWRITE);
  20.  }
  21.  
  22.  void
  23.  asmbuf_free(struct asmbuf *buf)
  24.  {
  25. -    munmap(buf, PAGE_SIZE);
  26. +    VirtualFree(buf, PAGE_SIZE, MEM_RELEASE);
  27.  }
  28.  
  29.  void
  30.  asmbuf_finalize(struct asmbuf *buf)
  31.  {
  32. -    mprotect(buf, PAGE_SIZE, PROT_READ | PROT_EXEC);
  33. +    DWORD old;
  34. +    VirtualProtect(buf, PAGE_SIZE, PAGE_EXECUTE_READ, &old);
  35.  }
  36.  
  37.  void
  38. @@ -50,7 +49,7 @@ int main(void)
  39.  {
  40.      /* Compile input program */
  41.      struct asmbuf *buf = asmbuf_create();
  42. -    asmbuf_ins(buf, 3, 0x4889f8); // mov %rdi, %rax
  43. +    asmbuf_ins(buf, 3, 0x4889c8); // mov %rcx, %rax
  44.      int c;
  45.      while ((c = fgetc(stdin)) != '\n' && c != EOF) {
  46.          if (c == ' ')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement