[Midnightbsd-cvs] src [9344] trunk/sys: Similarly to proc_getargv() and proc_getenvv(), export proc_getauxv()

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Sat Mar 4 11:44:42 EST 2017


Revision: 9344
          http://svnweb.midnightbsd.org/src/?rev=9344
Author:   laffer1
Date:     2017-03-04 11:44:42 -0500 (Sat, 04 Mar 2017)
Log Message:
-----------
Similarly to proc_getargv() and proc_getenvv(), export proc_getauxv()
to be able to reuse the code.

Obtained from: FreeBSD

Modified Paths:
--------------
    trunk/sys/kern/kern_proc.c
    trunk/sys/sys/proc.h

Modified: trunk/sys/kern/kern_proc.c
===================================================================
--- trunk/sys/kern/kern_proc.c	2017-03-04 16:44:09 UTC (rev 9343)
+++ trunk/sys/kern/kern_proc.c	2017-03-04 16:44:42 UTC (rev 9344)
@@ -1760,6 +1760,27 @@
 	return (get_ps_strings(curthread, p, sb, PROC_ENV));
 }
 
+int
+proc_getauxv(struct thread *td, struct proc *p, struct sbuf *sb)
+{
+	size_t vsize, size;
+	char **auxv;
+	int error;
+
+	error = get_proc_vector(td, p, &auxv, &vsize, PROC_AUX);
+	if (error == 0) {
+#ifdef COMPAT_FREEBSD32
+		if (SV_PROC_FLAG(p, SV_ILP32) != 0)
+			size = vsize * sizeof(Elf32_Auxinfo);
+		else
+#endif
+			size = vsize * sizeof(Elf_Auxinfo);
+		error = sbuf_bcat(sb, auxv, size);
+		free(auxv, M_TEMP);
+	}
+	return (error);
+}
+
 /*
  * This sysctl allows a process to retrieve the argument list or process
  * title for another process without groping around in the address space
@@ -1865,9 +1886,8 @@
 	int *name = (int *)arg1;
 	u_int namelen = arg2;
 	struct proc *p;
-	size_t vsize, size;
-	char **auxv;
-	int error;
+	struct sbuf sb;
+	int error, error2;
 
 	if (namelen != 1)
 		return (EINVAL);
@@ -1879,21 +1899,12 @@
 		PRELE(p);
 		return (0);
 	}
-	error = get_proc_vector(curthread, p, &auxv, &vsize, PROC_AUX);
-	if (error == 0) {
-#ifdef COMPAT_FREEBSD32
-		if (SV_PROC_FLAG(p, SV_ILP32) != 0)
-			size = vsize * sizeof(Elf32_Auxinfo);
-		else
-#endif
-		size = vsize * sizeof(Elf_Auxinfo);
-		PRELE(p);
-		error = SYSCTL_OUT(req, auxv, size);
-		free(auxv, M_TEMP);
-	} else {
-		PRELE(p);
-	}
-	return (error);
+	sbuf_new_for_sysctl(&sb, NULL, GET_PS_STRINGS_CHUNK_SZ, req);
+	error = proc_getauxv(curthread, p, &sb);
+	error2 = sbuf_finish(&sb);
+	PRELE(p);
+	sbuf_delete(&sb);
+	return (error != 0 ? error : error2);
 }
 
 /*

Modified: trunk/sys/sys/proc.h
===================================================================
--- trunk/sys/sys/proc.h	2017-03-04 16:44:09 UTC (rev 9343)
+++ trunk/sys/sys/proc.h	2017-03-04 16:44:42 UTC (rev 9344)
@@ -887,6 +887,7 @@
 void	pargs_drop(struct pargs *pa);
 void	pargs_hold(struct pargs *pa);
 int	proc_getargv(struct thread *td, struct proc *p, struct sbuf *sb);
+int	proc_getauxv(struct thread *td, struct proc *p, struct sbuf *sb);
 int	proc_getenvv(struct thread *td, struct proc *p, struct sbuf *sb);
 void	procinit(void);
 void	proc_linkup0(struct proc *p, struct thread *td);



More information about the Midnightbsd-cvs mailing list