]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - lib/libprocstat/libprocstat.h
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / lib / libprocstat / libprocstat.h
1 /*-
2  * Copyright (c) 2009 Stanislav Sedov <stas@FreeBSD.org>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  *
26  * $FreeBSD$
27  */
28
29 #ifndef _LIBPROCSTAT_H_
30 #define _LIBPROCSTAT_H_
31
32 /*
33  * XXX: sys/elf.h conflicts with zfs_context.h. Workaround this by not
34  * including conflicting parts when building zfs code.
35  */
36 #ifndef ZFS
37 #include <sys/elf.h>
38 #endif
39
40 /*
41  * Vnode types.
42  */
43 #define PS_FST_VTYPE_VNON       1
44 #define PS_FST_VTYPE_VREG       2
45 #define PS_FST_VTYPE_VDIR       3
46 #define PS_FST_VTYPE_VBLK       4
47 #define PS_FST_VTYPE_VCHR       5
48 #define PS_FST_VTYPE_VLNK       6
49 #define PS_FST_VTYPE_VSOCK      7
50 #define PS_FST_VTYPE_VFIFO      8
51 #define PS_FST_VTYPE_VBAD       9
52 #define PS_FST_VTYPE_UNKNOWN    255
53
54 /*
55  * Descriptor types.
56  */
57 #define PS_FST_TYPE_VNODE       1
58 #define PS_FST_TYPE_FIFO        2
59 #define PS_FST_TYPE_SOCKET      3
60 #define PS_FST_TYPE_PIPE        4
61 #define PS_FST_TYPE_PTS         5
62 #define PS_FST_TYPE_KQUEUE      6
63 #define PS_FST_TYPE_CRYPTO      7
64 #define PS_FST_TYPE_MQUEUE      8
65 #define PS_FST_TYPE_SHM         9
66 #define PS_FST_TYPE_SEM         10
67 #define PS_FST_TYPE_UNKNOWN     11
68 #define PS_FST_TYPE_NONE        12
69
70 /*
71  * Special descriptor numbers.
72  */
73 #define PS_FST_UFLAG_RDIR       0x0001
74 #define PS_FST_UFLAG_CDIR       0x0002
75 #define PS_FST_UFLAG_JAIL       0x0004
76 #define PS_FST_UFLAG_TRACE      0x0008
77 #define PS_FST_UFLAG_TEXT       0x0010
78 #define PS_FST_UFLAG_MMAP       0x0020
79 #define PS_FST_UFLAG_CTTY       0x0040
80
81 /*
82  * Descriptor flags.
83  */
84 #define PS_FST_FFLAG_READ       0x0001
85 #define PS_FST_FFLAG_WRITE      0x0002
86 #define PS_FST_FFLAG_NONBLOCK   0x0004
87 #define PS_FST_FFLAG_APPEND     0x0008
88 #define PS_FST_FFLAG_SHLOCK     0x0010
89 #define PS_FST_FFLAG_EXLOCK     0x0020
90 #define PS_FST_FFLAG_ASYNC      0x0040
91 #define PS_FST_FFLAG_SYNC       0x0080
92 #define PS_FST_FFLAG_NOFOLLOW   0x0100
93 #define PS_FST_FFLAG_CREAT      0x0200
94 #define PS_FST_FFLAG_TRUNC      0x0400
95 #define PS_FST_FFLAG_EXCL       0x0800
96 #define PS_FST_FFLAG_DIRECT     0x1000
97 #define PS_FST_FFLAG_EXEC       0x2000
98 #define PS_FST_FFLAG_HASLOCK    0x4000
99 #define PS_FST_FFLAG_CAPABILITY 0x8000
100
101 struct kinfo_kstack;
102 struct kinfo_vmentry;
103 struct procstat;
104 struct rlimit;
105 struct filestat {
106         int     fs_type;        /* Descriptor type. */
107         int     fs_flags;       /* filestat specific flags. */
108         int     fs_fflags;      /* Descriptor access flags. */
109         int     fs_uflags;      /* How this file is used. */
110         int     fs_fd;          /* File descriptor number. */
111         int     fs_ref_count;   /* Reference count. */
112         off_t   fs_offset;      /* Seek location. */
113         void    *fs_typedep;    /* Type dependent data. */
114         char    *fs_path;
115         STAILQ_ENTRY(filestat)  next;
116         cap_rights_t    fs_cap_rights;  /* Capability rights, if flag set. */
117 };
118 struct vnstat {
119         uint64_t        vn_fileid;
120         uint64_t        vn_size;
121         char            *vn_mntdir;
122         uint32_t        vn_dev;
123         uint32_t        vn_fsid;
124         int             vn_type;
125         uint16_t        vn_mode;
126         char            vn_devname[SPECNAMELEN + 1];
127 };
128 struct ptsstat {
129         uint32_t        dev;
130         char            devname[SPECNAMELEN + 1];
131 };
132 struct pipestat {
133         size_t          buffer_cnt;
134         uint64_t        addr;
135         uint64_t        peer;
136 };
137 struct semstat {
138         uint32_t        value;
139         uint16_t        mode;
140 };
141 struct shmstat {
142         uint64_t        size;
143         uint16_t        mode;
144 };
145 struct sockstat {
146         uint64_t        inp_ppcb;
147         uint64_t        so_addr;
148         uint64_t        so_pcb;
149         uint64_t        unp_conn;
150         int             dom_family;
151         int             proto;
152         int             so_rcv_sb_state;
153         int             so_snd_sb_state;
154         struct sockaddr_storage sa_local;       /* Socket address. */
155         struct sockaddr_storage sa_peer;        /* Peer address. */
156         int             type;
157         char            dname[32];
158 };
159
160 STAILQ_HEAD(filestat_list, filestat);
161
162 __BEGIN_DECLS
163 void    procstat_close(struct procstat *procstat);
164 void    procstat_freeargv(struct procstat *procstat);
165 #ifndef ZFS
166 void    procstat_freeauxv(struct procstat *procstat, Elf_Auxinfo *auxv);
167 #endif
168 void    procstat_freeenvv(struct procstat *procstat);
169 void    procstat_freegroups(struct procstat *procstat, gid_t *groups);
170 void    procstat_freekstack(struct procstat *procstat,
171     struct kinfo_kstack *kkstp);
172 void    procstat_freeprocs(struct procstat *procstat, struct kinfo_proc *p);
173 void    procstat_freefiles(struct procstat *procstat,
174     struct filestat_list *head);
175 void    procstat_freevmmap(struct procstat *procstat,
176     struct kinfo_vmentry *vmmap);
177 struct filestat_list    *procstat_getfiles(struct procstat *procstat,
178     struct kinfo_proc *kp, int mmapped);
179 struct kinfo_proc       *procstat_getprocs(struct procstat *procstat,
180     int what, int arg, unsigned int *count);
181 int     procstat_get_pipe_info(struct procstat *procstat, struct filestat *fst,
182     struct pipestat *pipe, char *errbuf);
183 int     procstat_get_pts_info(struct procstat *procstat, struct filestat *fst,
184     struct ptsstat *pts, char *errbuf);
185 int     procstat_get_sem_info(struct procstat *procstat, struct filestat *fst,
186     struct semstat *sem, char *errbuf);
187 int     procstat_get_shm_info(struct procstat *procstat, struct filestat *fst,
188     struct shmstat *shm, char *errbuf);
189 int     procstat_get_socket_info(struct procstat *procstat, struct filestat *fst,
190     struct sockstat *sock, char *errbuf);
191 int     procstat_get_vnode_info(struct procstat *procstat, struct filestat *fst,
192     struct vnstat *vn, char *errbuf);
193 char    **procstat_getargv(struct procstat *procstat, struct kinfo_proc *p,
194     size_t nchr);
195 #ifndef ZFS
196 Elf_Auxinfo     *procstat_getauxv(struct procstat *procstat,
197     struct kinfo_proc *kp, unsigned int *cntp);
198 #endif
199 char    **procstat_getenvv(struct procstat *procstat, struct kinfo_proc *p,
200     size_t nchr);
201 gid_t   *procstat_getgroups(struct procstat *procstat, struct kinfo_proc *kp,
202     unsigned int *count);
203 struct kinfo_kstack     *procstat_getkstack(struct procstat *procstat,
204     struct kinfo_proc *kp, unsigned int *count);
205 int     procstat_getosrel(struct procstat *procstat, struct kinfo_proc *kp,
206     int *osrelp);
207 int     procstat_getpathname(struct procstat *procstat, struct kinfo_proc *kp,
208     char *pathname, size_t maxlen);
209 int     procstat_getrlimit(struct procstat *procstat, struct kinfo_proc *kp,
210     int which, struct rlimit* rlimit);
211 int     procstat_getumask(struct procstat *procstat, struct kinfo_proc *kp,
212     unsigned short* umask);
213 struct kinfo_vmentry    *procstat_getvmmap(struct procstat *procstat,
214     struct kinfo_proc *kp, unsigned int *count);
215 struct procstat *procstat_open_core(const char *filename);
216 struct procstat *procstat_open_sysctl(void);
217 struct procstat *procstat_open_kvm(const char *nlistf, const char *memf);
218 __END_DECLS
219
220 #endif  /* !_LIBPROCSTAT_H_ */