Home | History | Annotate | Download | only in libkvm
History log of /src/lib/libkvm/kvm.c
RevisionDateAuthorComments
 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.

RSS XML Feed