diff options
author | trociny <trociny@FreeBSD.org> | 2013-04-14 20:03:48 +0000 |
---|---|---|
committer | trociny <trociny@FreeBSD.org> | 2013-04-14 20:03:48 +0000 |
commit | 4bb922ab39d272b2c3139e57ae1743f929e2007d (patch) | |
tree | 1e13176202cccd9634933948529b6211c2745898 /sys/kern | |
parent | 335f3dbd9136ccf61c363fee13dc4a90c89cce50 (diff) | |
download | FreeBSD-src-4bb922ab39d272b2c3139e57ae1743f929e2007d.zip FreeBSD-src-4bb922ab39d272b2c3139e57ae1743f929e2007d.tar.gz |
Similarly to proc_getargv() and proc_getenvv(), export proc_getauxv()
to be able to reuse the code.
MFC after: 3 weeks
Diffstat (limited to 'sys/kern')
-rw-r--r-- | sys/kern/kern_proc.c | 47 |
1 files changed, 29 insertions, 18 deletions
diff --git a/sys/kern/kern_proc.c b/sys/kern/kern_proc.c index ded8950..cb1ec9d 100644 --- a/sys/kern/kern_proc.c +++ b/sys/kern/kern_proc.c @@ -1759,6 +1759,27 @@ proc_getenvv(struct thread *td, struct proc *p, struct sbuf *sb) 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 @@ -1864,9 +1885,8 @@ sysctl_kern_proc_auxv(SYSCTL_HANDLER_ARGS) 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); @@ -1878,21 +1898,12 @@ sysctl_kern_proc_auxv(SYSCTL_HANDLER_ARGS) 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); } /* |