From patchwork Tue Jul 27 17:25:35 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 60025 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 D93A1B6F01 for ; Wed, 28 Jul 2010 04:33:11 +1000 (EST) Received: from localhost ([127.0.0.1]:48791 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Odoxc-0001VZ-Nk for incoming@patchwork.ozlabs.org; Tue, 27 Jul 2010 14:33:04 -0400 Received: from [140.186.70.92] (port=37389 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Odojy-0003Dm-LB for qemu-devel@nongnu.org; Tue, 27 Jul 2010 14:19:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1Odojx-0003n6-J4 for qemu-devel@nongnu.org; Tue, 27 Jul 2010 14:18:58 -0400 Received: from b.mail.sonic.net ([64.142.19.5]:47023) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Odojx-0003mv-7n for qemu-devel@nongnu.org; Tue, 27 Jul 2010 14:18:57 -0400 Received: from are.twiddle.net (are.twiddle.net [75.101.38.216]) by b.mail.sonic.net (8.13.8.Beta0-Sonic/8.13.7) with ESMTP id o6RHPhFY019983 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Tue, 27 Jul 2010 10:25:43 -0700 Received: from are.twiddle.net (localhost [127.0.0.1]) by are.twiddle.net (8.14.4/8.14.4) with ESMTP id o6RHPhI1006943 for ; Tue, 27 Jul 2010 10:25:43 -0700 Received: (from rth@localhost) by are.twiddle.net (8.14.4/8.14.4/Submit) id o6RHPhDt006942 for qemu-devel@nongnu.org; Tue, 27 Jul 2010 10:25:43 -0700 From: Richard Henderson To: qemu-devel@nongnu.org Date: Tue, 27 Jul 2010 10:25:35 -0700 Message-Id: <1280251538-6860-10-git-send-email-rth@twiddle.net> X-Mailer: git-send-email 1.7.2 In-Reply-To: <1280251538-6860-1-git-send-email-rth@twiddle.net> References: <1280251538-6860-1-git-send-email-rth@twiddle.net> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4-2.6 Subject: [Qemu-devel] [PATCH 09/12] 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 | 31 +++++++++++++++++-------------- 1 files changed, 17 insertions(+), 14 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 86872b2..01020c5 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -1002,29 +1002,32 @@ 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); - info->stack_limit = error; - 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); + + info->stack_limit = error + guard; + stack_base = info->stack_limit + size - MAX_ARG_PAGES*TARGET_PAGE_SIZE; p += stack_base; for (i = 0 ; i < MAX_ARG_PAGES ; i++) {