Home | History | Annotate | Line # | Download | only in procfs
procfs.h revision 1.74.4.1
      1 /*	$NetBSD: procfs.h,v 1.74.4.1 2019/06/10 22:09:06 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 	PFSauxv,	/* ELF Auxiliary Vector */
     83 	PFSchroot,	/* the process's current root directory */
     84 	PFScmdline,	/* process command line args */
     85 	PFScpuinfo,	/* CPU info (if -o linux) */
     86 	PFScpustat,	/* status info (if -o linux) */
     87 	PFScurproc,	/* symbolic link for curproc */
     88 	PFScwd,		/* the process's current working directory */
     89 	PFSdevices,	/* major/device name mappings (if -o linux) */
     90 	PFSemul,	/* the process's emulation */
     91 	PFSenviron,	/* process environment */
     92 	PFSexe,		/* symlink to the executable file */
     93 	PFSfd,		/* a directory containing the processes open fd's */
     94 	PFSfile,	/* the executable file */
     95 	PFSfpregs,	/* the process's FP register set */
     96 	PFSloadavg,	/* load average (if -o linux) */
     97 	PFSlimit,	/* resource limits */
     98 	PFSmap,		/* memory map */
     99 	PFSmaps,	/* memory map, Linux style (if -o linux) */
    100 	PFSmem,		/* the process's memory image */
    101 	PFSmeminfo,	/* system memory info (if -o linux) */
    102 	PFSmounts,	/* mounted filesystems (if -o linux) */
    103 	PFSnote,	/* process notifier */
    104 	PFSnotepg,	/* process group notifier */
    105 	PFSproc,	/* a process-specific sub-directory */
    106 	PFSregs,	/* the process's register set */
    107 	PFSroot,	/* the filesystem root */
    108 	PFSself,	/* like curproc, but this is the Linux name */
    109 	PFSstat,	/* process status (if -o linux) */
    110 	PFSstatm,	/* process memory info (if -o linux) */
    111 	PFSstatus,	/* process status */
    112 	PFStask,	/* task subdirector (if -o linux) */
    113 	PFSuptime,	/* elapsed time since (if -o linux) */
    114 	PFSversion,	/* kernel version (if -o linux) */
    115 #ifdef __HAVE_PROCFS_MACHDEP
    116 	PROCFS_MACHDEP_NODE_TYPES
    117 #endif
    118 	PFSlast,	/* track number of types */
    119 } pfstype;
    120 
    121 /*
    122  * control data for the proc file system.
    123  */
    124 struct pfskey {
    125 	pfstype		pk_type;	/* type of procfs node */
    126 	pid_t		pk_pid;		/* associated process */
    127 	int		pk_fd;		/* associated fd if not -1 */
    128 };
    129 struct pfsnode {
    130 	struct vnode	*pfs_vnode;	/* vnode associated with this pfsnode */
    131 	struct pfskey	pfs_key;
    132 #define pfs_type pfs_key.pk_type
    133 #define pfs_pid pfs_key.pk_pid
    134 #define pfs_fd pfs_key.pk_fd
    135 	mode_t		pfs_mode;	/* mode bits for stat() */
    136 	u_long		pfs_flags;	/* open flags */
    137 	uint64_t	pfs_fileno;	/* unique file id */
    138 };
    139 
    140 #define PROCFS_NOTELEN	64	/* max length of a note (/proc/$pid/note) */
    141 #define PROCFS_MAXNAMLEN	255
    142 
    143 #endif /* _KERNEL */
    144 
    145 struct procfs_args {
    146 	int version;
    147 	int flags;
    148 };
    149 
    150 #define PROCFS_ARGSVERSION	1
    151 
    152 #define PROCFSMNT_LINUXCOMPAT	0x01
    153 
    154 #define PROCFSMNT_BITS "\177\20" \
    155     "b\00linuxcompat\0"
    156 
    157 /*
    158  * Kernel stuff follows
    159  */
    160 #ifdef _KERNEL
    161 #define CNEQ(cnp, s, len) \
    162 	 ((cnp)->cn_namelen == (len) && \
    163 	  (memcmp((s), (cnp)->cn_nameptr, (len)) == 0))
    164 
    165 #define UIO_MX 32
    166 
    167 #define PROCFS_FILENO(pid, type, fd) \
    168 	(  (type) == PFSroot ? 2 \
    169 	 : (type) == PFScurproc ? 3 \
    170 	 : (type) == PFSself ? 4 \
    171          : (fd) == -1 ? ((pid)+1) * PFSlast + (type) \
    172          : ((uint64_t)((pid)+1) << 32 | (fd)) * PFSlast + (type))
    173 #define PROCFS_TYPE(type)	((type) % PFSlast)
    174 
    175 struct procfsmount {
    176 	void *pmnt_exechook;
    177 	int pmnt_flags;
    178 };
    179 
    180 #define VFSTOPROC(mp)	((struct procfsmount *)(mp)->mnt_data)
    181 
    182 /*
    183  * Convert between pfsnode vnode
    184  */
    185 #define VTOPFS(vp)	((struct pfsnode *)(vp)->v_data)
    186 #define PFSTOV(pfs)	((pfs)->pfs_vnode)
    187 
    188 typedef struct vfs_namemap vfs_namemap_t;
    189 struct vfs_namemap {
    190 	const char *nm_name;
    191 	int nm_val;
    192 };
    193 
    194 int vfs_getuserstr(struct uio *, char *, int *);
    195 const vfs_namemap_t *vfs_findname(const vfs_namemap_t *, const char *, int);
    196 
    197 int procfs_proc_lock(int, struct proc **, int);
    198 void procfs_proc_unlock(struct proc *);
    199 struct mount;
    200 int procfs_allocvp(struct mount *, struct vnode **, pid_t, pfstype, int);
    201 int procfs_donote(struct lwp *, struct proc *, struct pfsnode *,
    202     struct uio *);
    203 int procfs_doregs(struct lwp *, struct lwp *, struct pfsnode *,
    204     struct uio *);
    205 int procfs_dofpregs(struct lwp *, struct lwp *, struct pfsnode *,
    206     struct uio *);
    207 int procfs_domem(struct lwp *, struct lwp *, struct pfsnode *,
    208     struct uio *);
    209 int procfs_do_pid_stat(struct lwp *, struct lwp *, struct pfsnode *,
    210     struct uio *);
    211 int procfs_dostatus(struct lwp *, struct lwp *, struct pfsnode *,
    212     struct uio *);
    213 int procfs_domap(struct lwp *, struct proc *, struct pfsnode *,
    214     struct uio *, int);
    215 int procfs_doprocargs(struct lwp *, struct proc *, struct pfsnode *,
    216     struct uio *, int);
    217 int procfs_domeminfo(struct lwp *, struct proc *, struct pfsnode *,
    218     struct uio *);
    219 int procfs_dodevices(struct lwp *, struct proc *, struct pfsnode *,
    220     struct uio *);
    221 int procfs_docpuinfo(struct lwp *, struct proc *, struct pfsnode *,
    222     struct uio *);
    223 int procfs_docpustat(struct lwp *, struct proc *, struct pfsnode *,
    224     struct uio *);
    225 int procfs_doloadavg(struct lwp *, struct proc *, struct pfsnode *,
    226     struct uio *);
    227 int procfs_do_pid_statm(struct lwp *, struct lwp *, struct pfsnode *,
    228     struct uio *);
    229 int procfs_dofd(struct lwp *, struct proc *, struct pfsnode *,
    230     struct uio *);
    231 int procfs_douptime(struct lwp *, struct proc *, struct pfsnode *,
    232     struct uio *);
    233 int procfs_domounts(struct lwp *, struct proc *, struct pfsnode *,
    234     struct uio *);
    235 int procfs_doemul(struct lwp *, struct proc *, struct pfsnode *,
    236     struct uio *);
    237 int procfs_doversion(struct lwp *, struct proc *, struct pfsnode *,
    238     struct uio *);
    239 int procfs_doauxv(struct lwp *, struct proc *, struct pfsnode *,
    240     struct uio *);
    241 int procfs_dolimit(struct lwp *, struct proc *, struct pfsnode *,
    242     struct uio *);
    243 
    244 void procfs_revoke_vnodes(struct proc *, void *);
    245 int procfs_getfp(struct pfsnode *, struct proc *, struct file **);
    246 
    247 /* functions to check whether or not files should be displayed */
    248 int procfs_validauxv(struct lwp *, struct mount *);
    249 int procfs_validfile(struct lwp *, struct mount *);
    250 int procfs_validfpregs(struct lwp *, struct mount *);
    251 int procfs_validregs(struct lwp *, struct mount *);
    252 int procfs_validmap(struct lwp *, struct mount *);
    253 
    254 int procfs_rw(void *);
    255 
    256 int procfs_getcpuinfstr(char *, size_t *);
    257 
    258 #define PROCFS_LOCKED	0x01
    259 #define PROCFS_WANT	0x02
    260 
    261 extern int (**procfs_vnodeop_p)(void *);
    262 extern struct vfsops procfs_vfsops;
    263 
    264 int	procfs_root(struct mount *, struct vnode **);
    265 
    266 #ifdef __HAVE_PROCFS_MACHDEP
    267 struct vattr;
    268 
    269 void	procfs_machdep_allocvp(struct vnode *);
    270 int	procfs_machdep_rw(struct lwp *, struct lwp *, struct pfsnode *,
    271 	    struct uio *);
    272 int	procfs_machdep_getattr(struct vnode *, struct vattr *, struct proc *);
    273 #endif
    274 
    275 #endif /* _KERNEL */
    276