Home | History | Annotate | only in /src/lib/libkvm
History log of /src/lib/libkvm
RevisionDateAuthorComments
 1.55 18-Sep-2025  mrg introduce a couple of new turn-off-gcc-warning variables and use them.

GCC 14 has a new annoying calloc() checker that we turn off in a bunch
of places, and there are a few more dangling-pointer issuse that come up,
but seem bogus.
 1.54 03-Aug-2023  rin Revert CC_WNO_USE_AFTER_FREE from Makefile's (thanks uwe@)
 1.53 03-Aug-2023  rin Sprinkle CC_WNO_USE_AFTER_FREE for GCC 12

All of them are blamed for idiom equivalent to:
newbuf = realloc(buf, size);
p = newbuf + (p - buf);
 1.52 01-Apr-2023  rillig libkvm: suppress lint warnings about extern declarations for now

This should be properly fixed by someone who is familiar with libkvm, as
it affects <sys/cpu_data.h> as well.
 1.51 24-Jan-2016  christos mips needs _KMEMUSER for label_t in pcb.h
 1.50 10-Aug-2014  matt MKCOMPAT fixes for when compat MACHINE_CPU != normal MACHINE_CPU
 1.49 21-Mar-2012  matt branches: 1.49.2;
These directories don't handle WARNS=5
 1.48 12-Sep-2011  christos branches: 1.48.2;
add a function to report the name of the file kvm_open{,.files} is using.
 1.47 14-Feb-2011  matt Add -D_KMEMUSER to CPPFLAGS
 1.46 05-Oct-2010  jym branches: 1.46.2;
Import PAE support for kvm(3):
- add kvm_i386pae.c (used for PAE memory translations), and update Makefile
for libkvm build.
- in pdppaddr: pass a flag to indicate PAE mode. Use a bit ignored
by the MMU. Mask address with PG_FRAME to avoid side effects.

Tested with vmstat(1)/netstat(1) to debug core files of PAE and !PAE
kernels. Older kernel dumps will default to native i386 (!PAE) mode.

XXX Currently, savecore(8) will fail to dump a PAE kernel in a !PAE
environment (and reciprocally). So you need to sync and reboot
with a kernel of the same mode as the one that crashed. Once the dump
is successful, this does not matter anymore.
 1.45 25-Oct-2008  mrg look for ${KVM_MACHINE_ARCH} before ${MACHINE_ARCH} and ${MACHINE_CPU}
 1.44 28-May-2007  tls Add new Makefile knob, USE_FORT, which extends USE_SSP by turning on the
FORTIFY_SOURCE feature of libssp, thus checking the size of arguments to
various string and memory copy and set functions (as well as a few system
calls and other miscellany) where known at function entry. RedHat has
evidently built all "core system packages" with this option for some time.

This option should be used at the top of Makefiles (or Makefile.inc where
this is used for subdirectories) but after any setting of LIB.

This is only useful for userland code, and cannot be used in libc or in
any code which includes the libc internals, because it overrides certain
libc functions with macros. Some effort has been made to make USE_FORT=yes
work correctly for a full-system build by having the bsd.sys.mk logic
disable the feature where it should not be used (libc, libssp iteself,
the kernel) but no attempt has been made to build the entire system with
USE_FORT and doing so will doubtless expose numerous bugs and misfeatures.

Adjust the system build so that all programs and libraries that are setuid,
directly handle network data (including serial comm data), perform
authentication, or appear likely to have (or have a history of having)
data-driven bugs (e.g. file(1)) are built with USE_FORT=yes by default,
with the exception of libc, which cannot use USE_FORT and thus uses
only USE_SSP by default. Tested on i386 with no ill results; USE_FORT=no
per-directory or in a system build will disable if desired.
 1.43 10-Feb-2007  ad Add ${NETBSDSRCDIR}/sys to the include path.
 1.42 28-Mar-2003  christos do the exit on lint warnings only on i386 like libc, to avoid the wrath of
the sloppy archs.
 1.41 28-Mar-2003  christos exit on lint warnings.
 1.40 01-Mar-2003  lukem Add workaround for building with ${MACHINE}==sparc64, ${MACHINE_ARCH}==sparc;
symlink the appropriate machine & sparc include directories into the objdir.

XXX: this is necessary until (when?) the sparc Arch Dependent headers
(used by MACHINE_ARCH==sparc) are separated from the sparc Machine
Dependent headeres (used by MACHINE==sparc but not MACHINE==sparc64).
 1.39 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.38 19-Aug-2002  lukem Explicitly move setting of NOxxx and USE_SHLIBDIR to the top of the
Makefile (before including <bsd.own.mk>)
 1.37 28-Dec-2001  lukem branches: 1.37.2;
* Add user-controlled mk.conf variables
- SHLIBDIR Location to install shared libraries if ${USE_SHLIBDIR}
is "yes". Defaults to "/usr/lib".

- USE_SHLIBDIR If "yes", install shared libraries in ${SHLIBDIR}
instead of ${LIBDIR}. Defaults to "no".
Sets ${_LIBSODIR} to the appropriate value.
This may be set by individual Makefiles as well.

- SHLINKDIR Location of shared linker. Defaults to "/usr/libexec".
If != "/usr/libexec", change the dynamic-linker
encoded in shared programs

* Set USE_SHLIBDIR for libraries used by /bin and /sbin:
libc libcrypt libcrypto libedit libipsec libkvm libm libmi387
libtermcap libutil libz

* If ${_LIBSODIR} != ${LIBDIR}, add symlinks from ${LIBDIR}/${LIB}.so*
to ${_LIBSODIR}/${LIB}.so* for compatibility.

* Always install /sbin/init statically (for now)


The net effect of these changes depends on how the variables are set:

