xref: /freebsd/sys/fs/procfs/procfs.h (revision 2ad872c5794e4c26fdf6ed219ad3f09ca0d5304a)
1 /*
2  * Copyright (c) 1993 Jan-Simon Pendry
3  * Copyright (c) 1993
4  *	The Regents of the University of California.  All rights reserved.
5  *
6  * This code is derived from software contributed to Berkeley by
7  * Jan-Simon Pendry.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  * 3. All advertising materials mentioning features or use of this software
18  *    must display the following acknowledgement:
19  *	This product includes software developed by the University of
20  *	California, Berkeley and its contributors.
21  * 4. Neither the name of the University nor the names of its contributors
22  *    may be used to endorse or promote products derived from this software
23  *    without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35  * SUCH DAMAGE.
36  *
37  *	@(#)procfs.h	8.9 (Berkeley) 5/14/95
38  *
39  * From:
40  *	$Id: procfs.h,v 1.20 1998/07/07 04:08:44 bde Exp $
41  */
42 
43 /*
44  * The different types of node in a procfs filesystem
45  */
46 typedef enum {
47 	Proot,		/* the filesystem root */
48 	Pcurproc,	/* symbolic link for curproc */
49 	Pproc,		/* a process-specific sub-directory */
50 	Pfile,		/* the executable file */
51 	Pmem,		/* the process's memory image */
52 	Pregs,		/* the process's register set */
53 	Pfpregs,	/* the process's FP register set */
54 	Pctl,		/* process control */
55 	Pstatus,	/* process status */
56 	Pnote,		/* process notifier */
57 	Pnotepg,	/* process group notifier */
58 	Pmap,		/* memory map */
59 	Ptype,		/* executable type */
60 	Pcmdline	/* command line */
61 } pfstype;
62 
63 /*
64  * control data for the proc file system.
65  */
66 struct pfsnode {
67 	struct pfsnode	*pfs_next;	/* next on list */
68 	struct vnode	*pfs_vnode;	/* vnode associated with this pfsnode */
69 	pfstype		pfs_type;	/* type of procfs node */
70 	pid_t		pfs_pid;	/* associated process */
71 	u_short		pfs_mode;	/* mode bits for stat() */
72 	u_long		pfs_flags;	/* open flags */
73 	u_long		pfs_fileno;	/* unique file id */
74 	pid_t		pfs_lockowner;	/* pfs lock owner */
75 };
76 
77 #define PROCFS_NOTELEN	64	/* max length of a note (/proc/$pid/note) */
78 #define PROCFS_CTLLEN 	8	/* max length of a ctl msg (/proc/$pid/ctl */
79 
80 /*
81  * Kernel stuff follows
82  */
83 #ifdef KERNEL
84 #define CNEQ(cnp, s, len) \
85 	 ((cnp)->cn_namelen == (len) && \
86 	  (bcmp((s), (cnp)->cn_nameptr, (len)) == 0))
87 
88 #define KMEM_GROUP 2
89 
90 /*
91  * Check to see whether access to target process is allowed
92  * Evaluates to 1 if access is allowed.
93  */
94 #define CHECKIO(p1, p2) \
95      ((((p1)->p_cred->pc_ucred->cr_uid == (p2)->p_cred->p_ruid) && \
96        ((p1)->p_cred->p_ruid == (p2)->p_cred->p_ruid) && \
97        ((p1)->p_cred->p_svuid == (p2)->p_cred->p_ruid) && \
98        ((p2)->p_flag & P_SUGID) == 0) || \
99       (suser((p1)->p_cred->pc_ucred, &(p1)->p_acflag) == 0))
100 
101 /*
102  * Format of a directory entry in /proc, ...
103  * This must map onto struct dirent (see <dirent.h>)
104  */
105 #define PROCFS_NAMELEN 8
106 struct pfsdent {
107 	u_int32_t d_fileno;
108 	u_int16_t d_reclen;
109 	u_int8_t  d_type;
110 	u_int8_t  d_namlen;
111 	char	d_name[PROCFS_NAMELEN];
112 };
113 #define UIO_MX sizeof(struct pfsdent)
114 #define PROCFS_FILENO(pid, type) \
115 	(((type) < Pproc) ? \
116 			((type) + 2) : \
117 			((((pid)+1) << 4) + ((int) (type))))
118 
119 /*
120  * Convert between pfsnode vnode
121  */
122 #define VTOPFS(vp)	((struct pfsnode *)(vp)->v_data)
123 #define PFSTOV(pfs)	((pfs)->pfs_vnode)
124 
125 typedef struct vfs_namemap vfs_namemap_t;
126 struct vfs_namemap {
127 	const char *nm_name;
128 	int nm_val;
129 };
130 
131 int vfs_getuserstr __P((struct uio *, char *, int *));
132 vfs_namemap_t *vfs_findname __P((vfs_namemap_t *, char *, int));
133 
134 /* <machine/reg.h> */
135 struct reg;
136 struct fpreg;
137 
138 #define PFIND(pid) ((pid) ? pfind(pid) : &proc0)
139 
140 void procfs_exit __P((struct proc *));
141 int procfs_freevp __P((struct vnode *));
142 int procfs_allocvp __P((struct mount *, struct vnode **, long, pfstype));
143 struct vnode *procfs_findtextvp __P((struct proc *));
144 int procfs_sstep __P((struct proc *));
145 void procfs_fix_sstep __P((struct proc *));
146 int procfs_read_regs __P((struct proc *, struct reg *));
147 int procfs_write_regs __P((struct proc *, struct reg *));
148 int procfs_read_fpregs __P((struct proc *, struct fpreg *));
149 int procfs_write_fpregs __P((struct proc *, struct fpreg *));
150 int procfs_donote __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
151 int procfs_doregs __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
152 int procfs_dofpregs __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
153 int procfs_domem __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
154 int procfs_doctl __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
155 int procfs_dostatus __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
156 int procfs_domap __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
157 int procfs_dotype __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
158 int procfs_docmdline __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
159 
160 /* Return 1 if process has special kernel digging privileges */
161 int procfs_kmemaccess __P((struct proc *));
162 
163 /* functions to check whether or not files should be displayed */
164 int procfs_validfile __P((struct proc *));
165 int procfs_validfpregs __P((struct proc *));
166 int procfs_validregs __P((struct proc *));
167 int procfs_validmap __P((struct proc *));
168 int procfs_validtype __P((struct proc *));
169 
170 #define PROCFS_LOCKED	0x01
171 #define PROCFS_WANT	0x02
172 
173 extern vop_t **procfs_vnodeop_p;
174 
175 int	procfs_root __P((struct mount *, struct vnode **));
176 int	procfs_rw __P((struct vop_read_args *));
177 #endif /* KERNEL */
178