Module Name:    src
Committed By:   kamil
Date:           Wed Mar 29 19:52:30 UTC 2017

Modified Files:
        src/sys/kern: core_elf32.c sys_ptrace_common.c

Log Message:
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>


To generate a diff of this commit:
cvs rdiff -u -r1.51 -r1.52 src/sys/kern/core_elf32.c
cvs rdiff -u -r1.18 -r1.19 src/sys/kern/sys_ptrace_common.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/core_elf32.c
diff -u src/sys/kern/core_elf32.c:1.51 src/sys/kern/core_elf32.c:1.52
--- src/sys/kern/core_elf32.c:1.51	Wed Jan 25 17:55:47 2017
+++ src/sys/kern/core_elf32.c	Wed Mar 29 19:52:30 2017
@@ -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 @@ coredump_note_auxv(struct lwp *l, struct
 
 	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);

Index: src/sys/kern/sys_ptrace_common.c
diff -u src/sys/kern/sys_ptrace_common.c:1.18 src/sys/kern/sys_ptrace_common.c:1.19
--- src/sys/kern/sys_ptrace_common.c:1.18	Thu Feb 23 04:48:36 2017
+++ src/sys/kern/sys_ptrace_common.c	Wed Mar 29 19:52:30 2017
@@ -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 @@ __KERNEL_RCSID(0, "$NetBSD: sys_ptrace_c
 #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 @@ do_ptrace(struct ptrace_methods *ptm, st
 		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)

Reply via email to