libx86-mmap-offset.patch 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. diff -ur libx86-1.1/lrmi.c libx86-1.1.hack/lrmi.c
  2. --- libx86-1.1/lrmi.c 2006-10-30 15:10:16.000000000 -0500
  3. +++ libx86-1.1.hack/lrmi.c 2009-10-26 15:55:42.000000000 -0400
  4. @@ -136,7 +136,7 @@
  5. if (context.ready)
  6. return 1;
  7. - if (!LRMI_common_init())
  8. + if (!LRMI_common_init(0))
  9. return 0;
  10. /*
  11. diff -ur libx86-1.1/thunk.c libx86-1.1.hack/thunk.c
  12. --- libx86-1.1/thunk.c 2008-04-02 20:48:00.000000000 -0400
  13. +++ libx86-1.1.hack/thunk.c 2009-10-26 16:05:39.000000000 -0400
  14. @@ -139,11 +139,11 @@
  15. int i;
  16. X86EMU_intrFuncs intFuncs[256];
  17. - if (!LRMI_common_init())
  18. + mmap_addr = LRMI_common_init(1);
  19. +
  20. + if (!mmap_addr)
  21. return 0;
  22. - mmap_addr = 0;
  23. -
  24. X86EMU_pioFuncs pioFuncs = {
  25. (&x_inb),
  26. (&x_inw),
  27. @@ -169,10 +169,10 @@
  28. X86_ESP = 0xFFF9;
  29. memset (stack, 0, 64*1024);
  30. - *((char *)0) = 0x4f; /* Make sure that we end up jumping back to a
  31. - halt instruction */
  32. + *mmap_addr = 0x4f; /* Make sure that we end up jumping back to a
  33. + halt instruction */
  34. - M.mem_base = 0;
  35. + M.mem_base = (unsigned long)mmap_addr;
  36. M.mem_size = 1024*1024;
  37. return 1;
  38. diff -ur libx86-1.1/x86-common.c libx86-1.1.hack/x86-common.c
  39. --- libx86-1.1/x86-common.c 2008-05-16 12:56:23.000000000 -0400
  40. +++ libx86-1.1.hack/x86-common.c 2009-10-26 16:03:21.000000000 -0400
  41. @@ -45,14 +45,15 @@
  42. static struct {
  43. int ready;
  44. int count;
  45. + void *offset;
  46. struct mem_block blocks[REAL_MEM_BLOCKS];
  47. } mem_info = { 0 };
  48. static int
  49. -real_mem_init(void)
  50. +real_mem_init(int high_page)
  51. {
  52. void *m;
  53. - int fd_zero;
  54. + int fd_zero, flags = MAP_SHARED;
  55. if (mem_info.ready)
  56. return 1;
  57. @@ -63,9 +64,12 @@
  58. return 0;
  59. }
  60. + if (!high_page)
  61. + flags |= MAP_FIXED;
  62. +
  63. m = mmap((void *)REAL_MEM_BASE, REAL_MEM_SIZE,
  64. - PROT_READ | PROT_WRITE | PROT_EXEC,
  65. - MAP_FIXED | MAP_SHARED, fd_zero, 0);
  66. + PROT_READ | PROT_WRITE | PROT_EXEC,
  67. + flags, fd_zero, 0);
  68. if (m == (void *)-1) {
  69. perror("mmap /dev/zero");
  70. @@ -76,6 +80,7 @@
  71. close(fd_zero);
  72. mem_info.ready = 1;
  73. + mem_info.offset = m;
  74. mem_info.count = 1;
  75. mem_info.blocks[0].size = REAL_MEM_SIZE;
  76. mem_info.blocks[0].free = 1;
  77. @@ -87,7 +92,7 @@
  78. real_mem_deinit(void)
  79. {
  80. if (mem_info.ready) {
  81. - munmap((void *)REAL_MEM_BASE, REAL_MEM_SIZE);
  82. + munmap(mem_info.offset, REAL_MEM_SIZE);
  83. mem_info.ready = 0;
  84. }
  85. }
  86. @@ -119,7 +124,7 @@
  87. LRMI_alloc_real(int size)
  88. {
  89. int i;
  90. - char *r = (char *)REAL_MEM_BASE;
  91. + char *r = (char *)mem_info.offset;
  92. if (!mem_info.ready)
  93. return NULL;
  94. @@ -151,7 +156,7 @@
  95. LRMI_free_real(void *m)
  96. {
  97. int i;
  98. - char *r = (char *)REAL_MEM_BASE;
  99. + char *r = (char *)mem_info.offset;
  100. if (!mem_info.ready)
  101. return;
  102. @@ -200,13 +205,15 @@
  103. return *(unsigned short *)(i * 4);
  104. }
  105. -int LRMI_common_init(void)
  106. +void *LRMI_common_init(int high_page)
  107. {
  108. - void *m;
  109. + void *m, *offset;
  110. int fd_mem;
  111. - if (!real_mem_init())
  112. - return 0;
  113. + if (!real_mem_init(high_page))
  114. + return NULL;
  115. +
  116. + offset = mem_info.offset - REAL_MEM_BASE;
  117. /*
  118. Map the Interrupt Vectors (0x0 - 0x400) + BIOS data (0x400 - 0x502)
  119. @@ -217,33 +224,33 @@
  120. if (fd_mem == -1) {
  121. real_mem_deinit();
  122. perror("open /dev/mem");
  123. - return 0;
  124. + return NULL;
  125. }
  126. - m = mmap((void *)0, 0x502,
  127. - PROT_READ | PROT_WRITE | PROT_EXEC,
  128. - MAP_FIXED | MAP_SHARED, fd_mem, 0);
  129. + m = mmap(offset, 0x502,
  130. + PROT_READ | PROT_WRITE | PROT_EXEC,
  131. + MAP_FIXED | MAP_SHARED, fd_mem, 0);
  132. if (m == (void *)-1) {
  133. close(fd_mem);
  134. real_mem_deinit();
  135. perror("mmap /dev/mem");
  136. - return 0;
  137. + return NULL;
  138. }
  139. - m = mmap((void *)0xa0000, 0x100000 - 0xa0000,
  140. + m = mmap(offset+0xa0000, 0x100000 - 0xa0000,
  141. PROT_READ | PROT_WRITE | PROT_EXEC,
  142. MAP_FIXED | MAP_SHARED, fd_mem, 0xa0000);
  143. if (m == (void *)-1) {
  144. - munmap((void *)0, 0x502);
  145. + munmap(offset, 0x502);
  146. close(fd_mem);
  147. real_mem_deinit();
  148. perror("mmap /dev/mem");
  149. - return 0;
  150. + return NULL;
  151. }
  152. close(fd_mem);
  153. - return 1;
  154. + return offset;
  155. }
  156. diff -ur libx86-1.1/x86-common.h libx86-1.1.hack/x86-common.h
  157. --- libx86-1.1/x86-common.h 2006-09-07 18:44:27.000000000 -0400
  158. +++ libx86-1.1.hack/x86-common.h 2009-10-26 16:01:19.000000000 -0400
  159. @@ -40,4 +40,4 @@
  160. void *LRMI_alloc_real(int size);
  161. void LRMI_free_real(void *m);
  162. -int LRMI_common_init(void);
  163. +void *LRMI_common_init(int high_page);