xref: /freebsd/sys/fs/procfs/procfs.h (revision e627b39baccd1ec9129690167cf5e6d860509655)
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.6 (Berkeley) 2/3/94
38  *
39  *	$Id: procfs.h,v 1.11 1996/06/18 05:15:58 dyson Exp $
40  */
41 
42 /*
43  * The different types of node in a procfs filesystem
44  */
45 typedef enum {
46 	Proot,		/* the filesystem root */
47 	Pproc,		/* a process-specific sub-directory */
48 	Pfile,		/* the executable file */
49 	Pmem,		/* the process's memory image */
50 	Pregs,		/* the process's register set */
51 	Pfpregs,	/* the process's FP register set */
52 	Pctl,		/* process control */
53 	Pstatus,	/* process status */
54 	Pnote,		/* process notifier */
55 	Pnotepg,	/* process group notifier */
56 	Pmap,		/* memory map */
57 	Ptype		/* executable type */
58 } pfstype;
59 
60 /*
61  * control data for the proc file system.
62  */
63 struct pfsnode {
64 	struct pfsnode	*pfs_next;	/* next on list */
65 	struct vnode	*pfs_vnode;	/* vnode associated with this pfsnode */
66 	pfstype		pfs_type;	/* type of procfs node */
67 	pid_t		pfs_pid;	/* associated process */
68 	u_short		pfs_mode;	/* mode bits for stat() */
69 	u_long		pfs_flags;	/* open flags */
70 	u_long		pfs_fileno;	/* unique file id */
71 	pid_t		pfs_lockowner;	/* pfs lock owner */
72 };
73 
74 #define PROCFS_NOTELEN	64	/* max length of a note (/proc/$pid/note) */
75 #define PROCFS_CTLLEN 	8	/* max length of a ctl msg (/proc/$pid/ctl */
76 
77 /*
78  * Kernel stuff follows
79  */
80 #ifdef KERNEL
81 #define CNEQ(cnp, s, len) \
82 	 ((cnp)->cn_namelen == (len) && \
83 	  (bcmp((s), (cnp)->cn_nameptr, (len)) == 0))
84 
85 #define KMEM_GROUP 2
86 /*
87  * Format of a directory entry in /proc, ...
88  * This must map onto struct dirent (see <dirent.h>)
89  */
90 #define PROCFS_NAMELEN 8
91 struct pfsdent {
92 	u_long	d_fileno;
93 	u_short	d_reclen;
94 	u_char	d_type;
95 	u_char	d_namlen;
96 	char	d_name[PROCFS_NAMELEN];
97 };
98 #define UIO_MX sizeof(struct pfsdent)
99 #define PROCFS_FILENO(pid, type) \
100 	(((type) == Proot) ? \
101 			2 : \
102 			((((pid)+1) << 3) + ((int) (type))))
103 
104 /*
105  * Convert between pfsnode vnode
106  */
107 #define VTOPFS(vp)	((struct pfsnode *)(vp)->v_data)
108 #define PFSTOV(pfs)	((pfs)->pfs_vnode)
109 
110 typedef struct vfs_namemap vfs_namemap_t;
111 struct vfs_namemap {
112 	const char *nm_name;
113 	int nm_val;
114 };
115 
116 extern int vfs_getuserstr __P((struct uio *, char *, int *));
117 extern vfs_namemap_t *vfs_findname __P((vfs_namemap_t *, char *, int));
118 
119 /* <machine/reg.h> */
120 struct reg;
121 struct fpreg;
122 
123 #define PFIND(pid) ((pid) ? pfind(pid) : &proc0)
124 extern int procfs_freevp __P((struct vnode *));
125 extern int procfs_allocvp __P((struct mount *, struct vnode **, long, pfstype));
126 extern struct vnode *procfs_findtextvp __P((struct proc *));
127 extern int procfs_sstep __P((struct proc *));
128 extern void procfs_fix_sstep __P((struct proc *));
129 extern int procfs_read_regs __P((struct proc *, struct reg *));
130 extern int procfs_write_regs __P((struct proc *, struct reg *));
131 extern int procfs_read_fpregs __P((struct proc *, struct fpreg *));
132 extern int procfs_write_fpregs __P((struct proc *, struct fpreg *));
133 extern int procfs_donote __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
134 extern int procfs_doregs __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
135 extern int procfs_dofpregs __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
136 extern int procfs_domem __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
137 extern int procfs_doctl __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
138 extern int procfs_dostatus __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
139 extern int procfs_domap __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
140 extern int procfs_dotype __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
141 
142 /* check to see if the process has the "items" (regs/file) */
143 int procfs_validfile __P((struct proc *));
144 int procfs_validfpregs __P((struct proc *));
145 int procfs_validregs __P((struct proc *));
146 int procfs_validmap __P((struct proc *));
147 int procfs_validtype __P((struct proc *));
148 
149 #define PROCFS_LOCKED	0x01
150 #define PROCFS_WANT	0x02
151 
152 extern vop_t **procfs_vnodeop_p;
153 extern struct vfsops procfs_vfsops;
154 
155 int	procfs_root __P((struct mount *, struct vnode **));
156 int	procfs_rw __P((struct vop_read_args *));
157 #endif /* KERNEL */
158