From patchwork Sun Apr 4 22:14:47 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 51236 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id C0C2DB7D53 for ; Thu, 29 Apr 2010 06:20:01 +1000 (EST) Received: from localhost ([127.0.0.1]:45734 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O7Di8-00043u-Rh for incoming@patchwork.ozlabs.org; Wed, 28 Apr 2010 16:18:20 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1O7D6s-0005nB-Th for qemu-devel@nongnu.org; Wed, 28 Apr 2010 15:39:51 -0400 Received: from [140.186.70.92] (port=51736 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O7D6n-0005hz-Mj for qemu-devel@nongnu.org; Wed, 28 Apr 2010 15:39:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1O7D6l-0007X2-00 for qemu-devel@nongnu.org; Wed, 28 Apr 2010 15:39:45 -0400 Received: from are.twiddle.net ([75.149.56.221]:55994) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1O7D6k-0007Vv-Nt for qemu-devel@nongnu.org; Wed, 28 Apr 2010 15:39:42 -0400 Received: by are.twiddle.net (Postfix, from userid 5000) id 2AAD0106D; Wed, 28 Apr 2010 12:39:41 -0700 (PDT) Message-Id: <9b2d67800c4c8cc9a491560fd101e6276f07ecb4.1272483393.git.rth@twiddle.net> In-Reply-To: References: From: Richard Henderson Date: Sun, 4 Apr 2010 15:14:47 -0700 To: qemu-devel@nongnu.org X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) Cc: Subject: [Qemu-devel] [PATCH 09/14] linux-user: Put the stack guard page at the top. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 --- 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 5853a30..464160a 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -1002,28 +1002,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++) {