From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KjgaZ-0006sM-Oj for qemu-devel@nongnu.org; Sat, 27 Sep 2008 16:40:27 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KjgaZ-0006ri-8n for qemu-devel@nongnu.org; Sat, 27 Sep 2008 16:40:27 -0400 Received: from [199.232.76.173] (port=58850 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KjgaZ-0006re-6A for qemu-devel@nongnu.org; Sat, 27 Sep 2008 16:40:27 -0400 Received: from csl.cornell.edu ([128.84.224.10]:3151 helo=vlsi.csl.cornell.edu) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KjgaY-00084t-Lf for qemu-devel@nongnu.org; Sat, 27 Sep 2008 16:40:26 -0400 Received: from stanley.csl.cornell.edu (stanley.csl.cornell.edu [128.84.224.15]) by vlsi.csl.cornell.edu (8.13.4/8.13.4) with ESMTP id m8RKeFnT012985 for ; Sat, 27 Sep 2008 16:40:20 -0400 (EDT) Date: Sat, 27 Sep 2008 16:40:15 -0400 (EDT) From: Vince Weaver Message-ID: <20080927163641.O28993@stanley.csl.cornell.edu> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Subject: [Qemu-devel] RFC: mremap() patch Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org 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 Index: linux-user/mmap.c =================================================================== --- linux-user/mmap.c (revision 5321) +++ linux-user/mmap.c (working copy) @@ -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 {