1.) If nothing is set or changed, there is no change from the
current behaviour:
- Static /bin, /sbin, and bits of /usr/*
- Dynamic rest
- Shared linker is /usr/libexec/ld*so

2.) If the following make variables are set:
LDSTATIC=
SHLINKDIR=/lib
SHLIBDIR=/lib
Then the behaviour becomes:
- Dynamic tools
- .so libraries used by /bin and /sbin are installed to /lib,
with symlinks from /usr/lib/lib*so to -> /lib/lib*so
where appropriate
- Shared linker is /lib/ld*so

3.) As per 2.), but add the following variable:
USE_SHLIBDIR=yes
This forces all .so's to be instaleld in /lib (with compat
symlinks), not just those tagged by their Makefiles to be.
Again, compat symlinks are installed
 1.36 21-May-2001  fredette Added support for sun2 kernel cores.
 1.35 08-Jan-2001  bjh21 Rename kvm_arm32.c to kvm_arm.c, since it's shared between arm32 and arm26.
The Makefile now finds the correct file without help.
 1.34 08-Jan-2001  itojun use MACIHNE_CPU to determine architecture-dependent source code directory.
is use of exists(foo) safe enough?
TODO: many other places to fix
 1.33 04-Jan-2001  itojun sh3 split
 1.32 13-Jun-2000  simonb Document KVM_NO_FILES and kvm_get{proc,argv,envv}2(). Better wording
kindly accepted!

XXX: Need to update distrib lists. Tomorrow...
 1.31 09-May-2000  bjh21 branches: 1.31.2;
Initial commit of arm26 port
 1.30 12-Sep-1999  chs the PMAP_NEW option is gone as the new interface is no longer optional.
 1.29 24-Mar-1999  mrg completely remove Mach VM support. all that is left is the all the
header files as UVM still uses (most of) these.
 1.28 24-Feb-1999  drochner make this build again after the mips->mipse? transition
 1.27 19-Feb-1998  thorpej NetBSD/mips uses new libkvm now.
 1.26 19-Feb-1998  thorpej Sigh, typo.
 1.25 19-Feb-1998  thorpej Simplify test ... MACHINE_ARCH == "mips"
 1.24 18-Feb-1998  perry add -DPMAP_NEW if PMAP_NEW is on in mk.conf
 1.23 18-Feb-1998  thorpej Rewrite _kvm_kvatop() to work with the new crash dump format, and make
the i386 port use libkvm, not libkvm.old.
 1.22 11-Feb-1998  mrg oops, forgot to add support for UVM here.
 1.21 22-Oct-1997  lukem use CPPFLAGS instead of CFLAGS
 1.20 19-Oct-1997  oki branches: 1.20.2;
Oops, fixed edit error at previous commit.
 1.19 19-Oct-1997  oki NetBSD/x68k now use libkvm instead of libkvm.old
 1.18 05-Oct-1997  mark Switch from libkvm.old to libkvm for the arm32 port.
 1.17 23-Jun-1997  veego Use bsd.prog.mk and not bsd.{own,man}.mk
 1.16 23-Jun-1997  veego Add bsd.own.mk for bsd.man.mk.
 1.15 23-Jun-1997  veego Don't include bsd.lib.mk if you don't build a library, just use bsd.man.mk
to build the manpages.
 1.14 23-Jun-1997  mrg move man pages into share/man.
 1.13 21-Mar-1997  gwr typo
 1.12 21-Mar-1997  gwr Build the same libkvm.* on all m68k machines. (Well... except for the
stragglers that still use libkvm.old ) The m68k machines now dispatch
based on the machine name to the appropriate libkvm implementation.
 1.11 18-Mar-1996  thorpej RCS id police.
 1.10 18-Mar-1996  leo Add a manual page for the kvm_dump_* functions.
 1.9 22-Dec-1994  cgd specify man pages the new way.
 1.8 18-Sep-1994  mycroft Merge the m68k files. The code itself should be merged.
 1.7 28-Jul-1994  gwr Add sun3 support (only "live" kernels for now).
 1.6 16-May-1994  chopps branches: 1.6.2;
add support for current m68k based pmaps till they can be "fixed"
 1.5 09-May-1994  cgd m68k-ify the hp300 kvm file; use MACHINE_ARCH to pick files up
 1.4 09-May-1994  cgd clean up import
 1.3 23-Apr-1994  briggs Add mac68k to amiga in looking for cpu040.
 1.2 14-Feb-1994  chopps temporary additional lookup of cpu040 for amiga's until new kvm stuff or new
amiga 040 VM stuff.
 1.1 27-Jan-1994  cgd branches: 1.1.1;
create this in preparation for later.
 1.1.1.1 09-May-1994  cgd new libkvm
 1.6.2.1 29-Jul-1994  cgd from trunk
 1.20.2.1 09-Nov-1997  lukem sync with trunk (approved by thorpej)
 1.31.2.1 23-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.37.2.3 19-Dec-2002  thorpej Sync with HEAD.
 1.37.2.2 23-Apr-2002  nathanw Make libkvm able to cope with a LWPified kernel.

Add a kvm_getlwps() function to retrieve the LWPs of a specific process.
 1.37.2.1 28-Dec-2001  nathanw file Makefile was added on branch nathanw_sa on 2002-04-23 20:10:19 +0000
 1.46.2.1 17-Feb-2011  bouyer Sync with HEAD
 1.48.2.1 17-Apr-2012  yamt sync with head
 1.49.2.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.1 03-Apr-2013  agc branches: 1.1.2;
file Version.map was initially added on branch agc-symver.
 1.1.2.1 03-Apr-2013  agc Add symbol versioning information for the following libraries:

libbluetooth
libbsdmalloc
libexecinfo
libform
libintl
libipsec
libkvm
liblwres
libnpf
libp2k
libpci
libperfuse
libppath
libprop
libpuffs
librefuse
librpcsvc
librt
librumpclient
librumphijack
librumpuser
libukfs
libusbhid
libwrap
 1.13 13-Sep-2011  wiz Sort sections.
 1.12 12-Sep-2011  christos add a function to report the name of the file kvm_open{,.files} is using.
 1.11 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.10 16-May-2003  wiz Consistently spell "crash dump" as two separate words. From jmc@openbsd.
 1.9 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.8 01-Oct-2002  wiz New sentence, new line. From Robert Elz.
 1.7 20-Aug-2002  wiz Use Nm instead of Xrefing ourselves.
 1.6 18-Aug-2002  yamt add FILES section to refer to /dev/mem.
from openbsd.
 1.5 02-Jul-1999  simonb branches: 1.5.10;
More trailing white space.
 1.4 06-Feb-1998  perry macroize BSD, NetBSD, FreeBSD and misc cleanup
 1.3 20-Aug-1997  mikel use -mdoc .Pa macro for filenames
 1.2 18-Mar-1996  thorpej RCS id police.
 1.1 09-May-1994  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 09-May-1994  cgd new libkvm
 1.5.10.3 19-Dec-2002  thorpej Sync with HEAD.
 1.5.10.2 23-Apr-2002  wiz Fix date in kvm_getlwps.3, and sort SEE ALSO in both it and kvm.3.
 1.5.10.1 23-Apr-2002  nathanw Make libkvm able to cope with a LWPified kernel.

Add a kvm_getlwps() function to retrieve the LWPs of a specific process.
 1.111 23-Aug-2023  rin libkvm: whitespace
 1.110 10-Jan-2022  christos Get rid of usrstack/USRSTACK. Document that the old version of getargv is
broken because of ASLR.
 1.109 02-May-2020  christos Cast off_t to size_t to appease lint:
warning: conversion from 'long long' to 'int' may lose accuracy
 1.108 28-Apr-2020  christos Don't treat failure to map the file as fatal.
 1.107 28-Apr-2020  christos make kvm_pread use the mapped buffer if it is available.
 1.106 28-Apr-2020  christos Implement kvm_write() for dump files. We map the file privately so that
changes don't get propagated back, and then write to the private buffer.
This is not useful yes, but it is simple enough to make pread use the buffer
if it is available.
 1.105 08-Mar-2020  chs only do bounce buffering for character devices.
 1.104 05-Nov-2018  mrg branches: 1.104.2;
initialise the kvm errbuf so that if an error occurs, but the
internal _kvm_*err() functions aren't called, stack garbage is
not reported as an error string.

call _kvm_err() if _kvm_kvatop() fails. now the above is not
triggered anymore :-)
 1.103 07-Feb-2018  maxv branches: 1.103.2; 1.103.4;
Keep /dev/ksyms open in _kvm_open(). This way /dev/ksyms can be put into
$g_kmem without breaking the tools that need kmem+ksyms.

Discussed on tech-kern@ three weeks ago. The original issue was reported
by maya@, the patch was written by Tom Ivar Helbekkmo, ok christos@.
 1.102 29-Mar-2016  mrg distinguish between partial and failed read, so that "read 0xffffffff bytes failed"
is not output..
 1.101 19-Feb-2014  dsl Remove the #include <sys/user.h> from all of libkvm.
sys/user.h is a stub that just #includes sys/pcb.h.
There are no 'struct pcb' anywhere in here, so I'm extremely doubtful
any of the builds will fail.
OTOH it might be relying on a header that pcb.h includes.
In any case i386 and amd64 build.
 1.100 26-Aug-2012  martin branches: 1.100.2;
Do not fail kvm_dump_mkheader without setting an error message
 1.99 15-Oct-2011  christos branches: 1.99.2;
kill open_cloexec()
 1.98 12-Sep-2011  christos add a function to report the name of the file kvm_open{,.files} is using.
 1.97 26-Nov-2010  dholland Return error on failure instead of hiding it and always returning zero.
From Henning Petersen in PR 44152.
 1.96 23-Oct-2010  stacktic Do not return -1 on _kvm_read when all the requested data could be read (fix bin/38648)
 1.95 20-Sep-2010  jym Change kvm_pa2off() and kvm_kvatop() prototypes (private to kvm(3)):

-int _kvm_kvatop(kvm_t *, u_long, u_long *);
-off_t _kvm_pa2off(kvm_t *, u_long);
+int _kvm_kvatop(kvm_t *, vaddr_t, paddr_t *);
+off_t _kvm_pa2off(kvm_t *, paddr_t);

Basically, use vaddr_t for VA and paddr_t for PA. In addition, for variables
representing addresses, use paddr_t or vaddr_t, depending on the context.

For most arches, vaddr_t and paddr_t are equivalent to unsigned long. However,
the change was needed for exotic situations, like i386 PAE, were unsigned long
is not suitable for PA which are 64 bits long. As this required a complete
change of the function prototypes, all arches had to be adapted accordingly.

Core files from before this commit should still work with the new code; I did
not see any direct dependency between core's structure and kvatop/pa2off.

The change was compile tested for all arches, as it impacts all of them.

See also:

http://mail-index.netbsd.org/current-users/2010/09/07/msg014249.html
 1.94 14-Sep-2009  apb Move the code that tries to open _PATH_KSYMS first into a common path,
so that it is used both for the /dev/mem case and the core dump case.

Output from savecore(8) before:
savecore - - - (null): kvm_openfiles: /netbsd: No such file or directory
and after:
savecore - - - no core dump
 1.93 20-Aug-2009  he Anoter instance of <sys/exec_aout.h> -> <sys/exec.h>.
 1.92 15-Jan-2008  ad ... and make kvm_dump_inval() work on the raw device.
 1.91 15-Jan-2008  ad Handle reading from raw disk devices.
 1.90 08-Nov-2007  joerg Fix a typo in the last change that broke a comparision.
 1.89 08-Nov-2007  joerg Add kvm_dump_header and implement kvm_dump_wrtheader on top of it.
This function allows the caller finer control of how the writes happen
and doesn't force stdio as interface. Optimise clear_gap a bit to not
fill the gap byte-wise. Bump minor version of libkvm.
 1.88 08-Nov-2007  joerg ANSIfy.
 1.87 11-May-2006  yamt branches: 1.87.10;
#include a necessary header directly, rather than via user.h.
 1.86 21-Mar-2006  christos Coverity CID 881: Always print an error if allocation failed.
If the program is not specified use getprogname()
 1.85 16-Feb-2006  christos 1. Eliminate some unnecessary to kvm_{m,re}alloc.
2. Don't malloc/free procbase/procbase2/lwpbase continuously. Keep track
of the size, and only do it if necessary.
3. Write a macro to malloc/realloc and set the size of members so that it
is done correctly. Previous open coded version in kvm_file.c always
set the length, which is incorrect.
4. Remove bogus check against INT_MAX.
5. use NULL to initialize pointers instead of 0.
 1.84 30-Jul-2005  yamt as swap is now optional, ENXIO on /dev/drum is normal.
 1.83 13-Feb-2004  wiz Uppercase CPU, plural is CPUs.
 1.82 04-Nov-2003  cube When using /dev/ksyms, don't keep it open more than strictly necessary.
This allows LKM manipulation while an application using libkvm, such as
vmstat or gkrellm, is running.

Patch reviewed by Anders Magnusson.
 1.81 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.80 11-May-2003  ragge Make the kvm routines use /dev/ksyms to get the kernel namelist.
If it fails, use /netbsd instead.
 1.79 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.78 16-Nov-2002  itojun use strlcpy to ensure string termination
 1.77 17-Sep-2002  christos Use FD_CLOEXEC instead of `1' and don't cast.
 1.76 17-Sep-2002  atatat Default using the value of machdep.booted_kernel from sysctl() if it
is available and points to a file. The value of "/netbsd" is still
the ultimate fallback.
 1.75 17-Sep-2002  drochner another SETFL->SETFD
 1.74 17-Sep-2002  drochner actually do the close-on-exec
 1.73 16-Sep-2002  christos Set the close-on-exec bit on all file descriptors we open. Inspired by a
FreeBSD security advisory.

Reviewed by thorpej
 1.72 08-Aug-2002  soren Don't omit third argument to open(2).
PR lib/15752 from Stephen Ma.
 1.71 26-May-2002  wiz __STDC__ is always defined on NetBSD.
 1.70 18-Sep-2001  wiz branches: 1.70.2; 1.70.4;
Give initiali[sz]e all the "i"s it deserves.
 1.69 16-Nov-2000  msaitoh Add forgotten initialization.
Fixed PR#11446.
 1.68 04-Oct-2000  sommerfeld format-string audit cleanups
 1.67 29-Jun-2000  mrg <vm/vm.h> -> <uvm/uvm_extern.h>
 1.66 26-Jun-2000  mrg remove redundant vm includes
 1.65 26-May-2000  simonb branches: 1.65.4;
Add kvm interface to the new sysctls:
kvm_getproc2() -> sysctl(KERN_PROC2)
kvm_getargv2() -> sysctl(KERN_PROC_ARGS, KERN_PROC_ARGV)
kvm_getenvv2() -> sysctl(KERN_PROC_ARGS, KERN_PROC_ENV)
Add new KVM_NO_FILES flag to kvm_open*() - set up enough state to
use the above calls without having to open any kernel files.

XXX: kvm_getprocs.3 and kvm_open.3 to be updated soon.
 1.64 02-Jul-1999  simonb More trailing white space.
 1.63 01-Apr-1999  mycroft branches: 1.63.2;
Nuke swap_pager.h.
 1.62 27-Sep-1998  christos Remove lint
 1.61 10-Aug-1998  perry bzero->memset, bcopy->memcpy, bcmp->memcmp
 1.60 01-Aug-1998  thorpej Remove some lint.
 1.59 26-Jul-1998  mycroft const poisoning.
 1.58 30-Jun-1998  thorpej Oops, missed a couple of pread(2) uses.
 1.57 30-Jun-1998  thorpej Use pread(2) and pwrite(2) rather than lseek(2)/{read,write}(2).
 1.56 29-Jun-1998  msaitoh fix return value of kvm_read() and kvm_write()
 1.55 03-Feb-1998  perry remove obsolete register declarations
 1.54 10-Oct-1997  mrg clean up WARNS on the alpha.
 1.53 15-Aug-1997  mikel use <sys/cdefs.h> __RCSID() macro
 1.52 12-Aug-1997  gwr Call _kvm_mdopen(kd) to do machine-dependent initialization.
 1.51 09-Apr-1997  thorpej Add missing argument to fprintf().
 1.50 23-Jan-1997  mrg - convert unsafe strcpy(), strcat() and sprintf() to the `n' versions.
- some KNF.
 1.49 09-Nov-1996  pk Check return value of _kvm_initvtop().
 1.48 12-Oct-1996  cgd Don't use a kernel database based on the file name, use only
/var/db/kvm.db, and only use that if no kernel namelist file
is named. Update the documentation to describe this.
 1.47 04-Oct-1996  cgd some spaces -> tabs
 1.46 01-Oct-1996  cgd add code so that if kvm_nlist() failed because __fdnlist() failed,
kvm_geterr() actually provides useful information rather than just an
empty string.
 1.45 23-Jun-1996  leo Fix the empty error message problem more completely. When the magic-check
fails on the cpu_hdr, return 0 instead of -1. This allows the caller to
distinguise between fatal errors and 'nothing there'.
 1.44 23-Jun-1996  leo Fix the mysterious empty error message when savecore is executed and no
dump is present. This was caused by the fact that kvm_dump_mkheader() was
called *before* savecore checks the dump magic and kvm_dump_mkheader() returned
-1 without setting an error message. The latter is fixed now.
 1.43 05-May-1996  gwr Allow more flexibility in the format of cpu_kcore_hdr_t and isolate
the knowledge of that struct in the machine-dependent module.
 1.42 18-Mar-1996  thorpej RCS id police.
 1.41 18-Mar-1996  leo Nuke the kd_live argument to kvm_dump_mkheader(). it's not needed anymore...
 1.40 16-Mar-1996  leo New libkvm/savecore implementation. With the following differences:
1) savecore will not access the dump or live-kernel directly. It
will always use the kvm-functions. Allowing it to work on kernels
that don't have a 1-1 PA-VA mapping.
2) the kvm-lib has some additional functions to accomplish 1
- kvm_dump_mkheader()
- kvm_dump_wrtheader()
- kvm_dump_inval()
3) the file formats of the dump generated by the kernel and the dump
generated by savecore have been changed. The file format now looks
like the format produced for 'normal' core dumps.
Ports not yet supporting the new kvm-format will be using libkvm.old/
savecore.old for the time being.
 1.39 04-Jul-1995  cgd slight type cleanup. add some prototypes for internal functions,
some 'const' poisoning, some lvalue lossage.
 1.38 16-May-1995  mycroft Use the new ps_strings format. Find the arguments using their
addresses in the argv array, rather than guessing based on the location
of NULs.
 1.37 09-Jan-1995  mycroft Eliminate _kvm_uvatop(), in favor of using the machine-independent VM structures.
 1.36 18-Sep-1994  mycroft Move the swap page buffer into struct __kvm. Cache the page size during
kvm_open(). Fix an existing memory leak.
 1.35 09-May-1994  cgd clean up import
 1.34 05-May-1994  cgd field name change, and safety (minor)
 1.33 05-May-1994  cgd update for changed flags
 1.32 23-Apr-1994  briggs Add mac68k to amiga in looking for cpu040.
 1.31 17-Apr-1994  cgd kill end-check bug.
 1.30 15-Apr-1994  cgd queue foo
 1.29 31-Mar-1994  cgd quiet compiler, too
 1.28 31-Mar-1994  cgd bad cast, pointed out by Rafal Boni
 1.27 01-Mar-1994  phil Adding a ns32k definition for X_DEADKERNEL.
 1.26 14-Feb-1994  pk Sparc specific memory translations.
Some reorganization of the kernel nlist array.
 1.25 14-Feb-1994  chopps temporary additional lookup of cpu040 for amiga's until new kvm stuff or new
amiga 040 VM stuff.
 1.24 01-Feb-1994  mycroft Always read CLBYTES chunks, and cache the last one read. Don't allocate two
large arrays statically.
 1.23 07-Jan-1994  cgd get rid of the awful RSS hack
 1.22 15-Dec-1993  mycroft P[GD]_SHIFT --> P[GD]SHIFT
 1.21 05-Dec-1993  cgd look for m68k, rather than hp300 or amiga
 1.20 13-Oct-1993  mycroft Forgot to initialize `cp' in setsyserr().
 1.19 02-Oct-1993  mycroft Remove code for old VM system. Don't use page tables in kvm_procread().
Change `#if DEBUG' to `#ifdef DEBUG'. Read some symbols from the kernel
only once.
 1.18 16-Aug-1993  mycroft Last change was almost correct, but we have to check that the pager actually
has the page. If not, we go up the shadow chain.
 1.17 15-Aug-1993  mycroft Fix an off-by-one error when scanning the vm map for a page. Also, if the
page is not in core, don't recurse into shadow objects if we've already found
a pager.
 1.16 15-Aug-1993  mycroft Fix a bug in virtual to physical address translation on hp300s, and add support
for Amigas.
 1.15 14-Aug-1993  cgd line 860: use CLSHIFT rather than PGSHIFT.
line 927: fix bogus indentation
also make sure first chars of buffers are null char, just in
case nothing rational is read...
 1.14 14-Aug-1993  cgd implement kvm_procread for the hp300. now things mostly work on
the hp300, in terms of kvm. still minor strangeness re: sendmail...
 1.13 14-Aug-1993  mycroft #include <machine/pte.h>, not <hp300/hp300/pte.h>. Also, make it at least
compile for non-i386 architectures, but exit with an error message (for now).
 1.12 01-Aug-1993  mycroft Add RCS identifiers.
 1.11 19-Jul-1993  mycroft branches: 1.11.2;
Read swap in CLBYTES blocks.
 1.10 15-Jun-1993  deraadt kernel string read function takes much less time. could be optimized further,
by making block reads kernel page aligned. (cgd will make the next optimization
in this file)
 1.9 01-Jun-1993  cgd misc minor changes
 1.8 01-Jun-1993  cgd update kvm.c for the new way of doing things:
(1) add support for new stack format/PS_STRINGS
(2) add support for kvm_getenv
the HP300 support in kvm_procread needs to be looked at/filled in,
from example code in kvm_getu, plus hacks
 1.7 20-May-1993  cgd don't inlude select.h, but keep header cleanups
 1.6 20-May-1993  cgd fix new select stuff
 1.5 11-May-1993  cgd fix problem where kvm_getprocs(), ..., kvm_freeprocs(), kvm_getprocs()
would get no processes.
 1.4 27-Apr-1993  mycroft Fix memory leak.
 1.3 10-Apr-1993  cgd From: pk@cs.few.eur.nl (Paul Kranenburg)

patch which allows ps(1) and w(1) to lay
their hands on process command line arguments.
 1.2 21-Mar-1993  cgd after 0.2.2 "stable" patches applied
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 09-May-1994  cgd new libkvm
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.11.2.2 19-Jul-1993  mycroft Read swap in CLBYTES blocks.
 1.11.2.1 19-Jul-1993  mycroft file kvm.c was added on branch netbsd-0-9 on 1993-07-19 12:37:14 +0000
 1.63.2.1 04-Oct-2000  he Pull up revision 1.68 (requested by sommerfeld):
Format string audit.
 1.65.4.2 19-Sep-2002  itojun lib/libkvm/kvm.c 1.72-1.75,1.77

Set the close-on-exec bit on all file descriptors we open. Inspired by a
FreeBSD security advisory.
 1.65.4.1 03-Feb-2001  he Pull up revision 1.69 (requested by msaitoh):
Add forgotten initialization. Fixes PR#11446.
 1.70.4.1 16-Jun-2003  grant Pull up revision 1.65.4.2 from netbsd-1-5 branch (requested by david in
ticket #1255):

Set the close-on-exec bit on all file descriptors we open. Inspired by
a FreeBSD security advisory.
 1.70.2.3 19-Dec-2002  thorpej Sync with HEAD.
 1.70.2.2 23-Apr-2002  nathanw Make libkvm able to cope with a LWPified kernel.

Add a kvm_getlwps() function to retrieve the LWPs of a specific process.
 1.70.2.1 18-Sep-2001  nathanw file kvm.c was added on branch nathanw_sa on 2002-04-23 20:10:19 +0000
 1.87.10.2 23-Mar-2008  matt sync with HEAD
 1.87.10.1 09-Jan-2008  matt sync with HEAD
 1.99.2.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.99.2.1 30-Oct-2012  yamt sync with head
 1.100.2.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.103.4.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.103.4.1 10-Jun-2019  christos Sync with HEAD
 1.103.2.1 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.104.2.1 08-Mar-2020  martin Pull up following revision(s) (requested by chs in ticket #763):

lib/libkvm/kvm.c: revision 1.105
lib/libkvm/kvm_x86_64.c: revision 1.11

only do bounce buffering for character devices.

use a binary search in _kvm_pa2off(). this helps a lot for sparse dumps,
which can have millions of memory segments.
 1.12 23-Aug-2023  rin libkvm: whitespace
 1.11 10-Jan-2022  christos Get rid of usrstack/USRSTACK. Document that the old version of getargv is
broken because of ASLR.
 1.10 10-Nov-2020  skrll Catch up with aa64 is not mips change
 1.9 12-Sep-2019  mlelstv Need register defines that were moved to armreg.h
 1.8 19-Dec-2018  mrg be consistent about uint64_t and bit masks.
 1.7 19-Dec-2018  mrg use uint64_t for idx_mask. fixes lookups for some PAs. from skrll.

bump copyright. we updated this a lot of this in 2018.
 1.6 18-Dec-2018  skrll Fix _kvm_kvatop so that it now works.
 1.5 09-Nov-2018  mrg tg1 is a 64 bit value, store it in a 64 bit variable.
 1.4 01-Nov-2018  mrg compare matching TG1 bits.

aarch64 crash dump kvtop now less broken, but still not stable.
 1.3 01-Apr-2018  ryo branches: 1.3.2;
Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)
 1.2 14-Jun-2017  kamil branches: 1.2.4;
Stop including <sys/user.h> in userland libraries

This header in this context is freebsdism.
 1.1 10-Aug-2014  matt branches: 1.1.4;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.
 1.1.4.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.1.4.1 10-Aug-2014  tls file kvm_aarch64.c was added on branch tls-maxphys on 2014-08-20 00:02:17 +0000
 1.2.4.3 26-Dec-2018  pgoyette Sync with HEAD, resolve a few conflicts
 1.2.4.2 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.2.4.1 07-Apr-2018  pgoyette Sync with HEAD. 77 conflicts resolved - all of them $NetBSD$
 1.3.2.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.3.2.1 10-Jun-2019  christos Sync with HEAD
 1.29 23-Aug-2023  rin libkvm: whitespace
 1.28 10-Jan-2022  christos Get rid of usrstack/USRSTACK. Document that the old version of getargv is
broken because of ASLR.
 1.27 19-Feb-2014  dsl Remove the #include <sys/user.h> from all of libkvm.
sys/user.h is a stub that just #includes sys/pcb.h.
There are no 'struct pcb' anywhere in here, so I'm extremely doubtful
any of the builds will fail.
OTOH it might be relying on a header that pcb.h includes.
In any case i386 and amd64 build.
 1.26 27-Jan-2014  matt Add missing __RCSID("$NetBSD$");
 1.25 20-Sep-2010  jym branches: 1.25.6; 1.25.12;
Change kvm_pa2off() and kvm_kvatop() prototypes (private to kvm(3)):

-int _kvm_kvatop(kvm_t *, u_long, u_long *);
-off_t _kvm_pa2off(kvm_t *, u_long);
+int _kvm_kvatop(kvm_t *, vaddr_t, paddr_t *);
+off_t _kvm_pa2off(kvm_t *, paddr_t);

Basically, use vaddr_t for VA and paddr_t for PA. In addition, for variables
representing addresses, use paddr_t or vaddr_t, depending on the context.

For most arches, vaddr_t and paddr_t are equivalent to unsigned long. However,
the change was needed for exotic situations, like i386 PAE, were unsigned long
is not suitable for PA which are 64 bits long. As this required a complete
change of the function prototypes, all arches had to be adapted accordingly.

Core files from before this commit should still work with the new code; I did
not see any direct dependency between core's structure and kvatop/pa2off.

The change was compile tested for all arches, as it impacts all of them.

See also:

http://mail-index.netbsd.org/current-users/2010/09/07/msg014249.html
 1.24 19-Sep-2010  jym Ansify and KNF all functions within kvm(3). No objection on current-users@.

Used as ground for u_long => vaddr_t/paddr_t replacements in kvm(3)
private functions.

Compile tested for all arches. See also:

http://mail-index.netbsd.org/current-users/2010/09/07/msg014249.html
 1.23 15-Jan-2008  ad Handle reading from raw disk devices.
 1.22 16-May-2003  wiz branches: 1.22.22;
Consistently spell "crash dump" as two separate words. From jmc@openbsd.
 1.21 09-Apr-2003  nathanw Just use PAGE_SHIFT from <machine/vmparam.h> instead of going through
hoops to read and cache the value from the crash dump header.
 1.20 05-Aug-2001  matt branches: 1.20.2;
Include <machine/vmparam.h> for VM_MIN_*...
 1.19 05-Aug-2001  matt Don't include <machine/pmap.h> and <machine/vmparam.h> if _KERNEL isn't
defined. Include them explicitly in the few kvm_arch.c that need them.
 1.18 29-Jun-2000  mrg <vm/vm.h> -> <uvm/uvm_extern.h>
 1.17 26-Jun-2000  mrg remove redundant vm includes
 1.16 14-Jun-2000  cgd fix up NetBSD RCS Ids to match the standard, and the leading comment as
to match as well. No functional changes.
 1.15 02-Jul-1999  simonb branches: 1.15.6;
More trailing white space.
 1.14 17-Aug-1998  thorpej vm_size_t -> vaddr_t, thanks Matt Thomas for pointing it out.
 1.13 01-Aug-1998  thorpej Remove some lint.
 1.12 30-Jun-1998  thorpej Use pread(2) and pwrite(2) rather than lseek(2)/{read,write}(2).
 1.11 25-Mar-1998  thorpej Don't rely on a constant page shift value; dynamically compute it based
on the page size in the crash dump header.
 1.10 03-Mar-1998  thorpej Update for changes to <machine/pte.h>
 1.9 14-Feb-1998  cgd adjust changes in alpha's kcore.h.
 1.8 02-Nov-1997  ross --Fix k1seg translation, which has been broken since
--10/10/97 when a WARNS "fix" was put in that broke
--kernel core dump stack backtrace and other
--things that go thru libkvm.
 1.7 10-Oct-1997  mrg branches: 1.7.2;
clean up WARNS on the alpha.
 1.6 12-Aug-1997  gwr Add _kvm_mdopen()
 1.5 01-Oct-1996  cgd add support for real KV addresses, and clean up some.
 1.4 01-Oct-1996  cgd Real alpha support, minus actual KV -> physical translation. (Does K0SEG ->
physical translation, though, which is enough for e.g. dmesg and vmstat -i.)
 1.3 01-Oct-1996  cgd stub _kvm_pa2off so that new libkvm links
 1.2 29-Sep-1995  cgd reminder to not forget k0seg translations. (nothing done here yet, though.)
 1.1 10-Feb-1995  cgd stubs.
 1.7.2.1 02-Nov-1997  mellon Pull rev 1.8 up from trunk (ross)
 1.15.6.1 23-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.20.2.2 05-Aug-2001  matt Include <machine/vmparam.h> for VM_MIN_*...
 1.20.2.1 05-Aug-2001  matt file kvm_alpha.c was added on branch nathanw_sa on 2001-08-05 17:51:41 +0000
 1.22.22.1 23-Mar-2008  matt sync with HEAD
 1.25.12.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.25.6.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.7 10-Jan-2022  christos Get rid of usrstack/USRSTACK. Document that the old version of getargv is
broken because of ASLR.
 1.6 20-Sep-2010  jym Change kvm_pa2off() and kvm_kvatop() prototypes (private to kvm(3)):

-int _kvm_kvatop(kvm_t *, u_long, u_long *);
-off_t _kvm_pa2off(kvm_t *, u_long);
+int _kvm_kvatop(kvm_t *, vaddr_t, paddr_t *);
+off_t _kvm_pa2off(kvm_t *, paddr_t);

Basically, use vaddr_t for VA and paddr_t for PA. In addition, for variables
representing addresses, use paddr_t or vaddr_t, depending on the context.

For most arches, vaddr_t and paddr_t are equivalent to unsigned long. However,
the change was needed for exotic situations, like i386 PAE, were unsigned long
is not suitable for PA which are 64 bits long. As this required a complete
change of the function prototypes, all arches had to be adapted accordingly.

Core files from before this commit should still work with the new code; I did
not see any direct dependency between core's structure and kvatop/pa2off.

The change was compile tested for all arches, as it impacts all of them.

See also:

http://mail-index.netbsd.org/current-users/2010/09/07/msg014249.html
 1.5 19-Sep-2010  jym Ansify and KNF all functions within kvm(3). No objection on current-users@.

Used as ground for u_long => vaddr_t/paddr_t replacements in kvm(3)
private functions.

Compile tested for all arches. See also:

http://mail-index.netbsd.org/current-users/2010/09/07/msg014249.html
 1.4 15-Jan-2008  ad Handle reading from raw disk devices.
 1.3 01-Jan-2008  chris Update libkvm to be able to deal with arm kernel core dumps.

These changes allow savecore to successfully save a kernel core dump.

Final part of fixing PR cats/18026
 1.2 16-Jul-2001  matt branches: 1.2.2; 1.2.26;
Steal the variable VM_* stuff from m68k.
 1.1 08-Jan-2001  bjh21 Rename kvm_arm32.c to kvm_arm.c, since it's shared between arm32 and arm26.
The Makefile now finds the correct file without help.
 1.2.26.2 23-Mar-2008  matt sync with HEAD
 1.2.26.1 09-Jan-2008  matt sync with HEAD
 1.2.2.2 16-Jul-2001  matt Steal the variable VM_* stuff from m68k.
 1.2.2.1 16-Jul-2001  matt file kvm_arm.c was added on branch nathanw_sa on 2001-07-16 05:45:53 +0000
 1.8 08-Jan-2001  bjh21 Rename kvm_arm32.c to kvm_arm.c, since it's shared between arm32 and arm26.
The Makefile now finds the correct file without help.
 1.7 29-Jun-2000  mrg <vm/vm.h> -> <uvm/uvm_extern.h>
 1.6 18-Oct-1997  mark Include stdlib.h for prototype of free().
 1.5 05-Oct-1997  mark New version for libkvm rather than libkvm.old. Based on the kvm_powerpc.c
this is mainly stubs at the moment.
 1.4 15-Aug-1997  mikel use <sys/cdefs.h> __RCSID() macro
 1.3 14-Aug-1997  gwr Add _kvm_mdopen()
 1.2 18-Mar-1996  thorpej RCS id police.
 1.1 02-Feb-1996  mark Initial commit of the libkvm code for the arm32 port.
 1.15 20-Oct-2009  snj Remove 3rd and 4th clause on Leo Weppelman's license. OK leo@.
 1.14 10-Mar-2009  joerg Remove redundant .br.
 1.13 16-May-2003  wiz branches: 1.13.40;
Consistently spell "crash dump" as two separate words. From jmc@openbsd.
 1.12 16-Apr-2003  wiz Use
.In header.h
instead of
.Fd #include \*[Lt]header.h\*[Gt]
Much easier to read and write, and supported by groff for ages.
Okayed by ross.
 1.11 01-Oct-2002  wiz New sentence, new line. From Robert Elz.
 1.10 07-Feb-2002  ross branches: 1.10.2;
Generate <>& symbolically.
 1.9 15-Jan-2002  wiz Sort sections.
 1.8 25-Apr-2001  simonb Spell occurred correctly.
 1.7 06-Apr-2001  simonb xref kvm_open.
 1.6 02-Jul-1999  simonb More trailing white space.
 1.5 08-Jun-1998  lukem there probably are bugs. however, don't make an issue of it
 1.4 05-Feb-1998  perry add LIBRARY section to man page
 1.3 03-Feb-1998  perry NetBSD 1.1A -> .Nx 1.2
 1.2 23-Jun-1996  leo Fix the empty error message problem more completely. When the magic-check
fails on the cpu_hdr, return 0 instead of -1. This allows the caller to
distinguise between fatal errors and 'nothing there'.
 1.1 18-Mar-1996  leo Add a manual page for the kvm_dump_* functions.
 1.10.2.2 19-Dec-2002  thorpej Sync with HEAD.
 1.10.2.1 07-Feb-2002  thorpej file kvm_dump.3 was added on branch nathanw_sa on 2002-12-19 02:26:16 +0000
 1.13.40.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.29 19-Feb-2014  dsl Remove the #include <sys/user.h> from all of libkvm.
sys/user.h is a stub that just #includes sys/pcb.h.
There are no 'struct pcb' anywhere in here, so I'm extremely doubtful
any of the builds will fail.
OTOH it might be relying on a header that pcb.h includes.
In any case i386 and amd64 build.
 1.28 26-Sep-2010  jym branches: 1.28.6; 1.28.12;
Define KREAD() inside kvm_private.h, for reusability.
 1.27 19-Sep-2010  jym Ansify and KNF all functions within kvm(3). No objection on current-users@.

Used as ground for u_long => vaddr_t/paddr_t replacements in kvm(3)
private functions.

Compile tested for all arches. See also:

http://mail-index.netbsd.org/current-users/2010/09/07/msg014249.html
 1.26 12-Mar-2008  mrg don't need <sys/tty.h> here.
 1.25 27-Feb-2008  ad +#define _KERNEL
+#include <sys/types.h>
+#undef _KERNEL
 1.24 16-Feb-2006  christos branches: 1.24.10; 1.24.16;
1. Eliminate some unnecessary to kvm_{m,re}alloc.
2. Don't malloc/free procbase/procbase2/lwpbase continuously. Keep track
of the size, and only do it if necessary.
3. Write a macro to malloc/realloc and set the size of members so that it
is done correctly. Previous open coded version in kvm_file.c always
set the length, which is incorrect.
4. Remove bogus check against INT_MAX.
5. use NULL to initialize pointers instead of 0.
 1.23 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.22 02-Feb-2003  christos undo mallocvar.h change!
 1.21 01-Feb-2003  tron Include "sys/mallocvar.h" with "_KERNEL" defined in time to avoid
build failure because MALLOC_DECLARE() is not defined.
 1.20 01-Feb-2003  tron Fix build problem by rearranging the order of "#include" statements so
that "sys/mallocvar.h" gets include while "_KERNEL" is defined.
 1.19 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.18 05-Nov-2001  lukem branches: 1.18.2;
WARNS=2 fixes
 1.17 29-Jun-2000  mrg <vm/vm.h> -> <uvm/uvm_extern.h>
 1.16 26-Jun-2000  mrg remove redundant vm includes
 1.15 26-May-2000  simonb Add kvm interface to the new sysctls:
kvm_getproc2() -> sysctl(KERN_PROC2)
kvm_getargv2() -> sysctl(KERN_PROC_ARGS, KERN_PROC_ARGV)
kvm_getenvv2() -> sysctl(KERN_PROC_ARGS, KERN_PROC_ENV)
Add new KVM_NO_FILES flag to kvm_open*() - set up enough state to
use the above calls without having to open any kernel files.

XXX: kvm_getprocs.3 and kvm_open.3 to be updated soon.
 1.14 19-Aug-1999  cgd fix four major and one minor bug in dead kernel file-getting. Three
of the biggies crept in in rev. 1.10 (we need a lint trap!), the
others were here since the file was originally imported.
 1.13 02-Jul-1999  simonb More trailing white space.
 1.12 01-Apr-1999  veego branches: 1.12.2;
Nuke swap_pager.h.
 1.11 29-Sep-1998  thorpej Need string.h.
 1.10 27-Sep-1998  christos Remove lint
 1.9 03-Feb-1998  perry remove obsolete register declarations
 1.8 15-Aug-1997  drochner Fix compiler warnings.
 1.7 15-Aug-1997  mikel use <sys/cdefs.h> __RCSID() macro
GC unused variables and fix error message typo in kvm_deadfiles()
 1.6 20-Jun-1997  mikel add explicit return type for kvm_deadfiles()
 1.5 18-Mar-1996  thorpej RCS id police.
 1.4 28-Mar-1995  jtc KERNEL -> _KERNEL
 1.3 19-Oct-1994  cgd fix type of variables, add headers, protos, where necessary.
 1.2 30-Aug-1994  mycroft Update to match include files.
 1.1 09-May-1994  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 09-May-1994  cgd new libkvm
 1.12.2.1 20-Aug-1999  cgd pull up rev 1.14 from trunk (cgd)
 1.18.2.2 23-Apr-2002  nathanw Make libkvm able to cope with a LWPified kernel.

Add a kvm_getlwps() function to retrieve the LWPs of a specific process.
 1.18.2.1 05-Nov-2001  nathanw file kvm_file.c was added on branch nathanw_sa on 2002-04-23 20:10:19 +0000
 1.24.16.1 24-Mar-2008  keiichi sync with head.
 1.24.10.1 23-Mar-2008  matt sync with HEAD
 1.28.12.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.28.6.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.9 10-Mar-2009  joerg Remove redundant .br.
 1.8 07-Aug-2003  agc branches: 1.8.40;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.7 16-Apr-2003  wiz Use
.In header.h
instead of
.Fd #include \*[Lt]header.h\*[Gt]
Much easier to read and write, and supported by groff for ages.
Okayed by ross.
 1.6 07-Feb-2002  ross branches: 1.6.2;
Generate <>& symbolically.
 1.5 15-Jan-2002  wiz Sort sections.
 1.4 02-Jul-1999  simonb More trailing white space.
 1.3 05-Feb-1998  perry add LIBRARY section to man page
 1.2 18-Mar-1996  thorpej RCS id police.
 1.1 09-May-1994  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 09-May-1994  cgd new libkvm
 1.6.2.2 07-Feb-2002  ross Generate <>& symbolically.
 1.6.2.1 07-Feb-2002  ross file kvm_geterr.3 was added on branch nathanw_sa on 2002-02-07 07:00:49 +0000
 1.8.40.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.11 10-Mar-2009  joerg Remove redundant .br.
 1.10 07-Aug-2003  agc branches: 1.10.40;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.9 16-Apr-2003  wiz Use
.In header.h
instead of
.Fd #include \*[Lt]header.h\*[Gt]
Much easier to read and write, and supported by groff for ages.
Okayed by ross.
 1.8 01-Oct-2002  wiz New sentence, new line. From Robert Elz.
 1.7 07-Feb-2002  ross branches: 1.7.2;
Generate <>& symbolically.
 1.6 15-Jan-2002  wiz Sort sections and SEE ALSO, fix punctuation nits.
 1.5 05-Feb-1998  perry add LIBRARY section to man page
 1.4 12-Oct-1996  cgd use ".Dv NULL" rather than just "NULL", like everyplace else
 1.3 18-Mar-1996  thorpej RCS id police.
 1.2 28-Mar-1995  jtc KERNEL -> _KERNEL
 1.1 09-May-1994  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 09-May-1994  cgd new libkvm
 1.7.2.2 19-Dec-2002  thorpej Sync with HEAD.
 1.7.2.1 07-Feb-2002  thorpej file kvm_getfiles.3 was added on branch nathanw_sa on 2002-12-19 02:26:16 +0000
 1.10.40.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.2 13-Sep-2011  wiz Fix Xr.
 1.1 12-Sep-2011  christos doc for kvm_getkernelname
 1.13 11-Dec-2018  sevan Reword post mortem description. It tries to get the tree averages if it can.
 1.12 11-Dec-2018  sevan Clarify the difference to getloadavg(3).
 1.11 10-Mar-2009  joerg branches: 1.11.44; 1.11.46;
Remove redundant .br.
 1.10 07-Aug-2003  agc branches: 1.10.40;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.9 16-Apr-2003  wiz Use
.In header.h
instead of
.Fd #include \*[Lt]header.h\*[Gt]
Much easier to read and write, and supported by groff for ages.
Okayed by ross.
 1.8 18-Aug-2002  yamt change DIAGNOSTICS to RETURN VALUES
since it describes return values.
from openbsd.
 1.7 07-Feb-2002  ross branches: 1.7.2;
Generate <>& symbolically.
 1.6 15-Jan-2002  wiz Sort SEE ALSO.
 1.5 06-Apr-2001  simonb xref kvm_open.
 1.4 05-Feb-1998  perry add LIBRARY section to man page
 1.3 03-Jan-1997  mikel fix description; PR misc/3077.
also added xref to sysctl(3), which may be preferable.
 1.2 18-Mar-1996  thorpej RCS id police.
 1.1 09-May-1994  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 09-May-1994  cgd new libkvm
 1.7.2.2 19-Dec-2002  thorpej Sync with HEAD.
 1.7.2.1 07-Feb-2002  thorpej file kvm_getloadavg.3 was added on branch nathanw_sa on 2002-12-19 02:26:17 +0000
 1.10.40.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.11.46.1 10-Jun-2019  christos Sync with HEAD
 1.11.44.1 26-Dec-2018  pgoyette Sync with HEAD, resolve a few conflicts
 1.11 21-Mar-2012  matt Use C89 function definition
 1.10 26-Sep-2010  jym branches: 1.10.6; 1.10.8;
Define KREAD() inside kvm_private.h, for reusability.
 1.9 19-Sep-2010  jym Ansify and KNF all functions within kvm(3). No objection on current-users@.

Used as ground for u_long => vaddr_t/paddr_t replacements in kvm(3)
private functions.

Compile tested for all arches. See also:

http://mail-index.netbsd.org/current-users/2010/09/07/msg014249.html
 1.8 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.7 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.6 26-Jun-2000  mrg branches: 1.6.2;
use <uvm/uvm_param.h> now.
 1.5 27-Sep-1998  christos Remove lint
 1.4 15-Aug-1997  mikel use <sys/cdefs.h> __RCSID() macro
 1.3 20-Jun-1997  mikel include <stdlib.h> for getloadavg() prototype
 1.2 18-Mar-1996  thorpej RCS id police.
 1.1 09-May-1994  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 09-May-1994  cgd new libkvm
 1.6.2.1 23-Apr-2002  nathanw Make libkvm able to cope with a LWPified kernel.

Add a kvm_getlwps() function to retrieve the LWPs of a specific process.
 1.10.8.2 23-Apr-2012  riz Back out changes committed as part of ticket #195 which were apparently
not intended as part of the pullup request. Should fix netbsd-6 build.
 1.10.8.1 23-Apr-2012  riz Pull up following revision(s) (requested by manu in ticket #195):
lib/libskey/skeysubr.c: revision 1.27
lib/libkvm/kvm_getloadavg.c: revision 1.11
lib/libwrap/update.c: revision 1.9
lib/liby/yyerror.c: revision 1.9
lib/libpuffs/puffs_ops.3: revision 1.30
lib/libwrap/misc.c: revision 1.10
lib/libwrap/hosts_access.c: revision 1.20
lib/libpuffs/pnode.c: revision 1.11
lib/libperfuse/subr.c: revision 1.17
lib/libpuffs/pnode.c: revision 1.12
lib/libperfuse/subr.c: revision 1.18
lib/libwrap/options.c: revision 1.15
lib/libwrap/fix_options.c: revision 1.11
lib/libperfuse/ops.c: revision 1.52
lib/libperfuse/ops.c: revision 1.53
lib/libperfuse/ops.c: revision 1.54
lib/libwrap/hosts_ctl.c: revision 1.5
lib/libintl/gettext.c: revision 1.27
lib/libwrap/shell_cmd.c: revision 1.6
lib/libpuffs/dispatcher.c: revision 1.39
lib/libperfuse/perfuse_priv.h: revision 1.27
lib/libwrap/socket.c: revision 1.19
lib/libpuffs/puffs.3: revision 1.50
lib/libperfuse/perfuse_priv.h: revision 1.28
lib/libpuffs/puffs_priv.h: revision 1.45
lib/libpuffs/puffs.3: revision 1.51
lib/libperfuse/perfuse_priv.h: revision 1.29
lib/libwrap/percent_x.c: revision 1.5
lib/libpuffs/puffs.3: revision 1.52
lib/libperfuse/debug.c: revision 1.11
sys/fs/puffs/puffs_vnops.c: revision 1.165
lib/libwrap/tcpd.h: revision 1.13
sys/fs/puffs/puffs_vnops.c: revision 1.166
lib/libwrap/eval.c: revision 1.7
sys/fs/puffs/puffs_msgif.h: revision 1.78
sys/fs/puffs/puffs_vfsops.c: revision 1.101
lib/libwrap/rfc931.c: revision 1.9
lib/libwrap/clean_exit.c: revision 1.5
lib/libpuffs/puffs.h: revision 1.120
lib/libc/stdlib/jemalloc.c: revision 1.27
lib/librmt/rmtlib.c: revision 1.26
lib/libpuffs/puffs.h: revision 1.121
sys/fs/puffs/puffs_sys.h: revision 1.79
lib/librumpclient/rumpclient.c: revision 1.48
lib/libwrap/refuse.c: revision 1.5
lib/libperfuse/perfuse.c: revision 1.26
lib/libperfuse/perfuse.c: revision 1.27
tests/fs/puffs/t_fuzz.c: revision 1.5
lib/libperfuse/perfuse.c: revision 1.28
lib/libpuffs/dispatcher.c: revision 1.40
sys/fs/puffs/puffs_node.c: revision 1.24
lib/libwrap/diag.c: revision 1.9
lib/libintl/textdomain.c: revision 1.13
Use C89 function definition
Add name and atttribute cache with filesytem provided TTL.
lookup, create, mknod, mkdir, symlink, getattr and setattr messages
have been extended so that attributes and their TTL can be provided
by the filesytem. lookup, create, mknod, mkdir, and symlink messages
are also extended so that the filesystem can provide name TTL.
Add PUFFS_KFLAG_CACHE_FS_TTL flag to puffs_init(3) to use name and
attribute cache with filesystem provided TTL.
lookup, create, mknod, mkdir, symlink, getattr and setattr messages
have been extended so that attributes and their TTL can be provided
by the filesytem. lookup, create, mknod, mkdir, and symlink messages
are also extended so that the filesystem can provide name TTL.
The filesystem updates attributes and TTL using
puffs_pn_getvap(3), puffs_pn_getvattl(3), and puffs_pn_getcnttl(3)
Use new PUFFS_KFLAG_CACHE_FS_TTL option to puffs_init(3) so that
FUSE TTL on name and attributes are used. This save many PUFFS
operations and improves performances.
PUFFS_KFLAG_CACHE_FS_TTL is #ifdef'ed in many places for now so that
libperfuse can still be used on netbsd-5.
Split file system.
Comma fixes.
Remove dangling &quot;and&quot;.
Bump date for previous.
- Makesure update_va does not change vnode size when it should not. For
instance when doing a fault-issued VOP_GETPAGES within VOP_WRITE, changing
size leads to panic: genfs_getpages: past eof.
-Handle ticks wrap around for vnode name andattribute timeout
- When using PUFFS_KFLAG_CACHE_FS_TTL, do not use puffs_node to carry
attribute and TTL fora newly created node. Instead extend puffs_newinfo
and add puffs_newinfo_setva() and puffs_newinfo_setttl()
- Remove node_mk_common_final in libperfuse. It used to set uid/gid for
a newly created vnode but has been made redundant along time ago since
uid and gid are properly set in FUSE header.
- In libperfuse, check for corner case where opc = 0 on INACTIVE and RECLAIM
(how is it possible? Check for it to avoid a crash anyway)
- In libperfuse, make sure we unlimit RLIMIT_AS and RLIMIT_DATA so that
we do notrun out of memory because the kernel is lazy at reclaiming vnodes.
- In libperfuse, cleanup style of perfuse_destroy_pn()
Do not set PUFFS_KFLAG_CACHE_FS_TTL for PUFFS tests
 1.10.6.1 17-Apr-2012  yamt sync with head
 1.8 09-Jan-2018  kamil Correct the signature of kvm_getlwps(3) in the man-page.

The elemsize argument is of type "size_t", not "int *".

Sponsored by <The NetBSD Foundation>
 1.7 23-Jan-2016  dholland branches: 1.7.8;
Update synopses to match u_int/u_long/etc. changes. Do not bump date as
it's not a substantive change.
 1.6 10-Mar-2009  joerg Remove redundant .br.
 1.5 30-Apr-2008  martin branches: 1.5.8;
Convert TNF licenses to new 2 clause variant
 1.4 10-Feb-2004  jmmv branches: 1.4.30;
List sys/param.h as a prerequisite of sys/sysctl.h. Bump date.
 1.3 16-Apr-2003  wiz Use
.In header.h
instead of
.Fd #include \*[Lt]header.h\*[Gt]
Much easier to read and write, and supported by groff for ages.
Okayed by ross.
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 23-Apr-2002  nathanw branches: 1.1.2;
file kvm_getlwps.3 was initially added on branch nathanw_sa.
 1.1.2.2 23-Apr-2002  wiz Fix date in kvm_getlwps.3, and sort SEE ALSO in both it and kvm.3.
 1.1.2.1 23-Apr-2002  nathanw Make libkvm able to cope with a LWPified kernel.

Add a kvm_getlwps() function to retrieve the LWPs of a specific process.
 1.4.30.1 18-May-2008  yamt sync with head.
 1.5.8.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.7.8.1 03-Feb-2018  snj Pull up following revision(s) (requested by kamil in ticket #516):
lib/libkvm/kvm_getlwps.3: revision 1.8
Correct the signature of kvm_getlwps(3) in the man-page.
The elemsize argument is of type "size_t", not "int *".
Sponsored by <The NetBSD Foundation>
 1.17 09-Jan-2018  kamil Correct the signature of kvm_getproc2(3) in the man-page.

The elemsize argument is of type "size_t", not "int".

Sponsored by <The NetBSD Foundation>
 1.16 22-Oct-2017  abhinav Add rest of the functions from the SYNOPSIS to the NAME section
 1.15 10-Mar-2009  joerg branches: 1.15.38;
Remove redundant .br.
 1.14 10-Feb-2004  jmmv branches: 1.14.40;
List sys/param.h as a prerequisite of sys/sysctl.h. Bump date.
 1.13 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.12 16-Apr-2003  wiz Use
.In header.h
instead of
.Fd #include \*[Lt]header.h\*[Gt]
Much easier to read and write, and supported by groff for ages.
Okayed by ross.
 1.11 02-Oct-2002  wiz session, not sessiod. By Adrian Mrva.
 1.10 01-Oct-2002  wiz New sentence, new line. From Robert Elz.
 1.9 07-Feb-2002  ross branches: 1.9.2;
Generate <>& symbolically.
 1.8 15-Jan-2002  wiz Sort sections, fix whitespace and punctuation nits.
 1.7 13-Jun-2000  simonb Document KVM_NO_FILES and kvm_get{proc,argv,envv}2(). Better wording
kindly accepted!

XXX: Need to update distrib lists. Tomorrow...
 1.6 15-Apr-2000  simonb branches: 1.6.2;
Document KERN_PROC_TTY_NODEV and KERN_PROC_TTY_REVOKE.
 1.5 02-Jul-1999  simonb More trailing white space.
 1.4 05-Feb-1998  perry add LIBRARY section to man page
 1.3 20-May-1996  mrg update to reflect reality.
 1.2 18-Mar-1996  thorpej RCS id police.
 1.1 09-May-1994  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 09-May-1994  cgd new libkvm
 1.6.2.1 23-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.9.2.2 19-Dec-2002  thorpej Sync with HEAD.
 1.9.2.1 07-Feb-2002  thorpej file kvm_getprocs.3 was added on branch nathanw_sa on 2002-12-19 02:26:18 +0000
 1.14.40.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.15.38.1 03-Feb-2018  snj Pull up following revision(s) (requested by kamil in ticket #517):
lib/libkvm/kvm_getprocs.3: revision 1.17
Correct the signature of kvm_getproc2(3) in the man-page.
The elemsize argument is of type "size_t", not "int".
Sponsored by <The NetBSD Foundation>
 1.1 09-May-1994  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 09-May-1994  mycroft Clean up deleted files.
 1.1.1.1 09-May-1994  cgd new libkvm
 1.8 10-Jan-2022  christos Get rid of usrstack/USRSTACK. Document that the old version of getargv is
broken because of ASLR.
 1.7 19-Feb-2014  dsl Remove the #include <sys/user.h> from all of libkvm.
sys/user.h is a stub that just #includes sys/pcb.h.
There are no 'struct pcb' anywhere in here, so I'm extremely doubtful
any of the builds will fail.
OTOH it might be relying on a header that pcb.h includes.
In any case i386 and amd64 build.
 1.6 20-Sep-2010  jym branches: 1.6.6; 1.6.12;
Change kvm_pa2off() and kvm_kvatop() prototypes (private to kvm(3)):

-int _kvm_kvatop(kvm_t *, u_long, u_long *);
-off_t _kvm_pa2off(kvm_t *, u_long);
+int _kvm_kvatop(kvm_t *, vaddr_t, paddr_t *);
+off_t _kvm_pa2off(kvm_t *, paddr_t);

Basically, use vaddr_t for VA and paddr_t for PA. In addition, for variables
representing addresses, use paddr_t or vaddr_t, depending on the context.

For most arches, vaddr_t and paddr_t are equivalent to unsigned long. However,
the change was needed for exotic situations, like i386 PAE, were unsigned long
is not suitable for PA which are 64 bits long. As this required a complete
change of the function prototypes, all arches had to be adapted accordingly.

Core files from before this commit should still work with the new code; I did
not see any direct dependency between core's structure and kvatop/pa2off.

The change was compile tested for all arches, as it impacts all of them.

See also:

http://mail-index.netbsd.org/current-users/2010/09/07/msg014249.html
 1.5 24-Jun-2010  skrll More KNF
 1.4 24-Jun-2010  skrll ANSIfy / KNF.
 1.3 15-Jan-2008  ad Handle reading from raw disk devices.
 1.2 07-Aug-2003  agc branches: 1.2.22;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.1 06-Jun-2002  fredette branches: 1.1.2;
Added hppa support (some of it incomplete) to lib/csu, lib/libc,
and lib/libkvm.
 1.1.2.2 19-Dec-2002  thorpej Sync with HEAD.
 1.1.2.1 06-Jun-2002  thorpej file kvm_hppa.c was added on branch nathanw_sa on 2002-12-19 02:26:19 +0000
 1.2.22.1 23-Mar-2008  matt sync with HEAD
 1.6.12.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.6.6.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.32 10-Jan-2022  christos Get rid of usrstack/USRSTACK. Document that the old version of getargv is
broken because of ASLR.
 1.31 25-Apr-2020  maxv Switch to the new PTE naming. The old naming is now unused, remove it.
 1.30 19-Feb-2014  dsl Remove the #include <sys/user.h> from all of libkvm.
sys/user.h is a stub that just #includes sys/pcb.h.
There are no 'struct pcb' anywhere in here, so I'm extremely doubtful
any of the builds will fail.
OTOH it might be relying on a header that pcb.h includes.
In any case i386 and amd64 build.
 1.29 05-Oct-2010  jym branches: 1.29.6; 1.29.12;
Import PAE support for kvm(3):
- add kvm_i386pae.c (used for PAE memory translations), and update Makefile
for libkvm build.
- in pdppaddr: pass a flag to indicate PAE mode. Use a bit ignored
by the MMU. Mask address with PG_FRAME to avoid side effects.

Tested with vmstat(1)/netstat(1) to debug core files of PAE and !PAE
kernels. Older kernel dumps will default to native i386 (!PAE) mode.

XXX Currently, savecore(8) will fail to dump a PAE kernel in a !PAE
environment (and reciprocally). So you need to sync and reboot
with a kernel of the same mode as the one that crashed. Once the dump
is successful, this does not matter anymore.
 1.28 20-Sep-2010  jym Change kvm_pa2off() and kvm_kvatop() prototypes (private to kvm(3)):

-int _kvm_kvatop(kvm_t *, u_long, u_long *);
-off_t _kvm_pa2off(kvm_t *, u_long);
+int _kvm_kvatop(kvm_t *, vaddr_t, paddr_t *);
+off_t _kvm_pa2off(kvm_t *, paddr_t);

Basically, use vaddr_t for VA and paddr_t for PA. In addition, for variables
representing addresses, use paddr_t or vaddr_t, depending on the context.

For most arches, vaddr_t and paddr_t are equivalent to unsigned long. However,
the change was needed for exotic situations, like i386 PAE, were unsigned long
is not suitable for PA which are 64 bits long. As this required a complete
change of the function prototypes, all arches had to be adapted accordingly.

Core files from before this commit should still work with the new code; I did
not see any direct dependency between core's structure and kvatop/pa2off.

The change was compile tested for all arches, as it impacts all of them.

See also:

http://mail-index.netbsd.org/current-users/2010/09/07/msg014249.html
 1.27 19-Sep-2010  jym Ansify and KNF all functions within kvm(3). No objection on current-users@.

Used as ground for u_long => vaddr_t/paddr_t replacements in kvm(3)
private functions.

Compile tested for all arches. See also:

http://mail-index.netbsd.org/current-users/2010/09/07/msg014249.html
 1.26 25-Oct-2008  mrg use <i386/foo.h> in a few places.
 1.25 15-Jan-2008  ad Handle reading from raw disk devices.
 1.24 05-Jan-2008  jld Add address translation support for 4MB pages, which we use to map the
kernel text.
 1.23 05-Jan-2008  jld The address translation routine needs to use the plN_pi macros (for
indexing into the PTP), not the plN_i ones (for indexing into the entire
linear page table); cf. the analogous code for amd64. Fixes ~everything
to do with kernel core dumps on i386.
 1.22 18-Oct-2007  yamt sync with kernel after the merge of yamt-x86pmap branch.
 1.21 27-Aug-2004  thorpej branches: 1.21.16;
pdtpaddr -> pdppaddr
 1.20 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.19 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.18 05-Aug-2001  matt branches: 1.18.2;
Don't include <machine/pmap.h> and <machine/vmparam.h> if _KERNEL isn't
defined. Include them explicitly in the few kvm_arch.c that need them.
 1.17 29-Jun-2000  mrg <vm/vm.h> -> <uvm/uvm_extern.h>
 1.16 26-Jun-2000  mrg remove redundant vm includes
 1.15 02-Jul-1999  simonb More trailing white space.
 1.14 27-Sep-1998  christos Remove lint
 1.13 30-Jun-1998  thorpej Use pread(2) and pwrite(2) rather than lseek(2)/{read,write}(2).
 1.12 18-Feb-1998  thorpej Rewrite _kvm_kvatop() to work with the new crash dump format, and make
the i386 port use libkvm, not libkvm.old.
 1.11 15-Aug-1997  mikel use <sys/cdefs.h> __RCSID() macro
 1.10 14-Aug-1997  gwr Add _kvm_mdopen()
 1.9 18-Mar-1996  thorpej RCS id police.
 1.8 08-Mar-1996  mycroft Clean up a bit.
 1.7 29-Jun-1995  cgd fix a piece of sloppy coding on my part. gdb -k still doesn't work, though.
 1.6 26-Jun-1995  cgd update to match reality.
 1.5 09-Jan-1995  mycroft Eliminate _kvm_uvatop(), in favor of using the machine-independent VM structures.
 1.4 15-Aug-1994  mycroft Update to match current pmap.
 1.3 18-May-1994  pk branches: 1.3.2;
Fix kvm_uvatop().
 1.2 09-May-1994  cgd just punt for now; don't want to deal with this & don't want it to core
 1.1 09-May-1994  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 09-May-1994  cgd new libkvm
 1.3.2.1 15-Aug-1994  mycroft update from trunk
 1.18.2.2 23-Apr-2002  nathanw Make libkvm able to cope with a LWPified kernel.

Add a kvm_getlwps() function to retrieve the LWPs of a specific process.
 1.18.2.1 05-Aug-2001  nathanw file kvm_i386.c was added on branch nathanw_sa on 2002-04-23 20:10:20 +0000
 1.21.16.3 23-Mar-2008  matt sync with HEAD
 1.21.16.2 09-Jan-2008  matt sync with HEAD
 1.21.16.1 06-Nov-2007  matt sync with HEAD
 1.29.12.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.29.6.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.4 23-Aug-2023  rin libkvm: whitespace
 1.3 25-Apr-2020  maxv Switch to the new PTE naming. The old naming is now unused, remove it.
 1.2 19-Feb-2014  dsl Remove the #include <sys/user.h> from all of libkvm.
sys/user.h is a stub that just #includes sys/pcb.h.
There are no 'struct pcb' anywhere in here, so I'm extremely doubtful
any of the builds will fail.
OTOH it might be relying on a header that pcb.h includes.
In any case i386 and amd64 build.
 1.1 05-Oct-2010  jym branches: 1.1.6; 1.1.12;
Import PAE support for kvm(3):
- add kvm_i386pae.c (used for PAE memory translations), and update Makefile
for libkvm build.
- in pdppaddr: pass a flag to indicate PAE mode. Use a bit ignored
by the MMU. Mask address with PG_FRAME to avoid side effects.

Tested with vmstat(1)/netstat(1) to debug core files of PAE and !PAE
kernels. Older kernel dumps will default to native i386 (!PAE) mode.

XXX Currently, savecore(8) will fail to dump a PAE kernel in a !PAE
environment (and reciprocally). So you need to sync and reboot
with a kernel of the same mode as the one that crashed. Once the dump
is successful, this does not matter anymore.
 1.1.12.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.1.6.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.3 11-Dec-2021  mrg remove clause 3 from all my licenses that aren't conflicting with
another copyright claim line. again. (i did this in 2008 and then
did not update all of my personal templates.)
 1.2 30-Jun-2016  mrg various ia64 updates:
- add a compat vfork because of stupid
- add a weak sbrk
- add a shmat syscall
- add an empty kvm implementation that links
- add missing fp stuff
 1.1 17-Apr-2015  martin Dummy support for ia64
 1.20 10-Jan-2022  christos Get rid of usrstack/USRSTACK. Document that the old version of getargv is
broken because of ASLR.
 1.19 27-Jan-2014  matt Add missing __RCSID("$NetBSD$");
 1.18 20-Sep-2010  jym branches: 1.18.6; 1.18.12;
Change kvm_pa2off() and kvm_kvatop() prototypes (private to kvm(3)):

-int _kvm_kvatop(kvm_t *, u_long, u_long *);
-off_t _kvm_pa2off(kvm_t *, u_long);
+int _kvm_kvatop(kvm_t *, vaddr_t, paddr_t *);
+off_t _kvm_pa2off(kvm_t *, paddr_t);

Basically, use vaddr_t for VA and paddr_t for PA. In addition, for variables
representing addresses, use paddr_t or vaddr_t, depending on the context.

For most arches, vaddr_t and paddr_t are equivalent to unsigned long. However,
the change was needed for exotic situations, like i386 PAE, were unsigned long
is not suitable for PA which are 64 bits long. As this required a complete
change of the function prototypes, all arches had to be adapted accordingly.

Core files from before this commit should still work with the new code; I did
not see any direct dependency between core's structure and kvatop/pa2off.

The change was compile tested for all arches, as it impacts all of them.

See also:

http://mail-index.netbsd.org/current-users/2010/09/07/msg014249.html
 1.17 19-Sep-2010  jym Ansify and KNF all functions within kvm(3). No objection on current-users@.

Used as ground for u_long => vaddr_t/paddr_t replacements in kvm(3)
private functions.

Compile tested for all arches. See also:

http://mail-index.netbsd.org/current-users/2010/09/07/msg014249.html
 1.16 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.15 21-May-2001  fredette branches: 1.15.2; 1.15.34;
Added support for sun2 kernel cores.
 1.14 17-Jan-1998  veego Never ever commit changes without comiling it, even if you only change a
comment.
 1.13 28-Oct-1997  gwr Use <m68k/kcore.h> rather than <machine/kcore.h> to ensure
machine independence.
 1.12 12-Aug-1997  gwr Add _kvm_mdopen()
 1.11 09-Apr-1997  thorpej Update for new m68k/kcore.h. We use dispatch information provided
by the crash dump itself to facilitate cross-analysis. The m68k_cmn
for Utah pmaps reads MMU configuration from the crash dump to that
this works on 4k and 8k h/w page size systems.
 1.10 21-Mar-1997  gwr Build the same libkvm.* on all m68k machines. (Well... except for the
stragglers that still use libkvm.old ) The m68k machines now dispatch
based on the machine name to the appropriate libkvm implementation.
 1.9 07-May-1996  leo Fix small typo in last commit.
 1.8 05-May-1996  gwr Allow more flexibility in the format of cpu_kcore_hdr_t and isolate
the knowledge of that struct in the machine-dependent module.
 1.7 18-Mar-1996  thorpej RCS id police.
 1.6 16-Mar-1996  leo New libkvm/savecore implementation. With the following differences:
1) savecore will not access the dump or live-kernel directly. It
will always use the kvm-functions. Allowing it to work on kernels
that don't have a 1-1 PA-VA mapping.
2) the kvm-lib has some additional functions to accomplish 1
- kvm_dump_mkheader()
- kvm_dump_wrtheader()
- kvm_dump_inval()
3) the file formats of the dump generated by the kernel and the dump
generated by savecore have been changed. The file format now looks
like the format produced for 'normal' core dumps.
Ports not yet supporting the new kvm-format will be using libkvm.old/
savecore.old for the time being.
 1.5 01-Jul-1995  briggs Take out cpu040 case for mac68k.
 1.4 02-Apr-1995  chopps should work without specialization now.
 1.3 09-Jan-1995  mycroft Eliminate _kvm_uvatop(), in favor of using the machine-independent VM structures.
 1.2 18-Sep-1994  mycroft Merge the m68k files. The code itself should be merged.
 1.1 09-May-1994  cgd m68k-ify the hp300 kvm file; use MACHINE_ARCH to pick files up
 1.15.34.1 18-May-2008  yamt sync with head.
 1.15.2.2 21-May-2001  fredette Added support for sun2 kernel cores.
 1.15.2.1 21-May-2001  fredette file kvm_m68k.c was added on branch nathanw_sa on 2001-05-21 14:56:30 +0000
 1.18.12.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.18.6.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.6 20-Sep-2010  jym Change kvm_pa2off() and kvm_kvatop() prototypes (private to kvm(3)):

-int _kvm_kvatop(kvm_t *, u_long, u_long *);
-off_t _kvm_pa2off(kvm_t *, u_long);
+int _kvm_kvatop(kvm_t *, vaddr_t, paddr_t *);
+off_t _kvm_pa2off(kvm_t *, paddr_t);

Basically, use vaddr_t for VA and paddr_t for PA. In addition, for variables
representing addresses, use paddr_t or vaddr_t, depending on the context.

For most arches, vaddr_t and paddr_t are equivalent to unsigned long. However,
the change was needed for exotic situations, like i386 PAE, were unsigned long
is not suitable for PA which are 64 bits long. As this required a complete
change of the function prototypes, all arches had to be adapted accordingly.

Core files from before this commit should still work with the new code; I did
not see any direct dependency between core's structure and kvatop/pa2off.

The change was compile tested for all arches, as it impacts all of them.

See also:

http://mail-index.netbsd.org/current-users/2010/09/07/msg014249.html
 1.5 19-Sep-2010  jym Ansify and KNF all functions within kvm(3). No objection on current-users@.

Used as ground for u_long => vaddr_t/paddr_t replacements in kvm(3)
private functions.

Compile tested for all arches. See also:

http://mail-index.netbsd.org/current-users/2010/09/07/msg014249.html
 1.4 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.3 21-May-2001  fredette branches: 1.3.2; 1.3.34;
Added support for sun2 kernel cores.
 1.2 09-Apr-1997  thorpej Update for new m68k/kcore.h. We use dispatch information provided
by the crash dump itself to facilitate cross-analysis. The m68k_cmn
for Utah pmaps reads MMU configuration from the crash dump to that
this works on 4k and 8k h/w page size systems.
 1.1 21-Mar-1997  gwr Build the same libkvm.* on all m68k machines. (Well... except for the
stragglers that still use libkvm.old ) The m68k machines now dispatch
based on the machine name to the appropriate libkvm implementation.
 1.3.34.1 18-May-2008  yamt sync with head.
 1.3.2.2 21-May-2001  fredette Added support for sun2 kernel cores.
 1.3.2.1 21-May-2001  fredette file kvm_m68k.h was added on branch nathanw_sa on 2001-05-21 14:56:30 +0000
 1.18 04-Mar-2014  matt #include <m68k/m68k.h>
 1.17 13-Sep-2011  christos branches: 1.17.2; 1.17.8;
Include <sys/param.h> for MAXPATHLEN
 1.16 26-Sep-2010  jym Define KREAD() inside kvm_private.h, for reusability.
 1.15 20-Sep-2010  jym Change kvm_pa2off() and kvm_kvatop() prototypes (private to kvm(3)):

-int _kvm_kvatop(kvm_t *, u_long, u_long *);
-off_t _kvm_pa2off(kvm_t *, u_long);
+int _kvm_kvatop(kvm_t *, vaddr_t, paddr_t *);
+off_t _kvm_pa2off(kvm_t *, paddr_t);

Basically, use vaddr_t for VA and paddr_t for PA. In addition, for variables
representing addresses, use paddr_t or vaddr_t, depending on the context.

For most arches, vaddr_t and paddr_t are equivalent to unsigned long. However,
the change was needed for exotic situations, like i386 PAE, were unsigned long
is not suitable for PA which are 64 bits long. As this required a complete
change of the function prototypes, all arches had to be adapted accordingly.

Core files from before this commit should still work with the new code; I did
not see any direct dependency between core's structure and kvatop/pa2off.

The change was compile tested for all arches, as it impacts all of them.

See also:

http://mail-index.netbsd.org/current-users/2010/09/07/msg014249.html
 1.14 19-Sep-2010  jym Ansify and KNF all functions within kvm(3). No objection on current-users@.

Used as ground for u_long => vaddr_t/paddr_t replacements in kvm(3)
private functions.

Compile tested for all arches. See also:

http://mail-index.netbsd.org/current-users/2010/09/07/msg014249.html
 1.13 15-Jan-2008  ad Handle reading from raw disk devices.
 1.12 07-Aug-2003  agc branches: 1.12.22;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.11 16-May-2003  wiz Consistently spell "crash dump" as two separate words. From jmc@openbsd.
 1.10 10-Oct-2000  he Use %lx instead of %x with _kvm_err when arg is u_long.
 1.9 02-Jul-1999  simonb branches: 1.9.8;
More trailing white space.
 1.8 30-Jun-1998  thorpej branches: 1.8.2;
Use pread(2) and pwrite(2) rather than lseek(2)/{read,write}(2).
 1.7 12-Oct-1997  briggs Fix a couple of warnings.
 1.6 12-Oct-1997  briggs Put spaces around / in comment so 'machine/*.h' does not generate '/* inside
comment' warning.
 1.5 26-Aug-1997  kleink /* Tyop. */
 1.4 15-Aug-1997  mikel use <sys/cdefs.h> __RCSID() macro
 1.3 23-Apr-1997  scottr In kvm_cmn_pa2off(), make sure to use the correct RAM segment start/size
