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