2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2009 Stanislav Sedov <stas@FreeBSD.org>
5 * Copyright (c) 2017 Dell EMC
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #ifndef _LIBPROCSTAT_H_
33 #define _LIBPROCSTAT_H_
36 * XXX: sys/elf.h conflicts with zfs_context.h. Workaround this by not
37 * including conflicting parts when building zfs code.
42 #include <sys/caprights.h>
47 #define PS_FST_VTYPE_VNON 1
48 #define PS_FST_VTYPE_VREG 2
49 #define PS_FST_VTYPE_VDIR 3
50 #define PS_FST_VTYPE_VBLK 4
51 #define PS_FST_VTYPE_VCHR 5
52 #define PS_FST_VTYPE_VLNK 6
53 #define PS_FST_VTYPE_VSOCK 7
54 #define PS_FST_VTYPE_VFIFO 8
55 #define PS_FST_VTYPE_VBAD 9
56 #define PS_FST_VTYPE_UNKNOWN 255
61 #define PS_FST_TYPE_VNODE 1
62 #define PS_FST_TYPE_FIFO 2
63 #define PS_FST_TYPE_SOCKET 3
64 #define PS_FST_TYPE_PIPE 4
65 #define PS_FST_TYPE_PTS 5
66 #define PS_FST_TYPE_KQUEUE 6
67 #define PS_FST_TYPE_CRYPTO 7
68 #define PS_FST_TYPE_MQUEUE 8
69 #define PS_FST_TYPE_SHM 9
70 #define PS_FST_TYPE_SEM 10
71 #define PS_FST_TYPE_UNKNOWN 11
72 #define PS_FST_TYPE_NONE 12
73 #define PS_FST_TYPE_PROCDESC 13
74 #define PS_FST_TYPE_DEV 14
77 * Special descriptor numbers.
79 #define PS_FST_UFLAG_RDIR 0x0001
80 #define PS_FST_UFLAG_CDIR 0x0002
81 #define PS_FST_UFLAG_JAIL 0x0004
82 #define PS_FST_UFLAG_TRACE 0x0008
83 #define PS_FST_UFLAG_TEXT 0x0010
84 #define PS_FST_UFLAG_MMAP 0x0020
85 #define PS_FST_UFLAG_CTTY 0x0040
90 #define PS_FST_FFLAG_READ 0x0001
91 #define PS_FST_FFLAG_WRITE 0x0002
92 #define PS_FST_FFLAG_NONBLOCK 0x0004
93 #define PS_FST_FFLAG_APPEND 0x0008
94 #define PS_FST_FFLAG_SHLOCK 0x0010
95 #define PS_FST_FFLAG_EXLOCK 0x0020
96 #define PS_FST_FFLAG_ASYNC 0x0040
97 #define PS_FST_FFLAG_SYNC 0x0080
98 #define PS_FST_FFLAG_NOFOLLOW 0x0100
99 #define PS_FST_FFLAG_CREAT 0x0200
100 #define PS_FST_FFLAG_TRUNC 0x0400
101 #define PS_FST_FFLAG_EXCL 0x0800
102 #define PS_FST_FFLAG_DIRECT 0x1000
103 #define PS_FST_FFLAG_EXEC 0x2000
104 #define PS_FST_FFLAG_HASLOCK 0x4000
107 struct kinfo_vmentry;
109 struct ptrace_lwpinfo;
112 int fs_type; /* Descriptor type. */
113 int fs_flags; /* filestat specific flags. */
114 int fs_fflags; /* Descriptor access flags. */
115 int fs_uflags; /* How this file is used. */
116 int fs_fd; /* File descriptor number. */
117 int fs_ref_count; /* Reference count. */
118 off_t fs_offset; /* Seek location. */
119 void *fs_typedep; /* Type dependent data. */
121 STAILQ_ENTRY(filestat) next;
122 cap_rights_t fs_cap_rights; /* Capability rights, if flag set. */
132 char vn_devname[SPECNAMELEN + 1];
136 char devname[SPECNAMELEN + 1];
160 struct sockaddr_storage sa_local; /* Socket address. */
161 struct sockaddr_storage sa_peer; /* Peer address. */
168 STAILQ_HEAD(filestat_list, filestat);
171 void procstat_close(struct procstat *procstat);
172 void procstat_freeargv(struct procstat *procstat);
174 void procstat_freeauxv(struct procstat *procstat, Elf_Auxinfo *auxv);
176 void procstat_freeenvv(struct procstat *procstat);
177 void procstat_freegroups(struct procstat *procstat, gid_t *groups);
178 void procstat_freekstack(struct procstat *procstat,
179 struct kinfo_kstack *kkstp);
180 void procstat_freeprocs(struct procstat *procstat, struct kinfo_proc *p);
181 void procstat_freefiles(struct procstat *procstat,
182 struct filestat_list *head);
183 void procstat_freeptlwpinfo(struct procstat *procstat,
184 struct ptrace_lwpinfo *pl);
185 void procstat_freevmmap(struct procstat *procstat,
186 struct kinfo_vmentry *vmmap);
187 struct filestat_list *procstat_getfiles(struct procstat *procstat,
188 struct kinfo_proc *kp, int mmapped);
189 struct kinfo_proc *procstat_getprocs(struct procstat *procstat,
190 int what, int arg, unsigned int *count);
191 int procstat_get_pipe_info(struct procstat *procstat, struct filestat *fst,
192 struct pipestat *pipe, char *errbuf);
193 int procstat_get_pts_info(struct procstat *procstat, struct filestat *fst,
194 struct ptsstat *pts, char *errbuf);
195 int procstat_get_sem_info(struct procstat *procstat, struct filestat *fst,
196 struct semstat *sem, char *errbuf);
197 int procstat_get_shm_info(struct procstat *procstat, struct filestat *fst,
198 struct shmstat *shm, char *errbuf);
199 int procstat_get_socket_info(struct procstat *procstat, struct filestat *fst,
200 struct sockstat *sock, char *errbuf);
201 int procstat_get_vnode_info(struct procstat *procstat, struct filestat *fst,
202 struct vnstat *vn, char *errbuf);
203 char **procstat_getargv(struct procstat *procstat, struct kinfo_proc *p,
206 Elf_Auxinfo *procstat_getauxv(struct procstat *procstat,
207 struct kinfo_proc *kp, unsigned int *cntp);
209 struct ptrace_lwpinfo *procstat_getptlwpinfo(struct procstat *procstat,
211 char **procstat_getenvv(struct procstat *procstat, struct kinfo_proc *p,
213 gid_t *procstat_getgroups(struct procstat *procstat, struct kinfo_proc *kp,
214 unsigned int *count);
215 struct kinfo_kstack *procstat_getkstack(struct procstat *procstat,
216 struct kinfo_proc *kp, unsigned int *count);
217 int procstat_getosrel(struct procstat *procstat, struct kinfo_proc *kp,
219 int procstat_getpathname(struct procstat *procstat, struct kinfo_proc *kp,
220 char *pathname, size_t maxlen);
221 int procstat_getrlimit(struct procstat *procstat, struct kinfo_proc *kp,
222 int which, struct rlimit* rlimit);
223 int procstat_getumask(struct procstat *procstat, struct kinfo_proc *kp,
224 unsigned short* umask);
225 struct kinfo_vmentry *procstat_getvmmap(struct procstat *procstat,
226 struct kinfo_proc *kp, unsigned int *count);
227 struct procstat *procstat_open_core(const char *filename);
228 struct procstat *procstat_open_sysctl(void);
229 struct procstat *procstat_open_kvm(const char *nlistf, const char *memf);
232 #endif /* !_LIBPROCSTAT_H_ */