values when adjusting the PA/offset. (Only broken in the case where we
had multiple RAM segments.)
 1.2 09-Apr-1997  thorpej Update for new m68k/kcore.h. We use dispatch information provided
by the crash dump itself to facilitate cross-analysis. The m68k_cmn
for Utah pmaps reads MMU configuration from the crash dump to that
this works on 4k and 8k h/w page size systems.
 1.1 21-Mar-1997  gwr Build the same libkvm.* on all m68k machines. (Well... except for the
stragglers that still use libkvm.old ) The m68k machines now dispatch
based on the machine name to the appropriate libkvm implementation.
 1.8.2.1 25-Oct-2000  he Pull up revision 1.10 (requested by steve):
Use %lx instead of %x with _kvm_err when arg is u_long.
 1.9.8.1 18-Oct-2000  tv Pullup 1.10 [he]:
Use %lx instead of %x with _kvm_err when arg is u_long.
 1.12.22.1 23-Mar-2008  matt sync with HEAD
 1.17.8.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.17.2.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.23 10-Jan-2022  christos Get rid of usrstack/USRSTACK. Document that the old version of getargv is
broken because of ASLR.
 1.22 19-Feb-2014  dsl Remove the #include <sys/user.h> from all of libkvm.
sys/user.h is a stub that just #includes sys/pcb.h.
There are no 'struct pcb' anywhere in here, so I'm extremely doubtful
any of the builds will fail.
OTOH it might be relying on a header that pcb.h includes.
In any case i386 and amd64 build.
 1.21 23-Jan-2011  matt branches: 1.21.4; 1.21.10;
