2011-11-22 20:59:52 +00:00
|
|
|
/*-
|
2017-11-27 15:37:16 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
|
|
|
|
*
|
2011-11-22 20:59:52 +00:00
|
|
|
* Copyright (c) 2011 Mikolaj Golub
|
2015-09-05 17:02:01 +00:00
|
|
|
* Copyright (c) 2015 Allan Jude <allanjude@freebsd.org>
|
2011-11-22 20:59:52 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2020-09-27 23:01:54 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2011-11-22 20:59:52 +00:00
|
|
|
#include <sys/param.h>
|
2011-11-27 15:53:58 +00:00
|
|
|
#include <sys/elf.h>
|
2011-11-22 20:59:52 +00:00
|
|
|
#include <sys/sysctl.h>
|
|
|
|
#include <sys/user.h>
|
|
|
|
|
2011-11-27 15:53:58 +00:00
|
|
|
#include <vm/vm.h>
|
|
|
|
|
2011-11-22 20:59:52 +00:00
|
|
|
#include <err.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <libprocstat.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "procstat.h"
|
|
|
|
|
2011-12-12 22:01:33 +00:00
|
|
|
void
|
2013-04-20 08:15:43 +00:00
|
|
|
procstat_auxv(struct procstat *procstat, struct kinfo_proc *kipp)
|
2011-12-12 22:01:33 +00:00
|
|
|
{
|
2013-04-20 08:15:43 +00:00
|
|
|
Elf_Auxinfo *auxv;
|
|
|
|
u_int count, i;
|
|
|
|
static char prefix[256];
|
2011-12-12 22:01:33 +00:00
|
|
|
|
2017-10-14 18:38:36 +00:00
|
|
|
if ((procstat_opts & PS_OPT_NOHEADER) == 0)
|
2015-09-05 17:02:01 +00:00
|
|
|
xo_emit("{T:/%5s %-16s %-16s %-16s}\n", "PID", "COMM", "AUXV",
|
|
|
|
"VALUE");
|
|
|
|
|
2013-04-20 08:15:43 +00:00
|
|
|
auxv = procstat_getauxv(procstat, kipp, &count);
|
|
|
|
if (auxv == NULL)
|
2011-11-22 20:59:52 +00:00
|
|
|
return;
|
2015-09-05 17:02:01 +00:00
|
|
|
snprintf(prefix, sizeof(prefix), "%5d %-16s", kipp->ki_pid,
|
|
|
|
kipp->ki_comm);
|
|
|
|
|
|
|
|
xo_emit("{e:process_id/%5d/%d}{e:command/%-16s/%s}", kipp->ki_pid,
|
2011-11-27 15:53:58 +00:00
|
|
|
kipp->ki_comm);
|
2015-09-05 17:02:01 +00:00
|
|
|
|
2013-04-20 08:15:43 +00:00
|
|
|
for (i = 0; i < count; i++) {
|
2011-11-23 07:34:09 +00:00
|
|
|
switch(auxv[i].a_type) {
|
2011-11-22 20:59:52 +00:00
|
|
|
case AT_NULL:
|
|
|
|
return;
|
|
|
|
case AT_IGNORE:
|
|
|
|
break;
|
|
|
|
case AT_EXECFD:
|
2015-09-05 17:02:01 +00:00
|
|
|
xo_emit("{dw:/%s}{Lw:/%-16s/%s}{:AT_EXECFD/%ld}\n",
|
|
|
|
prefix, "AT_EXECFD", (long)auxv[i].a_un.a_val);
|
2011-11-22 20:59:52 +00:00
|
|
|
break;
|
|
|
|
case AT_PHDR:
|
2015-09-05 17:02:01 +00:00
|
|
|
xo_emit("{dw:/%s}{Lw:/%-16s/%s}{:AT_PHDR/%p}\n",
|
|
|
|
prefix, "AT_PHDR", auxv[i].a_un.a_ptr);
|
2011-11-22 20:59:52 +00:00
|
|
|
break;
|
|
|
|
case AT_PHENT:
|
2015-09-05 17:02:01 +00:00
|
|
|
xo_emit("{dw:/%s}{Lw:/%-16s/%s}{:AT_PHENT/%ld}\n",
|
|
|
|
prefix, "AT_PHENT", (long)auxv[i].a_un.a_val);
|
2011-11-22 20:59:52 +00:00
|
|
|
break;
|
|
|
|
case AT_PHNUM:
|
2015-09-05 17:02:01 +00:00
|
|
|
xo_emit("{dw:/%s}{Lw:/%-16s/%s}{:AT_PHNUM/%ld}\n",
|
|
|
|
prefix, "AT_PHNUM", (long)auxv[i].a_un.a_val);
|
2011-11-22 20:59:52 +00:00
|
|
|
break;
|
|
|
|
case AT_PAGESZ:
|
2015-09-05 17:02:01 +00:00
|
|
|
xo_emit("{dw:/%s}{Lw:/%-16s/%s}{:AT_PAGESZ/%ld}\n",
|
|
|
|
prefix, "AT_PAGESZ", (long)auxv[i].a_un.a_val);
|
2011-11-22 20:59:52 +00:00
|
|
|
break;
|
|
|
|
case AT_BASE:
|
2015-09-05 17:02:01 +00:00
|
|
|
xo_emit("{dw:/%s}{Lw:/%-16s/%s}{:AT_BASE/%p}\n",
|
|
|
|
prefix, "AT_BASE", auxv[i].a_un.a_ptr);
|
2011-11-22 20:59:52 +00:00
|
|
|
break;
|
|
|
|
case AT_FLAGS:
|
2015-09-05 17:02:01 +00:00
|
|
|
xo_emit("{dw:/%s}{Lw:/%-16s/%s}{:AT_FLAGS/%#lx}\n",
|
|
|
|
prefix, "AT_FLAGS", (u_long)auxv[i].a_un.a_val);
|
2011-11-22 20:59:52 +00:00
|
|
|
break;
|
|
|
|
case AT_ENTRY:
|
2015-09-05 17:02:01 +00:00
|
|
|
xo_emit("{dw:/%s}{Lw:/%-16s/%s}{:AT_ENTRY/%p}\n",
|
|
|
|
prefix, "AT_ENTRY", auxv[i].a_un.a_ptr);
|
2011-11-22 20:59:52 +00:00
|
|
|
break;
|
2011-11-23 07:34:09 +00:00
|
|
|
#ifdef AT_NOTELF
|
2011-11-22 20:59:52 +00:00
|
|
|
case AT_NOTELF:
|
2015-09-05 17:02:01 +00:00
|
|
|
xo_emit("{dw:/%s}{Lw:/%-16s/%s}{:AT_NOTELF/%ld}\n",
|
|
|
|
prefix, "AT_NOTELF", (long)auxv[i].a_un.a_val);
|
2011-11-22 20:59:52 +00:00
|
|
|
break;
|
2011-11-23 07:34:09 +00:00
|
|
|
#endif
|
|
|
|
#ifdef AT_UID
|
2011-11-22 20:59:52 +00:00
|
|
|
case AT_UID:
|
2015-09-05 17:02:01 +00:00
|
|
|
xo_emit("{dw:/%s}{Lw:/%-16s/%s}{:AT_UID/%ld}\n",
|
|
|
|
prefix, "AT_UID", (long)auxv[i].a_un.a_val);
|
2011-11-22 20:59:52 +00:00
|
|
|
break;
|
2011-11-23 07:34:09 +00:00
|
|
|
#endif
|
|
|
|
#ifdef AT_EUID
|
2011-11-22 20:59:52 +00:00
|
|
|
case AT_EUID:
|
2015-09-05 17:02:01 +00:00
|
|
|
xo_emit("{dw:/%s}{Lw:/%-16s/%s}{:AT_EUID/%ld}\n",
|
|
|
|
prefix, "AT_EUID", (long)auxv[i].a_un.a_val);
|
2011-11-22 20:59:52 +00:00
|
|
|
break;
|
2011-11-23 07:34:09 +00:00
|
|
|
#endif
|
|
|
|
#ifdef AT_GID
|
2011-11-22 20:59:52 +00:00
|
|
|
case AT_GID:
|
2015-09-05 17:02:01 +00:00
|
|
|
xo_emit("{dw:/%s}{Lw:/%-16s/%s}{:AT_GID/%ld}\n",
|
|
|
|
prefix, "AT_GID", (long)auxv[i].a_un.a_val);
|
2011-11-22 20:59:52 +00:00
|
|
|
break;
|
2011-11-23 07:34:09 +00:00
|
|
|
#endif
|
|
|
|
#ifdef AT_EGID
|
2011-11-22 20:59:52 +00:00
|
|
|
case AT_EGID:
|
2015-09-05 17:02:01 +00:00
|
|
|
xo_emit("{dw:/%s}{Lw:/%-16s/%s}{:AT_EGID/%ld}\n",
|
|
|
|
prefix, "AT_EGID", (long)auxv[i].a_un.a_val);
|
2011-11-22 20:59:52 +00:00
|
|
|
break;
|
2011-11-23 07:34:09 +00:00
|
|
|
#endif
|
2011-11-22 20:59:52 +00:00
|
|
|
case AT_EXECPATH:
|
2015-09-05 17:02:01 +00:00
|
|
|
xo_emit("{dw:/%s}{Lw:/%-16s/%s}{:AT_EXECPATH/%p}\n",
|
|
|
|
prefix, "AT_EXECPATH", auxv[i].a_un.a_ptr);
|
2011-11-22 20:59:52 +00:00
|
|
|
break;
|
|
|
|
case AT_CANARY:
|
2015-09-05 17:02:01 +00:00
|
|
|
xo_emit("{dw:/%s}{Lw:/%-16s/%s}{:AT_CANARY/%p}\n",
|
|
|
|
prefix, "AT_CANARY", auxv[i].a_un.a_ptr);
|
2011-11-22 20:59:52 +00:00
|
|
|
break;
|
|
|
|
case AT_CANARYLEN:
|
2015-09-05 17:02:01 +00:00
|
|
|
xo_emit("{dw:/%s}{Lw:/%-16s/%s}{:AT_CANARYLEN/%ld}\n",
|
|
|
|
prefix, "AT_CANARYLEN", (long)auxv[i].a_un.a_val);
|
2011-11-22 20:59:52 +00:00
|
|
|
break;
|
|
|
|
case AT_OSRELDATE:
|
2015-09-05 17:02:01 +00:00
|
|
|
xo_emit("{dw:/%s}{Lw:/%-16s/%s}{:AT_OSRELDATE/%ld}\n",
|
|
|
|
prefix, "AT_OSRELDATE", (long)auxv[i].a_un.a_val);
|
2011-11-22 20:59:52 +00:00
|
|
|
break;
|
|
|
|
case AT_NCPUS:
|
2015-09-05 17:02:01 +00:00
|
|
|
xo_emit("{dw:/%s}{Lw:/%-16s/%s}{:AT_NCPUS/%ld}\n",
|
|
|
|
prefix, "AT_NCPUS", (long)auxv[i].a_un.a_val);
|
2011-11-22 20:59:52 +00:00
|
|
|
break;
|
|
|
|
case AT_PAGESIZES:
|
2015-09-05 17:02:01 +00:00
|
|
|
xo_emit("{dw:/%s}{Lw:/%-16s/%s}{:AT_PAGESIZES/%p}\n",
|
|
|
|
prefix, "AT_PAGESIZES", auxv[i].a_un.a_ptr);
|
2011-11-22 20:59:52 +00:00
|
|
|
break;
|
|
|
|
case AT_PAGESIZESLEN:
|
2015-09-05 17:02:01 +00:00
|
|
|
xo_emit("{dw:/%s}{Lw:/%-16s/%s}"
|
|
|
|
"{:AT_PAGESIZESLEN/%ld}\n", prefix,
|
|
|
|
"AT_PAGESIZESLEN", (long)auxv[i].a_un.a_val);
|
2011-11-22 20:59:52 +00:00
|
|
|
break;
|
|
|
|
case AT_STACKPROT:
|
2011-11-27 15:53:58 +00:00
|
|
|
if ((auxv[i].a_un.a_val & VM_PROT_EXECUTE) != 0)
|
2015-09-05 17:02:01 +00:00
|
|
|
xo_emit("{dw:/%s}{Lw:/%-16s/%s}"
|
|
|
|
"{:AT_STACKPROT/%s}\n", prefix,
|
2015-09-06 17:47:03 +00:00
|
|
|
"AT_STACKPROT", "EXECUTABLE");
|
2011-11-27 15:53:58 +00:00
|
|
|
else
|
2015-09-05 17:02:01 +00:00
|
|
|
xo_emit("{dw:/%s}{Lw:/%-16s/%s}"
|
|
|
|
"{:AT_STACKPROT/%s}\n", prefix,
|
2015-09-06 17:47:03 +00:00
|
|
|
"AT_STACKPROT", "NONEXECUTABLE");
|
2011-11-22 20:59:52 +00:00
|
|
|
break;
|
2012-09-16 05:52:54 +00:00
|
|
|
#ifdef AT_TIMEKEEP
|
|
|
|
case AT_TIMEKEEP:
|
2015-09-05 17:02:01 +00:00
|
|
|
xo_emit("{dw:/%s}{Lw:/%-16s/%s}{:AT_TIMEKEEP/%p}\n",
|
|
|
|
prefix, "AT_TIMEKEEP", auxv[i].a_un.a_ptr);
|
2011-11-22 20:59:52 +00:00
|
|
|
break;
|
2018-10-29 23:48:20 +00:00
|
|
|
#endif
|
|
|
|
#ifdef AT_EHDRFLAGS
|
|
|
|
case AT_EHDRFLAGS:
|
|
|
|
xo_emit("{dw:/%s}{Lw:/%-16s/%s}{:AT_EHDRFLAGS/%#lx}\n",
|
|
|
|
prefix, "AT_EHDRFLAGS", (u_long)auxv[i].a_un.a_val);
|
|
|
|
break;
|
2019-06-11 00:59:46 +00:00
|
|
|
#endif
|
|
|
|
#ifdef AT_HWCAP
|
|
|
|
case AT_HWCAP:
|
|
|
|
xo_emit("{dw:/%s}{Lw:/%-16s/%s}{:AT_HWCAP/%#lx}\n",
|
|
|
|
prefix, "AT_HWCAP", (u_long)auxv[i].a_un.a_val);
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef AT_HWCAP2
|
|
|
|
case AT_HWCAP2:
|
|
|
|
xo_emit("{dw:/%s}{Lw:/%-16s/%s}{:AT_HWCAP2/%#lx}\n",
|
|
|
|
prefix, "AT_HWCAP2", (u_long)auxv[i].a_un.a_val);
|
|
|
|
break;
|
2020-02-09 12:10:37 +00:00
|
|
|
#endif
|
|
|
|
#ifdef AT_BSDFLAGS
|
|
|
|
case AT_BSDFLAGS:
|
|
|
|
xo_emit("{dw:/%s}{Lw:/%-16s/%s}{:AT_BSDFLAGS/%#lx}\n",
|
|
|
|
prefix, "AT_BSDFLAGS", (u_long)auxv[i].a_un.a_val);
|
|
|
|
break;
|
2020-04-15 20:25:38 +00:00
|
|
|
#endif
|
|
|
|
#ifdef AT_ARGC
|
|
|
|
case AT_ARGC:
|
|
|
|
xo_emit("{dw:/%s}{Lw:/%-16s/%s}{:AT_ARGC/%ld}\n",
|
|
|
|
prefix, "AT_ARGC", (long)auxv[i].a_un.a_val);
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef AT_ARGV
|
|
|
|
case AT_ARGV:
|
|
|
|
xo_emit("{dw:/%s}{Lw:/%-16s/%s}{:AT_ARGV/%p}\n",
|
|
|
|
prefix, "AT_ARGV", auxv[i].a_un.a_ptr);
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef AT_ENVC
|
|
|
|
case AT_ENVC:
|
|
|
|
xo_emit("{dw:/%s}{Lw:/%-16s/%s}{:AT_ENVC/%ld}\n",
|
|
|
|
prefix, "AT_ENVC", (long)auxv[i].a_un.a_val);
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef AT_ENVV
|
|
|
|
case AT_ENVV:
|
|
|
|
xo_emit("{dw:/%s}{Lw:/%-16s/%s}{:AT_ENVV/%p}\n",
|
|
|
|
prefix, "AT_ENVV", auxv[i].a_un.a_ptr);
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef AT_PS_STRINGS
|
|
|
|
case AT_PS_STRINGS:
|
|
|
|
xo_emit("{dw:/%s}{Lw:/%-16s/%s}{:AT_PS_STRINGS/%p}\n",
|
|
|
|
prefix, "AT_PS_STRINGS", auxv[i].a_un.a_ptr);
|
|
|
|
break;
|
2012-09-16 05:52:54 +00:00
|
|
|
#endif
|
2011-11-22 20:59:52 +00:00
|
|
|
default:
|
2015-09-05 17:02:01 +00:00
|
|
|
xo_emit("{dw:/%s}{Lw:/%16ld/%ld}{:UNKNOWN/%#lx}\n",
|
|
|
|
prefix, auxv[i].a_type, auxv[i].a_un.a_val);
|
2011-11-22 20:59:52 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-09-05 17:02:01 +00:00
|
|
|
xo_emit("\n");
|
2013-04-20 08:15:43 +00:00
|
|
|
procstat_freeauxv(procstat, auxv);
|
2011-11-22 20:59:52 +00:00
|
|
|
}
|
|
|
|
|