mark host pages as reserved
PATCH 1/1 mark host pages as reserved
Hi all,
This patch teaches the user space emulator about host pages. It marks present host page mappings with PAGE_RESERVED so mmap_find_vma() properly can detect that pages at mmap_next_start should be skipped over instead of being overwritten using mmap(). Without this patch I experience crashes with the arm or sh4 user space emulator together with sbox2. This combination sometimes result in that host libraries are mapped into the qemu process space starting from 0x4xxxxxxx instead of 0xb7xxxxxx. This together with the initial value of mmap_next_start results in a segfault when the elf loader overwrites the mapped host libraries with the target binary.
Comments anyone?
/ magnus
cpu-all.h +1 -0
@@ -716,6 +716,7 @@ extern unsigned long qemu_host_page_mask/* original state of the write flag (used when tracking self-modifying code */ #define PAGE_WRITE_ORG 0x0010 +#define PAGE_RESERVED 0x0020void page_dump (FILE *f);int page_get_flags (target_ulong address);
exec.c +21 -0
@@ -209,6 +209,27 @@ static void page_init(void) qemu_host_page_mask = ~(qemu_host_page_size -1 ); l1_phys_map =qemu_vmalloc (L1_SIZE *sizeof (void *));memset (l1_phys_map,0 ,L1_SIZE *sizeof (void *)); + +#if !defined(_WIN32) && defined(CONFIG_USER_ONLY ) + { +long long startaddr, endaddr; +FILE *f; +int n; + + f =fopen ("/proc/self/maps" ,"r" ); +if (f) { +do { + n =fscanf (f,"%llx-%llx %*[^\n]\n" , &startaddr, &endaddr); +if (n ==2 ) { +page_set_flags (TARGET_PAGE_ALIGN (startaddr), +TARGET_PAGE_ALIGN (endaddr), +PAGE_RESERVED ); + } + }while (!feof (f)); +fclose (f); + } + } +#endif }static inline PageDesc *page_find_alloc (unsigned int index)
linux-user/mmap.c +1 -1
@@ -162,7 +162,7 @@ static abi_ulong mmap_next_start = 0x400'start'. If 'start' == 0, then a default start address is used. Return -1 if error. */ -/* XXX: should mark pages used by the host as reserved to be sure not +/* page_init() marks pages used by the host as reserved to be sure not to use them. */ static abi_ulong mmap_find_vma (abi_ulong start,abi_ulong size) {
Hi everyone,
Quoted 13 lines · Magnus Damm
Hi all,
This patch teaches the user space emulator about host pages. It marks present host page mappings with
PAGE_RESERVEDsommap_find_vma()properly can detect that pages atmmap_next_startshould be skipped over instead of being overwritten usingmmap(). Without this patch I experience crashes with the arm or sh4 user space emulator together with sbox2. This combination sometimes result in that host libraries are mapped into the qemu process space starting from 0x4xxxxxxx instead of 0xb7xxxxxx. This together with the initial value ofmmap_next_startresults in a segfault when the elf loader overwrites the mapped host libraries with the target binary.
Quoted 1 line
Comments anyone?
Any reason for not applying this patch? This fixes user space emulation for all targets.
Thanks,
/ magnus
Quoted 16 lines · Magnus Damm
Hi everyone,
Quoted 13 lines · Magnus Damm
Hi all,
This patch teaches the user space emulator about host pages. It marks present host page mappings with
PAGE_RESERVEDsommap_find_vma()properly can detect that pages atmmap_next_startshould be skipped over instead of being overwritten usingmmap(). Without this patch I experience crashes with the arm or sh4 user space emulator together with sbox2. This combination sometimes result in that host libraries are mapped into the qemu process space starting from 0x4xxxxxxx instead of 0xb7xxxxxx. This together with the initial value ofmmap_next_startresults in a segfault when the elf loader overwrites the mapped host libraries with the target binary.
Quoted 4 lines
Quoted 1 line
Comments anyone?
Any reason for not applying this patch? This fixes user space emulation for all targets.
It seems OK.
Fabrice.