Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys Add a note for the auxv array so we can find our load lo...



details:   https://anonhg.NetBSD.org/src/rev/6c51fd8be96d
branches:  trunk
changeset: 345384:6c51fd8be96d
user:      christos <christos%NetBSD.org@localhost>
date:      Tue May 24 00:49:55 2016 +0000

description:
Add a note for the auxv array so we can find our load location from a
core file of a PIE binary.

diffstat:

 sys/kern/core_elf32.c |  59 +++++++++++++++++++++++++++++++++++++++++++++-----
 sys/sys/exec_elf.h    |   5 +++-
 2 files changed, 57 insertions(+), 7 deletions(-)

diffs (123 lines):

diff -r a2e7176d4bfb -r 6c51fd8be96d sys/kern/core_elf32.c
--- a/sys/kern/core_elf32.c     Mon May 23 23:36:02 2016 +0000
+++ b/sys/kern/core_elf32.c     Tue May 24 00:49:55 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: core_elf32.c,v 1.45 2014/04/02 17:19:49 matt Exp $     */
+/*     $NetBSD: core_elf32.c,v 1.46 2016/05/24 00:49:56 christos Exp $ */
 
 /*
  * Copyright (c) 2001 Wasabi Systems, Inc.
@@ -40,7 +40,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(1, "$NetBSD: core_elf32.c,v 1.45 2014/04/02 17:19:49 matt Exp $");
+__KERNEL_RCSID(1, "$NetBSD: core_elf32.c,v 1.46 2016/05/24 00:49:56 christos Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_coredump.h"
@@ -343,12 +343,11 @@
        return (0);
 }
 
-static int
-ELFNAMEEND(coredump_notes)(struct lwp *l, struct note_state *ns)
+static void
+coredump_note_procinfo(struct lwp *l, struct note_state *ns)
 {
        struct proc *p;
        struct netbsd_elfcore_procinfo cpi;
-       int error;
        struct lwp *l0;
        sigset_t ss1, ss2;
 
@@ -398,6 +397,54 @@
 
        ELFNAMEEND(coredump_savenote)(ns, ELF_NOTE_NETBSD_CORE_PROCINFO,
            ELF_NOTE_NETBSD_CORE_NAME, &cpi, sizeof(cpi));
+}
+
+static int
+coredump_note_auxv(struct lwp *l, struct note_state *ns)
+{
+       struct ps_strings pss;
+       int error;
+       struct proc *p = l->l_proc;
+       struct vmspace *vm;
+       void *uauxv, *kauxv;
+       size_t len;
+
+       if ((error = copyin_psstrings(p, &pss)) != 0)
+               return error;
+
+       if (pss.ps_envstr == NULL)
+               return EIO;
+
+        vm = p->p_vmspace;
+       uvmspace_addref(vm);
+
+       len = p->p_execsw->es_arglen * sizeof(char *);
+       uauxv = (void *)(pss.ps_envstr + pss.ps_nenvstr + 1);
+       kauxv = kmem_alloc(len, KM_SLEEP);
+       error = copyin_vmspace(vm, uauxv, kauxv, len);
+
+       uvmspace_free(vm);
+
+       if (error == 0) {
+               ELFNAMEEND(coredump_savenote)(ns, ELF_NOTE_NETBSD_CORE_AUXV,
+                   ELF_NOTE_NETBSD_CORE_NAME, kauxv, len);
+       }
+       
+       kmem_free(kauxv, len);
+       return error;
+}
+
+static int
+ELFNAMEEND(coredump_notes)(struct lwp *l, struct note_state *ns)
+{
+       int error;
+       struct lwp *l0;
+       struct proc *p = l->l_proc;
+
+       coredump_note_procinfo(l, ns);
+       error = coredump_note_auxv(l, ns);
+       if (error)
+               return error;
 
        /* XXX Add hook for machdep per-proc notes. */
 
@@ -407,7 +454,7 @@
         */
        error = ELFNAMEEND(coredump_note)(l, ns);
        if (error)
-               return (error);
+               return error;
 
        /*
         * Now, for each LWP, write the register info and any other
diff -r a2e7176d4bfb -r 6c51fd8be96d sys/sys/exec_elf.h
--- a/sys/sys/exec_elf.h        Mon May 23 23:36:02 2016 +0000
+++ b/sys/sys/exec_elf.h        Tue May 24 00:49:55 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: exec_elf.h,v 1.153 2016/02/19 20:45:21 christos Exp $  */
+/*     $NetBSD: exec_elf.h,v 1.154 2016/05/24 00:49:55 christos Exp $  */
 
 /*-
  * Copyright (c) 1994 The NetBSD Foundation, Inc.
@@ -975,6 +975,8 @@
  *
  *     ELF_NOTE_NETBSD_CORE_PROCINFO
  *             Note is a "netbsd_elfcore_procinfo" structure.
+ *     ELF_NOTE_NETBSD_CORE_AUXV
+ *             Note is an array of AuxInfo structures.
  *
  * We also use ptrace(2) request numbers (the ones that exist in
  * machine-dependent space) to identify register info notes.  The
@@ -988,6 +990,7 @@
 #define ELF_NOTE_NETBSD_CORE_NAME      "NetBSD-CORE"
 
 #define ELF_NOTE_NETBSD_CORE_PROCINFO  1
+#define ELF_NOTE_NETBSD_CORE_AUXV      2
 
 #define NETBSD_ELFCORE_PROCINFO_VERSION 1
 



Home | Main Index | Thread Index | Old Index