Home | History | Annotate | Line # | Download | only in procfs
procfs.h revision 1.42
      1 /*	$NetBSD: procfs.h,v 1.42 2003/04/17 19:04:25 jdolecek Exp $	*/
      2 
      3 /*
      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 
     42 /* This also pulls in __HAVE_PROCFS_MACHDEP */
     43 #include <sys/ptrace.h>
     44 
     45 /*
     46  * The different types of node in a procfs filesystem
     47  */
     48 typedef enum {
     49 	Proot,		/* the filesystem root */
     50 	Pcurproc,	/* symbolic link for curproc */
     51 	Pself,		/* like curproc, but this is the Linux name */
     52 	Pproc,		/* a process-specific sub-directory */
     53 	Pfile,		/* the executable file */
     54 	Pmem,		/* the process's memory image */
     55 	Pregs,		/* the process's register set */
     56 	Pfpregs,	/* the process's FP register set */
     57 	Pctl,		/* process control */
     58 	Pstatus,	/* process status */
     59 	Pnote,		/* process notifier */
     60 	Pnotepg,	/* process group notifier */
     61 	Pmap,		/* memory map */
     62 	Pcmdline,	/* process command line args */
     63 	Pmeminfo,	/* system memory info (if -o linux) */
     64 	Pcpuinfo,	/* CPU info (if -o linux) */
     65 	Pmaps,		/* memory map, Linux style (if -o linux) */
     66 	Pfd,		/* a directory containing the processes open fd's */
     67 	Puptime,	/* elapsed time since (if -o linux) */
     68 #ifdef __HAVE_PROCFS_MACHDEP
     69 	PROCFS_MACHDEP_NODE_TYPES
     70 #endif
     71 } pfstype;
     72 
     73 /*
     74  * control data for the proc file system.
     75  */
     76 struct pfsnode {
     77 	LIST_ENTRY(pfsnode) pfs_hash;	/* hash chain */
     78 	struct vnode	*pfs_vnode;	/* vnode associated with this pfsnode */
     79 	pfstype		pfs_type;	/* type of procfs node */
     80 	pid_t		pfs_pid;	/* associated process */
     81 	int		pfs_fd;		/* associated fd if not -1 */
     82 	mode_t		pfs_mode;	/* mode bits for stat() */
     83 	u_long		pfs_flags;	/* open flags */
     84 	u_long		pfs_fileno;	/* unique file id */
     85 };
     86 
     87 #define PROCFS_NOTELEN	64	/* max length of a note (/proc/$pid/note) */
     88 #define PROCFS_CTLLEN 	8	/* max length of a ctl msg (/proc/$pid/ctl */
     89 
     90 struct procfs_args {
     91 	int version;
     92 	int flags;
     93 };
     94 
     95 #define PROCFS_ARGSVERSION	1
     96 
     97 #define PROCFSMNT_LINUXCOMPAT	0x01
     98 
     99 #define PROCFSMNT_BITS "\177\20" \
    100     "b\00linuxcompat"
    101 
    102 /*
    103  * Kernel stuff follows
    104  */
    105 #ifdef _KERNEL
    106 #define CNEQ(cnp, s, len) \
    107 	 ((cnp)->cn_namelen == (len) && \
    108 	  (memcmp((s), (cnp)->cn_nameptr, (len)) == 0))
    109 
    110 #define UIO_MX 32
    111 
    112 #define PROCFS_FILENO(pid, type, fd) \
    113     (((type) < Pproc) ? ((type) + 2) : \
    114 	(((fd) == -1) ? ((((pid)+1) << 4) + ((int) (type))) : \
    115 	((((pid)+1) << 16) | ((fd) << 4) | ((int) (type)))))
    116 
    117 struct procfsmount {
    118 	void *pmnt_exechook;
    119 	int pmnt_flags;
    120 };
    121 
    122 #define VFSTOPROC(mp)	((struct procfsmount *)(mp)->mnt_data)
    123 
    124 /*
    125  * Convert between pfsnode vnode
    126  */
    127 #define VTOPFS(vp)	((struct pfsnode *)(vp)->v_data)
    128 #define PFSTOV(pfs)	((pfs)->pfs_vnode)
    129 
    130 typedef struct vfs_namemap vfs_namemap_t;
    131 struct vfs_namemap {
    132 	const char *nm_name;
    133 	int nm_val;
    134 };
    135 
    136 int vfs_getuserstr __P((struct uio *, char *, int *));
    137 const vfs_namemap_t *vfs_findname __P((const vfs_namemap_t *, const char *, int));
    138 
    139 #define PFIND(pid) ((pid) ? pfind(pid) : &proc0)
    140 int procfs_freevp __P((struct vnode *));
    141 int procfs_allocvp __P((struct mount *, struct vnode **, pid_t, pfstype, int));
    142 int procfs_donote __P((struct proc *, struct proc *, struct pfsnode *,
    143     struct uio *));
    144 int procfs_doregs __P((struct proc *, struct lwp *, struct pfsnode *,
    145     struct uio *));
    146 int procfs_dofpregs __P((struct proc *, struct lwp *, struct pfsnode *,
    147     struct uio *));
    148 int procfs_domem __P((struct proc *, struct proc *, struct pfsnode *,
    149     struct uio *));
    150 int procfs_doctl __P((struct proc *, struct lwp *, struct pfsnode *,
    151     struct uio *));
    152 int procfs_dostatus __P((struct proc *, struct lwp *, struct pfsnode *,
    153     struct uio *));
    154 int procfs_domap __P((struct proc *, struct proc *, struct pfsnode *,
    155     struct uio *, int));
    156 int procfs_docmdline __P((struct proc *, struct proc *, struct pfsnode *,
    157     struct uio *));
    158 int procfs_domeminfo __P((struct proc *, struct proc *, struct pfsnode *,
    159     struct uio *));
    160 int procfs_docpuinfo __P((struct proc *, struct proc *, struct pfsnode *,
    161     struct uio *));
    162 int procfs_dofd __P((struct proc *, struct proc *, struct pfsnode *,
    163     struct uio *));
    164 int procfs_douptime __P((struct proc *, struct proc *, struct pfsnode *,
    165     struct uio *));
    166 
    167 void procfs_revoke_vnodes __P((struct proc *, void *));
    168 void procfs_hashinit __P((void));
    169 void procfs_hashreinit __P((void));
    170 void procfs_hashdone __P((void));
    171 int procfs_getfp __P((struct pfsnode *, struct proc **, struct file **));
    172 
    173 /* functions to check whether or not files should be displayed */
    174 int procfs_validfile __P((struct proc *, struct mount *));
    175 int procfs_validfpregs __P((struct proc *, struct mount *));
    176 int procfs_validregs __P((struct proc *, struct mount *));
    177 int procfs_validmap __P((struct proc *, struct mount *));
    178 
    179 int procfs_rw __P((void *));
    180 
    181 int procfs_getcpuinfstr __P((char *, int *));
    182 
    183 #define PROCFS_LOCKED	0x01
    184 #define PROCFS_WANT	0x02
    185 
    186 extern int (**procfs_vnodeop_p) __P((void *));
    187 extern struct vfsops procfs_vfsops;
    188 
    189 int	procfs_root __P((struct mount *, struct vnode **));
    190 
    191 #ifdef __HAVE_PROCFS_MACHDEP
    192 struct vattr;
    193 
    194 void	procfs_machdep_allocvp(struct vnode *);
    195 int	procfs_machdep_rw(struct proc *, struct lwp *, struct pfsnode *,
    196 	    struct uio *);
    197 int	procfs_machdep_getattr(struct vnode *, struct vattr *, struct proc *);
    198 #endif
    199 
    200 #endif /* _KERNEL */
    201