History log of /netbsd-current/sys/miscfs/procfs/procfs_vnops.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.232 12-May-2024 christos

PR/58227: Ricardo Branco: Add support for proc/sysvipc in Linux emulator


# 1.231 12-May-2024 christos

PR/58240: Ricardo Branco: Add support for proc/self/limits as used by Linux


# 1.230 17-Jan-2024 hannken

Add a hashmap to access all procfs nodes by pid.


Revision tags: netbsd-10-0-RELEASE netbsd-10-0-RC6 netbsd-10-0-RC5 netbsd-10-0-RC4 netbsd-10-0-RC3 netbsd-10-0-RC2 thorpej-ifq-base thorpej-altq-separation-base netbsd-10-0-RC1 netbsd-10-base bouyer-sunxi-drm-base
# 1.229 17-Jun-2022 shm

branches: 1.229.4;
Add missing permission check


# 1.228 27-Mar-2022 christos

dedup the eofs link/symlink methods


# 1.227 17-Jan-2022 bouyer

If the calling process is running under linux emulation, make /proc/xxx/fd/
return only symlinks pointing to the original file in the filesystem,
instead of a hard link. This matches the linux behavior, and some
linux programs relies on it (they unconditionally call readlink() on
/proc/xxx/fd/yy and don't deal with it returning EINVAL).
Proposed on tech-kern@ in
http://mail-index.netbsd.org/tech-kern/2022/01/11/msg027877.html


# 1.226 14-Jan-2022 christos

Fix emul and exe DT_ types (from RVP, as was the previous commit)


# 1.225 14-Jan-2022 christos

Put the appropriate DT_ constant in the dirent structure depending on the
file type.


# 1.224 11-Jan-2022 christos

remove redundant error initialization and break earlier. (from rvp)


# 1.223 11-Jan-2022 hannken

Use a single "p" variable.

Should fix PR kern/56614: kernel panic on tmux


# 1.222 10-Jan-2022 christos

use a single nc variable.


# 1.221 10-Jan-2022 christos

Fix locking in the error path (from RVP). Centralize unlock code.


# 1.220 08-Dec-2021 andvar

s/efficent/efficient/ in comments.


# 1.219 05-Oct-2021 christos

PR/53299: RVP: kernfs and procfs are broken when sysctl security.curtain
is enabled


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base thorpej-i2c-spi-conf-base
# 1.218 18-Jul-2021 dholland

Abolish all the silly indirection macros for initializing vnode ops tables.

These are things of the form #define foofs_op genfs_op, or #define
foofs_op genfs_eopnotsupp, or similar. They serve no purpose besides
obfuscation, and have gotten cutpasted all over everywhere.


# 1.217 29-Jun-2021 dholland

- Add a new vnode op: VOP_PARSEPATH.
- Move namei_getcomponent to genfs_vnops.c and call it genfs_parsepath.
- Add a parsepath entry to every vnode ops table.

VOP_PARSEPATH takes a directory vnode to be searched and a complete
following path and chooses how much of that path to consume. To begin
with, all parsepath calls are genfs_parsepath, which locates the first
'/' as always.

Note that the call doesn't take the whole struct componentname, only
the string. The other bits of struct componentname should not be
needed and there's no reason to cause potential complications by
exposing them.


# 1.216 28-Jun-2021 chs

VOP_BMAP() may be called via ioctl(FIOGETBMAP) on any vnode that applications
can open. change various pseudo-fs *_bmap methods return an error instead of
panic.

Reported-by: syzbot+8289a3eaf2ba60958c87@syzkaller.appspotmail.com


Revision tags: cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base thorpej-cfargs-base thorpej-futex-base
# 1.215 27-Jun-2020 christos

branches: 1.215.6;
Introduce genfs_pathconf() and use it for the default case in all filesystems.


# 1.214 23-May-2020 ad

Move proc_lock into the data segment. It was dynamically allocated because
at the time we had mutex_obj_alloc() but not __cacheline_aligned.


# 1.213 16-May-2020 christos

Add ACL support for FFS. From FreeBSD.


# 1.212 29-Apr-2020 thorpej

If the procfs mount is marked as linux-compat, then allow proc lookup
by any LWP ID in the proc, not just the canonical PID.


Revision tags: bouyer-xenpvh-base2
# 1.211 21-Apr-2020 ad

Revert the changes made in February to make cwdinfo use mostly lockless,
which relied on taking extra vnode refs.

Having benchmarked various experimental changes over the past few months it
seems that it's better to avoid vnode refs as much as possible. cwdi_lock
as a RW lock already did that to some extent for getcwd() and will permit
the same for namei() too.


Revision tags: phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base is-mlppp-base phil-wifi-20200406 ad-namecache-base3
# 1.210 24-Feb-2020 ad

branches: 1.210.4;
v_interlock -> vmobjlock


# 1.209 23-Feb-2020 ad

Merge from ad-namecache:

- Have a stab at clustering the members of vnode_t and vnode_impl_t in a
more cache-conscious way. With that done, go back to adjusting v_usecount
with atomics and keep vi_lock directly in vnode_impl_t (saves KVA).

- Allow VOP_LOCK(LK_NONE) for the benefit of VFS_VGET() and VFS_ROOT().
Make sure LK_UPGRADE always comes with LK_NOWAIT.

- Make cwdinfo use mostly lockless.


# 1.208 01-Feb-2020 riastradh

Load struct filedesc::fd_dt with atomic_load_consume.

Exceptions: when fd_refcnt <= 1, or when holding fd_lock.

While here:

- Restore KASSERT(mutex_owned(&fdp->fd_lock)) in fd_unused.
=> This is used only in fd_close and fd_abort, where it holds.
- Move bounds check assertion in fd_putfile to where it matters.
- Store fd_dt with atomic_store_release.
- Move load of fd_dt under lock in knote_fdclose.
- Omit membar_consumer in fdesc_readdir.
=> atomic_load_consume serves the same purpose now.
=> Was needed only on alpha anyway.


Revision tags: ad-namecache-base2 ad-namecache-base1 ad-namecache-base phil-wifi-20191119
# 1.207 29-Aug-2019 hannken

branches: 1.207.2;
Add missing operation VOP_GETPAGES() returning EFAULT.

Without this operation posix_fadvise(..., POSIX_FADV_WILLNEED)
would leave the v_interlock held.

Observed by maxv@


Revision tags: netbsd-9-base phil-wifi-20190609 isaki-audio2-base
# 1.206 30-Mar-2019 christos

branches: 1.206.4;
add a node for the process resource limits.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020
# 1.205 14-Oct-2018 jdolecek

remove M_CANFAIL flag for malloc(9) - it was completely ignored, so had
actually no effect


Revision tags: pgoyette-compat-0930 pgoyette-compat-0906
# 1.204 03-Sep-2018 riastradh

Rename min/max -> uimin/uimax for better honesty.

These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER! Some subsystems have

#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)


Revision tags: pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415
# 1.203 07-Apr-2018 hannken

branches: 1.203.2;
Lock the target cwdi and take an additional reference to the
vnode we are interested in to prevent it from disappearing
before getcwd_common().

Should fix PR kern/53096 (netbsd-8 crash on heavy disk I/O)


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.202 31-Dec-2017 christos

branches: 1.202.2;
Add an environ node


Revision tags: tls-maxphys-base-20171202
# 1.201 01-Dec-2017 christos

Allow procfs_kqfilter, since we allow poll. "go" does it.


# 1.200 08-Nov-2017 christos

fix locking, remove error(1) comments.


# 1.199 08-Nov-2017 christos

use p->p_path, remove unused code.


# 1.198 28-Aug-2017 kamil

Remove the filesystem tracing feature

This is a legacy interface from 4.4BSD, and it was
introduced to overcome shortcomings of ptrace(2) at that time, which are
no longer relevant (performance). Today /proc/#/ctl offers a narrow
subset of ptrace(2) commands and is not applicable for modern
applications use beyond simplistic tracing scenarios.

This removal will simplify kernel internals. Users will still be able to
use all the other /proc files.

This change won't affect other procfs files neither Linux compat
features within mount_procfs(8). /proc/#/ctl isn't available on Linux.

Remove:
- /proc/#/ctl from mount_procfs(8)
- P_FSTRACE note from the documentation of ps(1)
- /proc/#/ctl and filesystem tracing documentation from mount_procfs(8)
- KAUTH_REQ_PROCESS_PROCFS_CTL documentation from kauth(9)
- source code file miscfs/procfs/procfs_ctl.c
- PFSctl and procfs_doctl() from sys/miscfs/procfs/procfs.h
- KAUTH_REQ_PROCESS_PROCFS_CTL from sys/sys/kauth.h
- PSL_FSTRACE (0x00010000) from sys/sys/proc.h
- P_FSTRACE (0x00010000) from sys/sys/sysctl.h

Reduce code complexity after removal of this functionality.

Update TODO.ptrace accordingly: remove two entries about /proc tracing.

Do not keep legacy notes as comments in the headers about removed
PSL_FSTRACE / P_FSTRACE, as this interface had little number of users
(close or equal to zero).

Proposed on tech-kern@.

All filesystem tracing utility users are encouraged to switch to ptrace(2).

Sponsored by <The NetBSD Foundation>


Revision tags: matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base
# 1.197 26-May-2017 riastradh

branches: 1.197.2;
Make VOP_RECLAIM do the last unlock of the vnode.

VOP_RECLAIM naturally has exclusive access to the vnode, so having it
locked on entry is not strictly necessary -- but it means if there
are any final operations that must be done on the vnode, such as
ffs_update, requiring exclusive access to it, we can now kassert that
the vnode is locked in those operations.

We can't just have the caller release the last lock because some file
systems don't use genfs_lock, and require the vnode to remain valid
for VOP_UNLOCK to work, notably unionfs.


Revision tags: prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.196 11-Apr-2017 riastradh

Make VOP_INACTIVE preserve vnode lock on return.

Discussed on tech-kern:
https://mail-index.netbsd.org/tech-kern/2017/04/01/msg021751.html

Ride 7.99.68, a bumpy bus of incremental vfs improvements!


Revision tags: jdolecek-ncq-base
# 1.195 30-Mar-2017 christos

add an auxv node.


Revision tags: pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004 localcount-20160914
# 1.194 20-Aug-2016 hannken

branches: 1.194.2;
Remove now obsolete operation vcache_remove().

Welcome to 7.99.36


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 nick-nhusb-base-20150921 nick-nhusb-base-20150606
# 1.193 20-Apr-2015 riastradh

branches: 1.193.2;
Make VOP_LINK return directory still locked and referenced.

Ride 7.99.10 bump.


Revision tags: nick-nhusb-base-20150406 nick-nhusb-base
# 1.192 05-Sep-2014 matt

branches: 1.192.2;
Try not to use f_data, use f_{vnode,socket,pipe,mqueue,kqueue,ksem} to get
a correctly typed pointer.


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.191 27-Jul-2014 hannken

branches: 1.191.2; 1.191.4; 1.191.8;
Change procfs from hashlist to vcache.
- Key is (type, pid, fd)
- Remove argument "p" from procfs_allocvp(). It is only used
when "type == PFSfd". Lookup the proc with proc_find() when
procfs_loadvnode() needs it.
- Use a vfs_vnode_iterator for procfs_revoke_vnodes().


# 1.190 25-Jul-2014 dholland

Add VOP_FALLOCATE and VOP_FDISCARD to every vnode ops table I can
find.

The filesystem ones all call genfs_eopnotsupp - right now I am only
implementing the plumbing and we can implement fallocate and/or
fdiscard for files later.

The device ones call spec_fallocate (which is also genfs_eopnotsupp)
and spec_fdiscard, which dispatches to the device-level op.

The fifo ones all call vn_fifo_bypass, which also ends up being
EOPNOTSUPP.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base
# 1.189 07-Feb-2014 hannken

branches: 1.189.2;
Change vnode operation lookup to return the resulting vnode *vpp unlocked.
Change cache_lookup() to return an unlocked vnode.

Discussed on tech-kern@

Welcome to 6.99.31


# 1.188 23-Jan-2014 hannken

Change vnode operations create, mknod, mkdir and symlink to return
the resulting vnode *vpp unlocked.

Discussed on tech-kern@

Welcome to 6.99.30


# 1.187 17-Jan-2014 hannken

Change vnode operations create, mknod, mkdir and symlink to keep the
directory node dvp locked on return.

Discussed on tech-kern@

Welcome to 6.99.29


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base
# 1.186 18-Mar-2013 plunky

branches: 1.186.6;
C99 section 6.7.2.3 (Tags) Note 3 states that:

A type specifier of the form

enum identifier

without an enumerator list shall only appear after the type it
specifies is complete.

which means that we cannot pass an "enum vtype" argument to
kauth_access_action() without fully specifying the type first.
Unfortunately there is a complicated include file loop which
makes that difficult, so convert this minimal function into a
macro (and capitalize it).

(ok elad@)


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 1.185 25-Nov-2012 christos

do something reasonable with kernel semaphores.


Revision tags: yamt-pagecache-base6 jmcneill-usbmp-base10
# 1.184 28-May-2012 christos

branches: 1.184.2;
add a task process subdirectory for emul linux


Revision tags: yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 1.183 13-Mar-2012 elad

Replace the remaining KAUTH_GENERIC_ISSUSER authorization calls with
something meaningful. All relevant documentation has been updated or
written.

Most of these changes were brought up in the following messages:

http://mail-index.netbsd.org/tech-kern/2012/01/18/msg012490.html
http://mail-index.netbsd.org/tech-kern/2012/01/19/msg012502.html
http://mail-index.netbsd.org/tech-kern/2012/02/17/msg012728.html

Thanks to christos, manu, njoly, and jmmv for input.

Huge thanks to pgoyette for spinning these changes through some build
cycles and ATF.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.182 04-Sep-2011 jmcneill

branches: 1.182.2; 1.182.6;
PR# kern/45021: Please support /emul/linux/proc/version

Add /proc/version for procfs with -o linux. The version reported depends
on the emulation type of the calling process:

$ cat /proc/version
NetBSD version 5.99.55 (netbsd@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) NetBSD 5.99.55 (GENERIC) #39: Sun Sep 4 09:10:05 EDT 2011

$ /emul/linux/bin/cat /proc/version
Linux version 2.6.18 (linux@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) #0 Wed Mar 3 03:03:03 PST 2010

$ /emul/linux32/bin/cat /proc/version
Linux version 2.6.18 (linux32@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) #0 Wed Mar 3 03:03:03 PST 2010


# 1.181 23-Jun-2011 christos

From Aleksey Cheusov: Don't make it easy for compromised systems to bypass
ASLR protections by providing the mapping addresses of programs to everyone.


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base matt-mips64-premerge-20101231 uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10 rmind-uvmplock-base
# 1.180 01-Jul-2010 rmind

Remove pfind() and pgfind(), fix locking in various broken uses of these.
Rename real routines to proc_find() and pgrp_find(), remove PFIND_* flags
and have consistent behaviour. Provide proc_find_raw() for special cases.
Fix memory leak in sysctl_proc_corename().

COMPAT_LINUX: rework ptrace() locking, minimise differences between
different versions per-arch.

Note: while this change adds some formal cosmetics for COMPAT_DARWIN and
COMPAT_IRIX - locking there is utterly broken (for ages).

Fixes PR/43176.


# 1.179 24-Jun-2010 hannken

Clean up vnode lock operations pass 2:

VOP_UNLOCK(vp, flags) -> VOP_UNLOCK(vp): Remove the unneeded flags argument.

Welcome to 5.99.32.

Discussed on tech-kern.


# 1.178 08-Jun-2010 hannken

Procfs_lookup() does not lookup directory descriptors in the fd/
subdirectory. There is no need for recursive vnode locking here.

Ok: Christos Zoulas <christos@netbsd.org>


Revision tags: uebayasi-xip-base1 yamt-nfs-mp-base9 uebayasi-xip-base
# 1.177 08-Jan-2010 pooka

branches: 1.177.2; 1.177.4;
The VATTR_NULL/VREF/VHOLD/HOLDRELE() macros lost their will to live
years ago when the kernel was modified to not alter ABI based on
DIAGNOSTIC, and now just call the respective function interfaces
(in lowercase). Plenty of mix'n match upper/lowercase has creeped
into the tree since then. Nuke the macros and convert all callsites
to lowercase.

no functional change


Revision tags: matt-premerge-20091211 yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 jym-xensuspend-nbase
# 1.176 03-Jul-2009 elad

Where possible, extract the file-system's access() routine to two internal
functions: the first checking if the operation is possible (regardless of
permissions), the second checking file-system permissions, ACLs, etc.

Mailing list reference:

http://mail-index.netbsd.org/tech-kern/2009/06/21/msg005311.html


# 1.175 23-Jun-2009 elad

Move the implementation of vaccess() to genfs_can_access(), in line with
the other routines of the same spirit.

Adjust file-system code to use it.

Keep vaccess() for KPI compatibility and to keep element of least
surprise. A "diagnostic" message warning that vaccess() is deprecated will
be printed when it's used (obviously, only in DIAGNOSTIC kernels).

No objections on tech-kern@:

http://mail-index.netbsd.org/tech-kern/2009/06/21/msg005310.html


Revision tags: yamt-nfs-mp-base5
# 1.174 24-May-2009 ad

More changes to improve kern_descrip.c.

- Avoid atomics in more places.
- Remove the per-descriptor mutex, and just use filedesc_t::fd_lock.
It was only being used to synchronize close, and in any case we needed
to take fd_lock to free the descriptor slot.
- Optimize certain paths for the <NDFDFILE case.
- Sprinkle more comments and assertions.
- Cache more stuff in filedesc_t.
- Fix numerous minor bugs spotted along the way.
- Restructure how the open files array is maintained, for clarity and so
that we can eliminate the membar_consumer() call in fd_getfile(). This is
mostly syntactic sugar; the main functional change is that fd_nfiles now
lives alongside the open file array.

Some measurements with libmicro:

- simple file syscalls are like close() are between 1 to 10% faster.
- some nice improvements, e.g. poll(1000) which is ~50% faster.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 nick-hppapmap-base2 jym-xensuspend-base nick-hppapmap-base mjf-devfs2-base
# 1.173 17-Dec-2008 cegger

branches: 1.173.2;
kill MALLOC and FREE macros.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 haad-dm-base2 haad-nbase2 ad-audiomp2-base netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 haad-dm-base
# 1.172 05-Sep-2008 skrll

branches: 1.172.2;
PR/39324 kernel diagnostic assertion "l->l_stat != LSZOMB" failed.

Ignore procs with zero or all LSZOMB LWPs. Get a non-LSZOMB LWP to perform
operations against as part of the deal.

procfs really needs to be updated to support multi-threading fully.
Hi Antti!


# 1.171 05-Sep-2008 skrll

ANSIfy


Revision tags: simonb-wapbl-nbase simonb-wapbl-base
# 1.170 02-Jul-2008 rmind

branches: 1.170.2;
Remove proc_representative_lwp(), use a simple LIST_FIRST() instead.
OK by <ad>.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base
# 1.169 28-Apr-2008 martin

branches: 1.169.2; 1.169.4;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-nfs-mp-base
# 1.168 24-Apr-2008 ad

branches: 1.168.2;
Merge proc::p_mutex and proc::p_smutex into a single adaptive mutex, since
we no longer need to guard against access from hardware interrupt handlers.

Additionally, if cloning a process with CLONE_SIGHAND, arrange to have the
child process share the parent's lock so that signal state may be kept in
sync. Partially addresses PR kern/37437.


# 1.167 24-Apr-2008 ad

Network protocol interrupts can now block on locks, so merge the globals
proclist_mutex and proclist_lock into a single adaptive mutex (proc_lock).
Implications:

- Inspecting process state requires thread context, so signals can no longer
be sent from a hardware interrupt handler. Signal activity must be
deferred to a soft interrupt or kthread.

- As the proc state locking is simplified, it's now safe to take exit()
and wait() out from under kernel_lock.

- The system spends less time at IPL_SCHED, and there is less lock activity.


Revision tags: yamt-pf42-baseX yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14
# 1.166 21-Mar-2008 ad

branches: 1.166.2;
Catch up with descriptor handling changes. See kern_descrip.c revision
1.173 for details.


Revision tags: keiichi-mipv6-nbase nick-net80211-sync-base keiichi-mipv6-base bouyer-xeni386-nbase matt-armv6-nbase mjf-devfs-base hpcarm-cleanup-base
# 1.165 23-Jan-2008 elad

branches: 1.165.6;
Tons of process scope changes.

- Add a KAUTH_PROCESS_SCHEDULER action, to handle scheduler related
requests, and add specific requests for set/get scheduler policy and
set/get scheduler parameters.

- Add a KAUTH_PROCESS_KEVENT_FILTER action, to handle kevent(2) related
requests.

- Add a KAUTH_DEVICE_TTY_STI action to handle requests to TIOCSTI.

- Add requests for the KAUTH_PROCESS_CANSEE action, indicating what
process information is being looked at (entry itself, args, env,
open files).

- Add requests for the KAUTH_PROCESS_RLIMIT action indicating set/get.

- Add requests for the KAUTH_PROCESS_CORENAME action indicating set/get.

- Make bsd44 secmodel code handle the newly added rqeuests appropriately.

All of the above make it possible to issue finer-grained kauth(9) calls in
many places, removing some KAUTH_GENERIC_ISSUSER requests.

- Remove the "CAN" from KAUTH_PROCESS_CAN{KTRACE,PROCFS,PTRACE,SIGNAL}.

Discussed with christos@ and yamt@.


Revision tags: bouyer-xeni386-base matt-armv6-base
# 1.164 02-Jan-2008 ad

Merge vmlocking2 to head.


Revision tags: vmlocking2-base3 yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 vmlocking-nbase jmcneill-pm-base reinoud-bufcleanup-base
# 1.163 26-Nov-2007 pooka

branches: 1.163.2; 1.163.6;
Remove the "struct lwp *" argument from all VFS and VOP interfaces.
The general trend is to remove it from all kernel interfaces and
this is a start. In case the calling lwp is desired, curlwp should
be used.

quick consensus on tech-kern


Revision tags: bouyer-xenamd64-base2 bouyer-xenamd64-base
# 1.162 09-Nov-2007 christos

make the last argument of procfs_dir size_t


# 1.161 07-Nov-2007 ad

Merge from vmlocking:

- pool_cache changes.
- Debugger/procfs locking fixes.
- Other minor changes.


Revision tags: jmcneill-base yamt-x86pmap-base4 yamt-x86pmap-base3 vmlocking-base
# 1.160 10-Oct-2007 ad

branches: 1.160.2; 1.160.4;
Merge from vmlocking:

- Split vnode::v_flag into three fields, depending on field locking.
- simple_lock -> kmutex in a few places.
- Fix some simple locking problems.


# 1.159 08-Oct-2007 ad

Merge file descriptor locking, cwdi locking and cross-call changes
from the vmlocking branch.


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base2 yamt-x86pmap-base matt-mips64-base
# 1.158 22-Jul-2007 pooka

branches: 1.158.4; 1.158.6; 1.158.8; 1.158.10;
Don't allow getcwd() on procfs vnodes and provide "/" as the path
instead of the result from getcwd(). The works around locking
panics caused by namei calling VOP_READLINK while holding on to a
directory lock and getcwd() trying to acquire that lock. The real
fix would be to get rid of getcwd() calls within VOPs (not locking
safe), but that's not a viable option in the netbsd-4 timeframe.

Suggestion for workaround from David Holland.


Revision tags: nick-csl-alignment-base mjf-ufs-trans-base
# 1.157 24-May-2007 agc

branches: 1.157.2;
Extend the Linux emulation of /proc to include

/proc/stat
/proc/loadavg and
/proc/<pid>/statm.

These are only present when -o linux is specified as a mount option
to procfs.

Factor out some common code so that it can be used by a number of
functions.

XXX The values returned in the statm emulation need to be verified.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 1.156 04-Apr-2007 rmind

Unfortunately, missed procfs_proc_unlock() in previous.
Pointed out by pooka@


# 1.155 04-Apr-2007 rmind

procfs_readlink: Handle a possible fail of fd_getfile(), also, we
do not need to check for error again.
CID: 4436


# 1.154 09-Mar-2007 ad

branches: 1.154.2; 1.154.4;
- Make the proclist_lock a mutex. The write:read ratio is unfavourable,
and mutexes are cheaper use than RW locks.
- LOCK_ASSERT -> KASSERT in some places.
- Hold proclist_lock/kernel_lock longer in a couple of places.


# 1.153 04-Mar-2007 christos

Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.


# 1.152 03-Mar-2007 salo

Don't prepend rootvnode to the path in non-NULL case for exe links.
It breaks procfs in chroot.

from <christos>, tested by me.


Revision tags: ad-audiomp-base
# 1.151 19-Feb-2007 pooka

When checking for file validity under pid/, do proper proc->lwp
lookup (fsvo proper) instead of fiddling directly with the lwp
list.


# 1.150 18-Feb-2007 pooka

Don't check for validity of p in lookup for root nodes, since it
will always be NULL. Rather, just call pt_valid with NULL directly
and let it decide if we're a linux mount or not.


# 1.149 17-Feb-2007 pavel

Change the process/lwp flags seen by userland via sysctl back to the
P_*/L_* naming convention, and rename the in-kernel flags to avoid
conflict. (P_ -> PK_, L_ -> LW_ ). Add back the (now unused) LSDEAD
constant.

Restores source compatibility with pre-newlock2 tools like ps or top.

Reviewed by Andrew Doran.


# 1.148 16-Feb-2007 pooka

branches: 1.148.2;
In lookup, when checking for procfs process node validity, target the
process we're trying to get information about through procfs, not
the caller of lookup.

fixes 'ls -l /proc/*/file' panic, which would occur when trying to
lookup "file" for a kernel thread, which doesn't have p->p_textvp.


# 1.147 15-Feb-2007 ad

Need to acquire procp->p_mutex for procfs_dir().


# 1.146 11-Feb-2007 ad

Eliminate a couple of reference count and mutex leaks.


Revision tags: post-newlock2-merge
# 1.145 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 1.144 25-Dec-2006 elad

PR/35226: Johann Franz: Problems with permissions in
/usr/pkg/emul/linux/proc .

Okay mlelstv@


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3
# 1.143 09-Dec-2006 chs

a smorgasbord of improvements to vnode locking and path lookup:
- LOCKPARENT is no longer relevant for lookup(), relookup() or VOP_LOOKUP().
these now always return the parent vnode locked. namei() works as before.
lookup() and various other paths no longer acquire vnode locks in the
wrong order via vrele(). fixes PR 32535.
as a nice side effect, path lookup is also up to 25% faster.
- the above allows us to get rid of PDIRUNLOCK.
- also get rid of WANTPARENT (just use LOCKPARENT and unlock it).
- remove an assumption in layer_node_find() that all file systems implement
a recursive VOP_LOCK() (unionfs doesn't).
- require that all file systems supply vfs_vptofh and vfs_fhtovp routines.
fill in eopnotsupp() for file systems that don't support being exported
and remove the checks for NULL. (layerfs calls these without checking.)
- in union_lookup1(), don't change refcounts in the ISDOTDOT case, just
adjust which vnode is locked. fixes PR 33374.
- apply fixes for ufs_rename() from ufs_vnops.c rev. 1.61 to ext2fs_rename().


# 1.142 04-Dec-2006 christos

From Nicolas Joly: restore previous behavior in procfs_validfile_linux, since
readdir passes a NULL lwp.


# 1.141 03-Dec-2006 elad

Move kauth(9) call to where it belongs. Noticed by Nicolas Joly, thanks!


Revision tags: netbsd-4-base
# 1.140 28-Nov-2006 elad

branches: 1.140.2;
Move ktrace, ptrace, systrace, and procfs to use kauth(9).

First, remove process_checkioperm() calls from MD code. Similar checks
using kauth(9) routines (on the process scope, using appropriate action)
are done in the callers.

Add secmodel back-end to handle each subsystem.


# 1.139 25-Nov-2006 skrll

Expose the 'exe' symlink to the process realpath in NetBSD as well. An
example user is gdb.

OK'd by christos.


# 1.138 16-Nov-2006 christos

__unused removal on arguments; approved by core.


# 1.137 29-Oct-2006 christos

add an "emul" file node.


# 1.136 25-Oct-2006 christos

1. fix procfs_validfile{,_linux} to test for NULL pointers properly.
2. make "exe" entry be a symlink to the executable, instead of pointing
directly to the vnode of the executable.
3. factor out commonly used code.


Revision tags: yamt-splraiseipl-base2
# 1.135 12-Oct-2006 christos

- sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386


# 1.134 20-Sep-2006 manu

Emulate Linux's /proc/devices


Revision tags: abandoned-netbsd-4-base yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base rpaulo-netinet-merge-pcb-base
# 1.133 13-Jun-2006 yamt

branches: 1.133.6; 1.133.8;
use KAUTH_PROCESS_CANSEE rather than CURTAIN where appropriate.


# 1.132 13-Jun-2006 yamt

remove unnecessary arguments from kauth_authorize_process.
ie. make it similar to the one found in apple TN.


# 1.131 07-Jun-2006 kardel

merge FreeBSD timecounters from branch simonb-timecounters
- struct timeval time is gone
time.tv_sec -> time_second
- struct timeval mono_time is gone
mono_time.tv_sec -> time_uptime
- access to time via
{get,}{micro,nano,bin}time()
get* versions are fast but less precise
- support NTP nanokernel implementation (NTP API 4)
- further reading:
Timecounter Paper: http://phk.freebsd.dk/pubs/timecounter.pdf
NTP Nanokernel: http://www.eecis.udel.edu/~mills/ntp/html/kern.html


Revision tags: yamt-pdpolicy-base5 simonb-timecounters-base
# 1.130 14-May-2006 elad

branches: 1.130.2;
integrate kauth.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 elad-kernelauth-base yamt-pdpolicy-base yamt-uio_vmspace-base5
# 1.129 02-Feb-2006 christos

branches: 1.129.2; 1.129.4; 1.129.6; 1.129.8;
PR/32692: Matthew Mondor: linux compatibility in /proc/self should point
directly to the directory containing the pid instead of pointing to
/proc/curproc, because some programs rely on calling readlink on /proc/self
to get the pid.


# 1.128 11-Dec-2005 christos

branches: 1.128.2; 1.128.4;
merge ktrace-lwp.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base ktrace-lwp-base
# 1.127 02-Nov-2005 yamt

merge yamt-vop branch. remove following VOPs.

VOP_BLKATOFF
VOP_VALLOC
VOP_BALLOC
VOP_REALLOCBLKS
VOP_VFREE
VOP_TRUNCATE
VOP_UPDATE


Revision tags: yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 1.126 01-Oct-2005 atatat

branches: 1.126.2;
Add "cwd" and "root" symlinks to each process's directory. The cwd
link points to the process's current working directory, and the root
link points to the process's root directory. What else would you
expect?

For directories that are out of reach (caller is in a chroot, target
process is in a different chroot, etc), the links point to "/"
instead.


# 1.125 11-Sep-2005 elad

Implement curtain for procfs.


# 1.124 30-Aug-2005 xtraeme

Remove __P()


# 1.123 29-May-2005 christos

branches: 1.123.2;
- sprinkle const
- avoid shadowed variables.


Revision tags: kent-audio2-base
# 1.122 02-Apr-2005 christos

PR/29782: Martin Husemann: procfs can not unmount when some process has its
current directory in curproc. Fix from Pedro Martelletto:
We cannot call vgone() from procfs_inactive() if we are coming from
vclean(). that's what's probably causing the deadlock.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 yamt-km-base4 yamt-km-base3 netbsd-3-base
# 1.121 26-Feb-2005 perry

nuke trailing whitespace


Revision tags: yamt-km-base2 yamt-km-base kent-audio1-beforemerge kent-audio1-base
# 1.120 04-Oct-2004 yamt

branches: 1.120.4; 1.120.6;
procfs_readdir:
- return correct cookie when buffer size is small.
- simplify logic.


# 1.119 04-Oct-2004 yamt

procfs_readdir: remove a redundant assignment.


# 1.118 02-Oct-2004 yamt

procfs_getattr: correct size of /proc/self.


# 1.117 01-Oct-2004 yamt

procfs_readdir:
- fix a locking problem, using proclist_foreach_call. PR/27098.
- correct snprintf size argument.


# 1.116 01-Oct-2004 yamt

procfs_readdir: fix an offset handling bug after addition of /proc/self.


# 1.115 01-Oct-2004 yamt

procfs_readdir: use a list macro.


# 1.114 20-Sep-2004 jdolecek

add 'mounts' file for -o linux, which lists all currently mounted
filesystems; Linux glibc statvfs() uses this to get some of mount flags,
and this file is also useful as /emul/linux/etc/mtab (via symlink)


# 1.113 29-Apr-2004 jrf

Removed remaining caddr_t casts we do not need in miscfs. Recompiled
kernel and ran for a day or so. There are still some caddr_t types in
the arguments of some calls, I will do those separately (later) as
they touch a lot more of the system.
Approved by christos@NetBSD.org.


# 1.112 22-Apr-2004 itojun

sprintf -> snprintf


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.111 15-Feb-2004 jdolecek

unlock the descriptor table simple lock after fd_getfile() call in
procfs_readdir()
fixes procfs locking problems reported on current-users@, problem place
found by enami tsugutomo


# 1.110 30-Oct-2003 simonb

Remove some assigned-to but otherwise unused variables.


# 1.109 27-Sep-2003 darcy

Changes as discussed with itojun on tech-kern. I have modified the enums
to have KFS or PFS differentiators. Further I have wrapped the enum in
procfs in "#ifdef _KERNEL" as it is done in kernfs.

To see the discussion go to http://mail-index.NetBSD.org/tech-kern/2003/09/
and look for "Mismatched enums in include files" in the list.


# 1.108 07-Sep-2003 itojun

remove meaningless line (variable overwritten 2 lines below)


# 1.107 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.


# 1.106 29-Jun-2003 fvdl

branches: 1.106.2;
Back out the lwp/ktrace changes. They contained a lot of colateral damage,
and need to be examined and discussed more.


# 1.105 29-Jun-2003 thorpej

Undo part of the ktrace/lwp changes. In particular:
* Remove the "lwp *" argument that was added to vget(). Turns out
that nothing actually used it!
* Remove the "lwp *" arguments that were added to VFS_ROOT(), VFS_VGET(),
and VFS_FHTOVP(); all they did was pass it to vget() (which, as noted
above, didn't use it).
* Remove all of the "lwp *" arguments to internal functions that were added
just to appease the above.


# 1.104 28-Jun-2003 darrenr

Pass lwp pointers throughtout the kernel, as required, so that the lwpid can
be inserted into ktrace records. The general change has been to replace
"struct proc *" with "struct lwp *" in various function prototypes, pass
the lwp through and use l_proc to get the process pointer when needed.

Bump the kernel rev up to 1.6V


# 1.103 28-May-2003 christos

Add /proc/<pid>/stat for linux compat. j2sdk1.4.2 depends on it.


# 1.102 18-Apr-2003 christos

Make symlinks for directories that point to the actual directory.
Make symlinks to [kqueue] and [misc] for kqueue and misc fds.


# 1.101 17-Apr-2003 jdolecek

do not show nodes corresponding to directory descriptors for process
in fd/ subdirectory, nor allow lookup/open for the nodes
this fixes PR kern/21187 for good, and also avoids interesting directory
locking issues


# 1.100 17-Apr-2003 jdolecek

procfs_readdir(): in Pfd case, only show descriptors of types we want
how to represent (vnodes, fifo, pipes); also use fd_getfile() et al

this avoids annoying EOPNOTSUPP error messages from ls -F and such


# 1.99 17-Apr-2003 jdolecek

procfs_lookup(): use fd_getfile() et al in Pfd case


# 1.98 17-Apr-2003 jdolecek

use fd_getfile() in procfs_getfp(), and FILE_USE()/FILE_UNUSE() the
returned file descriptor pointer appropriately


# 1.97 17-Apr-2003 jdolecek

make some local arrays/variables static + const


# 1.96 10-Apr-2003 jdolecek

use former genfs_eopnotsupp_rele() as genfs_eopnotsupp(), so that vnodes
are vput()/vrele()d as necessary - some filesystems did use the wrong
one for some ops, and it's just safer to not take the chance

based on suggestion by Bill Studenmund


# 1.95 05-Apr-2003 dsl

Remove pointless check against PID_MAX. Let pfind() do the validation.
(The new pid allocation code may decide to allocate pids above PID_MAX.)


# 1.94 25-Feb-2003 jrf

This addresses PR kerm/19989. Thanks to hamajima@nagoya.ydc.co.jp for submitting this patch which enables /proc/uptime for linux emul. Patch reviewed by atatat@netbsd.org and tron@netbsd.org, approved by tron@netbsd.org.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 1.93 04-Jan-2003 martin

Cast off_t expression to long long to match format even on 64 bit
plattforms.

Shouldn't we introduce a PRIoff_t macro to create such format strings?


# 1.92 03-Jan-2003 christos

add LK_CANRECURSE in the locking of /dev/<pid>/fd/<n> and remove the curproc
kludge. Thanks to fvdl.


# 1.91 03-Jan-2003 christos

Implement /proc/<pid>/fd/<n>. This is work in progress. Questionable things:
- Is it ok to convert DTYPE_PIPE to VFIFO and DTYPE_SOCKET to VSOCK?
- XXX: Avoid locking issue in ls -Rl /proc by avoiding curproc
- Does I/O to pipes work?
- XXX: Are there security implications?


Revision tags: fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge gehenna-devsw-base kqueue-base
# 1.90 03-Aug-2002 simonb

Just use the "time" variable in the *_getattr functions instead of a call
to (the potentially expensive) microtime().


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.89 09-May-2002 thorpej

branches: 1.89.2;
Move code shared by procfs and the kernel proper out of procfs and
into the kernel proper (renaming functions from procfs_* to process_*).


Revision tags: eeh-devprop-base newlock-base ifpoll-base
# 1.88 12-Jan-2002 christos

Don't hide the real return code with EPERM.


# 1.87 06-Dec-2001 chs

add a VOP_PUTPAGES method for all the filesystems that don't have pages,
just unlock the interlock.


# 1.86 05-Dec-2001 thorpej

* Allow machine-dependent code to specify hooks for ptrace(2)
(__HAVE_PTRACE_MACHDEP) and procfs (__HAVE_PROCFS_MACHDEP).
These changes will allow platforms like x86 (XMM) and PowerPC
(AltiVec) to export extended register sets in a sane manner.

* Use __HAVE_PTRACE_MACHDEP to export x86 XMM registers (standard
FP + SSE/SSE2) using PT_{GET,SET}XMMREGS (in the machdep
ptrace request space).
* Use __HAVE_PROCFS_MACHDEP to export x86 XMM registers via
/proc/N/xmmregs in procfs.


Revision tags: thorpej-mips-cache-base
# 1.85 10-Nov-2001 lukem

add RCSIDs


# 1.84 06-Nov-2001 simonb

Remove some variables that are set but never used.


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base
# 1.83 31-Aug-2001 chs

branches: 1.83.2; 1.83.4;
map files are zero-length.


# 1.82 03-Jun-2001 chs

branches: 1.82.2;
procfs_bmap() should never be called, make it a "bad op".
let procfs_mmap() use the default error method.


Revision tags: thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 1.81 14-Apr-2001 kleink

In procfs_readdir(), give /proc/# directories DT_DIR (rather than DT_REG).


# 1.80 30-Mar-2001 fvdl

Bump va_blocksize for the map files some more, so that programs with
quite a few mappings have a chance of being handled correctly if
st_blksize is looked at.


# 1.79 29-Mar-2001 fvdl

For -o linux mounts, add some code to emulate /proc/#/maps.
Needs NAMECACHE_ENTER_REVERSE to include filenames.


# 1.78 21-Feb-2001 jdolecek

branches: 1.78.2;
make some more constant arrays 'const'


# 1.77 22-Jan-2001 jdolecek

make filesystem vnodeop, specop, fifoop and vnodeopv_* arrays const


# 1.76 17-Jan-2001 fvdl

Add a few linux-style files, only enabled when -o linux is specified
for the mount. Currently these are /proc/cpuinfo and /proc/meminfo.
The former only does something on i386 right now.


# 1.75 24-Nov-2000 chs

remove dead code and other misc cleanup.


# 1.74 09-Aug-2000 tv

Only show the "exe" entry to Linux processes, suggested by christos.
Since there are actually three struct emul's for linux, use the e_name
field to determine eligibility with strcmp().


# 1.73 09-Aug-2000 tv

Some versions of Linux libc look for /proc/.../exe instead of /proc/../file.
Add an entry for "exe" that is the same as "file", provided only if
COMPAT_LINUX is set.


# 1.72 03-Aug-2000 thorpej

MALLOC()/FREE() are not to be used for variable sized allocations.


# 1.71 28-Jun-2000 mrg

<vm/vm.h> -> <uvm/uvm_extern.h>


Revision tags: netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 1.70 30-Mar-2000 simonb

branches: 1.70.4;
Delete duplicate declaration of atopid().


Revision tags: chs-ubc2-newbase wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base fvdl-softdep-base
# 1.69 02-Sep-1999 thorpej

branches: 1.69.2; 1.69.8;
Make /proc/self a symlink to /proc/curproc. I've observed Linux programs
that expect /proc/self/cmdline to exist.


# 1.68 25-Aug-1999 sommerfeld

Change variable used for directory offset from "int" to "off_t".
Overkill, but avoids a host of truncation problems.


# 1.67 24-Aug-1999 sommerfeld

Fix PR8270:

Problem turned out to be due to improper handling of reads beyond EOF:
they should just return without error with the uio unchanged, and the
caller will recognize this as a zero-byte return (EOF).

The previous fix to protect directory reads against bogus uio_offset
values returned EINVAL, which broke mount -o union, which only
union'ed in the lower directory if the upper directory cleanly
returned EOF.

While we're here, protect kernfs as well.


# 1.66 14-Aug-1999 christos

protect against large uio_offset


# 1.65 03-Aug-1999 wrstuden

Add support for fcntl(2) to generate VOP_FCNTL calls. Any fcntl
call with F_FSCTL set and F_SETFL calls generate calls to a new
fileop fo_fcntl. Add genfs_fcntl() and soo_fcntl() which return 0
for F_SETFL and EOPNOTSUPP otherwise. Have all leaf filesystems
use genfs_fcntl().

Reviewed by: thorpej
Tested by: wrstuden


Revision tags: chs-ubc2-base
# 1.64 25-Jul-1999 thorpej

Add calls to lock the proclist as appropriate.


# 1.63 14-Jul-1999 thorpej

Fix a paste-o in procfs_lookup() introduced with the vnode locking changes.
Fixes PR #7961, Mario Kemper <magick@bundy.lip.owl.de>.


# 1.62 08-Jul-1999 wrstuden

Bump osrelease to 1.4E. Add layerfs files, remove null_subr.c.

Update coda to new struct lock in struct vnode.

make fdescfs, kernfs, portalfs, and procfs actually lock their vnodes.
It's not that hard.

Make unionfs set v_vnlock = NULL so any overlayed fs will call its
VOP_LOCK.


Revision tags: kame_141_19991130 netbsd-1-4-PATCH001 kame_14_19990705 kame_14_19990628 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.61 12-Mar-1999 christos

branches: 1.61.2; 1.61.4;
PR/7143: Jaromir Docelek: Add procfs/cmdline from Linux emulation


# 1.60 25-Jan-1999 msaitoh

Add /proc/#/map. From FreeBSD.


Revision tags: kenh-if-detach-base chs-ubc-base
# 1.59 08-Sep-1998 thorpej

- Use proclists[], rather than checking allproc and zombproc explicitly.
- Add some comments about locking.


# 1.58 13-Aug-1998 kleink

Per POSIX, fail with EINVAL if advisory locking is attempted on a file type
that doesn't support it, rather than using a homegrown EBADF or EOPNOTSUPP.


# 1.57 10-Aug-1998 matthias

create miscfs/genfs/genfs_vnops.c:genfs_enoioctl and make all the other
filesystems use it instead of a private version.


# 1.56 09-Aug-1998 perry

bzero->memset, bcopy->memcpy, bcmp->memcmp


# 1.55 03-Aug-1998 kleink

Recognize _PC_SYNC_IO.


Revision tags: eeh-paddr_t-base
# 1.54 21-Apr-1998 fvdl

procfs_readdir: in case of error, check if cookies actually have
been allocated before freeing them. From Wolfgang Solfrank.


# 1.53 01-Mar-1998 fvdl

Merge with Lite2 + local changes


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base marc-pcmcia-base
# 1.52 10-Oct-1997 fvdl

Bump last argument to VOP_READDIR to off_t (from u_long).


Revision tags: thorpej-signal-base
# 1.51 27-Aug-1997 thorpej

Fix a reversed argument which caused procfs_checkioperm() to always return
"OK". Add a few comments to avoid further confusion.


# 1.50 12-Aug-1997 thorpej

Fix the procfs hole described on current-users, similar to a fix for
FreeBSD by Sean Eric Fagan, but a bit different. This makes the checks
in the same places as sef's FreeBSD patch, but does not hardcode the
"kmem" group into the kernel, and also does a check identical to the
(3) and (4) checks in the NetBSD ptrace(2):

(1) it's not owned by you, or is set-id on exec (unless
you're root), or

(2) it's init, which controls the security level of the
entire system, and the system was not compiled with
permanently insecure mode turned on.


Revision tags: marc-pcmcia-bp
# 1.49 08-May-1997 mycroft

branches: 1.49.4;
Pass the vnode type to vaccess(), and use it when checking VEXEC. Make sure
that the mode bits passed to vaccess() and returned by foo_getattr() contain
only permission bits.


# 1.48 05-May-1997 mycroft

Need stat.h.


# 1.47 05-May-1997 mycroft

Eliminate bogus uses of V{READ,WRITE,EXEC}. Use S_I[RWX]{USR,GRP,OTH} where
appropriate.


# 1.46 28-Apr-1997 mycroft

Minor code cleanup.


Revision tags: is-newarp-before-merge is-newarp-base
# 1.45 25-Oct-1996 cgd

define path name string variables that we should not (and, thankfully, do
not) modify as 'const char *' rather 'char *'.


# 1.44 13-Oct-1996 christos

backout previous kprintf changes


# 1.43 10-Oct-1996 christos

printf -> kprintf, sprintf -> ksprintf


# 1.42 07-Sep-1996 mycroft

Implement poll(2).


# 1.41 01-Sep-1996 mycroft

Add a set of generic file system operations that most file systems use.
Also, fix some time stamp bogosities.


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 1.40 16-Mar-1996 christos

Fix printf format follies.


# 1.39 13-Feb-1996 mycroft

GC *_nullop(). Minor nits.


# 1.38 12-Feb-1996 christos

close PR/2063: procfs_rw prototyped twice with different prototypes


# 1.37 09-Feb-1996 christos

miscfs prototype changes


# 1.36 09-Feb-1996 mycroft

Fix vop_link, vop_symlink, and vop_remove semantics in several ways:
* Change the argument names to vop_link so they actually make sense.
* Implement vop_link and vop_symlink for all file systems, so they do proper
cleanup.
* Require the file system to decide whether or not linking and unlinking of
directories is allowed, and disable it for all current file systems.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.35 09-Oct-1995 mycroft

Use the index number as the cookie, rather than multiplying by UIO_MX.


# 1.34 09-Oct-1995 mycroft

Add support for cookies, mostly from Greg Hudson.


# 1.33 15-Apr-1995 cgd

fix timeval vs. timespec warnings


# 1.32 03-Feb-1995 mycroft

Return EROFS rather than ENOENT in many cases. Also some cosmetic cleanup.


# 1.31 27-Dec-1994 mycroft

Format police.


# 1.30 24-Dec-1994 ws

Implement and use a common access checking routine


# 1.29 14-Dec-1994 mycroft

Remove a_fp.


# 1.28 14-Nov-1994 christos

fixed struct comment


# 1.27 30-Oct-1994 cgd

be more careful with types, also pull in headers where necessary.


# 1.26 20-Oct-1994 cgd

update for new syscall args description mechanism


# 1.25 30-Aug-1994 mycroft

Convert process, file, and namei lists and hash tables to use queue.h.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.24 29-Jun-1994 cgd

New RCS ID's, take two. they're more aesthecially pleasant, and use 'NetBSD'


# 1.23 16-Jun-1994 mycroft

Remove an unneeded test.


# 1.22 15-Jun-1994 mycroft

Minor update from JSP after merging my changes.


# 1.21 08-Jun-1994 mycroft

Update to 4.4-Lite fs code, with local changes.


# 1.20 05-May-1994 cgd

lots of changes: prototype migration, move lots of variables, definitions,
and structure elements around. kill some unnecessary type and macro
definitions. standardize clock handling. More changes than you'd want.


# 1.19 15-Apr-1994 cgd

forgot these...


# 1.18 12-Apr-1994 cgd

be a bit smarter about determining if files shouldn't be seen by the user.
Also, DON'T allow a lookup to succeed on a file that's not visible!


# 1.17 15-Feb-1994 mycroft

Undo last change; executables is `file', not `a.out'.


# 1.16 14-Feb-1994 ws

Rename file -> a.out


# 1.15 14-Feb-1994 ws

Don't try to show a file for a process if there is none


# 1.14 28-Jan-1994 cgd

make a fpregs file.


# 1.13 20-Jan-1994 ws

Make procfs really work for debugging.
Implement not & notepg files in procfs.


# 1.12 09-Jan-1994 ws

Bug fixes and enhancements:
Make NFS serving work (BUT DON'T USE "attach" TO /proc/*/ctl FOR NOW!!!)
Make `curproc' a symbolic link
Add `.' and `..' entries to the directories.
Return better guesses on the size of the files.


# 1.11 05-Jan-1994 cgd

return size of 'reg' from getattr()


# 1.10 05-Jan-1994 cgd

make it compile (cleanly) for us


# 1.9 05-Jan-1994 cgd

add new procfs code, from Jan-Simon Pendry, jsp@sequent.com.
This is pretty-much "virgin", so that diffs can be done later.


# 1.8 18-Dec-1993 mycroft

Canonicalize all #includes.


Revision tags: magnum-base
# 1.7 16-Sep-1993 cgd

kill volatile warning.


# 1.6 07-Sep-1993 ws

branches: 1.6.2;
Changes to VFS readdir semantics
NFS changes for better cookie support
ISOFS changes for better Rockridge support and support for generation numbers


# 1.5 26-Aug-1993 pk

Implement setattr: mode for process entries; mode + uid/gid for the
PROCFS root directory.
Fixed omission in pfs_root() which came to light as a result of the above:
hold on to vnode for root dir.


# 1.4 25-Aug-1993 pk

Fixed improperly initialized nfsnode in pfs_lookup()


# 1.3 24-Aug-1993 pk

copyright update.


# 1.2 24-Aug-1993 pk

Rcs Id added.


# 1.1 24-Aug-1993 pk

branches: 1.1.1;
Initial version of a proc filesystem.


# 1.230 17-Jan-2024 hannken

Add a hashmap to access all procfs nodes by pid.


Revision tags: netbsd-10-0-RC3 netbsd-10-0-RC2 thorpej-ifq-base thorpej-altq-separation-base netbsd-10-0-RC1 netbsd-10-base bouyer-sunxi-drm-base
# 1.229 17-Jun-2022 shm

Add missing permission check


# 1.228 27-Mar-2022 christos

dedup the eofs link/symlink methods


# 1.227 17-Jan-2022 bouyer

If the calling process is running under linux emulation, make /proc/xxx/fd/
return only symlinks pointing to the original file in the filesystem,
instead of a hard link. This matches the linux behavior, and some
linux programs relies on it (they unconditionally call readlink() on
/proc/xxx/fd/yy and don't deal with it returning EINVAL).
Proposed on tech-kern@ in
http://mail-index.netbsd.org/tech-kern/2022/01/11/msg027877.html


# 1.226 14-Jan-2022 christos

Fix emul and exe DT_ types (from RVP, as was the previous commit)


# 1.225 14-Jan-2022 christos

Put the appropriate DT_ constant in the dirent structure depending on the
file type.


# 1.224 11-Jan-2022 christos

remove redundant error initialization and break earlier. (from rvp)


# 1.223 11-Jan-2022 hannken

Use a single "p" variable.

Should fix PR kern/56614: kernel panic on tmux


# 1.222 10-Jan-2022 christos

use a single nc variable.


# 1.221 10-Jan-2022 christos

Fix locking in the error path (from RVP). Centralize unlock code.


# 1.220 08-Dec-2021 andvar

s/efficent/efficient/ in comments.


# 1.219 05-Oct-2021 christos

PR/53299: RVP: kernfs and procfs are broken when sysctl security.curtain
is enabled


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base thorpej-i2c-spi-conf-base
# 1.218 18-Jul-2021 dholland

Abolish all the silly indirection macros for initializing vnode ops tables.

These are things of the form #define foofs_op genfs_op, or #define
foofs_op genfs_eopnotsupp, or similar. They serve no purpose besides
obfuscation, and have gotten cutpasted all over everywhere.


# 1.217 29-Jun-2021 dholland

- Add a new vnode op: VOP_PARSEPATH.
- Move namei_getcomponent to genfs_vnops.c and call it genfs_parsepath.
- Add a parsepath entry to every vnode ops table.

VOP_PARSEPATH takes a directory vnode to be searched and a complete
following path and chooses how much of that path to consume. To begin
with, all parsepath calls are genfs_parsepath, which locates the first
'/' as always.

Note that the call doesn't take the whole struct componentname, only
the string. The other bits of struct componentname should not be
needed and there's no reason to cause potential complications by
exposing them.


# 1.216 28-Jun-2021 chs

VOP_BMAP() may be called via ioctl(FIOGETBMAP) on any vnode that applications
can open. change various pseudo-fs *_bmap methods return an error instead of
panic.

Reported-by: syzbot+8289a3eaf2ba60958c87@syzkaller.appspotmail.com


Revision tags: cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base thorpej-cfargs-base thorpej-futex-base
# 1.215 27-Jun-2020 christos

branches: 1.215.6;
Introduce genfs_pathconf() and use it for the default case in all filesystems.


# 1.214 23-May-2020 ad

Move proc_lock into the data segment. It was dynamically allocated because
at the time we had mutex_obj_alloc() but not __cacheline_aligned.


# 1.213 16-May-2020 christos

Add ACL support for FFS. From FreeBSD.


# 1.212 29-Apr-2020 thorpej

If the procfs mount is marked as linux-compat, then allow proc lookup
by any LWP ID in the proc, not just the canonical PID.


Revision tags: bouyer-xenpvh-base2
# 1.211 21-Apr-2020 ad

Revert the changes made in February to make cwdinfo use mostly lockless,
which relied on taking extra vnode refs.

Having benchmarked various experimental changes over the past few months it
seems that it's better to avoid vnode refs as much as possible. cwdi_lock
as a RW lock already did that to some extent for getcwd() and will permit
the same for namei() too.


Revision tags: phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base is-mlppp-base phil-wifi-20200406 ad-namecache-base3
# 1.210 24-Feb-2020 ad

branches: 1.210.4;
v_interlock -> vmobjlock


# 1.209 23-Feb-2020 ad

Merge from ad-namecache:

- Have a stab at clustering the members of vnode_t and vnode_impl_t in a
more cache-conscious way. With that done, go back to adjusting v_usecount
with atomics and keep vi_lock directly in vnode_impl_t (saves KVA).

- Allow VOP_LOCK(LK_NONE) for the benefit of VFS_VGET() and VFS_ROOT().
Make sure LK_UPGRADE always comes with LK_NOWAIT.

- Make cwdinfo use mostly lockless.


# 1.208 01-Feb-2020 riastradh

Load struct filedesc::fd_dt with atomic_load_consume.

Exceptions: when fd_refcnt <= 1, or when holding fd_lock.

While here:

- Restore KASSERT(mutex_owned(&fdp->fd_lock)) in fd_unused.
=> This is used only in fd_close and fd_abort, where it holds.
- Move bounds check assertion in fd_putfile to where it matters.
- Store fd_dt with atomic_store_release.
- Move load of fd_dt under lock in knote_fdclose.
- Omit membar_consumer in fdesc_readdir.
=> atomic_load_consume serves the same purpose now.
=> Was needed only on alpha anyway.


Revision tags: ad-namecache-base2 ad-namecache-base1 ad-namecache-base phil-wifi-20191119
# 1.207 29-Aug-2019 hannken

branches: 1.207.2;
Add missing operation VOP_GETPAGES() returning EFAULT.

Without this operation posix_fadvise(..., POSIX_FADV_WILLNEED)
would leave the v_interlock held.

Observed by maxv@


Revision tags: netbsd-9-base phil-wifi-20190609 isaki-audio2-base
# 1.206 30-Mar-2019 christos

branches: 1.206.4;
add a node for the process resource limits.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020
# 1.205 14-Oct-2018 jdolecek

remove M_CANFAIL flag for malloc(9) - it was completely ignored, so had
actually no effect


Revision tags: pgoyette-compat-0930 pgoyette-compat-0906
# 1.204 03-Sep-2018 riastradh

Rename min/max -> uimin/uimax for better honesty.

These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER! Some subsystems have

#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)


Revision tags: pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415
# 1.203 07-Apr-2018 hannken

branches: 1.203.2;
Lock the target cwdi and take an additional reference to the
vnode we are interested in to prevent it from disappearing
before getcwd_common().

Should fix PR kern/53096 (netbsd-8 crash on heavy disk I/O)


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.202 31-Dec-2017 christos

branches: 1.202.2;
Add an environ node


Revision tags: tls-maxphys-base-20171202
# 1.201 01-Dec-2017 christos

Allow procfs_kqfilter, since we allow poll. "go" does it.


# 1.200 08-Nov-2017 christos

fix locking, remove error(1) comments.


# 1.199 08-Nov-2017 christos

use p->p_path, remove unused code.


# 1.198 28-Aug-2017 kamil

Remove the filesystem tracing feature

This is a legacy interface from 4.4BSD, and it was
introduced to overcome shortcomings of ptrace(2) at that time, which are
no longer relevant (performance). Today /proc/#/ctl offers a narrow
subset of ptrace(2) commands and is not applicable for modern
applications use beyond simplistic tracing scenarios.

This removal will simplify kernel internals. Users will still be able to
use all the other /proc files.

This change won't affect other procfs files neither Linux compat
features within mount_procfs(8). /proc/#/ctl isn't available on Linux.

Remove:
- /proc/#/ctl from mount_procfs(8)
- P_FSTRACE note from the documentation of ps(1)
- /proc/#/ctl and filesystem tracing documentation from mount_procfs(8)
- KAUTH_REQ_PROCESS_PROCFS_CTL documentation from kauth(9)
- source code file miscfs/procfs/procfs_ctl.c
- PFSctl and procfs_doctl() from sys/miscfs/procfs/procfs.h
- KAUTH_REQ_PROCESS_PROCFS_CTL from sys/sys/kauth.h
- PSL_FSTRACE (0x00010000) from sys/sys/proc.h
- P_FSTRACE (0x00010000) from sys/sys/sysctl.h

Reduce code complexity after removal of this functionality.

Update TODO.ptrace accordingly: remove two entries about /proc tracing.

Do not keep legacy notes as comments in the headers about removed
PSL_FSTRACE / P_FSTRACE, as this interface had little number of users
(close or equal to zero).

Proposed on tech-kern@.

All filesystem tracing utility users are encouraged to switch to ptrace(2).

Sponsored by <The NetBSD Foundation>


Revision tags: matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base
# 1.197 26-May-2017 riastradh

branches: 1.197.2;
Make VOP_RECLAIM do the last unlock of the vnode.

VOP_RECLAIM naturally has exclusive access to the vnode, so having it
locked on entry is not strictly necessary -- but it means if there
are any final operations that must be done on the vnode, such as
ffs_update, requiring exclusive access to it, we can now kassert that
the vnode is locked in those operations.

We can't just have the caller release the last lock because some file
systems don't use genfs_lock, and require the vnode to remain valid
for VOP_UNLOCK to work, notably unionfs.


Revision tags: prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.196 11-Apr-2017 riastradh

Make VOP_INACTIVE preserve vnode lock on return.

Discussed on tech-kern:
https://mail-index.netbsd.org/tech-kern/2017/04/01/msg021751.html

Ride 7.99.68, a bumpy bus of incremental vfs improvements!


Revision tags: jdolecek-ncq-base
# 1.195 30-Mar-2017 christos

add an auxv node.


Revision tags: pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004 localcount-20160914
# 1.194 20-Aug-2016 hannken

branches: 1.194.2;
Remove now obsolete operation vcache_remove().

Welcome to 7.99.36


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 nick-nhusb-base-20150921 nick-nhusb-base-20150606
# 1.193 20-Apr-2015 riastradh

branches: 1.193.2;
Make VOP_LINK return directory still locked and referenced.

Ride 7.99.10 bump.


Revision tags: nick-nhusb-base-20150406 nick-nhusb-base
# 1.192 05-Sep-2014 matt

branches: 1.192.2;
Try not to use f_data, use f_{vnode,socket,pipe,mqueue,kqueue,ksem} to get
a correctly typed pointer.


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.191 27-Jul-2014 hannken

branches: 1.191.2; 1.191.4; 1.191.8;
Change procfs from hashlist to vcache.
- Key is (type, pid, fd)
- Remove argument "p" from procfs_allocvp(). It is only used
when "type == PFSfd". Lookup the proc with proc_find() when
procfs_loadvnode() needs it.
- Use a vfs_vnode_iterator for procfs_revoke_vnodes().


# 1.190 25-Jul-2014 dholland

Add VOP_FALLOCATE and VOP_FDISCARD to every vnode ops table I can
find.

The filesystem ones all call genfs_eopnotsupp - right now I am only
implementing the plumbing and we can implement fallocate and/or
fdiscard for files later.

The device ones call spec_fallocate (which is also genfs_eopnotsupp)
and spec_fdiscard, which dispatches to the device-level op.

The fifo ones all call vn_fifo_bypass, which also ends up being
EOPNOTSUPP.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base
# 1.189 07-Feb-2014 hannken

branches: 1.189.2;
Change vnode operation lookup to return the resulting vnode *vpp unlocked.
Change cache_lookup() to return an unlocked vnode.

Discussed on tech-kern@

Welcome to 6.99.31


# 1.188 23-Jan-2014 hannken

Change vnode operations create, mknod, mkdir and symlink to return
the resulting vnode *vpp unlocked.

Discussed on tech-kern@

Welcome to 6.99.30


# 1.187 17-Jan-2014 hannken

Change vnode operations create, mknod, mkdir and symlink to keep the
directory node dvp locked on return.

Discussed on tech-kern@

Welcome to 6.99.29


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base
# 1.186 18-Mar-2013 plunky

branches: 1.186.6;
C99 section 6.7.2.3 (Tags) Note 3 states that:

A type specifier of the form

enum identifier

without an enumerator list shall only appear after the type it
specifies is complete.

which means that we cannot pass an "enum vtype" argument to
kauth_access_action() without fully specifying the type first.
Unfortunately there is a complicated include file loop which
makes that difficult, so convert this minimal function into a
macro (and capitalize it).

(ok elad@)


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 1.185 25-Nov-2012 christos

do something reasonable with kernel semaphores.


Revision tags: yamt-pagecache-base6 jmcneill-usbmp-base10
# 1.184 28-May-2012 christos

branches: 1.184.2;
add a task process subdirectory for emul linux


Revision tags: yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 1.183 13-Mar-2012 elad

Replace the remaining KAUTH_GENERIC_ISSUSER authorization calls with
something meaningful. All relevant documentation has been updated or
written.

Most of these changes were brought up in the following messages:

http://mail-index.netbsd.org/tech-kern/2012/01/18/msg012490.html
http://mail-index.netbsd.org/tech-kern/2012/01/19/msg012502.html
http://mail-index.netbsd.org/tech-kern/2012/02/17/msg012728.html

Thanks to christos, manu, njoly, and jmmv for input.

Huge thanks to pgoyette for spinning these changes through some build
cycles and ATF.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.182 04-Sep-2011 jmcneill

branches: 1.182.2; 1.182.6;
PR# kern/45021: Please support /emul/linux/proc/version

Add /proc/version for procfs with -o linux. The version reported depends
on the emulation type of the calling process:

$ cat /proc/version
NetBSD version 5.99.55 (netbsd@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) NetBSD 5.99.55 (GENERIC) #39: Sun Sep 4 09:10:05 EDT 2011

$ /emul/linux/bin/cat /proc/version
Linux version 2.6.18 (linux@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) #0 Wed Mar 3 03:03:03 PST 2010

$ /emul/linux32/bin/cat /proc/version
Linux version 2.6.18 (linux32@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) #0 Wed Mar 3 03:03:03 PST 2010


# 1.181 23-Jun-2011 christos

From Aleksey Cheusov: Don't make it easy for compromised systems to bypass
ASLR protections by providing the mapping addresses of programs to everyone.


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base matt-mips64-premerge-20101231 uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10 rmind-uvmplock-base
# 1.180 01-Jul-2010 rmind

Remove pfind() and pgfind(), fix locking in various broken uses of these.
Rename real routines to proc_find() and pgrp_find(), remove PFIND_* flags
and have consistent behaviour. Provide proc_find_raw() for special cases.
Fix memory leak in sysctl_proc_corename().

COMPAT_LINUX: rework ptrace() locking, minimise differences between
different versions per-arch.

Note: while this change adds some formal cosmetics for COMPAT_DARWIN and
COMPAT_IRIX - locking there is utterly broken (for ages).

Fixes PR/43176.


# 1.179 24-Jun-2010 hannken

Clean up vnode lock operations pass 2:

VOP_UNLOCK(vp, flags) -> VOP_UNLOCK(vp): Remove the unneeded flags argument.

Welcome to 5.99.32.

Discussed on tech-kern.


# 1.178 08-Jun-2010 hannken

Procfs_lookup() does not lookup directory descriptors in the fd/
subdirectory. There is no need for recursive vnode locking here.

Ok: Christos Zoulas <christos@netbsd.org>


Revision tags: uebayasi-xip-base1 yamt-nfs-mp-base9 uebayasi-xip-base
# 1.177 08-Jan-2010 pooka

branches: 1.177.2; 1.177.4;
The VATTR_NULL/VREF/VHOLD/HOLDRELE() macros lost their will to live
years ago when the kernel was modified to not alter ABI based on
DIAGNOSTIC, and now just call the respective function interfaces
(in lowercase). Plenty of mix'n match upper/lowercase has creeped
into the tree since then. Nuke the macros and convert all callsites
to lowercase.

no functional change


Revision tags: matt-premerge-20091211 yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 jym-xensuspend-nbase
# 1.176 03-Jul-2009 elad

Where possible, extract the file-system's access() routine to two internal
functions: the first checking if the operation is possible (regardless of
permissions), the second checking file-system permissions, ACLs, etc.

Mailing list reference:

http://mail-index.netbsd.org/tech-kern/2009/06/21/msg005311.html


# 1.175 23-Jun-2009 elad

Move the implementation of vaccess() to genfs_can_access(), in line with
the other routines of the same spirit.

Adjust file-system code to use it.

Keep vaccess() for KPI compatibility and to keep element of least
surprise. A "diagnostic" message warning that vaccess() is deprecated will
be printed when it's used (obviously, only in DIAGNOSTIC kernels).

No objections on tech-kern@:

http://mail-index.netbsd.org/tech-kern/2009/06/21/msg005310.html


Revision tags: yamt-nfs-mp-base5
# 1.174 24-May-2009 ad

More changes to improve kern_descrip.c.

- Avoid atomics in more places.
- Remove the per-descriptor mutex, and just use filedesc_t::fd_lock.
It was only being used to synchronize close, and in any case we needed
to take fd_lock to free the descriptor slot.
- Optimize certain paths for the <NDFDFILE case.
- Sprinkle more comments and assertions.
- Cache more stuff in filedesc_t.
- Fix numerous minor bugs spotted along the way.
- Restructure how the open files array is maintained, for clarity and so
that we can eliminate the membar_consumer() call in fd_getfile(). This is
mostly syntactic sugar; the main functional change is that fd_nfiles now
lives alongside the open file array.

Some measurements with libmicro:

- simple file syscalls are like close() are between 1 to 10% faster.
- some nice improvements, e.g. poll(1000) which is ~50% faster.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 nick-hppapmap-base2 jym-xensuspend-base nick-hppapmap-base mjf-devfs2-base
# 1.173 17-Dec-2008 cegger

branches: 1.173.2;
kill MALLOC and FREE macros.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 haad-dm-base2 haad-nbase2 ad-audiomp2-base netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 haad-dm-base
# 1.172 05-Sep-2008 skrll

branches: 1.172.2;
PR/39324 kernel diagnostic assertion "l->l_stat != LSZOMB" failed.

Ignore procs with zero or all LSZOMB LWPs. Get a non-LSZOMB LWP to perform
operations against as part of the deal.

procfs really needs to be updated to support multi-threading fully.
Hi Antti!


# 1.171 05-Sep-2008 skrll

ANSIfy


Revision tags: simonb-wapbl-nbase simonb-wapbl-base
# 1.170 02-Jul-2008 rmind

branches: 1.170.2;
Remove proc_representative_lwp(), use a simple LIST_FIRST() instead.
OK by <ad>.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base
# 1.169 28-Apr-2008 martin

branches: 1.169.2; 1.169.4;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-nfs-mp-base
# 1.168 24-Apr-2008 ad

branches: 1.168.2;
Merge proc::p_mutex and proc::p_smutex into a single adaptive mutex, since
we no longer need to guard against access from hardware interrupt handlers.

Additionally, if cloning a process with CLONE_SIGHAND, arrange to have the
child process share the parent's lock so that signal state may be kept in
sync. Partially addresses PR kern/37437.


# 1.167 24-Apr-2008 ad

Network protocol interrupts can now block on locks, so merge the globals
proclist_mutex and proclist_lock into a single adaptive mutex (proc_lock).
Implications:

- Inspecting process state requires thread context, so signals can no longer
be sent from a hardware interrupt handler. Signal activity must be
deferred to a soft interrupt or kthread.

- As the proc state locking is simplified, it's now safe to take exit()
and wait() out from under kernel_lock.

- The system spends less time at IPL_SCHED, and there is less lock activity.


Revision tags: yamt-pf42-baseX yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14
# 1.166 21-Mar-2008 ad

branches: 1.166.2;
Catch up with descriptor handling changes. See kern_descrip.c revision
1.173 for details.


Revision tags: keiichi-mipv6-nbase nick-net80211-sync-base keiichi-mipv6-base bouyer-xeni386-nbase matt-armv6-nbase mjf-devfs-base hpcarm-cleanup-base
# 1.165 23-Jan-2008 elad

branches: 1.165.6;
Tons of process scope changes.

- Add a KAUTH_PROCESS_SCHEDULER action, to handle scheduler related
requests, and add specific requests for set/get scheduler policy and
set/get scheduler parameters.

- Add a KAUTH_PROCESS_KEVENT_FILTER action, to handle kevent(2) related
requests.

- Add a KAUTH_DEVICE_TTY_STI action to handle requests to TIOCSTI.

- Add requests for the KAUTH_PROCESS_CANSEE action, indicating what
process information is being looked at (entry itself, args, env,
open files).

- Add requests for the KAUTH_PROCESS_RLIMIT action indicating set/get.

- Add requests for the KAUTH_PROCESS_CORENAME action indicating set/get.

- Make bsd44 secmodel code handle the newly added rqeuests appropriately.

All of the above make it possible to issue finer-grained kauth(9) calls in
many places, removing some KAUTH_GENERIC_ISSUSER requests.

- Remove the "CAN" from KAUTH_PROCESS_CAN{KTRACE,PROCFS,PTRACE,SIGNAL}.

Discussed with christos@ and yamt@.


Revision tags: bouyer-xeni386-base matt-armv6-base
# 1.164 02-Jan-2008 ad

Merge vmlocking2 to head.


Revision tags: vmlocking2-base3 yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 vmlocking-nbase jmcneill-pm-base reinoud-bufcleanup-base
# 1.163 26-Nov-2007 pooka

branches: 1.163.2; 1.163.6;
Remove the "struct lwp *" argument from all VFS and VOP interfaces.
The general trend is to remove it from all kernel interfaces and
this is a start. In case the calling lwp is desired, curlwp should
be used.

quick consensus on tech-kern


Revision tags: bouyer-xenamd64-base2 bouyer-xenamd64-base
# 1.162 09-Nov-2007 christos

make the last argument of procfs_dir size_t


# 1.161 07-Nov-2007 ad

Merge from vmlocking:

- pool_cache changes.
- Debugger/procfs locking fixes.
- Other minor changes.


Revision tags: jmcneill-base yamt-x86pmap-base4 yamt-x86pmap-base3 vmlocking-base
# 1.160 10-Oct-2007 ad

branches: 1.160.2; 1.160.4;
Merge from vmlocking:

- Split vnode::v_flag into three fields, depending on field locking.
- simple_lock -> kmutex in a few places.
- Fix some simple locking problems.


# 1.159 08-Oct-2007 ad

Merge file descriptor locking, cwdi locking and cross-call changes
from the vmlocking branch.


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base2 yamt-x86pmap-base matt-mips64-base
# 1.158 22-Jul-2007 pooka

branches: 1.158.4; 1.158.6; 1.158.8; 1.158.10;
Don't allow getcwd() on procfs vnodes and provide "/" as the path
instead of the result from getcwd(). The works around locking
panics caused by namei calling VOP_READLINK while holding on to a
directory lock and getcwd() trying to acquire that lock. The real
fix would be to get rid of getcwd() calls within VOPs (not locking
safe), but that's not a viable option in the netbsd-4 timeframe.

Suggestion for workaround from David Holland.


Revision tags: nick-csl-alignment-base mjf-ufs-trans-base
# 1.157 24-May-2007 agc

branches: 1.157.2;
Extend the Linux emulation of /proc to include

/proc/stat
/proc/loadavg and
/proc/<pid>/statm.

These are only present when -o linux is specified as a mount option
to procfs.

Factor out some common code so that it can be used by a number of
functions.

XXX The values returned in the statm emulation need to be verified.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 1.156 04-Apr-2007 rmind

Unfortunately, missed procfs_proc_unlock() in previous.
Pointed out by pooka@


# 1.155 04-Apr-2007 rmind

procfs_readlink: Handle a possible fail of fd_getfile(), also, we
do not need to check for error again.
CID: 4436


# 1.154 09-Mar-2007 ad

branches: 1.154.2; 1.154.4;
- Make the proclist_lock a mutex. The write:read ratio is unfavourable,
and mutexes are cheaper use than RW locks.
- LOCK_ASSERT -> KASSERT in some places.
- Hold proclist_lock/kernel_lock longer in a couple of places.


# 1.153 04-Mar-2007 christos

Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.


# 1.152 03-Mar-2007 salo

Don't prepend rootvnode to the path in non-NULL case for exe links.
It breaks procfs in chroot.

from <christos>, tested by me.


Revision tags: ad-audiomp-base
# 1.151 19-Feb-2007 pooka

When checking for file validity under pid/, do proper proc->lwp
lookup (fsvo proper) instead of fiddling directly with the lwp
list.


# 1.150 18-Feb-2007 pooka

Don't check for validity of p in lookup for root nodes, since it
will always be NULL. Rather, just call pt_valid with NULL directly
and let it decide if we're a linux mount or not.


# 1.149 17-Feb-2007 pavel

Change the process/lwp flags seen by userland via sysctl back to the
P_*/L_* naming convention, and rename the in-kernel flags to avoid
conflict. (P_ -> PK_, L_ -> LW_ ). Add back the (now unused) LSDEAD
constant.

Restores source compatibility with pre-newlock2 tools like ps or top.

Reviewed by Andrew Doran.


# 1.148 16-Feb-2007 pooka

branches: 1.148.2;
In lookup, when checking for procfs process node validity, target the
process we're trying to get information about through procfs, not
the caller of lookup.

fixes 'ls -l /proc/*/file' panic, which would occur when trying to
lookup "file" for a kernel thread, which doesn't have p->p_textvp.


# 1.147 15-Feb-2007 ad

Need to acquire procp->p_mutex for procfs_dir().


# 1.146 11-Feb-2007 ad

Eliminate a couple of reference count and mutex leaks.


Revision tags: post-newlock2-merge
# 1.145 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 1.144 25-Dec-2006 elad

PR/35226: Johann Franz: Problems with permissions in
/usr/pkg/emul/linux/proc .

Okay mlelstv@


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3
# 1.143 09-Dec-2006 chs

a smorgasbord of improvements to vnode locking and path lookup:
- LOCKPARENT is no longer relevant for lookup(), relookup() or VOP_LOOKUP().
these now always return the parent vnode locked. namei() works as before.
lookup() and various other paths no longer acquire vnode locks in the
wrong order via vrele(). fixes PR 32535.
as a nice side effect, path lookup is also up to 25% faster.
- the above allows us to get rid of PDIRUNLOCK.
- also get rid of WANTPARENT (just use LOCKPARENT and unlock it).
- remove an assumption in layer_node_find() that all file systems implement
a recursive VOP_LOCK() (unionfs doesn't).
- require that all file systems supply vfs_vptofh and vfs_fhtovp routines.
fill in eopnotsupp() for file systems that don't support being exported
and remove the checks for NULL. (layerfs calls these without checking.)
- in union_lookup1(), don't change refcounts in the ISDOTDOT case, just
adjust which vnode is locked. fixes PR 33374.
- apply fixes for ufs_rename() from ufs_vnops.c rev. 1.61 to ext2fs_rename().


# 1.142 04-Dec-2006 christos

From Nicolas Joly: restore previous behavior in procfs_validfile_linux, since
readdir passes a NULL lwp.


# 1.141 03-Dec-2006 elad

Move kauth(9) call to where it belongs. Noticed by Nicolas Joly, thanks!


Revision tags: netbsd-4-base
# 1.140 28-Nov-2006 elad

branches: 1.140.2;
Move ktrace, ptrace, systrace, and procfs to use kauth(9).

First, remove process_checkioperm() calls from MD code. Similar checks
using kauth(9) routines (on the process scope, using appropriate action)
are done in the callers.

Add secmodel back-end to handle each subsystem.


# 1.139 25-Nov-2006 skrll

Expose the 'exe' symlink to the process realpath in NetBSD as well. An
example user is gdb.

OK'd by christos.


# 1.138 16-Nov-2006 christos

__unused removal on arguments; approved by core.


# 1.137 29-Oct-2006 christos

add an "emul" file node.


# 1.136 25-Oct-2006 christos

1. fix procfs_validfile{,_linux} to test for NULL pointers properly.
2. make "exe" entry be a symlink to the executable, instead of pointing
directly to the vnode of the executable.
3. factor out commonly used code.


Revision tags: yamt-splraiseipl-base2
# 1.135 12-Oct-2006 christos

- sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386


# 1.134 20-Sep-2006 manu

Emulate Linux's /proc/devices


Revision tags: abandoned-netbsd-4-base yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base rpaulo-netinet-merge-pcb-base
# 1.133 13-Jun-2006 yamt

branches: 1.133.6; 1.133.8;
use KAUTH_PROCESS_CANSEE rather than CURTAIN where appropriate.


# 1.132 13-Jun-2006 yamt

remove unnecessary arguments from kauth_authorize_process.
ie. make it similar to the one found in apple TN.


# 1.131 07-Jun-2006 kardel

merge FreeBSD timecounters from branch simonb-timecounters
- struct timeval time is gone
time.tv_sec -> time_second
- struct timeval mono_time is gone
mono_time.tv_sec -> time_uptime
- access to time via
{get,}{micro,nano,bin}time()
get* versions are fast but less precise
- support NTP nanokernel implementation (NTP API 4)
- further reading:
Timecounter Paper: http://phk.freebsd.dk/pubs/timecounter.pdf
NTP Nanokernel: http://www.eecis.udel.edu/~mills/ntp/html/kern.html


Revision tags: yamt-pdpolicy-base5 simonb-timecounters-base
# 1.130 14-May-2006 elad

branches: 1.130.2;
integrate kauth.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 elad-kernelauth-base yamt-pdpolicy-base yamt-uio_vmspace-base5
# 1.129 02-Feb-2006 christos

branches: 1.129.2; 1.129.4; 1.129.6; 1.129.8;
PR/32692: Matthew Mondor: linux compatibility in /proc/self should point
directly to the directory containing the pid instead of pointing to
/proc/curproc, because some programs rely on calling readlink on /proc/self
to get the pid.


# 1.128 11-Dec-2005 christos

branches: 1.128.2; 1.128.4;
merge ktrace-lwp.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base ktrace-lwp-base
# 1.127 02-Nov-2005 yamt

merge yamt-vop branch. remove following VOPs.

VOP_BLKATOFF
VOP_VALLOC
VOP_BALLOC
VOP_REALLOCBLKS
VOP_VFREE
VOP_TRUNCATE
VOP_UPDATE


Revision tags: yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 1.126 01-Oct-2005 atatat

branches: 1.126.2;
Add "cwd" and "root" symlinks to each process's directory. The cwd
link points to the process's current working directory, and the root
link points to the process's root directory. What else would you
expect?

For directories that are out of reach (caller is in a chroot, target
process is in a different chroot, etc), the links point to "/"
instead.


# 1.125 11-Sep-2005 elad

Implement curtain for procfs.


# 1.124 30-Aug-2005 xtraeme

Remove __P()


# 1.123 29-May-2005 christos

branches: 1.123.2;
- sprinkle const
- avoid shadowed variables.


Revision tags: kent-audio2-base
# 1.122 02-Apr-2005 christos

PR/29782: Martin Husemann: procfs can not unmount when some process has its
current directory in curproc. Fix from Pedro Martelletto:
We cannot call vgone() from procfs_inactive() if we are coming from
vclean(). that's what's probably causing the deadlock.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 yamt-km-base4 yamt-km-base3 netbsd-3-base
# 1.121 26-Feb-2005 perry

nuke trailing whitespace


Revision tags: yamt-km-base2 yamt-km-base kent-audio1-beforemerge kent-audio1-base
# 1.120 04-Oct-2004 yamt

branches: 1.120.4; 1.120.6;
procfs_readdir:
- return correct cookie when buffer size is small.
- simplify logic.


# 1.119 04-Oct-2004 yamt

procfs_readdir: remove a redundant assignment.


# 1.118 02-Oct-2004 yamt

procfs_getattr: correct size of /proc/self.


# 1.117 01-Oct-2004 yamt

procfs_readdir:
- fix a locking problem, using proclist_foreach_call. PR/27098.
- correct snprintf size argument.


# 1.116 01-Oct-2004 yamt

procfs_readdir: fix an offset handling bug after addition of /proc/self.


# 1.115 01-Oct-2004 yamt

procfs_readdir: use a list macro.


# 1.114 20-Sep-2004 jdolecek

add 'mounts' file for -o linux, which lists all currently mounted
filesystems; Linux glibc statvfs() uses this to get some of mount flags,
and this file is also useful as /emul/linux/etc/mtab (via symlink)


# 1.113 29-Apr-2004 jrf

Removed remaining caddr_t casts we do not need in miscfs. Recompiled
kernel and ran for a day or so. There are still some caddr_t types in
the arguments of some calls, I will do those separately (later) as
they touch a lot more of the system.
Approved by christos@NetBSD.org.


# 1.112 22-Apr-2004 itojun

sprintf -> snprintf


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.111 15-Feb-2004 jdolecek

unlock the descriptor table simple lock after fd_getfile() call in
procfs_readdir()
fixes procfs locking problems reported on current-users@, problem place
found by enami tsugutomo


# 1.110 30-Oct-2003 simonb

Remove some assigned-to but otherwise unused variables.


# 1.109 27-Sep-2003 darcy

Changes as discussed with itojun on tech-kern. I have modified the enums
to have KFS or PFS differentiators. Further I have wrapped the enum in
procfs in "#ifdef _KERNEL" as it is done in kernfs.

To see the discussion go to http://mail-index.NetBSD.org/tech-kern/2003/09/
and look for "Mismatched enums in include files" in the list.


# 1.108 07-Sep-2003 itojun

remove meaningless line (variable overwritten 2 lines below)


# 1.107 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.


# 1.106 29-Jun-2003 fvdl

branches: 1.106.2;
Back out the lwp/ktrace changes. They contained a lot of colateral damage,
and need to be examined and discussed more.


# 1.105 29-Jun-2003 thorpej

Undo part of the ktrace/lwp changes. In particular:
* Remove the "lwp *" argument that was added to vget(). Turns out
that nothing actually used it!
* Remove the "lwp *" arguments that were added to VFS_ROOT(), VFS_VGET(),
and VFS_FHTOVP(); all they did was pass it to vget() (which, as noted
above, didn't use it).
* Remove all of the "lwp *" arguments to internal functions that were added
just to appease the above.


# 1.104 28-Jun-2003 darrenr

Pass lwp pointers throughtout the kernel, as required, so that the lwpid can
be inserted into ktrace records. The general change has been to replace
"struct proc *" with "struct lwp *" in various function prototypes, pass
the lwp through and use l_proc to get the process pointer when needed.

Bump the kernel rev up to 1.6V


# 1.103 28-May-2003 christos

Add /proc/<pid>/stat for linux compat. j2sdk1.4.2 depends on it.


# 1.102 18-Apr-2003 christos

Make symlinks for directories that point to the actual directory.
Make symlinks to [kqueue] and [misc] for kqueue and misc fds.


# 1.101 17-Apr-2003 jdolecek

do not show nodes corresponding to directory descriptors for process
in fd/ subdirectory, nor allow lookup/open for the nodes
this fixes PR kern/21187 for good, and also avoids interesting directory
locking issues


# 1.100 17-Apr-2003 jdolecek

procfs_readdir(): in Pfd case, only show descriptors of types we want
how to represent (vnodes, fifo, pipes); also use fd_getfile() et al

this avoids annoying EOPNOTSUPP error messages from ls -F and such


# 1.99 17-Apr-2003 jdolecek

procfs_lookup(): use fd_getfile() et al in Pfd case


# 1.98 17-Apr-2003 jdolecek

use fd_getfile() in procfs_getfp(), and FILE_USE()/FILE_UNUSE() the
returned file descriptor pointer appropriately


# 1.97 17-Apr-2003 jdolecek

make some local arrays/variables static + const


# 1.96 10-Apr-2003 jdolecek

use former genfs_eopnotsupp_rele() as genfs_eopnotsupp(), so that vnodes
are vput()/vrele()d as necessary - some filesystems did use the wrong
one for some ops, and it's just safer to not take the chance

based on suggestion by Bill Studenmund


# 1.95 05-Apr-2003 dsl

Remove pointless check against PID_MAX. Let pfind() do the validation.
(The new pid allocation code may decide to allocate pids above PID_MAX.)


# 1.94 25-Feb-2003 jrf

This addresses PR kerm/19989. Thanks to hamajima@nagoya.ydc.co.jp for submitting this patch which enables /proc/uptime for linux emul. Patch reviewed by atatat@netbsd.org and tron@netbsd.org, approved by tron@netbsd.org.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 1.93 04-Jan-2003 martin

Cast off_t expression to long long to match format even on 64 bit
plattforms.

Shouldn't we introduce a PRIoff_t macro to create such format strings?


# 1.92 03-Jan-2003 christos

add LK_CANRECURSE in the locking of /dev/<pid>/fd/<n> and remove the curproc
kludge. Thanks to fvdl.


# 1.91 03-Jan-2003 christos

Implement /proc/<pid>/fd/<n>. This is work in progress. Questionable things:
- Is it ok to convert DTYPE_PIPE to VFIFO and DTYPE_SOCKET to VSOCK?
- XXX: Avoid locking issue in ls -Rl /proc by avoiding curproc
- Does I/O to pipes work?
- XXX: Are there security implications?


Revision tags: fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge gehenna-devsw-base kqueue-base
# 1.90 03-Aug-2002 simonb

Just use the "time" variable in the *_getattr functions instead of a call
to (the potentially expensive) microtime().


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.89 09-May-2002 thorpej

branches: 1.89.2;
Move code shared by procfs and the kernel proper out of procfs and
into the kernel proper (renaming functions from procfs_* to process_*).


Revision tags: eeh-devprop-base newlock-base ifpoll-base
# 1.88 12-Jan-2002 christos

Don't hide the real return code with EPERM.


# 1.87 06-Dec-2001 chs

add a VOP_PUTPAGES method for all the filesystems that don't have pages,
just unlock the interlock.


# 1.86 05-Dec-2001 thorpej

* Allow machine-dependent code to specify hooks for ptrace(2)
(__HAVE_PTRACE_MACHDEP) and procfs (__HAVE_PROCFS_MACHDEP).
These changes will allow platforms like x86 (XMM) and PowerPC
(AltiVec) to export extended register sets in a sane manner.

* Use __HAVE_PTRACE_MACHDEP to export x86 XMM registers (standard
FP + SSE/SSE2) using PT_{GET,SET}XMMREGS (in the machdep
ptrace request space).
* Use __HAVE_PROCFS_MACHDEP to export x86 XMM registers via
/proc/N/xmmregs in procfs.


Revision tags: thorpej-mips-cache-base
# 1.85 10-Nov-2001 lukem

add RCSIDs


# 1.84 06-Nov-2001 simonb

Remove some variables that are set but never used.


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base
# 1.83 31-Aug-2001 chs

branches: 1.83.2; 1.83.4;
map files are zero-length.


# 1.82 03-Jun-2001 chs

branches: 1.82.2;
procfs_bmap() should never be called, make it a "bad op".
let procfs_mmap() use the default error method.


Revision tags: thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 1.81 14-Apr-2001 kleink

In procfs_readdir(), give /proc/# directories DT_DIR (rather than DT_REG).


# 1.80 30-Mar-2001 fvdl

Bump va_blocksize for the map files some more, so that programs with
quite a few mappings have a chance of being handled correctly if
st_blksize is looked at.


# 1.79 29-Mar-2001 fvdl

For -o linux mounts, add some code to emulate /proc/#/maps.
Needs NAMECACHE_ENTER_REVERSE to include filenames.


# 1.78 21-Feb-2001 jdolecek

branches: 1.78.2;
make some more constant arrays 'const'


# 1.77 22-Jan-2001 jdolecek

make filesystem vnodeop, specop, fifoop and vnodeopv_* arrays const


# 1.76 17-Jan-2001 fvdl

Add a few linux-style files, only enabled when -o linux is specified
for the mount. Currently these are /proc/cpuinfo and /proc/meminfo.
The former only does something on i386 right now.


# 1.75 24-Nov-2000 chs

remove dead code and other misc cleanup.


# 1.74 09-Aug-2000 tv

Only show the "exe" entry to Linux processes, suggested by christos.
Since there are actually three struct emul's for linux, use the e_name
field to determine eligibility with strcmp().


# 1.73 09-Aug-2000 tv

Some versions of Linux libc look for /proc/.../exe instead of /proc/../file.
Add an entry for "exe" that is the same as "file", provided only if
COMPAT_LINUX is set.


# 1.72 03-Aug-2000 thorpej

MALLOC()/FREE() are not to be used for variable sized allocations.


# 1.71 28-Jun-2000 mrg

<vm/vm.h> -> <uvm/uvm_extern.h>


Revision tags: netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 1.70 30-Mar-2000 simonb

branches: 1.70.4;
Delete duplicate declaration of atopid().


Revision tags: chs-ubc2-newbase wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base fvdl-softdep-base
# 1.69 02-Sep-1999 thorpej

branches: 1.69.2; 1.69.8;
Make /proc/self a symlink to /proc/curproc. I've observed Linux programs
that expect /proc/self/cmdline to exist.


# 1.68 25-Aug-1999 sommerfeld

Change variable used for directory offset from "int" to "off_t".
Overkill, but avoids a host of truncation problems.


# 1.67 24-Aug-1999 sommerfeld

Fix PR8270:

Problem turned out to be due to improper handling of reads beyond EOF:
they should just return without error with the uio unchanged, and the
caller will recognize this as a zero-byte return (EOF).

The previous fix to protect directory reads against bogus uio_offset
values returned EINVAL, which broke mount -o union, which only
union'ed in the lower directory if the upper directory cleanly
returned EOF.

While we're here, protect kernfs as well.


# 1.66 14-Aug-1999 christos

protect against large uio_offset


# 1.65 03-Aug-1999 wrstuden

Add support for fcntl(2) to generate VOP_FCNTL calls. Any fcntl
call with F_FSCTL set and F_SETFL calls generate calls to a new
fileop fo_fcntl. Add genfs_fcntl() and soo_fcntl() which return 0
for F_SETFL and EOPNOTSUPP otherwise. Have all leaf filesystems
use genfs_fcntl().

Reviewed by: thorpej
Tested by: wrstuden


Revision tags: chs-ubc2-base
# 1.64 25-Jul-1999 thorpej

Add calls to lock the proclist as appropriate.


# 1.63 14-Jul-1999 thorpej

Fix a paste-o in procfs_lookup() introduced with the vnode locking changes.
Fixes PR #7961, Mario Kemper <magick@bundy.lip.owl.de>.


# 1.62 08-Jul-1999 wrstuden

Bump osrelease to 1.4E. Add layerfs files, remove null_subr.c.

Update coda to new struct lock in struct vnode.

make fdescfs, kernfs, portalfs, and procfs actually lock their vnodes.
It's not that hard.

Make unionfs set v_vnlock = NULL so any overlayed fs will call its
VOP_LOCK.


Revision tags: kame_141_19991130 netbsd-1-4-PATCH001 kame_14_19990705 kame_14_19990628 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.61 12-Mar-1999 christos

branches: 1.61.2; 1.61.4;
PR/7143: Jaromir Docelek: Add procfs/cmdline from Linux emulation


# 1.60 25-Jan-1999 msaitoh

Add /proc/#/map. From FreeBSD.


Revision tags: kenh-if-detach-base chs-ubc-base
# 1.59 08-Sep-1998 thorpej

- Use proclists[], rather than checking allproc and zombproc explicitly.
- Add some comments about locking.


# 1.58 13-Aug-1998 kleink

Per POSIX, fail with EINVAL if advisory locking is attempted on a file type
that doesn't support it, rather than using a homegrown EBADF or EOPNOTSUPP.


# 1.57 10-Aug-1998 matthias

create miscfs/genfs/genfs_vnops.c:genfs_enoioctl and make all the other
filesystems use it instead of a private version.


# 1.56 09-Aug-1998 perry

bzero->memset, bcopy->memcpy, bcmp->memcmp


# 1.55 03-Aug-1998 kleink

Recognize _PC_SYNC_IO.


Revision tags: eeh-paddr_t-base
# 1.54 21-Apr-1998 fvdl

procfs_readdir: in case of error, check if cookies actually have
been allocated before freeing them. From Wolfgang Solfrank.


# 1.53 01-Mar-1998 fvdl

Merge with Lite2 + local changes


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base marc-pcmcia-base
# 1.52 10-Oct-1997 fvdl

Bump last argument to VOP_READDIR to off_t (from u_long).


Revision tags: thorpej-signal-base
# 1.51 27-Aug-1997 thorpej

Fix a reversed argument which caused procfs_checkioperm() to always return
"OK". Add a few comments to avoid further confusion.


# 1.50 12-Aug-1997 thorpej

Fix the procfs hole described on current-users, similar to a fix for
FreeBSD by Sean Eric Fagan, but a bit different. This makes the checks
in the same places as sef's FreeBSD patch, but does not hardcode the
"kmem" group into the kernel, and also does a check identical to the
(3) and (4) checks in the NetBSD ptrace(2):

(1) it's not owned by you, or is set-id on exec (unless
you're root), or

(2) it's init, which controls the security level of the
entire system, and the system was not compiled with
permanently insecure mode turned on.


Revision tags: marc-pcmcia-bp
# 1.49 08-May-1997 mycroft

branches: 1.49.4;
Pass the vnode type to vaccess(), and use it when checking VEXEC. Make sure
that the mode bits passed to vaccess() and returned by foo_getattr() contain
only permission bits.


# 1.48 05-May-1997 mycroft

Need stat.h.


# 1.47 05-May-1997 mycroft

Eliminate bogus uses of V{READ,WRITE,EXEC}. Use S_I[RWX]{USR,GRP,OTH} where
appropriate.


# 1.46 28-Apr-1997 mycroft

Minor code cleanup.


Revision tags: is-newarp-before-merge is-newarp-base
# 1.45 25-Oct-1996 cgd

define path name string variables that we should not (and, thankfully, do
not) modify as 'const char *' rather 'char *'.


# 1.44 13-Oct-1996 christos

backout previous kprintf changes


# 1.43 10-Oct-1996 christos

printf -> kprintf, sprintf -> ksprintf


# 1.42 07-Sep-1996 mycroft

Implement poll(2).


# 1.41 01-Sep-1996 mycroft

Add a set of generic file system operations that most file systems use.
Also, fix some time stamp bogosities.


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 1.40 16-Mar-1996 christos

Fix printf format follies.


# 1.39 13-Feb-1996 mycroft

GC *_nullop(). Minor nits.


# 1.38 12-Feb-1996 christos

close PR/2063: procfs_rw prototyped twice with different prototypes


# 1.37 09-Feb-1996 christos

miscfs prototype changes


# 1.36 09-Feb-1996 mycroft

Fix vop_link, vop_symlink, and vop_remove semantics in several ways:
* Change the argument names to vop_link so they actually make sense.
* Implement vop_link and vop_symlink for all file systems, so they do proper
cleanup.
* Require the file system to decide whether or not linking and unlinking of
directories is allowed, and disable it for all current file systems.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.35 09-Oct-1995 mycroft

Use the index number as the cookie, rather than multiplying by UIO_MX.


# 1.34 09-Oct-1995 mycroft

Add support for cookies, mostly from Greg Hudson.


# 1.33 15-Apr-1995 cgd

fix timeval vs. timespec warnings


# 1.32 03-Feb-1995 mycroft

Return EROFS rather than ENOENT in many cases. Also some cosmetic cleanup.


# 1.31 27-Dec-1994 mycroft

Format police.


# 1.30 24-Dec-1994 ws

Implement and use a common access checking routine


# 1.29 14-Dec-1994 mycroft

Remove a_fp.


# 1.28 14-Nov-1994 christos

fixed struct comment


# 1.27 30-Oct-1994 cgd

be more careful with types, also pull in headers where necessary.


# 1.26 20-Oct-1994 cgd

update for new syscall args description mechanism


# 1.25 30-Aug-1994 mycroft

Convert process, file, and namei lists and hash tables to use queue.h.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.24 29-Jun-1994 cgd

New RCS ID's, take two. they're more aesthecially pleasant, and use 'NetBSD'


# 1.23 16-Jun-1994 mycroft

Remove an unneeded test.


# 1.22 15-Jun-1994 mycroft

Minor update from JSP after merging my changes.


# 1.21 08-Jun-1994 mycroft

Update to 4.4-Lite fs code, with local changes.


# 1.20 05-May-1994 cgd

lots of changes: prototype migration, move lots of variables, definitions,
and structure elements around. kill some unnecessary type and macro
definitions. standardize clock handling. More changes than you'd want.


# 1.19 15-Apr-1994 cgd

forgot these...


# 1.18 12-Apr-1994 cgd

be a bit smarter about determining if files shouldn't be seen by the user.
Also, DON'T allow a lookup to succeed on a file that's not visible!


# 1.17 15-Feb-1994 mycroft

Undo last change; executables is `file', not `a.out'.


# 1.16 14-Feb-1994 ws

Rename file -> a.out


# 1.15 14-Feb-1994 ws

Don't try to show a file for a process if there is none


# 1.14 28-Jan-1994 cgd

make a fpregs file.


# 1.13 20-Jan-1994 ws

Make procfs really work for debugging.
Implement not & notepg files in procfs.


# 1.12 09-Jan-1994 ws

Bug fixes and enhancements:
Make NFS serving work (BUT DON'T USE "attach" TO /proc/*/ctl FOR NOW!!!)
Make `curproc' a symbolic link
Add `.' and `..' entries to the directories.
Return better guesses on the size of the files.


# 1.11 05-Jan-1994 cgd

return size of 'reg' from getattr()


# 1.10 05-Jan-1994 cgd

make it compile (cleanly) for us


# 1.9 05-Jan-1994 cgd

add new procfs code, from Jan-Simon Pendry, jsp@sequent.com.
This is pretty-much "virgin", so that diffs can be done later.


# 1.8 18-Dec-1993 mycroft

Canonicalize all #includes.


Revision tags: magnum-base
# 1.7 16-Sep-1993 cgd

kill volatile warning.


# 1.6 07-Sep-1993 ws

branches: 1.6.2;
Changes to VFS readdir semantics
NFS changes for better cookie support
ISOFS changes for better Rockridge support and support for generation numbers


# 1.5 26-Aug-1993 pk

Implement setattr: mode for process entries; mode + uid/gid for the
PROCFS root directory.
Fixed omission in pfs_root() which came to light as a result of the above:
hold on to vnode for root dir.


# 1.4 25-Aug-1993 pk

Fixed improperly initialized nfsnode in pfs_lookup()


# 1.3 24-Aug-1993 pk

copyright update.


# 1.2 24-Aug-1993 pk

Rcs Id added.


# 1.1 24-Aug-1993 pk

branches: 1.1.1;
Initial version of a proc filesystem.


# 1.229 17-Jun-2022 shm

Add missing permission check


# 1.228 27-Mar-2022 christos

dedup the eofs link/symlink methods


# 1.227 17-Jan-2022 bouyer

If the calling process is running under linux emulation, make /proc/xxx/fd/
return only symlinks pointing to the original file in the filesystem,
instead of a hard link. This matches the linux behavior, and some
linux programs relies on it (they unconditionally call readlink() on
/proc/xxx/fd/yy and don't deal with it returning EINVAL).
Proposed on tech-kern@ in
http://mail-index.netbsd.org/tech-kern/2022/01/11/msg027877.html


# 1.226 14-Jan-2022 christos

Fix emul and exe DT_ types (from RVP, as was the previous commit)


# 1.225 14-Jan-2022 christos

Put the appropriate DT_ constant in the dirent structure depending on the
file type.


# 1.224 11-Jan-2022 christos

remove redundant error initialization and break earlier. (from rvp)


# 1.223 11-Jan-2022 hannken

Use a single "p" variable.

Should fix PR kern/56614: kernel panic on tmux


# 1.222 10-Jan-2022 christos

use a single nc variable.


# 1.221 10-Jan-2022 christos

Fix locking in the error path (from RVP). Centralize unlock code.


# 1.220 08-Dec-2021 andvar

s/efficent/efficient/ in comments.


# 1.219 05-Oct-2021 christos

PR/53299: RVP: kernfs and procfs are broken when sysctl security.curtain
is enabled


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base thorpej-i2c-spi-conf-base
# 1.218 18-Jul-2021 dholland

Abolish all the silly indirection macros for initializing vnode ops tables.

These are things of the form #define foofs_op genfs_op, or #define
foofs_op genfs_eopnotsupp, or similar. They serve no purpose besides
obfuscation, and have gotten cutpasted all over everywhere.


# 1.217 29-Jun-2021 dholland

- Add a new vnode op: VOP_PARSEPATH.
- Move namei_getcomponent to genfs_vnops.c and call it genfs_parsepath.
- Add a parsepath entry to every vnode ops table.

VOP_PARSEPATH takes a directory vnode to be searched and a complete
following path and chooses how much of that path to consume. To begin
with, all parsepath calls are genfs_parsepath, which locates the first
'/' as always.

Note that the call doesn't take the whole struct componentname, only
the string. The other bits of struct componentname should not be
needed and there's no reason to cause potential complications by
exposing them.


# 1.216 28-Jun-2021 chs

VOP_BMAP() may be called via ioctl(FIOGETBMAP) on any vnode that applications
can open. change various pseudo-fs *_bmap methods return an error instead of
panic.

Reported-by: syzbot+8289a3eaf2ba60958c87@syzkaller.appspotmail.com


Revision tags: cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base thorpej-cfargs-base thorpej-futex-base
# 1.215 27-Jun-2020 christos

branches: 1.215.6;
Introduce genfs_pathconf() and use it for the default case in all filesystems.


# 1.214 23-May-2020 ad

Move proc_lock into the data segment. It was dynamically allocated because
at the time we had mutex_obj_alloc() but not __cacheline_aligned.


# 1.213 16-May-2020 christos

Add ACL support for FFS. From FreeBSD.


# 1.212 29-Apr-2020 thorpej

If the procfs mount is marked as linux-compat, then allow proc lookup
by any LWP ID in the proc, not just the canonical PID.


Revision tags: bouyer-xenpvh-base2
# 1.211 21-Apr-2020 ad

Revert the changes made in February to make cwdinfo use mostly lockless,
which relied on taking extra vnode refs.

Having benchmarked various experimental changes over the past few months it
seems that it's better to avoid vnode refs as much as possible. cwdi_lock
as a RW lock already did that to some extent for getcwd() and will permit
the same for namei() too.


Revision tags: phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base is-mlppp-base phil-wifi-20200406 ad-namecache-base3
# 1.210 24-Feb-2020 ad

branches: 1.210.4;
v_interlock -> vmobjlock


# 1.209 23-Feb-2020 ad

Merge from ad-namecache:

- Have a stab at clustering the members of vnode_t and vnode_impl_t in a
more cache-conscious way. With that done, go back to adjusting v_usecount
with atomics and keep vi_lock directly in vnode_impl_t (saves KVA).

- Allow VOP_LOCK(LK_NONE) for the benefit of VFS_VGET() and VFS_ROOT().
Make sure LK_UPGRADE always comes with LK_NOWAIT.

- Make cwdinfo use mostly lockless.


# 1.208 01-Feb-2020 riastradh

Load struct filedesc::fd_dt with atomic_load_consume.

Exceptions: when fd_refcnt <= 1, or when holding fd_lock.

While here:

- Restore KASSERT(mutex_owned(&fdp->fd_lock)) in fd_unused.
=> This is used only in fd_close and fd_abort, where it holds.
- Move bounds check assertion in fd_putfile to where it matters.
- Store fd_dt with atomic_store_release.
- Move load of fd_dt under lock in knote_fdclose.
- Omit membar_consumer in fdesc_readdir.
=> atomic_load_consume serves the same purpose now.
=> Was needed only on alpha anyway.


Revision tags: ad-namecache-base2 ad-namecache-base1 ad-namecache-base phil-wifi-20191119
# 1.207 29-Aug-2019 hannken

branches: 1.207.2;
Add missing operation VOP_GETPAGES() returning EFAULT.

Without this operation posix_fadvise(..., POSIX_FADV_WILLNEED)
would leave the v_interlock held.

Observed by maxv@


Revision tags: netbsd-9-base phil-wifi-20190609 isaki-audio2-base
# 1.206 30-Mar-2019 christos

branches: 1.206.4;
add a node for the process resource limits.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020
# 1.205 14-Oct-2018 jdolecek

remove M_CANFAIL flag for malloc(9) - it was completely ignored, so had
actually no effect


Revision tags: pgoyette-compat-0930 pgoyette-compat-0906
# 1.204 03-Sep-2018 riastradh

Rename min/max -> uimin/uimax for better honesty.

These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER! Some subsystems have

#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)


Revision tags: pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415
# 1.203 07-Apr-2018 hannken

branches: 1.203.2;
Lock the target cwdi and take an additional reference to the
vnode we are interested in to prevent it from disappearing
before getcwd_common().

Should fix PR kern/53096 (netbsd-8 crash on heavy disk I/O)


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.202 31-Dec-2017 christos

branches: 1.202.2;
Add an environ node


Revision tags: tls-maxphys-base-20171202
# 1.201 01-Dec-2017 christos

Allow procfs_kqfilter, since we allow poll. "go" does it.


# 1.200 08-Nov-2017 christos

fix locking, remove error(1) comments.


# 1.199 08-Nov-2017 christos

use p->p_path, remove unused code.


# 1.198 28-Aug-2017 kamil

Remove the filesystem tracing feature

This is a legacy interface from 4.4BSD, and it was
introduced to overcome shortcomings of ptrace(2) at that time, which are
no longer relevant (performance). Today /proc/#/ctl offers a narrow
subset of ptrace(2) commands and is not applicable for modern
applications use beyond simplistic tracing scenarios.

This removal will simplify kernel internals. Users will still be able to
use all the other /proc files.

This change won't affect other procfs files neither Linux compat
features within mount_procfs(8). /proc/#/ctl isn't available on Linux.

Remove:
- /proc/#/ctl from mount_procfs(8)
- P_FSTRACE note from the documentation of ps(1)
- /proc/#/ctl and filesystem tracing documentation from mount_procfs(8)
- KAUTH_REQ_PROCESS_PROCFS_CTL documentation from kauth(9)
- source code file miscfs/procfs/procfs_ctl.c
- PFSctl and procfs_doctl() from sys/miscfs/procfs/procfs.h
- KAUTH_REQ_PROCESS_PROCFS_CTL from sys/sys/kauth.h
- PSL_FSTRACE (0x00010000) from sys/sys/proc.h
- P_FSTRACE (0x00010000) from sys/sys/sysctl.h

Reduce code complexity after removal of this functionality.

Update TODO.ptrace accordingly: remove two entries about /proc tracing.

Do not keep legacy notes as comments in the headers about removed
PSL_FSTRACE / P_FSTRACE, as this interface had little number of users
(close or equal to zero).

Proposed on tech-kern@.

All filesystem tracing utility users are encouraged to switch to ptrace(2).

Sponsored by <The NetBSD Foundation>


Revision tags: matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base
# 1.197 26-May-2017 riastradh

branches: 1.197.2;
Make VOP_RECLAIM do the last unlock of the vnode.

VOP_RECLAIM naturally has exclusive access to the vnode, so having it
locked on entry is not strictly necessary -- but it means if there
are any final operations that must be done on the vnode, such as
ffs_update, requiring exclusive access to it, we can now kassert that
the vnode is locked in those operations.

We can't just have the caller release the last lock because some file
systems don't use genfs_lock, and require the vnode to remain valid
for VOP_UNLOCK to work, notably unionfs.


Revision tags: prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.196 11-Apr-2017 riastradh

Make VOP_INACTIVE preserve vnode lock on return.

Discussed on tech-kern:
https://mail-index.netbsd.org/tech-kern/2017/04/01/msg021751.html

Ride 7.99.68, a bumpy bus of incremental vfs improvements!


Revision tags: jdolecek-ncq-base
# 1.195 30-Mar-2017 christos

add an auxv node.


Revision tags: pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004 localcount-20160914
# 1.194 20-Aug-2016 hannken

branches: 1.194.2;
Remove now obsolete operation vcache_remove().

Welcome to 7.99.36


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 nick-nhusb-base-20150921 nick-nhusb-base-20150606
# 1.193 20-Apr-2015 riastradh

branches: 1.193.2;
Make VOP_LINK return directory still locked and referenced.

Ride 7.99.10 bump.


Revision tags: nick-nhusb-base-20150406 nick-nhusb-base
# 1.192 05-Sep-2014 matt

branches: 1.192.2;
Try not to use f_data, use f_{vnode,socket,pipe,mqueue,kqueue,ksem} to get
a correctly typed pointer.


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.191 27-Jul-2014 hannken

branches: 1.191.2; 1.191.4; 1.191.8;
Change procfs from hashlist to vcache.
- Key is (type, pid, fd)
- Remove argument "p" from procfs_allocvp(). It is only used
when "type == PFSfd". Lookup the proc with proc_find() when
procfs_loadvnode() needs it.
- Use a vfs_vnode_iterator for procfs_revoke_vnodes().


# 1.190 25-Jul-2014 dholland

Add VOP_FALLOCATE and VOP_FDISCARD to every vnode ops table I can
find.

The filesystem ones all call genfs_eopnotsupp - right now I am only
implementing the plumbing and we can implement fallocate and/or
fdiscard for files later.

The device ones call spec_fallocate (which is also genfs_eopnotsupp)
and spec_fdiscard, which dispatches to the device-level op.

The fifo ones all call vn_fifo_bypass, which also ends up being
EOPNOTSUPP.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base
# 1.189 07-Feb-2014 hannken

branches: 1.189.2;
Change vnode operation lookup to return the resulting vnode *vpp unlocked.
Change cache_lookup() to return an unlocked vnode.

Discussed on tech-kern@

Welcome to 6.99.31


# 1.188 23-Jan-2014 hannken

Change vnode operations create, mknod, mkdir and symlink to return
the resulting vnode *vpp unlocked.

Discussed on tech-kern@

Welcome to 6.99.30


# 1.187 17-Jan-2014 hannken

Change vnode operations create, mknod, mkdir and symlink to keep the
directory node dvp locked on return.

Discussed on tech-kern@

Welcome to 6.99.29


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base
# 1.186 18-Mar-2013 plunky

branches: 1.186.6;
C99 section 6.7.2.3 (Tags) Note 3 states that:

A type specifier of the form

enum identifier

without an enumerator list shall only appear after the type it
specifies is complete.

which means that we cannot pass an "enum vtype" argument to
kauth_access_action() without fully specifying the type first.
Unfortunately there is a complicated include file loop which
makes that difficult, so convert this minimal function into a
macro (and capitalize it).

(ok elad@)


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 1.185 25-Nov-2012 christos

do something reasonable with kernel semaphores.


Revision tags: yamt-pagecache-base6 jmcneill-usbmp-base10
# 1.184 28-May-2012 christos

branches: 1.184.2;
add a task process subdirectory for emul linux


Revision tags: yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 1.183 13-Mar-2012 elad

Replace the remaining KAUTH_GENERIC_ISSUSER authorization calls with
something meaningful. All relevant documentation has been updated or
written.

Most of these changes were brought up in the following messages:

http://mail-index.netbsd.org/tech-kern/2012/01/18/msg012490.html
http://mail-index.netbsd.org/tech-kern/2012/01/19/msg012502.html
http://mail-index.netbsd.org/tech-kern/2012/02/17/msg012728.html

Thanks to christos, manu, njoly, and jmmv for input.

Huge thanks to pgoyette for spinning these changes through some build
cycles and ATF.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.182 04-Sep-2011 jmcneill

branches: 1.182.2; 1.182.6;
PR# kern/45021: Please support /emul/linux/proc/version

Add /proc/version for procfs with -o linux. The version reported depends
on the emulation type of the calling process:

$ cat /proc/version
NetBSD version 5.99.55 (netbsd@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) NetBSD 5.99.55 (GENERIC) #39: Sun Sep 4 09:10:05 EDT 2011

$ /emul/linux/bin/cat /proc/version
Linux version 2.6.18 (linux@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) #0 Wed Mar 3 03:03:03 PST 2010

$ /emul/linux32/bin/cat /proc/version
Linux version 2.6.18 (linux32@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) #0 Wed Mar 3 03:03:03 PST 2010


# 1.181 23-Jun-2011 christos

From Aleksey Cheusov: Don't make it easy for compromised systems to bypass
ASLR protections by providing the mapping addresses of programs to everyone.


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base matt-mips64-premerge-20101231 uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10 rmind-uvmplock-base
# 1.180 01-Jul-2010 rmind

Remove pfind() and pgfind(), fix locking in various broken uses of these.
Rename real routines to proc_find() and pgrp_find(), remove PFIND_* flags
and have consistent behaviour. Provide proc_find_raw() for special cases.
Fix memory leak in sysctl_proc_corename().

COMPAT_LINUX: rework ptrace() locking, minimise differences between
different versions per-arch.

Note: while this change adds some formal cosmetics for COMPAT_DARWIN and
COMPAT_IRIX - locking there is utterly broken (for ages).

Fixes PR/43176.


# 1.179 24-Jun-2010 hannken

Clean up vnode lock operations pass 2:

VOP_UNLOCK(vp, flags) -> VOP_UNLOCK(vp): Remove the unneeded flags argument.

Welcome to 5.99.32.

Discussed on tech-kern.


# 1.178 08-Jun-2010 hannken

Procfs_lookup() does not lookup directory descriptors in the fd/
subdirectory. There is no need for recursive vnode locking here.

Ok: Christos Zoulas <christos@netbsd.org>


Revision tags: uebayasi-xip-base1 yamt-nfs-mp-base9 uebayasi-xip-base
# 1.177 08-Jan-2010 pooka

branches: 1.177.2; 1.177.4;
The VATTR_NULL/VREF/VHOLD/HOLDRELE() macros lost their will to live
years ago when the kernel was modified to not alter ABI based on
DIAGNOSTIC, and now just call the respective function interfaces
(in lowercase). Plenty of mix'n match upper/lowercase has creeped
into the tree since then. Nuke the macros and convert all callsites
to lowercase.

no functional change


Revision tags: matt-premerge-20091211 yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 jym-xensuspend-nbase
# 1.176 03-Jul-2009 elad

Where possible, extract the file-system's access() routine to two internal
functions: the first checking if the operation is possible (regardless of
permissions), the second checking file-system permissions, ACLs, etc.

Mailing list reference:

http://mail-index.netbsd.org/tech-kern/2009/06/21/msg005311.html


# 1.175 23-Jun-2009 elad

Move the implementation of vaccess() to genfs_can_access(), in line with
the other routines of the same spirit.

Adjust file-system code to use it.

Keep vaccess() for KPI compatibility and to keep element of least
surprise. A "diagnostic" message warning that vaccess() is deprecated will
be printed when it's used (obviously, only in DIAGNOSTIC kernels).

No objections on tech-kern@:

http://mail-index.netbsd.org/tech-kern/2009/06/21/msg005310.html


Revision tags: yamt-nfs-mp-base5
# 1.174 24-May-2009 ad

More changes to improve kern_descrip.c.

- Avoid atomics in more places.
- Remove the per-descriptor mutex, and just use filedesc_t::fd_lock.
It was only being used to synchronize close, and in any case we needed
to take fd_lock to free the descriptor slot.
- Optimize certain paths for the <NDFDFILE case.
- Sprinkle more comments and assertions.
- Cache more stuff in filedesc_t.
- Fix numerous minor bugs spotted along the way.
- Restructure how the open files array is maintained, for clarity and so
that we can eliminate the membar_consumer() call in fd_getfile(). This is
mostly syntactic sugar; the main functional change is that fd_nfiles now
lives alongside the open file array.

Some measurements with libmicro:

- simple file syscalls are like close() are between 1 to 10% faster.
- some nice improvements, e.g. poll(1000) which is ~50% faster.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 nick-hppapmap-base2 jym-xensuspend-base nick-hppapmap-base mjf-devfs2-base
# 1.173 17-Dec-2008 cegger

branches: 1.173.2;
kill MALLOC and FREE macros.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 haad-dm-base2 haad-nbase2 ad-audiomp2-base netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 haad-dm-base
# 1.172 05-Sep-2008 skrll

branches: 1.172.2;
PR/39324 kernel diagnostic assertion "l->l_stat != LSZOMB" failed.

Ignore procs with zero or all LSZOMB LWPs. Get a non-LSZOMB LWP to perform
operations against as part of the deal.

procfs really needs to be updated to support multi-threading fully.
Hi Antti!


# 1.171 05-Sep-2008 skrll

ANSIfy


Revision tags: simonb-wapbl-nbase simonb-wapbl-base
# 1.170 02-Jul-2008 rmind

branches: 1.170.2;
Remove proc_representative_lwp(), use a simple LIST_FIRST() instead.
OK by <ad>.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base
# 1.169 28-Apr-2008 martin

branches: 1.169.2; 1.169.4;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-nfs-mp-base
# 1.168 24-Apr-2008 ad

branches: 1.168.2;
Merge proc::p_mutex and proc::p_smutex into a single adaptive mutex, since
we no longer need to guard against access from hardware interrupt handlers.

Additionally, if cloning a process with CLONE_SIGHAND, arrange to have the
child process share the parent's lock so that signal state may be kept in
sync. Partially addresses PR kern/37437.


# 1.167 24-Apr-2008 ad

Network protocol interrupts can now block on locks, so merge the globals
proclist_mutex and proclist_lock into a single adaptive mutex (proc_lock).
Implications:

- Inspecting process state requires thread context, so signals can no longer
be sent from a hardware interrupt handler. Signal activity must be
deferred to a soft interrupt or kthread.

- As the proc state locking is simplified, it's now safe to take exit()
and wait() out from under kernel_lock.

- The system spends less time at IPL_SCHED, and there is less lock activity.


Revision tags: yamt-pf42-baseX yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14
# 1.166 21-Mar-2008 ad

branches: 1.166.2;
Catch up with descriptor handling changes. See kern_descrip.c revision
1.173 for details.


Revision tags: keiichi-mipv6-nbase nick-net80211-sync-base keiichi-mipv6-base bouyer-xeni386-nbase matt-armv6-nbase mjf-devfs-base hpcarm-cleanup-base
# 1.165 23-Jan-2008 elad

branches: 1.165.6;
Tons of process scope changes.

- Add a KAUTH_PROCESS_SCHEDULER action, to handle scheduler related
requests, and add specific requests for set/get scheduler policy and
set/get scheduler parameters.

- Add a KAUTH_PROCESS_KEVENT_FILTER action, to handle kevent(2) related
requests.

- Add a KAUTH_DEVICE_TTY_STI action to handle requests to TIOCSTI.

- Add requests for the KAUTH_PROCESS_CANSEE action, indicating what
process information is being looked at (entry itself, args, env,
open files).

- Add requests for the KAUTH_PROCESS_RLIMIT action indicating set/get.

- Add requests for the KAUTH_PROCESS_CORENAME action indicating set/get.

- Make bsd44 secmodel code handle the newly added rqeuests appropriately.

All of the above make it possible to issue finer-grained kauth(9) calls in
many places, removing some KAUTH_GENERIC_ISSUSER requests.

- Remove the "CAN" from KAUTH_PROCESS_CAN{KTRACE,PROCFS,PTRACE,SIGNAL}.

Discussed with christos@ and yamt@.


Revision tags: bouyer-xeni386-base matt-armv6-base
# 1.164 02-Jan-2008 ad

Merge vmlocking2 to head.


Revision tags: vmlocking2-base3 yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 vmlocking-nbase jmcneill-pm-base reinoud-bufcleanup-base
# 1.163 26-Nov-2007 pooka

branches: 1.163.2; 1.163.6;
Remove the "struct lwp *" argument from all VFS and VOP interfaces.
The general trend is to remove it from all kernel interfaces and
this is a start. In case the calling lwp is desired, curlwp should
be used.

quick consensus on tech-kern


Revision tags: bouyer-xenamd64-base2 bouyer-xenamd64-base
# 1.162 09-Nov-2007 christos

make the last argument of procfs_dir size_t


# 1.161 07-Nov-2007 ad

Merge from vmlocking:

- pool_cache changes.
- Debugger/procfs locking fixes.
- Other minor changes.


Revision tags: jmcneill-base yamt-x86pmap-base4 yamt-x86pmap-base3 vmlocking-base
# 1.160 10-Oct-2007 ad

branches: 1.160.2; 1.160.4;
Merge from vmlocking:

- Split vnode::v_flag into three fields, depending on field locking.
- simple_lock -> kmutex in a few places.
- Fix some simple locking problems.


# 1.159 08-Oct-2007 ad

Merge file descriptor locking, cwdi locking and cross-call changes
from the vmlocking branch.


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base2 yamt-x86pmap-base matt-mips64-base
# 1.158 22-Jul-2007 pooka

branches: 1.158.4; 1.158.6; 1.158.8; 1.158.10;
Don't allow getcwd() on procfs vnodes and provide "/" as the path
instead of the result from getcwd(). The works around locking
panics caused by namei calling VOP_READLINK while holding on to a
directory lock and getcwd() trying to acquire that lock. The real
fix would be to get rid of getcwd() calls within VOPs (not locking
safe), but that's not a viable option in the netbsd-4 timeframe.

Suggestion for workaround from David Holland.


Revision tags: nick-csl-alignment-base mjf-ufs-trans-base
# 1.157 24-May-2007 agc

branches: 1.157.2;
Extend the Linux emulation of /proc to include

/proc/stat
/proc/loadavg and
/proc/<pid>/statm.

These are only present when -o linux is specified as a mount option
to procfs.

Factor out some common code so that it can be used by a number of
functions.

XXX The values returned in the statm emulation need to be verified.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 1.156 04-Apr-2007 rmind

Unfortunately, missed procfs_proc_unlock() in previous.
Pointed out by pooka@


# 1.155 04-Apr-2007 rmind

procfs_readlink: Handle a possible fail of fd_getfile(), also, we
do not need to check for error again.
CID: 4436


# 1.154 09-Mar-2007 ad

branches: 1.154.2; 1.154.4;
- Make the proclist_lock a mutex. The write:read ratio is unfavourable,
and mutexes are cheaper use than RW locks.
- LOCK_ASSERT -> KASSERT in some places.
- Hold proclist_lock/kernel_lock longer in a couple of places.


# 1.153 04-Mar-2007 christos

Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.


# 1.152 03-Mar-2007 salo

Don't prepend rootvnode to the path in non-NULL case for exe links.
It breaks procfs in chroot.

from <christos>, tested by me.


Revision tags: ad-audiomp-base
# 1.151 19-Feb-2007 pooka

When checking for file validity under pid/, do proper proc->lwp
lookup (fsvo proper) instead of fiddling directly with the lwp
list.


# 1.150 18-Feb-2007 pooka

Don't check for validity of p in lookup for root nodes, since it
will always be NULL. Rather, just call pt_valid with NULL directly
and let it decide if we're a linux mount or not.


# 1.149 17-Feb-2007 pavel

Change the process/lwp flags seen by userland via sysctl back to the
P_*/L_* naming convention, and rename the in-kernel flags to avoid
conflict. (P_ -> PK_, L_ -> LW_ ). Add back the (now unused) LSDEAD
constant.

Restores source compatibility with pre-newlock2 tools like ps or top.

Reviewed by Andrew Doran.


# 1.148 16-Feb-2007 pooka

branches: 1.148.2;
In lookup, when checking for procfs process node validity, target the
process we're trying to get information about through procfs, not
the caller of lookup.

fixes 'ls -l /proc/*/file' panic, which would occur when trying to
lookup "file" for a kernel thread, which doesn't have p->p_textvp.


# 1.147 15-Feb-2007 ad

Need to acquire procp->p_mutex for procfs_dir().


# 1.146 11-Feb-2007 ad

Eliminate a couple of reference count and mutex leaks.


Revision tags: post-newlock2-merge
# 1.145 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 1.144 25-Dec-2006 elad

PR/35226: Johann Franz: Problems with permissions in
/usr/pkg/emul/linux/proc .

Okay mlelstv@


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3
# 1.143 09-Dec-2006 chs

a smorgasbord of improvements to vnode locking and path lookup:
- LOCKPARENT is no longer relevant for lookup(), relookup() or VOP_LOOKUP().
these now always return the parent vnode locked. namei() works as before.
lookup() and various other paths no longer acquire vnode locks in the
wrong order via vrele(). fixes PR 32535.
as a nice side effect, path lookup is also up to 25% faster.
- the above allows us to get rid of PDIRUNLOCK.
- also get rid of WANTPARENT (just use LOCKPARENT and unlock it).
- remove an assumption in layer_node_find() that all file systems implement
a recursive VOP_LOCK() (unionfs doesn't).
- require that all file systems supply vfs_vptofh and vfs_fhtovp routines.
fill in eopnotsupp() for file systems that don't support being exported
and remove the checks for NULL. (layerfs calls these without checking.)
- in union_lookup1(), don't change refcounts in the ISDOTDOT case, just
adjust which vnode is locked. fixes PR 33374.
- apply fixes for ufs_rename() from ufs_vnops.c rev. 1.61 to ext2fs_rename().


# 1.142 04-Dec-2006 christos

From Nicolas Joly: restore previous behavior in procfs_validfile_linux, since
readdir passes a NULL lwp.


# 1.141 03-Dec-2006 elad

Move kauth(9) call to where it belongs. Noticed by Nicolas Joly, thanks!


Revision tags: netbsd-4-base
# 1.140 28-Nov-2006 elad

branches: 1.140.2;
Move ktrace, ptrace, systrace, and procfs to use kauth(9).

First, remove process_checkioperm() calls from MD code. Similar checks
using kauth(9) routines (on the process scope, using appropriate action)
are done in the callers.

Add secmodel back-end to handle each subsystem.


# 1.139 25-Nov-2006 skrll

Expose the 'exe' symlink to the process realpath in NetBSD as well. An
example user is gdb.

OK'd by christos.


# 1.138 16-Nov-2006 christos

__unused removal on arguments; approved by core.


# 1.137 29-Oct-2006 christos

add an "emul" file node.


# 1.136 25-Oct-2006 christos

1. fix procfs_validfile{,_linux} to test for NULL pointers properly.
2. make "exe" entry be a symlink to the executable, instead of pointing
directly to the vnode of the executable.
3. factor out commonly used code.


Revision tags: yamt-splraiseipl-base2
# 1.135 12-Oct-2006 christos

- sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386


# 1.134 20-Sep-2006 manu

Emulate Linux's /proc/devices


Revision tags: abandoned-netbsd-4-base yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base rpaulo-netinet-merge-pcb-base
# 1.133 13-Jun-2006 yamt

branches: 1.133.6; 1.133.8;
use KAUTH_PROCESS_CANSEE rather than CURTAIN where appropriate.


# 1.132 13-Jun-2006 yamt

remove unnecessary arguments from kauth_authorize_process.
ie. make it similar to the one found in apple TN.


# 1.131 07-Jun-2006 kardel

merge FreeBSD timecounters from branch simonb-timecounters
- struct timeval time is gone
time.tv_sec -> time_second
- struct timeval mono_time is gone
mono_time.tv_sec -> time_uptime
- access to time via
{get,}{micro,nano,bin}time()
get* versions are fast but less precise
- support NTP nanokernel implementation (NTP API 4)
- further reading:
Timecounter Paper: http://phk.freebsd.dk/pubs/timecounter.pdf
NTP Nanokernel: http://www.eecis.udel.edu/~mills/ntp/html/kern.html


Revision tags: yamt-pdpolicy-base5 simonb-timecounters-base
# 1.130 14-May-2006 elad

branches: 1.130.2;
integrate kauth.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 elad-kernelauth-base yamt-pdpolicy-base yamt-uio_vmspace-base5
# 1.129 02-Feb-2006 christos

branches: 1.129.2; 1.129.4; 1.129.6; 1.129.8;
PR/32692: Matthew Mondor: linux compatibility in /proc/self should point
directly to the directory containing the pid instead of pointing to
/proc/curproc, because some programs rely on calling readlink on /proc/self
to get the pid.


# 1.128 11-Dec-2005 christos

branches: 1.128.2; 1.128.4;
merge ktrace-lwp.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base ktrace-lwp-base
# 1.127 02-Nov-2005 yamt

merge yamt-vop branch. remove following VOPs.

VOP_BLKATOFF
VOP_VALLOC
VOP_BALLOC
VOP_REALLOCBLKS
VOP_VFREE
VOP_TRUNCATE
VOP_UPDATE


Revision tags: yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 1.126 01-Oct-2005 atatat

branches: 1.126.2;
Add "cwd" and "root" symlinks to each process's directory. The cwd
link points to the process's current working directory, and the root
link points to the process's root directory. What else would you
expect?

For directories that are out of reach (caller is in a chroot, target
process is in a different chroot, etc), the links point to "/"
instead.


# 1.125 11-Sep-2005 elad

Implement curtain for procfs.


# 1.124 30-Aug-2005 xtraeme

Remove __P()


# 1.123 29-May-2005 christos

branches: 1.123.2;
- sprinkle const
- avoid shadowed variables.


Revision tags: kent-audio2-base
# 1.122 02-Apr-2005 christos

PR/29782: Martin Husemann: procfs can not unmount when some process has its
current directory in curproc. Fix from Pedro Martelletto:
We cannot call vgone() from procfs_inactive() if we are coming from
vclean(). that's what's probably causing the deadlock.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 yamt-km-base4 yamt-km-base3 netbsd-3-base
# 1.121 26-Feb-2005 perry

nuke trailing whitespace


Revision tags: yamt-km-base2 yamt-km-base kent-audio1-beforemerge kent-audio1-base
# 1.120 04-Oct-2004 yamt

branches: 1.120.4; 1.120.6;
procfs_readdir:
- return correct cookie when buffer size is small.
- simplify logic.


# 1.119 04-Oct-2004 yamt

procfs_readdir: remove a redundant assignment.


# 1.118 02-Oct-2004 yamt

procfs_getattr: correct size of /proc/self.


# 1.117 01-Oct-2004 yamt

procfs_readdir:
- fix a locking problem, using proclist_foreach_call. PR/27098.
- correct snprintf size argument.


# 1.116 01-Oct-2004 yamt

procfs_readdir: fix an offset handling bug after addition of /proc/self.


# 1.115 01-Oct-2004 yamt

procfs_readdir: use a list macro.


# 1.114 20-Sep-2004 jdolecek

add 'mounts' file for -o linux, which lists all currently mounted
filesystems; Linux glibc statvfs() uses this to get some of mount flags,
and this file is also useful as /emul/linux/etc/mtab (via symlink)


# 1.113 29-Apr-2004 jrf

Removed remaining caddr_t casts we do not need in miscfs. Recompiled
kernel and ran for a day or so. There are still some caddr_t types in
the arguments of some calls, I will do those separately (later) as
they touch a lot more of the system.
Approved by christos@NetBSD.org.


# 1.112 22-Apr-2004 itojun

sprintf -> snprintf


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.111 15-Feb-2004 jdolecek

unlock the descriptor table simple lock after fd_getfile() call in
procfs_readdir()
fixes procfs locking problems reported on current-users@, problem place
found by enami tsugutomo


# 1.110 30-Oct-2003 simonb

Remove some assigned-to but otherwise unused variables.


# 1.109 27-Sep-2003 darcy

Changes as discussed with itojun on tech-kern. I have modified the enums
to have KFS or PFS differentiators. Further I have wrapped the enum in
procfs in "#ifdef _KERNEL" as it is done in kernfs.

To see the discussion go to http://mail-index.NetBSD.org/tech-kern/2003/09/
and look for "Mismatched enums in include files" in the list.


# 1.108 07-Sep-2003 itojun

remove meaningless line (variable overwritten 2 lines below)


# 1.107 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.


# 1.106 29-Jun-2003 fvdl

branches: 1.106.2;
Back out the lwp/ktrace changes. They contained a lot of colateral damage,
and need to be examined and discussed more.


# 1.105 29-Jun-2003 thorpej

Undo part of the ktrace/lwp changes. In particular:
* Remove the "lwp *" argument that was added to vget(). Turns out
that nothing actually used it!
* Remove the "lwp *" arguments that were added to VFS_ROOT(), VFS_VGET(),
and VFS_FHTOVP(); all they did was pass it to vget() (which, as noted
above, didn't use it).
* Remove all of the "lwp *" arguments to internal functions that were added
just to appease the above.


# 1.104 28-Jun-2003 darrenr

Pass lwp pointers throughtout the kernel, as required, so that the lwpid can
be inserted into ktrace records. The general change has been to replace
"struct proc *" with "struct lwp *" in various function prototypes, pass
the lwp through and use l_proc to get the process pointer when needed.

Bump the kernel rev up to 1.6V


# 1.103 28-May-2003 christos

Add /proc/<pid>/stat for linux compat. j2sdk1.4.2 depends on it.


# 1.102 18-Apr-2003 christos

Make symlinks for directories that point to the actual directory.
Make symlinks to [kqueue] and [misc] for kqueue and misc fds.


# 1.101 17-Apr-2003 jdolecek

do not show nodes corresponding to directory descriptors for process
in fd/ subdirectory, nor allow lookup/open for the nodes
this fixes PR kern/21187 for good, and also avoids interesting directory
locking issues


# 1.100 17-Apr-2003 jdolecek

procfs_readdir(): in Pfd case, only show descriptors of types we want
how to represent (vnodes, fifo, pipes); also use fd_getfile() et al

this avoids annoying EOPNOTSUPP error messages from ls -F and such


# 1.99 17-Apr-2003 jdolecek

procfs_lookup(): use fd_getfile() et al in Pfd case


# 1.98 17-Apr-2003 jdolecek

use fd_getfile() in procfs_getfp(), and FILE_USE()/FILE_UNUSE() the
returned file descriptor pointer appropriately


# 1.97 17-Apr-2003 jdolecek

make some local arrays/variables static + const


# 1.96 10-Apr-2003 jdolecek

use former genfs_eopnotsupp_rele() as genfs_eopnotsupp(), so that vnodes
are vput()/vrele()d as necessary - some filesystems did use the wrong
one for some ops, and it's just safer to not take the chance

based on suggestion by Bill Studenmund


# 1.95 05-Apr-2003 dsl

Remove pointless check against PID_MAX. Let pfind() do the validation.
(The new pid allocation code may decide to allocate pids above PID_MAX.)


# 1.94 25-Feb-2003 jrf

This addresses PR kerm/19989. Thanks to hamajima@nagoya.ydc.co.jp for submitting this patch which enables /proc/uptime for linux emul. Patch reviewed by atatat@netbsd.org and tron@netbsd.org, approved by tron@netbsd.org.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 1.93 04-Jan-2003 martin

Cast off_t expression to long long to match format even on 64 bit
plattforms.

Shouldn't we introduce a PRIoff_t macro to create such format strings?


# 1.92 03-Jan-2003 christos

add LK_CANRECURSE in the locking of /dev/<pid>/fd/<n> and remove the curproc
kludge. Thanks to fvdl.


# 1.91 03-Jan-2003 christos

Implement /proc/<pid>/fd/<n>. This is work in progress. Questionable things:
- Is it ok to convert DTYPE_PIPE to VFIFO and DTYPE_SOCKET to VSOCK?
- XXX: Avoid locking issue in ls -Rl /proc by avoiding curproc
- Does I/O to pipes work?
- XXX: Are there security implications?


Revision tags: fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge gehenna-devsw-base kqueue-base
# 1.90 03-Aug-2002 simonb

Just use the "time" variable in the *_getattr functions instead of a call
to (the potentially expensive) microtime().


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.89 09-May-2002 thorpej

branches: 1.89.2;
Move code shared by procfs and the kernel proper out of procfs and
into the kernel proper (renaming functions from procfs_* to process_*).


Revision tags: eeh-devprop-base newlock-base ifpoll-base
# 1.88 12-Jan-2002 christos

Don't hide the real return code with EPERM.


# 1.87 06-Dec-2001 chs

add a VOP_PUTPAGES method for all the filesystems that don't have pages,
just unlock the interlock.


# 1.86 05-Dec-2001 thorpej

* Allow machine-dependent code to specify hooks for ptrace(2)
(__HAVE_PTRACE_MACHDEP) and procfs (__HAVE_PROCFS_MACHDEP).
These changes will allow platforms like x86 (XMM) and PowerPC
(AltiVec) to export extended register sets in a sane manner.

* Use __HAVE_PTRACE_MACHDEP to export x86 XMM registers (standard
FP + SSE/SSE2) using PT_{GET,SET}XMMREGS (in the machdep
ptrace request space).
* Use __HAVE_PROCFS_MACHDEP to export x86 XMM registers via
/proc/N/xmmregs in procfs.


Revision tags: thorpej-mips-cache-base
# 1.85 10-Nov-2001 lukem

add RCSIDs


# 1.84 06-Nov-2001 simonb

Remove some variables that are set but never used.


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base
# 1.83 31-Aug-2001 chs

branches: 1.83.2; 1.83.4;
map files are zero-length.


# 1.82 03-Jun-2001 chs

branches: 1.82.2;
procfs_bmap() should never be called, make it a "bad op".
let procfs_mmap() use the default error method.


Revision tags: thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 1.81 14-Apr-2001 kleink

In procfs_readdir(), give /proc/# directories DT_DIR (rather than DT_REG).


# 1.80 30-Mar-2001 fvdl

Bump va_blocksize for the map files some more, so that programs with
quite a few mappings have a chance of being handled correctly if
st_blksize is looked at.


# 1.79 29-Mar-2001 fvdl

For -o linux mounts, add some code to emulate /proc/#/maps.
Needs NAMECACHE_ENTER_REVERSE to include filenames.


# 1.78 21-Feb-2001 jdolecek

branches: 1.78.2;
make some more constant arrays 'const'


# 1.77 22-Jan-2001 jdolecek

make filesystem vnodeop, specop, fifoop and vnodeopv_* arrays const


# 1.76 17-Jan-2001 fvdl

Add a few linux-style files, only enabled when -o linux is specified
for the mount. Currently these are /proc/cpuinfo and /proc/meminfo.
The former only does something on i386 right now.


# 1.75 24-Nov-2000 chs

remove dead code and other misc cleanup.


# 1.74 09-Aug-2000 tv

Only show the "exe" entry to Linux processes, suggested by christos.
Since there are actually three struct emul's for linux, use the e_name
field to determine eligibility with strcmp().


# 1.73 09-Aug-2000 tv

Some versions of Linux libc look for /proc/.../exe instead of /proc/../file.
Add an entry for "exe" that is the same as "file", provided only if
COMPAT_LINUX is set.


# 1.72 03-Aug-2000 thorpej

MALLOC()/FREE() are not to be used for variable sized allocations.


# 1.71 28-Jun-2000 mrg

<vm/vm.h> -> <uvm/uvm_extern.h>


Revision tags: netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 1.70 30-Mar-2000 simonb

branches: 1.70.4;
Delete duplicate declaration of atopid().


Revision tags: chs-ubc2-newbase wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base fvdl-softdep-base
# 1.69 02-Sep-1999 thorpej

branches: 1.69.2; 1.69.8;
Make /proc/self a symlink to /proc/curproc. I've observed Linux programs
that expect /proc/self/cmdline to exist.


# 1.68 25-Aug-1999 sommerfeld

Change variable used for directory offset from "int" to "off_t".
Overkill, but avoids a host of truncation problems.


# 1.67 24-Aug-1999 sommerfeld

Fix PR8270:

Problem turned out to be due to improper handling of reads beyond EOF:
they should just return without error with the uio unchanged, and the
caller will recognize this as a zero-byte return (EOF).

The previous fix to protect directory reads against bogus uio_offset
values returned EINVAL, which broke mount -o union, which only
union'ed in the lower directory if the upper directory cleanly
returned EOF.

While we're here, protect kernfs as well.


# 1.66 14-Aug-1999 christos

protect against large uio_offset


# 1.65 03-Aug-1999 wrstuden

Add support for fcntl(2) to generate VOP_FCNTL calls. Any fcntl
call with F_FSCTL set and F_SETFL calls generate calls to a new
fileop fo_fcntl. Add genfs_fcntl() and soo_fcntl() which return 0
for F_SETFL and EOPNOTSUPP otherwise. Have all leaf filesystems
use genfs_fcntl().

Reviewed by: thorpej
Tested by: wrstuden


Revision tags: chs-ubc2-base
# 1.64 25-Jul-1999 thorpej

Add calls to lock the proclist as appropriate.


# 1.63 14-Jul-1999 thorpej

Fix a paste-o in procfs_lookup() introduced with the vnode locking changes.
Fixes PR #7961, Mario Kemper <magick@bundy.lip.owl.de>.


# 1.62 08-Jul-1999 wrstuden

Bump osrelease to 1.4E. Add layerfs files, remove null_subr.c.

Update coda to new struct lock in struct vnode.

make fdescfs, kernfs, portalfs, and procfs actually lock their vnodes.
It's not that hard.

Make unionfs set v_vnlock = NULL so any overlayed fs will call its
VOP_LOCK.


Revision tags: kame_141_19991130 netbsd-1-4-PATCH001 kame_14_19990705 kame_14_19990628 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.61 12-Mar-1999 christos

branches: 1.61.2; 1.61.4;
PR/7143: Jaromir Docelek: Add procfs/cmdline from Linux emulation


# 1.60 25-Jan-1999 msaitoh

Add /proc/#/map. From FreeBSD.


Revision tags: kenh-if-detach-base chs-ubc-base
# 1.59 08-Sep-1998 thorpej

- Use proclists[], rather than checking allproc and zombproc explicitly.
- Add some comments about locking.


# 1.58 13-Aug-1998 kleink

Per POSIX, fail with EINVAL if advisory locking is attempted on a file type
that doesn't support it, rather than using a homegrown EBADF or EOPNOTSUPP.


# 1.57 10-Aug-1998 matthias

create miscfs/genfs/genfs_vnops.c:genfs_enoioctl and make all the other
filesystems use it instead of a private version.


# 1.56 09-Aug-1998 perry

bzero->memset, bcopy->memcpy, bcmp->memcmp


# 1.55 03-Aug-1998 kleink

Recognize _PC_SYNC_IO.


Revision tags: eeh-paddr_t-base
# 1.54 21-Apr-1998 fvdl

procfs_readdir: in case of error, check if cookies actually have
been allocated before freeing them. From Wolfgang Solfrank.


# 1.53 01-Mar-1998 fvdl

Merge with Lite2 + local changes


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base marc-pcmcia-base
# 1.52 10-Oct-1997 fvdl

Bump last argument to VOP_READDIR to off_t (from u_long).


Revision tags: thorpej-signal-base
# 1.51 27-Aug-1997 thorpej

Fix a reversed argument which caused procfs_checkioperm() to always return
"OK". Add a few comments to avoid further confusion.


# 1.50 12-Aug-1997 thorpej

Fix the procfs hole described on current-users, similar to a fix for
FreeBSD by Sean Eric Fagan, but a bit different. This makes the checks
in the same places as sef's FreeBSD patch, but does not hardcode the
"kmem" group into the kernel, and also does a check identical to the
(3) and (4) checks in the NetBSD ptrace(2):

(1) it's not owned by you, or is set-id on exec (unless
you're root), or

(2) it's init, which controls the security level of the
entire system, and the system was not compiled with
permanently insecure mode turned on.


Revision tags: marc-pcmcia-bp
# 1.49 08-May-1997 mycroft

branches: 1.49.4;
Pass the vnode type to vaccess(), and use it when checking VEXEC. Make sure
that the mode bits passed to vaccess() and returned by foo_getattr() contain
only permission bits.


# 1.48 05-May-1997 mycroft

Need stat.h.


# 1.47 05-May-1997 mycroft

Eliminate bogus uses of V{READ,WRITE,EXEC}. Use S_I[RWX]{USR,GRP,OTH} where
appropriate.


# 1.46 28-Apr-1997 mycroft

Minor code cleanup.


Revision tags: is-newarp-before-merge is-newarp-base
# 1.45 25-Oct-1996 cgd

define path name string variables that we should not (and, thankfully, do
not) modify as 'const char *' rather 'char *'.


# 1.44 13-Oct-1996 christos

backout previous kprintf changes


# 1.43 10-Oct-1996 christos

printf -> kprintf, sprintf -> ksprintf


# 1.42 07-Sep-1996 mycroft

Implement poll(2).


# 1.41 01-Sep-1996 mycroft

Add a set of generic file system operations that most file systems use.
Also, fix some time stamp bogosities.


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 1.40 16-Mar-1996 christos

Fix printf format follies.


# 1.39 13-Feb-1996 mycroft

GC *_nullop(). Minor nits.


# 1.38 12-Feb-1996 christos

close PR/2063: procfs_rw prototyped twice with different prototypes


# 1.37 09-Feb-1996 christos

miscfs prototype changes


# 1.36 09-Feb-1996 mycroft

Fix vop_link, vop_symlink, and vop_remove semantics in several ways:
* Change the argument names to vop_link so they actually make sense.
* Implement vop_link and vop_symlink for all file systems, so they do proper
cleanup.
* Require the file system to decide whether or not linking and unlinking of
directories is allowed, and disable it for all current file systems.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.35 09-Oct-1995 mycroft

Use the index number as the cookie, rather than multiplying by UIO_MX.


# 1.34 09-Oct-1995 mycroft

Add support for cookies, mostly from Greg Hudson.


# 1.33 15-Apr-1995 cgd

fix timeval vs. timespec warnings


# 1.32 03-Feb-1995 mycroft

Return EROFS rather than ENOENT in many cases. Also some cosmetic cleanup.


# 1.31 27-Dec-1994 mycroft

Format police.


# 1.30 24-Dec-1994 ws

Implement and use a common access checking routine


# 1.29 14-Dec-1994 mycroft

Remove a_fp.


# 1.28 14-Nov-1994 christos

fixed struct comment


# 1.27 30-Oct-1994 cgd

be more careful with types, also pull in headers where necessary.


# 1.26 20-Oct-1994 cgd

update for new syscall args description mechanism


# 1.25 30-Aug-1994 mycroft

Convert process, file, and namei lists and hash tables to use queue.h.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.24 29-Jun-1994 cgd

New RCS ID's, take two. they're more aesthecially pleasant, and use 'NetBSD'


# 1.23 16-Jun-1994 mycroft

Remove an unneeded test.


# 1.22 15-Jun-1994 mycroft

Minor update from JSP after merging my changes.


# 1.21 08-Jun-1994 mycroft

Update to 4.4-Lite fs code, with local changes.


# 1.20 05-May-1994 cgd

lots of changes: prototype migration, move lots of variables, definitions,
and structure elements around. kill some unnecessary type and macro
definitions. standardize clock handling. More changes than you'd want.


# 1.19 15-Apr-1994 cgd

forgot these...


# 1.18 12-Apr-1994 cgd

be a bit smarter about determining if files shouldn't be seen by the user.
Also, DON'T allow a lookup to succeed on a file that's not visible!


# 1.17 15-Feb-1994 mycroft

Undo last change; executables is `file', not `a.out'.


# 1.16 14-Feb-1994 ws

Rename file -> a.out


# 1.15 14-Feb-1994 ws

Don't try to show a file for a process if there is none


# 1.14 28-Jan-1994 cgd

make a fpregs file.


# 1.13 20-Jan-1994 ws

Make procfs really work for debugging.
Implement not & notepg files in procfs.


# 1.12 09-Jan-1994 ws

Bug fixes and enhancements:
Make NFS serving work (BUT DON'T USE "attach" TO /proc/*/ctl FOR NOW!!!)
Make `curproc' a symbolic link
Add `.' and `..' entries to the directories.
Return better guesses on the size of the files.


# 1.11 05-Jan-1994 cgd

return size of 'reg' from getattr()


# 1.10 05-Jan-1994 cgd

make it compile (cleanly) for us


# 1.9 05-Jan-1994 cgd

add new procfs code, from Jan-Simon Pendry, jsp@sequent.com.
This is pretty-much "virgin", so that diffs can be done later.


# 1.8 18-Dec-1993 mycroft

Canonicalize all #includes.


Revision tags: magnum-base
# 1.7 16-Sep-1993 cgd

kill volatile warning.


# 1.6 07-Sep-1993 ws

branches: 1.6.2;
Changes to VFS readdir semantics
NFS changes for better cookie support
ISOFS changes for better Rockridge support and support for generation numbers


# 1.5 26-Aug-1993 pk

Implement setattr: mode for process entries; mode + uid/gid for the
PROCFS root directory.
Fixed omission in pfs_root() which came to light as a result of the above:
hold on to vnode for root dir.


# 1.4 25-Aug-1993 pk

Fixed improperly initialized nfsnode in pfs_lookup()


# 1.3 24-Aug-1993 pk

copyright update.


# 1.2 24-Aug-1993 pk

Rcs Id added.


# 1.1 24-Aug-1993 pk

branches: 1.1.1;
Initial version of a proc filesystem.


# 1.228 27-Mar-2022 christos

dedup the eofs link/symlink methods


# 1.227 17-Jan-2022 bouyer

If the calling process is running under linux emulation, make /proc/xxx/fd/
return only symlinks pointing to the original file in the filesystem,
instead of a hard link. This matches the linux behavior, and some
linux programs relies on it (they unconditionally call readlink() on
/proc/xxx/fd/yy and don't deal with it returning EINVAL).
Proposed on tech-kern@ in
http://mail-index.netbsd.org/tech-kern/2022/01/11/msg027877.html


# 1.226 14-Jan-2022 christos

Fix emul and exe DT_ types (from RVP, as was the previous commit)


# 1.225 14-Jan-2022 christos

Put the appropriate DT_ constant in the dirent structure depending on the
file type.


# 1.224 11-Jan-2022 christos

remove redundant error initialization and break earlier. (from rvp)


# 1.223 11-Jan-2022 hannken

Use a single "p" variable.

Should fix PR kern/56614: kernel panic on tmux


# 1.222 10-Jan-2022 christos

use a single nc variable.


# 1.221 10-Jan-2022 christos

Fix locking in the error path (from RVP). Centralize unlock code.


# 1.220 08-Dec-2021 andvar

s/efficent/efficient/ in comments.


# 1.219 05-Oct-2021 christos

PR/53299: RVP: kernfs and procfs are broken when sysctl security.curtain
is enabled


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base thorpej-i2c-spi-conf-base
# 1.218 18-Jul-2021 dholland

Abolish all the silly indirection macros for initializing vnode ops tables.

These are things of the form #define foofs_op genfs_op, or #define
foofs_op genfs_eopnotsupp, or similar. They serve no purpose besides
obfuscation, and have gotten cutpasted all over everywhere.


# 1.217 29-Jun-2021 dholland

- Add a new vnode op: VOP_PARSEPATH.
- Move namei_getcomponent to genfs_vnops.c and call it genfs_parsepath.
- Add a parsepath entry to every vnode ops table.

VOP_PARSEPATH takes a directory vnode to be searched and a complete
following path and chooses how much of that path to consume. To begin
with, all parsepath calls are genfs_parsepath, which locates the first
'/' as always.

Note that the call doesn't take the whole struct componentname, only
the string. The other bits of struct componentname should not be
needed and there's no reason to cause potential complications by
exposing them.


# 1.216 28-Jun-2021 chs

VOP_BMAP() may be called via ioctl(FIOGETBMAP) on any vnode that applications
can open. change various pseudo-fs *_bmap methods return an error instead of
panic.

Reported-by: syzbot+8289a3eaf2ba60958c87@syzkaller.appspotmail.com


Revision tags: cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base thorpej-cfargs-base thorpej-futex-base
# 1.215 27-Jun-2020 christos

branches: 1.215.6;
Introduce genfs_pathconf() and use it for the default case in all filesystems.


# 1.214 23-May-2020 ad

Move proc_lock into the data segment. It was dynamically allocated because
at the time we had mutex_obj_alloc() but not __cacheline_aligned.


# 1.213 16-May-2020 christos

Add ACL support for FFS. From FreeBSD.


# 1.212 29-Apr-2020 thorpej

If the procfs mount is marked as linux-compat, then allow proc lookup
by any LWP ID in the proc, not just the canonical PID.


Revision tags: bouyer-xenpvh-base2
# 1.211 21-Apr-2020 ad

Revert the changes made in February to make cwdinfo use mostly lockless,
which relied on taking extra vnode refs.

Having benchmarked various experimental changes over the past few months it
seems that it's better to avoid vnode refs as much as possible. cwdi_lock
as a RW lock already did that to some extent for getcwd() and will permit
the same for namei() too.


Revision tags: phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base is-mlppp-base phil-wifi-20200406 ad-namecache-base3
# 1.210 24-Feb-2020 ad

branches: 1.210.4;
v_interlock -> vmobjlock


# 1.209 23-Feb-2020 ad

Merge from ad-namecache:

- Have a stab at clustering the members of vnode_t and vnode_impl_t in a
more cache-conscious way. With that done, go back to adjusting v_usecount
with atomics and keep vi_lock directly in vnode_impl_t (saves KVA).

- Allow VOP_LOCK(LK_NONE) for the benefit of VFS_VGET() and VFS_ROOT().
Make sure LK_UPGRADE always comes with LK_NOWAIT.

- Make cwdinfo use mostly lockless.


# 1.208 01-Feb-2020 riastradh

Load struct filedesc::fd_dt with atomic_load_consume.

Exceptions: when fd_refcnt <= 1, or when holding fd_lock.

While here:

- Restore KASSERT(mutex_owned(&fdp->fd_lock)) in fd_unused.
=> This is used only in fd_close and fd_abort, where it holds.
- Move bounds check assertion in fd_putfile to where it matters.
- Store fd_dt with atomic_store_release.
- Move load of fd_dt under lock in knote_fdclose.
- Omit membar_consumer in fdesc_readdir.
=> atomic_load_consume serves the same purpose now.
=> Was needed only on alpha anyway.


Revision tags: ad-namecache-base2 ad-namecache-base1 ad-namecache-base phil-wifi-20191119
# 1.207 29-Aug-2019 hannken

branches: 1.207.2;
Add missing operation VOP_GETPAGES() returning EFAULT.

Without this operation posix_fadvise(..., POSIX_FADV_WILLNEED)
would leave the v_interlock held.

Observed by maxv@


Revision tags: netbsd-9-base phil-wifi-20190609 isaki-audio2-base
# 1.206 30-Mar-2019 christos

branches: 1.206.4;
add a node for the process resource limits.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020
# 1.205 14-Oct-2018 jdolecek

remove M_CANFAIL flag for malloc(9) - it was completely ignored, so had
actually no effect


Revision tags: pgoyette-compat-0930 pgoyette-compat-0906
# 1.204 03-Sep-2018 riastradh

Rename min/max -> uimin/uimax for better honesty.

These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER! Some subsystems have

#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)


Revision tags: pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415
# 1.203 07-Apr-2018 hannken

branches: 1.203.2;
Lock the target cwdi and take an additional reference to the
vnode we are interested in to prevent it from disappearing
before getcwd_common().

Should fix PR kern/53096 (netbsd-8 crash on heavy disk I/O)


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.202 31-Dec-2017 christos

branches: 1.202.2;
Add an environ node


Revision tags: tls-maxphys-base-20171202
# 1.201 01-Dec-2017 christos

Allow procfs_kqfilter, since we allow poll. "go" does it.


# 1.200 08-Nov-2017 christos

fix locking, remove error(1) comments.


# 1.199 08-Nov-2017 christos

use p->p_path, remove unused code.


# 1.198 28-Aug-2017 kamil

Remove the filesystem tracing feature

This is a legacy interface from 4.4BSD, and it was
introduced to overcome shortcomings of ptrace(2) at that time, which are
no longer relevant (performance). Today /proc/#/ctl offers a narrow
subset of ptrace(2) commands and is not applicable for modern
applications use beyond simplistic tracing scenarios.

This removal will simplify kernel internals. Users will still be able to
use all the other /proc files.

This change won't affect other procfs files neither Linux compat
features within mount_procfs(8). /proc/#/ctl isn't available on Linux.

Remove:
- /proc/#/ctl from mount_procfs(8)
- P_FSTRACE note from the documentation of ps(1)
- /proc/#/ctl and filesystem tracing documentation from mount_procfs(8)
- KAUTH_REQ_PROCESS_PROCFS_CTL documentation from kauth(9)
- source code file miscfs/procfs/procfs_ctl.c
- PFSctl and procfs_doctl() from sys/miscfs/procfs/procfs.h
- KAUTH_REQ_PROCESS_PROCFS_CTL from sys/sys/kauth.h
- PSL_FSTRACE (0x00010000) from sys/sys/proc.h
- P_FSTRACE (0x00010000) from sys/sys/sysctl.h

Reduce code complexity after removal of this functionality.

Update TODO.ptrace accordingly: remove two entries about /proc tracing.

Do not keep legacy notes as comments in the headers about removed
PSL_FSTRACE / P_FSTRACE, as this interface had little number of users
(close or equal to zero).

Proposed on tech-kern@.

All filesystem tracing utility users are encouraged to switch to ptrace(2).

Sponsored by <The NetBSD Foundation>


Revision tags: matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base
# 1.197 26-May-2017 riastradh

branches: 1.197.2;
Make VOP_RECLAIM do the last unlock of the vnode.

VOP_RECLAIM naturally has exclusive access to the vnode, so having it
locked on entry is not strictly necessary -- but it means if there
are any final operations that must be done on the vnode, such as
ffs_update, requiring exclusive access to it, we can now kassert that
the vnode is locked in those operations.

We can't just have the caller release the last lock because some file
systems don't use genfs_lock, and require the vnode to remain valid
for VOP_UNLOCK to work, notably unionfs.


Revision tags: prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.196 11-Apr-2017 riastradh

Make VOP_INACTIVE preserve vnode lock on return.

Discussed on tech-kern:
https://mail-index.netbsd.org/tech-kern/2017/04/01/msg021751.html

Ride 7.99.68, a bumpy bus of incremental vfs improvements!


Revision tags: jdolecek-ncq-base
# 1.195 30-Mar-2017 christos

add an auxv node.


Revision tags: pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004 localcount-20160914
# 1.194 20-Aug-2016 hannken

branches: 1.194.2;
Remove now obsolete operation vcache_remove().

Welcome to 7.99.36


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 nick-nhusb-base-20150921 nick-nhusb-base-20150606
# 1.193 20-Apr-2015 riastradh

branches: 1.193.2;
Make VOP_LINK return directory still locked and referenced.

Ride 7.99.10 bump.


Revision tags: nick-nhusb-base-20150406 nick-nhusb-base
# 1.192 05-Sep-2014 matt

branches: 1.192.2;
Try not to use f_data, use f_{vnode,socket,pipe,mqueue,kqueue,ksem} to get
a correctly typed pointer.


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.191 27-Jul-2014 hannken

branches: 1.191.2; 1.191.4; 1.191.8;
Change procfs from hashlist to vcache.
- Key is (type, pid, fd)
- Remove argument "p" from procfs_allocvp(). It is only used
when "type == PFSfd". Lookup the proc with proc_find() when
procfs_loadvnode() needs it.
- Use a vfs_vnode_iterator for procfs_revoke_vnodes().


# 1.190 25-Jul-2014 dholland

Add VOP_FALLOCATE and VOP_FDISCARD to every vnode ops table I can
find.

The filesystem ones all call genfs_eopnotsupp - right now I am only
implementing the plumbing and we can implement fallocate and/or
fdiscard for files later.

The device ones call spec_fallocate (which is also genfs_eopnotsupp)
and spec_fdiscard, which dispatches to the device-level op.

The fifo ones all call vn_fifo_bypass, which also ends up being
EOPNOTSUPP.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base
# 1.189 07-Feb-2014 hannken

branches: 1.189.2;
Change vnode operation lookup to return the resulting vnode *vpp unlocked.
Change cache_lookup() to return an unlocked vnode.

Discussed on tech-kern@

Welcome to 6.99.31


# 1.188 23-Jan-2014 hannken

Change vnode operations create, mknod, mkdir and symlink to return
the resulting vnode *vpp unlocked.

Discussed on tech-kern@

Welcome to 6.99.30


# 1.187 17-Jan-2014 hannken

Change vnode operations create, mknod, mkdir and symlink to keep the
directory node dvp locked on return.

Discussed on tech-kern@

Welcome to 6.99.29


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base
# 1.186 18-Mar-2013 plunky

branches: 1.186.6;
C99 section 6.7.2.3 (Tags) Note 3 states that:

A type specifier of the form

enum identifier

without an enumerator list shall only appear after the type it
specifies is complete.

which means that we cannot pass an "enum vtype" argument to
kauth_access_action() without fully specifying the type first.
Unfortunately there is a complicated include file loop which
makes that difficult, so convert this minimal function into a
macro (and capitalize it).

(ok elad@)


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 1.185 25-Nov-2012 christos

do something reasonable with kernel semaphores.


Revision tags: yamt-pagecache-base6 jmcneill-usbmp-base10
# 1.184 28-May-2012 christos

branches: 1.184.2;
add a task process subdirectory for emul linux


Revision tags: yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 1.183 13-Mar-2012 elad

Replace the remaining KAUTH_GENERIC_ISSUSER authorization calls with
something meaningful. All relevant documentation has been updated or
written.

Most of these changes were brought up in the following messages:

http://mail-index.netbsd.org/tech-kern/2012/01/18/msg012490.html
http://mail-index.netbsd.org/tech-kern/2012/01/19/msg012502.html
http://mail-index.netbsd.org/tech-kern/2012/02/17/msg012728.html

Thanks to christos, manu, njoly, and jmmv for input.

Huge thanks to pgoyette for spinning these changes through some build
cycles and ATF.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.182 04-Sep-2011 jmcneill

branches: 1.182.2; 1.182.6;
PR# kern/45021: Please support /emul/linux/proc/version

Add /proc/version for procfs with -o linux. The version reported depends
on the emulation type of the calling process:

$ cat /proc/version
NetBSD version 5.99.55 (netbsd@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) NetBSD 5.99.55 (GENERIC) #39: Sun Sep 4 09:10:05 EDT 2011

$ /emul/linux/bin/cat /proc/version
Linux version 2.6.18 (linux@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) #0 Wed Mar 3 03:03:03 PST 2010

$ /emul/linux32/bin/cat /proc/version
Linux version 2.6.18 (linux32@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) #0 Wed Mar 3 03:03:03 PST 2010


# 1.181 23-Jun-2011 christos

From Aleksey Cheusov: Don't make it easy for compromised systems to bypass
ASLR protections by providing the mapping addresses of programs to everyone.


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base matt-mips64-premerge-20101231 uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10 rmind-uvmplock-base
# 1.180 01-Jul-2010 rmind

Remove pfind() and pgfind(), fix locking in various broken uses of these.
Rename real routines to proc_find() and pgrp_find(), remove PFIND_* flags
and have consistent behaviour. Provide proc_find_raw() for special cases.
Fix memory leak in sysctl_proc_corename().

COMPAT_LINUX: rework ptrace() locking, minimise differences between
different versions per-arch.

Note: while this change adds some formal cosmetics for COMPAT_DARWIN and
COMPAT_IRIX - locking there is utterly broken (for ages).

Fixes PR/43176.


# 1.179 24-Jun-2010 hannken

Clean up vnode lock operations pass 2:

VOP_UNLOCK(vp, flags) -> VOP_UNLOCK(vp): Remove the unneeded flags argument.

Welcome to 5.99.32.

Discussed on tech-kern.


# 1.178 08-Jun-2010 hannken

Procfs_lookup() does not lookup directory descriptors in the fd/
subdirectory. There is no need for recursive vnode locking here.

Ok: Christos Zoulas <christos@netbsd.org>


Revision tags: uebayasi-xip-base1 yamt-nfs-mp-base9 uebayasi-xip-base
# 1.177 08-Jan-2010 pooka

branches: 1.177.2; 1.177.4;
The VATTR_NULL/VREF/VHOLD/HOLDRELE() macros lost their will to live
years ago when the kernel was modified to not alter ABI based on
DIAGNOSTIC, and now just call the respective function interfaces
(in lowercase). Plenty of mix'n match upper/lowercase has creeped
into the tree since then. Nuke the macros and convert all callsites
to lowercase.

no functional change


Revision tags: matt-premerge-20091211 yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 jym-xensuspend-nbase
# 1.176 03-Jul-2009 elad

Where possible, extract the file-system's access() routine to two internal
functions: the first checking if the operation is possible (regardless of
permissions), the second checking file-system permissions, ACLs, etc.

Mailing list reference:

http://mail-index.netbsd.org/tech-kern/2009/06/21/msg005311.html


# 1.175 23-Jun-2009 elad

Move the implementation of vaccess() to genfs_can_access(), in line with
the other routines of the same spirit.

Adjust file-system code to use it.

Keep vaccess() for KPI compatibility and to keep element of least
surprise. A "diagnostic" message warning that vaccess() is deprecated will
be printed when it's used (obviously, only in DIAGNOSTIC kernels).

No objections on tech-kern@:

http://mail-index.netbsd.org/tech-kern/2009/06/21/msg005310.html


Revision tags: yamt-nfs-mp-base5
# 1.174 24-May-2009 ad

More changes to improve kern_descrip.c.

- Avoid atomics in more places.
- Remove the per-descriptor mutex, and just use filedesc_t::fd_lock.
It was only being used to synchronize close, and in any case we needed
to take fd_lock to free the descriptor slot.
- Optimize certain paths for the <NDFDFILE case.
- Sprinkle more comments and assertions.
- Cache more stuff in filedesc_t.
- Fix numerous minor bugs spotted along the way.
- Restructure how the open files array is maintained, for clarity and so
that we can eliminate the membar_consumer() call in fd_getfile(). This is
mostly syntactic sugar; the main functional change is that fd_nfiles now
lives alongside the open file array.

Some measurements with libmicro:

- simple file syscalls are like close() are between 1 to 10% faster.
- some nice improvements, e.g. poll(1000) which is ~50% faster.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 nick-hppapmap-base2 jym-xensuspend-base nick-hppapmap-base mjf-devfs2-base
# 1.173 17-Dec-2008 cegger

branches: 1.173.2;
kill MALLOC and FREE macros.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 haad-dm-base2 haad-nbase2 ad-audiomp2-base netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 haad-dm-base
# 1.172 05-Sep-2008 skrll

branches: 1.172.2;
PR/39324 kernel diagnostic assertion "l->l_stat != LSZOMB" failed.

Ignore procs with zero or all LSZOMB LWPs. Get a non-LSZOMB LWP to perform
operations against as part of the deal.

procfs really needs to be updated to support multi-threading fully.
Hi Antti!


# 1.171 05-Sep-2008 skrll

ANSIfy


Revision tags: simonb-wapbl-nbase simonb-wapbl-base
# 1.170 02-Jul-2008 rmind

branches: 1.170.2;
Remove proc_representative_lwp(), use a simple LIST_FIRST() instead.
OK by <ad>.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base
# 1.169 28-Apr-2008 martin

branches: 1.169.2; 1.169.4;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-nfs-mp-base
# 1.168 24-Apr-2008 ad

branches: 1.168.2;
Merge proc::p_mutex and proc::p_smutex into a single adaptive mutex, since
we no longer need to guard against access from hardware interrupt handlers.

Additionally, if cloning a process with CLONE_SIGHAND, arrange to have the
child process share the parent's lock so that signal state may be kept in
sync. Partially addresses PR kern/37437.


# 1.167 24-Apr-2008 ad

Network protocol interrupts can now block on locks, so merge the globals
proclist_mutex and proclist_lock into a single adaptive mutex (proc_lock).
Implications:

- Inspecting process state requires thread context, so signals can no longer
be sent from a hardware interrupt handler. Signal activity must be
deferred to a soft interrupt or kthread.

- As the proc state locking is simplified, it's now safe to take exit()
and wait() out from under kernel_lock.

- The system spends less time at IPL_SCHED, and there is less lock activity.


Revision tags: yamt-pf42-baseX yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14
# 1.166 21-Mar-2008 ad

branches: 1.166.2;
Catch up with descriptor handling changes. See kern_descrip.c revision
1.173 for details.


Revision tags: keiichi-mipv6-nbase nick-net80211-sync-base keiichi-mipv6-base bouyer-xeni386-nbase matt-armv6-nbase mjf-devfs-base hpcarm-cleanup-base
# 1.165 23-Jan-2008 elad

branches: 1.165.6;
Tons of process scope changes.

- Add a KAUTH_PROCESS_SCHEDULER action, to handle scheduler related
requests, and add specific requests for set/get scheduler policy and
set/get scheduler parameters.

- Add a KAUTH_PROCESS_KEVENT_FILTER action, to handle kevent(2) related
requests.

- Add a KAUTH_DEVICE_TTY_STI action to handle requests to TIOCSTI.

- Add requests for the KAUTH_PROCESS_CANSEE action, indicating what
process information is being looked at (entry itself, args, env,
open files).

- Add requests for the KAUTH_PROCESS_RLIMIT action indicating set/get.

- Add requests for the KAUTH_PROCESS_CORENAME action indicating set/get.

- Make bsd44 secmodel code handle the newly added rqeuests appropriately.

All of the above make it possible to issue finer-grained kauth(9) calls in
many places, removing some KAUTH_GENERIC_ISSUSER requests.

- Remove the "CAN" from KAUTH_PROCESS_CAN{KTRACE,PROCFS,PTRACE,SIGNAL}.

Discussed with christos@ and yamt@.


Revision tags: bouyer-xeni386-base matt-armv6-base
# 1.164 02-Jan-2008 ad

Merge vmlocking2 to head.


Revision tags: vmlocking2-base3 yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 vmlocking-nbase jmcneill-pm-base reinoud-bufcleanup-base
# 1.163 26-Nov-2007 pooka

branches: 1.163.2; 1.163.6;
Remove the "struct lwp *" argument from all VFS and VOP interfaces.
The general trend is to remove it from all kernel interfaces and
this is a start. In case the calling lwp is desired, curlwp should
be used.

quick consensus on tech-kern


Revision tags: bouyer-xenamd64-base2 bouyer-xenamd64-base
# 1.162 09-Nov-2007 christos

make the last argument of procfs_dir size_t


# 1.161 07-Nov-2007 ad

Merge from vmlocking:

- pool_cache changes.
- Debugger/procfs locking fixes.
- Other minor changes.


Revision tags: jmcneill-base yamt-x86pmap-base4 yamt-x86pmap-base3 vmlocking-base
# 1.160 10-Oct-2007 ad

branches: 1.160.2; 1.160.4;
Merge from vmlocking:

- Split vnode::v_flag into three fields, depending on field locking.
- simple_lock -> kmutex in a few places.
- Fix some simple locking problems.


# 1.159 08-Oct-2007 ad

Merge file descriptor locking, cwdi locking and cross-call changes
from the vmlocking branch.


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base2 yamt-x86pmap-base matt-mips64-base
# 1.158 22-Jul-2007 pooka

branches: 1.158.4; 1.158.6; 1.158.8; 1.158.10;
Don't allow getcwd() on procfs vnodes and provide "/" as the path
instead of the result from getcwd(). The works around locking
panics caused by namei calling VOP_READLINK while holding on to a
directory lock and getcwd() trying to acquire that lock. The real
fix would be to get rid of getcwd() calls within VOPs (not locking
safe), but that's not a viable option in the netbsd-4 timeframe.

Suggestion for workaround from David Holland.


Revision tags: nick-csl-alignment-base mjf-ufs-trans-base
# 1.157 24-May-2007 agc

branches: 1.157.2;
Extend the Linux emulation of /proc to include

/proc/stat
/proc/loadavg and
/proc/<pid>/statm.

These are only present when -o linux is specified as a mount option
to procfs.

Factor out some common code so that it can be used by a number of
functions.

XXX The values returned in the statm emulation need to be verified.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 1.156 04-Apr-2007 rmind

Unfortunately, missed procfs_proc_unlock() in previous.
Pointed out by pooka@


# 1.155 04-Apr-2007 rmind

procfs_readlink: Handle a possible fail of fd_getfile(), also, we
do not need to check for error again.
CID: 4436


# 1.154 09-Mar-2007 ad

branches: 1.154.2; 1.154.4;
- Make the proclist_lock a mutex. The write:read ratio is unfavourable,
and mutexes are cheaper use than RW locks.
- LOCK_ASSERT -> KASSERT in some places.
- Hold proclist_lock/kernel_lock longer in a couple of places.


# 1.153 04-Mar-2007 christos

Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.


# 1.152 03-Mar-2007 salo

Don't prepend rootvnode to the path in non-NULL case for exe links.
It breaks procfs in chroot.

from <christos>, tested by me.


Revision tags: ad-audiomp-base
# 1.151 19-Feb-2007 pooka

When checking for file validity under pid/, do proper proc->lwp
lookup (fsvo proper) instead of fiddling directly with the lwp
list.


# 1.150 18-Feb-2007 pooka

Don't check for validity of p in lookup for root nodes, since it
will always be NULL. Rather, just call pt_valid with NULL directly
and let it decide if we're a linux mount or not.


# 1.149 17-Feb-2007 pavel

Change the process/lwp flags seen by userland via sysctl back to the
P_*/L_* naming convention, and rename the in-kernel flags to avoid
conflict. (P_ -> PK_, L_ -> LW_ ). Add back the (now unused) LSDEAD
constant.

Restores source compatibility with pre-newlock2 tools like ps or top.

Reviewed by Andrew Doran.


# 1.148 16-Feb-2007 pooka

branches: 1.148.2;
In lookup, when checking for procfs process node validity, target the
process we're trying to get information about through procfs, not
the caller of lookup.

fixes 'ls -l /proc/*/file' panic, which would occur when trying to
lookup "file" for a kernel thread, which doesn't have p->p_textvp.


# 1.147 15-Feb-2007 ad

Need to acquire procp->p_mutex for procfs_dir().


# 1.146 11-Feb-2007 ad

Eliminate a couple of reference count and mutex leaks.


Revision tags: post-newlock2-merge
# 1.145 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 1.144 25-Dec-2006 elad

PR/35226: Johann Franz: Problems with permissions in
/usr/pkg/emul/linux/proc .

Okay mlelstv@


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3
# 1.143 09-Dec-2006 chs

a smorgasbord of improvements to vnode locking and path lookup:
- LOCKPARENT is no longer relevant for lookup(), relookup() or VOP_LOOKUP().
these now always return the parent vnode locked. namei() works as before.
lookup() and various other paths no longer acquire vnode locks in the
wrong order via vrele(). fixes PR 32535.
as a nice side effect, path lookup is also up to 25% faster.
- the above allows us to get rid of PDIRUNLOCK.
- also get rid of WANTPARENT (just use LOCKPARENT and unlock it).
- remove an assumption in layer_node_find() that all file systems implement
a recursive VOP_LOCK() (unionfs doesn't).
- require that all file systems supply vfs_vptofh and vfs_fhtovp routines.
fill in eopnotsupp() for file systems that don't support being exported
and remove the checks for NULL. (layerfs calls these without checking.)
- in union_lookup1(), don't change refcounts in the ISDOTDOT case, just
adjust which vnode is locked. fixes PR 33374.
- apply fixes for ufs_rename() from ufs_vnops.c rev. 1.61 to ext2fs_rename().


# 1.142 04-Dec-2006 christos

From Nicolas Joly: restore previous behavior in procfs_validfile_linux, since
readdir passes a NULL lwp.


# 1.141 03-Dec-2006 elad

Move kauth(9) call to where it belongs. Noticed by Nicolas Joly, thanks!


Revision tags: netbsd-4-base
# 1.140 28-Nov-2006 elad

branches: 1.140.2;
Move ktrace, ptrace, systrace, and procfs to use kauth(9).

First, remove process_checkioperm() calls from MD code. Similar checks
using kauth(9) routines (on the process scope, using appropriate action)
are done in the callers.

Add secmodel back-end to handle each subsystem.


# 1.139 25-Nov-2006 skrll

Expose the 'exe' symlink to the process realpath in NetBSD as well. An
example user is gdb.

OK'd by christos.


# 1.138 16-Nov-2006 christos

__unused removal on arguments; approved by core.


# 1.137 29-Oct-2006 christos

add an "emul" file node.


# 1.136 25-Oct-2006 christos

1. fix procfs_validfile{,_linux} to test for NULL pointers properly.
2. make "exe" entry be a symlink to the executable, instead of pointing
directly to the vnode of the executable.
3. factor out commonly used code.


Revision tags: yamt-splraiseipl-base2
# 1.135 12-Oct-2006 christos

- sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386


# 1.134 20-Sep-2006 manu

Emulate Linux's /proc/devices


Revision tags: abandoned-netbsd-4-base yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base rpaulo-netinet-merge-pcb-base
# 1.133 13-Jun-2006 yamt

branches: 1.133.6; 1.133.8;
use KAUTH_PROCESS_CANSEE rather than CURTAIN where appropriate.


# 1.132 13-Jun-2006 yamt

remove unnecessary arguments from kauth_authorize_process.
ie. make it similar to the one found in apple TN.


# 1.131 07-Jun-2006 kardel

merge FreeBSD timecounters from branch simonb-timecounters
- struct timeval time is gone
time.tv_sec -> time_second
- struct timeval mono_time is gone
mono_time.tv_sec -> time_uptime
- access to time via
{get,}{micro,nano,bin}time()
get* versions are fast but less precise
- support NTP nanokernel implementation (NTP API 4)
- further reading:
Timecounter Paper: http://phk.freebsd.dk/pubs/timecounter.pdf
NTP Nanokernel: http://www.eecis.udel.edu/~mills/ntp/html/kern.html


Revision tags: yamt-pdpolicy-base5 simonb-timecounters-base
# 1.130 14-May-2006 elad

branches: 1.130.2;
integrate kauth.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 elad-kernelauth-base yamt-pdpolicy-base yamt-uio_vmspace-base5
# 1.129 02-Feb-2006 christos

branches: 1.129.2; 1.129.4; 1.129.6; 1.129.8;
PR/32692: Matthew Mondor: linux compatibility in /proc/self should point
directly to the directory containing the pid instead of pointing to
/proc/curproc, because some programs rely on calling readlink on /proc/self
to get the pid.


# 1.128 11-Dec-2005 christos

branches: 1.128.2; 1.128.4;
merge ktrace-lwp.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base ktrace-lwp-base
# 1.127 02-Nov-2005 yamt

merge yamt-vop branch. remove following VOPs.

VOP_BLKATOFF
VOP_VALLOC
VOP_BALLOC
VOP_REALLOCBLKS
VOP_VFREE
VOP_TRUNCATE
VOP_UPDATE


Revision tags: yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 1.126 01-Oct-2005 atatat

branches: 1.126.2;
Add "cwd" and "root" symlinks to each process's directory. The cwd
link points to the process's current working directory, and the root
link points to the process's root directory. What else would you
expect?

For directories that are out of reach (caller is in a chroot, target
process is in a different chroot, etc), the links point to "/"
instead.


# 1.125 11-Sep-2005 elad

Implement curtain for procfs.


# 1.124 30-Aug-2005 xtraeme

Remove __P()


# 1.123 29-May-2005 christos

branches: 1.123.2;
- sprinkle const
- avoid shadowed variables.


Revision tags: kent-audio2-base
# 1.122 02-Apr-2005 christos

PR/29782: Martin Husemann: procfs can not unmount when some process has its
current directory in curproc. Fix from Pedro Martelletto:
We cannot call vgone() from procfs_inactive() if we are coming from
vclean(). that's what's probably causing the deadlock.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 yamt-km-base4 yamt-km-base3 netbsd-3-base
# 1.121 26-Feb-2005 perry

nuke trailing whitespace


Revision tags: yamt-km-base2 yamt-km-base kent-audio1-beforemerge kent-audio1-base
# 1.120 04-Oct-2004 yamt

branches: 1.120.4; 1.120.6;
procfs_readdir:
- return correct cookie when buffer size is small.
- simplify logic.


# 1.119 04-Oct-2004 yamt

procfs_readdir: remove a redundant assignment.


# 1.118 02-Oct-2004 yamt

procfs_getattr: correct size of /proc/self.


# 1.117 01-Oct-2004 yamt

procfs_readdir:
- fix a locking problem, using proclist_foreach_call. PR/27098.
- correct snprintf size argument.


# 1.116 01-Oct-2004 yamt

procfs_readdir: fix an offset handling bug after addition of /proc/self.


# 1.115 01-Oct-2004 yamt

procfs_readdir: use a list macro.


# 1.114 20-Sep-2004 jdolecek

add 'mounts' file for -o linux, which lists all currently mounted
filesystems; Linux glibc statvfs() uses this to get some of mount flags,
and this file is also useful as /emul/linux/etc/mtab (via symlink)


# 1.113 29-Apr-2004 jrf

Removed remaining caddr_t casts we do not need in miscfs. Recompiled
kernel and ran for a day or so. There are still some caddr_t types in
the arguments of some calls, I will do those separately (later) as
they touch a lot more of the system.
Approved by christos@NetBSD.org.


# 1.112 22-Apr-2004 itojun

sprintf -> snprintf


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.111 15-Feb-2004 jdolecek

unlock the descriptor table simple lock after fd_getfile() call in
procfs_readdir()
fixes procfs locking problems reported on current-users@, problem place
found by enami tsugutomo


# 1.110 30-Oct-2003 simonb

Remove some assigned-to but otherwise unused variables.


# 1.109 27-Sep-2003 darcy

Changes as discussed with itojun on tech-kern. I have modified the enums
to have KFS or PFS differentiators. Further I have wrapped the enum in
procfs in "#ifdef _KERNEL" as it is done in kernfs.

To see the discussion go to http://mail-index.NetBSD.org/tech-kern/2003/09/
and look for "Mismatched enums in include files" in the list.


# 1.108 07-Sep-2003 itojun

remove meaningless line (variable overwritten 2 lines below)


# 1.107 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.


# 1.106 29-Jun-2003 fvdl

branches: 1.106.2;
Back out the lwp/ktrace changes. They contained a lot of colateral damage,
and need to be examined and discussed more.


# 1.105 29-Jun-2003 thorpej

Undo part of the ktrace/lwp changes. In particular:
* Remove the "lwp *" argument that was added to vget(). Turns out
that nothing actually used it!
* Remove the "lwp *" arguments that were added to VFS_ROOT(), VFS_VGET(),
and VFS_FHTOVP(); all they did was pass it to vget() (which, as noted
above, didn't use it).
* Remove all of the "lwp *" arguments to internal functions that were added
just to appease the above.


# 1.104 28-Jun-2003 darrenr

Pass lwp pointers throughtout the kernel, as required, so that the lwpid can
be inserted into ktrace records. The general change has been to replace
"struct proc *" with "struct lwp *" in various function prototypes, pass
the lwp through and use l_proc to get the process pointer when needed.

Bump the kernel rev up to 1.6V


# 1.103 28-May-2003 christos

Add /proc/<pid>/stat for linux compat. j2sdk1.4.2 depends on it.


# 1.102 18-Apr-2003 christos

Make symlinks for directories that point to the actual directory.
Make symlinks to [kqueue] and [misc] for kqueue and misc fds.


# 1.101 17-Apr-2003 jdolecek

do not show nodes corresponding to directory descriptors for process
in fd/ subdirectory, nor allow lookup/open for the nodes
this fixes PR kern/21187 for good, and also avoids interesting directory
locking issues


# 1.100 17-Apr-2003 jdolecek

procfs_readdir(): in Pfd case, only show descriptors of types we want
how to represent (vnodes, fifo, pipes); also use fd_getfile() et al

this avoids annoying EOPNOTSUPP error messages from ls -F and such


# 1.99 17-Apr-2003 jdolecek

procfs_lookup(): use fd_getfile() et al in Pfd case


# 1.98 17-Apr-2003 jdolecek

use fd_getfile() in procfs_getfp(), and FILE_USE()/FILE_UNUSE() the
returned file descriptor pointer appropriately


# 1.97 17-Apr-2003 jdolecek

make some local arrays/variables static + const


# 1.96 10-Apr-2003 jdolecek

use former genfs_eopnotsupp_rele() as genfs_eopnotsupp(), so that vnodes
are vput()/vrele()d as necessary - some filesystems did use the wrong
one for some ops, and it's just safer to not take the chance

based on suggestion by Bill Studenmund


# 1.95 05-Apr-2003 dsl

Remove pointless check against PID_MAX. Let pfind() do the validation.
(The new pid allocation code may decide to allocate pids above PID_MAX.)


# 1.94 25-Feb-2003 jrf

This addresses PR kerm/19989. Thanks to hamajima@nagoya.ydc.co.jp for submitting this patch which enables /proc/uptime for linux emul. Patch reviewed by atatat@netbsd.org and tron@netbsd.org, approved by tron@netbsd.org.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 1.93 04-Jan-2003 martin

Cast off_t expression to long long to match format even on 64 bit
plattforms.

Shouldn't we introduce a PRIoff_t macro to create such format strings?


# 1.92 03-Jan-2003 christos

add LK_CANRECURSE in the locking of /dev/<pid>/fd/<n> and remove the curproc
kludge. Thanks to fvdl.


# 1.91 03-Jan-2003 christos

Implement /proc/<pid>/fd/<n>. This is work in progress. Questionable things:
- Is it ok to convert DTYPE_PIPE to VFIFO and DTYPE_SOCKET to VSOCK?
- XXX: Avoid locking issue in ls -Rl /proc by avoiding curproc
- Does I/O to pipes work?
- XXX: Are there security implications?


Revision tags: fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge gehenna-devsw-base kqueue-base
# 1.90 03-Aug-2002 simonb

Just use the "time" variable in the *_getattr functions instead of a call
to (the potentially expensive) microtime().


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.89 09-May-2002 thorpej

branches: 1.89.2;
Move code shared by procfs and the kernel proper out of procfs and
into the kernel proper (renaming functions from procfs_* to process_*).


Revision tags: eeh-devprop-base newlock-base ifpoll-base
# 1.88 12-Jan-2002 christos

Don't hide the real return code with EPERM.


# 1.87 06-Dec-2001 chs

add a VOP_PUTPAGES method for all the filesystems that don't have pages,
just unlock the interlock.


# 1.86 05-Dec-2001 thorpej

* Allow machine-dependent code to specify hooks for ptrace(2)
(__HAVE_PTRACE_MACHDEP) and procfs (__HAVE_PROCFS_MACHDEP).
These changes will allow platforms like x86 (XMM) and PowerPC
(AltiVec) to export extended register sets in a sane manner.

* Use __HAVE_PTRACE_MACHDEP to export x86 XMM registers (standard
FP + SSE/SSE2) using PT_{GET,SET}XMMREGS (in the machdep
ptrace request space).
* Use __HAVE_PROCFS_MACHDEP to export x86 XMM registers via
/proc/N/xmmregs in procfs.


Revision tags: thorpej-mips-cache-base
# 1.85 10-Nov-2001 lukem

add RCSIDs


# 1.84 06-Nov-2001 simonb

Remove some variables that are set but never used.


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base
# 1.83 31-Aug-2001 chs

branches: 1.83.2; 1.83.4;
map files are zero-length.


# 1.82 03-Jun-2001 chs

branches: 1.82.2;
procfs_bmap() should never be called, make it a "bad op".
let procfs_mmap() use the default error method.


Revision tags: thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 1.81 14-Apr-2001 kleink

In procfs_readdir(), give /proc/# directories DT_DIR (rather than DT_REG).


# 1.80 30-Mar-2001 fvdl

Bump va_blocksize for the map files some more, so that programs with
quite a few mappings have a chance of being handled correctly if
st_blksize is looked at.


# 1.79 29-Mar-2001 fvdl

For -o linux mounts, add some code to emulate /proc/#/maps.
Needs NAMECACHE_ENTER_REVERSE to include filenames.


# 1.78 21-Feb-2001 jdolecek

branches: 1.78.2;
make some more constant arrays 'const'


# 1.77 22-Jan-2001 jdolecek

make filesystem vnodeop, specop, fifoop and vnodeopv_* arrays const


# 1.76 17-Jan-2001 fvdl

Add a few linux-style files, only enabled when -o linux is specified
for the mount. Currently these are /proc/cpuinfo and /proc/meminfo.
The former only does something on i386 right now.


# 1.75 24-Nov-2000 chs

remove dead code and other misc cleanup.


# 1.74 09-Aug-2000 tv

Only show the "exe" entry to Linux processes, suggested by christos.
Since there are actually three struct emul's for linux, use the e_name
field to determine eligibility with strcmp().


# 1.73 09-Aug-2000 tv

Some versions of Linux libc look for /proc/.../exe instead of /proc/../file.
Add an entry for "exe" that is the same as "file", provided only if
COMPAT_LINUX is set.


# 1.72 03-Aug-2000 thorpej

MALLOC()/FREE() are not to be used for variable sized allocations.


# 1.71 28-Jun-2000 mrg

<vm/vm.h> -> <uvm/uvm_extern.h>


Revision tags: netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 1.70 30-Mar-2000 simonb

branches: 1.70.4;
Delete duplicate declaration of atopid().


Revision tags: chs-ubc2-newbase wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base fvdl-softdep-base
# 1.69 02-Sep-1999 thorpej

branches: 1.69.2; 1.69.8;
Make /proc/self a symlink to /proc/curproc. I've observed Linux programs
that expect /proc/self/cmdline to exist.


# 1.68 25-Aug-1999 sommerfeld

Change variable used for directory offset from "int" to "off_t".
Overkill, but avoids a host of truncation problems.


# 1.67 24-Aug-1999 sommerfeld

Fix PR8270:

Problem turned out to be due to improper handling of reads beyond EOF:
they should just return without error with the uio unchanged, and the
caller will recognize this as a zero-byte return (EOF).

The previous fix to protect directory reads against bogus uio_offset
values returned EINVAL, which broke mount -o union, which only
union'ed in the lower directory if the upper directory cleanly
returned EOF.

While we're here, protect kernfs as well.


# 1.66 14-Aug-1999 christos

protect against large uio_offset


# 1.65 03-Aug-1999 wrstuden

Add support for fcntl(2) to generate VOP_FCNTL calls. Any fcntl
call with F_FSCTL set and F_SETFL calls generate calls to a new
fileop fo_fcntl. Add genfs_fcntl() and soo_fcntl() which return 0
for F_SETFL and EOPNOTSUPP otherwise. Have all leaf filesystems
use genfs_fcntl().

Reviewed by: thorpej
Tested by: wrstuden


Revision tags: chs-ubc2-base
# 1.64 25-Jul-1999 thorpej

Add calls to lock the proclist as appropriate.


# 1.63 14-Jul-1999 thorpej

Fix a paste-o in procfs_lookup() introduced with the vnode locking changes.
Fixes PR #7961, Mario Kemper <magick@bundy.lip.owl.de>.


# 1.62 08-Jul-1999 wrstuden

Bump osrelease to 1.4E. Add layerfs files, remove null_subr.c.

Update coda to new struct lock in struct vnode.

make fdescfs, kernfs, portalfs, and procfs actually lock their vnodes.
It's not that hard.

Make unionfs set v_vnlock = NULL so any overlayed fs will call its
VOP_LOCK.


Revision tags: kame_141_19991130 netbsd-1-4-PATCH001 kame_14_19990705 kame_14_19990628 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.61 12-Mar-1999 christos

branches: 1.61.2; 1.61.4;
PR/7143: Jaromir Docelek: Add procfs/cmdline from Linux emulation


# 1.60 25-Jan-1999 msaitoh

Add /proc/#/map. From FreeBSD.


Revision tags: kenh-if-detach-base chs-ubc-base
# 1.59 08-Sep-1998 thorpej

- Use proclists[], rather than checking allproc and zombproc explicitly.
- Add some comments about locking.


# 1.58 13-Aug-1998 kleink

Per POSIX, fail with EINVAL if advisory locking is attempted on a file type
that doesn't support it, rather than using a homegrown EBADF or EOPNOTSUPP.


# 1.57 10-Aug-1998 matthias

create miscfs/genfs/genfs_vnops.c:genfs_enoioctl and make all the other
filesystems use it instead of a private version.


# 1.56 09-Aug-1998 perry

bzero->memset, bcopy->memcpy, bcmp->memcmp


# 1.55 03-Aug-1998 kleink

Recognize _PC_SYNC_IO.


Revision tags: eeh-paddr_t-base
# 1.54 21-Apr-1998 fvdl

procfs_readdir: in case of error, check if cookies actually have
been allocated before freeing them. From Wolfgang Solfrank.


# 1.53 01-Mar-1998 fvdl

Merge with Lite2 + local changes


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base marc-pcmcia-base
# 1.52 10-Oct-1997 fvdl

Bump last argument to VOP_READDIR to off_t (from u_long).


Revision tags: thorpej-signal-base
# 1.51 27-Aug-1997 thorpej

Fix a reversed argument which caused procfs_checkioperm() to always return
"OK". Add a few comments to avoid further confusion.


# 1.50 12-Aug-1997 thorpej

Fix the procfs hole described on current-users, similar to a fix for
FreeBSD by Sean Eric Fagan, but a bit different. This makes the checks
in the same places as sef's FreeBSD patch, but does not hardcode the
"kmem" group into the kernel, and also does a check identical to the
(3) and (4) checks in the NetBSD ptrace(2):

(1) it's not owned by you, or is set-id on exec (unless
you're root), or

(2) it's init, which controls the security level of the
entire system, and the system was not compiled with
permanently insecure mode turned on.


Revision tags: marc-pcmcia-bp
# 1.49 08-May-1997 mycroft

branches: 1.49.4;
Pass the vnode type to vaccess(), and use it when checking VEXEC. Make sure
that the mode bits passed to vaccess() and returned by foo_getattr() contain
only permission bits.


# 1.48 05-May-1997 mycroft

Need stat.h.


# 1.47 05-May-1997 mycroft

Eliminate bogus uses of V{READ,WRITE,EXEC}. Use S_I[RWX]{USR,GRP,OTH} where
appropriate.


# 1.46 28-Apr-1997 mycroft

Minor code cleanup.


Revision tags: is-newarp-before-merge is-newarp-base
# 1.45 25-Oct-1996 cgd

define path name string variables that we should not (and, thankfully, do
not) modify as 'const char *' rather 'char *'.


# 1.44 13-Oct-1996 christos

backout previous kprintf changes


# 1.43 10-Oct-1996 christos

printf -> kprintf, sprintf -> ksprintf


# 1.42 07-Sep-1996 mycroft

Implement poll(2).


# 1.41 01-Sep-1996 mycroft

Add a set of generic file system operations that most file systems use.
Also, fix some time stamp bogosities.


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 1.40 16-Mar-1996 christos

Fix printf format follies.


# 1.39 13-Feb-1996 mycroft

GC *_nullop(). Minor nits.


# 1.38 12-Feb-1996 christos

close PR/2063: procfs_rw prototyped twice with different prototypes


# 1.37 09-Feb-1996 christos

miscfs prototype changes


# 1.36 09-Feb-1996 mycroft

Fix vop_link, vop_symlink, and vop_remove semantics in several ways:
* Change the argument names to vop_link so they actually make sense.
* Implement vop_link and vop_symlink for all file systems, so they do proper
cleanup.
* Require the file system to decide whether or not linking and unlinking of
directories is allowed, and disable it for all current file systems.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.35 09-Oct-1995 mycroft

Use the index number as the cookie, rather than multiplying by UIO_MX.


# 1.34 09-Oct-1995 mycroft

Add support for cookies, mostly from Greg Hudson.


# 1.33 15-Apr-1995 cgd

fix timeval vs. timespec warnings


# 1.32 03-Feb-1995 mycroft

Return EROFS rather than ENOENT in many cases. Also some cosmetic cleanup.


# 1.31 27-Dec-1994 mycroft

Format police.


# 1.30 24-Dec-1994 ws

Implement and use a common access checking routine


# 1.29 14-Dec-1994 mycroft

Remove a_fp.


# 1.28 14-Nov-1994 christos

fixed struct comment


# 1.27 30-Oct-1994 cgd

be more careful with types, also pull in headers where necessary.


# 1.26 20-Oct-1994 cgd

update for new syscall args description mechanism


# 1.25 30-Aug-1994 mycroft

Convert process, file, and namei lists and hash tables to use queue.h.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.24 29-Jun-1994 cgd

New RCS ID's, take two. they're more aesthecially pleasant, and use 'NetBSD'


# 1.23 16-Jun-1994 mycroft

Remove an unneeded test.


# 1.22 15-Jun-1994 mycroft

Minor update from JSP after merging my changes.


# 1.21 08-Jun-1994 mycroft

Update to 4.4-Lite fs code, with local changes.


# 1.20 05-May-1994 cgd

lots of changes: prototype migration, move lots of variables, definitions,
and structure elements around. kill some unnecessary type and macro
definitions. standardize clock handling. More changes than you'd want.


# 1.19 15-Apr-1994 cgd

forgot these...


# 1.18 12-Apr-1994 cgd

be a bit smarter about determining if files shouldn't be seen by the user.
Also, DON'T allow a lookup to succeed on a file that's not visible!


# 1.17 15-Feb-1994 mycroft

Undo last change; executables is `file', not `a.out'.


# 1.16 14-Feb-1994 ws

Rename file -> a.out


# 1.15 14-Feb-1994 ws

Don't try to show a file for a process if there is none


# 1.14 28-Jan-1994 cgd

make a fpregs file.


# 1.13 20-Jan-1994 ws

Make procfs really work for debugging.
Implement not & notepg files in procfs.


# 1.12 09-Jan-1994 ws

Bug fixes and enhancements:
Make NFS serving work (BUT DON'T USE "attach" TO /proc/*/ctl FOR NOW!!!)
Make `curproc' a symbolic link
Add `.' and `..' entries to the directories.
Return better guesses on the size of the files.


# 1.11 05-Jan-1994 cgd

return size of 'reg' from getattr()


# 1.10 05-Jan-1994 cgd

make it compile (cleanly) for us


# 1.9 05-Jan-1994 cgd

add new procfs code, from Jan-Simon Pendry, jsp@sequent.com.
This is pretty-much "virgin", so that diffs can be done later.


# 1.8 18-Dec-1993 mycroft

Canonicalize all #includes.


Revision tags: magnum-base
# 1.7 16-Sep-1993 cgd

kill volatile warning.


# 1.6 07-Sep-1993 ws

branches: 1.6.2;
Changes to VFS readdir semantics
NFS changes for better cookie support
ISOFS changes for better Rockridge support and support for generation numbers


# 1.5 26-Aug-1993 pk

Implement setattr: mode for process entries; mode + uid/gid for the
PROCFS root directory.
Fixed omission in pfs_root() which came to light as a result of the above:
hold on to vnode for root dir.


# 1.4 25-Aug-1993 pk

Fixed improperly initialized nfsnode in pfs_lookup()


# 1.3 24-Aug-1993 pk

copyright update.


# 1.2 24-Aug-1993 pk

Rcs Id added.


# 1.1 24-Aug-1993 pk

branches: 1.1.1;
Initial version of a proc filesystem.


# 1.227 17-Jan-2022 bouyer

If the calling process is running under linux emulation, make /proc/xxx/fd/
return only symlinks pointing to the original file in the filesystem,
instead of a hard link. This matches the linux behavior, and some
linux programs relies on it (they unconditionally call readlink() on
/proc/xxx/fd/yy and don't deal with it returning EINVAL).
Proposed on tech-kern@ in
http://mail-index.netbsd.org/tech-kern/2022/01/11/msg027877.html


# 1.226 14-Jan-2022 christos

Fix emul and exe DT_ types (from RVP, as was the previous commit)


# 1.225 14-Jan-2022 christos

Put the appropriate DT_ constant in the dirent structure depending on the
file type.


# 1.224 11-Jan-2022 christos

remove redundant error initialization and break earlier. (from rvp)


# 1.223 11-Jan-2022 hannken

Use a single "p" variable.

Should fix PR kern/56614: kernel panic on tmux


# 1.222 10-Jan-2022 christos

use a single nc variable.


# 1.221 10-Jan-2022 christos

Fix locking in the error path (from RVP). Centralize unlock code.


# 1.220 08-Dec-2021 andvar

s/efficent/efficient/ in comments.


# 1.219 05-Oct-2021 christos

PR/53299: RVP: kernfs and procfs are broken when sysctl security.curtain
is enabled


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base thorpej-i2c-spi-conf-base
# 1.218 18-Jul-2021 dholland

Abolish all the silly indirection macros for initializing vnode ops tables.

These are things of the form #define foofs_op genfs_op, or #define
foofs_op genfs_eopnotsupp, or similar. They serve no purpose besides
obfuscation, and have gotten cutpasted all over everywhere.


# 1.217 29-Jun-2021 dholland

- Add a new vnode op: VOP_PARSEPATH.
- Move namei_getcomponent to genfs_vnops.c and call it genfs_parsepath.
- Add a parsepath entry to every vnode ops table.

VOP_PARSEPATH takes a directory vnode to be searched and a complete
following path and chooses how much of that path to consume. To begin
with, all parsepath calls are genfs_parsepath, which locates the first
'/' as always.

Note that the call doesn't take the whole struct componentname, only
the string. The other bits of struct componentname should not be
needed and there's no reason to cause potential complications by
exposing them.


# 1.216 28-Jun-2021 chs

VOP_BMAP() may be called via ioctl(FIOGETBMAP) on any vnode that applications
can open. change various pseudo-fs *_bmap methods return an error instead of
panic.

Reported-by: syzbot+8289a3eaf2ba60958c87@syzkaller.appspotmail.com


Revision tags: cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base thorpej-cfargs-base thorpej-futex-base
# 1.215 27-Jun-2020 christos

branches: 1.215.6;
Introduce genfs_pathconf() and use it for the default case in all filesystems.


# 1.214 23-May-2020 ad

Move proc_lock into the data segment. It was dynamically allocated because
at the time we had mutex_obj_alloc() but not __cacheline_aligned.


# 1.213 16-May-2020 christos

Add ACL support for FFS. From FreeBSD.


# 1.212 29-Apr-2020 thorpej

If the procfs mount is marked as linux-compat, then allow proc lookup
by any LWP ID in the proc, not just the canonical PID.


Revision tags: bouyer-xenpvh-base2
# 1.211 21-Apr-2020 ad

Revert the changes made in February to make cwdinfo use mostly lockless,
which relied on taking extra vnode refs.

Having benchmarked various experimental changes over the past few months it
seems that it's better to avoid vnode refs as much as possible. cwdi_lock
as a RW lock already did that to some extent for getcwd() and will permit
the same for namei() too.


Revision tags: phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base is-mlppp-base phil-wifi-20200406 ad-namecache-base3
# 1.210 24-Feb-2020 ad

branches: 1.210.4;
v_interlock -> vmobjlock


# 1.209 23-Feb-2020 ad

Merge from ad-namecache:

- Have a stab at clustering the members of vnode_t and vnode_impl_t in a
more cache-conscious way. With that done, go back to adjusting v_usecount
with atomics and keep vi_lock directly in vnode_impl_t (saves KVA).

- Allow VOP_LOCK(LK_NONE) for the benefit of VFS_VGET() and VFS_ROOT().
Make sure LK_UPGRADE always comes with LK_NOWAIT.

- Make cwdinfo use mostly lockless.


# 1.208 01-Feb-2020 riastradh

Load struct filedesc::fd_dt with atomic_load_consume.

Exceptions: when fd_refcnt <= 1, or when holding fd_lock.

While here:

- Restore KASSERT(mutex_owned(&fdp->fd_lock)) in fd_unused.
=> This is used only in fd_close and fd_abort, where it holds.
- Move bounds check assertion in fd_putfile to where it matters.
- Store fd_dt with atomic_store_release.
- Move load of fd_dt under lock in knote_fdclose.
- Omit membar_consumer in fdesc_readdir.
=> atomic_load_consume serves the same purpose now.
=> Was needed only on alpha anyway.


Revision tags: ad-namecache-base2 ad-namecache-base1 ad-namecache-base phil-wifi-20191119
# 1.207 29-Aug-2019 hannken

branches: 1.207.2;
Add missing operation VOP_GETPAGES() returning EFAULT.

Without this operation posix_fadvise(..., POSIX_FADV_WILLNEED)
would leave the v_interlock held.

Observed by maxv@


Revision tags: netbsd-9-base phil-wifi-20190609 isaki-audio2-base
# 1.206 30-Mar-2019 christos

branches: 1.206.4;
add a node for the process resource limits.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020
# 1.205 14-Oct-2018 jdolecek

remove M_CANFAIL flag for malloc(9) - it was completely ignored, so had
actually no effect


Revision tags: pgoyette-compat-0930 pgoyette-compat-0906
# 1.204 03-Sep-2018 riastradh

Rename min/max -> uimin/uimax for better honesty.

These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER! Some subsystems have

#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)


Revision tags: pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415
# 1.203 07-Apr-2018 hannken

branches: 1.203.2;
Lock the target cwdi and take an additional reference to the
vnode we are interested in to prevent it from disappearing
before getcwd_common().

Should fix PR kern/53096 (netbsd-8 crash on heavy disk I/O)


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.202 31-Dec-2017 christos

branches: 1.202.2;
Add an environ node


Revision tags: tls-maxphys-base-20171202
# 1.201 01-Dec-2017 christos

Allow procfs_kqfilter, since we allow poll. "go" does it.


# 1.200 08-Nov-2017 christos

fix locking, remove error(1) comments.


# 1.199 08-Nov-2017 christos

use p->p_path, remove unused code.


# 1.198 28-Aug-2017 kamil

Remove the filesystem tracing feature

This is a legacy interface from 4.4BSD, and it was
introduced to overcome shortcomings of ptrace(2) at that time, which are
no longer relevant (performance). Today /proc/#/ctl offers a narrow
subset of ptrace(2) commands and is not applicable for modern
applications use beyond simplistic tracing scenarios.

This removal will simplify kernel internals. Users will still be able to
use all the other /proc files.

This change won't affect other procfs files neither Linux compat
features within mount_procfs(8). /proc/#/ctl isn't available on Linux.

Remove:
- /proc/#/ctl from mount_procfs(8)
- P_FSTRACE note from the documentation of ps(1)
- /proc/#/ctl and filesystem tracing documentation from mount_procfs(8)
- KAUTH_REQ_PROCESS_PROCFS_CTL documentation from kauth(9)
- source code file miscfs/procfs/procfs_ctl.c
- PFSctl and procfs_doctl() from sys/miscfs/procfs/procfs.h
- KAUTH_REQ_PROCESS_PROCFS_CTL from sys/sys/kauth.h
- PSL_FSTRACE (0x00010000) from sys/sys/proc.h
- P_FSTRACE (0x00010000) from sys/sys/sysctl.h

Reduce code complexity after removal of this functionality.

Update TODO.ptrace accordingly: remove two entries about /proc tracing.

Do not keep legacy notes as comments in the headers about removed
PSL_FSTRACE / P_FSTRACE, as this interface had little number of users
(close or equal to zero).

Proposed on tech-kern@.

All filesystem tracing utility users are encouraged to switch to ptrace(2).

Sponsored by <The NetBSD Foundation>


Revision tags: matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base
# 1.197 26-May-2017 riastradh

branches: 1.197.2;
Make VOP_RECLAIM do the last unlock of the vnode.

VOP_RECLAIM naturally has exclusive access to the vnode, so having it
locked on entry is not strictly necessary -- but it means if there
are any final operations that must be done on the vnode, such as
ffs_update, requiring exclusive access to it, we can now kassert that
the vnode is locked in those operations.

We can't just have the caller release the last lock because some file
systems don't use genfs_lock, and require the vnode to remain valid
for VOP_UNLOCK to work, notably unionfs.


Revision tags: prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.196 11-Apr-2017 riastradh

Make VOP_INACTIVE preserve vnode lock on return.

Discussed on tech-kern:
https://mail-index.netbsd.org/tech-kern/2017/04/01/msg021751.html

Ride 7.99.68, a bumpy bus of incremental vfs improvements!


Revision tags: jdolecek-ncq-base
# 1.195 30-Mar-2017 christos

add an auxv node.


Revision tags: pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004 localcount-20160914
# 1.194 20-Aug-2016 hannken

branches: 1.194.2;
Remove now obsolete operation vcache_remove().

Welcome to 7.99.36


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 nick-nhusb-base-20150921 nick-nhusb-base-20150606
# 1.193 20-Apr-2015 riastradh

branches: 1.193.2;
Make VOP_LINK return directory still locked and referenced.

Ride 7.99.10 bump.


Revision tags: nick-nhusb-base-20150406 nick-nhusb-base
# 1.192 05-Sep-2014 matt

branches: 1.192.2;
Try not to use f_data, use f_{vnode,socket,pipe,mqueue,kqueue,ksem} to get
a correctly typed pointer.


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.191 27-Jul-2014 hannken

branches: 1.191.2; 1.191.4; 1.191.8;
Change procfs from hashlist to vcache.
- Key is (type, pid, fd)
- Remove argument "p" from procfs_allocvp(). It is only used
when "type == PFSfd". Lookup the proc with proc_find() when
procfs_loadvnode() needs it.
- Use a vfs_vnode_iterator for procfs_revoke_vnodes().


# 1.190 25-Jul-2014 dholland

Add VOP_FALLOCATE and VOP_FDISCARD to every vnode ops table I can
find.

The filesystem ones all call genfs_eopnotsupp - right now I am only
implementing the plumbing and we can implement fallocate and/or
fdiscard for files later.

The device ones call spec_fallocate (which is also genfs_eopnotsupp)
and spec_fdiscard, which dispatches to the device-level op.

The fifo ones all call vn_fifo_bypass, which also ends up being
EOPNOTSUPP.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base
# 1.189 07-Feb-2014 hannken

branches: 1.189.2;
Change vnode operation lookup to return the resulting vnode *vpp unlocked.
Change cache_lookup() to return an unlocked vnode.

Discussed on tech-kern@

Welcome to 6.99.31


# 1.188 23-Jan-2014 hannken

Change vnode operations create, mknod, mkdir and symlink to return
the resulting vnode *vpp unlocked.

Discussed on tech-kern@

Welcome to 6.99.30


# 1.187 17-Jan-2014 hannken

Change vnode operations create, mknod, mkdir and symlink to keep the
directory node dvp locked on return.

Discussed on tech-kern@

Welcome to 6.99.29


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base
# 1.186 18-Mar-2013 plunky

branches: 1.186.6;
C99 section 6.7.2.3 (Tags) Note 3 states that:

A type specifier of the form

enum identifier

without an enumerator list shall only appear after the type it
specifies is complete.

which means that we cannot pass an "enum vtype" argument to
kauth_access_action() without fully specifying the type first.
Unfortunately there is a complicated include file loop which
makes that difficult, so convert this minimal function into a
macro (and capitalize it).

(ok elad@)


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 1.185 25-Nov-2012 christos

do something reasonable with kernel semaphores.


Revision tags: yamt-pagecache-base6 jmcneill-usbmp-base10
# 1.184 28-May-2012 christos

branches: 1.184.2;
add a task process subdirectory for emul linux


Revision tags: yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 1.183 13-Mar-2012 elad

Replace the remaining KAUTH_GENERIC_ISSUSER authorization calls with
something meaningful. All relevant documentation has been updated or
written.

Most of these changes were brought up in the following messages:

http://mail-index.netbsd.org/tech-kern/2012/01/18/msg012490.html
http://mail-index.netbsd.org/tech-kern/2012/01/19/msg012502.html
http://mail-index.netbsd.org/tech-kern/2012/02/17/msg012728.html

Thanks to christos, manu, njoly, and jmmv for input.

Huge thanks to pgoyette for spinning these changes through some build
cycles and ATF.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.182 04-Sep-2011 jmcneill

branches: 1.182.2; 1.182.6;
PR# kern/45021: Please support /emul/linux/proc/version

Add /proc/version for procfs with -o linux. The version reported depends
on the emulation type of the calling process:

$ cat /proc/version
NetBSD version 5.99.55 (netbsd@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) NetBSD 5.99.55 (GENERIC) #39: Sun Sep 4 09:10:05 EDT 2011

$ /emul/linux/bin/cat /proc/version
Linux version 2.6.18 (linux@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) #0 Wed Mar 3 03:03:03 PST 2010

$ /emul/linux32/bin/cat /proc/version
Linux version 2.6.18 (linux32@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) #0 Wed Mar 3 03:03:03 PST 2010


# 1.181 23-Jun-2011 christos

From Aleksey Cheusov: Don't make it easy for compromised systems to bypass
ASLR protections by providing the mapping addresses of programs to everyone.


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base matt-mips64-premerge-20101231 uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10 rmind-uvmplock-base
# 1.180 01-Jul-2010 rmind

Remove pfind() and pgfind(), fix locking in various broken uses of these.
Rename real routines to proc_find() and pgrp_find(), remove PFIND_* flags
and have consistent behaviour. Provide proc_find_raw() for special cases.
Fix memory leak in sysctl_proc_corename().

COMPAT_LINUX: rework ptrace() locking, minimise differences between
different versions per-arch.

Note: while this change adds some formal cosmetics for COMPAT_DARWIN and
COMPAT_IRIX - locking there is utterly broken (for ages).

Fixes PR/43176.


# 1.179 24-Jun-2010 hannken

Clean up vnode lock operations pass 2:

VOP_UNLOCK(vp, flags) -> VOP_UNLOCK(vp): Remove the unneeded flags argument.

Welcome to 5.99.32.

Discussed on tech-kern.


# 1.178 08-Jun-2010 hannken

Procfs_lookup() does not lookup directory descriptors in the fd/
subdirectory. There is no need for recursive vnode locking here.

Ok: Christos Zoulas <christos@netbsd.org>


Revision tags: uebayasi-xip-base1 yamt-nfs-mp-base9 uebayasi-xip-base
# 1.177 08-Jan-2010 pooka

branches: 1.177.2; 1.177.4;
The VATTR_NULL/VREF/VHOLD/HOLDRELE() macros lost their will to live
years ago when the kernel was modified to not alter ABI based on
DIAGNOSTIC, and now just call the respective function interfaces
(in lowercase). Plenty of mix'n match upper/lowercase has creeped
into the tree since then. Nuke the macros and convert all callsites
to lowercase.

no functional change


Revision tags: matt-premerge-20091211 yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 jym-xensuspend-nbase
# 1.176 03-Jul-2009 elad

Where possible, extract the file-system's access() routine to two internal
functions: the first checking if the operation is possible (regardless of
permissions), the second checking file-system permissions, ACLs, etc.

Mailing list reference:

http://mail-index.netbsd.org/tech-kern/2009/06/21/msg005311.html


# 1.175 23-Jun-2009 elad

Move the implementation of vaccess() to genfs_can_access(), in line with
the other routines of the same spirit.

Adjust file-system code to use it.

Keep vaccess() for KPI compatibility and to keep element of least
surprise. A "diagnostic" message warning that vaccess() is deprecated will
be printed when it's used (obviously, only in DIAGNOSTIC kernels).

No objections on tech-kern@:

http://mail-index.netbsd.org/tech-kern/2009/06/21/msg005310.html


Revision tags: yamt-nfs-mp-base5
# 1.174 24-May-2009 ad

More changes to improve kern_descrip.c.

- Avoid atomics in more places.
- Remove the per-descriptor mutex, and just use filedesc_t::fd_lock.
It was only being used to synchronize close, and in any case we needed
to take fd_lock to free the descriptor slot.
- Optimize certain paths for the <NDFDFILE case.
- Sprinkle more comments and assertions.
- Cache more stuff in filedesc_t.
- Fix numerous minor bugs spotted along the way.
- Restructure how the open files array is maintained, for clarity and so
that we can eliminate the membar_consumer() call in fd_getfile(). This is
mostly syntactic sugar; the main functional change is that fd_nfiles now
lives alongside the open file array.

Some measurements with libmicro:

- simple file syscalls are like close() are between 1 to 10% faster.
- some nice improvements, e.g. poll(1000) which is ~50% faster.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 nick-hppapmap-base2 jym-xensuspend-base nick-hppapmap-base mjf-devfs2-base
# 1.173 17-Dec-2008 cegger

branches: 1.173.2;
kill MALLOC and FREE macros.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 haad-dm-base2 haad-nbase2 ad-audiomp2-base netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 haad-dm-base
# 1.172 05-Sep-2008 skrll

branches: 1.172.2;
PR/39324 kernel diagnostic assertion "l->l_stat != LSZOMB" failed.

Ignore procs with zero or all LSZOMB LWPs. Get a non-LSZOMB LWP to perform
operations against as part of the deal.

procfs really needs to be updated to support multi-threading fully.
Hi Antti!


# 1.171 05-Sep-2008 skrll

ANSIfy


Revision tags: simonb-wapbl-nbase simonb-wapbl-base
# 1.170 02-Jul-2008 rmind

branches: 1.170.2;
Remove proc_representative_lwp(), use a simple LIST_FIRST() instead.
OK by <ad>.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base
# 1.169 28-Apr-2008 martin

branches: 1.169.2; 1.169.4;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-nfs-mp-base
# 1.168 24-Apr-2008 ad

branches: 1.168.2;
Merge proc::p_mutex and proc::p_smutex into a single adaptive mutex, since
we no longer need to guard against access from hardware interrupt handlers.

Additionally, if cloning a process with CLONE_SIGHAND, arrange to have the
child process share the parent's lock so that signal state may be kept in
sync. Partially addresses PR kern/37437.


# 1.167 24-Apr-2008 ad

Network protocol interrupts can now block on locks, so merge the globals
proclist_mutex and proclist_lock into a single adaptive mutex (proc_lock).
Implications:

- Inspecting process state requires thread context, so signals can no longer
be sent from a hardware interrupt handler. Signal activity must be
deferred to a soft interrupt or kthread.

- As the proc state locking is simplified, it's now safe to take exit()
and wait() out from under kernel_lock.

- The system spends less time at IPL_SCHED, and there is less lock activity.


Revision tags: yamt-pf42-baseX yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14
# 1.166 21-Mar-2008 ad

branches: 1.166.2;
Catch up with descriptor handling changes. See kern_descrip.c revision
1.173 for details.


Revision tags: keiichi-mipv6-nbase nick-net80211-sync-base keiichi-mipv6-base bouyer-xeni386-nbase matt-armv6-nbase mjf-devfs-base hpcarm-cleanup-base
# 1.165 23-Jan-2008 elad

branches: 1.165.6;
Tons of process scope changes.

- Add a KAUTH_PROCESS_SCHEDULER action, to handle scheduler related
requests, and add specific requests for set/get scheduler policy and
set/get scheduler parameters.

- Add a KAUTH_PROCESS_KEVENT_FILTER action, to handle kevent(2) related
requests.

- Add a KAUTH_DEVICE_TTY_STI action to handle requests to TIOCSTI.

- Add requests for the KAUTH_PROCESS_CANSEE action, indicating what
process information is being looked at (entry itself, args, env,
open files).

- Add requests for the KAUTH_PROCESS_RLIMIT action indicating set/get.

- Add requests for the KAUTH_PROCESS_CORENAME action indicating set/get.

- Make bsd44 secmodel code handle the newly added rqeuests appropriately.

All of the above make it possible to issue finer-grained kauth(9) calls in
many places, removing some KAUTH_GENERIC_ISSUSER requests.

- Remove the "CAN" from KAUTH_PROCESS_CAN{KTRACE,PROCFS,PTRACE,SIGNAL}.

Discussed with christos@ and yamt@.


Revision tags: bouyer-xeni386-base matt-armv6-base
# 1.164 02-Jan-2008 ad

Merge vmlocking2 to head.


Revision tags: vmlocking2-base3 yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 vmlocking-nbase jmcneill-pm-base reinoud-bufcleanup-base
# 1.163 26-Nov-2007 pooka

branches: 1.163.2; 1.163.6;
Remove the "struct lwp *" argument from all VFS and VOP interfaces.
The general trend is to remove it from all kernel interfaces and
this is a start. In case the calling lwp is desired, curlwp should
be used.

quick consensus on tech-kern


Revision tags: bouyer-xenamd64-base2 bouyer-xenamd64-base
# 1.162 09-Nov-2007 christos

make the last argument of procfs_dir size_t


# 1.161 07-Nov-2007 ad

Merge from vmlocking:

- pool_cache changes.
- Debugger/procfs locking fixes.
- Other minor changes.


Revision tags: jmcneill-base yamt-x86pmap-base4 yamt-x86pmap-base3 vmlocking-base
# 1.160 10-Oct-2007 ad

branches: 1.160.2; 1.160.4;
Merge from vmlocking:

- Split vnode::v_flag into three fields, depending on field locking.
- simple_lock -> kmutex in a few places.
- Fix some simple locking problems.


# 1.159 08-Oct-2007 ad

Merge file descriptor locking, cwdi locking and cross-call changes
from the vmlocking branch.


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base2 yamt-x86pmap-base matt-mips64-base
# 1.158 22-Jul-2007 pooka

branches: 1.158.4; 1.158.6; 1.158.8; 1.158.10;
Don't allow getcwd() on procfs vnodes and provide "/" as the path
instead of the result from getcwd(). The works around locking
panics caused by namei calling VOP_READLINK while holding on to a
directory lock and getcwd() trying to acquire that lock. The real
fix would be to get rid of getcwd() calls within VOPs (not locking
safe), but that's not a viable option in the netbsd-4 timeframe.

Suggestion for workaround from David Holland.


Revision tags: nick-csl-alignment-base mjf-ufs-trans-base
# 1.157 24-May-2007 agc

branches: 1.157.2;
Extend the Linux emulation of /proc to include

/proc/stat
/proc/loadavg and
/proc/<pid>/statm.

These are only present when -o linux is specified as a mount option
to procfs.

Factor out some common code so that it can be used by a number of
functions.

XXX The values returned in the statm emulation need to be verified.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 1.156 04-Apr-2007 rmind

Unfortunately, missed procfs_proc_unlock() in previous.
Pointed out by pooka@


# 1.155 04-Apr-2007 rmind

procfs_readlink: Handle a possible fail of fd_getfile(), also, we
do not need to check for error again.
CID: 4436


# 1.154 09-Mar-2007 ad

branches: 1.154.2; 1.154.4;
- Make the proclist_lock a mutex. The write:read ratio is unfavourable,
and mutexes are cheaper use than RW locks.
- LOCK_ASSERT -> KASSERT in some places.
- Hold proclist_lock/kernel_lock longer in a couple of places.


# 1.153 04-Mar-2007 christos

Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.


# 1.152 03-Mar-2007 salo

Don't prepend rootvnode to the path in non-NULL case for exe links.
It breaks procfs in chroot.

from <christos>, tested by me.


Revision tags: ad-audiomp-base
# 1.151 19-Feb-2007 pooka

When checking for file validity under pid/, do proper proc->lwp
lookup (fsvo proper) instead of fiddling directly with the lwp
list.


# 1.150 18-Feb-2007 pooka

Don't check for validity of p in lookup for root nodes, since it
will always be NULL. Rather, just call pt_valid with NULL directly
and let it decide if we're a linux mount or not.


# 1.149 17-Feb-2007 pavel

Change the process/lwp flags seen by userland via sysctl back to the
P_*/L_* naming convention, and rename the in-kernel flags to avoid
conflict. (P_ -> PK_, L_ -> LW_ ). Add back the (now unused) LSDEAD
constant.

Restores source compatibility with pre-newlock2 tools like ps or top.

Reviewed by Andrew Doran.


# 1.148 16-Feb-2007 pooka

branches: 1.148.2;
In lookup, when checking for procfs process node validity, target the
process we're trying to get information about through procfs, not
the caller of lookup.

fixes 'ls -l /proc/*/file' panic, which would occur when trying to
lookup "file" for a kernel thread, which doesn't have p->p_textvp.


# 1.147 15-Feb-2007 ad

Need to acquire procp->p_mutex for procfs_dir().


# 1.146 11-Feb-2007 ad

Eliminate a couple of reference count and mutex leaks.


Revision tags: post-newlock2-merge
# 1.145 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 1.144 25-Dec-2006 elad

PR/35226: Johann Franz: Problems with permissions in
/usr/pkg/emul/linux/proc .

Okay mlelstv@


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3
# 1.143 09-Dec-2006 chs

a smorgasbord of improvements to vnode locking and path lookup:
- LOCKPARENT is no longer relevant for lookup(), relookup() or VOP_LOOKUP().
these now always return the parent vnode locked. namei() works as before.
lookup() and various other paths no longer acquire vnode locks in the
wrong order via vrele(). fixes PR 32535.
as a nice side effect, path lookup is also up to 25% faster.
- the above allows us to get rid of PDIRUNLOCK.
- also get rid of WANTPARENT (just use LOCKPARENT and unlock it).
- remove an assumption in layer_node_find() that all file systems implement
a recursive VOP_LOCK() (unionfs doesn't).
- require that all file systems supply vfs_vptofh and vfs_fhtovp routines.
fill in eopnotsupp() for file systems that don't support being exported
and remove the checks for NULL. (layerfs calls these without checking.)
- in union_lookup1(), don't change refcounts in the ISDOTDOT case, just
adjust which vnode is locked. fixes PR 33374.
- apply fixes for ufs_rename() from ufs_vnops.c rev. 1.61 to ext2fs_rename().


# 1.142 04-Dec-2006 christos

From Nicolas Joly: restore previous behavior in procfs_validfile_linux, since
readdir passes a NULL lwp.


# 1.141 03-Dec-2006 elad

Move kauth(9) call to where it belongs. Noticed by Nicolas Joly, thanks!


Revision tags: netbsd-4-base
# 1.140 28-Nov-2006 elad

branches: 1.140.2;
Move ktrace, ptrace, systrace, and procfs to use kauth(9).

First, remove process_checkioperm() calls from MD code. Similar checks
using kauth(9) routines (on the process scope, using appropriate action)
are done in the callers.

Add secmodel back-end to handle each subsystem.


# 1.139 25-Nov-2006 skrll

Expose the 'exe' symlink to the process realpath in NetBSD as well. An
example user is gdb.

OK'd by christos.


# 1.138 16-Nov-2006 christos

__unused removal on arguments; approved by core.


# 1.137 29-Oct-2006 christos

add an "emul" file node.


# 1.136 25-Oct-2006 christos

1. fix procfs_validfile{,_linux} to test for NULL pointers properly.
2. make "exe" entry be a symlink to the executable, instead of pointing
directly to the vnode of the executable.
3. factor out commonly used code.


Revision tags: yamt-splraiseipl-base2
# 1.135 12-Oct-2006 christos

- sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386


# 1.134 20-Sep-2006 manu

Emulate Linux's /proc/devices


Revision tags: abandoned-netbsd-4-base yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base rpaulo-netinet-merge-pcb-base
# 1.133 13-Jun-2006 yamt

branches: 1.133.6; 1.133.8;
use KAUTH_PROCESS_CANSEE rather than CURTAIN where appropriate.


# 1.132 13-Jun-2006 yamt

remove unnecessary arguments from kauth_authorize_process.
ie. make it similar to the one found in apple TN.


# 1.131 07-Jun-2006 kardel

merge FreeBSD timecounters from branch simonb-timecounters
- struct timeval time is gone
time.tv_sec -> time_second
- struct timeval mono_time is gone
mono_time.tv_sec -> time_uptime
- access to time via
{get,}{micro,nano,bin}time()
get* versions are fast but less precise
- support NTP nanokernel implementation (NTP API 4)
- further reading:
Timecounter Paper: http://phk.freebsd.dk/pubs/timecounter.pdf
NTP Nanokernel: http://www.eecis.udel.edu/~mills/ntp/html/kern.html


Revision tags: yamt-pdpolicy-base5 simonb-timecounters-base
# 1.130 14-May-2006 elad

branches: 1.130.2;
integrate kauth.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 elad-kernelauth-base yamt-pdpolicy-base yamt-uio_vmspace-base5
# 1.129 02-Feb-2006 christos

branches: 1.129.2; 1.129.4; 1.129.6; 1.129.8;
PR/32692: Matthew Mondor: linux compatibility in /proc/self should point
directly to the directory containing the pid instead of pointing to
/proc/curproc, because some programs rely on calling readlink on /proc/self
to get the pid.


# 1.128 11-Dec-2005 christos

branches: 1.128.2; 1.128.4;
merge ktrace-lwp.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base ktrace-lwp-base
# 1.127 02-Nov-2005 yamt

merge yamt-vop branch. remove following VOPs.

VOP_BLKATOFF
VOP_VALLOC
VOP_BALLOC
VOP_REALLOCBLKS
VOP_VFREE
VOP_TRUNCATE
VOP_UPDATE


Revision tags: yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 1.126 01-Oct-2005 atatat

branches: 1.126.2;
Add "cwd" and "root" symlinks to each process's directory. The cwd
link points to the process's current working directory, and the root
link points to the process's root directory. What else would you
expect?

For directories that are out of reach (caller is in a chroot, target
process is in a different chroot, etc), the links point to "/"
instead.


# 1.125 11-Sep-2005 elad

Implement curtain for procfs.


# 1.124 30-Aug-2005 xtraeme

Remove __P()


# 1.123 29-May-2005 christos

branches: 1.123.2;
- sprinkle const
- avoid shadowed variables.


Revision tags: kent-audio2-base
# 1.122 02-Apr-2005 christos

PR/29782: Martin Husemann: procfs can not unmount when some process has its
current directory in curproc. Fix from Pedro Martelletto:
We cannot call vgone() from procfs_inactive() if we are coming from
vclean(). that's what's probably causing the deadlock.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 yamt-km-base4 yamt-km-base3 netbsd-3-base
# 1.121 26-Feb-2005 perry

nuke trailing whitespace


Revision tags: yamt-km-base2 yamt-km-base kent-audio1-beforemerge kent-audio1-base
# 1.120 04-Oct-2004 yamt

branches: 1.120.4; 1.120.6;
procfs_readdir:
- return correct cookie when buffer size is small.
- simplify logic.


# 1.119 04-Oct-2004 yamt

procfs_readdir: remove a redundant assignment.


# 1.118 02-Oct-2004 yamt

procfs_getattr: correct size of /proc/self.


# 1.117 01-Oct-2004 yamt

procfs_readdir:
- fix a locking problem, using proclist_foreach_call. PR/27098.
- correct snprintf size argument.


# 1.116 01-Oct-2004 yamt

procfs_readdir: fix an offset handling bug after addition of /proc/self.


# 1.115 01-Oct-2004 yamt

procfs_readdir: use a list macro.


# 1.114 20-Sep-2004 jdolecek

add 'mounts' file for -o linux, which lists all currently mounted
filesystems; Linux glibc statvfs() uses this to get some of mount flags,
and this file is also useful as /emul/linux/etc/mtab (via symlink)


# 1.113 29-Apr-2004 jrf

Removed remaining caddr_t casts we do not need in miscfs. Recompiled
kernel and ran for a day or so. There are still some caddr_t types in
the arguments of some calls, I will do those separately (later) as
they touch a lot more of the system.
Approved by christos@NetBSD.org.


# 1.112 22-Apr-2004 itojun

sprintf -> snprintf


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.111 15-Feb-2004 jdolecek

unlock the descriptor table simple lock after fd_getfile() call in
procfs_readdir()
fixes procfs locking problems reported on current-users@, problem place
found by enami tsugutomo


# 1.110 30-Oct-2003 simonb

Remove some assigned-to but otherwise unused variables.


# 1.109 27-Sep-2003 darcy

Changes as discussed with itojun on tech-kern. I have modified the enums
to have KFS or PFS differentiators. Further I have wrapped the enum in
procfs in "#ifdef _KERNEL" as it is done in kernfs.

To see the discussion go to http://mail-index.NetBSD.org/tech-kern/2003/09/
and look for "Mismatched enums in include files" in the list.


# 1.108 07-Sep-2003 itojun

remove meaningless line (variable overwritten 2 lines below)


# 1.107 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.


# 1.106 29-Jun-2003 fvdl

branches: 1.106.2;
Back out the lwp/ktrace changes. They contained a lot of colateral damage,
and need to be examined and discussed more.


# 1.105 29-Jun-2003 thorpej

Undo part of the ktrace/lwp changes. In particular:
* Remove the "lwp *" argument that was added to vget(). Turns out
that nothing actually used it!
* Remove the "lwp *" arguments that were added to VFS_ROOT(), VFS_VGET(),
and VFS_FHTOVP(); all they did was pass it to vget() (which, as noted
above, didn't use it).
* Remove all of the "lwp *" arguments to internal functions that were added
just to appease the above.


# 1.104 28-Jun-2003 darrenr

Pass lwp pointers throughtout the kernel, as required, so that the lwpid can
be inserted into ktrace records. The general change has been to replace
"struct proc *" with "struct lwp *" in various function prototypes, pass
the lwp through and use l_proc to get the process pointer when needed.

Bump the kernel rev up to 1.6V


# 1.103 28-May-2003 christos

Add /proc/<pid>/stat for linux compat. j2sdk1.4.2 depends on it.


# 1.102 18-Apr-2003 christos

Make symlinks for directories that point to the actual directory.
Make symlinks to [kqueue] and [misc] for kqueue and misc fds.


# 1.101 17-Apr-2003 jdolecek

do not show nodes corresponding to directory descriptors for process
in fd/ subdirectory, nor allow lookup/open for the nodes
this fixes PR kern/21187 for good, and also avoids interesting directory
locking issues


# 1.100 17-Apr-2003 jdolecek

procfs_readdir(): in Pfd case, only show descriptors of types we want
how to represent (vnodes, fifo, pipes); also use fd_getfile() et al

this avoids annoying EOPNOTSUPP error messages from ls -F and such


# 1.99 17-Apr-2003 jdolecek

procfs_lookup(): use fd_getfile() et al in Pfd case


# 1.98 17-Apr-2003 jdolecek

use fd_getfile() in procfs_getfp(), and FILE_USE()/FILE_UNUSE() the
returned file descriptor pointer appropriately


# 1.97 17-Apr-2003 jdolecek

make some local arrays/variables static + const


# 1.96 10-Apr-2003 jdolecek

use former genfs_eopnotsupp_rele() as genfs_eopnotsupp(), so that vnodes
are vput()/vrele()d as necessary - some filesystems did use the wrong
one for some ops, and it's just safer to not take the chance

based on suggestion by Bill Studenmund


# 1.95 05-Apr-2003 dsl

Remove pointless check against PID_MAX. Let pfind() do the validation.
(The new pid allocation code may decide to allocate pids above PID_MAX.)


# 1.94 25-Feb-2003 jrf

This addresses PR kerm/19989. Thanks to hamajima@nagoya.ydc.co.jp for submitting this patch which enables /proc/uptime for linux emul. Patch reviewed by atatat@netbsd.org and tron@netbsd.org, approved by tron@netbsd.org.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 1.93 04-Jan-2003 martin

Cast off_t expression to long long to match format even on 64 bit
plattforms.

Shouldn't we introduce a PRIoff_t macro to create such format strings?


# 1.92 03-Jan-2003 christos

add LK_CANRECURSE in the locking of /dev/<pid>/fd/<n> and remove the curproc
kludge. Thanks to fvdl.


# 1.91 03-Jan-2003 christos

Implement /proc/<pid>/fd/<n>. This is work in progress. Questionable things:
- Is it ok to convert DTYPE_PIPE to VFIFO and DTYPE_SOCKET to VSOCK?
- XXX: Avoid locking issue in ls -Rl /proc by avoiding curproc
- Does I/O to pipes work?
- XXX: Are there security implications?


Revision tags: fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge gehenna-devsw-base kqueue-base
# 1.90 03-Aug-2002 simonb

Just use the "time" variable in the *_getattr functions instead of a call
to (the potentially expensive) microtime().


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.89 09-May-2002 thorpej

branches: 1.89.2;
Move code shared by procfs and the kernel proper out of procfs and
into the kernel proper (renaming functions from procfs_* to process_*).


Revision tags: eeh-devprop-base newlock-base ifpoll-base
# 1.88 12-Jan-2002 christos

Don't hide the real return code with EPERM.


# 1.87 06-Dec-2001 chs

add a VOP_PUTPAGES method for all the filesystems that don't have pages,
just unlock the interlock.


# 1.86 05-Dec-2001 thorpej

* Allow machine-dependent code to specify hooks for ptrace(2)
(__HAVE_PTRACE_MACHDEP) and procfs (__HAVE_PROCFS_MACHDEP).
These changes will allow platforms like x86 (XMM) and PowerPC
(AltiVec) to export extended register sets in a sane manner.

* Use __HAVE_PTRACE_MACHDEP to export x86 XMM registers (standard
FP + SSE/SSE2) using PT_{GET,SET}XMMREGS (in the machdep
ptrace request space).
* Use __HAVE_PROCFS_MACHDEP to export x86 XMM registers via
/proc/N/xmmregs in procfs.


Revision tags: thorpej-mips-cache-base
# 1.85 10-Nov-2001 lukem

add RCSIDs


# 1.84 06-Nov-2001 simonb

Remove some variables that are set but never used.


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base
# 1.83 31-Aug-2001 chs

branches: 1.83.2; 1.83.4;
map files are zero-length.


# 1.82 03-Jun-2001 chs

branches: 1.82.2;
procfs_bmap() should never be called, make it a "bad op".
let procfs_mmap() use the default error method.


Revision tags: thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 1.81 14-Apr-2001 kleink

In procfs_readdir(), give /proc/# directories DT_DIR (rather than DT_REG).


# 1.80 30-Mar-2001 fvdl

Bump va_blocksize for the map files some more, so that programs with
quite a few mappings have a chance of being handled correctly if
st_blksize is looked at.


# 1.79 29-Mar-2001 fvdl

For -o linux mounts, add some code to emulate /proc/#/maps.
Needs NAMECACHE_ENTER_REVERSE to include filenames.


# 1.78 21-Feb-2001 jdolecek

branches: 1.78.2;
make some more constant arrays 'const'


# 1.77 22-Jan-2001 jdolecek

make filesystem vnodeop, specop, fifoop and vnodeopv_* arrays const


# 1.76 17-Jan-2001 fvdl

Add a few linux-style files, only enabled when -o linux is specified
for the mount. Currently these are /proc/cpuinfo and /proc/meminfo.
The former only does something on i386 right now.


# 1.75 24-Nov-2000 chs

remove dead code and other misc cleanup.


# 1.74 09-Aug-2000 tv

Only show the "exe" entry to Linux processes, suggested by christos.
Since there are actually three struct emul's for linux, use the e_name
field to determine eligibility with strcmp().


# 1.73 09-Aug-2000 tv

Some versions of Linux libc look for /proc/.../exe instead of /proc/../file.
Add an entry for "exe" that is the same as "file", provided only if
COMPAT_LINUX is set.


# 1.72 03-Aug-2000 thorpej

MALLOC()/FREE() are not to be used for variable sized allocations.


# 1.71 28-Jun-2000 mrg

<vm/vm.h> -> <uvm/uvm_extern.h>


Revision tags: netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 1.70 30-Mar-2000 simonb

branches: 1.70.4;
Delete duplicate declaration of atopid().


Revision tags: chs-ubc2-newbase wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base fvdl-softdep-base
# 1.69 02-Sep-1999 thorpej

branches: 1.69.2; 1.69.8;
Make /proc/self a symlink to /proc/curproc. I've observed Linux programs
that expect /proc/self/cmdline to exist.


# 1.68 25-Aug-1999 sommerfeld

Change variable used for directory offset from "int" to "off_t".
Overkill, but avoids a host of truncation problems.


# 1.67 24-Aug-1999 sommerfeld

Fix PR8270:

Problem turned out to be due to improper handling of reads beyond EOF:
they should just return without error with the uio unchanged, and the
caller will recognize this as a zero-byte return (EOF).

The previous fix to protect directory reads against bogus uio_offset
values returned EINVAL, which broke mount -o union, which only
union'ed in the lower directory if the upper directory cleanly
returned EOF.

While we're here, protect kernfs as well.


# 1.66 14-Aug-1999 christos

protect against large uio_offset


# 1.65 03-Aug-1999 wrstuden

Add support for fcntl(2) to generate VOP_FCNTL calls. Any fcntl
call with F_FSCTL set and F_SETFL calls generate calls to a new
fileop fo_fcntl. Add genfs_fcntl() and soo_fcntl() which return 0
for F_SETFL and EOPNOTSUPP otherwise. Have all leaf filesystems
use genfs_fcntl().

Reviewed by: thorpej
Tested by: wrstuden


Revision tags: chs-ubc2-base
# 1.64 25-Jul-1999 thorpej

Add calls to lock the proclist as appropriate.


# 1.63 14-Jul-1999 thorpej

Fix a paste-o in procfs_lookup() introduced with the vnode locking changes.
Fixes PR #7961, Mario Kemper <magick@bundy.lip.owl.de>.


# 1.62 08-Jul-1999 wrstuden

Bump osrelease to 1.4E. Add layerfs files, remove null_subr.c.

Update coda to new struct lock in struct vnode.

make fdescfs, kernfs, portalfs, and procfs actually lock their vnodes.
It's not that hard.

Make unionfs set v_vnlock = NULL so any overlayed fs will call its
VOP_LOCK.


Revision tags: kame_141_19991130 netbsd-1-4-PATCH001 kame_14_19990705 kame_14_19990628 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.61 12-Mar-1999 christos

branches: 1.61.2; 1.61.4;
PR/7143: Jaromir Docelek: Add procfs/cmdline from Linux emulation


# 1.60 25-Jan-1999 msaitoh

Add /proc/#/map. From FreeBSD.


Revision tags: kenh-if-detach-base chs-ubc-base
# 1.59 08-Sep-1998 thorpej

- Use proclists[], rather than checking allproc and zombproc explicitly.
- Add some comments about locking.


# 1.58 13-Aug-1998 kleink

Per POSIX, fail with EINVAL if advisory locking is attempted on a file type
that doesn't support it, rather than using a homegrown EBADF or EOPNOTSUPP.


# 1.57 10-Aug-1998 matthias

create miscfs/genfs/genfs_vnops.c:genfs_enoioctl and make all the other
filesystems use it instead of a private version.


# 1.56 09-Aug-1998 perry

bzero->memset, bcopy->memcpy, bcmp->memcmp


# 1.55 03-Aug-1998 kleink

Recognize _PC_SYNC_IO.


Revision tags: eeh-paddr_t-base
# 1.54 21-Apr-1998 fvdl

procfs_readdir: in case of error, check if cookies actually have
been allocated before freeing them. From Wolfgang Solfrank.


# 1.53 01-Mar-1998 fvdl

Merge with Lite2 + local changes


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base marc-pcmcia-base
# 1.52 10-Oct-1997 fvdl

Bump last argument to VOP_READDIR to off_t (from u_long).


Revision tags: thorpej-signal-base
# 1.51 27-Aug-1997 thorpej

Fix a reversed argument which caused procfs_checkioperm() to always return
"OK". Add a few comments to avoid further confusion.


# 1.50 12-Aug-1997 thorpej

Fix the procfs hole described on current-users, similar to a fix for
FreeBSD by Sean Eric Fagan, but a bit different. This makes the checks
in the same places as sef's FreeBSD patch, but does not hardcode the
"kmem" group into the kernel, and also does a check identical to the
(3) and (4) checks in the NetBSD ptrace(2):

(1) it's not owned by you, or is set-id on exec (unless
you're root), or

(2) it's init, which controls the security level of the
entire system, and the system was not compiled with
permanently insecure mode turned on.


Revision tags: marc-pcmcia-bp
# 1.49 08-May-1997 mycroft

branches: 1.49.4;
Pass the vnode type to vaccess(), and use it when checking VEXEC. Make sure
that the mode bits passed to vaccess() and returned by foo_getattr() contain
only permission bits.


# 1.48 05-May-1997 mycroft

Need stat.h.


# 1.47 05-May-1997 mycroft

Eliminate bogus uses of V{READ,WRITE,EXEC}. Use S_I[RWX]{USR,GRP,OTH} where
appropriate.


# 1.46 28-Apr-1997 mycroft

Minor code cleanup.


Revision tags: is-newarp-before-merge is-newarp-base
# 1.45 25-Oct-1996 cgd

define path name string variables that we should not (and, thankfully, do
not) modify as 'const char *' rather 'char *'.


# 1.44 13-Oct-1996 christos

backout previous kprintf changes


# 1.43 10-Oct-1996 christos

printf -> kprintf, sprintf -> ksprintf


# 1.42 07-Sep-1996 mycroft

Implement poll(2).


# 1.41 01-Sep-1996 mycroft

Add a set of generic file system operations that most file systems use.
Also, fix some time stamp bogosities.


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 1.40 16-Mar-1996 christos

Fix printf format follies.


# 1.39 13-Feb-1996 mycroft

GC *_nullop(). Minor nits.


# 1.38 12-Feb-1996 christos

close PR/2063: procfs_rw prototyped twice with different prototypes


# 1.37 09-Feb-1996 christos

miscfs prototype changes


# 1.36 09-Feb-1996 mycroft

Fix vop_link, vop_symlink, and vop_remove semantics in several ways:
* Change the argument names to vop_link so they actually make sense.
* Implement vop_link and vop_symlink for all file systems, so they do proper
cleanup.
* Require the file system to decide whether or not linking and unlinking of
directories is allowed, and disable it for all current file systems.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.35 09-Oct-1995 mycroft

Use the index number as the cookie, rather than multiplying by UIO_MX.


# 1.34 09-Oct-1995 mycroft

Add support for cookies, mostly from Greg Hudson.


# 1.33 15-Apr-1995 cgd

fix timeval vs. timespec warnings


# 1.32 03-Feb-1995 mycroft

Return EROFS rather than ENOENT in many cases. Also some cosmetic cleanup.


# 1.31 27-Dec-1994 mycroft

Format police.


# 1.30 24-Dec-1994 ws

Implement and use a common access checking routine


# 1.29 14-Dec-1994 mycroft

Remove a_fp.


# 1.28 14-Nov-1994 christos

fixed struct comment


# 1.27 30-Oct-1994 cgd

be more careful with types, also pull in headers where necessary.


# 1.26 20-Oct-1994 cgd

update for new syscall args description mechanism


# 1.25 30-Aug-1994 mycroft

Convert process, file, and namei lists and hash tables to use queue.h.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.24 29-Jun-1994 cgd

New RCS ID's, take two. they're more aesthecially pleasant, and use 'NetBSD'


# 1.23 16-Jun-1994 mycroft

Remove an unneeded test.


# 1.22 15-Jun-1994 mycroft

Minor update from JSP after merging my changes.


# 1.21 08-Jun-1994 mycroft

Update to 4.4-Lite fs code, with local changes.


# 1.20 05-May-1994 cgd

lots of changes: prototype migration, move lots of variables, definitions,
and structure elements around. kill some unnecessary type and macro
definitions. standardize clock handling. More changes than you'd want.


# 1.19 15-Apr-1994 cgd

forgot these...


# 1.18 12-Apr-1994 cgd

be a bit smarter about determining if files shouldn't be seen by the user.
Also, DON'T allow a lookup to succeed on a file that's not visible!


# 1.17 15-Feb-1994 mycroft

Undo last change; executables is `file', not `a.out'.


# 1.16 14-Feb-1994 ws

Rename file -> a.out


# 1.15 14-Feb-1994 ws

Don't try to show a file for a process if there is none


# 1.14 28-Jan-1994 cgd

make a fpregs file.


# 1.13 20-Jan-1994 ws

Make procfs really work for debugging.
Implement not & notepg files in procfs.


# 1.12 09-Jan-1994 ws

Bug fixes and enhancements:
Make NFS serving work (BUT DON'T USE "attach" TO /proc/*/ctl FOR NOW!!!)
Make `curproc' a symbolic link
Add `.' and `..' entries to the directories.
Return better guesses on the size of the files.


# 1.11 05-Jan-1994 cgd

return size of 'reg' from getattr()


# 1.10 05-Jan-1994 cgd

make it compile (cleanly) for us


# 1.9 05-Jan-1994 cgd

add new procfs code, from Jan-Simon Pendry, jsp@sequent.com.
This is pretty-much "virgin", so that diffs can be done later.


# 1.8 18-Dec-1993 mycroft

Canonicalize all #includes.


Revision tags: magnum-base
# 1.7 16-Sep-1993 cgd

kill volatile warning.


# 1.6 07-Sep-1993 ws

branches: 1.6.2;
Changes to VFS readdir semantics
NFS changes for better cookie support
ISOFS changes for better Rockridge support and support for generation numbers


# 1.5 26-Aug-1993 pk

Implement setattr: mode for process entries; mode + uid/gid for the
PROCFS root directory.
Fixed omission in pfs_root() which came to light as a result of the above:
hold on to vnode for root dir.


# 1.4 25-Aug-1993 pk

Fixed improperly initialized nfsnode in pfs_lookup()


# 1.3 24-Aug-1993 pk

copyright update.


# 1.2 24-Aug-1993 pk

Rcs Id added.


# 1.1 24-Aug-1993 pk

branches: 1.1.1;
Initial version of a proc filesystem.


# 1.226 14-Jan-2022 christos

Fix emul and exe DT_ types (from RVP, as was the previous commit)


# 1.225 14-Jan-2022 christos

Put the appropriate DT_ constant in the dirent structure depending on the
file type.


# 1.224 11-Jan-2022 christos

remove redundant error initialization and break earlier. (from rvp)


# 1.223 11-Jan-2022 hannken

Use a single "p" variable.

Should fix PR kern/56614: kernel panic on tmux


# 1.222 10-Jan-2022 christos

use a single nc variable.


# 1.221 10-Jan-2022 christos

Fix locking in the error path (from RVP). Centralize unlock code.


# 1.220 08-Dec-2021 andvar

s/efficent/efficient/ in comments.


# 1.219 05-Oct-2021 christos

PR/53299: RVP: kernfs and procfs are broken when sysctl security.curtain
is enabled


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base thorpej-i2c-spi-conf-base
# 1.218 18-Jul-2021 dholland

Abolish all the silly indirection macros for initializing vnode ops tables.

These are things of the form #define foofs_op genfs_op, or #define
foofs_op genfs_eopnotsupp, or similar. They serve no purpose besides
obfuscation, and have gotten cutpasted all over everywhere.


# 1.217 29-Jun-2021 dholland

- Add a new vnode op: VOP_PARSEPATH.
- Move namei_getcomponent to genfs_vnops.c and call it genfs_parsepath.
- Add a parsepath entry to every vnode ops table.

VOP_PARSEPATH takes a directory vnode to be searched and a complete
following path and chooses how much of that path to consume. To begin
with, all parsepath calls are genfs_parsepath, which locates the first
'/' as always.

Note that the call doesn't take the whole struct componentname, only
the string. The other bits of struct componentname should not be
needed and there's no reason to cause potential complications by
exposing them.


# 1.216 28-Jun-2021 chs

VOP_BMAP() may be called via ioctl(FIOGETBMAP) on any vnode that applications
can open. change various pseudo-fs *_bmap methods return an error instead of
panic.

Reported-by: syzbot+8289a3eaf2ba60958c87@syzkaller.appspotmail.com


Revision tags: cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base thorpej-cfargs-base thorpej-futex-base
# 1.215 27-Jun-2020 christos

branches: 1.215.6;
Introduce genfs_pathconf() and use it for the default case in all filesystems.


# 1.214 23-May-2020 ad

Move proc_lock into the data segment. It was dynamically allocated because
at the time we had mutex_obj_alloc() but not __cacheline_aligned.


# 1.213 16-May-2020 christos

Add ACL support for FFS. From FreeBSD.


# 1.212 29-Apr-2020 thorpej

If the procfs mount is marked as linux-compat, then allow proc lookup
by any LWP ID in the proc, not just the canonical PID.


Revision tags: bouyer-xenpvh-base2
# 1.211 21-Apr-2020 ad

Revert the changes made in February to make cwdinfo use mostly lockless,
which relied on taking extra vnode refs.

Having benchmarked various experimental changes over the past few months it
seems that it's better to avoid vnode refs as much as possible. cwdi_lock
as a RW lock already did that to some extent for getcwd() and will permit
the same for namei() too.


Revision tags: phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base is-mlppp-base phil-wifi-20200406 ad-namecache-base3
# 1.210 24-Feb-2020 ad

branches: 1.210.4;
v_interlock -> vmobjlock


# 1.209 23-Feb-2020 ad

Merge from ad-namecache:

- Have a stab at clustering the members of vnode_t and vnode_impl_t in a
more cache-conscious way. With that done, go back to adjusting v_usecount
with atomics and keep vi_lock directly in vnode_impl_t (saves KVA).

- Allow VOP_LOCK(LK_NONE) for the benefit of VFS_VGET() and VFS_ROOT().
Make sure LK_UPGRADE always comes with LK_NOWAIT.

- Make cwdinfo use mostly lockless.


# 1.208 01-Feb-2020 riastradh

Load struct filedesc::fd_dt with atomic_load_consume.

Exceptions: when fd_refcnt <= 1, or when holding fd_lock.

While here:

- Restore KASSERT(mutex_owned(&fdp->fd_lock)) in fd_unused.
=> This is used only in fd_close and fd_abort, where it holds.
- Move bounds check assertion in fd_putfile to where it matters.
- Store fd_dt with atomic_store_release.
- Move load of fd_dt under lock in knote_fdclose.
- Omit membar_consumer in fdesc_readdir.
=> atomic_load_consume serves the same purpose now.
=> Was needed only on alpha anyway.


Revision tags: ad-namecache-base2 ad-namecache-base1 ad-namecache-base phil-wifi-20191119
# 1.207 29-Aug-2019 hannken

branches: 1.207.2;
Add missing operation VOP_GETPAGES() returning EFAULT.

Without this operation posix_fadvise(..., POSIX_FADV_WILLNEED)
would leave the v_interlock held.

Observed by maxv@


Revision tags: netbsd-9-base phil-wifi-20190609 isaki-audio2-base
# 1.206 30-Mar-2019 christos

branches: 1.206.4;
add a node for the process resource limits.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020
# 1.205 14-Oct-2018 jdolecek

remove M_CANFAIL flag for malloc(9) - it was completely ignored, so had
actually no effect


Revision tags: pgoyette-compat-0930 pgoyette-compat-0906
# 1.204 03-Sep-2018 riastradh

Rename min/max -> uimin/uimax for better honesty.

These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER! Some subsystems have

#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)


Revision tags: pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415
# 1.203 07-Apr-2018 hannken

branches: 1.203.2;
Lock the target cwdi and take an additional reference to the
vnode we are interested in to prevent it from disappearing
before getcwd_common().

Should fix PR kern/53096 (netbsd-8 crash on heavy disk I/O)


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.202 31-Dec-2017 christos

branches: 1.202.2;
Add an environ node


Revision tags: tls-maxphys-base-20171202
# 1.201 01-Dec-2017 christos

Allow procfs_kqfilter, since we allow poll. "go" does it.


# 1.200 08-Nov-2017 christos

fix locking, remove error(1) comments.


# 1.199 08-Nov-2017 christos

use p->p_path, remove unused code.


# 1.198 28-Aug-2017 kamil

Remove the filesystem tracing feature

This is a legacy interface from 4.4BSD, and it was
introduced to overcome shortcomings of ptrace(2) at that time, which are
no longer relevant (performance). Today /proc/#/ctl offers a narrow
subset of ptrace(2) commands and is not applicable for modern
applications use beyond simplistic tracing scenarios.

This removal will simplify kernel internals. Users will still be able to
use all the other /proc files.

This change won't affect other procfs files neither Linux compat
features within mount_procfs(8). /proc/#/ctl isn't available on Linux.

Remove:
- /proc/#/ctl from mount_procfs(8)
- P_FSTRACE note from the documentation of ps(1)
- /proc/#/ctl and filesystem tracing documentation from mount_procfs(8)
- KAUTH_REQ_PROCESS_PROCFS_CTL documentation from kauth(9)
- source code file miscfs/procfs/procfs_ctl.c
- PFSctl and procfs_doctl() from sys/miscfs/procfs/procfs.h
- KAUTH_REQ_PROCESS_PROCFS_CTL from sys/sys/kauth.h
- PSL_FSTRACE (0x00010000) from sys/sys/proc.h
- P_FSTRACE (0x00010000) from sys/sys/sysctl.h

Reduce code complexity after removal of this functionality.

Update TODO.ptrace accordingly: remove two entries about /proc tracing.

Do not keep legacy notes as comments in the headers about removed
PSL_FSTRACE / P_FSTRACE, as this interface had little number of users
(close or equal to zero).

Proposed on tech-kern@.

All filesystem tracing utility users are encouraged to switch to ptrace(2).

Sponsored by <The NetBSD Foundation>


Revision tags: matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base
# 1.197 26-May-2017 riastradh

branches: 1.197.2;
Make VOP_RECLAIM do the last unlock of the vnode.

VOP_RECLAIM naturally has exclusive access to the vnode, so having it
locked on entry is not strictly necessary -- but it means if there
are any final operations that must be done on the vnode, such as
ffs_update, requiring exclusive access to it, we can now kassert that
the vnode is locked in those operations.

We can't just have the caller release the last lock because some file
systems don't use genfs_lock, and require the vnode to remain valid
for VOP_UNLOCK to work, notably unionfs.


Revision tags: prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.196 11-Apr-2017 riastradh

Make VOP_INACTIVE preserve vnode lock on return.

Discussed on tech-kern:
https://mail-index.netbsd.org/tech-kern/2017/04/01/msg021751.html

Ride 7.99.68, a bumpy bus of incremental vfs improvements!


Revision tags: jdolecek-ncq-base
# 1.195 30-Mar-2017 christos

add an auxv node.


Revision tags: pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004 localcount-20160914
# 1.194 20-Aug-2016 hannken

branches: 1.194.2;
Remove now obsolete operation vcache_remove().

Welcome to 7.99.36


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 nick-nhusb-base-20150921 nick-nhusb-base-20150606
# 1.193 20-Apr-2015 riastradh

branches: 1.193.2;
Make VOP_LINK return directory still locked and referenced.

Ride 7.99.10 bump.


Revision tags: nick-nhusb-base-20150406 nick-nhusb-base
# 1.192 05-Sep-2014 matt

branches: 1.192.2;
Try not to use f_data, use f_{vnode,socket,pipe,mqueue,kqueue,ksem} to get
a correctly typed pointer.


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.191 27-Jul-2014 hannken

branches: 1.191.2; 1.191.4; 1.191.8;
Change procfs from hashlist to vcache.
- Key is (type, pid, fd)
- Remove argument "p" from procfs_allocvp(). It is only used
when "type == PFSfd". Lookup the proc with proc_find() when
procfs_loadvnode() needs it.
- Use a vfs_vnode_iterator for procfs_revoke_vnodes().


# 1.190 25-Jul-2014 dholland

Add VOP_FALLOCATE and VOP_FDISCARD to every vnode ops table I can
find.

The filesystem ones all call genfs_eopnotsupp - right now I am only
implementing the plumbing and we can implement fallocate and/or
fdiscard for files later.

The device ones call spec_fallocate (which is also genfs_eopnotsupp)
and spec_fdiscard, which dispatches to the device-level op.

The fifo ones all call vn_fifo_bypass, which also ends up being
EOPNOTSUPP.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base
# 1.189 07-Feb-2014 hannken

branches: 1.189.2;
Change vnode operation lookup to return the resulting vnode *vpp unlocked.
Change cache_lookup() to return an unlocked vnode.

Discussed on tech-kern@

Welcome to 6.99.31


# 1.188 23-Jan-2014 hannken

Change vnode operations create, mknod, mkdir and symlink to return
the resulting vnode *vpp unlocked.

Discussed on tech-kern@

Welcome to 6.99.30


# 1.187 17-Jan-2014 hannken

Change vnode operations create, mknod, mkdir and symlink to keep the
directory node dvp locked on return.

Discussed on tech-kern@

Welcome to 6.99.29


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base
# 1.186 18-Mar-2013 plunky

branches: 1.186.6;
C99 section 6.7.2.3 (Tags) Note 3 states that:

A type specifier of the form

enum identifier

without an enumerator list shall only appear after the type it
specifies is complete.

which means that we cannot pass an "enum vtype" argument to
kauth_access_action() without fully specifying the type first.
Unfortunately there is a complicated include file loop which
makes that difficult, so convert this minimal function into a
macro (and capitalize it).

(ok elad@)


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 1.185 25-Nov-2012 christos

do something reasonable with kernel semaphores.


Revision tags: yamt-pagecache-base6 jmcneill-usbmp-base10
# 1.184 28-May-2012 christos

branches: 1.184.2;
add a task process subdirectory for emul linux


Revision tags: yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 1.183 13-Mar-2012 elad

Replace the remaining KAUTH_GENERIC_ISSUSER authorization calls with
something meaningful. All relevant documentation has been updated or
written.

Most of these changes were brought up in the following messages:

http://mail-index.netbsd.org/tech-kern/2012/01/18/msg012490.html
http://mail-index.netbsd.org/tech-kern/2012/01/19/msg012502.html
http://mail-index.netbsd.org/tech-kern/2012/02/17/msg012728.html

Thanks to christos, manu, njoly, and jmmv for input.

Huge thanks to pgoyette for spinning these changes through some build
cycles and ATF.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.182 04-Sep-2011 jmcneill

branches: 1.182.2; 1.182.6;
PR# kern/45021: Please support /emul/linux/proc/version

Add /proc/version for procfs with -o linux. The version reported depends
on the emulation type of the calling process:

$ cat /proc/version
NetBSD version 5.99.55 (netbsd@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) NetBSD 5.99.55 (GENERIC) #39: Sun Sep 4 09:10:05 EDT 2011

$ /emul/linux/bin/cat /proc/version
Linux version 2.6.18 (linux@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) #0 Wed Mar 3 03:03:03 PST 2010

$ /emul/linux32/bin/cat /proc/version
Linux version 2.6.18 (linux32@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) #0 Wed Mar 3 03:03:03 PST 2010


# 1.181 23-Jun-2011 christos

From Aleksey Cheusov: Don't make it easy for compromised systems to bypass
ASLR protections by providing the mapping addresses of programs to everyone.


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base matt-mips64-premerge-20101231 uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10 rmind-uvmplock-base
# 1.180 01-Jul-2010 rmind

Remove pfind() and pgfind(), fix locking in various broken uses of these.
Rename real routines to proc_find() and pgrp_find(), remove PFIND_* flags
and have consistent behaviour. Provide proc_find_raw() for special cases.
Fix memory leak in sysctl_proc_corename().

COMPAT_LINUX: rework ptrace() locking, minimise differences between
different versions per-arch.

Note: while this change adds some formal cosmetics for COMPAT_DARWIN and
COMPAT_IRIX - locking there is utterly broken (for ages).

Fixes PR/43176.


# 1.179 24-Jun-2010 hannken

Clean up vnode lock operations pass 2:

VOP_UNLOCK(vp, flags) -> VOP_UNLOCK(vp): Remove the unneeded flags argument.

Welcome to 5.99.32.

Discussed on tech-kern.


# 1.178 08-Jun-2010 hannken

Procfs_lookup() does not lookup directory descriptors in the fd/
subdirectory. There is no need for recursive vnode locking here.

Ok: Christos Zoulas <christos@netbsd.org>


Revision tags: uebayasi-xip-base1 yamt-nfs-mp-base9 uebayasi-xip-base
# 1.177 08-Jan-2010 pooka

branches: 1.177.2; 1.177.4;
The VATTR_NULL/VREF/VHOLD/HOLDRELE() macros lost their will to live
years ago when the kernel was modified to not alter ABI based on
DIAGNOSTIC, and now just call the respective function interfaces
(in lowercase). Plenty of mix'n match upper/lowercase has creeped
into the tree since then. Nuke the macros and convert all callsites
to lowercase.

no functional change


Revision tags: matt-premerge-20091211 yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 jym-xensuspend-nbase
# 1.176 03-Jul-2009 elad

Where possible, extract the file-system's access() routine to two internal
functions: the first checking if the operation is possible (regardless of
permissions), the second checking file-system permissions, ACLs, etc.

Mailing list reference:

http://mail-index.netbsd.org/tech-kern/2009/06/21/msg005311.html


# 1.175 23-Jun-2009 elad

Move the implementation of vaccess() to genfs_can_access(), in line with
the other routines of the same spirit.

Adjust file-system code to use it.

Keep vaccess() for KPI compatibility and to keep element of least
surprise. A "diagnostic" message warning that vaccess() is deprecated will
be printed when it's used (obviously, only in DIAGNOSTIC kernels).

No objections on tech-kern@:

http://mail-index.netbsd.org/tech-kern/2009/06/21/msg005310.html


Revision tags: yamt-nfs-mp-base5
# 1.174 24-May-2009 ad

More changes to improve kern_descrip.c.

- Avoid atomics in more places.
- Remove the per-descriptor mutex, and just use filedesc_t::fd_lock.
It was only being used to synchronize close, and in any case we needed
to take fd_lock to free the descriptor slot.
- Optimize certain paths for the <NDFDFILE case.
- Sprinkle more comments and assertions.
- Cache more stuff in filedesc_t.
- Fix numerous minor bugs spotted along the way.
- Restructure how the open files array is maintained, for clarity and so
that we can eliminate the membar_consumer() call in fd_getfile(). This is
mostly syntactic sugar; the main functional change is that fd_nfiles now
lives alongside the open file array.

Some measurements with libmicro:

- simple file syscalls are like close() are between 1 to 10% faster.
- some nice improvements, e.g. poll(1000) which is ~50% faster.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 nick-hppapmap-base2 jym-xensuspend-base nick-hppapmap-base mjf-devfs2-base
# 1.173 17-Dec-2008 cegger

branches: 1.173.2;
kill MALLOC and FREE macros.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 haad-dm-base2 haad-nbase2 ad-audiomp2-base netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 haad-dm-base
# 1.172 05-Sep-2008 skrll

branches: 1.172.2;
PR/39324 kernel diagnostic assertion "l->l_stat != LSZOMB" failed.

Ignore procs with zero or all LSZOMB LWPs. Get a non-LSZOMB LWP to perform
operations against as part of the deal.

procfs really needs to be updated to support multi-threading fully.
Hi Antti!


# 1.171 05-Sep-2008 skrll

ANSIfy


Revision tags: simonb-wapbl-nbase simonb-wapbl-base
# 1.170 02-Jul-2008 rmind

branches: 1.170.2;
Remove proc_representative_lwp(), use a simple LIST_FIRST() instead.
OK by <ad>.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base
# 1.169 28-Apr-2008 martin

branches: 1.169.2; 1.169.4;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-nfs-mp-base
# 1.168 24-Apr-2008 ad

branches: 1.168.2;
Merge proc::p_mutex and proc::p_smutex into a single adaptive mutex, since
we no longer need to guard against access from hardware interrupt handlers.

Additionally, if cloning a process with CLONE_SIGHAND, arrange to have the
child process share the parent's lock so that signal state may be kept in
sync. Partially addresses PR kern/37437.


# 1.167 24-Apr-2008 ad

Network protocol interrupts can now block on locks, so merge the globals
proclist_mutex and proclist_lock into a single adaptive mutex (proc_lock).
Implications:

- Inspecting process state requires thread context, so signals can no longer
be sent from a hardware interrupt handler. Signal activity must be
deferred to a soft interrupt or kthread.

- As the proc state locking is simplified, it's now safe to take exit()
and wait() out from under kernel_lock.

- The system spends less time at IPL_SCHED, and there is less lock activity.


Revision tags: yamt-pf42-baseX yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14
# 1.166 21-Mar-2008 ad

branches: 1.166.2;
Catch up with descriptor handling changes. See kern_descrip.c revision
1.173 for details.


Revision tags: keiichi-mipv6-nbase nick-net80211-sync-base keiichi-mipv6-base bouyer-xeni386-nbase matt-armv6-nbase mjf-devfs-base hpcarm-cleanup-base
# 1.165 23-Jan-2008 elad

branches: 1.165.6;
Tons of process scope changes.

- Add a KAUTH_PROCESS_SCHEDULER action, to handle scheduler related
requests, and add specific requests for set/get scheduler policy and
set/get scheduler parameters.

- Add a KAUTH_PROCESS_KEVENT_FILTER action, to handle kevent(2) related
requests.

- Add a KAUTH_DEVICE_TTY_STI action to handle requests to TIOCSTI.

- Add requests for the KAUTH_PROCESS_CANSEE action, indicating what
process information is being looked at (entry itself, args, env,
open files).

- Add requests for the KAUTH_PROCESS_RLIMIT action indicating set/get.

- Add requests for the KAUTH_PROCESS_CORENAME action indicating set/get.

- Make bsd44 secmodel code handle the newly added rqeuests appropriately.

All of the above make it possible to issue finer-grained kauth(9) calls in
many places, removing some KAUTH_GENERIC_ISSUSER requests.

- Remove the "CAN" from KAUTH_PROCESS_CAN{KTRACE,PROCFS,PTRACE,SIGNAL}.

Discussed with christos@ and yamt@.


Revision tags: bouyer-xeni386-base matt-armv6-base
# 1.164 02-Jan-2008 ad

Merge vmlocking2 to head.


Revision tags: vmlocking2-base3 yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 vmlocking-nbase jmcneill-pm-base reinoud-bufcleanup-base
# 1.163 26-Nov-2007 pooka

branches: 1.163.2; 1.163.6;
Remove the "struct lwp *" argument from all VFS and VOP interfaces.
The general trend is to remove it from all kernel interfaces and
this is a start. In case the calling lwp is desired, curlwp should
be used.

quick consensus on tech-kern


Revision tags: bouyer-xenamd64-base2 bouyer-xenamd64-base
# 1.162 09-Nov-2007 christos

make the last argument of procfs_dir size_t


# 1.161 07-Nov-2007 ad

Merge from vmlocking:

- pool_cache changes.
- Debugger/procfs locking fixes.
- Other minor changes.


Revision tags: jmcneill-base yamt-x86pmap-base4 yamt-x86pmap-base3 vmlocking-base
# 1.160 10-Oct-2007 ad

branches: 1.160.2; 1.160.4;
Merge from vmlocking:

- Split vnode::v_flag into three fields, depending on field locking.
- simple_lock -> kmutex in a few places.
- Fix some simple locking problems.


# 1.159 08-Oct-2007 ad

Merge file descriptor locking, cwdi locking and cross-call changes
from the vmlocking branch.


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base2 yamt-x86pmap-base matt-mips64-base
# 1.158 22-Jul-2007 pooka

branches: 1.158.4; 1.158.6; 1.158.8; 1.158.10;
Don't allow getcwd() on procfs vnodes and provide "/" as the path
instead of the result from getcwd(). The works around locking
panics caused by namei calling VOP_READLINK while holding on to a
directory lock and getcwd() trying to acquire that lock. The real
fix would be to get rid of getcwd() calls within VOPs (not locking
safe), but that's not a viable option in the netbsd-4 timeframe.

Suggestion for workaround from David Holland.


Revision tags: nick-csl-alignment-base mjf-ufs-trans-base
# 1.157 24-May-2007 agc

branches: 1.157.2;
Extend the Linux emulation of /proc to include

/proc/stat
/proc/loadavg and
/proc/<pid>/statm.

These are only present when -o linux is specified as a mount option
to procfs.

Factor out some common code so that it can be used by a number of
functions.

XXX The values returned in the statm emulation need to be verified.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 1.156 04-Apr-2007 rmind

Unfortunately, missed procfs_proc_unlock() in previous.
Pointed out by pooka@


# 1.155 04-Apr-2007 rmind

procfs_readlink: Handle a possible fail of fd_getfile(), also, we
do not need to check for error again.
CID: 4436


# 1.154 09-Mar-2007 ad

branches: 1.154.2; 1.154.4;
- Make the proclist_lock a mutex. The write:read ratio is unfavourable,
and mutexes are cheaper use than RW locks.
- LOCK_ASSERT -> KASSERT in some places.
- Hold proclist_lock/kernel_lock longer in a couple of places.


# 1.153 04-Mar-2007 christos

Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.


# 1.152 03-Mar-2007 salo

Don't prepend rootvnode to the path in non-NULL case for exe links.
It breaks procfs in chroot.

from <christos>, tested by me.


Revision tags: ad-audiomp-base
# 1.151 19-Feb-2007 pooka

When checking for file validity under pid/, do proper proc->lwp
lookup (fsvo proper) instead of fiddling directly with the lwp
list.


# 1.150 18-Feb-2007 pooka

Don't check for validity of p in lookup for root nodes, since it
will always be NULL. Rather, just call pt_valid with NULL directly
and let it decide if we're a linux mount or not.


# 1.149 17-Feb-2007 pavel

Change the process/lwp flags seen by userland via sysctl back to the
P_*/L_* naming convention, and rename the in-kernel flags to avoid
conflict. (P_ -> PK_, L_ -> LW_ ). Add back the (now unused) LSDEAD
constant.

Restores source compatibility with pre-newlock2 tools like ps or top.

Reviewed by Andrew Doran.


# 1.148 16-Feb-2007 pooka

branches: 1.148.2;
In lookup, when checking for procfs process node validity, target the
process we're trying to get information about through procfs, not
the caller of lookup.

fixes 'ls -l /proc/*/file' panic, which would occur when trying to
lookup "file" for a kernel thread, which doesn't have p->p_textvp.


# 1.147 15-Feb-2007 ad

Need to acquire procp->p_mutex for procfs_dir().


# 1.146 11-Feb-2007 ad

Eliminate a couple of reference count and mutex leaks.


Revision tags: post-newlock2-merge
# 1.145 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 1.144 25-Dec-2006 elad

PR/35226: Johann Franz: Problems with permissions in
/usr/pkg/emul/linux/proc .

Okay mlelstv@


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3
# 1.143 09-Dec-2006 chs

a smorgasbord of improvements to vnode locking and path lookup:
- LOCKPARENT is no longer relevant for lookup(), relookup() or VOP_LOOKUP().
these now always return the parent vnode locked. namei() works as before.
lookup() and various other paths no longer acquire vnode locks in the
wrong order via vrele(). fixes PR 32535.
as a nice side effect, path lookup is also up to 25% faster.
- the above allows us to get rid of PDIRUNLOCK.
- also get rid of WANTPARENT (just use LOCKPARENT and unlock it).
- remove an assumption in layer_node_find() that all file systems implement
a recursive VOP_LOCK() (unionfs doesn't).
- require that all file systems supply vfs_vptofh and vfs_fhtovp routines.
fill in eopnotsupp() for file systems that don't support being exported
and remove the checks for NULL. (layerfs calls these without checking.)
- in union_lookup1(), don't change refcounts in the ISDOTDOT case, just
adjust which vnode is locked. fixes PR 33374.
- apply fixes for ufs_rename() from ufs_vnops.c rev. 1.61 to ext2fs_rename().


# 1.142 04-Dec-2006 christos

From Nicolas Joly: restore previous behavior in procfs_validfile_linux, since
readdir passes a NULL lwp.


# 1.141 03-Dec-2006 elad

Move kauth(9) call to where it belongs. Noticed by Nicolas Joly, thanks!


Revision tags: netbsd-4-base
# 1.140 28-Nov-2006 elad

branches: 1.140.2;
Move ktrace, ptrace, systrace, and procfs to use kauth(9).

First, remove process_checkioperm() calls from MD code. Similar checks
using kauth(9) routines (on the process scope, using appropriate action)
are done in the callers.

Add secmodel back-end to handle each subsystem.


# 1.139 25-Nov-2006 skrll

Expose the 'exe' symlink to the process realpath in NetBSD as well. An
example user is gdb.

OK'd by christos.


# 1.138 16-Nov-2006 christos

__unused removal on arguments; approved by core.


# 1.137 29-Oct-2006 christos

add an "emul" file node.


# 1.136 25-Oct-2006 christos

1. fix procfs_validfile{,_linux} to test for NULL pointers properly.
2. make "exe" entry be a symlink to the executable, instead of pointing
directly to the vnode of the executable.
3. factor out commonly used code.


Revision tags: yamt-splraiseipl-base2
# 1.135 12-Oct-2006 christos

- sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386


# 1.134 20-Sep-2006 manu

Emulate Linux's /proc/devices


Revision tags: abandoned-netbsd-4-base yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base rpaulo-netinet-merge-pcb-base
# 1.133 13-Jun-2006 yamt

branches: 1.133.6; 1.133.8;
use KAUTH_PROCESS_CANSEE rather than CURTAIN where appropriate.


# 1.132 13-Jun-2006 yamt

remove unnecessary arguments from kauth_authorize_process.
ie. make it similar to the one found in apple TN.


# 1.131 07-Jun-2006 kardel

merge FreeBSD timecounters from branch simonb-timecounters
- struct timeval time is gone
time.tv_sec -> time_second
- struct timeval mono_time is gone
mono_time.tv_sec -> time_uptime
- access to time via
{get,}{micro,nano,bin}time()
get* versions are fast but less precise
- support NTP nanokernel implementation (NTP API 4)
- further reading:
Timecounter Paper: http://phk.freebsd.dk/pubs/timecounter.pdf
NTP Nanokernel: http://www.eecis.udel.edu/~mills/ntp/html/kern.html


Revision tags: yamt-pdpolicy-base5 simonb-timecounters-base
# 1.130 14-May-2006 elad

branches: 1.130.2;
integrate kauth.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 elad-kernelauth-base yamt-pdpolicy-base yamt-uio_vmspace-base5
# 1.129 02-Feb-2006 christos

branches: 1.129.2; 1.129.4; 1.129.6; 1.129.8;
PR/32692: Matthew Mondor: linux compatibility in /proc/self should point
directly to the directory containing the pid instead of pointing to
/proc/curproc, because some programs rely on calling readlink on /proc/self
to get the pid.


# 1.128 11-Dec-2005 christos

branches: 1.128.2; 1.128.4;
merge ktrace-lwp.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base ktrace-lwp-base
# 1.127 02-Nov-2005 yamt

merge yamt-vop branch. remove following VOPs.

VOP_BLKATOFF
VOP_VALLOC
VOP_BALLOC
VOP_REALLOCBLKS
VOP_VFREE
VOP_TRUNCATE
VOP_UPDATE


Revision tags: yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 1.126 01-Oct-2005 atatat

branches: 1.126.2;
Add "cwd" and "root" symlinks to each process's directory. The cwd
link points to the process's current working directory, and the root
link points to the process's root directory. What else would you
expect?

For directories that are out of reach (caller is in a chroot, target
process is in a different chroot, etc), the links point to "/"
instead.


# 1.125 11-Sep-2005 elad

Implement curtain for procfs.


# 1.124 30-Aug-2005 xtraeme

Remove __P()


# 1.123 29-May-2005 christos

branches: 1.123.2;
- sprinkle const
- avoid shadowed variables.


Revision tags: kent-audio2-base
# 1.122 02-Apr-2005 christos

PR/29782: Martin Husemann: procfs can not unmount when some process has its
current directory in curproc. Fix from Pedro Martelletto:
We cannot call vgone() from procfs_inactive() if we are coming from
vclean(). that's what's probably causing the deadlock.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 yamt-km-base4 yamt-km-base3 netbsd-3-base
# 1.121 26-Feb-2005 perry

nuke trailing whitespace


Revision tags: yamt-km-base2 yamt-km-base kent-audio1-beforemerge kent-audio1-base
# 1.120 04-Oct-2004 yamt

branches: 1.120.4; 1.120.6;
procfs_readdir:
- return correct cookie when buffer size is small.
- simplify logic.


# 1.119 04-Oct-2004 yamt

procfs_readdir: remove a redundant assignment.


# 1.118 02-Oct-2004 yamt

procfs_getattr: correct size of /proc/self.


# 1.117 01-Oct-2004 yamt

procfs_readdir:
- fix a locking problem, using proclist_foreach_call. PR/27098.
- correct snprintf size argument.


# 1.116 01-Oct-2004 yamt

procfs_readdir: fix an offset handling bug after addition of /proc/self.


# 1.115 01-Oct-2004 yamt

procfs_readdir: use a list macro.


# 1.114 20-Sep-2004 jdolecek

add 'mounts' file for -o linux, which lists all currently mounted
filesystems; Linux glibc statvfs() uses this to get some of mount flags,
and this file is also useful as /emul/linux/etc/mtab (via symlink)


# 1.113 29-Apr-2004 jrf

Removed remaining caddr_t casts we do not need in miscfs. Recompiled
kernel and ran for a day or so. There are still some caddr_t types in
the arguments of some calls, I will do those separately (later) as
they touch a lot more of the system.
Approved by christos@NetBSD.org.


# 1.112 22-Apr-2004 itojun

sprintf -> snprintf


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.111 15-Feb-2004 jdolecek

unlock the descriptor table simple lock after fd_getfile() call in
procfs_readdir()
fixes procfs locking problems reported on current-users@, problem place
found by enami tsugutomo


# 1.110 30-Oct-2003 simonb

Remove some assigned-to but otherwise unused variables.


# 1.109 27-Sep-2003 darcy

Changes as discussed with itojun on tech-kern. I have modified the enums
to have KFS or PFS differentiators. Further I have wrapped the enum in
procfs in "#ifdef _KERNEL" as it is done in kernfs.

To see the discussion go to http://mail-index.NetBSD.org/tech-kern/2003/09/
and look for "Mismatched enums in include files" in the list.


# 1.108 07-Sep-2003 itojun

remove meaningless line (variable overwritten 2 lines below)


# 1.107 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.


# 1.106 29-Jun-2003 fvdl

branches: 1.106.2;
Back out the lwp/ktrace changes. They contained a lot of colateral damage,
and need to be examined and discussed more.


# 1.105 29-Jun-2003 thorpej

Undo part of the ktrace/lwp changes. In particular:
* Remove the "lwp *" argument that was added to vget(). Turns out
that nothing actually used it!
* Remove the "lwp *" arguments that were added to VFS_ROOT(), VFS_VGET(),
and VFS_FHTOVP(); all they did was pass it to vget() (which, as noted
above, didn't use it).
* Remove all of the "lwp *" arguments to internal functions that were added
just to appease the above.


# 1.104 28-Jun-2003 darrenr

Pass lwp pointers throughtout the kernel, as required, so that the lwpid can
be inserted into ktrace records. The general change has been to replace
"struct proc *" with "struct lwp *" in various function prototypes, pass
the lwp through and use l_proc to get the process pointer when needed.

Bump the kernel rev up to 1.6V


# 1.103 28-May-2003 christos

Add /proc/<pid>/stat for linux compat. j2sdk1.4.2 depends on it.


# 1.102 18-Apr-2003 christos

Make symlinks for directories that point to the actual directory.
Make symlinks to [kqueue] and [misc] for kqueue and misc fds.


# 1.101 17-Apr-2003 jdolecek

do not show nodes corresponding to directory descriptors for process
in fd/ subdirectory, nor allow lookup/open for the nodes
this fixes PR kern/21187 for good, and also avoids interesting directory
locking issues


# 1.100 17-Apr-2003 jdolecek

procfs_readdir(): in Pfd case, only show descriptors of types we want
how to represent (vnodes, fifo, pipes); also use fd_getfile() et al

this avoids annoying EOPNOTSUPP error messages from ls -F and such


# 1.99 17-Apr-2003 jdolecek

procfs_lookup(): use fd_getfile() et al in Pfd case


# 1.98 17-Apr-2003 jdolecek

use fd_getfile() in procfs_getfp(), and FILE_USE()/FILE_UNUSE() the
returned file descriptor pointer appropriately


# 1.97 17-Apr-2003 jdolecek

make some local arrays/variables static + const


# 1.96 10-Apr-2003 jdolecek

use former genfs_eopnotsupp_rele() as genfs_eopnotsupp(), so that vnodes
are vput()/vrele()d as necessary - some filesystems did use the wrong
one for some ops, and it's just safer to not take the chance

based on suggestion by Bill Studenmund


# 1.95 05-Apr-2003 dsl

Remove pointless check against PID_MAX. Let pfind() do the validation.
(The new pid allocation code may decide to allocate pids above PID_MAX.)


# 1.94 25-Feb-2003 jrf

This addresses PR kerm/19989. Thanks to hamajima@nagoya.ydc.co.jp for submitting this patch which enables /proc/uptime for linux emul. Patch reviewed by atatat@netbsd.org and tron@netbsd.org, approved by tron@netbsd.org.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 1.93 04-Jan-2003 martin

Cast off_t expression to long long to match format even on 64 bit
plattforms.

Shouldn't we introduce a PRIoff_t macro to create such format strings?


# 1.92 03-Jan-2003 christos

add LK_CANRECURSE in the locking of /dev/<pid>/fd/<n> and remove the curproc
kludge. Thanks to fvdl.


# 1.91 03-Jan-2003 christos

Implement /proc/<pid>/fd/<n>. This is work in progress. Questionable things:
- Is it ok to convert DTYPE_PIPE to VFIFO and DTYPE_SOCKET to VSOCK?
- XXX: Avoid locking issue in ls -Rl /proc by avoiding curproc
- Does I/O to pipes work?
- XXX: Are there security implications?


Revision tags: fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge gehenna-devsw-base kqueue-base
# 1.90 03-Aug-2002 simonb

Just use the "time" variable in the *_getattr functions instead of a call
to (the potentially expensive) microtime().


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.89 09-May-2002 thorpej

branches: 1.89.2;
Move code shared by procfs and the kernel proper out of procfs and
into the kernel proper (renaming functions from procfs_* to process_*).


Revision tags: eeh-devprop-base newlock-base ifpoll-base
# 1.88 12-Jan-2002 christos

Don't hide the real return code with EPERM.


# 1.87 06-Dec-2001 chs

add a VOP_PUTPAGES method for all the filesystems that don't have pages,
just unlock the interlock.


# 1.86 05-Dec-2001 thorpej

* Allow machine-dependent code to specify hooks for ptrace(2)
(__HAVE_PTRACE_MACHDEP) and procfs (__HAVE_PROCFS_MACHDEP).
These changes will allow platforms like x86 (XMM) and PowerPC
(AltiVec) to export extended register sets in a sane manner.

* Use __HAVE_PTRACE_MACHDEP to export x86 XMM registers (standard
FP + SSE/SSE2) using PT_{GET,SET}XMMREGS (in the machdep
ptrace request space).
* Use __HAVE_PROCFS_MACHDEP to export x86 XMM registers via
/proc/N/xmmregs in procfs.


Revision tags: thorpej-mips-cache-base
# 1.85 10-Nov-2001 lukem

add RCSIDs


# 1.84 06-Nov-2001 simonb

Remove some variables that are set but never used.


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base
# 1.83 31-Aug-2001 chs

branches: 1.83.2; 1.83.4;
map files are zero-length.


# 1.82 03-Jun-2001 chs

branches: 1.82.2;
procfs_bmap() should never be called, make it a "bad op".
let procfs_mmap() use the default error method.


Revision tags: thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 1.81 14-Apr-2001 kleink

In procfs_readdir(), give /proc/# directories DT_DIR (rather than DT_REG).


# 1.80 30-Mar-2001 fvdl

Bump va_blocksize for the map files some more, so that programs with
quite a few mappings have a chance of being handled correctly if
st_blksize is looked at.


# 1.79 29-Mar-2001 fvdl

For -o linux mounts, add some code to emulate /proc/#/maps.
Needs NAMECACHE_ENTER_REVERSE to include filenames.


# 1.78 21-Feb-2001 jdolecek

branches: 1.78.2;
make some more constant arrays 'const'


# 1.77 22-Jan-2001 jdolecek

make filesystem vnodeop, specop, fifoop and vnodeopv_* arrays const


# 1.76 17-Jan-2001 fvdl

Add a few linux-style files, only enabled when -o linux is specified
for the mount. Currently these are /proc/cpuinfo and /proc/meminfo.
The former only does something on i386 right now.


# 1.75 24-Nov-2000 chs

remove dead code and other misc cleanup.


# 1.74 09-Aug-2000 tv

Only show the "exe" entry to Linux processes, suggested by christos.
Since there are actually three struct emul's for linux, use the e_name
field to determine eligibility with strcmp().


# 1.73 09-Aug-2000 tv

Some versions of Linux libc look for /proc/.../exe instead of /proc/../file.
Add an entry for "exe" that is the same as "file", provided only if
COMPAT_LINUX is set.


# 1.72 03-Aug-2000 thorpej

MALLOC()/FREE() are not to be used for variable sized allocations.


# 1.71 28-Jun-2000 mrg

<vm/vm.h> -> <uvm/uvm_extern.h>


Revision tags: netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 1.70 30-Mar-2000 simonb

branches: 1.70.4;
Delete duplicate declaration of atopid().


Revision tags: chs-ubc2-newbase wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base fvdl-softdep-base
# 1.69 02-Sep-1999 thorpej

branches: 1.69.2; 1.69.8;
Make /proc/self a symlink to /proc/curproc. I've observed Linux programs
that expect /proc/self/cmdline to exist.


# 1.68 25-Aug-1999 sommerfeld

Change variable used for directory offset from "int" to "off_t".
Overkill, but avoids a host of truncation problems.


# 1.67 24-Aug-1999 sommerfeld

Fix PR8270:

Problem turned out to be due to improper handling of reads beyond EOF:
they should just return without error with the uio unchanged, and the
caller will recognize this as a zero-byte return (EOF).

The previous fix to protect directory reads against bogus uio_offset
values returned EINVAL, which broke mount -o union, which only
union'ed in the lower directory if the upper directory cleanly
returned EOF.

While we're here, protect kernfs as well.


# 1.66 14-Aug-1999 christos

protect against large uio_offset


# 1.65 03-Aug-1999 wrstuden

Add support for fcntl(2) to generate VOP_FCNTL calls. Any fcntl
call with F_FSCTL set and F_SETFL calls generate calls to a new
fileop fo_fcntl. Add genfs_fcntl() and soo_fcntl() which return 0
for F_SETFL and EOPNOTSUPP otherwise. Have all leaf filesystems
use genfs_fcntl().

Reviewed by: thorpej
Tested by: wrstuden


Revision tags: chs-ubc2-base
# 1.64 25-Jul-1999 thorpej

Add calls to lock the proclist as appropriate.


# 1.63 14-Jul-1999 thorpej

Fix a paste-o in procfs_lookup() introduced with the vnode locking changes.
Fixes PR #7961, Mario Kemper <magick@bundy.lip.owl.de>.


# 1.62 08-Jul-1999 wrstuden

Bump osrelease to 1.4E. Add layerfs files, remove null_subr.c.

Update coda to new struct lock in struct vnode.

make fdescfs, kernfs, portalfs, and procfs actually lock their vnodes.
It's not that hard.

Make unionfs set v_vnlock = NULL so any overlayed fs will call its
VOP_LOCK.


Revision tags: kame_141_19991130 netbsd-1-4-PATCH001 kame_14_19990705 kame_14_19990628 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.61 12-Mar-1999 christos

branches: 1.61.2; 1.61.4;
PR/7143: Jaromir Docelek: Add procfs/cmdline from Linux emulation


# 1.60 25-Jan-1999 msaitoh

Add /proc/#/map. From FreeBSD.


Revision tags: kenh-if-detach-base chs-ubc-base
# 1.59 08-Sep-1998 thorpej

- Use proclists[], rather than checking allproc and zombproc explicitly.
- Add some comments about locking.


# 1.58 13-Aug-1998 kleink

Per POSIX, fail with EINVAL if advisory locking is attempted on a file type
that doesn't support it, rather than using a homegrown EBADF or EOPNOTSUPP.


# 1.57 10-Aug-1998 matthias

create miscfs/genfs/genfs_vnops.c:genfs_enoioctl and make all the other
filesystems use it instead of a private version.


# 1.56 09-Aug-1998 perry

bzero->memset, bcopy->memcpy, bcmp->memcmp


# 1.55 03-Aug-1998 kleink

Recognize _PC_SYNC_IO.


Revision tags: eeh-paddr_t-base
# 1.54 21-Apr-1998 fvdl

procfs_readdir: in case of error, check if cookies actually have
been allocated before freeing them. From Wolfgang Solfrank.


# 1.53 01-Mar-1998 fvdl

Merge with Lite2 + local changes


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base marc-pcmcia-base
# 1.52 10-Oct-1997 fvdl

Bump last argument to VOP_READDIR to off_t (from u_long).


Revision tags: thorpej-signal-base
# 1.51 27-Aug-1997 thorpej

Fix a reversed argument which caused procfs_checkioperm() to always return
"OK". Add a few comments to avoid further confusion.


# 1.50 12-Aug-1997 thorpej

Fix the procfs hole described on current-users, similar to a fix for
FreeBSD by Sean Eric Fagan, but a bit different. This makes the checks
in the same places as sef's FreeBSD patch, but does not hardcode the
"kmem" group into the kernel, and also does a check identical to the
(3) and (4) checks in the NetBSD ptrace(2):

(1) it's not owned by you, or is set-id on exec (unless
you're root), or

(2) it's init, which controls the security level of the
entire system, and the system was not compiled with
permanently insecure mode turned on.


Revision tags: marc-pcmcia-bp
# 1.49 08-May-1997 mycroft

branches: 1.49.4;
Pass the vnode type to vaccess(), and use it when checking VEXEC. Make sure
that the mode bits passed to vaccess() and returned by foo_getattr() contain
only permission bits.


# 1.48 05-May-1997 mycroft

Need stat.h.


# 1.47 05-May-1997 mycroft

Eliminate bogus uses of V{READ,WRITE,EXEC}. Use S_I[RWX]{USR,GRP,OTH} where
appropriate.


# 1.46 28-Apr-1997 mycroft

Minor code cleanup.


Revision tags: is-newarp-before-merge is-newarp-base
# 1.45 25-Oct-1996 cgd

define path name string variables that we should not (and, thankfully, do
not) modify as 'const char *' rather 'char *'.


# 1.44 13-Oct-1996 christos

backout previous kprintf changes


# 1.43 10-Oct-1996 christos

printf -> kprintf, sprintf -> ksprintf


# 1.42 07-Sep-1996 mycroft

Implement poll(2).


# 1.41 01-Sep-1996 mycroft

Add a set of generic file system operations that most file systems use.
Also, fix some time stamp bogosities.


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 1.40 16-Mar-1996 christos

Fix printf format follies.


# 1.39 13-Feb-1996 mycroft

GC *_nullop(). Minor nits.


# 1.38 12-Feb-1996 christos

close PR/2063: procfs_rw prototyped twice with different prototypes


# 1.37 09-Feb-1996 christos

miscfs prototype changes


# 1.36 09-Feb-1996 mycroft

Fix vop_link, vop_symlink, and vop_remove semantics in several ways:
* Change the argument names to vop_link so they actually make sense.
* Implement vop_link and vop_symlink for all file systems, so they do proper
cleanup.
* Require the file system to decide whether or not linking and unlinking of
directories is allowed, and disable it for all current file systems.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.35 09-Oct-1995 mycroft

Use the index number as the cookie, rather than multiplying by UIO_MX.


# 1.34 09-Oct-1995 mycroft

Add support for cookies, mostly from Greg Hudson.


# 1.33 15-Apr-1995 cgd

fix timeval vs. timespec warnings


# 1.32 03-Feb-1995 mycroft

Return EROFS rather than ENOENT in many cases. Also some cosmetic cleanup.


# 1.31 27-Dec-1994 mycroft

Format police.


# 1.30 24-Dec-1994 ws

Implement and use a common access checking routine


# 1.29 14-Dec-1994 mycroft

Remove a_fp.


# 1.28 14-Nov-1994 christos

fixed struct comment


# 1.27 30-Oct-1994 cgd

be more careful with types, also pull in headers where necessary.


# 1.26 20-Oct-1994 cgd

update for new syscall args description mechanism


# 1.25 30-Aug-1994 mycroft

Convert process, file, and namei lists and hash tables to use queue.h.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.24 29-Jun-1994 cgd

New RCS ID's, take two. they're more aesthecially pleasant, and use 'NetBSD'


# 1.23 16-Jun-1994 mycroft

Remove an unneeded test.


# 1.22 15-Jun-1994 mycroft

Minor update from JSP after merging my changes.


# 1.21 08-Jun-1994 mycroft

Update to 4.4-Lite fs code, with local changes.


# 1.20 05-May-1994 cgd

lots of changes: prototype migration, move lots of variables, definitions,
and structure elements around. kill some unnecessary type and macro
definitions. standardize clock handling. More changes than you'd want.


# 1.19 15-Apr-1994 cgd

forgot these...


# 1.18 12-Apr-1994 cgd

be a bit smarter about determining if files shouldn't be seen by the user.
Also, DON'T allow a lookup to succeed on a file that's not visible!


# 1.17 15-Feb-1994 mycroft

Undo last change; executables is `file', not `a.out'.


# 1.16 14-Feb-1994 ws

Rename file -> a.out


# 1.15 14-Feb-1994 ws

Don't try to show a file for a process if there is none


# 1.14 28-Jan-1994 cgd

make a fpregs file.


# 1.13 20-Jan-1994 ws

Make procfs really work for debugging.
Implement not & notepg files in procfs.


# 1.12 09-Jan-1994 ws

Bug fixes and enhancements:
Make NFS serving work (BUT DON'T USE "attach" TO /proc/*/ctl FOR NOW!!!)
Make `curproc' a symbolic link
Add `.' and `..' entries to the directories.
Return better guesses on the size of the files.


# 1.11 05-Jan-1994 cgd

return size of 'reg' from getattr()


# 1.10 05-Jan-1994 cgd

make it compile (cleanly) for us


# 1.9 05-Jan-1994 cgd

add new procfs code, from Jan-Simon Pendry, jsp@sequent.com.
This is pretty-much "virgin", so that diffs can be done later.


# 1.8 18-Dec-1993 mycroft

Canonicalize all #includes.


Revision tags: magnum-base
# 1.7 16-Sep-1993 cgd

kill volatile warning.


# 1.6 07-Sep-1993 ws

branches: 1.6.2;
Changes to VFS readdir semantics
NFS changes for better cookie support
ISOFS changes for better Rockridge support and support for generation numbers


# 1.5 26-Aug-1993 pk

Implement setattr: mode for process entries; mode + uid/gid for the
PROCFS root directory.
Fixed omission in pfs_root() which came to light as a result of the above:
hold on to vnode for root dir.


# 1.4 25-Aug-1993 pk

Fixed improperly initialized nfsnode in pfs_lookup()


# 1.3 24-Aug-1993 pk

copyright update.


# 1.2 24-Aug-1993 pk

Rcs Id added.


# 1.1 24-Aug-1993 pk

branches: 1.1.1;
Initial version of a proc filesystem.


# 1.224 11-Jan-2022 christos

remove redundant error initialization and break earlier. (from rvp)


# 1.223 11-Jan-2022 hannken

Use a single "p" variable.

Should fix PR kern/56614: kernel panic on tmux


# 1.222 10-Jan-2022 christos

use a single nc variable.


# 1.221 10-Jan-2022 christos

Fix locking in the error path (from RVP). Centralize unlock code.


# 1.220 08-Dec-2021 andvar

s/efficent/efficient/ in comments.


# 1.219 05-Oct-2021 christos

PR/53299: RVP: kernfs and procfs are broken when sysctl security.curtain
is enabled


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base thorpej-i2c-spi-conf-base
# 1.218 18-Jul-2021 dholland

Abolish all the silly indirection macros for initializing vnode ops tables.

These are things of the form #define foofs_op genfs_op, or #define
foofs_op genfs_eopnotsupp, or similar. They serve no purpose besides
obfuscation, and have gotten cutpasted all over everywhere.


# 1.217 29-Jun-2021 dholland

- Add a new vnode op: VOP_PARSEPATH.
- Move namei_getcomponent to genfs_vnops.c and call it genfs_parsepath.
- Add a parsepath entry to every vnode ops table.

VOP_PARSEPATH takes a directory vnode to be searched and a complete
following path and chooses how much of that path to consume. To begin
with, all parsepath calls are genfs_parsepath, which locates the first
'/' as always.

Note that the call doesn't take the whole struct componentname, only
the string. The other bits of struct componentname should not be
needed and there's no reason to cause potential complications by
exposing them.


# 1.216 28-Jun-2021 chs

VOP_BMAP() may be called via ioctl(FIOGETBMAP) on any vnode that applications
can open. change various pseudo-fs *_bmap methods return an error instead of
panic.

Reported-by: syzbot+8289a3eaf2ba60958c87@syzkaller.appspotmail.com


Revision tags: cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base thorpej-cfargs-base thorpej-futex-base
# 1.215 27-Jun-2020 christos

branches: 1.215.6;
Introduce genfs_pathconf() and use it for the default case in all filesystems.


# 1.214 23-May-2020 ad

Move proc_lock into the data segment. It was dynamically allocated because
at the time we had mutex_obj_alloc() but not __cacheline_aligned.


# 1.213 16-May-2020 christos

Add ACL support for FFS. From FreeBSD.


# 1.212 29-Apr-2020 thorpej

If the procfs mount is marked as linux-compat, then allow proc lookup
by any LWP ID in the proc, not just the canonical PID.


Revision tags: bouyer-xenpvh-base2
# 1.211 21-Apr-2020 ad

Revert the changes made in February to make cwdinfo use mostly lockless,
which relied on taking extra vnode refs.

Having benchmarked various experimental changes over the past few months it
seems that it's better to avoid vnode refs as much as possible. cwdi_lock
as a RW lock already did that to some extent for getcwd() and will permit
the same for namei() too.


Revision tags: phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base is-mlppp-base phil-wifi-20200406 ad-namecache-base3
# 1.210 24-Feb-2020 ad

branches: 1.210.4;
v_interlock -> vmobjlock


# 1.209 23-Feb-2020 ad

Merge from ad-namecache:

- Have a stab at clustering the members of vnode_t and vnode_impl_t in a
more cache-conscious way. With that done, go back to adjusting v_usecount
with atomics and keep vi_lock directly in vnode_impl_t (saves KVA).

- Allow VOP_LOCK(LK_NONE) for the benefit of VFS_VGET() and VFS_ROOT().
Make sure LK_UPGRADE always comes with LK_NOWAIT.

- Make cwdinfo use mostly lockless.


# 1.208 01-Feb-2020 riastradh

Load struct filedesc::fd_dt with atomic_load_consume.

Exceptions: when fd_refcnt <= 1, or when holding fd_lock.

While here:

- Restore KASSERT(mutex_owned(&fdp->fd_lock)) in fd_unused.
=> This is used only in fd_close and fd_abort, where it holds.
- Move bounds check assertion in fd_putfile to where it matters.
- Store fd_dt with atomic_store_release.
- Move load of fd_dt under lock in knote_fdclose.
- Omit membar_consumer in fdesc_readdir.
=> atomic_load_consume serves the same purpose now.
=> Was needed only on alpha anyway.


Revision tags: ad-namecache-base2 ad-namecache-base1 ad-namecache-base phil-wifi-20191119
# 1.207 29-Aug-2019 hannken

branches: 1.207.2;
Add missing operation VOP_GETPAGES() returning EFAULT.

Without this operation posix_fadvise(..., POSIX_FADV_WILLNEED)
would leave the v_interlock held.

Observed by maxv@


Revision tags: netbsd-9-base phil-wifi-20190609 isaki-audio2-base
# 1.206 30-Mar-2019 christos

branches: 1.206.4;
add a node for the process resource limits.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020
# 1.205 14-Oct-2018 jdolecek

remove M_CANFAIL flag for malloc(9) - it was completely ignored, so had
actually no effect


Revision tags: pgoyette-compat-0930 pgoyette-compat-0906
# 1.204 03-Sep-2018 riastradh

Rename min/max -> uimin/uimax for better honesty.

These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER! Some subsystems have

#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)


Revision tags: pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415
# 1.203 07-Apr-2018 hannken

branches: 1.203.2;
Lock the target cwdi and take an additional reference to the
vnode we are interested in to prevent it from disappearing
before getcwd_common().

Should fix PR kern/53096 (netbsd-8 crash on heavy disk I/O)


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.202 31-Dec-2017 christos

branches: 1.202.2;
Add an environ node


Revision tags: tls-maxphys-base-20171202
# 1.201 01-Dec-2017 christos

Allow procfs_kqfilter, since we allow poll. "go" does it.


# 1.200 08-Nov-2017 christos

fix locking, remove error(1) comments.


# 1.199 08-Nov-2017 christos

use p->p_path, remove unused code.


# 1.198 28-Aug-2017 kamil

Remove the filesystem tracing feature

This is a legacy interface from 4.4BSD, and it was
introduced to overcome shortcomings of ptrace(2) at that time, which are
no longer relevant (performance). Today /proc/#/ctl offers a narrow
subset of ptrace(2) commands and is not applicable for modern
applications use beyond simplistic tracing scenarios.

This removal will simplify kernel internals. Users will still be able to
use all the other /proc files.

This change won't affect other procfs files neither Linux compat
features within mount_procfs(8). /proc/#/ctl isn't available on Linux.

Remove:
- /proc/#/ctl from mount_procfs(8)
- P_FSTRACE note from the documentation of ps(1)
- /proc/#/ctl and filesystem tracing documentation from mount_procfs(8)
- KAUTH_REQ_PROCESS_PROCFS_CTL documentation from kauth(9)
- source code file miscfs/procfs/procfs_ctl.c
- PFSctl and procfs_doctl() from sys/miscfs/procfs/procfs.h
- KAUTH_REQ_PROCESS_PROCFS_CTL from sys/sys/kauth.h
- PSL_FSTRACE (0x00010000) from sys/sys/proc.h
- P_FSTRACE (0x00010000) from sys/sys/sysctl.h

Reduce code complexity after removal of this functionality.

Update TODO.ptrace accordingly: remove two entries about /proc tracing.

Do not keep legacy notes as comments in the headers about removed
PSL_FSTRACE / P_FSTRACE, as this interface had little number of users
(close or equal to zero).

Proposed on tech-kern@.

All filesystem tracing utility users are encouraged to switch to ptrace(2).

Sponsored by <The NetBSD Foundation>


Revision tags: matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base
# 1.197 26-May-2017 riastradh

branches: 1.197.2;
Make VOP_RECLAIM do the last unlock of the vnode.

VOP_RECLAIM naturally has exclusive access to the vnode, so having it
locked on entry is not strictly necessary -- but it means if there
are any final operations that must be done on the vnode, such as
ffs_update, requiring exclusive access to it, we can now kassert that
the vnode is locked in those operations.

We can't just have the caller release the last lock because some file
systems don't use genfs_lock, and require the vnode to remain valid
for VOP_UNLOCK to work, notably unionfs.


Revision tags: prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.196 11-Apr-2017 riastradh

Make VOP_INACTIVE preserve vnode lock on return.

Discussed on tech-kern:
https://mail-index.netbsd.org/tech-kern/2017/04/01/msg021751.html

Ride 7.99.68, a bumpy bus of incremental vfs improvements!


Revision tags: jdolecek-ncq-base
# 1.195 30-Mar-2017 christos

add an auxv node.


Revision tags: pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004 localcount-20160914
# 1.194 20-Aug-2016 hannken

branches: 1.194.2;
Remove now obsolete operation vcache_remove().

Welcome to 7.99.36


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 nick-nhusb-base-20150921 nick-nhusb-base-20150606
# 1.193 20-Apr-2015 riastradh

branches: 1.193.2;
Make VOP_LINK return directory still locked and referenced.

Ride 7.99.10 bump.


Revision tags: nick-nhusb-base-20150406 nick-nhusb-base
# 1.192 05-Sep-2014 matt

branches: 1.192.2;
Try not to use f_data, use f_{vnode,socket,pipe,mqueue,kqueue,ksem} to get
a correctly typed pointer.


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.191 27-Jul-2014 hannken

branches: 1.191.2; 1.191.4; 1.191.8;
Change procfs from hashlist to vcache.
- Key is (type, pid, fd)
- Remove argument "p" from procfs_allocvp(). It is only used
when "type == PFSfd". Lookup the proc with proc_find() when
procfs_loadvnode() needs it.
- Use a vfs_vnode_iterator for procfs_revoke_vnodes().


# 1.190 25-Jul-2014 dholland

Add VOP_FALLOCATE and VOP_FDISCARD to every vnode ops table I can
find.

The filesystem ones all call genfs_eopnotsupp - right now I am only
implementing the plumbing and we can implement fallocate and/or
fdiscard for files later.

The device ones call spec_fallocate (which is also genfs_eopnotsupp)
and spec_fdiscard, which dispatches to the device-level op.

The fifo ones all call vn_fifo_bypass, which also ends up being
EOPNOTSUPP.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base
# 1.189 07-Feb-2014 hannken

branches: 1.189.2;
Change vnode operation lookup to return the resulting vnode *vpp unlocked.
Change cache_lookup() to return an unlocked vnode.

Discussed on tech-kern@

Welcome to 6.99.31


# 1.188 23-Jan-2014 hannken

Change vnode operations create, mknod, mkdir and symlink to return
the resulting vnode *vpp unlocked.

Discussed on tech-kern@

Welcome to 6.99.30


# 1.187 17-Jan-2014 hannken

Change vnode operations create, mknod, mkdir and symlink to keep the
directory node dvp locked on return.

Discussed on tech-kern@

Welcome to 6.99.29


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base
# 1.186 18-Mar-2013 plunky

branches: 1.186.6;
C99 section 6.7.2.3 (Tags) Note 3 states that:

A type specifier of the form

enum identifier

without an enumerator list shall only appear after the type it
specifies is complete.

which means that we cannot pass an "enum vtype" argument to
kauth_access_action() without fully specifying the type first.
Unfortunately there is a complicated include file loop which
makes that difficult, so convert this minimal function into a
macro (and capitalize it).

(ok elad@)


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 1.185 25-Nov-2012 christos

do something reasonable with kernel semaphores.


Revision tags: yamt-pagecache-base6 jmcneill-usbmp-base10
# 1.184 28-May-2012 christos

branches: 1.184.2;
add a task process subdirectory for emul linux


Revision tags: yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 1.183 13-Mar-2012 elad

Replace the remaining KAUTH_GENERIC_ISSUSER authorization calls with
something meaningful. All relevant documentation has been updated or
written.

Most of these changes were brought up in the following messages:

http://mail-index.netbsd.org/tech-kern/2012/01/18/msg012490.html
http://mail-index.netbsd.org/tech-kern/2012/01/19/msg012502.html
http://mail-index.netbsd.org/tech-kern/2012/02/17/msg012728.html

Thanks to christos, manu, njoly, and jmmv for input.

Huge thanks to pgoyette for spinning these changes through some build
cycles and ATF.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.182 04-Sep-2011 jmcneill

branches: 1.182.2; 1.182.6;
PR# kern/45021: Please support /emul/linux/proc/version

Add /proc/version for procfs with -o linux. The version reported depends
on the emulation type of the calling process:

$ cat /proc/version
NetBSD version 5.99.55 (netbsd@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) NetBSD 5.99.55 (GENERIC) #39: Sun Sep 4 09:10:05 EDT 2011

$ /emul/linux/bin/cat /proc/version
Linux version 2.6.18 (linux@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) #0 Wed Mar 3 03:03:03 PST 2010

$ /emul/linux32/bin/cat /proc/version
Linux version 2.6.18 (linux32@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) #0 Wed Mar 3 03:03:03 PST 2010


# 1.181 23-Jun-2011 christos

From Aleksey Cheusov: Don't make it easy for compromised systems to bypass
ASLR protections by providing the mapping addresses of programs to everyone.


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base matt-mips64-premerge-20101231 uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10 rmind-uvmplock-base
# 1.180 01-Jul-2010 rmind

Remove pfind() and pgfind(), fix locking in various broken uses of these.
Rename real routines to proc_find() and pgrp_find(), remove PFIND_* flags
and have consistent behaviour. Provide proc_find_raw() for special cases.
Fix memory leak in sysctl_proc_corename().

COMPAT_LINUX: rework ptrace() locking, minimise differences between
different versions per-arch.

Note: while this change adds some formal cosmetics for COMPAT_DARWIN and
COMPAT_IRIX - locking there is utterly broken (for ages).

Fixes PR/43176.


# 1.179 24-Jun-2010 hannken

Clean up vnode lock operations pass 2:

VOP_UNLOCK(vp, flags) -> VOP_UNLOCK(vp): Remove the unneeded flags argument.

Welcome to 5.99.32.

Discussed on tech-kern.


# 1.178 08-Jun-2010 hannken

Procfs_lookup() does not lookup directory descriptors in the fd/
subdirectory. There is no need for recursive vnode locking here.

Ok: Christos Zoulas <christos@netbsd.org>


Revision tags: uebayasi-xip-base1 yamt-nfs-mp-base9 uebayasi-xip-base
# 1.177 08-Jan-2010 pooka

branches: 1.177.2; 1.177.4;
The VATTR_NULL/VREF/VHOLD/HOLDRELE() macros lost their will to live
years ago when the kernel was modified to not alter ABI based on
DIAGNOSTIC, and now just call the respective function interfaces
(in lowercase). Plenty of mix'n match upper/lowercase has creeped
into the tree since then. Nuke the macros and convert all callsites
to lowercase.

no functional change


Revision tags: matt-premerge-20091211 yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 jym-xensuspend-nbase
# 1.176 03-Jul-2009 elad

Where possible, extract the file-system's access() routine to two internal
functions: the first checking if the operation is possible (regardless of
permissions), the second checking file-system permissions, ACLs, etc.

Mailing list reference:

http://mail-index.netbsd.org/tech-kern/2009/06/21/msg005311.html


# 1.175 23-Jun-2009 elad

Move the implementation of vaccess() to genfs_can_access(), in line with
the other routines of the same spirit.

Adjust file-system code to use it.

Keep vaccess() for KPI compatibility and to keep element of least
surprise. A "diagnostic" message warning that vaccess() is deprecated will
be printed when it's used (obviously, only in DIAGNOSTIC kernels).

No objections on tech-kern@:

http://mail-index.netbsd.org/tech-kern/2009/06/21/msg005310.html


Revision tags: yamt-nfs-mp-base5
# 1.174 24-May-2009 ad

More changes to improve kern_descrip.c.

- Avoid atomics in more places.
- Remove the per-descriptor mutex, and just use filedesc_t::fd_lock.
It was only being used to synchronize close, and in any case we needed
to take fd_lock to free the descriptor slot.
- Optimize certain paths for the <NDFDFILE case.
- Sprinkle more comments and assertions.
- Cache more stuff in filedesc_t.
- Fix numerous minor bugs spotted along the way.
- Restructure how the open files array is maintained, for clarity and so
that we can eliminate the membar_consumer() call in fd_getfile(). This is
mostly syntactic sugar; the main functional change is that fd_nfiles now
lives alongside the open file array.

Some measurements with libmicro:

- simple file syscalls are like close() are between 1 to 10% faster.
- some nice improvements, e.g. poll(1000) which is ~50% faster.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 nick-hppapmap-base2 jym-xensuspend-base nick-hppapmap-base mjf-devfs2-base
# 1.173 17-Dec-2008 cegger

branches: 1.173.2;
kill MALLOC and FREE macros.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 haad-dm-base2 haad-nbase2 ad-audiomp2-base netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 haad-dm-base
# 1.172 05-Sep-2008 skrll

branches: 1.172.2;
PR/39324 kernel diagnostic assertion "l->l_stat != LSZOMB" failed.

Ignore procs with zero or all LSZOMB LWPs. Get a non-LSZOMB LWP to perform
operations against as part of the deal.

procfs really needs to be updated to support multi-threading fully.
Hi Antti!


# 1.171 05-Sep-2008 skrll

ANSIfy


Revision tags: simonb-wapbl-nbase simonb-wapbl-base
# 1.170 02-Jul-2008 rmind

branches: 1.170.2;
Remove proc_representative_lwp(), use a simple LIST_FIRST() instead.
OK by <ad>.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base
# 1.169 28-Apr-2008 martin

branches: 1.169.2; 1.169.4;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-nfs-mp-base
# 1.168 24-Apr-2008 ad

branches: 1.168.2;
Merge proc::p_mutex and proc::p_smutex into a single adaptive mutex, since
we no longer need to guard against access from hardware interrupt handlers.

Additionally, if cloning a process with CLONE_SIGHAND, arrange to have the
child process share the parent's lock so that signal state may be kept in
sync. Partially addresses PR kern/37437.


# 1.167 24-Apr-2008 ad

Network protocol interrupts can now block on locks, so merge the globals
proclist_mutex and proclist_lock into a single adaptive mutex (proc_lock).
Implications:

- Inspecting process state requires thread context, so signals can no longer
be sent from a hardware interrupt handler. Signal activity must be
deferred to a soft interrupt or kthread.

- As the proc state locking is simplified, it's now safe to take exit()
and wait() out from under kernel_lock.

- The system spends less time at IPL_SCHED, and there is less lock activity.


Revision tags: yamt-pf42-baseX yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14
# 1.166 21-Mar-2008 ad

branches: 1.166.2;
Catch up with descriptor handling changes. See kern_descrip.c revision
1.173 for details.


Revision tags: keiichi-mipv6-nbase nick-net80211-sync-base keiichi-mipv6-base bouyer-xeni386-nbase matt-armv6-nbase mjf-devfs-base hpcarm-cleanup-base
# 1.165 23-Jan-2008 elad

branches: 1.165.6;
Tons of process scope changes.

- Add a KAUTH_PROCESS_SCHEDULER action, to handle scheduler related
requests, and add specific requests for set/get scheduler policy and
set/get scheduler parameters.

- Add a KAUTH_PROCESS_KEVENT_FILTER action, to handle kevent(2) related
requests.

- Add a KAUTH_DEVICE_TTY_STI action to handle requests to TIOCSTI.

- Add requests for the KAUTH_PROCESS_CANSEE action, indicating what
process information is being looked at (entry itself, args, env,
open files).

- Add requests for the KAUTH_PROCESS_RLIMIT action indicating set/get.

- Add requests for the KAUTH_PROCESS_CORENAME action indicating set/get.

- Make bsd44 secmodel code handle the newly added rqeuests appropriately.

All of the above make it possible to issue finer-grained kauth(9) calls in
many places, removing some KAUTH_GENERIC_ISSUSER requests.

- Remove the "CAN" from KAUTH_PROCESS_CAN{KTRACE,PROCFS,PTRACE,SIGNAL}.

Discussed with christos@ and yamt@.


Revision tags: bouyer-xeni386-base matt-armv6-base
# 1.164 02-Jan-2008 ad

Merge vmlocking2 to head.


Revision tags: vmlocking2-base3 yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 vmlocking-nbase jmcneill-pm-base reinoud-bufcleanup-base
# 1.163 26-Nov-2007 pooka

branches: 1.163.2; 1.163.6;
Remove the "struct lwp *" argument from all VFS and VOP interfaces.
The general trend is to remove it from all kernel interfaces and
this is a start. In case the calling lwp is desired, curlwp should
be used.

quick consensus on tech-kern


Revision tags: bouyer-xenamd64-base2 bouyer-xenamd64-base
# 1.162 09-Nov-2007 christos

make the last argument of procfs_dir size_t


# 1.161 07-Nov-2007 ad

Merge from vmlocking:

- pool_cache changes.
- Debugger/procfs locking fixes.
- Other minor changes.


Revision tags: jmcneill-base yamt-x86pmap-base4 yamt-x86pmap-base3 vmlocking-base
# 1.160 10-Oct-2007 ad

branches: 1.160.2; 1.160.4;
Merge from vmlocking:

- Split vnode::v_flag into three fields, depending on field locking.
- simple_lock -> kmutex in a few places.
- Fix some simple locking problems.


# 1.159 08-Oct-2007 ad

Merge file descriptor locking, cwdi locking and cross-call changes
from the vmlocking branch.


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base2 yamt-x86pmap-base matt-mips64-base
# 1.158 22-Jul-2007 pooka

branches: 1.158.4; 1.158.6; 1.158.8; 1.158.10;
Don't allow getcwd() on procfs vnodes and provide "/" as the path
instead of the result from getcwd(). The works around locking
panics caused by namei calling VOP_READLINK while holding on to a
directory lock and getcwd() trying to acquire that lock. The real
fix would be to get rid of getcwd() calls within VOPs (not locking
safe), but that's not a viable option in the netbsd-4 timeframe.

Suggestion for workaround from David Holland.


Revision tags: nick-csl-alignment-base mjf-ufs-trans-base
# 1.157 24-May-2007 agc

branches: 1.157.2;
Extend the Linux emulation of /proc to include

/proc/stat
/proc/loadavg and
/proc/<pid>/statm.

These are only present when -o linux is specified as a mount option
to procfs.

Factor out some common code so that it can be used by a number of
functions.

XXX The values returned in the statm emulation need to be verified.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 1.156 04-Apr-2007 rmind

Unfortunately, missed procfs_proc_unlock() in previous.
Pointed out by pooka@


# 1.155 04-Apr-2007 rmind

procfs_readlink: Handle a possible fail of fd_getfile(), also, we
do not need to check for error again.
CID: 4436


# 1.154 09-Mar-2007 ad

branches: 1.154.2; 1.154.4;
- Make the proclist_lock a mutex. The write:read ratio is unfavourable,
and mutexes are cheaper use than RW locks.
- LOCK_ASSERT -> KASSERT in some places.
- Hold proclist_lock/kernel_lock longer in a couple of places.


# 1.153 04-Mar-2007 christos

Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.


# 1.152 03-Mar-2007 salo

Don't prepend rootvnode to the path in non-NULL case for exe links.
It breaks procfs in chroot.

from <christos>, tested by me.


Revision tags: ad-audiomp-base
# 1.151 19-Feb-2007 pooka

When checking for file validity under pid/, do proper proc->lwp
lookup (fsvo proper) instead of fiddling directly with the lwp
list.


# 1.150 18-Feb-2007 pooka

Don't check for validity of p in lookup for root nodes, since it
will always be NULL. Rather, just call pt_valid with NULL directly
and let it decide if we're a linux mount or not.


# 1.149 17-Feb-2007 pavel

Change the process/lwp flags seen by userland via sysctl back to the
P_*/L_* naming convention, and rename the in-kernel flags to avoid
conflict. (P_ -> PK_, L_ -> LW_ ). Add back the (now unused) LSDEAD
constant.

Restores source compatibility with pre-newlock2 tools like ps or top.

Reviewed by Andrew Doran.


# 1.148 16-Feb-2007 pooka

branches: 1.148.2;
In lookup, when checking for procfs process node validity, target the
process we're trying to get information about through procfs, not
the caller of lookup.

fixes 'ls -l /proc/*/file' panic, which would occur when trying to
lookup "file" for a kernel thread, which doesn't have p->p_textvp.


# 1.147 15-Feb-2007 ad

Need to acquire procp->p_mutex for procfs_dir().


# 1.146 11-Feb-2007 ad

Eliminate a couple of reference count and mutex leaks.


Revision tags: post-newlock2-merge
# 1.145 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 1.144 25-Dec-2006 elad

PR/35226: Johann Franz: Problems with permissions in
/usr/pkg/emul/linux/proc .

Okay mlelstv@


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3
# 1.143 09-Dec-2006 chs

a smorgasbord of improvements to vnode locking and path lookup:
- LOCKPARENT is no longer relevant for lookup(), relookup() or VOP_LOOKUP().
these now always return the parent vnode locked. namei() works as before.
lookup() and various other paths no longer acquire vnode locks in the
wrong order via vrele(). fixes PR 32535.
as a nice side effect, path lookup is also up to 25% faster.
- the above allows us to get rid of PDIRUNLOCK.
- also get rid of WANTPARENT (just use LOCKPARENT and unlock it).
- remove an assumption in layer_node_find() that all file systems implement
a recursive VOP_LOCK() (unionfs doesn't).
- require that all file systems supply vfs_vptofh and vfs_fhtovp routines.
fill in eopnotsupp() for file systems that don't support being exported
and remove the checks for NULL. (layerfs calls these without checking.)
- in union_lookup1(), don't change refcounts in the ISDOTDOT case, just
adjust which vnode is locked. fixes PR 33374.
- apply fixes for ufs_rename() from ufs_vnops.c rev. 1.61 to ext2fs_rename().


# 1.142 04-Dec-2006 christos

From Nicolas Joly: restore previous behavior in procfs_validfile_linux, since
readdir passes a NULL lwp.


# 1.141 03-Dec-2006 elad

Move kauth(9) call to where it belongs. Noticed by Nicolas Joly, thanks!


Revision tags: netbsd-4-base
# 1.140 28-Nov-2006 elad

branches: 1.140.2;
Move ktrace, ptrace, systrace, and procfs to use kauth(9).

First, remove process_checkioperm() calls from MD code. Similar checks
using kauth(9) routines (on the process scope, using appropriate action)
are done in the callers.

Add secmodel back-end to handle each subsystem.


# 1.139 25-Nov-2006 skrll

Expose the 'exe' symlink to the process realpath in NetBSD as well. An
example user is gdb.

OK'd by christos.


# 1.138 16-Nov-2006 christos

__unused removal on arguments; approved by core.


# 1.137 29-Oct-2006 christos

add an "emul" file node.


# 1.136 25-Oct-2006 christos

1. fix procfs_validfile{,_linux} to test for NULL pointers properly.
2. make "exe" entry be a symlink to the executable, instead of pointing
directly to the vnode of the executable.
3. factor out commonly used code.


Revision tags: yamt-splraiseipl-base2
# 1.135 12-Oct-2006 christos

- sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386


# 1.134 20-Sep-2006 manu

Emulate Linux's /proc/devices


Revision tags: abandoned-netbsd-4-base yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base rpaulo-netinet-merge-pcb-base
# 1.133 13-Jun-2006 yamt

branches: 1.133.6; 1.133.8;
use KAUTH_PROCESS_CANSEE rather than CURTAIN where appropriate.


# 1.132 13-Jun-2006 yamt

remove unnecessary arguments from kauth_authorize_process.
ie. make it similar to the one found in apple TN.


# 1.131 07-Jun-2006 kardel

merge FreeBSD timecounters from branch simonb-timecounters
- struct timeval time is gone
time.tv_sec -> time_second
- struct timeval mono_time is gone
mono_time.tv_sec -> time_uptime
- access to time via
{get,}{micro,nano,bin}time()
get* versions are fast but less precise
- support NTP nanokernel implementation (NTP API 4)
- further reading:
Timecounter Paper: http://phk.freebsd.dk/pubs/timecounter.pdf
NTP Nanokernel: http://www.eecis.udel.edu/~mills/ntp/html/kern.html


Revision tags: yamt-pdpolicy-base5 simonb-timecounters-base
# 1.130 14-May-2006 elad

branches: 1.130.2;
integrate kauth.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 elad-kernelauth-base yamt-pdpolicy-base yamt-uio_vmspace-base5
# 1.129 02-Feb-2006 christos

branches: 1.129.2; 1.129.4; 1.129.6; 1.129.8;
PR/32692: Matthew Mondor: linux compatibility in /proc/self should point
directly to the directory containing the pid instead of pointing to
/proc/curproc, because some programs rely on calling readlink on /proc/self
to get the pid.


# 1.128 11-Dec-2005 christos

branches: 1.128.2; 1.128.4;
merge ktrace-lwp.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base ktrace-lwp-base
# 1.127 02-Nov-2005 yamt

merge yamt-vop branch. remove following VOPs.

VOP_BLKATOFF
VOP_VALLOC
VOP_BALLOC
VOP_REALLOCBLKS
VOP_VFREE
VOP_TRUNCATE
VOP_UPDATE


Revision tags: yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 1.126 01-Oct-2005 atatat

branches: 1.126.2;
Add "cwd" and "root" symlinks to each process's directory. The cwd
link points to the process's current working directory, and the root
link points to the process's root directory. What else would you
expect?

For directories that are out of reach (caller is in a chroot, target
process is in a different chroot, etc), the links point to "/"
instead.


# 1.125 11-Sep-2005 elad

Implement curtain for procfs.


# 1.124 30-Aug-2005 xtraeme

Remove __P()


# 1.123 29-May-2005 christos

branches: 1.123.2;
- sprinkle const
- avoid shadowed variables.


Revision tags: kent-audio2-base
# 1.122 02-Apr-2005 christos

PR/29782: Martin Husemann: procfs can not unmount when some process has its
current directory in curproc. Fix from Pedro Martelletto:
We cannot call vgone() from procfs_inactive() if we are coming from
vclean(). that's what's probably causing the deadlock.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 yamt-km-base4 yamt-km-base3 netbsd-3-base
# 1.121 26-Feb-2005 perry

nuke trailing whitespace


Revision tags: yamt-km-base2 yamt-km-base kent-audio1-beforemerge kent-audio1-base
# 1.120 04-Oct-2004 yamt

branches: 1.120.4; 1.120.6;
procfs_readdir:
- return correct cookie when buffer size is small.
- simplify logic.


# 1.119 04-Oct-2004 yamt

procfs_readdir: remove a redundant assignment.


# 1.118 02-Oct-2004 yamt

procfs_getattr: correct size of /proc/self.


# 1.117 01-Oct-2004 yamt

procfs_readdir:
- fix a locking problem, using proclist_foreach_call. PR/27098.
- correct snprintf size argument.


# 1.116 01-Oct-2004 yamt

procfs_readdir: fix an offset handling bug after addition of /proc/self.


# 1.115 01-Oct-2004 yamt

procfs_readdir: use a list macro.


# 1.114 20-Sep-2004 jdolecek

add 'mounts' file for -o linux, which lists all currently mounted
filesystems; Linux glibc statvfs() uses this to get some of mount flags,
and this file is also useful as /emul/linux/etc/mtab (via symlink)


# 1.113 29-Apr-2004 jrf

Removed remaining caddr_t casts we do not need in miscfs. Recompiled
kernel and ran for a day or so. There are still some caddr_t types in
the arguments of some calls, I will do those separately (later) as
they touch a lot more of the system.
Approved by christos@NetBSD.org.


# 1.112 22-Apr-2004 itojun

sprintf -> snprintf


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.111 15-Feb-2004 jdolecek

unlock the descriptor table simple lock after fd_getfile() call in
procfs_readdir()
fixes procfs locking problems reported on current-users@, problem place
found by enami tsugutomo


# 1.110 30-Oct-2003 simonb

Remove some assigned-to but otherwise unused variables.


# 1.109 27-Sep-2003 darcy

Changes as discussed with itojun on tech-kern. I have modified the enums
to have KFS or PFS differentiators. Further I have wrapped the enum in
procfs in "#ifdef _KERNEL" as it is done in kernfs.

To see the discussion go to http://mail-index.NetBSD.org/tech-kern/2003/09/
and look for "Mismatched enums in include files" in the list.


# 1.108 07-Sep-2003 itojun

remove meaningless line (variable overwritten 2 lines below)


# 1.107 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.


# 1.106 29-Jun-2003 fvdl

branches: 1.106.2;
Back out the lwp/ktrace changes. They contained a lot of colateral damage,
and need to be examined and discussed more.


# 1.105 29-Jun-2003 thorpej

Undo part of the ktrace/lwp changes. In particular:
* Remove the "lwp *" argument that was added to vget(). Turns out
that nothing actually used it!
* Remove the "lwp *" arguments that were added to VFS_ROOT(), VFS_VGET(),
and VFS_FHTOVP(); all they did was pass it to vget() (which, as noted
above, didn't use it).
* Remove all of the "lwp *" arguments to internal functions that were added
just to appease the above.


# 1.104 28-Jun-2003 darrenr

Pass lwp pointers throughtout the kernel, as required, so that the lwpid can
be inserted into ktrace records. The general change has been to replace
"struct proc *" with "struct lwp *" in various function prototypes, pass
the lwp through and use l_proc to get the process pointer when needed.

Bump the kernel rev up to 1.6V


# 1.103 28-May-2003 christos

Add /proc/<pid>/stat for linux compat. j2sdk1.4.2 depends on it.


# 1.102 18-Apr-2003 christos

Make symlinks for directories that point to the actual directory.
Make symlinks to [kqueue] and [misc] for kqueue and misc fds.


# 1.101 17-Apr-2003 jdolecek

do not show nodes corresponding to directory descriptors for process
in fd/ subdirectory, nor allow lookup/open for the nodes
this fixes PR kern/21187 for good, and also avoids interesting directory
locking issues


# 1.100 17-Apr-2003 jdolecek

procfs_readdir(): in Pfd case, only show descriptors of types we want
how to represent (vnodes, fifo, pipes); also use fd_getfile() et al

this avoids annoying EOPNOTSUPP error messages from ls -F and such


# 1.99 17-Apr-2003 jdolecek

procfs_lookup(): use fd_getfile() et al in Pfd case


# 1.98 17-Apr-2003 jdolecek

use fd_getfile() in procfs_getfp(), and FILE_USE()/FILE_UNUSE() the
returned file descriptor pointer appropriately


# 1.97 17-Apr-2003 jdolecek

make some local arrays/variables static + const


# 1.96 10-Apr-2003 jdolecek

use former genfs_eopnotsupp_rele() as genfs_eopnotsupp(), so that vnodes
are vput()/vrele()d as necessary - some filesystems did use the wrong
one for some ops, and it's just safer to not take the chance

based on suggestion by Bill Studenmund


# 1.95 05-Apr-2003 dsl

Remove pointless check against PID_MAX. Let pfind() do the validation.
(The new pid allocation code may decide to allocate pids above PID_MAX.)


# 1.94 25-Feb-2003 jrf

This addresses PR kerm/19989. Thanks to hamajima@nagoya.ydc.co.jp for submitting this patch which enables /proc/uptime for linux emul. Patch reviewed by atatat@netbsd.org and tron@netbsd.org, approved by tron@netbsd.org.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 1.93 04-Jan-2003 martin

Cast off_t expression to long long to match format even on 64 bit
plattforms.

Shouldn't we introduce a PRIoff_t macro to create such format strings?


# 1.92 03-Jan-2003 christos

add LK_CANRECURSE in the locking of /dev/<pid>/fd/<n> and remove the curproc
kludge. Thanks to fvdl.


# 1.91 03-Jan-2003 christos

Implement /proc/<pid>/fd/<n>. This is work in progress. Questionable things:
- Is it ok to convert DTYPE_PIPE to VFIFO and DTYPE_SOCKET to VSOCK?
- XXX: Avoid locking issue in ls -Rl /proc by avoiding curproc
- Does I/O to pipes work?
- XXX: Are there security implications?


Revision tags: fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge gehenna-devsw-base kqueue-base
# 1.90 03-Aug-2002 simonb

Just use the "time" variable in the *_getattr functions instead of a call
to (the potentially expensive) microtime().


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.89 09-May-2002 thorpej

branches: 1.89.2;
Move code shared by procfs and the kernel proper out of procfs and
into the kernel proper (renaming functions from procfs_* to process_*).


Revision tags: eeh-devprop-base newlock-base ifpoll-base
# 1.88 12-Jan-2002 christos

Don't hide the real return code with EPERM.


# 1.87 06-Dec-2001 chs

add a VOP_PUTPAGES method for all the filesystems that don't have pages,
just unlock the interlock.


# 1.86 05-Dec-2001 thorpej

* Allow machine-dependent code to specify hooks for ptrace(2)
(__HAVE_PTRACE_MACHDEP) and procfs (__HAVE_PROCFS_MACHDEP).
These changes will allow platforms like x86 (XMM) and PowerPC
(AltiVec) to export extended register sets in a sane manner.

* Use __HAVE_PTRACE_MACHDEP to export x86 XMM registers (standard
FP + SSE/SSE2) using PT_{GET,SET}XMMREGS (in the machdep
ptrace request space).
* Use __HAVE_PROCFS_MACHDEP to export x86 XMM registers via
/proc/N/xmmregs in procfs.


Revision tags: thorpej-mips-cache-base
# 1.85 10-Nov-2001 lukem

add RCSIDs


# 1.84 06-Nov-2001 simonb

Remove some variables that are set but never used.


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base
# 1.83 31-Aug-2001 chs

branches: 1.83.2; 1.83.4;
map files are zero-length.


# 1.82 03-Jun-2001 chs

branches: 1.82.2;
procfs_bmap() should never be called, make it a "bad op".
let procfs_mmap() use the default error method.


Revision tags: thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 1.81 14-Apr-2001 kleink

In procfs_readdir(), give /proc/# directories DT_DIR (rather than DT_REG).


# 1.80 30-Mar-2001 fvdl

Bump va_blocksize for the map files some more, so that programs with
quite a few mappings have a chance of being handled correctly if
st_blksize is looked at.


# 1.79 29-Mar-2001 fvdl

For -o linux mounts, add some code to emulate /proc/#/maps.
Needs NAMECACHE_ENTER_REVERSE to include filenames.


# 1.78 21-Feb-2001 jdolecek

branches: 1.78.2;
make some more constant arrays 'const'


# 1.77 22-Jan-2001 jdolecek

make filesystem vnodeop, specop, fifoop and vnodeopv_* arrays const


# 1.76 17-Jan-2001 fvdl

Add a few linux-style files, only enabled when -o linux is specified
for the mount. Currently these are /proc/cpuinfo and /proc/meminfo.
The former only does something on i386 right now.


# 1.75 24-Nov-2000 chs

remove dead code and other misc cleanup.


# 1.74 09-Aug-2000 tv

Only show the "exe" entry to Linux processes, suggested by christos.
Since there are actually three struct emul's for linux, use the e_name
field to determine eligibility with strcmp().


# 1.73 09-Aug-2000 tv

Some versions of Linux libc look for /proc/.../exe instead of /proc/../file.
Add an entry for "exe" that is the same as "file", provided only if
COMPAT_LINUX is set.


# 1.72 03-Aug-2000 thorpej

MALLOC()/FREE() are not to be used for variable sized allocations.


# 1.71 28-Jun-2000 mrg

<vm/vm.h> -> <uvm/uvm_extern.h>


Revision tags: netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 1.70 30-Mar-2000 simonb

branches: 1.70.4;
Delete duplicate declaration of atopid().


Revision tags: chs-ubc2-newbase wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base fvdl-softdep-base
# 1.69 02-Sep-1999 thorpej

branches: 1.69.2; 1.69.8;
Make /proc/self a symlink to /proc/curproc. I've observed Linux programs
that expect /proc/self/cmdline to exist.


# 1.68 25-Aug-1999 sommerfeld

Change variable used for directory offset from "int" to "off_t".
Overkill, but avoids a host of truncation problems.


# 1.67 24-Aug-1999 sommerfeld

Fix PR8270:

Problem turned out to be due to improper handling of reads beyond EOF:
they should just return without error with the uio unchanged, and the
caller will recognize this as a zero-byte return (EOF).

The previous fix to protect directory reads against bogus uio_offset
values returned EINVAL, which broke mount -o union, which only
union'ed in the lower directory if the upper directory cleanly
returned EOF.

While we're here, protect kernfs as well.


# 1.66 14-Aug-1999 christos

protect against large uio_offset


# 1.65 03-Aug-1999 wrstuden

Add support for fcntl(2) to generate VOP_FCNTL calls. Any fcntl
call with F_FSCTL set and F_SETFL calls generate calls to a new
fileop fo_fcntl. Add genfs_fcntl() and soo_fcntl() which return 0
for F_SETFL and EOPNOTSUPP otherwise. Have all leaf filesystems
use genfs_fcntl().

Reviewed by: thorpej
Tested by: wrstuden


Revision tags: chs-ubc2-base
# 1.64 25-Jul-1999 thorpej

Add calls to lock the proclist as appropriate.


# 1.63 14-Jul-1999 thorpej

Fix a paste-o in procfs_lookup() introduced with the vnode locking changes.
Fixes PR #7961, Mario Kemper <magick@bundy.lip.owl.de>.


# 1.62 08-Jul-1999 wrstuden

Bump osrelease to 1.4E. Add layerfs files, remove null_subr.c.

Update coda to new struct lock in struct vnode.

make fdescfs, kernfs, portalfs, and procfs actually lock their vnodes.
It's not that hard.

Make unionfs set v_vnlock = NULL so any overlayed fs will call its
VOP_LOCK.


Revision tags: kame_141_19991130 netbsd-1-4-PATCH001 kame_14_19990705 kame_14_19990628 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.61 12-Mar-1999 christos

branches: 1.61.2; 1.61.4;
PR/7143: Jaromir Docelek: Add procfs/cmdline from Linux emulation


# 1.60 25-Jan-1999 msaitoh

Add /proc/#/map. From FreeBSD.


Revision tags: kenh-if-detach-base chs-ubc-base
# 1.59 08-Sep-1998 thorpej

- Use proclists[], rather than checking allproc and zombproc explicitly.
- Add some comments about locking.


# 1.58 13-Aug-1998 kleink

Per POSIX, fail with EINVAL if advisory locking is attempted on a file type
that doesn't support it, rather than using a homegrown EBADF or EOPNOTSUPP.


# 1.57 10-Aug-1998 matthias

create miscfs/genfs/genfs_vnops.c:genfs_enoioctl and make all the other
filesystems use it instead of a private version.


# 1.56 09-Aug-1998 perry

bzero->memset, bcopy->memcpy, bcmp->memcmp


# 1.55 03-Aug-1998 kleink

Recognize _PC_SYNC_IO.


Revision tags: eeh-paddr_t-base
# 1.54 21-Apr-1998 fvdl

procfs_readdir: in case of error, check if cookies actually have
been allocated before freeing them. From Wolfgang Solfrank.


# 1.53 01-Mar-1998 fvdl

Merge with Lite2 + local changes


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base marc-pcmcia-base
# 1.52 10-Oct-1997 fvdl

Bump last argument to VOP_READDIR to off_t (from u_long).


Revision tags: thorpej-signal-base
# 1.51 27-Aug-1997 thorpej

Fix a reversed argument which caused procfs_checkioperm() to always return
"OK". Add a few comments to avoid further confusion.


# 1.50 12-Aug-1997 thorpej

Fix the procfs hole described on current-users, similar to a fix for
FreeBSD by Sean Eric Fagan, but a bit different. This makes the checks
in the same places as sef's FreeBSD patch, but does not hardcode the
"kmem" group into the kernel, and also does a check identical to the
(3) and (4) checks in the NetBSD ptrace(2):

(1) it's not owned by you, or is set-id on exec (unless
you're root), or

(2) it's init, which controls the security level of the
entire system, and the system was not compiled with
permanently insecure mode turned on.


Revision tags: marc-pcmcia-bp
# 1.49 08-May-1997 mycroft

branches: 1.49.4;
Pass the vnode type to vaccess(), and use it when checking VEXEC. Make sure
that the mode bits passed to vaccess() and returned by foo_getattr() contain
only permission bits.


# 1.48 05-May-1997 mycroft

Need stat.h.


# 1.47 05-May-1997 mycroft

Eliminate bogus uses of V{READ,WRITE,EXEC}. Use S_I[RWX]{USR,GRP,OTH} where
appropriate.


# 1.46 28-Apr-1997 mycroft

Minor code cleanup.


Revision tags: is-newarp-before-merge is-newarp-base
# 1.45 25-Oct-1996 cgd

define path name string variables that we should not (and, thankfully, do
not) modify as 'const char *' rather 'char *'.


# 1.44 13-Oct-1996 christos

backout previous kprintf changes


# 1.43 10-Oct-1996 christos

printf -> kprintf, sprintf -> ksprintf


# 1.42 07-Sep-1996 mycroft

Implement poll(2).


# 1.41 01-Sep-1996 mycroft

Add a set of generic file system operations that most file systems use.
Also, fix some time stamp bogosities.


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 1.40 16-Mar-1996 christos

Fix printf format follies.


# 1.39 13-Feb-1996 mycroft

GC *_nullop(). Minor nits.


# 1.38 12-Feb-1996 christos

close PR/2063: procfs_rw prototyped twice with different prototypes


# 1.37 09-Feb-1996 christos

miscfs prototype changes


# 1.36 09-Feb-1996 mycroft

Fix vop_link, vop_symlink, and vop_remove semantics in several ways:
* Change the argument names to vop_link so they actually make sense.
* Implement vop_link and vop_symlink for all file systems, so they do proper
cleanup.
* Require the file system to decide whether or not linking and unlinking of
directories is allowed, and disable it for all current file systems.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.35 09-Oct-1995 mycroft

Use the index number as the cookie, rather than multiplying by UIO_MX.


# 1.34 09-Oct-1995 mycroft

Add support for cookies, mostly from Greg Hudson.


# 1.33 15-Apr-1995 cgd

fix timeval vs. timespec warnings


# 1.32 03-Feb-1995 mycroft

Return EROFS rather than ENOENT in many cases. Also some cosmetic cleanup.


# 1.31 27-Dec-1994 mycroft

Format police.


# 1.30 24-Dec-1994 ws

Implement and use a common access checking routine


# 1.29 14-Dec-1994 mycroft

Remove a_fp.


# 1.28 14-Nov-1994 christos

fixed struct comment


# 1.27 30-Oct-1994 cgd

be more careful with types, also pull in headers where necessary.


# 1.26 20-Oct-1994 cgd

update for new syscall args description mechanism


# 1.25 30-Aug-1994 mycroft

Convert process, file, and namei lists and hash tables to use queue.h.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.24 29-Jun-1994 cgd

New RCS ID's, take two. they're more aesthecially pleasant, and use 'NetBSD'


# 1.23 16-Jun-1994 mycroft

Remove an unneeded test.


# 1.22 15-Jun-1994 mycroft

Minor update from JSP after merging my changes.


# 1.21 08-Jun-1994 mycroft

Update to 4.4-Lite fs code, with local changes.


# 1.20 05-May-1994 cgd

lots of changes: prototype migration, move lots of variables, definitions,
and structure elements around. kill some unnecessary type and macro
definitions. standardize clock handling. More changes than you'd want.


# 1.19 15-Apr-1994 cgd

forgot these...


# 1.18 12-Apr-1994 cgd

be a bit smarter about determining if files shouldn't be seen by the user.
Also, DON'T allow a lookup to succeed on a file that's not visible!


# 1.17 15-Feb-1994 mycroft

Undo last change; executables is `file', not `a.out'.


# 1.16 14-Feb-1994 ws

Rename file -> a.out


# 1.15 14-Feb-1994 ws

Don't try to show a file for a process if there is none


# 1.14 28-Jan-1994 cgd

make a fpregs file.


# 1.13 20-Jan-1994 ws

Make procfs really work for debugging.
Implement not & notepg files in procfs.


# 1.12 09-Jan-1994 ws

Bug fixes and enhancements:
Make NFS serving work (BUT DON'T USE "attach" TO /proc/*/ctl FOR NOW!!!)
Make `curproc' a symbolic link
Add `.' and `..' entries to the directories.
Return better guesses on the size of the files.


# 1.11 05-Jan-1994 cgd

return size of 'reg' from getattr()


# 1.10 05-Jan-1994 cgd

make it compile (cleanly) for us


# 1.9 05-Jan-1994 cgd

add new procfs code, from Jan-Simon Pendry, jsp@sequent.com.
This is pretty-much "virgin", so that diffs can be done later.


# 1.8 18-Dec-1993 mycroft

Canonicalize all #includes.


Revision tags: magnum-base
# 1.7 16-Sep-1993 cgd

kill volatile warning.


# 1.6 07-Sep-1993 ws

branches: 1.6.2;
Changes to VFS readdir semantics
NFS changes for better cookie support
ISOFS changes for better Rockridge support and support for generation numbers


# 1.5 26-Aug-1993 pk

Implement setattr: mode for process entries; mode + uid/gid for the
PROCFS root directory.
Fixed omission in pfs_root() which came to light as a result of the above:
hold on to vnode for root dir.


# 1.4 25-Aug-1993 pk

Fixed improperly initialized nfsnode in pfs_lookup()


# 1.3 24-Aug-1993 pk

copyright update.


# 1.2 24-Aug-1993 pk

Rcs Id added.


# 1.1 24-Aug-1993 pk

branches: 1.1.1;
Initial version of a proc filesystem.


# 1.223 11-Jan-2022 hannken

Use a single "p" variable.

Should fix PR kern/56614: kernel panic on tmux


# 1.222 10-Jan-2022 christos

use a single nc variable.


# 1.221 10-Jan-2022 christos

Fix locking in the error path (from RVP). Centralize unlock code.


# 1.220 08-Dec-2021 andvar

s/efficent/efficient/ in comments.


# 1.219 05-Oct-2021 christos

PR/53299: RVP: kernfs and procfs are broken when sysctl security.curtain
is enabled


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base thorpej-i2c-spi-conf-base
# 1.218 18-Jul-2021 dholland

Abolish all the silly indirection macros for initializing vnode ops tables.

These are things of the form #define foofs_op genfs_op, or #define
foofs_op genfs_eopnotsupp, or similar. They serve no purpose besides
obfuscation, and have gotten cutpasted all over everywhere.


# 1.217 29-Jun-2021 dholland

- Add a new vnode op: VOP_PARSEPATH.
- Move namei_getcomponent to genfs_vnops.c and call it genfs_parsepath.
- Add a parsepath entry to every vnode ops table.

VOP_PARSEPATH takes a directory vnode to be searched and a complete
following path and chooses how much of that path to consume. To begin
with, all parsepath calls are genfs_parsepath, which locates the first
'/' as always.

Note that the call doesn't take the whole struct componentname, only
the string. The other bits of struct componentname should not be
needed and there's no reason to cause potential complications by
exposing them.


# 1.216 28-Jun-2021 chs

VOP_BMAP() may be called via ioctl(FIOGETBMAP) on any vnode that applications
can open. change various pseudo-fs *_bmap methods return an error instead of
panic.

Reported-by: syzbot+8289a3eaf2ba60958c87@syzkaller.appspotmail.com


Revision tags: cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base thorpej-cfargs-base thorpej-futex-base
# 1.215 27-Jun-2020 christos

branches: 1.215.6;
Introduce genfs_pathconf() and use it for the default case in all filesystems.


# 1.214 23-May-2020 ad

Move proc_lock into the data segment. It was dynamically allocated because
at the time we had mutex_obj_alloc() but not __cacheline_aligned.


# 1.213 16-May-2020 christos

Add ACL support for FFS. From FreeBSD.


# 1.212 29-Apr-2020 thorpej

If the procfs mount is marked as linux-compat, then allow proc lookup
by any LWP ID in the proc, not just the canonical PID.


Revision tags: bouyer-xenpvh-base2
# 1.211 21-Apr-2020 ad

Revert the changes made in February to make cwdinfo use mostly lockless,
which relied on taking extra vnode refs.

Having benchmarked various experimental changes over the past few months it
seems that it's better to avoid vnode refs as much as possible. cwdi_lock
as a RW lock already did that to some extent for getcwd() and will permit
the same for namei() too.


Revision tags: phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base is-mlppp-base phil-wifi-20200406 ad-namecache-base3
# 1.210 24-Feb-2020 ad

branches: 1.210.4;
v_interlock -> vmobjlock


# 1.209 23-Feb-2020 ad

Merge from ad-namecache:

- Have a stab at clustering the members of vnode_t and vnode_impl_t in a
more cache-conscious way. With that done, go back to adjusting v_usecount
with atomics and keep vi_lock directly in vnode_impl_t (saves KVA).

- Allow VOP_LOCK(LK_NONE) for the benefit of VFS_VGET() and VFS_ROOT().
Make sure LK_UPGRADE always comes with LK_NOWAIT.

- Make cwdinfo use mostly lockless.


# 1.208 01-Feb-2020 riastradh

Load struct filedesc::fd_dt with atomic_load_consume.

Exceptions: when fd_refcnt <= 1, or when holding fd_lock.

While here:

- Restore KASSERT(mutex_owned(&fdp->fd_lock)) in fd_unused.
=> This is used only in fd_close and fd_abort, where it holds.
- Move bounds check assertion in fd_putfile to where it matters.
- Store fd_dt with atomic_store_release.
- Move load of fd_dt under lock in knote_fdclose.
- Omit membar_consumer in fdesc_readdir.
=> atomic_load_consume serves the same purpose now.
=> Was needed only on alpha anyway.


Revision tags: ad-namecache-base2 ad-namecache-base1 ad-namecache-base phil-wifi-20191119
# 1.207 29-Aug-2019 hannken

branches: 1.207.2;
Add missing operation VOP_GETPAGES() returning EFAULT.

Without this operation posix_fadvise(..., POSIX_FADV_WILLNEED)
would leave the v_interlock held.

Observed by maxv@


Revision tags: netbsd-9-base phil-wifi-20190609 isaki-audio2-base
# 1.206 30-Mar-2019 christos

branches: 1.206.4;
add a node for the process resource limits.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020
# 1.205 14-Oct-2018 jdolecek

remove M_CANFAIL flag for malloc(9) - it was completely ignored, so had
actually no effect


Revision tags: pgoyette-compat-0930 pgoyette-compat-0906
# 1.204 03-Sep-2018 riastradh

Rename min/max -> uimin/uimax for better honesty.

These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER! Some subsystems have

#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)


Revision tags: pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415
# 1.203 07-Apr-2018 hannken

branches: 1.203.2;
Lock the target cwdi and take an additional reference to the
vnode we are interested in to prevent it from disappearing
before getcwd_common().

Should fix PR kern/53096 (netbsd-8 crash on heavy disk I/O)


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.202 31-Dec-2017 christos

branches: 1.202.2;
Add an environ node


Revision tags: tls-maxphys-base-20171202
# 1.201 01-Dec-2017 christos

Allow procfs_kqfilter, since we allow poll. "go" does it.


# 1.200 08-Nov-2017 christos

fix locking, remove error(1) comments.


# 1.199 08-Nov-2017 christos

use p->p_path, remove unused code.


# 1.198 28-Aug-2017 kamil

Remove the filesystem tracing feature

This is a legacy interface from 4.4BSD, and it was
introduced to overcome shortcomings of ptrace(2) at that time, which are
no longer relevant (performance). Today /proc/#/ctl offers a narrow
subset of ptrace(2) commands and is not applicable for modern
applications use beyond simplistic tracing scenarios.

This removal will simplify kernel internals. Users will still be able to
use all the other /proc files.

This change won't affect other procfs files neither Linux compat
features within mount_procfs(8). /proc/#/ctl isn't available on Linux.

Remove:
- /proc/#/ctl from mount_procfs(8)
- P_FSTRACE note from the documentation of ps(1)
- /proc/#/ctl and filesystem tracing documentation from mount_procfs(8)
- KAUTH_REQ_PROCESS_PROCFS_CTL documentation from kauth(9)
- source code file miscfs/procfs/procfs_ctl.c
- PFSctl and procfs_doctl() from sys/miscfs/procfs/procfs.h
- KAUTH_REQ_PROCESS_PROCFS_CTL from sys/sys/kauth.h
- PSL_FSTRACE (0x00010000) from sys/sys/proc.h
- P_FSTRACE (0x00010000) from sys/sys/sysctl.h

Reduce code complexity after removal of this functionality.

Update TODO.ptrace accordingly: remove two entries about /proc tracing.

Do not keep legacy notes as comments in the headers about removed
PSL_FSTRACE / P_FSTRACE, as this interface had little number of users
(close or equal to zero).

Proposed on tech-kern@.

All filesystem tracing utility users are encouraged to switch to ptrace(2).

Sponsored by <The NetBSD Foundation>


Revision tags: matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base
# 1.197 26-May-2017 riastradh

branches: 1.197.2;
Make VOP_RECLAIM do the last unlock of the vnode.

VOP_RECLAIM naturally has exclusive access to the vnode, so having it
locked on entry is not strictly necessary -- but it means if there
are any final operations that must be done on the vnode, such as
ffs_update, requiring exclusive access to it, we can now kassert that
the vnode is locked in those operations.

We can't just have the caller release the last lock because some file
systems don't use genfs_lock, and require the vnode to remain valid
for VOP_UNLOCK to work, notably unionfs.


Revision tags: prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.196 11-Apr-2017 riastradh

Make VOP_INACTIVE preserve vnode lock on return.

Discussed on tech-kern:
https://mail-index.netbsd.org/tech-kern/2017/04/01/msg021751.html

Ride 7.99.68, a bumpy bus of incremental vfs improvements!


Revision tags: jdolecek-ncq-base
# 1.195 30-Mar-2017 christos

add an auxv node.


Revision tags: pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004 localcount-20160914
# 1.194 20-Aug-2016 hannken

branches: 1.194.2;
Remove now obsolete operation vcache_remove().

Welcome to 7.99.36


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 nick-nhusb-base-20150921 nick-nhusb-base-20150606
# 1.193 20-Apr-2015 riastradh

branches: 1.193.2;
Make VOP_LINK return directory still locked and referenced.

Ride 7.99.10 bump.


Revision tags: nick-nhusb-base-20150406 nick-nhusb-base
# 1.192 05-Sep-2014 matt

branches: 1.192.2;
Try not to use f_data, use f_{vnode,socket,pipe,mqueue,kqueue,ksem} to get
a correctly typed pointer.


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.191 27-Jul-2014 hannken

branches: 1.191.2; 1.191.4; 1.191.8;
Change procfs from hashlist to vcache.
- Key is (type, pid, fd)
- Remove argument "p" from procfs_allocvp(). It is only used
when "type == PFSfd". Lookup the proc with proc_find() when
procfs_loadvnode() needs it.
- Use a vfs_vnode_iterator for procfs_revoke_vnodes().


# 1.190 25-Jul-2014 dholland

Add VOP_FALLOCATE and VOP_FDISCARD to every vnode ops table I can
find.

The filesystem ones all call genfs_eopnotsupp - right now I am only
implementing the plumbing and we can implement fallocate and/or
fdiscard for files later.

The device ones call spec_fallocate (which is also genfs_eopnotsupp)
and spec_fdiscard, which dispatches to the device-level op.

The fifo ones all call vn_fifo_bypass, which also ends up being
EOPNOTSUPP.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base
# 1.189 07-Feb-2014 hannken

branches: 1.189.2;
Change vnode operation lookup to return the resulting vnode *vpp unlocked.
Change cache_lookup() to return an unlocked vnode.

Discussed on tech-kern@

Welcome to 6.99.31


# 1.188 23-Jan-2014 hannken

Change vnode operations create, mknod, mkdir and symlink to return
the resulting vnode *vpp unlocked.

Discussed on tech-kern@

Welcome to 6.99.30


# 1.187 17-Jan-2014 hannken

Change vnode operations create, mknod, mkdir and symlink to keep the
directory node dvp locked on return.

Discussed on tech-kern@

Welcome to 6.99.29


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base
# 1.186 18-Mar-2013 plunky

branches: 1.186.6;
C99 section 6.7.2.3 (Tags) Note 3 states that:

A type specifier of the form

enum identifier

without an enumerator list shall only appear after the type it
specifies is complete.

which means that we cannot pass an "enum vtype" argument to
kauth_access_action() without fully specifying the type first.
Unfortunately there is a complicated include file loop which
makes that difficult, so convert this minimal function into a
macro (and capitalize it).

(ok elad@)


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 1.185 25-Nov-2012 christos

do something reasonable with kernel semaphores.


Revision tags: yamt-pagecache-base6 jmcneill-usbmp-base10
# 1.184 28-May-2012 christos

branches: 1.184.2;
add a task process subdirectory for emul linux


Revision tags: yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 1.183 13-Mar-2012 elad

Replace the remaining KAUTH_GENERIC_ISSUSER authorization calls with
something meaningful. All relevant documentation has been updated or
written.

Most of these changes were brought up in the following messages:

http://mail-index.netbsd.org/tech-kern/2012/01/18/msg012490.html
http://mail-index.netbsd.org/tech-kern/2012/01/19/msg012502.html
http://mail-index.netbsd.org/tech-kern/2012/02/17/msg012728.html

Thanks to christos, manu, njoly, and jmmv for input.

Huge thanks to pgoyette for spinning these changes through some build
cycles and ATF.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.182 04-Sep-2011 jmcneill

branches: 1.182.2; 1.182.6;
PR# kern/45021: Please support /emul/linux/proc/version

Add /proc/version for procfs with -o linux. The version reported depends
on the emulation type of the calling process:

$ cat /proc/version
NetBSD version 5.99.55 (netbsd@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) NetBSD 5.99.55 (GENERIC) #39: Sun Sep 4 09:10:05 EDT 2011

$ /emul/linux/bin/cat /proc/version
Linux version 2.6.18 (linux@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) #0 Wed Mar 3 03:03:03 PST 2010

$ /emul/linux32/bin/cat /proc/version
Linux version 2.6.18 (linux32@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) #0 Wed Mar 3 03:03:03 PST 2010


# 1.181 23-Jun-2011 christos

From Aleksey Cheusov: Don't make it easy for compromised systems to bypass
ASLR protections by providing the mapping addresses of programs to everyone.


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base matt-mips64-premerge-20101231 uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10 rmind-uvmplock-base
# 1.180 01-Jul-2010 rmind

Remove pfind() and pgfind(), fix locking in various broken uses of these.
Rename real routines to proc_find() and pgrp_find(), remove PFIND_* flags
and have consistent behaviour. Provide proc_find_raw() for special cases.
Fix memory leak in sysctl_proc_corename().

COMPAT_LINUX: rework ptrace() locking, minimise differences between
different versions per-arch.

Note: while this change adds some formal cosmetics for COMPAT_DARWIN and
COMPAT_IRIX - locking there is utterly broken (for ages).

Fixes PR/43176.


# 1.179 24-Jun-2010 hannken

Clean up vnode lock operations pass 2:

VOP_UNLOCK(vp, flags) -> VOP_UNLOCK(vp): Remove the unneeded flags argument.

Welcome to 5.99.32.

Discussed on tech-kern.


# 1.178 08-Jun-2010 hannken

Procfs_lookup() does not lookup directory descriptors in the fd/
subdirectory. There is no need for recursive vnode locking here.

Ok: Christos Zoulas <christos@netbsd.org>


Revision tags: uebayasi-xip-base1 yamt-nfs-mp-base9 uebayasi-xip-base
# 1.177 08-Jan-2010 pooka

branches: 1.177.2; 1.177.4;
The VATTR_NULL/VREF/VHOLD/HOLDRELE() macros lost their will to live
years ago when the kernel was modified to not alter ABI based on
DIAGNOSTIC, and now just call the respective function interfaces
(in lowercase). Plenty of mix'n match upper/lowercase has creeped
into the tree since then. Nuke the macros and convert all callsites
to lowercase.

no functional change


Revision tags: matt-premerge-20091211 yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 jym-xensuspend-nbase
# 1.176 03-Jul-2009 elad

Where possible, extract the file-system's access() routine to two internal
functions: the first checking if the operation is possible (regardless of
permissions), the second checking file-system permissions, ACLs, etc.

Mailing list reference:

http://mail-index.netbsd.org/tech-kern/2009/06/21/msg005311.html


# 1.175 23-Jun-2009 elad

Move the implementation of vaccess() to genfs_can_access(), in line with
the other routines of the same spirit.

Adjust file-system code to use it.

Keep vaccess() for KPI compatibility and to keep element of least
surprise. A "diagnostic" message warning that vaccess() is deprecated will
be printed when it's used (obviously, only in DIAGNOSTIC kernels).

No objections on tech-kern@:

http://mail-index.netbsd.org/tech-kern/2009/06/21/msg005310.html


Revision tags: yamt-nfs-mp-base5
# 1.174 24-May-2009 ad

More changes to improve kern_descrip.c.

- Avoid atomics in more places.
- Remove the per-descriptor mutex, and just use filedesc_t::fd_lock.
It was only being used to synchronize close, and in any case we needed
to take fd_lock to free the descriptor slot.
- Optimize certain paths for the <NDFDFILE case.
- Sprinkle more comments and assertions.
- Cache more stuff in filedesc_t.
- Fix numerous minor bugs spotted along the way.
- Restructure how the open files array is maintained, for clarity and so
that we can eliminate the membar_consumer() call in fd_getfile(). This is
mostly syntactic sugar; the main functional change is that fd_nfiles now
lives alongside the open file array.

Some measurements with libmicro:

- simple file syscalls are like close() are between 1 to 10% faster.
- some nice improvements, e.g. poll(1000) which is ~50% faster.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 nick-hppapmap-base2 jym-xensuspend-base nick-hppapmap-base mjf-devfs2-base
# 1.173 17-Dec-2008 cegger

branches: 1.173.2;
kill MALLOC and FREE macros.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 haad-dm-base2 haad-nbase2 ad-audiomp2-base netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 haad-dm-base
# 1.172 05-Sep-2008 skrll

branches: 1.172.2;
PR/39324 kernel diagnostic assertion "l->l_stat != LSZOMB" failed.

Ignore procs with zero or all LSZOMB LWPs. Get a non-LSZOMB LWP to perform
operations against as part of the deal.

procfs really needs to be updated to support multi-threading fully.
Hi Antti!


# 1.171 05-Sep-2008 skrll

ANSIfy


Revision tags: simonb-wapbl-nbase simonb-wapbl-base
# 1.170 02-Jul-2008 rmind

branches: 1.170.2;
Remove proc_representative_lwp(), use a simple LIST_FIRST() instead.
OK by <ad>.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base
# 1.169 28-Apr-2008 martin

branches: 1.169.2; 1.169.4;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-nfs-mp-base
# 1.168 24-Apr-2008 ad

branches: 1.168.2;
Merge proc::p_mutex and proc::p_smutex into a single adaptive mutex, since
we no longer need to guard against access from hardware interrupt handlers.

Additionally, if cloning a process with CLONE_SIGHAND, arrange to have the
child process share the parent's lock so that signal state may be kept in
sync. Partially addresses PR kern/37437.


# 1.167 24-Apr-2008 ad

Network protocol interrupts can now block on locks, so merge the globals
proclist_mutex and proclist_lock into a single adaptive mutex (proc_lock).
Implications:

- Inspecting process state requires thread context, so signals can no longer
be sent from a hardware interrupt handler. Signal activity must be
deferred to a soft interrupt or kthread.

- As the proc state locking is simplified, it's now safe to take exit()
and wait() out from under kernel_lock.

- The system spends less time at IPL_SCHED, and there is less lock activity.


Revision tags: yamt-pf42-baseX yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14
# 1.166 21-Mar-2008 ad

branches: 1.166.2;
Catch up with descriptor handling changes. See kern_descrip.c revision
1.173 for details.


Revision tags: keiichi-mipv6-nbase nick-net80211-sync-base keiichi-mipv6-base bouyer-xeni386-nbase matt-armv6-nbase mjf-devfs-base hpcarm-cleanup-base
# 1.165 23-Jan-2008 elad

branches: 1.165.6;
Tons of process scope changes.

- Add a KAUTH_PROCESS_SCHEDULER action, to handle scheduler related
requests, and add specific requests for set/get scheduler policy and
set/get scheduler parameters.

- Add a KAUTH_PROCESS_KEVENT_FILTER action, to handle kevent(2) related
requests.

- Add a KAUTH_DEVICE_TTY_STI action to handle requests to TIOCSTI.

- Add requests for the KAUTH_PROCESS_CANSEE action, indicating what
process information is being looked at (entry itself, args, env,
open files).

- Add requests for the KAUTH_PROCESS_RLIMIT action indicating set/get.

- Add requests for the KAUTH_PROCESS_CORENAME action indicating set/get.

- Make bsd44 secmodel code handle the newly added rqeuests appropriately.

All of the above make it possible to issue finer-grained kauth(9) calls in
many places, removing some KAUTH_GENERIC_ISSUSER requests.

- Remove the "CAN" from KAUTH_PROCESS_CAN{KTRACE,PROCFS,PTRACE,SIGNAL}.

Discussed with christos@ and yamt@.


Revision tags: bouyer-xeni386-base matt-armv6-base
# 1.164 02-Jan-2008 ad

Merge vmlocking2 to head.


Revision tags: vmlocking2-base3 yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 vmlocking-nbase jmcneill-pm-base reinoud-bufcleanup-base
# 1.163 26-Nov-2007 pooka

branches: 1.163.2; 1.163.6;
Remove the "struct lwp *" argument from all VFS and VOP interfaces.
The general trend is to remove it from all kernel interfaces and
this is a start. In case the calling lwp is desired, curlwp should
be used.

quick consensus on tech-kern


Revision tags: bouyer-xenamd64-base2 bouyer-xenamd64-base
# 1.162 09-Nov-2007 christos

make the last argument of procfs_dir size_t


# 1.161 07-Nov-2007 ad

Merge from vmlocking:

- pool_cache changes.
- Debugger/procfs locking fixes.
- Other minor changes.


Revision tags: jmcneill-base yamt-x86pmap-base4 yamt-x86pmap-base3 vmlocking-base
# 1.160 10-Oct-2007 ad

branches: 1.160.2; 1.160.4;
Merge from vmlocking:

- Split vnode::v_flag into three fields, depending on field locking.
- simple_lock -> kmutex in a few places.
- Fix some simple locking problems.


# 1.159 08-Oct-2007 ad

Merge file descriptor locking, cwdi locking and cross-call changes
from the vmlocking branch.


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base2 yamt-x86pmap-base matt-mips64-base
# 1.158 22-Jul-2007 pooka

branches: 1.158.4; 1.158.6; 1.158.8; 1.158.10;
Don't allow getcwd() on procfs vnodes and provide "/" as the path
instead of the result from getcwd(). The works around locking
panics caused by namei calling VOP_READLINK while holding on to a
directory lock and getcwd() trying to acquire that lock. The real
fix would be to get rid of getcwd() calls within VOPs (not locking
safe), but that's not a viable option in the netbsd-4 timeframe.

Suggestion for workaround from David Holland.


Revision tags: nick-csl-alignment-base mjf-ufs-trans-base
# 1.157 24-May-2007 agc

branches: 1.157.2;
Extend the Linux emulation of /proc to include

/proc/stat
/proc/loadavg and
/proc/<pid>/statm.

These are only present when -o linux is specified as a mount option
to procfs.

Factor out some common code so that it can be used by a number of
functions.

XXX The values returned in the statm emulation need to be verified.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 1.156 04-Apr-2007 rmind

Unfortunately, missed procfs_proc_unlock() in previous.
Pointed out by pooka@


# 1.155 04-Apr-2007 rmind

procfs_readlink: Handle a possible fail of fd_getfile(), also, we
do not need to check for error again.
CID: 4436


# 1.154 09-Mar-2007 ad

branches: 1.154.2; 1.154.4;
- Make the proclist_lock a mutex. The write:read ratio is unfavourable,
and mutexes are cheaper use than RW locks.
- LOCK_ASSERT -> KASSERT in some places.
- Hold proclist_lock/kernel_lock longer in a couple of places.


# 1.153 04-Mar-2007 christos

Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.


# 1.152 03-Mar-2007 salo

Don't prepend rootvnode to the path in non-NULL case for exe links.
It breaks procfs in chroot.

from <christos>, tested by me.


Revision tags: ad-audiomp-base
# 1.151 19-Feb-2007 pooka

When checking for file validity under pid/, do proper proc->lwp
lookup (fsvo proper) instead of fiddling directly with the lwp
list.


# 1.150 18-Feb-2007 pooka

Don't check for validity of p in lookup for root nodes, since it
will always be NULL. Rather, just call pt_valid with NULL directly
and let it decide if we're a linux mount or not.


# 1.149 17-Feb-2007 pavel

Change the process/lwp flags seen by userland via sysctl back to the
P_*/L_* naming convention, and rename the in-kernel flags to avoid
conflict. (P_ -> PK_, L_ -> LW_ ). Add back the (now unused) LSDEAD
constant.

Restores source compatibility with pre-newlock2 tools like ps or top.

Reviewed by Andrew Doran.


# 1.148 16-Feb-2007 pooka

branches: 1.148.2;
In lookup, when checking for procfs process node validity, target the
process we're trying to get information about through procfs, not
the caller of lookup.

fixes 'ls -l /proc/*/file' panic, which would occur when trying to
lookup "file" for a kernel thread, which doesn't have p->p_textvp.


# 1.147 15-Feb-2007 ad

Need to acquire procp->p_mutex for procfs_dir().


# 1.146 11-Feb-2007 ad

Eliminate a couple of reference count and mutex leaks.


Revision tags: post-newlock2-merge
# 1.145 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 1.144 25-Dec-2006 elad

PR/35226: Johann Franz: Problems with permissions in
/usr/pkg/emul/linux/proc .

Okay mlelstv@


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3
# 1.143 09-Dec-2006 chs

a smorgasbord of improvements to vnode locking and path lookup:
- LOCKPARENT is no longer relevant for lookup(), relookup() or VOP_LOOKUP().
these now always return the parent vnode locked. namei() works as before.
lookup() and various other paths no longer acquire vnode locks in the
wrong order via vrele(). fixes PR 32535.
as a nice side effect, path lookup is also up to 25% faster.
- the above allows us to get rid of PDIRUNLOCK.
- also get rid of WANTPARENT (just use LOCKPARENT and unlock it).
- remove an assumption in layer_node_find() that all file systems implement
a recursive VOP_LOCK() (unionfs doesn't).
- require that all file systems supply vfs_vptofh and vfs_fhtovp routines.
fill in eopnotsupp() for file systems that don't support being exported
and remove the checks for NULL. (layerfs calls these without checking.)
- in union_lookup1(), don't change refcounts in the ISDOTDOT case, just
adjust which vnode is locked. fixes PR 33374.
- apply fixes for ufs_rename() from ufs_vnops.c rev. 1.61 to ext2fs_rename().


# 1.142 04-Dec-2006 christos

From Nicolas Joly: restore previous behavior in procfs_validfile_linux, since
readdir passes a NULL lwp.


# 1.141 03-Dec-2006 elad

Move kauth(9) call to where it belongs. Noticed by Nicolas Joly, thanks!


Revision tags: netbsd-4-base
# 1.140 28-Nov-2006 elad

branches: 1.140.2;
Move ktrace, ptrace, systrace, and procfs to use kauth(9).

First, remove process_checkioperm() calls from MD code. Similar checks
using kauth(9) routines (on the process scope, using appropriate action)
are done in the callers.

Add secmodel back-end to handle each subsystem.


# 1.139 25-Nov-2006 skrll

Expose the 'exe' symlink to the process realpath in NetBSD as well. An
example user is gdb.

OK'd by christos.


# 1.138 16-Nov-2006 christos

__unused removal on arguments; approved by core.


# 1.137 29-Oct-2006 christos

add an "emul" file node.


# 1.136 25-Oct-2006 christos

1. fix procfs_validfile{,_linux} to test for NULL pointers properly.
2. make "exe" entry be a symlink to the executable, instead of pointing
directly to the vnode of the executable.
3. factor out commonly used code.


Revision tags: yamt-splraiseipl-base2
# 1.135 12-Oct-2006 christos

- sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386


# 1.134 20-Sep-2006 manu

Emulate Linux's /proc/devices


Revision tags: abandoned-netbsd-4-base yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base rpaulo-netinet-merge-pcb-base
# 1.133 13-Jun-2006 yamt

branches: 1.133.6; 1.133.8;
use KAUTH_PROCESS_CANSEE rather than CURTAIN where appropriate.


# 1.132 13-Jun-2006 yamt

remove unnecessary arguments from kauth_authorize_process.
ie. make it similar to the one found in apple TN.


# 1.131 07-Jun-2006 kardel

merge FreeBSD timecounters from branch simonb-timecounters
- struct timeval time is gone
time.tv_sec -> time_second
- struct timeval mono_time is gone
mono_time.tv_sec -> time_uptime
- access to time via
{get,}{micro,nano,bin}time()
get* versions are fast but less precise
- support NTP nanokernel implementation (NTP API 4)
- further reading:
Timecounter Paper: http://phk.freebsd.dk/pubs/timecounter.pdf
NTP Nanokernel: http://www.eecis.udel.edu/~mills/ntp/html/kern.html


Revision tags: yamt-pdpolicy-base5 simonb-timecounters-base
# 1.130 14-May-2006 elad

branches: 1.130.2;
integrate kauth.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 elad-kernelauth-base yamt-pdpolicy-base yamt-uio_vmspace-base5
# 1.129 02-Feb-2006 christos

branches: 1.129.2; 1.129.4; 1.129.6; 1.129.8;
PR/32692: Matthew Mondor: linux compatibility in /proc/self should point
directly to the directory containing the pid instead of pointing to
/proc/curproc, because some programs rely on calling readlink on /proc/self
to get the pid.


# 1.128 11-Dec-2005 christos

branches: 1.128.2; 1.128.4;
merge ktrace-lwp.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base ktrace-lwp-base
# 1.127 02-Nov-2005 yamt

merge yamt-vop branch. remove following VOPs.

VOP_BLKATOFF
VOP_VALLOC
VOP_BALLOC
VOP_REALLOCBLKS
VOP_VFREE
VOP_TRUNCATE
VOP_UPDATE


Revision tags: yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 1.126 01-Oct-2005 atatat

branches: 1.126.2;
Add "cwd" and "root" symlinks to each process's directory. The cwd
link points to the process's current working directory, and the root
link points to the process's root directory. What else would you
expect?

For directories that are out of reach (caller is in a chroot, target
process is in a different chroot, etc), the links point to "/"
instead.


# 1.125 11-Sep-2005 elad

Implement curtain for procfs.


# 1.124 30-Aug-2005 xtraeme

Remove __P()


# 1.123 29-May-2005 christos

branches: 1.123.2;
- sprinkle const
- avoid shadowed variables.


Revision tags: kent-audio2-base
# 1.122 02-Apr-2005 christos

PR/29782: Martin Husemann: procfs can not unmount when some process has its
current directory in curproc. Fix from Pedro Martelletto:
We cannot call vgone() from procfs_inactive() if we are coming from
vclean(). that's what's probably causing the deadlock.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 yamt-km-base4 yamt-km-base3 netbsd-3-base
# 1.121 26-Feb-2005 perry

nuke trailing whitespace


Revision tags: yamt-km-base2 yamt-km-base kent-audio1-beforemerge kent-audio1-base
# 1.120 04-Oct-2004 yamt

branches: 1.120.4; 1.120.6;
procfs_readdir:
- return correct cookie when buffer size is small.
- simplify logic.


# 1.119 04-Oct-2004 yamt

procfs_readdir: remove a redundant assignment.


# 1.118 02-Oct-2004 yamt

procfs_getattr: correct size of /proc/self.


# 1.117 01-Oct-2004 yamt

procfs_readdir:
- fix a locking problem, using proclist_foreach_call. PR/27098.
- correct snprintf size argument.


# 1.116 01-Oct-2004 yamt

procfs_readdir: fix an offset handling bug after addition of /proc/self.


# 1.115 01-Oct-2004 yamt

procfs_readdir: use a list macro.


# 1.114 20-Sep-2004 jdolecek

add 'mounts' file for -o linux, which lists all currently mounted
filesystems; Linux glibc statvfs() uses this to get some of mount flags,
and this file is also useful as /emul/linux/etc/mtab (via symlink)


# 1.113 29-Apr-2004 jrf

Removed remaining caddr_t casts we do not need in miscfs. Recompiled
kernel and ran for a day or so. There are still some caddr_t types in
the arguments of some calls, I will do those separately (later) as
they touch a lot more of the system.
Approved by christos@NetBSD.org.


# 1.112 22-Apr-2004 itojun

sprintf -> snprintf


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.111 15-Feb-2004 jdolecek

unlock the descriptor table simple lock after fd_getfile() call in
procfs_readdir()
fixes procfs locking problems reported on current-users@, problem place
found by enami tsugutomo


# 1.110 30-Oct-2003 simonb

Remove some assigned-to but otherwise unused variables.


# 1.109 27-Sep-2003 darcy

Changes as discussed with itojun on tech-kern. I have modified the enums
to have KFS or PFS differentiators. Further I have wrapped the enum in
procfs in "#ifdef _KERNEL" as it is done in kernfs.

To see the discussion go to http://mail-index.NetBSD.org/tech-kern/2003/09/
and look for "Mismatched enums in include files" in the list.


# 1.108 07-Sep-2003 itojun

remove meaningless line (variable overwritten 2 lines below)


# 1.107 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.


# 1.106 29-Jun-2003 fvdl

branches: 1.106.2;
Back out the lwp/ktrace changes. They contained a lot of colateral damage,
and need to be examined and discussed more.


# 1.105 29-Jun-2003 thorpej

Undo part of the ktrace/lwp changes. In particular:
* Remove the "lwp *" argument that was added to vget(). Turns out
that nothing actually used it!
* Remove the "lwp *" arguments that were added to VFS_ROOT(), VFS_VGET(),
and VFS_FHTOVP(); all they did was pass it to vget() (which, as noted
above, didn't use it).
* Remove all of the "lwp *" arguments to internal functions that were added
just to appease the above.


# 1.104 28-Jun-2003 darrenr

Pass lwp pointers throughtout the kernel, as required, so that the lwpid can
be inserted into ktrace records. The general change has been to replace
"struct proc *" with "struct lwp *" in various function prototypes, pass
the lwp through and use l_proc to get the process pointer when needed.

Bump the kernel rev up to 1.6V


# 1.103 28-May-2003 christos

Add /proc/<pid>/stat for linux compat. j2sdk1.4.2 depends on it.


# 1.102 18-Apr-2003 christos

Make symlinks for directories that point to the actual directory.
Make symlinks to [kqueue] and [misc] for kqueue and misc fds.


# 1.101 17-Apr-2003 jdolecek

do not show nodes corresponding to directory descriptors for process
in fd/ subdirectory, nor allow lookup/open for the nodes
this fixes PR kern/21187 for good, and also avoids interesting directory
locking issues


# 1.100 17-Apr-2003 jdolecek

procfs_readdir(): in Pfd case, only show descriptors of types we want
how to represent (vnodes, fifo, pipes); also use fd_getfile() et al

this avoids annoying EOPNOTSUPP error messages from ls -F and such


# 1.99 17-Apr-2003 jdolecek

procfs_lookup(): use fd_getfile() et al in Pfd case


# 1.98 17-Apr-2003 jdolecek

use fd_getfile() in procfs_getfp(), and FILE_USE()/FILE_UNUSE() the
returned file descriptor pointer appropriately


# 1.97 17-Apr-2003 jdolecek

make some local arrays/variables static + const


# 1.96 10-Apr-2003 jdolecek

use former genfs_eopnotsupp_rele() as genfs_eopnotsupp(), so that vnodes
are vput()/vrele()d as necessary - some filesystems did use the wrong
one for some ops, and it's just safer to not take the chance

based on suggestion by Bill Studenmund


# 1.95 05-Apr-2003 dsl

Remove pointless check against PID_MAX. Let pfind() do the validation.
(The new pid allocation code may decide to allocate pids above PID_MAX.)


# 1.94 25-Feb-2003 jrf

This addresses PR kerm/19989. Thanks to hamajima@nagoya.ydc.co.jp for submitting this patch which enables /proc/uptime for linux emul. Patch reviewed by atatat@netbsd.org and tron@netbsd.org, approved by tron@netbsd.org.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 1.93 04-Jan-2003 martin

Cast off_t expression to long long to match format even on 64 bit
plattforms.

Shouldn't we introduce a PRIoff_t macro to create such format strings?


# 1.92 03-Jan-2003 christos

add LK_CANRECURSE in the locking of /dev/<pid>/fd/<n> and remove the curproc
kludge. Thanks to fvdl.


# 1.91 03-Jan-2003 christos

Implement /proc/<pid>/fd/<n>. This is work in progress. Questionable things:
- Is it ok to convert DTYPE_PIPE to VFIFO and DTYPE_SOCKET to VSOCK?
- XXX: Avoid locking issue in ls -Rl /proc by avoiding curproc
- Does I/O to pipes work?
- XXX: Are there security implications?


Revision tags: fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge gehenna-devsw-base kqueue-base
# 1.90 03-Aug-2002 simonb

Just use the "time" variable in the *_getattr functions instead of a call
to (the potentially expensive) microtime().


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.89 09-May-2002 thorpej

branches: 1.89.2;
Move code shared by procfs and the kernel proper out of procfs and
into the kernel proper (renaming functions from procfs_* to process_*).


Revision tags: eeh-devprop-base newlock-base ifpoll-base
# 1.88 12-Jan-2002 christos

Don't hide the real return code with EPERM.


# 1.87 06-Dec-2001 chs

add a VOP_PUTPAGES method for all the filesystems that don't have pages,
just unlock the interlock.


# 1.86 05-Dec-2001 thorpej

* Allow machine-dependent code to specify hooks for ptrace(2)
(__HAVE_PTRACE_MACHDEP) and procfs (__HAVE_PROCFS_MACHDEP).
These changes will allow platforms like x86 (XMM) and PowerPC
(AltiVec) to export extended register sets in a sane manner.

* Use __HAVE_PTRACE_MACHDEP to export x86 XMM registers (standard
FP + SSE/SSE2) using PT_{GET,SET}XMMREGS (in the machdep
ptrace request space).
* Use __HAVE_PROCFS_MACHDEP to export x86 XMM registers via
/proc/N/xmmregs in procfs.


Revision tags: thorpej-mips-cache-base
# 1.85 10-Nov-2001 lukem

add RCSIDs


# 1.84 06-Nov-2001 simonb

Remove some variables that are set but never used.


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base
# 1.83 31-Aug-2001 chs

branches: 1.83.2; 1.83.4;
map files are zero-length.


# 1.82 03-Jun-2001 chs

branches: 1.82.2;
procfs_bmap() should never be called, make it a "bad op".
let procfs_mmap() use the default error method.


Revision tags: thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 1.81 14-Apr-2001 kleink

In procfs_readdir(), give /proc/# directories DT_DIR (rather than DT_REG).


# 1.80 30-Mar-2001 fvdl

Bump va_blocksize for the map files some more, so that programs with
quite a few mappings have a chance of being handled correctly if
st_blksize is looked at.


# 1.79 29-Mar-2001 fvdl

For -o linux mounts, add some code to emulate /proc/#/maps.
Needs NAMECACHE_ENTER_REVERSE to include filenames.


# 1.78 21-Feb-2001 jdolecek

branches: 1.78.2;
make some more constant arrays 'const'


# 1.77 22-Jan-2001 jdolecek

make filesystem vnodeop, specop, fifoop and vnodeopv_* arrays const


# 1.76 17-Jan-2001 fvdl

Add a few linux-style files, only enabled when -o linux is specified
for the mount. Currently these are /proc/cpuinfo and /proc/meminfo.
The former only does something on i386 right now.


# 1.75 24-Nov-2000 chs

remove dead code and other misc cleanup.


# 1.74 09-Aug-2000 tv

Only show the "exe" entry to Linux processes, suggested by christos.
Since there are actually three struct emul's for linux, use the e_name
field to determine eligibility with strcmp().


# 1.73 09-Aug-2000 tv

Some versions of Linux libc look for /proc/.../exe instead of /proc/../file.
Add an entry for "exe" that is the same as "file", provided only if
COMPAT_LINUX is set.


# 1.72 03-Aug-2000 thorpej

MALLOC()/FREE() are not to be used for variable sized allocations.


# 1.71 28-Jun-2000 mrg

<vm/vm.h> -> <uvm/uvm_extern.h>


Revision tags: netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 1.70 30-Mar-2000 simonb

branches: 1.70.4;
Delete duplicate declaration of atopid().


Revision tags: chs-ubc2-newbase wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base fvdl-softdep-base
# 1.69 02-Sep-1999 thorpej

branches: 1.69.2; 1.69.8;
Make /proc/self a symlink to /proc/curproc. I've observed Linux programs
that expect /proc/self/cmdline to exist.


# 1.68 25-Aug-1999 sommerfeld

Change variable used for directory offset from "int" to "off_t".
Overkill, but avoids a host of truncation problems.


# 1.67 24-Aug-1999 sommerfeld

Fix PR8270:

Problem turned out to be due to improper handling of reads beyond EOF:
they should just return without error with the uio unchanged, and the
caller will recognize this as a zero-byte return (EOF).

The previous fix to protect directory reads against bogus uio_offset
values returned EINVAL, which broke mount -o union, which only
union'ed in the lower directory if the upper directory cleanly
returned EOF.

While we're here, protect kernfs as well.


# 1.66 14-Aug-1999 christos

protect against large uio_offset


# 1.65 03-Aug-1999 wrstuden

Add support for fcntl(2) to generate VOP_FCNTL calls. Any fcntl
call with F_FSCTL set and F_SETFL calls generate calls to a new
fileop fo_fcntl. Add genfs_fcntl() and soo_fcntl() which return 0
for F_SETFL and EOPNOTSUPP otherwise. Have all leaf filesystems
use genfs_fcntl().

Reviewed by: thorpej
Tested by: wrstuden


Revision tags: chs-ubc2-base
# 1.64 25-Jul-1999 thorpej

Add calls to lock the proclist as appropriate.


# 1.63 14-Jul-1999 thorpej

Fix a paste-o in procfs_lookup() introduced with the vnode locking changes.
Fixes PR #7961, Mario Kemper <magick@bundy.lip.owl.de>.


# 1.62 08-Jul-1999 wrstuden

Bump osrelease to 1.4E. Add layerfs files, remove null_subr.c.

Update coda to new struct lock in struct vnode.

make fdescfs, kernfs, portalfs, and procfs actually lock their vnodes.
It's not that hard.

Make unionfs set v_vnlock = NULL so any overlayed fs will call its
VOP_LOCK.


Revision tags: kame_141_19991130 netbsd-1-4-PATCH001 kame_14_19990705 kame_14_19990628 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.61 12-Mar-1999 christos

branches: 1.61.2; 1.61.4;
PR/7143: Jaromir Docelek: Add procfs/cmdline from Linux emulation


# 1.60 25-Jan-1999 msaitoh

Add /proc/#/map. From FreeBSD.


Revision tags: kenh-if-detach-base chs-ubc-base
# 1.59 08-Sep-1998 thorpej

- Use proclists[], rather than checking allproc and zombproc explicitly.
- Add some comments about locking.


# 1.58 13-Aug-1998 kleink

Per POSIX, fail with EINVAL if advisory locking is attempted on a file type
that doesn't support it, rather than using a homegrown EBADF or EOPNOTSUPP.


# 1.57 10-Aug-1998 matthias

create miscfs/genfs/genfs_vnops.c:genfs_enoioctl and make all the other
filesystems use it instead of a private version.


# 1.56 09-Aug-1998 perry

bzero->memset, bcopy->memcpy, bcmp->memcmp


# 1.55 03-Aug-1998 kleink

Recognize _PC_SYNC_IO.


Revision tags: eeh-paddr_t-base
# 1.54 21-Apr-1998 fvdl

procfs_readdir: in case of error, check if cookies actually have
been allocated before freeing them. From Wolfgang Solfrank.


# 1.53 01-Mar-1998 fvdl

Merge with Lite2 + local changes


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base marc-pcmcia-base
# 1.52 10-Oct-1997 fvdl

Bump last argument to VOP_READDIR to off_t (from u_long).


Revision tags: thorpej-signal-base
# 1.51 27-Aug-1997 thorpej

Fix a reversed argument which caused procfs_checkioperm() to always return
"OK". Add a few comments to avoid further confusion.


# 1.50 12-Aug-1997 thorpej

Fix the procfs hole described on current-users, similar to a fix for
FreeBSD by Sean Eric Fagan, but a bit different. This makes the checks
in the same places as sef's FreeBSD patch, but does not hardcode the
"kmem" group into the kernel, and also does a check identical to the
(3) and (4) checks in the NetBSD ptrace(2):

(1) it's not owned by you, or is set-id on exec (unless
you're root), or

(2) it's init, which controls the security level of the
entire system, and the system was not compiled with
permanently insecure mode turned on.


Revision tags: marc-pcmcia-bp
# 1.49 08-May-1997 mycroft

branches: 1.49.4;
Pass the vnode type to vaccess(), and use it when checking VEXEC. Make sure
that the mode bits passed to vaccess() and returned by foo_getattr() contain
only permission bits.


# 1.48 05-May-1997 mycroft

Need stat.h.


# 1.47 05-May-1997 mycroft

Eliminate bogus uses of V{READ,WRITE,EXEC}. Use S_I[RWX]{USR,GRP,OTH} where
appropriate.


# 1.46 28-Apr-1997 mycroft

Minor code cleanup.


Revision tags: is-newarp-before-merge is-newarp-base
# 1.45 25-Oct-1996 cgd

define path name string variables that we should not (and, thankfully, do
not) modify as 'const char *' rather 'char *'.


# 1.44 13-Oct-1996 christos

backout previous kprintf changes


# 1.43 10-Oct-1996 christos

printf -> kprintf, sprintf -> ksprintf


# 1.42 07-Sep-1996 mycroft

Implement poll(2).


# 1.41 01-Sep-1996 mycroft

Add a set of generic file system operations that most file systems use.
Also, fix some time stamp bogosities.


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 1.40 16-Mar-1996 christos

Fix printf format follies.


# 1.39 13-Feb-1996 mycroft

GC *_nullop(). Minor nits.


# 1.38 12-Feb-1996 christos

close PR/2063: procfs_rw prototyped twice with different prototypes


# 1.37 09-Feb-1996 christos

miscfs prototype changes


# 1.36 09-Feb-1996 mycroft

Fix vop_link, vop_symlink, and vop_remove semantics in several ways:
* Change the argument names to vop_link so they actually make sense.
* Implement vop_link and vop_symlink for all file systems, so they do proper
cleanup.
* Require the file system to decide whether or not linking and unlinking of
directories is allowed, and disable it for all current file systems.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.35 09-Oct-1995 mycroft

Use the index number as the cookie, rather than multiplying by UIO_MX.


# 1.34 09-Oct-1995 mycroft

Add support for cookies, mostly from Greg Hudson.


# 1.33 15-Apr-1995 cgd

fix timeval vs. timespec warnings


# 1.32 03-Feb-1995 mycroft

Return EROFS rather than ENOENT in many cases. Also some cosmetic cleanup.


# 1.31 27-Dec-1994 mycroft

Format police.


# 1.30 24-Dec-1994 ws

Implement and use a common access checking routine


# 1.29 14-Dec-1994 mycroft

Remove a_fp.


# 1.28 14-Nov-1994 christos

fixed struct comment


# 1.27 30-Oct-1994 cgd

be more careful with types, also pull in headers where necessary.


# 1.26 20-Oct-1994 cgd

update for new syscall args description mechanism


# 1.25 30-Aug-1994 mycroft

Convert process, file, and namei lists and hash tables to use queue.h.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.24 29-Jun-1994 cgd

New RCS ID's, take two. they're more aesthecially pleasant, and use 'NetBSD'


# 1.23 16-Jun-1994 mycroft

Remove an unneeded test.


# 1.22 15-Jun-1994 mycroft

Minor update from JSP after merging my changes.


# 1.21 08-Jun-1994 mycroft

Update to 4.4-Lite fs code, with local changes.


# 1.20 05-May-1994 cgd

lots of changes: prototype migration, move lots of variables, definitions,
and structure elements around. kill some unnecessary type and macro
definitions. standardize clock handling. More changes than you'd want.


# 1.19 15-Apr-1994 cgd

forgot these...


# 1.18 12-Apr-1994 cgd

be a bit smarter about determining if files shouldn't be seen by the user.
Also, DON'T allow a lookup to succeed on a file that's not visible!


# 1.17 15-Feb-1994 mycroft

Undo last change; executables is `file', not `a.out'.


# 1.16 14-Feb-1994 ws

Rename file -> a.out


# 1.15 14-Feb-1994 ws

Don't try to show a file for a process if there is none


# 1.14 28-Jan-1994 cgd

make a fpregs file.


# 1.13 20-Jan-1994 ws

Make procfs really work for debugging.
Implement not & notepg files in procfs.


# 1.12 09-Jan-1994 ws

Bug fixes and enhancements:
Make NFS serving work (BUT DON'T USE "attach" TO /proc/*/ctl FOR NOW!!!)
Make `curproc' a symbolic link
Add `.' and `..' entries to the directories.
Return better guesses on the size of the files.


# 1.11 05-Jan-1994 cgd

return size of 'reg' from getattr()


# 1.10 05-Jan-1994 cgd

make it compile (cleanly) for us


# 1.9 05-Jan-1994 cgd

add new procfs code, from Jan-Simon Pendry, jsp@sequent.com.
This is pretty-much "virgin", so that diffs can be done later.


# 1.8 18-Dec-1993 mycroft

Canonicalize all #includes.


Revision tags: magnum-base
# 1.7 16-Sep-1993 cgd

kill volatile warning.


# 1.6 07-Sep-1993 ws

branches: 1.6.2;
Changes to VFS readdir semantics
NFS changes for better cookie support
ISOFS changes for better Rockridge support and support for generation numbers


# 1.5 26-Aug-1993 pk

Implement setattr: mode for process entries; mode + uid/gid for the
PROCFS root directory.
Fixed omission in pfs_root() which came to light as a result of the above:
hold on to vnode for root dir.


# 1.4 25-Aug-1993 pk

Fixed improperly initialized nfsnode in pfs_lookup()


# 1.3 24-Aug-1993 pk

copyright update.


# 1.2 24-Aug-1993 pk

Rcs Id added.


# 1.1 24-Aug-1993 pk

branches: 1.1.1;
Initial version of a proc filesystem.


# 1.220 08-Dec-2021 andvar

s/efficent/efficient/ in comments.


# 1.219 05-Oct-2021 christos

PR/53299: RVP: kernfs and procfs are broken when sysctl security.curtain
is enabled


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base thorpej-i2c-spi-conf-base
# 1.218 18-Jul-2021 dholland

Abolish all the silly indirection macros for initializing vnode ops tables.

These are things of the form #define foofs_op genfs_op, or #define
foofs_op genfs_eopnotsupp, or similar. They serve no purpose besides
obfuscation, and have gotten cutpasted all over everywhere.


# 1.217 29-Jun-2021 dholland

- Add a new vnode op: VOP_PARSEPATH.
- Move namei_getcomponent to genfs_vnops.c and call it genfs_parsepath.
- Add a parsepath entry to every vnode ops table.

VOP_PARSEPATH takes a directory vnode to be searched and a complete
following path and chooses how much of that path to consume. To begin
with, all parsepath calls are genfs_parsepath, which locates the first
'/' as always.

Note that the call doesn't take the whole struct componentname, only
the string. The other bits of struct componentname should not be
needed and there's no reason to cause potential complications by
exposing them.


# 1.216 28-Jun-2021 chs

VOP_BMAP() may be called via ioctl(FIOGETBMAP) on any vnode that applications
can open. change various pseudo-fs *_bmap methods return an error instead of
panic.

Reported-by: syzbot+8289a3eaf2ba60958c87@syzkaller.appspotmail.com


Revision tags: cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base thorpej-cfargs-base thorpej-futex-base
# 1.215 27-Jun-2020 christos

branches: 1.215.6;
Introduce genfs_pathconf() and use it for the default case in all filesystems.


# 1.214 23-May-2020 ad

Move proc_lock into the data segment. It was dynamically allocated because
at the time we had mutex_obj_alloc() but not __cacheline_aligned.


# 1.213 16-May-2020 christos

Add ACL support for FFS. From FreeBSD.


# 1.212 29-Apr-2020 thorpej

If the procfs mount is marked as linux-compat, then allow proc lookup
by any LWP ID in the proc, not just the canonical PID.


Revision tags: bouyer-xenpvh-base2
# 1.211 21-Apr-2020 ad

Revert the changes made in February to make cwdinfo use mostly lockless,
which relied on taking extra vnode refs.

Having benchmarked various experimental changes over the past few months it
seems that it's better to avoid vnode refs as much as possible. cwdi_lock
as a RW lock already did that to some extent for getcwd() and will permit
the same for namei() too.


Revision tags: phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base is-mlppp-base phil-wifi-20200406 ad-namecache-base3
# 1.210 24-Feb-2020 ad

branches: 1.210.4;
v_interlock -> vmobjlock


# 1.209 23-Feb-2020 ad

Merge from ad-namecache:

- Have a stab at clustering the members of vnode_t and vnode_impl_t in a
more cache-conscious way. With that done, go back to adjusting v_usecount
with atomics and keep vi_lock directly in vnode_impl_t (saves KVA).

- Allow VOP_LOCK(LK_NONE) for the benefit of VFS_VGET() and VFS_ROOT().
Make sure LK_UPGRADE always comes with LK_NOWAIT.

- Make cwdinfo use mostly lockless.


# 1.208 01-Feb-2020 riastradh

Load struct filedesc::fd_dt with atomic_load_consume.

Exceptions: when fd_refcnt <= 1, or when holding fd_lock.

While here:

- Restore KASSERT(mutex_owned(&fdp->fd_lock)) in fd_unused.
=> This is used only in fd_close and fd_abort, where it holds.
- Move bounds check assertion in fd_putfile to where it matters.
- Store fd_dt with atomic_store_release.
- Move load of fd_dt under lock in knote_fdclose.
- Omit membar_consumer in fdesc_readdir.
=> atomic_load_consume serves the same purpose now.
=> Was needed only on alpha anyway.


Revision tags: ad-namecache-base2 ad-namecache-base1 ad-namecache-base phil-wifi-20191119
# 1.207 29-Aug-2019 hannken

branches: 1.207.2;
Add missing operation VOP_GETPAGES() returning EFAULT.

Without this operation posix_fadvise(..., POSIX_FADV_WILLNEED)
would leave the v_interlock held.

Observed by maxv@


Revision tags: netbsd-9-base phil-wifi-20190609 isaki-audio2-base
# 1.206 30-Mar-2019 christos

branches: 1.206.4;
add a node for the process resource limits.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020
# 1.205 14-Oct-2018 jdolecek

remove M_CANFAIL flag for malloc(9) - it was completely ignored, so had
actually no effect


Revision tags: pgoyette-compat-0930 pgoyette-compat-0906
# 1.204 03-Sep-2018 riastradh

Rename min/max -> uimin/uimax for better honesty.

These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER! Some subsystems have

#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)


Revision tags: pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415
# 1.203 07-Apr-2018 hannken

branches: 1.203.2;
Lock the target cwdi and take an additional reference to the
vnode we are interested in to prevent it from disappearing
before getcwd_common().

Should fix PR kern/53096 (netbsd-8 crash on heavy disk I/O)


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.202 31-Dec-2017 christos

branches: 1.202.2;
Add an environ node


Revision tags: tls-maxphys-base-20171202
# 1.201 01-Dec-2017 christos

Allow procfs_kqfilter, since we allow poll. "go" does it.


# 1.200 08-Nov-2017 christos

fix locking, remove error(1) comments.


# 1.199 08-Nov-2017 christos

use p->p_path, remove unused code.


# 1.198 28-Aug-2017 kamil

Remove the filesystem tracing feature

This is a legacy interface from 4.4BSD, and it was
introduced to overcome shortcomings of ptrace(2) at that time, which are
no longer relevant (performance). Today /proc/#/ctl offers a narrow
subset of ptrace(2) commands and is not applicable for modern
applications use beyond simplistic tracing scenarios.

This removal will simplify kernel internals. Users will still be able to
use all the other /proc files.

This change won't affect other procfs files neither Linux compat
features within mount_procfs(8). /proc/#/ctl isn't available on Linux.

Remove:
- /proc/#/ctl from mount_procfs(8)
- P_FSTRACE note from the documentation of ps(1)
- /proc/#/ctl and filesystem tracing documentation from mount_procfs(8)
- KAUTH_REQ_PROCESS_PROCFS_CTL documentation from kauth(9)
- source code file miscfs/procfs/procfs_ctl.c
- PFSctl and procfs_doctl() from sys/miscfs/procfs/procfs.h
- KAUTH_REQ_PROCESS_PROCFS_CTL from sys/sys/kauth.h
- PSL_FSTRACE (0x00010000) from sys/sys/proc.h
- P_FSTRACE (0x00010000) from sys/sys/sysctl.h

Reduce code complexity after removal of this functionality.

Update TODO.ptrace accordingly: remove two entries about /proc tracing.

Do not keep legacy notes as comments in the headers about removed
PSL_FSTRACE / P_FSTRACE, as this interface had little number of users
(close or equal to zero).

Proposed on tech-kern@.

All filesystem tracing utility users are encouraged to switch to ptrace(2).

Sponsored by <The NetBSD Foundation>


Revision tags: matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base
# 1.197 26-May-2017 riastradh

branches: 1.197.2;
Make VOP_RECLAIM do the last unlock of the vnode.

VOP_RECLAIM naturally has exclusive access to the vnode, so having it
locked on entry is not strictly necessary -- but it means if there
are any final operations that must be done on the vnode, such as
ffs_update, requiring exclusive access to it, we can now kassert that
the vnode is locked in those operations.

We can't just have the caller release the last lock because some file
systems don't use genfs_lock, and require the vnode to remain valid
for VOP_UNLOCK to work, notably unionfs.


Revision tags: prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.196 11-Apr-2017 riastradh

Make VOP_INACTIVE preserve vnode lock on return.

Discussed on tech-kern:
https://mail-index.netbsd.org/tech-kern/2017/04/01/msg021751.html

Ride 7.99.68, a bumpy bus of incremental vfs improvements!


Revision tags: jdolecek-ncq-base
# 1.195 30-Mar-2017 christos

add an auxv node.


Revision tags: pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004 localcount-20160914
# 1.194 20-Aug-2016 hannken

branches: 1.194.2;
Remove now obsolete operation vcache_remove().

Welcome to 7.99.36


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 nick-nhusb-base-20150921 nick-nhusb-base-20150606
# 1.193 20-Apr-2015 riastradh

branches: 1.193.2;
Make VOP_LINK return directory still locked and referenced.

Ride 7.99.10 bump.


Revision tags: nick-nhusb-base-20150406 nick-nhusb-base
# 1.192 05-Sep-2014 matt

branches: 1.192.2;
Try not to use f_data, use f_{vnode,socket,pipe,mqueue,kqueue,ksem} to get
a correctly typed pointer.


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.191 27-Jul-2014 hannken

branches: 1.191.2; 1.191.4; 1.191.8;
Change procfs from hashlist to vcache.
- Key is (type, pid, fd)
- Remove argument "p" from procfs_allocvp(). It is only used
when "type == PFSfd". Lookup the proc with proc_find() when
procfs_loadvnode() needs it.
- Use a vfs_vnode_iterator for procfs_revoke_vnodes().


# 1.190 25-Jul-2014 dholland

Add VOP_FALLOCATE and VOP_FDISCARD to every vnode ops table I can
find.

The filesystem ones all call genfs_eopnotsupp - right now I am only
implementing the plumbing and we can implement fallocate and/or
fdiscard for files later.

The device ones call spec_fallocate (which is also genfs_eopnotsupp)
and spec_fdiscard, which dispatches to the device-level op.

The fifo ones all call vn_fifo_bypass, which also ends up being
EOPNOTSUPP.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base
# 1.189 07-Feb-2014 hannken

branches: 1.189.2;
Change vnode operation lookup to return the resulting vnode *vpp unlocked.
Change cache_lookup() to return an unlocked vnode.

Discussed on tech-kern@

Welcome to 6.99.31


# 1.188 23-Jan-2014 hannken

Change vnode operations create, mknod, mkdir and symlink to return
the resulting vnode *vpp unlocked.

Discussed on tech-kern@

Welcome to 6.99.30


# 1.187 17-Jan-2014 hannken

Change vnode operations create, mknod, mkdir and symlink to keep the
directory node dvp locked on return.

Discussed on tech-kern@

Welcome to 6.99.29


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base
# 1.186 18-Mar-2013 plunky

branches: 1.186.6;
C99 section 6.7.2.3 (Tags) Note 3 states that:

A type specifier of the form

enum identifier

without an enumerator list shall only appear after the type it
specifies is complete.

which means that we cannot pass an "enum vtype" argument to
kauth_access_action() without fully specifying the type first.
Unfortunately there is a complicated include file loop which
makes that difficult, so convert this minimal function into a
macro (and capitalize it).

(ok elad@)


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 1.185 25-Nov-2012 christos

do something reasonable with kernel semaphores.


Revision tags: yamt-pagecache-base6 jmcneill-usbmp-base10
# 1.184 28-May-2012 christos

branches: 1.184.2;
add a task process subdirectory for emul linux


Revision tags: yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 1.183 13-Mar-2012 elad

Replace the remaining KAUTH_GENERIC_ISSUSER authorization calls with
something meaningful. All relevant documentation has been updated or
written.

Most of these changes were brought up in the following messages:

http://mail-index.netbsd.org/tech-kern/2012/01/18/msg012490.html
http://mail-index.netbsd.org/tech-kern/2012/01/19/msg012502.html
http://mail-index.netbsd.org/tech-kern/2012/02/17/msg012728.html

Thanks to christos, manu, njoly, and jmmv for input.

Huge thanks to pgoyette for spinning these changes through some build
cycles and ATF.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.182 04-Sep-2011 jmcneill

branches: 1.182.2; 1.182.6;
PR# kern/45021: Please support /emul/linux/proc/version

Add /proc/version for procfs with -o linux. The version reported depends
on the emulation type of the calling process:

$ cat /proc/version
NetBSD version 5.99.55 (netbsd@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) NetBSD 5.99.55 (GENERIC) #39: Sun Sep 4 09:10:05 EDT 2011

$ /emul/linux/bin/cat /proc/version
Linux version 2.6.18 (linux@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) #0 Wed Mar 3 03:03:03 PST 2010

$ /emul/linux32/bin/cat /proc/version
Linux version 2.6.18 (linux32@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) #0 Wed Mar 3 03:03:03 PST 2010


# 1.181 23-Jun-2011 christos

From Aleksey Cheusov: Don't make it easy for compromised systems to bypass
ASLR protections by providing the mapping addresses of programs to everyone.


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base matt-mips64-premerge-20101231 uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10 rmind-uvmplock-base
# 1.180 01-Jul-2010 rmind

Remove pfind() and pgfind(), fix locking in various broken uses of these.
Rename real routines to proc_find() and pgrp_find(), remove PFIND_* flags
and have consistent behaviour. Provide proc_find_raw() for special cases.
Fix memory leak in sysctl_proc_corename().

COMPAT_LINUX: rework ptrace() locking, minimise differences between
different versions per-arch.

Note: while this change adds some formal cosmetics for COMPAT_DARWIN and
COMPAT_IRIX - locking there is utterly broken (for ages).

Fixes PR/43176.


# 1.179 24-Jun-2010 hannken

Clean up vnode lock operations pass 2:

VOP_UNLOCK(vp, flags) -> VOP_UNLOCK(vp): Remove the unneeded flags argument.

Welcome to 5.99.32.

Discussed on tech-kern.


# 1.178 08-Jun-2010 hannken

Procfs_lookup() does not lookup directory descriptors in the fd/
subdirectory. There is no need for recursive vnode locking here.

Ok: Christos Zoulas <christos@netbsd.org>


Revision tags: uebayasi-xip-base1 yamt-nfs-mp-base9 uebayasi-xip-base
# 1.177 08-Jan-2010 pooka

branches: 1.177.2; 1.177.4;
The VATTR_NULL/VREF/VHOLD/HOLDRELE() macros lost their will to live
years ago when the kernel was modified to not alter ABI based on
DIAGNOSTIC, and now just call the respective function interfaces
(in lowercase). Plenty of mix'n match upper/lowercase has creeped
into the tree since then. Nuke the macros and convert all callsites
to lowercase.

no functional change


Revision tags: matt-premerge-20091211 yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 jym-xensuspend-nbase
# 1.176 03-Jul-2009 elad

Where possible, extract the file-system's access() routine to two internal
functions: the first checking if the operation is possible (regardless of
permissions), the second checking file-system permissions, ACLs, etc.

Mailing list reference:

http://mail-index.netbsd.org/tech-kern/2009/06/21/msg005311.html


# 1.175 23-Jun-2009 elad

Move the implementation of vaccess() to genfs_can_access(), in line with
the other routines of the same spirit.

Adjust file-system code to use it.

Keep vaccess() for KPI compatibility and to keep element of least
surprise. A "diagnostic" message warning that vaccess() is deprecated will
be printed when it's used (obviously, only in DIAGNOSTIC kernels).

No objections on tech-kern@:

http://mail-index.netbsd.org/tech-kern/2009/06/21/msg005310.html


Revision tags: yamt-nfs-mp-base5
# 1.174 24-May-2009 ad

More changes to improve kern_descrip.c.

- Avoid atomics in more places.
- Remove the per-descriptor mutex, and just use filedesc_t::fd_lock.
It was only being used to synchronize close, and in any case we needed
to take fd_lock to free the descriptor slot.
- Optimize certain paths for the <NDFDFILE case.
- Sprinkle more comments and assertions.
- Cache more stuff in filedesc_t.
- Fix numerous minor bugs spotted along the way.
- Restructure how the open files array is maintained, for clarity and so
that we can eliminate the membar_consumer() call in fd_getfile(). This is
mostly syntactic sugar; the main functional change is that fd_nfiles now
lives alongside the open file array.

Some measurements with libmicro:

- simple file syscalls are like close() are between 1 to 10% faster.
- some nice improvements, e.g. poll(1000) which is ~50% faster.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 nick-hppapmap-base2 jym-xensuspend-base nick-hppapmap-base mjf-devfs2-base
# 1.173 17-Dec-2008 cegger

branches: 1.173.2;
kill MALLOC and FREE macros.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 haad-dm-base2 haad-nbase2 ad-audiomp2-base netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 haad-dm-base
# 1.172 05-Sep-2008 skrll

branches: 1.172.2;
PR/39324 kernel diagnostic assertion "l->l_stat != LSZOMB" failed.

Ignore procs with zero or all LSZOMB LWPs. Get a non-LSZOMB LWP to perform
operations against as part of the deal.

procfs really needs to be updated to support multi-threading fully.
Hi Antti!


# 1.171 05-Sep-2008 skrll

ANSIfy


Revision tags: simonb-wapbl-nbase simonb-wapbl-base
# 1.170 02-Jul-2008 rmind

branches: 1.170.2;
Remove proc_representative_lwp(), use a simple LIST_FIRST() instead.
OK by <ad>.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base
# 1.169 28-Apr-2008 martin

branches: 1.169.2; 1.169.4;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-nfs-mp-base
# 1.168 24-Apr-2008 ad

branches: 1.168.2;
Merge proc::p_mutex and proc::p_smutex into a single adaptive mutex, since
we no longer need to guard against access from hardware interrupt handlers.

Additionally, if cloning a process with CLONE_SIGHAND, arrange to have the
child process share the parent's lock so that signal state may be kept in
sync. Partially addresses PR kern/37437.


# 1.167 24-Apr-2008 ad

Network protocol interrupts can now block on locks, so merge the globals
proclist_mutex and proclist_lock into a single adaptive mutex (proc_lock).
Implications:

- Inspecting process state requires thread context, so signals can no longer
be sent from a hardware interrupt handler. Signal activity must be
deferred to a soft interrupt or kthread.

- As the proc state locking is simplified, it's now safe to take exit()
and wait() out from under kernel_lock.

- The system spends less time at IPL_SCHED, and there is less lock activity.


Revision tags: yamt-pf42-baseX yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14
# 1.166 21-Mar-2008 ad

branches: 1.166.2;
Catch up with descriptor handling changes. See kern_descrip.c revision
1.173 for details.


Revision tags: keiichi-mipv6-nbase nick-net80211-sync-base keiichi-mipv6-base bouyer-xeni386-nbase matt-armv6-nbase mjf-devfs-base hpcarm-cleanup-base
# 1.165 23-Jan-2008 elad

branches: 1.165.6;
Tons of process scope changes.

- Add a KAUTH_PROCESS_SCHEDULER action, to handle scheduler related
requests, and add specific requests for set/get scheduler policy and
set/get scheduler parameters.

- Add a KAUTH_PROCESS_KEVENT_FILTER action, to handle kevent(2) related
requests.

- Add a KAUTH_DEVICE_TTY_STI action to handle requests to TIOCSTI.

- Add requests for the KAUTH_PROCESS_CANSEE action, indicating what
process information is being looked at (entry itself, args, env,
open files).

- Add requests for the KAUTH_PROCESS_RLIMIT action indicating set/get.

- Add requests for the KAUTH_PROCESS_CORENAME action indicating set/get.

- Make bsd44 secmodel code handle the newly added rqeuests appropriately.

All of the above make it possible to issue finer-grained kauth(9) calls in
many places, removing some KAUTH_GENERIC_ISSUSER requests.

- Remove the "CAN" from KAUTH_PROCESS_CAN{KTRACE,PROCFS,PTRACE,SIGNAL}.

Discussed with christos@ and yamt@.


Revision tags: bouyer-xeni386-base matt-armv6-base
# 1.164 02-Jan-2008 ad

Merge vmlocking2 to head.


Revision tags: vmlocking2-base3 yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 vmlocking-nbase jmcneill-pm-base reinoud-bufcleanup-base
# 1.163 26-Nov-2007 pooka

branches: 1.163.2; 1.163.6;
Remove the "struct lwp *" argument from all VFS and VOP interfaces.
The general trend is to remove it from all kernel interfaces and
this is a start. In case the calling lwp is desired, curlwp should
be used.

quick consensus on tech-kern


Revision tags: bouyer-xenamd64-base2 bouyer-xenamd64-base
# 1.162 09-Nov-2007 christos

make the last argument of procfs_dir size_t


# 1.161 07-Nov-2007 ad

Merge from vmlocking:

- pool_cache changes.
- Debugger/procfs locking fixes.
- Other minor changes.


Revision tags: jmcneill-base yamt-x86pmap-base4 yamt-x86pmap-base3 vmlocking-base
# 1.160 10-Oct-2007 ad

branches: 1.160.2; 1.160.4;
Merge from vmlocking:

- Split vnode::v_flag into three fields, depending on field locking.
- simple_lock -> kmutex in a few places.
- Fix some simple locking problems.


# 1.159 08-Oct-2007 ad

Merge file descriptor locking, cwdi locking and cross-call changes
from the vmlocking branch.


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base2 yamt-x86pmap-base matt-mips64-base
# 1.158 22-Jul-2007 pooka

branches: 1.158.4; 1.158.6; 1.158.8; 1.158.10;
Don't allow getcwd() on procfs vnodes and provide "/" as the path
instead of the result from getcwd(). The works around locking
panics caused by namei calling VOP_READLINK while holding on to a
directory lock and getcwd() trying to acquire that lock. The real
fix would be to get rid of getcwd() calls within VOPs (not locking
safe), but that's not a viable option in the netbsd-4 timeframe.

Suggestion for workaround from David Holland.


Revision tags: nick-csl-alignment-base mjf-ufs-trans-base
# 1.157 24-May-2007 agc

branches: 1.157.2;
Extend the Linux emulation of /proc to include

/proc/stat
/proc/loadavg and
/proc/<pid>/statm.

These are only present when -o linux is specified as a mount option
to procfs.

Factor out some common code so that it can be used by a number of
functions.

XXX The values returned in the statm emulation need to be verified.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 1.156 04-Apr-2007 rmind

Unfortunately, missed procfs_proc_unlock() in previous.
Pointed out by pooka@


# 1.155 04-Apr-2007 rmind

procfs_readlink: Handle a possible fail of fd_getfile(), also, we
do not need to check for error again.
CID: 4436


# 1.154 09-Mar-2007 ad

branches: 1.154.2; 1.154.4;
- Make the proclist_lock a mutex. The write:read ratio is unfavourable,
and mutexes are cheaper use than RW locks.
- LOCK_ASSERT -> KASSERT in some places.
- Hold proclist_lock/kernel_lock longer in a couple of places.


# 1.153 04-Mar-2007 christos

Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.


# 1.152 03-Mar-2007 salo

Don't prepend rootvnode to the path in non-NULL case for exe links.
It breaks procfs in chroot.

from <christos>, tested by me.


Revision tags: ad-audiomp-base
# 1.151 19-Feb-2007 pooka

When checking for file validity under pid/, do proper proc->lwp
lookup (fsvo proper) instead of fiddling directly with the lwp
list.


# 1.150 18-Feb-2007 pooka

Don't check for validity of p in lookup for root nodes, since it
will always be NULL. Rather, just call pt_valid with NULL directly
and let it decide if we're a linux mount or not.


# 1.149 17-Feb-2007 pavel

Change the process/lwp flags seen by userland via sysctl back to the
P_*/L_* naming convention, and rename the in-kernel flags to avoid
conflict. (P_ -> PK_, L_ -> LW_ ). Add back the (now unused) LSDEAD
constant.

Restores source compatibility with pre-newlock2 tools like ps or top.

Reviewed by Andrew Doran.


# 1.148 16-Feb-2007 pooka

branches: 1.148.2;
In lookup, when checking for procfs process node validity, target the
process we're trying to get information about through procfs, not
the caller of lookup.

fixes 'ls -l /proc/*/file' panic, which would occur when trying to
lookup "file" for a kernel thread, which doesn't have p->p_textvp.


# 1.147 15-Feb-2007 ad

Need to acquire procp->p_mutex for procfs_dir().


# 1.146 11-Feb-2007 ad

Eliminate a couple of reference count and mutex leaks.


Revision tags: post-newlock2-merge
# 1.145 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 1.144 25-Dec-2006 elad

PR/35226: Johann Franz: Problems with permissions in
/usr/pkg/emul/linux/proc .

Okay mlelstv@


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3
# 1.143 09-Dec-2006 chs

a smorgasbord of improvements to vnode locking and path lookup:
- LOCKPARENT is no longer relevant for lookup(), relookup() or VOP_LOOKUP().
these now always return the parent vnode locked. namei() works as before.
lookup() and various other paths no longer acquire vnode locks in the
wrong order via vrele(). fixes PR 32535.
as a nice side effect, path lookup is also up to 25% faster.
- the above allows us to get rid of PDIRUNLOCK.
- also get rid of WANTPARENT (just use LOCKPARENT and unlock it).
- remove an assumption in layer_node_find() that all file systems implement
a recursive VOP_LOCK() (unionfs doesn't).
- require that all file systems supply vfs_vptofh and vfs_fhtovp routines.
fill in eopnotsupp() for file systems that don't support being exported
and remove the checks for NULL. (layerfs calls these without checking.)
- in union_lookup1(), don't change refcounts in the ISDOTDOT case, just
adjust which vnode is locked. fixes PR 33374.
- apply fixes for ufs_rename() from ufs_vnops.c rev. 1.61 to ext2fs_rename().


# 1.142 04-Dec-2006 christos

From Nicolas Joly: restore previous behavior in procfs_validfile_linux, since
readdir passes a NULL lwp.


# 1.141 03-Dec-2006 elad

Move kauth(9) call to where it belongs. Noticed by Nicolas Joly, thanks!


Revision tags: netbsd-4-base
# 1.140 28-Nov-2006 elad

branches: 1.140.2;
Move ktrace, ptrace, systrace, and procfs to use kauth(9).

First, remove process_checkioperm() calls from MD code. Similar checks
using kauth(9) routines (on the process scope, using appropriate action)
are done in the callers.

Add secmodel back-end to handle each subsystem.


# 1.139 25-Nov-2006 skrll

Expose the 'exe' symlink to the process realpath in NetBSD as well. An
example user is gdb.

OK'd by christos.


# 1.138 16-Nov-2006 christos

__unused removal on arguments; approved by core.


# 1.137 29-Oct-2006 christos

add an "emul" file node.


# 1.136 25-Oct-2006 christos

1. fix procfs_validfile{,_linux} to test for NULL pointers properly.
2. make "exe" entry be a symlink to the executable, instead of pointing
directly to the vnode of the executable.
3. factor out commonly used code.


Revision tags: yamt-splraiseipl-base2
# 1.135 12-Oct-2006 christos

- sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386


# 1.134 20-Sep-2006 manu

Emulate Linux's /proc/devices


Revision tags: abandoned-netbsd-4-base yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base rpaulo-netinet-merge-pcb-base
# 1.133 13-Jun-2006 yamt

branches: 1.133.6; 1.133.8;
use KAUTH_PROCESS_CANSEE rather than CURTAIN where appropriate.


# 1.132 13-Jun-2006 yamt

remove unnecessary arguments from kauth_authorize_process.
ie. make it similar to the one found in apple TN.


# 1.131 07-Jun-2006 kardel

merge FreeBSD timecounters from branch simonb-timecounters
- struct timeval time is gone
time.tv_sec -> time_second
- struct timeval mono_time is gone
mono_time.tv_sec -> time_uptime
- access to time via
{get,}{micro,nano,bin}time()
get* versions are fast but less precise
- support NTP nanokernel implementation (NTP API 4)
- further reading:
Timecounter Paper: http://phk.freebsd.dk/pubs/timecounter.pdf
NTP Nanokernel: http://www.eecis.udel.edu/~mills/ntp/html/kern.html


Revision tags: yamt-pdpolicy-base5 simonb-timecounters-base
# 1.130 14-May-2006 elad

branches: 1.130.2;
integrate kauth.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 elad-kernelauth-base yamt-pdpolicy-base yamt-uio_vmspace-base5
# 1.129 02-Feb-2006 christos

branches: 1.129.2; 1.129.4; 1.129.6; 1.129.8;
PR/32692: Matthew Mondor: linux compatibility in /proc/self should point
directly to the directory containing the pid instead of pointing to
/proc/curproc, because some programs rely on calling readlink on /proc/self
to get the pid.


# 1.128 11-Dec-2005 christos

branches: 1.128.2; 1.128.4;
merge ktrace-lwp.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base ktrace-lwp-base
# 1.127 02-Nov-2005 yamt

merge yamt-vop branch. remove following VOPs.

VOP_BLKATOFF
VOP_VALLOC
VOP_BALLOC
VOP_REALLOCBLKS
VOP_VFREE
VOP_TRUNCATE
VOP_UPDATE


Revision tags: yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 1.126 01-Oct-2005 atatat

branches: 1.126.2;
Add "cwd" and "root" symlinks to each process's directory. The cwd
link points to the process's current working directory, and the root
link points to the process's root directory. What else would you
expect?

For directories that are out of reach (caller is in a chroot, target
process is in a different chroot, etc), the links point to "/"
instead.


# 1.125 11-Sep-2005 elad

Implement curtain for procfs.


# 1.124 30-Aug-2005 xtraeme

Remove __P()


# 1.123 29-May-2005 christos

branches: 1.123.2;
- sprinkle const
- avoid shadowed variables.


Revision tags: kent-audio2-base
# 1.122 02-Apr-2005 christos

PR/29782: Martin Husemann: procfs can not unmount when some process has its
current directory in curproc. Fix from Pedro Martelletto:
We cannot call vgone() from procfs_inactive() if we are coming from
vclean(). that's what's probably causing the deadlock.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 yamt-km-base4 yamt-km-base3 netbsd-3-base
# 1.121 26-Feb-2005 perry

nuke trailing whitespace


Revision tags: yamt-km-base2 yamt-km-base kent-audio1-beforemerge kent-audio1-base
# 1.120 04-Oct-2004 yamt

branches: 1.120.4; 1.120.6;
procfs_readdir:
- return correct cookie when buffer size is small.
- simplify logic.


# 1.119 04-Oct-2004 yamt

procfs_readdir: remove a redundant assignment.


# 1.118 02-Oct-2004 yamt

procfs_getattr: correct size of /proc/self.


# 1.117 01-Oct-2004 yamt

procfs_readdir:
- fix a locking problem, using proclist_foreach_call. PR/27098.
- correct snprintf size argument.


# 1.116 01-Oct-2004 yamt

procfs_readdir: fix an offset handling bug after addition of /proc/self.


# 1.115 01-Oct-2004 yamt

procfs_readdir: use a list macro.


# 1.114 20-Sep-2004 jdolecek

add 'mounts' file for -o linux, which lists all currently mounted
filesystems; Linux glibc statvfs() uses this to get some of mount flags,
and this file is also useful as /emul/linux/etc/mtab (via symlink)


# 1.113 29-Apr-2004 jrf

Removed remaining caddr_t casts we do not need in miscfs. Recompiled
kernel and ran for a day or so. There are still some caddr_t types in
the arguments of some calls, I will do those separately (later) as
they touch a lot more of the system.
Approved by christos@NetBSD.org.


# 1.112 22-Apr-2004 itojun

sprintf -> snprintf


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.111 15-Feb-2004 jdolecek

unlock the descriptor table simple lock after fd_getfile() call in
procfs_readdir()
fixes procfs locking problems reported on current-users@, problem place
found by enami tsugutomo


# 1.110 30-Oct-2003 simonb

Remove some assigned-to but otherwise unused variables.


# 1.109 27-Sep-2003 darcy

Changes as discussed with itojun on tech-kern. I have modified the enums
to have KFS or PFS differentiators. Further I have wrapped the enum in
procfs in "#ifdef _KERNEL" as it is done in kernfs.

To see the discussion go to http://mail-index.NetBSD.org/tech-kern/2003/09/
and look for "Mismatched enums in include files" in the list.


# 1.108 07-Sep-2003 itojun

remove meaningless line (variable overwritten 2 lines below)


# 1.107 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.


# 1.106 29-Jun-2003 fvdl

branches: 1.106.2;
Back out the lwp/ktrace changes. They contained a lot of colateral damage,
and need to be examined and discussed more.


# 1.105 29-Jun-2003 thorpej

Undo part of the ktrace/lwp changes. In particular:
* Remove the "lwp *" argument that was added to vget(). Turns out
that nothing actually used it!
* Remove the "lwp *" arguments that were added to VFS_ROOT(), VFS_VGET(),
and VFS_FHTOVP(); all they did was pass it to vget() (which, as noted
above, didn't use it).
* Remove all of the "lwp *" arguments to internal functions that were added
just to appease the above.


# 1.104 28-Jun-2003 darrenr

Pass lwp pointers throughtout the kernel, as required, so that the lwpid can
be inserted into ktrace records. The general change has been to replace
"struct proc *" with "struct lwp *" in various function prototypes, pass
the lwp through and use l_proc to get the process pointer when needed.

Bump the kernel rev up to 1.6V


# 1.103 28-May-2003 christos

Add /proc/<pid>/stat for linux compat. j2sdk1.4.2 depends on it.


# 1.102 18-Apr-2003 christos

Make symlinks for directories that point to the actual directory.
Make symlinks to [kqueue] and [misc] for kqueue and misc fds.


# 1.101 17-Apr-2003 jdolecek

do not show nodes corresponding to directory descriptors for process
in fd/ subdirectory, nor allow lookup/open for the nodes
this fixes PR kern/21187 for good, and also avoids interesting directory
locking issues


# 1.100 17-Apr-2003 jdolecek

procfs_readdir(): in Pfd case, only show descriptors of types we want
how to represent (vnodes, fifo, pipes); also use fd_getfile() et al

this avoids annoying EOPNOTSUPP error messages from ls -F and such


# 1.99 17-Apr-2003 jdolecek

procfs_lookup(): use fd_getfile() et al in Pfd case


# 1.98 17-Apr-2003 jdolecek

use fd_getfile() in procfs_getfp(), and FILE_USE()/FILE_UNUSE() the
returned file descriptor pointer appropriately


# 1.97 17-Apr-2003 jdolecek

make some local arrays/variables static + const


# 1.96 10-Apr-2003 jdolecek

use former genfs_eopnotsupp_rele() as genfs_eopnotsupp(), so that vnodes
are vput()/vrele()d as necessary - some filesystems did use the wrong
one for some ops, and it's just safer to not take the chance

based on suggestion by Bill Studenmund


# 1.95 05-Apr-2003 dsl

Remove pointless check against PID_MAX. Let pfind() do the validation.
(The new pid allocation code may decide to allocate pids above PID_MAX.)


# 1.94 25-Feb-2003 jrf

This addresses PR kerm/19989. Thanks to hamajima@nagoya.ydc.co.jp for submitting this patch which enables /proc/uptime for linux emul. Patch reviewed by atatat@netbsd.org and tron@netbsd.org, approved by tron@netbsd.org.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 1.93 04-Jan-2003 martin

Cast off_t expression to long long to match format even on 64 bit
plattforms.

Shouldn't we introduce a PRIoff_t macro to create such format strings?


# 1.92 03-Jan-2003 christos

add LK_CANRECURSE in the locking of /dev/<pid>/fd/<n> and remove the curproc
kludge. Thanks to fvdl.


# 1.91 03-Jan-2003 christos

Implement /proc/<pid>/fd/<n>. This is work in progress. Questionable things:
- Is it ok to convert DTYPE_PIPE to VFIFO and DTYPE_SOCKET to VSOCK?
- XXX: Avoid locking issue in ls -Rl /proc by avoiding curproc
- Does I/O to pipes work?
- XXX: Are there security implications?


Revision tags: fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge gehenna-devsw-base kqueue-base
# 1.90 03-Aug-2002 simonb

Just use the "time" variable in the *_getattr functions instead of a call
to (the potentially expensive) microtime().


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.89 09-May-2002 thorpej

branches: 1.89.2;
Move code shared by procfs and the kernel proper out of procfs and
into the kernel proper (renaming functions from procfs_* to process_*).


Revision tags: eeh-devprop-base newlock-base ifpoll-base
# 1.88 12-Jan-2002 christos

Don't hide the real return code with EPERM.


# 1.87 06-Dec-2001 chs

add a VOP_PUTPAGES method for all the filesystems that don't have pages,
just unlock the interlock.


# 1.86 05-Dec-2001 thorpej

* Allow machine-dependent code to specify hooks for ptrace(2)
(__HAVE_PTRACE_MACHDEP) and procfs (__HAVE_PROCFS_MACHDEP).
These changes will allow platforms like x86 (XMM) and PowerPC
(AltiVec) to export extended register sets in a sane manner.

* Use __HAVE_PTRACE_MACHDEP to export x86 XMM registers (standard
FP + SSE/SSE2) using PT_{GET,SET}XMMREGS (in the machdep
ptrace request space).
* Use __HAVE_PROCFS_MACHDEP to export x86 XMM registers via
/proc/N/xmmregs in procfs.


Revision tags: thorpej-mips-cache-base
# 1.85 10-Nov-2001 lukem

add RCSIDs


# 1.84 06-Nov-2001 simonb

Remove some variables that are set but never used.


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base
# 1.83 31-Aug-2001 chs

branches: 1.83.2; 1.83.4;
map files are zero-length.


# 1.82 03-Jun-2001 chs

branches: 1.82.2;
procfs_bmap() should never be called, make it a "bad op".
let procfs_mmap() use the default error method.


Revision tags: thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 1.81 14-Apr-2001 kleink

In procfs_readdir(), give /proc/# directories DT_DIR (rather than DT_REG).


# 1.80 30-Mar-2001 fvdl

Bump va_blocksize for the map files some more, so that programs with
quite a few mappings have a chance of being handled correctly if
st_blksize is looked at.


# 1.79 29-Mar-2001 fvdl

For -o linux mounts, add some code to emulate /proc/#/maps.
Needs NAMECACHE_ENTER_REVERSE to include filenames.


# 1.78 21-Feb-2001 jdolecek

branches: 1.78.2;
make some more constant arrays 'const'


# 1.77 22-Jan-2001 jdolecek

make filesystem vnodeop, specop, fifoop and vnodeopv_* arrays const


# 1.76 17-Jan-2001 fvdl

Add a few linux-style files, only enabled when -o linux is specified
for the mount. Currently these are /proc/cpuinfo and /proc/meminfo.
The former only does something on i386 right now.


# 1.75 24-Nov-2000 chs

remove dead code and other misc cleanup.


# 1.74 09-Aug-2000 tv

Only show the "exe" entry to Linux processes, suggested by christos.
Since there are actually three struct emul's for linux, use the e_name
field to determine eligibility with strcmp().


# 1.73 09-Aug-2000 tv

Some versions of Linux libc look for /proc/.../exe instead of /proc/../file.
Add an entry for "exe" that is the same as "file", provided only if
COMPAT_LINUX is set.


# 1.72 03-Aug-2000 thorpej

MALLOC()/FREE() are not to be used for variable sized allocations.


# 1.71 28-Jun-2000 mrg

<vm/vm.h> -> <uvm/uvm_extern.h>


Revision tags: netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 1.70 30-Mar-2000 simonb

branches: 1.70.4;
Delete duplicate declaration of atopid().


Revision tags: chs-ubc2-newbase wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base fvdl-softdep-base
# 1.69 02-Sep-1999 thorpej

branches: 1.69.2; 1.69.8;
Make /proc/self a symlink to /proc/curproc. I've observed Linux programs
that expect /proc/self/cmdline to exist.


# 1.68 25-Aug-1999 sommerfeld

Change variable used for directory offset from "int" to "off_t".
Overkill, but avoids a host of truncation problems.


# 1.67 24-Aug-1999 sommerfeld

Fix PR8270:

Problem turned out to be due to improper handling of reads beyond EOF:
they should just return without error with the uio unchanged, and the
caller will recognize this as a zero-byte return (EOF).

The previous fix to protect directory reads against bogus uio_offset
values returned EINVAL, which broke mount -o union, which only
union'ed in the lower directory if the upper directory cleanly
returned EOF.

While we're here, protect kernfs as well.


# 1.66 14-Aug-1999 christos

protect against large uio_offset


# 1.65 03-Aug-1999 wrstuden

Add support for fcntl(2) to generate VOP_FCNTL calls. Any fcntl
call with F_FSCTL set and F_SETFL calls generate calls to a new
fileop fo_fcntl. Add genfs_fcntl() and soo_fcntl() which return 0
for F_SETFL and EOPNOTSUPP otherwise. Have all leaf filesystems
use genfs_fcntl().

Reviewed by: thorpej
Tested by: wrstuden


Revision tags: chs-ubc2-base
# 1.64 25-Jul-1999 thorpej

Add calls to lock the proclist as appropriate.


# 1.63 14-Jul-1999 thorpej

Fix a paste-o in procfs_lookup() introduced with the vnode locking changes.
Fixes PR #7961, Mario Kemper <magick@bundy.lip.owl.de>.


# 1.62 08-Jul-1999 wrstuden

Bump osrelease to 1.4E. Add layerfs files, remove null_subr.c.

Update coda to new struct lock in struct vnode.

make fdescfs, kernfs, portalfs, and procfs actually lock their vnodes.
It's not that hard.

Make unionfs set v_vnlock = NULL so any overlayed fs will call its
VOP_LOCK.


Revision tags: kame_141_19991130 netbsd-1-4-PATCH001 kame_14_19990705 kame_14_19990628 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.61 12-Mar-1999 christos

branches: 1.61.2; 1.61.4;
PR/7143: Jaromir Docelek: Add procfs/cmdline from Linux emulation


# 1.60 25-Jan-1999 msaitoh

Add /proc/#/map. From FreeBSD.


Revision tags: kenh-if-detach-base chs-ubc-base
# 1.59 08-Sep-1998 thorpej

- Use proclists[], rather than checking allproc and zombproc explicitly.
- Add some comments about locking.


# 1.58 13-Aug-1998 kleink

Per POSIX, fail with EINVAL if advisory locking is attempted on a file type
that doesn't support it, rather than using a homegrown EBADF or EOPNOTSUPP.


# 1.57 10-Aug-1998 matthias

create miscfs/genfs/genfs_vnops.c:genfs_enoioctl and make all the other
filesystems use it instead of a private version.


# 1.56 09-Aug-1998 perry

bzero->memset, bcopy->memcpy, bcmp->memcmp


# 1.55 03-Aug-1998 kleink

Recognize _PC_SYNC_IO.


Revision tags: eeh-paddr_t-base
# 1.54 21-Apr-1998 fvdl

procfs_readdir: in case of error, check if cookies actually have
been allocated before freeing them. From Wolfgang Solfrank.


# 1.53 01-Mar-1998 fvdl

Merge with Lite2 + local changes


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base marc-pcmcia-base
# 1.52 10-Oct-1997 fvdl

Bump last argument to VOP_READDIR to off_t (from u_long).


Revision tags: thorpej-signal-base
# 1.51 27-Aug-1997 thorpej

Fix a reversed argument which caused procfs_checkioperm() to always return
"OK". Add a few comments to avoid further confusion.


# 1.50 12-Aug-1997 thorpej

Fix the procfs hole described on current-users, similar to a fix for
FreeBSD by Sean Eric Fagan, but a bit different. This makes the checks
in the same places as sef's FreeBSD patch, but does not hardcode the
"kmem" group into the kernel, and also does a check identical to the
(3) and (4) checks in the NetBSD ptrace(2):

(1) it's not owned by you, or is set-id on exec (unless
you're root), or

(2) it's init, which controls the security level of the
entire system, and the system was not compiled with
permanently insecure mode turned on.


Revision tags: marc-pcmcia-bp
# 1.49 08-May-1997 mycroft

branches: 1.49.4;
Pass the vnode type to vaccess(), and use it when checking VEXEC. Make sure
that the mode bits passed to vaccess() and returned by foo_getattr() contain
only permission bits.


# 1.48 05-May-1997 mycroft

Need stat.h.


# 1.47 05-May-1997 mycroft

Eliminate bogus uses of V{READ,WRITE,EXEC}. Use S_I[RWX]{USR,GRP,OTH} where
appropriate.


# 1.46 28-Apr-1997 mycroft

Minor code cleanup.


Revision tags: is-newarp-before-merge is-newarp-base
# 1.45 25-Oct-1996 cgd

define path name string variables that we should not (and, thankfully, do
not) modify as 'const char *' rather 'char *'.


# 1.44 13-Oct-1996 christos

backout previous kprintf changes


# 1.43 10-Oct-1996 christos

printf -> kprintf, sprintf -> ksprintf


# 1.42 07-Sep-1996 mycroft

Implement poll(2).


# 1.41 01-Sep-1996 mycroft

Add a set of generic file system operations that most file systems use.
Also, fix some time stamp bogosities.


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 1.40 16-Mar-1996 christos

Fix printf format follies.


# 1.39 13-Feb-1996 mycroft

GC *_nullop(). Minor nits.


# 1.38 12-Feb-1996 christos

close PR/2063: procfs_rw prototyped twice with different prototypes


# 1.37 09-Feb-1996 christos

miscfs prototype changes


# 1.36 09-Feb-1996 mycroft

Fix vop_link, vop_symlink, and vop_remove semantics in several ways:
* Change the argument names to vop_link so they actually make sense.
* Implement vop_link and vop_symlink for all file systems, so they do proper
cleanup.
* Require the file system to decide whether or not linking and unlinking of
directories is allowed, and disable it for all current file systems.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.35 09-Oct-1995 mycroft

Use the index number as the cookie, rather than multiplying by UIO_MX.


# 1.34 09-Oct-1995 mycroft

Add support for cookies, mostly from Greg Hudson.


# 1.33 15-Apr-1995 cgd

fix timeval vs. timespec warnings


# 1.32 03-Feb-1995 mycroft

Return EROFS rather than ENOENT in many cases. Also some cosmetic cleanup.


# 1.31 27-Dec-1994 mycroft

Format police.


# 1.30 24-Dec-1994 ws

Implement and use a common access checking routine


# 1.29 14-Dec-1994 mycroft

Remove a_fp.


# 1.28 14-Nov-1994 christos

fixed struct comment


# 1.27 30-Oct-1994 cgd

be more careful with types, also pull in headers where necessary.


# 1.26 20-Oct-1994 cgd

update for new syscall args description mechanism


# 1.25 30-Aug-1994 mycroft

Convert process, file, and namei lists and hash tables to use queue.h.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.24 29-Jun-1994 cgd

New RCS ID's, take two. they're more aesthecially pleasant, and use 'NetBSD'


# 1.23 16-Jun-1994 mycroft

Remove an unneeded test.


# 1.22 15-Jun-1994 mycroft

Minor update from JSP after merging my changes.


# 1.21 08-Jun-1994 mycroft

Update to 4.4-Lite fs code, with local changes.


# 1.20 05-May-1994 cgd

lots of changes: prototype migration, move lots of variables, definitions,
and structure elements around. kill some unnecessary type and macro
definitions. standardize clock handling. More changes than you'd want.


# 1.19 15-Apr-1994 cgd

forgot these...


# 1.18 12-Apr-1994 cgd

be a bit smarter about determining if files shouldn't be seen by the user.
Also, DON'T allow a lookup to succeed on a file that's not visible!


# 1.17 15-Feb-1994 mycroft

Undo last change; executables is `file', not `a.out'.


# 1.16 14-Feb-1994 ws

Rename file -> a.out


# 1.15 14-Feb-1994 ws

Don't try to show a file for a process if there is none


# 1.14 28-Jan-1994 cgd

make a fpregs file.


# 1.13 20-Jan-1994 ws

Make procfs really work for debugging.
Implement not & notepg files in procfs.


# 1.12 09-Jan-1994 ws

Bug fixes and enhancements:
Make NFS serving work (BUT DON'T USE "attach" TO /proc/*/ctl FOR NOW!!!)
Make `curproc' a symbolic link
Add `.' and `..' entries to the directories.
Return better guesses on the size of the files.


# 1.11 05-Jan-1994 cgd

return size of 'reg' from getattr()


# 1.10 05-Jan-1994 cgd

make it compile (cleanly) for us


# 1.9 05-Jan-1994 cgd

add new procfs code, from Jan-Simon Pendry, jsp@sequent.com.
This is pretty-much "virgin", so that diffs can be done later.


# 1.8 18-Dec-1993 mycroft

Canonicalize all #includes.


Revision tags: magnum-base
# 1.7 16-Sep-1993 cgd

kill volatile warning.


# 1.6 07-Sep-1993 ws

branches: 1.6.2;
Changes to VFS readdir semantics
NFS changes for better cookie support
ISOFS changes for better Rockridge support and support for generation numbers


# 1.5 26-Aug-1993 pk

Implement setattr: mode for process entries; mode + uid/gid for the
PROCFS root directory.
Fixed omission in pfs_root() which came to light as a result of the above:
hold on to vnode for root dir.


# 1.4 25-Aug-1993 pk

Fixed improperly initialized nfsnode in pfs_lookup()


# 1.3 24-Aug-1993 pk

copyright update.


# 1.2 24-Aug-1993 pk

Rcs Id added.


# 1.1 24-Aug-1993 pk

branches: 1.1.1;
Initial version of a proc filesystem.


# 1.219 05-Oct-2021 christos

PR/53299: RVP: kernfs and procfs are broken when sysctl security.curtain
is enabled


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base thorpej-i2c-spi-conf-base
# 1.218 18-Jul-2021 dholland

Abolish all the silly indirection macros for initializing vnode ops tables.

These are things of the form #define foofs_op genfs_op, or #define
foofs_op genfs_eopnotsupp, or similar. They serve no purpose besides
obfuscation, and have gotten cutpasted all over everywhere.


# 1.217 29-Jun-2021 dholland

- Add a new vnode op: VOP_PARSEPATH.
- Move namei_getcomponent to genfs_vnops.c and call it genfs_parsepath.
- Add a parsepath entry to every vnode ops table.

VOP_PARSEPATH takes a directory vnode to be searched and a complete
following path and chooses how much of that path to consume. To begin
with, all parsepath calls are genfs_parsepath, which locates the first
'/' as always.

Note that the call doesn't take the whole struct componentname, only
the string. The other bits of struct componentname should not be
needed and there's no reason to cause potential complications by
exposing them.


# 1.216 28-Jun-2021 chs

VOP_BMAP() may be called via ioctl(FIOGETBMAP) on any vnode that applications
can open. change various pseudo-fs *_bmap methods return an error instead of
panic.

Reported-by: syzbot+8289a3eaf2ba60958c87@syzkaller.appspotmail.com


Revision tags: cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base thorpej-cfargs-base thorpej-futex-base
# 1.215 27-Jun-2020 christos

branches: 1.215.6;
Introduce genfs_pathconf() and use it for the default case in all filesystems.


# 1.214 23-May-2020 ad

Move proc_lock into the data segment. It was dynamically allocated because
at the time we had mutex_obj_alloc() but not __cacheline_aligned.


# 1.213 16-May-2020 christos

Add ACL support for FFS. From FreeBSD.


# 1.212 29-Apr-2020 thorpej

If the procfs mount is marked as linux-compat, then allow proc lookup
by any LWP ID in the proc, not just the canonical PID.


Revision tags: bouyer-xenpvh-base2
# 1.211 21-Apr-2020 ad

Revert the changes made in February to make cwdinfo use mostly lockless,
which relied on taking extra vnode refs.

Having benchmarked various experimental changes over the past few months it
seems that it's better to avoid vnode refs as much as possible. cwdi_lock
as a RW lock already did that to some extent for getcwd() and will permit
the same for namei() too.


Revision tags: phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base is-mlppp-base phil-wifi-20200406 ad-namecache-base3
# 1.210 24-Feb-2020 ad

branches: 1.210.4;
v_interlock -> vmobjlock


# 1.209 23-Feb-2020 ad

Merge from ad-namecache:

- Have a stab at clustering the members of vnode_t and vnode_impl_t in a
more cache-conscious way. With that done, go back to adjusting v_usecount
with atomics and keep vi_lock directly in vnode_impl_t (saves KVA).

- Allow VOP_LOCK(LK_NONE) for the benefit of VFS_VGET() and VFS_ROOT().
Make sure LK_UPGRADE always comes with LK_NOWAIT.

- Make cwdinfo use mostly lockless.


# 1.208 01-Feb-2020 riastradh

Load struct filedesc::fd_dt with atomic_load_consume.

Exceptions: when fd_refcnt <= 1, or when holding fd_lock.

While here:

- Restore KASSERT(mutex_owned(&fdp->fd_lock)) in fd_unused.
=> This is used only in fd_close and fd_abort, where it holds.
- Move bounds check assertion in fd_putfile to where it matters.
- Store fd_dt with atomic_store_release.
- Move load of fd_dt under lock in knote_fdclose.
- Omit membar_consumer in fdesc_readdir.
=> atomic_load_consume serves the same purpose now.
=> Was needed only on alpha anyway.


Revision tags: ad-namecache-base2 ad-namecache-base1 ad-namecache-base phil-wifi-20191119
# 1.207 29-Aug-2019 hannken

branches: 1.207.2;
Add missing operation VOP_GETPAGES() returning EFAULT.

Without this operation posix_fadvise(..., POSIX_FADV_WILLNEED)
would leave the v_interlock held.

Observed by maxv@


Revision tags: netbsd-9-base phil-wifi-20190609 isaki-audio2-base
# 1.206 30-Mar-2019 christos

branches: 1.206.4;
add a node for the process resource limits.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020
# 1.205 14-Oct-2018 jdolecek

remove M_CANFAIL flag for malloc(9) - it was completely ignored, so had
actually no effect


Revision tags: pgoyette-compat-0930 pgoyette-compat-0906
# 1.204 03-Sep-2018 riastradh

Rename min/max -> uimin/uimax for better honesty.

These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER! Some subsystems have

#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)


Revision tags: pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415
# 1.203 07-Apr-2018 hannken

branches: 1.203.2;
Lock the target cwdi and take an additional reference to the
vnode we are interested in to prevent it from disappearing
before getcwd_common().

Should fix PR kern/53096 (netbsd-8 crash on heavy disk I/O)


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.202 31-Dec-2017 christos

branches: 1.202.2;
Add an environ node


Revision tags: tls-maxphys-base-20171202
# 1.201 01-Dec-2017 christos

Allow procfs_kqfilter, since we allow poll. "go" does it.


# 1.200 08-Nov-2017 christos

fix locking, remove error(1) comments.


# 1.199 08-Nov-2017 christos

use p->p_path, remove unused code.


# 1.198 28-Aug-2017 kamil

Remove the filesystem tracing feature

This is a legacy interface from 4.4BSD, and it was
introduced to overcome shortcomings of ptrace(2) at that time, which are
no longer relevant (performance). Today /proc/#/ctl offers a narrow
subset of ptrace(2) commands and is not applicable for modern
applications use beyond simplistic tracing scenarios.

This removal will simplify kernel internals. Users will still be able to
use all the other /proc files.

This change won't affect other procfs files neither Linux compat
features within mount_procfs(8). /proc/#/ctl isn't available on Linux.

Remove:
- /proc/#/ctl from mount_procfs(8)
- P_FSTRACE note from the documentation of ps(1)
- /proc/#/ctl and filesystem tracing documentation from mount_procfs(8)
- KAUTH_REQ_PROCESS_PROCFS_CTL documentation from kauth(9)
- source code file miscfs/procfs/procfs_ctl.c
- PFSctl and procfs_doctl() from sys/miscfs/procfs/procfs.h
- KAUTH_REQ_PROCESS_PROCFS_CTL from sys/sys/kauth.h
- PSL_FSTRACE (0x00010000) from sys/sys/proc.h
- P_FSTRACE (0x00010000) from sys/sys/sysctl.h

Reduce code complexity after removal of this functionality.

Update TODO.ptrace accordingly: remove two entries about /proc tracing.

Do not keep legacy notes as comments in the headers about removed
PSL_FSTRACE / P_FSTRACE, as this interface had little number of users
(close or equal to zero).

Proposed on tech-kern@.

All filesystem tracing utility users are encouraged to switch to ptrace(2).

Sponsored by <The NetBSD Foundation>


Revision tags: matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base
# 1.197 26-May-2017 riastradh

branches: 1.197.2;
Make VOP_RECLAIM do the last unlock of the vnode.

VOP_RECLAIM naturally has exclusive access to the vnode, so having it
locked on entry is not strictly necessary -- but it means if there
are any final operations that must be done on the vnode, such as
ffs_update, requiring exclusive access to it, we can now kassert that
the vnode is locked in those operations.

We can't just have the caller release the last lock because some file
systems don't use genfs_lock, and require the vnode to remain valid
for VOP_UNLOCK to work, notably unionfs.


Revision tags: prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.196 11-Apr-2017 riastradh

Make VOP_INACTIVE preserve vnode lock on return.

Discussed on tech-kern:
https://mail-index.netbsd.org/tech-kern/2017/04/01/msg021751.html

Ride 7.99.68, a bumpy bus of incremental vfs improvements!


Revision tags: jdolecek-ncq-base
# 1.195 30-Mar-2017 christos

add an auxv node.


Revision tags: pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004 localcount-20160914
# 1.194 20-Aug-2016 hannken

branches: 1.194.2;
Remove now obsolete operation vcache_remove().

Welcome to 7.99.36


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 nick-nhusb-base-20150921 nick-nhusb-base-20150606
# 1.193 20-Apr-2015 riastradh

branches: 1.193.2;
Make VOP_LINK return directory still locked and referenced.

Ride 7.99.10 bump.


Revision tags: nick-nhusb-base-20150406 nick-nhusb-base
# 1.192 05-Sep-2014 matt

branches: 1.192.2;
Try not to use f_data, use f_{vnode,socket,pipe,mqueue,kqueue,ksem} to get
a correctly typed pointer.


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.191 27-Jul-2014 hannken

branches: 1.191.2; 1.191.4; 1.191.8;
Change procfs from hashlist to vcache.
- Key is (type, pid, fd)
- Remove argument "p" from procfs_allocvp(). It is only used
when "type == PFSfd". Lookup the proc with proc_find() when
procfs_loadvnode() needs it.
- Use a vfs_vnode_iterator for procfs_revoke_vnodes().


# 1.190 25-Jul-2014 dholland

Add VOP_FALLOCATE and VOP_FDISCARD to every vnode ops table I can
find.

The filesystem ones all call genfs_eopnotsupp - right now I am only
implementing the plumbing and we can implement fallocate and/or
fdiscard for files later.

The device ones call spec_fallocate (which is also genfs_eopnotsupp)
and spec_fdiscard, which dispatches to the device-level op.

The fifo ones all call vn_fifo_bypass, which also ends up being
EOPNOTSUPP.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base
# 1.189 07-Feb-2014 hannken

branches: 1.189.2;
Change vnode operation lookup to return the resulting vnode *vpp unlocked.
Change cache_lookup() to return an unlocked vnode.

Discussed on tech-kern@

Welcome to 6.99.31


# 1.188 23-Jan-2014 hannken

Change vnode operations create, mknod, mkdir and symlink to return
the resulting vnode *vpp unlocked.

Discussed on tech-kern@

Welcome to 6.99.30


# 1.187 17-Jan-2014 hannken

Change vnode operations create, mknod, mkdir and symlink to keep the
directory node dvp locked on return.

Discussed on tech-kern@

Welcome to 6.99.29


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base
# 1.186 18-Mar-2013 plunky

branches: 1.186.6;
C99 section 6.7.2.3 (Tags) Note 3 states that:

A type specifier of the form

enum identifier

without an enumerator list shall only appear after the type it
specifies is complete.

which means that we cannot pass an "enum vtype" argument to
kauth_access_action() without fully specifying the type first.
Unfortunately there is a complicated include file loop which
makes that difficult, so convert this minimal function into a
macro (and capitalize it).

(ok elad@)


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 1.185 25-Nov-2012 christos

do something reasonable with kernel semaphores.


Revision tags: yamt-pagecache-base6 jmcneill-usbmp-base10
# 1.184 28-May-2012 christos

branches: 1.184.2;
add a task process subdirectory for emul linux


Revision tags: yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 1.183 13-Mar-2012 elad

Replace the remaining KAUTH_GENERIC_ISSUSER authorization calls with
something meaningful. All relevant documentation has been updated or
written.

Most of these changes were brought up in the following messages:

http://mail-index.netbsd.org/tech-kern/2012/01/18/msg012490.html
http://mail-index.netbsd.org/tech-kern/2012/01/19/msg012502.html
http://mail-index.netbsd.org/tech-kern/2012/02/17/msg012728.html

Thanks to christos, manu, njoly, and jmmv for input.

Huge thanks to pgoyette for spinning these changes through some build
cycles and ATF.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.182 04-Sep-2011 jmcneill

branches: 1.182.2; 1.182.6;
PR# kern/45021: Please support /emul/linux/proc/version

Add /proc/version for procfs with -o linux. The version reported depends
on the emulation type of the calling process:

$ cat /proc/version
NetBSD version 5.99.55 (netbsd@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) NetBSD 5.99.55 (GENERIC) #39: Sun Sep 4 09:10:05 EDT 2011

$ /emul/linux/bin/cat /proc/version
Linux version 2.6.18 (linux@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) #0 Wed Mar 3 03:03:03 PST 2010

$ /emul/linux32/bin/cat /proc/version
Linux version 2.6.18 (linux32@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) #0 Wed Mar 3 03:03:03 PST 2010


# 1.181 23-Jun-2011 christos

From Aleksey Cheusov: Don't make it easy for compromised systems to bypass
ASLR protections by providing the mapping addresses of programs to everyone.


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base matt-mips64-premerge-20101231 uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10 rmind-uvmplock-base
# 1.180 01-Jul-2010 rmind

Remove pfind() and pgfind(), fix locking in various broken uses of these.
Rename real routines to proc_find() and pgrp_find(), remove PFIND_* flags
and have consistent behaviour. Provide proc_find_raw() for special cases.
Fix memory leak in sysctl_proc_corename().

COMPAT_LINUX: rework ptrace() locking, minimise differences between
different versions per-arch.

Note: while this change adds some formal cosmetics for COMPAT_DARWIN and
COMPAT_IRIX - locking there is utterly broken (for ages).

Fixes PR/43176.


# 1.179 24-Jun-2010 hannken

Clean up vnode lock operations pass 2:

VOP_UNLOCK(vp, flags) -> VOP_UNLOCK(vp): Remove the unneeded flags argument.

Welcome to 5.99.32.

Discussed on tech-kern.


# 1.178 08-Jun-2010 hannken

Procfs_lookup() does not lookup directory descriptors in the fd/
subdirectory. There is no need for recursive vnode locking here.

Ok: Christos Zoulas <christos@netbsd.org>


Revision tags: uebayasi-xip-base1 yamt-nfs-mp-base9 uebayasi-xip-base
# 1.177 08-Jan-2010 pooka

branches: 1.177.2; 1.177.4;
The VATTR_NULL/VREF/VHOLD/HOLDRELE() macros lost their will to live
years ago when the kernel was modified to not alter ABI based on
DIAGNOSTIC, and now just call the respective function interfaces
(in lowercase). Plenty of mix'n match upper/lowercase has creeped
into the tree since then. Nuke the macros and convert all callsites
to lowercase.

no functional change


Revision tags: matt-premerge-20091211 yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 jym-xensuspend-nbase
# 1.176 03-Jul-2009 elad

Where possible, extract the file-system's access() routine to two internal
functions: the first checking if the operation is possible (regardless of
permissions), the second checking file-system permissions, ACLs, etc.

Mailing list reference:

http://mail-index.netbsd.org/tech-kern/2009/06/21/msg005311.html


# 1.175 23-Jun-2009 elad

Move the implementation of vaccess() to genfs_can_access(), in line with
the other routines of the same spirit.

Adjust file-system code to use it.

Keep vaccess() for KPI compatibility and to keep element of least
surprise. A "diagnostic" message warning that vaccess() is deprecated will
be printed when it's used (obviously, only in DIAGNOSTIC kernels).

No objections on tech-kern@:

http://mail-index.netbsd.org/tech-kern/2009/06/21/msg005310.html


Revision tags: yamt-nfs-mp-base5
# 1.174 24-May-2009 ad

More changes to improve kern_descrip.c.

- Avoid atomics in more places.
- Remove the per-descriptor mutex, and just use filedesc_t::fd_lock.
It was only being used to synchronize close, and in any case we needed
to take fd_lock to free the descriptor slot.
- Optimize certain paths for the <NDFDFILE case.
- Sprinkle more comments and assertions.
- Cache more stuff in filedesc_t.
- Fix numerous minor bugs spotted along the way.
- Restructure how the open files array is maintained, for clarity and so
that we can eliminate the membar_consumer() call in fd_getfile(). This is
mostly syntactic sugar; the main functional change is that fd_nfiles now
lives alongside the open file array.

Some measurements with libmicro:

- simple file syscalls are like close() are between 1 to 10% faster.
- some nice improvements, e.g. poll(1000) which is ~50% faster.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 nick-hppapmap-base2 jym-xensuspend-base nick-hppapmap-base mjf-devfs2-base
# 1.173 17-Dec-2008 cegger

branches: 1.173.2;
kill MALLOC and FREE macros.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 haad-dm-base2 haad-nbase2 ad-audiomp2-base netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 haad-dm-base
# 1.172 05-Sep-2008 skrll

branches: 1.172.2;
PR/39324 kernel diagnostic assertion "l->l_stat != LSZOMB" failed.

Ignore procs with zero or all LSZOMB LWPs. Get a non-LSZOMB LWP to perform
operations against as part of the deal.

procfs really needs to be updated to support multi-threading fully.
Hi Antti!


# 1.171 05-Sep-2008 skrll

ANSIfy


Revision tags: simonb-wapbl-nbase simonb-wapbl-base
# 1.170 02-Jul-2008 rmind

branches: 1.170.2;
Remove proc_representative_lwp(), use a simple LIST_FIRST() instead.
OK by <ad>.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base
# 1.169 28-Apr-2008 martin

branches: 1.169.2; 1.169.4;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-nfs-mp-base
# 1.168 24-Apr-2008 ad

branches: 1.168.2;
Merge proc::p_mutex and proc::p_smutex into a single adaptive mutex, since
we no longer need to guard against access from hardware interrupt handlers.

Additionally, if cloning a process with CLONE_SIGHAND, arrange to have the
child process share the parent's lock so that signal state may be kept in
sync. Partially addresses PR kern/37437.


# 1.167 24-Apr-2008 ad

Network protocol interrupts can now block on locks, so merge the globals
proclist_mutex and proclist_lock into a single adaptive mutex (proc_lock).
Implications:

- Inspecting process state requires thread context, so signals can no longer
be sent from a hardware interrupt handler. Signal activity must be
deferred to a soft interrupt or kthread.

- As the proc state locking is simplified, it's now safe to take exit()
and wait() out from under kernel_lock.

- The system spends less time at IPL_SCHED, and there is less lock activity.


Revision tags: yamt-pf42-baseX yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14
# 1.166 21-Mar-2008 ad

branches: 1.166.2;
Catch up with descriptor handling changes. See kern_descrip.c revision
1.173 for details.


Revision tags: keiichi-mipv6-nbase nick-net80211-sync-base keiichi-mipv6-base bouyer-xeni386-nbase matt-armv6-nbase mjf-devfs-base hpcarm-cleanup-base
# 1.165 23-Jan-2008 elad

branches: 1.165.6;
Tons of process scope changes.

- Add a KAUTH_PROCESS_SCHEDULER action, to handle scheduler related
requests, and add specific requests for set/get scheduler policy and
set/get scheduler parameters.

- Add a KAUTH_PROCESS_KEVENT_FILTER action, to handle kevent(2) related
requests.

- Add a KAUTH_DEVICE_TTY_STI action to handle requests to TIOCSTI.

- Add requests for the KAUTH_PROCESS_CANSEE action, indicating what
process information is being looked at (entry itself, args, env,
open files).

- Add requests for the KAUTH_PROCESS_RLIMIT action indicating set/get.

- Add requests for the KAUTH_PROCESS_CORENAME action indicating set/get.

- Make bsd44 secmodel code handle the newly added rqeuests appropriately.

All of the above make it possible to issue finer-grained kauth(9) calls in
many places, removing some KAUTH_GENERIC_ISSUSER requests.

- Remove the "CAN" from KAUTH_PROCESS_CAN{KTRACE,PROCFS,PTRACE,SIGNAL}.

Discussed with christos@ and yamt@.


Revision tags: bouyer-xeni386-base matt-armv6-base
# 1.164 02-Jan-2008 ad

Merge vmlocking2 to head.


Revision tags: vmlocking2-base3 yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 vmlocking-nbase jmcneill-pm-base reinoud-bufcleanup-base
# 1.163 26-Nov-2007 pooka

branches: 1.163.2; 1.163.6;
Remove the "struct lwp *" argument from all VFS and VOP interfaces.
The general trend is to remove it from all kernel interfaces and
this is a start. In case the calling lwp is desired, curlwp should
be used.

quick consensus on tech-kern


Revision tags: bouyer-xenamd64-base2 bouyer-xenamd64-base
# 1.162 09-Nov-2007 christos

make the last argument of procfs_dir size_t


# 1.161 07-Nov-2007 ad

Merge from vmlocking:

- pool_cache changes.
- Debugger/procfs locking fixes.
- Other minor changes.


Revision tags: jmcneill-base yamt-x86pmap-base4 yamt-x86pmap-base3 vmlocking-base
# 1.160 10-Oct-2007 ad

branches: 1.160.2; 1.160.4;
Merge from vmlocking:

- Split vnode::v_flag into three fields, depending on field locking.
- simple_lock -> kmutex in a few places.
- Fix some simple locking problems.


# 1.159 08-Oct-2007 ad

Merge file descriptor locking, cwdi locking and cross-call changes
from the vmlocking branch.


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base2 yamt-x86pmap-base matt-mips64-base
# 1.158 22-Jul-2007 pooka

branches: 1.158.4; 1.158.6; 1.158.8; 1.158.10;
Don't allow getcwd() on procfs vnodes and provide "/" as the path
instead of the result from getcwd(). The works around locking
panics caused by namei calling VOP_READLINK while holding on to a
directory lock and getcwd() trying to acquire that lock. The real
fix would be to get rid of getcwd() calls within VOPs (not locking
safe), but that's not a viable option in the netbsd-4 timeframe.

Suggestion for workaround from David Holland.


Revision tags: nick-csl-alignment-base mjf-ufs-trans-base
# 1.157 24-May-2007 agc

branches: 1.157.2;
Extend the Linux emulation of /proc to include

/proc/stat
/proc/loadavg and
/proc/<pid>/statm.

These are only present when -o linux is specified as a mount option
to procfs.

Factor out some common code so that it can be used by a number of
functions.

XXX The values returned in the statm emulation need to be verified.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 1.156 04-Apr-2007 rmind

Unfortunately, missed procfs_proc_unlock() in previous.
Pointed out by pooka@


# 1.155 04-Apr-2007 rmind

procfs_readlink: Handle a possible fail of fd_getfile(), also, we
do not need to check for error again.
CID: 4436


# 1.154 09-Mar-2007 ad

branches: 1.154.2; 1.154.4;
- Make the proclist_lock a mutex. The write:read ratio is unfavourable,
and mutexes are cheaper use than RW locks.
- LOCK_ASSERT -> KASSERT in some places.
- Hold proclist_lock/kernel_lock longer in a couple of places.


# 1.153 04-Mar-2007 christos

Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.


# 1.152 03-Mar-2007 salo

Don't prepend rootvnode to the path in non-NULL case for exe links.
It breaks procfs in chroot.

from <christos>, tested by me.


Revision tags: ad-audiomp-base
# 1.151 19-Feb-2007 pooka

When checking for file validity under pid/, do proper proc->lwp
lookup (fsvo proper) instead of fiddling directly with the lwp
list.


# 1.150 18-Feb-2007 pooka

Don't check for validity of p in lookup for root nodes, since it
will always be NULL. Rather, just call pt_valid with NULL directly
and let it decide if we're a linux mount or not.


# 1.149 17-Feb-2007 pavel

Change the process/lwp flags seen by userland via sysctl back to the
P_*/L_* naming convention, and rename the in-kernel flags to avoid
conflict. (P_ -> PK_, L_ -> LW_ ). Add back the (now unused) LSDEAD
constant.

Restores source compatibility with pre-newlock2 tools like ps or top.

Reviewed by Andrew Doran.


# 1.148 16-Feb-2007 pooka

branches: 1.148.2;
In lookup, when checking for procfs process node validity, target the
process we're trying to get information about through procfs, not
the caller of lookup.

fixes 'ls -l /proc/*/file' panic, which would occur when trying to
lookup "file" for a kernel thread, which doesn't have p->p_textvp.


# 1.147 15-Feb-2007 ad

Need to acquire procp->p_mutex for procfs_dir().


# 1.146 11-Feb-2007 ad

Eliminate a couple of reference count and mutex leaks.


Revision tags: post-newlock2-merge
# 1.145 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 1.144 25-Dec-2006 elad

PR/35226: Johann Franz: Problems with permissions in
/usr/pkg/emul/linux/proc .

Okay mlelstv@


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3
# 1.143 09-Dec-2006 chs

a smorgasbord of improvements to vnode locking and path lookup:
- LOCKPARENT is no longer relevant for lookup(), relookup() or VOP_LOOKUP().
these now always return the parent vnode locked. namei() works as before.
lookup() and various other paths no longer acquire vnode locks in the
wrong order via vrele(). fixes PR 32535.
as a nice side effect, path lookup is also up to 25% faster.
- the above allows us to get rid of PDIRUNLOCK.
- also get rid of WANTPARENT (just use LOCKPARENT and unlock it).
- remove an assumption in layer_node_find() that all file systems implement
a recursive VOP_LOCK() (unionfs doesn't).
- require that all file systems supply vfs_vptofh and vfs_fhtovp routines.
fill in eopnotsupp() for file systems that don't support being exported
and remove the checks for NULL. (layerfs calls these without checking.)
- in union_lookup1(), don't change refcounts in the ISDOTDOT case, just
adjust which vnode is locked. fixes PR 33374.
- apply fixes for ufs_rename() from ufs_vnops.c rev. 1.61 to ext2fs_rename().


# 1.142 04-Dec-2006 christos

From Nicolas Joly: restore previous behavior in procfs_validfile_linux, since
readdir passes a NULL lwp.


# 1.141 03-Dec-2006 elad

Move kauth(9) call to where it belongs. Noticed by Nicolas Joly, thanks!


Revision tags: netbsd-4-base
# 1.140 28-Nov-2006 elad

branches: 1.140.2;
Move ktrace, ptrace, systrace, and procfs to use kauth(9).

First, remove process_checkioperm() calls from MD code. Similar checks
using kauth(9) routines (on the process scope, using appropriate action)
are done in the callers.

Add secmodel back-end to handle each subsystem.


# 1.139 25-Nov-2006 skrll

Expose the 'exe' symlink to the process realpath in NetBSD as well. An
example user is gdb.

OK'd by christos.


# 1.138 16-Nov-2006 christos

__unused removal on arguments; approved by core.


# 1.137 29-Oct-2006 christos

add an "emul" file node.


# 1.136 25-Oct-2006 christos

1. fix procfs_validfile{,_linux} to test for NULL pointers properly.
2. make "exe" entry be a symlink to the executable, instead of pointing
directly to the vnode of the executable.
3. factor out commonly used code.


Revision tags: yamt-splraiseipl-base2
# 1.135 12-Oct-2006 christos

- sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386


# 1.134 20-Sep-2006 manu

Emulate Linux's /proc/devices


Revision tags: abandoned-netbsd-4-base yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base rpaulo-netinet-merge-pcb-base
# 1.133 13-Jun-2006 yamt

branches: 1.133.6; 1.133.8;
use KAUTH_PROCESS_CANSEE rather than CURTAIN where appropriate.


# 1.132 13-Jun-2006 yamt

remove unnecessary arguments from kauth_authorize_process.
ie. make it similar to the one found in apple TN.


# 1.131 07-Jun-2006 kardel

merge FreeBSD timecounters from branch simonb-timecounters
- struct timeval time is gone
time.tv_sec -> time_second
- struct timeval mono_time is gone
mono_time.tv_sec -> time_uptime
- access to time via
{get,}{micro,nano,bin}time()
get* versions are fast but less precise
- support NTP nanokernel implementation (NTP API 4)
- further reading:
Timecounter Paper: http://phk.freebsd.dk/pubs/timecounter.pdf
NTP Nanokernel: http://www.eecis.udel.edu/~mills/ntp/html/kern.html


Revision tags: yamt-pdpolicy-base5 simonb-timecounters-base
# 1.130 14-May-2006 elad

branches: 1.130.2;
integrate kauth.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 elad-kernelauth-base yamt-pdpolicy-base yamt-uio_vmspace-base5
# 1.129 02-Feb-2006 christos

branches: 1.129.2; 1.129.4; 1.129.6; 1.129.8;
PR/32692: Matthew Mondor: linux compatibility in /proc/self should point
directly to the directory containing the pid instead of pointing to
/proc/curproc, because some programs rely on calling readlink on /proc/self
to get the pid.


# 1.128 11-Dec-2005 christos

branches: 1.128.2; 1.128.4;
merge ktrace-lwp.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base ktrace-lwp-base
# 1.127 02-Nov-2005 yamt

merge yamt-vop branch. remove following VOPs.

VOP_BLKATOFF
VOP_VALLOC
VOP_BALLOC
VOP_REALLOCBLKS
VOP_VFREE
VOP_TRUNCATE
VOP_UPDATE


Revision tags: yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 1.126 01-Oct-2005 atatat

branches: 1.126.2;
Add "cwd" and "root" symlinks to each process's directory. The cwd
link points to the process's current working directory, and the root
link points to the process's root directory. What else would you
expect?

For directories that are out of reach (caller is in a chroot, target
process is in a different chroot, etc), the links point to "/"
instead.


# 1.125 11-Sep-2005 elad

Implement curtain for procfs.


# 1.124 30-Aug-2005 xtraeme

Remove __P()


# 1.123 29-May-2005 christos

branches: 1.123.2;
- sprinkle const
- avoid shadowed variables.


Revision tags: kent-audio2-base
# 1.122 02-Apr-2005 christos

PR/29782: Martin Husemann: procfs can not unmount when some process has its
current directory in curproc. Fix from Pedro Martelletto:
We cannot call vgone() from procfs_inactive() if we are coming from
vclean(). that's what's probably causing the deadlock.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 yamt-km-base4 yamt-km-base3 netbsd-3-base
# 1.121 26-Feb-2005 perry

nuke trailing whitespace


Revision tags: yamt-km-base2 yamt-km-base kent-audio1-beforemerge kent-audio1-base
# 1.120 04-Oct-2004 yamt

branches: 1.120.4; 1.120.6;
procfs_readdir:
- return correct cookie when buffer size is small.
- simplify logic.


# 1.119 04-Oct-2004 yamt

procfs_readdir: remove a redundant assignment.


# 1.118 02-Oct-2004 yamt

procfs_getattr: correct size of /proc/self.


# 1.117 01-Oct-2004 yamt

procfs_readdir:
- fix a locking problem, using proclist_foreach_call. PR/27098.
- correct snprintf size argument.


# 1.116 01-Oct-2004 yamt

procfs_readdir: fix an offset handling bug after addition of /proc/self.


# 1.115 01-Oct-2004 yamt

procfs_readdir: use a list macro.


# 1.114 20-Sep-2004 jdolecek

add 'mounts' file for -o linux, which lists all currently mounted
filesystems; Linux glibc statvfs() uses this to get some of mount flags,
and this file is also useful as /emul/linux/etc/mtab (via symlink)


# 1.113 29-Apr-2004 jrf

Removed remaining caddr_t casts we do not need in miscfs. Recompiled
kernel and ran for a day or so. There are still some caddr_t types in
the arguments of some calls, I will do those separately (later) as
they touch a lot more of the system.
Approved by christos@NetBSD.org.


# 1.112 22-Apr-2004 itojun

sprintf -> snprintf


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.111 15-Feb-2004 jdolecek

unlock the descriptor table simple lock after fd_getfile() call in
procfs_readdir()
fixes procfs locking problems reported on current-users@, problem place
found by enami tsugutomo


# 1.110 30-Oct-2003 simonb

Remove some assigned-to but otherwise unused variables.


# 1.109 27-Sep-2003 darcy

Changes as discussed with itojun on tech-kern. I have modified the enums
to have KFS or PFS differentiators. Further I have wrapped the enum in
procfs in "#ifdef _KERNEL" as it is done in kernfs.

To see the discussion go to http://mail-index.NetBSD.org/tech-kern/2003/09/
and look for "Mismatched enums in include files" in the list.


# 1.108 07-Sep-2003 itojun

remove meaningless line (variable overwritten 2 lines below)


# 1.107 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.


# 1.106 29-Jun-2003 fvdl

branches: 1.106.2;
Back out the lwp/ktrace changes. They contained a lot of colateral damage,
and need to be examined and discussed more.


# 1.105 29-Jun-2003 thorpej

Undo part of the ktrace/lwp changes. In particular:
* Remove the "lwp *" argument that was added to vget(). Turns out
that nothing actually used it!
* Remove the "lwp *" arguments that were added to VFS_ROOT(), VFS_VGET(),
and VFS_FHTOVP(); all they did was pass it to vget() (which, as noted
above, didn't use it).
* Remove all of the "lwp *" arguments to internal functions that were added
just to appease the above.


# 1.104 28-Jun-2003 darrenr

Pass lwp pointers throughtout the kernel, as required, so that the lwpid can
be inserted into ktrace records. The general change has been to replace
"struct proc *" with "struct lwp *" in various function prototypes, pass
the lwp through and use l_proc to get the process pointer when needed.

Bump the kernel rev up to 1.6V


# 1.103 28-May-2003 christos

Add /proc/<pid>/stat for linux compat. j2sdk1.4.2 depends on it.


# 1.102 18-Apr-2003 christos

Make symlinks for directories that point to the actual directory.
Make symlinks to [kqueue] and [misc] for kqueue and misc fds.


# 1.101 17-Apr-2003 jdolecek

do not show nodes corresponding to directory descriptors for process
in fd/ subdirectory, nor allow lookup/open for the nodes
this fixes PR kern/21187 for good, and also avoids interesting directory
locking issues


# 1.100 17-Apr-2003 jdolecek

procfs_readdir(): in Pfd case, only show descriptors of types we want
how to represent (vnodes, fifo, pipes); also use fd_getfile() et al

this avoids annoying EOPNOTSUPP error messages from ls -F and such


# 1.99 17-Apr-2003 jdolecek

procfs_lookup(): use fd_getfile() et al in Pfd case


# 1.98 17-Apr-2003 jdolecek

use fd_getfile() in procfs_getfp(), and FILE_USE()/FILE_UNUSE() the
returned file descriptor pointer appropriately


# 1.97 17-Apr-2003 jdolecek

make some local arrays/variables static + const


# 1.96 10-Apr-2003 jdolecek

use former genfs_eopnotsupp_rele() as genfs_eopnotsupp(), so that vnodes
are vput()/vrele()d as necessary - some filesystems did use the wrong
one for some ops, and it's just safer to not take the chance

based on suggestion by Bill Studenmund


# 1.95 05-Apr-2003 dsl

Remove pointless check against PID_MAX. Let pfind() do the validation.
(The new pid allocation code may decide to allocate pids above PID_MAX.)


# 1.94 25-Feb-2003 jrf

This addresses PR kerm/19989. Thanks to hamajima@nagoya.ydc.co.jp for submitting this patch which enables /proc/uptime for linux emul. Patch reviewed by atatat@netbsd.org and tron@netbsd.org, approved by tron@netbsd.org.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 1.93 04-Jan-2003 martin

Cast off_t expression to long long to match format even on 64 bit
plattforms.

Shouldn't we introduce a PRIoff_t macro to create such format strings?


# 1.92 03-Jan-2003 christos

add LK_CANRECURSE in the locking of /dev/<pid>/fd/<n> and remove the curproc
kludge. Thanks to fvdl.


# 1.91 03-Jan-2003 christos

Implement /proc/<pid>/fd/<n>. This is work in progress. Questionable things:
- Is it ok to convert DTYPE_PIPE to VFIFO and DTYPE_SOCKET to VSOCK?
- XXX: Avoid locking issue in ls -Rl /proc by avoiding curproc
- Does I/O to pipes work?
- XXX: Are there security implications?


Revision tags: fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge gehenna-devsw-base kqueue-base
# 1.90 03-Aug-2002 simonb

Just use the "time" variable in the *_getattr functions instead of a call
to (the potentially expensive) microtime().


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.89 09-May-2002 thorpej

branches: 1.89.2;
Move code shared by procfs and the kernel proper out of procfs and
into the kernel proper (renaming functions from procfs_* to process_*).


Revision tags: eeh-devprop-base newlock-base ifpoll-base
# 1.88 12-Jan-2002 christos

Don't hide the real return code with EPERM.


# 1.87 06-Dec-2001 chs

add a VOP_PUTPAGES method for all the filesystems that don't have pages,
just unlock the interlock.


# 1.86 05-Dec-2001 thorpej

* Allow machine-dependent code to specify hooks for ptrace(2)
(__HAVE_PTRACE_MACHDEP) and procfs (__HAVE_PROCFS_MACHDEP).
These changes will allow platforms like x86 (XMM) and PowerPC
(AltiVec) to export extended register sets in a sane manner.

* Use __HAVE_PTRACE_MACHDEP to export x86 XMM registers (standard
FP + SSE/SSE2) using PT_{GET,SET}XMMREGS (in the machdep
ptrace request space).
* Use __HAVE_PROCFS_MACHDEP to export x86 XMM registers via
/proc/N/xmmregs in procfs.


Revision tags: thorpej-mips-cache-base
# 1.85 10-Nov-2001 lukem

add RCSIDs


# 1.84 06-Nov-2001 simonb

Remove some variables that are set but never used.


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base
# 1.83 31-Aug-2001 chs

branches: 1.83.2; 1.83.4;
map files are zero-length.


# 1.82 03-Jun-2001 chs

branches: 1.82.2;
procfs_bmap() should never be called, make it a "bad op".
let procfs_mmap() use the default error method.


Revision tags: thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 1.81 14-Apr-2001 kleink

In procfs_readdir(), give /proc/# directories DT_DIR (rather than DT_REG).


# 1.80 30-Mar-2001 fvdl

Bump va_blocksize for the map files some more, so that programs with
quite a few mappings have a chance of being handled correctly if
st_blksize is looked at.


# 1.79 29-Mar-2001 fvdl

For -o linux mounts, add some code to emulate /proc/#/maps.
Needs NAMECACHE_ENTER_REVERSE to include filenames.


# 1.78 21-Feb-2001 jdolecek

branches: 1.78.2;
make some more constant arrays 'const'


# 1.77 22-Jan-2001 jdolecek

make filesystem vnodeop, specop, fifoop and vnodeopv_* arrays const


# 1.76 17-Jan-2001 fvdl

Add a few linux-style files, only enabled when -o linux is specified
for the mount. Currently these are /proc/cpuinfo and /proc/meminfo.
The former only does something on i386 right now.


# 1.75 24-Nov-2000 chs

remove dead code and other misc cleanup.


# 1.74 09-Aug-2000 tv

Only show the "exe" entry to Linux processes, suggested by christos.
Since there are actually three struct emul's for linux, use the e_name
field to determine eligibility with strcmp().


# 1.73 09-Aug-2000 tv

Some versions of Linux libc look for /proc/.../exe instead of /proc/../file.
Add an entry for "exe" that is the same as "file", provided only if
COMPAT_LINUX is set.


# 1.72 03-Aug-2000 thorpej

MALLOC()/FREE() are not to be used for variable sized allocations.


# 1.71 28-Jun-2000 mrg

<vm/vm.h> -> <uvm/uvm_extern.h>


Revision tags: netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 1.70 30-Mar-2000 simonb

branches: 1.70.4;
Delete duplicate declaration of atopid().


Revision tags: chs-ubc2-newbase wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base fvdl-softdep-base
# 1.69 02-Sep-1999 thorpej

branches: 1.69.2; 1.69.8;
Make /proc/self a symlink to /proc/curproc. I've observed Linux programs
that expect /proc/self/cmdline to exist.


# 1.68 25-Aug-1999 sommerfeld

Change variable used for directory offset from "int" to "off_t".
Overkill, but avoids a host of truncation problems.


# 1.67 24-Aug-1999 sommerfeld

Fix PR8270:

Problem turned out to be due to improper handling of reads beyond EOF:
they should just return without error with the uio unchanged, and the
caller will recognize this as a zero-byte return (EOF).

The previous fix to protect directory reads against bogus uio_offset
values returned EINVAL, which broke mount -o union, which only
union'ed in the lower directory if the upper directory cleanly
returned EOF.

While we're here, protect kernfs as well.


# 1.66 14-Aug-1999 christos

protect against large uio_offset


# 1.65 03-Aug-1999 wrstuden

Add support for fcntl(2) to generate VOP_FCNTL calls. Any fcntl
call with F_FSCTL set and F_SETFL calls generate calls to a new
fileop fo_fcntl. Add genfs_fcntl() and soo_fcntl() which return 0
for F_SETFL and EOPNOTSUPP otherwise. Have all leaf filesystems
use genfs_fcntl().

Reviewed by: thorpej
Tested by: wrstuden


Revision tags: chs-ubc2-base
# 1.64 25-Jul-1999 thorpej

Add calls to lock the proclist as appropriate.


# 1.63 14-Jul-1999 thorpej

Fix a paste-o in procfs_lookup() introduced with the vnode locking changes.
Fixes PR #7961, Mario Kemper <magick@bundy.lip.owl.de>.


# 1.62 08-Jul-1999 wrstuden

Bump osrelease to 1.4E. Add layerfs files, remove null_subr.c.

Update coda to new struct lock in struct vnode.

make fdescfs, kernfs, portalfs, and procfs actually lock their vnodes.
It's not that hard.

Make unionfs set v_vnlock = NULL so any overlayed fs will call its
VOP_LOCK.


Revision tags: kame_141_19991130 netbsd-1-4-PATCH001 kame_14_19990705 kame_14_19990628 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.61 12-Mar-1999 christos

branches: 1.61.2; 1.61.4;
PR/7143: Jaromir Docelek: Add procfs/cmdline from Linux emulation


# 1.60 25-Jan-1999 msaitoh

Add /proc/#/map. From FreeBSD.


Revision tags: kenh-if-detach-base chs-ubc-base
# 1.59 08-Sep-1998 thorpej

- Use proclists[], rather than checking allproc and zombproc explicitly.
- Add some comments about locking.


# 1.58 13-Aug-1998 kleink

Per POSIX, fail with EINVAL if advisory locking is attempted on a file type
that doesn't support it, rather than using a homegrown EBADF or EOPNOTSUPP.


# 1.57 10-Aug-1998 matthias

create miscfs/genfs/genfs_vnops.c:genfs_enoioctl and make all the other
filesystems use it instead of a private version.


# 1.56 09-Aug-1998 perry

bzero->memset, bcopy->memcpy, bcmp->memcmp


# 1.55 03-Aug-1998 kleink

Recognize _PC_SYNC_IO.


Revision tags: eeh-paddr_t-base
# 1.54 21-Apr-1998 fvdl

procfs_readdir: in case of error, check if cookies actually have
been allocated before freeing them. From Wolfgang Solfrank.


# 1.53 01-Mar-1998 fvdl

Merge with Lite2 + local changes


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base marc-pcmcia-base
# 1.52 10-Oct-1997 fvdl

Bump last argument to VOP_READDIR to off_t (from u_long).


Revision tags: thorpej-signal-base
# 1.51 27-Aug-1997 thorpej

Fix a reversed argument which caused procfs_checkioperm() to always return
"OK". Add a few comments to avoid further confusion.


# 1.50 12-Aug-1997 thorpej

Fix the procfs hole described on current-users, similar to a fix for
FreeBSD by Sean Eric Fagan, but a bit different. This makes the checks
in the same places as sef's FreeBSD patch, but does not hardcode the
"kmem" group into the kernel, and also does a check identical to the
(3) and (4) checks in the NetBSD ptrace(2):

(1) it's not owned by you, or is set-id on exec (unless
you're root), or

(2) it's init, which controls the security level of the
entire system, and the system was not compiled with
permanently insecure mode turned on.


Revision tags: marc-pcmcia-bp
# 1.49 08-May-1997 mycroft

branches: 1.49.4;
Pass the vnode type to vaccess(), and use it when checking VEXEC. Make sure
that the mode bits passed to vaccess() and returned by foo_getattr() contain
only permission bits.


# 1.48 05-May-1997 mycroft

Need stat.h.


# 1.47 05-May-1997 mycroft

Eliminate bogus uses of V{READ,WRITE,EXEC}. Use S_I[RWX]{USR,GRP,OTH} where
appropriate.


# 1.46 28-Apr-1997 mycroft

Minor code cleanup.


Revision tags: is-newarp-before-merge is-newarp-base
# 1.45 25-Oct-1996 cgd

define path name string variables that we should not (and, thankfully, do
not) modify as 'const char *' rather 'char *'.


# 1.44 13-Oct-1996 christos

backout previous kprintf changes


# 1.43 10-Oct-1996 christos

printf -> kprintf, sprintf -> ksprintf


# 1.42 07-Sep-1996 mycroft

Implement poll(2).


# 1.41 01-Sep-1996 mycroft

Add a set of generic file system operations that most file systems use.
Also, fix some time stamp bogosities.


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 1.40 16-Mar-1996 christos

Fix printf format follies.


# 1.39 13-Feb-1996 mycroft

GC *_nullop(). Minor nits.


# 1.38 12-Feb-1996 christos

close PR/2063: procfs_rw prototyped twice with different prototypes


# 1.37 09-Feb-1996 christos

miscfs prototype changes


# 1.36 09-Feb-1996 mycroft

Fix vop_link, vop_symlink, and vop_remove semantics in several ways:
* Change the argument names to vop_link so they actually make sense.
* Implement vop_link and vop_symlink for all file systems, so they do proper
cleanup.
* Require the file system to decide whether or not linking and unlinking of
directories is allowed, and disable it for all current file systems.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.35 09-Oct-1995 mycroft

Use the index number as the cookie, rather than multiplying by UIO_MX.


# 1.34 09-Oct-1995 mycroft

Add support for cookies, mostly from Greg Hudson.


# 1.33 15-Apr-1995 cgd

fix timeval vs. timespec warnings


# 1.32 03-Feb-1995 mycroft

Return EROFS rather than ENOENT in many cases. Also some cosmetic cleanup.


# 1.31 27-Dec-1994 mycroft

Format police.


# 1.30 24-Dec-1994 ws

Implement and use a common access checking routine


# 1.29 14-Dec-1994 mycroft

Remove a_fp.


# 1.28 14-Nov-1994 christos

fixed struct comment


# 1.27 30-Oct-1994 cgd

be more careful with types, also pull in headers where necessary.


# 1.26 20-Oct-1994 cgd

update for new syscall args description mechanism


# 1.25 30-Aug-1994 mycroft

Convert process, file, and namei lists and hash tables to use queue.h.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.24 29-Jun-1994 cgd

New RCS ID's, take two. they're more aesthecially pleasant, and use 'NetBSD'


# 1.23 16-Jun-1994 mycroft

Remove an unneeded test.


# 1.22 15-Jun-1994 mycroft

Minor update from JSP after merging my changes.


# 1.21 08-Jun-1994 mycroft

Update to 4.4-Lite fs code, with local changes.


# 1.20 05-May-1994 cgd

lots of changes: prototype migration, move lots of variables, definitions,
and structure elements around. kill some unnecessary type and macro
definitions. standardize clock handling. More changes than you'd want.


# 1.19 15-Apr-1994 cgd

forgot these...


# 1.18 12-Apr-1994 cgd

be a bit smarter about determining if files shouldn't be seen by the user.
Also, DON'T allow a lookup to succeed on a file that's not visible!


# 1.17 15-Feb-1994 mycroft

Undo last change; executables is `file', not `a.out'.


# 1.16 14-Feb-1994 ws

Rename file -> a.out


# 1.15 14-Feb-1994 ws

Don't try to show a file for a process if there is none


# 1.14 28-Jan-1994 cgd

make a fpregs file.


# 1.13 20-Jan-1994 ws

Make procfs really work for debugging.
Implement not & notepg files in procfs.


# 1.12 09-Jan-1994 ws

Bug fixes and enhancements:
Make NFS serving work (BUT DON'T USE "attach" TO /proc/*/ctl FOR NOW!!!)
Make `curproc' a symbolic link
Add `.' and `..' entries to the directories.
Return better guesses on the size of the files.


# 1.11 05-Jan-1994 cgd

return size of 'reg' from getattr()


# 1.10 05-Jan-1994 cgd

make it compile (cleanly) for us


# 1.9 05-Jan-1994 cgd

add new procfs code, from Jan-Simon Pendry, jsp@sequent.com.
This is pretty-much "virgin", so that diffs can be done later.


# 1.8 18-Dec-1993 mycroft

Canonicalize all #includes.


Revision tags: magnum-base
# 1.7 16-Sep-1993 cgd

kill volatile warning.


# 1.6 07-Sep-1993 ws

branches: 1.6.2;
Changes to VFS readdir semantics
NFS changes for better cookie support
ISOFS changes for better Rockridge support and support for generation numbers


# 1.5 26-Aug-1993 pk

Implement setattr: mode for process entries; mode + uid/gid for the
PROCFS root directory.
Fixed omission in pfs_root() which came to light as a result of the above:
hold on to vnode for root dir.


# 1.4 25-Aug-1993 pk

Fixed improperly initialized nfsnode in pfs_lookup()


# 1.3 24-Aug-1993 pk

copyright update.


# 1.2 24-Aug-1993 pk

Rcs Id added.


# 1.1 24-Aug-1993 pk

branches: 1.1.1;
Initial version of a proc filesystem.


# 1.218 18-Jul-2021 dholland

Abolish all the silly indirection macros for initializing vnode ops tables.

These are things of the form #define foofs_op genfs_op, or #define
foofs_op genfs_eopnotsupp, or similar. They serve no purpose besides
obfuscation, and have gotten cutpasted all over everywhere.


# 1.217 29-Jun-2021 dholland

- Add a new vnode op: VOP_PARSEPATH.
- Move namei_getcomponent to genfs_vnops.c and call it genfs_parsepath.
- Add a parsepath entry to every vnode ops table.

VOP_PARSEPATH takes a directory vnode to be searched and a complete
following path and chooses how much of that path to consume. To begin
with, all parsepath calls are genfs_parsepath, which locates the first
'/' as always.

Note that the call doesn't take the whole struct componentname, only
the string. The other bits of struct componentname should not be
needed and there's no reason to cause potential complications by
exposing them.


# 1.216 28-Jun-2021 chs

VOP_BMAP() may be called via ioctl(FIOGETBMAP) on any vnode that applications
can open. change various pseudo-fs *_bmap methods return an error instead of
panic.

Reported-by: syzbot+8289a3eaf2ba60958c87@syzkaller.appspotmail.com


Revision tags: cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base thorpej-i2c-spi-conf-base thorpej-cfargs-base thorpej-futex-base
# 1.215 27-Jun-2020 christos

Introduce genfs_pathconf() and use it for the default case in all filesystems.


# 1.214 23-May-2020 ad

Move proc_lock into the data segment. It was dynamically allocated because
at the time we had mutex_obj_alloc() but not __cacheline_aligned.


# 1.213 16-May-2020 christos

Add ACL support for FFS. From FreeBSD.


# 1.212 29-Apr-2020 thorpej

If the procfs mount is marked as linux-compat, then allow proc lookup
by any LWP ID in the proc, not just the canonical PID.


Revision tags: bouyer-xenpvh-base2
# 1.211 21-Apr-2020 ad

Revert the changes made in February to make cwdinfo use mostly lockless,
which relied on taking extra vnode refs.

Having benchmarked various experimental changes over the past few months it
seems that it's better to avoid vnode refs as much as possible. cwdi_lock
as a RW lock already did that to some extent for getcwd() and will permit
the same for namei() too.


Revision tags: phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base is-mlppp-base phil-wifi-20200406 ad-namecache-base3
# 1.210 24-Feb-2020 ad

branches: 1.210.4;
v_interlock -> vmobjlock


# 1.209 23-Feb-2020 ad

Merge from ad-namecache:

- Have a stab at clustering the members of vnode_t and vnode_impl_t in a
more cache-conscious way. With that done, go back to adjusting v_usecount
with atomics and keep vi_lock directly in vnode_impl_t (saves KVA).

- Allow VOP_LOCK(LK_NONE) for the benefit of VFS_VGET() and VFS_ROOT().
Make sure LK_UPGRADE always comes with LK_NOWAIT.

- Make cwdinfo use mostly lockless.


# 1.208 01-Feb-2020 riastradh

Load struct filedesc::fd_dt with atomic_load_consume.

Exceptions: when fd_refcnt <= 1, or when holding fd_lock.

While here:

- Restore KASSERT(mutex_owned(&fdp->fd_lock)) in fd_unused.
=> This is used only in fd_close and fd_abort, where it holds.
- Move bounds check assertion in fd_putfile to where it matters.
- Store fd_dt with atomic_store_release.
- Move load of fd_dt under lock in knote_fdclose.
- Omit membar_consumer in fdesc_readdir.
=> atomic_load_consume serves the same purpose now.
=> Was needed only on alpha anyway.


Revision tags: ad-namecache-base2 ad-namecache-base1 ad-namecache-base phil-wifi-20191119
# 1.207 29-Aug-2019 hannken

branches: 1.207.2;
Add missing operation VOP_GETPAGES() returning EFAULT.

Without this operation posix_fadvise(..., POSIX_FADV_WILLNEED)
would leave the v_interlock held.

Observed by maxv@


Revision tags: netbsd-9-base phil-wifi-20190609 isaki-audio2-base
# 1.206 30-Mar-2019 christos

branches: 1.206.4;
add a node for the process resource limits.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020
# 1.205 14-Oct-2018 jdolecek

remove M_CANFAIL flag for malloc(9) - it was completely ignored, so had
actually no effect


Revision tags: pgoyette-compat-0930 pgoyette-compat-0906
# 1.204 03-Sep-2018 riastradh

Rename min/max -> uimin/uimax for better honesty.

These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER! Some subsystems have

#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)


Revision tags: pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415
# 1.203 07-Apr-2018 hannken

branches: 1.203.2;
Lock the target cwdi and take an additional reference to the
vnode we are interested in to prevent it from disappearing
before getcwd_common().

Should fix PR kern/53096 (netbsd-8 crash on heavy disk I/O)


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.202 31-Dec-2017 christos

branches: 1.202.2;
Add an environ node


Revision tags: tls-maxphys-base-20171202
# 1.201 01-Dec-2017 christos

Allow procfs_kqfilter, since we allow poll. "go" does it.


# 1.200 08-Nov-2017 christos

fix locking, remove error(1) comments.


# 1.199 08-Nov-2017 christos

use p->p_path, remove unused code.


# 1.198 28-Aug-2017 kamil

Remove the filesystem tracing feature

This is a legacy interface from 4.4BSD, and it was
introduced to overcome shortcomings of ptrace(2) at that time, which are
no longer relevant (performance). Today /proc/#/ctl offers a narrow
subset of ptrace(2) commands and is not applicable for modern
applications use beyond simplistic tracing scenarios.

This removal will simplify kernel internals. Users will still be able to
use all the other /proc files.

This change won't affect other procfs files neither Linux compat
features within mount_procfs(8). /proc/#/ctl isn't available on Linux.

Remove:
- /proc/#/ctl from mount_procfs(8)
- P_FSTRACE note from the documentation of ps(1)
- /proc/#/ctl and filesystem tracing documentation from mount_procfs(8)
- KAUTH_REQ_PROCESS_PROCFS_CTL documentation from kauth(9)
- source code file miscfs/procfs/procfs_ctl.c
- PFSctl and procfs_doctl() from sys/miscfs/procfs/procfs.h
- KAUTH_REQ_PROCESS_PROCFS_CTL from sys/sys/kauth.h
- PSL_FSTRACE (0x00010000) from sys/sys/proc.h
- P_FSTRACE (0x00010000) from sys/sys/sysctl.h

Reduce code complexity after removal of this functionality.

Update TODO.ptrace accordingly: remove two entries about /proc tracing.

Do not keep legacy notes as comments in the headers about removed
PSL_FSTRACE / P_FSTRACE, as this interface had little number of users
(close or equal to zero).

Proposed on tech-kern@.

All filesystem tracing utility users are encouraged to switch to ptrace(2).

Sponsored by <The NetBSD Foundation>


Revision tags: matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base
# 1.197 26-May-2017 riastradh

branches: 1.197.2;
Make VOP_RECLAIM do the last unlock of the vnode.

VOP_RECLAIM naturally has exclusive access to the vnode, so having it
locked on entry is not strictly necessary -- but it means if there
are any final operations that must be done on the vnode, such as
ffs_update, requiring exclusive access to it, we can now kassert that
the vnode is locked in those operations.

We can't just have the caller release the last lock because some file
systems don't use genfs_lock, and require the vnode to remain valid
for VOP_UNLOCK to work, notably unionfs.


Revision tags: prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.196 11-Apr-2017 riastradh

Make VOP_INACTIVE preserve vnode lock on return.

Discussed on tech-kern:
https://mail-index.netbsd.org/tech-kern/2017/04/01/msg021751.html

Ride 7.99.68, a bumpy bus of incremental vfs improvements!


Revision tags: jdolecek-ncq-base
# 1.195 30-Mar-2017 christos

add an auxv node.


Revision tags: pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004 localcount-20160914
# 1.194 20-Aug-2016 hannken

branches: 1.194.2;
Remove now obsolete operation vcache_remove().

Welcome to 7.99.36


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 nick-nhusb-base-20150921 nick-nhusb-base-20150606
# 1.193 20-Apr-2015 riastradh

branches: 1.193.2;
Make VOP_LINK return directory still locked and referenced.

Ride 7.99.10 bump.


Revision tags: nick-nhusb-base-20150406 nick-nhusb-base
# 1.192 05-Sep-2014 matt

branches: 1.192.2;
Try not to use f_data, use f_{vnode,socket,pipe,mqueue,kqueue,ksem} to get
a correctly typed pointer.


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.191 27-Jul-2014 hannken

branches: 1.191.2; 1.191.4; 1.191.8;
Change procfs from hashlist to vcache.
- Key is (type, pid, fd)
- Remove argument "p" from procfs_allocvp(). It is only used
when "type == PFSfd". Lookup the proc with proc_find() when
procfs_loadvnode() needs it.
- Use a vfs_vnode_iterator for procfs_revoke_vnodes().


# 1.190 25-Jul-2014 dholland

Add VOP_FALLOCATE and VOP_FDISCARD to every vnode ops table I can
find.

The filesystem ones all call genfs_eopnotsupp - right now I am only
implementing the plumbing and we can implement fallocate and/or
fdiscard for files later.

The device ones call spec_fallocate (which is also genfs_eopnotsupp)
and spec_fdiscard, which dispatches to the device-level op.

The fifo ones all call vn_fifo_bypass, which also ends up being
EOPNOTSUPP.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base
# 1.189 07-Feb-2014 hannken

branches: 1.189.2;
Change vnode operation lookup to return the resulting vnode *vpp unlocked.
Change cache_lookup() to return an unlocked vnode.

Discussed on tech-kern@

Welcome to 6.99.31


# 1.188 23-Jan-2014 hannken

Change vnode operations create, mknod, mkdir and symlink to return
the resulting vnode *vpp unlocked.

Discussed on tech-kern@

Welcome to 6.99.30


# 1.187 17-Jan-2014 hannken

Change vnode operations create, mknod, mkdir and symlink to keep the
directory node dvp locked on return.

Discussed on tech-kern@

Welcome to 6.99.29


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base
# 1.186 18-Mar-2013 plunky

branches: 1.186.6;
C99 section 6.7.2.3 (Tags) Note 3 states that:

A type specifier of the form

enum identifier

without an enumerator list shall only appear after the type it
specifies is complete.

which means that we cannot pass an "enum vtype" argument to
kauth_access_action() without fully specifying the type first.
Unfortunately there is a complicated include file loop which
makes that difficult, so convert this minimal function into a
macro (and capitalize it).

(ok elad@)


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 1.185 25-Nov-2012 christos

do something reasonable with kernel semaphores.


Revision tags: yamt-pagecache-base6 jmcneill-usbmp-base10
# 1.184 28-May-2012 christos

branches: 1.184.2;
add a task process subdirectory for emul linux


Revision tags: yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 1.183 13-Mar-2012 elad

Replace the remaining KAUTH_GENERIC_ISSUSER authorization calls with
something meaningful. All relevant documentation has been updated or
written.

Most of these changes were brought up in the following messages:

http://mail-index.netbsd.org/tech-kern/2012/01/18/msg012490.html
http://mail-index.netbsd.org/tech-kern/2012/01/19/msg012502.html
http://mail-index.netbsd.org/tech-kern/2012/02/17/msg012728.html

Thanks to christos, manu, njoly, and jmmv for input.

Huge thanks to pgoyette for spinning these changes through some build
cycles and ATF.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.182 04-Sep-2011 jmcneill

branches: 1.182.2; 1.182.6;
PR# kern/45021: Please support /emul/linux/proc/version

Add /proc/version for procfs with -o linux. The version reported depends
on the emulation type of the calling process:

$ cat /proc/version
NetBSD version 5.99.55 (netbsd@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) NetBSD 5.99.55 (GENERIC) #39: Sun Sep 4 09:10:05 EDT 2011

$ /emul/linux/bin/cat /proc/version
Linux version 2.6.18 (linux@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) #0 Wed Mar 3 03:03:03 PST 2010

$ /emul/linux32/bin/cat /proc/version
Linux version 2.6.18 (linux32@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) #0 Wed Mar 3 03:03:03 PST 2010


# 1.181 23-Jun-2011 christos

From Aleksey Cheusov: Don't make it easy for compromised systems to bypass
ASLR protections by providing the mapping addresses of programs to everyone.


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base matt-mips64-premerge-20101231 uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10 rmind-uvmplock-base
# 1.180 01-Jul-2010 rmind

Remove pfind() and pgfind(), fix locking in various broken uses of these.
Rename real routines to proc_find() and pgrp_find(), remove PFIND_* flags
and have consistent behaviour. Provide proc_find_raw() for special cases.
Fix memory leak in sysctl_proc_corename().

COMPAT_LINUX: rework ptrace() locking, minimise differences between
different versions per-arch.

Note: while this change adds some formal cosmetics for COMPAT_DARWIN and
COMPAT_IRIX - locking there is utterly broken (for ages).

Fixes PR/43176.


# 1.179 24-Jun-2010 hannken

Clean up vnode lock operations pass 2:

VOP_UNLOCK(vp, flags) -> VOP_UNLOCK(vp): Remove the unneeded flags argument.

Welcome to 5.99.32.

Discussed on tech-kern.


# 1.178 08-Jun-2010 hannken

Procfs_lookup() does not lookup directory descriptors in the fd/
subdirectory. There is no need for recursive vnode locking here.

Ok: Christos Zoulas <christos@netbsd.org>


Revision tags: uebayasi-xip-base1 yamt-nfs-mp-base9 uebayasi-xip-base
# 1.177 08-Jan-2010 pooka

branches: 1.177.2; 1.177.4;
The VATTR_NULL/VREF/VHOLD/HOLDRELE() macros lost their will to live
years ago when the kernel was modified to not alter ABI based on
DIAGNOSTIC, and now just call the respective function interfaces
(in lowercase). Plenty of mix'n match upper/lowercase has creeped
into the tree since then. Nuke the macros and convert all callsites
to lowercase.

no functional change


Revision tags: matt-premerge-20091211 yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 jym-xensuspend-nbase
# 1.176 03-Jul-2009 elad

Where possible, extract the file-system's access() routine to two internal
functions: the first checking if the operation is possible (regardless of
permissions), the second checking file-system permissions, ACLs, etc.

Mailing list reference:

http://mail-index.netbsd.org/tech-kern/2009/06/21/msg005311.html


# 1.175 23-Jun-2009 elad

Move the implementation of vaccess() to genfs_can_access(), in line with
the other routines of the same spirit.

Adjust file-system code to use it.

Keep vaccess() for KPI compatibility and to keep element of least
surprise. A "diagnostic" message warning that vaccess() is deprecated will
be printed when it's used (obviously, only in DIAGNOSTIC kernels).

No objections on tech-kern@:

http://mail-index.netbsd.org/tech-kern/2009/06/21/msg005310.html


Revision tags: yamt-nfs-mp-base5
# 1.174 24-May-2009 ad

More changes to improve kern_descrip.c.

- Avoid atomics in more places.
- Remove the per-descriptor mutex, and just use filedesc_t::fd_lock.
It was only being used to synchronize close, and in any case we needed
to take fd_lock to free the descriptor slot.
- Optimize certain paths for the <NDFDFILE case.
- Sprinkle more comments and assertions.
- Cache more stuff in filedesc_t.
- Fix numerous minor bugs spotted along the way.
- Restructure how the open files array is maintained, for clarity and so
that we can eliminate the membar_consumer() call in fd_getfile(). This is
mostly syntactic sugar; the main functional change is that fd_nfiles now
lives alongside the open file array.

Some measurements with libmicro:

- simple file syscalls are like close() are between 1 to 10% faster.
- some nice improvements, e.g. poll(1000) which is ~50% faster.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 nick-hppapmap-base2 jym-xensuspend-base nick-hppapmap-base mjf-devfs2-base
# 1.173 17-Dec-2008 cegger

branches: 1.173.2;
kill MALLOC and FREE macros.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 haad-dm-base2 haad-nbase2 ad-audiomp2-base netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 haad-dm-base
# 1.172 05-Sep-2008 skrll

branches: 1.172.2;
PR/39324 kernel diagnostic assertion "l->l_stat != LSZOMB" failed.

Ignore procs with zero or all LSZOMB LWPs. Get a non-LSZOMB LWP to perform
operations against as part of the deal.

procfs really needs to be updated to support multi-threading fully.
Hi Antti!


# 1.171 05-Sep-2008 skrll

ANSIfy


Revision tags: simonb-wapbl-nbase simonb-wapbl-base
# 1.170 02-Jul-2008 rmind

branches: 1.170.2;
Remove proc_representative_lwp(), use a simple LIST_FIRST() instead.
OK by <ad>.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base
# 1.169 28-Apr-2008 martin

branches: 1.169.2; 1.169.4;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-nfs-mp-base
# 1.168 24-Apr-2008 ad

branches: 1.168.2;
Merge proc::p_mutex and proc::p_smutex into a single adaptive mutex, since
we no longer need to guard against access from hardware interrupt handlers.

Additionally, if cloning a process with CLONE_SIGHAND, arrange to have the
child process share the parent's lock so that signal state may be kept in
sync. Partially addresses PR kern/37437.


# 1.167 24-Apr-2008 ad

Network protocol interrupts can now block on locks, so merge the globals
proclist_mutex and proclist_lock into a single adaptive mutex (proc_lock).
Implications:

- Inspecting process state requires thread context, so signals can no longer
be sent from a hardware interrupt handler. Signal activity must be
deferred to a soft interrupt or kthread.

- As the proc state locking is simplified, it's now safe to take exit()
and wait() out from under kernel_lock.

- The system spends less time at IPL_SCHED, and there is less lock activity.


Revision tags: yamt-pf42-baseX yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14
# 1.166 21-Mar-2008 ad

branches: 1.166.2;
Catch up with descriptor handling changes. See kern_descrip.c revision
1.173 for details.


Revision tags: keiichi-mipv6-nbase nick-net80211-sync-base keiichi-mipv6-base bouyer-xeni386-nbase matt-armv6-nbase mjf-devfs-base hpcarm-cleanup-base
# 1.165 23-Jan-2008 elad

branches: 1.165.6;
Tons of process scope changes.

- Add a KAUTH_PROCESS_SCHEDULER action, to handle scheduler related
requests, and add specific requests for set/get scheduler policy and
set/get scheduler parameters.

- Add a KAUTH_PROCESS_KEVENT_FILTER action, to handle kevent(2) related
requests.

- Add a KAUTH_DEVICE_TTY_STI action to handle requests to TIOCSTI.

- Add requests for the KAUTH_PROCESS_CANSEE action, indicating what
process information is being looked at (entry itself, args, env,
open files).

- Add requests for the KAUTH_PROCESS_RLIMIT action indicating set/get.

- Add requests for the KAUTH_PROCESS_CORENAME action indicating set/get.

- Make bsd44 secmodel code handle the newly added rqeuests appropriately.

All of the above make it possible to issue finer-grained kauth(9) calls in
many places, removing some KAUTH_GENERIC_ISSUSER requests.

- Remove the "CAN" from KAUTH_PROCESS_CAN{KTRACE,PROCFS,PTRACE,SIGNAL}.

Discussed with christos@ and yamt@.


Revision tags: bouyer-xeni386-base matt-armv6-base
# 1.164 02-Jan-2008 ad

Merge vmlocking2 to head.


Revision tags: vmlocking2-base3 yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 vmlocking-nbase jmcneill-pm-base reinoud-bufcleanup-base
# 1.163 26-Nov-2007 pooka

branches: 1.163.2; 1.163.6;
Remove the "struct lwp *" argument from all VFS and VOP interfaces.
The general trend is to remove it from all kernel interfaces and
this is a start. In case the calling lwp is desired, curlwp should
be used.

quick consensus on tech-kern


Revision tags: bouyer-xenamd64-base2 bouyer-xenamd64-base
# 1.162 09-Nov-2007 christos

make the last argument of procfs_dir size_t


# 1.161 07-Nov-2007 ad

Merge from vmlocking:

- pool_cache changes.
- Debugger/procfs locking fixes.
- Other minor changes.


Revision tags: jmcneill-base yamt-x86pmap-base4 yamt-x86pmap-base3 vmlocking-base
# 1.160 10-Oct-2007 ad

branches: 1.160.2; 1.160.4;
Merge from vmlocking:

- Split vnode::v_flag into three fields, depending on field locking.
- simple_lock -> kmutex in a few places.
- Fix some simple locking problems.


# 1.159 08-Oct-2007 ad

Merge file descriptor locking, cwdi locking and cross-call changes
from the vmlocking branch.


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base2 yamt-x86pmap-base matt-mips64-base
# 1.158 22-Jul-2007 pooka

branches: 1.158.4; 1.158.6; 1.158.8; 1.158.10;
Don't allow getcwd() on procfs vnodes and provide "/" as the path
instead of the result from getcwd(). The works around locking
panics caused by namei calling VOP_READLINK while holding on to a
directory lock and getcwd() trying to acquire that lock. The real
fix would be to get rid of getcwd() calls within VOPs (not locking
safe), but that's not a viable option in the netbsd-4 timeframe.

Suggestion for workaround from David Holland.


Revision tags: nick-csl-alignment-base mjf-ufs-trans-base
# 1.157 24-May-2007 agc

branches: 1.157.2;
Extend the Linux emulation of /proc to include

/proc/stat
/proc/loadavg and
/proc/<pid>/statm.

These are only present when -o linux is specified as a mount option
to procfs.

Factor out some common code so that it can be used by a number of
functions.

XXX The values returned in the statm emulation need to be verified.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 1.156 04-Apr-2007 rmind

Unfortunately, missed procfs_proc_unlock() in previous.
Pointed out by pooka@


# 1.155 04-Apr-2007 rmind

procfs_readlink: Handle a possible fail of fd_getfile(), also, we
do not need to check for error again.
CID: 4436


# 1.154 09-Mar-2007 ad

branches: 1.154.2; 1.154.4;
- Make the proclist_lock a mutex. The write:read ratio is unfavourable,
and mutexes are cheaper use than RW locks.
- LOCK_ASSERT -> KASSERT in some places.
- Hold proclist_lock/kernel_lock longer in a couple of places.


# 1.153 04-Mar-2007 christos

Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.


# 1.152 03-Mar-2007 salo

Don't prepend rootvnode to the path in non-NULL case for exe links.
It breaks procfs in chroot.

from <christos>, tested by me.


Revision tags: ad-audiomp-base
# 1.151 19-Feb-2007 pooka

When checking for file validity under pid/, do proper proc->lwp
lookup (fsvo proper) instead of fiddling directly with the lwp
list.


# 1.150 18-Feb-2007 pooka

Don't check for validity of p in lookup for root nodes, since it
will always be NULL. Rather, just call pt_valid with NULL directly
and let it decide if we're a linux mount or not.


# 1.149 17-Feb-2007 pavel

Change the process/lwp flags seen by userland via sysctl back to the
P_*/L_* naming convention, and rename the in-kernel flags to avoid
conflict. (P_ -> PK_, L_ -> LW_ ). Add back the (now unused) LSDEAD
constant.

Restores source compatibility with pre-newlock2 tools like ps or top.

Reviewed by Andrew Doran.


# 1.148 16-Feb-2007 pooka

branches: 1.148.2;
In lookup, when checking for procfs process node validity, target the
process we're trying to get information about through procfs, not
the caller of lookup.

fixes 'ls -l /proc/*/file' panic, which would occur when trying to
lookup "file" for a kernel thread, which doesn't have p->p_textvp.


# 1.147 15-Feb-2007 ad

Need to acquire procp->p_mutex for procfs_dir().


# 1.146 11-Feb-2007 ad

Eliminate a couple of reference count and mutex leaks.


Revision tags: post-newlock2-merge
# 1.145 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 1.144 25-Dec-2006 elad

PR/35226: Johann Franz: Problems with permissions in
/usr/pkg/emul/linux/proc .

Okay mlelstv@


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3
# 1.143 09-Dec-2006 chs

a smorgasbord of improvements to vnode locking and path lookup:
- LOCKPARENT is no longer relevant for lookup(), relookup() or VOP_LOOKUP().
these now always return the parent vnode locked. namei() works as before.
lookup() and various other paths no longer acquire vnode locks in the
wrong order via vrele(). fixes PR 32535.
as a nice side effect, path lookup is also up to 25% faster.
- the above allows us to get rid of PDIRUNLOCK.
- also get rid of WANTPARENT (just use LOCKPARENT and unlock it).
- remove an assumption in layer_node_find() that all file systems implement
a recursive VOP_LOCK() (unionfs doesn't).
- require that all file systems supply vfs_vptofh and vfs_fhtovp routines.
fill in eopnotsupp() for file systems that don't support being exported
and remove the checks for NULL. (layerfs calls these without checking.)
- in union_lookup1(), don't change refcounts in the ISDOTDOT case, just
adjust which vnode is locked. fixes PR 33374.
- apply fixes for ufs_rename() from ufs_vnops.c rev. 1.61 to ext2fs_rename().


# 1.142 04-Dec-2006 christos

From Nicolas Joly: restore previous behavior in procfs_validfile_linux, since
readdir passes a NULL lwp.


# 1.141 03-Dec-2006 elad

Move kauth(9) call to where it belongs. Noticed by Nicolas Joly, thanks!


Revision tags: netbsd-4-base
# 1.140 28-Nov-2006 elad

branches: 1.140.2;
Move ktrace, ptrace, systrace, and procfs to use kauth(9).

First, remove process_checkioperm() calls from MD code. Similar checks
using kauth(9) routines (on the process scope, using appropriate action)
are done in the callers.

Add secmodel back-end to handle each subsystem.


# 1.139 25-Nov-2006 skrll

Expose the 'exe' symlink to the process realpath in NetBSD as well. An
example user is gdb.

OK'd by christos.


# 1.138 16-Nov-2006 christos

__unused removal on arguments; approved by core.


# 1.137 29-Oct-2006 christos

add an "emul" file node.


# 1.136 25-Oct-2006 christos

1. fix procfs_validfile{,_linux} to test for NULL pointers properly.
2. make "exe" entry be a symlink to the executable, instead of pointing
directly to the vnode of the executable.
3. factor out commonly used code.


Revision tags: yamt-splraiseipl-base2
# 1.135 12-Oct-2006 christos

- sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386


# 1.134 20-Sep-2006 manu

Emulate Linux's /proc/devices


Revision tags: abandoned-netbsd-4-base yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base rpaulo-netinet-merge-pcb-base
# 1.133 13-Jun-2006 yamt

branches: 1.133.6; 1.133.8;
use KAUTH_PROCESS_CANSEE rather than CURTAIN where appropriate.


# 1.132 13-Jun-2006 yamt

remove unnecessary arguments from kauth_authorize_process.
ie. make it similar to the one found in apple TN.


# 1.131 07-Jun-2006 kardel

merge FreeBSD timecounters from branch simonb-timecounters
- struct timeval time is gone
time.tv_sec -> time_second
- struct timeval mono_time is gone
mono_time.tv_sec -> time_uptime
- access to time via
{get,}{micro,nano,bin}time()
get* versions are fast but less precise
- support NTP nanokernel implementation (NTP API 4)
- further reading:
Timecounter Paper: http://phk.freebsd.dk/pubs/timecounter.pdf
NTP Nanokernel: http://www.eecis.udel.edu/~mills/ntp/html/kern.html


Revision tags: yamt-pdpolicy-base5 simonb-timecounters-base
# 1.130 14-May-2006 elad

branches: 1.130.2;
integrate kauth.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 elad-kernelauth-base yamt-pdpolicy-base yamt-uio_vmspace-base5
# 1.129 02-Feb-2006 christos

branches: 1.129.2; 1.129.4; 1.129.6; 1.129.8;
PR/32692: Matthew Mondor: linux compatibility in /proc/self should point
directly to the directory containing the pid instead of pointing to
/proc/curproc, because some programs rely on calling readlink on /proc/self
to get the pid.


# 1.128 11-Dec-2005 christos

branches: 1.128.2; 1.128.4;
merge ktrace-lwp.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base ktrace-lwp-base
# 1.127 02-Nov-2005 yamt

merge yamt-vop branch. remove following VOPs.

VOP_BLKATOFF
VOP_VALLOC
VOP_BALLOC
VOP_REALLOCBLKS
VOP_VFREE
VOP_TRUNCATE
VOP_UPDATE


Revision tags: yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 1.126 01-Oct-2005 atatat

branches: 1.126.2;
Add "cwd" and "root" symlinks to each process's directory. The cwd
link points to the process's current working directory, and the root
link points to the process's root directory. What else would you
expect?

For directories that are out of reach (caller is in a chroot, target
process is in a different chroot, etc), the links point to "/"
instead.


# 1.125 11-Sep-2005 elad

Implement curtain for procfs.


# 1.124 30-Aug-2005 xtraeme

Remove __P()


# 1.123 29-May-2005 christos

branches: 1.123.2;
- sprinkle const
- avoid shadowed variables.


Revision tags: kent-audio2-base
# 1.122 02-Apr-2005 christos

PR/29782: Martin Husemann: procfs can not unmount when some process has its
current directory in curproc. Fix from Pedro Martelletto:
We cannot call vgone() from procfs_inactive() if we are coming from
vclean(). that's what's probably causing the deadlock.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 yamt-km-base4 yamt-km-base3 netbsd-3-base
# 1.121 26-Feb-2005 perry

nuke trailing whitespace


Revision tags: yamt-km-base2 yamt-km-base kent-audio1-beforemerge kent-audio1-base
# 1.120 04-Oct-2004 yamt

branches: 1.120.4; 1.120.6;
procfs_readdir:
- return correct cookie when buffer size is small.
- simplify logic.


# 1.119 04-Oct-2004 yamt

procfs_readdir: remove a redundant assignment.


# 1.118 02-Oct-2004 yamt

procfs_getattr: correct size of /proc/self.


# 1.117 01-Oct-2004 yamt

procfs_readdir:
- fix a locking problem, using proclist_foreach_call. PR/27098.
- correct snprintf size argument.


# 1.116 01-Oct-2004 yamt

procfs_readdir: fix an offset handling bug after addition of /proc/self.


# 1.115 01-Oct-2004 yamt

procfs_readdir: use a list macro.


# 1.114 20-Sep-2004 jdolecek

add 'mounts' file for -o linux, which lists all currently mounted
filesystems; Linux glibc statvfs() uses this to get some of mount flags,
and this file is also useful as /emul/linux/etc/mtab (via symlink)


# 1.113 29-Apr-2004 jrf

Removed remaining caddr_t casts we do not need in miscfs. Recompiled
kernel and ran for a day or so. There are still some caddr_t types in
the arguments of some calls, I will do those separately (later) as
they touch a lot more of the system.
Approved by christos@NetBSD.org.


# 1.112 22-Apr-2004 itojun

sprintf -> snprintf


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.111 15-Feb-2004 jdolecek

unlock the descriptor table simple lock after fd_getfile() call in
procfs_readdir()
fixes procfs locking problems reported on current-users@, problem place
found by enami tsugutomo


# 1.110 30-Oct-2003 simonb

Remove some assigned-to but otherwise unused variables.


# 1.109 27-Sep-2003 darcy

Changes as discussed with itojun on tech-kern. I have modified the enums
to have KFS or PFS differentiators. Further I have wrapped the enum in
procfs in "#ifdef _KERNEL" as it is done in kernfs.

To see the discussion go to http://mail-index.NetBSD.org/tech-kern/2003/09/
and look for "Mismatched enums in include files" in the list.


# 1.108 07-Sep-2003 itojun

remove meaningless line (variable overwritten 2 lines below)


# 1.107 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.


# 1.106 29-Jun-2003 fvdl

branches: 1.106.2;
Back out the lwp/ktrace changes. They contained a lot of colateral damage,
and need to be examined and discussed more.


# 1.105 29-Jun-2003 thorpej

Undo part of the ktrace/lwp changes. In particular:
* Remove the "lwp *" argument that was added to vget(). Turns out
that nothing actually used it!
* Remove the "lwp *" arguments that were added to VFS_ROOT(), VFS_VGET(),
and VFS_FHTOVP(); all they did was pass it to vget() (which, as noted
above, didn't use it).
* Remove all of the "lwp *" arguments to internal functions that were added
just to appease the above.


# 1.104 28-Jun-2003 darrenr

Pass lwp pointers throughtout the kernel, as required, so that the lwpid can
be inserted into ktrace records. The general change has been to replace
"struct proc *" with "struct lwp *" in various function prototypes, pass
the lwp through and use l_proc to get the process pointer when needed.

Bump the kernel rev up to 1.6V


# 1.103 28-May-2003 christos

Add /proc/<pid>/stat for linux compat. j2sdk1.4.2 depends on it.


# 1.102 18-Apr-2003 christos

Make symlinks for directories that point to the actual directory.
Make symlinks to [kqueue] and [misc] for kqueue and misc fds.


# 1.101 17-Apr-2003 jdolecek

do not show nodes corresponding to directory descriptors for process
in fd/ subdirectory, nor allow lookup/open for the nodes
this fixes PR kern/21187 for good, and also avoids interesting directory
locking issues


# 1.100 17-Apr-2003 jdolecek

procfs_readdir(): in Pfd case, only show descriptors of types we want
how to represent (vnodes, fifo, pipes); also use fd_getfile() et al

this avoids annoying EOPNOTSUPP error messages from ls -F and such


# 1.99 17-Apr-2003 jdolecek

procfs_lookup(): use fd_getfile() et al in Pfd case


# 1.98 17-Apr-2003 jdolecek

use fd_getfile() in procfs_getfp(), and FILE_USE()/FILE_UNUSE() the
returned file descriptor pointer appropriately


# 1.97 17-Apr-2003 jdolecek

make some local arrays/variables static + const


# 1.96 10-Apr-2003 jdolecek

use former genfs_eopnotsupp_rele() as genfs_eopnotsupp(), so that vnodes
are vput()/vrele()d as necessary - some filesystems did use the wrong
one for some ops, and it's just safer to not take the chance

based on suggestion by Bill Studenmund


# 1.95 05-Apr-2003 dsl

Remove pointless check against PID_MAX. Let pfind() do the validation.
(The new pid allocation code may decide to allocate pids above PID_MAX.)


# 1.94 25-Feb-2003 jrf

This addresses PR kerm/19989. Thanks to hamajima@nagoya.ydc.co.jp for submitting this patch which enables /proc/uptime for linux emul. Patch reviewed by atatat@netbsd.org and tron@netbsd.org, approved by tron@netbsd.org.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 1.93 04-Jan-2003 martin

Cast off_t expression to long long to match format even on 64 bit
plattforms.

Shouldn't we introduce a PRIoff_t macro to create such format strings?


# 1.92 03-Jan-2003 christos

add LK_CANRECURSE in the locking of /dev/<pid>/fd/<n> and remove the curproc
kludge. Thanks to fvdl.


# 1.91 03-Jan-2003 christos

Implement /proc/<pid>/fd/<n>. This is work in progress. Questionable things:
- Is it ok to convert DTYPE_PIPE to VFIFO and DTYPE_SOCKET to VSOCK?
- XXX: Avoid locking issue in ls -Rl /proc by avoiding curproc
- Does I/O to pipes work?
- XXX: Are there security implications?


Revision tags: fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge gehenna-devsw-base kqueue-base
# 1.90 03-Aug-2002 simonb

Just use the "time" variable in the *_getattr functions instead of a call
to (the potentially expensive) microtime().


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.89 09-May-2002 thorpej

branches: 1.89.2;
Move code shared by procfs and the kernel proper out of procfs and
into the kernel proper (renaming functions from procfs_* to process_*).


Revision tags: eeh-devprop-base newlock-base ifpoll-base
# 1.88 12-Jan-2002 christos

Don't hide the real return code with EPERM.


# 1.87 06-Dec-2001 chs

add a VOP_PUTPAGES method for all the filesystems that don't have pages,
just unlock the interlock.


# 1.86 05-Dec-2001 thorpej

* Allow machine-dependent code to specify hooks for ptrace(2)
(__HAVE_PTRACE_MACHDEP) and procfs (__HAVE_PROCFS_MACHDEP).
These changes will allow platforms like x86 (XMM) and PowerPC
(AltiVec) to export extended register sets in a sane manner.

* Use __HAVE_PTRACE_MACHDEP to export x86 XMM registers (standard
FP + SSE/SSE2) using PT_{GET,SET}XMMREGS (in the machdep
ptrace request space).
* Use __HAVE_PROCFS_MACHDEP to export x86 XMM registers via
/proc/N/xmmregs in procfs.


Revision tags: thorpej-mips-cache-base
# 1.85 10-Nov-2001 lukem

add RCSIDs


# 1.84 06-Nov-2001 simonb

Remove some variables that are set but never used.


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base
# 1.83 31-Aug-2001 chs

branches: 1.83.2; 1.83.4;
map files are zero-length.


# 1.82 03-Jun-2001 chs

branches: 1.82.2;
procfs_bmap() should never be called, make it a "bad op".
let procfs_mmap() use the default error method.


Revision tags: thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 1.81 14-Apr-2001 kleink

In procfs_readdir(), give /proc/# directories DT_DIR (rather than DT_REG).


# 1.80 30-Mar-2001 fvdl

Bump va_blocksize for the map files some more, so that programs with
quite a few mappings have a chance of being handled correctly if
st_blksize is looked at.


# 1.79 29-Mar-2001 fvdl

For -o linux mounts, add some code to emulate /proc/#/maps.
Needs NAMECACHE_ENTER_REVERSE to include filenames.


# 1.78 21-Feb-2001 jdolecek

branches: 1.78.2;
make some more constant arrays 'const'


# 1.77 22-Jan-2001 jdolecek

make filesystem vnodeop, specop, fifoop and vnodeopv_* arrays const


# 1.76 17-Jan-2001 fvdl

Add a few linux-style files, only enabled when -o linux is specified
for the mount. Currently these are /proc/cpuinfo and /proc/meminfo.
The former only does something on i386 right now.


# 1.75 24-Nov-2000 chs

remove dead code and other misc cleanup.


# 1.74 09-Aug-2000 tv

Only show the "exe" entry to Linux processes, suggested by christos.
Since there are actually three struct emul's for linux, use the e_name
field to determine eligibility with strcmp().


# 1.73 09-Aug-2000 tv

Some versions of Linux libc look for /proc/.../exe instead of /proc/../file.
Add an entry for "exe" that is the same as "file", provided only if
COMPAT_LINUX is set.


# 1.72 03-Aug-2000 thorpej

MALLOC()/FREE() are not to be used for variable sized allocations.


# 1.71 28-Jun-2000 mrg

<vm/vm.h> -> <uvm/uvm_extern.h>


Revision tags: netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 1.70 30-Mar-2000 simonb

branches: 1.70.4;
Delete duplicate declaration of atopid().


Revision tags: chs-ubc2-newbase wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base fvdl-softdep-base
# 1.69 02-Sep-1999 thorpej

branches: 1.69.2; 1.69.8;
Make /proc/self a symlink to /proc/curproc. I've observed Linux programs
that expect /proc/self/cmdline to exist.


# 1.68 25-Aug-1999 sommerfeld

Change variable used for directory offset from "int" to "off_t".
Overkill, but avoids a host of truncation problems.


# 1.67 24-Aug-1999 sommerfeld

Fix PR8270:

Problem turned out to be due to improper handling of reads beyond EOF:
they should just return without error with the uio unchanged, and the
caller will recognize this as a zero-byte return (EOF).

The previous fix to protect directory reads against bogus uio_offset
values returned EINVAL, which broke mount -o union, which only
union'ed in the lower directory if the upper directory cleanly
returned EOF.

While we're here, protect kernfs as well.


# 1.66 14-Aug-1999 christos

protect against large uio_offset


# 1.65 03-Aug-1999 wrstuden

Add support for fcntl(2) to generate VOP_FCNTL calls. Any fcntl
call with F_FSCTL set and F_SETFL calls generate calls to a new
fileop fo_fcntl. Add genfs_fcntl() and soo_fcntl() which return 0
for F_SETFL and EOPNOTSUPP otherwise. Have all leaf filesystems
use genfs_fcntl().

Reviewed by: thorpej
Tested by: wrstuden


Revision tags: chs-ubc2-base
# 1.64 25-Jul-1999 thorpej

Add calls to lock the proclist as appropriate.


# 1.63 14-Jul-1999 thorpej

Fix a paste-o in procfs_lookup() introduced with the vnode locking changes.
Fixes PR #7961, Mario Kemper <magick@bundy.lip.owl.de>.


# 1.62 08-Jul-1999 wrstuden

Bump osrelease to 1.4E. Add layerfs files, remove null_subr.c.

Update coda to new struct lock in struct vnode.

make fdescfs, kernfs, portalfs, and procfs actually lock their vnodes.
It's not that hard.

Make unionfs set v_vnlock = NULL so any overlayed fs will call its
VOP_LOCK.


Revision tags: kame_141_19991130 netbsd-1-4-PATCH001 kame_14_19990705 kame_14_19990628 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.61 12-Mar-1999 christos

branches: 1.61.2; 1.61.4;
PR/7143: Jaromir Docelek: Add procfs/cmdline from Linux emulation


# 1.60 25-Jan-1999 msaitoh

Add /proc/#/map. From FreeBSD.


Revision tags: kenh-if-detach-base chs-ubc-base
# 1.59 08-Sep-1998 thorpej

- Use proclists[], rather than checking allproc and zombproc explicitly.
- Add some comments about locking.


# 1.58 13-Aug-1998 kleink

Per POSIX, fail with EINVAL if advisory locking is attempted on a file type
that doesn't support it, rather than using a homegrown EBADF or EOPNOTSUPP.


# 1.57 10-Aug-1998 matthias

create miscfs/genfs/genfs_vnops.c:genfs_enoioctl and make all the other
filesystems use it instead of a private version.


# 1.56 09-Aug-1998 perry

bzero->memset, bcopy->memcpy, bcmp->memcmp


# 1.55 03-Aug-1998 kleink

Recognize _PC_SYNC_IO.


Revision tags: eeh-paddr_t-base
# 1.54 21-Apr-1998 fvdl

procfs_readdir: in case of error, check if cookies actually have
been allocated before freeing them. From Wolfgang Solfrank.


# 1.53 01-Mar-1998 fvdl

Merge with Lite2 + local changes


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base marc-pcmcia-base
# 1.52 10-Oct-1997 fvdl

Bump last argument to VOP_READDIR to off_t (from u_long).


Revision tags: thorpej-signal-base
# 1.51 27-Aug-1997 thorpej

Fix a reversed argument which caused procfs_checkioperm() to always return
"OK". Add a few comments to avoid further confusion.


# 1.50 12-Aug-1997 thorpej

Fix the procfs hole described on current-users, similar to a fix for
FreeBSD by Sean Eric Fagan, but a bit different. This makes the checks
in the same places as sef's FreeBSD patch, but does not hardcode the
"kmem" group into the kernel, and also does a check identical to the
(3) and (4) checks in the NetBSD ptrace(2):

(1) it's not owned by you, or is set-id on exec (unless
you're root), or

(2) it's init, which controls the security level of the
entire system, and the system was not compiled with
permanently insecure mode turned on.


Revision tags: marc-pcmcia-bp
# 1.49 08-May-1997 mycroft

branches: 1.49.4;
Pass the vnode type to vaccess(), and use it when checking VEXEC. Make sure
that the mode bits passed to vaccess() and returned by foo_getattr() contain
only permission bits.


# 1.48 05-May-1997 mycroft

Need stat.h.


# 1.47 05-May-1997 mycroft

Eliminate bogus uses of V{READ,WRITE,EXEC}. Use S_I[RWX]{USR,GRP,OTH} where
appropriate.


# 1.46 28-Apr-1997 mycroft

Minor code cleanup.


Revision tags: is-newarp-before-merge is-newarp-base
# 1.45 25-Oct-1996 cgd

define path name string variables that we should not (and, thankfully, do
not) modify as 'const char *' rather 'char *'.


# 1.44 13-Oct-1996 christos

backout previous kprintf changes


# 1.43 10-Oct-1996 christos

printf -> kprintf, sprintf -> ksprintf


# 1.42 07-Sep-1996 mycroft

Implement poll(2).


# 1.41 01-Sep-1996 mycroft

Add a set of generic file system operations that most file systems use.
Also, fix some time stamp bogosities.


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 1.40 16-Mar-1996 christos

Fix printf format follies.


# 1.39 13-Feb-1996 mycroft

GC *_nullop(). Minor nits.


# 1.38 12-Feb-1996 christos

close PR/2063: procfs_rw prototyped twice with different prototypes


# 1.37 09-Feb-1996 christos

miscfs prototype changes


# 1.36 09-Feb-1996 mycroft

Fix vop_link, vop_symlink, and vop_remove semantics in several ways:
* Change the argument names to vop_link so they actually make sense.
* Implement vop_link and vop_symlink for all file systems, so they do proper
cleanup.
* Require the file system to decide whether or not linking and unlinking of
directories is allowed, and disable it for all current file systems.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.35 09-Oct-1995 mycroft

Use the index number as the cookie, rather than multiplying by UIO_MX.


# 1.34 09-Oct-1995 mycroft

Add support for cookies, mostly from Greg Hudson.


# 1.33 15-Apr-1995 cgd

fix timeval vs. timespec warnings


# 1.32 03-Feb-1995 mycroft

Return EROFS rather than ENOENT in many cases. Also some cosmetic cleanup.


# 1.31 27-Dec-1994 mycroft

Format police.


# 1.30 24-Dec-1994 ws

Implement and use a common access checking routine


# 1.29 14-Dec-1994 mycroft

Remove a_fp.


# 1.28 14-Nov-1994 christos

fixed struct comment


# 1.27 30-Oct-1994 cgd

be more careful with types, also pull in headers where necessary.


# 1.26 20-Oct-1994 cgd

update for new syscall args description mechanism


# 1.25 30-Aug-1994 mycroft

Convert process, file, and namei lists and hash tables to use queue.h.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.24 29-Jun-1994 cgd

New RCS ID's, take two. they're more aesthecially pleasant, and use 'NetBSD'


# 1.23 16-Jun-1994 mycroft

Remove an unneeded test.


# 1.22 15-Jun-1994 mycroft

Minor update from JSP after merging my changes.


# 1.21 08-Jun-1994 mycroft

Update to 4.4-Lite fs code, with local changes.


# 1.20 05-May-1994 cgd

lots of changes: prototype migration, move lots of variables, definitions,
and structure elements around. kill some unnecessary type and macro
definitions. standardize clock handling. More changes than you'd want.


# 1.19 15-Apr-1994 cgd

forgot these...


# 1.18 12-Apr-1994 cgd

be a bit smarter about determining if files shouldn't be seen by the user.
Also, DON'T allow a lookup to succeed on a file that's not visible!


# 1.17 15-Feb-1994 mycroft

Undo last change; executables is `file', not `a.out'.


# 1.16 14-Feb-1994 ws

Rename file -> a.out


# 1.15 14-Feb-1994 ws

Don't try to show a file for a process if there is none


# 1.14 28-Jan-1994 cgd

make a fpregs file.


# 1.13 20-Jan-1994 ws

Make procfs really work for debugging.
Implement not & notepg files in procfs.


# 1.12 09-Jan-1994 ws

Bug fixes and enhancements:
Make NFS serving work (BUT DON'T USE "attach" TO /proc/*/ctl FOR NOW!!!)
Make `curproc' a symbolic link
Add `.' and `..' entries to the directories.
Return better guesses on the size of the files.


# 1.11 05-Jan-1994 cgd

return size of 'reg' from getattr()


# 1.10 05-Jan-1994 cgd

make it compile (cleanly) for us


# 1.9 05-Jan-1994 cgd

add new procfs code, from Jan-Simon Pendry, jsp@sequent.com.
This is pretty-much "virgin", so that diffs can be done later.


# 1.8 18-Dec-1993 mycroft

Canonicalize all #includes.


Revision tags: magnum-base
# 1.7 16-Sep-1993 cgd

kill volatile warning.


# 1.6 07-Sep-1993 ws

branches: 1.6.2;
Changes to VFS readdir semantics
NFS changes for better cookie support
ISOFS changes for better Rockridge support and support for generation numbers


# 1.5 26-Aug-1993 pk

Implement setattr: mode for process entries; mode + uid/gid for the
PROCFS root directory.
Fixed omission in pfs_root() which came to light as a result of the above:
hold on to vnode for root dir.


# 1.4 25-Aug-1993 pk

Fixed improperly initialized nfsnode in pfs_lookup()


# 1.3 24-Aug-1993 pk

copyright update.


# 1.2 24-Aug-1993 pk

Rcs Id added.


# 1.1 24-Aug-1993 pk

branches: 1.1.1;
Initial version of a proc filesystem.


# 1.217 29-Jun-2021 dholland

- Add a new vnode op: VOP_PARSEPATH.
- Move namei_getcomponent to genfs_vnops.c and call it genfs_parsepath.
- Add a parsepath entry to every vnode ops table.

VOP_PARSEPATH takes a directory vnode to be searched and a complete
following path and chooses how much of that path to consume. To begin
with, all parsepath calls are genfs_parsepath, which locates the first
'/' as always.

Note that the call doesn't take the whole struct componentname, only
the string. The other bits of struct componentname should not be
needed and there's no reason to cause potential complications by
exposing them.


# 1.216 28-Jun-2021 chs

VOP_BMAP() may be called via ioctl(FIOGETBMAP) on any vnode that applications
can open. change various pseudo-fs *_bmap methods return an error instead of
panic.

Reported-by: syzbot+8289a3eaf2ba60958c87@syzkaller.appspotmail.com


Revision tags: cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base thorpej-i2c-spi-conf-base thorpej-cfargs-base thorpej-futex-base
# 1.215 27-Jun-2020 christos

Introduce genfs_pathconf() and use it for the default case in all filesystems.


# 1.214 23-May-2020 ad

Move proc_lock into the data segment. It was dynamically allocated because
at the time we had mutex_obj_alloc() but not __cacheline_aligned.


# 1.213 16-May-2020 christos

Add ACL support for FFS. From FreeBSD.


# 1.212 29-Apr-2020 thorpej

If the procfs mount is marked as linux-compat, then allow proc lookup
by any LWP ID in the proc, not just the canonical PID.


Revision tags: bouyer-xenpvh-base2
# 1.211 21-Apr-2020 ad

Revert the changes made in February to make cwdinfo use mostly lockless,
which relied on taking extra vnode refs.

Having benchmarked various experimental changes over the past few months it
seems that it's better to avoid vnode refs as much as possible. cwdi_lock
as a RW lock already did that to some extent for getcwd() and will permit
the same for namei() too.


Revision tags: phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base is-mlppp-base phil-wifi-20200406 ad-namecache-base3
# 1.210 24-Feb-2020 ad

branches: 1.210.4;
v_interlock -> vmobjlock


# 1.209 23-Feb-2020 ad

Merge from ad-namecache:

- Have a stab at clustering the members of vnode_t and vnode_impl_t in a
more cache-conscious way. With that done, go back to adjusting v_usecount
with atomics and keep vi_lock directly in vnode_impl_t (saves KVA).

- Allow VOP_LOCK(LK_NONE) for the benefit of VFS_VGET() and VFS_ROOT().
Make sure LK_UPGRADE always comes with LK_NOWAIT.

- Make cwdinfo use mostly lockless.


# 1.208 01-Feb-2020 riastradh

Load struct filedesc::fd_dt with atomic_load_consume.

Exceptions: when fd_refcnt <= 1, or when holding fd_lock.

While here:

- Restore KASSERT(mutex_owned(&fdp->fd_lock)) in fd_unused.
=> This is used only in fd_close and fd_abort, where it holds.
- Move bounds check assertion in fd_putfile to where it matters.
- Store fd_dt with atomic_store_release.
- Move load of fd_dt under lock in knote_fdclose.
- Omit membar_consumer in fdesc_readdir.
=> atomic_load_consume serves the same purpose now.
=> Was needed only on alpha anyway.


Revision tags: ad-namecache-base2 ad-namecache-base1 ad-namecache-base phil-wifi-20191119
# 1.207 29-Aug-2019 hannken

branches: 1.207.2;
Add missing operation VOP_GETPAGES() returning EFAULT.

Without this operation posix_fadvise(..., POSIX_FADV_WILLNEED)
would leave the v_interlock held.

Observed by maxv@


Revision tags: netbsd-9-base phil-wifi-20190609 isaki-audio2-base
# 1.206 30-Mar-2019 christos

branches: 1.206.4;
add a node for the process resource limits.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020
# 1.205 14-Oct-2018 jdolecek

remove M_CANFAIL flag for malloc(9) - it was completely ignored, so had
actually no effect


Revision tags: pgoyette-compat-0930 pgoyette-compat-0906
# 1.204 03-Sep-2018 riastradh

Rename min/max -> uimin/uimax for better honesty.

These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER! Some subsystems have

#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)


Revision tags: pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415
# 1.203 07-Apr-2018 hannken

branches: 1.203.2;
Lock the target cwdi and take an additional reference to the
vnode we are interested in to prevent it from disappearing
before getcwd_common().

Should fix PR kern/53096 (netbsd-8 crash on heavy disk I/O)


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.202 31-Dec-2017 christos

branches: 1.202.2;
Add an environ node


Revision tags: tls-maxphys-base-20171202
# 1.201 01-Dec-2017 christos

Allow procfs_kqfilter, since we allow poll. "go" does it.


# 1.200 08-Nov-2017 christos

fix locking, remove error(1) comments.


# 1.199 08-Nov-2017 christos

use p->p_path, remove unused code.


# 1.198 28-Aug-2017 kamil

Remove the filesystem tracing feature

This is a legacy interface from 4.4BSD, and it was
introduced to overcome shortcomings of ptrace(2) at that time, which are
no longer relevant (performance). Today /proc/#/ctl offers a narrow
subset of ptrace(2) commands and is not applicable for modern
applications use beyond simplistic tracing scenarios.

This removal will simplify kernel internals. Users will still be able to
use all the other /proc files.

This change won't affect other procfs files neither Linux compat
features within mount_procfs(8). /proc/#/ctl isn't available on Linux.

Remove:
- /proc/#/ctl from mount_procfs(8)
- P_FSTRACE note from the documentation of ps(1)
- /proc/#/ctl and filesystem tracing documentation from mount_procfs(8)
- KAUTH_REQ_PROCESS_PROCFS_CTL documentation from kauth(9)
- source code file miscfs/procfs/procfs_ctl.c
- PFSctl and procfs_doctl() from sys/miscfs/procfs/procfs.h
- KAUTH_REQ_PROCESS_PROCFS_CTL from sys/sys/kauth.h
- PSL_FSTRACE (0x00010000) from sys/sys/proc.h
- P_FSTRACE (0x00010000) from sys/sys/sysctl.h

Reduce code complexity after removal of this functionality.

Update TODO.ptrace accordingly: remove two entries about /proc tracing.

Do not keep legacy notes as comments in the headers about removed
PSL_FSTRACE / P_FSTRACE, as this interface had little number of users
(close or equal to zero).

Proposed on tech-kern@.

All filesystem tracing utility users are encouraged to switch to ptrace(2).

Sponsored by <The NetBSD Foundation>


Revision tags: matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base
# 1.197 26-May-2017 riastradh

branches: 1.197.2;
Make VOP_RECLAIM do the last unlock of the vnode.

VOP_RECLAIM naturally has exclusive access to the vnode, so having it
locked on entry is not strictly necessary -- but it means if there
are any final operations that must be done on the vnode, such as
ffs_update, requiring exclusive access to it, we can now kassert that
the vnode is locked in those operations.

We can't just have the caller release the last lock because some file
systems don't use genfs_lock, and require the vnode to remain valid
for VOP_UNLOCK to work, notably unionfs.


Revision tags: prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.196 11-Apr-2017 riastradh

Make VOP_INACTIVE preserve vnode lock on return.

Discussed on tech-kern:
https://mail-index.netbsd.org/tech-kern/2017/04/01/msg021751.html

Ride 7.99.68, a bumpy bus of incremental vfs improvements!


Revision tags: jdolecek-ncq-base
# 1.195 30-Mar-2017 christos

add an auxv node.


Revision tags: pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004 localcount-20160914
# 1.194 20-Aug-2016 hannken

branches: 1.194.2;
Remove now obsolete operation vcache_remove().

Welcome to 7.99.36


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 nick-nhusb-base-20150921 nick-nhusb-base-20150606
# 1.193 20-Apr-2015 riastradh

branches: 1.193.2;
Make VOP_LINK return directory still locked and referenced.

Ride 7.99.10 bump.


Revision tags: nick-nhusb-base-20150406 nick-nhusb-base
# 1.192 05-Sep-2014 matt

branches: 1.192.2;
Try not to use f_data, use f_{vnode,socket,pipe,mqueue,kqueue,ksem} to get
a correctly typed pointer.


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.191 27-Jul-2014 hannken

branches: 1.191.2; 1.191.4; 1.191.8;
Change procfs from hashlist to vcache.
- Key is (type, pid, fd)
- Remove argument "p" from procfs_allocvp(). It is only used
when "type == PFSfd". Lookup the proc with proc_find() when
procfs_loadvnode() needs it.
- Use a vfs_vnode_iterator for procfs_revoke_vnodes().


# 1.190 25-Jul-2014 dholland

Add VOP_FALLOCATE and VOP_FDISCARD to every vnode ops table I can
find.

The filesystem ones all call genfs_eopnotsupp - right now I am only
implementing the plumbing and we can implement fallocate and/or
fdiscard for files later.

The device ones call spec_fallocate (which is also genfs_eopnotsupp)
and spec_fdiscard, which dispatches to the device-level op.

The fifo ones all call vn_fifo_bypass, which also ends up being
EOPNOTSUPP.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base
# 1.189 07-Feb-2014 hannken

branches: 1.189.2;
Change vnode operation lookup to return the resulting vnode *vpp unlocked.
Change cache_lookup() to return an unlocked vnode.

Discussed on tech-kern@

Welcome to 6.99.31


# 1.188 23-Jan-2014 hannken

Change vnode operations create, mknod, mkdir and symlink to return
the resulting vnode *vpp unlocked.

Discussed on tech-kern@

Welcome to 6.99.30


# 1.187 17-Jan-2014 hannken

Change vnode operations create, mknod, mkdir and symlink to keep the
directory node dvp locked on return.

Discussed on tech-kern@

Welcome to 6.99.29


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base
# 1.186 18-Mar-2013 plunky

branches: 1.186.6;
C99 section 6.7.2.3 (Tags) Note 3 states that:

A type specifier of the form

enum identifier

without an enumerator list shall only appear after the type it
specifies is complete.

which means that we cannot pass an "enum vtype" argument to
kauth_access_action() without fully specifying the type first.
Unfortunately there is a complicated include file loop which
makes that difficult, so convert this minimal function into a
macro (and capitalize it).

(ok elad@)


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 1.185 25-Nov-2012 christos

do something reasonable with kernel semaphores.


Revision tags: yamt-pagecache-base6 jmcneill-usbmp-base10
# 1.184 28-May-2012 christos

branches: 1.184.2;
add a task process subdirectory for emul linux


Revision tags: yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 1.183 13-Mar-2012 elad

Replace the remaining KAUTH_GENERIC_ISSUSER authorization calls with
something meaningful. All relevant documentation has been updated or
written.

Most of these changes were brought up in the following messages:

http://mail-index.netbsd.org/tech-kern/2012/01/18/msg012490.html
http://mail-index.netbsd.org/tech-kern/2012/01/19/msg012502.html
http://mail-index.netbsd.org/tech-kern/2012/02/17/msg012728.html

Thanks to christos, manu, njoly, and jmmv for input.

Huge thanks to pgoyette for spinning these changes through some build
cycles and ATF.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.182 04-Sep-2011 jmcneill

branches: 1.182.2; 1.182.6;
PR# kern/45021: Please support /emul/linux/proc/version

Add /proc/version for procfs with -o linux. The version reported depends
on the emulation type of the calling process:

$ cat /proc/version
NetBSD version 5.99.55 (netbsd@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) NetBSD 5.99.55 (GENERIC) #39: Sun Sep 4 09:10:05 EDT 2011

$ /emul/linux/bin/cat /proc/version
Linux version 2.6.18 (linux@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) #0 Wed Mar 3 03:03:03 PST 2010

$ /emul/linux32/bin/cat /proc/version
Linux version 2.6.18 (linux32@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) #0 Wed Mar 3 03:03:03 PST 2010


# 1.181 23-Jun-2011 christos

From Aleksey Cheusov: Don't make it easy for compromised systems to bypass
ASLR protections by providing the mapping addresses of programs to everyone.


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base matt-mips64-premerge-20101231 uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10 rmind-uvmplock-base
# 1.180 01-Jul-2010 rmind

Remove pfind() and pgfind(), fix locking in various broken uses of these.
Rename real routines to proc_find() and pgrp_find(), remove PFIND_* flags
and have consistent behaviour. Provide proc_find_raw() for special cases.
Fix memory leak in sysctl_proc_corename().

COMPAT_LINUX: rework ptrace() locking, minimise differences between
different versions per-arch.

Note: while this change adds some formal cosmetics for COMPAT_DARWIN and
COMPAT_IRIX - locking there is utterly broken (for ages).

Fixes PR/43176.


# 1.179 24-Jun-2010 hannken

Clean up vnode lock operations pass 2:

VOP_UNLOCK(vp, flags) -> VOP_UNLOCK(vp): Remove the unneeded flags argument.

Welcome to 5.99.32.

Discussed on tech-kern.


# 1.178 08-Jun-2010 hannken

Procfs_lookup() does not lookup directory descriptors in the fd/
subdirectory. There is no need for recursive vnode locking here.

Ok: Christos Zoulas <christos@netbsd.org>


Revision tags: uebayasi-xip-base1 yamt-nfs-mp-base9 uebayasi-xip-base
# 1.177 08-Jan-2010 pooka

branches: 1.177.2; 1.177.4;
The VATTR_NULL/VREF/VHOLD/HOLDRELE() macros lost their will to live
years ago when the kernel was modified to not alter ABI based on
DIAGNOSTIC, and now just call the respective function interfaces
(in lowercase). Plenty of mix'n match upper/lowercase has creeped
into the tree since then. Nuke the macros and convert all callsites
to lowercase.

no functional change


Revision tags: matt-premerge-20091211 yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 jym-xensuspend-nbase
# 1.176 03-Jul-2009 elad

Where possible, extract the file-system's access() routine to two internal
functions: the first checking if the operation is possible (regardless of
permissions), the second checking file-system permissions, ACLs, etc.

Mailing list reference:

http://mail-index.netbsd.org/tech-kern/2009/06/21/msg005311.html


# 1.175 23-Jun-2009 elad

Move the implementation of vaccess() to genfs_can_access(), in line with
the other routines of the same spirit.

Adjust file-system code to use it.

Keep vaccess() for KPI compatibility and to keep element of least
surprise. A "diagnostic" message warning that vaccess() is deprecated will
be printed when it's used (obviously, only in DIAGNOSTIC kernels).

No objections on tech-kern@:

http://mail-index.netbsd.org/tech-kern/2009/06/21/msg005310.html


Revision tags: yamt-nfs-mp-base5
# 1.174 24-May-2009 ad

More changes to improve kern_descrip.c.

- Avoid atomics in more places.
- Remove the per-descriptor mutex, and just use filedesc_t::fd_lock.
It was only being used to synchronize close, and in any case we needed
to take fd_lock to free the descriptor slot.
- Optimize certain paths for the <NDFDFILE case.
- Sprinkle more comments and assertions.
- Cache more stuff in filedesc_t.
- Fix numerous minor bugs spotted along the way.
- Restructure how the open files array is maintained, for clarity and so
that we can eliminate the membar_consumer() call in fd_getfile(). This is
mostly syntactic sugar; the main functional change is that fd_nfiles now
lives alongside the open file array.

Some measurements with libmicro:

- simple file syscalls are like close() are between 1 to 10% faster.
- some nice improvements, e.g. poll(1000) which is ~50% faster.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 nick-hppapmap-base2 jym-xensuspend-base nick-hppapmap-base mjf-devfs2-base
# 1.173 17-Dec-2008 cegger

branches: 1.173.2;
kill MALLOC and FREE macros.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 haad-dm-base2 haad-nbase2 ad-audiomp2-base netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 haad-dm-base
# 1.172 05-Sep-2008 skrll

branches: 1.172.2;
PR/39324 kernel diagnostic assertion "l->l_stat != LSZOMB" failed.

Ignore procs with zero or all LSZOMB LWPs. Get a non-LSZOMB LWP to perform
operations against as part of the deal.

procfs really needs to be updated to support multi-threading fully.
Hi Antti!


# 1.171 05-Sep-2008 skrll

ANSIfy


Revision tags: simonb-wapbl-nbase simonb-wapbl-base
# 1.170 02-Jul-2008 rmind

branches: 1.170.2;
Remove proc_representative_lwp(), use a simple LIST_FIRST() instead.
OK by <ad>.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base
# 1.169 28-Apr-2008 martin

branches: 1.169.2; 1.169.4;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-nfs-mp-base
# 1.168 24-Apr-2008 ad

branches: 1.168.2;
Merge proc::p_mutex and proc::p_smutex into a single adaptive mutex, since
we no longer need to guard against access from hardware interrupt handlers.

Additionally, if cloning a process with CLONE_SIGHAND, arrange to have the
child process share the parent's lock so that signal state may be kept in
sync. Partially addresses PR kern/37437.


# 1.167 24-Apr-2008 ad

Network protocol interrupts can now block on locks, so merge the globals
proclist_mutex and proclist_lock into a single adaptive mutex (proc_lock).
Implications:

- Inspecting process state requires thread context, so signals can no longer
be sent from a hardware interrupt handler. Signal activity must be
deferred to a soft interrupt or kthread.

- As the proc state locking is simplified, it's now safe to take exit()
and wait() out from under kernel_lock.

- The system spends less time at IPL_SCHED, and there is less lock activity.


Revision tags: yamt-pf42-baseX yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14
# 1.166 21-Mar-2008 ad

branches: 1.166.2;
Catch up with descriptor handling changes. See kern_descrip.c revision
1.173 for details.


Revision tags: keiichi-mipv6-nbase nick-net80211-sync-base keiichi-mipv6-base bouyer-xeni386-nbase matt-armv6-nbase mjf-devfs-base hpcarm-cleanup-base
# 1.165 23-Jan-2008 elad

branches: 1.165.6;
Tons of process scope changes.

- Add a KAUTH_PROCESS_SCHEDULER action, to handle scheduler related
requests, and add specific requests for set/get scheduler policy and
set/get scheduler parameters.

- Add a KAUTH_PROCESS_KEVENT_FILTER action, to handle kevent(2) related
requests.

- Add a KAUTH_DEVICE_TTY_STI action to handle requests to TIOCSTI.

- Add requests for the KAUTH_PROCESS_CANSEE action, indicating what
process information is being looked at (entry itself, args, env,
open files).

- Add requests for the KAUTH_PROCESS_RLIMIT action indicating set/get.

- Add requests for the KAUTH_PROCESS_CORENAME action indicating set/get.

- Make bsd44 secmodel code handle the newly added rqeuests appropriately.

All of the above make it possible to issue finer-grained kauth(9) calls in
many places, removing some KAUTH_GENERIC_ISSUSER requests.

- Remove the "CAN" from KAUTH_PROCESS_CAN{KTRACE,PROCFS,PTRACE,SIGNAL}.

Discussed with christos@ and yamt@.


Revision tags: bouyer-xeni386-base matt-armv6-base
# 1.164 02-Jan-2008 ad

Merge vmlocking2 to head.


Revision tags: vmlocking2-base3 yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 vmlocking-nbase jmcneill-pm-base reinoud-bufcleanup-base
# 1.163 26-Nov-2007 pooka

branches: 1.163.2; 1.163.6;
Remove the "struct lwp *" argument from all VFS and VOP interfaces.
The general trend is to remove it from all kernel interfaces and
this is a start. In case the calling lwp is desired, curlwp should
be used.

quick consensus on tech-kern


Revision tags: bouyer-xenamd64-base2 bouyer-xenamd64-base
# 1.162 09-Nov-2007 christos

make the last argument of procfs_dir size_t


# 1.161 07-Nov-2007 ad

Merge from vmlocking:

- pool_cache changes.
- Debugger/procfs locking fixes.
- Other minor changes.


Revision tags: jmcneill-base yamt-x86pmap-base4 yamt-x86pmap-base3 vmlocking-base
# 1.160 10-Oct-2007 ad

branches: 1.160.2; 1.160.4;
Merge from vmlocking:

- Split vnode::v_flag into three fields, depending on field locking.
- simple_lock -> kmutex in a few places.
- Fix some simple locking problems.


# 1.159 08-Oct-2007 ad

Merge file descriptor locking, cwdi locking and cross-call changes
from the vmlocking branch.


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base2 yamt-x86pmap-base matt-mips64-base
# 1.158 22-Jul-2007 pooka

branches: 1.158.4; 1.158.6; 1.158.8; 1.158.10;
Don't allow getcwd() on procfs vnodes and provide "/" as the path
instead of the result from getcwd(). The works around locking
panics caused by namei calling VOP_READLINK while holding on to a
directory lock and getcwd() trying to acquire that lock. The real
fix would be to get rid of getcwd() calls within VOPs (not locking
safe), but that's not a viable option in the netbsd-4 timeframe.

Suggestion for workaround from David Holland.


Revision tags: nick-csl-alignment-base mjf-ufs-trans-base
# 1.157 24-May-2007 agc

branches: 1.157.2;
Extend the Linux emulation of /proc to include

/proc/stat
/proc/loadavg and
/proc/<pid>/statm.

These are only present when -o linux is specified as a mount option
to procfs.

Factor out some common code so that it can be used by a number of
functions.

XXX The values returned in the statm emulation need to be verified.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 1.156 04-Apr-2007 rmind

Unfortunately, missed procfs_proc_unlock() in previous.
Pointed out by pooka@


# 1.155 04-Apr-2007 rmind

procfs_readlink: Handle a possible fail of fd_getfile(), also, we
do not need to check for error again.
CID: 4436


# 1.154 09-Mar-2007 ad

branches: 1.154.2; 1.154.4;
- Make the proclist_lock a mutex. The write:read ratio is unfavourable,
and mutexes are cheaper use than RW locks.
- LOCK_ASSERT -> KASSERT in some places.
- Hold proclist_lock/kernel_lock longer in a couple of places.


# 1.153 04-Mar-2007 christos

Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.


# 1.152 03-Mar-2007 salo

Don't prepend rootvnode to the path in non-NULL case for exe links.
It breaks procfs in chroot.

from <christos>, tested by me.


Revision tags: ad-audiomp-base
# 1.151 19-Feb-2007 pooka

When checking for file validity under pid/, do proper proc->lwp
lookup (fsvo proper) instead of fiddling directly with the lwp
list.


# 1.150 18-Feb-2007 pooka

Don't check for validity of p in lookup for root nodes, since it
will always be NULL. Rather, just call pt_valid with NULL directly
and let it decide if we're a linux mount or not.


# 1.149 17-Feb-2007 pavel

Change the process/lwp flags seen by userland via sysctl back to the
P_*/L_* naming convention, and rename the in-kernel flags to avoid
conflict. (P_ -> PK_, L_ -> LW_ ). Add back the (now unused) LSDEAD
constant.

Restores source compatibility with pre-newlock2 tools like ps or top.

Reviewed by Andrew Doran.


# 1.148 16-Feb-2007 pooka

branches: 1.148.2;
In lookup, when checking for procfs process node validity, target the
process we're trying to get information about through procfs, not
the caller of lookup.

fixes 'ls -l /proc/*/file' panic, which would occur when trying to
lookup "file" for a kernel thread, which doesn't have p->p_textvp.


# 1.147 15-Feb-2007 ad

Need to acquire procp->p_mutex for procfs_dir().


# 1.146 11-Feb-2007 ad

Eliminate a couple of reference count and mutex leaks.


Revision tags: post-newlock2-merge
# 1.145 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 1.144 25-Dec-2006 elad

PR/35226: Johann Franz: Problems with permissions in
/usr/pkg/emul/linux/proc .

Okay mlelstv@


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3
# 1.143 09-Dec-2006 chs

a smorgasbord of improvements to vnode locking and path lookup:
- LOCKPARENT is no longer relevant for lookup(), relookup() or VOP_LOOKUP().
these now always return the parent vnode locked. namei() works as before.
lookup() and various other paths no longer acquire vnode locks in the
wrong order via vrele(). fixes PR 32535.
as a nice side effect, path lookup is also up to 25% faster.
- the above allows us to get rid of PDIRUNLOCK.
- also get rid of WANTPARENT (just use LOCKPARENT and unlock it).
- remove an assumption in layer_node_find() that all file systems implement
a recursive VOP_LOCK() (unionfs doesn't).
- require that all file systems supply vfs_vptofh and vfs_fhtovp routines.
fill in eopnotsupp() for file systems that don't support being exported
and remove the checks for NULL. (layerfs calls these without checking.)
- in union_lookup1(), don't change refcounts in the ISDOTDOT case, just
adjust which vnode is locked. fixes PR 33374.
- apply fixes for ufs_rename() from ufs_vnops.c rev. 1.61 to ext2fs_rename().


# 1.142 04-Dec-2006 christos

From Nicolas Joly: restore previous behavior in procfs_validfile_linux, since
readdir passes a NULL lwp.


# 1.141 03-Dec-2006 elad

Move kauth(9) call to where it belongs. Noticed by Nicolas Joly, thanks!


Revision tags: netbsd-4-base
# 1.140 28-Nov-2006 elad

branches: 1.140.2;
Move ktrace, ptrace, systrace, and procfs to use kauth(9).

First, remove process_checkioperm() calls from MD code. Similar checks
using kauth(9) routines (on the process scope, using appropriate action)
are done in the callers.

Add secmodel back-end to handle each subsystem.


# 1.139 25-Nov-2006 skrll

Expose the 'exe' symlink to the process realpath in NetBSD as well. An
example user is gdb.

OK'd by christos.


# 1.138 16-Nov-2006 christos

__unused removal on arguments; approved by core.


# 1.137 29-Oct-2006 christos

add an "emul" file node.


# 1.136 25-Oct-2006 christos

1. fix procfs_validfile{,_linux} to test for NULL pointers properly.
2. make "exe" entry be a symlink to the executable, instead of pointing
directly to the vnode of the executable.
3. factor out commonly used code.


Revision tags: yamt-splraiseipl-base2
# 1.135 12-Oct-2006 christos

- sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386


# 1.134 20-Sep-2006 manu

Emulate Linux's /proc/devices


Revision tags: abandoned-netbsd-4-base yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base rpaulo-netinet-merge-pcb-base
# 1.133 13-Jun-2006 yamt

branches: 1.133.6; 1.133.8;
use KAUTH_PROCESS_CANSEE rather than CURTAIN where appropriate.


# 1.132 13-Jun-2006 yamt

remove unnecessary arguments from kauth_authorize_process.
ie. make it similar to the one found in apple TN.


# 1.131 07-Jun-2006 kardel

merge FreeBSD timecounters from branch simonb-timecounters
- struct timeval time is gone
time.tv_sec -> time_second
- struct timeval mono_time is gone
mono_time.tv_sec -> time_uptime
- access to time via
{get,}{micro,nano,bin}time()
get* versions are fast but less precise
- support NTP nanokernel implementation (NTP API 4)
- further reading:
Timecounter Paper: http://phk.freebsd.dk/pubs/timecounter.pdf
NTP Nanokernel: http://www.eecis.udel.edu/~mills/ntp/html/kern.html


Revision tags: yamt-pdpolicy-base5 simonb-timecounters-base
# 1.130 14-May-2006 elad

branches: 1.130.2;
integrate kauth.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 elad-kernelauth-base yamt-pdpolicy-base yamt-uio_vmspace-base5
# 1.129 02-Feb-2006 christos

branches: 1.129.2; 1.129.4; 1.129.6; 1.129.8;
PR/32692: Matthew Mondor: linux compatibility in /proc/self should point
directly to the directory containing the pid instead of pointing to
/proc/curproc, because some programs rely on calling readlink on /proc/self
to get the pid.


# 1.128 11-Dec-2005 christos

branches: 1.128.2; 1.128.4;
merge ktrace-lwp.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base ktrace-lwp-base
# 1.127 02-Nov-2005 yamt

merge yamt-vop branch. remove following VOPs.

VOP_BLKATOFF
VOP_VALLOC
VOP_BALLOC
VOP_REALLOCBLKS
VOP_VFREE
VOP_TRUNCATE
VOP_UPDATE


Revision tags: yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 1.126 01-Oct-2005 atatat

branches: 1.126.2;
Add "cwd" and "root" symlinks to each process's directory. The cwd
link points to the process's current working directory, and the root
link points to the process's root directory. What else would you
expect?

For directories that are out of reach (caller is in a chroot, target
process is in a different chroot, etc), the links point to "/"
instead.


# 1.125 11-Sep-2005 elad

Implement curtain for procfs.


# 1.124 30-Aug-2005 xtraeme

Remove __P()


# 1.123 29-May-2005 christos

branches: 1.123.2;
- sprinkle const
- avoid shadowed variables.


Revision tags: kent-audio2-base
# 1.122 02-Apr-2005 christos

PR/29782: Martin Husemann: procfs can not unmount when some process has its
current directory in curproc. Fix from Pedro Martelletto:
We cannot call vgone() from procfs_inactive() if we are coming from
vclean(). that's what's probably causing the deadlock.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 yamt-km-base4 yamt-km-base3 netbsd-3-base
# 1.121 26-Feb-2005 perry

nuke trailing whitespace


Revision tags: yamt-km-base2 yamt-km-base kent-audio1-beforemerge kent-audio1-base
# 1.120 04-Oct-2004 yamt

branches: 1.120.4; 1.120.6;
procfs_readdir:
- return correct cookie when buffer size is small.
- simplify logic.


# 1.119 04-Oct-2004 yamt

procfs_readdir: remove a redundant assignment.


# 1.118 02-Oct-2004 yamt

procfs_getattr: correct size of /proc/self.


# 1.117 01-Oct-2004 yamt

procfs_readdir:
- fix a locking problem, using proclist_foreach_call. PR/27098.
- correct snprintf size argument.


# 1.116 01-Oct-2004 yamt

procfs_readdir: fix an offset handling bug after addition of /proc/self.


# 1.115 01-Oct-2004 yamt

procfs_readdir: use a list macro.


# 1.114 20-Sep-2004 jdolecek

add 'mounts' file for -o linux, which lists all currently mounted
filesystems; Linux glibc statvfs() uses this to get some of mount flags,
and this file is also useful as /emul/linux/etc/mtab (via symlink)


# 1.113 29-Apr-2004 jrf

Removed remaining caddr_t casts we do not need in miscfs. Recompiled
kernel and ran for a day or so. There are still some caddr_t types in
the arguments of some calls, I will do those separately (later) as
they touch a lot more of the system.
Approved by christos@NetBSD.org.


# 1.112 22-Apr-2004 itojun

sprintf -> snprintf


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.111 15-Feb-2004 jdolecek

unlock the descriptor table simple lock after fd_getfile() call in
procfs_readdir()
fixes procfs locking problems reported on current-users@, problem place
found by enami tsugutomo


# 1.110 30-Oct-2003 simonb

Remove some assigned-to but otherwise unused variables.


# 1.109 27-Sep-2003 darcy

Changes as discussed with itojun on tech-kern. I have modified the enums
to have KFS or PFS differentiators. Further I have wrapped the enum in
procfs in "#ifdef _KERNEL" as it is done in kernfs.

To see the discussion go to http://mail-index.NetBSD.org/tech-kern/2003/09/
and look for "Mismatched enums in include files" in the list.


# 1.108 07-Sep-2003 itojun

remove meaningless line (variable overwritten 2 lines below)


# 1.107 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.


# 1.106 29-Jun-2003 fvdl

branches: 1.106.2;
Back out the lwp/ktrace changes. They contained a lot of colateral damage,
and need to be examined and discussed more.


# 1.105 29-Jun-2003 thorpej

Undo part of the ktrace/lwp changes. In particular:
* Remove the "lwp *" argument that was added to vget(). Turns out
that nothing actually used it!
* Remove the "lwp *" arguments that were added to VFS_ROOT(), VFS_VGET(),
and VFS_FHTOVP(); all they did was pass it to vget() (which, as noted
above, didn't use it).
* Remove all of the "lwp *" arguments to internal functions that were added
just to appease the above.


# 1.104 28-Jun-2003 darrenr

Pass lwp pointers throughtout the kernel, as required, so that the lwpid can
be inserted into ktrace records. The general change has been to replace
"struct proc *" with "struct lwp *" in various function prototypes, pass
the lwp through and use l_proc to get the process pointer when needed.

Bump the kernel rev up to 1.6V


# 1.103 28-May-2003 christos

Add /proc/<pid>/stat for linux compat. j2sdk1.4.2 depends on it.


# 1.102 18-Apr-2003 christos

Make symlinks for directories that point to the actual directory.
Make symlinks to [kqueue] and [misc] for kqueue and misc fds.


# 1.101 17-Apr-2003 jdolecek

do not show nodes corresponding to directory descriptors for process
in fd/ subdirectory, nor allow lookup/open for the nodes
this fixes PR kern/21187 for good, and also avoids interesting directory
locking issues


# 1.100 17-Apr-2003 jdolecek

procfs_readdir(): in Pfd case, only show descriptors of types we want
how to represent (vnodes, fifo, pipes); also use fd_getfile() et al

this avoids annoying EOPNOTSUPP error messages from ls -F and such


# 1.99 17-Apr-2003 jdolecek

procfs_lookup(): use fd_getfile() et al in Pfd case


# 1.98 17-Apr-2003 jdolecek

use fd_getfile() in procfs_getfp(), and FILE_USE()/FILE_UNUSE() the
returned file descriptor pointer appropriately


# 1.97 17-Apr-2003 jdolecek

make some local arrays/variables static + const


# 1.96 10-Apr-2003 jdolecek

use former genfs_eopnotsupp_rele() as genfs_eopnotsupp(), so that vnodes
are vput()/vrele()d as necessary - some filesystems did use the wrong
one for some ops, and it's just safer to not take the chance

based on suggestion by Bill Studenmund


# 1.95 05-Apr-2003 dsl

Remove pointless check against PID_MAX. Let pfind() do the validation.
(The new pid allocation code may decide to allocate pids above PID_MAX.)


# 1.94 25-Feb-2003 jrf

This addresses PR kerm/19989. Thanks to hamajima@nagoya.ydc.co.jp for submitting this patch which enables /proc/uptime for linux emul. Patch reviewed by atatat@netbsd.org and tron@netbsd.org, approved by tron@netbsd.org.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 1.93 04-Jan-2003 martin

Cast off_t expression to long long to match format even on 64 bit
plattforms.

Shouldn't we introduce a PRIoff_t macro to create such format strings?


# 1.92 03-Jan-2003 christos

add LK_CANRECURSE in the locking of /dev/<pid>/fd/<n> and remove the curproc
kludge. Thanks to fvdl.


# 1.91 03-Jan-2003 christos

Implement /proc/<pid>/fd/<n>. This is work in progress. Questionable things:
- Is it ok to convert DTYPE_PIPE to VFIFO and DTYPE_SOCKET to VSOCK?
- XXX: Avoid locking issue in ls -Rl /proc by avoiding curproc
- Does I/O to pipes work?
- XXX: Are there security implications?


Revision tags: fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge gehenna-devsw-base kqueue-base
# 1.90 03-Aug-2002 simonb

Just use the "time" variable in the *_getattr functions instead of a call
to (the potentially expensive) microtime().


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.89 09-May-2002 thorpej

branches: 1.89.2;
Move code shared by procfs and the kernel proper out of procfs and
into the kernel proper (renaming functions from procfs_* to process_*).


Revision tags: eeh-devprop-base newlock-base ifpoll-base
# 1.88 12-Jan-2002 christos

Don't hide the real return code with EPERM.


# 1.87 06-Dec-2001 chs

add a VOP_PUTPAGES method for all the filesystems that don't have pages,
just unlock the interlock.


# 1.86 05-Dec-2001 thorpej

* Allow machine-dependent code to specify hooks for ptrace(2)
(__HAVE_PTRACE_MACHDEP) and procfs (__HAVE_PROCFS_MACHDEP).
These changes will allow platforms like x86 (XMM) and PowerPC
(AltiVec) to export extended register sets in a sane manner.

* Use __HAVE_PTRACE_MACHDEP to export x86 XMM registers (standard
FP + SSE/SSE2) using PT_{GET,SET}XMMREGS (in the machdep
ptrace request space).
* Use __HAVE_PROCFS_MACHDEP to export x86 XMM registers via
/proc/N/xmmregs in procfs.


Revision tags: thorpej-mips-cache-base
# 1.85 10-Nov-2001 lukem

add RCSIDs


# 1.84 06-Nov-2001 simonb

Remove some variables that are set but never used.


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base
# 1.83 31-Aug-2001 chs

branches: 1.83.2; 1.83.4;
map files are zero-length.


# 1.82 03-Jun-2001 chs

branches: 1.82.2;
procfs_bmap() should never be called, make it a "bad op".
let procfs_mmap() use the default error method.


Revision tags: thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 1.81 14-Apr-2001 kleink

In procfs_readdir(), give /proc/# directories DT_DIR (rather than DT_REG).


# 1.80 30-Mar-2001 fvdl

Bump va_blocksize for the map files some more, so that programs with
quite a few mappings have a chance of being handled correctly if
st_blksize is looked at.


# 1.79 29-Mar-2001 fvdl

For -o linux mounts, add some code to emulate /proc/#/maps.
Needs NAMECACHE_ENTER_REVERSE to include filenames.


# 1.78 21-Feb-2001 jdolecek

branches: 1.78.2;
make some more constant arrays 'const'


# 1.77 22-Jan-2001 jdolecek

make filesystem vnodeop, specop, fifoop and vnodeopv_* arrays const


# 1.76 17-Jan-2001 fvdl

Add a few linux-style files, only enabled when -o linux is specified
for the mount. Currently these are /proc/cpuinfo and /proc/meminfo.
The former only does something on i386 right now.


# 1.75 24-Nov-2000 chs

remove dead code and other misc cleanup.


# 1.74 09-Aug-2000 tv

Only show the "exe" entry to Linux processes, suggested by christos.
Since there are actually three struct emul's for linux, use the e_name
field to determine eligibility with strcmp().


# 1.73 09-Aug-2000 tv

Some versions of Linux libc look for /proc/.../exe instead of /proc/../file.
Add an entry for "exe" that is the same as "file", provided only if
COMPAT_LINUX is set.


# 1.72 03-Aug-2000 thorpej

MALLOC()/FREE() are not to be used for variable sized allocations.


# 1.71 28-Jun-2000 mrg

<vm/vm.h> -> <uvm/uvm_extern.h>


Revision tags: netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 1.70 30-Mar-2000 simonb

branches: 1.70.4;
Delete duplicate declaration of atopid().


Revision tags: chs-ubc2-newbase wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base fvdl-softdep-base
# 1.69 02-Sep-1999 thorpej

branches: 1.69.2; 1.69.8;
Make /proc/self a symlink to /proc/curproc. I've observed Linux programs
that expect /proc/self/cmdline to exist.


# 1.68 25-Aug-1999 sommerfeld

Change variable used for directory offset from "int" to "off_t".
Overkill, but avoids a host of truncation problems.


# 1.67 24-Aug-1999 sommerfeld

Fix PR8270:

Problem turned out to be due to improper handling of reads beyond EOF:
they should just return without error with the uio unchanged, and the
caller will recognize this as a zero-byte return (EOF).

The previous fix to protect directory reads against bogus uio_offset
values returned EINVAL, which broke mount -o union, which only
union'ed in the lower directory if the upper directory cleanly
returned EOF.

While we're here, protect kernfs as well.


# 1.66 14-Aug-1999 christos

protect against large uio_offset


# 1.65 03-Aug-1999 wrstuden

Add support for fcntl(2) to generate VOP_FCNTL calls. Any fcntl
call with F_FSCTL set and F_SETFL calls generate calls to a new
fileop fo_fcntl. Add genfs_fcntl() and soo_fcntl() which return 0
for F_SETFL and EOPNOTSUPP otherwise. Have all leaf filesystems
use genfs_fcntl().

Reviewed by: thorpej
Tested by: wrstuden


Revision tags: chs-ubc2-base
# 1.64 25-Jul-1999 thorpej

Add calls to lock the proclist as appropriate.


# 1.63 14-Jul-1999 thorpej

Fix a paste-o in procfs_lookup() introduced with the vnode locking changes.
Fixes PR #7961, Mario Kemper <magick@bundy.lip.owl.de>.


# 1.62 08-Jul-1999 wrstuden

Bump osrelease to 1.4E. Add layerfs files, remove null_subr.c.

Update coda to new struct lock in struct vnode.

make fdescfs, kernfs, portalfs, and procfs actually lock their vnodes.
It's not that hard.

Make unionfs set v_vnlock = NULL so any overlayed fs will call its
VOP_LOCK.


Revision tags: kame_141_19991130 netbsd-1-4-PATCH001 kame_14_19990705 kame_14_19990628 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.61 12-Mar-1999 christos

branches: 1.61.2; 1.61.4;
PR/7143: Jaromir Docelek: Add procfs/cmdline from Linux emulation


# 1.60 25-Jan-1999 msaitoh

Add /proc/#/map. From FreeBSD.


Revision tags: kenh-if-detach-base chs-ubc-base
# 1.59 08-Sep-1998 thorpej

- Use proclists[], rather than checking allproc and zombproc explicitly.
- Add some comments about locking.


# 1.58 13-Aug-1998 kleink

Per POSIX, fail with EINVAL if advisory locking is attempted on a file type
that doesn't support it, rather than using a homegrown EBADF or EOPNOTSUPP.


# 1.57 10-Aug-1998 matthias

create miscfs/genfs/genfs_vnops.c:genfs_enoioctl and make all the other
filesystems use it instead of a private version.


# 1.56 09-Aug-1998 perry

bzero->memset, bcopy->memcpy, bcmp->memcmp


# 1.55 03-Aug-1998 kleink

Recognize _PC_SYNC_IO.


Revision tags: eeh-paddr_t-base
# 1.54 21-Apr-1998 fvdl

procfs_readdir: in case of error, check if cookies actually have
been allocated before freeing them. From Wolfgang Solfrank.


# 1.53 01-Mar-1998 fvdl

Merge with Lite2 + local changes


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base marc-pcmcia-base
# 1.52 10-Oct-1997 fvdl

Bump last argument to VOP_READDIR to off_t (from u_long).


Revision tags: thorpej-signal-base
# 1.51 27-Aug-1997 thorpej

Fix a reversed argument which caused procfs_checkioperm() to always return
"OK". Add a few comments to avoid further confusion.


# 1.50 12-Aug-1997 thorpej

Fix the procfs hole described on current-users, similar to a fix for
FreeBSD by Sean Eric Fagan, but a bit different. This makes the checks
in the same places as sef's FreeBSD patch, but does not hardcode the
"kmem" group into the kernel, and also does a check identical to the
(3) and (4) checks in the NetBSD ptrace(2):

(1) it's not owned by you, or is set-id on exec (unless
you're root), or

(2) it's init, which controls the security level of the
entire system, and the system was not compiled with
permanently insecure mode turned on.


Revision tags: marc-pcmcia-bp
# 1.49 08-May-1997 mycroft

branches: 1.49.4;
Pass the vnode type to vaccess(), and use it when checking VEXEC. Make sure
that the mode bits passed to vaccess() and returned by foo_getattr() contain
only permission bits.


# 1.48 05-May-1997 mycroft

Need stat.h.


# 1.47 05-May-1997 mycroft

Eliminate bogus uses of V{READ,WRITE,EXEC}. Use S_I[RWX]{USR,GRP,OTH} where
appropriate.


# 1.46 28-Apr-1997 mycroft

Minor code cleanup.


Revision tags: is-newarp-before-merge is-newarp-base
# 1.45 25-Oct-1996 cgd

define path name string variables that we should not (and, thankfully, do
not) modify as 'const char *' rather 'char *'.


# 1.44 13-Oct-1996 christos

backout previous kprintf changes


# 1.43 10-Oct-1996 christos

printf -> kprintf, sprintf -> ksprintf


# 1.42 07-Sep-1996 mycroft

Implement poll(2).


# 1.41 01-Sep-1996 mycroft

Add a set of generic file system operations that most file systems use.
Also, fix some time stamp bogosities.


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 1.40 16-Mar-1996 christos

Fix printf format follies.


# 1.39 13-Feb-1996 mycroft

GC *_nullop(). Minor nits.


# 1.38 12-Feb-1996 christos

close PR/2063: procfs_rw prototyped twice with different prototypes


# 1.37 09-Feb-1996 christos

miscfs prototype changes


# 1.36 09-Feb-1996 mycroft

Fix vop_link, vop_symlink, and vop_remove semantics in several ways:
* Change the argument names to vop_link so they actually make sense.
* Implement vop_link and vop_symlink for all file systems, so they do proper
cleanup.
* Require the file system to decide whether or not linking and unlinking of
directories is allowed, and disable it for all current file systems.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.35 09-Oct-1995 mycroft

Use the index number as the cookie, rather than multiplying by UIO_MX.


# 1.34 09-Oct-1995 mycroft

Add support for cookies, mostly from Greg Hudson.


# 1.33 15-Apr-1995 cgd

fix timeval vs. timespec warnings


# 1.32 03-Feb-1995 mycroft

Return EROFS rather than ENOENT in many cases. Also some cosmetic cleanup.


# 1.31 27-Dec-1994 mycroft

Format police.


# 1.30 24-Dec-1994 ws

Implement and use a common access checking routine


# 1.29 14-Dec-1994 mycroft

Remove a_fp.


# 1.28 14-Nov-1994 christos

fixed struct comment


# 1.27 30-Oct-1994 cgd

be more careful with types, also pull in headers where necessary.


# 1.26 20-Oct-1994 cgd

update for new syscall args description mechanism


# 1.25 30-Aug-1994 mycroft

Convert process, file, and namei lists and hash tables to use queue.h.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.24 29-Jun-1994 cgd

New RCS ID's, take two. they're more aesthecially pleasant, and use 'NetBSD'


# 1.23 16-Jun-1994 mycroft

Remove an unneeded test.


# 1.22 15-Jun-1994 mycroft

Minor update from JSP after merging my changes.


# 1.21 08-Jun-1994 mycroft

Update to 4.4-Lite fs code, with local changes.


# 1.20 05-May-1994 cgd

lots of changes: prototype migration, move lots of variables, definitions,
and structure elements around. kill some unnecessary type and macro
definitions. standardize clock handling. More changes than you'd want.


# 1.19 15-Apr-1994 cgd

forgot these...


# 1.18 12-Apr-1994 cgd

be a bit smarter about determining if files shouldn't be seen by the user.
Also, DON'T allow a lookup to succeed on a file that's not visible!


# 1.17 15-Feb-1994 mycroft

Undo last change; executables is `file', not `a.out'.


# 1.16 14-Feb-1994 ws

Rename file -> a.out


# 1.15 14-Feb-1994 ws

Don't try to show a file for a process if there is none


# 1.14 28-Jan-1994 cgd

make a fpregs file.


# 1.13 20-Jan-1994 ws

Make procfs really work for debugging.
Implement not & notepg files in procfs.


# 1.12 09-Jan-1994 ws

Bug fixes and enhancements:
Make NFS serving work (BUT DON'T USE "attach" TO /proc/*/ctl FOR NOW!!!)
Make `curproc' a symbolic link
Add `.' and `..' entries to the directories.
Return better guesses on the size of the files.


# 1.11 05-Jan-1994 cgd

return size of 'reg' from getattr()


# 1.10 05-Jan-1994 cgd

make it compile (cleanly) for us


# 1.9 05-Jan-1994 cgd

add new procfs code, from Jan-Simon Pendry, jsp@sequent.com.
This is pretty-much "virgin", so that diffs can be done later.


# 1.8 18-Dec-1993 mycroft

Canonicalize all #includes.


Revision tags: magnum-base
# 1.7 16-Sep-1993 cgd

kill volatile warning.


# 1.6 07-Sep-1993 ws

branches: 1.6.2;
Changes to VFS readdir semantics
NFS changes for better cookie support
ISOFS changes for better Rockridge support and support for generation numbers


# 1.5 26-Aug-1993 pk

Implement setattr: mode for process entries; mode + uid/gid for the
PROCFS root directory.
Fixed omission in pfs_root() which came to light as a result of the above:
hold on to vnode for root dir.


# 1.4 25-Aug-1993 pk

Fixed improperly initialized nfsnode in pfs_lookup()


# 1.3 24-Aug-1993 pk

copyright update.


# 1.2 24-Aug-1993 pk

Rcs Id added.


# 1.1 24-Aug-1993 pk

branches: 1.1.1;
Initial version of a proc filesystem.


# 1.216 28-Jun-2021 chs

VOP_BMAP() may be called via ioctl(FIOGETBMAP) on any vnode that applications
can open. change various pseudo-fs *_bmap methods return an error instead of
panic.

Reported-by: syzbot+8289a3eaf2ba60958c87@syzkaller.appspotmail.com


Revision tags: cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base thorpej-i2c-spi-conf-base thorpej-cfargs-base thorpej-futex-base
# 1.215 27-Jun-2020 christos

Introduce genfs_pathconf() and use it for the default case in all filesystems.


# 1.214 23-May-2020 ad

Move proc_lock into the data segment. It was dynamically allocated because
at the time we had mutex_obj_alloc() but not __cacheline_aligned.


# 1.213 16-May-2020 christos

Add ACL support for FFS. From FreeBSD.


# 1.212 29-Apr-2020 thorpej

If the procfs mount is marked as linux-compat, then allow proc lookup
by any LWP ID in the proc, not just the canonical PID.


Revision tags: bouyer-xenpvh-base2
# 1.211 21-Apr-2020 ad

Revert the changes made in February to make cwdinfo use mostly lockless,
which relied on taking extra vnode refs.

Having benchmarked various experimental changes over the past few months it
seems that it's better to avoid vnode refs as much as possible. cwdi_lock
as a RW lock already did that to some extent for getcwd() and will permit
the same for namei() too.


Revision tags: phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base is-mlppp-base phil-wifi-20200406 ad-namecache-base3
# 1.210 24-Feb-2020 ad

branches: 1.210.4;
v_interlock -> vmobjlock


# 1.209 23-Feb-2020 ad

Merge from ad-namecache:

- Have a stab at clustering the members of vnode_t and vnode_impl_t in a
more cache-conscious way. With that done, go back to adjusting v_usecount
with atomics and keep vi_lock directly in vnode_impl_t (saves KVA).

- Allow VOP_LOCK(LK_NONE) for the benefit of VFS_VGET() and VFS_ROOT().
Make sure LK_UPGRADE always comes with LK_NOWAIT.

- Make cwdinfo use mostly lockless.


# 1.208 01-Feb-2020 riastradh

Load struct filedesc::fd_dt with atomic_load_consume.

Exceptions: when fd_refcnt <= 1, or when holding fd_lock.

While here:

- Restore KASSERT(mutex_owned(&fdp->fd_lock)) in fd_unused.
=> This is used only in fd_close and fd_abort, where it holds.
- Move bounds check assertion in fd_putfile to where it matters.
- Store fd_dt with atomic_store_release.
- Move load of fd_dt under lock in knote_fdclose.
- Omit membar_consumer in fdesc_readdir.
=> atomic_load_consume serves the same purpose now.
=> Was needed only on alpha anyway.


Revision tags: ad-namecache-base2 ad-namecache-base1 ad-namecache-base phil-wifi-20191119
# 1.207 29-Aug-2019 hannken

branches: 1.207.2;
Add missing operation VOP_GETPAGES() returning EFAULT.

Without this operation posix_fadvise(..., POSIX_FADV_WILLNEED)
would leave the v_interlock held.

Observed by maxv@


Revision tags: netbsd-9-base phil-wifi-20190609 isaki-audio2-base
# 1.206 30-Mar-2019 christos

branches: 1.206.4;
add a node for the process resource limits.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020
# 1.205 14-Oct-2018 jdolecek

remove M_CANFAIL flag for malloc(9) - it was completely ignored, so had
actually no effect


Revision tags: pgoyette-compat-0930 pgoyette-compat-0906
# 1.204 03-Sep-2018 riastradh

Rename min/max -> uimin/uimax for better honesty.

These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER! Some subsystems have

#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)


Revision tags: pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415
# 1.203 07-Apr-2018 hannken

branches: 1.203.2;
Lock the target cwdi and take an additional reference to the
vnode we are interested in to prevent it from disappearing
before getcwd_common().

Should fix PR kern/53096 (netbsd-8 crash on heavy disk I/O)


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.202 31-Dec-2017 christos

branches: 1.202.2;
Add an environ node


Revision tags: tls-maxphys-base-20171202
# 1.201 01-Dec-2017 christos

Allow procfs_kqfilter, since we allow poll. "go" does it.


# 1.200 08-Nov-2017 christos

fix locking, remove error(1) comments.


# 1.199 08-Nov-2017 christos

use p->p_path, remove unused code.


# 1.198 28-Aug-2017 kamil

Remove the filesystem tracing feature

This is a legacy interface from 4.4BSD, and it was
introduced to overcome shortcomings of ptrace(2) at that time, which are
no longer relevant (performance). Today /proc/#/ctl offers a narrow
subset of ptrace(2) commands and is not applicable for modern
applications use beyond simplistic tracing scenarios.

This removal will simplify kernel internals. Users will still be able to
use all the other /proc files.

This change won't affect other procfs files neither Linux compat
features within mount_procfs(8). /proc/#/ctl isn't available on Linux.

Remove:
- /proc/#/ctl from mount_procfs(8)
- P_FSTRACE note from the documentation of ps(1)
- /proc/#/ctl and filesystem tracing documentation from mount_procfs(8)
- KAUTH_REQ_PROCESS_PROCFS_CTL documentation from kauth(9)
- source code file miscfs/procfs/procfs_ctl.c
- PFSctl and procfs_doctl() from sys/miscfs/procfs/procfs.h
- KAUTH_REQ_PROCESS_PROCFS_CTL from sys/sys/kauth.h
- PSL_FSTRACE (0x00010000) from sys/sys/proc.h
- P_FSTRACE (0x00010000) from sys/sys/sysctl.h

Reduce code complexity after removal of this functionality.

Update TODO.ptrace accordingly: remove two entries about /proc tracing.

Do not keep legacy notes as comments in the headers about removed
PSL_FSTRACE / P_FSTRACE, as this interface had little number of users
(close or equal to zero).

Proposed on tech-kern@.

All filesystem tracing utility users are encouraged to switch to ptrace(2).

Sponsored by <The NetBSD Foundation>


Revision tags: matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base
# 1.197 26-May-2017 riastradh

branches: 1.197.2;
Make VOP_RECLAIM do the last unlock of the vnode.

VOP_RECLAIM naturally has exclusive access to the vnode, so having it
locked on entry is not strictly necessary -- but it means if there
are any final operations that must be done on the vnode, such as
ffs_update, requiring exclusive access to it, we can now kassert that
the vnode is locked in those operations.

We can't just have the caller release the last lock because some file
systems don't use genfs_lock, and require the vnode to remain valid
for VOP_UNLOCK to work, notably unionfs.


Revision tags: prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.196 11-Apr-2017 riastradh

Make VOP_INACTIVE preserve vnode lock on return.

Discussed on tech-kern:
https://mail-index.netbsd.org/tech-kern/2017/04/01/msg021751.html

Ride 7.99.68, a bumpy bus of incremental vfs improvements!


Revision tags: jdolecek-ncq-base
# 1.195 30-Mar-2017 christos

add an auxv node.


Revision tags: pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004 localcount-20160914
# 1.194 20-Aug-2016 hannken

branches: 1.194.2;
Remove now obsolete operation vcache_remove().

Welcome to 7.99.36


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 nick-nhusb-base-20150921 nick-nhusb-base-20150606
# 1.193 20-Apr-2015 riastradh

branches: 1.193.2;
Make VOP_LINK return directory still locked and referenced.

Ride 7.99.10 bump.


Revision tags: nick-nhusb-base-20150406 nick-nhusb-base
# 1.192 05-Sep-2014 matt

branches: 1.192.2;
Try not to use f_data, use f_{vnode,socket,pipe,mqueue,kqueue,ksem} to get
a correctly typed pointer.


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.191 27-Jul-2014 hannken

branches: 1.191.2; 1.191.4; 1.191.8;
Change procfs from hashlist to vcache.
- Key is (type, pid, fd)
- Remove argument "p" from procfs_allocvp(). It is only used
when "type == PFSfd". Lookup the proc with proc_find() when
procfs_loadvnode() needs it.
- Use a vfs_vnode_iterator for procfs_revoke_vnodes().


# 1.190 25-Jul-2014 dholland

Add VOP_FALLOCATE and VOP_FDISCARD to every vnode ops table I can
find.

The filesystem ones all call genfs_eopnotsupp - right now I am only
implementing the plumbing and we can implement fallocate and/or
fdiscard for files later.

The device ones call spec_fallocate (which is also genfs_eopnotsupp)
and spec_fdiscard, which dispatches to the device-level op.

The fifo ones all call vn_fifo_bypass, which also ends up being
EOPNOTSUPP.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base
# 1.189 07-Feb-2014 hannken

branches: 1.189.2;
Change vnode operation lookup to return the resulting vnode *vpp unlocked.
Change cache_lookup() to return an unlocked vnode.

Discussed on tech-kern@

Welcome to 6.99.31


# 1.188 23-Jan-2014 hannken

Change vnode operations create, mknod, mkdir and symlink to return
the resulting vnode *vpp unlocked.

Discussed on tech-kern@

Welcome to 6.99.30


# 1.187 17-Jan-2014 hannken

Change vnode operations create, mknod, mkdir and symlink to keep the
directory node dvp locked on return.

Discussed on tech-kern@

Welcome to 6.99.29


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base
# 1.186 18-Mar-2013 plunky

branches: 1.186.6;
C99 section 6.7.2.3 (Tags) Note 3 states that:

A type specifier of the form

enum identifier

without an enumerator list shall only appear after the type it
specifies is complete.

which means that we cannot pass an "enum vtype" argument to
kauth_access_action() without fully specifying the type first.
Unfortunately there is a complicated include file loop which
makes that difficult, so convert this minimal function into a
macro (and capitalize it).

(ok elad@)


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 1.185 25-Nov-2012 christos

do something reasonable with kernel semaphores.


Revision tags: yamt-pagecache-base6 jmcneill-usbmp-base10
# 1.184 28-May-2012 christos

branches: 1.184.2;
add a task process subdirectory for emul linux


Revision tags: yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 1.183 13-Mar-2012 elad

Replace the remaining KAUTH_GENERIC_ISSUSER authorization calls with
something meaningful. All relevant documentation has been updated or
written.

Most of these changes were brought up in the following messages:

http://mail-index.netbsd.org/tech-kern/2012/01/18/msg012490.html
http://mail-index.netbsd.org/tech-kern/2012/01/19/msg012502.html
http://mail-index.netbsd.org/tech-kern/2012/02/17/msg012728.html

Thanks to christos, manu, njoly, and jmmv for input.

Huge thanks to pgoyette for spinning these changes through some build
cycles and ATF.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.182 04-Sep-2011 jmcneill

branches: 1.182.2; 1.182.6;
PR# kern/45021: Please support /emul/linux/proc/version

Add /proc/version for procfs with -o linux. The version reported depends
on the emulation type of the calling process:

$ cat /proc/version
NetBSD version 5.99.55 (netbsd@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) NetBSD 5.99.55 (GENERIC) #39: Sun Sep 4 09:10:05 EDT 2011

$ /emul/linux/bin/cat /proc/version
Linux version 2.6.18 (linux@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) #0 Wed Mar 3 03:03:03 PST 2010

$ /emul/linux32/bin/cat /proc/version
Linux version 2.6.18 (linux32@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) #0 Wed Mar 3 03:03:03 PST 2010


# 1.181 23-Jun-2011 christos

From Aleksey Cheusov: Don't make it easy for compromised systems to bypass
ASLR protections by providing the mapping addresses of programs to everyone.


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base matt-mips64-premerge-20101231 uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10 rmind-uvmplock-base
# 1.180 01-Jul-2010 rmind

Remove pfind() and pgfind(), fix locking in various broken uses of these.
Rename real routines to proc_find() and pgrp_find(), remove PFIND_* flags
and have consistent behaviour. Provide proc_find_raw() for special cases.
Fix memory leak in sysctl_proc_corename().

COMPAT_LINUX: rework ptrace() locking, minimise differences between
different versions per-arch.

Note: while this change adds some formal cosmetics for COMPAT_DARWIN and
COMPAT_IRIX - locking there is utterly broken (for ages).

Fixes PR/43176.


# 1.179 24-Jun-2010 hannken

Clean up vnode lock operations pass 2:

VOP_UNLOCK(vp, flags) -> VOP_UNLOCK(vp): Remove the unneeded flags argument.

Welcome to 5.99.32.

Discussed on tech-kern.


# 1.178 08-Jun-2010 hannken

Procfs_lookup() does not lookup directory descriptors in the fd/
subdirectory. There is no need for recursive vnode locking here.

Ok: Christos Zoulas <christos@netbsd.org>


Revision tags: uebayasi-xip-base1 yamt-nfs-mp-base9 uebayasi-xip-base
# 1.177 08-Jan-2010 pooka

branches: 1.177.2; 1.177.4;
The VATTR_NULL/VREF/VHOLD/HOLDRELE() macros lost their will to live
years ago when the kernel was modified to not alter ABI based on
DIAGNOSTIC, and now just call the respective function interfaces
(in lowercase). Plenty of mix'n match upper/lowercase has creeped
into the tree since then. Nuke the macros and convert all callsites
to lowercase.

no functional change


Revision tags: matt-premerge-20091211 yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 jym-xensuspend-nbase
# 1.176 03-Jul-2009 elad

Where possible, extract the file-system's access() routine to two internal
functions: the first checking if the operation is possible (regardless of
permissions), the second checking file-system permissions, ACLs, etc.

Mailing list reference:

http://mail-index.netbsd.org/tech-kern/2009/06/21/msg005311.html


# 1.175 23-Jun-2009 elad

Move the implementation of vaccess() to genfs_can_access(), in line with
the other routines of the same spirit.

Adjust file-system code to use it.

Keep vaccess() for KPI compatibility and to keep element of least
surprise. A "diagnostic" message warning that vaccess() is deprecated will
be printed when it's used (obviously, only in DIAGNOSTIC kernels).

No objections on tech-kern@:

http://mail-index.netbsd.org/tech-kern/2009/06/21/msg005310.html


Revision tags: yamt-nfs-mp-base5
# 1.174 24-May-2009 ad

More changes to improve kern_descrip.c.

- Avoid atomics in more places.
- Remove the per-descriptor mutex, and just use filedesc_t::fd_lock.
It was only being used to synchronize close, and in any case we needed
to take fd_lock to free the descriptor slot.
- Optimize certain paths for the <NDFDFILE case.
- Sprinkle more comments and assertions.
- Cache more stuff in filedesc_t.
- Fix numerous minor bugs spotted along the way.
- Restructure how the open files array is maintained, for clarity and so
that we can eliminate the membar_consumer() call in fd_getfile(). This is
mostly syntactic sugar; the main functional change is that fd_nfiles now
lives alongside the open file array.

Some measurements with libmicro:

- simple file syscalls are like close() are between 1 to 10% faster.
- some nice improvements, e.g. poll(1000) which is ~50% faster.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 nick-hppapmap-base2 jym-xensuspend-base nick-hppapmap-base mjf-devfs2-base
# 1.173 17-Dec-2008 cegger

branches: 1.173.2;
kill MALLOC and FREE macros.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 haad-dm-base2 haad-nbase2 ad-audiomp2-base netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 haad-dm-base
# 1.172 05-Sep-2008 skrll

branches: 1.172.2;
PR/39324 kernel diagnostic assertion "l->l_stat != LSZOMB" failed.

Ignore procs with zero or all LSZOMB LWPs. Get a non-LSZOMB LWP to perform
operations against as part of the deal.

procfs really needs to be updated to support multi-threading fully.
Hi Antti!


# 1.171 05-Sep-2008 skrll

ANSIfy


Revision tags: simonb-wapbl-nbase simonb-wapbl-base
# 1.170 02-Jul-2008 rmind

branches: 1.170.2;
Remove proc_representative_lwp(), use a simple LIST_FIRST() instead.
OK by <ad>.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base
# 1.169 28-Apr-2008 martin

branches: 1.169.2; 1.169.4;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-nfs-mp-base
# 1.168 24-Apr-2008 ad

branches: 1.168.2;
Merge proc::p_mutex and proc::p_smutex into a single adaptive mutex, since
we no longer need to guard against access from hardware interrupt handlers.

Additionally, if cloning a process with CLONE_SIGHAND, arrange to have the
child process share the parent's lock so that signal state may be kept in
sync. Partially addresses PR kern/37437.


# 1.167 24-Apr-2008 ad

Network protocol interrupts can now block on locks, so merge the globals
proclist_mutex and proclist_lock into a single adaptive mutex (proc_lock).
Implications:

- Inspecting process state requires thread context, so signals can no longer
be sent from a hardware interrupt handler. Signal activity must be
deferred to a soft interrupt or kthread.

- As the proc state locking is simplified, it's now safe to take exit()
and wait() out from under kernel_lock.

- The system spends less time at IPL_SCHED, and there is less lock activity.


Revision tags: yamt-pf42-baseX yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14
# 1.166 21-Mar-2008 ad

branches: 1.166.2;
Catch up with descriptor handling changes. See kern_descrip.c revision
1.173 for details.


Revision tags: keiichi-mipv6-nbase nick-net80211-sync-base keiichi-mipv6-base bouyer-xeni386-nbase matt-armv6-nbase mjf-devfs-base hpcarm-cleanup-base
# 1.165 23-Jan-2008 elad

branches: 1.165.6;
Tons of process scope changes.

- Add a KAUTH_PROCESS_SCHEDULER action, to handle scheduler related
requests, and add specific requests for set/get scheduler policy and
set/get scheduler parameters.

- Add a KAUTH_PROCESS_KEVENT_FILTER action, to handle kevent(2) related
requests.

- Add a KAUTH_DEVICE_TTY_STI action to handle requests to TIOCSTI.

- Add requests for the KAUTH_PROCESS_CANSEE action, indicating what
process information is being looked at (entry itself, args, env,
open files).

- Add requests for the KAUTH_PROCESS_RLIMIT action indicating set/get.

- Add requests for the KAUTH_PROCESS_CORENAME action indicating set/get.

- Make bsd44 secmodel code handle the newly added rqeuests appropriately.

All of the above make it possible to issue finer-grained kauth(9) calls in
many places, removing some KAUTH_GENERIC_ISSUSER requests.

- Remove the "CAN" from KAUTH_PROCESS_CAN{KTRACE,PROCFS,PTRACE,SIGNAL}.

Discussed with christos@ and yamt@.


Revision tags: bouyer-xeni386-base matt-armv6-base
# 1.164 02-Jan-2008 ad

Merge vmlocking2 to head.


Revision tags: vmlocking2-base3 yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 vmlocking-nbase jmcneill-pm-base reinoud-bufcleanup-base
# 1.163 26-Nov-2007 pooka

branches: 1.163.2; 1.163.6;
Remove the "struct lwp *" argument from all VFS and VOP interfaces.
The general trend is to remove it from all kernel interfaces and
this is a start. In case the calling lwp is desired, curlwp should
be used.

quick consensus on tech-kern


Revision tags: bouyer-xenamd64-base2 bouyer-xenamd64-base
# 1.162 09-Nov-2007 christos

make the last argument of procfs_dir size_t


# 1.161 07-Nov-2007 ad

Merge from vmlocking:

- pool_cache changes.
- Debugger/procfs locking fixes.
- Other minor changes.


Revision tags: jmcneill-base yamt-x86pmap-base4 yamt-x86pmap-base3 vmlocking-base
# 1.160 10-Oct-2007 ad

branches: 1.160.2; 1.160.4;
Merge from vmlocking:

- Split vnode::v_flag into three fields, depending on field locking.
- simple_lock -> kmutex in a few places.
- Fix some simple locking problems.


# 1.159 08-Oct-2007 ad

Merge file descriptor locking, cwdi locking and cross-call changes
from the vmlocking branch.


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base2 yamt-x86pmap-base matt-mips64-base
# 1.158 22-Jul-2007 pooka

branches: 1.158.4; 1.158.6; 1.158.8; 1.158.10;
Don't allow getcwd() on procfs vnodes and provide "/" as the path
instead of the result from getcwd(). The works around locking
panics caused by namei calling VOP_READLINK while holding on to a
directory lock and getcwd() trying to acquire that lock. The real
fix would be to get rid of getcwd() calls within VOPs (not locking
safe), but that's not a viable option in the netbsd-4 timeframe.

Suggestion for workaround from David Holland.


Revision tags: nick-csl-alignment-base mjf-ufs-trans-base
# 1.157 24-May-2007 agc

branches: 1.157.2;
Extend the Linux emulation of /proc to include

/proc/stat
/proc/loadavg and
/proc/<pid>/statm.

These are only present when -o linux is specified as a mount option
to procfs.

Factor out some common code so that it can be used by a number of
functions.

XXX The values returned in the statm emulation need to be verified.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 1.156 04-Apr-2007 rmind

Unfortunately, missed procfs_proc_unlock() in previous.
Pointed out by pooka@


# 1.155 04-Apr-2007 rmind

procfs_readlink: Handle a possible fail of fd_getfile(), also, we
do not need to check for error again.
CID: 4436


# 1.154 09-Mar-2007 ad

branches: 1.154.2; 1.154.4;
- Make the proclist_lock a mutex. The write:read ratio is unfavourable,
and mutexes are cheaper use than RW locks.
- LOCK_ASSERT -> KASSERT in some places.
- Hold proclist_lock/kernel_lock longer in a couple of places.


# 1.153 04-Mar-2007 christos

Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.


# 1.152 03-Mar-2007 salo

Don't prepend rootvnode to the path in non-NULL case for exe links.
It breaks procfs in chroot.

from <christos>, tested by me.


Revision tags: ad-audiomp-base
# 1.151 19-Feb-2007 pooka

When checking for file validity under pid/, do proper proc->lwp
lookup (fsvo proper) instead of fiddling directly with the lwp
list.


# 1.150 18-Feb-2007 pooka

Don't check for validity of p in lookup for root nodes, since it
will always be NULL. Rather, just call pt_valid with NULL directly
and let it decide if we're a linux mount or not.


# 1.149 17-Feb-2007 pavel

Change the process/lwp flags seen by userland via sysctl back to the
P_*/L_* naming convention, and rename the in-kernel flags to avoid
conflict. (P_ -> PK_, L_ -> LW_ ). Add back the (now unused) LSDEAD
constant.

Restores source compatibility with pre-newlock2 tools like ps or top.

Reviewed by Andrew Doran.


# 1.148 16-Feb-2007 pooka

branches: 1.148.2;
In lookup, when checking for procfs process node validity, target the
process we're trying to get information about through procfs, not
the caller of lookup.

fixes 'ls -l /proc/*/file' panic, which would occur when trying to
lookup "file" for a kernel thread, which doesn't have p->p_textvp.


# 1.147 15-Feb-2007 ad

Need to acquire procp->p_mutex for procfs_dir().


# 1.146 11-Feb-2007 ad

Eliminate a couple of reference count and mutex leaks.


Revision tags: post-newlock2-merge
# 1.145 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 1.144 25-Dec-2006 elad

PR/35226: Johann Franz: Problems with permissions in
/usr/pkg/emul/linux/proc .

Okay mlelstv@


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3
# 1.143 09-Dec-2006 chs

a smorgasbord of improvements to vnode locking and path lookup:
- LOCKPARENT is no longer relevant for lookup(), relookup() or VOP_LOOKUP().
these now always return the parent vnode locked. namei() works as before.
lookup() and various other paths no longer acquire vnode locks in the
wrong order via vrele(). fixes PR 32535.
as a nice side effect, path lookup is also up to 25% faster.
- the above allows us to get rid of PDIRUNLOCK.
- also get rid of WANTPARENT (just use LOCKPARENT and unlock it).
- remove an assumption in layer_node_find() that all file systems implement
a recursive VOP_LOCK() (unionfs doesn't).
- require that all file systems supply vfs_vptofh and vfs_fhtovp routines.
fill in eopnotsupp() for file systems that don't support being exported
and remove the checks for NULL. (layerfs calls these without checking.)
- in union_lookup1(), don't change refcounts in the ISDOTDOT case, just
adjust which vnode is locked. fixes PR 33374.
- apply fixes for ufs_rename() from ufs_vnops.c rev. 1.61 to ext2fs_rename().


# 1.142 04-Dec-2006 christos

From Nicolas Joly: restore previous behavior in procfs_validfile_linux, since
readdir passes a NULL lwp.


# 1.141 03-Dec-2006 elad

Move kauth(9) call to where it belongs. Noticed by Nicolas Joly, thanks!


Revision tags: netbsd-4-base
# 1.140 28-Nov-2006 elad

branches: 1.140.2;
Move ktrace, ptrace, systrace, and procfs to use kauth(9).

First, remove process_checkioperm() calls from MD code. Similar checks
using kauth(9) routines (on the process scope, using appropriate action)
are done in the callers.

Add secmodel back-end to handle each subsystem.


# 1.139 25-Nov-2006 skrll

Expose the 'exe' symlink to the process realpath in NetBSD as well. An
example user is gdb.

OK'd by christos.


# 1.138 16-Nov-2006 christos

__unused removal on arguments; approved by core.


# 1.137 29-Oct-2006 christos

add an "emul" file node.


# 1.136 25-Oct-2006 christos

1. fix procfs_validfile{,_linux} to test for NULL pointers properly.
2. make "exe" entry be a symlink to the executable, instead of pointing
directly to the vnode of the executable.
3. factor out commonly used code.


Revision tags: yamt-splraiseipl-base2
# 1.135 12-Oct-2006 christos

- sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386


# 1.134 20-Sep-2006 manu

Emulate Linux's /proc/devices


Revision tags: abandoned-netbsd-4-base yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base rpaulo-netinet-merge-pcb-base
# 1.133 13-Jun-2006 yamt

branches: 1.133.6; 1.133.8;
use KAUTH_PROCESS_CANSEE rather than CURTAIN where appropriate.


# 1.132 13-Jun-2006 yamt

remove unnecessary arguments from kauth_authorize_process.
ie. make it similar to the one found in apple TN.


# 1.131 07-Jun-2006 kardel

merge FreeBSD timecounters from branch simonb-timecounters
- struct timeval time is gone
time.tv_sec -> time_second
- struct timeval mono_time is gone
mono_time.tv_sec -> time_uptime
- access to time via
{get,}{micro,nano,bin}time()
get* versions are fast but less precise
- support NTP nanokernel implementation (NTP API 4)
- further reading:
Timecounter Paper: http://phk.freebsd.dk/pubs/timecounter.pdf
NTP Nanokernel: http://www.eecis.udel.edu/~mills/ntp/html/kern.html


Revision tags: yamt-pdpolicy-base5 simonb-timecounters-base
# 1.130 14-May-2006 elad

branches: 1.130.2;
integrate kauth.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 elad-kernelauth-base yamt-pdpolicy-base yamt-uio_vmspace-base5
# 1.129 02-Feb-2006 christos

branches: 1.129.2; 1.129.4; 1.129.6; 1.129.8;
PR/32692: Matthew Mondor: linux compatibility in /proc/self should point
directly to the directory containing the pid instead of pointing to
/proc/curproc, because some programs rely on calling readlink on /proc/self
to get the pid.


# 1.128 11-Dec-2005 christos

branches: 1.128.2; 1.128.4;
merge ktrace-lwp.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base ktrace-lwp-base
# 1.127 02-Nov-2005 yamt

merge yamt-vop branch. remove following VOPs.

VOP_BLKATOFF
VOP_VALLOC
VOP_BALLOC
VOP_REALLOCBLKS
VOP_VFREE
VOP_TRUNCATE
VOP_UPDATE


Revision tags: yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 1.126 01-Oct-2005 atatat

branches: 1.126.2;
Add "cwd" and "root" symlinks to each process's directory. The cwd
link points to the process's current working directory, and the root
link points to the process's root directory. What else would you
expect?

For directories that are out of reach (caller is in a chroot, target
process is in a different chroot, etc), the links point to "/"
instead.


# 1.125 11-Sep-2005 elad

Implement curtain for procfs.


# 1.124 30-Aug-2005 xtraeme

Remove __P()


# 1.123 29-May-2005 christos

branches: 1.123.2;
- sprinkle const
- avoid shadowed variables.


Revision tags: kent-audio2-base
# 1.122 02-Apr-2005 christos

PR/29782: Martin Husemann: procfs can not unmount when some process has its
current directory in curproc. Fix from Pedro Martelletto:
We cannot call vgone() from procfs_inactive() if we are coming from
vclean(). that's what's probably causing the deadlock.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 yamt-km-base4 yamt-km-base3 netbsd-3-base
# 1.121 26-Feb-2005 perry

nuke trailing whitespace


Revision tags: yamt-km-base2 yamt-km-base kent-audio1-beforemerge kent-audio1-base
# 1.120 04-Oct-2004 yamt

branches: 1.120.4; 1.120.6;
procfs_readdir:
- return correct cookie when buffer size is small.
- simplify logic.


# 1.119 04-Oct-2004 yamt

procfs_readdir: remove a redundant assignment.


# 1.118 02-Oct-2004 yamt

procfs_getattr: correct size of /proc/self.


# 1.117 01-Oct-2004 yamt

procfs_readdir:
- fix a locking problem, using proclist_foreach_call. PR/27098.
- correct snprintf size argument.


# 1.116 01-Oct-2004 yamt

procfs_readdir: fix an offset handling bug after addition of /proc/self.


# 1.115 01-Oct-2004 yamt

procfs_readdir: use a list macro.


# 1.114 20-Sep-2004 jdolecek

add 'mounts' file for -o linux, which lists all currently mounted
filesystems; Linux glibc statvfs() uses this to get some of mount flags,
and this file is also useful as /emul/linux/etc/mtab (via symlink)


# 1.113 29-Apr-2004 jrf

Removed remaining caddr_t casts we do not need in miscfs. Recompiled
kernel and ran for a day or so. There are still some caddr_t types in
the arguments of some calls, I will do those separately (later) as
they touch a lot more of the system.
Approved by christos@NetBSD.org.


# 1.112 22-Apr-2004 itojun

sprintf -> snprintf


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.111 15-Feb-2004 jdolecek

unlock the descriptor table simple lock after fd_getfile() call in
procfs_readdir()
fixes procfs locking problems reported on current-users@, problem place
found by enami tsugutomo


# 1.110 30-Oct-2003 simonb

Remove some assigned-to but otherwise unused variables.


# 1.109 27-Sep-2003 darcy

Changes as discussed with itojun on tech-kern. I have modified the enums
to have KFS or PFS differentiators. Further I have wrapped the enum in
procfs in "#ifdef _KERNEL" as it is done in kernfs.

To see the discussion go to http://mail-index.NetBSD.org/tech-kern/2003/09/
and look for "Mismatched enums in include files" in the list.


# 1.108 07-Sep-2003 itojun

remove meaningless line (variable overwritten 2 lines below)


# 1.107 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.


# 1.106 29-Jun-2003 fvdl

branches: 1.106.2;
Back out the lwp/ktrace changes. They contained a lot of colateral damage,
and need to be examined and discussed more.


# 1.105 29-Jun-2003 thorpej

Undo part of the ktrace/lwp changes. In particular:
* Remove the "lwp *" argument that was added to vget(). Turns out
that nothing actually used it!
* Remove the "lwp *" arguments that were added to VFS_ROOT(), VFS_VGET(),
and VFS_FHTOVP(); all they did was pass it to vget() (which, as noted
above, didn't use it).
* Remove all of the "lwp *" arguments to internal functions that were added
just to appease the above.


# 1.104 28-Jun-2003 darrenr

Pass lwp pointers throughtout the kernel, as required, so that the lwpid can
be inserted into ktrace records. The general change has been to replace
"struct proc *" with "struct lwp *" in various function prototypes, pass
the lwp through and use l_proc to get the process pointer when needed.

Bump the kernel rev up to 1.6V


# 1.103 28-May-2003 christos

Add /proc/<pid>/stat for linux compat. j2sdk1.4.2 depends on it.


# 1.102 18-Apr-2003 christos

Make symlinks for directories that point to the actual directory.
Make symlinks to [kqueue] and [misc] for kqueue and misc fds.


# 1.101 17-Apr-2003 jdolecek

do not show nodes corresponding to directory descriptors for process
in fd/ subdirectory, nor allow lookup/open for the nodes
this fixes PR kern/21187 for good, and also avoids interesting directory
locking issues


# 1.100 17-Apr-2003 jdolecek

procfs_readdir(): in Pfd case, only show descriptors of types we want
how to represent (vnodes, fifo, pipes); also use fd_getfile() et al

this avoids annoying EOPNOTSUPP error messages from ls -F and such


# 1.99 17-Apr-2003 jdolecek

procfs_lookup(): use fd_getfile() et al in Pfd case


# 1.98 17-Apr-2003 jdolecek

use fd_getfile() in procfs_getfp(), and FILE_USE()/FILE_UNUSE() the
returned file descriptor pointer appropriately


# 1.97 17-Apr-2003 jdolecek

make some local arrays/variables static + const


# 1.96 10-Apr-2003 jdolecek

use former genfs_eopnotsupp_rele() as genfs_eopnotsupp(), so that vnodes
are vput()/vrele()d as necessary - some filesystems did use the wrong
one for some ops, and it's just safer to not take the chance

based on suggestion by Bill Studenmund


# 1.95 05-Apr-2003 dsl

Remove pointless check against PID_MAX. Let pfind() do the validation.
(The new pid allocation code may decide to allocate pids above PID_MAX.)


# 1.94 25-Feb-2003 jrf

This addresses PR kerm/19989. Thanks to hamajima@nagoya.ydc.co.jp for submitting this patch which enables /proc/uptime for linux emul. Patch reviewed by atatat@netbsd.org and tron@netbsd.org, approved by tron@netbsd.org.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 1.93 04-Jan-2003 martin

Cast off_t expression to long long to match format even on 64 bit
plattforms.

Shouldn't we introduce a PRIoff_t macro to create such format strings?


# 1.92 03-Jan-2003 christos

add LK_CANRECURSE in the locking of /dev/<pid>/fd/<n> and remove the curproc
kludge. Thanks to fvdl.


# 1.91 03-Jan-2003 christos

Implement /proc/<pid>/fd/<n>. This is work in progress. Questionable things:
- Is it ok to convert DTYPE_PIPE to VFIFO and DTYPE_SOCKET to VSOCK?
- XXX: Avoid locking issue in ls -Rl /proc by avoiding curproc
- Does I/O to pipes work?
- XXX: Are there security implications?


Revision tags: fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge gehenna-devsw-base kqueue-base
# 1.90 03-Aug-2002 simonb

Just use the "time" variable in the *_getattr functions instead of a call
to (the potentially expensive) microtime().


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.89 09-May-2002 thorpej

branches: 1.89.2;
Move code shared by procfs and the kernel proper out of procfs and
into the kernel proper (renaming functions from procfs_* to process_*).


Revision tags: eeh-devprop-base newlock-base ifpoll-base
# 1.88 12-Jan-2002 christos

Don't hide the real return code with EPERM.


# 1.87 06-Dec-2001 chs

add a VOP_PUTPAGES method for all the filesystems that don't have pages,
just unlock the interlock.


# 1.86 05-Dec-2001 thorpej

* Allow machine-dependent code to specify hooks for ptrace(2)
(__HAVE_PTRACE_MACHDEP) and procfs (__HAVE_PROCFS_MACHDEP).
These changes will allow platforms like x86 (XMM) and PowerPC
(AltiVec) to export extended register sets in a sane manner.

* Use __HAVE_PTRACE_MACHDEP to export x86 XMM registers (standard
FP + SSE/SSE2) using PT_{GET,SET}XMMREGS (in the machdep
ptrace request space).
* Use __HAVE_PROCFS_MACHDEP to export x86 XMM registers via
/proc/N/xmmregs in procfs.


Revision tags: thorpej-mips-cache-base
# 1.85 10-Nov-2001 lukem

add RCSIDs


# 1.84 06-Nov-2001 simonb

Remove some variables that are set but never used.


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base
# 1.83 31-Aug-2001 chs

branches: 1.83.2; 1.83.4;
map files are zero-length.


# 1.82 03-Jun-2001 chs

branches: 1.82.2;
procfs_bmap() should never be called, make it a "bad op".
let procfs_mmap() use the default error method.


Revision tags: thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 1.81 14-Apr-2001 kleink

In procfs_readdir(), give /proc/# directories DT_DIR (rather than DT_REG).


# 1.80 30-Mar-2001 fvdl

Bump va_blocksize for the map files some more, so that programs with
quite a few mappings have a chance of being handled correctly if
st_blksize is looked at.


# 1.79 29-Mar-2001 fvdl

For -o linux mounts, add some code to emulate /proc/#/maps.
Needs NAMECACHE_ENTER_REVERSE to include filenames.


# 1.78 21-Feb-2001 jdolecek

branches: 1.78.2;
make some more constant arrays 'const'


# 1.77 22-Jan-2001 jdolecek

make filesystem vnodeop, specop, fifoop and vnodeopv_* arrays const


# 1.76 17-Jan-2001 fvdl

Add a few linux-style files, only enabled when -o linux is specified
for the mount. Currently these are /proc/cpuinfo and /proc/meminfo.
The former only does something on i386 right now.


# 1.75 24-Nov-2000 chs

remove dead code and other misc cleanup.


# 1.74 09-Aug-2000 tv

Only show the "exe" entry to Linux processes, suggested by christos.
Since there are actually three struct emul's for linux, use the e_name
field to determine eligibility with strcmp().


# 1.73 09-Aug-2000 tv

Some versions of Linux libc look for /proc/.../exe instead of /proc/../file.
Add an entry for "exe" that is the same as "file", provided only if
COMPAT_LINUX is set.


# 1.72 03-Aug-2000 thorpej

MALLOC()/FREE() are not to be used for variable sized allocations.


# 1.71 28-Jun-2000 mrg

<vm/vm.h> -> <uvm/uvm_extern.h>


Revision tags: netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 1.70 30-Mar-2000 simonb

branches: 1.70.4;
Delete duplicate declaration of atopid().


Revision tags: chs-ubc2-newbase wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base fvdl-softdep-base
# 1.69 02-Sep-1999 thorpej

branches: 1.69.2; 1.69.8;
Make /proc/self a symlink to /proc/curproc. I've observed Linux programs
that expect /proc/self/cmdline to exist.


# 1.68 25-Aug-1999 sommerfeld

Change variable used for directory offset from "int" to "off_t".
Overkill, but avoids a host of truncation problems.


# 1.67 24-Aug-1999 sommerfeld

Fix PR8270:

Problem turned out to be due to improper handling of reads beyond EOF:
they should just return without error with the uio unchanged, and the
caller will recognize this as a zero-byte return (EOF).

The previous fix to protect directory reads against bogus uio_offset
values returned EINVAL, which broke mount -o union, which only
union'ed in the lower directory if the upper directory cleanly
returned EOF.

While we're here, protect kernfs as well.


# 1.66 14-Aug-1999 christos

protect against large uio_offset


# 1.65 03-Aug-1999 wrstuden

Add support for fcntl(2) to generate VOP_FCNTL calls. Any fcntl
call with F_FSCTL set and F_SETFL calls generate calls to a new
fileop fo_fcntl. Add genfs_fcntl() and soo_fcntl() which return 0
for F_SETFL and EOPNOTSUPP otherwise. Have all leaf filesystems
use genfs_fcntl().

Reviewed by: thorpej
Tested by: wrstuden


Revision tags: chs-ubc2-base
# 1.64 25-Jul-1999 thorpej

Add calls to lock the proclist as appropriate.


# 1.63 14-Jul-1999 thorpej

Fix a paste-o in procfs_lookup() introduced with the vnode locking changes.
Fixes PR #7961, Mario Kemper <magick@bundy.lip.owl.de>.


# 1.62 08-Jul-1999 wrstuden

Bump osrelease to 1.4E. Add layerfs files, remove null_subr.c.

Update coda to new struct lock in struct vnode.

make fdescfs, kernfs, portalfs, and procfs actually lock their vnodes.
It's not that hard.

Make unionfs set v_vnlock = NULL so any overlayed fs will call its
VOP_LOCK.


Revision tags: kame_141_19991130 netbsd-1-4-PATCH001 kame_14_19990705 kame_14_19990628 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.61 12-Mar-1999 christos

branches: 1.61.2; 1.61.4;
PR/7143: Jaromir Docelek: Add procfs/cmdline from Linux emulation


# 1.60 25-Jan-1999 msaitoh

Add /proc/#/map. From FreeBSD.


Revision tags: kenh-if-detach-base chs-ubc-base
# 1.59 08-Sep-1998 thorpej

- Use proclists[], rather than checking allproc and zombproc explicitly.
- Add some comments about locking.


# 1.58 13-Aug-1998 kleink

Per POSIX, fail with EINVAL if advisory locking is attempted on a file type
that doesn't support it, rather than using a homegrown EBADF or EOPNOTSUPP.


# 1.57 10-Aug-1998 matthias

create miscfs/genfs/genfs_vnops.c:genfs_enoioctl and make all the other
filesystems use it instead of a private version.


# 1.56 09-Aug-1998 perry

bzero->memset, bcopy->memcpy, bcmp->memcmp


# 1.55 03-Aug-1998 kleink

Recognize _PC_SYNC_IO.


Revision tags: eeh-paddr_t-base
# 1.54 21-Apr-1998 fvdl

procfs_readdir: in case of error, check if cookies actually have
been allocated before freeing them. From Wolfgang Solfrank.


# 1.53 01-Mar-1998 fvdl

Merge with Lite2 + local changes


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base marc-pcmcia-base
# 1.52 10-Oct-1997 fvdl

Bump last argument to VOP_READDIR to off_t (from u_long).


Revision tags: thorpej-signal-base
# 1.51 27-Aug-1997 thorpej

Fix a reversed argument which caused procfs_checkioperm() to always return
"OK". Add a few comments to avoid further confusion.


# 1.50 12-Aug-1997 thorpej

Fix the procfs hole described on current-users, similar to a fix for
FreeBSD by Sean Eric Fagan, but a bit different. This makes the checks
in the same places as sef's FreeBSD patch, but does not hardcode the
"kmem" group into the kernel, and also does a check identical to the
(3) and (4) checks in the NetBSD ptrace(2):

(1) it's not owned by you, or is set-id on exec (unless
you're root), or

(2) it's init, which controls the security level of the
entire system, and the system was not compiled with
permanently insecure mode turned on.


Revision tags: marc-pcmcia-bp
# 1.49 08-May-1997 mycroft

branches: 1.49.4;
Pass the vnode type to vaccess(), and use it when checking VEXEC. Make sure
that the mode bits passed to vaccess() and returned by foo_getattr() contain
only permission bits.


# 1.48 05-May-1997 mycroft

Need stat.h.


# 1.47 05-May-1997 mycroft

Eliminate bogus uses of V{READ,WRITE,EXEC}. Use S_I[RWX]{USR,GRP,OTH} where
appropriate.


# 1.46 28-Apr-1997 mycroft

Minor code cleanup.


Revision tags: is-newarp-before-merge is-newarp-base
# 1.45 25-Oct-1996 cgd

define path name string variables that we should not (and, thankfully, do
not) modify as 'const char *' rather 'char *'.


# 1.44 13-Oct-1996 christos

backout previous kprintf changes


# 1.43 10-Oct-1996 christos

printf -> kprintf, sprintf -> ksprintf


# 1.42 07-Sep-1996 mycroft

Implement poll(2).


# 1.41 01-Sep-1996 mycroft

Add a set of generic file system operations that most file systems use.
Also, fix some time stamp bogosities.


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 1.40 16-Mar-1996 christos

Fix printf format follies.


# 1.39 13-Feb-1996 mycroft

GC *_nullop(). Minor nits.


# 1.38 12-Feb-1996 christos

close PR/2063: procfs_rw prototyped twice with different prototypes


# 1.37 09-Feb-1996 christos

miscfs prototype changes


# 1.36 09-Feb-1996 mycroft

Fix vop_link, vop_symlink, and vop_remove semantics in several ways:
* Change the argument names to vop_link so they actually make sense.
* Implement vop_link and vop_symlink for all file systems, so they do proper
cleanup.
* Require the file system to decide whether or not linking and unlinking of
directories is allowed, and disable it for all current file systems.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.35 09-Oct-1995 mycroft

Use the index number as the cookie, rather than multiplying by UIO_MX.


# 1.34 09-Oct-1995 mycroft

Add support for cookies, mostly from Greg Hudson.


# 1.33 15-Apr-1995 cgd

fix timeval vs. timespec warnings


# 1.32 03-Feb-1995 mycroft

Return EROFS rather than ENOENT in many cases. Also some cosmetic cleanup.


# 1.31 27-Dec-1994 mycroft

Format police.


# 1.30 24-Dec-1994 ws

Implement and use a common access checking routine


# 1.29 14-Dec-1994 mycroft

Remove a_fp.


# 1.28 14-Nov-1994 christos

fixed struct comment


# 1.27 30-Oct-1994 cgd

be more careful with types, also pull in headers where necessary.


# 1.26 20-Oct-1994 cgd

update for new syscall args description mechanism


# 1.25 30-Aug-1994 mycroft

Convert process, file, and namei lists and hash tables to use queue.h.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.24 29-Jun-1994 cgd

New RCS ID's, take two. they're more aesthecially pleasant, and use 'NetBSD'


# 1.23 16-Jun-1994 mycroft

Remove an unneeded test.


# 1.22 15-Jun-1994 mycroft

Minor update from JSP after merging my changes.


# 1.21 08-Jun-1994 mycroft

Update to 4.4-Lite fs code, with local changes.


# 1.20 05-May-1994 cgd

lots of changes: prototype migration, move lots of variables, definitions,
and structure elements around. kill some unnecessary type and macro
definitions. standardize clock handling. More changes than you'd want.


# 1.19 15-Apr-1994 cgd

forgot these...


# 1.18 12-Apr-1994 cgd

be a bit smarter about determining if files shouldn't be seen by the user.
Also, DON'T allow a lookup to succeed on a file that's not visible!


# 1.17 15-Feb-1994 mycroft

Undo last change; executables is `file', not `a.out'.


# 1.16 14-Feb-1994 ws

Rename file -> a.out


# 1.15 14-Feb-1994 ws

Don't try to show a file for a process if there is none


# 1.14 28-Jan-1994 cgd

make a fpregs file.


# 1.13 20-Jan-1994 ws

Make procfs really work for debugging.
Implement not & notepg files in procfs.


# 1.12 09-Jan-1994 ws

Bug fixes and enhancements:
Make NFS serving work (BUT DON'T USE "attach" TO /proc/*/ctl FOR NOW!!!)
Make `curproc' a symbolic link
Add `.' and `..' entries to the directories.
Return better guesses on the size of the files.


# 1.11 05-Jan-1994 cgd

return size of 'reg' from getattr()


# 1.10 05-Jan-1994 cgd

make it compile (cleanly) for us


# 1.9 05-Jan-1994 cgd

add new procfs code, from Jan-Simon Pendry, jsp@sequent.com.
This is pretty-much "virgin", so that diffs can be done later.


# 1.8 18-Dec-1993 mycroft

Canonicalize all #includes.


Revision tags: magnum-base
# 1.7 16-Sep-1993 cgd

kill volatile warning.


# 1.6 07-Sep-1993 ws

branches: 1.6.2;
Changes to VFS readdir semantics
NFS changes for better cookie support
ISOFS changes for better Rockridge support and support for generation numbers


# 1.5 26-Aug-1993 pk

Implement setattr: mode for process entries; mode + uid/gid for the
PROCFS root directory.
Fixed omission in pfs_root() which came to light as a result of the above:
hold on to vnode for root dir.


# 1.4 25-Aug-1993 pk

Fixed improperly initialized nfsnode in pfs_lookup()


# 1.3 24-Aug-1993 pk

copyright update.


# 1.2 24-Aug-1993 pk

Rcs Id added.


# 1.1 24-Aug-1993 pk

branches: 1.1.1;
Initial version of a proc filesystem.


# 1.215 27-Jun-2020 christos

Introduce genfs_pathconf() and use it for the default case in all filesystems.


# 1.214 23-May-2020 ad

Move proc_lock into the data segment. It was dynamically allocated because
at the time we had mutex_obj_alloc() but not __cacheline_aligned.


# 1.213 16-May-2020 christos

Add ACL support for FFS. From FreeBSD.


# 1.212 29-Apr-2020 thorpej

If the procfs mount is marked as linux-compat, then allow proc lookup
by any LWP ID in the proc, not just the canonical PID.


Revision tags: bouyer-xenpvh-base2
# 1.211 21-Apr-2020 ad

Revert the changes made in February to make cwdinfo use mostly lockless,
which relied on taking extra vnode refs.

Having benchmarked various experimental changes over the past few months it
seems that it's better to avoid vnode refs as much as possible. cwdi_lock
as a RW lock already did that to some extent for getcwd() and will permit
the same for namei() too.


Revision tags: phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base is-mlppp-base phil-wifi-20200406 ad-namecache-base3
# 1.210 24-Feb-2020 ad

branches: 1.210.4;
v_interlock -> vmobjlock


# 1.209 23-Feb-2020 ad

Merge from ad-namecache:

- Have a stab at clustering the members of vnode_t and vnode_impl_t in a
more cache-conscious way. With that done, go back to adjusting v_usecount
with atomics and keep vi_lock directly in vnode_impl_t (saves KVA).

- Allow VOP_LOCK(LK_NONE) for the benefit of VFS_VGET() and VFS_ROOT().
Make sure LK_UPGRADE always comes with LK_NOWAIT.

- Make cwdinfo use mostly lockless.


# 1.208 01-Feb-2020 riastradh

Load struct filedesc::fd_dt with atomic_load_consume.

Exceptions: when fd_refcnt <= 1, or when holding fd_lock.

While here:

- Restore KASSERT(mutex_owned(&fdp->fd_lock)) in fd_unused.
=> This is used only in fd_close and fd_abort, where it holds.
- Move bounds check assertion in fd_putfile to where it matters.
- Store fd_dt with atomic_store_release.
- Move load of fd_dt under lock in knote_fdclose.
- Omit membar_consumer in fdesc_readdir.
=> atomic_load_consume serves the same purpose now.
=> Was needed only on alpha anyway.


Revision tags: ad-namecache-base2 ad-namecache-base1 ad-namecache-base phil-wifi-20191119
# 1.207 29-Aug-2019 hannken

branches: 1.207.2;
Add missing operation VOP_GETPAGES() returning EFAULT.

Without this operation posix_fadvise(..., POSIX_FADV_WILLNEED)
would leave the v_interlock held.

Observed by maxv@


Revision tags: netbsd-9-base phil-wifi-20190609 isaki-audio2-base
# 1.206 30-Mar-2019 christos

branches: 1.206.4;
add a node for the process resource limits.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020
# 1.205 14-Oct-2018 jdolecek

remove M_CANFAIL flag for malloc(9) - it was completely ignored, so had
actually no effect


Revision tags: pgoyette-compat-0930 pgoyette-compat-0906
# 1.204 03-Sep-2018 riastradh

Rename min/max -> uimin/uimax for better honesty.

These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER! Some subsystems have

#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)


Revision tags: pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415
# 1.203 07-Apr-2018 hannken

branches: 1.203.2;
Lock the target cwdi and take an additional reference to the
vnode we are interested in to prevent it from disappearing
before getcwd_common().

Should fix PR kern/53096 (netbsd-8 crash on heavy disk I/O)


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.202 31-Dec-2017 christos

branches: 1.202.2;
Add an environ node


Revision tags: tls-maxphys-base-20171202
# 1.201 01-Dec-2017 christos

Allow procfs_kqfilter, since we allow poll. "go" does it.


# 1.200 08-Nov-2017 christos

fix locking, remove error(1) comments.


# 1.199 08-Nov-2017 christos

use p->p_path, remove unused code.


# 1.198 28-Aug-2017 kamil

Remove the filesystem tracing feature

This is a legacy interface from 4.4BSD, and it was
introduced to overcome shortcomings of ptrace(2) at that time, which are
no longer relevant (performance). Today /proc/#/ctl offers a narrow
subset of ptrace(2) commands and is not applicable for modern
applications use beyond simplistic tracing scenarios.

This removal will simplify kernel internals. Users will still be able to
use all the other /proc files.

This change won't affect other procfs files neither Linux compat
features within mount_procfs(8). /proc/#/ctl isn't available on Linux.

Remove:
- /proc/#/ctl from mount_procfs(8)
- P_FSTRACE note from the documentation of ps(1)
- /proc/#/ctl and filesystem tracing documentation from mount_procfs(8)
- KAUTH_REQ_PROCESS_PROCFS_CTL documentation from kauth(9)
- source code file miscfs/procfs/procfs_ctl.c
- PFSctl and procfs_doctl() from sys/miscfs/procfs/procfs.h
- KAUTH_REQ_PROCESS_PROCFS_CTL from sys/sys/kauth.h
- PSL_FSTRACE (0x00010000) from sys/sys/proc.h
- P_FSTRACE (0x00010000) from sys/sys/sysctl.h

Reduce code complexity after removal of this functionality.

Update TODO.ptrace accordingly: remove two entries about /proc tracing.

Do not keep legacy notes as comments in the headers about removed
PSL_FSTRACE / P_FSTRACE, as this interface had little number of users
(close or equal to zero).

Proposed on tech-kern@.

All filesystem tracing utility users are encouraged to switch to ptrace(2).

Sponsored by <The NetBSD Foundation>


Revision tags: matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base
# 1.197 26-May-2017 riastradh

branches: 1.197.2;
Make VOP_RECLAIM do the last unlock of the vnode.

VOP_RECLAIM naturally has exclusive access to the vnode, so having it
locked on entry is not strictly necessary -- but it means if there
are any final operations that must be done on the vnode, such as
ffs_update, requiring exclusive access to it, we can now kassert that
the vnode is locked in those operations.

We can't just have the caller release the last lock because some file
systems don't use genfs_lock, and require the vnode to remain valid
for VOP_UNLOCK to work, notably unionfs.


Revision tags: prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.196 11-Apr-2017 riastradh

Make VOP_INACTIVE preserve vnode lock on return.

Discussed on tech-kern:
https://mail-index.netbsd.org/tech-kern/2017/04/01/msg021751.html

Ride 7.99.68, a bumpy bus of incremental vfs improvements!


Revision tags: jdolecek-ncq-base
# 1.195 30-Mar-2017 christos

add an auxv node.


Revision tags: pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004 localcount-20160914
# 1.194 20-Aug-2016 hannken

branches: 1.194.2;
Remove now obsolete operation vcache_remove().

Welcome to 7.99.36


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 nick-nhusb-base-20150921 nick-nhusb-base-20150606
# 1.193 20-Apr-2015 riastradh

branches: 1.193.2;
Make VOP_LINK return directory still locked and referenced.

Ride 7.99.10 bump.


Revision tags: nick-nhusb-base-20150406 nick-nhusb-base
# 1.192 05-Sep-2014 matt

branches: 1.192.2;
Try not to use f_data, use f_{vnode,socket,pipe,mqueue,kqueue,ksem} to get
a correctly typed pointer.


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.191 27-Jul-2014 hannken

branches: 1.191.2; 1.191.4; 1.191.8;
Change procfs from hashlist to vcache.
- Key is (type, pid, fd)
- Remove argument "p" from procfs_allocvp(). It is only used
when "type == PFSfd". Lookup the proc with proc_find() when
procfs_loadvnode() needs it.
- Use a vfs_vnode_iterator for procfs_revoke_vnodes().


# 1.190 25-Jul-2014 dholland

Add VOP_FALLOCATE and VOP_FDISCARD to every vnode ops table I can
find.

The filesystem ones all call genfs_eopnotsupp - right now I am only
implementing the plumbing and we can implement fallocate and/or
fdiscard for files later.

The device ones call spec_fallocate (which is also genfs_eopnotsupp)
and spec_fdiscard, which dispatches to the device-level op.

The fifo ones all call vn_fifo_bypass, which also ends up being
EOPNOTSUPP.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base
# 1.189 07-Feb-2014 hannken

branches: 1.189.2;
Change vnode operation lookup to return the resulting vnode *vpp unlocked.
Change cache_lookup() to return an unlocked vnode.

Discussed on tech-kern@

Welcome to 6.99.31


# 1.188 23-Jan-2014 hannken

Change vnode operations create, mknod, mkdir and symlink to return
the resulting vnode *vpp unlocked.

Discussed on tech-kern@

Welcome to 6.99.30


# 1.187 17-Jan-2014 hannken

Change vnode operations create, mknod, mkdir and symlink to keep the
directory node dvp locked on return.

Discussed on tech-kern@

Welcome to 6.99.29


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base
# 1.186 18-Mar-2013 plunky

branches: 1.186.6;
C99 section 6.7.2.3 (Tags) Note 3 states that:

A type specifier of the form

enum identifier

without an enumerator list shall only appear after the type it
specifies is complete.

which means that we cannot pass an "enum vtype" argument to
kauth_access_action() without fully specifying the type first.
Unfortunately there is a complicated include file loop which
makes that difficult, so convert this minimal function into a
macro (and capitalize it).

(ok elad@)


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 1.185 25-Nov-2012 christos

do something reasonable with kernel semaphores.


Revision tags: yamt-pagecache-base6 jmcneill-usbmp-base10
# 1.184 28-May-2012 christos

branches: 1.184.2;
add a task process subdirectory for emul linux


Revision tags: yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 1.183 13-Mar-2012 elad

Replace the remaining KAUTH_GENERIC_ISSUSER authorization calls with
something meaningful. All relevant documentation has been updated or
written.

Most of these changes were brought up in the following messages:

http://mail-index.netbsd.org/tech-kern/2012/01/18/msg012490.html
http://mail-index.netbsd.org/tech-kern/2012/01/19/msg012502.html
http://mail-index.netbsd.org/tech-kern/2012/02/17/msg012728.html

Thanks to christos, manu, njoly, and jmmv for input.

Huge thanks to pgoyette for spinning these changes through some build
cycles and ATF.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.182 04-Sep-2011 jmcneill

branches: 1.182.2; 1.182.6;
PR# kern/45021: Please support /emul/linux/proc/version

Add /proc/version for procfs with -o linux. The version reported depends
on the emulation type of the calling process:

$ cat /proc/version
NetBSD version 5.99.55 (netbsd@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) NetBSD 5.99.55 (GENERIC) #39: Sun Sep 4 09:10:05 EDT 2011

$ /emul/linux/bin/cat /proc/version
Linux version 2.6.18 (linux@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) #0 Wed Mar 3 03:03:03 PST 2010

$ /emul/linux32/bin/cat /proc/version
Linux version 2.6.18 (linux32@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) #0 Wed Mar 3 03:03:03 PST 2010


# 1.181 23-Jun-2011 christos

From Aleksey Cheusov: Don't make it easy for compromised systems to bypass
ASLR protections by providing the mapping addresses of programs to everyone.


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base matt-mips64-premerge-20101231 uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10 rmind-uvmplock-base
# 1.180 01-Jul-2010 rmind

Remove pfind() and pgfind(), fix locking in various broken uses of these.
Rename real routines to proc_find() and pgrp_find(), remove PFIND_* flags
and have consistent behaviour. Provide proc_find_raw() for special cases.
Fix memory leak in sysctl_proc_corename().

COMPAT_LINUX: rework ptrace() locking, minimise differences between
different versions per-arch.

Note: while this change adds some formal cosmetics for COMPAT_DARWIN and
COMPAT_IRIX - locking there is utterly broken (for ages).

Fixes PR/43176.


# 1.179 24-Jun-2010 hannken

Clean up vnode lock operations pass 2:

VOP_UNLOCK(vp, flags) -> VOP_UNLOCK(vp): Remove the unneeded flags argument.

Welcome to 5.99.32.

Discussed on tech-kern.


# 1.178 08-Jun-2010 hannken

Procfs_lookup() does not lookup directory descriptors in the fd/
subdirectory. There is no need for recursive vnode locking here.

Ok: Christos Zoulas <christos@netbsd.org>


Revision tags: uebayasi-xip-base1 yamt-nfs-mp-base9 uebayasi-xip-base
# 1.177 08-Jan-2010 pooka

branches: 1.177.2; 1.177.4;
The VATTR_NULL/VREF/VHOLD/HOLDRELE() macros lost their will to live
years ago when the kernel was modified to not alter ABI based on
DIAGNOSTIC, and now just call the respective function interfaces
(in lowercase). Plenty of mix'n match upper/lowercase has creeped
into the tree since then. Nuke the macros and convert all callsites
to lowercase.

no functional change


Revision tags: matt-premerge-20091211 yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 jym-xensuspend-nbase
# 1.176 03-Jul-2009 elad

Where possible, extract the file-system's access() routine to two internal
functions: the first checking if the operation is possible (regardless of
permissions), the second checking file-system permissions, ACLs, etc.

Mailing list reference:

http://mail-index.netbsd.org/tech-kern/2009/06/21/msg005311.html


# 1.175 23-Jun-2009 elad

Move the implementation of vaccess() to genfs_can_access(), in line with
the other routines of the same spirit.

Adjust file-system code to use it.

Keep vaccess() for KPI compatibility and to keep element of least
surprise. A "diagnostic" message warning that vaccess() is deprecated will
be printed when it's used (obviously, only in DIAGNOSTIC kernels).

No objections on tech-kern@:

http://mail-index.netbsd.org/tech-kern/2009/06/21/msg005310.html


Revision tags: yamt-nfs-mp-base5
# 1.174 24-May-2009 ad

More changes to improve kern_descrip.c.

- Avoid atomics in more places.
- Remove the per-descriptor mutex, and just use filedesc_t::fd_lock.
It was only being used to synchronize close, and in any case we needed
to take fd_lock to free the descriptor slot.
- Optimize certain paths for the <NDFDFILE case.
- Sprinkle more comments and assertions.
- Cache more stuff in filedesc_t.
- Fix numerous minor bugs spotted along the way.
- Restructure how the open files array is maintained, for clarity and so
that we can eliminate the membar_consumer() call in fd_getfile(). This is
mostly syntactic sugar; the main functional change is that fd_nfiles now
lives alongside the open file array.

Some measurements with libmicro:

- simple file syscalls are like close() are between 1 to 10% faster.
- some nice improvements, e.g. poll(1000) which is ~50% faster.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 nick-hppapmap-base2 jym-xensuspend-base nick-hppapmap-base mjf-devfs2-base
# 1.173 17-Dec-2008 cegger

branches: 1.173.2;
kill MALLOC and FREE macros.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 haad-dm-base2 haad-nbase2 ad-audiomp2-base netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 haad-dm-base
# 1.172 05-Sep-2008 skrll

branches: 1.172.2;
PR/39324 kernel diagnostic assertion "l->l_stat != LSZOMB" failed.

Ignore procs with zero or all LSZOMB LWPs. Get a non-LSZOMB LWP to perform
operations against as part of the deal.

procfs really needs to be updated to support multi-threading fully.
Hi Antti!


# 1.171 05-Sep-2008 skrll

ANSIfy


Revision tags: simonb-wapbl-nbase simonb-wapbl-base
# 1.170 02-Jul-2008 rmind

branches: 1.170.2;
Remove proc_representative_lwp(), use a simple LIST_FIRST() instead.
OK by <ad>.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base
# 1.169 28-Apr-2008 martin

branches: 1.169.2; 1.169.4;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-nfs-mp-base
# 1.168 24-Apr-2008 ad

branches: 1.168.2;
Merge proc::p_mutex and proc::p_smutex into a single adaptive mutex, since
we no longer need to guard against access from hardware interrupt handlers.

Additionally, if cloning a process with CLONE_SIGHAND, arrange to have the
child process share the parent's lock so that signal state may be kept in
sync. Partially addresses PR kern/37437.


# 1.167 24-Apr-2008 ad

Network protocol interrupts can now block on locks, so merge the globals
proclist_mutex and proclist_lock into a single adaptive mutex (proc_lock).
Implications:

- Inspecting process state requires thread context, so signals can no longer
be sent from a hardware interrupt handler. Signal activity must be
deferred to a soft interrupt or kthread.

- As the proc state locking is simplified, it's now safe to take exit()
and wait() out from under kernel_lock.

- The system spends less time at IPL_SCHED, and there is less lock activity.


Revision tags: yamt-pf42-baseX yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14
# 1.166 21-Mar-2008 ad

branches: 1.166.2;
Catch up with descriptor handling changes. See kern_descrip.c revision
1.173 for details.


Revision tags: keiichi-mipv6-nbase nick-net80211-sync-base keiichi-mipv6-base bouyer-xeni386-nbase matt-armv6-nbase mjf-devfs-base hpcarm-cleanup-base
# 1.165 23-Jan-2008 elad

branches: 1.165.6;
Tons of process scope changes.

- Add a KAUTH_PROCESS_SCHEDULER action, to handle scheduler related
requests, and add specific requests for set/get scheduler policy and
set/get scheduler parameters.

- Add a KAUTH_PROCESS_KEVENT_FILTER action, to handle kevent(2) related
requests.

- Add a KAUTH_DEVICE_TTY_STI action to handle requests to TIOCSTI.

- Add requests for the KAUTH_PROCESS_CANSEE action, indicating what
process information is being looked at (entry itself, args, env,
open files).

- Add requests for the KAUTH_PROCESS_RLIMIT action indicating set/get.

- Add requests for the KAUTH_PROCESS_CORENAME action indicating set/get.

- Make bsd44 secmodel code handle the newly added rqeuests appropriately.

All of the above make it possible to issue finer-grained kauth(9) calls in
many places, removing some KAUTH_GENERIC_ISSUSER requests.

- Remove the "CAN" from KAUTH_PROCESS_CAN{KTRACE,PROCFS,PTRACE,SIGNAL}.

Discussed with christos@ and yamt@.


Revision tags: bouyer-xeni386-base matt-armv6-base
# 1.164 02-Jan-2008 ad

Merge vmlocking2 to head.


Revision tags: vmlocking2-base3 yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 vmlocking-nbase jmcneill-pm-base reinoud-bufcleanup-base
# 1.163 26-Nov-2007 pooka

branches: 1.163.2; 1.163.6;
Remove the "struct lwp *" argument from all VFS and VOP interfaces.
The general trend is to remove it from all kernel interfaces and
this is a start. In case the calling lwp is desired, curlwp should
be used.

quick consensus on tech-kern


Revision tags: bouyer-xenamd64-base2 bouyer-xenamd64-base
# 1.162 09-Nov-2007 christos

make the last argument of procfs_dir size_t


# 1.161 07-Nov-2007 ad

Merge from vmlocking:

- pool_cache changes.
- Debugger/procfs locking fixes.
- Other minor changes.


Revision tags: jmcneill-base yamt-x86pmap-base4 yamt-x86pmap-base3 vmlocking-base
# 1.160 10-Oct-2007 ad

branches: 1.160.2; 1.160.4;
Merge from vmlocking:

- Split vnode::v_flag into three fields, depending on field locking.
- simple_lock -> kmutex in a few places.
- Fix some simple locking problems.


# 1.159 08-Oct-2007 ad

Merge file descriptor locking, cwdi locking and cross-call changes
from the vmlocking branch.


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base2 yamt-x86pmap-base matt-mips64-base
# 1.158 22-Jul-2007 pooka

branches: 1.158.4; 1.158.6; 1.158.8; 1.158.10;
Don't allow getcwd() on procfs vnodes and provide "/" as the path
instead of the result from getcwd(). The works around locking
panics caused by namei calling VOP_READLINK while holding on to a
directory lock and getcwd() trying to acquire that lock. The real
fix would be to get rid of getcwd() calls within VOPs (not locking
safe), but that's not a viable option in the netbsd-4 timeframe.

Suggestion for workaround from David Holland.


Revision tags: nick-csl-alignment-base mjf-ufs-trans-base
# 1.157 24-May-2007 agc

branches: 1.157.2;
Extend the Linux emulation of /proc to include

/proc/stat
/proc/loadavg and
/proc/<pid>/statm.

These are only present when -o linux is specified as a mount option
to procfs.

Factor out some common code so that it can be used by a number of
functions.

XXX The values returned in the statm emulation need to be verified.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 1.156 04-Apr-2007 rmind

Unfortunately, missed procfs_proc_unlock() in previous.
Pointed out by pooka@


# 1.155 04-Apr-2007 rmind

procfs_readlink: Handle a possible fail of fd_getfile(), also, we
do not need to check for error again.
CID: 4436


# 1.154 09-Mar-2007 ad

branches: 1.154.2; 1.154.4;
- Make the proclist_lock a mutex. The write:read ratio is unfavourable,
and mutexes are cheaper use than RW locks.
- LOCK_ASSERT -> KASSERT in some places.
- Hold proclist_lock/kernel_lock longer in a couple of places.


# 1.153 04-Mar-2007 christos

Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.


# 1.152 03-Mar-2007 salo

Don't prepend rootvnode to the path in non-NULL case for exe links.
It breaks procfs in chroot.

from <christos>, tested by me.


Revision tags: ad-audiomp-base
# 1.151 19-Feb-2007 pooka

When checking for file validity under pid/, do proper proc->lwp
lookup (fsvo proper) instead of fiddling directly with the lwp
list.


# 1.150 18-Feb-2007 pooka

Don't check for validity of p in lookup for root nodes, since it
will always be NULL. Rather, just call pt_valid with NULL directly
and let it decide if we're a linux mount or not.


# 1.149 17-Feb-2007 pavel

Change the process/lwp flags seen by userland via sysctl back to the
P_*/L_* naming convention, and rename the in-kernel flags to avoid
conflict. (P_ -> PK_, L_ -> LW_ ). Add back the (now unused) LSDEAD
constant.

Restores source compatibility with pre-newlock2 tools like ps or top.

Reviewed by Andrew Doran.


# 1.148 16-Feb-2007 pooka

branches: 1.148.2;
In lookup, when checking for procfs process node validity, target the
process we're trying to get information about through procfs, not
the caller of lookup.

fixes 'ls -l /proc/*/file' panic, which would occur when trying to
lookup "file" for a kernel thread, which doesn't have p->p_textvp.


# 1.147 15-Feb-2007 ad

Need to acquire procp->p_mutex for procfs_dir().


# 1.146 11-Feb-2007 ad

Eliminate a couple of reference count and mutex leaks.


Revision tags: post-newlock2-merge
# 1.145 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 1.144 25-Dec-2006 elad

PR/35226: Johann Franz: Problems with permissions in
/usr/pkg/emul/linux/proc .

Okay mlelstv@


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3
# 1.143 09-Dec-2006 chs

a smorgasbord of improvements to vnode locking and path lookup:
- LOCKPARENT is no longer relevant for lookup(), relookup() or VOP_LOOKUP().
these now always return the parent vnode locked. namei() works as before.
lookup() and various other paths no longer acquire vnode locks in the
wrong order via vrele(). fixes PR 32535.
as a nice side effect, path lookup is also up to 25% faster.
- the above allows us to get rid of PDIRUNLOCK.
- also get rid of WANTPARENT (just use LOCKPARENT and unlock it).
- remove an assumption in layer_node_find() that all file systems implement
a recursive VOP_LOCK() (unionfs doesn't).
- require that all file systems supply vfs_vptofh and vfs_fhtovp routines.
fill in eopnotsupp() for file systems that don't support being exported
and remove the checks for NULL. (layerfs calls these without checking.)
- in union_lookup1(), don't change refcounts in the ISDOTDOT case, just
adjust which vnode is locked. fixes PR 33374.
- apply fixes for ufs_rename() from ufs_vnops.c rev. 1.61 to ext2fs_rename().


# 1.142 04-Dec-2006 christos

From Nicolas Joly: restore previous behavior in procfs_validfile_linux, since
readdir passes a NULL lwp.


# 1.141 03-Dec-2006 elad

Move kauth(9) call to where it belongs. Noticed by Nicolas Joly, thanks!


Revision tags: netbsd-4-base
# 1.140 28-Nov-2006 elad

branches: 1.140.2;
Move ktrace, ptrace, systrace, and procfs to use kauth(9).

First, remove process_checkioperm() calls from MD code. Similar checks
using kauth(9) routines (on the process scope, using appropriate action)
are done in the callers.

Add secmodel back-end to handle each subsystem.


# 1.139 25-Nov-2006 skrll

Expose the 'exe' symlink to the process realpath in NetBSD as well. An
example user is gdb.

OK'd by christos.


# 1.138 16-Nov-2006 christos

__unused removal on arguments; approved by core.


# 1.137 29-Oct-2006 christos

add an "emul" file node.


# 1.136 25-Oct-2006 christos

1. fix procfs_validfile{,_linux} to test for NULL pointers properly.
2. make "exe" entry be a symlink to the executable, instead of pointing
directly to the vnode of the executable.
3. factor out commonly used code.


Revision tags: yamt-splraiseipl-base2
# 1.135 12-Oct-2006 christos

- sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386


# 1.134 20-Sep-2006 manu

Emulate Linux's /proc/devices


Revision tags: abandoned-netbsd-4-base yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base rpaulo-netinet-merge-pcb-base
# 1.133 13-Jun-2006 yamt

branches: 1.133.6; 1.133.8;
use KAUTH_PROCESS_CANSEE rather than CURTAIN where appropriate.


# 1.132 13-Jun-2006 yamt

remove unnecessary arguments from kauth_authorize_process.
ie. make it similar to the one found in apple TN.


# 1.131 07-Jun-2006 kardel

merge FreeBSD timecounters from branch simonb-timecounters
- struct timeval time is gone
time.tv_sec -> time_second
- struct timeval mono_time is gone
mono_time.tv_sec -> time_uptime
- access to time via
{get,}{micro,nano,bin}time()
get* versions are fast but less precise
- support NTP nanokernel implementation (NTP API 4)
- further reading:
Timecounter Paper: http://phk.freebsd.dk/pubs/timecounter.pdf
NTP Nanokernel: http://www.eecis.udel.edu/~mills/ntp/html/kern.html


Revision tags: yamt-pdpolicy-base5 simonb-timecounters-base
# 1.130 14-May-2006 elad

branches: 1.130.2;
integrate kauth.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 elad-kernelauth-base yamt-pdpolicy-base yamt-uio_vmspace-base5
# 1.129 02-Feb-2006 christos

branches: 1.129.2; 1.129.4; 1.129.6; 1.129.8;
PR/32692: Matthew Mondor: linux compatibility in /proc/self should point
directly to the directory containing the pid instead of pointing to
/proc/curproc, because some programs rely on calling readlink on /proc/self
to get the pid.


# 1.128 11-Dec-2005 christos

branches: 1.128.2; 1.128.4;
merge ktrace-lwp.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base ktrace-lwp-base
# 1.127 02-Nov-2005 yamt

merge yamt-vop branch. remove following VOPs.

VOP_BLKATOFF
VOP_VALLOC
VOP_BALLOC
VOP_REALLOCBLKS
VOP_VFREE
VOP_TRUNCATE
VOP_UPDATE


Revision tags: yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 1.126 01-Oct-2005 atatat

branches: 1.126.2;
Add "cwd" and "root" symlinks to each process's directory. The cwd
link points to the process's current working directory, and the root
link points to the process's root directory. What else would you
expect?

For directories that are out of reach (caller is in a chroot, target
process is in a different chroot, etc), the links point to "/"
instead.


# 1.125 11-Sep-2005 elad

Implement curtain for procfs.


# 1.124 30-Aug-2005 xtraeme

Remove __P()


# 1.123 29-May-2005 christos

branches: 1.123.2;
- sprinkle const
- avoid shadowed variables.


Revision tags: kent-audio2-base
# 1.122 02-Apr-2005 christos

PR/29782: Martin Husemann: procfs can not unmount when some process has its
current directory in curproc. Fix from Pedro Martelletto:
We cannot call vgone() from procfs_inactive() if we are coming from
vclean(). that's what's probably causing the deadlock.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 yamt-km-base4 yamt-km-base3 netbsd-3-base
# 1.121 26-Feb-2005 perry

nuke trailing whitespace


Revision tags: yamt-km-base2 yamt-km-base kent-audio1-beforemerge kent-audio1-base
# 1.120 04-Oct-2004 yamt

branches: 1.120.4; 1.120.6;
procfs_readdir:
- return correct cookie when buffer size is small.
- simplify logic.


# 1.119 04-Oct-2004 yamt

procfs_readdir: remove a redundant assignment.


# 1.118 02-Oct-2004 yamt

procfs_getattr: correct size of /proc/self.


# 1.117 01-Oct-2004 yamt

procfs_readdir:
- fix a locking problem, using proclist_foreach_call. PR/27098.
- correct snprintf size argument.


# 1.116 01-Oct-2004 yamt

procfs_readdir: fix an offset handling bug after addition of /proc/self.


# 1.115 01-Oct-2004 yamt

procfs_readdir: use a list macro.


# 1.114 20-Sep-2004 jdolecek

add 'mounts' file for -o linux, which lists all currently mounted
filesystems; Linux glibc statvfs() uses this to get some of mount flags,
and this file is also useful as /emul/linux/etc/mtab (via symlink)


# 1.113 29-Apr-2004 jrf

Removed remaining caddr_t casts we do not need in miscfs. Recompiled
kernel and ran for a day or so. There are still some caddr_t types in
the arguments of some calls, I will do those separately (later) as
they touch a lot more of the system.
Approved by christos@NetBSD.org.


# 1.112 22-Apr-2004 itojun

sprintf -> snprintf


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.111 15-Feb-2004 jdolecek

unlock the descriptor table simple lock after fd_getfile() call in
procfs_readdir()
fixes procfs locking problems reported on current-users@, problem place
found by enami tsugutomo


# 1.110 30-Oct-2003 simonb

Remove some assigned-to but otherwise unused variables.


# 1.109 27-Sep-2003 darcy

Changes as discussed with itojun on tech-kern. I have modified the enums
to have KFS or PFS differentiators. Further I have wrapped the enum in
procfs in "#ifdef _KERNEL" as it is done in kernfs.

To see the discussion go to http://mail-index.NetBSD.org/tech-kern/2003/09/
and look for "Mismatched enums in include files" in the list.


# 1.108 07-Sep-2003 itojun

remove meaningless line (variable overwritten 2 lines below)


# 1.107 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.


# 1.106 29-Jun-2003 fvdl

branches: 1.106.2;
Back out the lwp/ktrace changes. They contained a lot of colateral damage,
and need to be examined and discussed more.


# 1.105 29-Jun-2003 thorpej

Undo part of the ktrace/lwp changes. In particular:
* Remove the "lwp *" argument that was added to vget(). Turns out
that nothing actually used it!
* Remove the "lwp *" arguments that were added to VFS_ROOT(), VFS_VGET(),
and VFS_FHTOVP(); all they did was pass it to vget() (which, as noted
above, didn't use it).
* Remove all of the "lwp *" arguments to internal functions that were added
just to appease the above.


# 1.104 28-Jun-2003 darrenr

Pass lwp pointers throughtout the kernel, as required, so that the lwpid can
be inserted into ktrace records. The general change has been to replace
"struct proc *" with "struct lwp *" in various function prototypes, pass
the lwp through and use l_proc to get the process pointer when needed.

Bump the kernel rev up to 1.6V


# 1.103 28-May-2003 christos

Add /proc/<pid>/stat for linux compat. j2sdk1.4.2 depends on it.


# 1.102 18-Apr-2003 christos

Make symlinks for directories that point to the actual directory.
Make symlinks to [kqueue] and [misc] for kqueue and misc fds.


# 1.101 17-Apr-2003 jdolecek

do not show nodes corresponding to directory descriptors for process
in fd/ subdirectory, nor allow lookup/open for the nodes
this fixes PR kern/21187 for good, and also avoids interesting directory
locking issues


# 1.100 17-Apr-2003 jdolecek

procfs_readdir(): in Pfd case, only show descriptors of types we want
how to represent (vnodes, fifo, pipes); also use fd_getfile() et al

this avoids annoying EOPNOTSUPP error messages from ls -F and such


# 1.99 17-Apr-2003 jdolecek

procfs_lookup(): use fd_getfile() et al in Pfd case


# 1.98 17-Apr-2003 jdolecek

use fd_getfile() in procfs_getfp(), and FILE_USE()/FILE_UNUSE() the
returned file descriptor pointer appropriately


# 1.97 17-Apr-2003 jdolecek

make some local arrays/variables static + const


# 1.96 10-Apr-2003 jdolecek

use former genfs_eopnotsupp_rele() as genfs_eopnotsupp(), so that vnodes
are vput()/vrele()d as necessary - some filesystems did use the wrong
one for some ops, and it's just safer to not take the chance

based on suggestion by Bill Studenmund


# 1.95 05-Apr-2003 dsl

Remove pointless check against PID_MAX. Let pfind() do the validation.
(The new pid allocation code may decide to allocate pids above PID_MAX.)


# 1.94 25-Feb-2003 jrf

This addresses PR kerm/19989. Thanks to hamajima@nagoya.ydc.co.jp for submitting this patch which enables /proc/uptime for linux emul. Patch reviewed by atatat@netbsd.org and tron@netbsd.org, approved by tron@netbsd.org.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 1.93 04-Jan-2003 martin

Cast off_t expression to long long to match format even on 64 bit
plattforms.

Shouldn't we introduce a PRIoff_t macro to create such format strings?


# 1.92 03-Jan-2003 christos

add LK_CANRECURSE in the locking of /dev/<pid>/fd/<n> and remove the curproc
kludge. Thanks to fvdl.


# 1.91 03-Jan-2003 christos

Implement /proc/<pid>/fd/<n>. This is work in progress. Questionable things:
- Is it ok to convert DTYPE_PIPE to VFIFO and DTYPE_SOCKET to VSOCK?
- XXX: Avoid locking issue in ls -Rl /proc by avoiding curproc
- Does I/O to pipes work?
- XXX: Are there security implications?


Revision tags: fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge gehenna-devsw-base kqueue-base
# 1.90 03-Aug-2002 simonb

Just use the "time" variable in the *_getattr functions instead of a call
to (the potentially expensive) microtime().


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.89 09-May-2002 thorpej

branches: 1.89.2;
Move code shared by procfs and the kernel proper out of procfs and
into the kernel proper (renaming functions from procfs_* to process_*).


Revision tags: eeh-devprop-base newlock-base ifpoll-base
# 1.88 12-Jan-2002 christos

Don't hide the real return code with EPERM.


# 1.87 06-Dec-2001 chs

add a VOP_PUTPAGES method for all the filesystems that don't have pages,
just unlock the interlock.


# 1.86 05-Dec-2001 thorpej

* Allow machine-dependent code to specify hooks for ptrace(2)
(__HAVE_PTRACE_MACHDEP) and procfs (__HAVE_PROCFS_MACHDEP).
These changes will allow platforms like x86 (XMM) and PowerPC
(AltiVec) to export extended register sets in a sane manner.

* Use __HAVE_PTRACE_MACHDEP to export x86 XMM registers (standard
FP + SSE/SSE2) using PT_{GET,SET}XMMREGS (in the machdep
ptrace request space).
* Use __HAVE_PROCFS_MACHDEP to export x86 XMM registers via
/proc/N/xmmregs in procfs.


Revision tags: thorpej-mips-cache-base
# 1.85 10-Nov-2001 lukem

add RCSIDs


# 1.84 06-Nov-2001 simonb

Remove some variables that are set but never used.


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base
# 1.83 31-Aug-2001 chs

branches: 1.83.2; 1.83.4;
map files are zero-length.


# 1.82 03-Jun-2001 chs

branches: 1.82.2;
procfs_bmap() should never be called, make it a "bad op".
let procfs_mmap() use the default error method.


Revision tags: thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 1.81 14-Apr-2001 kleink

In procfs_readdir(), give /proc/# directories DT_DIR (rather than DT_REG).


# 1.80 30-Mar-2001 fvdl

Bump va_blocksize for the map files some more, so that programs with
quite a few mappings have a chance of being handled correctly if
st_blksize is looked at.


# 1.79 29-Mar-2001 fvdl

For -o linux mounts, add some code to emulate /proc/#/maps.
Needs NAMECACHE_ENTER_REVERSE to include filenames.


# 1.78 21-Feb-2001 jdolecek

branches: 1.78.2;
make some more constant arrays 'const'


# 1.77 22-Jan-2001 jdolecek

make filesystem vnodeop, specop, fifoop and vnodeopv_* arrays const


# 1.76 17-Jan-2001 fvdl

Add a few linux-style files, only enabled when -o linux is specified
for the mount. Currently these are /proc/cpuinfo and /proc/meminfo.
The former only does something on i386 right now.


# 1.75 24-Nov-2000 chs

remove dead code and other misc cleanup.


# 1.74 09-Aug-2000 tv

Only show the "exe" entry to Linux processes, suggested by christos.
Since there are actually three struct emul's for linux, use the e_name
field to determine eligibility with strcmp().


# 1.73 09-Aug-2000 tv

Some versions of Linux libc look for /proc/.../exe instead of /proc/../file.
Add an entry for "exe" that is the same as "file", provided only if
COMPAT_LINUX is set.


# 1.72 03-Aug-2000 thorpej

MALLOC()/FREE() are not to be used for variable sized allocations.


# 1.71 28-Jun-2000 mrg

<vm/vm.h> -> <uvm/uvm_extern.h>


Revision tags: netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 1.70 30-Mar-2000 simonb

branches: 1.70.4;
Delete duplicate declaration of atopid().


Revision tags: chs-ubc2-newbase wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base fvdl-softdep-base
# 1.69 02-Sep-1999 thorpej

branches: 1.69.2; 1.69.8;
Make /proc/self a symlink to /proc/curproc. I've observed Linux programs
that expect /proc/self/cmdline to exist.


# 1.68 25-Aug-1999 sommerfeld

Change variable used for directory offset from "int" to "off_t".
Overkill, but avoids a host of truncation problems.


# 1.67 24-Aug-1999 sommerfeld

Fix PR8270:

Problem turned out to be due to improper handling of reads beyond EOF:
they should just return without error with the uio unchanged, and the
caller will recognize this as a zero-byte return (EOF).

The previous fix to protect directory reads against bogus uio_offset
values returned EINVAL, which broke mount -o union, which only
union'ed in the lower directory if the upper directory cleanly
returned EOF.

While we're here, protect kernfs as well.


# 1.66 14-Aug-1999 christos

protect against large uio_offset


# 1.65 03-Aug-1999 wrstuden

Add support for fcntl(2) to generate VOP_FCNTL calls. Any fcntl
call with F_FSCTL set and F_SETFL calls generate calls to a new
fileop fo_fcntl. Add genfs_fcntl() and soo_fcntl() which return 0
for F_SETFL and EOPNOTSUPP otherwise. Have all leaf filesystems
use genfs_fcntl().

Reviewed by: thorpej
Tested by: wrstuden


Revision tags: chs-ubc2-base
# 1.64 25-Jul-1999 thorpej

Add calls to lock the proclist as appropriate.


# 1.63 14-Jul-1999 thorpej

Fix a paste-o in procfs_lookup() introduced with the vnode locking changes.
Fixes PR #7961, Mario Kemper <magick@bundy.lip.owl.de>.


# 1.62 08-Jul-1999 wrstuden

Bump osrelease to 1.4E. Add layerfs files, remove null_subr.c.

Update coda to new struct lock in struct vnode.

make fdescfs, kernfs, portalfs, and procfs actually lock their vnodes.
It's not that hard.

Make unionfs set v_vnlock = NULL so any overlayed fs will call its
VOP_LOCK.


Revision tags: kame_141_19991130 netbsd-1-4-PATCH001 kame_14_19990705 kame_14_19990628 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.61 12-Mar-1999 christos

branches: 1.61.2; 1.61.4;
PR/7143: Jaromir Docelek: Add procfs/cmdline from Linux emulation


# 1.60 25-Jan-1999 msaitoh

Add /proc/#/map. From FreeBSD.


Revision tags: kenh-if-detach-base chs-ubc-base
# 1.59 08-Sep-1998 thorpej

- Use proclists[], rather than checking allproc and zombproc explicitly.
- Add some comments about locking.


# 1.58 13-Aug-1998 kleink

Per POSIX, fail with EINVAL if advisory locking is attempted on a file type
that doesn't support it, rather than using a homegrown EBADF or EOPNOTSUPP.


# 1.57 10-Aug-1998 matthias

create miscfs/genfs/genfs_vnops.c:genfs_enoioctl and make all the other
filesystems use it instead of a private version.


# 1.56 09-Aug-1998 perry

bzero->memset, bcopy->memcpy, bcmp->memcmp


# 1.55 03-Aug-1998 kleink

Recognize _PC_SYNC_IO.


Revision tags: eeh-paddr_t-base
# 1.54 21-Apr-1998 fvdl

procfs_readdir: in case of error, check if cookies actually have
been allocated before freeing them. From Wolfgang Solfrank.


# 1.53 01-Mar-1998 fvdl

Merge with Lite2 + local changes


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base marc-pcmcia-base
# 1.52 10-Oct-1997 fvdl

Bump last argument to VOP_READDIR to off_t (from u_long).


Revision tags: thorpej-signal-base
# 1.51 27-Aug-1997 thorpej

Fix a reversed argument which caused procfs_checkioperm() to always return
"OK". Add a few comments to avoid further confusion.


# 1.50 12-Aug-1997 thorpej

Fix the procfs hole described on current-users, similar to a fix for
FreeBSD by Sean Eric Fagan, but a bit different. This makes the checks
in the same places as sef's FreeBSD patch, but does not hardcode the
"kmem" group into the kernel, and also does a check identical to the
(3) and (4) checks in the NetBSD ptrace(2):

(1) it's not owned by you, or is set-id on exec (unless
you're root), or

(2) it's init, which controls the security level of the
entire system, and the system was not compiled with
permanently insecure mode turned on.


Revision tags: marc-pcmcia-bp
# 1.49 08-May-1997 mycroft

branches: 1.49.4;
Pass the vnode type to vaccess(), and use it when checking VEXEC. Make sure
that the mode bits passed to vaccess() and returned by foo_getattr() contain
only permission bits.


# 1.48 05-May-1997 mycroft

Need stat.h.


# 1.47 05-May-1997 mycroft

Eliminate bogus uses of V{READ,WRITE,EXEC}. Use S_I[RWX]{USR,GRP,OTH} where
appropriate.


# 1.46 28-Apr-1997 mycroft

Minor code cleanup.


Revision tags: is-newarp-before-merge is-newarp-base
# 1.45 25-Oct-1996 cgd

define path name string variables that we should not (and, thankfully, do
not) modify as 'const char *' rather 'char *'.


# 1.44 13-Oct-1996 christos

backout previous kprintf changes


# 1.43 10-Oct-1996 christos

printf -> kprintf, sprintf -> ksprintf


# 1.42 07-Sep-1996 mycroft

Implement poll(2).


# 1.41 01-Sep-1996 mycroft

Add a set of generic file system operations that most file systems use.
Also, fix some time stamp bogosities.


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 1.40 16-Mar-1996 christos

Fix printf format follies.


# 1.39 13-Feb-1996 mycroft

GC *_nullop(). Minor nits.


# 1.38 12-Feb-1996 christos

close PR/2063: procfs_rw prototyped twice with different prototypes


# 1.37 09-Feb-1996 christos

miscfs prototype changes


# 1.36 09-Feb-1996 mycroft

Fix vop_link, vop_symlink, and vop_remove semantics in several ways:
* Change the argument names to vop_link so they actually make sense.
* Implement vop_link and vop_symlink for all file systems, so they do proper
cleanup.
* Require the file system to decide whether or not linking and unlinking of
directories is allowed, and disable it for all current file systems.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.35 09-Oct-1995 mycroft

Use the index number as the cookie, rather than multiplying by UIO_MX.


# 1.34 09-Oct-1995 mycroft

Add support for cookies, mostly from Greg Hudson.


# 1.33 15-Apr-1995 cgd

fix timeval vs. timespec warnings


# 1.32 03-Feb-1995 mycroft

Return EROFS rather than ENOENT in many cases. Also some cosmetic cleanup.


# 1.31 27-Dec-1994 mycroft

Format police.


# 1.30 24-Dec-1994 ws

Implement and use a common access checking routine


# 1.29 14-Dec-1994 mycroft

Remove a_fp.


# 1.28 14-Nov-1994 christos

fixed struct comment


# 1.27 30-Oct-1994 cgd

be more careful with types, also pull in headers where necessary.


# 1.26 20-Oct-1994 cgd

update for new syscall args description mechanism


# 1.25 30-Aug-1994 mycroft

Convert process, file, and namei lists and hash tables to use queue.h.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.24 29-Jun-1994 cgd

New RCS ID's, take two. they're more aesthecially pleasant, and use 'NetBSD'


# 1.23 16-Jun-1994 mycroft

Remove an unneeded test.


# 1.22 15-Jun-1994 mycroft

Minor update from JSP after merging my changes.


# 1.21 08-Jun-1994 mycroft

Update to 4.4-Lite fs code, with local changes.


# 1.20 05-May-1994 cgd

lots of changes: prototype migration, move lots of variables, definitions,
and structure elements around. kill some unnecessary type and macro
definitions. standardize clock handling. More changes than you'd want.


# 1.19 15-Apr-1994 cgd

forgot these...


# 1.18 12-Apr-1994 cgd

be a bit smarter about determining if files shouldn't be seen by the user.
Also, DON'T allow a lookup to succeed on a file that's not visible!


# 1.17 15-Feb-1994 mycroft

Undo last change; executables is `file', not `a.out'.


# 1.16 14-Feb-1994 ws

Rename file -> a.out


# 1.15 14-Feb-1994 ws

Don't try to show a file for a process if there is none


# 1.14 28-Jan-1994 cgd

make a fpregs file.


# 1.13 20-Jan-1994 ws

Make procfs really work for debugging.
Implement not & notepg files in procfs.


# 1.12 09-Jan-1994 ws

Bug fixes and enhancements:
Make NFS serving work (BUT DON'T USE "attach" TO /proc/*/ctl FOR NOW!!!)
Make `curproc' a symbolic link
Add `.' and `..' entries to the directories.
Return better guesses on the size of the files.


# 1.11 05-Jan-1994 cgd

return size of 'reg' from getattr()


# 1.10 05-Jan-1994 cgd

make it compile (cleanly) for us


# 1.9 05-Jan-1994 cgd

add new procfs code, from Jan-Simon Pendry, jsp@sequent.com.
This is pretty-much "virgin", so that diffs can be done later.


# 1.8 18-Dec-1993 mycroft

Canonicalize all #includes.


Revision tags: magnum-base
# 1.7 16-Sep-1993 cgd

kill volatile warning.


# 1.6 07-Sep-1993 ws

branches: 1.6.2;
Changes to VFS readdir semantics
NFS changes for better cookie support
ISOFS changes for better Rockridge support and support for generation numbers


# 1.5 26-Aug-1993 pk

Implement setattr: mode for process entries; mode + uid/gid for the
PROCFS root directory.
Fixed omission in pfs_root() which came to light as a result of the above:
hold on to vnode for root dir.


# 1.4 25-Aug-1993 pk

Fixed improperly initialized nfsnode in pfs_lookup()


# 1.3 24-Aug-1993 pk

copyright update.


# 1.2 24-Aug-1993 pk

Rcs Id added.


# 1.1 24-Aug-1993 pk

branches: 1.1.1;
Initial version of a proc filesystem.


# 1.214 23-May-2020 ad

Move proc_lock into the data segment. It was dynamically allocated because
at the time we had mutex_obj_alloc() but not __cacheline_aligned.


# 1.213 16-May-2020 christos

Add ACL support for FFS. From FreeBSD.


# 1.212 29-Apr-2020 thorpej

If the procfs mount is marked as linux-compat, then allow proc lookup
by any LWP ID in the proc, not just the canonical PID.


Revision tags: bouyer-xenpvh-base2
# 1.211 21-Apr-2020 ad

Revert the changes made in February to make cwdinfo use mostly lockless,
which relied on taking extra vnode refs.

Having benchmarked various experimental changes over the past few months it
seems that it's better to avoid vnode refs as much as possible. cwdi_lock
as a RW lock already did that to some extent for getcwd() and will permit
the same for namei() too.


Revision tags: phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base is-mlppp-base phil-wifi-20200406 ad-namecache-base3
# 1.210 24-Feb-2020 ad

branches: 1.210.4;
v_interlock -> vmobjlock


# 1.209 23-Feb-2020 ad

Merge from ad-namecache:

- Have a stab at clustering the members of vnode_t and vnode_impl_t in a
more cache-conscious way. With that done, go back to adjusting v_usecount
with atomics and keep vi_lock directly in vnode_impl_t (saves KVA).

- Allow VOP_LOCK(LK_NONE) for the benefit of VFS_VGET() and VFS_ROOT().
Make sure LK_UPGRADE always comes with LK_NOWAIT.

- Make cwdinfo use mostly lockless.


# 1.208 01-Feb-2020 riastradh

Load struct filedesc::fd_dt with atomic_load_consume.

Exceptions: when fd_refcnt <= 1, or when holding fd_lock.

While here:

- Restore KASSERT(mutex_owned(&fdp->fd_lock)) in fd_unused.
=> This is used only in fd_close and fd_abort, where it holds.
- Move bounds check assertion in fd_putfile to where it matters.
- Store fd_dt with atomic_store_release.
- Move load of fd_dt under lock in knote_fdclose.
- Omit membar_consumer in fdesc_readdir.
=> atomic_load_consume serves the same purpose now.
=> Was needed only on alpha anyway.


Revision tags: ad-namecache-base2 ad-namecache-base1 ad-namecache-base phil-wifi-20191119
# 1.207 29-Aug-2019 hannken

branches: 1.207.2;
Add missing operation VOP_GETPAGES() returning EFAULT.

Without this operation posix_fadvise(..., POSIX_FADV_WILLNEED)
would leave the v_interlock held.

Observed by maxv@


Revision tags: netbsd-9-base phil-wifi-20190609 isaki-audio2-base
# 1.206 30-Mar-2019 christos

branches: 1.206.4;
add a node for the process resource limits.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020
# 1.205 14-Oct-2018 jdolecek

remove M_CANFAIL flag for malloc(9) - it was completely ignored, so had
actually no effect


Revision tags: pgoyette-compat-0930 pgoyette-compat-0906
# 1.204 03-Sep-2018 riastradh

Rename min/max -> uimin/uimax for better honesty.

These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER! Some subsystems have

#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)


Revision tags: pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415
# 1.203 07-Apr-2018 hannken

branches: 1.203.2;
Lock the target cwdi and take an additional reference to the
vnode we are interested in to prevent it from disappearing
before getcwd_common().

Should fix PR kern/53096 (netbsd-8 crash on heavy disk I/O)


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.202 31-Dec-2017 christos

branches: 1.202.2;
Add an environ node


Revision tags: tls-maxphys-base-20171202
# 1.201 01-Dec-2017 christos

Allow procfs_kqfilter, since we allow poll. "go" does it.


# 1.200 08-Nov-2017 christos

fix locking, remove error(1) comments.


# 1.199 08-Nov-2017 christos

use p->p_path, remove unused code.


# 1.198 28-Aug-2017 kamil

Remove the filesystem tracing feature

This is a legacy interface from 4.4BSD, and it was
introduced to overcome shortcomings of ptrace(2) at that time, which are
no longer relevant (performance). Today /proc/#/ctl offers a narrow
subset of ptrace(2) commands and is not applicable for modern
applications use beyond simplistic tracing scenarios.

This removal will simplify kernel internals. Users will still be able to
use all the other /proc files.

This change won't affect other procfs files neither Linux compat
features within mount_procfs(8). /proc/#/ctl isn't available on Linux.

Remove:
- /proc/#/ctl from mount_procfs(8)
- P_FSTRACE note from the documentation of ps(1)
- /proc/#/ctl and filesystem tracing documentation from mount_procfs(8)
- KAUTH_REQ_PROCESS_PROCFS_CTL documentation from kauth(9)
- source code file miscfs/procfs/procfs_ctl.c
- PFSctl and procfs_doctl() from sys/miscfs/procfs/procfs.h
- KAUTH_REQ_PROCESS_PROCFS_CTL from sys/sys/kauth.h
- PSL_FSTRACE (0x00010000) from sys/sys/proc.h
- P_FSTRACE (0x00010000) from sys/sys/sysctl.h

Reduce code complexity after removal of this functionality.

Update TODO.ptrace accordingly: remove two entries about /proc tracing.

Do not keep legacy notes as comments in the headers about removed
PSL_FSTRACE / P_FSTRACE, as this interface had little number of users
(close or equal to zero).

Proposed on tech-kern@.

All filesystem tracing utility users are encouraged to switch to ptrace(2).

Sponsored by <The NetBSD Foundation>


Revision tags: matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base
# 1.197 26-May-2017 riastradh

branches: 1.197.2;
Make VOP_RECLAIM do the last unlock of the vnode.

VOP_RECLAIM naturally has exclusive access to the vnode, so having it
locked on entry is not strictly necessary -- but it means if there
are any final operations that must be done on the vnode, such as
ffs_update, requiring exclusive access to it, we can now kassert that
the vnode is locked in those operations.

We can't just have the caller release the last lock because some file
systems don't use genfs_lock, and require the vnode to remain valid
for VOP_UNLOCK to work, notably unionfs.


Revision tags: prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.196 11-Apr-2017 riastradh

Make VOP_INACTIVE preserve vnode lock on return.

Discussed on tech-kern:
https://mail-index.netbsd.org/tech-kern/2017/04/01/msg021751.html

Ride 7.99.68, a bumpy bus of incremental vfs improvements!


Revision tags: jdolecek-ncq-base
# 1.195 30-Mar-2017 christos

add an auxv node.


Revision tags: pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004 localcount-20160914
# 1.194 20-Aug-2016 hannken

branches: 1.194.2;
Remove now obsolete operation vcache_remove().

Welcome to 7.99.36


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 nick-nhusb-base-20150921 nick-nhusb-base-20150606
# 1.193 20-Apr-2015 riastradh

branches: 1.193.2;
Make VOP_LINK return directory still locked and referenced.

Ride 7.99.10 bump.


Revision tags: nick-nhusb-base-20150406 nick-nhusb-base
# 1.192 05-Sep-2014 matt

branches: 1.192.2;
Try not to use f_data, use f_{vnode,socket,pipe,mqueue,kqueue,ksem} to get
a correctly typed pointer.


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.191 27-Jul-2014 hannken

branches: 1.191.2; 1.191.4; 1.191.8;
Change procfs from hashlist to vcache.
- Key is (type, pid, fd)
- Remove argument "p" from procfs_allocvp(). It is only used
when "type == PFSfd". Lookup the proc with proc_find() when
procfs_loadvnode() needs it.
- Use a vfs_vnode_iterator for procfs_revoke_vnodes().


# 1.190 25-Jul-2014 dholland

Add VOP_FALLOCATE and VOP_FDISCARD to every vnode ops table I can
find.

The filesystem ones all call genfs_eopnotsupp - right now I am only
implementing the plumbing and we can implement fallocate and/or
fdiscard for files later.

The device ones call spec_fallocate (which is also genfs_eopnotsupp)
and spec_fdiscard, which dispatches to the device-level op.

The fifo ones all call vn_fifo_bypass, which also ends up being
EOPNOTSUPP.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base
# 1.189 07-Feb-2014 hannken

branches: 1.189.2;
Change vnode operation lookup to return the resulting vnode *vpp unlocked.
Change cache_lookup() to return an unlocked vnode.

Discussed on tech-kern@

Welcome to 6.99.31


# 1.188 23-Jan-2014 hannken

Change vnode operations create, mknod, mkdir and symlink to return
the resulting vnode *vpp unlocked.

Discussed on tech-kern@

Welcome to 6.99.30


# 1.187 17-Jan-2014 hannken

Change vnode operations create, mknod, mkdir and symlink to keep the
directory node dvp locked on return.

Discussed on tech-kern@

Welcome to 6.99.29


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base
# 1.186 18-Mar-2013 plunky

branches: 1.186.6;
C99 section 6.7.2.3 (Tags) Note 3 states that:

A type specifier of the form

enum identifier

without an enumerator list shall only appear after the type it
specifies is complete.

which means that we cannot pass an "enum vtype" argument to
kauth_access_action() without fully specifying the type first.
Unfortunately there is a complicated include file loop which
makes that difficult, so convert this minimal function into a
macro (and capitalize it).

(ok elad@)


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 1.185 25-Nov-2012 christos

do something reasonable with kernel semaphores.


Revision tags: yamt-pagecache-base6 jmcneill-usbmp-base10
# 1.184 28-May-2012 christos

branches: 1.184.2;
add a task process subdirectory for emul linux


Revision tags: yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 1.183 13-Mar-2012 elad

Replace the remaining KAUTH_GENERIC_ISSUSER authorization calls with
something meaningful. All relevant documentation has been updated or
written.

Most of these changes were brought up in the following messages:

http://mail-index.netbsd.org/tech-kern/2012/01/18/msg012490.html
http://mail-index.netbsd.org/tech-kern/2012/01/19/msg012502.html
http://mail-index.netbsd.org/tech-kern/2012/02/17/msg012728.html

Thanks to christos, manu, njoly, and jmmv for input.

Huge thanks to pgoyette for spinning these changes through some build
cycles and ATF.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.182 04-Sep-2011 jmcneill

branches: 1.182.2; 1.182.6;
PR# kern/45021: Please support /emul/linux/proc/version

Add /proc/version for procfs with -o linux. The version reported depends
on the emulation type of the calling process:

$ cat /proc/version
NetBSD version 5.99.55 (netbsd@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) NetBSD 5.99.55 (GENERIC) #39: Sun Sep 4 09:10:05 EDT 2011

$ /emul/linux/bin/cat /proc/version
Linux version 2.6.18 (linux@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) #0 Wed Mar 3 03:03:03 PST 2010

$ /emul/linux32/bin/cat /proc/version
Linux version 2.6.18 (linux32@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) #0 Wed Mar 3 03:03:03 PST 2010


# 1.181 23-Jun-2011 christos

From Aleksey Cheusov: Don't make it easy for compromised systems to bypass
ASLR protections by providing the mapping addresses of programs to everyone.


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base matt-mips64-premerge-20101231 uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10 rmind-uvmplock-base
# 1.180 01-Jul-2010 rmind

Remove pfind() and pgfind(), fix locking in various broken uses of these.
Rename real routines to proc_find() and pgrp_find(), remove PFIND_* flags
and have consistent behaviour. Provide proc_find_raw() for special cases.
Fix memory leak in sysctl_proc_corename().

COMPAT_LINUX: rework ptrace() locking, minimise differences between
different versions per-arch.

Note: while this change adds some formal cosmetics for COMPAT_DARWIN and
COMPAT_IRIX - locking there is utterly broken (for ages).

Fixes PR/43176.


# 1.179 24-Jun-2010 hannken

Clean up vnode lock operations pass 2:

VOP_UNLOCK(vp, flags) -> VOP_UNLOCK(vp): Remove the unneeded flags argument.

Welcome to 5.99.32.

Discussed on tech-kern.


# 1.178 08-Jun-2010 hannken

Procfs_lookup() does not lookup directory descriptors in the fd/
subdirectory. There is no need for recursive vnode locking here.

Ok: Christos Zoulas <christos@netbsd.org>


Revision tags: uebayasi-xip-base1 yamt-nfs-mp-base9 uebayasi-xip-base
# 1.177 08-Jan-2010 pooka

branches: 1.177.2; 1.177.4;
The VATTR_NULL/VREF/VHOLD/HOLDRELE() macros lost their will to live
years ago when the kernel was modified to not alter ABI based on
DIAGNOSTIC, and now just call the respective function interfaces
(in lowercase). Plenty of mix'n match upper/lowercase has creeped
into the tree since then. Nuke the macros and convert all callsites
to lowercase.

no functional change


Revision tags: matt-premerge-20091211 yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 jym-xensuspend-nbase
# 1.176 03-Jul-2009 elad

Where possible, extract the file-system's access() routine to two internal
functions: the first checking if the operation is possible (regardless of
permissions), the second checking file-system permissions, ACLs, etc.

Mailing list reference:

http://mail-index.netbsd.org/tech-kern/2009/06/21/msg005311.html


# 1.175 23-Jun-2009 elad

Move the implementation of vaccess() to genfs_can_access(), in line with
the other routines of the same spirit.

Adjust file-system code to use it.

Keep vaccess() for KPI compatibility and to keep element of least
surprise. A "diagnostic" message warning that vaccess() is deprecated will
be printed when it's used (obviously, only in DIAGNOSTIC kernels).

No objections on tech-kern@:

http://mail-index.netbsd.org/tech-kern/2009/06/21/msg005310.html


Revision tags: yamt-nfs-mp-base5
# 1.174 24-May-2009 ad

More changes to improve kern_descrip.c.

- Avoid atomics in more places.
- Remove the per-descriptor mutex, and just use filedesc_t::fd_lock.
It was only being used to synchronize close, and in any case we needed
to take fd_lock to free the descriptor slot.
- Optimize certain paths for the <NDFDFILE case.
- Sprinkle more comments and assertions.
- Cache more stuff in filedesc_t.
- Fix numerous minor bugs spotted along the way.
- Restructure how the open files array is maintained, for clarity and so
that we can eliminate the membar_consumer() call in fd_getfile(). This is
mostly syntactic sugar; the main functional change is that fd_nfiles now
lives alongside the open file array.

Some measurements with libmicro:

- simple file syscalls are like close() are between 1 to 10% faster.
- some nice improvements, e.g. poll(1000) which is ~50% faster.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 nick-hppapmap-base2 jym-xensuspend-base nick-hppapmap-base mjf-devfs2-base
# 1.173 17-Dec-2008 cegger

branches: 1.173.2;
kill MALLOC and FREE macros.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 haad-dm-base2 haad-nbase2 ad-audiomp2-base netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 haad-dm-base
# 1.172 05-Sep-2008 skrll

branches: 1.172.2;
PR/39324 kernel diagnostic assertion "l->l_stat != LSZOMB" failed.

Ignore procs with zero or all LSZOMB LWPs. Get a non-LSZOMB LWP to perform
operations against as part of the deal.

procfs really needs to be updated to support multi-threading fully.
Hi Antti!


# 1.171 05-Sep-2008 skrll

ANSIfy


Revision tags: simonb-wapbl-nbase simonb-wapbl-base
# 1.170 02-Jul-2008 rmind

branches: 1.170.2;
Remove proc_representative_lwp(), use a simple LIST_FIRST() instead.
OK by <ad>.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base
# 1.169 28-Apr-2008 martin

branches: 1.169.2; 1.169.4;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-nfs-mp-base
# 1.168 24-Apr-2008 ad

branches: 1.168.2;
Merge proc::p_mutex and proc::p_smutex into a single adaptive mutex, since
we no longer need to guard against access from hardware interrupt handlers.

Additionally, if cloning a process with CLONE_SIGHAND, arrange to have the
child process share the parent's lock so that signal state may be kept in
sync. Partially addresses PR kern/37437.


# 1.167 24-Apr-2008 ad

Network protocol interrupts can now block on locks, so merge the globals
proclist_mutex and proclist_lock into a single adaptive mutex (proc_lock).
Implications:

- Inspecting process state requires thread context, so signals can no longer
be sent from a hardware interrupt handler. Signal activity must be
deferred to a soft interrupt or kthread.

- As the proc state locking is simplified, it's now safe to take exit()
and wait() out from under kernel_lock.

- The system spends less time at IPL_SCHED, and there is less lock activity.


Revision tags: yamt-pf42-baseX yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14
# 1.166 21-Mar-2008 ad

branches: 1.166.2;
Catch up with descriptor handling changes. See kern_descrip.c revision
1.173 for details.


Revision tags: keiichi-mipv6-nbase nick-net80211-sync-base keiichi-mipv6-base bouyer-xeni386-nbase matt-armv6-nbase mjf-devfs-base hpcarm-cleanup-base
# 1.165 23-Jan-2008 elad

branches: 1.165.6;
Tons of process scope changes.

- Add a KAUTH_PROCESS_SCHEDULER action, to handle scheduler related
requests, and add specific requests for set/get scheduler policy and
set/get scheduler parameters.

- Add a KAUTH_PROCESS_KEVENT_FILTER action, to handle kevent(2) related
requests.

- Add a KAUTH_DEVICE_TTY_STI action to handle requests to TIOCSTI.

- Add requests for the KAUTH_PROCESS_CANSEE action, indicating what
process information is being looked at (entry itself, args, env,
open files).

- Add requests for the KAUTH_PROCESS_RLIMIT action indicating set/get.

- Add requests for the KAUTH_PROCESS_CORENAME action indicating set/get.

- Make bsd44 secmodel code handle the newly added rqeuests appropriately.

All of the above make it possible to issue finer-grained kauth(9) calls in
many places, removing some KAUTH_GENERIC_ISSUSER requests.

- Remove the "CAN" from KAUTH_PROCESS_CAN{KTRACE,PROCFS,PTRACE,SIGNAL}.

Discussed with christos@ and yamt@.


Revision tags: bouyer-xeni386-base matt-armv6-base
# 1.164 02-Jan-2008 ad

Merge vmlocking2 to head.


Revision tags: vmlocking2-base3 yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 vmlocking-nbase jmcneill-pm-base reinoud-bufcleanup-base
# 1.163 26-Nov-2007 pooka

branches: 1.163.2; 1.163.6;
Remove the "struct lwp *" argument from all VFS and VOP interfaces.
The general trend is to remove it from all kernel interfaces and
this is a start. In case the calling lwp is desired, curlwp should
be used.

quick consensus on tech-kern


Revision tags: bouyer-xenamd64-base2 bouyer-xenamd64-base
# 1.162 09-Nov-2007 christos

make the last argument of procfs_dir size_t


# 1.161 07-Nov-2007 ad

Merge from vmlocking:

- pool_cache changes.
- Debugger/procfs locking fixes.
- Other minor changes.


Revision tags: jmcneill-base yamt-x86pmap-base4 yamt-x86pmap-base3 vmlocking-base
# 1.160 10-Oct-2007 ad

branches: 1.160.2; 1.160.4;
Merge from vmlocking:

- Split vnode::v_flag into three fields, depending on field locking.
- simple_lock -> kmutex in a few places.
- Fix some simple locking problems.


# 1.159 08-Oct-2007 ad

Merge file descriptor locking, cwdi locking and cross-call changes
from the vmlocking branch.


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base2 yamt-x86pmap-base matt-mips64-base
# 1.158 22-Jul-2007 pooka

branches: 1.158.4; 1.158.6; 1.158.8; 1.158.10;
Don't allow getcwd() on procfs vnodes and provide "/" as the path
instead of the result from getcwd(). The works around locking
panics caused by namei calling VOP_READLINK while holding on to a
directory lock and getcwd() trying to acquire that lock. The real
fix would be to get rid of getcwd() calls within VOPs (not locking
safe), but that's not a viable option in the netbsd-4 timeframe.

Suggestion for workaround from David Holland.


Revision tags: nick-csl-alignment-base mjf-ufs-trans-base
# 1.157 24-May-2007 agc

branches: 1.157.2;
Extend the Linux emulation of /proc to include

/proc/stat
/proc/loadavg and
/proc/<pid>/statm.

These are only present when -o linux is specified as a mount option
to procfs.

Factor out some common code so that it can be used by a number of
functions.

XXX The values returned in the statm emulation need to be verified.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 1.156 04-Apr-2007 rmind

Unfortunately, missed procfs_proc_unlock() in previous.
Pointed out by pooka@


# 1.155 04-Apr-2007 rmind

procfs_readlink: Handle a possible fail of fd_getfile(), also, we
do not need to check for error again.
CID: 4436


# 1.154 09-Mar-2007 ad

branches: 1.154.2; 1.154.4;
- Make the proclist_lock a mutex. The write:read ratio is unfavourable,
and mutexes are cheaper use than RW locks.
- LOCK_ASSERT -> KASSERT in some places.
- Hold proclist_lock/kernel_lock longer in a couple of places.


# 1.153 04-Mar-2007 christos

Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.


# 1.152 03-Mar-2007 salo

Don't prepend rootvnode to the path in non-NULL case for exe links.
It breaks procfs in chroot.

from <christos>, tested by me.


Revision tags: ad-audiomp-base
# 1.151 19-Feb-2007 pooka

When checking for file validity under pid/, do proper proc->lwp
lookup (fsvo proper) instead of fiddling directly with the lwp
list.


# 1.150 18-Feb-2007 pooka

Don't check for validity of p in lookup for root nodes, since it
will always be NULL. Rather, just call pt_valid with NULL directly
and let it decide if we're a linux mount or not.


# 1.149 17-Feb-2007 pavel

Change the process/lwp flags seen by userland via sysctl back to the
P_*/L_* naming convention, and rename the in-kernel flags to avoid
conflict. (P_ -> PK_, L_ -> LW_ ). Add back the (now unused) LSDEAD
constant.

Restores source compatibility with pre-newlock2 tools like ps or top.

Reviewed by Andrew Doran.


# 1.148 16-Feb-2007 pooka

branches: 1.148.2;
In lookup, when checking for procfs process node validity, target the
process we're trying to get information about through procfs, not
the caller of lookup.

fixes 'ls -l /proc/*/file' panic, which would occur when trying to
lookup "file" for a kernel thread, which doesn't have p->p_textvp.


# 1.147 15-Feb-2007 ad

Need to acquire procp->p_mutex for procfs_dir().


# 1.146 11-Feb-2007 ad

Eliminate a couple of reference count and mutex leaks.


Revision tags: post-newlock2-merge
# 1.145 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 1.144 25-Dec-2006 elad

PR/35226: Johann Franz: Problems with permissions in
/usr/pkg/emul/linux/proc .

Okay mlelstv@


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3
# 1.143 09-Dec-2006 chs

a smorgasbord of improvements to vnode locking and path lookup:
- LOCKPARENT is no longer relevant for lookup(), relookup() or VOP_LOOKUP().
these now always return the parent vnode locked. namei() works as before.
lookup() and various other paths no longer acquire vnode locks in the
wrong order via vrele(). fixes PR 32535.
as a nice side effect, path lookup is also up to 25% faster.
- the above allows us to get rid of PDIRUNLOCK.
- also get rid of WANTPARENT (just use LOCKPARENT and unlock it).
- remove an assumption in layer_node_find() that all file systems implement
a recursive VOP_LOCK() (unionfs doesn't).
- require that all file systems supply vfs_vptofh and vfs_fhtovp routines.
fill in eopnotsupp() for file systems that don't support being exported
and remove the checks for NULL. (layerfs calls these without checking.)
- in union_lookup1(), don't change refcounts in the ISDOTDOT case, just
adjust which vnode is locked. fixes PR 33374.
- apply fixes for ufs_rename() from ufs_vnops.c rev. 1.61 to ext2fs_rename().


# 1.142 04-Dec-2006 christos

From Nicolas Joly: restore previous behavior in procfs_validfile_linux, since
readdir passes a NULL lwp.


# 1.141 03-Dec-2006 elad

Move kauth(9) call to where it belongs. Noticed by Nicolas Joly, thanks!


Revision tags: netbsd-4-base
# 1.140 28-Nov-2006 elad

branches: 1.140.2;
Move ktrace, ptrace, systrace, and procfs to use kauth(9).

First, remove process_checkioperm() calls from MD code. Similar checks
using kauth(9) routines (on the process scope, using appropriate action)
are done in the callers.

Add secmodel back-end to handle each subsystem.


# 1.139 25-Nov-2006 skrll

Expose the 'exe' symlink to the process realpath in NetBSD as well. An
example user is gdb.

OK'd by christos.


# 1.138 16-Nov-2006 christos

__unused removal on arguments; approved by core.


# 1.137 29-Oct-2006 christos

add an "emul" file node.


# 1.136 25-Oct-2006 christos

1. fix procfs_validfile{,_linux} to test for NULL pointers properly.
2. make "exe" entry be a symlink to the executable, instead of pointing
directly to the vnode of the executable.
3. factor out commonly used code.


Revision tags: yamt-splraiseipl-base2
# 1.135 12-Oct-2006 christos

- sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386


# 1.134 20-Sep-2006 manu

Emulate Linux's /proc/devices


Revision tags: abandoned-netbsd-4-base yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base rpaulo-netinet-merge-pcb-base
# 1.133 13-Jun-2006 yamt

branches: 1.133.6; 1.133.8;
use KAUTH_PROCESS_CANSEE rather than CURTAIN where appropriate.


# 1.132 13-Jun-2006 yamt

remove unnecessary arguments from kauth_authorize_process.
ie. make it similar to the one found in apple TN.


# 1.131 07-Jun-2006 kardel

merge FreeBSD timecounters from branch simonb-timecounters
- struct timeval time is gone
time.tv_sec -> time_second
- struct timeval mono_time is gone
mono_time.tv_sec -> time_uptime
- access to time via
{get,}{micro,nano,bin}time()
get* versions are fast but less precise
- support NTP nanokernel implementation (NTP API 4)
- further reading:
Timecounter Paper: http://phk.freebsd.dk/pubs/timecounter.pdf
NTP Nanokernel: http://www.eecis.udel.edu/~mills/ntp/html/kern.html


Revision tags: yamt-pdpolicy-base5 simonb-timecounters-base
# 1.130 14-May-2006 elad

branches: 1.130.2;
integrate kauth.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 elad-kernelauth-base yamt-pdpolicy-base yamt-uio_vmspace-base5
# 1.129 02-Feb-2006 christos

branches: 1.129.2; 1.129.4; 1.129.6; 1.129.8;
PR/32692: Matthew Mondor: linux compatibility in /proc/self should point
directly to the directory containing the pid instead of pointing to
/proc/curproc, because some programs rely on calling readlink on /proc/self
to get the pid.


# 1.128 11-Dec-2005 christos

branches: 1.128.2; 1.128.4;
merge ktrace-lwp.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base ktrace-lwp-base
# 1.127 02-Nov-2005 yamt

merge yamt-vop branch. remove following VOPs.

VOP_BLKATOFF
VOP_VALLOC
VOP_BALLOC
VOP_REALLOCBLKS
VOP_VFREE
VOP_TRUNCATE
VOP_UPDATE


Revision tags: yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 1.126 01-Oct-2005 atatat

branches: 1.126.2;
Add "cwd" and "root" symlinks to each process's directory. The cwd
link points to the process's current working directory, and the root
link points to the process's root directory. What else would you
expect?

For directories that are out of reach (caller is in a chroot, target
process is in a different chroot, etc), the links point to "/"
instead.


# 1.125 11-Sep-2005 elad

Implement curtain for procfs.


# 1.124 30-Aug-2005 xtraeme

Remove __P()


# 1.123 29-May-2005 christos

branches: 1.123.2;
- sprinkle const
- avoid shadowed variables.


Revision tags: kent-audio2-base
# 1.122 02-Apr-2005 christos

PR/29782: Martin Husemann: procfs can not unmount when some process has its
current directory in curproc. Fix from Pedro Martelletto:
We cannot call vgone() from procfs_inactive() if we are coming from
vclean(). that's what's probably causing the deadlock.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 yamt-km-base4 yamt-km-base3 netbsd-3-base
# 1.121 26-Feb-2005 perry

nuke trailing whitespace


Revision tags: yamt-km-base2 yamt-km-base kent-audio1-beforemerge kent-audio1-base
# 1.120 04-Oct-2004 yamt

branches: 1.120.4; 1.120.6;
procfs_readdir:
- return correct cookie when buffer size is small.
- simplify logic.


# 1.119 04-Oct-2004 yamt

procfs_readdir: remove a redundant assignment.


# 1.118 02-Oct-2004 yamt

procfs_getattr: correct size of /proc/self.


# 1.117 01-Oct-2004 yamt

procfs_readdir:
- fix a locking problem, using proclist_foreach_call. PR/27098.
- correct snprintf size argument.


# 1.116 01-Oct-2004 yamt

procfs_readdir: fix an offset handling bug after addition of /proc/self.


# 1.115 01-Oct-2004 yamt

procfs_readdir: use a list macro.


# 1.114 20-Sep-2004 jdolecek

add 'mounts' file for -o linux, which lists all currently mounted
filesystems; Linux glibc statvfs() uses this to get some of mount flags,
and this file is also useful as /emul/linux/etc/mtab (via symlink)


# 1.113 29-Apr-2004 jrf

Removed remaining caddr_t casts we do not need in miscfs. Recompiled
kernel and ran for a day or so. There are still some caddr_t types in
the arguments of some calls, I will do those separately (later) as
they touch a lot more of the system.
Approved by christos@NetBSD.org.


# 1.112 22-Apr-2004 itojun

sprintf -> snprintf


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.111 15-Feb-2004 jdolecek

unlock the descriptor table simple lock after fd_getfile() call in
procfs_readdir()
fixes procfs locking problems reported on current-users@, problem place
found by enami tsugutomo


# 1.110 30-Oct-2003 simonb

Remove some assigned-to but otherwise unused variables.


# 1.109 27-Sep-2003 darcy

Changes as discussed with itojun on tech-kern. I have modified the enums
to have KFS or PFS differentiators. Further I have wrapped the enum in
procfs in "#ifdef _KERNEL" as it is done in kernfs.

To see the discussion go to http://mail-index.NetBSD.org/tech-kern/2003/09/
and look for "Mismatched enums in include files" in the list.


# 1.108 07-Sep-2003 itojun

remove meaningless line (variable overwritten 2 lines below)


# 1.107 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.


# 1.106 29-Jun-2003 fvdl

branches: 1.106.2;
Back out the lwp/ktrace changes. They contained a lot of colateral damage,
and need to be examined and discussed more.


# 1.105 29-Jun-2003 thorpej

Undo part of the ktrace/lwp changes. In particular:
* Remove the "lwp *" argument that was added to vget(). Turns out
that nothing actually used it!
* Remove the "lwp *" arguments that were added to VFS_ROOT(), VFS_VGET(),
and VFS_FHTOVP(); all they did was pass it to vget() (which, as noted
above, didn't use it).
* Remove all of the "lwp *" arguments to internal functions that were added
just to appease the above.


# 1.104 28-Jun-2003 darrenr

Pass lwp pointers throughtout the kernel, as required, so that the lwpid can
be inserted into ktrace records. The general change has been to replace
"struct proc *" with "struct lwp *" in various function prototypes, pass
the lwp through and use l_proc to get the process pointer when needed.

Bump the kernel rev up to 1.6V


# 1.103 28-May-2003 christos

Add /proc/<pid>/stat for linux compat. j2sdk1.4.2 depends on it.


# 1.102 18-Apr-2003 christos

Make symlinks for directories that point to the actual directory.
Make symlinks to [kqueue] and [misc] for kqueue and misc fds.


# 1.101 17-Apr-2003 jdolecek

do not show nodes corresponding to directory descriptors for process
in fd/ subdirectory, nor allow lookup/open for the nodes
this fixes PR kern/21187 for good, and also avoids interesting directory
locking issues


# 1.100 17-Apr-2003 jdolecek

procfs_readdir(): in Pfd case, only show descriptors of types we want
how to represent (vnodes, fifo, pipes); also use fd_getfile() et al

this avoids annoying EOPNOTSUPP error messages from ls -F and such


# 1.99 17-Apr-2003 jdolecek

procfs_lookup(): use fd_getfile() et al in Pfd case


# 1.98 17-Apr-2003 jdolecek

use fd_getfile() in procfs_getfp(), and FILE_USE()/FILE_UNUSE() the
returned file descriptor pointer appropriately


# 1.97 17-Apr-2003 jdolecek

make some local arrays/variables static + const


# 1.96 10-Apr-2003 jdolecek

use former genfs_eopnotsupp_rele() as genfs_eopnotsupp(), so that vnodes
are vput()/vrele()d as necessary - some filesystems did use the wrong
one for some ops, and it's just safer to not take the chance

based on suggestion by Bill Studenmund


# 1.95 05-Apr-2003 dsl

Remove pointless check against PID_MAX. Let pfind() do the validation.
(The new pid allocation code may decide to allocate pids above PID_MAX.)


# 1.94 25-Feb-2003 jrf

This addresses PR kerm/19989. Thanks to hamajima@nagoya.ydc.co.jp for submitting this patch which enables /proc/uptime for linux emul. Patch reviewed by atatat@netbsd.org and tron@netbsd.org, approved by tron@netbsd.org.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 1.93 04-Jan-2003 martin

Cast off_t expression to long long to match format even on 64 bit
plattforms.

Shouldn't we introduce a PRIoff_t macro to create such format strings?


# 1.92 03-Jan-2003 christos

add LK_CANRECURSE in the locking of /dev/<pid>/fd/<n> and remove the curproc
kludge. Thanks to fvdl.


# 1.91 03-Jan-2003 christos

Implement /proc/<pid>/fd/<n>. This is work in progress. Questionable things:
- Is it ok to convert DTYPE_PIPE to VFIFO and DTYPE_SOCKET to VSOCK?
- XXX: Avoid locking issue in ls -Rl /proc by avoiding curproc
- Does I/O to pipes work?
- XXX: Are there security implications?


Revision tags: fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge gehenna-devsw-base kqueue-base
# 1.90 03-Aug-2002 simonb

Just use the "time" variable in the *_getattr functions instead of a call
to (the potentially expensive) microtime().


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.89 09-May-2002 thorpej

branches: 1.89.2;
Move code shared by procfs and the kernel proper out of procfs and
into the kernel proper (renaming functions from procfs_* to process_*).


Revision tags: eeh-devprop-base newlock-base ifpoll-base
# 1.88 12-Jan-2002 christos

Don't hide the real return code with EPERM.


# 1.87 06-Dec-2001 chs

add a VOP_PUTPAGES method for all the filesystems that don't have pages,
just unlock the interlock.


# 1.86 05-Dec-2001 thorpej

* Allow machine-dependent code to specify hooks for ptrace(2)
(__HAVE_PTRACE_MACHDEP) and procfs (__HAVE_PROCFS_MACHDEP).
These changes will allow platforms like x86 (XMM) and PowerPC
(AltiVec) to export extended register sets in a sane manner.

* Use __HAVE_PTRACE_MACHDEP to export x86 XMM registers (standard
FP + SSE/SSE2) using PT_{GET,SET}XMMREGS (in the machdep
ptrace request space).
* Use __HAVE_PROCFS_MACHDEP to export x86 XMM registers via
/proc/N/xmmregs in procfs.


Revision tags: thorpej-mips-cache-base
# 1.85 10-Nov-2001 lukem

add RCSIDs


# 1.84 06-Nov-2001 simonb

Remove some variables that are set but never used.


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base
# 1.83 31-Aug-2001 chs

branches: 1.83.2; 1.83.4;
map files are zero-length.


# 1.82 03-Jun-2001 chs

branches: 1.82.2;
procfs_bmap() should never be called, make it a "bad op".
let procfs_mmap() use the default error method.


Revision tags: thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 1.81 14-Apr-2001 kleink

In procfs_readdir(), give /proc/# directories DT_DIR (rather than DT_REG).


# 1.80 30-Mar-2001 fvdl

Bump va_blocksize for the map files some more, so that programs with
quite a few mappings have a chance of being handled correctly if
st_blksize is looked at.


# 1.79 29-Mar-2001 fvdl

For -o linux mounts, add some code to emulate /proc/#/maps.
Needs NAMECACHE_ENTER_REVERSE to include filenames.


# 1.78 21-Feb-2001 jdolecek

branches: 1.78.2;
make some more constant arrays 'const'


# 1.77 22-Jan-2001 jdolecek

make filesystem vnodeop, specop, fifoop and vnodeopv_* arrays const


# 1.76 17-Jan-2001 fvdl

Add a few linux-style files, only enabled when -o linux is specified
for the mount. Currently these are /proc/cpuinfo and /proc/meminfo.
The former only does something on i386 right now.


# 1.75 24-Nov-2000 chs

remove dead code and other misc cleanup.


# 1.74 09-Aug-2000 tv

Only show the "exe" entry to Linux processes, suggested by christos.
Since there are actually three struct emul's for linux, use the e_name
field to determine eligibility with strcmp().


# 1.73 09-Aug-2000 tv

Some versions of Linux libc look for /proc/.../exe instead of /proc/../file.
Add an entry for "exe" that is the same as "file", provided only if
COMPAT_LINUX is set.


# 1.72 03-Aug-2000 thorpej

MALLOC()/FREE() are not to be used for variable sized allocations.


# 1.71 28-Jun-2000 mrg

<vm/vm.h> -> <uvm/uvm_extern.h>


Revision tags: netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 1.70 30-Mar-2000 simonb

branches: 1.70.4;
Delete duplicate declaration of atopid().


Revision tags: chs-ubc2-newbase wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base fvdl-softdep-base
# 1.69 02-Sep-1999 thorpej

branches: 1.69.2; 1.69.8;
Make /proc/self a symlink to /proc/curproc. I've observed Linux programs
that expect /proc/self/cmdline to exist.


# 1.68 25-Aug-1999 sommerfeld

Change variable used for directory offset from "int" to "off_t".
Overkill, but avoids a host of truncation problems.


# 1.67 24-Aug-1999 sommerfeld

Fix PR8270:

Problem turned out to be due to improper handling of reads beyond EOF:
they should just return without error with the uio unchanged, and the
caller will recognize this as a zero-byte return (EOF).

The previous fix to protect directory reads against bogus uio_offset
values returned EINVAL, which broke mount -o union, which only
union'ed in the lower directory if the upper directory cleanly
returned EOF.

While we're here, protect kernfs as well.


# 1.66 14-Aug-1999 christos

protect against large uio_offset


# 1.65 03-Aug-1999 wrstuden

Add support for fcntl(2) to generate VOP_FCNTL calls. Any fcntl
call with F_FSCTL set and F_SETFL calls generate calls to a new
fileop fo_fcntl. Add genfs_fcntl() and soo_fcntl() which return 0
for F_SETFL and EOPNOTSUPP otherwise. Have all leaf filesystems
use genfs_fcntl().

Reviewed by: thorpej
Tested by: wrstuden


Revision tags: chs-ubc2-base
# 1.64 25-Jul-1999 thorpej

Add calls to lock the proclist as appropriate.


# 1.63 14-Jul-1999 thorpej

Fix a paste-o in procfs_lookup() introduced with the vnode locking changes.
Fixes PR #7961, Mario Kemper <magick@bundy.lip.owl.de>.


# 1.62 08-Jul-1999 wrstuden

Bump osrelease to 1.4E. Add layerfs files, remove null_subr.c.

Update coda to new struct lock in struct vnode.

make fdescfs, kernfs, portalfs, and procfs actually lock their vnodes.
It's not that hard.

Make unionfs set v_vnlock = NULL so any overlayed fs will call its
VOP_LOCK.


Revision tags: kame_141_19991130 netbsd-1-4-PATCH001 kame_14_19990705 kame_14_19990628 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.61 12-Mar-1999 christos

branches: 1.61.2; 1.61.4;
PR/7143: Jaromir Docelek: Add procfs/cmdline from Linux emulation


# 1.60 25-Jan-1999 msaitoh

Add /proc/#/map. From FreeBSD.


Revision tags: kenh-if-detach-base chs-ubc-base
# 1.59 08-Sep-1998 thorpej

- Use proclists[], rather than checking allproc and zombproc explicitly.
- Add some comments about locking.


# 1.58 13-Aug-1998 kleink

Per POSIX, fail with EINVAL if advisory locking is attempted on a file type
that doesn't support it, rather than using a homegrown EBADF or EOPNOTSUPP.


# 1.57 10-Aug-1998 matthias

create miscfs/genfs/genfs_vnops.c:genfs_enoioctl and make all the other
filesystems use it instead of a private version.


# 1.56 09-Aug-1998 perry

bzero->memset, bcopy->memcpy, bcmp->memcmp


# 1.55 03-Aug-1998 kleink

Recognize _PC_SYNC_IO.


Revision tags: eeh-paddr_t-base
# 1.54 21-Apr-1998 fvdl

procfs_readdir: in case of error, check if cookies actually have
been allocated before freeing them. From Wolfgang Solfrank.


# 1.53 01-Mar-1998 fvdl

Merge with Lite2 + local changes


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base marc-pcmcia-base
# 1.52 10-Oct-1997 fvdl

Bump last argument to VOP_READDIR to off_t (from u_long).


Revision tags: thorpej-signal-base
# 1.51 27-Aug-1997 thorpej

Fix a reversed argument which caused procfs_checkioperm() to always return
"OK". Add a few comments to avoid further confusion.


# 1.50 12-Aug-1997 thorpej

Fix the procfs hole described on current-users, similar to a fix for
FreeBSD by Sean Eric Fagan, but a bit different. This makes the checks
in the same places as sef's FreeBSD patch, but does not hardcode the
"kmem" group into the kernel, and also does a check identical to the
(3) and (4) checks in the NetBSD ptrace(2):

(1) it's not owned by you, or is set-id on exec (unless
you're root), or

(2) it's init, which controls the security level of the
entire system, and the system was not compiled with
permanently insecure mode turned on.


Revision tags: marc-pcmcia-bp
# 1.49 08-May-1997 mycroft

branches: 1.49.4;
Pass the vnode type to vaccess(), and use it when checking VEXEC. Make sure
that the mode bits passed to vaccess() and returned by foo_getattr() contain
only permission bits.


# 1.48 05-May-1997 mycroft

Need stat.h.


# 1.47 05-May-1997 mycroft

Eliminate bogus uses of V{READ,WRITE,EXEC}. Use S_I[RWX]{USR,GRP,OTH} where
appropriate.


# 1.46 28-Apr-1997 mycroft

Minor code cleanup.


Revision tags: is-newarp-before-merge is-newarp-base
# 1.45 25-Oct-1996 cgd

define path name string variables that we should not (and, thankfully, do
not) modify as 'const char *' rather 'char *'.


# 1.44 13-Oct-1996 christos

backout previous kprintf changes


# 1.43 10-Oct-1996 christos

printf -> kprintf, sprintf -> ksprintf


# 1.42 07-Sep-1996 mycroft

Implement poll(2).


# 1.41 01-Sep-1996 mycroft

Add a set of generic file system operations that most file systems use.
Also, fix some time stamp bogosities.


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 1.40 16-Mar-1996 christos

Fix printf format follies.


# 1.39 13-Feb-1996 mycroft

GC *_nullop(). Minor nits.


# 1.38 12-Feb-1996 christos

close PR/2063: procfs_rw prototyped twice with different prototypes


# 1.37 09-Feb-1996 christos

miscfs prototype changes


# 1.36 09-Feb-1996 mycroft

Fix vop_link, vop_symlink, and vop_remove semantics in several ways:
* Change the argument names to vop_link so they actually make sense.
* Implement vop_link and vop_symlink for all file systems, so they do proper
cleanup.
* Require the file system to decide whether or not linking and unlinking of
directories is allowed, and disable it for all current file systems.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.35 09-Oct-1995 mycroft

Use the index number as the cookie, rather than multiplying by UIO_MX.


# 1.34 09-Oct-1995 mycroft

Add support for cookies, mostly from Greg Hudson.


# 1.33 15-Apr-1995 cgd

fix timeval vs. timespec warnings


# 1.32 03-Feb-1995 mycroft

Return EROFS rather than ENOENT in many cases. Also some cosmetic cleanup.


# 1.31 27-Dec-1994 mycroft

Format police.


# 1.30 24-Dec-1994 ws

Implement and use a common access checking routine


# 1.29 14-Dec-1994 mycroft

Remove a_fp.


# 1.28 14-Nov-1994 christos

fixed struct comment


# 1.27 30-Oct-1994 cgd

be more careful with types, also pull in headers where necessary.


# 1.26 20-Oct-1994 cgd

update for new syscall args description mechanism


# 1.25 30-Aug-1994 mycroft

Convert process, file, and namei lists and hash tables to use queue.h.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.24 29-Jun-1994 cgd

New RCS ID's, take two. they're more aesthecially pleasant, and use 'NetBSD'


# 1.23 16-Jun-1994 mycroft

Remove an unneeded test.


# 1.22 15-Jun-1994 mycroft

Minor update from JSP after merging my changes.


# 1.21 08-Jun-1994 mycroft

Update to 4.4-Lite fs code, with local changes.


# 1.20 05-May-1994 cgd

lots of changes: prototype migration, move lots of variables, definitions,
and structure elements around. kill some unnecessary type and macro
definitions. standardize clock handling. More changes than you'd want.


# 1.19 15-Apr-1994 cgd

forgot these...


# 1.18 12-Apr-1994 cgd

be a bit smarter about determining if files shouldn't be seen by the user.
Also, DON'T allow a lookup to succeed on a file that's not visible!


# 1.17 15-Feb-1994 mycroft

Undo last change; executables is `file', not `a.out'.


# 1.16 14-Feb-1994 ws

Rename file -> a.out


# 1.15 14-Feb-1994 ws

Don't try to show a file for a process if there is none


# 1.14 28-Jan-1994 cgd

make a fpregs file.


# 1.13 20-Jan-1994 ws

Make procfs really work for debugging.
Implement not & notepg files in procfs.


# 1.12 09-Jan-1994 ws

Bug fixes and enhancements:
Make NFS serving work (BUT DON'T USE "attach" TO /proc/*/ctl FOR NOW!!!)
Make `curproc' a symbolic link
Add `.' and `..' entries to the directories.
Return better guesses on the size of the files.


# 1.11 05-Jan-1994 cgd

return size of 'reg' from getattr()


# 1.10 05-Jan-1994 cgd

make it compile (cleanly) for us


# 1.9 05-Jan-1994 cgd

add new procfs code, from Jan-Simon Pendry, jsp@sequent.com.
This is pretty-much "virgin", so that diffs can be done later.


# 1.8 18-Dec-1993 mycroft

Canonicalize all #includes.


Revision tags: magnum-base
# 1.7 16-Sep-1993 cgd

kill volatile warning.


# 1.6 07-Sep-1993 ws

branches: 1.6.2;
Changes to VFS readdir semantics
NFS changes for better cookie support
ISOFS changes for better Rockridge support and support for generation numbers


# 1.5 26-Aug-1993 pk

Implement setattr: mode for process entries; mode + uid/gid for the
PROCFS root directory.
Fixed omission in pfs_root() which came to light as a result of the above:
hold on to vnode for root dir.


# 1.4 25-Aug-1993 pk

Fixed improperly initialized nfsnode in pfs_lookup()


# 1.3 24-Aug-1993 pk

copyright update.


# 1.2 24-Aug-1993 pk

Rcs Id added.


# 1.1 24-Aug-1993 pk

branches: 1.1.1;
Initial version of a proc filesystem.


# 1.213 16-May-2020 christos

Add ACL support for FFS. From FreeBSD.


# 1.212 29-Apr-2020 thorpej

If the procfs mount is marked as linux-compat, then allow proc lookup
by any LWP ID in the proc, not just the canonical PID.


Revision tags: bouyer-xenpvh-base2
# 1.211 21-Apr-2020 ad

Revert the changes made in February to make cwdinfo use mostly lockless,
which relied on taking extra vnode refs.

Having benchmarked various experimental changes over the past few months it
seems that it's better to avoid vnode refs as much as possible. cwdi_lock
as a RW lock already did that to some extent for getcwd() and will permit
the same for namei() too.


Revision tags: phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base is-mlppp-base phil-wifi-20200406 ad-namecache-base3
# 1.210 24-Feb-2020 ad

branches: 1.210.4;
v_interlock -> vmobjlock


# 1.209 23-Feb-2020 ad

Merge from ad-namecache:

- Have a stab at clustering the members of vnode_t and vnode_impl_t in a
more cache-conscious way. With that done, go back to adjusting v_usecount
with atomics and keep vi_lock directly in vnode_impl_t (saves KVA).

- Allow VOP_LOCK(LK_NONE) for the benefit of VFS_VGET() and VFS_ROOT().
Make sure LK_UPGRADE always comes with LK_NOWAIT.

- Make cwdinfo use mostly lockless.


# 1.208 01-Feb-2020 riastradh

Load struct filedesc::fd_dt with atomic_load_consume.

Exceptions: when fd_refcnt <= 1, or when holding fd_lock.

While here:

- Restore KASSERT(mutex_owned(&fdp->fd_lock)) in fd_unused.
=> This is used only in fd_close and fd_abort, where it holds.
- Move bounds check assertion in fd_putfile to where it matters.
- Store fd_dt with atomic_store_release.
- Move load of fd_dt under lock in knote_fdclose.
- Omit membar_consumer in fdesc_readdir.
=> atomic_load_consume serves the same purpose now.
=> Was needed only on alpha anyway.


Revision tags: ad-namecache-base2 ad-namecache-base1 ad-namecache-base phil-wifi-20191119
# 1.207 29-Aug-2019 hannken

branches: 1.207.2;
Add missing operation VOP_GETPAGES() returning EFAULT.

Without this operation posix_fadvise(..., POSIX_FADV_WILLNEED)
would leave the v_interlock held.

Observed by maxv@


Revision tags: netbsd-9-base phil-wifi-20190609 isaki-audio2-base
# 1.206 30-Mar-2019 christos

branches: 1.206.4;
add a node for the process resource limits.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020
# 1.205 14-Oct-2018 jdolecek

remove M_CANFAIL flag for malloc(9) - it was completely ignored, so had
actually no effect


Revision tags: pgoyette-compat-0930 pgoyette-compat-0906
# 1.204 03-Sep-2018 riastradh

Rename min/max -> uimin/uimax for better honesty.

These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER! Some subsystems have

#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)


Revision tags: pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415
# 1.203 07-Apr-2018 hannken

branches: 1.203.2;
Lock the target cwdi and take an additional reference to the
vnode we are interested in to prevent it from disappearing
before getcwd_common().

Should fix PR kern/53096 (netbsd-8 crash on heavy disk I/O)


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.202 31-Dec-2017 christos

branches: 1.202.2;
Add an environ node


Revision tags: tls-maxphys-base-20171202
# 1.201 01-Dec-2017 christos

Allow procfs_kqfilter, since we allow poll. "go" does it.


# 1.200 08-Nov-2017 christos

fix locking, remove error(1) comments.


# 1.199 08-Nov-2017 christos

use p->p_path, remove unused code.


# 1.198 28-Aug-2017 kamil

Remove the filesystem tracing feature

This is a legacy interface from 4.4BSD, and it was
introduced to overcome shortcomings of ptrace(2) at that time, which are
no longer relevant (performance). Today /proc/#/ctl offers a narrow
subset of ptrace(2) commands and is not applicable for modern
applications use beyond simplistic tracing scenarios.

This removal will simplify kernel internals. Users will still be able to
use all the other /proc files.

This change won't affect other procfs files neither Linux compat
features within mount_procfs(8). /proc/#/ctl isn't available on Linux.

Remove:
- /proc/#/ctl from mount_procfs(8)
- P_FSTRACE note from the documentation of ps(1)
- /proc/#/ctl and filesystem tracing documentation from mount_procfs(8)
- KAUTH_REQ_PROCESS_PROCFS_CTL documentation from kauth(9)
- source code file miscfs/procfs/procfs_ctl.c
- PFSctl and procfs_doctl() from sys/miscfs/procfs/procfs.h
- KAUTH_REQ_PROCESS_PROCFS_CTL from sys/sys/kauth.h
- PSL_FSTRACE (0x00010000) from sys/sys/proc.h
- P_FSTRACE (0x00010000) from sys/sys/sysctl.h

Reduce code complexity after removal of this functionality.

Update TODO.ptrace accordingly: remove two entries about /proc tracing.

Do not keep legacy notes as comments in the headers about removed
PSL_FSTRACE / P_FSTRACE, as this interface had little number of users
(close or equal to zero).

Proposed on tech-kern@.

All filesystem tracing utility users are encouraged to switch to ptrace(2).

Sponsored by <The NetBSD Foundation>


Revision tags: matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base
# 1.197 26-May-2017 riastradh

branches: 1.197.2;
Make VOP_RECLAIM do the last unlock of the vnode.

VOP_RECLAIM naturally has exclusive access to the vnode, so having it
locked on entry is not strictly necessary -- but it means if there
are any final operations that must be done on the vnode, such as
ffs_update, requiring exclusive access to it, we can now kassert that
the vnode is locked in those operations.

We can't just have the caller release the last lock because some file
systems don't use genfs_lock, and require the vnode to remain valid
for VOP_UNLOCK to work, notably unionfs.


Revision tags: prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.196 11-Apr-2017 riastradh

Make VOP_INACTIVE preserve vnode lock on return.

Discussed on tech-kern:
https://mail-index.netbsd.org/tech-kern/2017/04/01/msg021751.html

Ride 7.99.68, a bumpy bus of incremental vfs improvements!


Revision tags: jdolecek-ncq-base
# 1.195 30-Mar-2017 christos

add an auxv node.


Revision tags: pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004 localcount-20160914
# 1.194 20-Aug-2016 hannken

branches: 1.194.2;
Remove now obsolete operation vcache_remove().

Welcome to 7.99.36


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 nick-nhusb-base-20150921 nick-nhusb-base-20150606
# 1.193 20-Apr-2015 riastradh

branches: 1.193.2;
Make VOP_LINK return directory still locked and referenced.

Ride 7.99.10 bump.


Revision tags: nick-nhusb-base-20150406 nick-nhusb-base
# 1.192 05-Sep-2014 matt

branches: 1.192.2;
Try not to use f_data, use f_{vnode,socket,pipe,mqueue,kqueue,ksem} to get
a correctly typed pointer.


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.191 27-Jul-2014 hannken

branches: 1.191.2; 1.191.4; 1.191.8;
Change procfs from hashlist to vcache.
- Key is (type, pid, fd)
- Remove argument "p" from procfs_allocvp(). It is only used
when "type == PFSfd". Lookup the proc with proc_find() when
procfs_loadvnode() needs it.
- Use a vfs_vnode_iterator for procfs_revoke_vnodes().


# 1.190 25-Jul-2014 dholland

Add VOP_FALLOCATE and VOP_FDISCARD to every vnode ops table I can
find.

The filesystem ones all call genfs_eopnotsupp - right now I am only
implementing the plumbing and we can implement fallocate and/or
fdiscard for files later.

The device ones call spec_fallocate (which is also genfs_eopnotsupp)
and spec_fdiscard, which dispatches to the device-level op.

The fifo ones all call vn_fifo_bypass, which also ends up being
EOPNOTSUPP.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base
# 1.189 07-Feb-2014 hannken

branches: 1.189.2;
Change vnode operation lookup to return the resulting vnode *vpp unlocked.
Change cache_lookup() to return an unlocked vnode.

Discussed on tech-kern@

Welcome to 6.99.31


# 1.188 23-Jan-2014 hannken

Change vnode operations create, mknod, mkdir and symlink to return
the resulting vnode *vpp unlocked.

Discussed on tech-kern@

Welcome to 6.99.30


# 1.187 17-Jan-2014 hannken

Change vnode operations create, mknod, mkdir and symlink to keep the
directory node dvp locked on return.

Discussed on tech-kern@

Welcome to 6.99.29


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base
# 1.186 18-Mar-2013 plunky

branches: 1.186.6;
C99 section 6.7.2.3 (Tags) Note 3 states that:

A type specifier of the form

enum identifier

without an enumerator list shall only appear after the type it
specifies is complete.

which means that we cannot pass an "enum vtype" argument to
kauth_access_action() without fully specifying the type first.
Unfortunately there is a complicated include file loop which
makes that difficult, so convert this minimal function into a
macro (and capitalize it).

(ok elad@)


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 1.185 25-Nov-2012 christos

do something reasonable with kernel semaphores.


Revision tags: yamt-pagecache-base6 jmcneill-usbmp-base10
# 1.184 28-May-2012 christos

branches: 1.184.2;
add a task process subdirectory for emul linux


Revision tags: yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 1.183 13-Mar-2012 elad

Replace the remaining KAUTH_GENERIC_ISSUSER authorization calls with
something meaningful. All relevant documentation has been updated or
written.

Most of these changes were brought up in the following messages:

http://mail-index.netbsd.org/tech-kern/2012/01/18/msg012490.html
http://mail-index.netbsd.org/tech-kern/2012/01/19/msg012502.html
http://mail-index.netbsd.org/tech-kern/2012/02/17/msg012728.html

Thanks to christos, manu, njoly, and jmmv for input.

Huge thanks to pgoyette for spinning these changes through some build
cycles and ATF.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.182 04-Sep-2011 jmcneill

branches: 1.182.2; 1.182.6;
PR# kern/45021: Please support /emul/linux/proc/version

Add /proc/version for procfs with -o linux. The version reported depends
on the emulation type of the calling process:

$ cat /proc/version
NetBSD version 5.99.55 (netbsd@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) NetBSD 5.99.55 (GENERIC) #39: Sun Sep 4 09:10:05 EDT 2011

$ /emul/linux/bin/cat /proc/version
Linux version 2.6.18 (linux@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) #0 Wed Mar 3 03:03:03 PST 2010

$ /emul/linux32/bin/cat /proc/version
Linux version 2.6.18 (linux32@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) #0 Wed Mar 3 03:03:03 PST 2010


# 1.181 23-Jun-2011 christos

From Aleksey Cheusov: Don't make it easy for compromised systems to bypass
ASLR protections by providing the mapping addresses of programs to everyone.


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base matt-mips64-premerge-20101231 uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10 rmind-uvmplock-base
# 1.180 01-Jul-2010 rmind

Remove pfind() and pgfind(), fix locking in various broken uses of these.
Rename real routines to proc_find() and pgrp_find(), remove PFIND_* flags
and have consistent behaviour. Provide proc_find_raw() for special cases.
Fix memory leak in sysctl_proc_corename().

COMPAT_LINUX: rework ptrace() locking, minimise differences between
different versions per-arch.

Note: while this change adds some formal cosmetics for COMPAT_DARWIN and
COMPAT_IRIX - locking there is utterly broken (for ages).

Fixes PR/43176.


# 1.179 24-Jun-2010 hannken

Clean up vnode lock operations pass 2:

VOP_UNLOCK(vp, flags) -> VOP_UNLOCK(vp): Remove the unneeded flags argument.

Welcome to 5.99.32.

Discussed on tech-kern.


# 1.178 08-Jun-2010 hannken

Procfs_lookup() does not lookup directory descriptors in the fd/
subdirectory. There is no need for recursive vnode locking here.

Ok: Christos Zoulas <christos@netbsd.org>


Revision tags: uebayasi-xip-base1 yamt-nfs-mp-base9 uebayasi-xip-base
# 1.177 08-Jan-2010 pooka

branches: 1.177.2; 1.177.4;
The VATTR_NULL/VREF/VHOLD/HOLDRELE() macros lost their will to live
years ago when the kernel was modified to not alter ABI based on
DIAGNOSTIC, and now just call the respective function interfaces
(in lowercase). Plenty of mix'n match upper/lowercase has creeped
into the tree since then. Nuke the macros and convert all callsites
to lowercase.

no functional change


Revision tags: matt-premerge-20091211 yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 jym-xensuspend-nbase
# 1.176 03-Jul-2009 elad

Where possible, extract the file-system's access() routine to two internal
functions: the first checking if the operation is possible (regardless of
permissions), the second checking file-system permissions, ACLs, etc.

Mailing list reference:

http://mail-index.netbsd.org/tech-kern/2009/06/21/msg005311.html


# 1.175 23-Jun-2009 elad

Move the implementation of vaccess() to genfs_can_access(), in line with
the other routines of the same spirit.

Adjust file-system code to use it.

Keep vaccess() for KPI compatibility and to keep element of least
surprise. A "diagnostic" message warning that vaccess() is deprecated will
be printed when it's used (obviously, only in DIAGNOSTIC kernels).

No objections on tech-kern@:

http://mail-index.netbsd.org/tech-kern/2009/06/21/msg005310.html


Revision tags: yamt-nfs-mp-base5
# 1.174 24-May-2009 ad

More changes to improve kern_descrip.c.

- Avoid atomics in more places.
- Remove the per-descriptor mutex, and just use filedesc_t::fd_lock.
It was only being used to synchronize close, and in any case we needed
to take fd_lock to free the descriptor slot.
- Optimize certain paths for the <NDFDFILE case.
- Sprinkle more comments and assertions.
- Cache more stuff in filedesc_t.
- Fix numerous minor bugs spotted along the way.
- Restructure how the open files array is maintained, for clarity and so
that we can eliminate the membar_consumer() call in fd_getfile(). This is
mostly syntactic sugar; the main functional change is that fd_nfiles now
lives alongside the open file array.

Some measurements with libmicro:

- simple file syscalls are like close() are between 1 to 10% faster.
- some nice improvements, e.g. poll(1000) which is ~50% faster.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 nick-hppapmap-base2 jym-xensuspend-base nick-hppapmap-base mjf-devfs2-base
# 1.173 17-Dec-2008 cegger

branches: 1.173.2;
kill MALLOC and FREE macros.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 haad-dm-base2 haad-nbase2 ad-audiomp2-base netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 haad-dm-base
# 1.172 05-Sep-2008 skrll

branches: 1.172.2;
PR/39324 kernel diagnostic assertion "l->l_stat != LSZOMB" failed.

Ignore procs with zero or all LSZOMB LWPs. Get a non-LSZOMB LWP to perform
operations against as part of the deal.

procfs really needs to be updated to support multi-threading fully.
Hi Antti!


# 1.171 05-Sep-2008 skrll

ANSIfy


Revision tags: simonb-wapbl-nbase simonb-wapbl-base
# 1.170 02-Jul-2008 rmind

branches: 1.170.2;
Remove proc_representative_lwp(), use a simple LIST_FIRST() instead.
OK by <ad>.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base
# 1.169 28-Apr-2008 martin

branches: 1.169.2; 1.169.4;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-nfs-mp-base
# 1.168 24-Apr-2008 ad

branches: 1.168.2;
Merge proc::p_mutex and proc::p_smutex into a single adaptive mutex, since
we no longer need to guard against access from hardware interrupt handlers.

Additionally, if cloning a process with CLONE_SIGHAND, arrange to have the
child process share the parent's lock so that signal state may be kept in
sync. Partially addresses PR kern/37437.


# 1.167 24-Apr-2008 ad

Network protocol interrupts can now block on locks, so merge the globals
proclist_mutex and proclist_lock into a single adaptive mutex (proc_lock).
Implications:

- Inspecting process state requires thread context, so signals can no longer
be sent from a hardware interrupt handler. Signal activity must be
deferred to a soft interrupt or kthread.

- As the proc state locking is simplified, it's now safe to take exit()
and wait() out from under kernel_lock.

- The system spends less time at IPL_SCHED, and there is less lock activity.


Revision tags: yamt-pf42-baseX yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14
# 1.166 21-Mar-2008 ad

branches: 1.166.2;
Catch up with descriptor handling changes. See kern_descrip.c revision
1.173 for details.


Revision tags: keiichi-mipv6-nbase nick-net80211-sync-base keiichi-mipv6-base bouyer-xeni386-nbase matt-armv6-nbase mjf-devfs-base hpcarm-cleanup-base
# 1.165 23-Jan-2008 elad

branches: 1.165.6;
Tons of process scope changes.

- Add a KAUTH_PROCESS_SCHEDULER action, to handle scheduler related
requests, and add specific requests for set/get scheduler policy and
set/get scheduler parameters.

- Add a KAUTH_PROCESS_KEVENT_FILTER action, to handle kevent(2) related
requests.

- Add a KAUTH_DEVICE_TTY_STI action to handle requests to TIOCSTI.

- Add requests for the KAUTH_PROCESS_CANSEE action, indicating what
process information is being looked at (entry itself, args, env,
open files).

- Add requests for the KAUTH_PROCESS_RLIMIT action indicating set/get.

- Add requests for the KAUTH_PROCESS_CORENAME action indicating set/get.

- Make bsd44 secmodel code handle the newly added rqeuests appropriately.

All of the above make it possible to issue finer-grained kauth(9) calls in
many places, removing some KAUTH_GENERIC_ISSUSER requests.

- Remove the "CAN" from KAUTH_PROCESS_CAN{KTRACE,PROCFS,PTRACE,SIGNAL}.

Discussed with christos@ and yamt@.


Revision tags: bouyer-xeni386-base matt-armv6-base
# 1.164 02-Jan-2008 ad

Merge vmlocking2 to head.


Revision tags: vmlocking2-base3 yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 vmlocking-nbase jmcneill-pm-base reinoud-bufcleanup-base
# 1.163 26-Nov-2007 pooka

branches: 1.163.2; 1.163.6;
Remove the "struct lwp *" argument from all VFS and VOP interfaces.
The general trend is to remove it from all kernel interfaces and
this is a start. In case the calling lwp is desired, curlwp should
be used.

quick consensus on tech-kern


Revision tags: bouyer-xenamd64-base2 bouyer-xenamd64-base
# 1.162 09-Nov-2007 christos

make the last argument of procfs_dir size_t


# 1.161 07-Nov-2007 ad

Merge from vmlocking:

- pool_cache changes.
- Debugger/procfs locking fixes.
- Other minor changes.


Revision tags: jmcneill-base yamt-x86pmap-base4 yamt-x86pmap-base3 vmlocking-base
# 1.160 10-Oct-2007 ad

branches: 1.160.2; 1.160.4;
Merge from vmlocking:

- Split vnode::v_flag into three fields, depending on field locking.
- simple_lock -> kmutex in a few places.
- Fix some simple locking problems.


# 1.159 08-Oct-2007 ad

Merge file descriptor locking, cwdi locking and cross-call changes
from the vmlocking branch.


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base2 yamt-x86pmap-base matt-mips64-base
# 1.158 22-Jul-2007 pooka

branches: 1.158.4; 1.158.6; 1.158.8; 1.158.10;
Don't allow getcwd() on procfs vnodes and provide "/" as the path
instead of the result from getcwd(). The works around locking
panics caused by namei calling VOP_READLINK while holding on to a
directory lock and getcwd() trying to acquire that lock. The real
fix would be to get rid of getcwd() calls within VOPs (not locking
safe), but that's not a viable option in the netbsd-4 timeframe.

Suggestion for workaround from David Holland.


Revision tags: nick-csl-alignment-base mjf-ufs-trans-base
# 1.157 24-May-2007 agc

branches: 1.157.2;
Extend the Linux emulation of /proc to include

/proc/stat
/proc/loadavg and
/proc/<pid>/statm.

These are only present when -o linux is specified as a mount option
to procfs.

Factor out some common code so that it can be used by a number of
functions.

XXX The values returned in the statm emulation need to be verified.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 1.156 04-Apr-2007 rmind

Unfortunately, missed procfs_proc_unlock() in previous.
Pointed out by pooka@


# 1.155 04-Apr-2007 rmind

procfs_readlink: Handle a possible fail of fd_getfile(), also, we
do not need to check for error again.
CID: 4436


# 1.154 09-Mar-2007 ad

branches: 1.154.2; 1.154.4;
- Make the proclist_lock a mutex. The write:read ratio is unfavourable,
and mutexes are cheaper use than RW locks.
- LOCK_ASSERT -> KASSERT in some places.
- Hold proclist_lock/kernel_lock longer in a couple of places.


# 1.153 04-Mar-2007 christos

Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.


# 1.152 03-Mar-2007 salo

Don't prepend rootvnode to the path in non-NULL case for exe links.
It breaks procfs in chroot.

from <christos>, tested by me.


Revision tags: ad-audiomp-base
# 1.151 19-Feb-2007 pooka

When checking for file validity under pid/, do proper proc->lwp
lookup (fsvo proper) instead of fiddling directly with the lwp
list.


# 1.150 18-Feb-2007 pooka

Don't check for validity of p in lookup for root nodes, since it
will always be NULL. Rather, just call pt_valid with NULL directly
and let it decide if we're a linux mount or not.


# 1.149 17-Feb-2007 pavel

Change the process/lwp flags seen by userland via sysctl back to the
P_*/L_* naming convention, and rename the in-kernel flags to avoid
conflict. (P_ -> PK_, L_ -> LW_ ). Add back the (now unused) LSDEAD
constant.

Restores source compatibility with pre-newlock2 tools like ps or top.

Reviewed by Andrew Doran.


# 1.148 16-Feb-2007 pooka

branches: 1.148.2;
In lookup, when checking for procfs process node validity, target the
process we're trying to get information about through procfs, not
the caller of lookup.

fixes 'ls -l /proc/*/file' panic, which would occur when trying to
lookup "file" for a kernel thread, which doesn't have p->p_textvp.


# 1.147 15-Feb-2007 ad

Need to acquire procp->p_mutex for procfs_dir().


# 1.146 11-Feb-2007 ad

Eliminate a couple of reference count and mutex leaks.


Revision tags: post-newlock2-merge
# 1.145 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 1.144 25-Dec-2006 elad

PR/35226: Johann Franz: Problems with permissions in
/usr/pkg/emul/linux/proc .

Okay mlelstv@


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3
# 1.143 09-Dec-2006 chs

a smorgasbord of improvements to vnode locking and path lookup:
- LOCKPARENT is no longer relevant for lookup(), relookup() or VOP_LOOKUP().
these now always return the parent vnode locked. namei() works as before.
lookup() and various other paths no longer acquire vnode locks in the
wrong order via vrele(). fixes PR 32535.
as a nice side effect, path lookup is also up to 25% faster.
- the above allows us to get rid of PDIRUNLOCK.
- also get rid of WANTPARENT (just use LOCKPARENT and unlock it).
- remove an assumption in layer_node_find() that all file systems implement
a recursive VOP_LOCK() (unionfs doesn't).
- require that all file systems supply vfs_vptofh and vfs_fhtovp routines.
fill in eopnotsupp() for file systems that don't support being exported
and remove the checks for NULL. (layerfs calls these without checking.)
- in union_lookup1(), don't change refcounts in the ISDOTDOT case, just
adjust which vnode is locked. fixes PR 33374.
- apply fixes for ufs_rename() from ufs_vnops.c rev. 1.61 to ext2fs_rename().


# 1.142 04-Dec-2006 christos

From Nicolas Joly: restore previous behavior in procfs_validfile_linux, since
readdir passes a NULL lwp.


# 1.141 03-Dec-2006 elad

Move kauth(9) call to where it belongs. Noticed by Nicolas Joly, thanks!


Revision tags: netbsd-4-base
# 1.140 28-Nov-2006 elad

branches: 1.140.2;
Move ktrace, ptrace, systrace, and procfs to use kauth(9).

First, remove process_checkioperm() calls from MD code. Similar checks
using kauth(9) routines (on the process scope, using appropriate action)
are done in the callers.

Add secmodel back-end to handle each subsystem.


# 1.139 25-Nov-2006 skrll

Expose the 'exe' symlink to the process realpath in NetBSD as well. An
example user is gdb.

OK'd by christos.


# 1.138 16-Nov-2006 christos

__unused removal on arguments; approved by core.


# 1.137 29-Oct-2006 christos

add an "emul" file node.


# 1.136 25-Oct-2006 christos

1. fix procfs_validfile{,_linux} to test for NULL pointers properly.
2. make "exe" entry be a symlink to the executable, instead of pointing
directly to the vnode of the executable.
3. factor out commonly used code.


Revision tags: yamt-splraiseipl-base2
# 1.135 12-Oct-2006 christos

- sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386


# 1.134 20-Sep-2006 manu

Emulate Linux's /proc/devices


Revision tags: abandoned-netbsd-4-base yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base rpaulo-netinet-merge-pcb-base
# 1.133 13-Jun-2006 yamt

branches: 1.133.6; 1.133.8;
use KAUTH_PROCESS_CANSEE rather than CURTAIN where appropriate.


# 1.132 13-Jun-2006 yamt

remove unnecessary arguments from kauth_authorize_process.
ie. make it similar to the one found in apple TN.


# 1.131 07-Jun-2006 kardel

merge FreeBSD timecounters from branch simonb-timecounters
- struct timeval time is gone
time.tv_sec -> time_second
- struct timeval mono_time is gone
mono_time.tv_sec -> time_uptime
- access to time via
{get,}{micro,nano,bin}time()
get* versions are fast but less precise
- support NTP nanokernel implementation (NTP API 4)
- further reading:
Timecounter Paper: http://phk.freebsd.dk/pubs/timecounter.pdf
NTP Nanokernel: http://www.eecis.udel.edu/~mills/ntp/html/kern.html


Revision tags: yamt-pdpolicy-base5 simonb-timecounters-base
# 1.130 14-May-2006 elad

branches: 1.130.2;
integrate kauth.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 elad-kernelauth-base yamt-pdpolicy-base yamt-uio_vmspace-base5
# 1.129 02-Feb-2006 christos

branches: 1.129.2; 1.129.4; 1.129.6; 1.129.8;
PR/32692: Matthew Mondor: linux compatibility in /proc/self should point
directly to the directory containing the pid instead of pointing to
/proc/curproc, because some programs rely on calling readlink on /proc/self
to get the pid.


# 1.128 11-Dec-2005 christos

branches: 1.128.2; 1.128.4;
merge ktrace-lwp.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base ktrace-lwp-base
# 1.127 02-Nov-2005 yamt

merge yamt-vop branch. remove following VOPs.

VOP_BLKATOFF
VOP_VALLOC
VOP_BALLOC
VOP_REALLOCBLKS
VOP_VFREE
VOP_TRUNCATE
VOP_UPDATE


Revision tags: yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 1.126 01-Oct-2005 atatat

branches: 1.126.2;
Add "cwd" and "root" symlinks to each process's directory. The cwd
link points to the process's current working directory, and the root
link points to the process's root directory. What else would you
expect?

For directories that are out of reach (caller is in a chroot, target
process is in a different chroot, etc), the links point to "/"
instead.


# 1.125 11-Sep-2005 elad

Implement curtain for procfs.


# 1.124 30-Aug-2005 xtraeme

Remove __P()


# 1.123 29-May-2005 christos

branches: 1.123.2;
- sprinkle const
- avoid shadowed variables.


Revision tags: kent-audio2-base
# 1.122 02-Apr-2005 christos

PR/29782: Martin Husemann: procfs can not unmount when some process has its
current directory in curproc. Fix from Pedro Martelletto:
We cannot call vgone() from procfs_inactive() if we are coming from
vclean(). that's what's probably causing the deadlock.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 yamt-km-base4 yamt-km-base3 netbsd-3-base
# 1.121 26-Feb-2005 perry

nuke trailing whitespace


Revision tags: yamt-km-base2 yamt-km-base kent-audio1-beforemerge kent-audio1-base
# 1.120 04-Oct-2004 yamt

branches: 1.120.4; 1.120.6;
procfs_readdir:
- return correct cookie when buffer size is small.
- simplify logic.


# 1.119 04-Oct-2004 yamt

procfs_readdir: remove a redundant assignment.


# 1.118 02-Oct-2004 yamt

procfs_getattr: correct size of /proc/self.


# 1.117 01-Oct-2004 yamt

procfs_readdir:
- fix a locking problem, using proclist_foreach_call. PR/27098.
- correct snprintf size argument.


# 1.116 01-Oct-2004 yamt

procfs_readdir: fix an offset handling bug after addition of /proc/self.


# 1.115 01-Oct-2004 yamt

procfs_readdir: use a list macro.


# 1.114 20-Sep-2004 jdolecek

add 'mounts' file for -o linux, which lists all currently mounted
filesystems; Linux glibc statvfs() uses this to get some of mount flags,
and this file is also useful as /emul/linux/etc/mtab (via symlink)


# 1.113 29-Apr-2004 jrf

Removed remaining caddr_t casts we do not need in miscfs. Recompiled
kernel and ran for a day or so. There are still some caddr_t types in
the arguments of some calls, I will do those separately (later) as
they touch a lot more of the system.
Approved by christos@NetBSD.org.


# 1.112 22-Apr-2004 itojun

sprintf -> snprintf


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.111 15-Feb-2004 jdolecek

unlock the descriptor table simple lock after fd_getfile() call in
procfs_readdir()
fixes procfs locking problems reported on current-users@, problem place
found by enami tsugutomo


# 1.110 30-Oct-2003 simonb

Remove some assigned-to but otherwise unused variables.


# 1.109 27-Sep-2003 darcy

Changes as discussed with itojun on tech-kern. I have modified the enums
to have KFS or PFS differentiators. Further I have wrapped the enum in
procfs in "#ifdef _KERNEL" as it is done in kernfs.

To see the discussion go to http://mail-index.NetBSD.org/tech-kern/2003/09/
and look for "Mismatched enums in include files" in the list.


# 1.108 07-Sep-2003 itojun

remove meaningless line (variable overwritten 2 lines below)


# 1.107 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.


# 1.106 29-Jun-2003 fvdl

branches: 1.106.2;
Back out the lwp/ktrace changes. They contained a lot of colateral damage,
and need to be examined and discussed more.


# 1.105 29-Jun-2003 thorpej

Undo part of the ktrace/lwp changes. In particular:
* Remove the "lwp *" argument that was added to vget(). Turns out
that nothing actually used it!
* Remove the "lwp *" arguments that were added to VFS_ROOT(), VFS_VGET(),
and VFS_FHTOVP(); all they did was pass it to vget() (which, as noted
above, didn't use it).
* Remove all of the "lwp *" arguments to internal functions that were added
just to appease the above.


# 1.104 28-Jun-2003 darrenr

Pass lwp pointers throughtout the kernel, as required, so that the lwpid can
be inserted into ktrace records. The general change has been to replace
"struct proc *" with "struct lwp *" in various function prototypes, pass
the lwp through and use l_proc to get the process pointer when needed.

Bump the kernel rev up to 1.6V


# 1.103 28-May-2003 christos

Add /proc/<pid>/stat for linux compat. j2sdk1.4.2 depends on it.


# 1.102 18-Apr-2003 christos

Make symlinks for directories that point to the actual directory.
Make symlinks to [kqueue] and [misc] for kqueue and misc fds.


# 1.101 17-Apr-2003 jdolecek

do not show nodes corresponding to directory descriptors for process
in fd/ subdirectory, nor allow lookup/open for the nodes
this fixes PR kern/21187 for good, and also avoids interesting directory
locking issues


# 1.100 17-Apr-2003 jdolecek

procfs_readdir(): in Pfd case, only show descriptors of types we want
how to represent (vnodes, fifo, pipes); also use fd_getfile() et al

this avoids annoying EOPNOTSUPP error messages from ls -F and such


# 1.99 17-Apr-2003 jdolecek

procfs_lookup(): use fd_getfile() et al in Pfd case


# 1.98 17-Apr-2003 jdolecek

use fd_getfile() in procfs_getfp(), and FILE_USE()/FILE_UNUSE() the
returned file descriptor pointer appropriately


# 1.97 17-Apr-2003 jdolecek

make some local arrays/variables static + const


# 1.96 10-Apr-2003 jdolecek

use former genfs_eopnotsupp_rele() as genfs_eopnotsupp(), so that vnodes
are vput()/vrele()d as necessary - some filesystems did use the wrong
one for some ops, and it's just safer to not take the chance

based on suggestion by Bill Studenmund


# 1.95 05-Apr-2003 dsl

Remove pointless check against PID_MAX. Let pfind() do the validation.
(The new pid allocation code may decide to allocate pids above PID_MAX.)


# 1.94 25-Feb-2003 jrf

This addresses PR kerm/19989. Thanks to hamajima@nagoya.ydc.co.jp for submitting this patch which enables /proc/uptime for linux emul. Patch reviewed by atatat@netbsd.org and tron@netbsd.org, approved by tron@netbsd.org.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 1.93 04-Jan-2003 martin

Cast off_t expression to long long to match format even on 64 bit
plattforms.

Shouldn't we introduce a PRIoff_t macro to create such format strings?


# 1.92 03-Jan-2003 christos

add LK_CANRECURSE in the locking of /dev/<pid>/fd/<n> and remove the curproc
kludge. Thanks to fvdl.


# 1.91 03-Jan-2003 christos

Implement /proc/<pid>/fd/<n>. This is work in progress. Questionable things:
- Is it ok to convert DTYPE_PIPE to VFIFO and DTYPE_SOCKET to VSOCK?
- XXX: Avoid locking issue in ls -Rl /proc by avoiding curproc
- Does I/O to pipes work?
- XXX: Are there security implications?


Revision tags: fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge gehenna-devsw-base kqueue-base
# 1.90 03-Aug-2002 simonb

Just use the "time" variable in the *_getattr functions instead of a call
to (the potentially expensive) microtime().


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.89 09-May-2002 thorpej

branches: 1.89.2;
Move code shared by procfs and the kernel proper out of procfs and
into the kernel proper (renaming functions from procfs_* to process_*).


Revision tags: eeh-devprop-base newlock-base ifpoll-base
# 1.88 12-Jan-2002 christos

Don't hide the real return code with EPERM.


# 1.87 06-Dec-2001 chs

add a VOP_PUTPAGES method for all the filesystems that don't have pages,
just unlock the interlock.


# 1.86 05-Dec-2001 thorpej

* Allow machine-dependent code to specify hooks for ptrace(2)
(__HAVE_PTRACE_MACHDEP) and procfs (__HAVE_PROCFS_MACHDEP).
These changes will allow platforms like x86 (XMM) and PowerPC
(AltiVec) to export extended register sets in a sane manner.

* Use __HAVE_PTRACE_MACHDEP to export x86 XMM registers (standard
FP + SSE/SSE2) using PT_{GET,SET}XMMREGS (in the machdep
ptrace request space).
* Use __HAVE_PROCFS_MACHDEP to export x86 XMM registers via
/proc/N/xmmregs in procfs.


Revision tags: thorpej-mips-cache-base
# 1.85 10-Nov-2001 lukem

add RCSIDs


# 1.84 06-Nov-2001 simonb

Remove some variables that are set but never used.


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base
# 1.83 31-Aug-2001 chs

branches: 1.83.2; 1.83.4;
map files are zero-length.


# 1.82 03-Jun-2001 chs

branches: 1.82.2;
procfs_bmap() should never be called, make it a "bad op".
let procfs_mmap() use the default error method.


Revision tags: thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 1.81 14-Apr-2001 kleink

In procfs_readdir(), give /proc/# directories DT_DIR (rather than DT_REG).


# 1.80 30-Mar-2001 fvdl

Bump va_blocksize for the map files some more, so that programs with
quite a few mappings have a chance of being handled correctly if
st_blksize is looked at.


# 1.79 29-Mar-2001 fvdl

For -o linux mounts, add some code to emulate /proc/#/maps.
Needs NAMECACHE_ENTER_REVERSE to include filenames.


# 1.78 21-Feb-2001 jdolecek

branches: 1.78.2;
make some more constant arrays 'const'


# 1.77 22-Jan-2001 jdolecek

make filesystem vnodeop, specop, fifoop and vnodeopv_* arrays const


# 1.76 17-Jan-2001 fvdl

Add a few linux-style files, only enabled when -o linux is specified
for the mount. Currently these are /proc/cpuinfo and /proc/meminfo.
The former only does something on i386 right now.


# 1.75 24-Nov-2000 chs

remove dead code and other misc cleanup.


# 1.74 09-Aug-2000 tv

Only show the "exe" entry to Linux processes, suggested by christos.
Since there are actually three struct emul's for linux, use the e_name
field to determine eligibility with strcmp().


# 1.73 09-Aug-2000 tv

Some versions of Linux libc look for /proc/.../exe instead of /proc/../file.
Add an entry for "exe" that is the same as "file", provided only if
COMPAT_LINUX is set.


# 1.72 03-Aug-2000 thorpej

MALLOC()/FREE() are not to be used for variable sized allocations.


# 1.71 28-Jun-2000 mrg

<vm/vm.h> -> <uvm/uvm_extern.h>


Revision tags: netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 1.70 30-Mar-2000 simonb

branches: 1.70.4;
Delete duplicate declaration of atopid().


Revision tags: chs-ubc2-newbase wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base fvdl-softdep-base
# 1.69 02-Sep-1999 thorpej

branches: 1.69.2; 1.69.8;
Make /proc/self a symlink to /proc/curproc. I've observed Linux programs
that expect /proc/self/cmdline to exist.


# 1.68 25-Aug-1999 sommerfeld

Change variable used for directory offset from "int" to "off_t".
Overkill, but avoids a host of truncation problems.


# 1.67 24-Aug-1999 sommerfeld

Fix PR8270:

Problem turned out to be due to improper handling of reads beyond EOF:
they should just return without error with the uio unchanged, and the
caller will recognize this as a zero-byte return (EOF).

The previous fix to protect directory reads against bogus uio_offset
values returned EINVAL, which broke mount -o union, which only
union'ed in the lower directory if the upper directory cleanly
returned EOF.

While we're here, protect kernfs as well.


# 1.66 14-Aug-1999 christos

protect against large uio_offset


# 1.65 03-Aug-1999 wrstuden

Add support for fcntl(2) to generate VOP_FCNTL calls. Any fcntl
call with F_FSCTL set and F_SETFL calls generate calls to a new
fileop fo_fcntl. Add genfs_fcntl() and soo_fcntl() which return 0
for F_SETFL and EOPNOTSUPP otherwise. Have all leaf filesystems
use genfs_fcntl().

Reviewed by: thorpej
Tested by: wrstuden


Revision tags: chs-ubc2-base
# 1.64 25-Jul-1999 thorpej

Add calls to lock the proclist as appropriate.


# 1.63 14-Jul-1999 thorpej

Fix a paste-o in procfs_lookup() introduced with the vnode locking changes.
Fixes PR #7961, Mario Kemper <magick@bundy.lip.owl.de>.


# 1.62 08-Jul-1999 wrstuden

Bump osrelease to 1.4E. Add layerfs files, remove null_subr.c.

Update coda to new struct lock in struct vnode.

make fdescfs, kernfs, portalfs, and procfs actually lock their vnodes.
It's not that hard.

Make unionfs set v_vnlock = NULL so any overlayed fs will call its
VOP_LOCK.


Revision tags: kame_141_19991130 netbsd-1-4-PATCH001 kame_14_19990705 kame_14_19990628 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.61 12-Mar-1999 christos

branches: 1.61.2; 1.61.4;
PR/7143: Jaromir Docelek: Add procfs/cmdline from Linux emulation


# 1.60 25-Jan-1999 msaitoh

Add /proc/#/map. From FreeBSD.


Revision tags: kenh-if-detach-base chs-ubc-base
# 1.59 08-Sep-1998 thorpej

- Use proclists[], rather than checking allproc and zombproc explicitly.
- Add some comments about locking.


# 1.58 13-Aug-1998 kleink

Per POSIX, fail with EINVAL if advisory locking is attempted on a file type
that doesn't support it, rather than using a homegrown EBADF or EOPNOTSUPP.


# 1.57 10-Aug-1998 matthias

create miscfs/genfs/genfs_vnops.c:genfs_enoioctl and make all the other
filesystems use it instead of a private version.


# 1.56 09-Aug-1998 perry

bzero->memset, bcopy->memcpy, bcmp->memcmp


# 1.55 03-Aug-1998 kleink

Recognize _PC_SYNC_IO.


Revision tags: eeh-paddr_t-base
# 1.54 21-Apr-1998 fvdl

procfs_readdir: in case of error, check if cookies actually have
been allocated before freeing them. From Wolfgang Solfrank.


# 1.53 01-Mar-1998 fvdl

Merge with Lite2 + local changes


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base marc-pcmcia-base
# 1.52 10-Oct-1997 fvdl

Bump last argument to VOP_READDIR to off_t (from u_long).


Revision tags: thorpej-signal-base
# 1.51 27-Aug-1997 thorpej

Fix a reversed argument which caused procfs_checkioperm() to always return
"OK". Add a few comments to avoid further confusion.


# 1.50 12-Aug-1997 thorpej

Fix the procfs hole described on current-users, similar to a fix for
FreeBSD by Sean Eric Fagan, but a bit different. This makes the checks
in the same places as sef's FreeBSD patch, but does not hardcode the
"kmem" group into the kernel, and also does a check identical to the
(3) and (4) checks in the NetBSD ptrace(2):

(1) it's not owned by you, or is set-id on exec (unless
you're root), or

(2) it's init, which controls the security level of the
entire system, and the system was not compiled with
permanently insecure mode turned on.


Revision tags: marc-pcmcia-bp
# 1.49 08-May-1997 mycroft

branches: 1.49.4;
Pass the vnode type to vaccess(), and use it when checking VEXEC. Make sure
that the mode bits passed to vaccess() and returned by foo_getattr() contain
only permission bits.


# 1.48 05-May-1997 mycroft

Need stat.h.


# 1.47 05-May-1997 mycroft

Eliminate bogus uses of V{READ,WRITE,EXEC}. Use S_I[RWX]{USR,GRP,OTH} where
appropriate.


# 1.46 28-Apr-1997 mycroft

Minor code cleanup.


Revision tags: is-newarp-before-merge is-newarp-base
# 1.45 25-Oct-1996 cgd

define path name string variables that we should not (and, thankfully, do
not) modify as 'const char *' rather 'char *'.


# 1.44 13-Oct-1996 christos

backout previous kprintf changes


# 1.43 10-Oct-1996 christos

printf -> kprintf, sprintf -> ksprintf


# 1.42 07-Sep-1996 mycroft

Implement poll(2).


# 1.41 01-Sep-1996 mycroft

Add a set of generic file system operations that most file systems use.
Also, fix some time stamp bogosities.


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 1.40 16-Mar-1996 christos

Fix printf format follies.


# 1.39 13-Feb-1996 mycroft

GC *_nullop(). Minor nits.


# 1.38 12-Feb-1996 christos

close PR/2063: procfs_rw prototyped twice with different prototypes


# 1.37 09-Feb-1996 christos

miscfs prototype changes


# 1.36 09-Feb-1996 mycroft

Fix vop_link, vop_symlink, and vop_remove semantics in several ways:
* Change the argument names to vop_link so they actually make sense.
* Implement vop_link and vop_symlink for all file systems, so they do proper
cleanup.
* Require the file system to decide whether or not linking and unlinking of
directories is allowed, and disable it for all current file systems.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.35 09-Oct-1995 mycroft

Use the index number as the cookie, rather than multiplying by UIO_MX.


# 1.34 09-Oct-1995 mycroft

Add support for cookies, mostly from Greg Hudson.


# 1.33 15-Apr-1995 cgd

fix timeval vs. timespec warnings


# 1.32 03-Feb-1995 mycroft

Return EROFS rather than ENOENT in many cases. Also some cosmetic cleanup.


# 1.31 27-Dec-1994 mycroft

Format police.


# 1.30 24-Dec-1994 ws

Implement and use a common access checking routine


# 1.29 14-Dec-1994 mycroft

Remove a_fp.


# 1.28 14-Nov-1994 christos

fixed struct comment


# 1.27 30-Oct-1994 cgd

be more careful with types, also pull in headers where necessary.


# 1.26 20-Oct-1994 cgd

update for new syscall args description mechanism


# 1.25 30-Aug-1994 mycroft

Convert process, file, and namei lists and hash tables to use queue.h.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.24 29-Jun-1994 cgd

New RCS ID's, take two. they're more aesthecially pleasant, and use 'NetBSD'


# 1.23 16-Jun-1994 mycroft

Remove an unneeded test.


# 1.22 15-Jun-1994 mycroft

Minor update from JSP after merging my changes.


# 1.21 08-Jun-1994 mycroft

Update to 4.4-Lite fs code, with local changes.


# 1.20 05-May-1994 cgd

lots of changes: prototype migration, move lots of variables, definitions,
and structure elements around. kill some unnecessary type and macro
definitions. standardize clock handling. More changes than you'd want.


# 1.19 15-Apr-1994 cgd

forgot these...


# 1.18 12-Apr-1994 cgd

be a bit smarter about determining if files shouldn't be seen by the user.
Also, DON'T allow a lookup to succeed on a file that's not visible!


# 1.17 15-Feb-1994 mycroft

Undo last change; executables is `file', not `a.out'.


# 1.16 14-Feb-1994 ws

Rename file -> a.out


# 1.15 14-Feb-1994 ws

Don't try to show a file for a process if there is none


# 1.14 28-Jan-1994 cgd

make a fpregs file.


# 1.13 20-Jan-1994 ws

Make procfs really work for debugging.
Implement not & notepg files in procfs.


# 1.12 09-Jan-1994 ws

Bug fixes and enhancements:
Make NFS serving work (BUT DON'T USE "attach" TO /proc/*/ctl FOR NOW!!!)
Make `curproc' a symbolic link
Add `.' and `..' entries to the directories.
Return better guesses on the size of the files.


# 1.11 05-Jan-1994 cgd

return size of 'reg' from getattr()


# 1.10 05-Jan-1994 cgd

make it compile (cleanly) for us


# 1.9 05-Jan-1994 cgd

add new procfs code, from Jan-Simon Pendry, jsp@sequent.com.
This is pretty-much "virgin", so that diffs can be done later.


# 1.8 18-Dec-1993 mycroft

Canonicalize all #includes.


Revision tags: magnum-base
# 1.7 16-Sep-1993 cgd

kill volatile warning.


# 1.6 07-Sep-1993 ws

branches: 1.6.2;
Changes to VFS readdir semantics
NFS changes for better cookie support
ISOFS changes for better Rockridge support and support for generation numbers


# 1.5 26-Aug-1993 pk

Implement setattr: mode for process entries; mode + uid/gid for the
PROCFS root directory.
Fixed omission in pfs_root() which came to light as a result of the above:
hold on to vnode for root dir.


# 1.4 25-Aug-1993 pk

Fixed improperly initialized nfsnode in pfs_lookup()


# 1.3 24-Aug-1993 pk

copyright update.


# 1.2 24-Aug-1993 pk

Rcs Id added.


# 1.1 24-Aug-1993 pk

branches: 1.1.1;
Initial version of a proc filesystem.


# 1.212 29-Apr-2020 thorpej

If the procfs mount is marked as linux-compat, then allow proc lookup
by any LWP ID in the proc, not just the canonical PID.


Revision tags: bouyer-xenpvh-base2
# 1.211 21-Apr-2020 ad

Revert the changes made in February to make cwdinfo use mostly lockless,
which relied on taking extra vnode refs.

Having benchmarked various experimental changes over the past few months it
seems that it's better to avoid vnode refs as much as possible. cwdi_lock
as a RW lock already did that to some extent for getcwd() and will permit
the same for namei() too.


Revision tags: phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base is-mlppp-base phil-wifi-20200406 ad-namecache-base3
# 1.210 24-Feb-2020 ad

branches: 1.210.4;
v_interlock -> vmobjlock


# 1.209 23-Feb-2020 ad

Merge from ad-namecache:

- Have a stab at clustering the members of vnode_t and vnode_impl_t in a
more cache-conscious way. With that done, go back to adjusting v_usecount
with atomics and keep vi_lock directly in vnode_impl_t (saves KVA).

- Allow VOP_LOCK(LK_NONE) for the benefit of VFS_VGET() and VFS_ROOT().
Make sure LK_UPGRADE always comes with LK_NOWAIT.

- Make cwdinfo use mostly lockless.


# 1.208 01-Feb-2020 riastradh

Load struct filedesc::fd_dt with atomic_load_consume.

Exceptions: when fd_refcnt <= 1, or when holding fd_lock.

While here:

- Restore KASSERT(mutex_owned(&fdp->fd_lock)) in fd_unused.
=> This is used only in fd_close and fd_abort, where it holds.
- Move bounds check assertion in fd_putfile to where it matters.
- Store fd_dt with atomic_store_release.
- Move load of fd_dt under lock in knote_fdclose.
- Omit membar_consumer in fdesc_readdir.
=> atomic_load_consume serves the same purpose now.
=> Was needed only on alpha anyway.


Revision tags: ad-namecache-base2 ad-namecache-base1 ad-namecache-base phil-wifi-20191119
# 1.207 29-Aug-2019 hannken

branches: 1.207.2;
Add missing operation VOP_GETPAGES() returning EFAULT.

Without this operation posix_fadvise(..., POSIX_FADV_WILLNEED)
would leave the v_interlock held.

Observed by maxv@


Revision tags: netbsd-9-base phil-wifi-20190609 isaki-audio2-base
# 1.206 30-Mar-2019 christos

branches: 1.206.4;
add a node for the process resource limits.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020
# 1.205 14-Oct-2018 jdolecek

remove M_CANFAIL flag for malloc(9) - it was completely ignored, so had
actually no effect


Revision tags: pgoyette-compat-0930 pgoyette-compat-0906
# 1.204 03-Sep-2018 riastradh

Rename min/max -> uimin/uimax for better honesty.

These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER! Some subsystems have

#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)


Revision tags: pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415
# 1.203 07-Apr-2018 hannken

branches: 1.203.2;
Lock the target cwdi and take an additional reference to the
vnode we are interested in to prevent it from disappearing
before getcwd_common().

Should fix PR kern/53096 (netbsd-8 crash on heavy disk I/O)


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.202 31-Dec-2017 christos

branches: 1.202.2;
Add an environ node


Revision tags: tls-maxphys-base-20171202
# 1.201 01-Dec-2017 christos

Allow procfs_kqfilter, since we allow poll. "go" does it.


# 1.200 08-Nov-2017 christos

fix locking, remove error(1) comments.


# 1.199 08-Nov-2017 christos

use p->p_path, remove unused code.


# 1.198 28-Aug-2017 kamil

Remove the filesystem tracing feature

This is a legacy interface from 4.4BSD, and it was
introduced to overcome shortcomings of ptrace(2) at that time, which are
no longer relevant (performance). Today /proc/#/ctl offers a narrow
subset of ptrace(2) commands and is not applicable for modern
applications use beyond simplistic tracing scenarios.

This removal will simplify kernel internals. Users will still be able to
use all the other /proc files.

This change won't affect other procfs files neither Linux compat
features within mount_procfs(8). /proc/#/ctl isn't available on Linux.

Remove:
- /proc/#/ctl from mount_procfs(8)
- P_FSTRACE note from the documentation of ps(1)
- /proc/#/ctl and filesystem tracing documentation from mount_procfs(8)
- KAUTH_REQ_PROCESS_PROCFS_CTL documentation from kauth(9)
- source code file miscfs/procfs/procfs_ctl.c
- PFSctl and procfs_doctl() from sys/miscfs/procfs/procfs.h
- KAUTH_REQ_PROCESS_PROCFS_CTL from sys/sys/kauth.h
- PSL_FSTRACE (0x00010000) from sys/sys/proc.h
- P_FSTRACE (0x00010000) from sys/sys/sysctl.h

Reduce code complexity after removal of this functionality.

Update TODO.ptrace accordingly: remove two entries about /proc tracing.

Do not keep legacy notes as comments in the headers about removed
PSL_FSTRACE / P_FSTRACE, as this interface had little number of users
(close or equal to zero).

Proposed on tech-kern@.

All filesystem tracing utility users are encouraged to switch to ptrace(2).

Sponsored by <The NetBSD Foundation>


Revision tags: matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base
# 1.197 26-May-2017 riastradh

branches: 1.197.2;
Make VOP_RECLAIM do the last unlock of the vnode.

VOP_RECLAIM naturally has exclusive access to the vnode, so having it
locked on entry is not strictly necessary -- but it means if there
are any final operations that must be done on the vnode, such as
ffs_update, requiring exclusive access to it, we can now kassert that
the vnode is locked in those operations.

We can't just have the caller release the last lock because some file
systems don't use genfs_lock, and require the vnode to remain valid
for VOP_UNLOCK to work, notably unionfs.


Revision tags: prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.196 11-Apr-2017 riastradh

Make VOP_INACTIVE preserve vnode lock on return.

Discussed on tech-kern:
https://mail-index.netbsd.org/tech-kern/2017/04/01/msg021751.html

Ride 7.99.68, a bumpy bus of incremental vfs improvements!


Revision tags: jdolecek-ncq-base
# 1.195 30-Mar-2017 christos

add an auxv node.


Revision tags: pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004 localcount-20160914
# 1.194 20-Aug-2016 hannken

branches: 1.194.2;
Remove now obsolete operation vcache_remove().

Welcome to 7.99.36


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 nick-nhusb-base-20150921 nick-nhusb-base-20150606
# 1.193 20-Apr-2015 riastradh

branches: 1.193.2;
Make VOP_LINK return directory still locked and referenced.

Ride 7.99.10 bump.


Revision tags: nick-nhusb-base-20150406 nick-nhusb-base
# 1.192 05-Sep-2014 matt

branches: 1.192.2;
Try not to use f_data, use f_{vnode,socket,pipe,mqueue,kqueue,ksem} to get
a correctly typed pointer.


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.191 27-Jul-2014 hannken

branches: 1.191.2; 1.191.4; 1.191.8;
Change procfs from hashlist to vcache.
- Key is (type, pid, fd)
- Remove argument "p" from procfs_allocvp(). It is only used
when "type == PFSfd". Lookup the proc with proc_find() when
procfs_loadvnode() needs it.
- Use a vfs_vnode_iterator for procfs_revoke_vnodes().


# 1.190 25-Jul-2014 dholland

Add VOP_FALLOCATE and VOP_FDISCARD to every vnode ops table I can
find.

The filesystem ones all call genfs_eopnotsupp - right now I am only
implementing the plumbing and we can implement fallocate and/or
fdiscard for files later.

The device ones call spec_fallocate (which is also genfs_eopnotsupp)
and spec_fdiscard, which dispatches to the device-level op.

The fifo ones all call vn_fifo_bypass, which also ends up being
EOPNOTSUPP.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base
# 1.189 07-Feb-2014 hannken

branches: 1.189.2;
Change vnode operation lookup to return the resulting vnode *vpp unlocked.
Change cache_lookup() to return an unlocked vnode.

Discussed on tech-kern@

Welcome to 6.99.31


# 1.188 23-Jan-2014 hannken

Change vnode operations create, mknod, mkdir and symlink to return
the resulting vnode *vpp unlocked.

Discussed on tech-kern@

Welcome to 6.99.30


# 1.187 17-Jan-2014 hannken

Change vnode operations create, mknod, mkdir and symlink to keep the
directory node dvp locked on return.

Discussed on tech-kern@

Welcome to 6.99.29


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base
# 1.186 18-Mar-2013 plunky

branches: 1.186.6;
C99 section 6.7.2.3 (Tags) Note 3 states that:

A type specifier of the form

enum identifier

without an enumerator list shall only appear after the type it
specifies is complete.

which means that we cannot pass an "enum vtype" argument to
kauth_access_action() without fully specifying the type first.
Unfortunately there is a complicated include file loop which
makes that difficult, so convert this minimal function into a
macro (and capitalize it).

(ok elad@)


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 1.185 25-Nov-2012 christos

do something reasonable with kernel semaphores.


Revision tags: yamt-pagecache-base6 jmcneill-usbmp-base10
# 1.184 28-May-2012 christos

branches: 1.184.2;
add a task process subdirectory for emul linux


Revision tags: yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 1.183 13-Mar-2012 elad

Replace the remaining KAUTH_GENERIC_ISSUSER authorization calls with
something meaningful. All relevant documentation has been updated or
written.

Most of these changes were brought up in the following messages:

http://mail-index.netbsd.org/tech-kern/2012/01/18/msg012490.html
http://mail-index.netbsd.org/tech-kern/2012/01/19/msg012502.html
http://mail-index.netbsd.org/tech-kern/2012/02/17/msg012728.html

Thanks to christos, manu, njoly, and jmmv for input.

Huge thanks to pgoyette for spinning these changes through some build
cycles and ATF.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.182 04-Sep-2011 jmcneill

branches: 1.182.2; 1.182.6;
PR# kern/45021: Please support /emul/linux/proc/version

Add /proc/version for procfs with -o linux. The version reported depends
on the emulation type of the calling process:

$ cat /proc/version
NetBSD version 5.99.55 (netbsd@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) NetBSD 5.99.55 (GENERIC) #39: Sun Sep 4 09:10:05 EDT 2011

$ /emul/linux/bin/cat /proc/version
Linux version 2.6.18 (linux@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) #0 Wed Mar 3 03:03:03 PST 2010

$ /emul/linux32/bin/cat /proc/version
Linux version 2.6.18 (linux32@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) #0 Wed Mar 3 03:03:03 PST 2010


# 1.181 23-Jun-2011 christos

From Aleksey Cheusov: Don't make it easy for compromised systems to bypass
ASLR protections by providing the mapping addresses of programs to everyone.


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base matt-mips64-premerge-20101231 uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10 rmind-uvmplock-base
# 1.180 01-Jul-2010 rmind

Remove pfind() and pgfind(), fix locking in various broken uses of these.
Rename real routines to proc_find() and pgrp_find(), remove PFIND_* flags
and have consistent behaviour. Provide proc_find_raw() for special cases.
Fix memory leak in sysctl_proc_corename().

COMPAT_LINUX: rework ptrace() locking, minimise differences between
different versions per-arch.

Note: while this change adds some formal cosmetics for COMPAT_DARWIN and
COMPAT_IRIX - locking there is utterly broken (for ages).

Fixes PR/43176.


# 1.179 24-Jun-2010 hannken

Clean up vnode lock operations pass 2:

VOP_UNLOCK(vp, flags) -> VOP_UNLOCK(vp): Remove the unneeded flags argument.

Welcome to 5.99.32.

Discussed on tech-kern.


# 1.178 08-Jun-2010 hannken

Procfs_lookup() does not lookup directory descriptors in the fd/
subdirectory. There is no need for recursive vnode locking here.

Ok: Christos Zoulas <christos@netbsd.org>


Revision tags: uebayasi-xip-base1 yamt-nfs-mp-base9 uebayasi-xip-base
# 1.177 08-Jan-2010 pooka

branches: 1.177.2; 1.177.4;
The VATTR_NULL/VREF/VHOLD/HOLDRELE() macros lost their will to live
years ago when the kernel was modified to not alter ABI based on
DIAGNOSTIC, and now just call the respective function interfaces
(in lowercase). Plenty of mix'n match upper/lowercase has creeped
into the tree since then. Nuke the macros and convert all callsites
to lowercase.

no functional change


Revision tags: matt-premerge-20091211 yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 jym-xensuspend-nbase
# 1.176 03-Jul-2009 elad

Where possible, extract the file-system's access() routine to two internal
functions: the first checking if the operation is possible (regardless of
permissions), the second checking file-system permissions, ACLs, etc.

Mailing list reference:

http://mail-index.netbsd.org/tech-kern/2009/06/21/msg005311.html


# 1.175 23-Jun-2009 elad

Move the implementation of vaccess() to genfs_can_access(), in line with
the other routines of the same spirit.

Adjust file-system code to use it.

Keep vaccess() for KPI compatibility and to keep element of least
surprise. A "diagnostic" message warning that vaccess() is deprecated will
be printed when it's used (obviously, only in DIAGNOSTIC kernels).

No objections on tech-kern@:

http://mail-index.netbsd.org/tech-kern/2009/06/21/msg005310.html


Revision tags: yamt-nfs-mp-base5
# 1.174 24-May-2009 ad

More changes to improve kern_descrip.c.

- Avoid atomics in more places.
- Remove the per-descriptor mutex, and just use filedesc_t::fd_lock.
It was only being used to synchronize close, and in any case we needed
to take fd_lock to free the descriptor slot.
- Optimize certain paths for the <NDFDFILE case.
- Sprinkle more comments and assertions.
- Cache more stuff in filedesc_t.
- Fix numerous minor bugs spotted along the way.
- Restructure how the open files array is maintained, for clarity and so
that we can eliminate the membar_consumer() call in fd_getfile(). This is
mostly syntactic sugar; the main functional change is that fd_nfiles now
lives alongside the open file array.

Some measurements with libmicro:

- simple file syscalls are like close() are between 1 to 10% faster.
- some nice improvements, e.g. poll(1000) which is ~50% faster.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 nick-hppapmap-base2 jym-xensuspend-base nick-hppapmap-base mjf-devfs2-base
# 1.173 17-Dec-2008 cegger

branches: 1.173.2;
kill MALLOC and FREE macros.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 haad-dm-base2 haad-nbase2 ad-audiomp2-base netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 haad-dm-base
# 1.172 05-Sep-2008 skrll

branches: 1.172.2;
PR/39324 kernel diagnostic assertion "l->l_stat != LSZOMB" failed.

Ignore procs with zero or all LSZOMB LWPs. Get a non-LSZOMB LWP to perform
operations against as part of the deal.

procfs really needs to be updated to support multi-threading fully.
Hi Antti!


# 1.171 05-Sep-2008 skrll

ANSIfy


Revision tags: simonb-wapbl-nbase simonb-wapbl-base
# 1.170 02-Jul-2008 rmind

branches: 1.170.2;
Remove proc_representative_lwp(), use a simple LIST_FIRST() instead.
OK by <ad>.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base
# 1.169 28-Apr-2008 martin

branches: 1.169.2; 1.169.4;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-nfs-mp-base
# 1.168 24-Apr-2008 ad

branches: 1.168.2;
Merge proc::p_mutex and proc::p_smutex into a single adaptive mutex, since
we no longer need to guard against access from hardware interrupt handlers.

Additionally, if cloning a process with CLONE_SIGHAND, arrange to have the
child process share the parent's lock so that signal state may be kept in
sync. Partially addresses PR kern/37437.


# 1.167 24-Apr-2008 ad

Network protocol interrupts can now block on locks, so merge the globals
proclist_mutex and proclist_lock into a single adaptive mutex (proc_lock).
Implications:

- Inspecting process state requires thread context, so signals can no longer
be sent from a hardware interrupt handler. Signal activity must be
deferred to a soft interrupt or kthread.

- As the proc state locking is simplified, it's now safe to take exit()
and wait() out from under kernel_lock.

- The system spends less time at IPL_SCHED, and there is less lock activity.


Revision tags: yamt-pf42-baseX yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14
# 1.166 21-Mar-2008 ad

branches: 1.166.2;
Catch up with descriptor handling changes. See kern_descrip.c revision
1.173 for details.


Revision tags: keiichi-mipv6-nbase nick-net80211-sync-base keiichi-mipv6-base bouyer-xeni386-nbase matt-armv6-nbase mjf-devfs-base hpcarm-cleanup-base
# 1.165 23-Jan-2008 elad

branches: 1.165.6;
Tons of process scope changes.

- Add a KAUTH_PROCESS_SCHEDULER action, to handle scheduler related
requests, and add specific requests for set/get scheduler policy and
set/get scheduler parameters.

- Add a KAUTH_PROCESS_KEVENT_FILTER action, to handle kevent(2) related
requests.

- Add a KAUTH_DEVICE_TTY_STI action to handle requests to TIOCSTI.

- Add requests for the KAUTH_PROCESS_CANSEE action, indicating what
process information is being looked at (entry itself, args, env,
open files).

- Add requests for the KAUTH_PROCESS_RLIMIT action indicating set/get.

- Add requests for the KAUTH_PROCESS_CORENAME action indicating set/get.

- Make bsd44 secmodel code handle the newly added rqeuests appropriately.

All of the above make it possible to issue finer-grained kauth(9) calls in
many places, removing some KAUTH_GENERIC_ISSUSER requests.

- Remove the "CAN" from KAUTH_PROCESS_CAN{KTRACE,PROCFS,PTRACE,SIGNAL}.

Discussed with christos@ and yamt@.


Revision tags: bouyer-xeni386-base matt-armv6-base
# 1.164 02-Jan-2008 ad

Merge vmlocking2 to head.


Revision tags: vmlocking2-base3 yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 vmlocking-nbase jmcneill-pm-base reinoud-bufcleanup-base
# 1.163 26-Nov-2007 pooka

branches: 1.163.2; 1.163.6;
Remove the "struct lwp *" argument from all VFS and VOP interfaces.
The general trend is to remove it from all kernel interfaces and
this is a start. In case the calling lwp is desired, curlwp should
be used.

quick consensus on tech-kern


Revision tags: bouyer-xenamd64-base2 bouyer-xenamd64-base
# 1.162 09-Nov-2007 christos

make the last argument of procfs_dir size_t


# 1.161 07-Nov-2007 ad

Merge from vmlocking:

- pool_cache changes.
- Debugger/procfs locking fixes.
- Other minor changes.


Revision tags: jmcneill-base yamt-x86pmap-base4 yamt-x86pmap-base3 vmlocking-base
# 1.160 10-Oct-2007 ad

branches: 1.160.2; 1.160.4;
Merge from vmlocking:

- Split vnode::v_flag into three fields, depending on field locking.
- simple_lock -> kmutex in a few places.
- Fix some simple locking problems.


# 1.159 08-Oct-2007 ad

Merge file descriptor locking, cwdi locking and cross-call changes
from the vmlocking branch.


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base2 yamt-x86pmap-base matt-mips64-base
# 1.158 22-Jul-2007 pooka

branches: 1.158.4; 1.158.6; 1.158.8; 1.158.10;
Don't allow getcwd() on procfs vnodes and provide "/" as the path
instead of the result from getcwd(). The works around locking
panics caused by namei calling VOP_READLINK while holding on to a
directory lock and getcwd() trying to acquire that lock. The real
fix would be to get rid of getcwd() calls within VOPs (not locking
safe), but that's not a viable option in the netbsd-4 timeframe.

Suggestion for workaround from David Holland.


Revision tags: nick-csl-alignment-base mjf-ufs-trans-base
# 1.157 24-May-2007 agc

branches: 1.157.2;
Extend the Linux emulation of /proc to include

/proc/stat
/proc/loadavg and
/proc/<pid>/statm.

These are only present when -o linux is specified as a mount option
to procfs.

Factor out some common code so that it can be used by a number of
functions.

XXX The values returned in the statm emulation need to be verified.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 1.156 04-Apr-2007 rmind

Unfortunately, missed procfs_proc_unlock() in previous.
Pointed out by pooka@


# 1.155 04-Apr-2007 rmind

procfs_readlink: Handle a possible fail of fd_getfile(), also, we
do not need to check for error again.
CID: 4436


# 1.154 09-Mar-2007 ad

branches: 1.154.2; 1.154.4;
- Make the proclist_lock a mutex. The write:read ratio is unfavourable,
and mutexes are cheaper use than RW locks.
- LOCK_ASSERT -> KASSERT in some places.
- Hold proclist_lock/kernel_lock longer in a couple of places.


# 1.153 04-Mar-2007 christos

Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.


# 1.152 03-Mar-2007 salo

Don't prepend rootvnode to the path in non-NULL case for exe links.
It breaks procfs in chroot.

from <christos>, tested by me.


Revision tags: ad-audiomp-base
# 1.151 19-Feb-2007 pooka

When checking for file validity under pid/, do proper proc->lwp
lookup (fsvo proper) instead of fiddling directly with the lwp
list.


# 1.150 18-Feb-2007 pooka

Don't check for validity of p in lookup for root nodes, since it
will always be NULL. Rather, just call pt_valid with NULL directly
and let it decide if we're a linux mount or not.


# 1.149 17-Feb-2007 pavel

Change the process/lwp flags seen by userland via sysctl back to the
P_*/L_* naming convention, and rename the in-kernel flags to avoid
conflict. (P_ -> PK_, L_ -> LW_ ). Add back the (now unused) LSDEAD
constant.

Restores source compatibility with pre-newlock2 tools like ps or top.

Reviewed by Andrew Doran.


# 1.148 16-Feb-2007 pooka

branches: 1.148.2;
In lookup, when checking for procfs process node validity, target the
process we're trying to get information about through procfs, not
the caller of lookup.

fixes 'ls -l /proc/*/file' panic, which would occur when trying to
lookup "file" for a kernel thread, which doesn't have p->p_textvp.


# 1.147 15-Feb-2007 ad

Need to acquire procp->p_mutex for procfs_dir().


# 1.146 11-Feb-2007 ad

Eliminate a couple of reference count and mutex leaks.


Revision tags: post-newlock2-merge
# 1.145 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 1.144 25-Dec-2006 elad

PR/35226: Johann Franz: Problems with permissions in
/usr/pkg/emul/linux/proc .

Okay mlelstv@


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3
# 1.143 09-Dec-2006 chs

a smorgasbord of improvements to vnode locking and path lookup:
- LOCKPARENT is no longer relevant for lookup(), relookup() or VOP_LOOKUP().
these now always return the parent vnode locked. namei() works as before.
lookup() and various other paths no longer acquire vnode locks in the
wrong order via vrele(). fixes PR 32535.
as a nice side effect, path lookup is also up to 25% faster.
- the above allows us to get rid of PDIRUNLOCK.
- also get rid of WANTPARENT (just use LOCKPARENT and unlock it).
- remove an assumption in layer_node_find() that all file systems implement
a recursive VOP_LOCK() (unionfs doesn't).
- require that all file systems supply vfs_vptofh and vfs_fhtovp routines.
fill in eopnotsupp() for file systems that don't support being exported
and remove the checks for NULL. (layerfs calls these without checking.)
- in union_lookup1(), don't change refcounts in the ISDOTDOT case, just
adjust which vnode is locked. fixes PR 33374.
- apply fixes for ufs_rename() from ufs_vnops.c rev. 1.61 to ext2fs_rename().


# 1.142 04-Dec-2006 christos

From Nicolas Joly: restore previous behavior in procfs_validfile_linux, since
readdir passes a NULL lwp.


# 1.141 03-Dec-2006 elad

Move kauth(9) call to where it belongs. Noticed by Nicolas Joly, thanks!


Revision tags: netbsd-4-base
# 1.140 28-Nov-2006 elad

branches: 1.140.2;
Move ktrace, ptrace, systrace, and procfs to use kauth(9).

First, remove process_checkioperm() calls from MD code. Similar checks
using kauth(9) routines (on the process scope, using appropriate action)
are done in the callers.

Add secmodel back-end to handle each subsystem.


# 1.139 25-Nov-2006 skrll

Expose the 'exe' symlink to the process realpath in NetBSD as well. An
example user is gdb.

OK'd by christos.


# 1.138 16-Nov-2006 christos

__unused removal on arguments; approved by core.


# 1.137 29-Oct-2006 christos

add an "emul" file node.


# 1.136 25-Oct-2006 christos

1. fix procfs_validfile{,_linux} to test for NULL pointers properly.
2. make "exe" entry be a symlink to the executable, instead of pointing
directly to the vnode of the executable.
3. factor out commonly used code.


Revision tags: yamt-splraiseipl-base2
# 1.135 12-Oct-2006 christos

- sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386


# 1.134 20-Sep-2006 manu

Emulate Linux's /proc/devices


Revision tags: abandoned-netbsd-4-base yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base rpaulo-netinet-merge-pcb-base
# 1.133 13-Jun-2006 yamt

branches: 1.133.6; 1.133.8;
use KAUTH_PROCESS_CANSEE rather than CURTAIN where appropriate.


# 1.132 13-Jun-2006 yamt

remove unnecessary arguments from kauth_authorize_process.
ie. make it similar to the one found in apple TN.


# 1.131 07-Jun-2006 kardel

merge FreeBSD timecounters from branch simonb-timecounters
- struct timeval time is gone
time.tv_sec -> time_second
- struct timeval mono_time is gone
mono_time.tv_sec -> time_uptime
- access to time via
{get,}{micro,nano,bin}time()
get* versions are fast but less precise
- support NTP nanokernel implementation (NTP API 4)
- further reading:
Timecounter Paper: http://phk.freebsd.dk/pubs/timecounter.pdf
NTP Nanokernel: http://www.eecis.udel.edu/~mills/ntp/html/kern.html


Revision tags: yamt-pdpolicy-base5 simonb-timecounters-base
# 1.130 14-May-2006 elad

branches: 1.130.2;
integrate kauth.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 elad-kernelauth-base yamt-pdpolicy-base yamt-uio_vmspace-base5
# 1.129 02-Feb-2006 christos

branches: 1.129.2; 1.129.4; 1.129.6; 1.129.8;
PR/32692: Matthew Mondor: linux compatibility in /proc/self should point
directly to the directory containing the pid instead of pointing to
/proc/curproc, because some programs rely on calling readlink on /proc/self
to get the pid.


# 1.128 11-Dec-2005 christos

branches: 1.128.2; 1.128.4;
merge ktrace-lwp.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base ktrace-lwp-base
# 1.127 02-Nov-2005 yamt

merge yamt-vop branch. remove following VOPs.

VOP_BLKATOFF
VOP_VALLOC
VOP_BALLOC
VOP_REALLOCBLKS
VOP_VFREE
VOP_TRUNCATE
VOP_UPDATE


Revision tags: yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 1.126 01-Oct-2005 atatat

branches: 1.126.2;
Add "cwd" and "root" symlinks to each process's directory. The cwd
link points to the process's current working directory, and the root
link points to the process's root directory. What else would you
expect?

For directories that are out of reach (caller is in a chroot, target
process is in a different chroot, etc), the links point to "/"
instead.


# 1.125 11-Sep-2005 elad

Implement curtain for procfs.


# 1.124 30-Aug-2005 xtraeme

Remove __P()


# 1.123 29-May-2005 christos

branches: 1.123.2;
- sprinkle const
- avoid shadowed variables.


Revision tags: kent-audio2-base
# 1.122 02-Apr-2005 christos

PR/29782: Martin Husemann: procfs can not unmount when some process has its
current directory in curproc. Fix from Pedro Martelletto:
We cannot call vgone() from procfs_inactive() if we are coming from
vclean(). that's what's probably causing the deadlock.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 yamt-km-base4 yamt-km-base3 netbsd-3-base
# 1.121 26-Feb-2005 perry

nuke trailing whitespace


Revision tags: yamt-km-base2 yamt-km-base kent-audio1-beforemerge kent-audio1-base
# 1.120 04-Oct-2004 yamt

branches: 1.120.4; 1.120.6;
procfs_readdir:
- return correct cookie when buffer size is small.
- simplify logic.


# 1.119 04-Oct-2004 yamt

procfs_readdir: remove a redundant assignment.


# 1.118 02-Oct-2004 yamt

procfs_getattr: correct size of /proc/self.


# 1.117 01-Oct-2004 yamt

procfs_readdir:
- fix a locking problem, using proclist_foreach_call. PR/27098.
- correct snprintf size argument.


# 1.116 01-Oct-2004 yamt

procfs_readdir: fix an offset handling bug after addition of /proc/self.


# 1.115 01-Oct-2004 yamt

procfs_readdir: use a list macro.


# 1.114 20-Sep-2004 jdolecek

add 'mounts' file for -o linux, which lists all currently mounted
filesystems; Linux glibc statvfs() uses this to get some of mount flags,
and this file is also useful as /emul/linux/etc/mtab (via symlink)


# 1.113 29-Apr-2004 jrf

Removed remaining caddr_t casts we do not need in miscfs. Recompiled
kernel and ran for a day or so. There are still some caddr_t types in
the arguments of some calls, I will do those separately (later) as
they touch a lot more of the system.
Approved by christos@NetBSD.org.


# 1.112 22-Apr-2004 itojun

sprintf -> snprintf


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.111 15-Feb-2004 jdolecek

unlock the descriptor table simple lock after fd_getfile() call in
procfs_readdir()
fixes procfs locking problems reported on current-users@, problem place
found by enami tsugutomo


# 1.110 30-Oct-2003 simonb

Remove some assigned-to but otherwise unused variables.


# 1.109 27-Sep-2003 darcy

Changes as discussed with itojun on tech-kern. I have modified the enums
to have KFS or PFS differentiators. Further I have wrapped the enum in
procfs in "#ifdef _KERNEL" as it is done in kernfs.

To see the discussion go to http://mail-index.NetBSD.org/tech-kern/2003/09/
and look for "Mismatched enums in include files" in the list.


# 1.108 07-Sep-2003 itojun

remove meaningless line (variable overwritten 2 lines below)


# 1.107 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.


# 1.106 29-Jun-2003 fvdl

branches: 1.106.2;
Back out the lwp/ktrace changes. They contained a lot of colateral damage,
and need to be examined and discussed more.


# 1.105 29-Jun-2003 thorpej

Undo part of the ktrace/lwp changes. In particular:
* Remove the "lwp *" argument that was added to vget(). Turns out
that nothing actually used it!
* Remove the "lwp *" arguments that were added to VFS_ROOT(), VFS_VGET(),
and VFS_FHTOVP(); all they did was pass it to vget() (which, as noted
above, didn't use it).
* Remove all of the "lwp *" arguments to internal functions that were added
just to appease the above.


# 1.104 28-Jun-2003 darrenr

Pass lwp pointers throughtout the kernel, as required, so that the lwpid can
be inserted into ktrace records. The general change has been to replace
"struct proc *" with "struct lwp *" in various function prototypes, pass
the lwp through and use l_proc to get the process pointer when needed.

Bump the kernel rev up to 1.6V


# 1.103 28-May-2003 christos

Add /proc/<pid>/stat for linux compat. j2sdk1.4.2 depends on it.


# 1.102 18-Apr-2003 christos

Make symlinks for directories that point to the actual directory.
Make symlinks to [kqueue] and [misc] for kqueue and misc fds.


# 1.101 17-Apr-2003 jdolecek

do not show nodes corresponding to directory descriptors for process
in fd/ subdirectory, nor allow lookup/open for the nodes
this fixes PR kern/21187 for good, and also avoids interesting directory
locking issues


# 1.100 17-Apr-2003 jdolecek

procfs_readdir(): in Pfd case, only show descriptors of types we want
how to represent (vnodes, fifo, pipes); also use fd_getfile() et al

this avoids annoying EOPNOTSUPP error messages from ls -F and such


# 1.99 17-Apr-2003 jdolecek

procfs_lookup(): use fd_getfile() et al in Pfd case


# 1.98 17-Apr-2003 jdolecek

use fd_getfile() in procfs_getfp(), and FILE_USE()/FILE_UNUSE() the
returned file descriptor pointer appropriately


# 1.97 17-Apr-2003 jdolecek

make some local arrays/variables static + const


# 1.96 10-Apr-2003 jdolecek

use former genfs_eopnotsupp_rele() as genfs_eopnotsupp(), so that vnodes
are vput()/vrele()d as necessary - some filesystems did use the wrong
one for some ops, and it's just safer to not take the chance

based on suggestion by Bill Studenmund


# 1.95 05-Apr-2003 dsl

Remove pointless check against PID_MAX. Let pfind() do the validation.
(The new pid allocation code may decide to allocate pids above PID_MAX.)


# 1.94 25-Feb-2003 jrf

This addresses PR kerm/19989. Thanks to hamajima@nagoya.ydc.co.jp for submitting this patch which enables /proc/uptime for linux emul. Patch reviewed by atatat@netbsd.org and tron@netbsd.org, approved by tron@netbsd.org.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 1.93 04-Jan-2003 martin

Cast off_t expression to long long to match format even on 64 bit
plattforms.

Shouldn't we introduce a PRIoff_t macro to create such format strings?


# 1.92 03-Jan-2003 christos

add LK_CANRECURSE in the locking of /dev/<pid>/fd/<n> and remove the curproc
kludge. Thanks to fvdl.


# 1.91 03-Jan-2003 christos

Implement /proc/<pid>/fd/<n>. This is work in progress. Questionable things:
- Is it ok to convert DTYPE_PIPE to VFIFO and DTYPE_SOCKET to VSOCK?
- XXX: Avoid locking issue in ls -Rl /proc by avoiding curproc
- Does I/O to pipes work?
- XXX: Are there security implications?


Revision tags: fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge gehenna-devsw-base kqueue-base
# 1.90 03-Aug-2002 simonb

Just use the "time" variable in the *_getattr functions instead of a call
to (the potentially expensive) microtime().


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.89 09-May-2002 thorpej

branches: 1.89.2;
Move code shared by procfs and the kernel proper out of procfs and
into the kernel proper (renaming functions from procfs_* to process_*).


Revision tags: eeh-devprop-base newlock-base ifpoll-base
# 1.88 12-Jan-2002 christos

Don't hide the real return code with EPERM.


# 1.87 06-Dec-2001 chs

add a VOP_PUTPAGES method for all the filesystems that don't have pages,
just unlock the interlock.


# 1.86 05-Dec-2001 thorpej

* Allow machine-dependent code to specify hooks for ptrace(2)
(__HAVE_PTRACE_MACHDEP) and procfs (__HAVE_PROCFS_MACHDEP).
These changes will allow platforms like x86 (XMM) and PowerPC
(AltiVec) to export extended register sets in a sane manner.

* Use __HAVE_PTRACE_MACHDEP to export x86 XMM registers (standard
FP + SSE/SSE2) using PT_{GET,SET}XMMREGS (in the machdep
ptrace request space).
* Use __HAVE_PROCFS_MACHDEP to export x86 XMM registers via
/proc/N/xmmregs in procfs.


Revision tags: thorpej-mips-cache-base
# 1.85 10-Nov-2001 lukem

add RCSIDs


# 1.84 06-Nov-2001 simonb

Remove some variables that are set but never used.


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base
# 1.83 31-Aug-2001 chs

branches: 1.83.2; 1.83.4;
map files are zero-length.


# 1.82 03-Jun-2001 chs

branches: 1.82.2;
procfs_bmap() should never be called, make it a "bad op".
let procfs_mmap() use the default error method.


Revision tags: thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 1.81 14-Apr-2001 kleink

In procfs_readdir(), give /proc/# directories DT_DIR (rather than DT_REG).


# 1.80 30-Mar-2001 fvdl

Bump va_blocksize for the map files some more, so that programs with
quite a few mappings have a chance of being handled correctly if
st_blksize is looked at.


# 1.79 29-Mar-2001 fvdl

For -o linux mounts, add some code to emulate /proc/#/maps.
Needs NAMECACHE_ENTER_REVERSE to include filenames.


# 1.78 21-Feb-2001 jdolecek

branches: 1.78.2;
make some more constant arrays 'const'


# 1.77 22-Jan-2001 jdolecek

make filesystem vnodeop, specop, fifoop and vnodeopv_* arrays const


# 1.76 17-Jan-2001 fvdl

Add a few linux-style files, only enabled when -o linux is specified
for the mount. Currently these are /proc/cpuinfo and /proc/meminfo.
The former only does something on i386 right now.


# 1.75 24-Nov-2000 chs

remove dead code and other misc cleanup.


# 1.74 09-Aug-2000 tv

Only show the "exe" entry to Linux processes, suggested by christos.
Since there are actually three struct emul's for linux, use the e_name
field to determine eligibility with strcmp().


# 1.73 09-Aug-2000 tv

Some versions of Linux libc look for /proc/.../exe instead of /proc/../file.
Add an entry for "exe" that is the same as "file", provided only if
COMPAT_LINUX is set.


# 1.72 03-Aug-2000 thorpej

MALLOC()/FREE() are not to be used for variable sized allocations.


# 1.71 28-Jun-2000 mrg

<vm/vm.h> -> <uvm/uvm_extern.h>


Revision tags: netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 1.70 30-Mar-2000 simonb

branches: 1.70.4;
Delete duplicate declaration of atopid().


Revision tags: chs-ubc2-newbase wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base fvdl-softdep-base
# 1.69 02-Sep-1999 thorpej

branches: 1.69.2; 1.69.8;
Make /proc/self a symlink to /proc/curproc. I've observed Linux programs
that expect /proc/self/cmdline to exist.


# 1.68 25-Aug-1999 sommerfeld

Change variable used for directory offset from "int" to "off_t".
Overkill, but avoids a host of truncation problems.


# 1.67 24-Aug-1999 sommerfeld

Fix PR8270:

Problem turned out to be due to improper handling of reads beyond EOF:
they should just return without error with the uio unchanged, and the
caller will recognize this as a zero-byte return (EOF).

The previous fix to protect directory reads against bogus uio_offset
values returned EINVAL, which broke mount -o union, which only
union'ed in the lower directory if the upper directory cleanly
returned EOF.

While we're here, protect kernfs as well.


# 1.66 14-Aug-1999 christos

protect against large uio_offset


# 1.65 03-Aug-1999 wrstuden

Add support for fcntl(2) to generate VOP_FCNTL calls. Any fcntl
call with F_FSCTL set and F_SETFL calls generate calls to a new
fileop fo_fcntl. Add genfs_fcntl() and soo_fcntl() which return 0
for F_SETFL and EOPNOTSUPP otherwise. Have all leaf filesystems
use genfs_fcntl().

Reviewed by: thorpej
Tested by: wrstuden


Revision tags: chs-ubc2-base
# 1.64 25-Jul-1999 thorpej

Add calls to lock the proclist as appropriate.


# 1.63 14-Jul-1999 thorpej

Fix a paste-o in procfs_lookup() introduced with the vnode locking changes.
Fixes PR #7961, Mario Kemper <magick@bundy.lip.owl.de>.


# 1.62 08-Jul-1999 wrstuden

Bump osrelease to 1.4E. Add layerfs files, remove null_subr.c.

Update coda to new struct lock in struct vnode.

make fdescfs, kernfs, portalfs, and procfs actually lock their vnodes.
It's not that hard.

Make unionfs set v_vnlock = NULL so any overlayed fs will call its
VOP_LOCK.


Revision tags: kame_141_19991130 netbsd-1-4-PATCH001 kame_14_19990705 kame_14_19990628 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.61 12-Mar-1999 christos

branches: 1.61.2; 1.61.4;
PR/7143: Jaromir Docelek: Add procfs/cmdline from Linux emulation


# 1.60 25-Jan-1999 msaitoh

Add /proc/#/map. From FreeBSD.


Revision tags: kenh-if-detach-base chs-ubc-base
# 1.59 08-Sep-1998 thorpej

- Use proclists[], rather than checking allproc and zombproc explicitly.
- Add some comments about locking.


# 1.58 13-Aug-1998 kleink

Per POSIX, fail with EINVAL if advisory locking is attempted on a file type
that doesn't support it, rather than using a homegrown EBADF or EOPNOTSUPP.


# 1.57 10-Aug-1998 matthias

create miscfs/genfs/genfs_vnops.c:genfs_enoioctl and make all the other
filesystems use it instead of a private version.


# 1.56 09-Aug-1998 perry

bzero->memset, bcopy->memcpy, bcmp->memcmp


# 1.55 03-Aug-1998 kleink

Recognize _PC_SYNC_IO.


Revision tags: eeh-paddr_t-base
# 1.54 21-Apr-1998 fvdl

procfs_readdir: in case of error, check if cookies actually have
been allocated before freeing them. From Wolfgang Solfrank.


# 1.53 01-Mar-1998 fvdl

Merge with Lite2 + local changes


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base marc-pcmcia-base
# 1.52 10-Oct-1997 fvdl

Bump last argument to VOP_READDIR to off_t (from u_long).


Revision tags: thorpej-signal-base
# 1.51 27-Aug-1997 thorpej

Fix a reversed argument which caused procfs_checkioperm() to always return
"OK". Add a few comments to avoid further confusion.


# 1.50 12-Aug-1997 thorpej

Fix the procfs hole described on current-users, similar to a fix for
FreeBSD by Sean Eric Fagan, but a bit different. This makes the checks
in the same places as sef's FreeBSD patch, but does not hardcode the
"kmem" group into the kernel, and also does a check identical to the
(3) and (4) checks in the NetBSD ptrace(2):

(1) it's not owned by you, or is set-id on exec (unless
you're root), or

(2) it's init, which controls the security level of the
entire system, and the system was not compiled with
permanently insecure mode turned on.


Revision tags: marc-pcmcia-bp
# 1.49 08-May-1997 mycroft

branches: 1.49.4;
Pass the vnode type to vaccess(), and use it when checking VEXEC. Make sure
that the mode bits passed to vaccess() and returned by foo_getattr() contain
only permission bits.


# 1.48 05-May-1997 mycroft

Need stat.h.


# 1.47 05-May-1997 mycroft

Eliminate bogus uses of V{READ,WRITE,EXEC}. Use S_I[RWX]{USR,GRP,OTH} where
appropriate.


# 1.46 28-Apr-1997 mycroft

Minor code cleanup.


Revision tags: is-newarp-before-merge is-newarp-base
# 1.45 25-Oct-1996 cgd

define path name string variables that we should not (and, thankfully, do
not) modify as 'const char *' rather 'char *'.


# 1.44 13-Oct-1996 christos

backout previous kprintf changes


# 1.43 10-Oct-1996 christos

printf -> kprintf, sprintf -> ksprintf


# 1.42 07-Sep-1996 mycroft

Implement poll(2).


# 1.41 01-Sep-1996 mycroft

Add a set of generic file system operations that most file systems use.
Also, fix some time stamp bogosities.


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 1.40 16-Mar-1996 christos

Fix printf format follies.


# 1.39 13-Feb-1996 mycroft

GC *_nullop(). Minor nits.


# 1.38 12-Feb-1996 christos

close PR/2063: procfs_rw prototyped twice with different prototypes


# 1.37 09-Feb-1996 christos

miscfs prototype changes


# 1.36 09-Feb-1996 mycroft

Fix vop_link, vop_symlink, and vop_remove semantics in several ways:
* Change the argument names to vop_link so they actually make sense.
* Implement vop_link and vop_symlink for all file systems, so they do proper
cleanup.
* Require the file system to decide whether or not linking and unlinking of
directories is allowed, and disable it for all current file systems.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.35 09-Oct-1995 mycroft

Use the index number as the cookie, rather than multiplying by UIO_MX.


# 1.34 09-Oct-1995 mycroft

Add support for cookies, mostly from Greg Hudson.


# 1.33 15-Apr-1995 cgd

fix timeval vs. timespec warnings


# 1.32 03-Feb-1995 mycroft

Return EROFS rather than ENOENT in many cases. Also some cosmetic cleanup.


# 1.31 27-Dec-1994 mycroft

Format police.


# 1.30 24-Dec-1994 ws

Implement and use a common access checking routine


# 1.29 14-Dec-1994 mycroft

Remove a_fp.


# 1.28 14-Nov-1994 christos

fixed struct comment


# 1.27 30-Oct-1994 cgd

be more careful with types, also pull in headers where necessary.


# 1.26 20-Oct-1994 cgd

update for new syscall args description mechanism


# 1.25 30-Aug-1994 mycroft

Convert process, file, and namei lists and hash tables to use queue.h.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.24 29-Jun-1994 cgd

New RCS ID's, take two. they're more aesthecially pleasant, and use 'NetBSD'


# 1.23 16-Jun-1994 mycroft

Remove an unneeded test.


# 1.22 15-Jun-1994 mycroft

Minor update from JSP after merging my changes.


# 1.21 08-Jun-1994 mycroft

Update to 4.4-Lite fs code, with local changes.


# 1.20 05-May-1994 cgd

lots of changes: prototype migration, move lots of variables, definitions,
and structure elements around. kill some unnecessary type and macro
definitions. standardize clock handling. More changes than you'd want.


# 1.19 15-Apr-1994 cgd

forgot these...


# 1.18 12-Apr-1994 cgd

be a bit smarter about determining if files shouldn't be seen by the user.
Also, DON'T allow a lookup to succeed on a file that's not visible!


# 1.17 15-Feb-1994 mycroft

Undo last change; executables is `file', not `a.out'.


# 1.16 14-Feb-1994 ws

Rename file -> a.out


# 1.15 14-Feb-1994 ws

Don't try to show a file for a process if there is none


# 1.14 28-Jan-1994 cgd

make a fpregs file.


# 1.13 20-Jan-1994 ws

Make procfs really work for debugging.
Implement not & notepg files in procfs.


# 1.12 09-Jan-1994 ws

Bug fixes and enhancements:
Make NFS serving work (BUT DON'T USE "attach" TO /proc/*/ctl FOR NOW!!!)
Make `curproc' a symbolic link
Add `.' and `..' entries to the directories.
Return better guesses on the size of the files.


# 1.11 05-Jan-1994 cgd

return size of 'reg' from getattr()


# 1.10 05-Jan-1994 cgd

make it compile (cleanly) for us


# 1.9 05-Jan-1994 cgd

add new procfs code, from Jan-Simon Pendry, jsp@sequent.com.
This is pretty-much "virgin", so that diffs can be done later.


# 1.8 18-Dec-1993 mycroft

Canonicalize all #includes.


Revision tags: magnum-base
# 1.7 16-Sep-1993 cgd

kill volatile warning.


# 1.6 07-Sep-1993 ws

branches: 1.6.2;
Changes to VFS readdir semantics
NFS changes for better cookie support
ISOFS changes for better Rockridge support and support for generation numbers


# 1.5 26-Aug-1993 pk

Implement setattr: mode for process entries; mode + uid/gid for the
PROCFS root directory.
Fixed omission in pfs_root() which came to light as a result of the above:
hold on to vnode for root dir.


# 1.4 25-Aug-1993 pk

Fixed improperly initialized nfsnode in pfs_lookup()


# 1.3 24-Aug-1993 pk

copyright update.


# 1.2 24-Aug-1993 pk

Rcs Id added.


# 1.1 24-Aug-1993 pk

branches: 1.1.1;
Initial version of a proc filesystem.


# 1.211 21-Apr-2020 ad

Revert the changes made in February to make cwdinfo use mostly lockless,
which relied on taking extra vnode refs.

Having benchmarked various experimental changes over the past few months it
seems that it's better to avoid vnode refs as much as possible. cwdi_lock
as a RW lock already did that to some extent for getcwd() and will permit
the same for namei() too.


Revision tags: phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base is-mlppp-base phil-wifi-20200406 ad-namecache-base3
# 1.210 24-Feb-2020 ad

v_interlock -> vmobjlock


# 1.209 23-Feb-2020 ad

Merge from ad-namecache:

- Have a stab at clustering the members of vnode_t and vnode_impl_t in a
more cache-conscious way. With that done, go back to adjusting v_usecount
with atomics and keep vi_lock directly in vnode_impl_t (saves KVA).

- Allow VOP_LOCK(LK_NONE) for the benefit of VFS_VGET() and VFS_ROOT().
Make sure LK_UPGRADE always comes with LK_NOWAIT.

- Make cwdinfo use mostly lockless.


# 1.208 01-Feb-2020 riastradh

Load struct filedesc::fd_dt with atomic_load_consume.

Exceptions: when fd_refcnt <= 1, or when holding fd_lock.

While here:

- Restore KASSERT(mutex_owned(&fdp->fd_lock)) in fd_unused.
=> This is used only in fd_close and fd_abort, where it holds.
- Move bounds check assertion in fd_putfile to where it matters.
- Store fd_dt with atomic_store_release.
- Move load of fd_dt under lock in knote_fdclose.
- Omit membar_consumer in fdesc_readdir.
=> atomic_load_consume serves the same purpose now.
=> Was needed only on alpha anyway.


Revision tags: ad-namecache-base2 ad-namecache-base1 ad-namecache-base phil-wifi-20191119
# 1.207 29-Aug-2019 hannken

branches: 1.207.2;
Add missing operation VOP_GETPAGES() returning EFAULT.

Without this operation posix_fadvise(..., POSIX_FADV_WILLNEED)
would leave the v_interlock held.

Observed by maxv@


Revision tags: netbsd-9-base phil-wifi-20190609 isaki-audio2-base
# 1.206 30-Mar-2019 christos

branches: 1.206.4;
add a node for the process resource limits.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020
# 1.205 14-Oct-2018 jdolecek

remove M_CANFAIL flag for malloc(9) - it was completely ignored, so had
actually no effect


Revision tags: pgoyette-compat-0930 pgoyette-compat-0906
# 1.204 03-Sep-2018 riastradh

Rename min/max -> uimin/uimax for better honesty.

These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER! Some subsystems have

#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)


Revision tags: pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415
# 1.203 07-Apr-2018 hannken

branches: 1.203.2;
Lock the target cwdi and take an additional reference to the
vnode we are interested in to prevent it from disappearing
before getcwd_common().

Should fix PR kern/53096 (netbsd-8 crash on heavy disk I/O)


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.202 31-Dec-2017 christos

branches: 1.202.2;
Add an environ node


Revision tags: tls-maxphys-base-20171202
# 1.201 01-Dec-2017 christos

Allow procfs_kqfilter, since we allow poll. "go" does it.


# 1.200 08-Nov-2017 christos

fix locking, remove error(1) comments.


# 1.199 08-Nov-2017 christos

use p->p_path, remove unused code.


# 1.198 28-Aug-2017 kamil

Remove the filesystem tracing feature

This is a legacy interface from 4.4BSD, and it was
introduced to overcome shortcomings of ptrace(2) at that time, which are
no longer relevant (performance). Today /proc/#/ctl offers a narrow
subset of ptrace(2) commands and is not applicable for modern
applications use beyond simplistic tracing scenarios.

This removal will simplify kernel internals. Users will still be able to
use all the other /proc files.

This change won't affect other procfs files neither Linux compat
features within mount_procfs(8). /proc/#/ctl isn't available on Linux.

Remove:
- /proc/#/ctl from mount_procfs(8)
- P_FSTRACE note from the documentation of ps(1)
- /proc/#/ctl and filesystem tracing documentation from mount_procfs(8)
- KAUTH_REQ_PROCESS_PROCFS_CTL documentation from kauth(9)
- source code file miscfs/procfs/procfs_ctl.c
- PFSctl and procfs_doctl() from sys/miscfs/procfs/procfs.h
- KAUTH_REQ_PROCESS_PROCFS_CTL from sys/sys/kauth.h
- PSL_FSTRACE (0x00010000) from sys/sys/proc.h
- P_FSTRACE (0x00010000) from sys/sys/sysctl.h

Reduce code complexity after removal of this functionality.

Update TODO.ptrace accordingly: remove two entries about /proc tracing.

Do not keep legacy notes as comments in the headers about removed
PSL_FSTRACE / P_FSTRACE, as this interface had little number of users
(close or equal to zero).

Proposed on tech-kern@.

All filesystem tracing utility users are encouraged to switch to ptrace(2).

Sponsored by <The NetBSD Foundation>


Revision tags: matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base
# 1.197 26-May-2017 riastradh

branches: 1.197.2;
Make VOP_RECLAIM do the last unlock of the vnode.

VOP_RECLAIM naturally has exclusive access to the vnode, so having it
locked on entry is not strictly necessary -- but it means if there
are any final operations that must be done on the vnode, such as
ffs_update, requiring exclusive access to it, we can now kassert that
the vnode is locked in those operations.

We can't just have the caller release the last lock because some file
systems don't use genfs_lock, and require the vnode to remain valid
for VOP_UNLOCK to work, notably unionfs.


Revision tags: prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.196 11-Apr-2017 riastradh

Make VOP_INACTIVE preserve vnode lock on return.

Discussed on tech-kern:
https://mail-index.netbsd.org/tech-kern/2017/04/01/msg021751.html

Ride 7.99.68, a bumpy bus of incremental vfs improvements!


Revision tags: jdolecek-ncq-base
# 1.195 30-Mar-2017 christos

add an auxv node.


Revision tags: pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004 localcount-20160914
# 1.194 20-Aug-2016 hannken

branches: 1.194.2;
Remove now obsolete operation vcache_remove().

Welcome to 7.99.36


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 nick-nhusb-base-20150921 nick-nhusb-base-20150606
# 1.193 20-Apr-2015 riastradh

branches: 1.193.2;
Make VOP_LINK return directory still locked and referenced.

Ride 7.99.10 bump.


Revision tags: nick-nhusb-base-20150406 nick-nhusb-base
# 1.192 05-Sep-2014 matt

branches: 1.192.2;
Try not to use f_data, use f_{vnode,socket,pipe,mqueue,kqueue,ksem} to get
a correctly typed pointer.


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.191 27-Jul-2014 hannken

branches: 1.191.2; 1.191.4; 1.191.8;
Change procfs from hashlist to vcache.
- Key is (type, pid, fd)
- Remove argument "p" from procfs_allocvp(). It is only used
when "type == PFSfd". Lookup the proc with proc_find() when
procfs_loadvnode() needs it.
- Use a vfs_vnode_iterator for procfs_revoke_vnodes().


# 1.190 25-Jul-2014 dholland

Add VOP_FALLOCATE and VOP_FDISCARD to every vnode ops table I can
find.

The filesystem ones all call genfs_eopnotsupp - right now I am only
implementing the plumbing and we can implement fallocate and/or
fdiscard for files later.

The device ones call spec_fallocate (which is also genfs_eopnotsupp)
and spec_fdiscard, which dispatches to the device-level op.

The fifo ones all call vn_fifo_bypass, which also ends up being
EOPNOTSUPP.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base
# 1.189 07-Feb-2014 hannken

branches: 1.189.2;
Change vnode operation lookup to return the resulting vnode *vpp unlocked.
Change cache_lookup() to return an unlocked vnode.

Discussed on tech-kern@

Welcome to 6.99.31


# 1.188 23-Jan-2014 hannken

Change vnode operations create, mknod, mkdir and symlink to return
the resulting vnode *vpp unlocked.

Discussed on tech-kern@

Welcome to 6.99.30


# 1.187 17-Jan-2014 hannken

Change vnode operations create, mknod, mkdir and symlink to keep the
directory node dvp locked on return.

Discussed on tech-kern@

Welcome to 6.99.29


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base
# 1.186 18-Mar-2013 plunky

branches: 1.186.6;
C99 section 6.7.2.3 (Tags) Note 3 states that:

A type specifier of the form

enum identifier

without an enumerator list shall only appear after the type it
specifies is complete.

which means that we cannot pass an "enum vtype" argument to
kauth_access_action() without fully specifying the type first.
Unfortunately there is a complicated include file loop which
makes that difficult, so convert this minimal function into a
macro (and capitalize it).

(ok elad@)


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 1.185 25-Nov-2012 christos

do something reasonable with kernel semaphores.


Revision tags: yamt-pagecache-base6 jmcneill-usbmp-base10
# 1.184 28-May-2012 christos

branches: 1.184.2;
add a task process subdirectory for emul linux


Revision tags: yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 1.183 13-Mar-2012 elad

Replace the remaining KAUTH_GENERIC_ISSUSER authorization calls with
something meaningful. All relevant documentation has been updated or
written.

Most of these changes were brought up in the following messages:

http://mail-index.netbsd.org/tech-kern/2012/01/18/msg012490.html
http://mail-index.netbsd.org/tech-kern/2012/01/19/msg012502.html
http://mail-index.netbsd.org/tech-kern/2012/02/17/msg012728.html

Thanks to christos, manu, njoly, and jmmv for input.

Huge thanks to pgoyette for spinning these changes through some build
cycles and ATF.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.182 04-Sep-2011 jmcneill

branches: 1.182.2; 1.182.6;
PR# kern/45021: Please support /emul/linux/proc/version

Add /proc/version for procfs with -o linux. The version reported depends
on the emulation type of the calling process:

$ cat /proc/version
NetBSD version 5.99.55 (netbsd@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) NetBSD 5.99.55 (GENERIC) #39: Sun Sep 4 09:10:05 EDT 2011

$ /emul/linux/bin/cat /proc/version
Linux version 2.6.18 (linux@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) #0 Wed Mar 3 03:03:03 PST 2010

$ /emul/linux32/bin/cat /proc/version
Linux version 2.6.18 (linux32@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) #0 Wed Mar 3 03:03:03 PST 2010


# 1.181 23-Jun-2011 christos

From Aleksey Cheusov: Don't make it easy for compromised systems to bypass
ASLR protections by providing the mapping addresses of programs to everyone.


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base matt-mips64-premerge-20101231 uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10 rmind-uvmplock-base
# 1.180 01-Jul-2010 rmind

Remove pfind() and pgfind(), fix locking in various broken uses of these.
Rename real routines to proc_find() and pgrp_find(), remove PFIND_* flags
and have consistent behaviour. Provide proc_find_raw() for special cases.
Fix memory leak in sysctl_proc_corename().

COMPAT_LINUX: rework ptrace() locking, minimise differences between
different versions per-arch.

Note: while this change adds some formal cosmetics for COMPAT_DARWIN and
COMPAT_IRIX - locking there is utterly broken (for ages).

Fixes PR/43176.


# 1.179 24-Jun-2010 hannken

Clean up vnode lock operations pass 2:

VOP_UNLOCK(vp, flags) -> VOP_UNLOCK(vp): Remove the unneeded flags argument.

Welcome to 5.99.32.

Discussed on tech-kern.


# 1.178 08-Jun-2010 hannken

Procfs_lookup() does not lookup directory descriptors in the fd/
subdirectory. There is no need for recursive vnode locking here.

Ok: Christos Zoulas <christos@netbsd.org>


Revision tags: uebayasi-xip-base1 yamt-nfs-mp-base9 uebayasi-xip-base
# 1.177 08-Jan-2010 pooka

branches: 1.177.2; 1.177.4;
The VATTR_NULL/VREF/VHOLD/HOLDRELE() macros lost their will to live
years ago when the kernel was modified to not alter ABI based on
DIAGNOSTIC, and now just call the respective function interfaces
(in lowercase). Plenty of mix'n match upper/lowercase has creeped
into the tree since then. Nuke the macros and convert all callsites
to lowercase.

no functional change


Revision tags: matt-premerge-20091211 yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 jym-xensuspend-nbase
# 1.176 03-Jul-2009 elad

Where possible, extract the file-system's access() routine to two internal
functions: the first checking if the operation is possible (regardless of
permissions), the second checking file-system permissions, ACLs, etc.

Mailing list reference:

http://mail-index.netbsd.org/tech-kern/2009/06/21/msg005311.html


# 1.175 23-Jun-2009 elad

Move the implementation of vaccess() to genfs_can_access(), in line with
the other routines of the same spirit.

Adjust file-system code to use it.

Keep vaccess() for KPI compatibility and to keep element of least
surprise. A "diagnostic" message warning that vaccess() is deprecated will
be printed when it's used (obviously, only in DIAGNOSTIC kernels).

No objections on tech-kern@:

http://mail-index.netbsd.org/tech-kern/2009/06/21/msg005310.html


Revision tags: yamt-nfs-mp-base5
# 1.174 24-May-2009 ad

More changes to improve kern_descrip.c.

- Avoid atomics in more places.
- Remove the per-descriptor mutex, and just use filedesc_t::fd_lock.
It was only being used to synchronize close, and in any case we needed
to take fd_lock to free the descriptor slot.
- Optimize certain paths for the <NDFDFILE case.
- Sprinkle more comments and assertions.
- Cache more stuff in filedesc_t.
- Fix numerous minor bugs spotted along the way.
- Restructure how the open files array is maintained, for clarity and so
that we can eliminate the membar_consumer() call in fd_getfile(). This is
mostly syntactic sugar; the main functional change is that fd_nfiles now
lives alongside the open file array.

Some measurements with libmicro:

- simple file syscalls are like close() are between 1 to 10% faster.
- some nice improvements, e.g. poll(1000) which is ~50% faster.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 nick-hppapmap-base2 jym-xensuspend-base nick-hppapmap-base mjf-devfs2-base
# 1.173 17-Dec-2008 cegger

branches: 1.173.2;
kill MALLOC and FREE macros.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 haad-dm-base2 haad-nbase2 ad-audiomp2-base netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 haad-dm-base
# 1.172 05-Sep-2008 skrll

branches: 1.172.2;
PR/39324 kernel diagnostic assertion "l->l_stat != LSZOMB" failed.

Ignore procs with zero or all LSZOMB LWPs. Get a non-LSZOMB LWP to perform
operations against as part of the deal.

procfs really needs to be updated to support multi-threading fully.
Hi Antti!


# 1.171 05-Sep-2008 skrll

ANSIfy


Revision tags: simonb-wapbl-nbase simonb-wapbl-base
# 1.170 02-Jul-2008 rmind

branches: 1.170.2;
Remove proc_representative_lwp(), use a simple LIST_FIRST() instead.
OK by <ad>.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base
# 1.169 28-Apr-2008 martin

branches: 1.169.2; 1.169.4;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-nfs-mp-base
# 1.168 24-Apr-2008 ad

branches: 1.168.2;
Merge proc::p_mutex and proc::p_smutex into a single adaptive mutex, since
we no longer need to guard against access from hardware interrupt handlers.

Additionally, if cloning a process with CLONE_SIGHAND, arrange to have the
child process share the parent's lock so that signal state may be kept in
sync. Partially addresses PR kern/37437.


# 1.167 24-Apr-2008 ad

Network protocol interrupts can now block on locks, so merge the globals
proclist_mutex and proclist_lock into a single adaptive mutex (proc_lock).
Implications:

- Inspecting process state requires thread context, so signals can no longer
be sent from a hardware interrupt handler. Signal activity must be
deferred to a soft interrupt or kthread.

- As the proc state locking is simplified, it's now safe to take exit()
and wait() out from under kernel_lock.

- The system spends less time at IPL_SCHED, and there is less lock activity.


Revision tags: yamt-pf42-baseX yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14
# 1.166 21-Mar-2008 ad

branches: 1.166.2;
Catch up with descriptor handling changes. See kern_descrip.c revision
1.173 for details.


Revision tags: keiichi-mipv6-nbase nick-net80211-sync-base keiichi-mipv6-base bouyer-xeni386-nbase matt-armv6-nbase mjf-devfs-base hpcarm-cleanup-base
# 1.165 23-Jan-2008 elad

branches: 1.165.6;
Tons of process scope changes.

- Add a KAUTH_PROCESS_SCHEDULER action, to handle scheduler related
requests, and add specific requests for set/get scheduler policy and
set/get scheduler parameters.

- Add a KAUTH_PROCESS_KEVENT_FILTER action, to handle kevent(2) related
requests.

- Add a KAUTH_DEVICE_TTY_STI action to handle requests to TIOCSTI.

- Add requests for the KAUTH_PROCESS_CANSEE action, indicating what
process information is being looked at (entry itself, args, env,
open files).

- Add requests for the KAUTH_PROCESS_RLIMIT action indicating set/get.

- Add requests for the KAUTH_PROCESS_CORENAME action indicating set/get.

- Make bsd44 secmodel code handle the newly added rqeuests appropriately.

All of the above make it possible to issue finer-grained kauth(9) calls in
many places, removing some KAUTH_GENERIC_ISSUSER requests.

- Remove the "CAN" from KAUTH_PROCESS_CAN{KTRACE,PROCFS,PTRACE,SIGNAL}.

Discussed with christos@ and yamt@.


Revision tags: bouyer-xeni386-base matt-armv6-base
# 1.164 02-Jan-2008 ad

Merge vmlocking2 to head.


Revision tags: vmlocking2-base3 yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 vmlocking-nbase jmcneill-pm-base reinoud-bufcleanup-base
# 1.163 26-Nov-2007 pooka

branches: 1.163.2; 1.163.6;
Remove the "struct lwp *" argument from all VFS and VOP interfaces.
The general trend is to remove it from all kernel interfaces and
this is a start. In case the calling lwp is desired, curlwp should
be used.

quick consensus on tech-kern


Revision tags: bouyer-xenamd64-base2 bouyer-xenamd64-base
# 1.162 09-Nov-2007 christos

make the last argument of procfs_dir size_t


# 1.161 07-Nov-2007 ad

Merge from vmlocking:

- pool_cache changes.
- Debugger/procfs locking fixes.
- Other minor changes.


Revision tags: jmcneill-base yamt-x86pmap-base4 yamt-x86pmap-base3 vmlocking-base
# 1.160 10-Oct-2007 ad

branches: 1.160.2; 1.160.4;
Merge from vmlocking:

- Split vnode::v_flag into three fields, depending on field locking.
- simple_lock -> kmutex in a few places.
- Fix some simple locking problems.


# 1.159 08-Oct-2007 ad

Merge file descriptor locking, cwdi locking and cross-call changes
from the vmlocking branch.


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base2 yamt-x86pmap-base matt-mips64-base
# 1.158 22-Jul-2007 pooka

branches: 1.158.4; 1.158.6; 1.158.8; 1.158.10;
Don't allow getcwd() on procfs vnodes and provide "/" as the path
instead of the result from getcwd(). The works around locking
panics caused by namei calling VOP_READLINK while holding on to a
directory lock and getcwd() trying to acquire that lock. The real
fix would be to get rid of getcwd() calls within VOPs (not locking
safe), but that's not a viable option in the netbsd-4 timeframe.

Suggestion for workaround from David Holland.


Revision tags: nick-csl-alignment-base mjf-ufs-trans-base
# 1.157 24-May-2007 agc

branches: 1.157.2;
Extend the Linux emulation of /proc to include

/proc/stat
/proc/loadavg and
/proc/<pid>/statm.

These are only present when -o linux is specified as a mount option
to procfs.

Factor out some common code so that it can be used by a number of
functions.

XXX The values returned in the statm emulation need to be verified.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 1.156 04-Apr-2007 rmind

Unfortunately, missed procfs_proc_unlock() in previous.
Pointed out by pooka@


# 1.155 04-Apr-2007 rmind

procfs_readlink: Handle a possible fail of fd_getfile(), also, we
do not need to check for error again.
CID: 4436


# 1.154 09-Mar-2007 ad

branches: 1.154.2; 1.154.4;
- Make the proclist_lock a mutex. The write:read ratio is unfavourable,
and mutexes are cheaper use than RW locks.
- LOCK_ASSERT -> KASSERT in some places.
- Hold proclist_lock/kernel_lock longer in a couple of places.


# 1.153 04-Mar-2007 christos

Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.


# 1.152 03-Mar-2007 salo

Don't prepend rootvnode to the path in non-NULL case for exe links.
It breaks procfs in chroot.

from <christos>, tested by me.


Revision tags: ad-audiomp-base
# 1.151 19-Feb-2007 pooka

When checking for file validity under pid/, do proper proc->lwp
lookup (fsvo proper) instead of fiddling directly with the lwp
list.


# 1.150 18-Feb-2007 pooka

Don't check for validity of p in lookup for root nodes, since it
will always be NULL. Rather, just call pt_valid with NULL directly
and let it decide if we're a linux mount or not.


# 1.149 17-Feb-2007 pavel

Change the process/lwp flags seen by userland via sysctl back to the
P_*/L_* naming convention, and rename the in-kernel flags to avoid
conflict. (P_ -> PK_, L_ -> LW_ ). Add back the (now unused) LSDEAD
constant.

Restores source compatibility with pre-newlock2 tools like ps or top.

Reviewed by Andrew Doran.


# 1.148 16-Feb-2007 pooka

branches: 1.148.2;
In lookup, when checking for procfs process node validity, target the
process we're trying to get information about through procfs, not
the caller of lookup.

fixes 'ls -l /proc/*/file' panic, which would occur when trying to
lookup "file" for a kernel thread, which doesn't have p->p_textvp.


# 1.147 15-Feb-2007 ad

Need to acquire procp->p_mutex for procfs_dir().


# 1.146 11-Feb-2007 ad

Eliminate a couple of reference count and mutex leaks.


Revision tags: post-newlock2-merge
# 1.145 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 1.144 25-Dec-2006 elad

PR/35226: Johann Franz: Problems with permissions in
/usr/pkg/emul/linux/proc .

Okay mlelstv@


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3
# 1.143 09-Dec-2006 chs

a smorgasbord of improvements to vnode locking and path lookup:
- LOCKPARENT is no longer relevant for lookup(), relookup() or VOP_LOOKUP().
these now always return the parent vnode locked. namei() works as before.
lookup() and various other paths no longer acquire vnode locks in the
wrong order via vrele(). fixes PR 32535.
as a nice side effect, path lookup is also up to 25% faster.
- the above allows us to get rid of PDIRUNLOCK.
- also get rid of WANTPARENT (just use LOCKPARENT and unlock it).
- remove an assumption in layer_node_find() that all file systems implement
a recursive VOP_LOCK() (unionfs doesn't).
- require that all file systems supply vfs_vptofh and vfs_fhtovp routines.
fill in eopnotsupp() for file systems that don't support being exported
and remove the checks for NULL. (layerfs calls these without checking.)
- in union_lookup1(), don't change refcounts in the ISDOTDOT case, just
adjust which vnode is locked. fixes PR 33374.
- apply fixes for ufs_rename() from ufs_vnops.c rev. 1.61 to ext2fs_rename().


# 1.142 04-Dec-2006 christos

From Nicolas Joly: restore previous behavior in procfs_validfile_linux, since
readdir passes a NULL lwp.


# 1.141 03-Dec-2006 elad

Move kauth(9) call to where it belongs. Noticed by Nicolas Joly, thanks!


Revision tags: netbsd-4-base
# 1.140 28-Nov-2006 elad

branches: 1.140.2;
Move ktrace, ptrace, systrace, and procfs to use kauth(9).

First, remove process_checkioperm() calls from MD code. Similar checks
using kauth(9) routines (on the process scope, using appropriate action)
are done in the callers.

Add secmodel back-end to handle each subsystem.


# 1.139 25-Nov-2006 skrll

Expose the 'exe' symlink to the process realpath in NetBSD as well. An
example user is gdb.

OK'd by christos.


# 1.138 16-Nov-2006 christos

__unused removal on arguments; approved by core.


# 1.137 29-Oct-2006 christos

add an "emul" file node.


# 1.136 25-Oct-2006 christos

1. fix procfs_validfile{,_linux} to test for NULL pointers properly.
2. make "exe" entry be a symlink to the executable, instead of pointing
directly to the vnode of the executable.
3. factor out commonly used code.


Revision tags: yamt-splraiseipl-base2
# 1.135 12-Oct-2006 christos

- sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386


# 1.134 20-Sep-2006 manu

Emulate Linux's /proc/devices


Revision tags: abandoned-netbsd-4-base yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base rpaulo-netinet-merge-pcb-base
# 1.133 13-Jun-2006 yamt

branches: 1.133.6; 1.133.8;
use KAUTH_PROCESS_CANSEE rather than CURTAIN where appropriate.


# 1.132 13-Jun-2006 yamt

remove unnecessary arguments from kauth_authorize_process.
ie. make it similar to the one found in apple TN.


# 1.131 07-Jun-2006 kardel

merge FreeBSD timecounters from branch simonb-timecounters
- struct timeval time is gone
time.tv_sec -> time_second
- struct timeval mono_time is gone
mono_time.tv_sec -> time_uptime
- access to time via
{get,}{micro,nano,bin}time()
get* versions are fast but less precise
- support NTP nanokernel implementation (NTP API 4)
- further reading:
Timecounter Paper: http://phk.freebsd.dk/pubs/timecounter.pdf
NTP Nanokernel: http://www.eecis.udel.edu/~mills/ntp/html/kern.html


Revision tags: yamt-pdpolicy-base5 simonb-timecounters-base
# 1.130 14-May-2006 elad

branches: 1.130.2;
integrate kauth.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 elad-kernelauth-base yamt-pdpolicy-base yamt-uio_vmspace-base5
# 1.129 02-Feb-2006 christos

branches: 1.129.2; 1.129.4; 1.129.6; 1.129.8;
PR/32692: Matthew Mondor: linux compatibility in /proc/self should point
directly to the directory containing the pid instead of pointing to
/proc/curproc, because some programs rely on calling readlink on /proc/self
to get the pid.


# 1.128 11-Dec-2005 christos

branches: 1.128.2; 1.128.4;
merge ktrace-lwp.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base ktrace-lwp-base
# 1.127 02-Nov-2005 yamt

merge yamt-vop branch. remove following VOPs.

VOP_BLKATOFF
VOP_VALLOC
VOP_BALLOC
VOP_REALLOCBLKS
VOP_VFREE
VOP_TRUNCATE
VOP_UPDATE


Revision tags: yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 1.126 01-Oct-2005 atatat

branches: 1.126.2;
Add "cwd" and "root" symlinks to each process's directory. The cwd
link points to the process's current working directory, and the root
link points to the process's root directory. What else would you
expect?

For directories that are out of reach (caller is in a chroot, target
process is in a different chroot, etc), the links point to "/"
instead.


# 1.125 11-Sep-2005 elad

Implement curtain for procfs.


# 1.124 30-Aug-2005 xtraeme

Remove __P()


# 1.123 29-May-2005 christos

branches: 1.123.2;
- sprinkle const
- avoid shadowed variables.


Revision tags: kent-audio2-base
# 1.122 02-Apr-2005 christos

PR/29782: Martin Husemann: procfs can not unmount when some process has its
current directory in curproc. Fix from Pedro Martelletto:
We cannot call vgone() from procfs_inactive() if we are coming from
vclean(). that's what's probably causing the deadlock.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 yamt-km-base4 yamt-km-base3 netbsd-3-base
# 1.121 26-Feb-2005 perry

nuke trailing whitespace


Revision tags: yamt-km-base2 yamt-km-base kent-audio1-beforemerge kent-audio1-base
# 1.120 04-Oct-2004 yamt

branches: 1.120.4; 1.120.6;
procfs_readdir:
- return correct cookie when buffer size is small.
- simplify logic.


# 1.119 04-Oct-2004 yamt

procfs_readdir: remove a redundant assignment.


# 1.118 02-Oct-2004 yamt

procfs_getattr: correct size of /proc/self.


# 1.117 01-Oct-2004 yamt

procfs_readdir:
- fix a locking problem, using proclist_foreach_call. PR/27098.
- correct snprintf size argument.


# 1.116 01-Oct-2004 yamt

procfs_readdir: fix an offset handling bug after addition of /proc/self.


# 1.115 01-Oct-2004 yamt

procfs_readdir: use a list macro.


# 1.114 20-Sep-2004 jdolecek

add 'mounts' file for -o linux, which lists all currently mounted
filesystems; Linux glibc statvfs() uses this to get some of mount flags,
and this file is also useful as /emul/linux/etc/mtab (via symlink)


# 1.113 29-Apr-2004 jrf

Removed remaining caddr_t casts we do not need in miscfs. Recompiled
kernel and ran for a day or so. There are still some caddr_t types in
the arguments of some calls, I will do those separately (later) as
they touch a lot more of the system.
Approved by christos@NetBSD.org.


# 1.112 22-Apr-2004 itojun

sprintf -> snprintf


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.111 15-Feb-2004 jdolecek

unlock the descriptor table simple lock after fd_getfile() call in
procfs_readdir()
fixes procfs locking problems reported on current-users@, problem place
found by enami tsugutomo


# 1.110 30-Oct-2003 simonb

Remove some assigned-to but otherwise unused variables.


# 1.109 27-Sep-2003 darcy

Changes as discussed with itojun on tech-kern. I have modified the enums
to have KFS or PFS differentiators. Further I have wrapped the enum in
procfs in "#ifdef _KERNEL" as it is done in kernfs.

To see the discussion go to http://mail-index.NetBSD.org/tech-kern/2003/09/
and look for "Mismatched enums in include files" in the list.


# 1.108 07-Sep-2003 itojun

remove meaningless line (variable overwritten 2 lines below)


# 1.107 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.


# 1.106 29-Jun-2003 fvdl

branches: 1.106.2;
Back out the lwp/ktrace changes. They contained a lot of colateral damage,
and need to be examined and discussed more.


# 1.105 29-Jun-2003 thorpej

Undo part of the ktrace/lwp changes. In particular:
* Remove the "lwp *" argument that was added to vget(). Turns out
that nothing actually used it!
* Remove the "lwp *" arguments that were added to VFS_ROOT(), VFS_VGET(),
and VFS_FHTOVP(); all they did was pass it to vget() (which, as noted
above, didn't use it).
* Remove all of the "lwp *" arguments to internal functions that were added
just to appease the above.


# 1.104 28-Jun-2003 darrenr

Pass lwp pointers throughtout the kernel, as required, so that the lwpid can
be inserted into ktrace records. The general change has been to replace
"struct proc *" with "struct lwp *" in various function prototypes, pass
the lwp through and use l_proc to get the process pointer when needed.

Bump the kernel rev up to 1.6V


# 1.103 28-May-2003 christos

Add /proc/<pid>/stat for linux compat. j2sdk1.4.2 depends on it.


# 1.102 18-Apr-2003 christos

Make symlinks for directories that point to the actual directory.
Make symlinks to [kqueue] and [misc] for kqueue and misc fds.


# 1.101 17-Apr-2003 jdolecek

do not show nodes corresponding to directory descriptors for process
in fd/ subdirectory, nor allow lookup/open for the nodes
this fixes PR kern/21187 for good, and also avoids interesting directory
locking issues


# 1.100 17-Apr-2003 jdolecek

procfs_readdir(): in Pfd case, only show descriptors of types we want
how to represent (vnodes, fifo, pipes); also use fd_getfile() et al

this avoids annoying EOPNOTSUPP error messages from ls -F and such


# 1.99 17-Apr-2003 jdolecek

procfs_lookup(): use fd_getfile() et al in Pfd case


# 1.98 17-Apr-2003 jdolecek

use fd_getfile() in procfs_getfp(), and FILE_USE()/FILE_UNUSE() the
returned file descriptor pointer appropriately


# 1.97 17-Apr-2003 jdolecek

make some local arrays/variables static + const


# 1.96 10-Apr-2003 jdolecek

use former genfs_eopnotsupp_rele() as genfs_eopnotsupp(), so that vnodes
are vput()/vrele()d as necessary - some filesystems did use the wrong
one for some ops, and it's just safer to not take the chance

based on suggestion by Bill Studenmund


# 1.95 05-Apr-2003 dsl

Remove pointless check against PID_MAX. Let pfind() do the validation.
(The new pid allocation code may decide to allocate pids above PID_MAX.)


# 1.94 25-Feb-2003 jrf

This addresses PR kerm/19989. Thanks to hamajima@nagoya.ydc.co.jp for submitting this patch which enables /proc/uptime for linux emul. Patch reviewed by atatat@netbsd.org and tron@netbsd.org, approved by tron@netbsd.org.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 1.93 04-Jan-2003 martin

Cast off_t expression to long long to match format even on 64 bit
plattforms.

Shouldn't we introduce a PRIoff_t macro to create such format strings?


# 1.92 03-Jan-2003 christos

add LK_CANRECURSE in the locking of /dev/<pid>/fd/<n> and remove the curproc
kludge. Thanks to fvdl.


# 1.91 03-Jan-2003 christos

Implement /proc/<pid>/fd/<n>. This is work in progress. Questionable things:
- Is it ok to convert DTYPE_PIPE to VFIFO and DTYPE_SOCKET to VSOCK?
- XXX: Avoid locking issue in ls -Rl /proc by avoiding curproc
- Does I/O to pipes work?
- XXX: Are there security implications?


Revision tags: fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge gehenna-devsw-base kqueue-base
# 1.90 03-Aug-2002 simonb

Just use the "time" variable in the *_getattr functions instead of a call
to (the potentially expensive) microtime().


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.89 09-May-2002 thorpej

branches: 1.89.2;
Move code shared by procfs and the kernel proper out of procfs and
into the kernel proper (renaming functions from procfs_* to process_*).


Revision tags: eeh-devprop-base newlock-base ifpoll-base
# 1.88 12-Jan-2002 christos

Don't hide the real return code with EPERM.


# 1.87 06-Dec-2001 chs

add a VOP_PUTPAGES method for all the filesystems that don't have pages,
just unlock the interlock.


# 1.86 05-Dec-2001 thorpej

* Allow machine-dependent code to specify hooks for ptrace(2)
(__HAVE_PTRACE_MACHDEP) and procfs (__HAVE_PROCFS_MACHDEP).
These changes will allow platforms like x86 (XMM) and PowerPC
(AltiVec) to export extended register sets in a sane manner.

* Use __HAVE_PTRACE_MACHDEP to export x86 XMM registers (standard
FP + SSE/SSE2) using PT_{GET,SET}XMMREGS (in the machdep
ptrace request space).
* Use __HAVE_PROCFS_MACHDEP to export x86 XMM registers via
/proc/N/xmmregs in procfs.


Revision tags: thorpej-mips-cache-base
# 1.85 10-Nov-2001 lukem

add RCSIDs


# 1.84 06-Nov-2001 simonb

Remove some variables that are set but never used.


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base
# 1.83 31-Aug-2001 chs

branches: 1.83.2; 1.83.4;
map files are zero-length.


# 1.82 03-Jun-2001 chs

branches: 1.82.2;
procfs_bmap() should never be called, make it a "bad op".
let procfs_mmap() use the default error method.


Revision tags: thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 1.81 14-Apr-2001 kleink

In procfs_readdir(), give /proc/# directories DT_DIR (rather than DT_REG).


# 1.80 30-Mar-2001 fvdl

Bump va_blocksize for the map files some more, so that programs with
quite a few mappings have a chance of being handled correctly if
st_blksize is looked at.


# 1.79 29-Mar-2001 fvdl

For -o linux mounts, add some code to emulate /proc/#/maps.
Needs NAMECACHE_ENTER_REVERSE to include filenames.


# 1.78 21-Feb-2001 jdolecek

branches: 1.78.2;
make some more constant arrays 'const'


# 1.77 22-Jan-2001 jdolecek

make filesystem vnodeop, specop, fifoop and vnodeopv_* arrays const


# 1.76 17-Jan-2001 fvdl

Add a few linux-style files, only enabled when -o linux is specified
for the mount. Currently these are /proc/cpuinfo and /proc/meminfo.
The former only does something on i386 right now.


# 1.75 24-Nov-2000 chs

remove dead code and other misc cleanup.


# 1.74 09-Aug-2000 tv

Only show the "exe" entry to Linux processes, suggested by christos.
Since there are actually three struct emul's for linux, use the e_name
field to determine eligibility with strcmp().


# 1.73 09-Aug-2000 tv

Some versions of Linux libc look for /proc/.../exe instead of /proc/../file.
Add an entry for "exe" that is the same as "file", provided only if
COMPAT_LINUX is set.


# 1.72 03-Aug-2000 thorpej

MALLOC()/FREE() are not to be used for variable sized allocations.


# 1.71 28-Jun-2000 mrg

<vm/vm.h> -> <uvm/uvm_extern.h>


Revision tags: netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 1.70 30-Mar-2000 simonb

branches: 1.70.4;
Delete duplicate declaration of atopid().


Revision tags: chs-ubc2-newbase wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base fvdl-softdep-base
# 1.69 02-Sep-1999 thorpej

branches: 1.69.2; 1.69.8;
Make /proc/self a symlink to /proc/curproc. I've observed Linux programs
that expect /proc/self/cmdline to exist.


# 1.68 25-Aug-1999 sommerfeld

Change variable used for directory offset from "int" to "off_t".
Overkill, but avoids a host of truncation problems.


# 1.67 24-Aug-1999 sommerfeld

Fix PR8270:

Problem turned out to be due to improper handling of reads beyond EOF:
they should just return without error with the uio unchanged, and the
caller will recognize this as a zero-byte return (EOF).

The previous fix to protect directory reads against bogus uio_offset
values returned EINVAL, which broke mount -o union, which only
union'ed in the lower directory if the upper directory cleanly
returned EOF.

While we're here, protect kernfs as well.


# 1.66 14-Aug-1999 christos

protect against large uio_offset


# 1.65 03-Aug-1999 wrstuden

Add support for fcntl(2) to generate VOP_FCNTL calls. Any fcntl
call with F_FSCTL set and F_SETFL calls generate calls to a new
fileop fo_fcntl. Add genfs_fcntl() and soo_fcntl() which return 0
for F_SETFL and EOPNOTSUPP otherwise. Have all leaf filesystems
use genfs_fcntl().

Reviewed by: thorpej
Tested by: wrstuden


Revision tags: chs-ubc2-base
# 1.64 25-Jul-1999 thorpej

Add calls to lock the proclist as appropriate.


# 1.63 14-Jul-1999 thorpej

Fix a paste-o in procfs_lookup() introduced with the vnode locking changes.
Fixes PR #7961, Mario Kemper <magick@bundy.lip.owl.de>.


# 1.62 08-Jul-1999 wrstuden

Bump osrelease to 1.4E. Add layerfs files, remove null_subr.c.

Update coda to new struct lock in struct vnode.

make fdescfs, kernfs, portalfs, and procfs actually lock their vnodes.
It's not that hard.

Make unionfs set v_vnlock = NULL so any overlayed fs will call its
VOP_LOCK.


Revision tags: kame_141_19991130 netbsd-1-4-PATCH001 kame_14_19990705 kame_14_19990628 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.61 12-Mar-1999 christos

branches: 1.61.2; 1.61.4;
PR/7143: Jaromir Docelek: Add procfs/cmdline from Linux emulation


# 1.60 25-Jan-1999 msaitoh

Add /proc/#/map. From FreeBSD.


Revision tags: kenh-if-detach-base chs-ubc-base
# 1.59 08-Sep-1998 thorpej

- Use proclists[], rather than checking allproc and zombproc explicitly.
- Add some comments about locking.


# 1.58 13-Aug-1998 kleink

Per POSIX, fail with EINVAL if advisory locking is attempted on a file type
that doesn't support it, rather than using a homegrown EBADF or EOPNOTSUPP.


# 1.57 10-Aug-1998 matthias

create miscfs/genfs/genfs_vnops.c:genfs_enoioctl and make all the other
filesystems use it instead of a private version.


# 1.56 09-Aug-1998 perry

bzero->memset, bcopy->memcpy, bcmp->memcmp


# 1.55 03-Aug-1998 kleink

Recognize _PC_SYNC_IO.


Revision tags: eeh-paddr_t-base
# 1.54 21-Apr-1998 fvdl

procfs_readdir: in case of error, check if cookies actually have
been allocated before freeing them. From Wolfgang Solfrank.


# 1.53 01-Mar-1998 fvdl

Merge with Lite2 + local changes


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base marc-pcmcia-base
# 1.52 10-Oct-1997 fvdl

Bump last argument to VOP_READDIR to off_t (from u_long).


Revision tags: thorpej-signal-base
# 1.51 27-Aug-1997 thorpej

Fix a reversed argument which caused procfs_checkioperm() to always return
"OK". Add a few comments to avoid further confusion.


# 1.50 12-Aug-1997 thorpej

Fix the procfs hole described on current-users, similar to a fix for
FreeBSD by Sean Eric Fagan, but a bit different. This makes the checks
in the same places as sef's FreeBSD patch, but does not hardcode the
"kmem" group into the kernel, and also does a check identical to the
(3) and (4) checks in the NetBSD ptrace(2):

(1) it's not owned by you, or is set-id on exec (unless
you're root), or

(2) it's init, which controls the security level of the
entire system, and the system was not compiled with
permanently insecure mode turned on.


Revision tags: marc-pcmcia-bp
# 1.49 08-May-1997 mycroft

branches: 1.49.4;
Pass the vnode type to vaccess(), and use it when checking VEXEC. Make sure
that the mode bits passed to vaccess() and returned by foo_getattr() contain
only permission bits.


# 1.48 05-May-1997 mycroft

Need stat.h.


# 1.47 05-May-1997 mycroft

Eliminate bogus uses of V{READ,WRITE,EXEC}. Use S_I[RWX]{USR,GRP,OTH} where
appropriate.


# 1.46 28-Apr-1997 mycroft

Minor code cleanup.


Revision tags: is-newarp-before-merge is-newarp-base
# 1.45 25-Oct-1996 cgd

define path name string variables that we should not (and, thankfully, do
not) modify as 'const char *' rather 'char *'.


# 1.44 13-Oct-1996 christos

backout previous kprintf changes


# 1.43 10-Oct-1996 christos

printf -> kprintf, sprintf -> ksprintf


# 1.42 07-Sep-1996 mycroft

Implement poll(2).


# 1.41 01-Sep-1996 mycroft

Add a set of generic file system operations that most file systems use.
Also, fix some time stamp bogosities.


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 1.40 16-Mar-1996 christos

Fix printf format follies.


# 1.39 13-Feb-1996 mycroft

GC *_nullop(). Minor nits.


# 1.38 12-Feb-1996 christos

close PR/2063: procfs_rw prototyped twice with different prototypes


# 1.37 09-Feb-1996 christos

miscfs prototype changes


# 1.36 09-Feb-1996 mycroft

Fix vop_link, vop_symlink, and vop_remove semantics in several ways:
* Change the argument names to vop_link so they actually make sense.
* Implement vop_link and vop_symlink for all file systems, so they do proper
cleanup.
* Require the file system to decide whether or not linking and unlinking of
directories is allowed, and disable it for all current file systems.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.35 09-Oct-1995 mycroft

Use the index number as the cookie, rather than multiplying by UIO_MX.


# 1.34 09-Oct-1995 mycroft

Add support for cookies, mostly from Greg Hudson.


# 1.33 15-Apr-1995 cgd

fix timeval vs. timespec warnings


# 1.32 03-Feb-1995 mycroft

Return EROFS rather than ENOENT in many cases. Also some cosmetic cleanup.


# 1.31 27-Dec-1994 mycroft

Format police.


# 1.30 24-Dec-1994 ws

Implement and use a common access checking routine


# 1.29 14-Dec-1994 mycroft

Remove a_fp.


# 1.28 14-Nov-1994 christos

fixed struct comment


# 1.27 30-Oct-1994 cgd

be more careful with types, also pull in headers where necessary.


# 1.26 20-Oct-1994 cgd

update for new syscall args description mechanism


# 1.25 30-Aug-1994 mycroft

Convert process, file, and namei lists and hash tables to use queue.h.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.24 29-Jun-1994 cgd

New RCS ID's, take two. they're more aesthecially pleasant, and use 'NetBSD'


# 1.23 16-Jun-1994 mycroft

Remove an unneeded test.


# 1.22 15-Jun-1994 mycroft

Minor update from JSP after merging my changes.


# 1.21 08-Jun-1994 mycroft

Update to 4.4-Lite fs code, with local changes.


# 1.20 05-May-1994 cgd

lots of changes: prototype migration, move lots of variables, definitions,
and structure elements around. kill some unnecessary type and macro
definitions. standardize clock handling. More changes than you'd want.


# 1.19 15-Apr-1994 cgd

forgot these...


# 1.18 12-Apr-1994 cgd

be a bit smarter about determining if files shouldn't be seen by the user.
Also, DON'T allow a lookup to succeed on a file that's not visible!


# 1.17 15-Feb-1994 mycroft

Undo last change; executables is `file', not `a.out'.


# 1.16 14-Feb-1994 ws

Rename file -> a.out


# 1.15 14-Feb-1994 ws

Don't try to show a file for a process if there is none


# 1.14 28-Jan-1994 cgd

make a fpregs file.


# 1.13 20-Jan-1994 ws

Make procfs really work for debugging.
Implement not & notepg files in procfs.


# 1.12 09-Jan-1994 ws

Bug fixes and enhancements:
Make NFS serving work (BUT DON'T USE "attach" TO /proc/*/ctl FOR NOW!!!)
Make `curproc' a symbolic link
Add `.' and `..' entries to the directories.
Return better guesses on the size of the files.


# 1.11 05-Jan-1994 cgd

return size of 'reg' from getattr()


# 1.10 05-Jan-1994 cgd

make it compile (cleanly) for us


# 1.9 05-Jan-1994 cgd

add new procfs code, from Jan-Simon Pendry, jsp@sequent.com.
This is pretty-much "virgin", so that diffs can be done later.


# 1.8 18-Dec-1993 mycroft

Canonicalize all #includes.


Revision tags: magnum-base
# 1.7 16-Sep-1993 cgd

kill volatile warning.


# 1.6 07-Sep-1993 ws

branches: 1.6.2;
Changes to VFS readdir semantics
NFS changes for better cookie support
ISOFS changes for better Rockridge support and support for generation numbers


# 1.5 26-Aug-1993 pk

Implement setattr: mode for process entries; mode + uid/gid for the
PROCFS root directory.
Fixed omission in pfs_root() which came to light as a result of the above:
hold on to vnode for root dir.


# 1.4 25-Aug-1993 pk

Fixed improperly initialized nfsnode in pfs_lookup()


# 1.3 24-Aug-1993 pk

copyright update.


# 1.2 24-Aug-1993 pk

Rcs Id added.


# 1.1 24-Aug-1993 pk

branches: 1.1.1;
Initial version of a proc filesystem.


# 1.210 24-Feb-2020 ad

v_interlock -> vmobjlock


# 1.209 23-Feb-2020 ad

Merge from ad-namecache:

- Have a stab at clustering the members of vnode_t and vnode_impl_t in a
more cache-conscious way. With that done, go back to adjusting v_usecount
with atomics and keep vi_lock directly in vnode_impl_t (saves KVA).

- Allow VOP_LOCK(LK_NONE) for the benefit of VFS_VGET() and VFS_ROOT().
Make sure LK_UPGRADE always comes with LK_NOWAIT.

- Make cwdinfo use mostly lockless.


# 1.208 01-Feb-2020 riastradh

Load struct filedesc::fd_dt with atomic_load_consume.

Exceptions: when fd_refcnt <= 1, or when holding fd_lock.

While here:

- Restore KASSERT(mutex_owned(&fdp->fd_lock)) in fd_unused.
=> This is used only in fd_close and fd_abort, where it holds.
- Move bounds check assertion in fd_putfile to where it matters.
- Store fd_dt with atomic_store_release.
- Move load of fd_dt under lock in knote_fdclose.
- Omit membar_consumer in fdesc_readdir.
=> atomic_load_consume serves the same purpose now.
=> Was needed only on alpha anyway.


Revision tags: ad-namecache-base2 ad-namecache-base1 ad-namecache-base phil-wifi-20191119
# 1.207 29-Aug-2019 hannken

branches: 1.207.2;
Add missing operation VOP_GETPAGES() returning EFAULT.

Without this operation posix_fadvise(..., POSIX_FADV_WILLNEED)
would leave the v_interlock held.

Observed by maxv@


Revision tags: netbsd-9-base phil-wifi-20190609 isaki-audio2-base
# 1.206 30-Mar-2019 christos

branches: 1.206.4;
add a node for the process resource limits.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020
# 1.205 14-Oct-2018 jdolecek

remove M_CANFAIL flag for malloc(9) - it was completely ignored, so had
actually no effect


Revision tags: pgoyette-compat-0930 pgoyette-compat-0906
# 1.204 03-Sep-2018 riastradh

Rename min/max -> uimin/uimax for better honesty.

These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER! Some subsystems have

#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)


Revision tags: pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415
# 1.203 07-Apr-2018 hannken

branches: 1.203.2;
Lock the target cwdi and take an additional reference to the
vnode we are interested in to prevent it from disappearing
before getcwd_common().

Should fix PR kern/53096 (netbsd-8 crash on heavy disk I/O)


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.202 31-Dec-2017 christos

branches: 1.202.2;
Add an environ node


Revision tags: tls-maxphys-base-20171202
# 1.201 01-Dec-2017 christos

Allow procfs_kqfilter, since we allow poll. "go" does it.


# 1.200 08-Nov-2017 christos

fix locking, remove error(1) comments.


# 1.199 08-Nov-2017 christos

use p->p_path, remove unused code.


# 1.198 28-Aug-2017 kamil

Remove the filesystem tracing feature

This is a legacy interface from 4.4BSD, and it was
introduced to overcome shortcomings of ptrace(2) at that time, which are
no longer relevant (performance). Today /proc/#/ctl offers a narrow
subset of ptrace(2) commands and is not applicable for modern
applications use beyond simplistic tracing scenarios.

This removal will simplify kernel internals. Users will still be able to
use all the other /proc files.

This change won't affect other procfs files neither Linux compat
features within mount_procfs(8). /proc/#/ctl isn't available on Linux.

Remove:
- /proc/#/ctl from mount_procfs(8)
- P_FSTRACE note from the documentation of ps(1)
- /proc/#/ctl and filesystem tracing documentation from mount_procfs(8)
- KAUTH_REQ_PROCESS_PROCFS_CTL documentation from kauth(9)
- source code file miscfs/procfs/procfs_ctl.c
- PFSctl and procfs_doctl() from sys/miscfs/procfs/procfs.h
- KAUTH_REQ_PROCESS_PROCFS_CTL from sys/sys/kauth.h
- PSL_FSTRACE (0x00010000) from sys/sys/proc.h
- P_FSTRACE (0x00010000) from sys/sys/sysctl.h

Reduce code complexity after removal of this functionality.

Update TODO.ptrace accordingly: remove two entries about /proc tracing.

Do not keep legacy notes as comments in the headers about removed
PSL_FSTRACE / P_FSTRACE, as this interface had little number of users
(close or equal to zero).

Proposed on tech-kern@.

All filesystem tracing utility users are encouraged to switch to ptrace(2).

Sponsored by <The NetBSD Foundation>


Revision tags: matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base
# 1.197 26-May-2017 riastradh

branches: 1.197.2;
Make VOP_RECLAIM do the last unlock of the vnode.

VOP_RECLAIM naturally has exclusive access to the vnode, so having it
locked on entry is not strictly necessary -- but it means if there
are any final operations that must be done on the vnode, such as
ffs_update, requiring exclusive access to it, we can now kassert that
the vnode is locked in those operations.

We can't just have the caller release the last lock because some file
systems don't use genfs_lock, and require the vnode to remain valid
for VOP_UNLOCK to work, notably unionfs.


Revision tags: prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.196 11-Apr-2017 riastradh

Make VOP_INACTIVE preserve vnode lock on return.

Discussed on tech-kern:
https://mail-index.netbsd.org/tech-kern/2017/04/01/msg021751.html

Ride 7.99.68, a bumpy bus of incremental vfs improvements!


Revision tags: jdolecek-ncq-base
# 1.195 30-Mar-2017 christos

add an auxv node.


Revision tags: pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004 localcount-20160914
# 1.194 20-Aug-2016 hannken

branches: 1.194.2;
Remove now obsolete operation vcache_remove().

Welcome to 7.99.36


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 nick-nhusb-base-20150921 nick-nhusb-base-20150606
# 1.193 20-Apr-2015 riastradh

branches: 1.193.2;
Make VOP_LINK return directory still locked and referenced.

Ride 7.99.10 bump.


Revision tags: nick-nhusb-base-20150406 nick-nhusb-base
# 1.192 05-Sep-2014 matt

branches: 1.192.2;
Try not to use f_data, use f_{vnode,socket,pipe,mqueue,kqueue,ksem} to get
a correctly typed pointer.


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.191 27-Jul-2014 hannken

branches: 1.191.2; 1.191.4; 1.191.8;
Change procfs from hashlist to vcache.
- Key is (type, pid, fd)
- Remove argument "p" from procfs_allocvp(). It is only used
when "type == PFSfd". Lookup the proc with proc_find() when
procfs_loadvnode() needs it.
- Use a vfs_vnode_iterator for procfs_revoke_vnodes().


# 1.190 25-Jul-2014 dholland

Add VOP_FALLOCATE and VOP_FDISCARD to every vnode ops table I can
find.

The filesystem ones all call genfs_eopnotsupp - right now I am only
implementing the plumbing and we can implement fallocate and/or
fdiscard for files later.

The device ones call spec_fallocate (which is also genfs_eopnotsupp)
and spec_fdiscard, which dispatches to the device-level op.

The fifo ones all call vn_fifo_bypass, which also ends up being
EOPNOTSUPP.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base
# 1.189 07-Feb-2014 hannken

branches: 1.189.2;
Change vnode operation lookup to return the resulting vnode *vpp unlocked.
Change cache_lookup() to return an unlocked vnode.

Discussed on tech-kern@

Welcome to 6.99.31


# 1.188 23-Jan-2014 hannken

Change vnode operations create, mknod, mkdir and symlink to return
the resulting vnode *vpp unlocked.

Discussed on tech-kern@

Welcome to 6.99.30


# 1.187 17-Jan-2014 hannken

Change vnode operations create, mknod, mkdir and symlink to keep the
directory node dvp locked on return.

Discussed on tech-kern@

Welcome to 6.99.29


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base
# 1.186 18-Mar-2013 plunky

branches: 1.186.6;
C99 section 6.7.2.3 (Tags) Note 3 states that:

A type specifier of the form

enum identifier

without an enumerator list shall only appear after the type it
specifies is complete.

which means that we cannot pass an "enum vtype" argument to
kauth_access_action() without fully specifying the type first.
Unfortunately there is a complicated include file loop which
makes that difficult, so convert this minimal function into a
macro (and capitalize it).

(ok elad@)


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 1.185 25-Nov-2012 christos

do something reasonable with kernel semaphores.


Revision tags: yamt-pagecache-base6 jmcneill-usbmp-base10
# 1.184 28-May-2012 christos

branches: 1.184.2;
add a task process subdirectory for emul linux


Revision tags: yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 1.183 13-Mar-2012 elad

Replace the remaining KAUTH_GENERIC_ISSUSER authorization calls with
something meaningful. All relevant documentation has been updated or
written.

Most of these changes were brought up in the following messages:

http://mail-index.netbsd.org/tech-kern/2012/01/18/msg012490.html
http://mail-index.netbsd.org/tech-kern/2012/01/19/msg012502.html
http://mail-index.netbsd.org/tech-kern/2012/02/17/msg012728.html

Thanks to christos, manu, njoly, and jmmv for input.

Huge thanks to pgoyette for spinning these changes through some build
cycles and ATF.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.182 04-Sep-2011 jmcneill

branches: 1.182.2; 1.182.6;
PR# kern/45021: Please support /emul/linux/proc/version

Add /proc/version for procfs with -o linux. The version reported depends
on the emulation type of the calling process:

$ cat /proc/version
NetBSD version 5.99.55 (netbsd@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) NetBSD 5.99.55 (GENERIC) #39: Sun Sep 4 09:10:05 EDT 2011

$ /emul/linux/bin/cat /proc/version
Linux version 2.6.18 (linux@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) #0 Wed Mar 3 03:03:03 PST 2010

$ /emul/linux32/bin/cat /proc/version
Linux version 2.6.18 (linux32@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) #0 Wed Mar 3 03:03:03 PST 2010


# 1.181 23-Jun-2011 christos

From Aleksey Cheusov: Don't make it easy for compromised systems to bypass
ASLR protections by providing the mapping addresses of programs to everyone.


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base matt-mips64-premerge-20101231 uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10 rmind-uvmplock-base
# 1.180 01-Jul-2010 rmind

Remove pfind() and pgfind(), fix locking in various broken uses of these.
Rename real routines to proc_find() and pgrp_find(), remove PFIND_* flags
and have consistent behaviour. Provide proc_find_raw() for special cases.
Fix memory leak in sysctl_proc_corename().

COMPAT_LINUX: rework ptrace() locking, minimise differences between
different versions per-arch.

Note: while this change adds some formal cosmetics for COMPAT_DARWIN and
COMPAT_IRIX - locking there is utterly broken (for ages).

Fixes PR/43176.


# 1.179 24-Jun-2010 hannken

Clean up vnode lock operations pass 2:

VOP_UNLOCK(vp, flags) -> VOP_UNLOCK(vp): Remove the unneeded flags argument.

Welcome to 5.99.32.

Discussed on tech-kern.


# 1.178 08-Jun-2010 hannken

Procfs_lookup() does not lookup directory descriptors in the fd/
subdirectory. There is no need for recursive vnode locking here.

Ok: Christos Zoulas <christos@netbsd.org>


Revision tags: uebayasi-xip-base1 yamt-nfs-mp-base9 uebayasi-xip-base
# 1.177 08-Jan-2010 pooka

branches: 1.177.2; 1.177.4;
The VATTR_NULL/VREF/VHOLD/HOLDRELE() macros lost their will to live
years ago when the kernel was modified to not alter ABI based on
DIAGNOSTIC, and now just call the respective function interfaces
(in lowercase). Plenty of mix'n match upper/lowercase has creeped
into the tree since then. Nuke the macros and convert all callsites
to lowercase.

no functional change


Revision tags: matt-premerge-20091211 yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 jym-xensuspend-nbase
# 1.176 03-Jul-2009 elad

Where possible, extract the file-system's access() routine to two internal
functions: the first checking if the operation is possible (regardless of
permissions), the second checking file-system permissions, ACLs, etc.

Mailing list reference:

http://mail-index.netbsd.org/tech-kern/2009/06/21/msg005311.html


# 1.175 23-Jun-2009 elad

Move the implementation of vaccess() to genfs_can_access(), in line with
the other routines of the same spirit.

Adjust file-system code to use it.

Keep vaccess() for KPI compatibility and to keep element of least
surprise. A "diagnostic" message warning that vaccess() is deprecated will
be printed when it's used (obviously, only in DIAGNOSTIC kernels).

No objections on tech-kern@:

http://mail-index.netbsd.org/tech-kern/2009/06/21/msg005310.html


Revision tags: yamt-nfs-mp-base5
# 1.174 24-May-2009 ad

More changes to improve kern_descrip.c.

- Avoid atomics in more places.
- Remove the per-descriptor mutex, and just use filedesc_t::fd_lock.
It was only being used to synchronize close, and in any case we needed
to take fd_lock to free the descriptor slot.
- Optimize certain paths for the <NDFDFILE case.
- Sprinkle more comments and assertions.
- Cache more stuff in filedesc_t.
- Fix numerous minor bugs spotted along the way.
- Restructure how the open files array is maintained, for clarity and so
that we can eliminate the membar_consumer() call in fd_getfile(). This is
mostly syntactic sugar; the main functional change is that fd_nfiles now
lives alongside the open file array.

Some measurements with libmicro:

- simple file syscalls are like close() are between 1 to 10% faster.
- some nice improvements, e.g. poll(1000) which is ~50% faster.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 nick-hppapmap-base2 jym-xensuspend-base nick-hppapmap-base mjf-devfs2-base
# 1.173 17-Dec-2008 cegger

branches: 1.173.2;
kill MALLOC and FREE macros.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 haad-dm-base2 haad-nbase2 ad-audiomp2-base netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 haad-dm-base
# 1.172 05-Sep-2008 skrll

branches: 1.172.2;
PR/39324 kernel diagnostic assertion "l->l_stat != LSZOMB" failed.

Ignore procs with zero or all LSZOMB LWPs. Get a non-LSZOMB LWP to perform
operations against as part of the deal.

procfs really needs to be updated to support multi-threading fully.
Hi Antti!


# 1.171 05-Sep-2008 skrll

ANSIfy


Revision tags: simonb-wapbl-nbase simonb-wapbl-base
# 1.170 02-Jul-2008 rmind

branches: 1.170.2;
Remove proc_representative_lwp(), use a simple LIST_FIRST() instead.
OK by <ad>.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base
# 1.169 28-Apr-2008 martin

branches: 1.169.2; 1.169.4;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-nfs-mp-base
# 1.168 24-Apr-2008 ad

branches: 1.168.2;
Merge proc::p_mutex and proc::p_smutex into a single adaptive mutex, since
we no longer need to guard against access from hardware interrupt handlers.

Additionally, if cloning a process with CLONE_SIGHAND, arrange to have the
child process share the parent's lock so that signal state may be kept in
sync. Partially addresses PR kern/37437.


# 1.167 24-Apr-2008 ad

Network protocol interrupts can now block on locks, so merge the globals
proclist_mutex and proclist_lock into a single adaptive mutex (proc_lock).
Implications:

- Inspecting process state requires thread context, so signals can no longer
be sent from a hardware interrupt handler. Signal activity must be
deferred to a soft interrupt or kthread.

- As the proc state locking is simplified, it's now safe to take exit()
and wait() out from under kernel_lock.

- The system spends less time at IPL_SCHED, and there is less lock activity.


Revision tags: yamt-pf42-baseX yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14
# 1.166 21-Mar-2008 ad

branches: 1.166.2;
Catch up with descriptor handling changes. See kern_descrip.c revision
1.173 for details.


Revision tags: keiichi-mipv6-nbase nick-net80211-sync-base keiichi-mipv6-base bouyer-xeni386-nbase matt-armv6-nbase mjf-devfs-base hpcarm-cleanup-base
# 1.165 23-Jan-2008 elad

branches: 1.165.6;
Tons of process scope changes.

- Add a KAUTH_PROCESS_SCHEDULER action, to handle scheduler related
requests, and add specific requests for set/get scheduler policy and
set/get scheduler parameters.

- Add a KAUTH_PROCESS_KEVENT_FILTER action, to handle kevent(2) related
requests.

- Add a KAUTH_DEVICE_TTY_STI action to handle requests to TIOCSTI.

- Add requests for the KAUTH_PROCESS_CANSEE action, indicating what
process information is being looked at (entry itself, args, env,
open files).

- Add requests for the KAUTH_PROCESS_RLIMIT action indicating set/get.

- Add requests for the KAUTH_PROCESS_CORENAME action indicating set/get.

- Make bsd44 secmodel code handle the newly added rqeuests appropriately.

All of the above make it possible to issue finer-grained kauth(9) calls in
many places, removing some KAUTH_GENERIC_ISSUSER requests.

- Remove the "CAN" from KAUTH_PROCESS_CAN{KTRACE,PROCFS,PTRACE,SIGNAL}.

Discussed with christos@ and yamt@.


Revision tags: bouyer-xeni386-base matt-armv6-base
# 1.164 02-Jan-2008 ad

Merge vmlocking2 to head.


Revision tags: vmlocking2-base3 yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 vmlocking-nbase jmcneill-pm-base reinoud-bufcleanup-base
# 1.163 26-Nov-2007 pooka

branches: 1.163.2; 1.163.6;
Remove the "struct lwp *" argument from all VFS and VOP interfaces.
The general trend is to remove it from all kernel interfaces and
this is a start. In case the calling lwp is desired, curlwp should
be used.

quick consensus on tech-kern


Revision tags: bouyer-xenamd64-base2 bouyer-xenamd64-base
# 1.162 09-Nov-2007 christos

make the last argument of procfs_dir size_t


# 1.161 07-Nov-2007 ad

Merge from vmlocking:

- pool_cache changes.
- Debugger/procfs locking fixes.
- Other minor changes.


Revision tags: jmcneill-base yamt-x86pmap-base4 yamt-x86pmap-base3 vmlocking-base
# 1.160 10-Oct-2007 ad

branches: 1.160.2; 1.160.4;
Merge from vmlocking:

- Split vnode::v_flag into three fields, depending on field locking.
- simple_lock -> kmutex in a few places.
- Fix some simple locking problems.


# 1.159 08-Oct-2007 ad

Merge file descriptor locking, cwdi locking and cross-call changes
from the vmlocking branch.


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base2 yamt-x86pmap-base matt-mips64-base
# 1.158 22-Jul-2007 pooka

branches: 1.158.4; 1.158.6; 1.158.8; 1.158.10;
Don't allow getcwd() on procfs vnodes and provide "/" as the path
instead of the result from getcwd(). The works around locking
panics caused by namei calling VOP_READLINK while holding on to a
directory lock and getcwd() trying to acquire that lock. The real
fix would be to get rid of getcwd() calls within VOPs (not locking
safe), but that's not a viable option in the netbsd-4 timeframe.

Suggestion for workaround from David Holland.


Revision tags: nick-csl-alignment-base mjf-ufs-trans-base
# 1.157 24-May-2007 agc

branches: 1.157.2;
Extend the Linux emulation of /proc to include

/proc/stat
/proc/loadavg and
/proc/<pid>/statm.

These are only present when -o linux is specified as a mount option
to procfs.

Factor out some common code so that it can be used by a number of
functions.

XXX The values returned in the statm emulation need to be verified.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 1.156 04-Apr-2007 rmind

Unfortunately, missed procfs_proc_unlock() in previous.
Pointed out by pooka@


# 1.155 04-Apr-2007 rmind

procfs_readlink: Handle a possible fail of fd_getfile(), also, we
do not need to check for error again.
CID: 4436


# 1.154 09-Mar-2007 ad

branches: 1.154.2; 1.154.4;
- Make the proclist_lock a mutex. The write:read ratio is unfavourable,
and mutexes are cheaper use than RW locks.
- LOCK_ASSERT -> KASSERT in some places.
- Hold proclist_lock/kernel_lock longer in a couple of places.


# 1.153 04-Mar-2007 christos

Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.


# 1.152 03-Mar-2007 salo

Don't prepend rootvnode to the path in non-NULL case for exe links.
It breaks procfs in chroot.

from <christos>, tested by me.


Revision tags: ad-audiomp-base
# 1.151 19-Feb-2007 pooka

When checking for file validity under pid/, do proper proc->lwp
lookup (fsvo proper) instead of fiddling directly with the lwp
list.


# 1.150 18-Feb-2007 pooka

Don't check for validity of p in lookup for root nodes, since it
will always be NULL. Rather, just call pt_valid with NULL directly
and let it decide if we're a linux mount or not.


# 1.149 17-Feb-2007 pavel

Change the process/lwp flags seen by userland via sysctl back to the
P_*/L_* naming convention, and rename the in-kernel flags to avoid
conflict. (P_ -> PK_, L_ -> LW_ ). Add back the (now unused) LSDEAD
constant.

Restores source compatibility with pre-newlock2 tools like ps or top.

Reviewed by Andrew Doran.


# 1.148 16-Feb-2007 pooka

branches: 1.148.2;
In lookup, when checking for procfs process node validity, target the
process we're trying to get information about through procfs, not
the caller of lookup.

fixes 'ls -l /proc/*/file' panic, which would occur when trying to
lookup "file" for a kernel thread, which doesn't have p->p_textvp.


# 1.147 15-Feb-2007 ad

Need to acquire procp->p_mutex for procfs_dir().


# 1.146 11-Feb-2007 ad

Eliminate a couple of reference count and mutex leaks.


Revision tags: post-newlock2-merge
# 1.145 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 1.144 25-Dec-2006 elad

PR/35226: Johann Franz: Problems with permissions in
/usr/pkg/emul/linux/proc .

Okay mlelstv@


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3
# 1.143 09-Dec-2006 chs

a smorgasbord of improvements to vnode locking and path lookup:
- LOCKPARENT is no longer relevant for lookup(), relookup() or VOP_LOOKUP().
these now always return the parent vnode locked. namei() works as before.
lookup() and various other paths no longer acquire vnode locks in the
wrong order via vrele(). fixes PR 32535.
as a nice side effect, path lookup is also up to 25% faster.
- the above allows us to get rid of PDIRUNLOCK.
- also get rid of WANTPARENT (just use LOCKPARENT and unlock it).
- remove an assumption in layer_node_find() that all file systems implement
a recursive VOP_LOCK() (unionfs doesn't).
- require that all file systems supply vfs_vptofh and vfs_fhtovp routines.
fill in eopnotsupp() for file systems that don't support being exported
and remove the checks for NULL. (layerfs calls these without checking.)
- in union_lookup1(), don't change refcounts in the ISDOTDOT case, just
adjust which vnode is locked. fixes PR 33374.
- apply fixes for ufs_rename() from ufs_vnops.c rev. 1.61 to ext2fs_rename().


# 1.142 04-Dec-2006 christos

From Nicolas Joly: restore previous behavior in procfs_validfile_linux, since
readdir passes a NULL lwp.


# 1.141 03-Dec-2006 elad

Move kauth(9) call to where it belongs. Noticed by Nicolas Joly, thanks!


Revision tags: netbsd-4-base
# 1.140 28-Nov-2006 elad

branches: 1.140.2;
Move ktrace, ptrace, systrace, and procfs to use kauth(9).

First, remove process_checkioperm() calls from MD code. Similar checks
using kauth(9) routines (on the process scope, using appropriate action)
are done in the callers.

Add secmodel back-end to handle each subsystem.


# 1.139 25-Nov-2006 skrll

Expose the 'exe' symlink to the process realpath in NetBSD as well. An
example user is gdb.

OK'd by christos.


# 1.138 16-Nov-2006 christos

__unused removal on arguments; approved by core.


# 1.137 29-Oct-2006 christos

add an "emul" file node.


# 1.136 25-Oct-2006 christos

1. fix procfs_validfile{,_linux} to test for NULL pointers properly.
2. make "exe" entry be a symlink to the executable, instead of pointing
directly to the vnode of the executable.
3. factor out commonly used code.


Revision tags: yamt-splraiseipl-base2
# 1.135 12-Oct-2006 christos

- sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386


# 1.134 20-Sep-2006 manu

Emulate Linux's /proc/devices


Revision tags: abandoned-netbsd-4-base yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base rpaulo-netinet-merge-pcb-base
# 1.133 13-Jun-2006 yamt

branches: 1.133.6; 1.133.8;
use KAUTH_PROCESS_CANSEE rather than CURTAIN where appropriate.


# 1.132 13-Jun-2006 yamt

remove unnecessary arguments from kauth_authorize_process.
ie. make it similar to the one found in apple TN.


# 1.131 07-Jun-2006 kardel

merge FreeBSD timecounters from branch simonb-timecounters
- struct timeval time is gone
time.tv_sec -> time_second
- struct timeval mono_time is gone
mono_time.tv_sec -> time_uptime
- access to time via
{get,}{micro,nano,bin}time()
get* versions are fast but less precise
- support NTP nanokernel implementation (NTP API 4)
- further reading:
Timecounter Paper: http://phk.freebsd.dk/pubs/timecounter.pdf
NTP Nanokernel: http://www.eecis.udel.edu/~mills/ntp/html/kern.html


Revision tags: yamt-pdpolicy-base5 simonb-timecounters-base
# 1.130 14-May-2006 elad

branches: 1.130.2;
integrate kauth.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 elad-kernelauth-base yamt-pdpolicy-base yamt-uio_vmspace-base5
# 1.129 02-Feb-2006 christos

branches: 1.129.2; 1.129.4; 1.129.6; 1.129.8;
PR/32692: Matthew Mondor: linux compatibility in /proc/self should point
directly to the directory containing the pid instead of pointing to
/proc/curproc, because some programs rely on calling readlink on /proc/self
to get the pid.


# 1.128 11-Dec-2005 christos

branches: 1.128.2; 1.128.4;
merge ktrace-lwp.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base ktrace-lwp-base
# 1.127 02-Nov-2005 yamt

merge yamt-vop branch. remove following VOPs.

VOP_BLKATOFF
VOP_VALLOC
VOP_BALLOC
VOP_REALLOCBLKS
VOP_VFREE
VOP_TRUNCATE
VOP_UPDATE


Revision tags: yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 1.126 01-Oct-2005 atatat

branches: 1.126.2;
Add "cwd" and "root" symlinks to each process's directory. The cwd
link points to the process's current working directory, and the root
link points to the process's root directory. What else would you
expect?

For directories that are out of reach (caller is in a chroot, target
process is in a different chroot, etc), the links point to "/"
instead.


# 1.125 11-Sep-2005 elad

Implement curtain for procfs.


# 1.124 30-Aug-2005 xtraeme

Remove __P()


# 1.123 29-May-2005 christos

branches: 1.123.2;
- sprinkle const
- avoid shadowed variables.


Revision tags: kent-audio2-base
# 1.122 02-Apr-2005 christos

PR/29782: Martin Husemann: procfs can not unmount when some process has its
current directory in curproc. Fix from Pedro Martelletto:
We cannot call vgone() from procfs_inactive() if we are coming from
vclean(). that's what's probably causing the deadlock.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 yamt-km-base4 yamt-km-base3 netbsd-3-base
# 1.121 26-Feb-2005 perry

nuke trailing whitespace


Revision tags: yamt-km-base2 yamt-km-base kent-audio1-beforemerge kent-audio1-base
# 1.120 04-Oct-2004 yamt

branches: 1.120.4; 1.120.6;
procfs_readdir:
- return correct cookie when buffer size is small.
- simplify logic.


# 1.119 04-Oct-2004 yamt

procfs_readdir: remove a redundant assignment.


# 1.118 02-Oct-2004 yamt

procfs_getattr: correct size of /proc/self.


# 1.117 01-Oct-2004 yamt

procfs_readdir:
- fix a locking problem, using proclist_foreach_call. PR/27098.
- correct snprintf size argument.


# 1.116 01-Oct-2004 yamt

procfs_readdir: fix an offset handling bug after addition of /proc/self.


# 1.115 01-Oct-2004 yamt

procfs_readdir: use a list macro.


# 1.114 20-Sep-2004 jdolecek

add 'mounts' file for -o linux, which lists all currently mounted
filesystems; Linux glibc statvfs() uses this to get some of mount flags,
and this file is also useful as /emul/linux/etc/mtab (via symlink)


# 1.113 29-Apr-2004 jrf

Removed remaining caddr_t casts we do not need in miscfs. Recompiled
kernel and ran for a day or so. There are still some caddr_t types in
the arguments of some calls, I will do those separately (later) as
they touch a lot more of the system.
Approved by christos@NetBSD.org.


# 1.112 22-Apr-2004 itojun

sprintf -> snprintf


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.111 15-Feb-2004 jdolecek

unlock the descriptor table simple lock after fd_getfile() call in
procfs_readdir()
fixes procfs locking problems reported on current-users@, problem place
found by enami tsugutomo


# 1.110 30-Oct-2003 simonb

Remove some assigned-to but otherwise unused variables.


# 1.109 27-Sep-2003 darcy

Changes as discussed with itojun on tech-kern. I have modified the enums
to have KFS or PFS differentiators. Further I have wrapped the enum in
procfs in "#ifdef _KERNEL" as it is done in kernfs.

To see the discussion go to http://mail-index.NetBSD.org/tech-kern/2003/09/
and look for "Mismatched enums in include files" in the list.


# 1.108 07-Sep-2003 itojun

remove meaningless line (variable overwritten 2 lines below)


# 1.107 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.


# 1.106 29-Jun-2003 fvdl

branches: 1.106.2;
Back out the lwp/ktrace changes. They contained a lot of colateral damage,
and need to be examined and discussed more.


# 1.105 29-Jun-2003 thorpej

Undo part of the ktrace/lwp changes. In particular:
* Remove the "lwp *" argument that was added to vget(). Turns out
that nothing actually used it!
* Remove the "lwp *" arguments that were added to VFS_ROOT(), VFS_VGET(),
and VFS_FHTOVP(); all they did was pass it to vget() (which, as noted
above, didn't use it).
* Remove all of the "lwp *" arguments to internal functions that were added
just to appease the above.


# 1.104 28-Jun-2003 darrenr

Pass lwp pointers throughtout the kernel, as required, so that the lwpid can
be inserted into ktrace records. The general change has been to replace
"struct proc *" with "struct lwp *" in various function prototypes, pass
the lwp through and use l_proc to get the process pointer when needed.

Bump the kernel rev up to 1.6V


# 1.103 28-May-2003 christos

Add /proc/<pid>/stat for linux compat. j2sdk1.4.2 depends on it.


# 1.102 18-Apr-2003 christos

Make symlinks for directories that point to the actual directory.
Make symlinks to [kqueue] and [misc] for kqueue and misc fds.


# 1.101 17-Apr-2003 jdolecek

do not show nodes corresponding to directory descriptors for process
in fd/ subdirectory, nor allow lookup/open for the nodes
this fixes PR kern/21187 for good, and also avoids interesting directory
locking issues


# 1.100 17-Apr-2003 jdolecek

procfs_readdir(): in Pfd case, only show descriptors of types we want
how to represent (vnodes, fifo, pipes); also use fd_getfile() et al

this avoids annoying EOPNOTSUPP error messages from ls -F and such


# 1.99 17-Apr-2003 jdolecek

procfs_lookup(): use fd_getfile() et al in Pfd case


# 1.98 17-Apr-2003 jdolecek

use fd_getfile() in procfs_getfp(), and FILE_USE()/FILE_UNUSE() the
returned file descriptor pointer appropriately


# 1.97 17-Apr-2003 jdolecek

make some local arrays/variables static + const


# 1.96 10-Apr-2003 jdolecek

use former genfs_eopnotsupp_rele() as genfs_eopnotsupp(), so that vnodes
are vput()/vrele()d as necessary - some filesystems did use the wrong
one for some ops, and it's just safer to not take the chance

based on suggestion by Bill Studenmund


# 1.95 05-Apr-2003 dsl

Remove pointless check against PID_MAX. Let pfind() do the validation.
(The new pid allocation code may decide to allocate pids above PID_MAX.)


# 1.94 25-Feb-2003 jrf

This addresses PR kerm/19989. Thanks to hamajima@nagoya.ydc.co.jp for submitting this patch which enables /proc/uptime for linux emul. Patch reviewed by atatat@netbsd.org and tron@netbsd.org, approved by tron@netbsd.org.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 1.93 04-Jan-2003 martin

Cast off_t expression to long long to match format even on 64 bit
plattforms.

Shouldn't we introduce a PRIoff_t macro to create such format strings?


# 1.92 03-Jan-2003 christos

add LK_CANRECURSE in the locking of /dev/<pid>/fd/<n> and remove the curproc
kludge. Thanks to fvdl.


# 1.91 03-Jan-2003 christos

Implement /proc/<pid>/fd/<n>. This is work in progress. Questionable things:
- Is it ok to convert DTYPE_PIPE to VFIFO and DTYPE_SOCKET to VSOCK?
- XXX: Avoid locking issue in ls -Rl /proc by avoiding curproc
- Does I/O to pipes work?
- XXX: Are there security implications?


Revision tags: fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge gehenna-devsw-base kqueue-base
# 1.90 03-Aug-2002 simonb

Just use the "time" variable in the *_getattr functions instead of a call
to (the potentially expensive) microtime().


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.89 09-May-2002 thorpej

branches: 1.89.2;
Move code shared by procfs and the kernel proper out of procfs and
into the kernel proper (renaming functions from procfs_* to process_*).


Revision tags: eeh-devprop-base newlock-base ifpoll-base
# 1.88 12-Jan-2002 christos

Don't hide the real return code with EPERM.


# 1.87 06-Dec-2001 chs

add a VOP_PUTPAGES method for all the filesystems that don't have pages,
just unlock the interlock.


# 1.86 05-Dec-2001 thorpej

* Allow machine-dependent code to specify hooks for ptrace(2)
(__HAVE_PTRACE_MACHDEP) and procfs (__HAVE_PROCFS_MACHDEP).
These changes will allow platforms like x86 (XMM) and PowerPC
(AltiVec) to export extended register sets in a sane manner.

* Use __HAVE_PTRACE_MACHDEP to export x86 XMM registers (standard
FP + SSE/SSE2) using PT_{GET,SET}XMMREGS (in the machdep
ptrace request space).
* Use __HAVE_PROCFS_MACHDEP to export x86 XMM registers via
/proc/N/xmmregs in procfs.


Revision tags: thorpej-mips-cache-base
# 1.85 10-Nov-2001 lukem

add RCSIDs


# 1.84 06-Nov-2001 simonb

Remove some variables that are set but never used.


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base
# 1.83 31-Aug-2001 chs

branches: 1.83.2; 1.83.4;
map files are zero-length.


# 1.82 03-Jun-2001 chs

branches: 1.82.2;
procfs_bmap() should never be called, make it a "bad op".
let procfs_mmap() use the default error method.


Revision tags: thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 1.81 14-Apr-2001 kleink

In procfs_readdir(), give /proc/# directories DT_DIR (rather than DT_REG).


# 1.80 30-Mar-2001 fvdl

Bump va_blocksize for the map files some more, so that programs with
quite a few mappings have a chance of being handled correctly if
st_blksize is looked at.


# 1.79 29-Mar-2001 fvdl

For -o linux mounts, add some code to emulate /proc/#/maps.
Needs NAMECACHE_ENTER_REVERSE to include filenames.


# 1.78 21-Feb-2001 jdolecek

branches: 1.78.2;
make some more constant arrays 'const'


# 1.77 22-Jan-2001 jdolecek

make filesystem vnodeop, specop, fifoop and vnodeopv_* arrays const


# 1.76 17-Jan-2001 fvdl

Add a few linux-style files, only enabled when -o linux is specified
for the mount. Currently these are /proc/cpuinfo and /proc/meminfo.
The former only does something on i386 right now.


# 1.75 24-Nov-2000 chs

remove dead code and other misc cleanup.


# 1.74 09-Aug-2000 tv

Only show the "exe" entry to Linux processes, suggested by christos.
Since there are actually three struct emul's for linux, use the e_name
field to determine eligibility with strcmp().


# 1.73 09-Aug-2000 tv

Some versions of Linux libc look for /proc/.../exe instead of /proc/../file.
Add an entry for "exe" that is the same as "file", provided only if
COMPAT_LINUX is set.


# 1.72 03-Aug-2000 thorpej

MALLOC()/FREE() are not to be used for variable sized allocations.


# 1.71 28-Jun-2000 mrg

<vm/vm.h> -> <uvm/uvm_extern.h>


Revision tags: netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 1.70 30-Mar-2000 simonb

branches: 1.70.4;
Delete duplicate declaration of atopid().


Revision tags: chs-ubc2-newbase wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base fvdl-softdep-base
# 1.69 02-Sep-1999 thorpej

branches: 1.69.2; 1.69.8;
Make /proc/self a symlink to /proc/curproc. I've observed Linux programs
that expect /proc/self/cmdline to exist.


# 1.68 25-Aug-1999 sommerfeld

Change variable used for directory offset from "int" to "off_t".
Overkill, but avoids a host of truncation problems.


# 1.67 24-Aug-1999 sommerfeld

Fix PR8270:

Problem turned out to be due to improper handling of reads beyond EOF:
they should just return without error with the uio unchanged, and the
caller will recognize this as a zero-byte return (EOF).

The previous fix to protect directory reads against bogus uio_offset
values returned EINVAL, which broke mount -o union, which only
union'ed in the lower directory if the upper directory cleanly
returned EOF.

While we're here, protect kernfs as well.


# 1.66 14-Aug-1999 christos

protect against large uio_offset


# 1.65 03-Aug-1999 wrstuden

Add support for fcntl(2) to generate VOP_FCNTL calls. Any fcntl
call with F_FSCTL set and F_SETFL calls generate calls to a new
fileop fo_fcntl. Add genfs_fcntl() and soo_fcntl() which return 0
for F_SETFL and EOPNOTSUPP otherwise. Have all leaf filesystems
use genfs_fcntl().

Reviewed by: thorpej
Tested by: wrstuden


Revision tags: chs-ubc2-base
# 1.64 25-Jul-1999 thorpej

Add calls to lock the proclist as appropriate.


# 1.63 14-Jul-1999 thorpej

Fix a paste-o in procfs_lookup() introduced with the vnode locking changes.
Fixes PR #7961, Mario Kemper <magick@bundy.lip.owl.de>.


# 1.62 08-Jul-1999 wrstuden

Bump osrelease to 1.4E. Add layerfs files, remove null_subr.c.

Update coda to new struct lock in struct vnode.

make fdescfs, kernfs, portalfs, and procfs actually lock their vnodes.
It's not that hard.

Make unionfs set v_vnlock = NULL so any overlayed fs will call its
VOP_LOCK.


Revision tags: kame_141_19991130 netbsd-1-4-PATCH001 kame_14_19990705 kame_14_19990628 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.61 12-Mar-1999 christos

branches: 1.61.2; 1.61.4;
PR/7143: Jaromir Docelek: Add procfs/cmdline from Linux emulation


# 1.60 25-Jan-1999 msaitoh

Add /proc/#/map. From FreeBSD.


Revision tags: kenh-if-detach-base chs-ubc-base
# 1.59 08-Sep-1998 thorpej

- Use proclists[], rather than checking allproc and zombproc explicitly.
- Add some comments about locking.


# 1.58 13-Aug-1998 kleink

Per POSIX, fail with EINVAL if advisory locking is attempted on a file type
that doesn't support it, rather than using a homegrown EBADF or EOPNOTSUPP.


# 1.57 10-Aug-1998 matthias

create miscfs/genfs/genfs_vnops.c:genfs_enoioctl and make all the other
filesystems use it instead of a private version.


# 1.56 09-Aug-1998 perry

bzero->memset, bcopy->memcpy, bcmp->memcmp


# 1.55 03-Aug-1998 kleink

Recognize _PC_SYNC_IO.


Revision tags: eeh-paddr_t-base
# 1.54 21-Apr-1998 fvdl

procfs_readdir: in case of error, check if cookies actually have
been allocated before freeing them. From Wolfgang Solfrank.


# 1.53 01-Mar-1998 fvdl

Merge with Lite2 + local changes


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base marc-pcmcia-base
# 1.52 10-Oct-1997 fvdl

Bump last argument to VOP_READDIR to off_t (from u_long).


Revision tags: thorpej-signal-base
# 1.51 27-Aug-1997 thorpej

Fix a reversed argument which caused procfs_checkioperm() to always return
"OK". Add a few comments to avoid further confusion.


# 1.50 12-Aug-1997 thorpej

Fix the procfs hole described on current-users, similar to a fix for
FreeBSD by Sean Eric Fagan, but a bit different. This makes the checks
in the same places as sef's FreeBSD patch, but does not hardcode the
"kmem" group into the kernel, and also does a check identical to the
(3) and (4) checks in the NetBSD ptrace(2):

(1) it's not owned by you, or is set-id on exec (unless
you're root), or

(2) it's init, which controls the security level of the
entire system, and the system was not compiled with
permanently insecure mode turned on.


Revision tags: marc-pcmcia-bp
# 1.49 08-May-1997 mycroft

branches: 1.49.4;
Pass the vnode type to vaccess(), and use it when checking VEXEC. Make sure
that the mode bits passed to vaccess() and returned by foo_getattr() contain
only permission bits.


# 1.48 05-May-1997 mycroft

Need stat.h.


# 1.47 05-May-1997 mycroft

Eliminate bogus uses of V{READ,WRITE,EXEC}. Use S_I[RWX]{USR,GRP,OTH} where
appropriate.


# 1.46 28-Apr-1997 mycroft

Minor code cleanup.


Revision tags: is-newarp-before-merge is-newarp-base
# 1.45 25-Oct-1996 cgd

define path name string variables that we should not (and, thankfully, do
not) modify as 'const char *' rather 'char *'.


# 1.44 13-Oct-1996 christos

backout previous kprintf changes


# 1.43 10-Oct-1996 christos

printf -> kprintf, sprintf -> ksprintf


# 1.42 07-Sep-1996 mycroft

Implement poll(2).


# 1.41 01-Sep-1996 mycroft

Add a set of generic file system operations that most file systems use.
Also, fix some time stamp bogosities.


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 1.40 16-Mar-1996 christos

Fix printf format follies.


# 1.39 13-Feb-1996 mycroft

GC *_nullop(). Minor nits.


# 1.38 12-Feb-1996 christos

close PR/2063: procfs_rw prototyped twice with different prototypes


# 1.37 09-Feb-1996 christos

miscfs prototype changes


# 1.36 09-Feb-1996 mycroft

Fix vop_link, vop_symlink, and vop_remove semantics in several ways:
* Change the argument names to vop_link so they actually make sense.
* Implement vop_link and vop_symlink for all file systems, so they do proper
cleanup.
* Require the file system to decide whether or not linking and unlinking of
directories is allowed, and disable it for all current file systems.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.35 09-Oct-1995 mycroft

Use the index number as the cookie, rather than multiplying by UIO_MX.


# 1.34 09-Oct-1995 mycroft

Add support for cookies, mostly from Greg Hudson.


# 1.33 15-Apr-1995 cgd

fix timeval vs. timespec warnings


# 1.32 03-Feb-1995 mycroft

Return EROFS rather than ENOENT in many cases. Also some cosmetic cleanup.


# 1.31 27-Dec-1994 mycroft

Format police.


# 1.30 24-Dec-1994 ws

Implement and use a common access checking routine


# 1.29 14-Dec-1994 mycroft

Remove a_fp.


# 1.28 14-Nov-1994 christos

fixed struct comment


# 1.27 30-Oct-1994 cgd

be more careful with types, also pull in headers where necessary.


# 1.26 20-Oct-1994 cgd

update for new syscall args description mechanism


# 1.25 30-Aug-1994 mycroft

Convert process, file, and namei lists and hash tables to use queue.h.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.24 29-Jun-1994 cgd

New RCS ID's, take two. they're more aesthecially pleasant, and use 'NetBSD'


# 1.23 16-Jun-1994 mycroft

Remove an unneeded test.


# 1.22 15-Jun-1994 mycroft

Minor update from JSP after merging my changes.


# 1.21 08-Jun-1994 mycroft

Update to 4.4-Lite fs code, with local changes.


# 1.20 05-May-1994 cgd

lots of changes: prototype migration, move lots of variables, definitions,
and structure elements around. kill some unnecessary type and macro
definitions. standardize clock handling. More changes than you'd want.


# 1.19 15-Apr-1994 cgd

forgot these...


# 1.18 12-Apr-1994 cgd

be a bit smarter about determining if files shouldn't be seen by the user.
Also, DON'T allow a lookup to succeed on a file that's not visible!


# 1.17 15-Feb-1994 mycroft

Undo last change; executables is `file', not `a.out'.


# 1.16 14-Feb-1994 ws

Rename file -> a.out


# 1.15 14-Feb-1994 ws

Don't try to show a file for a process if there is none


# 1.14 28-Jan-1994 cgd

make a fpregs file.


# 1.13 20-Jan-1994 ws

Make procfs really work for debugging.
Implement not & notepg files in procfs.


# 1.12 09-Jan-1994 ws

Bug fixes and enhancements:
Make NFS serving work (BUT DON'T USE "attach" TO /proc/*/ctl FOR NOW!!!)
Make `curproc' a symbolic link
Add `.' and `..' entries to the directories.
Return better guesses on the size of the files.


# 1.11 05-Jan-1994 cgd

return size of 'reg' from getattr()


# 1.10 05-Jan-1994 cgd

make it compile (cleanly) for us


# 1.9 05-Jan-1994 cgd

add new procfs code, from Jan-Simon Pendry, jsp@sequent.com.
This is pretty-much "virgin", so that diffs can be done later.


# 1.8 18-Dec-1993 mycroft

Canonicalize all #includes.


Revision tags: magnum-base
# 1.7 16-Sep-1993 cgd

kill volatile warning.


# 1.6 07-Sep-1993 ws

branches: 1.6.2;
Changes to VFS readdir semantics
NFS changes for better cookie support
ISOFS changes for better Rockridge support and support for generation numbers


# 1.5 26-Aug-1993 pk

Implement setattr: mode for process entries; mode + uid/gid for the
PROCFS root directory.
Fixed omission in pfs_root() which came to light as a result of the above:
hold on to vnode for root dir.


# 1.4 25-Aug-1993 pk

Fixed improperly initialized nfsnode in pfs_lookup()


# 1.3 24-Aug-1993 pk

copyright update.


# 1.2 24-Aug-1993 pk

Rcs Id added.


# 1.1 24-Aug-1993 pk

branches: 1.1.1;
Initial version of a proc filesystem.


# 1.209 23-Feb-2020 ad

Merge from ad-namecache:

- Have a stab at clustering the members of vnode_t and vnode_impl_t in a
more cache-conscious way. With that done, go back to adjusting v_usecount
with atomics and keep vi_lock directly in vnode_impl_t (saves KVA).

- Allow VOP_LOCK(LK_NONE) for the benefit of VFS_VGET() and VFS_ROOT().
Make sure LK_UPGRADE always comes with LK_NOWAIT.

- Make cwdinfo use mostly lockless.


# 1.208 01-Feb-2020 riastradh

Load struct filedesc::fd_dt with atomic_load_consume.

Exceptions: when fd_refcnt <= 1, or when holding fd_lock.

While here:

- Restore KASSERT(mutex_owned(&fdp->fd_lock)) in fd_unused.
=> This is used only in fd_close and fd_abort, where it holds.
- Move bounds check assertion in fd_putfile to where it matters.
- Store fd_dt with atomic_store_release.
- Move load of fd_dt under lock in knote_fdclose.
- Omit membar_consumer in fdesc_readdir.
=> atomic_load_consume serves the same purpose now.
=> Was needed only on alpha anyway.


Revision tags: ad-namecache-base2 ad-namecache-base1 ad-namecache-base phil-wifi-20191119
# 1.207 29-Aug-2019 hannken

branches: 1.207.2;
Add missing operation VOP_GETPAGES() returning EFAULT.

Without this operation posix_fadvise(..., POSIX_FADV_WILLNEED)
would leave the v_interlock held.

Observed by maxv@


Revision tags: netbsd-9-base phil-wifi-20190609 isaki-audio2-base
# 1.206 30-Mar-2019 christos

branches: 1.206.4;
add a node for the process resource limits.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020
# 1.205 14-Oct-2018 jdolecek

remove M_CANFAIL flag for malloc(9) - it was completely ignored, so had
actually no effect


Revision tags: pgoyette-compat-0930 pgoyette-compat-0906
# 1.204 03-Sep-2018 riastradh

Rename min/max -> uimin/uimax for better honesty.

These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER! Some subsystems have

#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)


Revision tags: pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415
# 1.203 07-Apr-2018 hannken

branches: 1.203.2;
Lock the target cwdi and take an additional reference to the
vnode we are interested in to prevent it from disappearing
before getcwd_common().

Should fix PR kern/53096 (netbsd-8 crash on heavy disk I/O)


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.202 31-Dec-2017 christos

branches: 1.202.2;
Add an environ node


Revision tags: tls-maxphys-base-20171202
# 1.201 01-Dec-2017 christos

Allow procfs_kqfilter, since we allow poll. "go" does it.


# 1.200 08-Nov-2017 christos

fix locking, remove error(1) comments.


# 1.199 08-Nov-2017 christos

use p->p_path, remove unused code.


# 1.198 28-Aug-2017 kamil

Remove the filesystem tracing feature

This is a legacy interface from 4.4BSD, and it was
introduced to overcome shortcomings of ptrace(2) at that time, which are
no longer relevant (performance). Today /proc/#/ctl offers a narrow
subset of ptrace(2) commands and is not applicable for modern
applications use beyond simplistic tracing scenarios.

This removal will simplify kernel internals. Users will still be able to
use all the other /proc files.

This change won't affect other procfs files neither Linux compat
features within mount_procfs(8). /proc/#/ctl isn't available on Linux.

Remove:
- /proc/#/ctl from mount_procfs(8)
- P_FSTRACE note from the documentation of ps(1)
- /proc/#/ctl and filesystem tracing documentation from mount_procfs(8)
- KAUTH_REQ_PROCESS_PROCFS_CTL documentation from kauth(9)
- source code file miscfs/procfs/procfs_ctl.c
- PFSctl and procfs_doctl() from sys/miscfs/procfs/procfs.h
- KAUTH_REQ_PROCESS_PROCFS_CTL from sys/sys/kauth.h
- PSL_FSTRACE (0x00010000) from sys/sys/proc.h
- P_FSTRACE (0x00010000) from sys/sys/sysctl.h

Reduce code complexity after removal of this functionality.

Update TODO.ptrace accordingly: remove two entries about /proc tracing.

Do not keep legacy notes as comments in the headers about removed
PSL_FSTRACE / P_FSTRACE, as this interface had little number of users
(close or equal to zero).

Proposed on tech-kern@.

All filesystem tracing utility users are encouraged to switch to ptrace(2).

Sponsored by <The NetBSD Foundation>


Revision tags: matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base
# 1.197 26-May-2017 riastradh

branches: 1.197.2;
Make VOP_RECLAIM do the last unlock of the vnode.

VOP_RECLAIM naturally has exclusive access to the vnode, so having it
locked on entry is not strictly necessary -- but it means if there
are any final operations that must be done on the vnode, such as
ffs_update, requiring exclusive access to it, we can now kassert that
the vnode is locked in those operations.

We can't just have the caller release the last lock because some file
systems don't use genfs_lock, and require the vnode to remain valid
for VOP_UNLOCK to work, notably unionfs.


Revision tags: prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.196 11-Apr-2017 riastradh

Make VOP_INACTIVE preserve vnode lock on return.

Discussed on tech-kern:
https://mail-index.netbsd.org/tech-kern/2017/04/01/msg021751.html

Ride 7.99.68, a bumpy bus of incremental vfs improvements!


Revision tags: jdolecek-ncq-base
# 1.195 30-Mar-2017 christos

add an auxv node.


Revision tags: pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004 localcount-20160914
# 1.194 20-Aug-2016 hannken

branches: 1.194.2;
Remove now obsolete operation vcache_remove().

Welcome to 7.99.36


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 nick-nhusb-base-20150921 nick-nhusb-base-20150606
# 1.193 20-Apr-2015 riastradh

branches: 1.193.2;
Make VOP_LINK return directory still locked and referenced.

Ride 7.99.10 bump.


Revision tags: nick-nhusb-base-20150406 nick-nhusb-base
# 1.192 05-Sep-2014 matt

branches: 1.192.2;
Try not to use f_data, use f_{vnode,socket,pipe,mqueue,kqueue,ksem} to get
a correctly typed pointer.


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.191 27-Jul-2014 hannken

branches: 1.191.2; 1.191.4; 1.191.8;
Change procfs from hashlist to vcache.
- Key is (type, pid, fd)
- Remove argument "p" from procfs_allocvp(). It is only used
when "type == PFSfd". Lookup the proc with proc_find() when
procfs_loadvnode() needs it.
- Use a vfs_vnode_iterator for procfs_revoke_vnodes().


# 1.190 25-Jul-2014 dholland

Add VOP_FALLOCATE and VOP_FDISCARD to every vnode ops table I can
find.

The filesystem ones all call genfs_eopnotsupp - right now I am only
implementing the plumbing and we can implement fallocate and/or
fdiscard for files later.

The device ones call spec_fallocate (which is also genfs_eopnotsupp)
and spec_fdiscard, which dispatches to the device-level op.

The fifo ones all call vn_fifo_bypass, which also ends up being
EOPNOTSUPP.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base
# 1.189 07-Feb-2014 hannken

branches: 1.189.2;
Change vnode operation lookup to return the resulting vnode *vpp unlocked.
Change cache_lookup() to return an unlocked vnode.

Discussed on tech-kern@

Welcome to 6.99.31


# 1.188 23-Jan-2014 hannken

Change vnode operations create, mknod, mkdir and symlink to return
the resulting vnode *vpp unlocked.

Discussed on tech-kern@

Welcome to 6.99.30


# 1.187 17-Jan-2014 hannken

Change vnode operations create, mknod, mkdir and symlink to keep the
directory node dvp locked on return.

Discussed on tech-kern@

Welcome to 6.99.29


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base
# 1.186 18-Mar-2013 plunky

branches: 1.186.6;
C99 section 6.7.2.3 (Tags) Note 3 states that:

A type specifier of the form

enum identifier

without an enumerator list shall only appear after the type it
specifies is complete.

which means that we cannot pass an "enum vtype" argument to
kauth_access_action() without fully specifying the type first.
Unfortunately there is a complicated include file loop which
makes that difficult, so convert this minimal function into a
macro (and capitalize it).

(ok elad@)


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 1.185 25-Nov-2012 christos

do something reasonable with kernel semaphores.


Revision tags: yamt-pagecache-base6 jmcneill-usbmp-base10
# 1.184 28-May-2012 christos

branches: 1.184.2;
add a task process subdirectory for emul linux


Revision tags: yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 1.183 13-Mar-2012 elad

Replace the remaining KAUTH_GENERIC_ISSUSER authorization calls with
something meaningful. All relevant documentation has been updated or
written.

Most of these changes were brought up in the following messages:

http://mail-index.netbsd.org/tech-kern/2012/01/18/msg012490.html
http://mail-index.netbsd.org/tech-kern/2012/01/19/msg012502.html
http://mail-index.netbsd.org/tech-kern/2012/02/17/msg012728.html

Thanks to christos, manu, njoly, and jmmv for input.

Huge thanks to pgoyette for spinning these changes through some build
cycles and ATF.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.182 04-Sep-2011 jmcneill

branches: 1.182.2; 1.182.6;
PR# kern/45021: Please support /emul/linux/proc/version

Add /proc/version for procfs with -o linux. The version reported depends
on the emulation type of the calling process:

$ cat /proc/version
NetBSD version 5.99.55 (netbsd@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) NetBSD 5.99.55 (GENERIC) #39: Sun Sep 4 09:10:05 EDT 2011

$ /emul/linux/bin/cat /proc/version
Linux version 2.6.18 (linux@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) #0 Wed Mar 3 03:03:03 PST 2010

$ /emul/linux32/bin/cat /proc/version
Linux version 2.6.18 (linux32@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) #0 Wed Mar 3 03:03:03 PST 2010


# 1.181 23-Jun-2011 christos

From Aleksey Cheusov: Don't make it easy for compromised systems to bypass
ASLR protections by providing the mapping addresses of programs to everyone.


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base matt-mips64-premerge-20101231 uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10 rmind-uvmplock-base
# 1.180 01-Jul-2010 rmind

Remove pfind() and pgfind(), fix locking in various broken uses of these.
Rename real routines to proc_find() and pgrp_find(), remove PFIND_* flags
and have consistent behaviour. Provide proc_find_raw() for special cases.
Fix memory leak in sysctl_proc_corename().

COMPAT_LINUX: rework ptrace() locking, minimise differences between
different versions per-arch.

Note: while this change adds some formal cosmetics for COMPAT_DARWIN and
COMPAT_IRIX - locking there is utterly broken (for ages).

Fixes PR/43176.


# 1.179 24-Jun-2010 hannken

Clean up vnode lock operations pass 2:

VOP_UNLOCK(vp, flags) -> VOP_UNLOCK(vp): Remove the unneeded flags argument.

Welcome to 5.99.32.

Discussed on tech-kern.


# 1.178 08-Jun-2010 hannken

Procfs_lookup() does not lookup directory descriptors in the fd/
subdirectory. There is no need for recursive vnode locking here.

Ok: Christos Zoulas <christos@netbsd.org>


Revision tags: uebayasi-xip-base1 yamt-nfs-mp-base9 uebayasi-xip-base
# 1.177 08-Jan-2010 pooka

branches: 1.177.2; 1.177.4;
The VATTR_NULL/VREF/VHOLD/HOLDRELE() macros lost their will to live
years ago when the kernel was modified to not alter ABI based on
DIAGNOSTIC, and now just call the respective function interfaces
(in lowercase). Plenty of mix'n match upper/lowercase has creeped
into the tree since then. Nuke the macros and convert all callsites
to lowercase.

no functional change


Revision tags: matt-premerge-20091211 yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 jym-xensuspend-nbase
# 1.176 03-Jul-2009 elad

Where possible, extract the file-system's access() routine to two internal
functions: the first checking if the operation is possible (regardless of
permissions), the second checking file-system permissions, ACLs, etc.

Mailing list reference:

http://mail-index.netbsd.org/tech-kern/2009/06/21/msg005311.html


# 1.175 23-Jun-2009 elad

Move the implementation of vaccess() to genfs_can_access(), in line with
the other routines of the same spirit.

Adjust file-system code to use it.

Keep vaccess() for KPI compatibility and to keep element of least
surprise. A "diagnostic" message warning that vaccess() is deprecated will
be printed when it's used (obviously, only in DIAGNOSTIC kernels).

No objections on tech-kern@:

http://mail-index.netbsd.org/tech-kern/2009/06/21/msg005310.html


Revision tags: yamt-nfs-mp-base5
# 1.174 24-May-2009 ad

More changes to improve kern_descrip.c.

- Avoid atomics in more places.
- Remove the per-descriptor mutex, and just use filedesc_t::fd_lock.
It was only being used to synchronize close, and in any case we needed
to take fd_lock to free the descriptor slot.
- Optimize certain paths for the <NDFDFILE case.
- Sprinkle more comments and assertions.
- Cache more stuff in filedesc_t.
- Fix numerous minor bugs spotted along the way.
- Restructure how the open files array is maintained, for clarity and so
that we can eliminate the membar_consumer() call in fd_getfile(). This is
mostly syntactic sugar; the main functional change is that fd_nfiles now
lives alongside the open file array.

Some measurements with libmicro:

- simple file syscalls are like close() are between 1 to 10% faster.
- some nice improvements, e.g. poll(1000) which is ~50% faster.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 nick-hppapmap-base2 jym-xensuspend-base nick-hppapmap-base mjf-devfs2-base
# 1.173 17-Dec-2008 cegger

branches: 1.173.2;
kill MALLOC and FREE macros.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 haad-dm-base2 haad-nbase2 ad-audiomp2-base netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 haad-dm-base
# 1.172 05-Sep-2008 skrll

branches: 1.172.2;
PR/39324 kernel diagnostic assertion "l->l_stat != LSZOMB" failed.

Ignore procs with zero or all LSZOMB LWPs. Get a non-LSZOMB LWP to perform
operations against as part of the deal.

procfs really needs to be updated to support multi-threading fully.
Hi Antti!


# 1.171 05-Sep-2008 skrll

ANSIfy


Revision tags: simonb-wapbl-nbase simonb-wapbl-base
# 1.170 02-Jul-2008 rmind

branches: 1.170.2;
Remove proc_representative_lwp(), use a simple LIST_FIRST() instead.
OK by <ad>.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base
# 1.169 28-Apr-2008 martin

branches: 1.169.2; 1.169.4;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-nfs-mp-base
# 1.168 24-Apr-2008 ad

branches: 1.168.2;
Merge proc::p_mutex and proc::p_smutex into a single adaptive mutex, since
we no longer need to guard against access from hardware interrupt handlers.

Additionally, if cloning a process with CLONE_SIGHAND, arrange to have the
child process share the parent's lock so that signal state may be kept in
sync. Partially addresses PR kern/37437.


# 1.167 24-Apr-2008 ad

Network protocol interrupts can now block on locks, so merge the globals
proclist_mutex and proclist_lock into a single adaptive mutex (proc_lock).
Implications:

- Inspecting process state requires thread context, so signals can no longer
be sent from a hardware interrupt handler. Signal activity must be
deferred to a soft interrupt or kthread.

- As the proc state locking is simplified, it's now safe to take exit()
and wait() out from under kernel_lock.

- The system spends less time at IPL_SCHED, and there is less lock activity.


Revision tags: yamt-pf42-baseX yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14
# 1.166 21-Mar-2008 ad

branches: 1.166.2;
Catch up with descriptor handling changes. See kern_descrip.c revision
1.173 for details.


Revision tags: keiichi-mipv6-nbase nick-net80211-sync-base keiichi-mipv6-base bouyer-xeni386-nbase matt-armv6-nbase mjf-devfs-base hpcarm-cleanup-base
# 1.165 23-Jan-2008 elad

branches: 1.165.6;
Tons of process scope changes.

- Add a KAUTH_PROCESS_SCHEDULER action, to handle scheduler related
requests, and add specific requests for set/get scheduler policy and
set/get scheduler parameters.

- Add a KAUTH_PROCESS_KEVENT_FILTER action, to handle kevent(2) related
requests.

- Add a KAUTH_DEVICE_TTY_STI action to handle requests to TIOCSTI.

- Add requests for the KAUTH_PROCESS_CANSEE action, indicating what
process information is being looked at (entry itself, args, env,
open files).

- Add requests for the KAUTH_PROCESS_RLIMIT action indicating set/get.

- Add requests for the KAUTH_PROCESS_CORENAME action indicating set/get.

- Make bsd44 secmodel code handle the newly added rqeuests appropriately.

All of the above make it possible to issue finer-grained kauth(9) calls in
many places, removing some KAUTH_GENERIC_ISSUSER requests.

- Remove the "CAN" from KAUTH_PROCESS_CAN{KTRACE,PROCFS,PTRACE,SIGNAL}.

Discussed with christos@ and yamt@.


Revision tags: bouyer-xeni386-base matt-armv6-base
# 1.164 02-Jan-2008 ad

Merge vmlocking2 to head.


Revision tags: vmlocking2-base3 yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 vmlocking-nbase jmcneill-pm-base reinoud-bufcleanup-base
# 1.163 26-Nov-2007 pooka

branches: 1.163.2; 1.163.6;
Remove the "struct lwp *" argument from all VFS and VOP interfaces.
The general trend is to remove it from all kernel interfaces and
this is a start. In case the calling lwp is desired, curlwp should
be used.

quick consensus on tech-kern


Revision tags: bouyer-xenamd64-base2 bouyer-xenamd64-base
# 1.162 09-Nov-2007 christos

make the last argument of procfs_dir size_t


# 1.161 07-Nov-2007 ad

Merge from vmlocking:

- pool_cache changes.
- Debugger/procfs locking fixes.
- Other minor changes.


Revision tags: jmcneill-base yamt-x86pmap-base4 yamt-x86pmap-base3 vmlocking-base
# 1.160 10-Oct-2007 ad

branches: 1.160.2; 1.160.4;
Merge from vmlocking:

- Split vnode::v_flag into three fields, depending on field locking.
- simple_lock -> kmutex in a few places.
- Fix some simple locking problems.


# 1.159 08-Oct-2007 ad

Merge file descriptor locking, cwdi locking and cross-call changes
from the vmlocking branch.


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base2 yamt-x86pmap-base matt-mips64-base
# 1.158 22-Jul-2007 pooka

branches: 1.158.4; 1.158.6; 1.158.8; 1.158.10;
Don't allow getcwd() on procfs vnodes and provide "/" as the path
instead of the result from getcwd(). The works around locking
panics caused by namei calling VOP_READLINK while holding on to a
directory lock and getcwd() trying to acquire that lock. The real
fix would be to get rid of getcwd() calls within VOPs (not locking
safe), but that's not a viable option in the netbsd-4 timeframe.

Suggestion for workaround from David Holland.


Revision tags: nick-csl-alignment-base mjf-ufs-trans-base
# 1.157 24-May-2007 agc

branches: 1.157.2;
Extend the Linux emulation of /proc to include

/proc/stat
/proc/loadavg and
/proc/<pid>/statm.

These are only present when -o linux is specified as a mount option
to procfs.

Factor out some common code so that it can be used by a number of
functions.

XXX The values returned in the statm emulation need to be verified.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 1.156 04-Apr-2007 rmind

Unfortunately, missed procfs_proc_unlock() in previous.
Pointed out by pooka@


# 1.155 04-Apr-2007 rmind

procfs_readlink: Handle a possible fail of fd_getfile(), also, we
do not need to check for error again.
CID: 4436


# 1.154 09-Mar-2007 ad

branches: 1.154.2; 1.154.4;
- Make the proclist_lock a mutex. The write:read ratio is unfavourable,
and mutexes are cheaper use than RW locks.
- LOCK_ASSERT -> KASSERT in some places.
- Hold proclist_lock/kernel_lock longer in a couple of places.


# 1.153 04-Mar-2007 christos

Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.


# 1.152 03-Mar-2007 salo

Don't prepend rootvnode to the path in non-NULL case for exe links.
It breaks procfs in chroot.

from <christos>, tested by me.


Revision tags: ad-audiomp-base
# 1.151 19-Feb-2007 pooka

When checking for file validity under pid/, do proper proc->lwp
lookup (fsvo proper) instead of fiddling directly with the lwp
list.


# 1.150 18-Feb-2007 pooka

Don't check for validity of p in lookup for root nodes, since it
will always be NULL. Rather, just call pt_valid with NULL directly
and let it decide if we're a linux mount or not.


# 1.149 17-Feb-2007 pavel

Change the process/lwp flags seen by userland via sysctl back to the
P_*/L_* naming convention, and rename the in-kernel flags to avoid
conflict. (P_ -> PK_, L_ -> LW_ ). Add back the (now unused) LSDEAD
constant.

Restores source compatibility with pre-newlock2 tools like ps or top.

Reviewed by Andrew Doran.


# 1.148 16-Feb-2007 pooka

branches: 1.148.2;
In lookup, when checking for procfs process node validity, target the
process we're trying to get information about through procfs, not
the caller of lookup.

fixes 'ls -l /proc/*/file' panic, which would occur when trying to
lookup "file" for a kernel thread, which doesn't have p->p_textvp.


# 1.147 15-Feb-2007 ad

Need to acquire procp->p_mutex for procfs_dir().


# 1.146 11-Feb-2007 ad

Eliminate a couple of reference count and mutex leaks.


Revision tags: post-newlock2-merge
# 1.145 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 1.144 25-Dec-2006 elad

PR/35226: Johann Franz: Problems with permissions in
/usr/pkg/emul/linux/proc .

Okay mlelstv@


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3
# 1.143 09-Dec-2006 chs

a smorgasbord of improvements to vnode locking and path lookup:
- LOCKPARENT is no longer relevant for lookup(), relookup() or VOP_LOOKUP().
these now always return the parent vnode locked. namei() works as before.
lookup() and various other paths no longer acquire vnode locks in the
wrong order via vrele(). fixes PR 32535.
as a nice side effect, path lookup is also up to 25% faster.
- the above allows us to get rid of PDIRUNLOCK.
- also get rid of WANTPARENT (just use LOCKPARENT and unlock it).
- remove an assumption in layer_node_find() that all file systems implement
a recursive VOP_LOCK() (unionfs doesn't).
- require that all file systems supply vfs_vptofh and vfs_fhtovp routines.
fill in eopnotsupp() for file systems that don't support being exported
and remove the checks for NULL. (layerfs calls these without checking.)
- in union_lookup1(), don't change refcounts in the ISDOTDOT case, just
adjust which vnode is locked. fixes PR 33374.
- apply fixes for ufs_rename() from ufs_vnops.c rev. 1.61 to ext2fs_rename().


# 1.142 04-Dec-2006 christos

From Nicolas Joly: restore previous behavior in procfs_validfile_linux, since
readdir passes a NULL lwp.


# 1.141 03-Dec-2006 elad

Move kauth(9) call to where it belongs. Noticed by Nicolas Joly, thanks!


Revision tags: netbsd-4-base
# 1.140 28-Nov-2006 elad

branches: 1.140.2;
Move ktrace, ptrace, systrace, and procfs to use kauth(9).

First, remove process_checkioperm() calls from MD code. Similar checks
using kauth(9) routines (on the process scope, using appropriate action)
are done in the callers.

Add secmodel back-end to handle each subsystem.


# 1.139 25-Nov-2006 skrll

Expose the 'exe' symlink to the process realpath in NetBSD as well. An
example user is gdb.

OK'd by christos.


# 1.138 16-Nov-2006 christos

__unused removal on arguments; approved by core.


# 1.137 29-Oct-2006 christos

add an "emul" file node.


# 1.136 25-Oct-2006 christos

1. fix procfs_validfile{,_linux} to test for NULL pointers properly.
2. make "exe" entry be a symlink to the executable, instead of pointing
directly to the vnode of the executable.
3. factor out commonly used code.


Revision tags: yamt-splraiseipl-base2
# 1.135 12-Oct-2006 christos

- sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386


# 1.134 20-Sep-2006 manu

Emulate Linux's /proc/devices


Revision tags: abandoned-netbsd-4-base yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base rpaulo-netinet-merge-pcb-base
# 1.133 13-Jun-2006 yamt

branches: 1.133.6; 1.133.8;
use KAUTH_PROCESS_CANSEE rather than CURTAIN where appropriate.


# 1.132 13-Jun-2006 yamt

remove unnecessary arguments from kauth_authorize_process.
ie. make it similar to the one found in apple TN.


# 1.131 07-Jun-2006 kardel

merge FreeBSD timecounters from branch simonb-timecounters
- struct timeval time is gone
time.tv_sec -> time_second
- struct timeval mono_time is gone
mono_time.tv_sec -> time_uptime
- access to time via
{get,}{micro,nano,bin}time()
get* versions are fast but less precise
- support NTP nanokernel implementation (NTP API 4)
- further reading:
Timecounter Paper: http://phk.freebsd.dk/pubs/timecounter.pdf
NTP Nanokernel: http://www.eecis.udel.edu/~mills/ntp/html/kern.html


Revision tags: yamt-pdpolicy-base5 simonb-timecounters-base
# 1.130 14-May-2006 elad

branches: 1.130.2;
integrate kauth.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 elad-kernelauth-base yamt-pdpolicy-base yamt-uio_vmspace-base5
# 1.129 02-Feb-2006 christos

branches: 1.129.2; 1.129.4; 1.129.6; 1.129.8;
PR/32692: Matthew Mondor: linux compatibility in /proc/self should point
directly to the directory containing the pid instead of pointing to
/proc/curproc, because some programs rely on calling readlink on /proc/self
to get the pid.


# 1.128 11-Dec-2005 christos

branches: 1.128.2; 1.128.4;
merge ktrace-lwp.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base ktrace-lwp-base
# 1.127 02-Nov-2005 yamt

merge yamt-vop branch. remove following VOPs.

VOP_BLKATOFF
VOP_VALLOC
VOP_BALLOC
VOP_REALLOCBLKS
VOP_VFREE
VOP_TRUNCATE
VOP_UPDATE


Revision tags: yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 1.126 01-Oct-2005 atatat

branches: 1.126.2;
Add "cwd" and "root" symlinks to each process's directory. The cwd
link points to the process's current working directory, and the root
link points to the process's root directory. What else would you
expect?

For directories that are out of reach (caller is in a chroot, target
process is in a different chroot, etc), the links point to "/"
instead.


# 1.125 11-Sep-2005 elad

Implement curtain for procfs.


# 1.124 30-Aug-2005 xtraeme

Remove __P()


# 1.123 29-May-2005 christos

branches: 1.123.2;
- sprinkle const
- avoid shadowed variables.


Revision tags: kent-audio2-base
# 1.122 02-Apr-2005 christos

PR/29782: Martin Husemann: procfs can not unmount when some process has its
current directory in curproc. Fix from Pedro Martelletto:
We cannot call vgone() from procfs_inactive() if we are coming from
vclean(). that's what's probably causing the deadlock.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 yamt-km-base4 yamt-km-base3 netbsd-3-base
# 1.121 26-Feb-2005 perry

nuke trailing whitespace


Revision tags: yamt-km-base2 yamt-km-base kent-audio1-beforemerge kent-audio1-base
# 1.120 04-Oct-2004 yamt

branches: 1.120.4; 1.120.6;
procfs_readdir:
- return correct cookie when buffer size is small.
- simplify logic.


# 1.119 04-Oct-2004 yamt

procfs_readdir: remove a redundant assignment.


# 1.118 02-Oct-2004 yamt

procfs_getattr: correct size of /proc/self.


# 1.117 01-Oct-2004 yamt

procfs_readdir:
- fix a locking problem, using proclist_foreach_call. PR/27098.
- correct snprintf size argument.


# 1.116 01-Oct-2004 yamt

procfs_readdir: fix an offset handling bug after addition of /proc/self.


# 1.115 01-Oct-2004 yamt

procfs_readdir: use a list macro.


# 1.114 20-Sep-2004 jdolecek

add 'mounts' file for -o linux, which lists all currently mounted
filesystems; Linux glibc statvfs() uses this to get some of mount flags,
and this file is also useful as /emul/linux/etc/mtab (via symlink)


# 1.113 29-Apr-2004 jrf

Removed remaining caddr_t casts we do not need in miscfs. Recompiled
kernel and ran for a day or so. There are still some caddr_t types in
the arguments of some calls, I will do those separately (later) as
they touch a lot more of the system.
Approved by christos@NetBSD.org.


# 1.112 22-Apr-2004 itojun

sprintf -> snprintf


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.111 15-Feb-2004 jdolecek

unlock the descriptor table simple lock after fd_getfile() call in
procfs_readdir()
fixes procfs locking problems reported on current-users@, problem place
found by enami tsugutomo


# 1.110 30-Oct-2003 simonb

Remove some assigned-to but otherwise unused variables.


# 1.109 27-Sep-2003 darcy

Changes as discussed with itojun on tech-kern. I have modified the enums
to have KFS or PFS differentiators. Further I have wrapped the enum in
procfs in "#ifdef _KERNEL" as it is done in kernfs.

To see the discussion go to http://mail-index.NetBSD.org/tech-kern/2003/09/
and look for "Mismatched enums in include files" in the list.


# 1.108 07-Sep-2003 itojun

remove meaningless line (variable overwritten 2 lines below)


# 1.107 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.


# 1.106 29-Jun-2003 fvdl

branches: 1.106.2;
Back out the lwp/ktrace changes. They contained a lot of colateral damage,
and need to be examined and discussed more.


# 1.105 29-Jun-2003 thorpej

Undo part of the ktrace/lwp changes. In particular:
* Remove the "lwp *" argument that was added to vget(). Turns out
that nothing actually used it!
* Remove the "lwp *" arguments that were added to VFS_ROOT(), VFS_VGET(),
and VFS_FHTOVP(); all they did was pass it to vget() (which, as noted
above, didn't use it).
* Remove all of the "lwp *" arguments to internal functions that were added
just to appease the above.


# 1.104 28-Jun-2003 darrenr

Pass lwp pointers throughtout the kernel, as required, so that the lwpid can
be inserted into ktrace records. The general change has been to replace
"struct proc *" with "struct lwp *" in various function prototypes, pass
the lwp through and use l_proc to get the process pointer when needed.

Bump the kernel rev up to 1.6V


# 1.103 28-May-2003 christos

Add /proc/<pid>/stat for linux compat. j2sdk1.4.2 depends on it.


# 1.102 18-Apr-2003 christos

Make symlinks for directories that point to the actual directory.
Make symlinks to [kqueue] and [misc] for kqueue and misc fds.


# 1.101 17-Apr-2003 jdolecek

do not show nodes corresponding to directory descriptors for process
in fd/ subdirectory, nor allow lookup/open for the nodes
this fixes PR kern/21187 for good, and also avoids interesting directory
locking issues


# 1.100 17-Apr-2003 jdolecek

procfs_readdir(): in Pfd case, only show descriptors of types we want
how to represent (vnodes, fifo, pipes); also use fd_getfile() et al

this avoids annoying EOPNOTSUPP error messages from ls -F and such


# 1.99 17-Apr-2003 jdolecek

procfs_lookup(): use fd_getfile() et al in Pfd case


# 1.98 17-Apr-2003 jdolecek

use fd_getfile() in procfs_getfp(), and FILE_USE()/FILE_UNUSE() the
returned file descriptor pointer appropriately


# 1.97 17-Apr-2003 jdolecek

make some local arrays/variables static + const


# 1.96 10-Apr-2003 jdolecek

use former genfs_eopnotsupp_rele() as genfs_eopnotsupp(), so that vnodes
are vput()/vrele()d as necessary - some filesystems did use the wrong
one for some ops, and it's just safer to not take the chance

based on suggestion by Bill Studenmund


# 1.95 05-Apr-2003 dsl

Remove pointless check against PID_MAX. Let pfind() do the validation.
(The new pid allocation code may decide to allocate pids above PID_MAX.)


# 1.94 25-Feb-2003 jrf

This addresses PR kerm/19989. Thanks to hamajima@nagoya.ydc.co.jp for submitting this patch which enables /proc/uptime for linux emul. Patch reviewed by atatat@netbsd.org and tron@netbsd.org, approved by tron@netbsd.org.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 1.93 04-Jan-2003 martin

Cast off_t expression to long long to match format even on 64 bit
plattforms.

Shouldn't we introduce a PRIoff_t macro to create such format strings?


# 1.92 03-Jan-2003 christos

add LK_CANRECURSE in the locking of /dev/<pid>/fd/<n> and remove the curproc
kludge. Thanks to fvdl.


# 1.91 03-Jan-2003 christos

Implement /proc/<pid>/fd/<n>. This is work in progress. Questionable things:
- Is it ok to convert DTYPE_PIPE to VFIFO and DTYPE_SOCKET to VSOCK?
- XXX: Avoid locking issue in ls -Rl /proc by avoiding curproc
- Does I/O to pipes work?
- XXX: Are there security implications?


Revision tags: fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge gehenna-devsw-base kqueue-base
# 1.90 03-Aug-2002 simonb

Just use the "time" variable in the *_getattr functions instead of a call
to (the potentially expensive) microtime().


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.89 09-May-2002 thorpej

branches: 1.89.2;
Move code shared by procfs and the kernel proper out of procfs and
into the kernel proper (renaming functions from procfs_* to process_*).


Revision tags: eeh-devprop-base newlock-base ifpoll-base
# 1.88 12-Jan-2002 christos

Don't hide the real return code with EPERM.


# 1.87 06-Dec-2001 chs

add a VOP_PUTPAGES method for all the filesystems that don't have pages,
just unlock the interlock.


# 1.86 05-Dec-2001 thorpej

* Allow machine-dependent code to specify hooks for ptrace(2)
(__HAVE_PTRACE_MACHDEP) and procfs (__HAVE_PROCFS_MACHDEP).
These changes will allow platforms like x86 (XMM) and PowerPC
(AltiVec) to export extended register sets in a sane manner.

* Use __HAVE_PTRACE_MACHDEP to export x86 XMM registers (standard
FP + SSE/SSE2) using PT_{GET,SET}XMMREGS (in the machdep
ptrace request space).
* Use __HAVE_PROCFS_MACHDEP to export x86 XMM registers via
/proc/N/xmmregs in procfs.


Revision tags: thorpej-mips-cache-base
# 1.85 10-Nov-2001 lukem

add RCSIDs


# 1.84 06-Nov-2001 simonb

Remove some variables that are set but never used.


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base
# 1.83 31-Aug-2001 chs

branches: 1.83.2; 1.83.4;
map files are zero-length.


# 1.82 03-Jun-2001 chs

branches: 1.82.2;
procfs_bmap() should never be called, make it a "bad op".
let procfs_mmap() use the default error method.


Revision tags: thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 1.81 14-Apr-2001 kleink

In procfs_readdir(), give /proc/# directories DT_DIR (rather than DT_REG).


# 1.80 30-Mar-2001 fvdl

Bump va_blocksize for the map files some more, so that programs with
quite a few mappings have a chance of being handled correctly if
st_blksize is looked at.


# 1.79 29-Mar-2001 fvdl

For -o linux mounts, add some code to emulate /proc/#/maps.
Needs NAMECACHE_ENTER_REVERSE to include filenames.


# 1.78 21-Feb-2001 jdolecek

branches: 1.78.2;
make some more constant arrays 'const'


# 1.77 22-Jan-2001 jdolecek

make filesystem vnodeop, specop, fifoop and vnodeopv_* arrays const


# 1.76 17-Jan-2001 fvdl

Add a few linux-style files, only enabled when -o linux is specified
for the mount. Currently these are /proc/cpuinfo and /proc/meminfo.
The former only does something on i386 right now.


# 1.75 24-Nov-2000 chs

remove dead code and other misc cleanup.


# 1.74 09-Aug-2000 tv

Only show the "exe" entry to Linux processes, suggested by christos.
Since there are actually three struct emul's for linux, use the e_name
field to determine eligibility with strcmp().


# 1.73 09-Aug-2000 tv

Some versions of Linux libc look for /proc/.../exe instead of /proc/../file.
Add an entry for "exe" that is the same as "file", provided only if
COMPAT_LINUX is set.


# 1.72 03-Aug-2000 thorpej

MALLOC()/FREE() are not to be used for variable sized allocations.


# 1.71 28-Jun-2000 mrg

<vm/vm.h> -> <uvm/uvm_extern.h>


Revision tags: netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 1.70 30-Mar-2000 simonb

branches: 1.70.4;
Delete duplicate declaration of atopid().


Revision tags: chs-ubc2-newbase wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base fvdl-softdep-base
# 1.69 02-Sep-1999 thorpej

branches: 1.69.2; 1.69.8;
Make /proc/self a symlink to /proc/curproc. I've observed Linux programs
that expect /proc/self/cmdline to exist.


# 1.68 25-Aug-1999 sommerfeld

Change variable used for directory offset from "int" to "off_t".
Overkill, but avoids a host of truncation problems.


# 1.67 24-Aug-1999 sommerfeld

Fix PR8270:

Problem turned out to be due to improper handling of reads beyond EOF:
they should just return without error with the uio unchanged, and the
caller will recognize this as a zero-byte return (EOF).

The previous fix to protect directory reads against bogus uio_offset
values returned EINVAL, which broke mount -o union, which only
union'ed in the lower directory if the upper directory cleanly
returned EOF.

While we're here, protect kernfs as well.


# 1.66 14-Aug-1999 christos

protect against large uio_offset


# 1.65 03-Aug-1999 wrstuden

Add support for fcntl(2) to generate VOP_FCNTL calls. Any fcntl
call with F_FSCTL set and F_SETFL calls generate calls to a new
fileop fo_fcntl. Add genfs_fcntl() and soo_fcntl() which return 0
for F_SETFL and EOPNOTSUPP otherwise. Have all leaf filesystems
use genfs_fcntl().

Reviewed by: thorpej
Tested by: wrstuden


Revision tags: chs-ubc2-base
# 1.64 25-Jul-1999 thorpej

Add calls to lock the proclist as appropriate.


# 1.63 14-Jul-1999 thorpej

Fix a paste-o in procfs_lookup() introduced with the vnode locking changes.
Fixes PR #7961, Mario Kemper <magick@bundy.lip.owl.de>.


# 1.62 08-Jul-1999 wrstuden

Bump osrelease to 1.4E. Add layerfs files, remove null_subr.c.

Update coda to new struct lock in struct vnode.

make fdescfs, kernfs, portalfs, and procfs actually lock their vnodes.
It's not that hard.

Make unionfs set v_vnlock = NULL so any overlayed fs will call its
VOP_LOCK.


Revision tags: kame_141_19991130 netbsd-1-4-PATCH001 kame_14_19990705 kame_14_19990628 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.61 12-Mar-1999 christos

branches: 1.61.2; 1.61.4;
PR/7143: Jaromir Docelek: Add procfs/cmdline from Linux emulation


# 1.60 25-Jan-1999 msaitoh

Add /proc/#/map. From FreeBSD.


Revision tags: kenh-if-detach-base chs-ubc-base
# 1.59 08-Sep-1998 thorpej

- Use proclists[], rather than checking allproc and zombproc explicitly.
- Add some comments about locking.


# 1.58 13-Aug-1998 kleink

Per POSIX, fail with EINVAL if advisory locking is attempted on a file type
that doesn't support it, rather than using a homegrown EBADF or EOPNOTSUPP.


# 1.57 10-Aug-1998 matthias

create miscfs/genfs/genfs_vnops.c:genfs_enoioctl and make all the other
filesystems use it instead of a private version.


# 1.56 09-Aug-1998 perry

bzero->memset, bcopy->memcpy, bcmp->memcmp


# 1.55 03-Aug-1998 kleink

Recognize _PC_SYNC_IO.


Revision tags: eeh-paddr_t-base
# 1.54 21-Apr-1998 fvdl

procfs_readdir: in case of error, check if cookies actually have
been allocated before freeing them. From Wolfgang Solfrank.


# 1.53 01-Mar-1998 fvdl

Merge with Lite2 + local changes


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base marc-pcmcia-base
# 1.52 10-Oct-1997 fvdl

Bump last argument to VOP_READDIR to off_t (from u_long).


Revision tags: thorpej-signal-base
# 1.51 27-Aug-1997 thorpej

Fix a reversed argument which caused procfs_checkioperm() to always return
"OK". Add a few comments to avoid further confusion.


# 1.50 12-Aug-1997 thorpej

Fix the procfs hole described on current-users, similar to a fix for
FreeBSD by Sean Eric Fagan, but a bit different. This makes the checks
in the same places as sef's FreeBSD patch, but does not hardcode the
"kmem" group into the kernel, and also does a check identical to the
(3) and (4) checks in the NetBSD ptrace(2):

(1) it's not owned by you, or is set-id on exec (unless
you're root), or

(2) it's init, which controls the security level of the
entire system, and the system was not compiled with
permanently insecure mode turned on.


Revision tags: marc-pcmcia-bp
# 1.49 08-May-1997 mycroft

branches: 1.49.4;
Pass the vnode type to vaccess(), and use it when checking VEXEC. Make sure
that the mode bits passed to vaccess() and returned by foo_getattr() contain
only permission bits.


# 1.48 05-May-1997 mycroft

Need stat.h.


# 1.47 05-May-1997 mycroft

Eliminate bogus uses of V{READ,WRITE,EXEC}. Use S_I[RWX]{USR,GRP,OTH} where
appropriate.


# 1.46 28-Apr-1997 mycroft

Minor code cleanup.


Revision tags: is-newarp-before-merge is-newarp-base
# 1.45 25-Oct-1996 cgd

define path name string variables that we should not (and, thankfully, do
not) modify as 'const char *' rather 'char *'.


# 1.44 13-Oct-1996 christos

backout previous kprintf changes


# 1.43 10-Oct-1996 christos

printf -> kprintf, sprintf -> ksprintf


# 1.42 07-Sep-1996 mycroft

Implement poll(2).


# 1.41 01-Sep-1996 mycroft

Add a set of generic file system operations that most file systems use.
Also, fix some time stamp bogosities.


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 1.40 16-Mar-1996 christos

Fix printf format follies.


# 1.39 13-Feb-1996 mycroft

GC *_nullop(). Minor nits.


# 1.38 12-Feb-1996 christos

close PR/2063: procfs_rw prototyped twice with different prototypes


# 1.37 09-Feb-1996 christos

miscfs prototype changes


# 1.36 09-Feb-1996 mycroft

Fix vop_link, vop_symlink, and vop_remove semantics in several ways:
* Change the argument names to vop_link so they actually make sense.
* Implement vop_link and vop_symlink for all file systems, so they do proper
cleanup.
* Require the file system to decide whether or not linking and unlinking of
directories is allowed, and disable it for all current file systems.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.35 09-Oct-1995 mycroft

Use the index number as the cookie, rather than multiplying by UIO_MX.


# 1.34 09-Oct-1995 mycroft

Add support for cookies, mostly from Greg Hudson.


# 1.33 15-Apr-1995 cgd

fix timeval vs. timespec warnings


# 1.32 03-Feb-1995 mycroft

Return EROFS rather than ENOENT in many cases. Also some cosmetic cleanup.


# 1.31 27-Dec-1994 mycroft

Format police.


# 1.30 24-Dec-1994 ws

Implement and use a common access checking routine


# 1.29 14-Dec-1994 mycroft

Remove a_fp.


# 1.28 14-Nov-1994 christos

fixed struct comment


# 1.27 30-Oct-1994 cgd

be more careful with types, also pull in headers where necessary.


# 1.26 20-Oct-1994 cgd

update for new syscall args description mechanism


# 1.25 30-Aug-1994 mycroft

Convert process, file, and namei lists and hash tables to use queue.h.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.24 29-Jun-1994 cgd

New RCS ID's, take two. they're more aesthecially pleasant, and use 'NetBSD'


# 1.23 16-Jun-1994 mycroft

Remove an unneeded test.


# 1.22 15-Jun-1994 mycroft

Minor update from JSP after merging my changes.


# 1.21 08-Jun-1994 mycroft

Update to 4.4-Lite fs code, with local changes.


# 1.20 05-May-1994 cgd

lots of changes: prototype migration, move lots of variables, definitions,
and structure elements around. kill some unnecessary type and macro
definitions. standardize clock handling. More changes than you'd want.


# 1.19 15-Apr-1994 cgd

forgot these...


# 1.18 12-Apr-1994 cgd

be a bit smarter about determining if files shouldn't be seen by the user.
Also, DON'T allow a lookup to succeed on a file that's not visible!


# 1.17 15-Feb-1994 mycroft

Undo last change; executables is `file', not `a.out'.


# 1.16 14-Feb-1994 ws

Rename file -> a.out


# 1.15 14-Feb-1994 ws

Don't try to show a file for a process if there is none


# 1.14 28-Jan-1994 cgd

make a fpregs file.


# 1.13 20-Jan-1994 ws

Make procfs really work for debugging.
Implement not & notepg files in procfs.


# 1.12 09-Jan-1994 ws

Bug fixes and enhancements:
Make NFS serving work (BUT DON'T USE "attach" TO /proc/*/ctl FOR NOW!!!)
Make `curproc' a symbolic link
Add `.' and `..' entries to the directories.
Return better guesses on the size of the files.


# 1.11 05-Jan-1994 cgd

return size of 'reg' from getattr()


# 1.10 05-Jan-1994 cgd

make it compile (cleanly) for us


# 1.9 05-Jan-1994 cgd

add new procfs code, from Jan-Simon Pendry, jsp@sequent.com.
This is pretty-much "virgin", so that diffs can be done later.


# 1.8 18-Dec-1993 mycroft

Canonicalize all #includes.


Revision tags: magnum-base
# 1.7 16-Sep-1993 cgd

kill volatile warning.


# 1.6 07-Sep-1993 ws

branches: 1.6.2;
Changes to VFS readdir semantics
NFS changes for better cookie support
ISOFS changes for better Rockridge support and support for generation numbers


# 1.5 26-Aug-1993 pk

Implement setattr: mode for process entries; mode + uid/gid for the
PROCFS root directory.
Fixed omission in pfs_root() which came to light as a result of the above:
hold on to vnode for root dir.


# 1.4 25-Aug-1993 pk

Fixed improperly initialized nfsnode in pfs_lookup()


# 1.3 24-Aug-1993 pk

copyright update.


# 1.2 24-Aug-1993 pk

Rcs Id added.


# 1.1 24-Aug-1993 pk

branches: 1.1.1;
Initial version of a proc filesystem.


# 1.208 01-Feb-2020 riastradh

Load struct filedesc::fd_dt with atomic_load_consume.

Exceptions: when fd_refcnt <= 1, or when holding fd_lock.

While here:

- Restore KASSERT(mutex_owned(&fdp->fd_lock)) in fd_unused.
=> This is used only in fd_close and fd_abort, where it holds.
- Move bounds check assertion in fd_putfile to where it matters.
- Store fd_dt with atomic_store_release.
- Move load of fd_dt under lock in knote_fdclose.
- Omit membar_consumer in fdesc_readdir.
=> atomic_load_consume serves the same purpose now.
=> Was needed only on alpha anyway.


Revision tags: ad-namecache-base2 ad-namecache-base1 ad-namecache-base phil-wifi-20191119
# 1.207 29-Aug-2019 hannken

branches: 1.207.2;
Add missing operation VOP_GETPAGES() returning EFAULT.

Without this operation posix_fadvise(..., POSIX_FADV_WILLNEED)
would leave the v_interlock held.

Observed by maxv@


Revision tags: netbsd-9-base phil-wifi-20190609 isaki-audio2-base
# 1.206 30-Mar-2019 christos

branches: 1.206.4;
add a node for the process resource limits.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020
# 1.205 14-Oct-2018 jdolecek

remove M_CANFAIL flag for malloc(9) - it was completely ignored, so had
actually no effect


Revision tags: pgoyette-compat-0930 pgoyette-compat-0906
# 1.204 03-Sep-2018 riastradh

Rename min/max -> uimin/uimax for better honesty.

These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER! Some subsystems have

#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)


Revision tags: pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415
# 1.203 07-Apr-2018 hannken

branches: 1.203.2;
Lock the target cwdi and take an additional reference to the
vnode we are interested in to prevent it from disappearing
before getcwd_common().

Should fix PR kern/53096 (netbsd-8 crash on heavy disk I/O)


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.202 31-Dec-2017 christos

branches: 1.202.2;
Add an environ node


Revision tags: tls-maxphys-base-20171202
# 1.201 01-Dec-2017 christos

Allow procfs_kqfilter, since we allow poll. "go" does it.


# 1.200 08-Nov-2017 christos

fix locking, remove error(1) comments.


# 1.199 08-Nov-2017 christos

use p->p_path, remove unused code.


# 1.198 28-Aug-2017 kamil

Remove the filesystem tracing feature

This is a legacy interface from 4.4BSD, and it was
introduced to overcome shortcomings of ptrace(2) at that time, which are
no longer relevant (performance). Today /proc/#/ctl offers a narrow
subset of ptrace(2) commands and is not applicable for modern
applications use beyond simplistic tracing scenarios.

This removal will simplify kernel internals. Users will still be able to
use all the other /proc files.

This change won't affect other procfs files neither Linux compat
features within mount_procfs(8). /proc/#/ctl isn't available on Linux.

Remove:
- /proc/#/ctl from mount_procfs(8)
- P_FSTRACE note from the documentation of ps(1)
- /proc/#/ctl and filesystem tracing documentation from mount_procfs(8)
- KAUTH_REQ_PROCESS_PROCFS_CTL documentation from kauth(9)
- source code file miscfs/procfs/procfs_ctl.c
- PFSctl and procfs_doctl() from sys/miscfs/procfs/procfs.h
- KAUTH_REQ_PROCESS_PROCFS_CTL from sys/sys/kauth.h
- PSL_FSTRACE (0x00010000) from sys/sys/proc.h
- P_FSTRACE (0x00010000) from sys/sys/sysctl.h

Reduce code complexity after removal of this functionality.

Update TODO.ptrace accordingly: remove two entries about /proc tracing.

Do not keep legacy notes as comments in the headers about removed
PSL_FSTRACE / P_FSTRACE, as this interface had little number of users
(close or equal to zero).

Proposed on tech-kern@.

All filesystem tracing utility users are encouraged to switch to ptrace(2).

Sponsored by <The NetBSD Foundation>


Revision tags: matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base
# 1.197 26-May-2017 riastradh

branches: 1.197.2;
Make VOP_RECLAIM do the last unlock of the vnode.

VOP_RECLAIM naturally has exclusive access to the vnode, so having it
locked on entry is not strictly necessary -- but it means if there
are any final operations that must be done on the vnode, such as
ffs_update, requiring exclusive access to it, we can now kassert that
the vnode is locked in those operations.

We can't just have the caller release the last lock because some file
systems don't use genfs_lock, and require the vnode to remain valid
for VOP_UNLOCK to work, notably unionfs.


Revision tags: prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.196 11-Apr-2017 riastradh

Make VOP_INACTIVE preserve vnode lock on return.

Discussed on tech-kern:
https://mail-index.netbsd.org/tech-kern/2017/04/01/msg021751.html

Ride 7.99.68, a bumpy bus of incremental vfs improvements!


Revision tags: jdolecek-ncq-base
# 1.195 30-Mar-2017 christos

add an auxv node.


Revision tags: pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004 localcount-20160914
# 1.194 20-Aug-2016 hannken

branches: 1.194.2;
Remove now obsolete operation vcache_remove().

Welcome to 7.99.36


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 nick-nhusb-base-20150921 nick-nhusb-base-20150606
# 1.193 20-Apr-2015 riastradh

branches: 1.193.2;
Make VOP_LINK return directory still locked and referenced.

Ride 7.99.10 bump.


Revision tags: nick-nhusb-base-20150406 nick-nhusb-base
# 1.192 05-Sep-2014 matt

branches: 1.192.2;
Try not to use f_data, use f_{vnode,socket,pipe,mqueue,kqueue,ksem} to get
a correctly typed pointer.


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.191 27-Jul-2014 hannken

branches: 1.191.2; 1.191.4; 1.191.8;
Change procfs from hashlist to vcache.
- Key is (type, pid, fd)
- Remove argument "p" from procfs_allocvp(). It is only used
when "type == PFSfd". Lookup the proc with proc_find() when
procfs_loadvnode() needs it.
- Use a vfs_vnode_iterator for procfs_revoke_vnodes().


# 1.190 25-Jul-2014 dholland

Add VOP_FALLOCATE and VOP_FDISCARD to every vnode ops table I can
find.

The filesystem ones all call genfs_eopnotsupp - right now I am only
implementing the plumbing and we can implement fallocate and/or
fdiscard for files later.

The device ones call spec_fallocate (which is also genfs_eopnotsupp)
and spec_fdiscard, which dispatches to the device-level op.

The fifo ones all call vn_fifo_bypass, which also ends up being
EOPNOTSUPP.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base
# 1.189 07-Feb-2014 hannken

branches: 1.189.2;
Change vnode operation lookup to return the resulting vnode *vpp unlocked.
Change cache_lookup() to return an unlocked vnode.

Discussed on tech-kern@

Welcome to 6.99.31


# 1.188 23-Jan-2014 hannken

Change vnode operations create, mknod, mkdir and symlink to return
the resulting vnode *vpp unlocked.

Discussed on tech-kern@

Welcome to 6.99.30


# 1.187 17-Jan-2014 hannken

Change vnode operations create, mknod, mkdir and symlink to keep the
directory node dvp locked on return.

Discussed on tech-kern@

Welcome to 6.99.29


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base
# 1.186 18-Mar-2013 plunky

branches: 1.186.6;
C99 section 6.7.2.3 (Tags) Note 3 states that:

A type specifier of the form

enum identifier

without an enumerator list shall only appear after the type it
specifies is complete.

which means that we cannot pass an "enum vtype" argument to
kauth_access_action() without fully specifying the type first.
Unfortunately there is a complicated include file loop which
makes that difficult, so convert this minimal function into a
macro (and capitalize it).

(ok elad@)


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 1.185 25-Nov-2012 christos

do something reasonable with kernel semaphores.


Revision tags: yamt-pagecache-base6 jmcneill-usbmp-base10
# 1.184 28-May-2012 christos

branches: 1.184.2;
add a task process subdirectory for emul linux


Revision tags: yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 1.183 13-Mar-2012 elad

Replace the remaining KAUTH_GENERIC_ISSUSER authorization calls with
something meaningful. All relevant documentation has been updated or
written.

Most of these changes were brought up in the following messages:

http://mail-index.netbsd.org/tech-kern/2012/01/18/msg012490.html
http://mail-index.netbsd.org/tech-kern/2012/01/19/msg012502.html
http://mail-index.netbsd.org/tech-kern/2012/02/17/msg012728.html

Thanks to christos, manu, njoly, and jmmv for input.

Huge thanks to pgoyette for spinning these changes through some build
cycles and ATF.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.182 04-Sep-2011 jmcneill

branches: 1.182.2; 1.182.6;
PR# kern/45021: Please support /emul/linux/proc/version

Add /proc/version for procfs with -o linux. The version reported depends
on the emulation type of the calling process:

$ cat /proc/version
NetBSD version 5.99.55 (netbsd@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) NetBSD 5.99.55 (GENERIC) #39: Sun Sep 4 09:10:05 EDT 2011

$ /emul/linux/bin/cat /proc/version
Linux version 2.6.18 (linux@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) #0 Wed Mar 3 03:03:03 PST 2010

$ /emul/linux32/bin/cat /proc/version
Linux version 2.6.18 (linux32@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) #0 Wed Mar 3 03:03:03 PST 2010


# 1.181 23-Jun-2011 christos

From Aleksey Cheusov: Don't make it easy for compromised systems to bypass
ASLR protections by providing the mapping addresses of programs to everyone.


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base matt-mips64-premerge-20101231 uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10 rmind-uvmplock-base
# 1.180 01-Jul-2010 rmind

Remove pfind() and pgfind(), fix locking in various broken uses of these.
Rename real routines to proc_find() and pgrp_find(), remove PFIND_* flags
and have consistent behaviour. Provide proc_find_raw() for special cases.
Fix memory leak in sysctl_proc_corename().

COMPAT_LINUX: rework ptrace() locking, minimise differences between
different versions per-arch.

Note: while this change adds some formal cosmetics for COMPAT_DARWIN and
COMPAT_IRIX - locking there is utterly broken (for ages).

Fixes PR/43176.


# 1.179 24-Jun-2010 hannken

Clean up vnode lock operations pass 2:

VOP_UNLOCK(vp, flags) -> VOP_UNLOCK(vp): Remove the unneeded flags argument.

Welcome to 5.99.32.

Discussed on tech-kern.


# 1.178 08-Jun-2010 hannken

Procfs_lookup() does not lookup directory descriptors in the fd/
subdirectory. There is no need for recursive vnode locking here.

Ok: Christos Zoulas <christos@netbsd.org>


Revision tags: uebayasi-xip-base1 yamt-nfs-mp-base9 uebayasi-xip-base
# 1.177 08-Jan-2010 pooka

branches: 1.177.2; 1.177.4;
The VATTR_NULL/VREF/VHOLD/HOLDRELE() macros lost their will to live
years ago when the kernel was modified to not alter ABI based on
DIAGNOSTIC, and now just call the respective function interfaces
(in lowercase). Plenty of mix'n match upper/lowercase has creeped
into the tree since then. Nuke the macros and convert all callsites
to lowercase.

no functional change


Revision tags: matt-premerge-20091211 yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 jym-xensuspend-nbase
# 1.176 03-Jul-2009 elad

Where possible, extract the file-system's access() routine to two internal
functions: the first checking if the operation is possible (regardless of
permissions), the second checking file-system permissions, ACLs, etc.

Mailing list reference:

http://mail-index.netbsd.org/tech-kern/2009/06/21/msg005311.html


# 1.175 23-Jun-2009 elad

Move the implementation of vaccess() to genfs_can_access(), in line with
the other routines of the same spirit.

Adjust file-system code to use it.

Keep vaccess() for KPI compatibility and to keep element of least
surprise. A "diagnostic" message warning that vaccess() is deprecated will
be printed when it's used (obviously, only in DIAGNOSTIC kernels).

No objections on tech-kern@:

http://mail-index.netbsd.org/tech-kern/2009/06/21/msg005310.html


Revision tags: yamt-nfs-mp-base5
# 1.174 24-May-2009 ad

More changes to improve kern_descrip.c.

- Avoid atomics in more places.
- Remove the per-descriptor mutex, and just use filedesc_t::fd_lock.
It was only being used to synchronize close, and in any case we needed
to take fd_lock to free the descriptor slot.
- Optimize certain paths for the <NDFDFILE case.
- Sprinkle more comments and assertions.
- Cache more stuff in filedesc_t.
- Fix numerous minor bugs spotted along the way.
- Restructure how the open files array is maintained, for clarity and so
that we can eliminate the membar_consumer() call in fd_getfile(). This is
mostly syntactic sugar; the main functional change is that fd_nfiles now
lives alongside the open file array.

Some measurements with libmicro:

- simple file syscalls are like close() are between 1 to 10% faster.
- some nice improvements, e.g. poll(1000) which is ~50% faster.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 nick-hppapmap-base2 jym-xensuspend-base nick-hppapmap-base mjf-devfs2-base
# 1.173 17-Dec-2008 cegger

branches: 1.173.2;
kill MALLOC and FREE macros.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 haad-dm-base2 haad-nbase2 ad-audiomp2-base netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 haad-dm-base
# 1.172 05-Sep-2008 skrll

branches: 1.172.2;
PR/39324 kernel diagnostic assertion "l->l_stat != LSZOMB" failed.

Ignore procs with zero or all LSZOMB LWPs. Get a non-LSZOMB LWP to perform
operations against as part of the deal.

procfs really needs to be updated to support multi-threading fully.
Hi Antti!


# 1.171 05-Sep-2008 skrll

ANSIfy


Revision tags: simonb-wapbl-nbase simonb-wapbl-base
# 1.170 02-Jul-2008 rmind

branches: 1.170.2;
Remove proc_representative_lwp(), use a simple LIST_FIRST() instead.
OK by <ad>.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base
# 1.169 28-Apr-2008 martin

branches: 1.169.2; 1.169.4;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-nfs-mp-base
# 1.168 24-Apr-2008 ad

branches: 1.168.2;
Merge proc::p_mutex and proc::p_smutex into a single adaptive mutex, since
we no longer need to guard against access from hardware interrupt handlers.

Additionally, if cloning a process with CLONE_SIGHAND, arrange to have the
child process share the parent's lock so that signal state may be kept in
sync. Partially addresses PR kern/37437.


# 1.167 24-Apr-2008 ad

Network protocol interrupts can now block on locks, so merge the globals
proclist_mutex and proclist_lock into a single adaptive mutex (proc_lock).
Implications:

- Inspecting process state requires thread context, so signals can no longer
be sent from a hardware interrupt handler. Signal activity must be
deferred to a soft interrupt or kthread.

- As the proc state locking is simplified, it's now safe to take exit()
and wait() out from under kernel_lock.

- The system spends less time at IPL_SCHED, and there is less lock activity.


Revision tags: yamt-pf42-baseX yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14
# 1.166 21-Mar-2008 ad

branches: 1.166.2;
Catch up with descriptor handling changes. See kern_descrip.c revision
1.173 for details.


Revision tags: keiichi-mipv6-nbase nick-net80211-sync-base keiichi-mipv6-base bouyer-xeni386-nbase matt-armv6-nbase mjf-devfs-base hpcarm-cleanup-base
# 1.165 23-Jan-2008 elad

branches: 1.165.6;
Tons of process scope changes.

- Add a KAUTH_PROCESS_SCHEDULER action, to handle scheduler related
requests, and add specific requests for set/get scheduler policy and
set/get scheduler parameters.

- Add a KAUTH_PROCESS_KEVENT_FILTER action, to handle kevent(2) related
requests.

- Add a KAUTH_DEVICE_TTY_STI action to handle requests to TIOCSTI.

- Add requests for the KAUTH_PROCESS_CANSEE action, indicating what
process information is being looked at (entry itself, args, env,
open files).

- Add requests for the KAUTH_PROCESS_RLIMIT action indicating set/get.

- Add requests for the KAUTH_PROCESS_CORENAME action indicating set/get.

- Make bsd44 secmodel code handle the newly added rqeuests appropriately.

All of the above make it possible to issue finer-grained kauth(9) calls in
many places, removing some KAUTH_GENERIC_ISSUSER requests.

- Remove the "CAN" from KAUTH_PROCESS_CAN{KTRACE,PROCFS,PTRACE,SIGNAL}.

Discussed with christos@ and yamt@.


Revision tags: bouyer-xeni386-base matt-armv6-base
# 1.164 02-Jan-2008 ad

Merge vmlocking2 to head.


Revision tags: vmlocking2-base3 yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 vmlocking-nbase jmcneill-pm-base reinoud-bufcleanup-base
# 1.163 26-Nov-2007 pooka

branches: 1.163.2; 1.163.6;
Remove the "struct lwp *" argument from all VFS and VOP interfaces.
The general trend is to remove it from all kernel interfaces and
this is a start. In case the calling lwp is desired, curlwp should
be used.

quick consensus on tech-kern


Revision tags: bouyer-xenamd64-base2 bouyer-xenamd64-base
# 1.162 09-Nov-2007 christos

make the last argument of procfs_dir size_t


# 1.161 07-Nov-2007 ad

Merge from vmlocking:

- pool_cache changes.
- Debugger/procfs locking fixes.
- Other minor changes.


Revision tags: jmcneill-base yamt-x86pmap-base4 yamt-x86pmap-base3 vmlocking-base
# 1.160 10-Oct-2007 ad

branches: 1.160.2; 1.160.4;
Merge from vmlocking:

- Split vnode::v_flag into three fields, depending on field locking.
- simple_lock -> kmutex in a few places.
- Fix some simple locking problems.


# 1.159 08-Oct-2007 ad

Merge file descriptor locking, cwdi locking and cross-call changes
from the vmlocking branch.


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base2 yamt-x86pmap-base matt-mips64-base
# 1.158 22-Jul-2007 pooka

branches: 1.158.4; 1.158.6; 1.158.8; 1.158.10;
Don't allow getcwd() on procfs vnodes and provide "/" as the path
instead of the result from getcwd(). The works around locking
panics caused by namei calling VOP_READLINK while holding on to a
directory lock and getcwd() trying to acquire that lock. The real
fix would be to get rid of getcwd() calls within VOPs (not locking
safe), but that's not a viable option in the netbsd-4 timeframe.

Suggestion for workaround from David Holland.


Revision tags: nick-csl-alignment-base mjf-ufs-trans-base
# 1.157 24-May-2007 agc

branches: 1.157.2;
Extend the Linux emulation of /proc to include

/proc/stat
/proc/loadavg and
/proc/<pid>/statm.

These are only present when -o linux is specified as a mount option
to procfs.

Factor out some common code so that it can be used by a number of
functions.

XXX The values returned in the statm emulation need to be verified.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 1.156 04-Apr-2007 rmind

Unfortunately, missed procfs_proc_unlock() in previous.
Pointed out by pooka@


# 1.155 04-Apr-2007 rmind

procfs_readlink: Handle a possible fail of fd_getfile(), also, we
do not need to check for error again.
CID: 4436


# 1.154 09-Mar-2007 ad

branches: 1.154.2; 1.154.4;
- Make the proclist_lock a mutex. The write:read ratio is unfavourable,
and mutexes are cheaper use than RW locks.
- LOCK_ASSERT -> KASSERT in some places.
- Hold proclist_lock/kernel_lock longer in a couple of places.


# 1.153 04-Mar-2007 christos

Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.


# 1.152 03-Mar-2007 salo

Don't prepend rootvnode to the path in non-NULL case for exe links.
It breaks procfs in chroot.

from <christos>, tested by me.


Revision tags: ad-audiomp-base
# 1.151 19-Feb-2007 pooka

When checking for file validity under pid/, do proper proc->lwp
lookup (fsvo proper) instead of fiddling directly with the lwp
list.


# 1.150 18-Feb-2007 pooka

Don't check for validity of p in lookup for root nodes, since it
will always be NULL. Rather, just call pt_valid with NULL directly
and let it decide if we're a linux mount or not.


# 1.149 17-Feb-2007 pavel

Change the process/lwp flags seen by userland via sysctl back to the
P_*/L_* naming convention, and rename the in-kernel flags to avoid
conflict. (P_ -> PK_, L_ -> LW_ ). Add back the (now unused) LSDEAD
constant.

Restores source compatibility with pre-newlock2 tools like ps or top.

Reviewed by Andrew Doran.


# 1.148 16-Feb-2007 pooka

branches: 1.148.2;
In lookup, when checking for procfs process node validity, target the
process we're trying to get information about through procfs, not
the caller of lookup.

fixes 'ls -l /proc/*/file' panic, which would occur when trying to
lookup "file" for a kernel thread, which doesn't have p->p_textvp.


# 1.147 15-Feb-2007 ad

Need to acquire procp->p_mutex for procfs_dir().


# 1.146 11-Feb-2007 ad

Eliminate a couple of reference count and mutex leaks.


Revision tags: post-newlock2-merge
# 1.145 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 1.144 25-Dec-2006 elad

PR/35226: Johann Franz: Problems with permissions in
/usr/pkg/emul/linux/proc .

Okay mlelstv@


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3
# 1.143 09-Dec-2006 chs

a smorgasbord of improvements to vnode locking and path lookup:
- LOCKPARENT is no longer relevant for lookup(), relookup() or VOP_LOOKUP().
these now always return the parent vnode locked. namei() works as before.
lookup() and various other paths no longer acquire vnode locks in the
wrong order via vrele(). fixes PR 32535.
as a nice side effect, path lookup is also up to 25% faster.
- the above allows us to get rid of PDIRUNLOCK.
- also get rid of WANTPARENT (just use LOCKPARENT and unlock it).
- remove an assumption in layer_node_find() that all file systems implement
a recursive VOP_LOCK() (unionfs doesn't).
- require that all file systems supply vfs_vptofh and vfs_fhtovp routines.
fill in eopnotsupp() for file systems that don't support being exported
and remove the checks for NULL. (layerfs calls these without checking.)
- in union_lookup1(), don't change refcounts in the ISDOTDOT case, just
adjust which vnode is locked. fixes PR 33374.
- apply fixes for ufs_rename() from ufs_vnops.c rev. 1.61 to ext2fs_rename().


# 1.142 04-Dec-2006 christos

From Nicolas Joly: restore previous behavior in procfs_validfile_linux, since
readdir passes a NULL lwp.


# 1.141 03-Dec-2006 elad

Move kauth(9) call to where it belongs. Noticed by Nicolas Joly, thanks!


Revision tags: netbsd-4-base
# 1.140 28-Nov-2006 elad

branches: 1.140.2;
Move ktrace, ptrace, systrace, and procfs to use kauth(9).

First, remove process_checkioperm() calls from MD code. Similar checks
using kauth(9) routines (on the process scope, using appropriate action)
are done in the callers.

Add secmodel back-end to handle each subsystem.


# 1.139 25-Nov-2006 skrll

Expose the 'exe' symlink to the process realpath in NetBSD as well. An
example user is gdb.

OK'd by christos.


# 1.138 16-Nov-2006 christos

__unused removal on arguments; approved by core.


# 1.137 29-Oct-2006 christos

add an "emul" file node.


# 1.136 25-Oct-2006 christos

1. fix procfs_validfile{,_linux} to test for NULL pointers properly.
2. make "exe" entry be a symlink to the executable, instead of pointing
directly to the vnode of the executable.
3. factor out commonly used code.


Revision tags: yamt-splraiseipl-base2
# 1.135 12-Oct-2006 christos

- sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386


# 1.134 20-Sep-2006 manu

Emulate Linux's /proc/devices


Revision tags: abandoned-netbsd-4-base yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base rpaulo-netinet-merge-pcb-base
# 1.133 13-Jun-2006 yamt

branches: 1.133.6; 1.133.8;
use KAUTH_PROCESS_CANSEE rather than CURTAIN where appropriate.


# 1.132 13-Jun-2006 yamt

remove unnecessary arguments from kauth_authorize_process.
ie. make it similar to the one found in apple TN.


# 1.131 07-Jun-2006 kardel

merge FreeBSD timecounters from branch simonb-timecounters
- struct timeval time is gone
time.tv_sec -> time_second
- struct timeval mono_time is gone
mono_time.tv_sec -> time_uptime
- access to time via
{get,}{micro,nano,bin}time()
get* versions are fast but less precise
- support NTP nanokernel implementation (NTP API 4)
- further reading:
Timecounter Paper: http://phk.freebsd.dk/pubs/timecounter.pdf
NTP Nanokernel: http://www.eecis.udel.edu/~mills/ntp/html/kern.html


Revision tags: yamt-pdpolicy-base5 simonb-timecounters-base
# 1.130 14-May-2006 elad

branches: 1.130.2;
integrate kauth.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 elad-kernelauth-base yamt-pdpolicy-base yamt-uio_vmspace-base5
# 1.129 02-Feb-2006 christos

branches: 1.129.2; 1.129.4; 1.129.6; 1.129.8;
PR/32692: Matthew Mondor: linux compatibility in /proc/self should point
directly to the directory containing the pid instead of pointing to
/proc/curproc, because some programs rely on calling readlink on /proc/self
to get the pid.


# 1.128 11-Dec-2005 christos

branches: 1.128.2; 1.128.4;
merge ktrace-lwp.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base ktrace-lwp-base
# 1.127 02-Nov-2005 yamt

merge yamt-vop branch. remove following VOPs.

VOP_BLKATOFF
VOP_VALLOC
VOP_BALLOC
VOP_REALLOCBLKS
VOP_VFREE
VOP_TRUNCATE
VOP_UPDATE


Revision tags: yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 1.126 01-Oct-2005 atatat

branches: 1.126.2;
Add "cwd" and "root" symlinks to each process's directory. The cwd
link points to the process's current working directory, and the root
link points to the process's root directory. What else would you
expect?

For directories that are out of reach (caller is in a chroot, target
process is in a different chroot, etc), the links point to "/"
instead.


# 1.125 11-Sep-2005 elad

Implement curtain for procfs.


# 1.124 30-Aug-2005 xtraeme

Remove __P()


# 1.123 29-May-2005 christos

branches: 1.123.2;
- sprinkle const
- avoid shadowed variables.


Revision tags: kent-audio2-base
# 1.122 02-Apr-2005 christos

PR/29782: Martin Husemann: procfs can not unmount when some process has its
current directory in curproc. Fix from Pedro Martelletto:
We cannot call vgone() from procfs_inactive() if we are coming from
vclean(). that's what's probably causing the deadlock.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 yamt-km-base4 yamt-km-base3 netbsd-3-base
# 1.121 26-Feb-2005 perry

nuke trailing whitespace


Revision tags: yamt-km-base2 yamt-km-base kent-audio1-beforemerge kent-audio1-base
# 1.120 04-Oct-2004 yamt

branches: 1.120.4; 1.120.6;
procfs_readdir:
- return correct cookie when buffer size is small.
- simplify logic.


# 1.119 04-Oct-2004 yamt

procfs_readdir: remove a redundant assignment.


# 1.118 02-Oct-2004 yamt

procfs_getattr: correct size of /proc/self.


# 1.117 01-Oct-2004 yamt

procfs_readdir:
- fix a locking problem, using proclist_foreach_call. PR/27098.
- correct snprintf size argument.


# 1.116 01-Oct-2004 yamt

procfs_readdir: fix an offset handling bug after addition of /proc/self.


# 1.115 01-Oct-2004 yamt

procfs_readdir: use a list macro.


# 1.114 20-Sep-2004 jdolecek

add 'mounts' file for -o linux, which lists all currently mounted
filesystems; Linux glibc statvfs() uses this to get some of mount flags,
and this file is also useful as /emul/linux/etc/mtab (via symlink)


# 1.113 29-Apr-2004 jrf

Removed remaining caddr_t casts we do not need in miscfs. Recompiled
kernel and ran for a day or so. There are still some caddr_t types in
the arguments of some calls, I will do those separately (later) as
they touch a lot more of the system.
Approved by christos@NetBSD.org.


# 1.112 22-Apr-2004 itojun

sprintf -> snprintf


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.111 15-Feb-2004 jdolecek

unlock the descriptor table simple lock after fd_getfile() call in
procfs_readdir()
fixes procfs locking problems reported on current-users@, problem place
found by enami tsugutomo


# 1.110 30-Oct-2003 simonb

Remove some assigned-to but otherwise unused variables.


# 1.109 27-Sep-2003 darcy

Changes as discussed with itojun on tech-kern. I have modified the enums
to have KFS or PFS differentiators. Further I have wrapped the enum in
procfs in "#ifdef _KERNEL" as it is done in kernfs.

To see the discussion go to http://mail-index.NetBSD.org/tech-kern/2003/09/
and look for "Mismatched enums in include files" in the list.


# 1.108 07-Sep-2003 itojun

remove meaningless line (variable overwritten 2 lines below)


# 1.107 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.


# 1.106 29-Jun-2003 fvdl

branches: 1.106.2;
Back out the lwp/ktrace changes. They contained a lot of colateral damage,
and need to be examined and discussed more.


# 1.105 29-Jun-2003 thorpej

Undo part of the ktrace/lwp changes. In particular:
* Remove the "lwp *" argument that was added to vget(). Turns out
that nothing actually used it!
* Remove the "lwp *" arguments that were added to VFS_ROOT(), VFS_VGET(),
and VFS_FHTOVP(); all they did was pass it to vget() (which, as noted
above, didn't use it).
* Remove all of the "lwp *" arguments to internal functions that were added
just to appease the above.


# 1.104 28-Jun-2003 darrenr

Pass lwp pointers throughtout the kernel, as required, so that the lwpid can
be inserted into ktrace records. The general change has been to replace
"struct proc *" with "struct lwp *" in various function prototypes, pass
the lwp through and use l_proc to get the process pointer when needed.

Bump the kernel rev up to 1.6V


# 1.103 28-May-2003 christos

Add /proc/<pid>/stat for linux compat. j2sdk1.4.2 depends on it.


# 1.102 18-Apr-2003 christos

Make symlinks for directories that point to the actual directory.
Make symlinks to [kqueue] and [misc] for kqueue and misc fds.


# 1.101 17-Apr-2003 jdolecek

do not show nodes corresponding to directory descriptors for process
in fd/ subdirectory, nor allow lookup/open for the nodes
this fixes PR kern/21187 for good, and also avoids interesting directory
locking issues


# 1.100 17-Apr-2003 jdolecek

procfs_readdir(): in Pfd case, only show descriptors of types we want
how to represent (vnodes, fifo, pipes); also use fd_getfile() et al

this avoids annoying EOPNOTSUPP error messages from ls -F and such


# 1.99 17-Apr-2003 jdolecek

procfs_lookup(): use fd_getfile() et al in Pfd case


# 1.98 17-Apr-2003 jdolecek

use fd_getfile() in procfs_getfp(), and FILE_USE()/FILE_UNUSE() the
returned file descriptor pointer appropriately


# 1.97 17-Apr-2003 jdolecek

make some local arrays/variables static + const


# 1.96 10-Apr-2003 jdolecek

use former genfs_eopnotsupp_rele() as genfs_eopnotsupp(), so that vnodes
are vput()/vrele()d as necessary - some filesystems did use the wrong
one for some ops, and it's just safer to not take the chance

based on suggestion by Bill Studenmund


# 1.95 05-Apr-2003 dsl

Remove pointless check against PID_MAX. Let pfind() do the validation.
(The new pid allocation code may decide to allocate pids above PID_MAX.)


# 1.94 25-Feb-2003 jrf

This addresses PR kerm/19989. Thanks to hamajima@nagoya.ydc.co.jp for submitting this patch which enables /proc/uptime for linux emul. Patch reviewed by atatat@netbsd.org and tron@netbsd.org, approved by tron@netbsd.org.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 1.93 04-Jan-2003 martin

Cast off_t expression to long long to match format even on 64 bit
plattforms.

Shouldn't we introduce a PRIoff_t macro to create such format strings?


# 1.92 03-Jan-2003 christos

add LK_CANRECURSE in the locking of /dev/<pid>/fd/<n> and remove the curproc
kludge. Thanks to fvdl.


# 1.91 03-Jan-2003 christos

Implement /proc/<pid>/fd/<n>. This is work in progress. Questionable things:
- Is it ok to convert DTYPE_PIPE to VFIFO and DTYPE_SOCKET to VSOCK?
- XXX: Avoid locking issue in ls -Rl /proc by avoiding curproc
- Does I/O to pipes work?
- XXX: Are there security implications?


Revision tags: fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge gehenna-devsw-base kqueue-base
# 1.90 03-Aug-2002 simonb

Just use the "time" variable in the *_getattr functions instead of a call
to (the potentially expensive) microtime().


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.89 09-May-2002 thorpej

branches: 1.89.2;
Move code shared by procfs and the kernel proper out of procfs and
into the kernel proper (renaming functions from procfs_* to process_*).


Revision tags: eeh-devprop-base newlock-base ifpoll-base
# 1.88 12-Jan-2002 christos

Don't hide the real return code with EPERM.


# 1.87 06-Dec-2001 chs

add a VOP_PUTPAGES method for all the filesystems that don't have pages,
just unlock the interlock.


# 1.86 05-Dec-2001 thorpej

* Allow machine-dependent code to specify hooks for ptrace(2)
(__HAVE_PTRACE_MACHDEP) and procfs (__HAVE_PROCFS_MACHDEP).
These changes will allow platforms like x86 (XMM) and PowerPC
(AltiVec) to export extended register sets in a sane manner.

* Use __HAVE_PTRACE_MACHDEP to export x86 XMM registers (standard
FP + SSE/SSE2) using PT_{GET,SET}XMMREGS (in the machdep
ptrace request space).
* Use __HAVE_PROCFS_MACHDEP to export x86 XMM registers via
/proc/N/xmmregs in procfs.


Revision tags: thorpej-mips-cache-base
# 1.85 10-Nov-2001 lukem

add RCSIDs


# 1.84 06-Nov-2001 simonb

Remove some variables that are set but never used.


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base
# 1.83 31-Aug-2001 chs

branches: 1.83.2; 1.83.4;
map files are zero-length.


# 1.82 03-Jun-2001 chs

branches: 1.82.2;
procfs_bmap() should never be called, make it a "bad op".
let procfs_mmap() use the default error method.


Revision tags: thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 1.81 14-Apr-2001 kleink

In procfs_readdir(), give /proc/# directories DT_DIR (rather than DT_REG).


# 1.80 30-Mar-2001 fvdl

Bump va_blocksize for the map files some more, so that programs with
quite a few mappings have a chance of being handled correctly if
st_blksize is looked at.


# 1.79 29-Mar-2001 fvdl

For -o linux mounts, add some code to emulate /proc/#/maps.
Needs NAMECACHE_ENTER_REVERSE to include filenames.


# 1.78 21-Feb-2001 jdolecek

branches: 1.78.2;
make some more constant arrays 'const'


# 1.77 22-Jan-2001 jdolecek

make filesystem vnodeop, specop, fifoop and vnodeopv_* arrays const


# 1.76 17-Jan-2001 fvdl

Add a few linux-style files, only enabled when -o linux is specified
for the mount. Currently these are /proc/cpuinfo and /proc/meminfo.
The former only does something on i386 right now.


# 1.75 24-Nov-2000 chs

remove dead code and other misc cleanup.


# 1.74 09-Aug-2000 tv

Only show the "exe" entry to Linux processes, suggested by christos.
Since there are actually three struct emul's for linux, use the e_name
field to determine eligibility with strcmp().


# 1.73 09-Aug-2000 tv

Some versions of Linux libc look for /proc/.../exe instead of /proc/../file.
Add an entry for "exe" that is the same as "file", provided only if
COMPAT_LINUX is set.


# 1.72 03-Aug-2000 thorpej

MALLOC()/FREE() are not to be used for variable sized allocations.


# 1.71 28-Jun-2000 mrg

<vm/vm.h> -> <uvm/uvm_extern.h>


Revision tags: netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 1.70 30-Mar-2000 simonb

branches: 1.70.4;
Delete duplicate declaration of atopid().


Revision tags: chs-ubc2-newbase wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base fvdl-softdep-base
# 1.69 02-Sep-1999 thorpej

branches: 1.69.2; 1.69.8;
Make /proc/self a symlink to /proc/curproc. I've observed Linux programs
that expect /proc/self/cmdline to exist.


# 1.68 25-Aug-1999 sommerfeld

Change variable used for directory offset from "int" to "off_t".
Overkill, but avoids a host of truncation problems.


# 1.67 24-Aug-1999 sommerfeld

Fix PR8270:

Problem turned out to be due to improper handling of reads beyond EOF:
they should just return without error with the uio unchanged, and the
caller will recognize this as a zero-byte return (EOF).

The previous fix to protect directory reads against bogus uio_offset
values returned EINVAL, which broke mount -o union, which only
union'ed in the lower directory if the upper directory cleanly
returned EOF.

While we're here, protect kernfs as well.


# 1.66 14-Aug-1999 christos

protect against large uio_offset


# 1.65 03-Aug-1999 wrstuden

Add support for fcntl(2) to generate VOP_FCNTL calls. Any fcntl
call with F_FSCTL set and F_SETFL calls generate calls to a new
fileop fo_fcntl. Add genfs_fcntl() and soo_fcntl() which return 0
for F_SETFL and EOPNOTSUPP otherwise. Have all leaf filesystems
use genfs_fcntl().

Reviewed by: thorpej
Tested by: wrstuden


Revision tags: chs-ubc2-base
# 1.64 25-Jul-1999 thorpej

Add calls to lock the proclist as appropriate.


# 1.63 14-Jul-1999 thorpej

Fix a paste-o in procfs_lookup() introduced with the vnode locking changes.
Fixes PR #7961, Mario Kemper <magick@bundy.lip.owl.de>.


# 1.62 08-Jul-1999 wrstuden

Bump osrelease to 1.4E. Add layerfs files, remove null_subr.c.

Update coda to new struct lock in struct vnode.

make fdescfs, kernfs, portalfs, and procfs actually lock their vnodes.
It's not that hard.

Make unionfs set v_vnlock = NULL so any overlayed fs will call its
VOP_LOCK.


Revision tags: kame_141_19991130 netbsd-1-4-PATCH001 kame_14_19990705 kame_14_19990628 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.61 12-Mar-1999 christos

branches: 1.61.2; 1.61.4;
PR/7143: Jaromir Docelek: Add procfs/cmdline from Linux emulation


# 1.60 25-Jan-1999 msaitoh

Add /proc/#/map. From FreeBSD.


Revision tags: kenh-if-detach-base chs-ubc-base
# 1.59 08-Sep-1998 thorpej

- Use proclists[], rather than checking allproc and zombproc explicitly.
- Add some comments about locking.


# 1.58 13-Aug-1998 kleink

Per POSIX, fail with EINVAL if advisory locking is attempted on a file type
that doesn't support it, rather than using a homegrown EBADF or EOPNOTSUPP.


# 1.57 10-Aug-1998 matthias

create miscfs/genfs/genfs_vnops.c:genfs_enoioctl and make all the other
filesystems use it instead of a private version.


# 1.56 09-Aug-1998 perry

bzero->memset, bcopy->memcpy, bcmp->memcmp


# 1.55 03-Aug-1998 kleink

Recognize _PC_SYNC_IO.


Revision tags: eeh-paddr_t-base
# 1.54 21-Apr-1998 fvdl

procfs_readdir: in case of error, check if cookies actually have
been allocated before freeing them. From Wolfgang Solfrank.


# 1.53 01-Mar-1998 fvdl

Merge with Lite2 + local changes


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base marc-pcmcia-base
# 1.52 10-Oct-1997 fvdl

Bump last argument to VOP_READDIR to off_t (from u_long).


Revision tags: thorpej-signal-base
# 1.51 27-Aug-1997 thorpej

Fix a reversed argument which caused procfs_checkioperm() to always return
"OK". Add a few comments to avoid further confusion.


# 1.50 12-Aug-1997 thorpej

Fix the procfs hole described on current-users, similar to a fix for
FreeBSD by Sean Eric Fagan, but a bit different. This makes the checks
in the same places as sef's FreeBSD patch, but does not hardcode the
"kmem" group into the kernel, and also does a check identical to the
(3) and (4) checks in the NetBSD ptrace(2):

(1) it's not owned by you, or is set-id on exec (unless
you're root), or

(2) it's init, which controls the security level of the
entire system, and the system was not compiled with
permanently insecure mode turned on.


Revision tags: marc-pcmcia-bp
# 1.49 08-May-1997 mycroft

branches: 1.49.4;
Pass the vnode type to vaccess(), and use it when checking VEXEC. Make sure
that the mode bits passed to vaccess() and returned by foo_getattr() contain
only permission bits.


# 1.48 05-May-1997 mycroft

Need stat.h.


# 1.47 05-May-1997 mycroft

Eliminate bogus uses of V{READ,WRITE,EXEC}. Use S_I[RWX]{USR,GRP,OTH} where
appropriate.


# 1.46 28-Apr-1997 mycroft

Minor code cleanup.


Revision tags: is-newarp-before-merge is-newarp-base
# 1.45 25-Oct-1996 cgd

define path name string variables that we should not (and, thankfully, do
not) modify as 'const char *' rather 'char *'.


# 1.44 13-Oct-1996 christos

backout previous kprintf changes


# 1.43 10-Oct-1996 christos

printf -> kprintf, sprintf -> ksprintf


# 1.42 07-Sep-1996 mycroft

Implement poll(2).


# 1.41 01-Sep-1996 mycroft

Add a set of generic file system operations that most file systems use.
Also, fix some time stamp bogosities.


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 1.40 16-Mar-1996 christos

Fix printf format follies.


# 1.39 13-Feb-1996 mycroft

GC *_nullop(). Minor nits.


# 1.38 12-Feb-1996 christos

close PR/2063: procfs_rw prototyped twice with different prototypes


# 1.37 09-Feb-1996 christos

miscfs prototype changes


# 1.36 09-Feb-1996 mycroft

Fix vop_link, vop_symlink, and vop_remove semantics in several ways:
* Change the argument names to vop_link so they actually make sense.
* Implement vop_link and vop_symlink for all file systems, so they do proper
cleanup.
* Require the file system to decide whether or not linking and unlinking of
directories is allowed, and disable it for all current file systems.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.35 09-Oct-1995 mycroft

Use the index number as the cookie, rather than multiplying by UIO_MX.


# 1.34 09-Oct-1995 mycroft

Add support for cookies, mostly from Greg Hudson.


# 1.33 15-Apr-1995 cgd

fix timeval vs. timespec warnings


# 1.32 03-Feb-1995 mycroft

Return EROFS rather than ENOENT in many cases. Also some cosmetic cleanup.


# 1.31 27-Dec-1994 mycroft

Format police.


# 1.30 24-Dec-1994 ws

Implement and use a common access checking routine


# 1.29 14-Dec-1994 mycroft

Remove a_fp.


# 1.28 14-Nov-1994 christos

fixed struct comment


# 1.27 30-Oct-1994 cgd

be more careful with types, also pull in headers where necessary.


# 1.26 20-Oct-1994 cgd

update for new syscall args description mechanism


# 1.25 30-Aug-1994 mycroft

Convert process, file, and namei lists and hash tables to use queue.h.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.24 29-Jun-1994 cgd

New RCS ID's, take two. they're more aesthecially pleasant, and use 'NetBSD'


# 1.23 16-Jun-1994 mycroft

Remove an unneeded test.


# 1.22 15-Jun-1994 mycroft

Minor update from JSP after merging my changes.


# 1.21 08-Jun-1994 mycroft

Update to 4.4-Lite fs code, with local changes.


# 1.20 05-May-1994 cgd

lots of changes: prototype migration, move lots of variables, definitions,
and structure elements around. kill some unnecessary type and macro
definitions. standardize clock handling. More changes than you'd want.


# 1.19 15-Apr-1994 cgd

forgot these...


# 1.18 12-Apr-1994 cgd

be a bit smarter about determining if files shouldn't be seen by the user.
Also, DON'T allow a lookup to succeed on a file that's not visible!


# 1.17 15-Feb-1994 mycroft

Undo last change; executables is `file', not `a.out'.


# 1.16 14-Feb-1994 ws

Rename file -> a.out


# 1.15 14-Feb-1994 ws

Don't try to show a file for a process if there is none


# 1.14 28-Jan-1994 cgd

make a fpregs file.


# 1.13 20-Jan-1994 ws

Make procfs really work for debugging.
Implement not & notepg files in procfs.


# 1.12 09-Jan-1994 ws

Bug fixes and enhancements:
Make NFS serving work (BUT DON'T USE "attach" TO /proc/*/ctl FOR NOW!!!)
Make `curproc' a symbolic link
Add `.' and `..' entries to the directories.
Return better guesses on the size of the files.


# 1.11 05-Jan-1994 cgd

return size of 'reg' from getattr()


# 1.10 05-Jan-1994 cgd

make it compile (cleanly) for us


# 1.9 05-Jan-1994 cgd

add new procfs code, from Jan-Simon Pendry, jsp@sequent.com.
This is pretty-much "virgin", so that diffs can be done later.


# 1.8 18-Dec-1993 mycroft

Canonicalize all #includes.


Revision tags: magnum-base
# 1.7 16-Sep-1993 cgd

kill volatile warning.


# 1.6 07-Sep-1993 ws

branches: 1.6.2;
Changes to VFS readdir semantics
NFS changes for better cookie support
ISOFS changes for better Rockridge support and support for generation numbers


# 1.5 26-Aug-1993 pk

Implement setattr: mode for process entries; mode + uid/gid for the
PROCFS root directory.
Fixed omission in pfs_root() which came to light as a result of the above:
hold on to vnode for root dir.


# 1.4 25-Aug-1993 pk

Fixed improperly initialized nfsnode in pfs_lookup()


# 1.3 24-Aug-1993 pk

copyright update.


# 1.2 24-Aug-1993 pk

Rcs Id added.


# 1.1 24-Aug-1993 pk

branches: 1.1.1;
Initial version of a proc filesystem.


# 1.207 29-Aug-2019 hannken

Add missing operation VOP_GETPAGES() returning EFAULT.

Without this operation posix_fadvise(..., POSIX_FADV_WILLNEED)
would leave the v_interlock held.

Observed by maxv@


Revision tags: netbsd-9-base phil-wifi-20190609 isaki-audio2-base
# 1.206 30-Mar-2019 christos

add a node for the process resource limits.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020
# 1.205 14-Oct-2018 jdolecek

remove M_CANFAIL flag for malloc(9) - it was completely ignored, so had
actually no effect


Revision tags: pgoyette-compat-0930 pgoyette-compat-0906
# 1.204 03-Sep-2018 riastradh

Rename min/max -> uimin/uimax for better honesty.

These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER! Some subsystems have

#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)


Revision tags: pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415
# 1.203 07-Apr-2018 hannken

branches: 1.203.2;
Lock the target cwdi and take an additional reference to the
vnode we are interested in to prevent it from disappearing
before getcwd_common().

Should fix PR kern/53096 (netbsd-8 crash on heavy disk I/O)


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.202 31-Dec-2017 christos

branches: 1.202.2;
Add an environ node


Revision tags: tls-maxphys-base-20171202
# 1.201 01-Dec-2017 christos

Allow procfs_kqfilter, since we allow poll. "go" does it.


# 1.200 08-Nov-2017 christos

fix locking, remove error(1) comments.


# 1.199 08-Nov-2017 christos

use p->p_path, remove unused code.


# 1.198 28-Aug-2017 kamil

Remove the filesystem tracing feature

This is a legacy interface from 4.4BSD, and it was
introduced to overcome shortcomings of ptrace(2) at that time, which are
no longer relevant (performance). Today /proc/#/ctl offers a narrow
subset of ptrace(2) commands and is not applicable for modern
applications use beyond simplistic tracing scenarios.

This removal will simplify kernel internals. Users will still be able to
use all the other /proc files.

This change won't affect other procfs files neither Linux compat
features within mount_procfs(8). /proc/#/ctl isn't available on Linux.

Remove:
- /proc/#/ctl from mount_procfs(8)
- P_FSTRACE note from the documentation of ps(1)
- /proc/#/ctl and filesystem tracing documentation from mount_procfs(8)
- KAUTH_REQ_PROCESS_PROCFS_CTL documentation from kauth(9)
- source code file miscfs/procfs/procfs_ctl.c
- PFSctl and procfs_doctl() from sys/miscfs/procfs/procfs.h
- KAUTH_REQ_PROCESS_PROCFS_CTL from sys/sys/kauth.h
- PSL_FSTRACE (0x00010000) from sys/sys/proc.h
- P_FSTRACE (0x00010000) from sys/sys/sysctl.h

Reduce code complexity after removal of this functionality.

Update TODO.ptrace accordingly: remove two entries about /proc tracing.

Do not keep legacy notes as comments in the headers about removed
PSL_FSTRACE / P_FSTRACE, as this interface had little number of users
(close or equal to zero).

Proposed on tech-kern@.

All filesystem tracing utility users are encouraged to switch to ptrace(2).

Sponsored by <The NetBSD Foundation>


Revision tags: matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base
# 1.197 26-May-2017 riastradh

branches: 1.197.2;
Make VOP_RECLAIM do the last unlock of the vnode.

VOP_RECLAIM naturally has exclusive access to the vnode, so having it
locked on entry is not strictly necessary -- but it means if there
are any final operations that must be done on the vnode, such as
ffs_update, requiring exclusive access to it, we can now kassert that
the vnode is locked in those operations.

We can't just have the caller release the last lock because some file
systems don't use genfs_lock, and require the vnode to remain valid
for VOP_UNLOCK to work, notably unionfs.


Revision tags: prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.196 11-Apr-2017 riastradh

Make VOP_INACTIVE preserve vnode lock on return.

Discussed on tech-kern:
https://mail-index.netbsd.org/tech-kern/2017/04/01/msg021751.html

Ride 7.99.68, a bumpy bus of incremental vfs improvements!


Revision tags: jdolecek-ncq-base
# 1.195 30-Mar-2017 christos

add an auxv node.


Revision tags: pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004 localcount-20160914
# 1.194 20-Aug-2016 hannken

branches: 1.194.2;
Remove now obsolete operation vcache_remove().

Welcome to 7.99.36


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 nick-nhusb-base-20150921 nick-nhusb-base-20150606
# 1.193 20-Apr-2015 riastradh

branches: 1.193.2;
Make VOP_LINK return directory still locked and referenced.

Ride 7.99.10 bump.


Revision tags: nick-nhusb-base-20150406 nick-nhusb-base
# 1.192 05-Sep-2014 matt

branches: 1.192.2;
Try not to use f_data, use f_{vnode,socket,pipe,mqueue,kqueue,ksem} to get
a correctly typed pointer.


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.191 27-Jul-2014 hannken

Change procfs from hashlist to vcache.
- Key is (type, pid, fd)
- Remove argument "p" from procfs_allocvp(). It is only used
when "type == PFSfd". Lookup the proc with proc_find() when
procfs_loadvnode() needs it.
- Use a vfs_vnode_iterator for procfs_revoke_vnodes().


# 1.190 25-Jul-2014 dholland

Add VOP_FALLOCATE and VOP_FDISCARD to every vnode ops table I can
find.

The filesystem ones all call genfs_eopnotsupp - right now I am only
implementing the plumbing and we can implement fallocate and/or
fdiscard for files later.

The device ones call spec_fallocate (which is also genfs_eopnotsupp)
and spec_fdiscard, which dispatches to the device-level op.

The fifo ones all call vn_fifo_bypass, which also ends up being
EOPNOTSUPP.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base
# 1.189 07-Feb-2014 hannken

branches: 1.189.2;
Change vnode operation lookup to return the resulting vnode *vpp unlocked.
Change cache_lookup() to return an unlocked vnode.

Discussed on tech-kern@

Welcome to 6.99.31


# 1.188 23-Jan-2014 hannken

Change vnode operations create, mknod, mkdir and symlink to return
the resulting vnode *vpp unlocked.

Discussed on tech-kern@

Welcome to 6.99.30


# 1.187 17-Jan-2014 hannken

Change vnode operations create, mknod, mkdir and symlink to keep the
directory node dvp locked on return.

Discussed on tech-kern@

Welcome to 6.99.29


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base
# 1.186 18-Mar-2013 plunky

branches: 1.186.6;
C99 section 6.7.2.3 (Tags) Note 3 states that:

A type specifier of the form

enum identifier

without an enumerator list shall only appear after the type it
specifies is complete.

which means that we cannot pass an "enum vtype" argument to
kauth_access_action() without fully specifying the type first.
Unfortunately there is a complicated include file loop which
makes that difficult, so convert this minimal function into a
macro (and capitalize it).

(ok elad@)


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 1.185 25-Nov-2012 christos

do something reasonable with kernel semaphores.


Revision tags: yamt-pagecache-base6 jmcneill-usbmp-base10
# 1.184 28-May-2012 christos

branches: 1.184.2;
add a task process subdirectory for emul linux


Revision tags: yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 1.183 13-Mar-2012 elad

Replace the remaining KAUTH_GENERIC_ISSUSER authorization calls with
something meaningful. All relevant documentation has been updated or
written.

Most of these changes were brought up in the following messages:

http://mail-index.netbsd.org/tech-kern/2012/01/18/msg012490.html
http://mail-index.netbsd.org/tech-kern/2012/01/19/msg012502.html
http://mail-index.netbsd.org/tech-kern/2012/02/17/msg012728.html

Thanks to christos, manu, njoly, and jmmv for input.

Huge thanks to pgoyette for spinning these changes through some build
cycles and ATF.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.182 04-Sep-2011 jmcneill

branches: 1.182.2; 1.182.6;
PR# kern/45021: Please support /emul/linux/proc/version

Add /proc/version for procfs with -o linux. The version reported depends
on the emulation type of the calling process:

$ cat /proc/version
NetBSD version 5.99.55 (netbsd@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) NetBSD 5.99.55 (GENERIC) #39: Sun Sep 4 09:10:05 EDT 2011

$ /emul/linux/bin/cat /proc/version
Linux version 2.6.18 (linux@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) #0 Wed Mar 3 03:03:03 PST 2010

$ /emul/linux32/bin/cat /proc/version
Linux version 2.6.18 (linux32@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) #0 Wed Mar 3 03:03:03 PST 2010


# 1.181 23-Jun-2011 christos

From Aleksey Cheusov: Don't make it easy for compromised systems to bypass
ASLR protections by providing the mapping addresses of programs to everyone.


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base matt-mips64-premerge-20101231 uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10 rmind-uvmplock-base
# 1.180 01-Jul-2010 rmind

Remove pfind() and pgfind(), fix locking in various broken uses of these.
Rename real routines to proc_find() and pgrp_find(), remove PFIND_* flags
and have consistent behaviour. Provide proc_find_raw() for special cases.
Fix memory leak in sysctl_proc_corename().

COMPAT_LINUX: rework ptrace() locking, minimise differences between
different versions per-arch.

Note: while this change adds some formal cosmetics for COMPAT_DARWIN and
COMPAT_IRIX - locking there is utterly broken (for ages).

Fixes PR/43176.


# 1.179 24-Jun-2010 hannken

Clean up vnode lock operations pass 2:

VOP_UNLOCK(vp, flags) -> VOP_UNLOCK(vp): Remove the unneeded flags argument.

Welcome to 5.99.32.

Discussed on tech-kern.


# 1.178 08-Jun-2010 hannken

Procfs_lookup() does not lookup directory descriptors in the fd/
subdirectory. There is no need for recursive vnode locking here.

Ok: Christos Zoulas <christos@netbsd.org>


Revision tags: uebayasi-xip-base1 yamt-nfs-mp-base9 uebayasi-xip-base
# 1.177 08-Jan-2010 pooka

branches: 1.177.2; 1.177.4;
The VATTR_NULL/VREF/VHOLD/HOLDRELE() macros lost their will to live
years ago when the kernel was modified to not alter ABI based on
DIAGNOSTIC, and now just call the respective function interfaces
(in lowercase). Plenty of mix'n match upper/lowercase has creeped
into the tree since then. Nuke the macros and convert all callsites
to lowercase.

no functional change


Revision tags: matt-premerge-20091211 yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 jym-xensuspend-nbase
# 1.176 03-Jul-2009 elad

Where possible, extract the file-system's access() routine to two internal
functions: the first checking if the operation is possible (regardless of
permissions), the second checking file-system permissions, ACLs, etc.

Mailing list reference:

http://mail-index.netbsd.org/tech-kern/2009/06/21/msg005311.html


# 1.175 23-Jun-2009 elad

Move the implementation of vaccess() to genfs_can_access(), in line with
the other routines of the same spirit.

Adjust file-system code to use it.

Keep vaccess() for KPI compatibility and to keep element of least
surprise. A "diagnostic" message warning that vaccess() is deprecated will
be printed when it's used (obviously, only in DIAGNOSTIC kernels).

No objections on tech-kern@:

http://mail-index.netbsd.org/tech-kern/2009/06/21/msg005310.html


Revision tags: yamt-nfs-mp-base5
# 1.174 24-May-2009 ad

More changes to improve kern_descrip.c.

- Avoid atomics in more places.
- Remove the per-descriptor mutex, and just use filedesc_t::fd_lock.
It was only being used to synchronize close, and in any case we needed
to take fd_lock to free the descriptor slot.
- Optimize certain paths for the <NDFDFILE case.
- Sprinkle more comments and assertions.
- Cache more stuff in filedesc_t.
- Fix numerous minor bugs spotted along the way.
- Restructure how the open files array is maintained, for clarity and so
that we can eliminate the membar_consumer() call in fd_getfile(). This is
mostly syntactic sugar; the main functional change is that fd_nfiles now
lives alongside the open file array.

Some measurements with libmicro:

- simple file syscalls are like close() are between 1 to 10% faster.
- some nice improvements, e.g. poll(1000) which is ~50% faster.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 nick-hppapmap-base2 jym-xensuspend-base nick-hppapmap-base mjf-devfs2-base
# 1.173 17-Dec-2008 cegger

branches: 1.173.2;
kill MALLOC and FREE macros.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 haad-dm-base2 haad-nbase2 ad-audiomp2-base netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 haad-dm-base
# 1.172 05-Sep-2008 skrll

branches: 1.172.2;
PR/39324 kernel diagnostic assertion "l->l_stat != LSZOMB" failed.

Ignore procs with zero or all LSZOMB LWPs. Get a non-LSZOMB LWP to perform
operations against as part of the deal.

procfs really needs to be updated to support multi-threading fully.
Hi Antti!


# 1.171 05-Sep-2008 skrll

ANSIfy


Revision tags: simonb-wapbl-nbase simonb-wapbl-base
# 1.170 02-Jul-2008 rmind

branches: 1.170.2;
Remove proc_representative_lwp(), use a simple LIST_FIRST() instead.
OK by <ad>.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base
# 1.169 28-Apr-2008 martin

branches: 1.169.2; 1.169.4;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-nfs-mp-base
# 1.168 24-Apr-2008 ad

branches: 1.168.2;
Merge proc::p_mutex and proc::p_smutex into a single adaptive mutex, since
we no longer need to guard against access from hardware interrupt handlers.

Additionally, if cloning a process with CLONE_SIGHAND, arrange to have the
child process share the parent's lock so that signal state may be kept in
sync. Partially addresses PR kern/37437.


# 1.167 24-Apr-2008 ad

Network protocol interrupts can now block on locks, so merge the globals
proclist_mutex and proclist_lock into a single adaptive mutex (proc_lock).
Implications:

- Inspecting process state requires thread context, so signals can no longer
be sent from a hardware interrupt handler. Signal activity must be
deferred to a soft interrupt or kthread.

- As the proc state locking is simplified, it's now safe to take exit()
and wait() out from under kernel_lock.

- The system spends less time at IPL_SCHED, and there is less lock activity.


Revision tags: yamt-pf42-baseX yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14
# 1.166 21-Mar-2008 ad

branches: 1.166.2;
Catch up with descriptor handling changes. See kern_descrip.c revision
1.173 for details.


Revision tags: keiichi-mipv6-nbase nick-net80211-sync-base keiichi-mipv6-base bouyer-xeni386-nbase matt-armv6-nbase mjf-devfs-base hpcarm-cleanup-base
# 1.165 23-Jan-2008 elad

branches: 1.165.6;
Tons of process scope changes.

- Add a KAUTH_PROCESS_SCHEDULER action, to handle scheduler related
requests, and add specific requests for set/get scheduler policy and
set/get scheduler parameters.

- Add a KAUTH_PROCESS_KEVENT_FILTER action, to handle kevent(2) related
requests.

- Add a KAUTH_DEVICE_TTY_STI action to handle requests to TIOCSTI.

- Add requests for the KAUTH_PROCESS_CANSEE action, indicating what
process information is being looked at (entry itself, args, env,
open files).

- Add requests for the KAUTH_PROCESS_RLIMIT action indicating set/get.

- Add requests for the KAUTH_PROCESS_CORENAME action indicating set/get.

- Make bsd44 secmodel code handle the newly added rqeuests appropriately.

All of the above make it possible to issue finer-grained kauth(9) calls in
many places, removing some KAUTH_GENERIC_ISSUSER requests.

- Remove the "CAN" from KAUTH_PROCESS_CAN{KTRACE,PROCFS,PTRACE,SIGNAL}.

Discussed with christos@ and yamt@.


Revision tags: bouyer-xeni386-base matt-armv6-base
# 1.164 02-Jan-2008 ad

Merge vmlocking2 to head.


Revision tags: vmlocking2-base3 yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 vmlocking-nbase jmcneill-pm-base reinoud-bufcleanup-base
# 1.163 26-Nov-2007 pooka

branches: 1.163.2; 1.163.6;
Remove the "struct lwp *" argument from all VFS and VOP interfaces.
The general trend is to remove it from all kernel interfaces and
this is a start. In case the calling lwp is desired, curlwp should
be used.

quick consensus on tech-kern


Revision tags: bouyer-xenamd64-base2 bouyer-xenamd64-base
# 1.162 09-Nov-2007 christos

make the last argument of procfs_dir size_t


# 1.161 07-Nov-2007 ad

Merge from vmlocking:

- pool_cache changes.
- Debugger/procfs locking fixes.
- Other minor changes.


Revision tags: jmcneill-base yamt-x86pmap-base4 yamt-x86pmap-base3 vmlocking-base
# 1.160 10-Oct-2007 ad

branches: 1.160.2; 1.160.4;
Merge from vmlocking:

- Split vnode::v_flag into three fields, depending on field locking.
- simple_lock -> kmutex in a few places.
- Fix some simple locking problems.


# 1.159 08-Oct-2007 ad

Merge file descriptor locking, cwdi locking and cross-call changes
from the vmlocking branch.


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base2 yamt-x86pmap-base matt-mips64-base
# 1.158 22-Jul-2007 pooka

branches: 1.158.4; 1.158.6; 1.158.8; 1.158.10;
Don't allow getcwd() on procfs vnodes and provide "/" as the path
instead of the result from getcwd(). The works around locking
panics caused by namei calling VOP_READLINK while holding on to a
directory lock and getcwd() trying to acquire that lock. The real
fix would be to get rid of getcwd() calls within VOPs (not locking
safe), but that's not a viable option in the netbsd-4 timeframe.

Suggestion for workaround from David Holland.


Revision tags: nick-csl-alignment-base mjf-ufs-trans-base
# 1.157 24-May-2007 agc

branches: 1.157.2;
Extend the Linux emulation of /proc to include

/proc/stat
/proc/loadavg and
/proc/<pid>/statm.

These are only present when -o linux is specified as a mount option
to procfs.

Factor out some common code so that it can be used by a number of
functions.

XXX The values returned in the statm emulation need to be verified.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 1.156 04-Apr-2007 rmind

Unfortunately, missed procfs_proc_unlock() in previous.
Pointed out by pooka@


# 1.155 04-Apr-2007 rmind

procfs_readlink: Handle a possible fail of fd_getfile(), also, we
do not need to check for error again.
CID: 4436


# 1.154 09-Mar-2007 ad

branches: 1.154.2; 1.154.4;
- Make the proclist_lock a mutex. The write:read ratio is unfavourable,
and mutexes are cheaper use than RW locks.
- LOCK_ASSERT -> KASSERT in some places.
- Hold proclist_lock/kernel_lock longer in a couple of places.


# 1.153 04-Mar-2007 christos

Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.


# 1.152 03-Mar-2007 salo

Don't prepend rootvnode to the path in non-NULL case for exe links.
It breaks procfs in chroot.

from <christos>, tested by me.


Revision tags: ad-audiomp-base
# 1.151 19-Feb-2007 pooka

When checking for file validity under pid/, do proper proc->lwp
lookup (fsvo proper) instead of fiddling directly with the lwp
list.


# 1.150 18-Feb-2007 pooka

Don't check for validity of p in lookup for root nodes, since it
will always be NULL. Rather, just call pt_valid with NULL directly
and let it decide if we're a linux mount or not.


# 1.149 17-Feb-2007 pavel

Change the process/lwp flags seen by userland via sysctl back to the
P_*/L_* naming convention, and rename the in-kernel flags to avoid
conflict. (P_ -> PK_, L_ -> LW_ ). Add back the (now unused) LSDEAD
constant.

Restores source compatibility with pre-newlock2 tools like ps or top.

Reviewed by Andrew Doran.


# 1.148 16-Feb-2007 pooka

branches: 1.148.2;
In lookup, when checking for procfs process node validity, target the
process we're trying to get information about through procfs, not
the caller of lookup.

fixes 'ls -l /proc/*/file' panic, which would occur when trying to
lookup "file" for a kernel thread, which doesn't have p->p_textvp.


# 1.147 15-Feb-2007 ad

Need to acquire procp->p_mutex for procfs_dir().


# 1.146 11-Feb-2007 ad

Eliminate a couple of reference count and mutex leaks.


Revision tags: post-newlock2-merge
# 1.145 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 1.144 25-Dec-2006 elad

PR/35226: Johann Franz: Problems with permissions in
/usr/pkg/emul/linux/proc .

Okay mlelstv@


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3
# 1.143 09-Dec-2006 chs

a smorgasbord of improvements to vnode locking and path lookup:
- LOCKPARENT is no longer relevant for lookup(), relookup() or VOP_LOOKUP().
these now always return the parent vnode locked. namei() works as before.
lookup() and various other paths no longer acquire vnode locks in the
wrong order via vrele(). fixes PR 32535.
as a nice side effect, path lookup is also up to 25% faster.
- the above allows us to get rid of PDIRUNLOCK.
- also get rid of WANTPARENT (just use LOCKPARENT and unlock it).
- remove an assumption in layer_node_find() that all file systems implement
a recursive VOP_LOCK() (unionfs doesn't).
- require that all file systems supply vfs_vptofh and vfs_fhtovp routines.
fill in eopnotsupp() for file systems that don't support being exported
and remove the checks for NULL. (layerfs calls these without checking.)
- in union_lookup1(), don't change refcounts in the ISDOTDOT case, just
adjust which vnode is locked. fixes PR 33374.
- apply fixes for ufs_rename() from ufs_vnops.c rev. 1.61 to ext2fs_rename().


# 1.142 04-Dec-2006 christos

From Nicolas Joly: restore previous behavior in procfs_validfile_linux, since
readdir passes a NULL lwp.


# 1.141 03-Dec-2006 elad

Move kauth(9) call to where it belongs. Noticed by Nicolas Joly, thanks!


Revision tags: netbsd-4-base
# 1.140 28-Nov-2006 elad

branches: 1.140.2;
Move ktrace, ptrace, systrace, and procfs to use kauth(9).

First, remove process_checkioperm() calls from MD code. Similar checks
using kauth(9) routines (on the process scope, using appropriate action)
are done in the callers.

Add secmodel back-end to handle each subsystem.


# 1.139 25-Nov-2006 skrll

Expose the 'exe' symlink to the process realpath in NetBSD as well. An
example user is gdb.

OK'd by christos.


# 1.138 16-Nov-2006 christos

__unused removal on arguments; approved by core.


# 1.137 29-Oct-2006 christos

add an "emul" file node.


# 1.136 25-Oct-2006 christos

1. fix procfs_validfile{,_linux} to test for NULL pointers properly.
2. make "exe" entry be a symlink to the executable, instead of pointing
directly to the vnode of the executable.
3. factor out commonly used code.


Revision tags: yamt-splraiseipl-base2
# 1.135 12-Oct-2006 christos

- sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386


# 1.134 20-Sep-2006 manu

Emulate Linux's /proc/devices


Revision tags: abandoned-netbsd-4-base yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base rpaulo-netinet-merge-pcb-base
# 1.133 13-Jun-2006 yamt

branches: 1.133.6; 1.133.8;
use KAUTH_PROCESS_CANSEE rather than CURTAIN where appropriate.


# 1.132 13-Jun-2006 yamt

remove unnecessary arguments from kauth_authorize_process.
ie. make it similar to the one found in apple TN.


# 1.131 07-Jun-2006 kardel

merge FreeBSD timecounters from branch simonb-timecounters
- struct timeval time is gone
time.tv_sec -> time_second
- struct timeval mono_time is gone
mono_time.tv_sec -> time_uptime
- access to time via
{get,}{micro,nano,bin}time()
get* versions are fast but less precise
- support NTP nanokernel implementation (NTP API 4)
- further reading:
Timecounter Paper: http://phk.freebsd.dk/pubs/timecounter.pdf
NTP Nanokernel: http://www.eecis.udel.edu/~mills/ntp/html/kern.html


Revision tags: yamt-pdpolicy-base5 simonb-timecounters-base
# 1.130 14-May-2006 elad

branches: 1.130.2;
integrate kauth.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 elad-kernelauth-base yamt-pdpolicy-base yamt-uio_vmspace-base5
# 1.129 02-Feb-2006 christos

branches: 1.129.2; 1.129.4; 1.129.6; 1.129.8;
PR/32692: Matthew Mondor: linux compatibility in /proc/self should point
directly to the directory containing the pid instead of pointing to
/proc/curproc, because some programs rely on calling readlink on /proc/self
to get the pid.


# 1.128 11-Dec-2005 christos

branches: 1.128.2; 1.128.4;
merge ktrace-lwp.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base ktrace-lwp-base
# 1.127 02-Nov-2005 yamt

merge yamt-vop branch. remove following VOPs.

VOP_BLKATOFF
VOP_VALLOC
VOP_BALLOC
VOP_REALLOCBLKS
VOP_VFREE
VOP_TRUNCATE
VOP_UPDATE


Revision tags: yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 1.126 01-Oct-2005 atatat

branches: 1.126.2;
Add "cwd" and "root" symlinks to each process's directory. The cwd
link points to the process's current working directory, and the root
link points to the process's root directory. What else would you
expect?

For directories that are out of reach (caller is in a chroot, target
process is in a different chroot, etc), the links point to "/"
instead.


# 1.125 11-Sep-2005 elad

Implement curtain for procfs.


# 1.124 30-Aug-2005 xtraeme

Remove __P()


# 1.123 29-May-2005 christos

branches: 1.123.2;
- sprinkle const
- avoid shadowed variables.


Revision tags: kent-audio2-base
# 1.122 02-Apr-2005 christos

PR/29782: Martin Husemann: procfs can not unmount when some process has its
current directory in curproc. Fix from Pedro Martelletto:
We cannot call vgone() from procfs_inactive() if we are coming from
vclean(). that's what's probably causing the deadlock.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 yamt-km-base4 yamt-km-base3 netbsd-3-base
# 1.121 26-Feb-2005 perry

nuke trailing whitespace


Revision tags: yamt-km-base2 yamt-km-base kent-audio1-beforemerge kent-audio1-base
# 1.120 04-Oct-2004 yamt

branches: 1.120.4; 1.120.6;
procfs_readdir:
- return correct cookie when buffer size is small.
- simplify logic.


# 1.119 04-Oct-2004 yamt

procfs_readdir: remove a redundant assignment.


# 1.118 02-Oct-2004 yamt

procfs_getattr: correct size of /proc/self.


# 1.117 01-Oct-2004 yamt

procfs_readdir:
- fix a locking problem, using proclist_foreach_call. PR/27098.
- correct snprintf size argument.


# 1.116 01-Oct-2004 yamt

procfs_readdir: fix an offset handling bug after addition of /proc/self.


# 1.115 01-Oct-2004 yamt

procfs_readdir: use a list macro.


# 1.114 20-Sep-2004 jdolecek

add 'mounts' file for -o linux, which lists all currently mounted
filesystems; Linux glibc statvfs() uses this to get some of mount flags,
and this file is also useful as /emul/linux/etc/mtab (via symlink)


# 1.113 29-Apr-2004 jrf

Removed remaining caddr_t casts we do not need in miscfs. Recompiled
kernel and ran for a day or so. There are still some caddr_t types in
the arguments of some calls, I will do those separately (later) as
they touch a lot more of the system.
Approved by christos@NetBSD.org.


# 1.112 22-Apr-2004 itojun

sprintf -> snprintf


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.111 15-Feb-2004 jdolecek

unlock the descriptor table simple lock after fd_getfile() call in
procfs_readdir()
fixes procfs locking problems reported on current-users@, problem place
found by enami tsugutomo


# 1.110 30-Oct-2003 simonb

Remove some assigned-to but otherwise unused variables.


# 1.109 27-Sep-2003 darcy

Changes as discussed with itojun on tech-kern. I have modified the enums
to have KFS or PFS differentiators. Further I have wrapped the enum in
procfs in "#ifdef _KERNEL" as it is done in kernfs.

To see the discussion go to http://mail-index.NetBSD.org/tech-kern/2003/09/
and look for "Mismatched enums in include files" in the list.


# 1.108 07-Sep-2003 itojun

remove meaningless line (variable overwritten 2 lines below)


# 1.107 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.


# 1.106 29-Jun-2003 fvdl

branches: 1.106.2;
Back out the lwp/ktrace changes. They contained a lot of colateral damage,
and need to be examined and discussed more.


# 1.105 29-Jun-2003 thorpej

Undo part of the ktrace/lwp changes. In particular:
* Remove the "lwp *" argument that was added to vget(). Turns out
that nothing actually used it!
* Remove the "lwp *" arguments that were added to VFS_ROOT(), VFS_VGET(),
and VFS_FHTOVP(); all they did was pass it to vget() (which, as noted
above, didn't use it).
* Remove all of the "lwp *" arguments to internal functions that were added
just to appease the above.


# 1.104 28-Jun-2003 darrenr

Pass lwp pointers throughtout the kernel, as required, so that the lwpid can
be inserted into ktrace records. The general change has been to replace
"struct proc *" with "struct lwp *" in various function prototypes, pass
the lwp through and use l_proc to get the process pointer when needed.

Bump the kernel rev up to 1.6V


# 1.103 28-May-2003 christos

Add /proc/<pid>/stat for linux compat. j2sdk1.4.2 depends on it.


# 1.102 18-Apr-2003 christos

Make symlinks for directories that point to the actual directory.
Make symlinks to [kqueue] and [misc] for kqueue and misc fds.


# 1.101 17-Apr-2003 jdolecek

do not show nodes corresponding to directory descriptors for process
in fd/ subdirectory, nor allow lookup/open for the nodes
this fixes PR kern/21187 for good, and also avoids interesting directory
locking issues


# 1.100 17-Apr-2003 jdolecek

procfs_readdir(): in Pfd case, only show descriptors of types we want
how to represent (vnodes, fifo, pipes); also use fd_getfile() et al

this avoids annoying EOPNOTSUPP error messages from ls -F and such


# 1.99 17-Apr-2003 jdolecek

procfs_lookup(): use fd_getfile() et al in Pfd case


# 1.98 17-Apr-2003 jdolecek

use fd_getfile() in procfs_getfp(), and FILE_USE()/FILE_UNUSE() the
returned file descriptor pointer appropriately


# 1.97 17-Apr-2003 jdolecek

make some local arrays/variables static + const


# 1.96 10-Apr-2003 jdolecek

use former genfs_eopnotsupp_rele() as genfs_eopnotsupp(), so that vnodes
are vput()/vrele()d as necessary - some filesystems did use the wrong
one for some ops, and it's just safer to not take the chance

based on suggestion by Bill Studenmund


# 1.95 05-Apr-2003 dsl

Remove pointless check against PID_MAX. Let pfind() do the validation.
(The new pid allocation code may decide to allocate pids above PID_MAX.)


# 1.94 25-Feb-2003 jrf

This addresses PR kerm/19989. Thanks to hamajima@nagoya.ydc.co.jp for submitting this patch which enables /proc/uptime for linux emul. Patch reviewed by atatat@netbsd.org and tron@netbsd.org, approved by tron@netbsd.org.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 1.93 04-Jan-2003 martin

Cast off_t expression to long long to match format even on 64 bit
plattforms.

Shouldn't we introduce a PRIoff_t macro to create such format strings?


# 1.92 03-Jan-2003 christos

add LK_CANRECURSE in the locking of /dev/<pid>/fd/<n> and remove the curproc
kludge. Thanks to fvdl.


# 1.91 03-Jan-2003 christos

Implement /proc/<pid>/fd/<n>. This is work in progress. Questionable things:
- Is it ok to convert DTYPE_PIPE to VFIFO and DTYPE_SOCKET to VSOCK?
- XXX: Avoid locking issue in ls -Rl /proc by avoiding curproc
- Does I/O to pipes work?
- XXX: Are there security implications?


Revision tags: fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge gehenna-devsw-base kqueue-base
# 1.90 03-Aug-2002 simonb

Just use the "time" variable in the *_getattr functions instead of a call
to (the potentially expensive) microtime().


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.89 09-May-2002 thorpej

branches: 1.89.2;
Move code shared by procfs and the kernel proper out of procfs and
into the kernel proper (renaming functions from procfs_* to process_*).


Revision tags: eeh-devprop-base newlock-base ifpoll-base
# 1.88 12-Jan-2002 christos

Don't hide the real return code with EPERM.


# 1.87 06-Dec-2001 chs

add a VOP_PUTPAGES method for all the filesystems that don't have pages,
just unlock the interlock.


# 1.86 05-Dec-2001 thorpej

* Allow machine-dependent code to specify hooks for ptrace(2)
(__HAVE_PTRACE_MACHDEP) and procfs (__HAVE_PROCFS_MACHDEP).
These changes will allow platforms like x86 (XMM) and PowerPC
(AltiVec) to export extended register sets in a sane manner.

* Use __HAVE_PTRACE_MACHDEP to export x86 XMM registers (standard
FP + SSE/SSE2) using PT_{GET,SET}XMMREGS (in the machdep
ptrace request space).
* Use __HAVE_PROCFS_MACHDEP to export x86 XMM registers via
/proc/N/xmmregs in procfs.


Revision tags: thorpej-mips-cache-base
# 1.85 10-Nov-2001 lukem

add RCSIDs


# 1.84 06-Nov-2001 simonb

Remove some variables that are set but never used.


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base
# 1.83 31-Aug-2001 chs

branches: 1.83.2; 1.83.4;
map files are zero-length.


# 1.82 03-Jun-2001 chs

branches: 1.82.2;
procfs_bmap() should never be called, make it a "bad op".
let procfs_mmap() use the default error method.


Revision tags: thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 1.81 14-Apr-2001 kleink

In procfs_readdir(), give /proc/# directories DT_DIR (rather than DT_REG).


# 1.80 30-Mar-2001 fvdl

Bump va_blocksize for the map files some more, so that programs with
quite a few mappings have a chance of being handled correctly if
st_blksize is looked at.


# 1.79 29-Mar-2001 fvdl

For -o linux mounts, add some code to emulate /proc/#/maps.
Needs NAMECACHE_ENTER_REVERSE to include filenames.


# 1.78 21-Feb-2001 jdolecek

branches: 1.78.2;
make some more constant arrays 'const'


# 1.77 22-Jan-2001 jdolecek

make filesystem vnodeop, specop, fifoop and vnodeopv_* arrays const


# 1.76 17-Jan-2001 fvdl

Add a few linux-style files, only enabled when -o linux is specified
for the mount. Currently these are /proc/cpuinfo and /proc/meminfo.
The former only does something on i386 right now.


# 1.75 24-Nov-2000 chs

remove dead code and other misc cleanup.


# 1.74 09-Aug-2000 tv

Only show the "exe" entry to Linux processes, suggested by christos.
Since there are actually three struct emul's for linux, use the e_name
field to determine eligibility with strcmp().


# 1.73 09-Aug-2000 tv

Some versions of Linux libc look for /proc/.../exe instead of /proc/../file.
Add an entry for "exe" that is the same as "file", provided only if
COMPAT_LINUX is set.


# 1.72 03-Aug-2000 thorpej

MALLOC()/FREE() are not to be used for variable sized allocations.


# 1.71 28-Jun-2000 mrg

<vm/vm.h> -> <uvm/uvm_extern.h>


Revision tags: netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 1.70 30-Mar-2000 simonb

branches: 1.70.4;
Delete duplicate declaration of atopid().


Revision tags: chs-ubc2-newbase wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base fvdl-softdep-base
# 1.69 02-Sep-1999 thorpej

branches: 1.69.2; 1.69.8;
Make /proc/self a symlink to /proc/curproc. I've observed Linux programs
that expect /proc/self/cmdline to exist.


# 1.68 25-Aug-1999 sommerfeld

Change variable used for directory offset from "int" to "off_t".
Overkill, but avoids a host of truncation problems.


# 1.67 24-Aug-1999 sommerfeld

Fix PR8270:

Problem turned out to be due to improper handling of reads beyond EOF:
they should just return without error with the uio unchanged, and the
caller will recognize this as a zero-byte return (EOF).

The previous fix to protect directory reads against bogus uio_offset
values returned EINVAL, which broke mount -o union, which only
union'ed in the lower directory if the upper directory cleanly
returned EOF.

While we're here, protect kernfs as well.


# 1.66 14-Aug-1999 christos

protect against large uio_offset


# 1.65 03-Aug-1999 wrstuden

Add support for fcntl(2) to generate VOP_FCNTL calls. Any fcntl
call with F_FSCTL set and F_SETFL calls generate calls to a new
fileop fo_fcntl. Add genfs_fcntl() and soo_fcntl() which return 0
for F_SETFL and EOPNOTSUPP otherwise. Have all leaf filesystems
use genfs_fcntl().

Reviewed by: thorpej
Tested by: wrstuden


Revision tags: chs-ubc2-base
# 1.64 25-Jul-1999 thorpej

Add calls to lock the proclist as appropriate.


# 1.63 14-Jul-1999 thorpej

Fix a paste-o in procfs_lookup() introduced with the vnode locking changes.
Fixes PR #7961, Mario Kemper <magick@bundy.lip.owl.de>.


# 1.62 08-Jul-1999 wrstuden

Bump osrelease to 1.4E. Add layerfs files, remove null_subr.c.

Update coda to new struct lock in struct vnode.

make fdescfs, kernfs, portalfs, and procfs actually lock their vnodes.
It's not that hard.

Make unionfs set v_vnlock = NULL so any overlayed fs will call its
VOP_LOCK.


Revision tags: kame_141_19991130 netbsd-1-4-PATCH001 kame_14_19990705 kame_14_19990628 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.61 12-Mar-1999 christos

branches: 1.61.2; 1.61.4;
PR/7143: Jaromir Docelek: Add procfs/cmdline from Linux emulation


# 1.60 25-Jan-1999 msaitoh

Add /proc/#/map. From FreeBSD.


Revision tags: kenh-if-detach-base chs-ubc-base
# 1.59 08-Sep-1998 thorpej

- Use proclists[], rather than checking allproc and zombproc explicitly.
- Add some comments about locking.


# 1.58 13-Aug-1998 kleink

Per POSIX, fail with EINVAL if advisory locking is attempted on a file type
that doesn't support it, rather than using a homegrown EBADF or EOPNOTSUPP.


# 1.57 10-Aug-1998 matthias

create miscfs/genfs/genfs_vnops.c:genfs_enoioctl and make all the other
filesystems use it instead of a private version.


# 1.56 09-Aug-1998 perry

bzero->memset, bcopy->memcpy, bcmp->memcmp


# 1.55 03-Aug-1998 kleink

Recognize _PC_SYNC_IO.


Revision tags: eeh-paddr_t-base
# 1.54 21-Apr-1998 fvdl

procfs_readdir: in case of error, check if cookies actually have
been allocated before freeing them. From Wolfgang Solfrank.


# 1.53 01-Mar-1998 fvdl

Merge with Lite2 + local changes


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base marc-pcmcia-base
# 1.52 10-Oct-1997 fvdl

Bump last argument to VOP_READDIR to off_t (from u_long).


Revision tags: thorpej-signal-base
# 1.51 27-Aug-1997 thorpej

Fix a reversed argument which caused procfs_checkioperm() to always return
"OK". Add a few comments to avoid further confusion.


# 1.50 12-Aug-1997 thorpej

Fix the procfs hole described on current-users, similar to a fix for
FreeBSD by Sean Eric Fagan, but a bit different. This makes the checks
in the same places as sef's FreeBSD patch, but does not hardcode the
"kmem" group into the kernel, and also does a check identical to the
(3) and (4) checks in the NetBSD ptrace(2):

(1) it's not owned by you, or is set-id on exec (unless
you're root), or

(2) it's init, which controls the security level of the
entire system, and the system was not compiled with
permanently insecure mode turned on.


Revision tags: marc-pcmcia-bp
# 1.49 08-May-1997 mycroft

branches: 1.49.4;
Pass the vnode type to vaccess(), and use it when checking VEXEC. Make sure
that the mode bits passed to vaccess() and returned by foo_getattr() contain
only permission bits.


# 1.48 05-May-1997 mycroft

Need stat.h.


# 1.47 05-May-1997 mycroft

Eliminate bogus uses of V{READ,WRITE,EXEC}. Use S_I[RWX]{USR,GRP,OTH} where
appropriate.


# 1.46 28-Apr-1997 mycroft

Minor code cleanup.


Revision tags: is-newarp-before-merge is-newarp-base
# 1.45 25-Oct-1996 cgd

define path name string variables that we should not (and, thankfully, do
not) modify as 'const char *' rather 'char *'.


# 1.44 13-Oct-1996 christos

backout previous kprintf changes


# 1.43 10-Oct-1996 christos

printf -> kprintf, sprintf -> ksprintf


# 1.42 07-Sep-1996 mycroft

Implement poll(2).


# 1.41 01-Sep-1996 mycroft

Add a set of generic file system operations that most file systems use.
Also, fix some time stamp bogosities.


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 1.40 16-Mar-1996 christos

Fix printf format follies.


# 1.39 13-Feb-1996 mycroft

GC *_nullop(). Minor nits.


# 1.38 12-Feb-1996 christos

close PR/2063: procfs_rw prototyped twice with different prototypes


# 1.37 09-Feb-1996 christos

miscfs prototype changes


# 1.36 09-Feb-1996 mycroft

Fix vop_link, vop_symlink, and vop_remove semantics in several ways:
* Change the argument names to vop_link so they actually make sense.
* Implement vop_link and vop_symlink for all file systems, so they do proper
cleanup.
* Require the file system to decide whether or not linking and unlinking of
directories is allowed, and disable it for all current file systems.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.35 09-Oct-1995 mycroft

Use the index number as the cookie, rather than multiplying by UIO_MX.


# 1.34 09-Oct-1995 mycroft

Add support for cookies, mostly from Greg Hudson.


# 1.33 15-Apr-1995 cgd

fix timeval vs. timespec warnings


# 1.32 03-Feb-1995 mycroft

Return EROFS rather than ENOENT in many cases. Also some cosmetic cleanup.


# 1.31 27-Dec-1994 mycroft

Format police.


# 1.30 24-Dec-1994 ws

Implement and use a common access checking routine


# 1.29 14-Dec-1994 mycroft

Remove a_fp.


# 1.28 14-Nov-1994 christos

fixed struct comment


# 1.27 30-Oct-1994 cgd

be more careful with types, also pull in headers where necessary.


# 1.26 20-Oct-1994 cgd

update for new syscall args description mechanism


# 1.25 30-Aug-1994 mycroft

Convert process, file, and namei lists and hash tables to use queue.h.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.24 29-Jun-1994 cgd

New RCS ID's, take two. they're more aesthecially pleasant, and use 'NetBSD'


# 1.23 16-Jun-1994 mycroft

Remove an unneeded test.


# 1.22 15-Jun-1994 mycroft

Minor update from JSP after merging my changes.


# 1.21 08-Jun-1994 mycroft

Update to 4.4-Lite fs code, with local changes.


# 1.20 05-May-1994 cgd

lots of changes: prototype migration, move lots of variables, definitions,
and structure elements around. kill some unnecessary type and macro
definitions. standardize clock handling. More changes than you'd want.


# 1.19 15-Apr-1994 cgd

forgot these...


# 1.18 12-Apr-1994 cgd

be a bit smarter about determining if files shouldn't be seen by the user.
Also, DON'T allow a lookup to succeed on a file that's not visible!


# 1.17 15-Feb-1994 mycroft

Undo last change; executables is `file', not `a.out'.


# 1.16 14-Feb-1994 ws

Rename file -> a.out


# 1.15 14-Feb-1994 ws

Don't try to show a file for a process if there is none


# 1.14 28-Jan-1994 cgd

make a fpregs file.


# 1.13 20-Jan-1994 ws

Make procfs really work for debugging.
Implement not & notepg files in procfs.


# 1.12 09-Jan-1994 ws

Bug fixes and enhancements:
Make NFS serving work (BUT DON'T USE "attach" TO /proc/*/ctl FOR NOW!!!)
Make `curproc' a symbolic link
Add `.' and `..' entries to the directories.
Return better guesses on the size of the files.


# 1.11 05-Jan-1994 cgd

return size of 'reg' from getattr()


# 1.10 05-Jan-1994 cgd

make it compile (cleanly) for us


# 1.9 05-Jan-1994 cgd

add new procfs code, from Jan-Simon Pendry, jsp@sequent.com.
This is pretty-much "virgin", so that diffs can be done later.


# 1.8 18-Dec-1993 mycroft

Canonicalize all #includes.


Revision tags: magnum-base
# 1.7 16-Sep-1993 cgd

kill volatile warning.


# 1.6 07-Sep-1993 ws

branches: 1.6.2;
Changes to VFS readdir semantics
NFS changes for better cookie support
ISOFS changes for better Rockridge support and support for generation numbers


# 1.5 26-Aug-1993 pk

Implement setattr: mode for process entries; mode + uid/gid for the
PROCFS root directory.
Fixed omission in pfs_root() which came to light as a result of the above:
hold on to vnode for root dir.


# 1.4 25-Aug-1993 pk

Fixed improperly initialized nfsnode in pfs_lookup()


# 1.3 24-Aug-1993 pk

copyright update.


# 1.2 24-Aug-1993 pk

Rcs Id added.


# 1.1 24-Aug-1993 pk

branches: 1.1.1;
Initial version of a proc filesystem.


Revision tags: isaki-audio2-base
# 1.206 30-Mar-2019 christos

add a node for the process resource limits.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020
# 1.205 14-Oct-2018 jdolecek

remove M_CANFAIL flag for malloc(9) - it was completely ignored, so had
actually no effect


Revision tags: pgoyette-compat-0930 pgoyette-compat-0906
# 1.204 03-Sep-2018 riastradh

Rename min/max -> uimin/uimax for better honesty.

These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER! Some subsystems have

#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)


Revision tags: pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415
# 1.203 07-Apr-2018 hannken

Lock the target cwdi and take an additional reference to the
vnode we are interested in to prevent it from disappearing
before getcwd_common().

Should fix PR kern/53096 (netbsd-8 crash on heavy disk I/O)


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.202 31-Dec-2017 christos

branches: 1.202.2;
Add an environ node


Revision tags: tls-maxphys-base-20171202
# 1.201 01-Dec-2017 christos

Allow procfs_kqfilter, since we allow poll. "go" does it.


# 1.200 08-Nov-2017 christos

fix locking, remove error(1) comments.


# 1.199 08-Nov-2017 christos

use p->p_path, remove unused code.


# 1.198 28-Aug-2017 kamil

Remove the filesystem tracing feature

This is a legacy interface from 4.4BSD, and it was
introduced to overcome shortcomings of ptrace(2) at that time, which are
no longer relevant (performance). Today /proc/#/ctl offers a narrow
subset of ptrace(2) commands and is not applicable for modern
applications use beyond simplistic tracing scenarios.

This removal will simplify kernel internals. Users will still be able to
use all the other /proc files.

This change won't affect other procfs files neither Linux compat
features within mount_procfs(8). /proc/#/ctl isn't available on Linux.

Remove:
- /proc/#/ctl from mount_procfs(8)
- P_FSTRACE note from the documentation of ps(1)
- /proc/#/ctl and filesystem tracing documentation from mount_procfs(8)
- KAUTH_REQ_PROCESS_PROCFS_CTL documentation from kauth(9)
- source code file miscfs/procfs/procfs_ctl.c
- PFSctl and procfs_doctl() from sys/miscfs/procfs/procfs.h
- KAUTH_REQ_PROCESS_PROCFS_CTL from sys/sys/kauth.h
- PSL_FSTRACE (0x00010000) from sys/sys/proc.h
- P_FSTRACE (0x00010000) from sys/sys/sysctl.h

Reduce code complexity after removal of this functionality.

Update TODO.ptrace accordingly: remove two entries about /proc tracing.

Do not keep legacy notes as comments in the headers about removed
PSL_FSTRACE / P_FSTRACE, as this interface had little number of users
(close or equal to zero).

Proposed on tech-kern@.

All filesystem tracing utility users are encouraged to switch to ptrace(2).

Sponsored by <The NetBSD Foundation>


Revision tags: matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base
# 1.197 26-May-2017 riastradh

branches: 1.197.2;
Make VOP_RECLAIM do the last unlock of the vnode.

VOP_RECLAIM naturally has exclusive access to the vnode, so having it
locked on entry is not strictly necessary -- but it means if there
are any final operations that must be done on the vnode, such as
ffs_update, requiring exclusive access to it, we can now kassert that
the vnode is locked in those operations.

We can't just have the caller release the last lock because some file
systems don't use genfs_lock, and require the vnode to remain valid
for VOP_UNLOCK to work, notably unionfs.


Revision tags: prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.196 11-Apr-2017 riastradh

Make VOP_INACTIVE preserve vnode lock on return.

Discussed on tech-kern:
https://mail-index.netbsd.org/tech-kern/2017/04/01/msg021751.html

Ride 7.99.68, a bumpy bus of incremental vfs improvements!


Revision tags: jdolecek-ncq-base
# 1.195 30-Mar-2017 christos

add an auxv node.


Revision tags: pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004 localcount-20160914
# 1.194 20-Aug-2016 hannken

branches: 1.194.2;
Remove now obsolete operation vcache_remove().

Welcome to 7.99.36


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 nick-nhusb-base-20150921 nick-nhusb-base-20150606
# 1.193 20-Apr-2015 riastradh

branches: 1.193.2;
Make VOP_LINK return directory still locked and referenced.

Ride 7.99.10 bump.


Revision tags: nick-nhusb-base-20150406 nick-nhusb-base
# 1.192 05-Sep-2014 matt

branches: 1.192.2;
Try not to use f_data, use f_{vnode,socket,pipe,mqueue,kqueue,ksem} to get
a correctly typed pointer.


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.191 27-Jul-2014 hannken

Change procfs from hashlist to vcache.
- Key is (type, pid, fd)
- Remove argument "p" from procfs_allocvp(). It is only used
when "type == PFSfd". Lookup the proc with proc_find() when
procfs_loadvnode() needs it.
- Use a vfs_vnode_iterator for procfs_revoke_vnodes().


# 1.190 25-Jul-2014 dholland

Add VOP_FALLOCATE and VOP_FDISCARD to every vnode ops table I can
find.

The filesystem ones all call genfs_eopnotsupp - right now I am only
implementing the plumbing and we can implement fallocate and/or
fdiscard for files later.

The device ones call spec_fallocate (which is also genfs_eopnotsupp)
and spec_fdiscard, which dispatches to the device-level op.

The fifo ones all call vn_fifo_bypass, which also ends up being
EOPNOTSUPP.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base
# 1.189 07-Feb-2014 hannken

branches: 1.189.2;
Change vnode operation lookup to return the resulting vnode *vpp unlocked.
Change cache_lookup() to return an unlocked vnode.

Discussed on tech-kern@

Welcome to 6.99.31


# 1.188 23-Jan-2014 hannken

Change vnode operations create, mknod, mkdir and symlink to return
the resulting vnode *vpp unlocked.

Discussed on tech-kern@

Welcome to 6.99.30


# 1.187 17-Jan-2014 hannken

Change vnode operations create, mknod, mkdir and symlink to keep the
directory node dvp locked on return.

Discussed on tech-kern@

Welcome to 6.99.29


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base
# 1.186 18-Mar-2013 plunky

branches: 1.186.6;
C99 section 6.7.2.3 (Tags) Note 3 states that:

A type specifier of the form

enum identifier

without an enumerator list shall only appear after the type it
specifies is complete.

which means that we cannot pass an "enum vtype" argument to
kauth_access_action() without fully specifying the type first.
Unfortunately there is a complicated include file loop which
makes that difficult, so convert this minimal function into a
macro (and capitalize it).

(ok elad@)


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 1.185 25-Nov-2012 christos

do something reasonable with kernel semaphores.


Revision tags: yamt-pagecache-base6 jmcneill-usbmp-base10
# 1.184 28-May-2012 christos

branches: 1.184.2;
add a task process subdirectory for emul linux


Revision tags: yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 1.183 13-Mar-2012 elad

Replace the remaining KAUTH_GENERIC_ISSUSER authorization calls with
something meaningful. All relevant documentation has been updated or
written.

Most of these changes were brought up in the following messages:

http://mail-index.netbsd.org/tech-kern/2012/01/18/msg012490.html
http://mail-index.netbsd.org/tech-kern/2012/01/19/msg012502.html
http://mail-index.netbsd.org/tech-kern/2012/02/17/msg012728.html

Thanks to christos, manu, njoly, and jmmv for input.

Huge thanks to pgoyette for spinning these changes through some build
cycles and ATF.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.182 04-Sep-2011 jmcneill

branches: 1.182.2; 1.182.6;
PR# kern/45021: Please support /emul/linux/proc/version

Add /proc/version for procfs with -o linux. The version reported depends
on the emulation type of the calling process:

$ cat /proc/version
NetBSD version 5.99.55 (netbsd@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) NetBSD 5.99.55 (GENERIC) #39: Sun Sep 4 09:10:05 EDT 2011

$ /emul/linux/bin/cat /proc/version
Linux version 2.6.18 (linux@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) #0 Wed Mar 3 03:03:03 PST 2010

$ /emul/linux32/bin/cat /proc/version
Linux version 2.6.18 (linux32@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) #0 Wed Mar 3 03:03:03 PST 2010


# 1.181 23-Jun-2011 christos

From Aleksey Cheusov: Don't make it easy for compromised systems to bypass
ASLR protections by providing the mapping addresses of programs to everyone.


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base matt-mips64-premerge-20101231 uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10 rmind-uvmplock-base
# 1.180 01-Jul-2010 rmind

Remove pfind() and pgfind(), fix locking in various broken uses of these.
Rename real routines to proc_find() and pgrp_find(), remove PFIND_* flags
and have consistent behaviour. Provide proc_find_raw() for special cases.
Fix memory leak in sysctl_proc_corename().

COMPAT_LINUX: rework ptrace() locking, minimise differences between
different versions per-arch.

Note: while this change adds some formal cosmetics for COMPAT_DARWIN and
COMPAT_IRIX - locking there is utterly broken (for ages).

Fixes PR/43176.


# 1.179 24-Jun-2010 hannken

Clean up vnode lock operations pass 2:

VOP_UNLOCK(vp, flags) -> VOP_UNLOCK(vp): Remove the unneeded flags argument.

Welcome to 5.99.32.

Discussed on tech-kern.


# 1.178 08-Jun-2010 hannken

Procfs_lookup() does not lookup directory descriptors in the fd/
subdirectory. There is no need for recursive vnode locking here.

Ok: Christos Zoulas <christos@netbsd.org>


Revision tags: uebayasi-xip-base1 yamt-nfs-mp-base9 uebayasi-xip-base
# 1.177 08-Jan-2010 pooka

branches: 1.177.2; 1.177.4;
The VATTR_NULL/VREF/VHOLD/HOLDRELE() macros lost their will to live
years ago when the kernel was modified to not alter ABI based on
DIAGNOSTIC, and now just call the respective function interfaces
(in lowercase). Plenty of mix'n match upper/lowercase has creeped
into the tree since then. Nuke the macros and convert all callsites
to lowercase.

no functional change


Revision tags: matt-premerge-20091211 yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 jym-xensuspend-nbase
# 1.176 03-Jul-2009 elad

Where possible, extract the file-system's access() routine to two internal
functions: the first checking if the operation is possible (regardless of
permissions), the second checking file-system permissions, ACLs, etc.

Mailing list reference:

http://mail-index.netbsd.org/tech-kern/2009/06/21/msg005311.html


# 1.175 23-Jun-2009 elad

Move the implementation of vaccess() to genfs_can_access(), in line with
the other routines of the same spirit.

Adjust file-system code to use it.

Keep vaccess() for KPI compatibility and to keep element of least
surprise. A "diagnostic" message warning that vaccess() is deprecated will
be printed when it's used (obviously, only in DIAGNOSTIC kernels).

No objections on tech-kern@:

http://mail-index.netbsd.org/tech-kern/2009/06/21/msg005310.html


Revision tags: yamt-nfs-mp-base5
# 1.174 24-May-2009 ad

More changes to improve kern_descrip.c.

- Avoid atomics in more places.
- Remove the per-descriptor mutex, and just use filedesc_t::fd_lock.
It was only being used to synchronize close, and in any case we needed
to take fd_lock to free the descriptor slot.
- Optimize certain paths for the <NDFDFILE case.
- Sprinkle more comments and assertions.
- Cache more stuff in filedesc_t.
- Fix numerous minor bugs spotted along the way.
- Restructure how the open files array is maintained, for clarity and so
that we can eliminate the membar_consumer() call in fd_getfile(). This is
mostly syntactic sugar; the main functional change is that fd_nfiles now
lives alongside the open file array.

Some measurements with libmicro:

- simple file syscalls are like close() are between 1 to 10% faster.
- some nice improvements, e.g. poll(1000) which is ~50% faster.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 nick-hppapmap-base2 jym-xensuspend-base nick-hppapmap-base mjf-devfs2-base
# 1.173 17-Dec-2008 cegger

branches: 1.173.2;
kill MALLOC and FREE macros.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 haad-dm-base2 haad-nbase2 ad-audiomp2-base netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 haad-dm-base
# 1.172 05-Sep-2008 skrll

branches: 1.172.2;
PR/39324 kernel diagnostic assertion "l->l_stat != LSZOMB" failed.

Ignore procs with zero or all LSZOMB LWPs. Get a non-LSZOMB LWP to perform
operations against as part of the deal.

procfs really needs to be updated to support multi-threading fully.
Hi Antti!


# 1.171 05-Sep-2008 skrll

ANSIfy


Revision tags: simonb-wapbl-nbase simonb-wapbl-base
# 1.170 02-Jul-2008 rmind

branches: 1.170.2;
Remove proc_representative_lwp(), use a simple LIST_FIRST() instead.
OK by <ad>.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base
# 1.169 28-Apr-2008 martin

branches: 1.169.2; 1.169.4;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-nfs-mp-base
# 1.168 24-Apr-2008 ad

branches: 1.168.2;
Merge proc::p_mutex and proc::p_smutex into a single adaptive mutex, since
we no longer need to guard against access from hardware interrupt handlers.

Additionally, if cloning a process with CLONE_SIGHAND, arrange to have the
child process share the parent's lock so that signal state may be kept in
sync. Partially addresses PR kern/37437.


# 1.167 24-Apr-2008 ad

Network protocol interrupts can now block on locks, so merge the globals
proclist_mutex and proclist_lock into a single adaptive mutex (proc_lock).
Implications:

- Inspecting process state requires thread context, so signals can no longer
be sent from a hardware interrupt handler. Signal activity must be
deferred to a soft interrupt or kthread.

- As the proc state locking is simplified, it's now safe to take exit()
and wait() out from under kernel_lock.

- The system spends less time at IPL_SCHED, and there is less lock activity.


Revision tags: yamt-pf42-baseX yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14
# 1.166 21-Mar-2008 ad

branches: 1.166.2;
Catch up with descriptor handling changes. See kern_descrip.c revision
1.173 for details.


Revision tags: keiichi-mipv6-nbase nick-net80211-sync-base keiichi-mipv6-base bouyer-xeni386-nbase matt-armv6-nbase mjf-devfs-base hpcarm-cleanup-base
# 1.165 23-Jan-2008 elad

branches: 1.165.6;
Tons of process scope changes.

- Add a KAUTH_PROCESS_SCHEDULER action, to handle scheduler related
requests, and add specific requests for set/get scheduler policy and
set/get scheduler parameters.

- Add a KAUTH_PROCESS_KEVENT_FILTER action, to handle kevent(2) related
requests.

- Add a KAUTH_DEVICE_TTY_STI action to handle requests to TIOCSTI.

- Add requests for the KAUTH_PROCESS_CANSEE action, indicating what
process information is being looked at (entry itself, args, env,
open files).

- Add requests for the KAUTH_PROCESS_RLIMIT action indicating set/get.

- Add requests for the KAUTH_PROCESS_CORENAME action indicating set/get.

- Make bsd44 secmodel code handle the newly added rqeuests appropriately.

All of the above make it possible to issue finer-grained kauth(9) calls in
many places, removing some KAUTH_GENERIC_ISSUSER requests.

- Remove the "CAN" from KAUTH_PROCESS_CAN{KTRACE,PROCFS,PTRACE,SIGNAL}.

Discussed with christos@ and yamt@.


Revision tags: bouyer-xeni386-base matt-armv6-base
# 1.164 02-Jan-2008 ad

Merge vmlocking2 to head.


Revision tags: vmlocking2-base3 yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 vmlocking-nbase jmcneill-pm-base reinoud-bufcleanup-base
# 1.163 26-Nov-2007 pooka

branches: 1.163.2; 1.163.6;
Remove the "struct lwp *" argument from all VFS and VOP interfaces.
The general trend is to remove it from all kernel interfaces and
this is a start. In case the calling lwp is desired, curlwp should
be used.

quick consensus on tech-kern


Revision tags: bouyer-xenamd64-base2 bouyer-xenamd64-base
# 1.162 09-Nov-2007 christos

make the last argument of procfs_dir size_t


# 1.161 07-Nov-2007 ad

Merge from vmlocking:

- pool_cache changes.
- Debugger/procfs locking fixes.
- Other minor changes.


Revision tags: jmcneill-base yamt-x86pmap-base4 yamt-x86pmap-base3 vmlocking-base
# 1.160 10-Oct-2007 ad

branches: 1.160.2; 1.160.4;
Merge from vmlocking:

- Split vnode::v_flag into three fields, depending on field locking.
- simple_lock -> kmutex in a few places.
- Fix some simple locking problems.


# 1.159 08-Oct-2007 ad

Merge file descriptor locking, cwdi locking and cross-call changes
from the vmlocking branch.


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base2 yamt-x86pmap-base matt-mips64-base
# 1.158 22-Jul-2007 pooka

branches: 1.158.4; 1.158.6; 1.158.8; 1.158.10;
Don't allow getcwd() on procfs vnodes and provide "/" as the path
instead of the result from getcwd(). The works around locking
panics caused by namei calling VOP_READLINK while holding on to a
directory lock and getcwd() trying to acquire that lock. The real
fix would be to get rid of getcwd() calls within VOPs (not locking
safe), but that's not a viable option in the netbsd-4 timeframe.

Suggestion for workaround from David Holland.


Revision tags: nick-csl-alignment-base mjf-ufs-trans-base
# 1.157 24-May-2007 agc

branches: 1.157.2;
Extend the Linux emulation of /proc to include

/proc/stat
/proc/loadavg and
/proc/<pid>/statm.

These are only present when -o linux is specified as a mount option
to procfs.

Factor out some common code so that it can be used by a number of
functions.

XXX The values returned in the statm emulation need to be verified.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 1.156 04-Apr-2007 rmind

Unfortunately, missed procfs_proc_unlock() in previous.
Pointed out by pooka@


# 1.155 04-Apr-2007 rmind

procfs_readlink: Handle a possible fail of fd_getfile(), also, we
do not need to check for error again.
CID: 4436


# 1.154 09-Mar-2007 ad

branches: 1.154.2; 1.154.4;
- Make the proclist_lock a mutex. The write:read ratio is unfavourable,
and mutexes are cheaper use than RW locks.
- LOCK_ASSERT -> KASSERT in some places.
- Hold proclist_lock/kernel_lock longer in a couple of places.


# 1.153 04-Mar-2007 christos

Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.


# 1.152 03-Mar-2007 salo

Don't prepend rootvnode to the path in non-NULL case for exe links.
It breaks procfs in chroot.

from <christos>, tested by me.


Revision tags: ad-audiomp-base
# 1.151 19-Feb-2007 pooka

When checking for file validity under pid/, do proper proc->lwp
lookup (fsvo proper) instead of fiddling directly with the lwp
list.


# 1.150 18-Feb-2007 pooka

Don't check for validity of p in lookup for root nodes, since it
will always be NULL. Rather, just call pt_valid with NULL directly
and let it decide if we're a linux mount or not.


# 1.149 17-Feb-2007 pavel

Change the process/lwp flags seen by userland via sysctl back to the
P_*/L_* naming convention, and rename the in-kernel flags to avoid
conflict. (P_ -> PK_, L_ -> LW_ ). Add back the (now unused) LSDEAD
constant.

Restores source compatibility with pre-newlock2 tools like ps or top.

Reviewed by Andrew Doran.


# 1.148 16-Feb-2007 pooka

branches: 1.148.2;
In lookup, when checking for procfs process node validity, target the
process we're trying to get information about through procfs, not
the caller of lookup.

fixes 'ls -l /proc/*/file' panic, which would occur when trying to
lookup "file" for a kernel thread, which doesn't have p->p_textvp.


# 1.147 15-Feb-2007 ad

Need to acquire procp->p_mutex for procfs_dir().


# 1.146 11-Feb-2007 ad

Eliminate a couple of reference count and mutex leaks.


Revision tags: post-newlock2-merge
# 1.145 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 1.144 25-Dec-2006 elad

PR/35226: Johann Franz: Problems with permissions in
/usr/pkg/emul/linux/proc .

Okay mlelstv@


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3
# 1.143 09-Dec-2006 chs

a smorgasbord of improvements to vnode locking and path lookup:
- LOCKPARENT is no longer relevant for lookup(), relookup() or VOP_LOOKUP().
these now always return the parent vnode locked. namei() works as before.
lookup() and various other paths no longer acquire vnode locks in the
wrong order via vrele(). fixes PR 32535.
as a nice side effect, path lookup is also up to 25% faster.
- the above allows us to get rid of PDIRUNLOCK.
- also get rid of WANTPARENT (just use LOCKPARENT and unlock it).
- remove an assumption in layer_node_find() that all file systems implement
a recursive VOP_LOCK() (unionfs doesn't).
- require that all file systems supply vfs_vptofh and vfs_fhtovp routines.
fill in eopnotsupp() for file systems that don't support being exported
and remove the checks for NULL. (layerfs calls these without checking.)
- in union_lookup1(), don't change refcounts in the ISDOTDOT case, just
adjust which vnode is locked. fixes PR 33374.
- apply fixes for ufs_rename() from ufs_vnops.c rev. 1.61 to ext2fs_rename().


# 1.142 04-Dec-2006 christos

From Nicolas Joly: restore previous behavior in procfs_validfile_linux, since
readdir passes a NULL lwp.


# 1.141 03-Dec-2006 elad

Move kauth(9) call to where it belongs. Noticed by Nicolas Joly, thanks!


Revision tags: netbsd-4-base
# 1.140 28-Nov-2006 elad

branches: 1.140.2;
Move ktrace, ptrace, systrace, and procfs to use kauth(9).

First, remove process_checkioperm() calls from MD code. Similar checks
using kauth(9) routines (on the process scope, using appropriate action)
are done in the callers.

Add secmodel back-end to handle each subsystem.


# 1.139 25-Nov-2006 skrll

Expose the 'exe' symlink to the process realpath in NetBSD as well. An
example user is gdb.

OK'd by christos.


# 1.138 16-Nov-2006 christos

__unused removal on arguments; approved by core.


# 1.137 29-Oct-2006 christos

add an "emul" file node.


# 1.136 25-Oct-2006 christos

1. fix procfs_validfile{,_linux} to test for NULL pointers properly.
2. make "exe" entry be a symlink to the executable, instead of pointing
directly to the vnode of the executable.
3. factor out commonly used code.


Revision tags: yamt-splraiseipl-base2
# 1.135 12-Oct-2006 christos

- sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386


# 1.134 20-Sep-2006 manu

Emulate Linux's /proc/devices


Revision tags: abandoned-netbsd-4-base yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base rpaulo-netinet-merge-pcb-base
# 1.133 13-Jun-2006 yamt

branches: 1.133.6; 1.133.8;
use KAUTH_PROCESS_CANSEE rather than CURTAIN where appropriate.


# 1.132 13-Jun-2006 yamt

remove unnecessary arguments from kauth_authorize_process.
ie. make it similar to the one found in apple TN.


# 1.131 07-Jun-2006 kardel

merge FreeBSD timecounters from branch simonb-timecounters
- struct timeval time is gone
time.tv_sec -> time_second
- struct timeval mono_time is gone
mono_time.tv_sec -> time_uptime
- access to time via
{get,}{micro,nano,bin}time()
get* versions are fast but less precise
- support NTP nanokernel implementation (NTP API 4)
- further reading:
Timecounter Paper: http://phk.freebsd.dk/pubs/timecounter.pdf
NTP Nanokernel: http://www.eecis.udel.edu/~mills/ntp/html/kern.html


Revision tags: yamt-pdpolicy-base5 simonb-timecounters-base
# 1.130 14-May-2006 elad

branches: 1.130.2;
integrate kauth.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 elad-kernelauth-base yamt-pdpolicy-base yamt-uio_vmspace-base5
# 1.129 02-Feb-2006 christos

branches: 1.129.2; 1.129.4; 1.129.6; 1.129.8;
PR/32692: Matthew Mondor: linux compatibility in /proc/self should point
directly to the directory containing the pid instead of pointing to
/proc/curproc, because some programs rely on calling readlink on /proc/self
to get the pid.


# 1.128 11-Dec-2005 christos

branches: 1.128.2; 1.128.4;
merge ktrace-lwp.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base ktrace-lwp-base
# 1.127 02-Nov-2005 yamt

merge yamt-vop branch. remove following VOPs.

VOP_BLKATOFF
VOP_VALLOC
VOP_BALLOC
VOP_REALLOCBLKS
VOP_VFREE
VOP_TRUNCATE
VOP_UPDATE


Revision tags: yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 1.126 01-Oct-2005 atatat

branches: 1.126.2;
Add "cwd" and "root" symlinks to each process's directory. The cwd
link points to the process's current working directory, and the root
link points to the process's root directory. What else would you
expect?

For directories that are out of reach (caller is in a chroot, target
process is in a different chroot, etc), the links point to "/"
instead.


# 1.125 11-Sep-2005 elad

Implement curtain for procfs.


# 1.124 30-Aug-2005 xtraeme

Remove __P()


# 1.123 29-May-2005 christos

branches: 1.123.2;
- sprinkle const
- avoid shadowed variables.


Revision tags: kent-audio2-base
# 1.122 02-Apr-2005 christos

PR/29782: Martin Husemann: procfs can not unmount when some process has its
current directory in curproc. Fix from Pedro Martelletto:
We cannot call vgone() from procfs_inactive() if we are coming from
vclean(). that's what's probably causing the deadlock.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 yamt-km-base4 yamt-km-base3 netbsd-3-base
# 1.121 26-Feb-2005 perry

nuke trailing whitespace


Revision tags: yamt-km-base2 yamt-km-base kent-audio1-beforemerge kent-audio1-base
# 1.120 04-Oct-2004 yamt

branches: 1.120.4; 1.120.6;
procfs_readdir:
- return correct cookie when buffer size is small.
- simplify logic.


# 1.119 04-Oct-2004 yamt

procfs_readdir: remove a redundant assignment.


# 1.118 02-Oct-2004 yamt

procfs_getattr: correct size of /proc/self.


# 1.117 01-Oct-2004 yamt

procfs_readdir:
- fix a locking problem, using proclist_foreach_call. PR/27098.
- correct snprintf size argument.


# 1.116 01-Oct-2004 yamt

procfs_readdir: fix an offset handling bug after addition of /proc/self.


# 1.115 01-Oct-2004 yamt

procfs_readdir: use a list macro.


# 1.114 20-Sep-2004 jdolecek

add 'mounts' file for -o linux, which lists all currently mounted
filesystems; Linux glibc statvfs() uses this to get some of mount flags,
and this file is also useful as /emul/linux/etc/mtab (via symlink)


# 1.113 29-Apr-2004 jrf

Removed remaining caddr_t casts we do not need in miscfs. Recompiled
kernel and ran for a day or so. There are still some caddr_t types in
the arguments of some calls, I will do those separately (later) as
they touch a lot more of the system.
Approved by christos@NetBSD.org.


# 1.112 22-Apr-2004 itojun

sprintf -> snprintf


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.111 15-Feb-2004 jdolecek

unlock the descriptor table simple lock after fd_getfile() call in
procfs_readdir()
fixes procfs locking problems reported on current-users@, problem place
found by enami tsugutomo


# 1.110 30-Oct-2003 simonb

Remove some assigned-to but otherwise unused variables.


# 1.109 27-Sep-2003 darcy

Changes as discussed with itojun on tech-kern. I have modified the enums
to have KFS or PFS differentiators. Further I have wrapped the enum in
procfs in "#ifdef _KERNEL" as it is done in kernfs.

To see the discussion go to http://mail-index.NetBSD.org/tech-kern/2003/09/
and look for "Mismatched enums in include files" in the list.


# 1.108 07-Sep-2003 itojun

remove meaningless line (variable overwritten 2 lines below)


# 1.107 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.


# 1.106 29-Jun-2003 fvdl

branches: 1.106.2;
Back out the lwp/ktrace changes. They contained a lot of colateral damage,
and need to be examined and discussed more.


# 1.105 29-Jun-2003 thorpej

Undo part of the ktrace/lwp changes. In particular:
* Remove the "lwp *" argument that was added to vget(). Turns out
that nothing actually used it!
* Remove the "lwp *" arguments that were added to VFS_ROOT(), VFS_VGET(),
and VFS_FHTOVP(); all they did was pass it to vget() (which, as noted
above, didn't use it).
* Remove all of the "lwp *" arguments to internal functions that were added
just to appease the above.


# 1.104 28-Jun-2003 darrenr

Pass lwp pointers throughtout the kernel, as required, so that the lwpid can
be inserted into ktrace records. The general change has been to replace
"struct proc *" with "struct lwp *" in various function prototypes, pass
the lwp through and use l_proc to get the process pointer when needed.

Bump the kernel rev up to 1.6V


# 1.103 28-May-2003 christos

Add /proc/<pid>/stat for linux compat. j2sdk1.4.2 depends on it.


# 1.102 18-Apr-2003 christos

Make symlinks for directories that point to the actual directory.
Make symlinks to [kqueue] and [misc] for kqueue and misc fds.


# 1.101 17-Apr-2003 jdolecek

do not show nodes corresponding to directory descriptors for process
in fd/ subdirectory, nor allow lookup/open for the nodes
this fixes PR kern/21187 for good, and also avoids interesting directory
locking issues


# 1.100 17-Apr-2003 jdolecek

procfs_readdir(): in Pfd case, only show descriptors of types we want
how to represent (vnodes, fifo, pipes); also use fd_getfile() et al

this avoids annoying EOPNOTSUPP error messages from ls -F and such


# 1.99 17-Apr-2003 jdolecek

procfs_lookup(): use fd_getfile() et al in Pfd case


# 1.98 17-Apr-2003 jdolecek

use fd_getfile() in procfs_getfp(), and FILE_USE()/FILE_UNUSE() the
returned file descriptor pointer appropriately


# 1.97 17-Apr-2003 jdolecek

make some local arrays/variables static + const


# 1.96 10-Apr-2003 jdolecek

use former genfs_eopnotsupp_rele() as genfs_eopnotsupp(), so that vnodes
are vput()/vrele()d as necessary - some filesystems did use the wrong
one for some ops, and it's just safer to not take the chance

based on suggestion by Bill Studenmund


# 1.95 05-Apr-2003 dsl

Remove pointless check against PID_MAX. Let pfind() do the validation.
(The new pid allocation code may decide to allocate pids above PID_MAX.)


# 1.94 25-Feb-2003 jrf

This addresses PR kerm/19989. Thanks to hamajima@nagoya.ydc.co.jp for submitting this patch which enables /proc/uptime for linux emul. Patch reviewed by atatat@netbsd.org and tron@netbsd.org, approved by tron@netbsd.org.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 1.93 04-Jan-2003 martin

Cast off_t expression to long long to match format even on 64 bit
plattforms.

Shouldn't we introduce a PRIoff_t macro to create such format strings?


# 1.92 03-Jan-2003 christos

add LK_CANRECURSE in the locking of /dev/<pid>/fd/<n> and remove the curproc
kludge. Thanks to fvdl.


# 1.91 03-Jan-2003 christos

Implement /proc/<pid>/fd/<n>. This is work in progress. Questionable things:
- Is it ok to convert DTYPE_PIPE to VFIFO and DTYPE_SOCKET to VSOCK?
- XXX: Avoid locking issue in ls -Rl /proc by avoiding curproc
- Does I/O to pipes work?
- XXX: Are there security implications?


Revision tags: fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge gehenna-devsw-base kqueue-base
# 1.90 03-Aug-2002 simonb

Just use the "time" variable in the *_getattr functions instead of a call
to (the potentially expensive) microtime().


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.89 09-May-2002 thorpej

branches: 1.89.2;
Move code shared by procfs and the kernel proper out of procfs and
into the kernel proper (renaming functions from procfs_* to process_*).


Revision tags: eeh-devprop-base newlock-base ifpoll-base
# 1.88 12-Jan-2002 christos

Don't hide the real return code with EPERM.


# 1.87 06-Dec-2001 chs

add a VOP_PUTPAGES method for all the filesystems that don't have pages,
just unlock the interlock.


# 1.86 05-Dec-2001 thorpej

* Allow machine-dependent code to specify hooks for ptrace(2)
(__HAVE_PTRACE_MACHDEP) and procfs (__HAVE_PROCFS_MACHDEP).
These changes will allow platforms like x86 (XMM) and PowerPC
(AltiVec) to export extended register sets in a sane manner.

* Use __HAVE_PTRACE_MACHDEP to export x86 XMM registers (standard
FP + SSE/SSE2) using PT_{GET,SET}XMMREGS (in the machdep
ptrace request space).
* Use __HAVE_PROCFS_MACHDEP to export x86 XMM registers via
/proc/N/xmmregs in procfs.


Revision tags: thorpej-mips-cache-base
# 1.85 10-Nov-2001 lukem

add RCSIDs


# 1.84 06-Nov-2001 simonb

Remove some variables that are set but never used.


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base
# 1.83 31-Aug-2001 chs

branches: 1.83.2; 1.83.4;
map files are zero-length.


# 1.82 03-Jun-2001 chs

branches: 1.82.2;
procfs_bmap() should never be called, make it a "bad op".
let procfs_mmap() use the default error method.


Revision tags: thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 1.81 14-Apr-2001 kleink

In procfs_readdir(), give /proc/# directories DT_DIR (rather than DT_REG).


# 1.80 30-Mar-2001 fvdl

Bump va_blocksize for the map files some more, so that programs with
quite a few mappings have a chance of being handled correctly if
st_blksize is looked at.


# 1.79 29-Mar-2001 fvdl

For -o linux mounts, add some code to emulate /proc/#/maps.
Needs NAMECACHE_ENTER_REVERSE to include filenames.


# 1.78 21-Feb-2001 jdolecek

branches: 1.78.2;
make some more constant arrays 'const'


# 1.77 22-Jan-2001 jdolecek

make filesystem vnodeop, specop, fifoop and vnodeopv_* arrays const


# 1.76 17-Jan-2001 fvdl

Add a few linux-style files, only enabled when -o linux is specified
for the mount. Currently these are /proc/cpuinfo and /proc/meminfo.
The former only does something on i386 right now.


# 1.75 24-Nov-2000 chs

remove dead code and other misc cleanup.


# 1.74 09-Aug-2000 tv

Only show the "exe" entry to Linux processes, suggested by christos.
Since there are actually three struct emul's for linux, use the e_name
field to determine eligibility with strcmp().


# 1.73 09-Aug-2000 tv

Some versions of Linux libc look for /proc/.../exe instead of /proc/../file.
Add an entry for "exe" that is the same as "file", provided only if
COMPAT_LINUX is set.


# 1.72 03-Aug-2000 thorpej

MALLOC()/FREE() are not to be used for variable sized allocations.


# 1.71 28-Jun-2000 mrg

<vm/vm.h> -> <uvm/uvm_extern.h>


Revision tags: netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 1.70 30-Mar-2000 simonb

branches: 1.70.4;
Delete duplicate declaration of atopid().


Revision tags: chs-ubc2-newbase wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base fvdl-softdep-base
# 1.69 02-Sep-1999 thorpej

branches: 1.69.2; 1.69.8;
Make /proc/self a symlink to /proc/curproc. I've observed Linux programs
that expect /proc/self/cmdline to exist.


# 1.68 25-Aug-1999 sommerfeld

Change variable used for directory offset from "int" to "off_t".
Overkill, but avoids a host of truncation problems.


# 1.67 24-Aug-1999 sommerfeld

Fix PR8270:

Problem turned out to be due to improper handling of reads beyond EOF:
they should just return without error with the uio unchanged, and the
caller will recognize this as a zero-byte return (EOF).

The previous fix to protect directory reads against bogus uio_offset
values returned EINVAL, which broke mount -o union, which only
union'ed in the lower directory if the upper directory cleanly
returned EOF.

While we're here, protect kernfs as well.


# 1.66 14-Aug-1999 christos

protect against large uio_offset


# 1.65 03-Aug-1999 wrstuden

Add support for fcntl(2) to generate VOP_FCNTL calls. Any fcntl
call with F_FSCTL set and F_SETFL calls generate calls to a new
fileop fo_fcntl. Add genfs_fcntl() and soo_fcntl() which return 0
for F_SETFL and EOPNOTSUPP otherwise. Have all leaf filesystems
use genfs_fcntl().

Reviewed by: thorpej
Tested by: wrstuden


Revision tags: chs-ubc2-base
# 1.64 25-Jul-1999 thorpej

Add calls to lock the proclist as appropriate.


# 1.63 14-Jul-1999 thorpej

Fix a paste-o in procfs_lookup() introduced with the vnode locking changes.
Fixes PR #7961, Mario Kemper <magick@bundy.lip.owl.de>.


# 1.62 08-Jul-1999 wrstuden

Bump osrelease to 1.4E. Add layerfs files, remove null_subr.c.

Update coda to new struct lock in struct vnode.

make fdescfs, kernfs, portalfs, and procfs actually lock their vnodes.
It's not that hard.

Make unionfs set v_vnlock = NULL so any overlayed fs will call its
VOP_LOCK.


Revision tags: kame_141_19991130 netbsd-1-4-PATCH001 kame_14_19990705 kame_14_19990628 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.61 12-Mar-1999 christos

branches: 1.61.2; 1.61.4;
PR/7143: Jaromir Docelek: Add procfs/cmdline from Linux emulation


# 1.60 25-Jan-1999 msaitoh

Add /proc/#/map. From FreeBSD.


Revision tags: kenh-if-detach-base chs-ubc-base
# 1.59 08-Sep-1998 thorpej

- Use proclists[], rather than checking allproc and zombproc explicitly.
- Add some comments about locking.


# 1.58 13-Aug-1998 kleink

Per POSIX, fail with EINVAL if advisory locking is attempted on a file type
that doesn't support it, rather than using a homegrown EBADF or EOPNOTSUPP.


# 1.57 10-Aug-1998 matthias

create miscfs/genfs/genfs_vnops.c:genfs_enoioctl and make all the other
filesystems use it instead of a private version.


# 1.56 09-Aug-1998 perry

bzero->memset, bcopy->memcpy, bcmp->memcmp


# 1.55 03-Aug-1998 kleink

Recognize _PC_SYNC_IO.


Revision tags: eeh-paddr_t-base
# 1.54 21-Apr-1998 fvdl

procfs_readdir: in case of error, check if cookies actually have
been allocated before freeing them. From Wolfgang Solfrank.


# 1.53 01-Mar-1998 fvdl

Merge with Lite2 + local changes


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base marc-pcmcia-base
# 1.52 10-Oct-1997 fvdl

Bump last argument to VOP_READDIR to off_t (from u_long).


Revision tags: thorpej-signal-base
# 1.51 27-Aug-1997 thorpej

Fix a reversed argument which caused procfs_checkioperm() to always return
"OK". Add a few comments to avoid further confusion.


# 1.50 12-Aug-1997 thorpej

Fix the procfs hole described on current-users, similar to a fix for
FreeBSD by Sean Eric Fagan, but a bit different. This makes the checks
in the same places as sef's FreeBSD patch, but does not hardcode the
"kmem" group into the kernel, and also does a check identical to the
(3) and (4) checks in the NetBSD ptrace(2):

(1) it's not owned by you, or is set-id on exec (unless
you're root), or

(2) it's init, which controls the security level of the
entire system, and the system was not compiled with
permanently insecure mode turned on.


Revision tags: marc-pcmcia-bp
# 1.49 08-May-1997 mycroft

branches: 1.49.4;
Pass the vnode type to vaccess(), and use it when checking VEXEC. Make sure
that the mode bits passed to vaccess() and returned by foo_getattr() contain
only permission bits.


# 1.48 05-May-1997 mycroft

Need stat.h.


# 1.47 05-May-1997 mycroft

Eliminate bogus uses of V{READ,WRITE,EXEC}. Use S_I[RWX]{USR,GRP,OTH} where
appropriate.


# 1.46 28-Apr-1997 mycroft

Minor code cleanup.


Revision tags: is-newarp-before-merge is-newarp-base
# 1.45 25-Oct-1996 cgd

define path name string variables that we should not (and, thankfully, do
not) modify as 'const char *' rather 'char *'.


# 1.44 13-Oct-1996 christos

backout previous kprintf changes


# 1.43 10-Oct-1996 christos

printf -> kprintf, sprintf -> ksprintf


# 1.42 07-Sep-1996 mycroft

Implement poll(2).


# 1.41 01-Sep-1996 mycroft

Add a set of generic file system operations that most file systems use.
Also, fix some time stamp bogosities.


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 1.40 16-Mar-1996 christos

Fix printf format follies.


# 1.39 13-Feb-1996 mycroft

GC *_nullop(). Minor nits.


# 1.38 12-Feb-1996 christos

close PR/2063: procfs_rw prototyped twice with different prototypes


# 1.37 09-Feb-1996 christos

miscfs prototype changes


# 1.36 09-Feb-1996 mycroft

Fix vop_link, vop_symlink, and vop_remove semantics in several ways:
* Change the argument names to vop_link so they actually make sense.
* Implement vop_link and vop_symlink for all file systems, so they do proper
cleanup.
* Require the file system to decide whether or not linking and unlinking of
directories is allowed, and disable it for all current file systems.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.35 09-Oct-1995 mycroft

Use the index number as the cookie, rather than multiplying by UIO_MX.


# 1.34 09-Oct-1995 mycroft

Add support for cookies, mostly from Greg Hudson.


# 1.33 15-Apr-1995 cgd

fix timeval vs. timespec warnings


# 1.32 03-Feb-1995 mycroft

Return EROFS rather than ENOENT in many cases. Also some cosmetic cleanup.


# 1.31 27-Dec-1994 mycroft

Format police.


# 1.30 24-Dec-1994 ws

Implement and use a common access checking routine


# 1.29 14-Dec-1994 mycroft

Remove a_fp.


# 1.28 14-Nov-1994 christos

fixed struct comment


# 1.27 30-Oct-1994 cgd

be more careful with types, also pull in headers where necessary.


# 1.26 20-Oct-1994 cgd

update for new syscall args description mechanism


# 1.25 30-Aug-1994 mycroft

Convert process, file, and namei lists and hash tables to use queue.h.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.24 29-Jun-1994 cgd

New RCS ID's, take two. they're more aesthecially pleasant, and use 'NetBSD'


# 1.23 16-Jun-1994 mycroft

Remove an unneeded test.


# 1.22 15-Jun-1994 mycroft

Minor update from JSP after merging my changes.


# 1.21 08-Jun-1994 mycroft

Update to 4.4-Lite fs code, with local changes.


# 1.20 05-May-1994 cgd

lots of changes: prototype migration, move lots of variables, definitions,
and structure elements around. kill some unnecessary type and macro
definitions. standardize clock handling. More changes than you'd want.


# 1.19 15-Apr-1994 cgd

forgot these...


# 1.18 12-Apr-1994 cgd

be a bit smarter about determining if files shouldn't be seen by the user.
Also, DON'T allow a lookup to succeed on a file that's not visible!


# 1.17 15-Feb-1994 mycroft

Undo last change; executables is `file', not `a.out'.


# 1.16 14-Feb-1994 ws

Rename file -> a.out


# 1.15 14-Feb-1994 ws

Don't try to show a file for a process if there is none


# 1.14 28-Jan-1994 cgd

make a fpregs file.


# 1.13 20-Jan-1994 ws

Make procfs really work for debugging.
Implement not & notepg files in procfs.


# 1.12 09-Jan-1994 ws

Bug fixes and enhancements:
Make NFS serving work (BUT DON'T USE "attach" TO /proc/*/ctl FOR NOW!!!)
Make `curproc' a symbolic link
Add `.' and `..' entries to the directories.
Return better guesses on the size of the files.


# 1.11 05-Jan-1994 cgd

return size of 'reg' from getattr()


# 1.10 05-Jan-1994 cgd

make it compile (cleanly) for us


# 1.9 05-Jan-1994 cgd

add new procfs code, from Jan-Simon Pendry, jsp@sequent.com.
This is pretty-much "virgin", so that diffs can be done later.


# 1.8 18-Dec-1993 mycroft

Canonicalize all #includes.


Revision tags: magnum-base
# 1.7 16-Sep-1993 cgd

kill volatile warning.


# 1.6 07-Sep-1993 ws

branches: 1.6.2;
Changes to VFS readdir semantics
NFS changes for better cookie support
ISOFS changes for better Rockridge support and support for generation numbers


# 1.5 26-Aug-1993 pk

Implement setattr: mode for process entries; mode + uid/gid for the
PROCFS root directory.
Fixed omission in pfs_root() which came to light as a result of the above:
hold on to vnode for root dir.


# 1.4 25-Aug-1993 pk

Fixed improperly initialized nfsnode in pfs_lookup()


# 1.3 24-Aug-1993 pk

copyright update.


# 1.2 24-Aug-1993 pk

Rcs Id added.


# 1.1 24-Aug-1993 pk

branches: 1.1.1;
Initial version of a proc filesystem.


# 1.202 31-Dec-2017 christos

Add an environ node


Revision tags: tls-maxphys-base-20171202
# 1.201 01-Dec-2017 christos

Allow procfs_kqfilter, since we allow poll. "go" does it.


# 1.200 08-Nov-2017 christos

fix locking, remove error(1) comments.


# 1.199 08-Nov-2017 christos

use p->p_path, remove unused code.


# 1.198 28-Aug-2017 kamil

Remove the filesystem tracing feature

This is a legacy interface from 4.4BSD, and it was
introduced to overcome shortcomings of ptrace(2) at that time, which are
no longer relevant (performance). Today /proc/#/ctl offers a narrow
subset of ptrace(2) commands and is not applicable for modern
applications use beyond simplistic tracing scenarios.

This removal will simplify kernel internals. Users will still be able to
use all the other /proc files.

This change won't affect other procfs files neither Linux compat
features within mount_procfs(8). /proc/#/ctl isn't available on Linux.

Remove:
- /proc/#/ctl from mount_procfs(8)
- P_FSTRACE note from the documentation of ps(1)
- /proc/#/ctl and filesystem tracing documentation from mount_procfs(8)
- KAUTH_REQ_PROCESS_PROCFS_CTL documentation from kauth(9)
- source code file miscfs/procfs/procfs_ctl.c
- PFSctl and procfs_doctl() from sys/miscfs/procfs/procfs.h
- KAUTH_REQ_PROCESS_PROCFS_CTL from sys/sys/kauth.h
- PSL_FSTRACE (0x00010000) from sys/sys/proc.h
- P_FSTRACE (0x00010000) from sys/sys/sysctl.h

Reduce code complexity after removal of this functionality.

Update TODO.ptrace accordingly: remove two entries about /proc tracing.

Do not keep legacy notes as comments in the headers about removed
PSL_FSTRACE / P_FSTRACE, as this interface had little number of users
(close or equal to zero).

Proposed on tech-kern@.

All filesystem tracing utility users are encouraged to switch to ptrace(2).

Sponsored by <The NetBSD Foundation>


Revision tags: matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base
# 1.197 26-May-2017 riastradh

Make VOP_RECLAIM do the last unlock of the vnode.

VOP_RECLAIM naturally has exclusive access to the vnode, so having it
locked on entry is not strictly necessary -- but it means if there
are any final operations that must be done on the vnode, such as
ffs_update, requiring exclusive access to it, we can now kassert that
the vnode is locked in those operations.

We can't just have the caller release the last lock because some file
systems don't use genfs_lock, and require the vnode to remain valid
for VOP_UNLOCK to work, notably unionfs.


Revision tags: prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.196 11-Apr-2017 riastradh

Make VOP_INACTIVE preserve vnode lock on return.

Discussed on tech-kern:
https://mail-index.netbsd.org/tech-kern/2017/04/01/msg021751.html

Ride 7.99.68, a bumpy bus of incremental vfs improvements!


Revision tags: jdolecek-ncq-base
# 1.195 30-Mar-2017 christos

add an auxv node.


Revision tags: pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004 localcount-20160914
# 1.194 20-Aug-2016 hannken

branches: 1.194.2;
Remove now obsolete operation vcache_remove().

Welcome to 7.99.36


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 nick-nhusb-base-20150921 nick-nhusb-base-20150606
# 1.193 20-Apr-2015 riastradh

branches: 1.193.2;
Make VOP_LINK return directory still locked and referenced.

Ride 7.99.10 bump.


Revision tags: nick-nhusb-base-20150406 nick-nhusb-base
# 1.192 05-Sep-2014 matt

branches: 1.192.2;
Try not to use f_data, use f_{vnode,socket,pipe,mqueue,kqueue,ksem} to get
a correctly typed pointer.


Revision tags: netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.191 27-Jul-2014 hannken

Change procfs from hashlist to vcache.
- Key is (type, pid, fd)
- Remove argument "p" from procfs_allocvp(). It is only used
when "type == PFSfd". Lookup the proc with proc_find() when
procfs_loadvnode() needs it.
- Use a vfs_vnode_iterator for procfs_revoke_vnodes().


# 1.190 25-Jul-2014 dholland

Add VOP_FALLOCATE and VOP_FDISCARD to every vnode ops table I can
find.

The filesystem ones all call genfs_eopnotsupp - right now I am only
implementing the plumbing and we can implement fallocate and/or
fdiscard for files later.

The device ones call spec_fallocate (which is also genfs_eopnotsupp)
and spec_fdiscard, which dispatches to the device-level op.

The fifo ones all call vn_fifo_bypass, which also ends up being
EOPNOTSUPP.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base
# 1.189 07-Feb-2014 hannken

branches: 1.189.2;
Change vnode operation lookup to return the resulting vnode *vpp unlocked.
Change cache_lookup() to return an unlocked vnode.

Discussed on tech-kern@

Welcome to 6.99.31


# 1.188 23-Jan-2014 hannken

Change vnode operations create, mknod, mkdir and symlink to return
the resulting vnode *vpp unlocked.

Discussed on tech-kern@

Welcome to 6.99.30


# 1.187 17-Jan-2014 hannken

Change vnode operations create, mknod, mkdir and symlink to keep the
directory node dvp locked on return.

Discussed on tech-kern@

Welcome to 6.99.29


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base
# 1.186 18-Mar-2013 plunky

branches: 1.186.6;
C99 section 6.7.2.3 (Tags) Note 3 states that:

A type specifier of the form

enum identifier

without an enumerator list shall only appear after the type it
specifies is complete.

which means that we cannot pass an "enum vtype" argument to
kauth_access_action() without fully specifying the type first.
Unfortunately there is a complicated include file loop which
makes that difficult, so convert this minimal function into a
macro (and capitalize it).

(ok elad@)


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 1.185 25-Nov-2012 christos

do something reasonable with kernel semaphores.


Revision tags: yamt-pagecache-base6 jmcneill-usbmp-base10
# 1.184 28-May-2012 christos

branches: 1.184.2;
add a task process subdirectory for emul linux


Revision tags: yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 1.183 13-Mar-2012 elad

Replace the remaining KAUTH_GENERIC_ISSUSER authorization calls with
something meaningful. All relevant documentation has been updated or
written.

Most of these changes were brought up in the following messages:

http://mail-index.netbsd.org/tech-kern/2012/01/18/msg012490.html
http://mail-index.netbsd.org/tech-kern/2012/01/19/msg012502.html
http://mail-index.netbsd.org/tech-kern/2012/02/17/msg012728.html

Thanks to christos, manu, njoly, and jmmv for input.

Huge thanks to pgoyette for spinning these changes through some build
cycles and ATF.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.182 04-Sep-2011 jmcneill

branches: 1.182.2; 1.182.6;
PR# kern/45021: Please support /emul/linux/proc/version

Add /proc/version for procfs with -o linux. The version reported depends
on the emulation type of the calling process:

$ cat /proc/version
NetBSD version 5.99.55 (netbsd@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) NetBSD 5.99.55 (GENERIC) #39: Sun Sep 4 09:10:05 EDT 2011

$ /emul/linux/bin/cat /proc/version
Linux version 2.6.18 (linux@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) #0 Wed Mar 3 03:03:03 PST 2010

$ /emul/linux32/bin/cat /proc/version
Linux version 2.6.18 (linux32@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) #0 Wed Mar 3 03:03:03 PST 2010


# 1.181 23-Jun-2011 christos

From Aleksey Cheusov: Don't make it easy for compromised systems to bypass
ASLR protections by providing the mapping addresses of programs to everyone.


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base matt-mips64-premerge-20101231 uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10 rmind-uvmplock-base
# 1.180 01-Jul-2010 rmind

Remove pfind() and pgfind(), fix locking in various broken uses of these.
Rename real routines to proc_find() and pgrp_find(), remove PFIND_* flags
and have consistent behaviour. Provide proc_find_raw() for special cases.
Fix memory leak in sysctl_proc_corename().

COMPAT_LINUX: rework ptrace() locking, minimise differences between
different versions per-arch.

Note: while this change adds some formal cosmetics for COMPAT_DARWIN and
COMPAT_IRIX - locking there is utterly broken (for ages).

Fixes PR/43176.


# 1.179 24-Jun-2010 hannken

Clean up vnode lock operations pass 2:

VOP_UNLOCK(vp, flags) -> VOP_UNLOCK(vp): Remove the unneeded flags argument.

Welcome to 5.99.32.

Discussed on tech-kern.


# 1.178 08-Jun-2010 hannken

Procfs_lookup() does not lookup directory descriptors in the fd/
subdirectory. There is no need for recursive vnode locking here.

Ok: Christos Zoulas <christos@netbsd.org>


Revision tags: uebayasi-xip-base1 yamt-nfs-mp-base9 uebayasi-xip-base
# 1.177 08-Jan-2010 pooka

branches: 1.177.2; 1.177.4;
The VATTR_NULL/VREF/VHOLD/HOLDRELE() macros lost their will to live
years ago when the kernel was modified to not alter ABI based on
DIAGNOSTIC, and now just call the respective function interfaces
(in lowercase). Plenty of mix'n match upper/lowercase has creeped
into the tree since then. Nuke the macros and convert all callsites
to lowercase.

no functional change


Revision tags: matt-premerge-20091211 yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 jym-xensuspend-nbase
# 1.176 03-Jul-2009 elad

Where possible, extract the file-system's access() routine to two internal
functions: the first checking if the operation is possible (regardless of
permissions), the second checking file-system permissions, ACLs, etc.

Mailing list reference:

http://mail-index.netbsd.org/tech-kern/2009/06/21/msg005311.html


# 1.175 23-Jun-2009 elad

Move the implementation of vaccess() to genfs_can_access(), in line with
the other routines of the same spirit.

Adjust file-system code to use it.

Keep vaccess() for KPI compatibility and to keep element of least
surprise. A "diagnostic" message warning that vaccess() is deprecated will
be printed when it's used (obviously, only in DIAGNOSTIC kernels).

No objections on tech-kern@:

http://mail-index.netbsd.org/tech-kern/2009/06/21/msg005310.html


Revision tags: yamt-nfs-mp-base5
# 1.174 24-May-2009 ad

More changes to improve kern_descrip.c.

- Avoid atomics in more places.
- Remove the per-descriptor mutex, and just use filedesc_t::fd_lock.
It was only being used to synchronize close, and in any case we needed
to take fd_lock to free the descriptor slot.
- Optimize certain paths for the <NDFDFILE case.
- Sprinkle more comments and assertions.
- Cache more stuff in filedesc_t.
- Fix numerous minor bugs spotted along the way.
- Restructure how the open files array is maintained, for clarity and so
that we can eliminate the membar_consumer() call in fd_getfile(). This is
mostly syntactic sugar; the main functional change is that fd_nfiles now
lives alongside the open file array.

Some measurements with libmicro:

- simple file syscalls are like close() are between 1 to 10% faster.
- some nice improvements, e.g. poll(1000) which is ~50% faster.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 nick-hppapmap-base2 jym-xensuspend-base nick-hppapmap-base mjf-devfs2-base
# 1.173 17-Dec-2008 cegger

branches: 1.173.2;
kill MALLOC and FREE macros.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 haad-dm-base2 haad-nbase2 ad-audiomp2-base netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 haad-dm-base
# 1.172 05-Sep-2008 skrll

branches: 1.172.2;
PR/39324 kernel diagnostic assertion "l->l_stat != LSZOMB" failed.

Ignore procs with zero or all LSZOMB LWPs. Get a non-LSZOMB LWP to perform
operations against as part of the deal.

procfs really needs to be updated to support multi-threading fully.
Hi Antti!


# 1.171 05-Sep-2008 skrll

ANSIfy


Revision tags: simonb-wapbl-nbase simonb-wapbl-base
# 1.170 02-Jul-2008 rmind

branches: 1.170.2;
Remove proc_representative_lwp(), use a simple LIST_FIRST() instead.
OK by <ad>.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base
# 1.169 28-Apr-2008 martin

branches: 1.169.2; 1.169.4;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-nfs-mp-base
# 1.168 24-Apr-2008 ad

branches: 1.168.2;
Merge proc::p_mutex and proc::p_smutex into a single adaptive mutex, since
we no longer need to guard against access from hardware interrupt handlers.

Additionally, if cloning a process with CLONE_SIGHAND, arrange to have the
child process share the parent's lock so that signal state may be kept in
sync. Partially addresses PR kern/37437.


# 1.167 24-Apr-2008 ad

Network protocol interrupts can now block on locks, so merge the globals
proclist_mutex and proclist_lock into a single adaptive mutex (proc_lock).
Implications:

- Inspecting process state requires thread context, so signals can no longer
be sent from a hardware interrupt handler. Signal activity must be
deferred to a soft interrupt or kthread.

- As the proc state locking is simplified, it's now safe to take exit()
and wait() out from under kernel_lock.

- The system spends less time at IPL_SCHED, and there is less lock activity.


Revision tags: yamt-pf42-baseX yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14
# 1.166 21-Mar-2008 ad

branches: 1.166.2;
Catch up with descriptor handling changes. See kern_descrip.c revision
1.173 for details.


Revision tags: keiichi-mipv6-nbase nick-net80211-sync-base keiichi-mipv6-base bouyer-xeni386-nbase matt-armv6-nbase mjf-devfs-base hpcarm-cleanup-base
# 1.165 23-Jan-2008 elad

branches: 1.165.6;
Tons of process scope changes.

- Add a KAUTH_PROCESS_SCHEDULER action, to handle scheduler related
requests, and add specific requests for set/get scheduler policy and
set/get scheduler parameters.

- Add a KAUTH_PROCESS_KEVENT_FILTER action, to handle kevent(2) related
requests.

- Add a KAUTH_DEVICE_TTY_STI action to handle requests to TIOCSTI.

- Add requests for the KAUTH_PROCESS_CANSEE action, indicating what
process information is being looked at (entry itself, args, env,
open files).

- Add requests for the KAUTH_PROCESS_RLIMIT action indicating set/get.

- Add requests for the KAUTH_PROCESS_CORENAME action indicating set/get.

- Make bsd44 secmodel code handle the newly added rqeuests appropriately.

All of the above make it possible to issue finer-grained kauth(9) calls in
many places, removing some KAUTH_GENERIC_ISSUSER requests.

- Remove the "CAN" from KAUTH_PROCESS_CAN{KTRACE,PROCFS,PTRACE,SIGNAL}.

Discussed with christos@ and yamt@.


Revision tags: bouyer-xeni386-base matt-armv6-base
# 1.164 02-Jan-2008 ad

Merge vmlocking2 to head.


Revision tags: vmlocking2-base3 yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 vmlocking-nbase jmcneill-pm-base reinoud-bufcleanup-base
# 1.163 26-Nov-2007 pooka

branches: 1.163.2; 1.163.6;
Remove the "struct lwp *" argument from all VFS and VOP interfaces.
The general trend is to remove it from all kernel interfaces and
this is a start. In case the calling lwp is desired, curlwp should
be used.

quick consensus on tech-kern


Revision tags: bouyer-xenamd64-base2 bouyer-xenamd64-base
# 1.162 09-Nov-2007 christos

make the last argument of procfs_dir size_t


# 1.161 07-Nov-2007 ad

Merge from vmlocking:

- pool_cache changes.
- Debugger/procfs locking fixes.
- Other minor changes.


Revision tags: jmcneill-base yamt-x86pmap-base4 yamt-x86pmap-base3 vmlocking-base
# 1.160 10-Oct-2007 ad

branches: 1.160.2; 1.160.4;
Merge from vmlocking:

- Split vnode::v_flag into three fields, depending on field locking.
- simple_lock -> kmutex in a few places.
- Fix some simple locking problems.


# 1.159 08-Oct-2007 ad

Merge file descriptor locking, cwdi locking and cross-call changes
from the vmlocking branch.


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base2 yamt-x86pmap-base matt-mips64-base
# 1.158 22-Jul-2007 pooka

branches: 1.158.4; 1.158.6; 1.158.8; 1.158.10;
Don't allow getcwd() on procfs vnodes and provide "/" as the path
instead of the result from getcwd(). The works around locking
panics caused by namei calling VOP_READLINK while holding on to a
directory lock and getcwd() trying to acquire that lock. The real
fix would be to get rid of getcwd() calls within VOPs (not locking
safe), but that's not a viable option in the netbsd-4 timeframe.

Suggestion for workaround from David Holland.


Revision tags: nick-csl-alignment-base mjf-ufs-trans-base
# 1.157 24-May-2007 agc

branches: 1.157.2;
Extend the Linux emulation of /proc to include

/proc/stat
/proc/loadavg and
/proc/<pid>/statm.

These are only present when -o linux is specified as a mount option
to procfs.

Factor out some common code so that it can be used by a number of
functions.

XXX The values returned in the statm emulation need to be verified.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 1.156 04-Apr-2007 rmind

Unfortunately, missed procfs_proc_unlock() in previous.
Pointed out by pooka@


# 1.155 04-Apr-2007 rmind

procfs_readlink: Handle a possible fail of fd_getfile(), also, we
do not need to check for error again.
CID: 4436


# 1.154 09-Mar-2007 ad

branches: 1.154.2; 1.154.4;
- Make the proclist_lock a mutex. The write:read ratio is unfavourable,
and mutexes are cheaper use than RW locks.
- LOCK_ASSERT -> KASSERT in some places.
- Hold proclist_lock/kernel_lock longer in a couple of places.


# 1.153 04-Mar-2007 christos

Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.


# 1.152 03-Mar-2007 salo

Don't prepend rootvnode to the path in non-NULL case for exe links.
It breaks procfs in chroot.

from <christos>, tested by me.


Revision tags: ad-audiomp-base
# 1.151 19-Feb-2007 pooka

When checking for file validity under pid/, do proper proc->lwp
lookup (fsvo proper) instead of fiddling directly with the lwp
list.


# 1.150 18-Feb-2007 pooka

Don't check for validity of p in lookup for root nodes, since it
will always be NULL. Rather, just call pt_valid with NULL directly
and let it decide if we're a linux mount or not.


# 1.149 17-Feb-2007 pavel

Change the process/lwp flags seen by userland via sysctl back to the
P_*/L_* naming convention, and rename the in-kernel flags to avoid
conflict. (P_ -> PK_, L_ -> LW_ ). Add back the (now unused) LSDEAD
constant.

Restores source compatibility with pre-newlock2 tools like ps or top.

Reviewed by Andrew Doran.


# 1.148 16-Feb-2007 pooka

branches: 1.148.2;
In lookup, when checking for procfs process node validity, target the
process we're trying to get information about through procfs, not
the caller of lookup.

fixes 'ls -l /proc/*/file' panic, which would occur when trying to
lookup "file" for a kernel thread, which doesn't have p->p_textvp.


# 1.147 15-Feb-2007 ad

Need to acquire procp->p_mutex for procfs_dir().


# 1.146 11-Feb-2007 ad

Eliminate a couple of reference count and mutex leaks.


Revision tags: post-newlock2-merge
# 1.145 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 1.144 25-Dec-2006 elad

PR/35226: Johann Franz: Problems with permissions in
/usr/pkg/emul/linux/proc .

Okay mlelstv@


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3
# 1.143 09-Dec-2006 chs

a smorgasbord of improvements to vnode locking and path lookup:
- LOCKPARENT is no longer relevant for lookup(), relookup() or VOP_LOOKUP().
these now always return the parent vnode locked. namei() works as before.
lookup() and various other paths no longer acquire vnode locks in the
wrong order via vrele(). fixes PR 32535.
as a nice side effect, path lookup is also up to 25% faster.
- the above allows us to get rid of PDIRUNLOCK.
- also get rid of WANTPARENT (just use LOCKPARENT and unlock it).
- remove an assumption in layer_node_find() that all file systems implement
a recursive VOP_LOCK() (unionfs doesn't).
- require that all file systems supply vfs_vptofh and vfs_fhtovp routines.
fill in eopnotsupp() for file systems that don't support being exported
and remove the checks for NULL. (layerfs calls these without checking.)
- in union_lookup1(), don't change refcounts in the ISDOTDOT case, just
adjust which vnode is locked. fixes PR 33374.
- apply fixes for ufs_rename() from ufs_vnops.c rev. 1.61 to ext2fs_rename().


# 1.142 04-Dec-2006 christos

From Nicolas Joly: restore previous behavior in procfs_validfile_linux, since
readdir passes a NULL lwp.


# 1.141 03-Dec-2006 elad

Move kauth(9) call to where it belongs. Noticed by Nicolas Joly, thanks!


Revision tags: netbsd-4-base
# 1.140 28-Nov-2006 elad

branches: 1.140.2;
Move ktrace, ptrace, systrace, and procfs to use kauth(9).

First, remove process_checkioperm() calls from MD code. Similar checks
using kauth(9) routines (on the process scope, using appropriate action)
are done in the callers.

Add secmodel back-end to handle each subsystem.


# 1.139 25-Nov-2006 skrll

Expose the 'exe' symlink to the process realpath in NetBSD as well. An
example user is gdb.

OK'd by christos.


# 1.138 16-Nov-2006 christos

__unused removal on arguments; approved by core.


# 1.137 29-Oct-2006 christos

add an "emul" file node.


# 1.136 25-Oct-2006 christos

1. fix procfs_validfile{,_linux} to test for NULL pointers properly.
2. make "exe" entry be a symlink to the executable, instead of pointing
directly to the vnode of the executable.
3. factor out commonly used code.


Revision tags: yamt-splraiseipl-base2
# 1.135 12-Oct-2006 christos

- sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386


# 1.134 20-Sep-2006 manu

Emulate Linux's /proc/devices


Revision tags: abandoned-netbsd-4-base yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base rpaulo-netinet-merge-pcb-base
# 1.133 13-Jun-2006 yamt

branches: 1.133.6; 1.133.8;
use KAUTH_PROCESS_CANSEE rather than CURTAIN where appropriate.


# 1.132 13-Jun-2006 yamt

remove unnecessary arguments from kauth_authorize_process.
ie. make it similar to the one found in apple TN.


# 1.131 07-Jun-2006 kardel

merge FreeBSD timecounters from branch simonb-timecounters
- struct timeval time is gone
time.tv_sec -> time_second
- struct timeval mono_time is gone
mono_time.tv_sec -> time_uptime
- access to time via
{get,}{micro,nano,bin}time()
get* versions are fast but less precise
- support NTP nanokernel implementation (NTP API 4)
- further reading:
Timecounter Paper: http://phk.freebsd.dk/pubs/timecounter.pdf
NTP Nanokernel: http://www.eecis.udel.edu/~mills/ntp/html/kern.html


Revision tags: yamt-pdpolicy-base5 simonb-timecounters-base
# 1.130 14-May-2006 elad

branches: 1.130.2;
integrate kauth.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 elad-kernelauth-base yamt-pdpolicy-base yamt-uio_vmspace-base5
# 1.129 02-Feb-2006 christos

branches: 1.129.2; 1.129.4; 1.129.6; 1.129.8;
PR/32692: Matthew Mondor: linux compatibility in /proc/self should point
directly to the directory containing the pid instead of pointing to
/proc/curproc, because some programs rely on calling readlink on /proc/self
to get the pid.


# 1.128 11-Dec-2005 christos

branches: 1.128.2; 1.128.4;
merge ktrace-lwp.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base ktrace-lwp-base
# 1.127 02-Nov-2005 yamt

merge yamt-vop branch. remove following VOPs.

VOP_BLKATOFF
VOP_VALLOC
VOP_BALLOC
VOP_REALLOCBLKS
VOP_VFREE
VOP_TRUNCATE
VOP_UPDATE


Revision tags: yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 1.126 01-Oct-2005 atatat

branches: 1.126.2;
Add "cwd" and "root" symlinks to each process's directory. The cwd
link points to the process's current working directory, and the root
link points to the process's root directory. What else would you
expect?

For directories that are out of reach (caller is in a chroot, target
process is in a different chroot, etc), the links point to "/"
instead.


# 1.125 11-Sep-2005 elad

Implement curtain for procfs.


# 1.124 30-Aug-2005 xtraeme

Remove __P()


# 1.123 29-May-2005 christos

branches: 1.123.2;
- sprinkle const
- avoid shadowed variables.


Revision tags: kent-audio2-base
# 1.122 02-Apr-2005 christos

PR/29782: Martin Husemann: procfs can not unmount when some process has its
current directory in curproc. Fix from Pedro Martelletto:
We cannot call vgone() from procfs_inactive() if we are coming from
vclean(). that's what's probably causing the deadlock.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 yamt-km-base4 yamt-km-base3 netbsd-3-base
# 1.121 26-Feb-2005 perry

nuke trailing whitespace


Revision tags: yamt-km-base2 yamt-km-base kent-audio1-beforemerge kent-audio1-base
# 1.120 04-Oct-2004 yamt

branches: 1.120.4; 1.120.6;
procfs_readdir:
- return correct cookie when buffer size is small.
- simplify logic.


# 1.119 04-Oct-2004 yamt

procfs_readdir: remove a redundant assignment.


# 1.118 02-Oct-2004 yamt

procfs_getattr: correct size of /proc/self.


# 1.117 01-Oct-2004 yamt

procfs_readdir:
- fix a locking problem, using proclist_foreach_call. PR/27098.
- correct snprintf size argument.


# 1.116 01-Oct-2004 yamt

procfs_readdir: fix an offset handling bug after addition of /proc/self.


# 1.115 01-Oct-2004 yamt

procfs_readdir: use a list macro.


# 1.114 20-Sep-2004 jdolecek

add 'mounts' file for -o linux, which lists all currently mounted
filesystems; Linux glibc statvfs() uses this to get some of mount flags,
and this file is also useful as /emul/linux/etc/mtab (via symlink)


# 1.113 29-Apr-2004 jrf

Removed remaining caddr_t casts we do not need in miscfs. Recompiled
kernel and ran for a day or so. There are still some caddr_t types in
the arguments of some calls, I will do those separately (later) as
they touch a lot more of the system.
Approved by christos@NetBSD.org.


# 1.112 22-Apr-2004 itojun

sprintf -> snprintf


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.111 15-Feb-2004 jdolecek

unlock the descriptor table simple lock after fd_getfile() call in
procfs_readdir()
fixes procfs locking problems reported on current-users@, problem place
found by enami tsugutomo


# 1.110 30-Oct-2003 simonb

Remove some assigned-to but otherwise unused variables.


# 1.109 27-Sep-2003 darcy

Changes as discussed with itojun on tech-kern. I have modified the enums
to have KFS or PFS differentiators. Further I have wrapped the enum in
procfs in "#ifdef _KERNEL" as it is done in kernfs.

To see the discussion go to http://mail-index.NetBSD.org/tech-kern/2003/09/
and look for "Mismatched enums in include files" in the list.


# 1.108 07-Sep-2003 itojun

remove meaningless line (variable overwritten 2 lines below)


# 1.107 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.


# 1.106 29-Jun-2003 fvdl

branches: 1.106.2;
Back out the lwp/ktrace changes. They contained a lot of colateral damage,
and need to be examined and discussed more.


# 1.105 29-Jun-2003 thorpej

Undo part of the ktrace/lwp changes. In particular:
* Remove the "lwp *" argument that was added to vget(). Turns out
that nothing actually used it!
* Remove the "lwp *" arguments that were added to VFS_ROOT(), VFS_VGET(),
and VFS_FHTOVP(); all they did was pass it to vget() (which, as noted
above, didn't use it).
* Remove all of the "lwp *" arguments to internal functions that were added
just to appease the above.


# 1.104 28-Jun-2003 darrenr

Pass lwp pointers throughtout the kernel, as required, so that the lwpid can
be inserted into ktrace records. The general change has been to replace
"struct proc *" with "struct lwp *" in various function prototypes, pass
the lwp through and use l_proc to get the process pointer when needed.

Bump the kernel rev up to 1.6V


# 1.103 28-May-2003 christos

Add /proc/<pid>/stat for linux compat. j2sdk1.4.2 depends on it.


# 1.102 18-Apr-2003 christos

Make symlinks for directories that point to the actual directory.
Make symlinks to [kqueue] and [misc] for kqueue and misc fds.


# 1.101 17-Apr-2003 jdolecek

do not show nodes corresponding to directory descriptors for process
in fd/ subdirectory, nor allow lookup/open for the nodes
this fixes PR kern/21187 for good, and also avoids interesting directory
locking issues


# 1.100 17-Apr-2003 jdolecek

procfs_readdir(): in Pfd case, only show descriptors of types we want
how to represent (vnodes, fifo, pipes); also use fd_getfile() et al

this avoids annoying EOPNOTSUPP error messages from ls -F and such


# 1.99 17-Apr-2003 jdolecek

procfs_lookup(): use fd_getfile() et al in Pfd case


# 1.98 17-Apr-2003 jdolecek

use fd_getfile() in procfs_getfp(), and FILE_USE()/FILE_UNUSE() the
returned file descriptor pointer appropriately


# 1.97 17-Apr-2003 jdolecek

make some local arrays/variables static + const


# 1.96 10-Apr-2003 jdolecek

use former genfs_eopnotsupp_rele() as genfs_eopnotsupp(), so that vnodes
are vput()/vrele()d as necessary - some filesystems did use the wrong
one for some ops, and it's just safer to not take the chance

based on suggestion by Bill Studenmund


# 1.95 05-Apr-2003 dsl

Remove pointless check against PID_MAX. Let pfind() do the validation.
(The new pid allocation code may decide to allocate pids above PID_MAX.)


# 1.94 25-Feb-2003 jrf

This addresses PR kerm/19989. Thanks to hamajima@nagoya.ydc.co.jp for submitting this patch which enables /proc/uptime for linux emul. Patch reviewed by atatat@netbsd.org and tron@netbsd.org, approved by tron@netbsd.org.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 1.93 04-Jan-2003 martin

Cast off_t expression to long long to match format even on 64 bit
plattforms.

Shouldn't we introduce a PRIoff_t macro to create such format strings?


# 1.92 03-Jan-2003 christos

add LK_CANRECURSE in the locking of /dev/<pid>/fd/<n> and remove the curproc
kludge. Thanks to fvdl.


# 1.91 03-Jan-2003 christos

Implement /proc/<pid>/fd/<n>. This is work in progress. Questionable things:
- Is it ok to convert DTYPE_PIPE to VFIFO and DTYPE_SOCKET to VSOCK?
- XXX: Avoid locking issue in ls -Rl /proc by avoiding curproc
- Does I/O to pipes work?
- XXX: Are there security implications?


Revision tags: fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge gehenna-devsw-base kqueue-base
# 1.90 03-Aug-2002 simonb

Just use the "time" variable in the *_getattr functions instead of a call
to (the potentially expensive) microtime().


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.89 09-May-2002 thorpej

branches: 1.89.2;
Move code shared by procfs and the kernel proper out of procfs and
into the kernel proper (renaming functions from procfs_* to process_*).


Revision tags: eeh-devprop-base newlock-base ifpoll-base
# 1.88 12-Jan-2002 christos

Don't hide the real return code with EPERM.


# 1.87 06-Dec-2001 chs

add a VOP_PUTPAGES method for all the filesystems that don't have pages,
just unlock the interlock.


# 1.86 05-Dec-2001 thorpej

* Allow machine-dependent code to specify hooks for ptrace(2)
(__HAVE_PTRACE_MACHDEP) and procfs (__HAVE_PROCFS_MACHDEP).
These changes will allow platforms like x86 (XMM) and PowerPC
(AltiVec) to export extended register sets in a sane manner.

* Use __HAVE_PTRACE_MACHDEP to export x86 XMM registers (standard
FP + SSE/SSE2) using PT_{GET,SET}XMMREGS (in the machdep
ptrace request space).
* Use __HAVE_PROCFS_MACHDEP to export x86 XMM registers via
/proc/N/xmmregs in procfs.


Revision tags: thorpej-mips-cache-base
# 1.85 10-Nov-2001 lukem

add RCSIDs


# 1.84 06-Nov-2001 simonb

Remove some variables that are set but never used.


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base
# 1.83 31-Aug-2001 chs

branches: 1.83.2; 1.83.4;
map files are zero-length.


# 1.82 03-Jun-2001 chs

branches: 1.82.2;
procfs_bmap() should never be called, make it a "bad op".
let procfs_mmap() use the default error method.


Revision tags: thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 1.81 14-Apr-2001 kleink

In procfs_readdir(), give /proc/# directories DT_DIR (rather than DT_REG).


# 1.80 30-Mar-2001 fvdl

Bump va_blocksize for the map files some more, so that programs with
quite a few mappings have a chance of being handled correctly if
st_blksize is looked at.


# 1.79 29-Mar-2001 fvdl

For -o linux mounts, add some code to emulate /proc/#/maps.
Needs NAMECACHE_ENTER_REVERSE to include filenames.


# 1.78 21-Feb-2001 jdolecek

branches: 1.78.2;
make some more constant arrays 'const'


# 1.77 22-Jan-2001 jdolecek

make filesystem vnodeop, specop, fifoop and vnodeopv_* arrays const


# 1.76 17-Jan-2001 fvdl

Add a few linux-style files, only enabled when -o linux is specified
for the mount. Currently these are /proc/cpuinfo and /proc/meminfo.
The former only does something on i386 right now.


# 1.75 24-Nov-2000 chs

remove dead code and other misc cleanup.


# 1.74 09-Aug-2000 tv

Only show the "exe" entry to Linux processes, suggested by christos.
Since there are actually three struct emul's for linux, use the e_name
field to determine eligibility with strcmp().


# 1.73 09-Aug-2000 tv

Some versions of Linux libc look for /proc/.../exe instead of /proc/../file.
Add an entry for "exe" that is the same as "file", provided only if
COMPAT_LINUX is set.


# 1.72 03-Aug-2000 thorpej

MALLOC()/FREE() are not to be used for variable sized allocations.


# 1.71 28-Jun-2000 mrg

<vm/vm.h> -> <uvm/uvm_extern.h>


Revision tags: netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 1.70 30-Mar-2000 simonb

branches: 1.70.4;
Delete duplicate declaration of atopid().


Revision tags: chs-ubc2-newbase wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base fvdl-softdep-base
# 1.69 02-Sep-1999 thorpej

branches: 1.69.2; 1.69.8;
Make /proc/self a symlink to /proc/curproc. I've observed Linux programs
that expect /proc/self/cmdline to exist.


# 1.68 25-Aug-1999 sommerfeld

Change variable used for directory offset from "int" to "off_t".
Overkill, but avoids a host of truncation problems.


# 1.67 24-Aug-1999 sommerfeld

Fix PR8270:

Problem turned out to be due to improper handling of reads beyond EOF:
they should just return without error with the uio unchanged, and the
caller will recognize this as a zero-byte return (EOF).

The previous fix to protect directory reads against bogus uio_offset
values returned EINVAL, which broke mount -o union, which only
union'ed in the lower directory if the upper directory cleanly
returned EOF.

While we're here, protect kernfs as well.


# 1.66 14-Aug-1999 christos

protect against large uio_offset


# 1.65 03-Aug-1999 wrstuden

Add support for fcntl(2) to generate VOP_FCNTL calls. Any fcntl
call with F_FSCTL set and F_SETFL calls generate calls to a new
fileop fo_fcntl. Add genfs_fcntl() and soo_fcntl() which return 0
for F_SETFL and EOPNOTSUPP otherwise. Have all leaf filesystems
use genfs_fcntl().

Reviewed by: thorpej
Tested by: wrstuden


Revision tags: chs-ubc2-base
# 1.64 25-Jul-1999 thorpej

Add calls to lock the proclist as appropriate.


# 1.63 14-Jul-1999 thorpej

Fix a paste-o in procfs_lookup() introduced with the vnode locking changes.
Fixes PR #7961, Mario Kemper <magick@bundy.lip.owl.de>.


# 1.62 08-Jul-1999 wrstuden

Bump osrelease to 1.4E. Add layerfs files, remove null_subr.c.

Update coda to new struct lock in struct vnode.

make fdescfs, kernfs, portalfs, and procfs actually lock their vnodes.
It's not that hard.

Make unionfs set v_vnlock = NULL so any overlayed fs will call its
VOP_LOCK.


Revision tags: kame_141_19991130 netbsd-1-4-PATCH001 kame_14_19990705 kame_14_19990628 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.61 12-Mar-1999 christos

branches: 1.61.2; 1.61.4;
PR/7143: Jaromir Docelek: Add procfs/cmdline from Linux emulation


# 1.60 25-Jan-1999 msaitoh

Add /proc/#/map. From FreeBSD.


Revision tags: kenh-if-detach-base chs-ubc-base
# 1.59 08-Sep-1998 thorpej

- Use proclists[], rather than checking allproc and zombproc explicitly.
- Add some comments about locking.


# 1.58 13-Aug-1998 kleink

Per POSIX, fail with EINVAL if advisory locking is attempted on a file type
that doesn't support it, rather than using a homegrown EBADF or EOPNOTSUPP.


# 1.57 10-Aug-1998 matthias

create miscfs/genfs/genfs_vnops.c:genfs_enoioctl and make all the other
filesystems use it instead of a private version.


# 1.56 09-Aug-1998 perry

bzero->memset, bcopy->memcpy, bcmp->memcmp


# 1.55 03-Aug-1998 kleink

Recognize _PC_SYNC_IO.


Revision tags: eeh-paddr_t-base
# 1.54 21-Apr-1998 fvdl

procfs_readdir: in case of error, check if cookies actually have
been allocated before freeing them. From Wolfgang Solfrank.


# 1.53 01-Mar-1998 fvdl

Merge with Lite2 + local changes


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base marc-pcmcia-base
# 1.52 10-Oct-1997 fvdl

Bump last argument to VOP_READDIR to off_t (from u_long).


Revision tags: thorpej-signal-base
# 1.51 27-Aug-1997 thorpej

Fix a reversed argument which caused procfs_checkioperm() to always return
"OK". Add a few comments to avoid further confusion.


# 1.50 12-Aug-1997 thorpej

Fix the procfs hole described on current-users, similar to a fix for
FreeBSD by Sean Eric Fagan, but a bit different. This makes the checks
in the same places as sef's FreeBSD patch, but does not hardcode the
"kmem" group into the kernel, and also does a check identical to the
(3) and (4) checks in the NetBSD ptrace(2):

(1) it's not owned by you, or is set-id on exec (unless
you're root), or

(2) it's init, which controls the security level of the
entire system, and the system was not compiled with
permanently insecure mode turned on.


Revision tags: marc-pcmcia-bp
# 1.49 08-May-1997 mycroft

branches: 1.49.4;
Pass the vnode type to vaccess(), and use it when checking VEXEC. Make sure
that the mode bits passed to vaccess() and returned by foo_getattr() contain
only permission bits.


# 1.48 05-May-1997 mycroft

Need stat.h.


# 1.47 05-May-1997 mycroft

Eliminate bogus uses of V{READ,WRITE,EXEC}. Use S_I[RWX]{USR,GRP,OTH} where
appropriate.


# 1.46 28-Apr-1997 mycroft

Minor code cleanup.


Revision tags: is-newarp-before-merge is-newarp-base
# 1.45 25-Oct-1996 cgd

define path name string variables that we should not (and, thankfully, do
not) modify as 'const char *' rather 'char *'.


# 1.44 13-Oct-1996 christos

backout previous kprintf changes


# 1.43 10-Oct-1996 christos

printf -> kprintf, sprintf -> ksprintf


# 1.42 07-Sep-1996 mycroft

Implement poll(2).


# 1.41 01-Sep-1996 mycroft

Add a set of generic file system operations that most file systems use.
Also, fix some time stamp bogosities.


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 1.40 16-Mar-1996 christos

Fix printf format follies.


# 1.39 13-Feb-1996 mycroft

GC *_nullop(). Minor nits.


# 1.38 12-Feb-1996 christos

close PR/2063: procfs_rw prototyped twice with different prototypes


# 1.37 09-Feb-1996 christos

miscfs prototype changes


# 1.36 09-Feb-1996 mycroft

Fix vop_link, vop_symlink, and vop_remove semantics in several ways:
* Change the argument names to vop_link so they actually make sense.
* Implement vop_link and vop_symlink for all file systems, so they do proper
cleanup.
* Require the file system to decide whether or not linking and unlinking of
directories is allowed, and disable it for all current file systems.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.35 09-Oct-1995 mycroft

Use the index number as the cookie, rather than multiplying by UIO_MX.


# 1.34 09-Oct-1995 mycroft

Add support for cookies, mostly from Greg Hudson.


# 1.33 15-Apr-1995 cgd

fix timeval vs. timespec warnings


# 1.32 03-Feb-1995 mycroft

Return EROFS rather than ENOENT in many cases. Also some cosmetic cleanup.


# 1.31 27-Dec-1994 mycroft

Format police.


# 1.30 24-Dec-1994 ws

Implement and use a common access checking routine


# 1.29 14-Dec-1994 mycroft

Remove a_fp.


# 1.28 14-Nov-1994 christos

fixed struct comment


# 1.27 30-Oct-1994 cgd

be more careful with types, also pull in headers where necessary.


# 1.26 20-Oct-1994 cgd

update for new syscall args description mechanism


# 1.25 30-Aug-1994 mycroft

Convert process, file, and namei lists and hash tables to use queue.h.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.24 29-Jun-1994 cgd

New RCS ID's, take two. they're more aesthecially pleasant, and use 'NetBSD'


# 1.23 16-Jun-1994 mycroft

Remove an unneeded test.


# 1.22 15-Jun-1994 mycroft

Minor update from JSP after merging my changes.


# 1.21 08-Jun-1994 mycroft

Update to 4.4-Lite fs code, with local changes.


# 1.20 05-May-1994 cgd

lots of changes: prototype migration, move lots of variables, definitions,
and structure elements around. kill some unnecessary type and macro
definitions. standardize clock handling. More changes than you'd want.


# 1.19 15-Apr-1994 cgd

forgot these...


# 1.18 12-Apr-1994 cgd

be a bit smarter about determining if files shouldn't be seen by the user.
Also, DON'T allow a lookup to succeed on a file that's not visible!


# 1.17 15-Feb-1994 mycroft

Undo last change; executables is `file', not `a.out'.


# 1.16 14-Feb-1994 ws

Rename file -> a.out


# 1.15 14-Feb-1994 ws

Don't try to show a file for a process if there is none


# 1.14 28-Jan-1994 cgd

make a fpregs file.


# 1.13 20-Jan-1994 ws

Make procfs really work for debugging.
Implement not & notepg files in procfs.


# 1.12 09-Jan-1994 ws

Bug fixes and enhancements:
Make NFS serving work (BUT DON'T USE "attach" TO /proc/*/ctl FOR NOW!!!)
Make `curproc' a symbolic link
Add `.' and `..' entries to the directories.
Return better guesses on the size of the files.


# 1.11 05-Jan-1994 cgd

return size of 'reg' from getattr()


# 1.10 05-Jan-1994 cgd

make it compile (cleanly) for us


# 1.9 05-Jan-1994 cgd

add new procfs code, from Jan-Simon Pendry, jsp@sequent.com.
This is pretty-much "virgin", so that diffs can be done later.


# 1.8 18-Dec-1993 mycroft

Canonicalize all #includes.


Revision tags: magnum-base
# 1.7 16-Sep-1993 cgd

kill volatile warning.


# 1.6 07-Sep-1993 ws

branches: 1.6.2;
Changes to VFS readdir semantics
NFS changes for better cookie support
ISOFS changes for better Rockridge support and support for generation numbers


# 1.5 26-Aug-1993 pk

Implement setattr: mode for process entries; mode + uid/gid for the
PROCFS root directory.
Fixed omission in pfs_root() which came to light as a result of the above:
hold on to vnode for root dir.


# 1.4 25-Aug-1993 pk

Fixed improperly initialized nfsnode in pfs_lookup()


# 1.3 24-Aug-1993 pk

copyright update.


# 1.2 24-Aug-1993 pk

Rcs Id added.


# 1.1 24-Aug-1993 pk

branches: 1.1.1;
Initial version of a proc filesystem.


# 1.200 08-Nov-2017 christos

fix locking, remove error(1) comments.


# 1.199 08-Nov-2017 christos

use p->p_path, remove unused code.


# 1.198 28-Aug-2017 kamil

Remove the filesystem tracing feature

This is a legacy interface from 4.4BSD, and it was
introduced to overcome shortcomings of ptrace(2) at that time, which are
no longer relevant (performance). Today /proc/#/ctl offers a narrow
subset of ptrace(2) commands and is not applicable for modern
applications use beyond simplistic tracing scenarios.

This removal will simplify kernel internals. Users will still be able to
use all the other /proc files.

This change won't affect other procfs files neither Linux compat
features within mount_procfs(8). /proc/#/ctl isn't available on Linux.

Remove:
- /proc/#/ctl from mount_procfs(8)
- P_FSTRACE note from the documentation of ps(1)
- /proc/#/ctl and filesystem tracing documentation from mount_procfs(8)
- KAUTH_REQ_PROCESS_PROCFS_CTL documentation from kauth(9)
- source code file miscfs/procfs/procfs_ctl.c
- PFSctl and procfs_doctl() from sys/miscfs/procfs/procfs.h
- KAUTH_REQ_PROCESS_PROCFS_CTL from sys/sys/kauth.h
- PSL_FSTRACE (0x00010000) from sys/sys/proc.h
- P_FSTRACE (0x00010000) from sys/sys/sysctl.h

Reduce code complexity after removal of this functionality.

Update TODO.ptrace accordingly: remove two entries about /proc tracing.

Do not keep legacy notes as comments in the headers about removed
PSL_FSTRACE / P_FSTRACE, as this interface had little number of users
(close or equal to zero).

Proposed on tech-kern@.

All filesystem tracing utility users are encouraged to switch to ptrace(2).

Sponsored by <The NetBSD Foundation>


Revision tags: nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base
# 1.197 26-May-2017 riastradh

Make VOP_RECLAIM do the last unlock of the vnode.

VOP_RECLAIM naturally has exclusive access to the vnode, so having it
locked on entry is not strictly necessary -- but it means if there
are any final operations that must be done on the vnode, such as
ffs_update, requiring exclusive access to it, we can now kassert that
the vnode is locked in those operations.

We can't just have the caller release the last lock because some file
systems don't use genfs_lock, and require the vnode to remain valid
for VOP_UNLOCK to work, notably unionfs.


Revision tags: prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.196 11-Apr-2017 riastradh

Make VOP_INACTIVE preserve vnode lock on return.

Discussed on tech-kern:
https://mail-index.netbsd.org/tech-kern/2017/04/01/msg021751.html

Ride 7.99.68, a bumpy bus of incremental vfs improvements!


Revision tags: jdolecek-ncq-base
# 1.195 30-Mar-2017 christos

add an auxv node.


Revision tags: pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004 localcount-20160914
# 1.194 20-Aug-2016 hannken

branches: 1.194.2;
Remove now obsolete operation vcache_remove().

Welcome to 7.99.36


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 nick-nhusb-base-20150921 nick-nhusb-base-20150606
# 1.193 20-Apr-2015 riastradh

branches: 1.193.2;
Make VOP_LINK return directory still locked and referenced.

Ride 7.99.10 bump.


Revision tags: nick-nhusb-base-20150406 nick-nhusb-base
# 1.192 05-Sep-2014 matt

branches: 1.192.2;
Try not to use f_data, use f_{vnode,socket,pipe,mqueue,kqueue,ksem} to get
a correctly typed pointer.


Revision tags: netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.191 27-Jul-2014 hannken

Change procfs from hashlist to vcache.
- Key is (type, pid, fd)
- Remove argument "p" from procfs_allocvp(). It is only used
when "type == PFSfd". Lookup the proc with proc_find() when
procfs_loadvnode() needs it.
- Use a vfs_vnode_iterator for procfs_revoke_vnodes().


# 1.190 25-Jul-2014 dholland

Add VOP_FALLOCATE and VOP_FDISCARD to every vnode ops table I can
find.

The filesystem ones all call genfs_eopnotsupp - right now I am only
implementing the plumbing and we can implement fallocate and/or
fdiscard for files later.

The device ones call spec_fallocate (which is also genfs_eopnotsupp)
and spec_fdiscard, which dispatches to the device-level op.

The fifo ones all call vn_fifo_bypass, which also ends up being
EOPNOTSUPP.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base
# 1.189 07-Feb-2014 hannken

branches: 1.189.2;
Change vnode operation lookup to return the resulting vnode *vpp unlocked.
Change cache_lookup() to return an unlocked vnode.

Discussed on tech-kern@

Welcome to 6.99.31


# 1.188 23-Jan-2014 hannken

Change vnode operations create, mknod, mkdir and symlink to return
the resulting vnode *vpp unlocked.

Discussed on tech-kern@

Welcome to 6.99.30


# 1.187 17-Jan-2014 hannken

Change vnode operations create, mknod, mkdir and symlink to keep the
directory node dvp locked on return.

Discussed on tech-kern@

Welcome to 6.99.29


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base
# 1.186 18-Mar-2013 plunky

branches: 1.186.6;
C99 section 6.7.2.3 (Tags) Note 3 states that:

A type specifier of the form

enum identifier

without an enumerator list shall only appear after the type it
specifies is complete.

which means that we cannot pass an "enum vtype" argument to
kauth_access_action() without fully specifying the type first.
Unfortunately there is a complicated include file loop which
makes that difficult, so convert this minimal function into a
macro (and capitalize it).

(ok elad@)


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 1.185 25-Nov-2012 christos

do something reasonable with kernel semaphores.


Revision tags: yamt-pagecache-base6 jmcneill-usbmp-base10
# 1.184 28-May-2012 christos

branches: 1.184.2;
add a task process subdirectory for emul linux


Revision tags: yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 1.183 13-Mar-2012 elad

Replace the remaining KAUTH_GENERIC_ISSUSER authorization calls with
something meaningful. All relevant documentation has been updated or
written.

Most of these changes were brought up in the following messages:

http://mail-index.netbsd.org/tech-kern/2012/01/18/msg012490.html
http://mail-index.netbsd.org/tech-kern/2012/01/19/msg012502.html
http://mail-index.netbsd.org/tech-kern/2012/02/17/msg012728.html

Thanks to christos, manu, njoly, and jmmv for input.

Huge thanks to pgoyette for spinning these changes through some build
cycles and ATF.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.182 04-Sep-2011 jmcneill

branches: 1.182.2; 1.182.6;
PR# kern/45021: Please support /emul/linux/proc/version

Add /proc/version for procfs with -o linux. The version reported depends
on the emulation type of the calling process:

$ cat /proc/version
NetBSD version 5.99.55 (netbsd@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) NetBSD 5.99.55 (GENERIC) #39: Sun Sep 4 09:10:05 EDT 2011

$ /emul/linux/bin/cat /proc/version
Linux version 2.6.18 (linux@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) #0 Wed Mar 3 03:03:03 PST 2010

$ /emul/linux32/bin/cat /proc/version
Linux version 2.6.18 (linux32@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) #0 Wed Mar 3 03:03:03 PST 2010


# 1.181 23-Jun-2011 christos

From Aleksey Cheusov: Don't make it easy for compromised systems to bypass
ASLR protections by providing the mapping addresses of programs to everyone.


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base matt-mips64-premerge-20101231 uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10 rmind-uvmplock-base
# 1.180 01-Jul-2010 rmind

Remove pfind() and pgfind(), fix locking in various broken uses of these.
Rename real routines to proc_find() and pgrp_find(), remove PFIND_* flags
and have consistent behaviour. Provide proc_find_raw() for special cases.
Fix memory leak in sysctl_proc_corename().

COMPAT_LINUX: rework ptrace() locking, minimise differences between
different versions per-arch.

Note: while this change adds some formal cosmetics for COMPAT_DARWIN and
COMPAT_IRIX - locking there is utterly broken (for ages).

Fixes PR/43176.


# 1.179 24-Jun-2010 hannken

Clean up vnode lock operations pass 2:

VOP_UNLOCK(vp, flags) -> VOP_UNLOCK(vp): Remove the unneeded flags argument.

Welcome to 5.99.32.

Discussed on tech-kern.


# 1.178 08-Jun-2010 hannken

Procfs_lookup() does not lookup directory descriptors in the fd/
subdirectory. There is no need for recursive vnode locking here.

Ok: Christos Zoulas <christos@netbsd.org>


Revision tags: uebayasi-xip-base1 yamt-nfs-mp-base9 uebayasi-xip-base
# 1.177 08-Jan-2010 pooka

branches: 1.177.2; 1.177.4;
The VATTR_NULL/VREF/VHOLD/HOLDRELE() macros lost their will to live
years ago when the kernel was modified to not alter ABI based on
DIAGNOSTIC, and now just call the respective function interfaces
(in lowercase). Plenty of mix'n match upper/lowercase has creeped
into the tree since then. Nuke the macros and convert all callsites
to lowercase.

no functional change


Revision tags: matt-premerge-20091211 yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 jym-xensuspend-nbase
# 1.176 03-Jul-2009 elad

Where possible, extract the file-system's access() routine to two internal
functions: the first checking if the operation is possible (regardless of
permissions), the second checking file-system permissions, ACLs, etc.

Mailing list reference:

http://mail-index.netbsd.org/tech-kern/2009/06/21/msg005311.html


# 1.175 23-Jun-2009 elad

Move the implementation of vaccess() to genfs_can_access(), in line with
the other routines of the same spirit.

Adjust file-system code to use it.

Keep vaccess() for KPI compatibility and to keep element of least
surprise. A "diagnostic" message warning that vaccess() is deprecated will
be printed when it's used (obviously, only in DIAGNOSTIC kernels).

No objections on tech-kern@:

http://mail-index.netbsd.org/tech-kern/2009/06/21/msg005310.html


Revision tags: yamt-nfs-mp-base5
# 1.174 24-May-2009 ad

More changes to improve kern_descrip.c.

- Avoid atomics in more places.
- Remove the per-descriptor mutex, and just use filedesc_t::fd_lock.
It was only being used to synchronize close, and in any case we needed
to take fd_lock to free the descriptor slot.
- Optimize certain paths for the <NDFDFILE case.
- Sprinkle more comments and assertions.
- Cache more stuff in filedesc_t.
- Fix numerous minor bugs spotted along the way.
- Restructure how the open files array is maintained, for clarity and so
that we can eliminate the membar_consumer() call in fd_getfile(). This is
mostly syntactic sugar; the main functional change is that fd_nfiles now
lives alongside the open file array.

Some measurements with libmicro:

- simple file syscalls are like close() are between 1 to 10% faster.
- some nice improvements, e.g. poll(1000) which is ~50% faster.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 nick-hppapmap-base2 jym-xensuspend-base nick-hppapmap-base mjf-devfs2-base
# 1.173 17-Dec-2008 cegger

branches: 1.173.2;
kill MALLOC and FREE macros.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 haad-dm-base2 haad-nbase2 ad-audiomp2-base netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 haad-dm-base
# 1.172 05-Sep-2008 skrll

branches: 1.172.2;
PR/39324 kernel diagnostic assertion "l->l_stat != LSZOMB" failed.

Ignore procs with zero or all LSZOMB LWPs. Get a non-LSZOMB LWP to perform
operations against as part of the deal.

procfs really needs to be updated to support multi-threading fully.
Hi Antti!


# 1.171 05-Sep-2008 skrll

ANSIfy


Revision tags: simonb-wapbl-nbase simonb-wapbl-base
# 1.170 02-Jul-2008 rmind

branches: 1.170.2;
Remove proc_representative_lwp(), use a simple LIST_FIRST() instead.
OK by <ad>.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base
# 1.169 28-Apr-2008 martin

branches: 1.169.2; 1.169.4;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-nfs-mp-base
# 1.168 24-Apr-2008 ad

branches: 1.168.2;
Merge proc::p_mutex and proc::p_smutex into a single adaptive mutex, since
we no longer need to guard against access from hardware interrupt handlers.

Additionally, if cloning a process with CLONE_SIGHAND, arrange to have the
child process share the parent's lock so that signal state may be kept in
sync. Partially addresses PR kern/37437.


# 1.167 24-Apr-2008 ad

Network protocol interrupts can now block on locks, so merge the globals
proclist_mutex and proclist_lock into a single adaptive mutex (proc_lock).
Implications:

- Inspecting process state requires thread context, so signals can no longer
be sent from a hardware interrupt handler. Signal activity must be
deferred to a soft interrupt or kthread.

- As the proc state locking is simplified, it's now safe to take exit()
and wait() out from under kernel_lock.

- The system spends less time at IPL_SCHED, and there is less lock activity.


Revision tags: yamt-pf42-baseX yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14
# 1.166 21-Mar-2008 ad

branches: 1.166.2;
Catch up with descriptor handling changes. See kern_descrip.c revision
1.173 for details.


Revision tags: keiichi-mipv6-nbase nick-net80211-sync-base keiichi-mipv6-base bouyer-xeni386-nbase matt-armv6-nbase mjf-devfs-base hpcarm-cleanup-base
# 1.165 23-Jan-2008 elad

branches: 1.165.6;
Tons of process scope changes.

- Add a KAUTH_PROCESS_SCHEDULER action, to handle scheduler related
requests, and add specific requests for set/get scheduler policy and
set/get scheduler parameters.

- Add a KAUTH_PROCESS_KEVENT_FILTER action, to handle kevent(2) related
requests.

- Add a KAUTH_DEVICE_TTY_STI action to handle requests to TIOCSTI.

- Add requests for the KAUTH_PROCESS_CANSEE action, indicating what
process information is being looked at (entry itself, args, env,
open files).

- Add requests for the KAUTH_PROCESS_RLIMIT action indicating set/get.

- Add requests for the KAUTH_PROCESS_CORENAME action indicating set/get.

- Make bsd44 secmodel code handle the newly added rqeuests appropriately.

All of the above make it possible to issue finer-grained kauth(9) calls in
many places, removing some KAUTH_GENERIC_ISSUSER requests.

- Remove the "CAN" from KAUTH_PROCESS_CAN{KTRACE,PROCFS,PTRACE,SIGNAL}.

Discussed with christos@ and yamt@.


Revision tags: bouyer-xeni386-base matt-armv6-base
# 1.164 02-Jan-2008 ad

Merge vmlocking2 to head.


Revision tags: vmlocking2-base3 yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 vmlocking-nbase jmcneill-pm-base reinoud-bufcleanup-base
# 1.163 26-Nov-2007 pooka

branches: 1.163.2; 1.163.6;
Remove the "struct lwp *" argument from all VFS and VOP interfaces.
The general trend is to remove it from all kernel interfaces and
this is a start. In case the calling lwp is desired, curlwp should
be used.

quick consensus on tech-kern


Revision tags: bouyer-xenamd64-base2 bouyer-xenamd64-base
# 1.162 09-Nov-2007 christos

make the last argument of procfs_dir size_t


# 1.161 07-Nov-2007 ad

Merge from vmlocking:

- pool_cache changes.
- Debugger/procfs locking fixes.
- Other minor changes.


Revision tags: jmcneill-base yamt-x86pmap-base4 yamt-x86pmap-base3 vmlocking-base
# 1.160 10-Oct-2007 ad

branches: 1.160.2; 1.160.4;
Merge from vmlocking:

- Split vnode::v_flag into three fields, depending on field locking.
- simple_lock -> kmutex in a few places.
- Fix some simple locking problems.


# 1.159 08-Oct-2007 ad

Merge file descriptor locking, cwdi locking and cross-call changes
from the vmlocking branch.


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base2 yamt-x86pmap-base matt-mips64-base
# 1.158 22-Jul-2007 pooka

branches: 1.158.4; 1.158.6; 1.158.8; 1.158.10;
Don't allow getcwd() on procfs vnodes and provide "/" as the path
instead of the result from getcwd(). The works around locking
panics caused by namei calling VOP_READLINK while holding on to a
directory lock and getcwd() trying to acquire that lock. The real
fix would be to get rid of getcwd() calls within VOPs (not locking
safe), but that's not a viable option in the netbsd-4 timeframe.

Suggestion for workaround from David Holland.


Revision tags: nick-csl-alignment-base mjf-ufs-trans-base
# 1.157 24-May-2007 agc

branches: 1.157.2;
Extend the Linux emulation of /proc to include

/proc/stat
/proc/loadavg and
/proc/<pid>/statm.

These are only present when -o linux is specified as a mount option
to procfs.

Factor out some common code so that it can be used by a number of
functions.

XXX The values returned in the statm emulation need to be verified.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 1.156 04-Apr-2007 rmind

Unfortunately, missed procfs_proc_unlock() in previous.
Pointed out by pooka@


# 1.155 04-Apr-2007 rmind

procfs_readlink: Handle a possible fail of fd_getfile(), also, we
do not need to check for error again.
CID: 4436


# 1.154 09-Mar-2007 ad

branches: 1.154.2; 1.154.4;
- Make the proclist_lock a mutex. The write:read ratio is unfavourable,
and mutexes are cheaper use than RW locks.
- LOCK_ASSERT -> KASSERT in some places.
- Hold proclist_lock/kernel_lock longer in a couple of places.


# 1.153 04-Mar-2007 christos

Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.


# 1.152 03-Mar-2007 salo

Don't prepend rootvnode to the path in non-NULL case for exe links.
It breaks procfs in chroot.

from <christos>, tested by me.


Revision tags: ad-audiomp-base
# 1.151 19-Feb-2007 pooka

When checking for file validity under pid/, do proper proc->lwp
lookup (fsvo proper) instead of fiddling directly with the lwp
list.


# 1.150 18-Feb-2007 pooka

Don't check for validity of p in lookup for root nodes, since it
will always be NULL. Rather, just call pt_valid with NULL directly
and let it decide if we're a linux mount or not.


# 1.149 17-Feb-2007 pavel

Change the process/lwp flags seen by userland via sysctl back to the
P_*/L_* naming convention, and rename the in-kernel flags to avoid
conflict. (P_ -> PK_, L_ -> LW_ ). Add back the (now unused) LSDEAD
constant.

Restores source compatibility with pre-newlock2 tools like ps or top.

Reviewed by Andrew Doran.


# 1.148 16-Feb-2007 pooka

branches: 1.148.2;
In lookup, when checking for procfs process node validity, target the
process we're trying to get information about through procfs, not
the caller of lookup.

fixes 'ls -l /proc/*/file' panic, which would occur when trying to
lookup "file" for a kernel thread, which doesn't have p->p_textvp.


# 1.147 15-Feb-2007 ad

Need to acquire procp->p_mutex for procfs_dir().


# 1.146 11-Feb-2007 ad

Eliminate a couple of reference count and mutex leaks.


Revision tags: post-newlock2-merge
# 1.145 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 1.144 25-Dec-2006 elad

PR/35226: Johann Franz: Problems with permissions in
/usr/pkg/emul/linux/proc .

Okay mlelstv@


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3
# 1.143 09-Dec-2006 chs

a smorgasbord of improvements to vnode locking and path lookup:
- LOCKPARENT is no longer relevant for lookup(), relookup() or VOP_LOOKUP().
these now always return the parent vnode locked. namei() works as before.
lookup() and various other paths no longer acquire vnode locks in the
wrong order via vrele(). fixes PR 32535.
as a nice side effect, path lookup is also up to 25% faster.
- the above allows us to get rid of PDIRUNLOCK.
- also get rid of WANTPARENT (just use LOCKPARENT and unlock it).
- remove an assumption in layer_node_find() that all file systems implement
a recursive VOP_LOCK() (unionfs doesn't).
- require that all file systems supply vfs_vptofh and vfs_fhtovp routines.
fill in eopnotsupp() for file systems that don't support being exported
and remove the checks for NULL. (layerfs calls these without checking.)
- in union_lookup1(), don't change refcounts in the ISDOTDOT case, just
adjust which vnode is locked. fixes PR 33374.
- apply fixes for ufs_rename() from ufs_vnops.c rev. 1.61 to ext2fs_rename().


# 1.142 04-Dec-2006 christos

From Nicolas Joly: restore previous behavior in procfs_validfile_linux, since
readdir passes a NULL lwp.


# 1.141 03-Dec-2006 elad

Move kauth(9) call to where it belongs. Noticed by Nicolas Joly, thanks!


Revision tags: netbsd-4-base
# 1.140 28-Nov-2006 elad

branches: 1.140.2;
Move ktrace, ptrace, systrace, and procfs to use kauth(9).

First, remove process_checkioperm() calls from MD code. Similar checks
using kauth(9) routines (on the process scope, using appropriate action)
are done in the callers.

Add secmodel back-end to handle each subsystem.


# 1.139 25-Nov-2006 skrll

Expose the 'exe' symlink to the process realpath in NetBSD as well. An
example user is gdb.

OK'd by christos.


# 1.138 16-Nov-2006 christos

__unused removal on arguments; approved by core.


# 1.137 29-Oct-2006 christos

add an "emul" file node.


# 1.136 25-Oct-2006 christos

1. fix procfs_validfile{,_linux} to test for NULL pointers properly.
2. make "exe" entry be a symlink to the executable, instead of pointing
directly to the vnode of the executable.
3. factor out commonly used code.


Revision tags: yamt-splraiseipl-base2
# 1.135 12-Oct-2006 christos

- sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386


# 1.134 20-Sep-2006 manu

Emulate Linux's /proc/devices


Revision tags: abandoned-netbsd-4-base yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base rpaulo-netinet-merge-pcb-base
# 1.133 13-Jun-2006 yamt

branches: 1.133.6; 1.133.8;
use KAUTH_PROCESS_CANSEE rather than CURTAIN where appropriate.


# 1.132 13-Jun-2006 yamt

remove unnecessary arguments from kauth_authorize_process.
ie. make it similar to the one found in apple TN.


# 1.131 07-Jun-2006 kardel

merge FreeBSD timecounters from branch simonb-timecounters
- struct timeval time is gone
time.tv_sec -> time_second
- struct timeval mono_time is gone
mono_time.tv_sec -> time_uptime
- access to time via
{get,}{micro,nano,bin}time()
get* versions are fast but less precise
- support NTP nanokernel implementation (NTP API 4)
- further reading:
Timecounter Paper: http://phk.freebsd.dk/pubs/timecounter.pdf
NTP Nanokernel: http://www.eecis.udel.edu/~mills/ntp/html/kern.html


Revision tags: yamt-pdpolicy-base5 simonb-timecounters-base
# 1.130 14-May-2006 elad

branches: 1.130.2;
integrate kauth.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 elad-kernelauth-base yamt-pdpolicy-base yamt-uio_vmspace-base5
# 1.129 02-Feb-2006 christos

branches: 1.129.2; 1.129.4; 1.129.6; 1.129.8;
PR/32692: Matthew Mondor: linux compatibility in /proc/self should point
directly to the directory containing the pid instead of pointing to
/proc/curproc, because some programs rely on calling readlink on /proc/self
to get the pid.


# 1.128 11-Dec-2005 christos

branches: 1.128.2; 1.128.4;
merge ktrace-lwp.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base ktrace-lwp-base
# 1.127 02-Nov-2005 yamt

merge yamt-vop branch. remove following VOPs.

VOP_BLKATOFF
VOP_VALLOC
VOP_BALLOC
VOP_REALLOCBLKS
VOP_VFREE
VOP_TRUNCATE
VOP_UPDATE


Revision tags: yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 1.126 01-Oct-2005 atatat

branches: 1.126.2;
Add "cwd" and "root" symlinks to each process's directory. The cwd
link points to the process's current working directory, and the root
link points to the process's root directory. What else would you
expect?

For directories that are out of reach (caller is in a chroot, target
process is in a different chroot, etc), the links point to "/"
instead.


# 1.125 11-Sep-2005 elad

Implement curtain for procfs.


# 1.124 30-Aug-2005 xtraeme

Remove __P()


# 1.123 29-May-2005 christos

branches: 1.123.2;
- sprinkle const
- avoid shadowed variables.


Revision tags: kent-audio2-base
# 1.122 02-Apr-2005 christos

PR/29782: Martin Husemann: procfs can not unmount when some process has its
current directory in curproc. Fix from Pedro Martelletto:
We cannot call vgone() from procfs_inactive() if we are coming from
vclean(). that's what's probably causing the deadlock.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 yamt-km-base4 yamt-km-base3 netbsd-3-base
# 1.121 26-Feb-2005 perry

nuke trailing whitespace


Revision tags: yamt-km-base2 yamt-km-base kent-audio1-beforemerge kent-audio1-base
# 1.120 04-Oct-2004 yamt

branches: 1.120.4; 1.120.6;
procfs_readdir:
- return correct cookie when buffer size is small.
- simplify logic.


# 1.119 04-Oct-2004 yamt

procfs_readdir: remove a redundant assignment.


# 1.118 02-Oct-2004 yamt

procfs_getattr: correct size of /proc/self.


# 1.117 01-Oct-2004 yamt

procfs_readdir:
- fix a locking problem, using proclist_foreach_call. PR/27098.
- correct snprintf size argument.


# 1.116 01-Oct-2004 yamt

procfs_readdir: fix an offset handling bug after addition of /proc/self.


# 1.115 01-Oct-2004 yamt

procfs_readdir: use a list macro.


# 1.114 20-Sep-2004 jdolecek

add 'mounts' file for -o linux, which lists all currently mounted
filesystems; Linux glibc statvfs() uses this to get some of mount flags,
and this file is also useful as /emul/linux/etc/mtab (via symlink)


# 1.113 29-Apr-2004 jrf

Removed remaining caddr_t casts we do not need in miscfs. Recompiled
kernel and ran for a day or so. There are still some caddr_t types in
the arguments of some calls, I will do those separately (later) as
they touch a lot more of the system.
Approved by christos@NetBSD.org.


# 1.112 22-Apr-2004 itojun

sprintf -> snprintf


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.111 15-Feb-2004 jdolecek

unlock the descriptor table simple lock after fd_getfile() call in
procfs_readdir()
fixes procfs locking problems reported on current-users@, problem place
found by enami tsugutomo


# 1.110 30-Oct-2003 simonb

Remove some assigned-to but otherwise unused variables.


# 1.109 27-Sep-2003 darcy

Changes as discussed with itojun on tech-kern. I have modified the enums
to have KFS or PFS differentiators. Further I have wrapped the enum in
procfs in "#ifdef _KERNEL" as it is done in kernfs.

To see the discussion go to http://mail-index.NetBSD.org/tech-kern/2003/09/
and look for "Mismatched enums in include files" in the list.


# 1.108 07-Sep-2003 itojun

remove meaningless line (variable overwritten 2 lines below)


# 1.107 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.


# 1.106 29-Jun-2003 fvdl

branches: 1.106.2;
Back out the lwp/ktrace changes. They contained a lot of colateral damage,
and need to be examined and discussed more.


# 1.105 29-Jun-2003 thorpej

Undo part of the ktrace/lwp changes. In particular:
* Remove the "lwp *" argument that was added to vget(). Turns out
that nothing actually used it!
* Remove the "lwp *" arguments that were added to VFS_ROOT(), VFS_VGET(),
and VFS_FHTOVP(); all they did was pass it to vget() (which, as noted
above, didn't use it).
* Remove all of the "lwp *" arguments to internal functions that were added
just to appease the above.


# 1.104 28-Jun-2003 darrenr

Pass lwp pointers throughtout the kernel, as required, so that the lwpid can
be inserted into ktrace records. The general change has been to replace
"struct proc *" with "struct lwp *" in various function prototypes, pass
the lwp through and use l_proc to get the process pointer when needed.

Bump the kernel rev up to 1.6V


# 1.103 28-May-2003 christos

Add /proc/<pid>/stat for linux compat. j2sdk1.4.2 depends on it.


# 1.102 18-Apr-2003 christos

Make symlinks for directories that point to the actual directory.
Make symlinks to [kqueue] and [misc] for kqueue and misc fds.


# 1.101 17-Apr-2003 jdolecek

do not show nodes corresponding to directory descriptors for process
in fd/ subdirectory, nor allow lookup/open for the nodes
this fixes PR kern/21187 for good, and also avoids interesting directory
locking issues


# 1.100 17-Apr-2003 jdolecek

procfs_readdir(): in Pfd case, only show descriptors of types we want
how to represent (vnodes, fifo, pipes); also use fd_getfile() et al

this avoids annoying EOPNOTSUPP error messages from ls -F and such


# 1.99 17-Apr-2003 jdolecek

procfs_lookup(): use fd_getfile() et al in Pfd case


# 1.98 17-Apr-2003 jdolecek

use fd_getfile() in procfs_getfp(), and FILE_USE()/FILE_UNUSE() the
returned file descriptor pointer appropriately


# 1.97 17-Apr-2003 jdolecek

make some local arrays/variables static + const


# 1.96 10-Apr-2003 jdolecek

use former genfs_eopnotsupp_rele() as genfs_eopnotsupp(), so that vnodes
are vput()/vrele()d as necessary - some filesystems did use the wrong
one for some ops, and it's just safer to not take the chance

based on suggestion by Bill Studenmund


# 1.95 05-Apr-2003 dsl

Remove pointless check against PID_MAX. Let pfind() do the validation.
(The new pid allocation code may decide to allocate pids above PID_MAX.)


# 1.94 25-Feb-2003 jrf

This addresses PR kerm/19989. Thanks to hamajima@nagoya.ydc.co.jp for submitting this patch which enables /proc/uptime for linux emul. Patch reviewed by atatat@netbsd.org and tron@netbsd.org, approved by tron@netbsd.org.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 1.93 04-Jan-2003 martin

Cast off_t expression to long long to match format even on 64 bit
plattforms.

Shouldn't we introduce a PRIoff_t macro to create such format strings?


# 1.92 03-Jan-2003 christos

add LK_CANRECURSE in the locking of /dev/<pid>/fd/<n> and remove the curproc
kludge. Thanks to fvdl.


# 1.91 03-Jan-2003 christos

Implement /proc/<pid>/fd/<n>. This is work in progress. Questionable things:
- Is it ok to convert DTYPE_PIPE to VFIFO and DTYPE_SOCKET to VSOCK?
- XXX: Avoid locking issue in ls -Rl /proc by avoiding curproc
- Does I/O to pipes work?
- XXX: Are there security implications?


Revision tags: fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge gehenna-devsw-base kqueue-base
# 1.90 03-Aug-2002 simonb

Just use the "time" variable in the *_getattr functions instead of a call
to (the potentially expensive) microtime().


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.89 09-May-2002 thorpej

branches: 1.89.2;
Move code shared by procfs and the kernel proper out of procfs and
into the kernel proper (renaming functions from procfs_* to process_*).


Revision tags: eeh-devprop-base newlock-base ifpoll-base
# 1.88 12-Jan-2002 christos

Don't hide the real return code with EPERM.


# 1.87 06-Dec-2001 chs

add a VOP_PUTPAGES method for all the filesystems that don't have pages,
just unlock the interlock.


# 1.86 05-Dec-2001 thorpej

* Allow machine-dependent code to specify hooks for ptrace(2)
(__HAVE_PTRACE_MACHDEP) and procfs (__HAVE_PROCFS_MACHDEP).
These changes will allow platforms like x86 (XMM) and PowerPC
(AltiVec) to export extended register sets in a sane manner.

* Use __HAVE_PTRACE_MACHDEP to export x86 XMM registers (standard
FP + SSE/SSE2) using PT_{GET,SET}XMMREGS (in the machdep
ptrace request space).
* Use __HAVE_PROCFS_MACHDEP to export x86 XMM registers via
/proc/N/xmmregs in procfs.


Revision tags: thorpej-mips-cache-base
# 1.85 10-Nov-2001 lukem

add RCSIDs


# 1.84 06-Nov-2001 simonb

Remove some variables that are set but never used.


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base
# 1.83 31-Aug-2001 chs

branches: 1.83.2; 1.83.4;
map files are zero-length.


# 1.82 03-Jun-2001 chs

branches: 1.82.2;
procfs_bmap() should never be called, make it a "bad op".
let procfs_mmap() use the default error method.


Revision tags: thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 1.81 14-Apr-2001 kleink

In procfs_readdir(), give /proc/# directories DT_DIR (rather than DT_REG).


# 1.80 30-Mar-2001 fvdl

Bump va_blocksize for the map files some more, so that programs with
quite a few mappings have a chance of being handled correctly if
st_blksize is looked at.


# 1.79 29-Mar-2001 fvdl

For -o linux mounts, add some code to emulate /proc/#/maps.
Needs NAMECACHE_ENTER_REVERSE to include filenames.


# 1.78 21-Feb-2001 jdolecek

branches: 1.78.2;
make some more constant arrays 'const'


# 1.77 22-Jan-2001 jdolecek

make filesystem vnodeop, specop, fifoop and vnodeopv_* arrays const


# 1.76 17-Jan-2001 fvdl

Add a few linux-style files, only enabled when -o linux is specified
for the mount. Currently these are /proc/cpuinfo and /proc/meminfo.
The former only does something on i386 right now.


# 1.75 24-Nov-2000 chs

remove dead code and other misc cleanup.


# 1.74 09-Aug-2000 tv

Only show the "exe" entry to Linux processes, suggested by christos.
Since there are actually three struct emul's for linux, use the e_name
field to determine eligibility with strcmp().


# 1.73 09-Aug-2000 tv

Some versions of Linux libc look for /proc/.../exe instead of /proc/../file.
Add an entry for "exe" that is the same as "file", provided only if
COMPAT_LINUX is set.


# 1.72 03-Aug-2000 thorpej

MALLOC()/FREE() are not to be used for variable sized allocations.


# 1.71 28-Jun-2000 mrg

<vm/vm.h> -> <uvm/uvm_extern.h>


Revision tags: netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 1.70 30-Mar-2000 simonb

branches: 1.70.4;
Delete duplicate declaration of atopid().


Revision tags: chs-ubc2-newbase wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base fvdl-softdep-base
# 1.69 02-Sep-1999 thorpej

branches: 1.69.2; 1.69.8;
Make /proc/self a symlink to /proc/curproc. I've observed Linux programs
that expect /proc/self/cmdline to exist.


# 1.68 25-Aug-1999 sommerfeld

Change variable used for directory offset from "int" to "off_t".
Overkill, but avoids a host of truncation problems.


# 1.67 24-Aug-1999 sommerfeld

Fix PR8270:

Problem turned out to be due to improper handling of reads beyond EOF:
they should just return without error with the uio unchanged, and the
caller will recognize this as a zero-byte return (EOF).

The previous fix to protect directory reads against bogus uio_offset
values returned EINVAL, which broke mount -o union, which only
union'ed in the lower directory if the upper directory cleanly
returned EOF.

While we're here, protect kernfs as well.


# 1.66 14-Aug-1999 christos

protect against large uio_offset


# 1.65 03-Aug-1999 wrstuden

Add support for fcntl(2) to generate VOP_FCNTL calls. Any fcntl
call with F_FSCTL set and F_SETFL calls generate calls to a new
fileop fo_fcntl. Add genfs_fcntl() and soo_fcntl() which return 0
for F_SETFL and EOPNOTSUPP otherwise. Have all leaf filesystems
use genfs_fcntl().

Reviewed by: thorpej
Tested by: wrstuden


Revision tags: chs-ubc2-base
# 1.64 25-Jul-1999 thorpej

Add calls to lock the proclist as appropriate.


# 1.63 14-Jul-1999 thorpej

Fix a paste-o in procfs_lookup() introduced with the vnode locking changes.
Fixes PR #7961, Mario Kemper <magick@bundy.lip.owl.de>.


# 1.62 08-Jul-1999 wrstuden

Bump osrelease to 1.4E. Add layerfs files, remove null_subr.c.

Update coda to new struct lock in struct vnode.

make fdescfs, kernfs, portalfs, and procfs actually lock their vnodes.
It's not that hard.

Make unionfs set v_vnlock = NULL so any overlayed fs will call its
VOP_LOCK.


Revision tags: kame_141_19991130 netbsd-1-4-PATCH001 kame_14_19990705 kame_14_19990628 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.61 12-Mar-1999 christos

branches: 1.61.2; 1.61.4;
PR/7143: Jaromir Docelek: Add procfs/cmdline from Linux emulation


# 1.60 25-Jan-1999 msaitoh

Add /proc/#/map. From FreeBSD.


Revision tags: kenh-if-detach-base chs-ubc-base
# 1.59 08-Sep-1998 thorpej

- Use proclists[], rather than checking allproc and zombproc explicitly.
- Add some comments about locking.


# 1.58 13-Aug-1998 kleink

Per POSIX, fail with EINVAL if advisory locking is attempted on a file type
that doesn't support it, rather than using a homegrown EBADF or EOPNOTSUPP.


# 1.57 10-Aug-1998 matthias

create miscfs/genfs/genfs_vnops.c:genfs_enoioctl and make all the other
filesystems use it instead of a private version.


# 1.56 09-Aug-1998 perry

bzero->memset, bcopy->memcpy, bcmp->memcmp


# 1.55 03-Aug-1998 kleink

Recognize _PC_SYNC_IO.


Revision tags: eeh-paddr_t-base
# 1.54 21-Apr-1998 fvdl

procfs_readdir: in case of error, check if cookies actually have
been allocated before freeing them. From Wolfgang Solfrank.


# 1.53 01-Mar-1998 fvdl

Merge with Lite2 + local changes


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base marc-pcmcia-base
# 1.52 10-Oct-1997 fvdl

Bump last argument to VOP_READDIR to off_t (from u_long).


Revision tags: thorpej-signal-base
# 1.51 27-Aug-1997 thorpej

Fix a reversed argument which caused procfs_checkioperm() to always return
"OK". Add a few comments to avoid further confusion.


# 1.50 12-Aug-1997 thorpej

Fix the procfs hole described on current-users, similar to a fix for
FreeBSD by Sean Eric Fagan, but a bit different. This makes the checks
in the same places as sef's FreeBSD patch, but does not hardcode the
"kmem" group into the kernel, and also does a check identical to the
(3) and (4) checks in the NetBSD ptrace(2):

(1) it's not owned by you, or is set-id on exec (unless
you're root), or

(2) it's init, which controls the security level of the
entire system, and the system was not compiled with
permanently insecure mode turned on.


Revision tags: marc-pcmcia-bp
# 1.49 08-May-1997 mycroft

branches: 1.49.4;
Pass the vnode type to vaccess(), and use it when checking VEXEC. Make sure
that the mode bits passed to vaccess() and returned by foo_getattr() contain
only permission bits.


# 1.48 05-May-1997 mycroft

Need stat.h.


# 1.47 05-May-1997 mycroft

Eliminate bogus uses of V{READ,WRITE,EXEC}. Use S_I[RWX]{USR,GRP,OTH} where
appropriate.


# 1.46 28-Apr-1997 mycroft

Minor code cleanup.


Revision tags: is-newarp-before-merge is-newarp-base
# 1.45 25-Oct-1996 cgd

define path name string variables that we should not (and, thankfully, do
not) modify as 'const char *' rather 'char *'.


# 1.44 13-Oct-1996 christos

backout previous kprintf changes


# 1.43 10-Oct-1996 christos

printf -> kprintf, sprintf -> ksprintf


# 1.42 07-Sep-1996 mycroft

Implement poll(2).


# 1.41 01-Sep-1996 mycroft

Add a set of generic file system operations that most file systems use.
Also, fix some time stamp bogosities.


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 1.40 16-Mar-1996 christos

Fix printf format follies.


# 1.39 13-Feb-1996 mycroft

GC *_nullop(). Minor nits.


# 1.38 12-Feb-1996 christos

close PR/2063: procfs_rw prototyped twice with different prototypes


# 1.37 09-Feb-1996 christos

miscfs prototype changes


# 1.36 09-Feb-1996 mycroft

Fix vop_link, vop_symlink, and vop_remove semantics in several ways:
* Change the argument names to vop_link so they actually make sense.
* Implement vop_link and vop_symlink for all file systems, so they do proper
cleanup.
* Require the file system to decide whether or not linking and unlinking of
directories is allowed, and disable it for all current file systems.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.35 09-Oct-1995 mycroft

Use the index number as the cookie, rather than multiplying by UIO_MX.


# 1.34 09-Oct-1995 mycroft

Add support for cookies, mostly from Greg Hudson.


# 1.33 15-Apr-1995 cgd

fix timeval vs. timespec warnings


# 1.32 03-Feb-1995 mycroft

Return EROFS rather than ENOENT in many cases. Also some cosmetic cleanup.


# 1.31 27-Dec-1994 mycroft

Format police.


# 1.30 24-Dec-1994 ws

Implement and use a common access checking routine


# 1.29 14-Dec-1994 mycroft

Remove a_fp.


# 1.28 14-Nov-1994 christos

fixed struct comment


# 1.27 30-Oct-1994 cgd

be more careful with types, also pull in headers where necessary.


# 1.26 20-Oct-1994 cgd

update for new syscall args description mechanism


# 1.25 30-Aug-1994 mycroft

Convert process, file, and namei lists and hash tables to use queue.h.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.24 29-Jun-1994 cgd

New RCS ID's, take two. they're more aesthecially pleasant, and use 'NetBSD'


# 1.23 16-Jun-1994 mycroft

Remove an unneeded test.


# 1.22 15-Jun-1994 mycroft

Minor update from JSP after merging my changes.


# 1.21 08-Jun-1994 mycroft

Update to 4.4-Lite fs code, with local changes.


# 1.20 05-May-1994 cgd

lots of changes: prototype migration, move lots of variables, definitions,
and structure elements around. kill some unnecessary type and macro
definitions. standardize clock handling. More changes than you'd want.


# 1.19 15-Apr-1994 cgd

forgot these...


# 1.18 12-Apr-1994 cgd

be a bit smarter about determining if files shouldn't be seen by the user.
Also, DON'T allow a lookup to succeed on a file that's not visible!


# 1.17 15-Feb-1994 mycroft

Undo last change; executables is `file', not `a.out'.


# 1.16 14-Feb-1994 ws

Rename file -> a.out


# 1.15 14-Feb-1994 ws

Don't try to show a file for a process if there is none


# 1.14 28-Jan-1994 cgd

make a fpregs file.


# 1.13 20-Jan-1994 ws

Make procfs really work for debugging.
Implement not & notepg files in procfs.


# 1.12 09-Jan-1994 ws

Bug fixes and enhancements:
Make NFS serving work (BUT DON'T USE "attach" TO /proc/*/ctl FOR NOW!!!)
Make `curproc' a symbolic link
Add `.' and `..' entries to the directories.
Return better guesses on the size of the files.


# 1.11 05-Jan-1994 cgd

return size of 'reg' from getattr()


# 1.10 05-Jan-1994 cgd

make it compile (cleanly) for us


# 1.9 05-Jan-1994 cgd

add new procfs code, from Jan-Simon Pendry, jsp@sequent.com.
This is pretty-much "virgin", so that diffs can be done later.


# 1.8 18-Dec-1993 mycroft

Canonicalize all #includes.


Revision tags: magnum-base
# 1.7 16-Sep-1993 cgd

kill volatile warning.


# 1.6 07-Sep-1993 ws

branches: 1.6.2;
Changes to VFS readdir semantics
NFS changes for better cookie support
ISOFS changes for better Rockridge support and support for generation numbers


# 1.5 26-Aug-1993 pk

Implement setattr: mode for process entries; mode + uid/gid for the
PROCFS root directory.
Fixed omission in pfs_root() which came to light as a result of the above:
hold on to vnode for root dir.


# 1.4 25-Aug-1993 pk

Fixed improperly initialized nfsnode in pfs_lookup()


# 1.3 24-Aug-1993 pk

copyright update.


# 1.2 24-Aug-1993 pk

Rcs Id added.


# 1.1 24-Aug-1993 pk

branches: 1.1.1;
Initial version of a proc filesystem.


# 1.198 28-Aug-2017 kamil

Remove the filesystem tracing feature

This is a legacy interface from 4.4BSD, and it was
introduced to overcome shortcomings of ptrace(2) at that time, which are
no longer relevant (performance). Today /proc/#/ctl offers a narrow
subset of ptrace(2) commands and is not applicable for modern
applications use beyond simplistic tracing scenarios.

This removal will simplify kernel internals. Users will still be able to
use all the other /proc files.

This change won't affect other procfs files neither Linux compat
features within mount_procfs(8). /proc/#/ctl isn't available on Linux.

Remove:
- /proc/#/ctl from mount_procfs(8)
- P_FSTRACE note from the documentation of ps(1)
- /proc/#/ctl and filesystem tracing documentation from mount_procfs(8)
- KAUTH_REQ_PROCESS_PROCFS_CTL documentation from kauth(9)
- source code file miscfs/procfs/procfs_ctl.c
- PFSctl and procfs_doctl() from sys/miscfs/procfs/procfs.h
- KAUTH_REQ_PROCESS_PROCFS_CTL from sys/sys/kauth.h
- PSL_FSTRACE (0x00010000) from sys/sys/proc.h
- P_FSTRACE (0x00010000) from sys/sys/sysctl.h

Reduce code complexity after removal of this functionality.

Update TODO.ptrace accordingly: remove two entries about /proc tracing.

Do not keep legacy notes as comments in the headers about removed
PSL_FSTRACE / P_FSTRACE, as this interface had little number of users
(close or equal to zero).

Proposed on tech-kern@.

All filesystem tracing utility users are encouraged to switch to ptrace(2).

Sponsored by <The NetBSD Foundation>


Revision tags: nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base
# 1.197 26-May-2017 riastradh

Make VOP_RECLAIM do the last unlock of the vnode.

VOP_RECLAIM naturally has exclusive access to the vnode, so having it
locked on entry is not strictly necessary -- but it means if there
are any final operations that must be done on the vnode, such as
ffs_update, requiring exclusive access to it, we can now kassert that
the vnode is locked in those operations.

We can't just have the caller release the last lock because some file
systems don't use genfs_lock, and require the vnode to remain valid
for VOP_UNLOCK to work, notably unionfs.


Revision tags: prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.196 11-Apr-2017 riastradh

Make VOP_INACTIVE preserve vnode lock on return.

Discussed on tech-kern:
https://mail-index.netbsd.org/tech-kern/2017/04/01/msg021751.html

Ride 7.99.68, a bumpy bus of incremental vfs improvements!


Revision tags: jdolecek-ncq-base
# 1.195 30-Mar-2017 christos

add an auxv node.


Revision tags: pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004 localcount-20160914
# 1.194 20-Aug-2016 hannken

branches: 1.194.2;
Remove now obsolete operation vcache_remove().

Welcome to 7.99.36


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 nick-nhusb-base-20150921 nick-nhusb-base-20150606
# 1.193 20-Apr-2015 riastradh

branches: 1.193.2;
Make VOP_LINK return directory still locked and referenced.

Ride 7.99.10 bump.


Revision tags: nick-nhusb-base-20150406 nick-nhusb-base
# 1.192 05-Sep-2014 matt

branches: 1.192.2;
Try not to use f_data, use f_{vnode,socket,pipe,mqueue,kqueue,ksem} to get
a correctly typed pointer.


Revision tags: netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.191 27-Jul-2014 hannken

Change procfs from hashlist to vcache.
- Key is (type, pid, fd)
- Remove argument "p" from procfs_allocvp(). It is only used
when "type == PFSfd". Lookup the proc with proc_find() when
procfs_loadvnode() needs it.
- Use a vfs_vnode_iterator for procfs_revoke_vnodes().


# 1.190 25-Jul-2014 dholland

Add VOP_FALLOCATE and VOP_FDISCARD to every vnode ops table I can
find.

The filesystem ones all call genfs_eopnotsupp - right now I am only
implementing the plumbing and we can implement fallocate and/or
fdiscard for files later.

The device ones call spec_fallocate (which is also genfs_eopnotsupp)
and spec_fdiscard, which dispatches to the device-level op.

The fifo ones all call vn_fifo_bypass, which also ends up being
EOPNOTSUPP.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base
# 1.189 07-Feb-2014 hannken

branches: 1.189.2;
Change vnode operation lookup to return the resulting vnode *vpp unlocked.
Change cache_lookup() to return an unlocked vnode.

Discussed on tech-kern@

Welcome to 6.99.31


# 1.188 23-Jan-2014 hannken

Change vnode operations create, mknod, mkdir and symlink to return
the resulting vnode *vpp unlocked.

Discussed on tech-kern@

Welcome to 6.99.30


# 1.187 17-Jan-2014 hannken

Change vnode operations create, mknod, mkdir and symlink to keep the
directory node dvp locked on return.

Discussed on tech-kern@

Welcome to 6.99.29


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base
# 1.186 18-Mar-2013 plunky

branches: 1.186.6;
C99 section 6.7.2.3 (Tags) Note 3 states that:

A type specifier of the form

enum identifier

without an enumerator list shall only appear after the type it
specifies is complete.

which means that we cannot pass an "enum vtype" argument to
kauth_access_action() without fully specifying the type first.
Unfortunately there is a complicated include file loop which
makes that difficult, so convert this minimal function into a
macro (and capitalize it).

(ok elad@)


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 1.185 25-Nov-2012 christos

do something reasonable with kernel semaphores.


Revision tags: yamt-pagecache-base6 jmcneill-usbmp-base10
# 1.184 28-May-2012 christos

branches: 1.184.2;
add a task process subdirectory for emul linux


Revision tags: yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 1.183 13-Mar-2012 elad

Replace the remaining KAUTH_GENERIC_ISSUSER authorization calls with
something meaningful. All relevant documentation has been updated or
written.

Most of these changes were brought up in the following messages:

http://mail-index.netbsd.org/tech-kern/2012/01/18/msg012490.html
http://mail-index.netbsd.org/tech-kern/2012/01/19/msg012502.html
http://mail-index.netbsd.org/tech-kern/2012/02/17/msg012728.html

Thanks to christos, manu, njoly, and jmmv for input.

Huge thanks to pgoyette for spinning these changes through some build
cycles and ATF.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.182 04-Sep-2011 jmcneill

branches: 1.182.2; 1.182.6;
PR# kern/45021: Please support /emul/linux/proc/version

Add /proc/version for procfs with -o linux. The version reported depends
on the emulation type of the calling process:

$ cat /proc/version
NetBSD version 5.99.55 (netbsd@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) NetBSD 5.99.55 (GENERIC) #39: Sun Sep 4 09:10:05 EDT 2011

$ /emul/linux/bin/cat /proc/version
Linux version 2.6.18 (linux@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) #0 Wed Mar 3 03:03:03 PST 2010

$ /emul/linux32/bin/cat /proc/version
Linux version 2.6.18 (linux32@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) #0 Wed Mar 3 03:03:03 PST 2010


# 1.181 23-Jun-2011 christos

From Aleksey Cheusov: Don't make it easy for compromised systems to bypass
ASLR protections by providing the mapping addresses of programs to everyone.


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base matt-mips64-premerge-20101231 uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10 rmind-uvmplock-base
# 1.180 01-Jul-2010 rmind

Remove pfind() and pgfind(), fix locking in various broken uses of these.
Rename real routines to proc_find() and pgrp_find(), remove PFIND_* flags
and have consistent behaviour. Provide proc_find_raw() for special cases.
Fix memory leak in sysctl_proc_corename().

COMPAT_LINUX: rework ptrace() locking, minimise differences between
different versions per-arch.

Note: while this change adds some formal cosmetics for COMPAT_DARWIN and
COMPAT_IRIX - locking there is utterly broken (for ages).

Fixes PR/43176.


# 1.179 24-Jun-2010 hannken

Clean up vnode lock operations pass 2:

VOP_UNLOCK(vp, flags) -> VOP_UNLOCK(vp): Remove the unneeded flags argument.

Welcome to 5.99.32.

Discussed on tech-kern.


# 1.178 08-Jun-2010 hannken

Procfs_lookup() does not lookup directory descriptors in the fd/
subdirectory. There is no need for recursive vnode locking here.

Ok: Christos Zoulas <christos@netbsd.org>


Revision tags: uebayasi-xip-base1 yamt-nfs-mp-base9 uebayasi-xip-base
# 1.177 08-Jan-2010 pooka

branches: 1.177.2; 1.177.4;
The VATTR_NULL/VREF/VHOLD/HOLDRELE() macros lost their will to live
years ago when the kernel was modified to not alter ABI based on
DIAGNOSTIC, and now just call the respective function interfaces
(in lowercase). Plenty of mix'n match upper/lowercase has creeped
into the tree since then. Nuke the macros and convert all callsites
to lowercase.

no functional change


Revision tags: matt-premerge-20091211 yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 jym-xensuspend-nbase
# 1.176 03-Jul-2009 elad

Where possible, extract the file-system's access() routine to two internal
functions: the first checking if the operation is possible (regardless of
permissions), the second checking file-system permissions, ACLs, etc.

Mailing list reference:

http://mail-index.netbsd.org/tech-kern/2009/06/21/msg005311.html


# 1.175 23-Jun-2009 elad

Move the implementation of vaccess() to genfs_can_access(), in line with
the other routines of the same spirit.

Adjust file-system code to use it.

Keep vaccess() for KPI compatibility and to keep element of least
surprise. A "diagnostic" message warning that vaccess() is deprecated will
be printed when it's used (obviously, only in DIAGNOSTIC kernels).

No objections on tech-kern@:

http://mail-index.netbsd.org/tech-kern/2009/06/21/msg005310.html


Revision tags: yamt-nfs-mp-base5
# 1.174 24-May-2009 ad

More changes to improve kern_descrip.c.

- Avoid atomics in more places.
- Remove the per-descriptor mutex, and just use filedesc_t::fd_lock.
It was only being used to synchronize close, and in any case we needed
to take fd_lock to free the descriptor slot.
- Optimize certain paths for the <NDFDFILE case.
- Sprinkle more comments and assertions.
- Cache more stuff in filedesc_t.
- Fix numerous minor bugs spotted along the way.
- Restructure how the open files array is maintained, for clarity and so
that we can eliminate the membar_consumer() call in fd_getfile(). This is
mostly syntactic sugar; the main functional change is that fd_nfiles now
lives alongside the open file array.

Some measurements with libmicro:

- simple file syscalls are like close() are between 1 to 10% faster.
- some nice improvements, e.g. poll(1000) which is ~50% faster.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 nick-hppapmap-base2 jym-xensuspend-base nick-hppapmap-base mjf-devfs2-base
# 1.173 17-Dec-2008 cegger

branches: 1.173.2;
kill MALLOC and FREE macros.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 haad-dm-base2 haad-nbase2 ad-audiomp2-base netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 haad-dm-base
# 1.172 05-Sep-2008 skrll

branches: 1.172.2;
PR/39324 kernel diagnostic assertion "l->l_stat != LSZOMB" failed.

Ignore procs with zero or all LSZOMB LWPs. Get a non-LSZOMB LWP to perform
operations against as part of the deal.

procfs really needs to be updated to support multi-threading fully.
Hi Antti!


# 1.171 05-Sep-2008 skrll

ANSIfy


Revision tags: simonb-wapbl-nbase simonb-wapbl-base
# 1.170 02-Jul-2008 rmind

branches: 1.170.2;
Remove proc_representative_lwp(), use a simple LIST_FIRST() instead.
OK by <ad>.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base
# 1.169 28-Apr-2008 martin

branches: 1.169.2; 1.169.4;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-nfs-mp-base
# 1.168 24-Apr-2008 ad

branches: 1.168.2;
Merge proc::p_mutex and proc::p_smutex into a single adaptive mutex, since
we no longer need to guard against access from hardware interrupt handlers.

Additionally, if cloning a process with CLONE_SIGHAND, arrange to have the
child process share the parent's lock so that signal state may be kept in
sync. Partially addresses PR kern/37437.


# 1.167 24-Apr-2008 ad

Network protocol interrupts can now block on locks, so merge the globals
proclist_mutex and proclist_lock into a single adaptive mutex (proc_lock).
Implications:

- Inspecting process state requires thread context, so signals can no longer
be sent from a hardware interrupt handler. Signal activity must be
deferred to a soft interrupt or kthread.

- As the proc state locking is simplified, it's now safe to take exit()
and wait() out from under kernel_lock.

- The system spends less time at IPL_SCHED, and there is less lock activity.


Revision tags: yamt-pf42-baseX yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14
# 1.166 21-Mar-2008 ad

branches: 1.166.2;
Catch up with descriptor handling changes. See kern_descrip.c revision
1.173 for details.


Revision tags: keiichi-mipv6-nbase nick-net80211-sync-base keiichi-mipv6-base bouyer-xeni386-nbase matt-armv6-nbase mjf-devfs-base hpcarm-cleanup-base
# 1.165 23-Jan-2008 elad

branches: 1.165.6;
Tons of process scope changes.

- Add a KAUTH_PROCESS_SCHEDULER action, to handle scheduler related
requests, and add specific requests for set/get scheduler policy and
set/get scheduler parameters.

- Add a KAUTH_PROCESS_KEVENT_FILTER action, to handle kevent(2) related
requests.

- Add a KAUTH_DEVICE_TTY_STI action to handle requests to TIOCSTI.

- Add requests for the KAUTH_PROCESS_CANSEE action, indicating what
process information is being looked at (entry itself, args, env,
open files).

- Add requests for the KAUTH_PROCESS_RLIMIT action indicating set/get.

- Add requests for the KAUTH_PROCESS_CORENAME action indicating set/get.

- Make bsd44 secmodel code handle the newly added rqeuests appropriately.

All of the above make it possible to issue finer-grained kauth(9) calls in
many places, removing some KAUTH_GENERIC_ISSUSER requests.

- Remove the "CAN" from KAUTH_PROCESS_CAN{KTRACE,PROCFS,PTRACE,SIGNAL}.

Discussed with christos@ and yamt@.


Revision tags: bouyer-xeni386-base matt-armv6-base
# 1.164 02-Jan-2008 ad

Merge vmlocking2 to head.


Revision tags: vmlocking2-base3 yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 vmlocking-nbase jmcneill-pm-base reinoud-bufcleanup-base
# 1.163 26-Nov-2007 pooka

branches: 1.163.2; 1.163.6;
Remove the "struct lwp *" argument from all VFS and VOP interfaces.
The general trend is to remove it from all kernel interfaces and
this is a start. In case the calling lwp is desired, curlwp should
be used.

quick consensus on tech-kern


Revision tags: bouyer-xenamd64-base2 bouyer-xenamd64-base
# 1.162 09-Nov-2007 christos

make the last argument of procfs_dir size_t


# 1.161 07-Nov-2007 ad

Merge from vmlocking:

- pool_cache changes.
- Debugger/procfs locking fixes.
- Other minor changes.


Revision tags: jmcneill-base yamt-x86pmap-base4 yamt-x86pmap-base3 vmlocking-base
# 1.160 10-Oct-2007 ad

branches: 1.160.2; 1.160.4;
Merge from vmlocking:

- Split vnode::v_flag into three fields, depending on field locking.
- simple_lock -> kmutex in a few places.
- Fix some simple locking problems.


# 1.159 08-Oct-2007 ad

Merge file descriptor locking, cwdi locking and cross-call changes
from the vmlocking branch.


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base2 yamt-x86pmap-base matt-mips64-base
# 1.158 22-Jul-2007 pooka

branches: 1.158.4; 1.158.6; 1.158.8; 1.158.10;
Don't allow getcwd() on procfs vnodes and provide "/" as the path
instead of the result from getcwd(). The works around locking
panics caused by namei calling VOP_READLINK while holding on to a
directory lock and getcwd() trying to acquire that lock. The real
fix would be to get rid of getcwd() calls within VOPs (not locking
safe), but that's not a viable option in the netbsd-4 timeframe.

Suggestion for workaround from David Holland.


Revision tags: nick-csl-alignment-base mjf-ufs-trans-base
# 1.157 24-May-2007 agc

branches: 1.157.2;
Extend the Linux emulation of /proc to include

/proc/stat
/proc/loadavg and
/proc/<pid>/statm.

These are only present when -o linux is specified as a mount option
to procfs.

Factor out some common code so that it can be used by a number of
functions.

XXX The values returned in the statm emulation need to be verified.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 1.156 04-Apr-2007 rmind

Unfortunately, missed procfs_proc_unlock() in previous.
Pointed out by pooka@


# 1.155 04-Apr-2007 rmind

procfs_readlink: Handle a possible fail of fd_getfile(), also, we
do not need to check for error again.
CID: 4436


# 1.154 09-Mar-2007 ad

branches: 1.154.2; 1.154.4;
- Make the proclist_lock a mutex. The write:read ratio is unfavourable,
and mutexes are cheaper use than RW locks.
- LOCK_ASSERT -> KASSERT in some places.
- Hold proclist_lock/kernel_lock longer in a couple of places.


# 1.153 04-Mar-2007 christos

Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.


# 1.152 03-Mar-2007 salo

Don't prepend rootvnode to the path in non-NULL case for exe links.
It breaks procfs in chroot.

from <christos>, tested by me.


Revision tags: ad-audiomp-base
# 1.151 19-Feb-2007 pooka

When checking for file validity under pid/, do proper proc->lwp
lookup (fsvo proper) instead of fiddling directly with the lwp
list.


# 1.150 18-Feb-2007 pooka

Don't check for validity of p in lookup for root nodes, since it
will always be NULL. Rather, just call pt_valid with NULL directly
and let it decide if we're a linux mount or not.


# 1.149 17-Feb-2007 pavel

Change the process/lwp flags seen by userland via sysctl back to the
P_*/L_* naming convention, and rename the in-kernel flags to avoid
conflict. (P_ -> PK_, L_ -> LW_ ). Add back the (now unused) LSDEAD
constant.

Restores source compatibility with pre-newlock2 tools like ps or top.

Reviewed by Andrew Doran.


# 1.148 16-Feb-2007 pooka

branches: 1.148.2;
In lookup, when checking for procfs process node validity, target the
process we're trying to get information about through procfs, not
the caller of lookup.

fixes 'ls -l /proc/*/file' panic, which would occur when trying to
lookup "file" for a kernel thread, which doesn't have p->p_textvp.


# 1.147 15-Feb-2007 ad

Need to acquire procp->p_mutex for procfs_dir().


# 1.146 11-Feb-2007 ad

Eliminate a couple of reference count and mutex leaks.


Revision tags: post-newlock2-merge
# 1.145 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 1.144 25-Dec-2006 elad

PR/35226: Johann Franz: Problems with permissions in
/usr/pkg/emul/linux/proc .

Okay mlelstv@


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3
# 1.143 09-Dec-2006 chs

a smorgasbord of improvements to vnode locking and path lookup:
- LOCKPARENT is no longer relevant for lookup(), relookup() or VOP_LOOKUP().
these now always return the parent vnode locked. namei() works as before.
lookup() and various other paths no longer acquire vnode locks in the
wrong order via vrele(). fixes PR 32535.
as a nice side effect, path lookup is also up to 25% faster.
- the above allows us to get rid of PDIRUNLOCK.
- also get rid of WANTPARENT (just use LOCKPARENT and unlock it).
- remove an assumption in layer_node_find() that all file systems implement
a recursive VOP_LOCK() (unionfs doesn't).
- require that all file systems supply vfs_vptofh and vfs_fhtovp routines.
fill in eopnotsupp() for file systems that don't support being exported
and remove the checks for NULL. (layerfs calls these without checking.)
- in union_lookup1(), don't change refcounts in the ISDOTDOT case, just
adjust which vnode is locked. fixes PR 33374.
- apply fixes for ufs_rename() from ufs_vnops.c rev. 1.61 to ext2fs_rename().


# 1.142 04-Dec-2006 christos

From Nicolas Joly: restore previous behavior in procfs_validfile_linux, since
readdir passes a NULL lwp.


# 1.141 03-Dec-2006 elad

Move kauth(9) call to where it belongs. Noticed by Nicolas Joly, thanks!


Revision tags: netbsd-4-base
# 1.140 28-Nov-2006 elad

branches: 1.140.2;
Move ktrace, ptrace, systrace, and procfs to use kauth(9).

First, remove process_checkioperm() calls from MD code. Similar checks
using kauth(9) routines (on the process scope, using appropriate action)
are done in the callers.

Add secmodel back-end to handle each subsystem.


# 1.139 25-Nov-2006 skrll

Expose the 'exe' symlink to the process realpath in NetBSD as well. An
example user is gdb.

OK'd by christos.


# 1.138 16-Nov-2006 christos

__unused removal on arguments; approved by core.


# 1.137 29-Oct-2006 christos

add an "emul" file node.


# 1.136 25-Oct-2006 christos

1. fix procfs_validfile{,_linux} to test for NULL pointers properly.
2. make "exe" entry be a symlink to the executable, instead of pointing
directly to the vnode of the executable.
3. factor out commonly used code.


Revision tags: yamt-splraiseipl-base2
# 1.135 12-Oct-2006 christos

- sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386


# 1.134 20-Sep-2006 manu

Emulate Linux's /proc/devices


Revision tags: abandoned-netbsd-4-base yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base rpaulo-netinet-merge-pcb-base
# 1.133 13-Jun-2006 yamt

branches: 1.133.6; 1.133.8;
use KAUTH_PROCESS_CANSEE rather than CURTAIN where appropriate.


# 1.132 13-Jun-2006 yamt

remove unnecessary arguments from kauth_authorize_process.
ie. make it similar to the one found in apple TN.


# 1.131 07-Jun-2006 kardel

merge FreeBSD timecounters from branch simonb-timecounters
- struct timeval time is gone
time.tv_sec -> time_second
- struct timeval mono_time is gone
mono_time.tv_sec -> time_uptime
- access to time via
{get,}{micro,nano,bin}time()
get* versions are fast but less precise
- support NTP nanokernel implementation (NTP API 4)
- further reading:
Timecounter Paper: http://phk.freebsd.dk/pubs/timecounter.pdf
NTP Nanokernel: http://www.eecis.udel.edu/~mills/ntp/html/kern.html


Revision tags: yamt-pdpolicy-base5 simonb-timecounters-base
# 1.130 14-May-2006 elad

branches: 1.130.2;
integrate kauth.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 elad-kernelauth-base yamt-pdpolicy-base yamt-uio_vmspace-base5
# 1.129 02-Feb-2006 christos

branches: 1.129.2; 1.129.4; 1.129.6; 1.129.8;
PR/32692: Matthew Mondor: linux compatibility in /proc/self should point
directly to the directory containing the pid instead of pointing to
/proc/curproc, because some programs rely on calling readlink on /proc/self
to get the pid.


# 1.128 11-Dec-2005 christos

branches: 1.128.2; 1.128.4;
merge ktrace-lwp.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base ktrace-lwp-base
# 1.127 02-Nov-2005 yamt

merge yamt-vop branch. remove following VOPs.

VOP_BLKATOFF
VOP_VALLOC
VOP_BALLOC
VOP_REALLOCBLKS
VOP_VFREE
VOP_TRUNCATE
VOP_UPDATE


Revision tags: yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 1.126 01-Oct-2005 atatat

branches: 1.126.2;
Add "cwd" and "root" symlinks to each process's directory. The cwd
link points to the process's current working directory, and the root
link points to the process's root directory. What else would you
expect?

For directories that are out of reach (caller is in a chroot, target
process is in a different chroot, etc), the links point to "/"
instead.


# 1.125 11-Sep-2005 elad

Implement curtain for procfs.


# 1.124 30-Aug-2005 xtraeme

Remove __P()


# 1.123 29-May-2005 christos

branches: 1.123.2;
- sprinkle const
- avoid shadowed variables.


Revision tags: kent-audio2-base
# 1.122 02-Apr-2005 christos

PR/29782: Martin Husemann: procfs can not unmount when some process has its
current directory in curproc. Fix from Pedro Martelletto:
We cannot call vgone() from procfs_inactive() if we are coming from
vclean(). that's what's probably causing the deadlock.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 yamt-km-base4 yamt-km-base3 netbsd-3-base
# 1.121 26-Feb-2005 perry

nuke trailing whitespace


Revision tags: yamt-km-base2 yamt-km-base kent-audio1-beforemerge kent-audio1-base
# 1.120 04-Oct-2004 yamt

branches: 1.120.4; 1.120.6;
procfs_readdir:
- return correct cookie when buffer size is small.
- simplify logic.


# 1.119 04-Oct-2004 yamt

procfs_readdir: remove a redundant assignment.


# 1.118 02-Oct-2004 yamt

procfs_getattr: correct size of /proc/self.


# 1.117 01-Oct-2004 yamt

procfs_readdir:
- fix a locking problem, using proclist_foreach_call. PR/27098.
- correct snprintf size argument.


# 1.116 01-Oct-2004 yamt

procfs_readdir: fix an offset handling bug after addition of /proc/self.


# 1.115 01-Oct-2004 yamt

procfs_readdir: use a list macro.


# 1.114 20-Sep-2004 jdolecek

add 'mounts' file for -o linux, which lists all currently mounted
filesystems; Linux glibc statvfs() uses this to get some of mount flags,
and this file is also useful as /emul/linux/etc/mtab (via symlink)


# 1.113 29-Apr-2004 jrf

Removed remaining caddr_t casts we do not need in miscfs. Recompiled
kernel and ran for a day or so. There are still some caddr_t types in
the arguments of some calls, I will do those separately (later) as
they touch a lot more of the system.
Approved by christos@NetBSD.org.


# 1.112 22-Apr-2004 itojun

sprintf -> snprintf


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.111 15-Feb-2004 jdolecek

unlock the descriptor table simple lock after fd_getfile() call in
procfs_readdir()
fixes procfs locking problems reported on current-users@, problem place
found by enami tsugutomo


# 1.110 30-Oct-2003 simonb

Remove some assigned-to but otherwise unused variables.


# 1.109 27-Sep-2003 darcy

Changes as discussed with itojun on tech-kern. I have modified the enums
to have KFS or PFS differentiators. Further I have wrapped the enum in
procfs in "#ifdef _KERNEL" as it is done in kernfs.

To see the discussion go to http://mail-index.NetBSD.org/tech-kern/2003/09/
and look for "Mismatched enums in include files" in the list.


# 1.108 07-Sep-2003 itojun

remove meaningless line (variable overwritten 2 lines below)


# 1.107 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.


# 1.106 29-Jun-2003 fvdl

branches: 1.106.2;
Back out the lwp/ktrace changes. They contained a lot of colateral damage,
and need to be examined and discussed more.


# 1.105 29-Jun-2003 thorpej

Undo part of the ktrace/lwp changes. In particular:
* Remove the "lwp *" argument that was added to vget(). Turns out
that nothing actually used it!
* Remove the "lwp *" arguments that were added to VFS_ROOT(), VFS_VGET(),
and VFS_FHTOVP(); all they did was pass it to vget() (which, as noted
above, didn't use it).
* Remove all of the "lwp *" arguments to internal functions that were added
just to appease the above.


# 1.104 28-Jun-2003 darrenr

Pass lwp pointers throughtout the kernel, as required, so that the lwpid can
be inserted into ktrace records. The general change has been to replace
"struct proc *" with "struct lwp *" in various function prototypes, pass
the lwp through and use l_proc to get the process pointer when needed.

Bump the kernel rev up to 1.6V


# 1.103 28-May-2003 christos

Add /proc/<pid>/stat for linux compat. j2sdk1.4.2 depends on it.


# 1.102 18-Apr-2003 christos

Make symlinks for directories that point to the actual directory.
Make symlinks to [kqueue] and [misc] for kqueue and misc fds.


# 1.101 17-Apr-2003 jdolecek

do not show nodes corresponding to directory descriptors for process
in fd/ subdirectory, nor allow lookup/open for the nodes
this fixes PR kern/21187 for good, and also avoids interesting directory
locking issues


# 1.100 17-Apr-2003 jdolecek

procfs_readdir(): in Pfd case, only show descriptors of types we want
how to represent (vnodes, fifo, pipes); also use fd_getfile() et al

this avoids annoying EOPNOTSUPP error messages from ls -F and such


# 1.99 17-Apr-2003 jdolecek

procfs_lookup(): use fd_getfile() et al in Pfd case


# 1.98 17-Apr-2003 jdolecek

use fd_getfile() in procfs_getfp(), and FILE_USE()/FILE_UNUSE() the
returned file descriptor pointer appropriately


# 1.97 17-Apr-2003 jdolecek

make some local arrays/variables static + const


# 1.96 10-Apr-2003 jdolecek

use former genfs_eopnotsupp_rele() as genfs_eopnotsupp(), so that vnodes
are vput()/vrele()d as necessary - some filesystems did use the wrong
one for some ops, and it's just safer to not take the chance

based on suggestion by Bill Studenmund


# 1.95 05-Apr-2003 dsl

Remove pointless check against PID_MAX. Let pfind() do the validation.
(The new pid allocation code may decide to allocate pids above PID_MAX.)


# 1.94 25-Feb-2003 jrf

This addresses PR kerm/19989. Thanks to hamajima@nagoya.ydc.co.jp for submitting this patch which enables /proc/uptime for linux emul. Patch reviewed by atatat@netbsd.org and tron@netbsd.org, approved by tron@netbsd.org.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 1.93 04-Jan-2003 martin

Cast off_t expression to long long to match format even on 64 bit
plattforms.

Shouldn't we introduce a PRIoff_t macro to create such format strings?


# 1.92 03-Jan-2003 christos

add LK_CANRECURSE in the locking of /dev/<pid>/fd/<n> and remove the curproc
kludge. Thanks to fvdl.


# 1.91 03-Jan-2003 christos

Implement /proc/<pid>/fd/<n>. This is work in progress. Questionable things:
- Is it ok to convert DTYPE_PIPE to VFIFO and DTYPE_SOCKET to VSOCK?
- XXX: Avoid locking issue in ls -Rl /proc by avoiding curproc
- Does I/O to pipes work?
- XXX: Are there security implications?


Revision tags: fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge gehenna-devsw-base kqueue-base
# 1.90 03-Aug-2002 simonb

Just use the "time" variable in the *_getattr functions instead of a call
to (the potentially expensive) microtime().


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.89 09-May-2002 thorpej

branches: 1.89.2;
Move code shared by procfs and the kernel proper out of procfs and
into the kernel proper (renaming functions from procfs_* to process_*).


Revision tags: eeh-devprop-base newlock-base ifpoll-base
# 1.88 12-Jan-2002 christos

Don't hide the real return code with EPERM.


# 1.87 06-Dec-2001 chs

add a VOP_PUTPAGES method for all the filesystems that don't have pages,
just unlock the interlock.


# 1.86 05-Dec-2001 thorpej

* Allow machine-dependent code to specify hooks for ptrace(2)
(__HAVE_PTRACE_MACHDEP) and procfs (__HAVE_PROCFS_MACHDEP).
These changes will allow platforms like x86 (XMM) and PowerPC
(AltiVec) to export extended register sets in a sane manner.

* Use __HAVE_PTRACE_MACHDEP to export x86 XMM registers (standard
FP + SSE/SSE2) using PT_{GET,SET}XMMREGS (in the machdep
ptrace request space).
* Use __HAVE_PROCFS_MACHDEP to export x86 XMM registers via
/proc/N/xmmregs in procfs.


Revision tags: thorpej-mips-cache-base
# 1.85 10-Nov-2001 lukem

add RCSIDs


# 1.84 06-Nov-2001 simonb

Remove some variables that are set but never used.


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base
# 1.83 31-Aug-2001 chs

branches: 1.83.2; 1.83.4;
map files are zero-length.


# 1.82 03-Jun-2001 chs

branches: 1.82.2;
procfs_bmap() should never be called, make it a "bad op".
let procfs_mmap() use the default error method.


Revision tags: thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 1.81 14-Apr-2001 kleink

In procfs_readdir(), give /proc/# directories DT_DIR (rather than DT_REG).


# 1.80 30-Mar-2001 fvdl

Bump va_blocksize for the map files some more, so that programs with
quite a few mappings have a chance of being handled correctly if
st_blksize is looked at.


# 1.79 29-Mar-2001 fvdl

For -o linux mounts, add some code to emulate /proc/#/maps.
Needs NAMECACHE_ENTER_REVERSE to include filenames.


# 1.78 21-Feb-2001 jdolecek

branches: 1.78.2;
make some more constant arrays 'const'


# 1.77 22-Jan-2001 jdolecek

make filesystem vnodeop, specop, fifoop and vnodeopv_* arrays const


# 1.76 17-Jan-2001 fvdl

Add a few linux-style files, only enabled when -o linux is specified
for the mount. Currently these are /proc/cpuinfo and /proc/meminfo.
The former only does something on i386 right now.


# 1.75 24-Nov-2000 chs

remove dead code and other misc cleanup.


# 1.74 09-Aug-2000 tv

Only show the "exe" entry to Linux processes, suggested by christos.
Since there are actually three struct emul's for linux, use the e_name
field to determine eligibility with strcmp().


# 1.73 09-Aug-2000 tv

Some versions of Linux libc look for /proc/.../exe instead of /proc/../file.
Add an entry for "exe" that is the same as "file", provided only if
COMPAT_LINUX is set.


# 1.72 03-Aug-2000 thorpej

MALLOC()/FREE() are not to be used for variable sized allocations.


# 1.71 28-Jun-2000 mrg

<vm/vm.h> -> <uvm/uvm_extern.h>


Revision tags: netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 1.70 30-Mar-2000 simonb

branches: 1.70.4;
Delete duplicate declaration of atopid().


Revision tags: chs-ubc2-newbase wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base fvdl-softdep-base
# 1.69 02-Sep-1999 thorpej

branches: 1.69.2; 1.69.8;
Make /proc/self a symlink to /proc/curproc. I've observed Linux programs
that expect /proc/self/cmdline to exist.


# 1.68 25-Aug-1999 sommerfeld

Change variable used for directory offset from "int" to "off_t".
Overkill, but avoids a host of truncation problems.


# 1.67 24-Aug-1999 sommerfeld

Fix PR8270:

Problem turned out to be due to improper handling of reads beyond EOF:
they should just return without error with the uio unchanged, and the
caller will recognize this as a zero-byte return (EOF).

The previous fix to protect directory reads against bogus uio_offset
values returned EINVAL, which broke mount -o union, which only
union'ed in the lower directory if the upper directory cleanly
returned EOF.

While we're here, protect kernfs as well.


# 1.66 14-Aug-1999 christos

protect against large uio_offset


# 1.65 03-Aug-1999 wrstuden

Add support for fcntl(2) to generate VOP_FCNTL calls. Any fcntl
call with F_FSCTL set and F_SETFL calls generate calls to a new
fileop fo_fcntl. Add genfs_fcntl() and soo_fcntl() which return 0
for F_SETFL and EOPNOTSUPP otherwise. Have all leaf filesystems
use genfs_fcntl().

Reviewed by: thorpej
Tested by: wrstuden


Revision tags: chs-ubc2-base
# 1.64 25-Jul-1999 thorpej

Add calls to lock the proclist as appropriate.


# 1.63 14-Jul-1999 thorpej

Fix a paste-o in procfs_lookup() introduced with the vnode locking changes.
Fixes PR #7961, Mario Kemper <magick@bundy.lip.owl.de>.


# 1.62 08-Jul-1999 wrstuden

Bump osrelease to 1.4E. Add layerfs files, remove null_subr.c.

Update coda to new struct lock in struct vnode.

make fdescfs, kernfs, portalfs, and procfs actually lock their vnodes.
It's not that hard.

Make unionfs set v_vnlock = NULL so any overlayed fs will call its
VOP_LOCK.


Revision tags: kame_141_19991130 netbsd-1-4-PATCH001 kame_14_19990705 kame_14_19990628 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.61 12-Mar-1999 christos

branches: 1.61.2; 1.61.4;
PR/7143: Jaromir Docelek: Add procfs/cmdline from Linux emulation


# 1.60 25-Jan-1999 msaitoh

Add /proc/#/map. From FreeBSD.


Revision tags: kenh-if-detach-base chs-ubc-base
# 1.59 08-Sep-1998 thorpej

- Use proclists[], rather than checking allproc and zombproc explicitly.
- Add some comments about locking.


# 1.58 13-Aug-1998 kleink

Per POSIX, fail with EINVAL if advisory locking is attempted on a file type
that doesn't support it, rather than using a homegrown EBADF or EOPNOTSUPP.


# 1.57 10-Aug-1998 matthias

create miscfs/genfs/genfs_vnops.c:genfs_enoioctl and make all the other
filesystems use it instead of a private version.


# 1.56 09-Aug-1998 perry

bzero->memset, bcopy->memcpy, bcmp->memcmp


# 1.55 03-Aug-1998 kleink

Recognize _PC_SYNC_IO.


Revision tags: eeh-paddr_t-base
# 1.54 21-Apr-1998 fvdl

procfs_readdir: in case of error, check if cookies actually have
been allocated before freeing them. From Wolfgang Solfrank.


# 1.53 01-Mar-1998 fvdl

Merge with Lite2 + local changes


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base marc-pcmcia-base
# 1.52 10-Oct-1997 fvdl

Bump last argument to VOP_READDIR to off_t (from u_long).


Revision tags: thorpej-signal-base
# 1.51 27-Aug-1997 thorpej

Fix a reversed argument which caused procfs_checkioperm() to always return
"OK". Add a few comments to avoid further confusion.


# 1.50 12-Aug-1997 thorpej

Fix the procfs hole described on current-users, similar to a fix for
FreeBSD by Sean Eric Fagan, but a bit different. This makes the checks
in the same places as sef's FreeBSD patch, but does not hardcode the
"kmem" group into the kernel, and also does a check identical to the
(3) and (4) checks in the NetBSD ptrace(2):

(1) it's not owned by you, or is set-id on exec (unless
you're root), or

(2) it's init, which controls the security level of the
entire system, and the system was not compiled with
permanently insecure mode turned on.


Revision tags: marc-pcmcia-bp
# 1.49 08-May-1997 mycroft

branches: 1.49.4;
Pass the vnode type to vaccess(), and use it when checking VEXEC. Make sure
that the mode bits passed to vaccess() and returned by foo_getattr() contain
only permission bits.


# 1.48 05-May-1997 mycroft

Need stat.h.


# 1.47 05-May-1997 mycroft

Eliminate bogus uses of V{READ,WRITE,EXEC}. Use S_I[RWX]{USR,GRP,OTH} where
appropriate.


# 1.46 28-Apr-1997 mycroft

Minor code cleanup.


Revision tags: is-newarp-before-merge is-newarp-base
# 1.45 25-Oct-1996 cgd

define path name string variables that we should not (and, thankfully, do
not) modify as 'const char *' rather 'char *'.


# 1.44 13-Oct-1996 christos

backout previous kprintf changes


# 1.43 10-Oct-1996 christos

printf -> kprintf, sprintf -> ksprintf


# 1.42 07-Sep-1996 mycroft

Implement poll(2).


# 1.41 01-Sep-1996 mycroft

Add a set of generic file system operations that most file systems use.
Also, fix some time stamp bogosities.


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 1.40 16-Mar-1996 christos

Fix printf format follies.


# 1.39 13-Feb-1996 mycroft

GC *_nullop(). Minor nits.


# 1.38 12-Feb-1996 christos

close PR/2063: procfs_rw prototyped twice with different prototypes


# 1.37 09-Feb-1996 christos

miscfs prototype changes


# 1.36 09-Feb-1996 mycroft

Fix vop_link, vop_symlink, and vop_remove semantics in several ways:
* Change the argument names to vop_link so they actually make sense.
* Implement vop_link and vop_symlink for all file systems, so they do proper
cleanup.
* Require the file system to decide whether or not linking and unlinking of
directories is allowed, and disable it for all current file systems.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.35 09-Oct-1995 mycroft

Use the index number as the cookie, rather than multiplying by UIO_MX.


# 1.34 09-Oct-1995 mycroft

Add support for cookies, mostly from Greg Hudson.


# 1.33 15-Apr-1995 cgd

fix timeval vs. timespec warnings


# 1.32 03-Feb-1995 mycroft

Return EROFS rather than ENOENT in many cases. Also some cosmetic cleanup.


# 1.31 27-Dec-1994 mycroft

Format police.


# 1.30 24-Dec-1994 ws

Implement and use a common access checking routine


# 1.29 14-Dec-1994 mycroft

Remove a_fp.


# 1.28 14-Nov-1994 christos

fixed struct comment


# 1.27 30-Oct-1994 cgd

be more careful with types, also pull in headers where necessary.


# 1.26 20-Oct-1994 cgd

update for new syscall args description mechanism


# 1.25 30-Aug-1994 mycroft

Convert process, file, and namei lists and hash tables to use queue.h.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.24 29-Jun-1994 cgd

New RCS ID's, take two. they're more aesthecially pleasant, and use 'NetBSD'


# 1.23 16-Jun-1994 mycroft

Remove an unneeded test.


# 1.22 15-Jun-1994 mycroft

Minor update from JSP after merging my changes.


# 1.21 08-Jun-1994 mycroft

Update to 4.4-Lite fs code, with local changes.


# 1.20 05-May-1994 cgd

lots of changes: prototype migration, move lots of variables, definitions,
and structure elements around. kill some unnecessary type and macro
definitions. standardize clock handling. More changes than you'd want.


# 1.19 15-Apr-1994 cgd

forgot these...


# 1.18 12-Apr-1994 cgd

be a bit smarter about determining if files shouldn't be seen by the user.
Also, DON'T allow a lookup to succeed on a file that's not visible!


# 1.17 15-Feb-1994 mycroft

Undo last change; executables is `file', not `a.out'.


# 1.16 14-Feb-1994 ws

Rename file -> a.out


# 1.15 14-Feb-1994 ws

Don't try to show a file for a process if there is none


# 1.14 28-Jan-1994 cgd

make a fpregs file.


# 1.13 20-Jan-1994 ws

Make procfs really work for debugging.
Implement not & notepg files in procfs.


# 1.12 09-Jan-1994 ws

Bug fixes and enhancements:
Make NFS serving work (BUT DON'T USE "attach" TO /proc/*/ctl FOR NOW!!!)
Make `curproc' a symbolic link
Add `.' and `..' entries to the directories.
Return better guesses on the size of the files.


# 1.11 05-Jan-1994 cgd

return size of 'reg' from getattr()


# 1.10 05-Jan-1994 cgd

make it compile (cleanly) for us


# 1.9 05-Jan-1994 cgd

add new procfs code, from Jan-Simon Pendry, jsp@sequent.com.
This is pretty-much "virgin", so that diffs can be done later.


# 1.8 18-Dec-1993 mycroft

Canonicalize all #includes.


Revision tags: magnum-base
# 1.7 16-Sep-1993 cgd

kill volatile warning.


# 1.6 07-Sep-1993 ws

branches: 1.6.2;
Changes to VFS readdir semantics
NFS changes for better cookie support
ISOFS changes for better Rockridge support and support for generation numbers


# 1.5 26-Aug-1993 pk

Implement setattr: mode for process entries; mode + uid/gid for the
PROCFS root directory.
Fixed omission in pfs_root() which came to light as a result of the above:
hold on to vnode for root dir.


# 1.4 25-Aug-1993 pk

Fixed improperly initialized nfsnode in pfs_lookup()


# 1.3 24-Aug-1993 pk

copyright update.


# 1.2 24-Aug-1993 pk

Rcs Id added.


# 1.1 24-Aug-1993 pk

branches: 1.1.1;
Initial version of a proc filesystem.


# 1.197 26-May-2017 riastradh

Make VOP_RECLAIM do the last unlock of the vnode.

VOP_RECLAIM naturally has exclusive access to the vnode, so having it
locked on entry is not strictly necessary -- but it means if there
are any final operations that must be done on the vnode, such as
ffs_update, requiring exclusive access to it, we can now kassert that
the vnode is locked in those operations.

We can't just have the caller release the last lock because some file
systems don't use genfs_lock, and require the vnode to remain valid
for VOP_UNLOCK to work, notably unionfs.


Revision tags: prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.196 11-Apr-2017 riastradh

Make VOP_INACTIVE preserve vnode lock on return.

Discussed on tech-kern:
https://mail-index.netbsd.org/tech-kern/2017/04/01/msg021751.html

Ride 7.99.68, a bumpy bus of incremental vfs improvements!


Revision tags: jdolecek-ncq-base
# 1.195 30-Mar-2017 christos

add an auxv node.


Revision tags: pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004 localcount-20160914
# 1.194 20-Aug-2016 hannken

branches: 1.194.2;
Remove now obsolete operation vcache_remove().

Welcome to 7.99.36


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 nick-nhusb-base-20150921 nick-nhusb-base-20150606
# 1.193 20-Apr-2015 riastradh

branches: 1.193.2;
Make VOP_LINK return directory still locked and referenced.

Ride 7.99.10 bump.


Revision tags: nick-nhusb-base-20150406 nick-nhusb-base
# 1.192 05-Sep-2014 matt

branches: 1.192.2;
Try not to use f_data, use f_{vnode,socket,pipe,mqueue,kqueue,ksem} to get
a correctly typed pointer.


Revision tags: netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.191 27-Jul-2014 hannken

Change procfs from hashlist to vcache.
- Key is (type, pid, fd)
- Remove argument "p" from procfs_allocvp(). It is only used
when "type == PFSfd". Lookup the proc with proc_find() when
procfs_loadvnode() needs it.
- Use a vfs_vnode_iterator for procfs_revoke_vnodes().


# 1.190 25-Jul-2014 dholland

Add VOP_FALLOCATE and VOP_FDISCARD to every vnode ops table I can
find.

The filesystem ones all call genfs_eopnotsupp - right now I am only
implementing the plumbing and we can implement fallocate and/or
fdiscard for files later.

The device ones call spec_fallocate (which is also genfs_eopnotsupp)
and spec_fdiscard, which dispatches to the device-level op.

The fifo ones all call vn_fifo_bypass, which also ends up being
EOPNOTSUPP.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base
# 1.189 07-Feb-2014 hannken

branches: 1.189.2;
Change vnode operation lookup to return the resulting vnode *vpp unlocked.
Change cache_lookup() to return an unlocked vnode.

Discussed on tech-kern@

Welcome to 6.99.31


# 1.188 23-Jan-2014 hannken

Change vnode operations create, mknod, mkdir and symlink to return
the resulting vnode *vpp unlocked.

Discussed on tech-kern@

Welcome to 6.99.30


# 1.187 17-Jan-2014 hannken

Change vnode operations create, mknod, mkdir and symlink to keep the
directory node dvp locked on return.

Discussed on tech-kern@

Welcome to 6.99.29


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base
# 1.186 18-Mar-2013 plunky

branches: 1.186.6;
C99 section 6.7.2.3 (Tags) Note 3 states that:

A type specifier of the form

enum identifier

without an enumerator list shall only appear after the type it
specifies is complete.

which means that we cannot pass an "enum vtype" argument to
kauth_access_action() without fully specifying the type first.
Unfortunately there is a complicated include file loop which
makes that difficult, so convert this minimal function into a
macro (and capitalize it).

(ok elad@)


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 1.185 25-Nov-2012 christos

do something reasonable with kernel semaphores.


Revision tags: yamt-pagecache-base6 jmcneill-usbmp-base10
# 1.184 28-May-2012 christos

branches: 1.184.2;
add a task process subdirectory for emul linux


Revision tags: yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 1.183 13-Mar-2012 elad

Replace the remaining KAUTH_GENERIC_ISSUSER authorization calls with
something meaningful. All relevant documentation has been updated or
written.

Most of these changes were brought up in the following messages:

http://mail-index.netbsd.org/tech-kern/2012/01/18/msg012490.html
http://mail-index.netbsd.org/tech-kern/2012/01/19/msg012502.html
http://mail-index.netbsd.org/tech-kern/2012/02/17/msg012728.html

Thanks to christos, manu, njoly, and jmmv for input.

Huge thanks to pgoyette for spinning these changes through some build
cycles and ATF.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.182 04-Sep-2011 jmcneill

branches: 1.182.2; 1.182.6;
PR# kern/45021: Please support /emul/linux/proc/version

Add /proc/version for procfs with -o linux. The version reported depends
on the emulation type of the calling process:

$ cat /proc/version
NetBSD version 5.99.55 (netbsd@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) NetBSD 5.99.55 (GENERIC) #39: Sun Sep 4 09:10:05 EDT 2011

$ /emul/linux/bin/cat /proc/version
Linux version 2.6.18 (linux@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) #0 Wed Mar 3 03:03:03 PST 2010

$ /emul/linux32/bin/cat /proc/version
Linux version 2.6.18 (linux32@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) #0 Wed Mar 3 03:03:03 PST 2010


# 1.181 23-Jun-2011 christos

From Aleksey Cheusov: Don't make it easy for compromised systems to bypass
ASLR protections by providing the mapping addresses of programs to everyone.


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base matt-mips64-premerge-20101231 uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10 rmind-uvmplock-base
# 1.180 01-Jul-2010 rmind

Remove pfind() and pgfind(), fix locking in various broken uses of these.
Rename real routines to proc_find() and pgrp_find(), remove PFIND_* flags
and have consistent behaviour. Provide proc_find_raw() for special cases.
Fix memory leak in sysctl_proc_corename().

COMPAT_LINUX: rework ptrace() locking, minimise differences between
different versions per-arch.

Note: while this change adds some formal cosmetics for COMPAT_DARWIN and
COMPAT_IRIX - locking there is utterly broken (for ages).

Fixes PR/43176.


# 1.179 24-Jun-2010 hannken

Clean up vnode lock operations pass 2:

VOP_UNLOCK(vp, flags) -> VOP_UNLOCK(vp): Remove the unneeded flags argument.

Welcome to 5.99.32.

Discussed on tech-kern.


# 1.178 08-Jun-2010 hannken

Procfs_lookup() does not lookup directory descriptors in the fd/
subdirectory. There is no need for recursive vnode locking here.

Ok: Christos Zoulas <christos@netbsd.org>


Revision tags: uebayasi-xip-base1 yamt-nfs-mp-base9 uebayasi-xip-base
# 1.177 08-Jan-2010 pooka

branches: 1.177.2; 1.177.4;
The VATTR_NULL/VREF/VHOLD/HOLDRELE() macros lost their will to live
years ago when the kernel was modified to not alter ABI based on
DIAGNOSTIC, and now just call the respective function interfaces
(in lowercase). Plenty of mix'n match upper/lowercase has creeped
into the tree since then. Nuke the macros and convert all callsites
to lowercase.

no functional change


Revision tags: matt-premerge-20091211 yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 jym-xensuspend-nbase
# 1.176 03-Jul-2009 elad

Where possible, extract the file-system's access() routine to two internal
functions: the first checking if the operation is possible (regardless of
permissions), the second checking file-system permissions, ACLs, etc.

Mailing list reference:

http://mail-index.netbsd.org/tech-kern/2009/06/21/msg005311.html


# 1.175 23-Jun-2009 elad

Move the implementation of vaccess() to genfs_can_access(), in line with
the other routines of the same spirit.

Adjust file-system code to use it.

Keep vaccess() for KPI compatibility and to keep element of least
surprise. A "diagnostic" message warning that vaccess() is deprecated will
be printed when it's used (obviously, only in DIAGNOSTIC kernels).

No objections on tech-kern@:

http://mail-index.netbsd.org/tech-kern/2009/06/21/msg005310.html


Revision tags: yamt-nfs-mp-base5
# 1.174 24-May-2009 ad

More changes to improve kern_descrip.c.

- Avoid atomics in more places.
- Remove the per-descriptor mutex, and just use filedesc_t::fd_lock.
It was only being used to synchronize close, and in any case we needed
to take fd_lock to free the descriptor slot.
- Optimize certain paths for the <NDFDFILE case.
- Sprinkle more comments and assertions.
- Cache more stuff in filedesc_t.
- Fix numerous minor bugs spotted along the way.
- Restructure how the open files array is maintained, for clarity and so
that we can eliminate the membar_consumer() call in fd_getfile(). This is
mostly syntactic sugar; the main functional change is that fd_nfiles now
lives alongside the open file array.

Some measurements with libmicro:

- simple file syscalls are like close() are between 1 to 10% faster.
- some nice improvements, e.g. poll(1000) which is ~50% faster.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 nick-hppapmap-base2 jym-xensuspend-base nick-hppapmap-base mjf-devfs2-base
# 1.173 17-Dec-2008 cegger

branches: 1.173.2;
kill MALLOC and FREE macros.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 haad-dm-base2 haad-nbase2 ad-audiomp2-base netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 haad-dm-base
# 1.172 05-Sep-2008 skrll

branches: 1.172.2;
PR/39324 kernel diagnostic assertion "l->l_stat != LSZOMB" failed.

Ignore procs with zero or all LSZOMB LWPs. Get a non-LSZOMB LWP to perform
operations against as part of the deal.

procfs really needs to be updated to support multi-threading fully.
Hi Antti!


# 1.171 05-Sep-2008 skrll

ANSIfy


Revision tags: simonb-wapbl-nbase simonb-wapbl-base
# 1.170 02-Jul-2008 rmind

branches: 1.170.2;
Remove proc_representative_lwp(), use a simple LIST_FIRST() instead.
OK by <ad>.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base
# 1.169 28-Apr-2008 martin

branches: 1.169.2; 1.169.4;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-nfs-mp-base
# 1.168 24-Apr-2008 ad

branches: 1.168.2;
Merge proc::p_mutex and proc::p_smutex into a single adaptive mutex, since
we no longer need to guard against access from hardware interrupt handlers.

Additionally, if cloning a process with CLONE_SIGHAND, arrange to have the
child process share the parent's lock so that signal state may be kept in
sync. Partially addresses PR kern/37437.


# 1.167 24-Apr-2008 ad

Network protocol interrupts can now block on locks, so merge the globals
proclist_mutex and proclist_lock into a single adaptive mutex (proc_lock).
Implications:

- Inspecting process state requires thread context, so signals can no longer
be sent from a hardware interrupt handler. Signal activity must be
deferred to a soft interrupt or kthread.

- As the proc state locking is simplified, it's now safe to take exit()
and wait() out from under kernel_lock.

- The system spends less time at IPL_SCHED, and there is less lock activity.


Revision tags: yamt-pf42-baseX yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14
# 1.166 21-Mar-2008 ad

branches: 1.166.2;
Catch up with descriptor handling changes. See kern_descrip.c revision
1.173 for details.


Revision tags: keiichi-mipv6-nbase nick-net80211-sync-base keiichi-mipv6-base bouyer-xeni386-nbase matt-armv6-nbase mjf-devfs-base hpcarm-cleanup-base
# 1.165 23-Jan-2008 elad

branches: 1.165.6;
Tons of process scope changes.

- Add a KAUTH_PROCESS_SCHEDULER action, to handle scheduler related
requests, and add specific requests for set/get scheduler policy and
set/get scheduler parameters.

- Add a KAUTH_PROCESS_KEVENT_FILTER action, to handle kevent(2) related
requests.

- Add a KAUTH_DEVICE_TTY_STI action to handle requests to TIOCSTI.

- Add requests for the KAUTH_PROCESS_CANSEE action, indicating what
process information is being looked at (entry itself, args, env,
open files).

- Add requests for the KAUTH_PROCESS_RLIMIT action indicating set/get.

- Add requests for the KAUTH_PROCESS_CORENAME action indicating set/get.

- Make bsd44 secmodel code handle the newly added rqeuests appropriately.

All of the above make it possible to issue finer-grained kauth(9) calls in
many places, removing some KAUTH_GENERIC_ISSUSER requests.

- Remove the "CAN" from KAUTH_PROCESS_CAN{KTRACE,PROCFS,PTRACE,SIGNAL}.

Discussed with christos@ and yamt@.


Revision tags: bouyer-xeni386-base matt-armv6-base
# 1.164 02-Jan-2008 ad

Merge vmlocking2 to head.


Revision tags: vmlocking2-base3 yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 vmlocking-nbase jmcneill-pm-base reinoud-bufcleanup-base
# 1.163 26-Nov-2007 pooka

branches: 1.163.2; 1.163.6;
Remove the "struct lwp *" argument from all VFS and VOP interfaces.
The general trend is to remove it from all kernel interfaces and
this is a start. In case the calling lwp is desired, curlwp should
be used.

quick consensus on tech-kern


Revision tags: bouyer-xenamd64-base2 bouyer-xenamd64-base
# 1.162 09-Nov-2007 christos

make the last argument of procfs_dir size_t


# 1.161 07-Nov-2007 ad

Merge from vmlocking:

- pool_cache changes.
- Debugger/procfs locking fixes.
- Other minor changes.


Revision tags: jmcneill-base yamt-x86pmap-base4 yamt-x86pmap-base3 vmlocking-base
# 1.160 10-Oct-2007 ad

branches: 1.160.2; 1.160.4;
Merge from vmlocking:

- Split vnode::v_flag into three fields, depending on field locking.
- simple_lock -> kmutex in a few places.
- Fix some simple locking problems.


# 1.159 08-Oct-2007 ad

Merge file descriptor locking, cwdi locking and cross-call changes
from the vmlocking branch.


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base2 yamt-x86pmap-base matt-mips64-base
# 1.158 22-Jul-2007 pooka

branches: 1.158.4; 1.158.6; 1.158.8; 1.158.10;
Don't allow getcwd() on procfs vnodes and provide "/" as the path
instead of the result from getcwd(). The works around locking
panics caused by namei calling VOP_READLINK while holding on to a
directory lock and getcwd() trying to acquire that lock. The real
fix would be to get rid of getcwd() calls within VOPs (not locking
safe), but that's not a viable option in the netbsd-4 timeframe.

Suggestion for workaround from David Holland.


Revision tags: nick-csl-alignment-base mjf-ufs-trans-base
# 1.157 24-May-2007 agc

branches: 1.157.2;
Extend the Linux emulation of /proc to include

/proc/stat
/proc/loadavg and
/proc/<pid>/statm.

These are only present when -o linux is specified as a mount option
to procfs.

Factor out some common code so that it can be used by a number of
functions.

XXX The values returned in the statm emulation need to be verified.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 1.156 04-Apr-2007 rmind

Unfortunately, missed procfs_proc_unlock() in previous.
Pointed out by pooka@


# 1.155 04-Apr-2007 rmind

procfs_readlink: Handle a possible fail of fd_getfile(), also, we
do not need to check for error again.
CID: 4436


# 1.154 09-Mar-2007 ad

branches: 1.154.2; 1.154.4;
- Make the proclist_lock a mutex. The write:read ratio is unfavourable,
and mutexes are cheaper use than RW locks.
- LOCK_ASSERT -> KASSERT in some places.
- Hold proclist_lock/kernel_lock longer in a couple of places.


# 1.153 04-Mar-2007 christos

Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.


# 1.152 03-Mar-2007 salo

Don't prepend rootvnode to the path in non-NULL case for exe links.
It breaks procfs in chroot.

from <christos>, tested by me.


Revision tags: ad-audiomp-base
# 1.151 19-Feb-2007 pooka

When checking for file validity under pid/, do proper proc->lwp
lookup (fsvo proper) instead of fiddling directly with the lwp
list.


# 1.150 18-Feb-2007 pooka

Don't check for validity of p in lookup for root nodes, since it
will always be NULL. Rather, just call pt_valid with NULL directly
and let it decide if we're a linux mount or not.


# 1.149 17-Feb-2007 pavel

Change the process/lwp flags seen by userland via sysctl back to the
P_*/L_* naming convention, and rename the in-kernel flags to avoid
conflict. (P_ -> PK_, L_ -> LW_ ). Add back the (now unused) LSDEAD
constant.

Restores source compatibility with pre-newlock2 tools like ps or top.

Reviewed by Andrew Doran.


# 1.148 16-Feb-2007 pooka

branches: 1.148.2;
In lookup, when checking for procfs process node validity, target the
process we're trying to get information about through procfs, not
the caller of lookup.

fixes 'ls -l /proc/*/file' panic, which would occur when trying to
lookup "file" for a kernel thread, which doesn't have p->p_textvp.


# 1.147 15-Feb-2007 ad

Need to acquire procp->p_mutex for procfs_dir().


# 1.146 11-Feb-2007 ad

Eliminate a couple of reference count and mutex leaks.


Revision tags: post-newlock2-merge
# 1.145 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 1.144 25-Dec-2006 elad

PR/35226: Johann Franz: Problems with permissions in
/usr/pkg/emul/linux/proc .

Okay mlelstv@


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3
# 1.143 09-Dec-2006 chs

a smorgasbord of improvements to vnode locking and path lookup:
- LOCKPARENT is no longer relevant for lookup(), relookup() or VOP_LOOKUP().
these now always return the parent vnode locked. namei() works as before.
lookup() and various other paths no longer acquire vnode locks in the
wrong order via vrele(). fixes PR 32535.
as a nice side effect, path lookup is also up to 25% faster.
- the above allows us to get rid of PDIRUNLOCK.
- also get rid of WANTPARENT (just use LOCKPARENT and unlock it).
- remove an assumption in layer_node_find() that all file systems implement
a recursive VOP_LOCK() (unionfs doesn't).
- require that all file systems supply vfs_vptofh and vfs_fhtovp routines.
fill in eopnotsupp() for file systems that don't support being exported
and remove the checks for NULL. (layerfs calls these without checking.)
- in union_lookup1(), don't change refcounts in the ISDOTDOT case, just
adjust which vnode is locked. fixes PR 33374.
- apply fixes for ufs_rename() from ufs_vnops.c rev. 1.61 to ext2fs_rename().


# 1.142 04-Dec-2006 christos

From Nicolas Joly: restore previous behavior in procfs_validfile_linux, since
readdir passes a NULL lwp.


# 1.141 03-Dec-2006 elad

Move kauth(9) call to where it belongs. Noticed by Nicolas Joly, thanks!


Revision tags: netbsd-4-base
# 1.140 28-Nov-2006 elad

branches: 1.140.2;
Move ktrace, ptrace, systrace, and procfs to use kauth(9).

First, remove process_checkioperm() calls from MD code. Similar checks
using kauth(9) routines (on the process scope, using appropriate action)
are done in the callers.

Add secmodel back-end to handle each subsystem.


# 1.139 25-Nov-2006 skrll

Expose the 'exe' symlink to the process realpath in NetBSD as well. An
example user is gdb.

OK'd by christos.


# 1.138 16-Nov-2006 christos

__unused removal on arguments; approved by core.


# 1.137 29-Oct-2006 christos

add an "emul" file node.


# 1.136 25-Oct-2006 christos

1. fix procfs_validfile{,_linux} to test for NULL pointers properly.
2. make "exe" entry be a symlink to the executable, instead of pointing
directly to the vnode of the executable.
3. factor out commonly used code.


Revision tags: yamt-splraiseipl-base2
# 1.135 12-Oct-2006 christos

- sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386


# 1.134 20-Sep-2006 manu

Emulate Linux's /proc/devices


Revision tags: abandoned-netbsd-4-base yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base rpaulo-netinet-merge-pcb-base
# 1.133 13-Jun-2006 yamt

branches: 1.133.6; 1.133.8;
use KAUTH_PROCESS_CANSEE rather than CURTAIN where appropriate.


# 1.132 13-Jun-2006 yamt

remove unnecessary arguments from kauth_authorize_process.
ie. make it similar to the one found in apple TN.


# 1.131 07-Jun-2006 kardel

merge FreeBSD timecounters from branch simonb-timecounters
- struct timeval time is gone
time.tv_sec -> time_second
- struct timeval mono_time is gone
mono_time.tv_sec -> time_uptime
- access to time via
{get,}{micro,nano,bin}time()
get* versions are fast but less precise
- support NTP nanokernel implementation (NTP API 4)
- further reading:
Timecounter Paper: http://phk.freebsd.dk/pubs/timecounter.pdf
NTP Nanokernel: http://www.eecis.udel.edu/~mills/ntp/html/kern.html


Revision tags: yamt-pdpolicy-base5 simonb-timecounters-base
# 1.130 14-May-2006 elad

branches: 1.130.2;
integrate kauth.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 elad-kernelauth-base yamt-pdpolicy-base yamt-uio_vmspace-base5
# 1.129 02-Feb-2006 christos

branches: 1.129.2; 1.129.4; 1.129.6; 1.129.8;
PR/32692: Matthew Mondor: linux compatibility in /proc/self should point
directly to the directory containing the pid instead of pointing to
/proc/curproc, because some programs rely on calling readlink on /proc/self
to get the pid.


# 1.128 11-Dec-2005 christos

branches: 1.128.2; 1.128.4;
merge ktrace-lwp.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base ktrace-lwp-base
# 1.127 02-Nov-2005 yamt

merge yamt-vop branch. remove following VOPs.

VOP_BLKATOFF
VOP_VALLOC
VOP_BALLOC
VOP_REALLOCBLKS
VOP_VFREE
VOP_TRUNCATE
VOP_UPDATE


Revision tags: yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 1.126 01-Oct-2005 atatat

branches: 1.126.2;
Add "cwd" and "root" symlinks to each process's directory. The cwd
link points to the process's current working directory, and the root
link points to the process's root directory. What else would you
expect?

For directories that are out of reach (caller is in a chroot, target
process is in a different chroot, etc), the links point to "/"
instead.


# 1.125 11-Sep-2005 elad

Implement curtain for procfs.


# 1.124 30-Aug-2005 xtraeme

Remove __P()


# 1.123 29-May-2005 christos

branches: 1.123.2;
- sprinkle const
- avoid shadowed variables.


Revision tags: kent-audio2-base
# 1.122 02-Apr-2005 christos

PR/29782: Martin Husemann: procfs can not unmount when some process has its
current directory in curproc. Fix from Pedro Martelletto:
We cannot call vgone() from procfs_inactive() if we are coming from
vclean(). that's what's probably causing the deadlock.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 yamt-km-base4 yamt-km-base3 netbsd-3-base
# 1.121 26-Feb-2005 perry

nuke trailing whitespace


Revision tags: yamt-km-base2 yamt-km-base kent-audio1-beforemerge kent-audio1-base
# 1.120 04-Oct-2004 yamt

branches: 1.120.4; 1.120.6;
procfs_readdir:
- return correct cookie when buffer size is small.
- simplify logic.


# 1.119 04-Oct-2004 yamt

procfs_readdir: remove a redundant assignment.


# 1.118 02-Oct-2004 yamt

procfs_getattr: correct size of /proc/self.


# 1.117 01-Oct-2004 yamt

procfs_readdir:
- fix a locking problem, using proclist_foreach_call. PR/27098.
- correct snprintf size argument.


# 1.116 01-Oct-2004 yamt

procfs_readdir: fix an offset handling bug after addition of /proc/self.


# 1.115 01-Oct-2004 yamt

procfs_readdir: use a list macro.


# 1.114 20-Sep-2004 jdolecek

add 'mounts' file for -o linux, which lists all currently mounted
filesystems; Linux glibc statvfs() uses this to get some of mount flags,
and this file is also useful as /emul/linux/etc/mtab (via symlink)


# 1.113 29-Apr-2004 jrf

Removed remaining caddr_t casts we do not need in miscfs. Recompiled
kernel and ran for a day or so. There are still some caddr_t types in
the arguments of some calls, I will do those separately (later) as
they touch a lot more of the system.
Approved by christos@NetBSD.org.


# 1.112 22-Apr-2004 itojun

sprintf -> snprintf


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.111 15-Feb-2004 jdolecek

unlock the descriptor table simple lock after fd_getfile() call in
procfs_readdir()
fixes procfs locking problems reported on current-users@, problem place
found by enami tsugutomo


# 1.110 30-Oct-2003 simonb

Remove some assigned-to but otherwise unused variables.


# 1.109 27-Sep-2003 darcy

Changes as discussed with itojun on tech-kern. I have modified the enums
to have KFS or PFS differentiators. Further I have wrapped the enum in
procfs in "#ifdef _KERNEL" as it is done in kernfs.

To see the discussion go to http://mail-index.NetBSD.org/tech-kern/2003/09/
and look for "Mismatched enums in include files" in the list.


# 1.108 07-Sep-2003 itojun

remove meaningless line (variable overwritten 2 lines below)


# 1.107 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.


# 1.106 29-Jun-2003 fvdl

branches: 1.106.2;
Back out the lwp/ktrace changes. They contained a lot of colateral damage,
and need to be examined and discussed more.


# 1.105 29-Jun-2003 thorpej

Undo part of the ktrace/lwp changes. In particular:
* Remove the "lwp *" argument that was added to vget(). Turns out
that nothing actually used it!
* Remove the "lwp *" arguments that were added to VFS_ROOT(), VFS_VGET(),
and VFS_FHTOVP(); all they did was pass it to vget() (which, as noted
above, didn't use it).
* Remove all of the "lwp *" arguments to internal functions that were added
just to appease the above.


# 1.104 28-Jun-2003 darrenr

Pass lwp pointers throughtout the kernel, as required, so that the lwpid can
be inserted into ktrace records. The general change has been to replace
"struct proc *" with "struct lwp *" in various function prototypes, pass
the lwp through and use l_proc to get the process pointer when needed.

Bump the kernel rev up to 1.6V


# 1.103 28-May-2003 christos

Add /proc/<pid>/stat for linux compat. j2sdk1.4.2 depends on it.


# 1.102 18-Apr-2003 christos

Make symlinks for directories that point to the actual directory.
Make symlinks to [kqueue] and [misc] for kqueue and misc fds.


# 1.101 17-Apr-2003 jdolecek

do not show nodes corresponding to directory descriptors for process
in fd/ subdirectory, nor allow lookup/open for the nodes
this fixes PR kern/21187 for good, and also avoids interesting directory
locking issues


# 1.100 17-Apr-2003 jdolecek

procfs_readdir(): in Pfd case, only show descriptors of types we want
how to represent (vnodes, fifo, pipes); also use fd_getfile() et al

this avoids annoying EOPNOTSUPP error messages from ls -F and such


# 1.99 17-Apr-2003 jdolecek

procfs_lookup(): use fd_getfile() et al in Pfd case


# 1.98 17-Apr-2003 jdolecek

use fd_getfile() in procfs_getfp(), and FILE_USE()/FILE_UNUSE() the
returned file descriptor pointer appropriately


# 1.97 17-Apr-2003 jdolecek

make some local arrays/variables static + const


# 1.96 10-Apr-2003 jdolecek

use former genfs_eopnotsupp_rele() as genfs_eopnotsupp(), so that vnodes
are vput()/vrele()d as necessary - some filesystems did use the wrong
one for some ops, and it's just safer to not take the chance

based on suggestion by Bill Studenmund


# 1.95 05-Apr-2003 dsl

Remove pointless check against PID_MAX. Let pfind() do the validation.
(The new pid allocation code may decide to allocate pids above PID_MAX.)


# 1.94 25-Feb-2003 jrf

This addresses PR kerm/19989. Thanks to hamajima@nagoya.ydc.co.jp for submitting this patch which enables /proc/uptime for linux emul. Patch reviewed by atatat@netbsd.org and tron@netbsd.org, approved by tron@netbsd.org.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 1.93 04-Jan-2003 martin

Cast off_t expression to long long to match format even on 64 bit
plattforms.

Shouldn't we introduce a PRIoff_t macro to create such format strings?


# 1.92 03-Jan-2003 christos

add LK_CANRECURSE in the locking of /dev/<pid>/fd/<n> and remove the curproc
kludge. Thanks to fvdl.


# 1.91 03-Jan-2003 christos

Implement /proc/<pid>/fd/<n>. This is work in progress. Questionable things:
- Is it ok to convert DTYPE_PIPE to VFIFO and DTYPE_SOCKET to VSOCK?
- XXX: Avoid locking issue in ls -Rl /proc by avoiding curproc
- Does I/O to pipes work?
- XXX: Are there security implications?


Revision tags: fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge gehenna-devsw-base kqueue-base
# 1.90 03-Aug-2002 simonb

Just use the "time" variable in the *_getattr functions instead of a call
to (the potentially expensive) microtime().


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.89 09-May-2002 thorpej

branches: 1.89.2;
Move code shared by procfs and the kernel proper out of procfs and
into the kernel proper (renaming functions from procfs_* to process_*).


Revision tags: eeh-devprop-base newlock-base ifpoll-base
# 1.88 12-Jan-2002 christos

Don't hide the real return code with EPERM.


# 1.87 06-Dec-2001 chs

add a VOP_PUTPAGES method for all the filesystems that don't have pages,
just unlock the interlock.


# 1.86 05-Dec-2001 thorpej

* Allow machine-dependent code to specify hooks for ptrace(2)
(__HAVE_PTRACE_MACHDEP) and procfs (__HAVE_PROCFS_MACHDEP).
These changes will allow platforms like x86 (XMM) and PowerPC
(AltiVec) to export extended register sets in a sane manner.

* Use __HAVE_PTRACE_MACHDEP to export x86 XMM registers (standard
FP + SSE/SSE2) using PT_{GET,SET}XMMREGS (in the machdep
ptrace request space).
* Use __HAVE_PROCFS_MACHDEP to export x86 XMM registers via
/proc/N/xmmregs in procfs.


Revision tags: thorpej-mips-cache-base
# 1.85 10-Nov-2001 lukem

add RCSIDs


# 1.84 06-Nov-2001 simonb

Remove some variables that are set but never used.


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base
# 1.83 31-Aug-2001 chs

branches: 1.83.2; 1.83.4;
map files are zero-length.


# 1.82 03-Jun-2001 chs

branches: 1.82.2;
procfs_bmap() should never be called, make it a "bad op".
let procfs_mmap() use the default error method.


Revision tags: thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 1.81 14-Apr-2001 kleink

In procfs_readdir(), give /proc/# directories DT_DIR (rather than DT_REG).


# 1.80 30-Mar-2001 fvdl

Bump va_blocksize for the map files some more, so that programs with
quite a few mappings have a chance of being handled correctly if
st_blksize is looked at.


# 1.79 29-Mar-2001 fvdl

For -o linux mounts, add some code to emulate /proc/#/maps.
Needs NAMECACHE_ENTER_REVERSE to include filenames.


# 1.78 21-Feb-2001 jdolecek

branches: 1.78.2;
make some more constant arrays 'const'


# 1.77 22-Jan-2001 jdolecek

make filesystem vnodeop, specop, fifoop and vnodeopv_* arrays const


# 1.76 17-Jan-2001 fvdl

Add a few linux-style files, only enabled when -o linux is specified
for the mount. Currently these are /proc/cpuinfo and /proc/meminfo.
The former only does something on i386 right now.


# 1.75 24-Nov-2000 chs

remove dead code and other misc cleanup.


# 1.74 09-Aug-2000 tv

Only show the "exe" entry to Linux processes, suggested by christos.
Since there are actually three struct emul's for linux, use the e_name
field to determine eligibility with strcmp().


# 1.73 09-Aug-2000 tv

Some versions of Linux libc look for /proc/.../exe instead of /proc/../file.
Add an entry for "exe" that is the same as "file", provided only if
COMPAT_LINUX is set.


# 1.72 03-Aug-2000 thorpej

MALLOC()/FREE() are not to be used for variable sized allocations.


# 1.71 28-Jun-2000 mrg

<vm/vm.h> -> <uvm/uvm_extern.h>


Revision tags: netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 1.70 30-Mar-2000 simonb

branches: 1.70.4;
Delete duplicate declaration of atopid().


Revision tags: chs-ubc2-newbase wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base fvdl-softdep-base
# 1.69 02-Sep-1999 thorpej

branches: 1.69.2; 1.69.8;
Make /proc/self a symlink to /proc/curproc. I've observed Linux programs
that expect /proc/self/cmdline to exist.


# 1.68 25-Aug-1999 sommerfeld

Change variable used for directory offset from "int" to "off_t".
Overkill, but avoids a host of truncation problems.


# 1.67 24-Aug-1999 sommerfeld

Fix PR8270:

Problem turned out to be due to improper handling of reads beyond EOF:
they should just return without error with the uio unchanged, and the
caller will recognize this as a zero-byte return (EOF).

The previous fix to protect directory reads against bogus uio_offset
values returned EINVAL, which broke mount -o union, which only
union'ed in the lower directory if the upper directory cleanly
returned EOF.

While we're here, protect kernfs as well.


# 1.66 14-Aug-1999 christos

protect against large uio_offset


# 1.65 03-Aug-1999 wrstuden

Add support for fcntl(2) to generate VOP_FCNTL calls. Any fcntl
call with F_FSCTL set and F_SETFL calls generate calls to a new
fileop fo_fcntl. Add genfs_fcntl() and soo_fcntl() which return 0
for F_SETFL and EOPNOTSUPP otherwise. Have all leaf filesystems
use genfs_fcntl().

Reviewed by: thorpej
Tested by: wrstuden


Revision tags: chs-ubc2-base
# 1.64 25-Jul-1999 thorpej

Add calls to lock the proclist as appropriate.


# 1.63 14-Jul-1999 thorpej

Fix a paste-o in procfs_lookup() introduced with the vnode locking changes.
Fixes PR #7961, Mario Kemper <magick@bundy.lip.owl.de>.


# 1.62 08-Jul-1999 wrstuden

Bump osrelease to 1.4E. Add layerfs files, remove null_subr.c.

Update coda to new struct lock in struct vnode.

make fdescfs, kernfs, portalfs, and procfs actually lock their vnodes.
It's not that hard.

Make unionfs set v_vnlock = NULL so any overlayed fs will call its
VOP_LOCK.


Revision tags: kame_141_19991130 netbsd-1-4-PATCH001 kame_14_19990705 kame_14_19990628 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.61 12-Mar-1999 christos

branches: 1.61.2; 1.61.4;
PR/7143: Jaromir Docelek: Add procfs/cmdline from Linux emulation


# 1.60 25-Jan-1999 msaitoh

Add /proc/#/map. From FreeBSD.


Revision tags: kenh-if-detach-base chs-ubc-base
# 1.59 08-Sep-1998 thorpej

- Use proclists[], rather than checking allproc and zombproc explicitly.
- Add some comments about locking.


# 1.58 13-Aug-1998 kleink

Per POSIX, fail with EINVAL if advisory locking is attempted on a file type
that doesn't support it, rather than using a homegrown EBADF or EOPNOTSUPP.


# 1.57 10-Aug-1998 matthias

create miscfs/genfs/genfs_vnops.c:genfs_enoioctl and make all the other
filesystems use it instead of a private version.


# 1.56 09-Aug-1998 perry

bzero->memset, bcopy->memcpy, bcmp->memcmp


# 1.55 03-Aug-1998 kleink

Recognize _PC_SYNC_IO.


Revision tags: eeh-paddr_t-base
# 1.54 21-Apr-1998 fvdl

procfs_readdir: in case of error, check if cookies actually have
been allocated before freeing them. From Wolfgang Solfrank.


# 1.53 01-Mar-1998 fvdl

Merge with Lite2 + local changes


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base marc-pcmcia-base
# 1.52 10-Oct-1997 fvdl

Bump last argument to VOP_READDIR to off_t (from u_long).


Revision tags: thorpej-signal-base
# 1.51 27-Aug-1997 thorpej

Fix a reversed argument which caused procfs_checkioperm() to always return
"OK". Add a few comments to avoid further confusion.


# 1.50 12-Aug-1997 thorpej

Fix the procfs hole described on current-users, similar to a fix for
FreeBSD by Sean Eric Fagan, but a bit different. This makes the checks
in the same places as sef's FreeBSD patch, but does not hardcode the
"kmem" group into the kernel, and also does a check identical to the
(3) and (4) checks in the NetBSD ptrace(2):

(1) it's not owned by you, or is set-id on exec (unless
you're root), or

(2) it's init, which controls the security level of the
entire system, and the system was not compiled with
permanently insecure mode turned on.


Revision tags: marc-pcmcia-bp
# 1.49 08-May-1997 mycroft

branches: 1.49.4;
Pass the vnode type to vaccess(), and use it when checking VEXEC. Make sure
that the mode bits passed to vaccess() and returned by foo_getattr() contain
only permission bits.


# 1.48 05-May-1997 mycroft

Need stat.h.


# 1.47 05-May-1997 mycroft

Eliminate bogus uses of V{READ,WRITE,EXEC}. Use S_I[RWX]{USR,GRP,OTH} where
appropriate.


# 1.46 28-Apr-1997 mycroft

Minor code cleanup.


Revision tags: is-newarp-before-merge is-newarp-base
# 1.45 25-Oct-1996 cgd

define path name string variables that we should not (and, thankfully, do
not) modify as 'const char *' rather 'char *'.


# 1.44 13-Oct-1996 christos

backout previous kprintf changes


# 1.43 10-Oct-1996 christos

printf -> kprintf, sprintf -> ksprintf


# 1.42 07-Sep-1996 mycroft

Implement poll(2).


# 1.41 01-Sep-1996 mycroft

Add a set of generic file system operations that most file systems use.
Also, fix some time stamp bogosities.


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 1.40 16-Mar-1996 christos

Fix printf format follies.


# 1.39 13-Feb-1996 mycroft

GC *_nullop(). Minor nits.


# 1.38 12-Feb-1996 christos

close PR/2063: procfs_rw prototyped twice with different prototypes


# 1.37 09-Feb-1996 christos

miscfs prototype changes


# 1.36 09-Feb-1996 mycroft

Fix vop_link, vop_symlink, and vop_remove semantics in several ways:
* Change the argument names to vop_link so they actually make sense.
* Implement vop_link and vop_symlink for all file systems, so they do proper
cleanup.
* Require the file system to decide whether or not linking and unlinking of
directories is allowed, and disable it for all current file systems.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.35 09-Oct-1995 mycroft

Use the index number as the cookie, rather than multiplying by UIO_MX.


# 1.34 09-Oct-1995 mycroft

Add support for cookies, mostly from Greg Hudson.


# 1.33 15-Apr-1995 cgd

fix timeval vs. timespec warnings


# 1.32 03-Feb-1995 mycroft

Return EROFS rather than ENOENT in many cases. Also some cosmetic cleanup.


# 1.31 27-Dec-1994 mycroft

Format police.


# 1.30 24-Dec-1994 ws

Implement and use a common access checking routine


# 1.29 14-Dec-1994 mycroft

Remove a_fp.


# 1.28 14-Nov-1994 christos

fixed struct comment


# 1.27 30-Oct-1994 cgd

be more careful with types, also pull in headers where necessary.


# 1.26 20-Oct-1994 cgd

update for new syscall args description mechanism


# 1.25 30-Aug-1994 mycroft

Convert process, file, and namei lists and hash tables to use queue.h.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.24 29-Jun-1994 cgd

New RCS ID's, take two. they're more aesthecially pleasant, and use 'NetBSD'


# 1.23 16-Jun-1994 mycroft

Remove an unneeded test.


# 1.22 15-Jun-1994 mycroft

Minor update from JSP after merging my changes.


# 1.21 08-Jun-1994 mycroft

Update to 4.4-Lite fs code, with local changes.


# 1.20 05-May-1994 cgd

lots of changes: prototype migration, move lots of variables, definitions,
and structure elements around. kill some unnecessary type and macro
definitions. standardize clock handling. More changes than you'd want.


# 1.19 15-Apr-1994 cgd

forgot these...


# 1.18 12-Apr-1994 cgd

be a bit smarter about determining if files shouldn't be seen by the user.
Also, DON'T allow a lookup to succeed on a file that's not visible!


# 1.17 15-Feb-1994 mycroft

Undo last change; executables is `file', not `a.out'.


# 1.16 14-Feb-1994 ws

Rename file -> a.out


# 1.15 14-Feb-1994 ws

Don't try to show a file for a process if there is none


# 1.14 28-Jan-1994 cgd

make a fpregs file.


# 1.13 20-Jan-1994 ws

Make procfs really work for debugging.
Implement not & notepg files in procfs.


# 1.12 09-Jan-1994 ws

Bug fixes and enhancements:
Make NFS serving work (BUT DON'T USE "attach" TO /proc/*/ctl FOR NOW!!!)
Make `curproc' a symbolic link
Add `.' and `..' entries to the directories.
Return better guesses on the size of the files.


# 1.11 05-Jan-1994 cgd

return size of 'reg' from getattr()


# 1.10 05-Jan-1994 cgd

make it compile (cleanly) for us


# 1.9 05-Jan-1994 cgd

add new procfs code, from Jan-Simon Pendry, jsp@sequent.com.
This is pretty-much "virgin", so that diffs can be done later.


# 1.8 18-Dec-1993 mycroft

Canonicalize all #includes.


Revision tags: magnum-base
# 1.7 16-Sep-1993 cgd

kill volatile warning.


# 1.6 07-Sep-1993 ws

branches: 1.6.2;
Changes to VFS readdir semantics
NFS changes for better cookie support
ISOFS changes for better Rockridge support and support for generation numbers


# 1.5 26-Aug-1993 pk

Implement setattr: mode for process entries; mode + uid/gid for the
PROCFS root directory.
Fixed omission in pfs_root() which came to light as a result of the above:
hold on to vnode for root dir.


# 1.4 25-Aug-1993 pk

Fixed improperly initialized nfsnode in pfs_lookup()


# 1.3 24-Aug-1993 pk

copyright update.


# 1.2 24-Aug-1993 pk

Rcs Id added.


# 1.1 24-Aug-1993 pk

branches: 1.1.1;
Initial version of a proc filesystem.


Revision tags: prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.196 11-Apr-2017 riastradh

Make VOP_INACTIVE preserve vnode lock on return.

Discussed on tech-kern:
https://mail-index.netbsd.org/tech-kern/2017/04/01/msg021751.html

Ride 7.99.68, a bumpy bus of incremental vfs improvements!


Revision tags: jdolecek-ncq-base
# 1.195 30-Mar-2017 christos

add an auxv node.


Revision tags: pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004 localcount-20160914
# 1.194 20-Aug-2016 hannken

branches: 1.194.2;
Remove now obsolete operation vcache_remove().

Welcome to 7.99.36


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 nick-nhusb-base-20150921 nick-nhusb-base-20150606
# 1.193 20-Apr-2015 riastradh

branches: 1.193.2;
Make VOP_LINK return directory still locked and referenced.

Ride 7.99.10 bump.


Revision tags: nick-nhusb-base-20150406 nick-nhusb-base
# 1.192 05-Sep-2014 matt

branches: 1.192.2;
Try not to use f_data, use f_{vnode,socket,pipe,mqueue,kqueue,ksem} to get
a correctly typed pointer.


Revision tags: netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.191 27-Jul-2014 hannken

Change procfs from hashlist to vcache.
- Key is (type, pid, fd)
- Remove argument "p" from procfs_allocvp(). It is only used
when "type == PFSfd". Lookup the proc with proc_find() when
procfs_loadvnode() needs it.
- Use a vfs_vnode_iterator for procfs_revoke_vnodes().


# 1.190 25-Jul-2014 dholland

Add VOP_FALLOCATE and VOP_FDISCARD to every vnode ops table I can
find.

The filesystem ones all call genfs_eopnotsupp - right now I am only
implementing the plumbing and we can implement fallocate and/or
fdiscard for files later.

The device ones call spec_fallocate (which is also genfs_eopnotsupp)
and spec_fdiscard, which dispatches to the device-level op.

The fifo ones all call vn_fifo_bypass, which also ends up being
EOPNOTSUPP.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base
# 1.189 07-Feb-2014 hannken

branches: 1.189.2;
Change vnode operation lookup to return the resulting vnode *vpp unlocked.
Change cache_lookup() to return an unlocked vnode.

Discussed on tech-kern@

Welcome to 6.99.31


# 1.188 23-Jan-2014 hannken

Change vnode operations create, mknod, mkdir and symlink to return
the resulting vnode *vpp unlocked.

Discussed on tech-kern@

Welcome to 6.99.30


# 1.187 17-Jan-2014 hannken

Change vnode operations create, mknod, mkdir and symlink to keep the
directory node dvp locked on return.

Discussed on tech-kern@

Welcome to 6.99.29


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base
# 1.186 18-Mar-2013 plunky

branches: 1.186.6;
C99 section 6.7.2.3 (Tags) Note 3 states that:

A type specifier of the form

enum identifier

without an enumerator list shall only appear after the type it
specifies is complete.

which means that we cannot pass an "enum vtype" argument to
kauth_access_action() without fully specifying the type first.
Unfortunately there is a complicated include file loop which
makes that difficult, so convert this minimal function into a
macro (and capitalize it).

(ok elad@)


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 1.185 25-Nov-2012 christos

do something reasonable with kernel semaphores.


Revision tags: yamt-pagecache-base6 jmcneill-usbmp-base10
# 1.184 28-May-2012 christos

branches: 1.184.2;
add a task process subdirectory for emul linux


Revision tags: yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 1.183 13-Mar-2012 elad

Replace the remaining KAUTH_GENERIC_ISSUSER authorization calls with
something meaningful. All relevant documentation has been updated or
written.

Most of these changes were brought up in the following messages:

http://mail-index.netbsd.org/tech-kern/2012/01/18/msg012490.html
http://mail-index.netbsd.org/tech-kern/2012/01/19/msg012502.html
http://mail-index.netbsd.org/tech-kern/2012/02/17/msg012728.html

Thanks to christos, manu, njoly, and jmmv for input.

Huge thanks to pgoyette for spinning these changes through some build
cycles and ATF.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.182 04-Sep-2011 jmcneill

branches: 1.182.2; 1.182.6;
PR# kern/45021: Please support /emul/linux/proc/version

Add /proc/version for procfs with -o linux. The version reported depends
on the emulation type of the calling process:

$ cat /proc/version
NetBSD version 5.99.55 (netbsd@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) NetBSD 5.99.55 (GENERIC) #39: Sun Sep 4 09:10:05 EDT 2011

$ /emul/linux/bin/cat /proc/version
Linux version 2.6.18 (linux@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) #0 Wed Mar 3 03:03:03 PST 2010

$ /emul/linux32/bin/cat /proc/version
Linux version 2.6.18 (linux32@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) #0 Wed Mar 3 03:03:03 PST 2010


# 1.181 23-Jun-2011 christos

From Aleksey Cheusov: Don't make it easy for compromised systems to bypass
ASLR protections by providing the mapping addresses of programs to everyone.


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base matt-mips64-premerge-20101231 uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10 rmind-uvmplock-base
# 1.180 01-Jul-2010 rmind

Remove pfind() and pgfind(), fix locking in various broken uses of these.
Rename real routines to proc_find() and pgrp_find(), remove PFIND_* flags
and have consistent behaviour. Provide proc_find_raw() for special cases.
Fix memory leak in sysctl_proc_corename().

COMPAT_LINUX: rework ptrace() locking, minimise differences between
different versions per-arch.

Note: while this change adds some formal cosmetics for COMPAT_DARWIN and
COMPAT_IRIX - locking there is utterly broken (for ages).

Fixes PR/43176.


# 1.179 24-Jun-2010 hannken

Clean up vnode lock operations pass 2:

VOP_UNLOCK(vp, flags) -> VOP_UNLOCK(vp): Remove the unneeded flags argument.

Welcome to 5.99.32.

Discussed on tech-kern.


# 1.178 08-Jun-2010 hannken

Procfs_lookup() does not lookup directory descriptors in the fd/
subdirectory. There is no need for recursive vnode locking here.

Ok: Christos Zoulas <christos@netbsd.org>


Revision tags: uebayasi-xip-base1 yamt-nfs-mp-base9 uebayasi-xip-base
# 1.177 08-Jan-2010 pooka

branches: 1.177.2; 1.177.4;
The VATTR_NULL/VREF/VHOLD/HOLDRELE() macros lost their will to live
years ago when the kernel was modified to not alter ABI based on
DIAGNOSTIC, and now just call the respective function interfaces
(in lowercase). Plenty of mix'n match upper/lowercase has creeped
into the tree since then. Nuke the macros and convert all callsites
to lowercase.

no functional change


Revision tags: matt-premerge-20091211 yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 jym-xensuspend-nbase
# 1.176 03-Jul-2009 elad

Where possible, extract the file-system's access() routine to two internal
functions: the first checking if the operation is possible (regardless of
permissions), the second checking file-system permissions, ACLs, etc.

Mailing list reference:

http://mail-index.netbsd.org/tech-kern/2009/06/21/msg005311.html


# 1.175 23-Jun-2009 elad

Move the implementation of vaccess() to genfs_can_access(), in line with
the other routines of the same spirit.

Adjust file-system code to use it.

Keep vaccess() for KPI compatibility and to keep element of least
surprise. A "diagnostic" message warning that vaccess() is deprecated will
be printed when it's used (obviously, only in DIAGNOSTIC kernels).

No objections on tech-kern@:

http://mail-index.netbsd.org/tech-kern/2009/06/21/msg005310.html


Revision tags: yamt-nfs-mp-base5
# 1.174 24-May-2009 ad

More changes to improve kern_descrip.c.

- Avoid atomics in more places.
- Remove the per-descriptor mutex, and just use filedesc_t::fd_lock.
It was only being used to synchronize close, and in any case we needed
to take fd_lock to free the descriptor slot.
- Optimize certain paths for the <NDFDFILE case.
- Sprinkle more comments and assertions.
- Cache more stuff in filedesc_t.
- Fix numerous minor bugs spotted along the way.
- Restructure how the open files array is maintained, for clarity and so
that we can eliminate the membar_consumer() call in fd_getfile(). This is
mostly syntactic sugar; the main functional change is that fd_nfiles now
lives alongside the open file array.

Some measurements with libmicro:

- simple file syscalls are like close() are between 1 to 10% faster.
- some nice improvements, e.g. poll(1000) which is ~50% faster.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 nick-hppapmap-base2 jym-xensuspend-base nick-hppapmap-base mjf-devfs2-base
# 1.173 17-Dec-2008 cegger

branches: 1.173.2;
kill MALLOC and FREE macros.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 haad-dm-base2 haad-nbase2 ad-audiomp2-base netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 haad-dm-base
# 1.172 05-Sep-2008 skrll

branches: 1.172.2;
PR/39324 kernel diagnostic assertion "l->l_stat != LSZOMB" failed.

Ignore procs with zero or all LSZOMB LWPs. Get a non-LSZOMB LWP to perform
operations against as part of the deal.

procfs really needs to be updated to support multi-threading fully.
Hi Antti!


# 1.171 05-Sep-2008 skrll

ANSIfy


Revision tags: simonb-wapbl-nbase simonb-wapbl-base
# 1.170 02-Jul-2008 rmind

branches: 1.170.2;
Remove proc_representative_lwp(), use a simple LIST_FIRST() instead.
OK by <ad>.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base
# 1.169 28-Apr-2008 martin

branches: 1.169.2; 1.169.4;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-nfs-mp-base
# 1.168 24-Apr-2008 ad

branches: 1.168.2;
Merge proc::p_mutex and proc::p_smutex into a single adaptive mutex, since
we no longer need to guard against access from hardware interrupt handlers.

Additionally, if cloning a process with CLONE_SIGHAND, arrange to have the
child process share the parent's lock so that signal state may be kept in
sync. Partially addresses PR kern/37437.


# 1.167 24-Apr-2008 ad

Network protocol interrupts can now block on locks, so merge the globals
proclist_mutex and proclist_lock into a single adaptive mutex (proc_lock).
Implications:

- Inspecting process state requires thread context, so signals can no longer
be sent from a hardware interrupt handler. Signal activity must be
deferred to a soft interrupt or kthread.

- As the proc state locking is simplified, it's now safe to take exit()
and wait() out from under kernel_lock.

- The system spends less time at IPL_SCHED, and there is less lock activity.


Revision tags: yamt-pf42-baseX yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14
# 1.166 21-Mar-2008 ad

branches: 1.166.2;
Catch up with descriptor handling changes. See kern_descrip.c revision
1.173 for details.


Revision tags: keiichi-mipv6-nbase nick-net80211-sync-base keiichi-mipv6-base bouyer-xeni386-nbase matt-armv6-nbase mjf-devfs-base hpcarm-cleanup-base
# 1.165 23-Jan-2008 elad

branches: 1.165.6;
Tons of process scope changes.

- Add a KAUTH_PROCESS_SCHEDULER action, to handle scheduler related
requests, and add specific requests for set/get scheduler policy and
set/get scheduler parameters.

- Add a KAUTH_PROCESS_KEVENT_FILTER action, to handle kevent(2) related
requests.

- Add a KAUTH_DEVICE_TTY_STI action to handle requests to TIOCSTI.

- Add requests for the KAUTH_PROCESS_CANSEE action, indicating what
process information is being looked at (entry itself, args, env,
open files).

- Add requests for the KAUTH_PROCESS_RLIMIT action indicating set/get.

- Add requests for the KAUTH_PROCESS_CORENAME action indicating set/get.

- Make bsd44 secmodel code handle the newly added rqeuests appropriately.

All of the above make it possible to issue finer-grained kauth(9) calls in
many places, removing some KAUTH_GENERIC_ISSUSER requests.

- Remove the "CAN" from KAUTH_PROCESS_CAN{KTRACE,PROCFS,PTRACE,SIGNAL}.

Discussed with christos@ and yamt@.


Revision tags: bouyer-xeni386-base matt-armv6-base
# 1.164 02-Jan-2008 ad

Merge vmlocking2 to head.


Revision tags: vmlocking2-base3 yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 vmlocking-nbase jmcneill-pm-base reinoud-bufcleanup-base
# 1.163 26-Nov-2007 pooka

branches: 1.163.2; 1.163.6;
Remove the "struct lwp *" argument from all VFS and VOP interfaces.
The general trend is to remove it from all kernel interfaces and
this is a start. In case the calling lwp is desired, curlwp should
be used.

quick consensus on tech-kern


Revision tags: bouyer-xenamd64-base2 bouyer-xenamd64-base
# 1.162 09-Nov-2007 christos

make the last argument of procfs_dir size_t


# 1.161 07-Nov-2007 ad

Merge from vmlocking:

- pool_cache changes.
- Debugger/procfs locking fixes.
- Other minor changes.


Revision tags: jmcneill-base yamt-x86pmap-base4 yamt-x86pmap-base3 vmlocking-base
# 1.160 10-Oct-2007 ad

branches: 1.160.2; 1.160.4;
Merge from vmlocking:

- Split vnode::v_flag into three fields, depending on field locking.
- simple_lock -> kmutex in a few places.
- Fix some simple locking problems.


# 1.159 08-Oct-2007 ad

Merge file descriptor locking, cwdi locking and cross-call changes
from the vmlocking branch.


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base2 yamt-x86pmap-base matt-mips64-base
# 1.158 22-Jul-2007 pooka

branches: 1.158.4; 1.158.6; 1.158.8; 1.158.10;
Don't allow getcwd() on procfs vnodes and provide "/" as the path
instead of the result from getcwd(). The works around locking
panics caused by namei calling VOP_READLINK while holding on to a
directory lock and getcwd() trying to acquire that lock. The real
fix would be to get rid of getcwd() calls within VOPs (not locking
safe), but that's not a viable option in the netbsd-4 timeframe.

Suggestion for workaround from David Holland.


Revision tags: nick-csl-alignment-base mjf-ufs-trans-base
# 1.157 24-May-2007 agc

branches: 1.157.2;
Extend the Linux emulation of /proc to include

/proc/stat
/proc/loadavg and
/proc/<pid>/statm.

These are only present when -o linux is specified as a mount option
to procfs.

Factor out some common code so that it can be used by a number of
functions.

XXX The values returned in the statm emulation need to be verified.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 1.156 04-Apr-2007 rmind

Unfortunately, missed procfs_proc_unlock() in previous.
Pointed out by pooka@


# 1.155 04-Apr-2007 rmind

procfs_readlink: Handle a possible fail of fd_getfile(), also, we
do not need to check for error again.
CID: 4436


# 1.154 09-Mar-2007 ad

branches: 1.154.2; 1.154.4;
- Make the proclist_lock a mutex. The write:read ratio is unfavourable,
and mutexes are cheaper use than RW locks.
- LOCK_ASSERT -> KASSERT in some places.
- Hold proclist_lock/kernel_lock longer in a couple of places.


# 1.153 04-Mar-2007 christos

Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.


# 1.152 03-Mar-2007 salo

Don't prepend rootvnode to the path in non-NULL case for exe links.
It breaks procfs in chroot.

from <christos>, tested by me.


Revision tags: ad-audiomp-base
# 1.151 19-Feb-2007 pooka

When checking for file validity under pid/, do proper proc->lwp
lookup (fsvo proper) instead of fiddling directly with the lwp
list.


# 1.150 18-Feb-2007 pooka

Don't check for validity of p in lookup for root nodes, since it
will always be NULL. Rather, just call pt_valid with NULL directly
and let it decide if we're a linux mount or not.


# 1.149 17-Feb-2007 pavel

Change the process/lwp flags seen by userland via sysctl back to the
P_*/L_* naming convention, and rename the in-kernel flags to avoid
conflict. (P_ -> PK_, L_ -> LW_ ). Add back the (now unused) LSDEAD
constant.

Restores source compatibility with pre-newlock2 tools like ps or top.

Reviewed by Andrew Doran.


# 1.148 16-Feb-2007 pooka

branches: 1.148.2;
In lookup, when checking for procfs process node validity, target the
process we're trying to get information about through procfs, not
the caller of lookup.

fixes 'ls -l /proc/*/file' panic, which would occur when trying to
lookup "file" for a kernel thread, which doesn't have p->p_textvp.


# 1.147 15-Feb-2007 ad

Need to acquire procp->p_mutex for procfs_dir().


# 1.146 11-Feb-2007 ad

Eliminate a couple of reference count and mutex leaks.


Revision tags: post-newlock2-merge
# 1.145 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 1.144 25-Dec-2006 elad

PR/35226: Johann Franz: Problems with permissions in
/usr/pkg/emul/linux/proc .

Okay mlelstv@


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3
# 1.143 09-Dec-2006 chs

a smorgasbord of improvements to vnode locking and path lookup:
- LOCKPARENT is no longer relevant for lookup(), relookup() or VOP_LOOKUP().
these now always return the parent vnode locked. namei() works as before.
lookup() and various other paths no longer acquire vnode locks in the
wrong order via vrele(). fixes PR 32535.
as a nice side effect, path lookup is also up to 25% faster.
- the above allows us to get rid of PDIRUNLOCK.
- also get rid of WANTPARENT (just use LOCKPARENT and unlock it).
- remove an assumption in layer_node_find() that all file systems implement
a recursive VOP_LOCK() (unionfs doesn't).
- require that all file systems supply vfs_vptofh and vfs_fhtovp routines.
fill in eopnotsupp() for file systems that don't support being exported
and remove the checks for NULL. (layerfs calls these without checking.)
- in union_lookup1(), don't change refcounts in the ISDOTDOT case, just
adjust which vnode is locked. fixes PR 33374.
- apply fixes for ufs_rename() from ufs_vnops.c rev. 1.61 to ext2fs_rename().


# 1.142 04-Dec-2006 christos

From Nicolas Joly: restore previous behavior in procfs_validfile_linux, since
readdir passes a NULL lwp.


# 1.141 03-Dec-2006 elad

Move kauth(9) call to where it belongs. Noticed by Nicolas Joly, thanks!


Revision tags: netbsd-4-base
# 1.140 28-Nov-2006 elad

branches: 1.140.2;
Move ktrace, ptrace, systrace, and procfs to use kauth(9).

First, remove process_checkioperm() calls from MD code. Similar checks
using kauth(9) routines (on the process scope, using appropriate action)
are done in the callers.

Add secmodel back-end to handle each subsystem.


# 1.139 25-Nov-2006 skrll

Expose the 'exe' symlink to the process realpath in NetBSD as well. An
example user is gdb.

OK'd by christos.


# 1.138 16-Nov-2006 christos

__unused removal on arguments; approved by core.


# 1.137 29-Oct-2006 christos

add an "emul" file node.


# 1.136 25-Oct-2006 christos

1. fix procfs_validfile{,_linux} to test for NULL pointers properly.
2. make "exe" entry be a symlink to the executable, instead of pointing
directly to the vnode of the executable.
3. factor out commonly used code.


Revision tags: yamt-splraiseipl-base2
# 1.135 12-Oct-2006 christos

- sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386


# 1.134 20-Sep-2006 manu

Emulate Linux's /proc/devices


Revision tags: abandoned-netbsd-4-base yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base rpaulo-netinet-merge-pcb-base
# 1.133 13-Jun-2006 yamt

branches: 1.133.6; 1.133.8;
use KAUTH_PROCESS_CANSEE rather than CURTAIN where appropriate.


# 1.132 13-Jun-2006 yamt

remove unnecessary arguments from kauth_authorize_process.
ie. make it similar to the one found in apple TN.


# 1.131 07-Jun-2006 kardel

merge FreeBSD timecounters from branch simonb-timecounters
- struct timeval time is gone
time.tv_sec -> time_second
- struct timeval mono_time is gone
mono_time.tv_sec -> time_uptime
- access to time via
{get,}{micro,nano,bin}time()
get* versions are fast but less precise
- support NTP nanokernel implementation (NTP API 4)
- further reading:
Timecounter Paper: http://phk.freebsd.dk/pubs/timecounter.pdf
NTP Nanokernel: http://www.eecis.udel.edu/~mills/ntp/html/kern.html


Revision tags: yamt-pdpolicy-base5 simonb-timecounters-base
# 1.130 14-May-2006 elad

branches: 1.130.2;
integrate kauth.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 elad-kernelauth-base yamt-pdpolicy-base yamt-uio_vmspace-base5
# 1.129 02-Feb-2006 christos

branches: 1.129.2; 1.129.4; 1.129.6; 1.129.8;
PR/32692: Matthew Mondor: linux compatibility in /proc/self should point
directly to the directory containing the pid instead of pointing to
/proc/curproc, because some programs rely on calling readlink on /proc/self
to get the pid.


# 1.128 11-Dec-2005 christos

branches: 1.128.2; 1.128.4;
merge ktrace-lwp.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base ktrace-lwp-base
# 1.127 02-Nov-2005 yamt

merge yamt-vop branch. remove following VOPs.

VOP_BLKATOFF
VOP_VALLOC
VOP_BALLOC
VOP_REALLOCBLKS
VOP_VFREE
VOP_TRUNCATE
VOP_UPDATE


Revision tags: yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 1.126 01-Oct-2005 atatat

branches: 1.126.2;
Add "cwd" and "root" symlinks to each process's directory. The cwd
link points to the process's current working directory, and the root
link points to the process's root directory. What else would you
expect?

For directories that are out of reach (caller is in a chroot, target
process is in a different chroot, etc), the links point to "/"
instead.


# 1.125 11-Sep-2005 elad

Implement curtain for procfs.


# 1.124 30-Aug-2005 xtraeme

Remove __P()


# 1.123 29-May-2005 christos

branches: 1.123.2;
- sprinkle const
- avoid shadowed variables.


Revision tags: kent-audio2-base
# 1.122 02-Apr-2005 christos

PR/29782: Martin Husemann: procfs can not unmount when some process has its
current directory in curproc. Fix from Pedro Martelletto:
We cannot call vgone() from procfs_inactive() if we are coming from
vclean(). that's what's probably causing the deadlock.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 yamt-km-base4 yamt-km-base3 netbsd-3-base
# 1.121 26-Feb-2005 perry

nuke trailing whitespace


Revision tags: yamt-km-base2 yamt-km-base kent-audio1-beforemerge kent-audio1-base
# 1.120 04-Oct-2004 yamt

branches: 1.120.4; 1.120.6;
procfs_readdir:
- return correct cookie when buffer size is small.
- simplify logic.


# 1.119 04-Oct-2004 yamt

procfs_readdir: remove a redundant assignment.


# 1.118 02-Oct-2004 yamt

procfs_getattr: correct size of /proc/self.


# 1.117 01-Oct-2004 yamt

procfs_readdir:
- fix a locking problem, using proclist_foreach_call. PR/27098.
- correct snprintf size argument.


# 1.116 01-Oct-2004 yamt

procfs_readdir: fix an offset handling bug after addition of /proc/self.


# 1.115 01-Oct-2004 yamt

procfs_readdir: use a list macro.


# 1.114 20-Sep-2004 jdolecek

add 'mounts' file for -o linux, which lists all currently mounted
filesystems; Linux glibc statvfs() uses this to get some of mount flags,
and this file is also useful as /emul/linux/etc/mtab (via symlink)


# 1.113 29-Apr-2004 jrf

Removed remaining caddr_t casts we do not need in miscfs. Recompiled
kernel and ran for a day or so. There are still some caddr_t types in
the arguments of some calls, I will do those separately (later) as
they touch a lot more of the system.
Approved by christos@NetBSD.org.


# 1.112 22-Apr-2004 itojun

sprintf -> snprintf


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.111 15-Feb-2004 jdolecek

unlock the descriptor table simple lock after fd_getfile() call in
procfs_readdir()
fixes procfs locking problems reported on current-users@, problem place
found by enami tsugutomo


# 1.110 30-Oct-2003 simonb

Remove some assigned-to but otherwise unused variables.


# 1.109 27-Sep-2003 darcy

Changes as discussed with itojun on tech-kern. I have modified the enums
to have KFS or PFS differentiators. Further I have wrapped the enum in
procfs in "#ifdef _KERNEL" as it is done in kernfs.

To see the discussion go to http://mail-index.NetBSD.org/tech-kern/2003/09/
and look for "Mismatched enums in include files" in the list.


# 1.108 07-Sep-2003 itojun

remove meaningless line (variable overwritten 2 lines below)


# 1.107 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.


# 1.106 29-Jun-2003 fvdl

branches: 1.106.2;
Back out the lwp/ktrace changes. They contained a lot of colateral damage,
and need to be examined and discussed more.


# 1.105 29-Jun-2003 thorpej

Undo part of the ktrace/lwp changes. In particular:
* Remove the "lwp *" argument that was added to vget(). Turns out
that nothing actually used it!
* Remove the "lwp *" arguments that were added to VFS_ROOT(), VFS_VGET(),
and VFS_FHTOVP(); all they did was pass it to vget() (which, as noted
above, didn't use it).
* Remove all of the "lwp *" arguments to internal functions that were added
just to appease the above.


# 1.104 28-Jun-2003 darrenr

Pass lwp pointers throughtout the kernel, as required, so that the lwpid can
be inserted into ktrace records. The general change has been to replace
"struct proc *" with "struct lwp *" in various function prototypes, pass
the lwp through and use l_proc to get the process pointer when needed.

Bump the kernel rev up to 1.6V


# 1.103 28-May-2003 christos

Add /proc/<pid>/stat for linux compat. j2sdk1.4.2 depends on it.


# 1.102 18-Apr-2003 christos

Make symlinks for directories that point to the actual directory.
Make symlinks to [kqueue] and [misc] for kqueue and misc fds.


# 1.101 17-Apr-2003 jdolecek

do not show nodes corresponding to directory descriptors for process
in fd/ subdirectory, nor allow lookup/open for the nodes
this fixes PR kern/21187 for good, and also avoids interesting directory
locking issues


# 1.100 17-Apr-2003 jdolecek

procfs_readdir(): in Pfd case, only show descriptors of types we want
how to represent (vnodes, fifo, pipes); also use fd_getfile() et al

this avoids annoying EOPNOTSUPP error messages from ls -F and such


# 1.99 17-Apr-2003 jdolecek

procfs_lookup(): use fd_getfile() et al in Pfd case


# 1.98 17-Apr-2003 jdolecek

use fd_getfile() in procfs_getfp(), and FILE_USE()/FILE_UNUSE() the
returned file descriptor pointer appropriately


# 1.97 17-Apr-2003 jdolecek

make some local arrays/variables static + const


# 1.96 10-Apr-2003 jdolecek

use former genfs_eopnotsupp_rele() as genfs_eopnotsupp(), so that vnodes
are vput()/vrele()d as necessary - some filesystems did use the wrong
one for some ops, and it's just safer to not take the chance

based on suggestion by Bill Studenmund


# 1.95 05-Apr-2003 dsl

Remove pointless check against PID_MAX. Let pfind() do the validation.
(The new pid allocation code may decide to allocate pids above PID_MAX.)


# 1.94 25-Feb-2003 jrf

This addresses PR kerm/19989. Thanks to hamajima@nagoya.ydc.co.jp for submitting this patch which enables /proc/uptime for linux emul. Patch reviewed by atatat@netbsd.org and tron@netbsd.org, approved by tron@netbsd.org.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 1.93 04-Jan-2003 martin

Cast off_t expression to long long to match format even on 64 bit
plattforms.

Shouldn't we introduce a PRIoff_t macro to create such format strings?


# 1.92 03-Jan-2003 christos

add LK_CANRECURSE in the locking of /dev/<pid>/fd/<n> and remove the curproc
kludge. Thanks to fvdl.


# 1.91 03-Jan-2003 christos

Implement /proc/<pid>/fd/<n>. This is work in progress. Questionable things:
- Is it ok to convert DTYPE_PIPE to VFIFO and DTYPE_SOCKET to VSOCK?
- XXX: Avoid locking issue in ls -Rl /proc by avoiding curproc
- Does I/O to pipes work?
- XXX: Are there security implications?


Revision tags: fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge gehenna-devsw-base kqueue-base
# 1.90 03-Aug-2002 simonb

Just use the "time" variable in the *_getattr functions instead of a call
to (the potentially expensive) microtime().


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.89 09-May-2002 thorpej

branches: 1.89.2;
Move code shared by procfs and the kernel proper out of procfs and
into the kernel proper (renaming functions from procfs_* to process_*).


Revision tags: eeh-devprop-base newlock-base ifpoll-base
# 1.88 12-Jan-2002 christos

Don't hide the real return code with EPERM.


# 1.87 06-Dec-2001 chs

add a VOP_PUTPAGES method for all the filesystems that don't have pages,
just unlock the interlock.


# 1.86 05-Dec-2001 thorpej

* Allow machine-dependent code to specify hooks for ptrace(2)
(__HAVE_PTRACE_MACHDEP) and procfs (__HAVE_PROCFS_MACHDEP).
These changes will allow platforms like x86 (XMM) and PowerPC
(AltiVec) to export extended register sets in a sane manner.

* Use __HAVE_PTRACE_MACHDEP to export x86 XMM registers (standard
FP + SSE/SSE2) using PT_{GET,SET}XMMREGS (in the machdep
ptrace request space).
* Use __HAVE_PROCFS_MACHDEP to export x86 XMM registers via
/proc/N/xmmregs in procfs.


Revision tags: thorpej-mips-cache-base
# 1.85 10-Nov-2001 lukem

add RCSIDs


# 1.84 06-Nov-2001 simonb

Remove some variables that are set but never used.


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base
# 1.83 31-Aug-2001 chs

branches: 1.83.2; 1.83.4;
map files are zero-length.


# 1.82 03-Jun-2001 chs

branches: 1.82.2;
procfs_bmap() should never be called, make it a "bad op".
let procfs_mmap() use the default error method.


Revision tags: thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 1.81 14-Apr-2001 kleink

In procfs_readdir(), give /proc/# directories DT_DIR (rather than DT_REG).


# 1.80 30-Mar-2001 fvdl

Bump va_blocksize for the map files some more, so that programs with
quite a few mappings have a chance of being handled correctly if
st_blksize is looked at.


# 1.79 29-Mar-2001 fvdl

For -o linux mounts, add some code to emulate /proc/#/maps.
Needs NAMECACHE_ENTER_REVERSE to include filenames.


# 1.78 21-Feb-2001 jdolecek

branches: 1.78.2;
make some more constant arrays 'const'


# 1.77 22-Jan-2001 jdolecek

make filesystem vnodeop, specop, fifoop and vnodeopv_* arrays const


# 1.76 17-Jan-2001 fvdl

Add a few linux-style files, only enabled when -o linux is specified
for the mount. Currently these are /proc/cpuinfo and /proc/meminfo.
The former only does something on i386 right now.


# 1.75 24-Nov-2000 chs

remove dead code and other misc cleanup.


# 1.74 09-Aug-2000 tv

Only show the "exe" entry to Linux processes, suggested by christos.
Since there are actually three struct emul's for linux, use the e_name
field to determine eligibility with strcmp().


# 1.73 09-Aug-2000 tv

Some versions of Linux libc look for /proc/.../exe instead of /proc/../file.
Add an entry for "exe" that is the same as "file", provided only if
COMPAT_LINUX is set.


# 1.72 03-Aug-2000 thorpej

MALLOC()/FREE() are not to be used for variable sized allocations.


# 1.71 28-Jun-2000 mrg

<vm/vm.h> -> <uvm/uvm_extern.h>


Revision tags: netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 1.70 30-Mar-2000 simonb

branches: 1.70.4;
Delete duplicate declaration of atopid().


Revision tags: chs-ubc2-newbase wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base fvdl-softdep-base
# 1.69 02-Sep-1999 thorpej

branches: 1.69.2; 1.69.8;
Make /proc/self a symlink to /proc/curproc. I've observed Linux programs
that expect /proc/self/cmdline to exist.


# 1.68 25-Aug-1999 sommerfeld

Change variable used for directory offset from "int" to "off_t".
Overkill, but avoids a host of truncation problems.


# 1.67 24-Aug-1999 sommerfeld

Fix PR8270:

Problem turned out to be due to improper handling of reads beyond EOF:
they should just return without error with the uio unchanged, and the
caller will recognize this as a zero-byte return (EOF).

The previous fix to protect directory reads against bogus uio_offset
values returned EINVAL, which broke mount -o union, which only
union'ed in the lower directory if the upper directory cleanly
returned EOF.

While we're here, protect kernfs as well.


# 1.66 14-Aug-1999 christos

protect against large uio_offset


# 1.65 03-Aug-1999 wrstuden

Add support for fcntl(2) to generate VOP_FCNTL calls. Any fcntl
call with F_FSCTL set and F_SETFL calls generate calls to a new
fileop fo_fcntl. Add genfs_fcntl() and soo_fcntl() which return 0
for F_SETFL and EOPNOTSUPP otherwise. Have all leaf filesystems
use genfs_fcntl().

Reviewed by: thorpej
Tested by: wrstuden


Revision tags: chs-ubc2-base
# 1.64 25-Jul-1999 thorpej

Add calls to lock the proclist as appropriate.


# 1.63 14-Jul-1999 thorpej

Fix a paste-o in procfs_lookup() introduced with the vnode locking changes.
Fixes PR #7961, Mario Kemper <magick@bundy.lip.owl.de>.


# 1.62 08-Jul-1999 wrstuden

Bump osrelease to 1.4E. Add layerfs files, remove null_subr.c.

Update coda to new struct lock in struct vnode.

make fdescfs, kernfs, portalfs, and procfs actually lock their vnodes.
It's not that hard.

Make unionfs set v_vnlock = NULL so any overlayed fs will call its
VOP_LOCK.


Revision tags: kame_141_19991130 netbsd-1-4-PATCH001 kame_14_19990705 kame_14_19990628 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.61 12-Mar-1999 christos

branches: 1.61.2; 1.61.4;
PR/7143: Jaromir Docelek: Add procfs/cmdline from Linux emulation


# 1.60 25-Jan-1999 msaitoh

Add /proc/#/map. From FreeBSD.


Revision tags: kenh-if-detach-base chs-ubc-base
# 1.59 08-Sep-1998 thorpej

- Use proclists[], rather than checking allproc and zombproc explicitly.
- Add some comments about locking.


# 1.58 13-Aug-1998 kleink

Per POSIX, fail with EINVAL if advisory locking is attempted on a file type
that doesn't support it, rather than using a homegrown EBADF or EOPNOTSUPP.


# 1.57 10-Aug-1998 matthias

create miscfs/genfs/genfs_vnops.c:genfs_enoioctl and make all the other
filesystems use it instead of a private version.


# 1.56 09-Aug-1998 perry

bzero->memset, bcopy->memcpy, bcmp->memcmp


# 1.55 03-Aug-1998 kleink

Recognize _PC_SYNC_IO.


Revision tags: eeh-paddr_t-base
# 1.54 21-Apr-1998 fvdl

procfs_readdir: in case of error, check if cookies actually have
been allocated before freeing them. From Wolfgang Solfrank.


# 1.53 01-Mar-1998 fvdl

Merge with Lite2 + local changes


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base marc-pcmcia-base
# 1.52 10-Oct-1997 fvdl

Bump last argument to VOP_READDIR to off_t (from u_long).


Revision tags: thorpej-signal-base
# 1.51 27-Aug-1997 thorpej

Fix a reversed argument which caused procfs_checkioperm() to always return
"OK". Add a few comments to avoid further confusion.


# 1.50 12-Aug-1997 thorpej

Fix the procfs hole described on current-users, similar to a fix for
FreeBSD by Sean Eric Fagan, but a bit different. This makes the checks
in the same places as sef's FreeBSD patch, but does not hardcode the
"kmem" group into the kernel, and also does a check identical to the
(3) and (4) checks in the NetBSD ptrace(2):

(1) it's not owned by you, or is set-id on exec (unless
you're root), or

(2) it's init, which controls the security level of the
entire system, and the system was not compiled with
permanently insecure mode turned on.


Revision tags: marc-pcmcia-bp
# 1.49 08-May-1997 mycroft

branches: 1.49.4;
Pass the vnode type to vaccess(), and use it when checking VEXEC. Make sure
that the mode bits passed to vaccess() and returned by foo_getattr() contain
only permission bits.


# 1.48 05-May-1997 mycroft

Need stat.h.


# 1.47 05-May-1997 mycroft

Eliminate bogus uses of V{READ,WRITE,EXEC}. Use S_I[RWX]{USR,GRP,OTH} where
appropriate.


# 1.46 28-Apr-1997 mycroft

Minor code cleanup.


Revision tags: is-newarp-before-merge is-newarp-base
# 1.45 25-Oct-1996 cgd

define path name string variables that we should not (and, thankfully, do
not) modify as 'const char *' rather 'char *'.


# 1.44 13-Oct-1996 christos

backout previous kprintf changes


# 1.43 10-Oct-1996 christos

printf -> kprintf, sprintf -> ksprintf


# 1.42 07-Sep-1996 mycroft

Implement poll(2).


# 1.41 01-Sep-1996 mycroft

Add a set of generic file system operations that most file systems use.
Also, fix some time stamp bogosities.


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 1.40 16-Mar-1996 christos

Fix printf format follies.


# 1.39 13-Feb-1996 mycroft

GC *_nullop(). Minor nits.


# 1.38 12-Feb-1996 christos

close PR/2063: procfs_rw prototyped twice with different prototypes


# 1.37 09-Feb-1996 christos

miscfs prototype changes


# 1.36 09-Feb-1996 mycroft

Fix vop_link, vop_symlink, and vop_remove semantics in several ways:
* Change the argument names to vop_link so they actually make sense.
* Implement vop_link and vop_symlink for all file systems, so they do proper
cleanup.
* Require the file system to decide whether or not linking and unlinking of
directories is allowed, and disable it for all current file systems.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.35 09-Oct-1995 mycroft

Use the index number as the cookie, rather than multiplying by UIO_MX.


# 1.34 09-Oct-1995 mycroft

Add support for cookies, mostly from Greg Hudson.


# 1.33 15-Apr-1995 cgd

fix timeval vs. timespec warnings


# 1.32 03-Feb-1995 mycroft

Return EROFS rather than ENOENT in many cases. Also some cosmetic cleanup.


# 1.31 27-Dec-1994 mycroft

Format police.


# 1.30 24-Dec-1994 ws

Implement and use a common access checking routine


# 1.29 14-Dec-1994 mycroft

Remove a_fp.


# 1.28 14-Nov-1994 christos

fixed struct comment


# 1.27 30-Oct-1994 cgd

be more careful with types, also pull in headers where necessary.


# 1.26 20-Oct-1994 cgd

update for new syscall args description mechanism


# 1.25 30-Aug-1994 mycroft

Convert process, file, and namei lists and hash tables to use queue.h.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.24 29-Jun-1994 cgd

New RCS ID's, take two. they're more aesthecially pleasant, and use 'NetBSD'


# 1.23 16-Jun-1994 mycroft

Remove an unneeded test.


# 1.22 15-Jun-1994 mycroft

Minor update from JSP after merging my changes.


# 1.21 08-Jun-1994 mycroft

Update to 4.4-Lite fs code, with local changes.


# 1.20 05-May-1994 cgd

lots of changes: prototype migration, move lots of variables, definitions,
and structure elements around. kill some unnecessary type and macro
definitions. standardize clock handling. More changes than you'd want.


# 1.19 15-Apr-1994 cgd

forgot these...


# 1.18 12-Apr-1994 cgd

be a bit smarter about determining if files shouldn't be seen by the user.
Also, DON'T allow a lookup to succeed on a file that's not visible!


# 1.17 15-Feb-1994 mycroft

Undo last change; executables is `file', not `a.out'.


# 1.16 14-Feb-1994 ws

Rename file -> a.out


# 1.15 14-Feb-1994 ws

Don't try to show a file for a process if there is none


# 1.14 28-Jan-1994 cgd

make a fpregs file.


# 1.13 20-Jan-1994 ws

Make procfs really work for debugging.
Implement not & notepg files in procfs.


# 1.12 09-Jan-1994 ws

Bug fixes and enhancements:
Make NFS serving work (BUT DON'T USE "attach" TO /proc/*/ctl FOR NOW!!!)
Make `curproc' a symbolic link
Add `.' and `..' entries to the directories.
Return better guesses on the size of the files.


# 1.11 05-Jan-1994 cgd

return size of 'reg' from getattr()


# 1.10 05-Jan-1994 cgd

make it compile (cleanly) for us


# 1.9 05-Jan-1994 cgd

add new procfs code, from Jan-Simon Pendry, jsp@sequent.com.
This is pretty-much "virgin", so that diffs can be done later.


# 1.8 18-Dec-1993 mycroft

Canonicalize all #includes.


Revision tags: magnum-base
# 1.7 16-Sep-1993 cgd

kill volatile warning.


# 1.6 07-Sep-1993 ws

branches: 1.6.2;
Changes to VFS readdir semantics
NFS changes for better cookie support
ISOFS changes for better Rockridge support and support for generation numbers


# 1.5 26-Aug-1993 pk

Implement setattr: mode for process entries; mode + uid/gid for the
PROCFS root directory.
Fixed omission in pfs_root() which came to light as a result of the above:
hold on to vnode for root dir.


# 1.4 25-Aug-1993 pk

Fixed improperly initialized nfsnode in pfs_lookup()


# 1.3 24-Aug-1993 pk

copyright update.


# 1.2 24-Aug-1993 pk

Rcs Id added.


# 1.1 24-Aug-1993 pk

branches: 1.1.1;
Initial version of a proc filesystem.


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004 localcount-20160914
# 1.194 20-Aug-2016 hannken

Remove now obsolete operation vcache_remove().

Welcome to 7.99.36


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 nick-nhusb-base-20150921 nick-nhusb-base-20150606
# 1.193 20-Apr-2015 riastradh

Make VOP_LINK return directory still locked and referenced.

Ride 7.99.10 bump.


Revision tags: nick-nhusb-base-20150406 nick-nhusb-base
# 1.192 05-Sep-2014 matt

branches: 1.192.2;
Try not to use f_data, use f_{vnode,socket,pipe,mqueue,kqueue,ksem} to get
a correctly typed pointer.


Revision tags: netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.191 27-Jul-2014 hannken

Change procfs from hashlist to vcache.
- Key is (type, pid, fd)
- Remove argument "p" from procfs_allocvp(). It is only used
when "type == PFSfd". Lookup the proc with proc_find() when
procfs_loadvnode() needs it.
- Use a vfs_vnode_iterator for procfs_revoke_vnodes().


# 1.190 25-Jul-2014 dholland

Add VOP_FALLOCATE and VOP_FDISCARD to every vnode ops table I can
find.

The filesystem ones all call genfs_eopnotsupp - right now I am only
implementing the plumbing and we can implement fallocate and/or
fdiscard for files later.

The device ones call spec_fallocate (which is also genfs_eopnotsupp)
and spec_fdiscard, which dispatches to the device-level op.

The fifo ones all call vn_fifo_bypass, which also ends up being
EOPNOTSUPP.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base
# 1.189 07-Feb-2014 hannken

branches: 1.189.2;
Change vnode operation lookup to return the resulting vnode *vpp unlocked.
Change cache_lookup() to return an unlocked vnode.

Discussed on tech-kern@

Welcome to 6.99.31


# 1.188 23-Jan-2014 hannken

Change vnode operations create, mknod, mkdir and symlink to return
the resulting vnode *vpp unlocked.

Discussed on tech-kern@

Welcome to 6.99.30


# 1.187 17-Jan-2014 hannken

Change vnode operations create, mknod, mkdir and symlink to keep the
directory node dvp locked on return.

Discussed on tech-kern@

Welcome to 6.99.29


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base
# 1.186 18-Mar-2013 plunky

branches: 1.186.6;
C99 section 6.7.2.3 (Tags) Note 3 states that:

A type specifier of the form

enum identifier

without an enumerator list shall only appear after the type it
specifies is complete.

which means that we cannot pass an "enum vtype" argument to
kauth_access_action() without fully specifying the type first.
Unfortunately there is a complicated include file loop which
makes that difficult, so convert this minimal function into a
macro (and capitalize it).

(ok elad@)


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 1.185 25-Nov-2012 christos

do something reasonable with kernel semaphores.


Revision tags: yamt-pagecache-base6 jmcneill-usbmp-base10
# 1.184 28-May-2012 christos

branches: 1.184.2;
add a task process subdirectory for emul linux


Revision tags: yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 1.183 13-Mar-2012 elad

Replace the remaining KAUTH_GENERIC_ISSUSER authorization calls with
something meaningful. All relevant documentation has been updated or
written.

Most of these changes were brought up in the following messages:

http://mail-index.netbsd.org/tech-kern/2012/01/18/msg012490.html
http://mail-index.netbsd.org/tech-kern/2012/01/19/msg012502.html
http://mail-index.netbsd.org/tech-kern/2012/02/17/msg012728.html

Thanks to christos, manu, njoly, and jmmv for input.

Huge thanks to pgoyette for spinning these changes through some build
cycles and ATF.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.182 04-Sep-2011 jmcneill

branches: 1.182.2; 1.182.6;
PR# kern/45021: Please support /emul/linux/proc/version

Add /proc/version for procfs with -o linux. The version reported depends
on the emulation type of the calling process:

$ cat /proc/version
NetBSD version 5.99.55 (netbsd@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) NetBSD 5.99.55 (GENERIC) #39: Sun Sep 4 09:10:05 EDT 2011

$ /emul/linux/bin/cat /proc/version
Linux version 2.6.18 (linux@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) #0 Wed Mar 3 03:03:03 PST 2010

$ /emul/linux32/bin/cat /proc/version
Linux version 2.6.18 (linux32@localhost) (gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)) #0 Wed Mar 3 03:03:03 PST 2010


# 1.181 23-Jun-2011 christos

From Aleksey Cheusov: Don't make it easy for compromised systems to bypass
ASLR protections by providing the mapping addresses of programs to everyone.


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base matt-mips64-premerge-20101231 uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10 rmind-uvmplock-base
# 1.180 01-Jul-2010 rmind

Remove pfind() and pgfind(), fix locking in various broken uses of these.
Rename real routines to proc_find() and pgrp_find(), remove PFIND_* flags
and have consistent behaviour. Provide proc_find_raw() for special cases.
Fix memory leak in sysctl_proc_corename().

COMPAT_LINUX: rework ptrace() locking, minimise differences between
different versions per-arch.

Note: while this change adds some formal cosmetics for COMPAT_DARWIN and
COMPAT_IRIX - locking there is utterly broken (for ages).

Fixes PR/43176.


# 1.179 24-Jun-2010 hannken

Clean up vnode lock operations pass 2:

VOP_UNLOCK(vp, flags) -> VOP_UNLOCK(vp): Remove the unneeded flags argument.

Welcome to 5.99.32.

Discussed on tech-kern.


# 1.178 08-Jun-2010 hannken

Procfs_lookup() does not lookup directory descriptors in the fd/
subdirectory. There is no need for recursive vnode locking here.

Ok: Christos Zoulas <christos@netbsd.org>


Revision tags: uebayasi-xip-base1 yamt-nfs-mp-base9 uebayasi-xip-base
# 1.177 08-Jan-2010 pooka

branches: 1.177.2; 1.177.4;
The VATTR_NULL/VREF/VHOLD/HOLDRELE() macros lost their will to live
years ago when the kernel was modified to not alter ABI based on
DIAGNOSTIC, and now just call the respective function interfaces
(in lowercase). Plenty of mix'n match upper/lowercase has creeped
into the tree since then. Nuke the macros and convert all callsites
to lowercase.

no functional change


Revision tags: matt-premerge-20091211 yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 jym-xensuspend-nbase
# 1.176 03-Jul-2009 elad

Where possible, extract the file-system's access() routine to two internal
functions: the first checking if the operation is possible (regardless of
permissions), the second checking file-system permissions, ACLs, etc.

Mailing list reference:

http://mail-index.netbsd.org/tech-kern/2009/06/21/msg005311.html


# 1.175 23-Jun-2009 elad

Move the implementation of vaccess() to genfs_can_access(), in line with
the other routines of the same spirit.

Adjust file-system code to use it.

Keep vaccess() for KPI compatibility and to keep element of least
surprise. A "diagnostic" message warning that vaccess() is deprecated will
be printed when it's used (obviously, only in DIAGNOSTIC kernels).

No objections on tech-kern@:

http://mail-index.netbsd.org/tech-kern/2009/06/21/msg005310.html


Revision tags: yamt-nfs-mp-base5
# 1.174 24-May-2009 ad

More changes to improve kern_descrip.c.

- Avoid atomics in more places.
- Remove the per-descriptor mutex, and just use filedesc_t::fd_lock.
It was only being used to synchronize close, and in any case we needed
to take fd_lock to free the descriptor slot.
- Optimize certain paths for the <NDFDFILE case.
- Sprinkle more comments and assertions.
- Cache more stuff in filedesc_t.
- Fix numerous minor bugs spotted along the way.
- Restructure how the open files array is maintained, for clarity and so
that we can eliminate the membar_consumer() call in fd_getfile(). This is
mostly syntactic sugar; the main functional change is that fd_nfiles now
lives alongside the open file array.

Some measurements with libmicro:

- simple file syscalls are like close() are between 1 to 10% faster.
- some nice improvements, e.g. poll(1000) which is ~50% faster.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 nick-hppapmap-base2 jym-xensuspend-base nick-hppapmap-base mjf-devfs2-base
# 1.173 17-Dec-2008 cegger

branches: 1.173.2;
kill MALLOC and FREE macros.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 haad-dm-base2 haad-nbase2 ad-audiomp2-base netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 haad-dm-base
# 1.172 05-Sep-2008 skrll

branches: 1.172.2;
PR/39324 kernel diagnostic assertion "l->l_stat != LSZOMB" failed.

Ignore procs with zero or all LSZOMB LWPs. Get a non-LSZOMB LWP to perform
operations against as part of the deal.

procfs really needs to be updated to support multi-threading fully.
Hi Antti!


# 1.171 05-Sep-2008 skrll

ANSIfy


Revision tags: simonb-wapbl-nbase simonb-wapbl-base
# 1.170 02-Jul-2008 rmind

branches: 1.170.2;
Remove proc_representative_lwp(), use a simple LIST_FIRST() instead.
OK by <ad>.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base
# 1.169 28-Apr-2008 martin

branches: 1.169.2; 1.169.4;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-nfs-mp-base
# 1.168 24-Apr-2008 ad

branches: 1.168.2;
Merge proc::p_mutex and proc::p_smutex into a single adaptive mutex, since
we no longer need to guard against access from hardware interrupt handlers.

Additionally, if cloning a process with CLONE_SIGHAND, arrange to have the
child process share the parent's lock so that signal state may be kept in
sync. Partially addresses PR kern/37437.


# 1.167 24-Apr-2008 ad

Network protocol interrupts can now block on locks, so merge the globals
proclist_mutex and proclist_lock into a single adaptive mutex (proc_lock).
Implications:

- Inspecting process state requires thread context, so signals can no longer
be sent from a hardware interrupt handler. Signal activity must be
deferred to a soft interrupt or kthread.

- As the proc state locking is simplified, it's now safe to take exit()
and wait() out from under kernel_lock.

- The system spends less time at IPL_SCHED, and there is less lock activity.


Revision tags: yamt-pf42-baseX yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14
# 1.166 21-Mar-2008 ad

branches: 1.166.2;
Catch up with descriptor handling changes. See kern_descrip.c revision
1.173 for details.


Revision tags: keiichi-mipv6-nbase nick-net80211-sync-base keiichi-mipv6-base bouyer-xeni386-nbase matt-armv6-nbase mjf-devfs-base hpcarm-cleanup-base
# 1.165 23-Jan-2008 elad

branches: 1.165.6;
Tons of process scope changes.

- Add a KAUTH_PROCESS_SCHEDULER action, to handle scheduler related
requests, and add specific requests for set/get scheduler policy and
set/get scheduler parameters.

- Add a KAUTH_PROCESS_KEVENT_FILTER action, to handle kevent(2) related
requests.

- Add a KAUTH_DEVICE_TTY_STI action to handle requests to TIOCSTI.

- Add requests for the KAUTH_PROCESS_CANSEE action, indicating what
process information is being looked at (entry itself, args, env,
open files).

- Add requests for the KAUTH_PROCESS_RLIMIT action indicating set/get.

- Add requests for the KAUTH_PROCESS_CORENAME action indicating set/get.

- Make bsd44 secmodel code handle the newly added rqeuests appropriately.

All of the above make it possible to issue finer-grained kauth(9) calls in
many places, removing some KAUTH_GENERIC_ISSUSER requests.

- Remove the "CAN" from KAUTH_PROCESS_CAN{KTRACE,PROCFS,PTRACE,SIGNAL}.

Discussed with christos@ and yamt@.


Revision tags: bouyer-xeni386-base matt-armv6-base
# 1.164 02-Jan-2008 ad

Merge vmlocking2 to head.


Revision tags: vmlocking2-base3 yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 vmlocking-nbase jmcneill-pm-base reinoud-bufcleanup-base
# 1.163 26-Nov-2007 pooka

branches: 1.163.2; 1.163.6;
Remove the "struct lwp *" argument from all VFS and VOP interfaces.
The general trend is to remove it from all kernel interfaces and
this is a start. In case the calling lwp is desired, curlwp should
be used.

quick consensus on tech-kern


Revision tags: bouyer-xenamd64-base2 bouyer-xenamd64-base
# 1.162 09-Nov-2007 christos

make the last argument of procfs_dir size_t


# 1.161 07-Nov-2007 ad

Merge from vmlocking:

- pool_cache changes.
- Debugger/procfs locking fixes.
- Other minor changes.


Revision tags: jmcneill-base yamt-x86pmap-base4 yamt-x86pmap-base3 vmlocking-base
# 1.160 10-Oct-2007 ad

branches: 1.160.2; 1.160.4;
Merge from vmlocking:

- Split vnode::v_flag into three fields, depending on field locking.
- simple_lock -> kmutex in a few places.
- Fix some simple locking problems.


# 1.159 08-Oct-2007 ad

Merge file descriptor locking, cwdi locking and cross-call changes
from the vmlocking branch.


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base2 yamt-x86pmap-base matt-mips64-base
# 1.158 22-Jul-2007 pooka

branches: 1.158.4; 1.158.6; 1.158.8; 1.158.10;
Don't allow getcwd() on procfs vnodes and provide "/" as the path
instead of the result from getcwd(). The works around locking
panics caused by namei calling VOP_READLINK while holding on to a
directory lock and getcwd() trying to acquire that lock. The real
fix would be to get rid of getcwd() calls within VOPs (not locking
safe), but that's not a viable option in the netbsd-4 timeframe.

Suggestion for workaround from David Holland.


Revision tags: nick-csl-alignment-base mjf-ufs-trans-base
# 1.157 24-May-2007 agc

branches: 1.157.2;
Extend the Linux emulation of /proc to include

/proc/stat
/proc/loadavg and
/proc/<pid>/statm.

These are only present when -o linux is specified as a mount option
to procfs.

Factor out some common code so that it can be used by a number of
functions.

XXX The values returned in the statm emulation need to be verified.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 1.156 04-Apr-2007 rmind

Unfortunately, missed procfs_proc_unlock() in previous.
Pointed out by pooka@


# 1.155 04-Apr-2007 rmind

procfs_readlink: Handle a possible fail of fd_getfile(), also, we
do not need to check for error again.
CID: 4436


# 1.154 09-Mar-2007 ad

branches: 1.154.2; 1.154.4;
- Make the proclist_lock a mutex. The write:read ratio is unfavourable,
and mutexes are cheaper use than RW locks.
- LOCK_ASSERT -> KASSERT in some places.
- Hold proclist_lock/kernel_lock longer in a couple of places.


# 1.153 04-Mar-2007 christos

Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.


# 1.152 03-Mar-2007 salo

Don't prepend rootvnode to the path in non-NULL case for exe links.
It breaks procfs in chroot.

from <christos>, tested by me.


Revision tags: ad-audiomp-base
# 1.151 19-Feb-2007 pooka

When checking for file validity under pid/, do proper proc->lwp
lookup (fsvo proper) instead of fiddling directly with the lwp
list.


# 1.150 18-Feb-2007 pooka

Don't check for validity of p in lookup for root nodes, since it
will always be NULL. Rather, just call pt_valid with NULL directly
and let it decide if we're a linux mount or not.


# 1.149 17-Feb-2007 pavel

Change the process/lwp flags seen by userland via sysctl back to the
P_*/L_* naming convention, and rename the in-kernel flags to avoid
conflict. (P_ -> PK_, L_ -> LW_ ). Add back the (now unused) LSDEAD
constant.

Restores source compatibility with pre-newlock2 tools like ps or top.

Reviewed by Andrew Doran.


# 1.148 16-Feb-2007 pooka

branches: 1.148.2;
In lookup, when checking for procfs process node validity, target the
process we're trying to get information about through procfs, not
the caller of lookup.

fixes 'ls -l /proc/*/file' panic, which would occur when trying to
lookup "file" for a kernel thread, which doesn't have p->p_textvp.


# 1.147 15-Feb-2007 ad

Need to acquire procp->p_mutex for procfs_dir().


# 1.146 11-Feb-2007 ad

Eliminate a couple of reference count and mutex leaks.


Revision tags: post-newlock2-merge
# 1.145 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 1.144 25-Dec-2006 elad

PR/35226: Johann Franz: Problems with permissions in
/usr/pkg/emul/linux/proc .

Okay mlelstv@


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3
# 1.143 09-Dec-2006 chs

a smorgasbord of improvements to vnode locking and path lookup:
- LOCKPARENT is no longer relevant for lookup(), relookup() or VOP_LOOKUP().
these now always return the parent vnode locked. namei() works as before.
lookup() and various other paths no longer acquire vnode locks in the
wrong order via vrele(). fixes PR 32535.
as a nice side effect, path lookup is also up to 25% faster.
- the above allows us to get rid of PDIRUNLOCK.
- also get rid of WANTPARENT (just use LOCKPARENT and unlock it).
- remove an assumption in layer_node_find() that all file systems implement
a recursive VOP_LOCK() (unionfs doesn't).
- require that all file systems supply vfs_vptofh and vfs_fhtovp routines.
fill in eopnotsupp() for file systems that don't support being exported
and remove the checks for NULL. (layerfs calls these without checking.)
- in union_lookup1(), don't change refcounts in the ISDOTDOT case, just
adjust which vnode is locked. fixes PR 33374.
- apply fixes for ufs_rename() from ufs_vnops.c rev. 1.61 to ext2fs_rename().


# 1.142 04-Dec-2006 christos

From Nicolas Joly: restore previous behavior in procfs_validfile_linux, since
readdir passes a NULL lwp.


# 1.141 03-Dec-2006 elad

Move kauth(9) call to where it belongs. Noticed by Nicolas Joly, thanks!


Revision tags: netbsd-4-base
# 1.140 28-Nov-2006 elad

branches: 1.140.2;
Move ktrace, ptrace, systrace, and procfs to use kauth(9).

First, remove process_checkioperm() calls from MD code. Similar checks
using kauth(9) routines (on the process scope, using appropriate action)
are done in the callers.

Add secmodel back-end to handle each subsystem.


# 1.139 25-Nov-2006 skrll

Expose the 'exe' symlink to the process realpath in NetBSD as well. An
example user is gdb.

OK'd by christos.


# 1.138 16-Nov-2006 christos

__unused removal on arguments; approved by core.


# 1.137 29-Oct-2006 christos

add an "emul" file node.


# 1.136 25-Oct-2006 christos

1. fix procfs_validfile{,_linux} to test for NULL pointers properly.
2. make "exe" entry be a symlink to the executable, instead of pointing
directly to the vnode of the executable.
3. factor out commonly used code.


Revision tags: yamt-splraiseipl-base2
# 1.135 12-Oct-2006 christos

- sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386


# 1.134 20-Sep-2006 manu

Emulate Linux's /proc/devices


Revision tags: abandoned-netbsd-4-base yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base rpaulo-netinet-merge-pcb-base
# 1.133 13-Jun-2006 yamt

branches: 1.133.6; 1.133.8;
use KAUTH_PROCESS_CANSEE rather than CURTAIN where appropriate.


# 1.132 13-Jun-2006 yamt

remove unnecessary arguments from kauth_authorize_process.
ie. make it similar to the one found in apple TN.


# 1.131 07-Jun-2006 kardel

merge FreeBSD timecounters from branch simonb-timecounters
- struct timeval time is gone
time.tv_sec -> time_second
- struct timeval mono_time is gone
mono_time.tv_sec -> time_uptime
- access to time via
{get,}{micro,nano,bin}time()
get* versions are fast but less precise
- support NTP nanokernel implementation (NTP API 4)
- further reading:
Timecounter Paper: http://phk.freebsd.dk/pubs/timecounter.pdf
NTP Nanokernel: http://www.eecis.udel.edu/~mills/ntp/html/kern.html


Revision tags: yamt-pdpolicy-base5 simonb-timecounters-base
# 1.130 14-May-2006 elad

branches: 1.130.2;
integrate kauth.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 elad-kernelauth-base yamt-pdpolicy-base yamt-uio_vmspace-base5
# 1.129 02-Feb-2006 christos

branches: 1.129.2; 1.129.4; 1.129.6; 1.129.8;
PR/32692: Matthew Mondor: linux compatibility in /proc/self should point
directly to the directory containing the pid instead of pointing to
/proc/curproc, because some programs rely on calling readlink on /proc/self
to get the pid.


# 1.128 11-Dec-2005 christos

branches: 1.128.2; 1.128.4;
merge ktrace-lwp.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base ktrace-lwp-base
# 1.127 02-Nov-2005 yamt

merge yamt-vop branch. remove following VOPs.

VOP_BLKATOFF
VOP_VALLOC
VOP_BALLOC
VOP_REALLOCBLKS
VOP_VFREE
VOP_TRUNCATE
VOP_UPDATE


Revision tags: yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 1.126 01-Oct-2005 atatat

branches: 1.126.2;
Add "cwd" and "root" symlinks to each process's directory. The cwd
link points to the process's current working directory, and the root
link points to the process's root directory. What else would you
expect?

For directories that are out of reach (caller is in a chroot, target
process is in a different chroot, etc), the links point to "/"
instead.


# 1.125 11-Sep-2005 elad

Implement curtain for procfs.


# 1.124 30-Aug-2005 xtraeme

Remove __P()


# 1.123 29-May-2005 christos

branches: 1.123.2;
- sprinkle const
- avoid shadowed variables.


Revision tags: kent-audio2-base
# 1.122 02-Apr-2005 christos

PR/29782: Martin Husemann: procfs can not unmount when some process has its
current directory in curproc. Fix from Pedro Martelletto:
We cannot call vgone() from procfs_inactive() if we are coming from
vclean(). that's what's probably causing the deadlock.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 yamt-km-base4 yamt-km-base3 netbsd-3-base
# 1.121 26-Feb-2005 perry

nuke trailing whitespace


Revision tags: yamt-km-base2 yamt-km-base kent-audio1-beforemerge kent-audio1-base
# 1.120 04-Oct-2004 yamt

branches: 1.120.4; 1.120.6;
procfs_readdir:
- return correct cookie when buffer size is small.
- simplify logic.


# 1.119 04-Oct-2004 yamt

procfs_readdir: remove a redundant assignment.


# 1.118 02-Oct-2004 yamt

procfs_getattr: correct size of /proc/self.


# 1.117 01-Oct-2004 yamt

procfs_readdir:
- fix a locking problem, using proclist_foreach_call. PR/27098.
- correct snprintf size argument.


# 1.116 01-Oct-2004 yamt

procfs_readdir: fix an offset handling bug after addition of /proc/self.


# 1.115 01-Oct-2004 yamt

procfs_readdir: use a list macro.


# 1.114 20-Sep-2004 jdolecek

add 'mounts' file for -o linux, which lists all currently mounted
filesystems; Linux glibc statvfs() uses this to get some of mount flags,
and this file is also useful as /emul/linux/etc/mtab (via symlink)


# 1.113 29-Apr-2004 jrf

Removed remaining caddr_t casts we do not need in miscfs. Recompiled
kernel and ran for a day or so. There are still some caddr_t types in
the arguments of some calls, I will do those separately (later) as
they touch a lot more of the system.
Approved by christos@NetBSD.org.


# 1.112 22-Apr-2004 itojun

sprintf -> snprintf


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.111 15-Feb-2004 jdolecek

unlock the descriptor table simple lock after fd_getfile() call in
procfs_readdir()
fixes procfs locking problems reported on current-users@, problem place
found by enami tsugutomo


# 1.110 30-Oct-2003 simonb

Remove some assigned-to but otherwise unused variables.


# 1.109 27-Sep-2003 darcy

Changes as discussed with itojun on tech-kern. I have modified the enums
to have KFS or PFS differentiators. Further I have wrapped the enum in
procfs in "#ifdef _KERNEL" as it is done in kernfs.

To see the discussion go to http://mail-index.NetBSD.org/tech-kern/2003/09/
and look for "Mismatched enums in include files" in the list.


# 1.108 07-Sep-2003 itojun

remove meaningless line (variable overwritten 2 lines below)


# 1.107 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.


# 1.106 29-Jun-2003 fvdl

branches: 1.106.2;
Back out the lwp/ktrace changes. They contained a lot of colateral damage,
and need to be examined and discussed more.


# 1.105 29-Jun-2003 thorpej

Undo part of the ktrace/lwp changes. In particular:
* Remove the "lwp *" argument that was added to vget(). Turns out
that nothing actually used it!
* Remove the "lwp *" arguments that were added to VFS_ROOT(), VFS_VGET(),
and VFS_FHTOVP(); all they did was pass it to vget() (which, as noted
above, didn't use it).
* Remove all of the "lwp *" arguments to internal functions that were added
just to appease the above.


# 1.104 28-Jun-2003 darrenr

Pass lwp pointers throughtout the kernel, as required, so that the lwpid can
be inserted into ktrace records. The general change has been to replace
"struct proc *" with "struct lwp *" in various function prototypes, pass
the lwp through and use l_proc to get the process pointer when needed.

Bump the kernel rev up to 1.6V


# 1.103 28-May-2003 christos

Add /proc/<pid>/stat for linux compat. j2sdk1.4.2 depends on it.


# 1.102 18-Apr-2003 christos

Make symlinks for directories that point to the actual directory.
Make symlinks to [kqueue] and [misc] for kqueue and misc fds.


# 1.101 17-Apr-2003 jdolecek

do not show nodes corresponding to directory descriptors for process
in fd/ subdirectory, nor allow lookup/open for the nodes
this fixes PR kern/21187 for good, and also avoids interesting directory
locking issues


# 1.100 17-Apr-2003 jdolecek

procfs_readdir(): in Pfd case, only show descriptors of types we want
how to represent (vnodes, fifo, pipes); also use fd_getfile() et al

this avoids annoying EOPNOTSUPP error messages from ls -F and such


# 1.99 17-Apr-2003 jdolecek

procfs_lookup(): use fd_getfile() et al in Pfd case


# 1.98 17-Apr-2003 jdolecek

use fd_getfile() in procfs_getfp(), and FILE_USE()/FILE_UNUSE() the
returned file descriptor pointer appropriately


# 1.97 17-Apr-2003 jdolecek

make some local arrays/variables static + const


# 1.96 10-Apr-2003 jdolecek

use former genfs_eopnotsupp_rele() as genfs_eopnotsupp(), so that vnodes
are vput()/vrele()d as necessary - some filesystems did use the wrong
one for some ops, and it's just safer to not take the chance

based on suggestion by Bill Studenmund


# 1.95 05-Apr-2003 dsl

Remove pointless check against PID_MAX. Let pfind() do the validation.
(The new pid allocation code may decide to allocate pids above PID_MAX.)


# 1.94 25-Feb-2003 jrf

This addresses PR kerm/19989. Thanks to hamajima@nagoya.ydc.co.jp for submitting this patch which enables /proc/uptime for linux emul. Patch reviewed by atatat@netbsd.org and tron@netbsd.org, approved by tron@netbsd.org.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 1.93 04-Jan-2003 martin

Cast off_t expression to long long to match format even on 64 bit
plattforms.

Shouldn't we introduce a PRIoff_t macro to create such format strings?


# 1.92 03-Jan-2003 christos

add LK_CANRECURSE in the locking of /dev/<pid>/fd/<n> and remove the curproc
kludge. Thanks to fvdl.


# 1.91 03-Jan-2003 christos

Implement /proc/<pid>/fd/<n>. This is work in progress. Questionable things:
- Is it ok to convert DTYPE_PIPE to VFIFO and DTYPE_SOCKET to VSOCK?
- XXX: Avoid locking issue in ls -Rl /proc by avoiding curproc
- Does I/O to pipes work?
- XXX: Are there security implications?


Revision tags: fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge gehenna-devsw-base kqueue-base
# 1.90 03-Aug-2002 simonb

Just use the "time" variable in the *_getattr functions instead of a call
to (the potentially expensive) microtime().


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.89 09-May-2002 thorpej

branches: 1.89.2;
Move code shared by procfs and the kernel proper out of procfs and
into the kernel proper (renaming functions from procfs_* to process_*).


Revision tags: eeh-devprop-base newlock-base ifpoll-base
# 1.88 12-Jan-2002 christos

Don't hide the real return code with EPERM.


# 1.87 06-Dec-2001 chs

add a VOP_PUTPAGES method for all the filesystems that don't have pages,
just unlock the interlock.


# 1.86 05-Dec-2001 thorpej

* Allow machine-dependent code to specify hooks for ptrace(2)
(__HAVE_PTRACE_MACHDEP) and procfs (__HAVE_PROCFS_MACHDEP).
These changes will allow platforms like x86 (XMM) and PowerPC
(AltiVec) to export extended register sets in a sane manner.

* Use __HAVE_PTRACE_MACHDEP to export x86 XMM registers (standard
FP + SSE/SSE2) using PT_{GET,SET}XMMREGS (in the machdep
ptrace request space).
* Use __HAVE_PROCFS_MACHDEP to export x86 XMM registers via
/proc/N/xmmregs in procfs.


Revision tags: thorpej-mips-cache-base
# 1.85 10-Nov-2001 lukem

add RCSIDs


# 1.84 06-Nov-2001 simonb

Remove some variables that are set but never used.


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base
# 1.83 31-Aug-2001 chs

branches: 1.83.2; 1.83.4;
map files are zero-length.


# 1.82 03-Jun-2001 chs

branches: 1.82.2;
procfs_bmap() should never be called, make it a "bad op".
let procfs_mmap() use the default error method.


Revision tags: thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 1.81 14-Apr-2001 kleink

In procfs_readdir(), give /proc/# directories DT_DIR (rather than DT_REG).


# 1.80 30-Mar-2001 fvdl

Bump va_blocksize for the map files some more, so that programs with
quite a few mappings have a chance of being handled correctly if
st_blksize is looked at.


# 1.79 29-Mar-2001 fvdl

For -o linux mounts, add some code to emulate /proc/#/maps.
Needs NAMECACHE_ENTER_REVERSE to include filenames.


# 1.78 21-Feb-2001 jdolecek

branches: 1.78.2;
make some more constant arrays 'const'


# 1.77 22-Jan-2001 jdolecek

make filesystem vnodeop, specop, fifoop and vnodeopv_* arrays const


# 1.76 17-Jan-2001 fvdl

Add a few linux-style files, only enabled when -o linux is specified
for the mount. Currently these are /proc/cpuinfo and /proc/meminfo.
The former only does something on i386 right now.


# 1.75 24-Nov-2000 chs

remove dead code and other misc cleanup.


# 1.74 09-Aug-2000 tv

Only show the "exe" entry to Linux processes, suggested by christos.
Since there are actually three struct emul's for linux, use the e_name
field to determine eligibility with strcmp().


# 1.73 09-Aug-2000 tv

Some versions of Linux libc look for /proc/.../exe instead of /proc/../file.
Add an entry for "exe" that is the same as "file", provided only if
COMPAT_LINUX is set.


# 1.72 03-Aug-2000 thorpej

MALLOC()/FREE() are not to be used for variable sized allocations.


# 1.71 28-Jun-2000 mrg

<vm/vm.h> -> <uvm/uvm_extern.h>


Revision tags: netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 1.70 30-Mar-2000 simonb

branches: 1.70.4;
Delete duplicate declaration of atopid().


Revision tags: chs-ubc2-newbase wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base fvdl-softdep-base
# 1.69 02-Sep-1999 thorpej

branches: 1.69.2; 1.69.8;
Make /proc/self a symlink to /proc/curproc. I've observed Linux programs
that expect /proc/self/cmdline to exist.


# 1.68 25-Aug-1999 sommerfeld

Change variable used for directory offset from "int" to "off_t".
Overkill, but avoids a host of truncation problems.


# 1.67 24-Aug-1999 sommerfeld

Fix PR8270:

Problem turned out to be due to improper handling of reads beyond EOF:
they should just return without error with the uio unchanged, and the
caller will recognize this as a zero-byte return (EOF).

The previous fix to protect directory reads against bogus uio_offset
values returned EINVAL, which broke mount -o union, which only
union'ed in the lower directory if the upper directory cleanly
returned EOF.

While we're here, protect kernfs as well.


# 1.66 14-Aug-1999 christos

protect against large uio_offset


# 1.65 03-Aug-1999 wrstuden

Add support for fcntl(2) to generate VOP_FCNTL calls. Any fcntl
call with F_FSCTL set and F_SETFL calls generate calls to a new
fileop fo_fcntl. Add genfs_fcntl() and soo_fcntl() which return 0
for F_SETFL and EOPNOTSUPP otherwise. Have all leaf filesystems
use genfs_fcntl().

Reviewed by: thorpej
Tested by: wrstuden


Revision tags: chs-ubc2-base
# 1.64 25-Jul-1999 thorpej

Add calls to lock the proclist as appropriate.


# 1.63 14-Jul-1999 thorpej

Fix a paste-o in procfs_lookup() introduced with the vnode locking changes.
Fixes PR #7961, Mario Kemper <magick@bundy.lip.owl.de>.


# 1.62 08-Jul-1999 wrstuden

Bump osrelease to 1.4E. Add layerfs files, remove null_subr.c.

Update coda to new struct lock in struct vnode.

make fdescfs, kernfs, portalfs, and procfs actually lock their vnodes.
It's not that hard.

Make unionfs set v_vnlock = NULL so any overlayed fs will call its
VOP_LOCK.


Revision tags: kame_141_19991130 netbsd-1-4-PATCH001 kame_14_19990705 kame_14_19990628 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.61 12-Mar-1999 christos

branches: 1.61.2; 1.61.4;
PR/7143: Jaromir Docelek: Add procfs/cmdline from Linux emulation


# 1.60 25-Jan-1999 msaitoh

Add /proc/#/map. From FreeBSD.


Revision tags: kenh-if-detach-base chs-ubc-base
# 1.59 08-Sep-1998 thorpej

- Use proclists[], rather than checking allproc and zombproc explicitly.
- Add some comments about locking.


# 1.58 13-Aug-1998 kleink

Per POSIX, fail with EINVAL if advisory locking is attempted on a file type
that doesn't support it, rather than using a homegrown EBADF or EOPNOTSUPP.


# 1.57 10-Aug-1998 matthias

create miscfs/genfs/genfs_vnops.c:genfs_enoioctl and make all the other
filesystems use it instead of a private version.


# 1.56 09-Aug-1998 perry

bzero->memset, bcopy->memcpy, bcmp->memcmp


# 1.55 03-Aug-1998 kleink

Recognize _PC_SYNC_IO.


Revision tags: eeh-paddr_t-base
# 1.54 21-Apr-1998 fvdl

procfs_readdir: in case of error, check if cookies actually have
been allocated before freeing them. From Wolfgang Solfrank.


# 1.53 01-Mar-1998 fvdl

Merge with Lite2 + local changes


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base marc-pcmcia-base
# 1.52 10-Oct-1997 fvdl

Bump last argument to VOP_READDIR to off_t (from u_long).


Revision tags: thorpej-signal-base
# 1.51 27-Aug-1997 thorpej

Fix a reversed argument which caused procfs_checkioperm() to always return
"OK". Add a few comments to avoid further confusion.


# 1.50 12-Aug-1997 thorpej

Fix the procfs hole described on current-users, similar to a fix for
FreeBSD by Sean Eric Fagan, but a bit different. This makes the checks
in the same places as sef's FreeBSD patch, but does not hardcode the
"kmem" group into the kernel, and also does a check identical to the
(3) and (4) checks in the NetBSD ptrace(2):

(1) it's not owned by you, or is set-id on exec (unless
you're root), or

(2) it's init, which controls the security level of the
entire system, and the system was not compiled with
permanently insecure mode turned on.


Revision tags: marc-pcmcia-bp
# 1.49 08-May-1997 mycroft

branches: 1.49.4;
Pass the vnode type to vaccess(), and use it when checking VEXEC. Make sure
that the mode bits passed to vaccess() and returned by foo_getattr() contain
only permission bits.


# 1.48 05-May-1997 mycroft

Need stat.h.


# 1.47 05-May-1997 mycroft

Eliminate bogus uses of V{READ,WRITE,EXEC}. Use S_I[RWX]{USR,GRP,OTH} where
appropriate.


# 1.46 28-Apr-1997 mycroft

Minor code cleanup.


Revision tags: is-newarp-before-merge is-newarp-base
# 1.45 25-Oct-1996 cgd

define path name string variables that we should not (and, thankfully, do
not) modify as 'const char *' rather 'char *'.


# 1.44 13-Oct-1996 christos

backout previous kprintf changes


# 1.43 10-Oct-1996 christos

printf -> kprintf, sprintf -> ksprintf


# 1.42 07-Sep-1996 mycroft

Implement poll(2).


# 1.41 01-Sep-1996 mycroft

Add a set of generic file system operations that most file systems use.
Also, fix some time stamp bogosities.


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 1.40 16-Mar-1996 christos

Fix printf format follies.


# 1.39 13-Feb-1996 mycroft

GC *_nullop(). Minor nits.


# 1.38 12-Feb-1996 christos

close PR/2063: procfs_rw prototyped twice with different prototypes


# 1.37 09-Feb-1996 christos

miscfs prototype changes


# 1.36 09-Feb-1996 mycroft

Fix vop_link, vop_symlink, and vop_remove semantics in several ways:
* Change the argument names to vop_link so they actually make sense.
* Implement vop_link and vop_symlink for all file systems, so they do proper
cleanup.
* Require the file system to decide whether or not linking and unlinking of
directories is allowed, and disable it for all current file systems.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.35 09-Oct-1995 mycroft

Use the index number as the cookie, rather than multiplying by UIO_MX.


# 1.34 09-Oct-1995 mycroft

Add support for cookies, mostly from Greg Hudson.


# 1.33 15-Apr-1995 cgd

fix timeval vs. timespec warnings


# 1.32 03-Feb-1995 mycroft

Return EROFS rather than ENOENT in many cases. Also some cosmetic cleanup.


# 1.31 27-Dec-1994 mycroft

Format police.


# 1.30 24-Dec-1994 ws

Implement and use a common access checking routine


# 1.29 14-Dec-1994 mycroft

Remove a_fp.


# 1.28 14-Nov-1994 christos

fixed struct comment


# 1.27 30-Oct-1994 cgd

be more careful with types, also pull in headers where necessary.


# 1.26 20-Oct-1994 cgd

update for new syscall args description mechanism


# 1.25 30-Aug-1994 mycroft

Convert process, file, and namei lists and hash tables to use queue.h.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.24 29-Jun-1994 cgd

New RCS ID's, take two. they're more aesthecially pleasant, and use 'NetBSD'


# 1.23 16-Jun-1994 mycroft

Remove an unneeded test.


# 1.22 15-Jun-1994 mycroft

Minor update from JSP after merging my changes.


# 1.21 08-Jun-1994 mycroft

Update to 4.4-Lite fs code, with local changes.


# 1.20 05-May-1994 cgd

lots of changes: prototype migration, move lots of variables, definitions,
and structure elements around. kill some unnecessary type and macro
definitions. standardize clock handling. More changes than you'd want.


# 1.19 15-Apr-1994 cgd

forgot these...


# 1.18 12-Apr-1994 cgd

be a bit smarter about determining if files shouldn't be seen by the user.
Also, DON'T allow a lookup to succeed on a file that's not visible!


# 1.17 15-Feb-1994 mycroft

Undo last change; executables is `file', not `a.out'.


# 1.16 14-Feb-1994 ws

Rename file -> a.out


# 1.15 14-Feb-1994 ws

Don't try to show a file for a process if there is none


# 1.14 28-Jan-1994 cgd

make a fpregs file.


# 1.13 20-Jan-1994 ws

Make procfs really work for debugging.
Implement not & notepg files in procfs.


# 1.12 09-Jan-1994 ws

Bug fixes and enhancements:
Make NFS serving work (BUT DON'T USE "attach" TO /proc/*/ctl FOR NOW!!!)
Make `curproc' a symbolic link
Add `.' and `..' entries to the directories.
Return better guesses on the size of the files.


# 1.11 05-Jan-1994 cgd

return size of 'reg' from getattr()


# 1.10 05-Jan-1994 cgd

make it compile (cleanly) for us


# 1.9 05-Jan-1994 cgd

add new procfs code, from Jan-Simon Pendry, jsp@sequent.com.
This is pretty-much "virgin", so that diffs can be done later.


# 1.8 18-Dec-1993 mycroft

Canonicalize all #includes.


Revision tags: magnum-base
# 1.7 16-Sep-1993 cgd

kill volatile warning.


# 1.6 07-Sep-1993 ws

branches: 1.6.2;
Changes to VFS readdir semantics
NFS changes for better cookie support
ISOFS changes for better Rockridge support and support for generation numbers


# 1.5 26-Aug-1993 pk

Implement setattr: mode for process entries; mode + uid/gid for the
PROCFS root directory.
Fixed omission in pfs_root() which came to light as a result of the above:
hold on to vnode for root dir.


# 1.4 25-Aug-1993 pk

Fixed improperly initialized nfsnode in pfs_lookup()


# 1.3 24-Aug-1993 pk

copyright update.


# 1.2 24-Aug-1993 pk

Rcs Id added.


# 1.1 24-Aug-1993 pk

branches: 1.1.1;
Initial version of a proc filesystem.