Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys factor out getauxv code.
details: https://anonhg.NetBSD.org/src/rev/c71000fba224
branches: trunk
changeset: 352414:c71000fba224
user: christos <christos%NetBSD.org@localhost>
date: Thu Mar 30 20:17:11 2017 +0000
description:
factor out getauxv code.
diffstat:
sys/kern/core_elf32.c | 28 ++++++++--------------------
sys/kern/kern_proc.c | 35 +++++++++++++++++++++++++++++++++--
sys/sys/proc.h | 3 ++-
3 files changed, 43 insertions(+), 23 deletions(-)
diffs (125 lines):
diff -r f22d8957efa3 -r c71000fba224 sys/kern/core_elf32.c
--- a/sys/kern/core_elf32.c Thu Mar 30 20:16:42 2017 +0000
+++ b/sys/kern/core_elf32.c Thu Mar 30 20:17:11 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: core_elf32.c,v 1.53 2017/03/29 22:48:03 kamil Exp $ */
+/* $NetBSD: core_elf32.c,v 1.54 2017/03/30 20:17:11 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.53 2017/03/29 22:48:03 kamil Exp $");
+__KERNEL_RCSID(1, "$NetBSD: core_elf32.c,v 1.54 2017/03/30 20:17:11 christos Exp $");
#ifdef _KERNEL_OPT
#include "opt_coredump.h"
@@ -403,30 +403,18 @@
static int
coredump_note_auxv(struct lwp *l, struct note_state *ns)
{
- struct ps_strings pss;
int error;
- struct proc *p = l->l_proc;
- void *uauxv, *kauxv;
+ size_t len;
+ void *kauxv;
- if ((error = copyin_psstrings(p, &pss)) != 0)
+ if ((error = proc_getauxv(l->l_proc, &kauxv, &len)) != 0)
return error;
- if (pss.ps_envstr == NULL)
- return EIO;
-
- 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;
-
- kauxv = kmem_alloc(len, KM_SLEEP);
- error = copyin_proc(p, uauxv, kauxv, len);
- if (error == 0) {
- ELFNAMEEND(coredump_savenote)(ns, ELF_NOTE_NETBSD_CORE_AUXV,
- ELF_NOTE_NETBSD_CORE_NAME, kauxv, len);
- }
+ ELFNAMEEND(coredump_savenote)(ns, ELF_NOTE_NETBSD_CORE_AUXV,
+ ELF_NOTE_NETBSD_CORE_NAME, kauxv, len);
kmem_free(kauxv, len);
- return error;
+ return 0;
}
static int
diff -r f22d8957efa3 -r c71000fba224 sys/kern/kern_proc.c
--- a/sys/kern/kern_proc.c Thu Mar 30 20:16:42 2017 +0000
+++ b/sys/kern/kern_proc.c Thu Mar 30 20:17:11 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_proc.c,v 1.205 2017/01/28 16:43:59 christos Exp $ */
+/* $NetBSD: kern_proc.c,v 1.206 2017/03/30 20:17:11 christos Exp $ */
/*-
* Copyright (c) 1999, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_proc.c,v 1.205 2017/01/28 16:43:59 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_proc.c,v 1.206 2017/03/30 20:17:11 christos Exp $");
#ifdef _KERNEL_OPT
#include "opt_kstack.h"
@@ -2470,3 +2470,34 @@
return 0;
#endif
}
+
+int
+proc_getauxv(struct proc *p, void **buf, size_t *len)
+{
+ struct ps_strings pss;
+ int error;
+ void *uauxv, *kauxv;
+
+ if ((error = copyin_psstrings(p, &pss)) != 0)
+ return error;
+
+ if (pss.ps_envstr == NULL)
+ return EIO;
+
+ size_t ptrsz = PROC_PTRSZ(p);
+ uauxv = (void *)((char *)pss.ps_envstr + (pss.ps_nenvstr + 1) * ptrsz);
+ size_t size = p->p_execsw->es_arglen;
+
+ kauxv = kmem_alloc(size, KM_SLEEP);
+
+ error = copyin_proc(p, uauxv, kauxv, size);
+ if (error) {
+ kmem_free(kauxv, size);
+ return error;
+ }
+
+ *buf = kauxv;
+ *len = size;
+
+ return 0;
+}
diff -r f22d8957efa3 -r c71000fba224 sys/sys/proc.h
--- a/sys/sys/proc.h Thu Mar 30 20:16:42 2017 +0000
+++ b/sys/sys/proc.h Thu Mar 30 20:17:11 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: proc.h,v 1.339 2017/03/24 17:40:44 christos Exp $ */
+/* $NetBSD: proc.h,v 1.340 2017/03/30 20:17:11 christos Exp $ */
/*-
* Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -543,6 +543,7 @@
int proc_vmspace_getref(struct proc *, struct vmspace **);
void proc_crmod_leave(kauth_cred_t, kauth_cred_t, bool);
void proc_crmod_enter(void);
+int proc_getauxv(struct proc *, void **, size_t *);
int proc_specific_key_create(specificdata_key_t *, specificdata_dtor_t);
void proc_specific_key_delete(specificdata_key_t);
Home |
Main Index |
Thread Index |
Old Index