Home | History | Annotate | Line # | Download | only in procfs
procfs.h revision 1.67
      1 /*	$NetBSD: procfs.h,v 1.67 2011/09/27 01:23:59 christos Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1993
      5  *	The Regents of the University of California.  All rights reserved.
      6  *
      7  * This code is derived from software contributed to Berkeley by
      8  * Jan-Simon Pendry.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. Neither the name of the University nor the names of its contributors
     19  *    may be used to endorse or promote products derived from this software
     20  *    without specific prior written permission.
     21  *
     22  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     23  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     25  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     28  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32  * SUCH DAMAGE.
     33  *
     34  *	@(#)procfs.h	8.9 (Berkeley) 5/14/95
     35  */
     36 
     37 /*
     38  * Copyright (c) 1993 Jan-Simon Pendry
     39  *
     40  * This code is derived from software contributed to Berkeley by
     41  * Jan-Simon Pendry.
     42  *
     43  * Redistribution and use in source and binary forms, with or without
     44  * modification, are permitted provided that the following conditions
     45  * are met:
     46  * 1. Redistributions of source code must retain the above copyright
     47  *    notice, this list of conditions and the following disclaimer.
     48  * 2. Redistributions in binary form must reproduce the above copyright
     49  *    notice, this list of conditions and the following disclaimer in the
     50  *    documentation and/or other materials provided with the distribution.
     51  * 3. All advertising materials mentioning features or use of this software
     52  *    must display the following acknowledgement:
     53  *	This product includes software developed by the University of
     54  *	California, Berkeley and its contributors.
     55  * 4. Neither the name of the University nor the names of its contributors
     56  *    may be used to endorse or promote products derived from this software
     57  *    without specific prior written permission.
     58  *
     59  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     60  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     61  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     62  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     63  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     64  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     65  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     66  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     67  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     68  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     69  * SUCH DAMAGE.
     70  *
     71  *	@(#)procfs.h	8.9 (Berkeley) 5/14/95
     72  */
     73 
     74 /* This also pulls in __HAVE_PROCFS_MACHDEP */
     75 #include <sys/ptrace.h>
     76 
     77 #ifdef _KERNEL
     78 /*
     79  * The different types of node in a procfs filesystem
     80  */
     81 typedef enum {
     82 	PFSroot,	/* the filesystem root */
     83 	PFScurproc,	/* symbolic link for curproc */
     84 	PFSself,	/* like curproc, but this is the Linux name */
     85 	PFSproc,	/* a process-specific sub-directory */
     86 	PFSfile,	/* the executable file */
     87 	PFSexe,		/* symlink to the executable file */
     88 	PFSmem,		/* the process's memory image */
     89 	PFSregs,	/* the process's register set */
     90 	PFSfpregs,	/* the process's FP register set */
     91 	PFSctl,		/* process control */
     92 	PFSstat,	/* process status (if -o linux) */
     93 	PFSstatus,	/* process status */
     94 	PFSnote,	/* process notifier */
     95 	PFSnotepg,	/* process group notifier */
     96 	PFSmap,		/* memory map */
     97 	PFScmdline,	/* process command line args */
     98 	PFSmeminfo,	/* system memory info (if -o linux) */
     99 	PFScpuinfo,	/* CPU info (if -o linux) */
    100 	PFSmaps,	/* memory map, Linux style (if -o linux) */
    101 	PFSfd,		/* a directory containing the processes open fd's */
    102 	PFSuptime,	/* elapsed time since (if -o linux) */
    103 	PFSmounts,	/* mounted filesystems (if -o linux) */
    104 	PFScwd,		/* the process's current working directory */
    105 	PFSchroot,	/* the process's current root directory */
    106 	PFSemul,	/* the process's emulation */
    107 	PFSdevices,	/* major/device name mappings (if -o linux) */
    108 	PFScpustat,	/* status info (if -o linux) */
    109 	PFSloadavg,	/* load average (if -o linux) */
    110 	PFSstatm,	/* process memory info (if -o linux) */
    111 	PFSversion,	/* kernel version (if -o linux) */
    112 #ifdef __HAVE_PROCFS_MACHDEP
    113 	PROCFS_MACHDEP_NODE_TYPES
    114 #endif
    115 } pfstype;
    116 
    117 /*
    118  * control data for the proc file system.
    119  */
    120 struct pfsnode {
    121 	LIST_ENTRY(pfsnode) pfs_hash;	/* hash chain */
    122 	struct vnode	*pfs_vnode;	/* vnode associated with this pfsnode */
    123 	pfstype		pfs_type;	/* type of procfs node */
    124 	pid_t		pfs_pid;	/* associated process */
    125 	int		pfs_fd;		/* associated fd if not -1 */
    126 	mode_t		pfs_mode;	/* mode bits for stat() */
    127 	u_long		pfs_flags;	/* open flags */
    128 	u_long		pfs_fileno;	/* unique file id */
    129 };
    130 
    131 #define PROCFS_NOTELEN	64	/* max length of a note (/proc/$pid/note) */
    132 #define PROCFS_CTLLEN 	8	/* max length of a ctl msg (/proc/$pid/ctl */
    133 #define PROCFS_MAXNAMLEN	255
    134 
    135 #endif /* _KERNEL */
    136 
    137 struct procfs_args {
    138 	int version;
    139 	int flags;
    140 };
    141 
    142 #define PROCFS_ARGSVERSION	1
    143 
    144 #define PROCFSMNT_LINUXCOMPAT	0x01
    145 
    146 #define PROCFSMNT_BITS "\177\20" \
    147     "b\00linuxcompat\0"
    148 
    149 /*
    150  * Kernel stuff follows
    151  */
    152 #ifdef _KERNEL
    153 #define CNEQ(cnp, s, len) \
    154 	 ((cnp)->cn_namelen == (len) && \
    155 	  (memcmp((s), (cnp)->cn_nameptr, (len)) == 0))
    156 
    157 #define UIO_MX 32
    158 
    159 #define PROCFS_FILENO(pid, type, fd) \
    160     (((type) < PFSproc) ? ((type) + 2) : \
    161 	(((fd) == -1) ? ((((pid)+1) << 5) + ((int) (type))) : \
    162 	((((pid)+1) << 16) | ((fd) << 5) | ((int) (type)))))
    163 #define PROCFS_TYPE(type)	((type) & 0x1f)
    164 
    165 struct procfsmount {
    166 	void *pmnt_exechook;
    167 	int pmnt_flags;
    168 };
    169 
    170 #define VFSTOPROC(mp)	((struct procfsmount *)(mp)->mnt_data)
    171 
    172 /*
    173  * Convert between pfsnode vnode
    174  */
    175 #define VTOPFS(vp)	((struct pfsnode *)(vp)->v_data)
    176 #define PFSTOV(pfs)	((pfs)->pfs_vnode)
    177 
    178 typedef struct vfs_namemap vfs_namemap_t;
    179 struct vfs_namemap {
    180 	const char *nm_name;
    181 	int nm_val;
    182 };
    183 
    184 int vfs_getuserstr(struct uio *, char *, int *);
    185 const vfs_namemap_t *vfs_findname(const vfs_namemap_t *, const char *, int);
    186 
    187 int procfs_proc_lock(int, struct proc **, int);
    188 void procfs_proc_unlock(struct proc *);
    189 int procfs_freevp(struct vnode *);
    190 int procfs_allocvp(struct mount *, struct vnode **, pid_t, pfstype, int,
    191     struct proc *);
    192 int procfs_donote(struct lwp *, struct proc *, struct pfsnode *,
    193     struct uio *);
    194 int procfs_doregs(struct lwp *, struct lwp *, struct pfsnode *,
    195     struct uio *);
    196 int procfs_dofpregs(struct lwp *, struct lwp *, struct pfsnode *,
    197     struct uio *);
    198 int procfs_domem(struct lwp *, struct lwp *, struct pfsnode *,
    199     struct uio *);
    200 int procfs_doctl(struct lwp *, struct lwp *, struct pfsnode *,
    201     struct uio *);
    202 int procfs_do_pid_stat(struct lwp *, struct lwp *, struct pfsnode *,
    203     struct uio *);
    204 int procfs_dostatus(struct lwp *, struct lwp *, struct pfsnode *,
    205     struct uio *);
    206 int procfs_domap(struct lwp *, struct proc *, struct pfsnode *,
    207     struct uio *, int);
    208 int procfs_docmdline(struct lwp *, struct proc *, struct pfsnode *,
    209     struct uio *);
    210 int procfs_domeminfo(struct lwp *, struct proc *, struct pfsnode *,
    211     struct uio *);
    212 int procfs_dodevices(struct lwp *, struct proc *, struct pfsnode *,
    213     struct uio *);
    214 int procfs_docpuinfo(struct lwp *, struct proc *, struct pfsnode *,
    215     struct uio *);
    216 int procfs_docpustat(struct lwp *, struct proc *, struct pfsnode *,
    217     struct uio *);
    218 int procfs_doloadavg(struct lwp *, struct proc *, struct pfsnode *,
    219     struct uio *);
    220 int procfs_do_pid_statm(struct lwp *, struct lwp *, struct pfsnode *,
    221     struct uio *);
    222 int procfs_dofd(struct lwp *, struct proc *, struct pfsnode *,
    223     struct uio *);
    224 int procfs_douptime(struct lwp *, struct proc *, struct pfsnode *,
    225     struct uio *);
    226 int procfs_domounts(struct lwp *, struct proc *, struct pfsnode *,
    227     struct uio *);
    228 int procfs_doemul(struct lwp *, struct proc *, struct pfsnode *,
    229     struct uio *);
    230 int procfs_doversion(struct lwp *, struct proc *, struct pfsnode *,
    231     struct uio *);
    232 
    233 void procfs_revoke_vnodes(struct proc *, void *);
    234 void procfs_hashinit(void);
    235 void procfs_hashreinit(void);
    236 void procfs_hashdone(void);
    237 int procfs_getfp(struct pfsnode *, struct proc *, struct file **);
    238 
    239 /* functions to check whether or not files should be displayed */
    240 int procfs_validfile(struct lwp *, struct mount *);
    241 int procfs_validfpregs(struct lwp *, struct mount *);
    242 int procfs_validregs(struct lwp *, struct mount *);
    243 int procfs_validmap(struct lwp *, struct mount *);
    244 
    245 int procfs_rw(void *);
    246 
    247 int procfs_getcpuinfstr(char *, int *);
    248 
    249 #define PROCFS_LOCKED	0x01
    250 #define PROCFS_WANT	0x02
    251 
    252 extern int (**procfs_vnodeop_p)(void *);
    253 extern struct vfsops procfs_vfsops;
    254 
    255 int	procfs_root(struct mount *, struct vnode **);
    256 
    257 #ifdef __HAVE_PROCFS_MACHDEP
    258 struct vattr;
    259 
    260 void	procfs_machdep_allocvp(struct vnode *);
    261 int	procfs_machdep_rw(struct lwp *, struct lwp *, struct pfsnode *,
    262 	    struct uio *);
    263 int	procfs_machdep_getattr(struct vnode *, struct vattr *, struct proc *);
    264 #endif
    265 
    266 #endif /* _KERNEL */
    267