1221807Sstas/*-
2221807Sstas * Copyright (c) 2009 Stanislav Sedov <stas@FreeBSD.org>
3221807Sstas * All rights reserved.
4221807Sstas *
5221807Sstas * Redistribution and use in source and binary forms, with or without
6221807Sstas * modification, are permitted provided that the following conditions
7221807Sstas * are met:
8221807Sstas * 1. Redistributions of source code must retain the above copyright
9221807Sstas *    notice, this list of conditions and the following disclaimer.
10221807Sstas * 2. Redistributions in binary form must reproduce the above copyright
11221807Sstas *    notice, this list of conditions and the following disclaimer in the
12221807Sstas *    documentation and/or other materials provided with the distribution.
13221807Sstas *
14221807Sstas * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
15221807Sstas * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16221807Sstas * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17221807Sstas * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
18221807Sstas * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19221807Sstas * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20221807Sstas * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21221807Sstas * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22221807Sstas * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23221807Sstas * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24221807Sstas * SUCH DAMAGE.
25221807Sstas *
26221807Sstas * $FreeBSD$
27221807Sstas */
28221807Sstas
29221807Sstas#ifndef _LIBPROCSTAT_H_
30221807Sstas#define	_LIBPROCSTAT_H_
31221807Sstas
32221807Sstas/*
33249681Strociny * XXX: sys/elf.h conflicts with zfs_context.h. Workaround this by not
34249681Strociny * including conflicting parts when building zfs code.
35249681Strociny */
36249681Strociny#ifndef ZFS
37249681Strociny#include <sys/elf.h>
38249681Strociny#endif
39255219Spjd#include <sys/caprights.h>
40249681Strociny
41249681Strociny/*
42221807Sstas * Vnode types.
43221807Sstas */
44221807Sstas#define	PS_FST_VTYPE_VNON	1
45221807Sstas#define	PS_FST_VTYPE_VREG	2
46221807Sstas#define	PS_FST_VTYPE_VDIR	3
47221807Sstas#define	PS_FST_VTYPE_VBLK	4
48221807Sstas#define	PS_FST_VTYPE_VCHR	5
49221807Sstas#define	PS_FST_VTYPE_VLNK	6
50221807Sstas#define	PS_FST_VTYPE_VSOCK	7
51221807Sstas#define	PS_FST_VTYPE_VFIFO	8
52221807Sstas#define	PS_FST_VTYPE_VBAD	9
53221807Sstas#define	PS_FST_VTYPE_UNKNOWN	255
54221807Sstas
55221807Sstas/*
56221807Sstas * Descriptor types.
57221807Sstas */
58221807Sstas#define	PS_FST_TYPE_VNODE	1
59221807Sstas#define	PS_FST_TYPE_FIFO	2
60221807Sstas#define	PS_FST_TYPE_SOCKET	3
61221807Sstas#define	PS_FST_TYPE_PIPE	4
62221807Sstas#define	PS_FST_TYPE_PTS		5
63221807Sstas#define	PS_FST_TYPE_KQUEUE	6
64221807Sstas#define	PS_FST_TYPE_CRYPTO	7
65221807Sstas#define	PS_FST_TYPE_MQUEUE	8
66221807Sstas#define	PS_FST_TYPE_SHM		9
67221807Sstas#define	PS_FST_TYPE_SEM		10
68221807Sstas#define	PS_FST_TYPE_UNKNOWN	11
69221807Sstas#define	PS_FST_TYPE_NONE	12
70221807Sstas
71221807Sstas/*
72221807Sstas * Special descriptor numbers.
73221807Sstas */
74221807Sstas#define	PS_FST_UFLAG_RDIR	0x0001
75221807Sstas#define	PS_FST_UFLAG_CDIR	0x0002
76221807Sstas#define	PS_FST_UFLAG_JAIL	0x0004
77221807Sstas#define	PS_FST_UFLAG_TRACE	0x0008
78221807Sstas#define	PS_FST_UFLAG_TEXT	0x0010
79221807Sstas#define	PS_FST_UFLAG_MMAP	0x0020
80221807Sstas#define	PS_FST_UFLAG_CTTY	0x0040
81221807Sstas
82221807Sstas/*
83221807Sstas * Descriptor flags.
84221807Sstas */
85221807Sstas#define PS_FST_FFLAG_READ	0x0001
86221807Sstas#define PS_FST_FFLAG_WRITE	0x0002
87221807Sstas#define	PS_FST_FFLAG_NONBLOCK	0x0004
88221807Sstas#define	PS_FST_FFLAG_APPEND	0x0008
89221807Sstas#define	PS_FST_FFLAG_SHLOCK	0x0010
90221807Sstas#define	PS_FST_FFLAG_EXLOCK	0x0020
91221807Sstas#define	PS_FST_FFLAG_ASYNC	0x0040
92221807Sstas#define	PS_FST_FFLAG_SYNC	0x0080
93221807Sstas#define	PS_FST_FFLAG_NOFOLLOW	0x0100
94221807Sstas#define	PS_FST_FFLAG_CREAT	0x0200
95221807Sstas#define	PS_FST_FFLAG_TRUNC	0x0400
96221807Sstas#define	PS_FST_FFLAG_EXCL	0x0800
97221807Sstas#define	PS_FST_FFLAG_DIRECT	0x1000
98221807Sstas#define	PS_FST_FFLAG_EXEC	0x2000
99221807Sstas#define	PS_FST_FFLAG_HASLOCK	0x4000
100221807Sstas
101249684Strocinystruct kinfo_kstack;
102249667Strocinystruct kinfo_vmentry;
103221807Sstasstruct procstat;
104249674Strocinystruct rlimit;
105221807Sstasstruct filestat {
106221807Sstas	int	fs_type;	/* Descriptor type. */
107221807Sstas	int	fs_flags;	/* filestat specific flags. */
108221807Sstas	int	fs_fflags;	/* Descriptor access flags. */
109221807Sstas	int	fs_uflags;	/* How this file is used. */
110221807Sstas	int	fs_fd;		/* File descriptor number. */
111221807Sstas	int	fs_ref_count;	/* Reference count. */
112221807Sstas	off_t	fs_offset;	/* Seek location. */
113221807Sstas	void	*fs_typedep;	/* Type dependent data. */
114221807Sstas	char	*fs_path;
115221807Sstas	STAILQ_ENTRY(filestat)	next;
116224859Srwatson	cap_rights_t	fs_cap_rights;	/* Capability rights, if flag set. */
117221807Sstas};
118221807Sstasstruct vnstat {
119221807Sstas	uint64_t	vn_fileid;
120221807Sstas	uint64_t	vn_size;
121221807Sstas	char		*vn_mntdir;
122221807Sstas	uint32_t	vn_dev;
123221807Sstas	uint32_t	vn_fsid;
124221807Sstas	int		vn_type;
125221807Sstas	uint16_t	vn_mode;
126221807Sstas	char		vn_devname[SPECNAMELEN + 1];
127221807Sstas};
128221807Sstasstruct ptsstat {
129221807Sstas	uint32_t	dev;
130221807Sstas	char		devname[SPECNAMELEN + 1];
131221807Sstas};
132221807Sstasstruct pipestat {
133221807Sstas	size_t		buffer_cnt;
134221807Sstas	uint64_t	addr;
135221807Sstas	uint64_t	peer;
136221807Sstas};
137250223Sjhbstruct semstat {
138250223Sjhb	uint32_t	value;
139250223Sjhb	uint16_t	mode;
140250223Sjhb};
141233760Sjhbstruct shmstat {
142233760Sjhb	uint64_t	size;
143233760Sjhb	uint16_t	mode;
144233760Sjhb};
145221807Sstasstruct sockstat {
146221807Sstas	uint64_t	inp_ppcb;
147221807Sstas	uint64_t	so_addr;
148221807Sstas	uint64_t	so_pcb;
149221807Sstas	uint64_t	unp_conn;
150221807Sstas	int		dom_family;
151221807Sstas	int		proto;
152221807Sstas	int		so_rcv_sb_state;
153221807Sstas	int		so_snd_sb_state;
154221807Sstas	struct sockaddr_storage	sa_local;	/* Socket address. */
155221807Sstas	struct sockaddr_storage	sa_peer;	/* Peer address. */
156221807Sstas	int		type;
157221807Sstas	char		dname[32];
158221807Sstas};
159221807Sstas
160221807SstasSTAILQ_HEAD(filestat_list, filestat);
161221807Sstas
162240080Strociny__BEGIN_DECLS
163221807Sstasvoid	procstat_close(struct procstat *procstat);
164249679Strocinyvoid	procstat_freeargv(struct procstat *procstat);
165249681Strociny#ifndef ZFS
166249681Strocinyvoid	procstat_freeauxv(struct procstat *procstat, Elf_Auxinfo *auxv);
167249681Strociny#endif
168249679Strocinyvoid	procstat_freeenvv(struct procstat *procstat);
169249670Strocinyvoid	procstat_freegroups(struct procstat *procstat, gid_t *groups);
170249684Strocinyvoid	procstat_freekstack(struct procstat *procstat,
171249684Strociny    struct kinfo_kstack *kkstp);
172221807Sstasvoid	procstat_freeprocs(struct procstat *procstat, struct kinfo_proc *p);
173221807Sstasvoid	procstat_freefiles(struct procstat *procstat,
174221807Sstas    struct filestat_list *head);
175249667Strocinyvoid	procstat_freevmmap(struct procstat *procstat,
176249667Strociny    struct kinfo_vmentry *vmmap);
177221807Sstasstruct filestat_list	*procstat_getfiles(struct procstat *procstat,
178221807Sstas    struct kinfo_proc *kp, int mmapped);
179221807Sstasstruct kinfo_proc	*procstat_getprocs(struct procstat *procstat,
180221807Sstas    int what, int arg, unsigned int *count);
181221807Sstasint	procstat_get_pipe_info(struct procstat *procstat, struct filestat *fst,
182221807Sstas    struct pipestat *pipe, char *errbuf);
183221807Sstasint	procstat_get_pts_info(struct procstat *procstat, struct filestat *fst,
184221807Sstas    struct ptsstat *pts, char *errbuf);
185250223Sjhbint	procstat_get_sem_info(struct procstat *procstat, struct filestat *fst,
186250223Sjhb    struct semstat *sem, char *errbuf);
187233760Sjhbint	procstat_get_shm_info(struct procstat *procstat, struct filestat *fst,
188233760Sjhb    struct shmstat *shm, char *errbuf);
189221807Sstasint	procstat_get_socket_info(struct procstat *procstat, struct filestat *fst,
190221807Sstas    struct sockstat *sock, char *errbuf);
191221807Sstasint	procstat_get_vnode_info(struct procstat *procstat, struct filestat *fst,
192221807Sstas    struct vnstat *vn, char *errbuf);
193249679Strocinychar	**procstat_getargv(struct procstat *procstat, struct kinfo_proc *p,
194249679Strociny    size_t nchr);
195249681Strociny#ifndef ZFS
196249681StrocinyElf_Auxinfo	*procstat_getauxv(struct procstat *procstat,
197249681Strociny    struct kinfo_proc *kp, unsigned int *cntp);
198249681Strociny#endif
199249679Strocinychar	**procstat_getenvv(struct procstat *procstat, struct kinfo_proc *p,
200249679Strociny    size_t nchr);
201249670Strocinygid_t	*procstat_getgroups(struct procstat *procstat, struct kinfo_proc *kp,
202249670Strociny    unsigned int *count);
203249684Strocinystruct kinfo_kstack	*procstat_getkstack(struct procstat *procstat,
204249684Strociny    struct kinfo_proc *kp, unsigned int *count);
205249677Strocinyint	procstat_getosrel(struct procstat *procstat, struct kinfo_proc *kp,
206249677Strociny    int *osrelp);
207249676Strocinyint	procstat_getpathname(struct procstat *procstat, struct kinfo_proc *kp,
208249676Strociny    char *pathname, size_t maxlen);
209249676Strocinyint	procstat_getrlimit(struct procstat *procstat, struct kinfo_proc *kp,
210249676Strociny    int which, struct rlimit* rlimit);
211249672Strocinyint	procstat_getumask(struct procstat *procstat, struct kinfo_proc *kp,
212249672Strociny    unsigned short* umask);
213249667Strocinystruct kinfo_vmentry	*procstat_getvmmap(struct procstat *procstat,
214249667Strociny    struct kinfo_proc *kp, unsigned int *count);
215249666Strocinystruct procstat	*procstat_open_core(const char *filename);
216221807Sstasstruct procstat	*procstat_open_sysctl(void);
217221807Sstasstruct procstat	*procstat_open_kvm(const char *nlistf, const char *memf);
218240080Strociny__END_DECLS
219221807Sstas
220221807Sstas#endif	/* !_LIBPROCSTAT_H_ */
221