From patchwork Thu Aug 6 22:41:02 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kai Backman X-Patchwork-Id: 30911 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 bilbo.ozlabs.org (Postfix) with ESMTPS id 779B9B7B60 for ; Fri, 7 Aug 2009 15:08:45 +1000 (EST) Received: from localhost ([127.0.0.1]:58567 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MZHh0-0007rr-Kb for incoming@patchwork.ozlabs.org; Fri, 07 Aug 2009 01:08:38 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MZBe9-0005mO-0N for qemu-devel@nongnu.org; Thu, 06 Aug 2009 18:41:17 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MZBe4-0005m3-GL for qemu-devel@nongnu.org; Thu, 06 Aug 2009 18:41:16 -0400 Received: from [199.232.76.173] (port=48892 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MZBe4-0005m0-Dm for qemu-devel@nongnu.org; Thu, 06 Aug 2009 18:41:12 -0400 Received: from smtp-out.google.com ([216.239.45.13]:49035) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1MZBe3-000559-3b for qemu-devel@nongnu.org; Thu, 06 Aug 2009 18:41:12 -0400 Received: from spaceape8.eur.corp.google.com (spaceape8.eur.corp.google.com [172.28.16.142]) by smtp-out.google.com with ESMTP id n76Mf64s010986 for ; Thu, 6 Aug 2009 15:41:07 -0700 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=google.com; s=beta; t=1249598467; bh=FCpac05NY/0Sd7s/mdNAMIR4qV8=; h=DomainKey-Signature:MIME-Version:In-Reply-To:References:Date: Message-ID:Subject:From:To:Cc:Content-Type:X-System-Of-Record; b=r dDhaqJJnc1uIJP5h9oQf9WvX9McVMsh6Bpy6wGw/bboejQ0kBk6vL/VgFM9u+ea/fpI UC2QoaTQYEc3zSHD9A== DomainKey-Signature: a=rsa-sha1; s=beta; d=google.com; c=nofws; q=dns; h=mime-version:in-reply-to:references:date:message-id:subject:from:to: cc:content-type:x-system-of-record; b=HEJr2E/PMg7vjAW5d12YxrVaYFzaTL4092aUthlXF+EmFYQhZ2E+8bHXuUyEqF4ll yXs6dnROBXn5mVa4i4T+A== Received: from an-out-0708.google.com (anac38.prod.google.com [10.100.54.38]) by spaceape8.eur.corp.google.com with ESMTP id n76MesoN009924 for ; Thu, 6 Aug 2009 15:41:04 -0700 Received: by an-out-0708.google.com with SMTP id c38so267824ana.0 for ; Thu, 06 Aug 2009 15:41:03 -0700 (PDT) MIME-Version: 1.0 Received: by 10.150.182.21 with SMTP id e21mr999688ybf.145.1249598462943; Thu, 06 Aug 2009 15:41:02 -0700 (PDT) In-Reply-To: <20090618185731.GC24046@kos.to> References: <20090618185731.GC24046@kos.to> Date: Thu, 6 Aug 2009 15:41:02 -0700 Message-ID: Subject: Re: [Qemu-devel] Patch to fix mapping of elf pheaders specifying both .data and .bss segments From: Kai Backman To: Riku Voipio X-System-Of-Record: true X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 3) X-Mailman-Approved-At: Fri, 07 Aug 2009 01:07:11 -0400 Cc: qemu-devel@nongnu.org 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 On Thu, Jun 18, 2009 at 11:57 AM, Riku Voipio wrote: > The patch attached is totally messed up thou. Sorry for the delay. I was vacationing in Finland (incidentally).. To restart the thread, I've re-attached the patch. Kai diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 190ad14..e4e75d5 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -1211,7 +1211,7 @@ int load_elf_binary(struct linux_binprm * bprm, struct target_pt_regs * regs, abi_ulong mapped_addr; struct elf_phdr * elf_ppnt; struct elf_phdr *elf_phdata; - abi_ulong elf_bss, k, elf_brk; + abi_ulong elf_bss, last_bss, mapped_bss, k, elf_brk; int retval; char * elf_interpreter; abi_ulong elf_entry, interp_load_addr = 0; @@ -1271,6 +1271,7 @@ int load_elf_binary(struct linux_binprm * bprm, struct target_pt_regs * regs, elf_ppnt = elf_phdata; elf_bss = 0; + last_bss = 0; elf_brk = 0; @@ -1495,12 +1496,24 @@ int load_elf_binary(struct linux_binprm * bprm, struct target_pt_regs * regs, k = elf_ppnt->p_vaddr + elf_ppnt->p_filesz; if (k > elf_bss) elf_bss = k; + k = elf_ppnt->p_vaddr + elf_ppnt->p_memsz; + if (k > last_bss) + last_bss = k; if ((elf_ppnt->p_flags & PF_X) && end_code < k) end_code = k; if (end_data < k) end_data = k; k = elf_ppnt->p_vaddr + elf_ppnt->p_memsz; if (k > elf_brk) elf_brk = k; + if (!elf_interpreter && last_bss > elf_bss) { + padzero(elf_bss, last_bss); + mapped_bss = TARGET_ELF_PAGESTART(elf_bss + qemu_host_page_size - 1); + + /* Map the last of the bss segment */ + target_mmap(load_bias + mapped_bss, last_bss-mapped_bss, + PROT_READ|PROT_WRITE|PROT_EXEC, + MAP_FIXED|MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); + } } elf_entry += load_bias;