Teach libkvm how kernel virtual memory is laided on 64-bit MIPS kernels.
 1.20 20-Sep-2010  jym branches: 1.20.2;
Change kvm_pa2off() and kvm_kvatop() prototypes (private to kvm(3)):

-int _kvm_kvatop(kvm_t *, u_long, u_long *);
-off_t _kvm_pa2off(kvm_t *, u_long);
+int _kvm_kvatop(kvm_t *, vaddr_t, paddr_t *);
+off_t _kvm_pa2off(kvm_t *, paddr_t);

Basically, use vaddr_t for VA and paddr_t for PA. In addition, for variables
representing addresses, use paddr_t or vaddr_t, depending on the context.

For most arches, vaddr_t and paddr_t are equivalent to unsigned long. However,
the change was needed for exotic situations, like i386 PAE, were unsigned long
is not suitable for PA which are 64 bits long. As this required a complete
change of the function prototypes, all arches had to be adapted accordingly.

Core files from before this commit should still work with the new code; I did
not see any direct dependency between core's structure and kvatop/pa2off.

The change was compile tested for all arches, as it impacts all of them.

See also:

http://mail-index.netbsd.org/current-users/2010/09/07/msg014249.html
 1.19 19-Sep-2010  jym Ansify and KNF all functions within kvm(3). No objection on current-users@.

Used as ground for u_long => vaddr_t/paddr_t replacements in kvm(3)
private functions.

Compile tested for all arches. See also:

http://mail-index.netbsd.org/current-users/2010/09/07/msg014249.html
 1.18 15-Jan-2008  ad branches: 1.18.16;
Handle reading from raw disk devices.
 1.17 16-May-2003  wiz branches: 1.17.22;
Consistently spell "crash dump" as two separate words. From jmc@openbsd.
 1.16 05-Aug-2001  matt branches: 1.16.2;
Don't include <machine/pmap.h> and <machine/vmparam.h> if _KERNEL isn't
defined. Include them explicitly in the few kvm_arch.c that need them.
 1.15 29-Jun-2000  mrg <vm/vm.h> -> <uvm/uvm_extern.h>
 1.14 26-Jun-2000  mrg remove redundant vm includes
 1.13 14-Jun-2000  cgd fix up NetBSD RCS Ids to match the standard, and the leading comment as
to match as well. No functional changes.
 1.12 02-Jul-1999  simonb branches: 1.12.6;
More trailing white space.
 1.11 30-Jun-1998  thorpej Use pread(2) and pwrite(2) rather than lseek(2)/{read,write}(2).
 1.10 19-Feb-1998  thorpej Rewrite NetBSD/mips crash dump address translation, based on NetBSD/alpha's,
using new crash dump format.
 1.9 03-Feb-1998  perry remove obsolete register declarations
 1.8 20-Oct-1997  jonathan kill lint.
 1.7 15-Aug-1997  mikel use <sys/cdefs.h> __RCSID() macro
 1.6 14-Aug-1997  gwr Add _kvm_mdopen()
 1.5 25-Jun-1997  jonathan MACH_CACHED_TO_PHYS() -> MIPS_KSEG0_TO_PHYS().
 1.4 18-Jun-1997  jonathan Include mips1_pte.h and mips3_pte.h. Read cpu_arch from the kernel
and set local variables for MIPSx_PG_V, MIPSx_PG_SHIFT_,
MIPSx_PG_FRAME accordingly.

