xref: /dragonfly/sys/vfs/procfs/procfs.h (revision 2b3f93ea6d1f70880f3e87f3c2cbe0dc0bfc9332)
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. Neither the name of the University nor the names of its contributors
18  *    may be used to endorse or promote products derived from this software
19  *    without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  *
33  *        @(#)procfs.h        8.9 (Berkeley) 5/14/95
34  *
35  * From:
36  * $FreeBSD: src/sys/miscfs/procfs/procfs.h,v 1.32.2.3 2002/01/22 17:22:59 nectar Exp $
37  * $DragonFly: src/sys/vfs/procfs/procfs.h,v 1.8 2007/02/19 01:14:24 corecode Exp $
38  */
39 
40 /*
41  * The different types of node in a procfs filesystem
42  */
43 typedef enum {
44           Proot,              /* the filesystem root */
45           Pcurproc, /* symbolic link for curproc */
46           Pproc,              /* a process-specific sub-directory */
47           Pfile,              /* the executable file */
48           Pmem,               /* the process's memory image */
49           Pregs,              /* the process's register set */
50           Pfpregs,  /* the process's FP register set */
51           Pdbregs,  /* the process's debug 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           Pcmdline, /* command line */
59           Prlimit             /* resource limits */
60 } pfstype;
61 
62 /*
63  * control data for the proc file system.
64  */
65 struct pfsnode {
66           struct pfsnode      *pfs_next;          /* next on list */
67           struct vnode        *pfs_vnode;         /* vnode associated with this pfsnode */
68           pfstype             pfs_type; /* type of procfs node */
69           pid_t               pfs_pid;  /* associated process */
70           u_short             pfs_mode; /* mode bits for stat() */
71           u_long              pfs_flags;          /* open flags */
72           u_long              pfs_fileno;         /* unique file id */
73           struct lock         pfs_lock; /* pfs locked */
74 };
75 
76 #define PROCFS_NOTELEN        64        /* max length of a note (/proc/$pid/note) */
77 #define PROCFS_CTLLEN         8         /* max length of a ctl msg (/proc/$pid/ctl */
78 #define PROCFS_NAMELEN        8         /* max length of a filename component */
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 PROCFS_FILENO(pid, type) \
89           (((type) < Pproc) ? \
90                               ((type) + 2) : \
91                               ((((pid)+1) << 4) + ((int) (type))))
92 
93 /* XXX: Is PRIV_DEBUG_UNPRIV correct? */
94 #define CHECKIO(p1, p2) \
95      ((((p1)->p_ucred->cr_uid == (p2)->p_ucred->cr_ruid) && \
96        ((p1)->p_ucred->cr_ruid == (p2)->p_ucred->cr_ruid) && \
97        ((p1)->p_ucred->cr_svuid == (p2)->p_ucred->cr_ruid) && \
98        ((p2)->p_flags & (P_SUGID|P_INEXEC)) == 0) || \
99       (caps_priv_check((p1)->p_ucred, SYSCAP_NODEBUG_UNPRIV) == 0))
100 
101 /*
102  * Convert between pfsnode vnode
103  */
104 #define VTOPFS(vp)  ((struct pfsnode *)(vp)->v_data)
105 #define PFSTOV(pfs) ((pfs)->pfs_vnode)
106 
107 typedef struct vfs_namemap vfs_namemap_t;
108 struct vfs_namemap {
109           const char *nm_name;
110           int nm_val;
111 };
112 
113 int vfs_getuserstr (struct uio *, char *, int *);
114 vfs_namemap_t *vfs_findname (vfs_namemap_t *, char *, int);
115 
116 /* <machine/reg.h> */
117 struct reg;
118 struct fpreg;
119 struct dbreg;
120 
121 void procfs_exit (struct thread *);
122 int procfs_freevp (struct vnode *);
123 int procfs_allocvp (struct mount *, struct vnode **, long, pfstype);
124 struct vnode *procfs_findtextvp (struct proc *);
125 int procfs_sstep (struct lwp *);
126 int procfs_read_regs (struct lwp *, struct reg *);
127 int procfs_write_regs (struct lwp *, struct reg *);
128 int procfs_read_fpregs (struct lwp *, struct fpreg *);
129 int procfs_write_fpregs (struct lwp *, struct fpreg *);
130 int procfs_read_dbregs (struct lwp *, struct dbreg *);
131 int procfs_write_dbregs (struct lwp *, struct dbreg *);
132 int procfs_donote (struct proc *, struct lwp *, struct pfsnode *pfsp, struct uio *uio);
133 int procfs_doregs (struct proc *, struct lwp *, struct pfsnode *pfsp, struct uio *uio);
134 int procfs_dofpregs (struct proc *, struct lwp *, struct pfsnode *pfsp, struct uio *uio);
135 int procfs_dodbregs (struct proc *, struct lwp *, struct pfsnode *pfsp, struct uio *uio);
136 int procfs_domem (struct proc *, struct lwp *, struct pfsnode *pfsp, struct uio *uio);
137 int procfs_doctl (struct proc *, struct lwp *, struct pfsnode *pfsp, struct uio *uio);
138 int procfs_dostatus (struct proc *, struct lwp *, struct pfsnode *pfsp, struct uio *uio);
139 int procfs_domap (struct proc *, struct lwp *, struct pfsnode *pfsp, struct uio *uio);
140 int procfs_dotype (struct proc *, struct lwp *, struct pfsnode *pfsp, struct uio *uio);
141 int procfs_docmdline (struct proc *, struct lwp *, struct pfsnode *pfsp, struct uio *uio);
142 int procfs_dorlimit (struct proc *, struct lwp *, struct pfsnode *pfsp, struct uio *uio);
143 
144 /* functions to check whether or not files should be displayed */
145 int procfs_validfile (struct lwp *);
146 int procfs_validfpregs (struct lwp *);
147 int procfs_validregs (struct lwp *);
148 int procfs_validdbregs (struct lwp *);
149 int procfs_validmap (struct lwp *);
150 int procfs_validtype (struct lwp *);
151 
152 struct proc *pfs_pfind(pid_t);
153 struct proc *pfs_zpfind(pid_t);
154 void pfs_pdone(struct proc *);
155 
156 #define PFS_DEAD        0x80000000      /* or'd with pid */
157 
158 int       procfs_root (struct mount *, struct vnode **);
159 int       procfs_rw (struct vop_read_args *);
160 
161 #endif /* _KERNEL */
162