linprocfs - Fix process exit / procfs vnode access race & stepping races
[dragonfly.git] / sys / emulation / linux / i386 / linprocfs / linprocfs.h
CommitLineData
984263bc
MD
1/*
2 * Copyright (c) 2000 Dag-Erling Coïdan Smørgrav
3 * Copyright (c) 1999 Pierre Beyssac
4 * Copyright (c) 1993 Jan-Simon Pendry
5 * Copyright (c) 1993
6 * The Regents of the University of California. All rights reserved.
7 *
8 * This code is derived from software contributed to Berkeley by
9 * Jan-Simon Pendry.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by the University of
22 * California, Berkeley and its contributors.
23 * 4. Neither the name of the University nor the names of its contributors
24 * may be used to endorse or promote products derived from this software
25 * without specific prior written permission.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
28 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 * SUCH DAMAGE.
38 *
39 * @(#)procfs.h 8.9 (Berkeley) 5/14/95
40 *
41 * $FreeBSD: src/sys/i386/linux/linprocfs/linprocfs.h,v 1.2.2.4 2001/06/25 19:46:47 pirzyk Exp $
c97fb367 42 * $DragonFly: src/sys/emulation/linux/i386/linprocfs/linprocfs.h,v 1.10 2007/02/03 09:50:49 y0netan1 Exp $
984263bc
MD
43 */
44
45/*
46 * The different types of node in a procfs filesystem
47 */
48typedef enum {
49 Proot, /* the filesystem root */
50 Pself, /* symbolic link for curproc */
51 Pproc, /* a process-specific sub-directory */
52 Pexe, /* the executable file */
53 Pmem, /* the process's memory image */
54 Pprocstat, /* the process's status */
55 Pprocstatus, /* the process's status (again) */
56 Pmeminfo, /* memory system statistics */
57 Pcpuinfo, /* CPU model, speed and features */
58 Pstat, /* kernel/system statistics */
59 Puptime, /* system uptime */
60 Pversion, /* system version */
a1f82243
AH
61 Ploadavg, /* system load average */
62 Pnet, /* the net sub-directory */
63 Pnetdev, /* net devices */
64 Psys, /* the sys sub-directory */
65 Psyskernel, /* the sys/kernel sub-directory */
66 Pdevices, /* devices */
67 Posrelease, /* osrelease */
68 Postype, /* ostype */
69 Ppidmax, /* pid_max */
70 Pcwd,
71 Pprocroot,
72 Pfd,
73 Pcmdline,
74 Penviron,
75 Pmaps,
76 Pstatm,
a3c5067f 77 Pmounts,
984263bc
MD
78} pfstype;
79
80/*
81 * control data for the proc file system.
82 */
83struct pfsnode {
84 struct pfsnode *pfs_next; /* next on list */
85 struct vnode *pfs_vnode; /* vnode associated with this pfsnode */
86 pfstype pfs_type; /* type of procfs node */
87 pid_t pfs_pid; /* associated process */
88 u_short pfs_mode; /* mode bits for stat() */
89 u_long pfs_flags; /* open flags */
90 u_long pfs_fileno; /* unique file id */
dadab5e9 91 struct thread *pfs_lockowner; /* pfs lock owner */
984263bc
MD
92};
93
94#define PROCFS_NAMELEN 8 /* max length of a filename component */
95
96/*
97 * Kernel stuff follows
98 */
99#ifdef _KERNEL
100#define CNEQ(cnp, s, len) \
101 ((cnp)->cn_namelen == (len) && \
102 (bcmp((s), (cnp)->cn_nameptr, (len)) == 0))
103
104#define KMEM_GROUP 2
105
106#define PROCFS_FILENO(pid, type) \
107 (((type) < Pproc) ? \
108 ((type) + 2) : \
109 ((((pid)+1) << 4) + ((int) (type))))
110
111/*
112 * Convert between pfsnode vnode
113 */
114#define VTOPFS(vp) ((struct pfsnode *)(vp)->v_data)
115#define PFSTOV(pfs) ((pfs)->pfs_vnode)
116
117typedef struct vfs_namemap vfs_namemap_t;
118struct vfs_namemap {
119 const char *nm_name;
120 int nm_val;
121};
122
b1efe3b4
RG
123int vfs_getuserstr (struct uio *, char *, int *);
124vfs_namemap_t *vfs_findname (vfs_namemap_t *, char *, int);
984263bc 125
527fddf7 126/* <sys/reg.h> */
984263bc
MD
127struct reg;
128struct fpreg;
129struct dbreg;
130
58c2553a 131#define PFIND(pid) ((pid) ? pfindn(pid) : &proc0) /* pfindn() not MPSAFE XXX */
984263bc 132
c97fb367 133void linprocfs_init (void);
b1efe3b4
RG
134void linprocfs_exit (struct thread *);
135int linprocfs_freevp (struct vnode *);
136int linprocfs_allocvp (struct mount *, struct vnode **, long, pfstype);
137int linprocfs_sstep (struct proc *);
138void linprocfs_fix_sstep (struct proc *);
96a686f9 139struct proc *linprocfs_pfind(pid_t pfs_pid);
984263bc 140#if 0
b1efe3b4
RG
141int linprocfs_read_regs (struct proc *, struct reg *);
142int linprocfs_write_regs (struct proc *, struct reg *);
143int linprocfs_read_fpregs (struct proc *, struct fpreg *);
144int linprocfs_write_fpregs (struct proc *, struct fpreg *);
145int linprocfs_read_dbregs (struct proc *, struct dbreg *);
146int linprocfs_write_dbregs (struct proc *, struct dbreg *);
984263bc 147#endif
b1efe3b4
RG
148int linprocfs_domeminfo (struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio);
149int linprocfs_docpuinfo (struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio);
a3c5067f 150int linprocfs_domounts (struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio);
b1efe3b4
RG
151int linprocfs_dostat (struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio);
152int linprocfs_douptime (struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio);
153int linprocfs_doversion (struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio);
154int linprocfs_doprocstat (struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio);
155int linprocfs_doprocstatus (struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio);
156int linprocfs_doloadavg (struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio);
a1f82243
AH
157int linprocfs_donetdev (struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio);
158int linprocfs_dodevices (struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio);
159int linprocfs_doosrelease (struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio);
160int linprocfs_doostype (struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio);
161int linprocfs_dopidmax (struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio);
162int linprocfs_domaps(struct proc *curp, struct proc *p, struct pfsnode *pfs, struct uio *uio);
163int linprocfs_dostatm(struct proc *curp, struct proc *p, struct pfsnode *pfs, struct uio *uio);
984263bc 164/* functions to check whether or not files should be displayed */
b1efe3b4 165int linprocfs_validfile (struct proc *);
984263bc
MD
166
167#define PROCFS_LOCKED 0x01
168#define PROCFS_WANT 0x02
169
383d6d14
MD
170#define PFS_DEAD 0x80000000 /* or'd with pid */
171
b1efe3b4
RG
172int linprocfs_root (struct mount *, struct vnode **);
173int linprocfs_rw (struct vop_read_args *);
984263bc 174#endif /* _KERNEL */