procfs.h revision 1.48 1 /* $NetBSD: procfs.h,v 1.48 2003/08/07 16:32:41 agc Exp $ */
2
3 /*
4 * Copyright (c) 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * This code is derived from software contributed to Berkeley by
8 * Jan-Simon Pendry.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 *
34 * @(#)procfs.h 8.9 (Berkeley) 5/14/95
35 */
36
37 /*
38 * Copyright (c) 1993 Jan-Simon Pendry
39 *
40 * This code is derived from software contributed to Berkeley by
41 * Jan-Simon Pendry.
42 *
43 * Redistribution and use in source and binary forms, with or without
44 * modification, are permitted provided that the following conditions
45 * are met:
46 * 1. Redistributions of source code must retain the above copyright
47 * notice, this list of conditions and the following disclaimer.
48 * 2. Redistributions in binary form must reproduce the above copyright
49 * notice, this list of conditions and the following disclaimer in the
50 * documentation and/or other materials provided with the distribution.
51 * 3. All advertising materials mentioning features or use of this software
52 * must display the following acknowledgement:
53 * This product includes software developed by the University of
54 * California, Berkeley and its contributors.
55 * 4. Neither the name of the University nor the names of its contributors
56 * may be used to endorse or promote products derived from this software
57 * without specific prior written permission.
58 *
59 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
60 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
61 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
62 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
63 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
64 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
65 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
66 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
67 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
68 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
69 * SUCH DAMAGE.
70 *
71 * @(#)procfs.h 8.9 (Berkeley) 5/14/95
72 */
73
74 /* This also pulls in __HAVE_PROCFS_MACHDEP */
75 #include <sys/ptrace.h>
76
77 /*
78 * The different types of node in a procfs filesystem
79 */
80 typedef enum {
81 Proot, /* the filesystem root */
82 Pcurproc, /* symbolic link for curproc */
83 Pself, /* like curproc, but this is the Linux name */
84 Pproc, /* a process-specific sub-directory */
85 Pfile, /* the executable file */
86 Pmem, /* the process's memory image */
87 Pregs, /* the process's register set */
88 Pfpregs, /* the process's FP register set */
89 Pctl, /* process control */
90 Pstat, /* process status (if -o linux) */
91 Pstatus, /* process status */
92 Pnote, /* process notifier */
93 Pnotepg, /* process group notifier */
94 Pmap, /* memory map */
95 Pcmdline, /* process command line args */
96 Pmeminfo, /* system memory info (if -o linux) */
97 Pcpuinfo, /* CPU info (if -o linux) */
98 Pmaps, /* memory map, Linux style (if -o linux) */
99 Pfd, /* a directory containing the processes open fd's */
100 Puptime, /* elapsed time since (if -o linux) */
101 #ifdef __HAVE_PROCFS_MACHDEP
102 PROCFS_MACHDEP_NODE_TYPES
103 #endif
104 } pfstype;
105
106 /*
107 * control data for the proc file system.
108 */
109 struct pfsnode {
110 LIST_ENTRY(pfsnode) pfs_hash; /* hash chain */
111 struct vnode *pfs_vnode; /* vnode associated with this pfsnode */
112 pfstype pfs_type; /* type of procfs node */
113 pid_t pfs_pid; /* associated process */
114 int pfs_fd; /* associated fd if not -1 */
115 mode_t pfs_mode; /* mode bits for stat() */
116 u_long pfs_flags; /* open flags */
117 u_long pfs_fileno; /* unique file id */
118 };
119
120 #define PROCFS_NOTELEN 64 /* max length of a note (/proc/$pid/note) */
121 #define PROCFS_CTLLEN 8 /* max length of a ctl msg (/proc/$pid/ctl */
122
123 struct procfs_args {
124 int version;
125 int flags;
126 };
127
128 #define PROCFS_ARGSVERSION 1
129
130 #define PROCFSMNT_LINUXCOMPAT 0x01
131
132 #define PROCFSMNT_BITS "\177\20" \
133 "b\00linuxcompat"
134
135 /*
136 * Kernel stuff follows
137 */
138 #ifdef _KERNEL
139 #define CNEQ(cnp, s, len) \
140 ((cnp)->cn_namelen == (len) && \
141 (memcmp((s), (cnp)->cn_nameptr, (len)) == 0))
142
143 #define UIO_MX 32
144
145 #define PROCFS_FILENO(pid, type, fd) \
146 (((type) < Pproc) ? ((type) + 2) : \
147 (((fd) == -1) ? ((((pid)+1) << 5) + ((int) (type))) : \
148 ((((pid)+1) << 16) | ((fd) << 5) | ((int) (type)))))
149
150 struct procfsmount {
151 void *pmnt_exechook;
152 int pmnt_flags;
153 };
154
155 #define VFSTOPROC(mp) ((struct procfsmount *)(mp)->mnt_data)
156
157 /*
158 * Convert between pfsnode vnode
159 */
160 #define VTOPFS(vp) ((struct pfsnode *)(vp)->v_data)
161 #define PFSTOV(pfs) ((pfs)->pfs_vnode)
162
163 typedef struct vfs_namemap vfs_namemap_t;
164 struct vfs_namemap {
165 const char *nm_name;
166 int nm_val;
167 };
168
169 int vfs_getuserstr __P((struct uio *, char *, int *));
170 const vfs_namemap_t *vfs_findname __P((const vfs_namemap_t *, const char *, int));
171
172 #define PFIND(pid) ((pid) ? pfind(pid) : &proc0)
173 int procfs_freevp __P((struct vnode *));
174 int procfs_allocvp __P((struct mount *, struct vnode **, pid_t, pfstype, int));
175 int procfs_donote __P((struct proc *, struct proc *, struct pfsnode *,
176 struct uio *));
177 int procfs_doregs __P((struct proc *, struct lwp *, struct pfsnode *,
178 struct uio *));
179 int procfs_dofpregs __P((struct proc *, struct lwp *, struct pfsnode *,
180 struct uio *));
181 int procfs_domem __P((struct proc *, struct proc *, struct pfsnode *,
182 struct uio *));
183 int procfs_doctl __P((struct proc *, struct lwp *, struct pfsnode *,
184 struct uio *));
185 int procfs_do_pid_stat __P((struct proc *, struct lwp *, struct pfsnode *,
186 struct uio *));
187 int procfs_dostatus __P((struct proc *, struct lwp *, struct pfsnode *,
188 struct uio *));
189 int procfs_domap __P((struct proc *, struct proc *, struct pfsnode *,
190 struct uio *, int));
191 int procfs_docmdline __P((struct proc *, struct proc *, struct pfsnode *,
192 struct uio *));
193 int procfs_domeminfo __P((struct proc *, struct proc *, struct pfsnode *,
194 struct uio *));
195 int procfs_docpuinfo __P((struct proc *, struct proc *, struct pfsnode *,
196 struct uio *));
197 int procfs_dofd __P((struct proc *, struct proc *, struct pfsnode *,
198 struct uio *));
199 int procfs_douptime __P((struct proc *, struct proc *, struct pfsnode *,
200 struct uio *));
201
202 void procfs_revoke_vnodes __P((struct proc *, void *));
203 void procfs_hashinit __P((void));
204 void procfs_hashreinit __P((void));
205 void procfs_hashdone __P((void));
206 int procfs_getfp __P((struct pfsnode *, struct proc **, struct file **));
207
208 /* functions to check whether or not files should be displayed */
209 int procfs_validfile __P((struct proc *, struct mount *));
210 int procfs_validfpregs __P((struct proc *, struct mount *));
211 int procfs_validregs __P((struct proc *, struct mount *));
212 int procfs_validmap __P((struct proc *, struct mount *));
213
214 int procfs_rw __P((void *));
215
216 int procfs_getcpuinfstr __P((char *, int *));
217
218 #define PROCFS_LOCKED 0x01
219 #define PROCFS_WANT 0x02
220
221 extern int (**procfs_vnodeop_p) __P((void *));
222 extern struct vfsops procfs_vfsops;
223
224 int procfs_root __P((struct mount *, struct vnode **));
225
226 #ifdef __HAVE_PROCFS_MACHDEP
227 struct vattr;
228
229 void procfs_machdep_allocvp(struct vnode *);
230 int procfs_machdep_rw(struct proc *, struct lwp *, struct pfsnode *,
231 struct uio *);
232 int procfs_machdep_getattr(struct vnode *, struct vattr *, struct proc *);
233 #endif
234
235 #endif /* _KERNEL */
236