qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Magnus Damm" <magnus.damm@gmail.com>
To: qemu-devel@nongnu.org
Cc: Lauri Leukkunen <lle@rahina.org>
Subject: [Qemu-devel] [PATCH] mark host pages as reserved
Date: Wed, 5 Dec 2007 17:45:03 +0900	[thread overview]
Message-ID: <aec7e5c30712050045u79bcf3abkf93c2d7dbb067a8b@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 692 bytes --]

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

[-- Attachment #2: qemu-cvs-20071205b-reserve-host-pages.patch --]
[-- Type: application/octet-stream, Size: 1735 bytes --]

--- 0001/cpu-all.h
+++ work/cpu-all.h	2007-12-05 17:05:36.000000000 +0900
@@ -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  0x0020
 
 void page_dump(FILE *f);
 int page_get_flags(target_ulong address);
--- 0001/exec.c
+++ work/exec.c	2007-12-05 17:06:07.000000000 +0900
@@ -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)
--- 0001/linux-user/mmap.c
+++ work/linux-user/mmap.c	2007-12-05 17:05:36.000000000 +0900
@@ -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)
 {

             reply	other threads:[~2007-12-05  8:45 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-12-05  8:45 Magnus Damm [this message]
2007-12-11  3:21 ` [Qemu-devel] Re: [PATCH] mark host pages as reserved Magnus Damm
2007-12-11  9:14   ` Fabrice Bellard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aec7e5c30712050045u79bcf3abkf93c2d7dbb067a8b@mail.gmail.com \
    --to=magnus.damm@gmail.com \
    --cc=lle@rahina.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).