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