diff options
author | bdrewery <bdrewery@FreeBSD.org> | 2017-10-23 18:25:21 +0000 |
---|---|---|
committer | bdrewery <bdrewery@FreeBSD.org> | 2017-10-23 18:25:21 +0000 |
commit | 4b13cb33c40720888fe967367bf009ca6cf272fd (patch) | |
tree | 4491d3f5e0ad545aca21ef8c4ab7b103f46b625f /lib/libprocstat/libprocstat.c | |
parent | b916159a6fa3858710d1a0f75cb5a26825ccc698 (diff) | |
download | FreeBSD-src-4b13cb33c40720888fe967367bf009ca6cf272fd.zip FreeBSD-src-4b13cb33c40720888fe967367bf009ca6cf272fd.tar.gz |
MFC r316286:
Add support for capturing 'struct ptrace_lwpinfo' for signals resulting in a
process dumping core in the corefile.
Direct stable changed: Padding added to struct thread and td_si added to end
with explicit bzeroing when forking/initializing a thread to preserve KBI.
Diffstat (limited to 'lib/libprocstat/libprocstat.c')
-rw-r--r-- | lib/libprocstat/libprocstat.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/lib/libprocstat/libprocstat.c b/lib/libprocstat/libprocstat.c index 9dc9800..9c6877c 100644 --- a/lib/libprocstat/libprocstat.c +++ b/lib/libprocstat/libprocstat.c @@ -1,4 +1,5 @@ /*- + * Copyright (c) 2017 Dell EMC * Copyright (c) 2009 Stanislav Sedov <stas@FreeBSD.org> * Copyright (c) 1988, 1993 * The Regents of the University of California. All rights reserved. @@ -65,6 +66,7 @@ __FBSDID("$FreeBSD$"); #define _KERNEL #include <sys/mount.h> #include <sys/pipe.h> +#include <sys/ptrace.h> #include <ufs/ufs/quota.h> #include <ufs/ufs/inode.h> #include <fs/devfs/devfs.h> @@ -2469,6 +2471,48 @@ procstat_freeauxv(struct procstat *procstat __unused, Elf_Auxinfo *auxv) free(auxv); } +static struct ptrace_lwpinfo * +procstat_getptlwpinfo_core(struct procstat_core *core, unsigned int *cntp) +{ + void *buf; + struct ptrace_lwpinfo *pl; + unsigned int cnt; + size_t len; + + cnt = procstat_core_note_count(core, PSC_TYPE_PTLWPINFO); + if (cnt == 0) + return (NULL); + + len = cnt * sizeof(*pl); + buf = calloc(1, len); + pl = procstat_core_get(core, PSC_TYPE_PTLWPINFO, buf, &len); + if (pl == NULL) { + free(buf); + return (NULL); + } + *cntp = len / sizeof(*pl); + return (pl); +} + +struct ptrace_lwpinfo * +procstat_getptlwpinfo(struct procstat *procstat, unsigned int *cntp) +{ + switch (procstat->type) { + case PROCSTAT_CORE: + return (procstat_getptlwpinfo_core(procstat->core, cntp)); + default: + warnx("unknown access method: %d", procstat->type); + return (NULL); + } +} + +void +procstat_freeptlwpinfo(struct procstat *procstat __unused, + struct ptrace_lwpinfo *pl) +{ + free(pl); +} + static struct kinfo_kstack * procstat_getkstack_sysctl(pid_t pid, int *cntp) { |