From patchwork Wed Nov 2 19:23:22 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Graf X-Patchwork-Id: 123317 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id BA67FB6F8B for ; Thu, 3 Nov 2011 06:23:53 +1100 (EST) Received: from localhost ([::1]:49557 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RLgPZ-0005OI-U1 for incoming@patchwork.ozlabs.org; Wed, 02 Nov 2011 15:23:45 -0400 Received: from eggs.gnu.org ([140.186.70.92]:39147) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RLgPO-0005F5-8H for qemu-devel@nongnu.org; Wed, 02 Nov 2011 15:23:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RLgPM-0005LD-7O for qemu-devel@nongnu.org; Wed, 02 Nov 2011 15:23:34 -0400 Received: from cantor2.suse.de ([195.135.220.15]:53005 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RLgPL-0005Km-PC for qemu-devel@nongnu.org; Wed, 02 Nov 2011 15:23:32 -0400 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.221.2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx2.suse.de (Postfix) with ESMTP id 559D28A95F; Wed, 2 Nov 2011 20:23:31 +0100 (CET) From: Alexander Graf To: qemu-devel@nongnu.org Date: Wed, 2 Nov 2011 20:23:22 +0100 Message-Id: <1320261806-13194-2-git-send-email-agraf@suse.de> X-Mailer: git-send-email 1.6.0.2 In-Reply-To: <1320261806-13194-1-git-send-email-agraf@suse.de> References: <1320261806-13194-1-git-send-email-agraf@suse.de> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4-2.6 X-Received-From: 195.135.220.15 Cc: adrian@suse.de, riku.voipio@iki.fi Subject: [Qemu-devel] [PATCH 1/5] linux-user: save auxv length X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org We create our own AUXV segment on stack and save a pointer to it. However we don't save the length of it, so any code that wants to do anything useful with it later on has to walk it again. Instead, let's remember the length of our AUXV segment. This simplifies later uses by a lot. Signed-off-by: Alexander Graf --- linux-user/elfload.c | 15 ++++----------- linux-user/qemu.h | 1 + 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index a413976..3a8eee4 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -1246,6 +1246,7 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc, struct image_info *interp_info) { abi_ulong sp; + abi_ulong sp_auxv; int size; int i; abi_ulong u_rand_bytes; @@ -1317,6 +1318,7 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc, sp -= n; put_user_ual(id, sp); \ } while(0) + sp_auxv = sp; NEW_AUX_ENT (AT_NULL, 0); /* There must be exactly DLINFO_ITEMS entries here. */ @@ -1347,6 +1349,7 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc, #undef NEW_AUX_ENT info->saved_auxv = sp; + info->auxv_len = sp_auxv - sp; sp = loader_build_argptr(envc, argc, sp, p, 0); return sp; @@ -2330,9 +2333,8 @@ static void fill_auxv_note(struct memelfnote *note, const TaskState *ts) { elf_addr_t auxv = (elf_addr_t)ts->info->saved_auxv; elf_addr_t orig_auxv = auxv; - abi_ulong val; void *ptr; - int i, len; + int len = ts->info->auxv_len; /* * Auxiliary vector is stored in target process stack. It contains @@ -2340,15 +2342,6 @@ static void fill_auxv_note(struct memelfnote *note, const TaskState *ts) * strictly necessary but we do it here for sake of completeness. */ - /* find out lenght of the vector, AT_NULL is terminator */ - i = len = 0; - do { - get_user_ual(val, auxv); - i += 2; - auxv += 2 * sizeof (elf_addr_t); - } while (val != AT_NULL); - len = i * sizeof (elf_addr_t); - /* read in whole auxv vector and copy it to memelfnote */ ptr = lock_user(VERIFY_READ, orig_auxv, len, 0); if (ptr != NULL) { diff --git a/linux-user/qemu.h b/linux-user/qemu.h index 55ad9d8..ef08d39 100644 --- a/linux-user/qemu.h +++ b/linux-user/qemu.h @@ -48,6 +48,7 @@ struct image_info { abi_ulong code_offset; abi_ulong data_offset; abi_ulong saved_auxv; + abi_ulong auxv_len; abi_ulong arg_start; abi_ulong arg_end; int personality;