Kernel - Fix numerous procfs/ptrace issues
[dragonfly.git] / sys / vfs / procfs / procfs.h
CommitLineData
984263bc
MD
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 * $FreeBSD: src/sys/miscfs/procfs/procfs.h,v 1.32.2.3 2002/01/22 17:22:59 nectar Exp $
c7e98b2f 41 * $DragonFly: src/sys/vfs/procfs/procfs.h,v 1.8 2007/02/19 01:14:24 corecode Exp $
984263bc
MD
42 */
43
44/*
45 * The different types of node in a procfs filesystem
46 */
47typedef enum {
48 Proot, /* the filesystem root */
49 Pcurproc, /* symbolic link for curproc */
50 Pproc, /* a process-specific sub-directory */
51 Pfile, /* the executable file */
52 Pmem, /* the process's memory image */
53 Pregs, /* the process's register set */
54 Pfpregs, /* the process's FP register set */
55 Pdbregs, /* the process's debug register set */
56 Pctl, /* process control */
57 Pstatus, /* process status */
58 Pnote, /* process notifier */
59 Pnotepg, /* process group notifier */
60 Pmap, /* memory map */
61 Ptype, /* executable type */
62 Pcmdline, /* command line */
63 Prlimit /* resource limits */
64} pfstype;
65
66/*
67 * control data for the proc file system.
68 */
69struct pfsnode {
70 struct pfsnode *pfs_next; /* next on list */
71 struct vnode *pfs_vnode; /* vnode associated with this pfsnode */
72 pfstype pfs_type; /* type of procfs node */
73 pid_t pfs_pid; /* associated process */
74 u_short pfs_mode; /* mode bits for stat() */
75 u_long pfs_flags; /* open flags */
76 u_long pfs_fileno; /* unique file id */
77 pid_t pfs_lockowner; /* pfs lock owner */
78};
79
80#define PROCFS_NOTELEN 64 /* max length of a note (/proc/$pid/note) */
81#define PROCFS_CTLLEN 8 /* max length of a ctl msg (/proc/$pid/ctl */
82#define PROCFS_NAMELEN 8 /* max length of a filename component */
83
84/*
85 * Kernel stuff follows
86 */
87#ifdef _KERNEL
88#define CNEQ(cnp, s, len) \
89 ((cnp)->cn_namelen == (len) && \
90 (bcmp((s), (cnp)->cn_nameptr, (len)) == 0))
91
92#define PROCFS_FILENO(pid, type) \
93 (((type) < Pproc) ? \
94 ((type) + 2) : \
95 ((((pid)+1) << 4) + ((int) (type))))
96
0620bd26 97/* XXX: Is PRIV_DEBUG_UNPRIV correct? */
984263bc 98#define CHECKIO(p1, p2) \
41c20dac
MD
99 ((((p1)->p_ucred->cr_uid == (p2)->p_ucred->cr_ruid) && \
100 ((p1)->p_ucred->cr_ruid == (p2)->p_ucred->cr_ruid) && \
101 ((p1)->p_ucred->cr_svuid == (p2)->p_ucred->cr_ruid) && \
4643740a 102 ((p2)->p_flags & (P_SUGID|P_INEXEC)) == 0) || \
0620bd26 103 (priv_check_cred((p1)->p_ucred, PRIV_DEBUG_UNPRIV, 0) == 0))
984263bc
MD
104
105/*
106 * Convert between pfsnode vnode
107 */
108#define VTOPFS(vp) ((struct pfsnode *)(vp)->v_data)
109#define PFSTOV(pfs) ((pfs)->pfs_vnode)
110
111typedef struct vfs_namemap vfs_namemap_t;
112struct vfs_namemap {
113 const char *nm_name;
114 int nm_val;
115};
116
a6ee311a
RG
117int vfs_getuserstr (struct uio *, char *, int *);
118vfs_namemap_t *vfs_findname (vfs_namemap_t *, char *, int);
984263bc
MD
119
120/* <machine/reg.h> */
121struct reg;
122struct fpreg;
123struct dbreg;
124
a6ee311a
RG
125void procfs_exit (struct thread *);
126int procfs_freevp (struct vnode *);
127int procfs_allocvp (struct mount *, struct vnode **, long, pfstype);
128struct vnode *procfs_findtextvp (struct proc *);
c7e98b2f
SS
129int procfs_sstep (struct lwp *);
130int procfs_read_regs (struct lwp *, struct reg *);
131int procfs_write_regs (struct lwp *, struct reg *);
132int procfs_read_fpregs (struct lwp *, struct fpreg *);
133int procfs_write_fpregs (struct lwp *, struct fpreg *);
134int procfs_read_dbregs (struct lwp *, struct dbreg *);
135int procfs_write_dbregs (struct lwp *, struct dbreg *);
136int procfs_donote (struct proc *, struct lwp *, struct pfsnode *pfsp, struct uio *uio);
137int procfs_doregs (struct proc *, struct lwp *, struct pfsnode *pfsp, struct uio *uio);
138int procfs_dofpregs (struct proc *, struct lwp *, struct pfsnode *pfsp, struct uio *uio);
139int procfs_dodbregs (struct proc *, struct lwp *, struct pfsnode *pfsp, struct uio *uio);
140int procfs_domem (struct proc *, struct lwp *, struct pfsnode *pfsp, struct uio *uio);
141int procfs_doctl (struct proc *, struct lwp *, struct pfsnode *pfsp, struct uio *uio);
142int procfs_dostatus (struct proc *, struct lwp *, struct pfsnode *pfsp, struct uio *uio);
143int procfs_domap (struct proc *, struct lwp *, struct pfsnode *pfsp, struct uio *uio);
144int procfs_dotype (struct proc *, struct lwp *, struct pfsnode *pfsp, struct uio *uio);
145int procfs_docmdline (struct proc *, struct lwp *, struct pfsnode *pfsp, struct uio *uio);
146int procfs_dorlimit (struct proc *, struct lwp *, struct pfsnode *pfsp, struct uio *uio);
984263bc
MD
147
148/* functions to check whether or not files should be displayed */
c7e98b2f
SS
149int procfs_validfile (struct lwp *);
150int procfs_validfpregs (struct lwp *);
151int procfs_validregs (struct lwp *);
152int procfs_validdbregs (struct lwp *);
153int procfs_validmap (struct lwp *);
154int procfs_validtype (struct lwp *);
984263bc 155
198c0ff2 156struct proc *pfs_pfind(pid_t);
b2a6ad87 157struct proc *pfs_zpfind(pid_t);
f44c73be 158void pfs_pdone(struct proc *);
198c0ff2 159
984263bc
MD
160#define PROCFS_LOCKED 0x01
161#define PROCFS_WANT 0x02
162
e193508c
MD
163#define PFS_DEAD 0x80000000 /* or'd with pid */
164
a6ee311a
RG
165int procfs_root (struct mount *, struct vnode **);
166int procfs_rw (struct vop_read_args *);
0961aa92 167
984263bc 168#endif /* _KERNEL */