Module Name:    src
Committed By:   christos
Date:           Fri Jun  7 23:35:53 UTC 2019

Modified Files:
        src/sys/compat/netbsd32: netbsd32_exec_elf32.c
        src/sys/kern: exec_elf.c
        src/sys/sys: exec_elf.h param.h

Log Message:
deduplicate the elf auxv builder code, welcome to 8.99.43


To generate a diff of this commit:
cvs rdiff -u -r1.44 -r1.45 src/sys/compat/netbsd32/netbsd32_exec_elf32.c
cvs rdiff -u -r1.97 -r1.98 src/sys/kern/exec_elf.c
cvs rdiff -u -r1.160 -r1.161 src/sys/sys/exec_elf.h
cvs rdiff -u -r1.590 -r1.591 src/sys/sys/param.h

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

Modified files:

Index: src/sys/compat/netbsd32/netbsd32_exec_elf32.c
diff -u src/sys/compat/netbsd32/netbsd32_exec_elf32.c:1.44 src/sys/compat/netbsd32/netbsd32_exec_elf32.c:1.45
--- src/sys/compat/netbsd32/netbsd32_exec_elf32.c:1.44	Fri Jun  7 16:13:54 2019
+++ src/sys/compat/netbsd32/netbsd32_exec_elf32.c	Fri Jun  7 19:35:53 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: netbsd32_exec_elf32.c,v 1.44 2019/06/07 20:13:54 christos Exp $	*/
+/*	$NetBSD: netbsd32_exec_elf32.c,v 1.45 2019/06/07 23:35:53 christos Exp $	*/
 /*	from: NetBSD: exec_aout.c,v 1.15 1996/09/26 23:34:46 cgd Exp */
 
 /*
@@ -57,7 +57,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: netbsd32_exec_elf32.c,v 1.44 2019/06/07 20:13:54 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_exec_elf32.c,v 1.45 2019/06/07 23:35:53 christos Exp $");
 
 #define	ELFSIZE		32
 
@@ -134,102 +134,10 @@ int
 netbsd32_elf32_copyargs(struct lwp *l, struct exec_package *pack,
     struct ps_strings *arginfo, char **stackp, void *argp)
 {
-	size_t len, vlen;
-	AuxInfo ai[ELF_AUX_ENTRIES], *a, *execname;
-	struct elf_args *ap;
 	int error;
 
 	if ((error = netbsd32_copyargs(l, pack, arginfo, stackp, argp)) != 0)
 		return error;
 
-	a = ai;
-
-	memset(ai, 0, sizeof(ai));
-
-	/*
-	 * Push extra arguments on the stack needed by dynamically
-	 * linked binaries
-	 */
-	if ((ap = (struct elf_args *)pack->ep_emul_arg)) {
-
-		a->a_type = AT_PHDR;
-		a->a_v = ap->arg_phaddr;
-		a++;
-
-		a->a_type = AT_PHENT;
-		a->a_v = ap->arg_phentsize;
-		a++;
-
-		a->a_type = AT_PHNUM;
-		a->a_v = ap->arg_phnum;
-		a++;
-
-		a->a_type = AT_PAGESZ;
-		a->a_v = PAGE_SIZE;
-		a++;
-
-		a->a_type = AT_BASE;
-		a->a_v = ap->arg_interp;
-		a++;
-
-		a->a_type = AT_FLAGS;
-		a->a_v = 0;
-		a++;
-
-		a->a_type = AT_ENTRY;
-		a->a_v = ap->arg_entry;
-		a++;
-
-		a->a_type = AT_EUID;
-		a->a_v = kauth_cred_geteuid(l->l_cred);
-		a++;
-
-		a->a_type = AT_RUID;
-		a->a_v = kauth_cred_getuid(l->l_cred);
-		a++;
-
-		a->a_type = AT_EGID;
-		a->a_v = kauth_cred_getegid(l->l_cred);
-		a++;
-
-		a->a_type = AT_RGID;
-		a->a_v = kauth_cred_getgid(l->l_cred);
-		a++;
-
-		a->a_type = AT_STACKBASE;
-		a->a_v = l->l_proc->p_stackbase;
-		a++;
-
-		execname = a;
-		a->a_type = AT_SUN_EXECNAME;
-		a++;
-
-		exec_free_emul_arg(pack);
-	} else {
-		execname = NULL;
-	}
-
-	a->a_type = AT_NULL;
-	a->a_v = 0;
-	a++;
-
-	vlen = (a - ai) * sizeof(ai[0]);
-
-	KASSERT(vlen <= sizeof(ai));
-
-	if (execname) {
-		char *path = l->l_proc->p_path;
-		execname->a_v = (uintptr_t)(*stackp + vlen);
-		len = strlen(path) + 1;
-		if ((error = copyout(path, (*stackp + vlen), len)) != 0)
-			return error;
-		len = ALIGN(len);
-	} else {
-		len = 0;
-	}
-	if ((error = copyout(ai, *stackp, len)) != 0)
-		return error;
-	*stackp += vlen + len;
-
-	return 0;
+	return elf32_populate_auxv(l, pack, stackp);
 }

