qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Richard Henderson <rth@twiddle.net>
To: qemu-devel@nongnu.org
Cc: paul@codesourcery.com
Subject: [Qemu-devel] [PATCH 09/12] linux-user: Put the stack guard page at the top.
Date: Wed,  5 May 2010 11:07:45 -0700	[thread overview]
Message-ID: <1273082868-13675-10-git-send-email-rth@twiddle.net> (raw)
In-Reply-To: <cover.1270486025.git.rth@twiddle.net>

There are no supported stack-grows-up targets.  We were putting
the guard page at the highest address, i.e. the bottom of the stack.
Use the maximum of host and guest page size for the guard size.

Signed-off-by: Richard Henderson <rth@twiddle.net>
---
 linux-user/elfload.c |   29 ++++++++++++++++-------------
 1 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index fb03687..bd4b8fc 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -984,28 +984,31 @@ static abi_ulong copy_elf_strings(int argc,char ** argv, void **page,
 static abi_ulong setup_arg_pages(abi_ulong p, struct linux_binprm *bprm,
                                  struct image_info *info)
 {
-    abi_ulong stack_base, size, error;
+    abi_ulong stack_base, size, error, guard;
     int i;
 
     /* Create enough stack to hold everything.  If we don't use
-     * it for args, we'll use it for something else...
-     */
+       it for args, we'll use it for something else.  */
     size = guest_stack_size;
-    if (size < MAX_ARG_PAGES*TARGET_PAGE_SIZE)
+    if (size < MAX_ARG_PAGES*TARGET_PAGE_SIZE) {
         size = MAX_ARG_PAGES*TARGET_PAGE_SIZE;
-    error = target_mmap(0,
-                        size + qemu_host_page_size,
-                        PROT_READ | PROT_WRITE,
-                        MAP_PRIVATE | MAP_ANONYMOUS,
-                        -1, 0);
+    }
+    guard = TARGET_PAGE_SIZE;
+    if (guard < qemu_real_host_page_size) {
+        guard = qemu_real_host_page_size;
+    }
+
+    error = target_mmap(0, size + guard, PROT_READ | PROT_WRITE,
+                        MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
     if (error == -1) {
-        perror("stk mmap");
+        perror("mmap stack");
         exit(-1);
     }
-    /* we reserve one extra page at the top of the stack as guard */
-    target_mprotect(error + size, qemu_host_page_size, PROT_NONE);
 
-    stack_base = error + size - MAX_ARG_PAGES*TARGET_PAGE_SIZE;
+    /* We reserve one extra page at the top of the stack as guard.  */
+    target_mprotect(error, guard, PROT_NONE);
+
+    stack_base = error + guard + size - MAX_ARG_PAGES*TARGET_PAGE_SIZE;
     p += stack_base;
 
     for (i = 0 ; i < MAX_ARG_PAGES ; i++) {
-- 
1.7.0.1

  parent reply	other threads:[~2010-05-05 19:14 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-05 16:47 [Qemu-devel] [PATCH 00/14] Implement VDSO for x86_64-linux-user Richard Henderson
2010-03-31 22:12 ` [Qemu-devel] [PATCH 01/14] linux-user: Handle filesz < memsz for any PT_LOAD segment Richard Henderson
2010-04-04 18:38 ` [Qemu-devel] [PATCH 13/14] linux-user: Build vdso for x64 Richard Henderson
2010-04-04 19:07 ` [Qemu-devel] [PATCH 03/14] linux-user: Reindent elfload.c Richard Henderson
2010-04-04 19:34 ` [Qemu-devel] [PATCH 04/14] linux-user: Reduce lseek+reads while loading elf files Richard Henderson
2010-04-04 19:35 ` [Qemu-devel] [PATCH 05/14] linux-user: Fix ELF_DATA for Alpha Richard Henderson
2010-04-04 19:54 ` [Qemu-devel] [PATCH 06/14] linux-user: Clean up byte-swapping in elfload.c Richard Henderson
2010-04-04 21:16 ` [Qemu-devel] [PATCH 07/14] linux-user: Load symbols from the interpreter Richard Henderson
2010-04-04 22:04 ` [Qemu-devel] [PATCH 08/14] linux-user: Improve consistency checking in elf headers Richard Henderson
2010-04-04 22:14 ` [Qemu-devel] [PATCH 09/14] linux-user: Put the stack guard page at the top Richard Henderson
2010-04-04 22:31 ` [Qemu-devel] [PATCH 10/14] linux-user: Remove partial support for a.out interpreters Richard Henderson
2010-04-05  0:46 ` [Qemu-devel] [PATCH 11/14] linux-user: Extract load_elf_image from load_elf_interp Richard Henderson
2010-04-05  2:13 ` [Qemu-devel] [PATCH 14/14] linux-user: Load a VDSO for x86-64 Richard Henderson
2010-04-05 16:26 ` [Qemu-devel] [PATCH 02/14] Add more DT_* and AT_* constants to qemu's copy of elf.h Richard Henderson
2010-04-05 16:37 ` [Qemu-devel] [PATCH 12/14] linux-user: Re-use load_elf_image for the main binary Richard Henderson
2010-04-05 18:14   ` malc
2010-04-05 18:38     ` Richard Henderson
2010-04-28 19:36 ` [Qemu-devel] [PATCH 00/14] Implement VDSO for x86-64-linux-user, v2 Richard Henderson
2010-04-28 19:39   ` [Qemu-devel] [PATCH 04/14] linux-user: Reduce lseek+reads while loading elf files Richard Henderson
2010-04-28 19:39   ` [Qemu-devel] [PATCH 01/14] linux-user: Handle filesz < memsz for any PT_LOAD segment Richard Henderson
2010-04-28 19:39   ` [Qemu-devel] [PATCH 02/14] Add more DT_* and AT_* constants to qemu's copy of elf.h Richard Henderson
2010-04-28 19:39   ` [Qemu-devel] [PATCH 09/14] linux-user: Put the stack guard page at the top Richard Henderson
2010-04-28 19:39   ` [Qemu-devel] [PATCH 05/14] linux-user: Fix ELF_DATA for Alpha Richard Henderson
2010-04-28 19:39   ` [Qemu-devel] [PATCH 10/14] linux-user: Remove partial support for a.out interpreters Richard Henderson
2010-04-28 19:39   ` [Qemu-devel] [PATCH 06/14] linux-user: Clean up byte-swapping in elfload.c Richard Henderson
2010-04-28 19:39   ` [Qemu-devel] [PATCH 08/14] linux-user: Improve consistency checking in elf headers Richard Henderson
2010-04-28 19:39   ` [Qemu-devel] [PATCH 11/14] linux-user: Extract load_elf_image from load_elf_interp Richard Henderson
2010-04-28 19:39   ` [Qemu-devel] [PATCH 14/14] linux-user: Load a VDSO for x86-64 Richard Henderson
2010-04-28 19:39   ` [Qemu-devel] [PATCH 13/14] linux-user: Build vdso for x64 Richard Henderson
2010-04-28 19:39   ` [Qemu-devel] [PATCH 12/14] linux-user: Re-use load_elf_image for the main binary Richard Henderson
2010-04-28 19:39   ` [Qemu-devel] [PATCH 07/14] linux-user: Load symbols from the interpreter Richard Henderson
2010-04-28 19:39   ` [Qemu-devel] [PATCH 03/14] linux-user: Reindent elfload.c Richard Henderson
2010-05-05 18:07 ` [Qemu-devel] [PATCH 00/12] Cleanup linux-user/elfload.c, v2 Richard Henderson
2010-05-05 18:07 ` [Qemu-devel] [PATCH 01/12] linux-user: Handle filesz < memsz for any PT_LOAD segment Richard Henderson
2010-05-05 18:07 ` [Qemu-devel] [PATCH 02/12] Add more DT_* and AT_* constants to qemu's copy of elf.h Richard Henderson
2010-05-05 18:07 ` [Qemu-devel] [PATCH 03/12] linux-user: Reindent elfload.c Richard Henderson
2010-05-05 18:07 ` [Qemu-devel] [PATCH 04/12] linux-user: Reduce lseek+reads while loading elf files Richard Henderson
2010-05-05 18:07 ` [Qemu-devel] [PATCH 05/12] linux-user: Define ELF_DATA generically Richard Henderson
2010-05-05 18:07 ` [Qemu-devel] [PATCH 06/12] linux-user: Clean up byte-swapping in elfload.c Richard Henderson
2010-05-05 18:07 ` [Qemu-devel] [PATCH 07/12] linux-user: Load symbols from the interpreter Richard Henderson
2010-05-05 18:07 ` [Qemu-devel] [PATCH 08/12] linux-user: Improve consistency checking in elf headers Richard Henderson
2010-05-05 18:07 ` Richard Henderson [this message]
2010-05-05 18:07 ` [Qemu-devel] [PATCH 10/12] linux-user: Remove partial support for a.out interpreters Richard Henderson
2010-05-05 18:07 ` [Qemu-devel] [PATCH 11/12] linux-user: Extract load_elf_image from load_elf_interp Richard Henderson
2010-05-05 18:07 ` [Qemu-devel] [PATCH 12/12] linux-user: Re-use load_elf_image for the main binary Richard Henderson
  -- strict thread matches above, loose matches on Subject: below --
2010-07-27 17:25 [Qemu-devel] [PATCH 00/12 v4] Clean up linux-user/elfload.c Richard Henderson
2010-07-27 17:25 ` [Qemu-devel] [PATCH 09/12] linux-user: Put the stack guard page at the top Richard Henderson

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=1273082868-13675-10-git-send-email-rth@twiddle.net \
    --to=rth@twiddle.net \
    --cc=paul@codesourcery.com \
    --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).