qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Alexander Graf <agraf@suse.de>
To: qemu-devel@nongnu.org
Cc: adrian@suse.de, riku.voipio@iki.fi
Subject: [Qemu-devel] [PATCH 1/5] linux-user: save auxv length
Date: Wed,  2 Nov 2011 20:23:22 +0100	[thread overview]
Message-ID: <1320261806-13194-2-git-send-email-agraf@suse.de> (raw)
In-Reply-To: <1320261806-13194-1-git-send-email-agraf@suse.de>

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 <agraf@suse.de>
---
 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;
-- 
1.6.0.2

  reply	other threads:[~2011-11-02 19:23 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-02 19:23 [Qemu-devel] [PATCH 0/5] linux-user: fake some /proc/self entries Alexander Graf
2011-11-02 19:23 ` Alexander Graf [this message]
2011-11-02 19:23   ` [Qemu-devel] [PATCH 2/5] linux-user: add open() hijack infrastructure Alexander Graf
2011-11-02 19:23     ` [Qemu-devel] [PATCH 3/5] linux-user: fake /proc/self/maps Alexander Graf
2011-11-02 19:23       ` [Qemu-devel] [PATCH 4/5] linux-user: fake /proc/self/stat Alexander Graf
2011-11-02 19:23         ` [Qemu-devel] [PATCH 5/5] linux-user: fake /proc/self/auxv Alexander Graf
2011-11-03 19:28       ` [Qemu-devel] [PATCH 3/5] linux-user: fake /proc/self/maps Alexander Graf
2011-11-03  9:34     ` [Qemu-devel] [PATCH 2/5] linux-user: add open() hijack infrastructure David Gilbert
2011-11-03 18:33       ` Alexander Graf
2011-11-03 10:47 ` [Qemu-devel] [PATCH 0/5] linux-user: fake some /proc/self entries Riku Voipio
2011-11-03 18:34   ` Alexander Graf

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=1320261806-13194-2-git-send-email-agraf@suse.de \
    --to=agraf@suse.de \
    --cc=adrian@suse.de \
    --cc=qemu-devel@nongnu.org \
    --cc=riku.voipio@iki.fi \
    /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).