Skip to contentSkip to conversation

Fix page protection flag handling solving ARM emulation issues

PATCH New Richard Purdie 1 participant 1 message Apr 23, 2008

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix page protection flag handling solving ARM emulation issues

Hi,

I've been seeing some strange errors when trying to mix binaries from two different ARM toolchains. They work on real hardware but they don't work under qemu failing with an error about being unable to change the stack area protection bits. I tracked this down to an mprotect call failing inside the dynamic linker.

The reason is that ARM has some strange page protection bits (from mman.h):

#define PROT_GROWSDOWN 0x01000000 /* Extend change to start of
growsdown vma (mprotect only). */
#define PROT_GROWSUP 0x02000000 /* Extend change to start of
growsup vma (mprotect only). */

and if qemu sees these as page protection flags it gets rather upset.

A fix is to:

a) not error if these bits are present
b) not pass them to the host system since that doesn't like them

I've attached a simple patch which fixes the ARM on x86 case. This shouldn't break anything existing although some tweaking of the bits may be needed for some mixtures of other architectures.

Regards,

Richard

linux-user/mmap.c +1 -2
Index: qemu-0.9.1/linux-user/mmap.c
===================================================================
@@ -49,8 +49,7 @@
     end = start + len;
     if (end < start)
         return -EINVAL;
-    if (prot & ~(PROT_READ | PROT_WRITE | PROT_EXEC))
-        return -EINVAL;
+    prot = prot & (PROT_READ | PROT_WRITE | PROT_EXEC);
     if (len == 0)
         return 0;