Skip to contentSkip to conversation

RFC: mremap() patch

Qemu-devel Vince Weaver 1 participant 1 message Sep 27, 2008

lore
Share & tools
lore
#0 lore raw

Hello

This patch lets programs using mremap() on 32-bit targets on top of 64-bit machines work.

It is a hack though in many ways. I was wondering if anyone had any better ideas on how to implement this (short of fixing the Linux mremap() syscall which I think has already been shot-down on the linux-kernel list, and in any case would be linux specific and require new kernels).

The big problem is trying to get the original mmap() flags back. Right now my patch just assumes write and read, which probably isn't correct.

Vince

mmap.c +13 -0
Index: linux-user/mmap.c
===================================================================
@@ -538,6 +538,25 @@
     mmap_lock();
     /* XXX: use 5 args syscall */
     host_addr = (long)mremap(g2h(old_addr), old_size, new_size, flags);
+#if TARGET_ABI_BITS == 32
+    if (host_addr > 0xffffffff) {
+       void *temp_addr;
+ +       temp_addr = mmap(NULL,new_size,
+			PROT_READ|PROT_WRITE,MAP_ANONYMOUS|MAP_PRIVATE|MAP_32BIT, 0, 0);
+       memcpy(temp_addr,(void *)host_addr,old_size);
+       munmap((void *)host_addr,new_size); +       host_addr=(long)temp_addr;
+
+ +       if (host_addr > 0xffffffff) {
+ +          printf("ERROR!  mremap() returned 64-bit value on 32-bit target!\n\n");
+          exit(-1); +       }
+    }
+#endif +
     if (host_addr == -1) {
         new_addr = -1;
     } else {