Home | History | Annotate | Line # | Download | only in procfs
procfs.h revision 1.86.2.1
      1  1.86.2.1  perseant /*	$NetBSD: procfs.h,v 1.86.2.1 2025/08/02 05:57:45 perseant 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.82    martin #include <sys/proc.h>
     79      1.82    martin 
     80       1.1       cgd /*
     81       1.1       cgd  * The different types of node in a procfs filesystem
     82       1.1       cgd  */
     83       1.1       cgd typedef enum {
     84      1.75  christos 	PFSauxv,	/* ELF Auxiliary Vector */
     85      1.75  christos 	PFSchroot,	/* the process's current root directory */
     86      1.75  christos 	PFScmdline,	/* process command line args */
     87      1.75  christos 	PFScpuinfo,	/* CPU info (if -o linux) */
     88      1.75  christos 	PFScpustat,	/* status info (if -o linux) */
     89      1.49     darcy 	PFScurproc,	/* symbolic link for curproc */
     90      1.75  christos 	PFScwd,		/* the process's current working directory */
     91      1.75  christos 	PFSdevices,	/* major/device name mappings (if -o linux) */
     92      1.75  christos 	PFSemul,	/* the process's emulation */
     93      1.75  christos 	PFSenviron,	/* process environment */
     94      1.75  christos 	PFSexe,		/* symlink to the executable file */
     95      1.75  christos 	PFSfd,		/* a directory containing the processes open fd's */
     96      1.49     darcy 	PFSfile,	/* the executable file */
     97      1.75  christos 	PFSfpregs,	/* the process's FP register set */
     98      1.75  christos 	PFSloadavg,	/* load average (if -o linux) */
     99      1.75  christos 	PFSlimit,	/* resource limits */
    100      1.85  christos 	PFSlimits,	/* resource limits, Linux style (if -o linux) */
    101      1.75  christos 	PFSmap,		/* memory map */
    102      1.75  christos 	PFSmaps,	/* memory map, Linux style (if -o linux) */
    103      1.49     darcy 	PFSmem,		/* the process's memory image */
    104      1.75  christos 	PFSmeminfo,	/* system memory info (if -o linux) */
    105      1.75  christos 	PFSmounts,	/* mounted filesystems (if -o linux) */
    106  1.86.2.1  perseant 	PFSmqueue,	/* sys/fs/mqueue subdirectory (if -o linux) */
    107  1.86.2.1  perseant 	PFSmq_msg_def,	/* sys/fs/mqueue/msg_default (if -o linux) */
    108  1.86.2.1  perseant 	PFSmq_msg_max,	/* sys/fs/mqueue/msg_max (if -o linux) */
    109  1.86.2.1  perseant 	PFSmq_siz_def,	/* sys/fs/mqueue/msgsize_default (if -o linux) */
    110  1.86.2.1  perseant 	PFSmq_siz_max,	/* sys/fs/mqueue/msgsize_max (if -o linux) */
    111  1.86.2.1  perseant 	PFSmq_qmax,	/* sys/fs/mqueue/queues_max (if -o linux) */
    112      1.75  christos 	PFSnote,	/* process notifier */
    113      1.75  christos 	PFSnotepg,	/* process group notifier */
    114      1.75  christos 	PFSproc,	/* a process-specific sub-directory */
    115      1.49     darcy 	PFSregs,	/* the process's register set */
    116      1.75  christos 	PFSroot,	/* the filesystem root */
    117      1.75  christos 	PFSself,	/* like curproc, but this is the Linux name */
    118      1.49     darcy 	PFSstat,	/* process status (if -o linux) */
    119      1.75  christos 	PFSstatm,	/* process memory info (if -o linux) */
    120      1.49     darcy 	PFSstatus,	/* process status */
    121  1.86.2.1  perseant 	PFSsys,		/* sys subdirectory (if -o linux) */
    122  1.86.2.1  perseant 	PFSsysfs,	/* sys/fs subdirectory (if -o linux) */
    123      1.86  christos 	PFSsysvipc,	/* sysvipc subdirectory (if -o linux) */
    124      1.86  christos 	PFSsysvipc_msg,	/* sysvipc msg info (if -o linux) */
    125      1.86  christos 	PFSsysvipc_sem,	/* sysvipc sem info (if -o linux) */
    126      1.86  christos 	PFSsysvipc_shm,	/* sysvipc shm info (if -o linux) */
    127      1.86  christos 	PFStask,	/* task subdirectory (if -o linux) */
    128      1.49     darcy 	PFSuptime,	/* elapsed time since (if -o linux) */
    129      1.66  jmcneill 	PFSversion,	/* kernel version (if -o linux) */
    130      1.36   thorpej #ifdef __HAVE_PROCFS_MACHDEP
    131      1.36   thorpej 	PROCFS_MACHDEP_NODE_TYPES
    132      1.36   thorpej #endif
    133      1.76   mlelstv 	PFSlast,	/* track number of types */
    134       1.1       cgd } pfstype;
    135       1.1       cgd 
    136       1.1       cgd /*
    137       1.1       cgd  * control data for the proc file system.
    138       1.1       cgd  */
    139      1.70   hannken struct pfskey {
    140      1.70   hannken 	pfstype		pk_type;	/* type of procfs node */
    141      1.70   hannken 	pid_t		pk_pid;		/* associated process */
    142      1.70   hannken 	int		pk_fd;		/* associated fd if not -1 */
    143      1.70   hannken };
    144       1.1       cgd struct pfsnode {
    145      1.83   hannken 	LIST_ENTRY(pfsnode) pfs_hash;	/* per pid hash list */
    146       1.1       cgd 	struct vnode	*pfs_vnode;	/* vnode associated with this pfsnode */
    147      1.83   hannken 	struct mount	*pfs_mount;	/* mount associated with this pfsnode */
    148      1.70   hannken 	struct pfskey	pfs_key;
    149      1.70   hannken #define pfs_type pfs_key.pk_type
    150      1.70   hannken #define pfs_pid pfs_key.pk_pid
    151      1.70   hannken #define pfs_fd pfs_key.pk_fd
    152      1.18   mycroft 	mode_t		pfs_mode;	/* mode bits for stat() */
    153       1.1       cgd 	u_long		pfs_flags;	/* open flags */
    154      1.76   mlelstv 	uint64_t	pfs_fileno;	/* unique file id */
    155       1.1       cgd };
    156       1.1       cgd 
    157       1.9   mycroft #define PROCFS_NOTELEN	64	/* max length of a note (/proc/$pid/note) */
    158      1.67  christos #define PROCFS_MAXNAMLEN	255
    159      1.52  drochner 
    160      1.52  drochner #endif /* _KERNEL */
    161       1.1       cgd 
    162      1.31      fvdl struct procfs_args {
    163      1.31      fvdl 	int version;
    164      1.31      fvdl 	int flags;
    165      1.31      fvdl };
    166      1.31      fvdl 
    167      1.31      fvdl #define PROCFS_ARGSVERSION	1
    168      1.31      fvdl 
    169      1.31      fvdl #define PROCFSMNT_LINUXCOMPAT	0x01
    170      1.38  christos 
    171      1.38  christos #define PROCFSMNT_BITS "\177\20" \
    172      1.51      yamt     "b\00linuxcompat\0"
    173      1.31      fvdl 
    174       1.1       cgd /*
    175       1.1       cgd  * Kernel stuff follows
    176       1.1       cgd  */
    177      1.13    briggs #ifdef _KERNEL
    178       1.9   mycroft #define CNEQ(cnp, s, len) \
    179       1.9   mycroft 	 ((cnp)->cn_namelen == (len) && \
    180      1.22     perry 	  (memcmp((s), (cnp)->cn_nameptr, (len)) == 0))
    181       1.1       cgd 
    182      1.14   mycroft #define UIO_MX 32
    183      1.14   mycroft 
    184      1.77  christos static __inline ino_t
    185      1.77  christos procfs_fileno(pid_t _pid, pfstype _type, int _fd)
    186      1.77  christos {
    187      1.77  christos 	ino_t _ino;
    188      1.77  christos 	switch (_type) {
    189      1.77  christos 	case PFSroot:
    190      1.77  christos 		return 2;
    191      1.77  christos 	case PFScurproc:
    192      1.77  christos 		return 3;
    193      1.77  christos 	case PFSself:
    194      1.77  christos 		return 4;
    195      1.77  christos 	default:
    196      1.77  christos 		_ino = _pid + 1;
    197      1.77  christos 		if (_fd != -1)
    198      1.77  christos 			_ino = _ino << 32 | _fd;
    199      1.77  christos 		return _ino * PFSlast + _type;
    200      1.77  christos 	}
    201      1.77  christos }
    202      1.77  christos 
    203      1.77  christos #define PROCFS_FILENO(pid, type, fd) procfs_fileno(pid, type, fd)
    204      1.77  christos 
    205      1.76   mlelstv #define PROCFS_TYPE(type)	((type) % PFSlast)
    206       1.1       cgd 
    207      1.28      fvdl struct procfsmount {
    208      1.31      fvdl 	int pmnt_flags;
    209      1.28      fvdl };
    210      1.28      fvdl 
    211      1.28      fvdl #define VFSTOPROC(mp)	((struct procfsmount *)(mp)->mnt_data)
    212      1.28      fvdl 
    213       1.1       cgd /*
    214       1.1       cgd  * Convert between pfsnode vnode
    215       1.1       cgd  */
    216       1.1       cgd #define VTOPFS(vp)	((struct pfsnode *)(vp)->v_data)
    217       1.1       cgd #define PFSTOV(pfs)	((pfs)->pfs_vnode)
    218       1.1       cgd 
    219       1.9   mycroft typedef struct vfs_namemap vfs_namemap_t;
    220       1.9   mycroft struct vfs_namemap {
    221       1.1       cgd 	const char *nm_name;
    222       1.1       cgd 	int nm_val;
    223       1.1       cgd };
    224       1.1       cgd 
    225      1.57   xtraeme int vfs_getuserstr(struct uio *, char *, int *);
    226      1.57   xtraeme const vfs_namemap_t *vfs_findname(const vfs_namemap_t *, const char *, int);
    227       1.1       cgd 
    228      1.80  riastrad struct mount;
    229      1.80  riastrad 
    230      1.79   thorpej struct proc *procfs_proc_find(struct mount *, pid_t);
    231      1.79   thorpej bool procfs_use_linux_compat(struct mount *);
    232      1.81    bouyer 
    233      1.81    bouyer static inline bool
    234      1.81    bouyer procfs_proc_is_linux_compat(void)
    235      1.81    bouyer {
    236      1.81    bouyer 	const char *emulname = curlwp->l_proc->p_emul->e_name;
    237      1.81    bouyer 	return (strncmp(emulname, "linux", 5) == 0);
    238      1.81    bouyer }
    239      1.81    bouyer 
    240      1.79   thorpej int procfs_proc_lock(struct mount *, int, struct proc **, int);
    241      1.63        ad void procfs_proc_unlock(struct proc *);
    242      1.70   hannken int procfs_allocvp(struct mount *, struct vnode **, pid_t, pfstype, int);
    243      1.59  christos int procfs_donote(struct lwp *, struct proc *, struct pfsnode *,
    244      1.57   xtraeme     struct uio *);
    245      1.59  christos int procfs_doregs(struct lwp *, struct lwp *, struct pfsnode *,
    246      1.57   xtraeme     struct uio *);
    247      1.59  christos int procfs_dofpregs(struct lwp *, struct lwp *, struct pfsnode *,
    248      1.57   xtraeme     struct uio *);
    249      1.59  christos int procfs_domem(struct lwp *, struct lwp *, struct pfsnode *,
    250      1.57   xtraeme     struct uio *);
    251      1.59  christos int procfs_do_pid_stat(struct lwp *, struct lwp *, struct pfsnode *,
    252      1.57   xtraeme     struct uio *);
    253      1.59  christos int procfs_dostatus(struct lwp *, struct lwp *, struct pfsnode *,
    254      1.57   xtraeme     struct uio *);
    255      1.59  christos int procfs_domap(struct lwp *, struct proc *, struct pfsnode *,
    256      1.57   xtraeme     struct uio *, int);
    257      1.74  christos int procfs_doprocargs(struct lwp *, struct proc *, struct pfsnode *,
    258      1.73  christos     struct uio *, int);
    259      1.59  christos int procfs_domeminfo(struct lwp *, struct proc *, struct pfsnode *,
    260      1.57   xtraeme     struct uio *);
    261      1.60      manu int procfs_dodevices(struct lwp *, struct proc *, struct pfsnode *,
    262      1.60      manu     struct uio *);
    263      1.59  christos int procfs_docpuinfo(struct lwp *, struct proc *, struct pfsnode *,
    264      1.57   xtraeme     struct uio *);
    265      1.64       agc int procfs_docpustat(struct lwp *, struct proc *, struct pfsnode *,
    266      1.64       agc     struct uio *);
    267      1.64       agc int procfs_doloadavg(struct lwp *, struct proc *, struct pfsnode *,
    268      1.64       agc     struct uio *);
    269      1.64       agc int procfs_do_pid_statm(struct lwp *, struct lwp *, struct pfsnode *,
    270      1.64       agc     struct uio *);
    271      1.59  christos int procfs_dofd(struct lwp *, struct proc *, struct pfsnode *,
    272      1.57   xtraeme     struct uio *);
    273      1.59  christos int procfs_douptime(struct lwp *, struct proc *, struct pfsnode *,
    274      1.57   xtraeme     struct uio *);
    275      1.59  christos int procfs_domounts(struct lwp *, struct proc *, struct pfsnode *,
    276      1.57   xtraeme     struct uio *);
    277      1.62  christos int procfs_doemul(struct lwp *, struct proc *, struct pfsnode *,
    278      1.62  christos     struct uio *);
    279      1.66  jmcneill int procfs_doversion(struct lwp *, struct proc *, struct pfsnode *,
    280      1.66  jmcneill     struct uio *);
    281      1.71  christos int procfs_doauxv(struct lwp *, struct proc *, struct pfsnode *,
    282      1.71  christos     struct uio *);
    283      1.75  christos int procfs_dolimit(struct lwp *, struct proc *, struct pfsnode *,
    284      1.75  christos     struct uio *);
    285      1.85  christos int procfs_dolimits(struct lwp *, struct proc *, struct pfsnode *,
    286      1.85  christos     struct uio *);
    287  1.86.2.1  perseant int procfs_domq_msg_def(struct lwp *, struct proc *, struct pfsnode *,
    288  1.86.2.1  perseant     struct uio *);
    289  1.86.2.1  perseant int procfs_domq_msg_max(struct lwp *, struct proc *, struct pfsnode *,
    290  1.86.2.1  perseant     struct uio *);
    291  1.86.2.1  perseant int procfs_domq_siz_def(struct lwp *, struct proc *, struct pfsnode *,
    292  1.86.2.1  perseant     struct uio *);
    293  1.86.2.1  perseant int procfs_domq_siz_max(struct lwp *, struct proc *, struct pfsnode *,
    294  1.86.2.1  perseant     struct uio *);
    295  1.86.2.1  perseant int procfs_domq_qmax(struct lwp *, struct proc *, struct pfsnode *,
    296  1.86.2.1  perseant     struct uio *);
    297      1.86  christos int procfs_dosysvipc_msg(struct lwp *, struct proc *, struct pfsnode *,
    298      1.86  christos     struct uio *);
    299      1.86  christos int procfs_dosysvipc_sem(struct lwp *, struct proc *, struct pfsnode *,
    300      1.86  christos     struct uio *);
    301      1.86  christos int procfs_dosysvipc_shm(struct lwp *, struct proc *, struct pfsnode *,
    302      1.86  christos     struct uio *);
    303      1.57   xtraeme 
    304      1.83   hannken void procfs_hashrem(struct pfsnode *);
    305      1.63        ad int procfs_getfp(struct pfsnode *, struct proc *, struct file **);
    306       1.8       cgd 
    307       1.8       cgd /* functions to check whether or not files should be displayed */
    308      1.71  christos int procfs_validauxv(struct lwp *, struct mount *);
    309      1.59  christos int procfs_validfile(struct lwp *, struct mount *);
    310      1.59  christos int procfs_validfpregs(struct lwp *, struct mount *);
    311      1.59  christos int procfs_validregs(struct lwp *, struct mount *);
    312      1.59  christos int procfs_validmap(struct lwp *, struct mount *);
    313      1.17  christos 
    314      1.57   xtraeme int procfs_rw(void *);
    315      1.31      fvdl 
    316      1.69  christos int procfs_getcpuinfstr(char *, size_t *);
    317       1.1       cgd 
    318       1.1       cgd #define PROCFS_LOCKED	0x01
    319       1.1       cgd #define PROCFS_WANT	0x02
    320       1.1       cgd 
    321      1.57   xtraeme extern int (**procfs_vnodeop_p)(void *);
    322       1.1       cgd extern struct vfsops procfs_vfsops;
    323       1.1       cgd 
    324      1.78        ad int	procfs_root(struct mount *, int, struct vnode **);
    325      1.36   thorpej 
    326      1.36   thorpej #ifdef __HAVE_PROCFS_MACHDEP
    327      1.36   thorpej struct vattr;
    328      1.36   thorpej 
    329      1.36   thorpej void	procfs_machdep_allocvp(struct vnode *);
    330      1.59  christos int	procfs_machdep_rw(struct lwp *, struct lwp *, struct pfsnode *,
    331      1.36   thorpej 	    struct uio *);
    332      1.36   thorpej int	procfs_machdep_getattr(struct vnode *, struct vattr *, struct proc *);
    333      1.36   thorpej #endif
    334      1.16  christos 
    335      1.13    briggs #endif /* _KERNEL */
    336