(defining both MIPS3 and MIPS1 and using pte.h. doesn't yet work in userland.)
 1.3 18-Mar-1996  thorpej RCS id police.
 1.2 09-Jan-1995  mycroft Eliminate _kvm_uvatop(), in favor of using the machine-independent VM structures.
 1.1 09-May-1994  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 09-May-1994  cgd new libkvm
 1.12.6.1 23-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.16.2.2 05-Aug-2001  matt Don't include <machine/pmap.h> and <machine/vmparam.h> if _KERNEL isn't
defined. Include them explicitly in the few kvm_arch.c that need them.
 1.16.2.1 05-Aug-2001  matt file kvm_mips.c was added on branch nathanw_sa on 2001-08-05 03:33:16 +0000
 1.17.22.1 23-Mar-2008  matt sync with HEAD
 1.18.16.3 27-Dec-2011  matt Deal with non fixed page size on MIPS.
 1.18.16.2 27-Dec-2011  matt Don't use NBPG/PGSHIFT/PGOFFST any more.
Use nbpg from kvm_t and initialize that from the cpu_kcore_hdr_t.
 1.18.16.1 28-Jan-2010  matt Teach KVM about where the kernel is when _LP64 is defined.
 1.20.2.1 08-Feb-2011  bouyer Sync with HEAD
 1.21.10.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.21.4.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.11 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.10 13-May-2003  wiz Bump date for last; remove end-of-line spaces.
 1.9 11-May-2003  ragge Update after recent changes.
 1.8 16-Apr-2003  wiz Use
.In header.h
instead of
.Fd #include \*[Lt]header.h\*[Gt]
Much easier to read and write, and supported by groff for ages.
Okayed by ross.
 1.7 01-Oct-2002  wiz New sentence, new line. From Robert Elz.
 1.6 07-Feb-2002  ross branches: 1.6.2;
Generate <>& symbolically.
 1.5 05-Feb-1998  perry add LIBRARY section to man page
 1.4 12-Oct-1996  cgd Don't use a kernel database based on the file name, use only
/var/db/kvm.db, and only use that if no kernel namelist file
is named. Update the documentation to describe this.
 1.3 18-Mar-1996  thorpej RCS id police.
 1.2 06-Aug-1994  jtc vmunix -> netbsd (PR #375)
 1.1 09-May-1994  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 09-May-1994  cgd branches: 1.1.1.1.2;
new libkvm
 1.1.1.1.2.1 06-Aug-1994  mycroft update from trunk
 1.6.2.2 19-Dec-2002  thorpej Sync with HEAD.
 1.6.2.1 07-Feb-2002  thorpej file kvm_nlist.3 was added on branch nathanw_sa on 2002-12-19 02:26:20 +0000
 1.18 09-Jan-2008  simonb Remove support for NetBSD/pc532.
 1.17 07-Aug-2003  agc branches: 1.17.22;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.16 16-May-2003  wiz Consistently spell "crash dump" as two separate words. From jmc@openbsd.
 1.15 17-Sep-2001  simonb branches: 1.15.2;
Need <machine/pmap.h> for the pdei and ptei macros.
 1.14 05-Aug-2001  matt Don't include <machine/pmap.h> and <machine/vmparam.h> if _KERNEL isn't
defined. Include them explicitly in the few kvm_arch.c that need them.
 1.13 10-Oct-2000  he Use %lx instead of %x with _kvm_err when arg is u_long.
 1.12 29-Jun-2000  mrg <vm/vm.h> -> <uvm/uvm_extern.h>
 1.11 26-Jun-2000  mrg remove redundant vm includes
 1.10 02-Jul-1999  simonb branches: 1.10.8;
More trailing white space.
 1.9 30-Jun-1998  thorpej branches: 1.9.2;
Use pread(2) and pwrite(2) rather than lseek(2)/{read,write}(2).
 1.8 28-Oct-1997  phil include stdlib.h to define free().
 1.7 15-Aug-1997  mikel branches: 1.7.2;
use <sys/cdefs.h> __RCSID() macro
 1.6 12-Aug-1997  gwr Add _kvm_mdopen()
 1.5 08-Feb-1997  matthias The pc532 port now uses the new libkvm.
 1.4 18-Mar-1996  thorpej RCS id police.
 1.3 01-Feb-1996  phil Update for recent changes in the kernel.
 1.2 09-Jan-1995  mycroft Eliminate _kvm_uvatop(), in favor of using the machine-independent VM structures.
 1.1 20-May-1994  phil pc532 support in libkvm
 1.7.2.1 28-Oct-1997  mellon Pull rev 1.8 up from trunk
 1.9.2.1 27-Oct-2000  he Pull up revision 1.13 (requested by he):
Use %lx to format u_long parameter.
 1.10.8.1 18-Oct-2000  tv Pullup 1.13 [he]:
Use %lx instead of %x with _kvm_err when arg is u_long.
 1.15.2.2 17-Sep-2001  simonb Need <machine/pmap.h> for the pdei and ptei macros.
 1.15.2.1 17-Sep-2001  simonb file kvm_ns32k.c was added on branch nathanw_sa on 2001-09-17 12:48:21 +0000
 1.17.22.1 23-Mar-2008  matt sync with HEAD
 1.2 18-Sep-1994  mycroft Clean up deleted files.
 1.1 16-May-1994  chopps add support for current m68k based pmaps till they can be "fixed"
 1.18 12-Sep-2011  christos add a function to report the name of the file kvm_open{,.files} is using.
 1.17 22-Mar-2010  joerg Use .In instead of .Ar Pa for headers.
 1.16 14-Sep-2009  apb Make the documentation match reality. If no explicit kernel name is
provided, kvm_open() and kvm_openfiles() will try _PATH_KSYMS first,
then either the path from sysctl machdep.booted_kernel (if that's
available) or _PATH_UNIX (if the sysctl is not available).
 1.15 10-Mar-2009  joerg Remove redundant .br.
 1.14 07-Aug-2003  agc branches: 1.14.40;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.13 27-Jun-2003  wiz Pa Aq -> Aq Pa so that both work.
 1.12 16-Apr-2003  wiz Use
.In header.h
instead of
.Fd #include \*[Lt]header.h\*[Gt]
Much easier to read and write, and supported by groff for ages.
Okayed by ross.
 1.11 01-Oct-2002  wiz New sentence, new line. From Robert Elz.
 1.10 04-Sep-2002  wiz "initialse" looks nice, but is not correct.
 1.9 07-Feb-2002  ross branches: 1.9.2;
Generate <>& symbolically.
 1.8 15-Jan-2002  wiz Sort sections, fix punctuation nits.
 1.7 13-Jun-2000  simonb Document KVM_NO_FILES and kvm_get{proc,argv,envv}2(). Better wording
kindly accepted!

XXX: Need to update distrib lists. Tomorrow...
 1.6 02-Jul-1999  simonb branches: 1.6.6;
More trailing white space.
 1.5 06-Feb-1998  perry macroize BSD, NetBSD, FreeBSD and misc cleanup
 1.4 05-Feb-1998  perry add LIBRARY section to man page
 1.3 20-Aug-1997  mikel use -mdoc .Pa macro for filenames
 1.2 18-Mar-1996  thorpej RCS id police.
 1.1 09-May-1994  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 09-May-1994  cgd new libkvm
 1.6.6.1 23-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.9.2.2 19-Dec-2002  thorpej Sync with HEAD.
 1.9.2.1 07-Feb-2002  thorpej file kvm_open.3 was added on branch nathanw_sa on 2002-12-19 02:26:21 +0000
 1.14.40.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.3 23-Aug-2023  rin libkvm: whitespace
 1.2 10-Jan-2022  christos Get rid of usrstack/USRSTACK. Document that the old version of getargv is
broken because of ASLR.
 1.1 03-Sep-2014  matt New files for OR1K support
 1.15 23-Aug-2023  rin libkvm: whitespace
 1.14 10-Jan-2022  christos Get rid of usrstack/USRSTACK. Document that the old version of getargv is
broken because of ASLR.
 1.13 27-Jan-2014  matt Add missing __RCSID("$NetBSD$");
 1.12 20-Sep-2010  jym branches: 1.12.6; 1.12.12;
Change kvm_pa2off() and kvm_kvatop() prototypes (private to kvm(3)):

-int _kvm_kvatop(kvm_t *, u_long, u_long *);
-off_t _kvm_pa2off(kvm_t *, u_long);
+int _kvm_kvatop(kvm_t *, vaddr_t, paddr_t *);
+off_t _kvm_pa2off(kvm_t *, paddr_t);

Basically, use vaddr_t for VA and paddr_t for PA. In addition, for variables
representing addresses, use paddr_t or vaddr_t, depending on the context.

For most arches, vaddr_t and paddr_t are equivalent to unsigned long. However,
the change was needed for exotic situations, like i386 PAE, were unsigned long
is not suitable for PA which are 64 bits long. As this required a complete
change of the function prototypes, all arches had to be adapted accordingly.

Core files from before this commit should still work with the new code; I did
not see any direct dependency between core's structure and kvatop/pa2off.

The change was compile tested for all arches, as it impacts all of them.

See also:

http://mail-index.netbsd.org/current-users/2010/09/07/msg014249.html
 1.11 19-Sep-2010  jym KNF
 1.10 19-Sep-2010  jym Ansify and KNF all functions within kvm(3). No objection on current-users@.

Used as ground for u_long => vaddr_t/paddr_t replacements in kvm(3)
private functions.

Compile tested for all arches. See also:

http://mail-index.netbsd.org/current-users/2010/09/07/msg014249.html
 1.9 25-Feb-2010  matt Adapt to <powerpc/spr.h> breakup.
 1.8 15-Jan-2008  ad branches: 1.8.20;
Handle reading from raw disk devices.
 1.7 17-Feb-2005  briggs branches: 1.7.16;
Supply _kvm_kvatop() and _kvm_pa2off() for OEA-type CPUs. This does
not yet support other PPC CPU types.
Contributed by Wasabi Systems Inc.
 1.6 05-Aug-2001  matt branches: 1.6.2;
Don't include <machine/pmap.h> and <machine/vmparam.h> if _KERNEL isn't
defined. Include them explicitly in the few kvm_arch.c that need them.
 1.5 29-Jun-2000  mrg <vm/vm.h> -> <uvm/uvm_extern.h>
 1.4 03-Feb-1998  mycroft Need stdlib.h for prototypes.
 1.3 19-Sep-1997  thorpej Need <vm/vm.h>
 1.2 12-Aug-1997  gwr Add _kvm_mdopen()
 1.1 29-Mar-1997  thorpej kvm routines for PowerPC; just stubs, for now. From Wolfgang Solfrank
<ws@tools.de>
 1.6.2.2 05-Aug-2001  matt Don't include <machine/pmap.h> and <machine/vmparam.h> if _KERNEL isn't
defined. Include them explicitly in the few kvm_arch.c that need them.
 1.6.2.1 05-Aug-2001  matt file kvm_powerpc.c was added on branch nathanw_sa on 2001-08-05 03:33:16 +0000
 1.7.16.1 23-Mar-2008  matt sync with HEAD
 1.8.20.2 26-Jul-2011  matt Include the battable, not just the contents of the bat registers.
 1.8.20.1 07-Jan-2011  matt Deal with <spr.h> split.
 1.12.12.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.12.6.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.8 23-Aug-2023  rin libkvm: whitespace
 1.7 10-Jan-2022  christos Get rid of usrstack/USRSTACK. Document that the old version of getargv is
broken because of ASLR.
 1.6 23-Aug-2014  matt #if 0 some code not in use yet
 1.5 27-Jan-2014  matt branches: 1.5.4;
Add missing __RCSID("$NetBSD$");
 1.4 20-Sep-2010  jym branches: 1.4.6; 1.4.12;
Change kvm_pa2off() and kvm_kvatop() prototypes (private to kvm(3)):

-int _kvm_kvatop(kvm_t *, u_long, u_long *);
-off_t _kvm_pa2off(kvm_t *, u_long);
+int _kvm_kvatop(kvm_t *, vaddr_t, paddr_t *);
+off_t _kvm_pa2off(kvm_t *, paddr_t);

Basically, use vaddr_t for VA and paddr_t for PA. In addition, for variables
representing addresses, use paddr_t or vaddr_t, depending on the context.

For most arches, vaddr_t and paddr_t are equivalent to unsigned long. However,
the change was needed for exotic situations, like i386 PAE, were unsigned long
is not suitable for PA which are 64 bits long. As this required a complete
change of the function prototypes, all arches had to be adapted accordingly.

Core files from before this commit should still work with the new code; I did
not see any direct dependency between core's structure and kvatop/pa2off.

The change was compile tested for all arches, as it impacts all of them.

See also:

http://mail-index.netbsd.org/current-users/2010/09/07/msg014249.html
 1.3 19-Sep-2010  jym Ansify and KNF all functions within kvm(3). No objection on current-users@.

Used as ground for u_long => vaddr_t/paddr_t replacements in kvm(3)
private functions.

Compile tested for all arches. See also:

http://mail-index.netbsd.org/current-users/2010/09/07/msg014249.html
 1.2 05-Jul-2006  ross disable via radical lobotomy
this can't be properly converted now until kernel includes are available
 1.1 01-Jul-2006  ross ppc64 outline, needs more work
 1.4.12.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.4.6.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.5.4.1 04-Feb-2015  martin Pull up following revision(s) (requested by chs in ticket #489):
lib/libkvm/kvm_powerpc64.c: revision 1.6
 1.23 19-Apr-2022  rillig lib: remove CONSTCOND comment

Since 2021-01-31, lint doesn't need it anymore for the common pattern of
'do ... while (0)'.
 1.22 10-Jan-2022  christos Get rid of usrstack/USRSTACK. Document that the old version of getargv is
broken because of ASLR.
 1.21 28-Apr-2020  christos Implement kvm_write() for dump files. We map the file privately so that
changes don't get propagated back, and then write to the private buffer.
This is not useful yes, but it is simple enough to make pread use the buffer
if it is available.
 1.20 12-Sep-2011  christos add a function to report the name of the file kvm_open{,.files} is using.
 1.19 26-Sep-2010  jym Define KREAD() inside kvm_private.h, for reusability.
 1.18 20-Sep-2010  jym Change kvm_pa2off() and kvm_kvatop() prototypes (private to kvm(3)):

-int _kvm_kvatop(kvm_t *, u_long, u_long *);
-off_t _kvm_pa2off(kvm_t *, u_long);
+int _kvm_kvatop(kvm_t *, vaddr_t, paddr_t *);
+off_t _kvm_pa2off(kvm_t *, paddr_t);

Basically, use vaddr_t for VA and paddr_t for PA. In addition, for variables
representing addresses, use paddr_t or vaddr_t, depending on the context.

For most arches, vaddr_t and paddr_t are equivalent to unsigned long. However,
the change was needed for exotic situations, like i386 PAE, were unsigned long
is not suitable for PA which are 64 bits long. As this required a complete
change of the function prototypes, all arches had to be adapted accordingly.

Core files from before this commit should still work with the new code; I did
not see any direct dependency between core's structure and kvatop/pa2off.

The change was compile tested for all arches, as it impacts all of them.

See also:

http://mail-index.netbsd.org/current-users/2010/09/07/msg014249.html
 1.17 19-Sep-2010  jym Ansify and KNF all functions within kvm(3). No objection on current-users@.

Used as ground for u_long => vaddr_t/paddr_t replacements in kvm(3)
private functions.

Compile tested for all arches. See also:

http://mail-index.netbsd.org/current-users/2010/09/07/msg014249.html
 1.16 15-Jan-2008  ad Handle reading from raw disk devices.
 1.15 16-Feb-2006  christos branches: 1.15.10;
1. Eliminate some unnecessary to kvm_{m,re}alloc.
2. Don't malloc/free procbase/procbase2/lwpbase continuously. Keep track
of the size, and only do it if necessary.
3. Write a macro to malloc/realloc and set the size of members so that it
is done correctly. Previous open coded version in kvm_file.c always
set the length, which is incorrect.
4. Remove bogus check against INT_MAX.
5. use NULL to initialize pointers instead of 0.
 1.14 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.13 16-May-2003  wiz Consistently spell "crash dump" as two separate words. From jmc@openbsd.
 1.12 11-May-2003  ragge Make the kvm routines use /dev/ksyms to get the kernel namelist.
If it fails, use /netbsd instead.
 1.11 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.10 04-Oct-2000  sommerfeld branches: 1.10.2;
format-string audit cleanups
 1.9 26-May-2000  simonb Add kvm interface to the new sysctls:
kvm_getproc2() -> sysctl(KERN_PROC2)
kvm_getargv2() -> sysctl(KERN_PROC_ARGS, KERN_PROC_ARGV)
kvm_getenvv2() -> sysctl(KERN_PROC_ARGS, KERN_PROC_ENV)
Add new KVM_NO_FILES flag to kvm_open*() - set up enough state to
use the above calls without having to open any kernel files.

XXX: kvm_getprocs.3 and kvm_open.3 to be updated soon.
 1.8 12-Aug-1997  gwr branches: 1.8.4;
Add the members: usrstack, min_uva, max_uva to struct __kvm
and declare the function _kvm_mdopen() that initializes them.
 1.7 05-May-1996  gwr Allow more flexibility in the format of cpu_kcore_hdr_t and isolate
the knowledge of that struct in the machine-dependent module.
 1.6 18-Mar-1996  thorpej RCS id police.
 1.5 16-Mar-1996  leo New libkvm/savecore implementation. With the following differences:
1) savecore will not access the dump or live-kernel directly. It
will always use the kvm-functions. Allowing it to work on kernels
that don't have a 1-1 PA-VA mapping.
2) the kvm-lib has some additional functions to accomplish 1
- kvm_dump_mkheader()
- kvm_dump_wrtheader()
- kvm_dump_inval()
3) the file formats of the dump generated by the kernel and the dump
generated by savecore have been changed. The file format now looks
like the format produced for 'normal' core dumps.
Ports not yet supporting the new kvm-format will be using libkvm.old/
savecore.old for the time being.
 1.4 16-May-1995  mycroft Use the new ps_strings format. Find the arguments using their
addresses in the argv array, rather than guessing based on the location
of NULs.
 1.3 09-Jan-1995  mycroft Eliminate _kvm_uvatop(), in favor of using the machine-independent VM structures.
 1.2 18-Sep-1994  mycroft Move the swap page buffer into struct __kvm. Cache the page size during
kvm_open(). Fix an existing memory leak.
 1.1 09-May-1994  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 09-May-1994  cgd new libkvm
 1.8.4.1 04-Oct-2000  he Pull up revision 1.10 (requested by sommerfeld):
Format string audit.
 1.10.2.1 23-Apr-2002  nathanw Make libkvm able to cope with a LWPified kernel.

Add a kvm_getlwps() function to retrieve the LWPs of a specific process.
 1.15.10.1 23-Mar-2008  matt sync with HEAD
 1.100 15-Dec-2024  christos remove unused.
 1.99 10-Aug-2023  mrg branches: 1.99.2;
avoid various use-after-free issues.

create a ptrdiff_t offset between the start of an allocation region and
some interesting pointer, so it can be adjusted with this offset after
realloc() returns.

found by GCC 12.
 1.98 19-Apr-2022  rillig lib: remove CONSTCOND comment

Since 2021-01-31, lint doesn't need it anymore for the common pattern of
'do ... while (0)'.
 1.97 10-Jan-2022  christos read the ps arguments from the correct place.
 1.96 10-Jan-2022  christos Get rid of usrstack/USRSTACK. Document that the old version of getargv is
broken because of ASLR.
 1.95 19-Jul-2021  christos Match the declaration in <sys/kauth.h>
 1.94 11-Dec-2019  ad Redo previous more conventionally. Requested by kre@.
 1.93 10-Dec-2019  ad Mask out always zero bits off pg->phys_addr.
 1.92 04-Apr-2016  christos branches: 1.92.16;
some ports need <sys/wait.h>
 1.91 04-Apr-2016  christos catch up with p_xstat split.
 1.90 19-Feb-2014  dsl Remove the #include <sys/user.h> from all of libkvm.
sys/user.h is a stub that just #includes sys/pcb.h.
There are no 'struct pcb' anywhere in here, so I'm extremely doubtful
any of the builds will fail.
OTOH it might be relying on a header that pcb.h includes.
In any case i386 and amd64 build.
 1.89 05-Jun-2012  martin branches: 1.89.2;
Measure kinfo_proc2::p_vm_vsize in pages, as it was always documented.
This value seems to never have been used anywhere.
This makes it consistent with it's cousin p_vm_msize (which is in pages as
well and has several uses).
 1.88 12-Nov-2010  uebayasi branches: 1.88.6; 1.88.8;
Fix build.
 1.87 26-Sep-2010  jym Define KREAD() inside kvm_private.h, for reusability.
 1.86 20-Sep-2010  jym Change kvm_pa2off() and kvm_kvatop() prototypes (private to kvm(3)):

-int _kvm_kvatop(kvm_t *, u_long, u_long *);
-off_t _kvm_pa2off(kvm_t *, u_long);
+int _kvm_kvatop(kvm_t *, vaddr_t, paddr_t *);
+off_t _kvm_pa2off(kvm_t *, paddr_t);

Basically, use vaddr_t for VA and paddr_t for PA. In addition, for variables
representing addresses, use paddr_t or vaddr_t, depending on the context.

For most arches, vaddr_t and paddr_t are equivalent to unsigned long. However,
the change was needed for exotic situations, like i386 PAE, were unsigned long
is not suitable for PA which are 64 bits long. As this required a complete
change of the function prototypes, all arches had to be adapted accordingly.

Core files from before this commit should still work with the new code; I did
not see any direct dependency between core's structure and kvatop/pa2off.

The change was compile tested for all arches, as it impacts all of them.

See also:

http://mail-index.netbsd.org/current-users/2010/09/07/msg014249.html
 1.85 19-Sep-2010  jym Ansify and KNF all functions within kvm(3). No objection on current-users@.

Used as ground for u_long => vaddr_t/paddr_t replacements in kvm(3)
private functions.

Compile tested for all arches. See also:

http://mail-index.netbsd.org/current-users/2010/09/07/msg014249.html
 1.84 21-Oct-2009  rmind Remove uarea swap-out functionality:

- Addresses the issue described in PR/38828.
- Some simplification in threading and sleepq subsystems.
- Eliminates pmap_collect() and, as a side note, allows pmap optimisations.
- Eliminates XS_CTL_DATA_ONSTACK in scsipi code.
- Avoids few scans on LWP list and thus potentially long holds of proc_lock.
- Cuts ~1.5k lines of code. Reduces amd64 kernel size by ~4k.
- Removes __SWAP_BROKEN cases.

Tested on x86, mips, acorn32 (thanks <mpumford>) and partly tested on
acorn26 (thanks to <bjh21>).

Discussed on <tech-kern>, reviewed by <ad>.
 1.83 16-May-2009  yamt kvm_getprocs actually works with KVM_NO_FILES.
 1.82 29-Mar-2009  mrg - add new RLIMIT_AS (aka RLIMIT_VMEM) resource that limits the total
address space available to processes. this limit exists in most other
modern unix variants, and like most of them, our defaults are unlimited.
remove the old mmap / rlimit.datasize hack.

- adds the VMCMD_STACK flag to all the stack-creation vmcmd callers.
it is currently unused, but was added a few years ago.

- add a pair of new process size values to kinfo_proc2{}. one is the
total size of the process memory map, and the other is the total size
adjusted for unused stack space (since most processes have a lot of
this...)

- patch sh, and csh to notice RLIMIT_AS. (in some cases, the alias
RLIMIT_VMEM was already present and used if availble.)

- patch ps, top and systat to notice the new k_vm_vsize member of
kinfo_proc2{}.

- update irix, svr4, svr4_32, linux and osf1 emulations to support
this information. (freebsd could be done, but that it's best left
as part of the full-update of compat/freebsd.)


this addresses PR 7897. it also gives correct memory usage values,
which have never been entirely correct (since mmap), and have been
very incorrect since jemalloc() was enabled.

tested on i386 and sparc64, build tested on several other platforms.

thanks to many folks for feedback and testing but most espcially
chuq and yamt for critical suggestions that lead to this patch not
having a special ugliness i wasn't happy with anyway :-)
 1.81 28-Dec-2008  christos branches: 1.81.2;
tdev is unsigned
 1.80 28-Dec-2008  christos cast dev_t's to int32_t because XXX: sysctl can't change size. This should
be not a problem since tty's live in the low part of the dev range.
 1.79 29-Nov-2008  cegger check error case for kvm_getlwps or SIGSEGV occurs due to dereferecing a NULL pointer.
return NULL if there are no threads or proceed further through all loops.
Fixes PR 40004. Ok rmind@
 1.78 28-Apr-2008  martin branches: 1.78.6;
Remove clause 3 and 4 from TNF licenses
 1.77 05-Feb-2008  elad branches: 1.77.4;
PR/37962: Andrew Doran: libkvm is busted due to kauth_cred redefinition

Sync structure with kernel version.
 1.76 15-Jan-2008  ad Handle reading from raw disk devices.
 1.75 22-Dec-2007  yamt sync with kernel.
 1.74 06-Nov-2007  ad Catch up with scheduling changes in the kernel.
 1.73 09-Jul-2007  ad branches: 1.73.4;
'true' is a C99 keyword.
 1.72 07-Jul-2007  christos treat ESRCH as a soft error. From Anon Ymous
 1.71 06-Jul-2007  christos - Fix kvm_getlwps not to spit errors if we lose the race:
