Source-Changes-HG archive

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

[src/trunk]: src/sys/kern Generate ELF AUXV for core(5) and ptrace(2) limited...



details:   https://anonhg.NetBSD.org/src/rev/74d4fb2384c1
branches:  trunk
changeset: 352382:74d4fb2384c1
user:      kamil <kamil%NetBSD.org@localhost>
date:      Wed Mar 29 19:52:30 2017 +0000

description:
Generate ELF AUXV for core(5) and ptrace(2) limited to the vector TYPE x V

Previously PT_DUMPCORE and PIOD_READ_AUXV and regular core dumping retrieved
the vector of AuxInfo {a_type, a_v} + MAXPATHLEN + ALIGN(1).

The extra data is not actually needed in the returned chunk. It can be
retrieved with PT_READ_I operations and it's the preferred way to access
them as the AuxInfo fields contain pointers (void* format) to them.

This changes the behavior of the kernel, no stable releases are affected
with this move. Current software is not affected as other systems already
stop generating data on AT_NULL. This streamlines the NetBSD behavior with
other ELF format OSes. This move also simplifies determination if we got
all the needed data inside the debugger and we no longer need to eliminate
the unneeded chunk at the end.

Sponsored by <The NetBSD Foundation>

diffstat:

 sys/kern/core_elf32.c        |  6 +++---
 sys/kern/sys_ptrace_common.c |  7 ++++---
 2 files changed, 7 insertions(+), 6 deletions(-)

diffs (62 lines):

diff -r 6f2c485f8e73 -r 74d4fb2384c1 sys/kern/core_elf32.c
--- a/sys/kern/core_elf32.c     Wed Mar 29 15:28:42 2017 +0000
+++ b/sys/kern/core_elf32.c     Wed Mar 29 19:52:30 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: core_elf32.c,v 1.51 2017/01/25 17:55:47 christos Exp $ */
+/*     $NetBSD: core_elf32.c,v 1.52 2017/03/29 19:52:30 kamil Exp $    */
 
 /*
  * Copyright (c) 2001 Wasabi Systems, Inc.
@@ -40,7 +40,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(1, "$NetBSD: core_elf32.c,v 1.51 2017/01/25 17:55:47 christos Exp $");
+__KERNEL_RCSID(1, "$NetBSD: core_elf32.c,v 1.52 2017/03/29 19:52:30 kamil Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_coredump.h"
@@ -416,7 +416,7 @@
 
        size_t ptrsz = PROC_PTRSZ(p);
        uauxv = (void *)((char *)pss.ps_envstr + (pss.ps_nenvstr + 1) * ptrsz);
-       size_t len = p->p_execsw->es_arglen;
+       size_t len = ELF_AUX_ENTRIES * sizeof(AuxInfo);
 
        kauxv = kmem_alloc(len, KM_SLEEP);
        error = copyin_proc(p, uauxv, kauxv, len);
diff -r 6f2c485f8e73 -r 74d4fb2384c1 sys/kern/sys_ptrace_common.c
--- a/sys/kern/sys_ptrace_common.c      Wed Mar 29 15:28:42 2017 +0000
+++ b/sys/kern/sys_ptrace_common.c      Wed Mar 29 19:52:30 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sys_ptrace_common.c,v 1.18 2017/02/23 04:48:36 kamil Exp $     */
+/*     $NetBSD: sys_ptrace_common.c,v 1.19 2017/03/29 19:52:30 kamil Exp $     */
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -118,7 +118,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sys_ptrace_common.c,v 1.18 2017/02/23 04:48:36 kamil Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_ptrace_common.c,v 1.19 2017/03/29 19:52:30 kamil Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ptrace.h"
@@ -129,6 +129,7 @@
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/proc.h>
+#include <sys/exec_elf.h>
 #include <sys/errno.h>
 #include <sys/exec.h>
 #include <sys/pax.h>
@@ -624,7 +625,7 @@
                case PIOD_READ_AUXV:
                        req = PT_READ_D;
                        uio.uio_rw = UIO_READ;
-                       tmp = t->p_execsw->es_arglen;
+                       tmp = ELF_AUX_ENTRIES * sizeof(AuxInfo);
                        if (uio.uio_offset > tmp)
                                return EIO;
                        if (uio.uio_resid > tmp - uio.uio_offset)



Home | Main Index | Thread Index | Old Index