Skip to contentSkip to conversation

linux-user/mmap.c query

Qemu-devel [email protected] 2 participants 2 messages Sep 22, 2004 – Sep 23, 2004

lore
Share & tools
lore
#0 lore raw

Hi Fabrice and everyone

I'm trying to use qemu-arm to run some statically linked linux binaries, and I've come across an issue with the target_mmap function. The test at line 185:
if (offset & ~TARGET_PAGE_MASK)
return -EINVAL;
seems to be unnecessary as there is code to handle a non-aligned offset later on in the function which is introduced by the comment
/* worst case: we cannot map the file because the offset is not
aligned, so we read it */

In addition, there seems to be an inconsistency in the way errors are reported from target_mmap and what is expected by linux-user/elfload.c. target_mmap() returns -EINVAL, but elfload.c expects errors to be reported with -1 and errno to be set.

The following (totally minimal) patch enables me to run a few simple statically linked ARM binaries. (This is just to make it clear the change I am talking about).

Once this is addressed I run into problems with binaries which execute code from writable pages - the code pages are marked non-writable by tb_link_phys() but segfaults arising from writes are not handled. I haven't fully investigated this problem yet. Is this supposed to work? I'll try and create a test case if I don't make any progress on this.

BTW, is it possible to run qemu-arm under gdb and get breakpoints working? When I try, gdb complains because the qemu binary is remapped somewhere else in the addres space.

Regards
Charlie

mmap.c 22 Sep 2004 20:18:53 -0000 renamed from mmap.c 5 Jul 2004 21:25:16 -0000 1.7 +1 -1
@@ -182,7 +182,7 @@
     }
 #endif
 
-    if (offset & ~TARGET_PAGE_MASK)
+    if (offset & ~TARGET_PAGE_MASK && 0)
         return -EINVAL;
 
     len = TARGET_PAGE_ALIGN(len);
#1 lore raw
Quoted 3 lines · On Wednesday 22 September 2004 23:16, [email protected] wrote:

BTW, is it possible to run qemu-arm under gdb and get breakpoints working? When I try, gdb complains because the qemu binary is remapped somewhere else in the addres space.

Configure with --static.

Quoted 11 lines
mmap.c   22 Sep 2004 20:18:53 -0000 renamed from mmap.c   5 Jul 2004 21:25:16 -0000       1.7 +0 -0
@@ -182,7 +182,7 @@
      }
  #endif


-    if (offset & ~TARGET_PAGE_MASK)
+    if (offset & ~TARGET_PAGE_MASK && 0)
         return -EINVAL;

     len = TARGET_PAGE_ALIGN(len);

Isn't this just papering over the problem? What about the other places in that function which return -EINVAL?

Also the later code handles host misalignment, whereas this test if for target misalignment.

Paul