Index: src/sys/kern/exec_elf.c
diff -u src/sys/kern/exec_elf.c:1.97 src/sys/kern/exec_elf.c:1.98
--- src/sys/kern/exec_elf.c:1.97	Thu Apr 12 16:49:08 2018
+++ src/sys/kern/exec_elf.c	Fri Jun  7 19:35:52 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: exec_elf.c,v 1.97 2018/04/12 20:49:08 christos Exp $	*/
+/*	$NetBSD: exec_elf.c,v 1.98 2019/06/07 23:35:52 christos Exp $	*/
 
 /*-
  * Copyright (c) 1994, 2000, 2005, 2015 The NetBSD Foundation, Inc.
@@ -57,7 +57,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(1, "$NetBSD: exec_elf.c,v 1.97 2018/04/12 20:49:08 christos Exp $");
+__KERNEL_RCSID(1, "$NetBSD: exec_elf.c,v 1.98 2019/06/07 23:35:52 christos Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_pax.h"
@@ -89,6 +89,7 @@ extern struct emul emul_netbsd;
 
 #define elf_check_header	ELFNAME(check_header)
 #define elf_copyargs		ELFNAME(copyargs)
+#define elf_populate_auxv	ELFNAME(populate_auxv)
 #define elf_load_interp		ELFNAME(load_interp)
 #define elf_load_psection	ELFNAME(load_psection)
 #define exec_elf_makecmds	ELFNAME2(exec,makecmds)
@@ -149,22 +150,15 @@ elf_placedynexec(struct exec_package *ep
 	return 0;
 }
 
-/*
- * Copy arguments onto the stack in the normal way, but add some
- * extra information in case of dynamic binding.
- */
+
 int
-elf_copyargs(struct lwp *l, struct exec_package *pack,
-    struct ps_strings *arginfo, char **stackp, void *argp)
+elf_populate_auxv(struct lwp *l, struct exec_package *pack, char **stackp)
 {
 	size_t len, vlen;
 	AuxInfo ai[ELF_AUX_ENTRIES], *a, *execname;
 	struct elf_args *ap;
 	int error;
 
-	if ((error = copyargs(l, pack, arginfo, stackp, argp)) != 0)
-		return error;
-
 	a = ai;
 
 	memset(ai, 0, sizeof(ai));
@@ -266,6 +260,22 @@ elf_copyargs(struct lwp *l, struct exec_
 }
 
 /*
+ * Copy arguments onto the stack in the normal way, but add some
+ * extra information in case of dynamic binding.
+ */
+int
+elf_copyargs(struct lwp *l, struct exec_package *pack,
+    struct ps_strings *arginfo, char **stackp, void *argp)
+{
+	int error;
+
+	if ((error = copyargs(l, pack, arginfo, stackp, argp)) != 0)
+		return error;
+
+	return elf_populate_auxv(l, pack, stackp);
+}
+
+/*
  * elf_check_header():
  *
  * Check header for validity; return 0 if ok, ENOEXEC if error

Index: src/sys/sys/exec_elf.h
diff -u src/sys/sys/exec_elf.h:1.160 src/sys/sys/exec_elf.h:1.161
--- src/sys/sys/exec_elf.h:1.160	Thu May 24 13:05:18 2018
+++ src/sys/sys/exec_elf.h	Fri Jun  7 19:35:52 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: exec_elf.h,v 1.160 2018/05/24 17:05:18 christos Exp $	*/
+/*	$NetBSD: exec_elf.h,v 1.161 2019/06/07 23:35:52 christos Exp $	*/
 
 /*-
  * Copyright (c) 1994 The NetBSD Foundation, Inc.
@@ -1341,6 +1341,7 @@ struct exec_package;
 
 #ifdef EXEC_ELF32
 int	exec_elf32_makecmds(struct lwp *, struct exec_package *);
+int	elf32_populate_auxv(struct lwp *, struct exec_package *, char **);
 int	elf32_copyargs(struct lwp *, struct exec_package *,
     struct ps_strings *, char **, void *);
 
@@ -1353,6 +1354,7 @@ int	elf32_check_header(Elf32_Ehdr *);
 
 #ifdef EXEC_ELF64
 int	exec_elf64_makecmds(struct lwp *, struct exec_package *);
+int	elf64_populate_auxv(struct lwp *, struct exec_package *, char **);
 int	elf64_copyargs(struct lwp *, struct exec_package *,
     struct ps_strings *, char **, void *);
 

Index: src/sys/sys/param.h
diff -u src/sys/sys/param.h:1.590 src/sys/sys/param.h:1.591
--- src/sys/sys/param.h:1.590	Wed May 29 06:09:01 2019
+++ src/sys/sys/param.h	Fri Jun  7 19:35:52 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: param.h,v 1.590 2019/05/29 10:09:01 msaitoh Exp $	*/
+/*	$NetBSD: param.h,v 1.591 2019/06/07 23:35:52 christos Exp $	*/
 
 /*-
  * Copyright (c) 1982, 1986, 1989, 1993
@@ -67,7 +67,7 @@
  *	2.99.9		(299000900)
  */
 
-#define	__NetBSD_Version__	899004200	/* NetBSD 8.99.42 */
+#define	__NetBSD_Version__	899004300	/* NetBSD 8.99.43 */
 
 #define __NetBSD_Prereq__(M,m,p) (((((M) * 100000000) + \
     (m) * 1000000) + (p) * 100) <= __NetBSD_Version__)

Reply via email to