about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authormogery <mo.geryy@gmail.com>2021-10-12 19:47:31 +0200
committermogery <mo.geryy@gmail.com>2021-10-12 19:47:31 +0200
commit0c27b82ff3b8a1da27d7ed32e89c90518f9c2c0c (patch)
treeb457777235dbb2d0754ea00500d0115d7ee8f2c4 /src
parent289deb3655b976610aa7b7f84a9273326451337f (diff)
downloadbox64-0c27b82ff3b8a1da27d7ed32e89c90518f9c2c0c.tar.gz
box64-0c27b82ff3b8a1da27d7ed32e89c90518f9c2c0c.zip
Map bricks below first 2GB of address space
This fixes an issue with mono where JIT compiled code would
near-call wrapped libraries, but fail because the difference
between PC and the call address did not fit into an imm32.

This was fixed by replacing posix_memalign with my_mmap and
providing the MAP_32BIT flag.

Fixes #131
Diffstat (limited to 'src')
-rwxr-xr-xsrc/tools/bridge.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/tools/bridge.c b/src/tools/bridge.c
index 5f6bb5af..c800b8c5 100755
--- a/src/tools/bridge.c
+++ b/src/tools/bridge.c
@@ -4,6 +4,7 @@
 #include <string.h>
 #include <dlfcn.h>
 #include <pthread.h>
+#include <sys/mman.h>
 
 #include "custommem.h"
 #include "bridge.h"
@@ -36,9 +37,11 @@ typedef struct bridge_s {
 brick_t* NewBrick()
 {
     brick_t* ret = (brick_t*)calloc(1, sizeof(brick_t));
-    if(posix_memalign((void**)&ret->b, box64_pagesize, NBRICK*sizeof(onebridge_t))) {
+    void* ptr = my_mmap(thread_get_emu(), NULL, NBRICK * sizeof(onebridge_t), PROT_READ | PROT_WRITE, MAP_PRIVATE | 0x40 | MAP_ANONYMOUS, -1, 0); // 0x40 is MAP_32BIT
+    if(ptr == MAP_FAILED) {
         printf_log(LOG_NONE, "Warning, cannot allocate 0x%lx aligned bytes for bridge, will probably crash later\n", NBRICK*sizeof(onebridge_t));
     }
+    ret->b = ptr;
     return ret;
 }