- if the process does not exist anymore, return NULL
- if the process has created more lwps retry
XXX[1]: We should fix sysctl_kern_lwp() to return the number of lwps it
needs in oldlenp when ENOMEM. The we can avoid calling sysctl
twice (by starting let's say with always 1 lwp, or 10).
XXX[2]: We should fix kvm_getlwps to never spit errors.
- Silence new lint warnings
 1.70 17-May-2007  christos fix for yamt-idlelwp
 1.69 01-May-2007  dsl Set kp2p->p_ru = 0 in the kproc2 structure.
It was only ever non-zero for zombies, and now doesn't exist.
The 'pstats' field has been valid for zombies for a while (it isn't in
the uarea any more).
Fixes part of build breakage.
 1.68 24-Feb-2007  christos Revert the kauth_impl.h change. Elad is going to maintain this. Asked by core@
 1.67 18-Feb-2007  dsl Update only user code that uses the types of the e_[pu]cred members
of struct kinfo_proc.
 1.66 09-Feb-2007  ad Sync with kernel changes introduced by merging the newlock2 branch.
 1.65 06-Feb-2007  elad PR/35506: Chuck Silvers: ps doesn't work on crash dumps, libkvm doesn't
know about kauth

Implemented _kvm_convertcred() to handle copying kauth_cred_t to userspace
and converting it to the appropriate 'struct eproc' members ('pcred' and
'ucred' respectively).

Okay mlelstv@.
 1.64 28-Jan-2007  chs fill in p_stat for crashdumps like the kernel does for the sysctl.
 1.63 31-Dec-2006  yamt kvm_getproc2: retry on ENOMEM.
it happens when the number of processes are changed in the mean time.
 1.62 11-May-2006  yamt branches: 1.62.4;
#include a necessary header directly, rather than via user.h.
 1.61 16-Feb-2006  christos 1. Eliminate some unnecessary to kvm_{m,re}alloc.
2. Don't malloc/free procbase/procbase2/lwpbase continuously. Keep track
of the size, and only do it if necessary.
3. Write a macro to malloc/realloc and set the size of members so that it
is done correctly. Previous open coded version in kvm_file.c always
set the length, which is incorrect.
4. Remove bogus check against INT_MAX.
5. use NULL to initialize pointers instead of 0.
 1.60 30-Jul-2005  yamt as swap is now optional, ENXIO on /dev/drum is normal.
 1.59 11-May-2005  jmc Fix fallout from vm_anon changes
 1.58 12-May-2004  toshii Fix typos.
 1.57 19-Feb-2004  atatat Use new PTRTOUINT64() macro instead of local PTRTOINT64() macro.
 1.56 17-Nov-2003  christos zero out nl, from Todd Miller. thanks!
 1.55 29-Sep-2003  wiz available, not avaliable. From miod@openbsd.
 1.54 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.53 28-Mar-2003  christos remove scanning of deadproc, since zombproc should contain all the processes
in deadproc according to the comment in kern_proc.c. deadproc is not a
struct proclist anymore, so it would require more work to scan anyway, and
this is unnecessary.
 1.52 20-Mar-2003  ross fix LP64 and other warnings
 1.51 19-Mar-2003  dsl Alternative pid/proc allocater, removes all searches associated with pid
lookup and allocation, and any dependency on NPROC or MAXUSERS.
NO_PID changed to -1 (and renamed NO_PGID) to remove artificial limit
on PID_MAX.
As discussed on tech-kern.
 1.50 01-Mar-2003  atatat Add p_svuid and p_svgid to kinfo_proc2. Populate them in the kernel
and in libkvm. Then teach ps how to show them to you.

Also, teach ps how to show the names for all the uids, the rest of the
group numbers, and the "group access list".
 1.49 26-Feb-2003  enami Use _kvm_freeprocs() rather than free() so that kvm_close() won't
free already free'ed region.
 1.48 26-Feb-2003  enami Cosmetic changes.
 1.47 02-Feb-2003  christos delint (unsigned long long) -> (unsigned long) casts.
 1.46 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.45 24-Mar-2001  jdolecek branches: 1.45.2;
kvm_doargv2(): make sure the string ends with '\0'; sysctl() might not
properly end it if the data would be longer than the supplied
buffer

This fixes lib/11467 by SAITOH Masanobu and lib/12389, maybe also
lib/12439.
 1.44 24-Mar-2001  jdolecek Minor fix to kvm_doargv2() - if the kd->argv is reallocated, reinitialize
'ap' too. This doesn't seem to have any effect either way; seems like the
condition is never met?
 1.43 22-Dec-2000  jdolecek adapt to latest struct proc, struct sigacts, struct sigctx changes
 1.42 05-Oct-2000  enami Make this file compiles on alpha.
 1.41 04-Oct-2000  sommerfeld format-string audit cleanups
 1.40 16-Jul-2000  christos revert part of previous; u_long -> uintptr_t now that uintptr_t is u_long.
 1.39 16-Jul-2000  christos de-lint. Most important problem was the cast from pointer to uintptr_t to
u_int64_t; changed the uintptr_t to u_long.
 1.38 29-Jun-2000  mrg <vm/vm.h> -> <uvm/uvm_extern.h>
 1.37 26-Jun-2000  mrg remove redundant vm includes
 1.36 04-Jun-2000  tron branches: 1.36.2;
Use "NULL" instead of "0" in pointer assignments and comparisons.
 1.35 27-May-2000  thorpej branches: 1.35.2;
p_schedflags doesn't exist anymore; just set it to zero for now,
although we'll be able to get the correct info through kmem
groveling later.
 1.34 26-May-2000  simonb Add kvm interface to the new sysctls:
kvm_getproc2() -> sysctl(KERN_PROC2)
kvm_getargv2() -> sysctl(KERN_PROC_ARGS, KERN_PROC_ARGV)
kvm_getenvv2() -> sysctl(KERN_PROC_ARGS, KERN_PROC_ENV)
Add new KVM_NO_FILES flag to kvm_open*() - set up enough state to
use the above calls without having to open any kernel files.

XXX: kvm_getprocs.3 and kvm_open.3 to be updated soon.
 1.33 15-Apr-2000  simonb Fill in e_sid when building the eproc from a crash dump.
 1.32 15-Jan-2000  chs in kvm_getprocs(), check for error from kvm_deadprocs().
 1.31 02-Jul-1999  simonb More trailing white space.
 1.30 24-Mar-1999  mrg branches: 1.30.2;
completely remove Mach VM support. all that is left is the all the
header files as UVM still uses (most of) these.
 1.29 25-Jan-1999  mrg catch up with the UVM amap changes.. tested by nathanw@mit.edu, thanks.
 1.28 27-Sep-1998  christos Remove lint
 1.27 09-Sep-1998  thorpej Adjust for the reaper process.

XXX Would really like to use proclists[] here, but not right now.
 1.26 15-Aug-1998  mycroft Assign my copyrights to TNF.
 1.25 10-Aug-1998  perry bzero->memset, bcopy->memcpy, bcmp->memcmp
 1.24 30-Jun-1998  thorpej Use pread(2) and pwrite(2) rather than lseek(2)/{read,write}(2).
 1.23 12-Feb-1998  chs add UVM support.
 1.22 11-Feb-1998  mrg while it is still kinda broken, at least let it compile -DUVM...
 1.21 03-Feb-1998  perry remove obsolete register declarations
 1.20 15-Aug-1997  drochner Fix compiler warnings.
 1.19 15-Aug-1997  mikel use <sys/cdefs.h> __RCSID() macro
 1.18 12-Aug-1997  gwr Instead of: USRSTACK, VM_MIN_ADDRESS, VM_MAXUSER_ADDRESS
Use these: kd->usrstack, kd->min_uva, kd->max_uva
 1.17 20-Jun-1997  mikel fix some printf() formats
 1.16 18-Mar-1996  thorpej RCS id police.
 1.15 04-Jul-1995  cgd slight type cleanup. add some prototypes for internal functions,
some 'const' poisoning, some lvalue lossage.
 1.14 25-May-1995  mycroft Fix up the last argv pointer correctly when terminating early.
 1.13 18-May-1995  mycroft Fix one more reallocing bug.
 1.12 18-May-1995  mycroft Fix up another pointer if we realloc the argument list.
 1.11 16-May-1995  mycroft Update copyright.
 1.10 16-May-1995  mycroft Use the new ps_strings format. Find the arguments using their
addresses in the argv array, rather than guessing based on the location
of NULs.
 1.9 12-Jan-1995  pk The sparc port no longer needs special casing.
 1.8 09-Jan-1995  mycroft Eliminate _kvm_uvatop(), in favor of using the machine-independent VM structures.
 1.7 19-Oct-1994  cgd fix type of variables, add headers, protos, where necessary.
 1.6 18-Sep-1994  mycroft Move the swap page buffer into struct __kvm. Cache the page size during
kvm_open(). Fix an existing memory leak.
 1.5 18-Sep-1994  deraadt Don't use NBPG/PGOFSET/PGSHIFT. Use getpagesize() and calculate them.
 1.4 30-Aug-1994  mycroft Update to match include files.
 1.3 13-Aug-1994  mycroft Don't return garbage if there are no argument and/or environment strings.
 1.2 23-May-1994  mycroft branches: 1.2.2;
Deal with shadow objects correctly.
 1.1 09-May-1994  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 09-May-1994  cgd new libkvm
 1.2.2.1 13-Aug-1994  mycroft update from trunk
 1.30.2.2 08-Oct-2000  he Pull up revision 1.42 (via patch, requested by he):
Fix compilation problem after format string audit fixes.
 1.30.2.1 04-Oct-2000  he Pull up revision 1.41 (via patch, requested by sommerfeld):
Format string audit.
 1.35.2.1 23-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.36.2.1 30-Mar-2001  he Pull up revision 1.45 (requested by jdolecek):
Properly '\0'-terminate data from sysctl() which might not end
properly if data would be longer than requested. Fixes PR#11467,
PR#12389 and possibly PR#12439.
 1.45.2.5 09-May-2002  nathanw Fill in new kinfo_proc2 flags from core.
 1.45.2.4 09-May-2002  nathanw Use kvm_read() to get l.l_wmesg from a core file.
 1.45.2.3 23-Apr-2002  nathanw Freeing the kinfo_lwp structure is centralized.
 1.45.2.2 23-Apr-2002  nathanw Make libkvm able to cope with a LWPified kernel.

Add a kvm_getlwps() function to retrieve the LWPs of a specific process.
 1.45.2.1 24-Mar-2001  nathanw file kvm_proc.c was added on branch nathanw_sa on 2002-04-23 20:10:20 +0000
 1.62.4.2 16-Feb-2007  riz Pull up following revision(s) (requested by chs in ticket #421):
lib/libkvm/kvm_proc.c: revision 1.64
fill in p_stat for crashdumps like the kernel does for the sysctl.
 1.62.4.1 11-Feb-2007  tron Pull up following revision(s) (requested by elad in ticket #415):
lib/libkvm/kvm_proc.c: revision 1.65
PR/35506: Chuck Silvers: ps doesn't work on crash dumps, libkvm doesn't
know about kauth
Implemented _kvm_convertcred() to handle copying kauth_cred_t to userspace
and converting it to the appropriate 'struct eproc' members ('pcred' and
'ucred' respectively).
Okay mlelstv@.
 1.73.4.3 23-Mar-2008  matt sync with HEAD
 1.73.4.2 09-Jan-2008  matt sync with HEAD
 1.73.4.1 06-Nov-2007  matt sync with HEAD
 1.77.4.1 18-May-2008  yamt sync with head.
 1.78.6.2 01-Apr-2009  snj Pull up following revision(s) (requested by mrg in ticket #622):
bin/csh/csh.1: revision 1.46
bin/csh/func.c: revision 1.37
bin/ps/print.c: revision 1.111
bin/ps/ps.c: revision 1.74
bin/sh/miscbltin.c: revision 1.38
bin/sh/sh.1: revision 1.92 via patch
external/bsd/top/dist/machine/m_netbsd.c: revision 1.7
lib/libkvm/kvm_proc.c: revision 1.82
sys/arch/mips/mips/cpu_exec.c: revision 1.55
sys/compat/darwin/darwin_exec.c: revision 1.57
sys/compat/ibcs2/ibcs2_exec.c: revision 1.73
sys/compat/irix/irix_resource.c: revision 1.15
sys/compat/linux/arch/amd64/linux_exec_machdep.c: revision 1.16
sys/compat/linux/arch/i386/linux_exec_machdep.c: revision 1.12
sys/compat/linux/common/linux_limit.h: revision 1.5
sys/compat/osf1/osf1_resource.c: revision 1.14
sys/compat/svr4/svr4_resource.c: revision 1.18
sys/compat/svr4_32/svr4_32_resource.c: revision 1.17
sys/kern/exec_subr.c: revision 1.62
sys/kern/init_sysctl.c: revision 1.160
sys/kern/kern_exec.c: revision 1.288
sys/kern/kern_resource.c: revision 1.151
sys/sys/param.h: patch
sys/sys/resource.h: revision 1.31
sys/sys/sysctl.h: revision 1.184
sys/uvm/uvm_extern.h: revision 1.153
sys/uvm/uvm_glue.c: revision 1.136
sys/uvm/uvm_mmap.c: revision 1.128
usr.bin/systat/ps.c: revision 1.32
- - add new RLIMIT_AS (aka RLIMIT_VMEM) resource that limits the total
address space available to processes. this limit exists in most other
modern unix variants, and like most of them, our defaults are unlimited.
remove the old mmap / rlimit.datasize hack.
- - adds the VMCMD_STACK flag to all the stack-creation vmcmd callers.
it is currently unused, but was added a few years ago.
- - add a pair of new process size values to kinfo_proc2{}. one is the
total size of the process memory map, and the other is the total size
adjusted for unused stack space (since most processes have a lot of
this...)
- - patch sh, and csh to notice RLIMIT_AS. (in some cases, the alias
RLIMIT_VMEM was already present and used if availble.)
- - patch ps, top and systat to notice the new k_vm_vsize member of
kinfo_proc2{}.
- - update irix, svr4, svr4_32, linux and osf1 emulations to support
this information. (freebsd could be done, but that it's best left
as part of the full-update of compat/freebsd.)
this addresses PR 7897. it also gives correct memory usage values,
which have never been entirely correct (since mmap), and have been
very incorrect since jemalloc() was enabled.
tested on i386 and sparc64, build tested on several other platforms.
thanks to many folks for feedback and testing but most espcially
chuq and yamt for critical suggestions that lead to this patch not
having a special ugliness i wasn't happy with anyway :-)
 1.78.6.1 29-Nov-2008  bouyer Pull up following revision(s) (requested by cegger in ticket #146):
lib/libkvm/kvm_proc.c: revision 1.79
check error case for kvm_getlwps or SIGSEGV occurs due to dereferecing a
NULL pointer.
return NULL if there are no threads or proceed further through all loops.
Fixes PR 40004. Ok rmind@
 1.81.2.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.88.8.1 12-Jun-2012  riz Pull up following revision(s) (requested by martin in ticket #310):
sys/kern/kern_proc.c: revision 1.184
lib/libkvm/kvm_proc.c: revision 1.89
Measure kinfo_proc2::p_vm_vsize in pages, as it was always documented.
This value seems to never have been used anywhere.
This makes it consistent with it's cousin p_vm_msize (which is in pages as
well and has several uses).
 1.88.6.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.88.6.1 30-Oct-2012  yamt sync with head
 1.89.2.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.92.16.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.99.2.1 02-Aug-2025  perseant Sync with HEAD
 1.9 23-Jan-2016  dholland Update synopses to match u_int/u_long/etc. changes. Do not bump date as
it's not a substantive change.
 1.8 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.7 16-Apr-2003  wiz Use
.In header.h
instead of
.Fd #include \*[Lt]header.h\*[Gt]
Much easier to read and write, and supported by groff for ages.
Okayed by ross.
 1.6 01-Oct-2002  wiz New sentence, new line. From Robert Elz.
 1.5 07-Feb-2002  ross branches: 1.5.2;
Generate <>& symbolically.
 1.4 02-Jul-1999  simonb More trailing white space.
 1.3 05-Feb-1998  perry add LIBRARY section to man page
 1.2 18-Mar-1996  thorpej RCS id police.
 1.1 09-May-1994  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 09-May-1994  cgd new libkvm
 1.5.2.2 19-Dec-2002  thorpej Sync with HEAD.
 1.5.2.1 07-Feb-2002  thorpej file kvm_read.3 was added on branch nathanw_sa on 2002-12-19 02:26:22 +0000
 1.4 12-Oct-2024  skrll Remove unnecessary cast.
 1.3 23-Aug-2023  rin branches: 1.3.2;
libkvm: whitespace
 1.2 10-Jan-2022  christos Get rid of usrstack/USRSTACK. Document that the old version of getargv is
broken because of ASLR.
 1.1 19-Sep-2014  matt New files for Userland support of UCB RISC-V (both 32-bit and 64-bit)
 1.3.2.1 02-Aug-2025  perseant Sync with HEAD
 1.10 10-Jan-2022  christos Get rid of usrstack/USRSTACK. Document that the old version of getargv is
broken because of ASLR.
 1.9 19-Feb-2014  dsl Remove the #include <sys/user.h> from all of libkvm.
sys/user.h is a stub that just #includes sys/pcb.h.
There are no 'struct pcb' anywhere in here, so I'm extremely doubtful
any of the builds will fail.
OTOH it might be relying on a header that pcb.h includes.
In any case i386 and amd64 build.
 1.8 20-Sep-2010  jym branches: 1.8.6; 1.8.12;
Change kvm_pa2off() and kvm_kvatop() prototypes (private to kvm(3)):

-int _kvm_kvatop(kvm_t *, u_long, u_long *);
-off_t _kvm_pa2off(kvm_t *, u_long);
+int _kvm_kvatop(kvm_t *, vaddr_t, paddr_t *);
+off_t _kvm_pa2off(kvm_t *, paddr_t);

Basically, use vaddr_t for VA and paddr_t for PA. In addition, for variables
representing addresses, use paddr_t or vaddr_t, depending on the context.

For most arches, vaddr_t and paddr_t are equivalent to unsigned long. However,
the change was needed for exotic situations, like i386 PAE, were unsigned long
is not suitable for PA which are 64 bits long. As this required a complete
change of the function prototypes, all arches had to be adapted accordingly.

Core files from before this commit should still work with the new code; I did
not see any direct dependency between core's structure and kvatop/pa2off.

The change was compile tested for all arches, as it impacts all of them.

See also:

http://mail-index.netbsd.org/current-users/2010/09/07/msg014249.html
 1.7 19-Sep-2010  jym Ansify and KNF all functions within kvm(3). No objection on current-users@.

Used as ground for u_long => vaddr_t/paddr_t replacements in kvm(3)
private functions.

Compile tested for all arches. See also:

http://mail-index.netbsd.org/current-users/2010/09/07/msg014249.html
 1.6 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.5 10-Jul-2002  scw Minor correction: s/i386/SH3/
 1.4 05-Aug-2001  matt branches: 1.4.2;
Don't include <machine/pmap.h> and <machine/vmparam.h> if _KERNEL isn't
defined. Include them explicitly in the few kvm_arch.c that need them.
 1.3 29-Jun-2000  mrg <vm/vm.h> -> <uvm/uvm_extern.h>
 1.2 26-Jun-2000  mrg remove redundant vm includes
 1.1 06-Jun-2000  msaitoh branches: 1.1.4;
libkvm for sh3
 1.1.4.2 23-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.1.4.1 06-Jun-2000  minoura file kvm_sh3.c was added on branch minoura-xpg4dl on 2000-06-23 16:16:48 +0000
 1.4.2.2 19-Dec-2002  thorpej Sync with HEAD.
 1.4.2.1 05-Aug-2001  thorpej file kvm_sh3.c was added on branch nathanw_sa on 2002-12-19 02:26:23 +0000
 1.8.12.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.8.6.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.3 08-Apr-2007  scw Remove support for NetBSD/{,evb}sh5.
 1.2 07-Aug-2003  agc branches: 1.2.16; 1.2.18;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.1 10-Jul-2002  scw branches: 1.1.2;
SH-5 kvm glue, based on sh3 version.
 1.1.2.2 19-Dec-2002  thorpej Sync with HEAD.
 1.1.2.1 10-Jul-2002  thorpej file kvm_sh5.c was added on branch nathanw_sa on 2002-12-19 02:26:24 +0000
 1.2.18.1 03-Sep-2007  wrstuden Sync w/ NetBSD-4-RC_1
 1.2.16.1 19-Jul-2007  liamjfoy Remove evbsh5 files. Bye!

ok core@
 1.36 10-Jan-2022  christos Get rid of usrstack/USRSTACK. Document that the old version of getargv is
broken because of ASLR.
 1.35 31-Oct-2015  nakayama Use PRIxPADDR instead of type casting.
 1.34 07-Oct-2015  martin Fix the -m32 compat build for sparc64 after recent sparc/include/types.h
changes. XXX I suspect this variant has not been tested in real life.
 1.33 19-Feb-2014  dsl Remove the #include <sys/user.h> from all of libkvm.
sys/user.h is a stub that just #includes sys/pcb.h.
There are no 'struct pcb' anywhere in here, so I'm extremely doubtful
any of the builds will fail.
OTOH it might be relying on a header that pcb.h includes.
In any case i386 and amd64 build.
 1.32 20-Sep-2010  jym branches: 1.32.6; 1.32.12;
Change kvm_pa2off() and kvm_kvatop() prototypes (private to kvm(3)):

-int _kvm_kvatop(kvm_t *, u_long, u_long *);
-off_t _kvm_pa2off(kvm_t *, u_long);
+int _kvm_kvatop(kvm_t *, vaddr_t, paddr_t *);
+off_t _kvm_pa2off(kvm_t *, paddr_t);

Basically, use vaddr_t for VA and paddr_t for PA. In addition, for variables
representing addresses, use paddr_t or vaddr_t, depending on the context.

For most arches, vaddr_t and paddr_t are equivalent to unsigned long. However,
the change was needed for exotic situations, like i386 PAE, were unsigned long
is not suitable for PA which are 64 bits long. As this required a complete
change of the function prototypes, all arches had to be adapted accordingly.

Core files from before this commit should still work with the new code; I did
not see any direct dependency between core's structure and kvatop/pa2off.

The change was compile tested for all arches, as it impacts all of them.

See also:

http://mail-index.netbsd.org/current-users/2010/09/07/msg014249.html
 1.31 19-Sep-2010  jym Ansify and KNF all functions within kvm(3). No objection on current-users@.

Used as ground for u_long => vaddr_t/paddr_t replacements in kvm(3)
private functions.

Compile tested for all arches. See also:

http://mail-index.netbsd.org/current-users/2010/09/07/msg014249.html
 1.30 25-Oct-2008  mrg use <sparc/pmap.h> and <sparc/kcore.h> so this builds properly with
a 64 bit "cc -m32".
 1.29 15-Jan-2008  ad Handle reading from raw disk devices.
 1.28 07-Aug-2003  agc branches: 1.28.22;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.27 16-May-2003  wiz Consistently spell "crash dump" as two separate words. From jmc@openbsd.
 1.26 22-Sep-2001  mrg branches: 1.26.2;
undefine VA_VPG and VA_OFF before defining them.
 1.25 05-Aug-2001  matt Don't include <machine/pmap.h> and <machine/vmparam.h> if _KERNEL isn't
defined. Include them explicitly in the few kvm_arch.c that need them.
 1.24 04-Oct-2000  sommerfeld Format size mismatch
 1.23 29-Jun-2000  mrg <vm/vm.h> -> <uvm/uvm_extern.h>
 1.22 26-Jun-2000  mrg remove redundant vm includes
 1.21 02-Jul-1999  simonb More trailing white space.
 1.20 01-Feb-1999  mrg branches: 1.20.2;
uh...make this build on the sparc again...or something. i've had
to pull a few #define's from the sparc64 include's into this file,
renamed so that they don't break the sparc64. this is really hacky,
and should be fixed somehow. if the sparc is going to know about
32bit sparc64 kernels, the information necessary to get this needs
to exist somewhere for it to grab, not for duplication :(
 1.19 30-Jan-1999  eeh Need to be able to handle sparc64 executables as well.
 1.18 30-Jun-1998  thorpej Use pread(2) and pwrite(2) rather than lseek(2)/{read,write}(2).
 1.17 15-Mar-1998  pk No need for autoconf.h
 1.16 03-Feb-1998  perry remove obsolete register declarations
 1.15 10-Oct-1997  mrg clean WARNS on the sparc.
 1.14 20-Sep-1997  pk The `cpu_kcore' header has changed allowing libkvm to be independent of
the kernel's link address (KERNBASE).
 1.13 15-Aug-1997  mikel use <sys/cdefs.h> __RCSID() macro
 1.12 12-Aug-1997  gwr Add _kvm_mdopen()
 1.11 02-Apr-1997  pk Off by 1 in PMEG comparison.
 1.10 09-Nov-1996  pk Handle crash dumps new-style.
 1.9 01-Apr-1996  cgd sync with libkvm.old sources (change committed by pk):
>Catch up with system PMAP.
 1.8 18-Mar-1996  thorpej RCS id police.
 1.7 05-Jul-1995  pk Deal with crash dumps again.
 1.6 13-Apr-1995  pk Disable "dead kernel" stuff until we have something new.
 1.5 09-Jan-1995  mycroft Eliminate _kvm_uvatop(), in favor of using the machine-independent VM structures.
 1.4 02-Nov-1994  deraadt make this work (with a horrible hack for determining the cputyp)
 1.3 18-Sep-1994  deraadt should work for sun4 and sun4c
 1.2 10-Jun-1994  pk Changes in pmap structures.
 1.1 09-May-1994  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 09-May-1994  cgd new libkvm
 1.20.2.1 06-Oct-2000  he Pull up revision 1.24 (requested by sommerfeld):
Fix mismatched int vs. long format error.
 1.26.2.2 22-Sep-2001  mrg undefine VA_VPG and VA_OFF before defining them.
 1.26.2.1 22-Sep-2001  mrg file kvm_sparc.c was added on branch nathanw_sa on 2001-09-22 00:53:02 +0000
 1.28.22.1 23-Mar-2008  matt sync with HEAD
 1.32.12.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.32.6.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.19 23-Aug-2023  rin libkvm: whitespace
 1.18 10-Jan-2022  christos Get rid of usrstack/USRSTACK. Document that the old version of getargv is
broken because of ASLR.
 1.17 21-Feb-2014  palle sun4v: Rename TLB_ defines to SUN4U_TLB_ so entries created using TSB_DATA() are properly setup for sun4u and sun4v. Relocate the cputyp variable from autoconf.c to locore.s and make it const in param.h so optimized code can be generated. Parts from OpenBSD. Optimization suggested by nakayama@. OK martin@, mrg@, nakayama@
 1.16 19-Feb-2014  dsl Remove the #include <sys/user.h> from all of libkvm.
sys/user.h is a stub that just #includes sys/pcb.h.
There are no 'struct pcb' anywhere in here, so I'm extremely doubtful
any of the builds will fail.
OTOH it might be relying on a header that pcb.h includes.
In any case i386 and amd64 build.
 1.15 20-Sep-2010  jym branches: 1.15.6; 1.15.12;
Change kvm_pa2off() and kvm_kvatop() prototypes (private to kvm(3)):

-int _kvm_kvatop(kvm_t *, u_long, u_long *);
-off_t _kvm_pa2off(kvm_t *, u_long);
+int _kvm_kvatop(kvm_t *, vaddr_t, paddr_t *);
+off_t _kvm_pa2off(kvm_t *, paddr_t);

Basically, use vaddr_t for VA and paddr_t for PA. In addition, for variables
representing addresses, use paddr_t or vaddr_t, depending on the context.

For most arches, vaddr_t and paddr_t are equivalent to unsigned long. However,
the change was needed for exotic situations, like i386 PAE, were unsigned long
is not suitable for PA which are 64 bits long. As this required a complete
change of the function prototypes, all arches had to be adapted accordingly.

Core files from before this commit should still work with the new code; I did
not see any direct dependency between core's structure and kvatop/pa2off.

The change was compile tested for all arches, as it impacts all of them.

See also:

http://mail-index.netbsd.org/current-users/2010/09/07/msg014249.html
 1.14 19-Sep-2010  jym Ansify and KNF all functions within kvm(3). No objection on current-users@.

Used as ground for u_long => vaddr_t/paddr_t replacements in kvm(3)
private functions.

Compile tested for all arches. See also:

http://mail-index.netbsd.org/current-users/2010/09/07/msg014249.html
 1.13 18-Jan-2008  martin Use the new information about per-cpu mappings. Gdb now can examine
the interrupt stack.
 1.12 15-Jan-2008  ad Handle reading from raw disk devices.
 1.11 05-Nov-2007  martin Use the new sparc64 kcore cpu segment extensions to properly map VA/PAs
on kernels with more then 4 MB text/rodata segment.
 1.10 07-Aug-2003  agc branches: 1.10.16; 1.10.18; 1.10.22;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.9 16-May-2003  wiz Consistently spell "crash dump" as two separate words. From jmc@openbsd.
 1.8 03-Apr-2003  martin #include <machine/vmparam.h> for PAGE_SIZE
 1.7 05-Aug-2001  matt branches: 1.7.2;
Don't include <machine/pmap.h> and <machine/vmparam.h> if _KERNEL isn't
defined. Include them explicitly in the few kvm_arch.c that need them.
 1.6 10-Oct-2000  he Use %lx instead of %x with _kvm_err when arg is u_long.
 1.5 01-Aug-2000  eeh Handle kernel cores properly.
 1.4 29-Jun-2000  mrg <vm/vm.h> -> <uvm/uvm_extern.h>
 1.3 26-Jun-2000  mrg remove redundant vm includes
 1.2 02-Jul-1999  simonb branches: 1.2.8;
More trailing white space.
 1.1 25-Nov-1998  eeh branches: 1.1.2;
Add enough of a kvm_sparc64.c to get the kvm library to build.
 1.1.2.1 27-Oct-2000  he Pull up revision 1.6 (requested by he):
Use %lx to format u_long parameter.
 1.2.8.2 18-Oct-2000  tv Pullup 1.6 [he]:
Use %lx instead of %x with _kvm_err when arg is u_long.
 1.2.8.1 07-Aug-2000  mrg pullup 1.5 (approved by thorpej):
>Handle kernel cores properly.
 1.7.2.2 05-Aug-2001  matt Don't include <machine/pmap.h> and <machine/vmparam.h> if _KERNEL isn't
defined. Include them explicitly in the few kvm_arch.c that need them.
 1.7.2.1 05-Aug-2001  matt file kvm_sparc64.c was added on branch nathanw_sa on 2001-08-05 03:33:16 +0000
 1.10.22.2 23-Mar-2008  matt sync with HEAD
 1.10.22.1 06-Nov-2007  matt sync with HEAD
 1.10.18.2 18-Jan-2008  skrll Apply martin's changes to:

Use the new information about per-cpu mappings. Gdb now can examine
the interrupt stack.
 1.10.18.1 30-Dec-2007  skrll Apply changes from ticket #983.

Modified Files:
src/sys/arch/sparc64/include: kcore.h
src/sys/arch/sparc64/sparc64: pmap.c

Log Message:
Extend the sparc64 cpu kcore segment so that it records all kernel mappings
done via locked 4 MB pages. The old format could only record physically
continous kernel text mappings.
For compatibility reasons, just extend the structure and fill in all the
old fields as well.

Modified Files:
src/lib/libkvm: kvm_sparc64.c

Log Message:
Use the new sparc64 kcore cpu segment extensions to properly map VA/PAs
on kernels with more then 4 MB text/rodata segment.
 1.10.16.2 16-Sep-2008  bouyer Sync with the following revisions (requested by skrll in ticket #1196):
gnu/dist/gdb removed
gnu/usr.bin/gdb53 removed
distrib/cats/instkernel/Makefile 1.14.6.1
gnu/dist/gdb6/bfd/config.bfd 1.3.6.1
gnu/dist/gdb6/bfd/elfxx-sparc.c 1.1.1.2.6.1
gnu/dist/gdb6/bfd/elfxx-sparc.h 1.1.1.2.6.1
gnu/dist/gdb6/gdb/Makefile.in 1.2.2.1.2.2
gnu/dist/gdb6/gdb/alpha-tdep.c 1.1.1.2.6.1
gnu/dist/gdb6/gdb/alpha-tdep.h 1.1.1.2.6.1
gnu/dist/gdb6/gdb/alphabsd-nat.c 1.1.1.2.6.2
gnu/dist/gdb6/gdb/alphabsd-nat.h 1.1.2.1
gnu/dist/gdb6/gdb/alphabsd-tdep.c 1.1.1.2.6.1
gnu/dist/gdb6/gdb/alphabsd-tdep.h 1.1.1.2.6.1
gnu/dist/gdb6/gdb/alphanbsd-nat.c 1.1.2.1
gnu/dist/gdb6/gdb/alphanbsd-tdep.c 1.1.1.2.6.1
gnu/dist/gdb6/gdb/amd64-nat.c 1.1.1.2.6.1
gnu/dist/gdb6/gdb/amd64bsd-nat.c 1.1.1.2.6.1
gnu/dist/gdb6/gdb/amd64nbsd-nat.c 1.1.1.2.6.3
gnu/dist/gdb6/gdb/amd64nbsd-tdep.c 1.1.1.2.6.1
gnu/dist/gdb6/gdb/arm-tdep.h 1.1.1.2.6.1
gnu/dist/gdb6/gdb/armbsd-tdep.c 1.1.2.1
gnu/dist/gdb6/gdb/armnbsd-nat.c 1.1.1.2.6.2
gnu/dist/gdb6/gdb/armnbsd-tdep.c 1.1.1.2.6.1
gnu/dist/gdb6/gdb/configure 1.1.1.2.6.1
gnu/dist/gdb6/gdb/configure.ac 1.1.1.2.6.1
gnu/dist/gdb6/gdb/i386bsd-nat.c 1.1.1.2.6.1
gnu/dist/gdb6/gdb/i386nbsd-tdep.c 1.1.1.2.6.1
gnu/dist/gdb6/gdb/m68kbsd-nat.c 1.1.1.2.6.2
gnu/dist/gdb6/gdb/mipsnbsd-nat.c 1.1.1.2.6.2
gnu/dist/gdb6/gdb/nbsd-thread.c 1.1.2.3
gnu/dist/gdb6/gdb/ppcnbsd-nat.c 1.1.1.2.6.2
gnu/dist/gdb6/gdb/ppcnbsd-tdep.c 1.3.6.1
gnu/dist/gdb6/gdb/sh-tdep.c 1.1.1.2.6.1
gnu/dist/gdb6/gdb/shnbsd-nat.c 1.1.1.2.6.3
gnu/dist/gdb6/gdb/shnbsd-tdep.c 1.1.1.2.6.4
gnu/dist/gdb6/gdb/shnbsd-tdep.h 1.1.1.2.6.1
gnu/dist/gdb6/gdb/sparc-nat.c 1.1.1.2.6.1
gnu/dist/gdb6/gdb/sparc64nbsd-nat.c 1.1.1.2.6.2
gnu/dist/gdb6/gdb/sparcnbsd-nat.c 1.1.1.2.6.2
gnu/dist/gdb6/gdb/tramp-frame.h 1.1.1.2.6.1
gnu/dist/gdb6/gdb/vaxbsd-nat.c 1.1.1.2.6.2
gnu/dist/gdb6/gdb/config/alpha/nbsd.mh 1.1.1.2.6.1
gnu/dist/gdb6/gdb/config/arm/nbsd.mt 1.1.1.1.6.1
gnu/dist/gdb6/gdb/config/arm/nbsdelf.mh 1.1.1.1.6.1
gnu/dist/gdb6/gdb/config/i386/nbsd64.mh 1.1.1.1.6.1
gnu/dist/gdb6/gdb/config/m68k/nbsdelf.mh 1.1.1.1.6.1
gnu/dist/gdb6/gdb/config/mips/nbsd.mh 1.1.1.1.6.1
gnu/dist/gdb6/gdb/config/powerpc/nbsd.mh 1.1.1.2.6.1
gnu/dist/gdb6/gdb/config/sh/nbsd.mh 1.1.1.1.6.2
gnu/dist/gdb6/gdb/config/sh/tm-nbsd.h 1.1.1.1.6.1
gnu/dist/gdb6/gdb/config/sparc/nbsd64.mh 1.1.1.1.6.1
gnu/dist/gdb6/gdb/config/sparc/nbsdelf.mh 1.1.1.1.6.1
gnu/dist/gdb6/gdb/config/vax/nbsdelf.mh 1.1.1.1.6.1
gnu/dist/gdb6/opcodes/configure 1.1.1.2.6.1
gnu/dist/gdb6/opcodes/configure.in 1.1.1.2.6.1
gnu/usr.bin/Makefile 1.126.4.1
gnu/usr.bin/gdb6/arch/alpha/config.h 1.3.4.1
gnu/usr.bin/gdb6/arch/alpha/defs.mk 1.2.6.1
gnu/usr.bin/gdb6/arch/alpha/init.c 1.2.6.1
gnu/usr.bin/gdb6/arch/alpha/nm.h 1.2.6.1
gnu/usr.bin/gdb6/arch/arm/defs.mk 1.2.6.2
gnu/usr.bin/gdb6/arch/arm/init.c 1.1.6.1
gnu/usr.bin/gdb6/arch/armeb/config.h 1.1.6.2
gnu/usr.bin/gdb6/arch/armeb/defs.mk 1.1.6.3
gnu/usr.bin/gdb6/arch/armeb/init.c 1.1.6.2
gnu/usr.bin/gdb6/arch/armeb/tm.h 1.1.6.2
gnu/usr.bin/gdb6/arch/armeb/version.c 1.1.6.2
gnu/usr.bin/gdb6/arch/i386/defs.mk 1.4.4.1
gnu/usr.bin/gdb6/arch/i386/init.c 1.3.6.1
gnu/usr.bin/gdb6/arch/m68000/config.h 1.1.6.2
gnu/usr.bin/gdb6/arch/m68000/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/arch/m68000/init.c 1.1.6.2
gnu/usr.bin/gdb6/arch/m68000/tm.h 1.1.6.2
gnu/usr.bin/gdb6/arch/m68000/version.c 1.1.6.2
gnu/usr.bin/gdb6/arch/m68k/defs.mk 1.1.4.1
gnu/usr.bin/gdb6/arch/m68k/init.c 1.1.4.1
gnu/usr.bin/gdb6/arch/mipseb/config.h 1.3.4.1
gnu/usr.bin/gdb6/arch/mipseb/defs.mk 1.2.6.2
gnu/usr.bin/gdb6/arch/mipseb/init.c 1.2.6.2
gnu/usr.bin/gdb6/arch/mipsel/config.h 1.2.6.3
gnu/usr.bin/gdb6/arch/mipsel/defs.mk 1.2.6.3
gnu/usr.bin/gdb6/arch/mipsel/init.c 1.2.6.3
gnu/usr.bin/gdb6/arch/mipsel/tm.h 1.2.6.2
gnu/usr.bin/gdb6/arch/mipsel/version.c 1.2.6.2
gnu/usr.bin/gdb6/arch/powerpc/defs.mk 1.3.6.1
gnu/usr.bin/gdb6/arch/powerpc/init.c 1.3.6.1
gnu/usr.bin/gdb6/arch/sh3eb/config.h 1.2.2.2
gnu/usr.bin/gdb6/arch/sh3eb/defs.mk 1.2.8.3
gnu/usr.bin/gdb6/arch/sh3eb/init.c 1.1.8.3
gnu/usr.bin/gdb6/arch/sh3eb/nm.h 1.1.8.2
gnu/usr.bin/gdb6/arch/sh3eb/tm.h 1.1.8.2
gnu/usr.bin/gdb6/arch/sh3eb/version.c 1.1.8.2
gnu/usr.bin/gdb6/arch/sh3el/config.h 1.2.2.2
gnu/usr.bin/gdb6/arch/sh3el/defs.mk 1.2.8.3
gnu/usr.bin/gdb6/arch/sh3el/init.c 1.1.8.3
gnu/usr.bin/gdb6/arch/sh3el/nm.h 1.1.8.2
gnu/usr.bin/gdb6/arch/sh3el/tm.h 1.1.8.2
gnu/usr.bin/gdb6/arch/sh3el/version.c 1.1.8.2
gnu/usr.bin/gdb6/arch/sparc/defs.mk 1.2.6.1
gnu/usr.bin/gdb6/arch/sparc/init.c 1.1.6.1
gnu/usr.bin/gdb6/arch/sparc64/defs.mk 1.2.6.1
gnu/usr.bin/gdb6/arch/sparc64/init.c 1.1.6.1
gnu/usr.bin/gdb6/arch/vax/config.h 1.1.6.2
gnu/usr.bin/gdb6/arch/vax/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/arch/vax/init.c 1.1.6.2
gnu/usr.bin/gdb6/arch/vax/tm.h 1.1.6.2
gnu/usr.bin/gdb6/arch/vax/version.c 1.1.6.2
gnu/usr.bin/gdb6/arch/x86_64/defs.mk 1.2.6.1
gnu/usr.bin/gdb6/arch/x86_64/init.c 1.1.6.1
gnu/usr.bin/gdb6/bfd/arch/armeb/bfd.h 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/armeb/bfdver.h 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/armeb/config.h 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/armeb/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/m68000/bfd.h 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/m68000/bfdver.h 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/m68000/config.h 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/m68000/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/mipsel/bfd.h 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/mipsel/bfdver.h 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/mipsel/config.h 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/mipsel/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/sh3eb/bfd.h 1.1.8.3
gnu/usr.bin/gdb6/bfd/arch/sh3eb/bfdver.h 1.1.8.2
gnu/usr.bin/gdb6/bfd/arch/sh3eb/config.h 1.1.8.2
gnu/usr.bin/gdb6/bfd/arch/sh3eb/defs.mk 1.1.8.3
gnu/usr.bin/gdb6/bfd/arch/sh3el/bfd.h 1.1.8.3
gnu/usr.bin/gdb6/bfd/arch/sh3el/bfdver.h 1.1.8.2
gnu/usr.bin/gdb6/bfd/arch/sh3el/config.h 1.1.8.2
gnu/usr.bin/gdb6/bfd/arch/sh3el/defs.mk 1.1.8.3
gnu/usr.bin/gdb6/bfd/arch/vax/bfd.h 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/vax/bfdver.h 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/vax/config.h 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/vax/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/gdb/Makefile 1.5.2.1.2.2
gnu/usr.bin/gdb6/gdbtui/Makefile 1.2.6.1
gnu/usr.bin/gdb6/libiberty/arch/armeb/config.h 1.1.6.2
gnu/usr.bin/gdb6/libiberty/arch/armeb/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/libiberty/arch/m68000/config.h 1.1.6.2
gnu/usr.bin/gdb6/libiberty/arch/m68000/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/libiberty/arch/mipsel/config.h 1.1.6.2
gnu/usr.bin/gdb6/libiberty/arch/mipsel/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/libiberty/arch/sh3eb/config.h 1.1.8.2
gnu/usr.bin/gdb6/libiberty/arch/sh3eb/defs.mk 1.1.8.2
gnu/usr.bin/gdb6/libiberty/arch/sh3el/config.h 1.1.8.2
gnu/usr.bin/gdb6/libiberty/arch/sh3el/defs.mk 1.1.8.2
gnu/usr.bin/gdb6/libiberty/arch/vax/config.h 1.1.6.2
gnu/usr.bin/gdb6/libiberty/arch/vax/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/opcodes/arch/armeb/config.h 1.1.6.2
gnu/usr.bin/gdb6/opcodes/arch/armeb/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/opcodes/arch/m68000/config.h 1.1.6.2
gnu/usr.bin/gdb6/opcodes/arch/m68000/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/opcodes/arch/mipsel/config.h 1.1.6.2
gnu/usr.bin/gdb6/opcodes/arch/mipsel/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/opcodes/arch/sh3eb/config.h 1.1.8.2
gnu/usr.bin/gdb6/opcodes/arch/sh3eb/defs.mk 1.1.8.3
gnu/usr.bin/gdb6/opcodes/arch/sh3el/config.h 1.1.8.2
gnu/usr.bin/gdb6/opcodes/arch/sh3el/defs.mk 1.1.8.3
gnu/usr.bin/gdb6/opcodes/arch/vax/config.h 1.1.6.2
gnu/usr.bin/gdb6/opcodes/arch/vax/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/readline/arch/armeb/config.h 1.1.6.2
gnu/usr.bin/gdb6/readline/arch/armeb/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/readline/arch/m68000/config.h 1.1.6.2
gnu/usr.bin/gdb6/readline/arch/m68000/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/readline/arch/mipsel/config.h 1.1.6.2
gnu/usr.bin/gdb6/readline/arch/mipsel/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/readline/arch/sh3eb/config.h 1.1.8.2
gnu/usr.bin/gdb6/readline/arch/sh3eb/defs.mk 1.1.8.2
gnu/usr.bin/gdb6/readline/arch/sh3el/config.h 1.1.8.2
gnu/usr.bin/gdb6/readline/arch/sh3el/defs.mk 1.1.8.2
gnu/usr.bin/gdb6/readline/arch/vax/config.h 1.1.6.2
gnu/usr.bin/gdb6/readline/arch/vax/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/sim/arch/mipseb/cconfig.h 1.1.2.1
gnu/usr.bin/gdb6/sim/arch/mipseb/config.h 1.1.2.1
gnu/usr.bin/gdb6/sim/arch/mipseb/defs.mk 1.1.2.1
gnu/usr.bin/gdb6/sim/arch/mipsel/cconfig.h 1.1.2.1
gnu/usr.bin/gdb6/sim/arch/mipsel/config.h 1.1.2.1
gnu/usr.bin/gdb6/sim/arch/mipsel/defs.mk 1.1.2.1
lib/libkvm/kvm_sparc64.c 1.10.18.2
lib/libpthread/pthread.c 1.48.6.4
lib/libpthread/pthread_barrier.c 1.6.18.1
lib/libpthread/pthread_cond.c 1.18.12.2
lib/libpthread/pthread_debug.h 1.8.18.1
lib/libpthread/pthread_int.h 1.34.4.5
lib/libpthread/pthread_lock.c 1.14.6.1
lib/libpthread/pthread_mutex.c 1.22.4.2
lib/libpthread/pthread_run.c 1.18.12.4
lib/libpthread/pthread_rwlock.c 1.13.6.2
lib/libpthread/pthread_sa.c 1.37.6.5
lib/libpthread/pthread_sig.c 1.47.4.8
lib/libpthread/pthread_sleep.c 1.7.6.2
lib/libpthread/sem.c 1.9.6.2
lib/libpthread/arch/sh3/pthread_md.h 1.3.6.1
regress/lib/libpthread/resolv/Makefile 1.1.12.1
regress/lib/libpthread/sigrunning/Makefile 1.1.2.1
regress/lib/libpthread/sigrunning/sigrunning.c 1.1.2.1
share/mk/bsd.own.mk 1.489.4.3
sys/arch/amd64/amd64/locore.S 1.18.14.1
sys/arch/amd64/amd64/machdep.c 1.44.2.3.2.1
sys/arch/amd64/conf/kern.ldscript 1.1.70.1
sys/arch/cats/conf/Makefile.cats.inc 1.17.30.1
sys/arch/shark/conf/Makefile.shark.inc 1.6.30.1
sys/arch/sparc64/conf/kern.ldscript 1.7.26.2
sys/arch/sparc64/conf/kern32.ldscript 1.6.26.2
sys/arch/sparc64/include/kcore.h 1.4.92.2
sys/arch/sparc64/sparc64/locore.s 1.232.4.4
sys/arch/sparc64/sparc64/machdep.c 1.193.4.3
sys/arch/sparc64/sparc64/pmap.c 1.184.2.1.2.4
sys/conf/newvers.sh 1.42.26.2
sys/kern/kern_sa.c 1.87.4.11
sys/kern/kern_synch.c 1.173.4.2
sys/sys/savar.h 1.20.10.2
tools/gdb/Makefile 1.9.4.1
tools/gdb/mknative-gdb 1.1.6.1

pullup the wrstuden-fixsa CVS branch to netbsd-4:
toolchain/35540 - GDB 6 support for pthreads.
port-sparc64/37534 - ktrace firefox gives
kernel trap 30: data access expection
GDB changes:
- delete gdb53
- enable gdb6 on all architectures
- add support for amd64 crash dumps
- add support for sparc64 crash dumps
- add support for /proc pid to executable filename for all archs
- enable thread support for all architectures
- add a note section to kernels to all platforms
- support detection/unwinding of signals for most architectures.
- Fix PTHREAD_UCONTEXT_TO_REG / PTHREAD_REG_TO_UCONTEXT on sh3.
- Apply fix from binutils-current so that sparc gdb can be cross built
on a 64bit host.
SA/pthread changes:
Pre-allocate memory needed for event delivery. Eliminates dropped
interrupts under load.
Deliver intra-process signals to running threads
Eliminate some deadlock scenarios
Fix intra-process signal delivery when delivering to a thread waiting
for signals. Makes afs work again!
 1.10.16.1 01-Feb-2008  riz Pull up following revision(s) (requested by martin in ticket #983):
sys/arch/sparc64/include/kcore.h: revision 1.5
lib/libkvm/kvm_sparc64.c: revision 1.11
sys/arch/sparc64/sparc64/pmap.c: revision 1.201
Extend the sparc64 cpu kcore segment so that it records all kernel mappings
done via locked 4 MB pages. The old format could only record physically
continous kernel text mappings.
For compatibility reasons, just extend the structure and fill in all the
old fields as well.
Use the new sparc64 kcore cpu segment extensions to properly map VA/PAs
on kernels with more then 4 MB text/rodata segment.
 1.15.12.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.15.6.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.6 14-Sep-2011  christos more sys/param.h additions
 1.5 20-Sep-2010  jym Change kvm_pa2off() and kvm_kvatop() prototypes (private to kvm(3)):

-int _kvm_kvatop(kvm_t *, u_long, u_long *);
-off_t _kvm_pa2off(kvm_t *, u_long);
+int _kvm_kvatop(kvm_t *, vaddr_t, paddr_t *);
+off_t _kvm_pa2off(kvm_t *, paddr_t);

Basically, use vaddr_t for VA and paddr_t for PA. In addition, for variables
representing addresses, use paddr_t or vaddr_t, depending on the context.

For most arches, vaddr_t and paddr_t are equivalent to unsigned long. However,
the change was needed for exotic situations, like i386 PAE, were unsigned long
is not suitable for PA which are 64 bits long. As this required a complete
change of the function prototypes, all arches had to be adapted accordingly.

Core files from before this commit should still work with the new code; I did
not see any direct dependency between core's structure and kvatop/pa2off.

The change was compile tested for all arches, as it impacts all of them.

See also:

http://mail-index.netbsd.org/current-users/2010/09/07/msg014249.html
 1.4 19-Sep-2010  jym Ansify and KNF all functions within kvm(3). No objection on current-users@.

Used as ground for u_long => vaddr_t/paddr_t replacements in kvm(3)
private functions.

Compile tested for all arches. See also:

http://mail-index.netbsd.org/current-users/2010/09/07/msg014249.html
 1.3 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.2 16-May-2003  wiz Consistently spell "crash dump" as two separate words. From jmc@openbsd.
 1.1 21-May-2001  fredette branches: 1.1.2;
Added support for sun2 kernel cores.
 1.1.2.2 21-May-2001  fredette Added support for sun2 kernel cores.
 1.1.2.1 21-May-2001  fredette file kvm_sun2.c was added on branch nathanw_sa on 2001-05-21 14:56:31 +0000
 1.15 14-Sep-2011  christos more sys/param.h additions
 1.14 20-Sep-2010  jym Change kvm_pa2off() and kvm_kvatop() prototypes (private to kvm(3)):

-int _kvm_kvatop(kvm_t *, u_long, u_long *);
-off_t _kvm_pa2off(kvm_t *, u_long);
+int _kvm_kvatop(kvm_t *, vaddr_t, paddr_t *);
+off_t _kvm_pa2off(kvm_t *, paddr_t);

Basically, use vaddr_t for VA and paddr_t for PA. In addition, for variables
representing addresses, use paddr_t or vaddr_t, depending on the context.

For most arches, vaddr_t and paddr_t are equivalent to unsigned long. However,
the change was needed for exotic situations, like i386 PAE, were unsigned long
is not suitable for PA which are 64 bits long. As this required a complete
change of the function prototypes, all arches had to be adapted accordingly.

Core files from before this commit should still work with the new code; I did
not see any direct dependency between core's structure and kvatop/pa2off.

The change was compile tested for all arches, as it impacts all of them.

See also:

http://mail-index.netbsd.org/current-users/2010/09/07/msg014249.html
 1.13 19-Sep-2010  jym Ansify and KNF all functions within kvm(3). No objection on current-users@.

Used as ground for u_long => vaddr_t/paddr_t replacements in kvm(3)
private functions.

Compile tested for all arches. See also:

http://mail-index.netbsd.org/current-users/2010/09/07/msg014249.html
 1.12 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.11 16-May-2003  wiz Consistently spell "crash dump" as two separate words. From jmc@openbsd.
 1.10 10-Oct-2000  he Use %lx instead of %x with _kvm_err when arg is u_long.
 1.9 02-Jul-1999  simonb branches: 1.9.8;
More trailing white space.
 1.8 12-Oct-1997  briggs branches: 1.8.4;
Put spaces around / in comment so 'machine/*.h' does not generate '/* inside
comment' warning.
 1.7 15-Aug-1997  mikel use <sys/cdefs.h> __RCSID() macro
 1.6 09-Apr-1997  thorpej Update for new m68k/kcore.h. We use dispatch information provided
by the crash dump itself to facilitate cross-analysis. The m68k_cmn
for Utah pmaps reads MMU configuration from the crash dump to that
this works on 4k and 8k h/w page size systems.
 1.5 21-Mar-1997  gwr Build the same libkvm.* on all m68k machines. (Well... except for the
stragglers that still use libkvm.old ) The m68k machines now dispatch
based on the machine name to the appropriate libkvm implementation.
 1.4 05-May-1996  gwr Allow more flexibility in the format of cpu_kcore_hdr_t and isolate
the knowledge of that struct in the machine-dependent module.
 1.3 18-Mar-1996  thorpej RCS id police.
 1.2 09-Jan-1995  mycroft Eliminate _kvm_uvatop(), in favor of using the machine-independent VM structures.
 1.1 28-Jul-1994  gwr branches: 1.1.2;
Add sun3 support (only "live" kernels for now).
 1.1.2.2 28-Jul-1994  gwr Add sun3 support (only "live" kernels for now).
 1.1.2.1 28-Jul-1994  gwr file kvm_sun3.c was added on branch netbsd-1-0 on 1994-07-28 21:46:37 +0000
 1.8.4.1 27-Oct-2000  he Pull up revision 1.10 (requested by is):
Use %lx to format u_long parameter.
 1.9.8.1 18-Oct-2000  tv Pullup 1.10 [he]:
Use %lx instead of %x with _kvm_err when arg is u_long.
 1.12 14-Sep-2011  christos more sys/param.h additions
 1.11 20-Sep-2010  jym Change kvm_pa2off() and kvm_kvatop() prototypes (private to kvm(3)):

-int _kvm_kvatop(kvm_t *, u_long, u_long *);
-off_t _kvm_pa2off(kvm_t *, u_long);
+int _kvm_kvatop(kvm_t *, vaddr_t, paddr_t *);
+off_t _kvm_pa2off(kvm_t *, paddr_t);

Basically, use vaddr_t for VA and paddr_t for PA. In addition, for variables
representing addresses, use paddr_t or vaddr_t, depending on the context.

For most arches, vaddr_t and paddr_t are equivalent to unsigned long. However,
the change was needed for exotic situations, like i386 PAE, were unsigned long
is not suitable for PA which are 64 bits long. As this required a complete
change of the function prototypes, all arches had to be adapted accordingly.

Core files from before this commit should still work with the new code; I did
not see any direct dependency between core's structure and kvatop/pa2off.

The change was compile tested for all arches, as it impacts all of them.

See also:

http://mail-index.netbsd.org/current-users/2010/09/07/msg014249.html
 1.10 19-Sep-2010  jym Ansify and KNF all functions within kvm(3). No objection on current-users@.

Used as ground for u_long => vaddr_t/paddr_t replacements in kvm(3)
private functions.

Compile tested for all arches. See also:

http://mail-index.netbsd.org/current-users/2010/09/07/msg014249.html
 1.9 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.8 16-May-2003  wiz branches: 1.8.30;
Consistently spell "crash dump" as two separate words. From jmc@openbsd.
 1.7 10-Oct-2000  he Use %lx instead of %x with _kvm_err when arg is u_long.
 1.6 02-Jul-1999  simonb branches: 1.6.8;
More trailing white space.
 1.5 12-Oct-1997  briggs branches: 1.5.4;
Put spaces around / in comment so 'machine/*.h' does not generate '/* inside
comment' warning.
 1.4 15-Aug-1997  mikel use <sys/cdefs.h> __RCSID() macro
 1.3 17-Jul-1997  gwr Get the length right in _kvm_sun3x_kvatop().
 1.2 09-Apr-1997  thorpej Update for new m68k/kcore.h. We use dispatch information provided
by the crash dump itself to facilitate cross-analysis. The m68k_cmn
for Utah pmaps reads MMU configuration from the crash dump to that
this works on 4k and 8k h/w page size systems.
 1.1 21-Mar-1997  gwr Build the same libkvm.* on all m68k machines. (Well... except for the
stragglers that still use libkvm.old ) The m68k machines now dispatch
based on the machine name to the appropriate libkvm implementation.
 1.5.4.1 27-Oct-2000  he Pull up revision 1.7 (requested by is):
Use %lx to format u_long parameter.
 1.6.8.1 18-Oct-2000  tv Pullup 1.7 [he]:
Use %lx instead of %x with _kvm_err when arg is u_long.
 1.8.30.1 18-May-2008  yamt sync with head.
 1.21 10-Jan-2022  christos Get rid of usrstack/USRSTACK. Document that the old version of getargv is
broken because of ASLR.
 1.20 19-Feb-2014  dsl Remove the #include <sys/user.h> from all of libkvm.
sys/user.h is a stub that just #includes sys/pcb.h.
There are no 'struct pcb' anywhere in here, so I'm extremely doubtful
any of the builds will fail.
OTOH it might be relying on a header that pcb.h includes.
In any case i386 and amd64 build.
 1.19 27-Jan-2014  matt Add missing __RCSID("$NetBSD$");
 1.18 20-Sep-2010  jym branches: 1.18.6; 1.18.12;
Change kvm_pa2off() and kvm_kvatop() prototypes (private to kvm(3)):

-int _kvm_kvatop(kvm_t *, u_long, u_long *);
-off_t _kvm_pa2off(kvm_t *, u_long);
+int _kvm_kvatop(kvm_t *, vaddr_t, paddr_t *);
+off_t _kvm_pa2off(kvm_t *, paddr_t);

Basically, use vaddr_t for VA and paddr_t for PA. In addition, for variables
representing addresses, use paddr_t or vaddr_t, depending on the context.

For most arches, vaddr_t and paddr_t are equivalent to unsigned long. However,
the change was needed for exotic situations, like i386 PAE, were unsigned long
is not suitable for PA which are 64 bits long. As this required a complete
change of the function prototypes, all arches had to be adapted accordingly.

Core files from before this commit should still work with the new code; I did
not see any direct dependency between core's structure and kvatop/pa2off.

The change was compile tested for all arches, as it impacts all of them.

See also:

http://mail-index.netbsd.org/current-users/2010/09/07/msg014249.html
 1.17 19-Sep-2010  jym Ansify and KNF all functions within kvm(3). No objection on current-users@.

Used as ground for u_long => vaddr_t/paddr_t replacements in kvm(3)
private functions.

Compile tested for all arches. See also:

http://mail-index.netbsd.org/current-users/2010/09/07/msg014249.html
 1.16 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.15 16-May-2003  wiz Consistently spell "crash dump" as two separate words. From jmc@openbsd.
 1.14 29-Nov-2001  thorpej branches: 1.14.2;
Rename a local to avoid a -Wshadow warning.
 1.13 07-Sep-2001  chuck include machine/vmparam.h so it will compile once again
 1.12 27-Oct-2000  matt be consistent in the use of u_long. eventually they should be uintptr_t.
 1.11 10-Oct-2000  he Use %lx instead of %x with _kvm_err when arg is u_long.
 1.10 29-Jun-2000  mrg <vm/vm.h> -> <uvm/uvm_extern.h>
 1.9 26-Jun-2000  mrg remove redundant vm includes
 1.8 02-Jul-1999  simonb branches: 1.8.8;
More trailing white space.
 1.7 03-Feb-1998  perry branches: 1.7.2;
remove obsolete register declarations
 1.6 20-Oct-1997  ragge Fix warnings.
 1.5 12-Aug-1997  gwr Add _kvm_mdopen()
 1.4 07-Jun-1997  ragge Vax now uses new libkvm.
 1.3 18-Mar-1996  thorpej RCS id police.
 1.2 25-Apr-1995  ragge kvm_vax.c added.
 1.1 17-Apr-1995  ragge kvm machine specific code for VAX.
 1.7.2.2 27-Oct-2000  he Pull up revision 1.12 (requested by matt):
Some more format / type fixes.
 1.7.2.1 27-Oct-2000  he Pull up revision 1.11 (requested by he):
Use %lx to format u_long parameter.
 1.8.8.1 18-Oct-2000  tv Pullup 1.11 [he]:
Use %lx instead of %x with _kvm_err when arg is u_long.
 1.14.2.2 29-Nov-2001  thorpej Rename a local to avoid a -Wshadow warning.
 1.14.2.1 29-Nov-2001  thorpej file kvm_vax.c was added on branch nathanw_sa on 2001-11-29 23:32:43 +0000
 1.18.12.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.18.6.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.13 10-Jan-2022  christos Get rid of usrstack/USRSTACK. Document that the old version of getargv is
broken because of ASLR.
 1.12 25-Apr-2020  maxv Switch to the new PTE naming. The old naming is now unused, remove it.
 1.11 08-Mar-2020  chs use a binary search in _kvm_pa2off(). this helps a lot for sparse dumps,
which can have millions of memory segments.
 1.10 19-Feb-2014  dsl branches: 1.10.26; 1.10.28;
Remove the #include <sys/user.h> from all of libkvm.
sys/user.h is a stub that just #includes sys/pcb.h.
There are no 'struct pcb' anywhere in here, so I'm extremely doubtful
any of the builds will fail.
OTOH it might be relying on a header that pcb.h includes.
In any case i386 and amd64 build.
 1.9 10-Jan-2012  chs branches: 1.9.6;
fix handling of large pages.
 1.8 20-Sep-2010  jym branches: 1.8.6;
Change kvm_pa2off() and kvm_kvatop() prototypes (private to kvm(3)):

-int _kvm_kvatop(kvm_t *, u_long, u_long *);
-off_t _kvm_pa2off(kvm_t *, u_long);
+int _kvm_kvatop(kvm_t *, vaddr_t, paddr_t *);
+off_t _kvm_pa2off(kvm_t *, paddr_t);

Basically, use vaddr_t for VA and paddr_t for PA. In addition, for variables
representing addresses, use paddr_t or vaddr_t, depending on the context.

For most arches, vaddr_t and paddr_t are equivalent to unsigned long. However,
the change was needed for exotic situations, like i386 PAE, were unsigned long
is not suitable for PA which are 64 bits long. As this required a complete
change of the function prototypes, all arches had to be adapted accordingly.

Core files from before this commit should still work with the new code; I did
not see any direct dependency between core's structure and kvatop/pa2off.

The change was compile tested for all arches, as it impacts all of them.

See also:

http://mail-index.netbsd.org/current-users/2010/09/07/msg014249.html
 1.7 19-Sep-2010  jym Ansify and KNF all functions within kvm(3). No objection on current-users@.

Used as ground for u_long => vaddr_t/paddr_t replacements in kvm(3)
private functions.

Compile tested for all arches. See also:

http://mail-index.netbsd.org/current-users/2010/09/07/msg014249.html
 1.6 15-Jan-2008  ad Handle reading from raw disk devices.
 1.5 04-Aug-2005  fvdl branches: 1.5.10;
Fix parsing the page tables.
 1.4 07-Aug-2003  agc branches: 1.4.4; 1.4.6;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.3 05-Jun-2002  fvdl kva -> physaddr translation through pagetable walking; for crash dumps
(as yet untested).
 1.2 05-Aug-2001  matt branches: 1.2.2;
Don't include <machine/pmap.h> and <machine/vmparam.h> if _KERNEL isn't
defined. Include them explicitly in the few kvm_arch.c that need them.
 1.1 19-Jun-2001  fvdl Add (mostly stub) x86-64 kvm stuff. Needs work.
 1.2.2.2 19-Dec-2002  thorpej Sync with HEAD.
 1.2.2.1 05-Aug-2001  thorpej file kvm_x86_64.c was added on branch nathanw_sa on 2002-12-19 02:26:25 +0000
 1.4.6.1 06-Nov-2005  tron Pull up following revision(s) (requested by chs in ticket #934):
lib/libkvm/kvm_x86_64.c: revision 1.5
Fix parsing the page tables.
 1.4.4.1 06-Nov-2005  riz Pull up following revision(s) (requested by chs in ticket #5969):
lib/libkvm/kvm_x86_64.c: revision 1.5
Fix parsing the page tables.
 1.5.10.1 23-Mar-2008  matt sync with HEAD
 1.8.6.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.8.6.1 17-Apr-2012  yamt sync with head
 1.9.6.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.10.28.1 08-Mar-2020  martin Pull up following revision(s) (requested by chs in ticket #763):

lib/libkvm/kvm.c: revision 1.105
lib/libkvm/kvm_x86_64.c: revision 1.11

only do bounce buffering for character devices.

use a binary search in _kvm_pa2off(). this helps a lot for sparse dumps,
which can have millions of memory segments.
 1.10.26.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.12 11-Jan-2009  christos bump shared libraries.
 1.11 08-Nov-2007  joerg Add kvm_dump_header and implement kvm_dump_wrtheader on top of it.
This function allows the caller finer control of how the writes happen
and doesn't force stdio as interface. Optimise clear_gap a bit to not
fill the gap byte-wise. Bump minor version of libkvm.
 1.10 18-Jan-2003  thorpej branches: 1.10.22;
Merge the nathanw_sa branch.
 1.9 26-May-2000  simonb branches: 1.9.6;
Add kvm interface to the new sysctls:
kvm_getproc2() -> sysctl(KERN_PROC2)
kvm_getargv2() -> sysctl(KERN_PROC_ARGS, KERN_PROC_ARGV)
kvm_getenvv2() -> sysctl(KERN_PROC_ARGS, KERN_PROC_ENV)
Add new KVM_NO_FILES flag to kvm_open*() - set up enough state to
use the above calls without having to open any kernel files.

XXX: kvm_getprocs.3 and kvm_open.3 to be updated soon.
 1.8 25-Feb-1999  abs Add a note to update src/distrib/sets/lists/base/shl.*, and add a missing
RCS Id.
 1.7 05-Jan-1998  perry RCSID Police.
 1.6 20-Mar-1996  mrg libkvm has totally changed, bump major version.
 1.5 09-May-1994  cgd the world has changed
 1.4 05-May-1994  cgd field name change, and safety (minor)
 1.3 05-May-1994  cgd update for changed flags
 1.2 27-Mar-1994  cgd _double_ major number bump! joy!
 1.1 27-Jan-1994  cgd create this in preparation for later.
 1.9.6.1 23-Apr-2002  nathanw Make libkvm able to cope with a LWPified kernel.

Add a kvm_getlwps() function to retrieve the LWPs of a specific process.
 1.10.22.1 09-Jan-2008  matt sync with HEAD

RSS XML Feed