Commit graph

456 commits

Author SHA1 Message Date
John Baldwin 9789cd30e5 Remove trailing whitespace. 2015-11-26 19:42:10 +00:00
John Baldwin 8296e78c83 Remove kvm_sparc.c. This is for 32-bit sparc support and was imported
from 4.4BSD.  It has never been used by FreeBSD.
2015-11-26 19:39:15 +00:00
Bryan Drewery 7b3ea376a2 META MODE: Prefer INSTALL=tools/install.sh to lessen the need for xinstall.host.
This both avoids some dependencies on xinstall.host and allows
bootstrapping on older releases to work due to lack of at least 'install -l'
support.

Sponsored by:	EMC / Isilon Storage Division
2015-11-25 19:10:28 +00:00
Andrew Turner db5ac78d34 Add support to libkvm for reading minidumps on arm64. The kernel side is
missing until it can be cleaned up.

Reviewed by:	jhb
Approved by:	ABT Systems Ltd
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D3319
2015-08-20 11:07:51 +00:00
Konstantin Belousov b4490c6e93 The si_status field of the siginfo_t, provided by the waitid(2) and
SIGCHLD signal, should keep full 32 bits of the status passed to the
_exit(2).

Split the combined p_xstat of the struct proc into the separate exit
status p_xexit for normal process exit, and signalled termination
information p_xsig.  Kernel-visible macro KW_EXITCODE() reconstructs
old p_xstat from p_xexit and p_xsig.  p_xexit contains complete status
and copied out into si_status.

Requested by:	Joerg Schilling
Reviewed by:	jilles (previous version), pho
Tested by:	pho
Sponsored by:	The FreeBSD Foundation
2015-07-18 09:02:50 +00:00
Baptiste Daroussin 18b2ee82db Revert r284417 it is not necessary anymore 2015-06-15 19:28:07 +00:00
Baptiste Daroussin 4232f82668 Enforce overwritting SHLIBDIR
Since METAMODE has been added, sys.mk loads bsd.mkopt.mk which ends load loading
bsd.own.mk which then defines SHLIBDIR before all the Makefile.inc everywhere.

This makes /lib being populated again.

Reported by:	many
2015-06-15 15:34:20 +00:00
Simon J. Gerraty ccfb965433 Add META_MODE support.
Off by default, build behaves normally.
WITH_META_MODE we get auto objdir creation, the ability to
start build from anywhere in the tree.

Still need to add real targets under targets/ to build packages.

Differential Revision:       D2796
Reviewed by: brooks imp
2015-06-13 19:20:56 +00:00
Simon J. Gerraty 44d314f704 dirdeps.mk now sets DEP_RELDIR 2015-06-08 23:35:17 +00:00
Simon J. Gerraty 98e0ffaefb Merge sync of head 2015-05-27 01:19:58 +00:00
Andrew Turner cd12a51d8d Add stub functions to build libkvm. There will be added, but we need them
now get the toolchain target building.

Differential Revision:	https://reviews.freebsd.org/D2185
Sponsored by:	The FreeBSD Foundation
2015-04-02 17:30:19 +00:00
Simon J. Gerraty 9268022b74 Merge from head@274682 2014-11-19 01:07:58 +00:00
Andrew Turner 58c47a70a3 Allow libkvm to get the kernel va to pa delta without the need for
physaddr. This should allow for a kernel where PHYSADDR and KERNPHYSADDR
are both undefined.

For now libkvm will use the old method of reading physaddr and kernaddr
to allow it to work with old kernels. This could be removed in the future
when enough time has passed.

Differential Revision:	https://reviews.freebsd.org/D939
MFC after:	1 week
2014-10-19 20:23:31 +00:00
Adrian Chadd e77f9fed15 Update the ULE scheduler + thread and kinfo structs to use int for cpuid
rather than u_char.

To try and play nice with the ABI, the u_char CPU ID values are clamped
at 254.  The new fields now contain the full CPU ID, or -1 for no cpu.

Differential Revision:	D955
Reviewed by:	jhb, kib
Sponsored by:	Norse Corp, Inc.
2014-10-18 19:36:11 +00:00
Andrew Turner 89184254a4 Fix the type of pte_pa as when it is passed into _kvm_pa2off it is either
a uint64_t or a pointer to an off_t. With it being a u_long can result in
incorrect values being returned.
2014-10-16 13:49:54 +00:00
Simon J. Gerraty ee7b0571c2 Merge head from 7/28 2014-08-19 06:50:54 +00:00
Marcel Moolenaar e7d939bda2 Remove ia64.
This includes:
o   All directories named *ia64*
o   All files named *ia64*
o   All ia64-specific code guarded by __ia64__
o   All ia64-specific makefile logic
o   Mention of ia64 in comments and documentation

This excludes:
o   Everything under contrib/
o   Everything under crypto/
o   sys/xen/interface
o   sys/sys/elf_common.h

Discussed at: BSDcan
2014-07-07 00:27:09 +00:00
Simon J. Gerraty fae50821ae Updated dependencies 2014-05-16 14:09:51 +00:00
Simon J. Gerraty 76b28ad6ab Updated dependencies 2014-05-10 05:16:28 +00:00
Simon J. Gerraty 9d2ab4a62d Merge head 2014-04-27 08:13:43 +00:00
Andrew Turner 73279d4113 Add a new ARM TARGET_ARCH, armv6hf. This is considered experimental.
This targets the existing ARMv6 and ARMv7 SoCs that contain a VFP unit.
This is an optional coprocessors may not be present in all devices, however
it appears to be in all current SoCs we support.

armv6hf targets the VFP variant of the ARM EABI and our copy of gcc is too
old to support this. Because of this there are a number of WITH/WITHOUT
options that are unsupported and must be left as the default value. The
options and their required value are:
 * WITH_ARM_EABI
 * WITHOUT_GCC
 * WITHOUT_GNUCXX

In addition, without an external toolchain, the following need to be left
as their default:
 * WITH_CLANG
 * WITH_CLANG_IS_CC

As there is a different method of passing float and double values to
functions the ABI is incompatible with existing armv6 binaries. To use
this a full rebuild of world is required. Because no floating point values
are passed into the kernel an armv6 kernel with VFP enabled will work with
an armv6hf userland and vice versa.
2014-03-23 12:49:25 +00:00
Gleb Smirnoff 9292aad4c9 Add kvm_getncpus() to obtain mp_ncpus.
Sponsored by:	Nginx, Inc.
2014-02-12 19:22:48 +00:00
Ed Maste 4842a3220d Add bounds check for pteindex / pdeindex 2014-02-12 15:57:38 +00:00
Gleb Smirnoff 19b5cffe0b While it isn't too late and kvm_read_zpcpu() function isn't yet used
outside libkvm(3), change its order of arguments, so that it is the
same as in kvm_read().

Sponsored by:	Nginx, Inc.
2014-02-12 09:41:17 +00:00
John-Mark Gurney d5ad10055b add support for building a cross-gdb for ARM... This isn't hooked up
to xdev yet as I don't know how to make it work properly...  It also
isn't heavily tested...

Reviewed by:	silence on -arm
2014-02-12 02:08:42 +00:00
Marcel Moolenaar 0b6a0ca072 Handle truncation of the size returned by _kvm_kvatop(). Cores can have
segments larger than INT_MAX.
2014-01-16 06:26:03 +00:00
Marcel Moolenaar cfe2be2b5e We don't have to worry about page sizes when working on virtual
cores (i.e. minidumps). Every segment is virtually contiguous.
2014-01-13 19:02:31 +00:00
Marcel Moolenaar f864e2ab73 Re-apply the part of r260022 that was reverted by r260030 with
one significant difference: for LIB32 builds both TARGET_ARCH
and MACHINE_ARCH are defined. TARGET_ARCH confusingly holds the
architecture of the host (e.g. amd64), while MACHINE_ARCH holds
the architecture were trying to build (e.g. i386). With both
set and different, r260022 changed the behaviour to interpret
the condition as building a cross-amd64 libkvm on i386, when
obviously we're trying to build an i386 version on amd64. When
COMPAT_32BIT is defined, we're building LIB32 and ignore the
value of TARGET_ARCH as we did before.
2014-01-13 19:01:14 +00:00
Marcel Moolenaar 71694e554d Revert part of r260022: LIB32 builds were broken by it. 2013-12-29 03:15:15 +00:00
Marcel Moolenaar 5f96573141 Add support for virtual cores (aka minidumps). To that end, refactor this
file as follows:
1.  Common ia64-specific support functions have the ia64_ prefix.
2.  Functions that work on physical cores have the phys_ prefix.
3.  Functions that work on virtual cores have the virt_ prefix.

With that:
1.  _kvm_kvatop() has been renamed to phys_kvatop() as it handles
    physical cores only.
2.  The new _kvm_kvatop() is nothing but a wrapper that calls either
    phys_kvatop() or virt_kvatop() by virtue of the kvatop function
    pointer in the vmstate structure.
3.  virt_kvatop() is nothing but a wrapper around virt_addr2off().
4.  virt_addr2off() iterates over the Phdrs to find the segment in
    which the address falls and return the file offset for it.

Now it's up to the kernel to populate the core file appropriately.
2013-12-29 02:31:40 +00:00
Marcel Moolenaar 4081b25521 Allow building a cross libkvm for ia64. 2013-12-28 23:02:48 +00:00
Marcel Moolenaar 3f6558c489 Allow building a cross libkvm by setting TARGET_ARCH. The library so
produced will be called libkvm-${ARCH} instead of libkvm. This allows
installing it alongside the native version.
For symbol lookups, use ps_pglobal_lookup() instead of __fdnlist()
when building a cross libkvm. It is assumed that the cross tool that
uses the cross libkvm also provides an implementation for this
proc_services function.

Note that this commit does not change any of the architecture-specific
code for cross-compilation.
2013-12-28 23:01:57 +00:00
Marcel Moolenaar 8a69c4ada4 Fix "kptdir is itself virtual" error, caused by having the kptdir in PBVM.
While here improve errors by having them include addresses (either virtual
or physical).
2013-12-26 07:10:54 +00:00
Gleb Smirnoff 3329973740 Revert r256514 for libkvm. It wasn't correct actually and breaks build. 2013-10-15 13:53:35 +00:00
Gleb Smirnoff 511b5fa590 - While we are spreading the counter(9) across network stack, more userland
tools would need to know about the counter_u64_t type. Allow to include
sys/counter.h from userspace.
- Utilize now defined type in kvm_counter_u64_fetch().

Sponsored by:	Netflix
Sponsored by:	Nginx, Inc.
2013-10-15 10:05:37 +00:00
Simon J. Gerraty d1d0158641 Merge from head 2013-09-05 20:18:59 +00:00
Mikolaj Golub 374931bdc1 In r227839, when removing libkvm dependency on procfs(5),
kvm_uread() function, used for reading from /proc/pid/mem, was
removed too. But the function declaration remained in kvm.h
public header and the soname was not bumped.

Remove kvm_uread() from kvm.h and bump the soname.

Reported by:	rmh
Discussed on:	arch
2013-07-10 19:44:43 +00:00
Ed Maste 371df6c6ad Switch to 2-clause license and standard text
Approved by:	bms@
2013-06-06 21:09:27 +00:00
Jilles Tjoelker 7b05a79942 libkvm: Make second /dev/null file descriptor close-on-exec as well.
MFC after:	1 week
2013-05-04 11:45:48 +00:00
Jilles Tjoelker 76dce67f0f libkvm: Use O_CLOEXEC instead of separate fcntl(F_SETFD) call.
MFC after:	1 week
2013-05-04 09:47:51 +00:00
Simon J. Gerraty 69e6d7b75e sync from head 2013-04-12 20:48:55 +00:00
Joel Dahl aaaade7024 Remove EOL whitespace. 2013-04-11 13:05:38 +00:00
Gleb Smirnoff 8d13912c31 Fix typo. 2013-04-11 10:14:28 +00:00
Gleb Smirnoff b448b67bbb Include types.h for C99 uintXX_t types. 2013-04-11 07:30:49 +00:00
Gleb Smirnoff 2a2134043c o Provide function kvm_read_zpcpu() to access UMA_ZONE_PCPU allocations.
o Provide function kvm_counter_u64_fetch() to fetch valut of a counter(9).

Sponsored by:	Nginx, Inc.
2013-04-10 20:26:53 +00:00
Simon J. Gerraty 7cf3a1c6b2 Updated dependencies 2013-03-11 17:21:52 +00:00
Simon J. Gerraty f5f7c05209 Updated dependencies 2013-02-16 01:23:54 +00:00
Simon J. Gerraty 23090366f7 Sync from head 2012-11-04 02:52:03 +00:00
Andriy Gapon ca895af355 kvm_getprocs: gracefully handle errors from kvm_deadprocs
and don't confuse callers with incorrect return value

MFC after:	9 days
2012-10-06 20:16:04 +00:00
Andriy Gapon 9fb9ea1c03 kvm_proclist: ignore processes in larvae state
Reviewed by:	jhb
MFC after:	8 days
2012-10-06 20:12:24 +00:00
Kevin Lo bedceb7c9c If the IdlePDPT is not present, PAE is not active 2012-09-10 08:16:45 +00:00
Marcel Moolenaar 7750ad47a9 Sync FreeBSD's bmake branch with Juniper's internal bmake branch.
Requested by: Simon Gerraty <sjg@juniper.net>
2012-08-22 19:25:57 +00:00
Glen Barber a3fb6da9ba General mdoc(7) and typo fixes.
PR:		167734
Submitted by:	Nobuyuki Koganemaru (kogane!jp.freebsd.org)
MFC after:	3 days
2012-05-11 20:06:46 +00:00
Mikolaj Golub 767993ec97 Try to avoid ambiguity when sysctl returns ENOMEM additionally
checking the returned oldlen: when ENOMEM is due to the supplied
buffer being too short the return oldlen is equal to buffer size.

Without this additional check kvm_getprocs() gets stuck in loop if the
returned ENOMEM was due the exceeded memorylocked limit. This is
easily can be observed running `limits -l 1k top'.

Submitted by:	Andrey Zonov <andrey zonov org>
MFC after:	1 week
2012-02-01 18:02:13 +00:00
Mikolaj Golub 952a0c3eed In kvm_argv(), the case when the supplied buffer was too short to hold the
requested value was handled incorrectly, and the function retuned NULL
instead of the truncated result.

Fix this and also remove unnecessary check for buf != NULL, which alway
retuns true.

MFC after:	3 days
2012-01-15 18:51:07 +00:00
Mikolaj Golub ee5169dc9d Now kvm_getenvv() and kvm_getargv() don't need procfs(5).
MFC after:	2 weeks
2011-11-22 21:12:28 +00:00
Marcel Moolenaar d69bc9bcbe Add support for PBVM addresses. In a nutshell this means:
o   get the physical address and size of the PBVM page table. This
    can be found in the bootinfo structure, of which the physical
    address is recorded as the ELF entry point.
o   translate region 4 virtual addresses to physical addresses using
    the PBVM page table.

In _kvm_kvatop() make the distinction between physical address and
core file offset a little clearer to avoid confusion. To further
enhance readability, always store the translated address into pa
so that it's obvious how the translation from va to pa happened.

Approved by:	re (blanket)
2011-08-06 15:59:54 +00:00
Bjoern A. Zeeb 925af54487 Rename ki_ocomm to ki_tdname and OCOMMLEN to TDNAMLEN.
Provide backward compatibility defines under BURN_BRIDGES.

Suggested by:	jhb
Reviewed by:	emaste
Sponsored by:	Sandvine Incorporated
Approved by:	re (kib)
2011-07-18 20:06:15 +00:00
Attilio Rao a2f4e284b0 Completely remove now unused pc_other_cpus, pc_cpumask.
Tested by:	pluknet
2011-07-04 10:45:54 +00:00
Attilio Rao 1de471dfee Revert r222363, as bde@ pointed out the initial solution was far more
correct.
2011-05-31 20:59:53 +00:00
Attilio Rao d361ed4b1c Style fix: cast to size_t rather than u_long when comparing to sizeof()
rets.

Requested by:	kib
2011-05-27 16:01:51 +00:00
Attilio Rao d5880f9cdf In the near future cpuset_t objects in struct pcpu will be axed out, but
as long as this does not happen, we need to fix interfaces to userland
in order to not break run-time accesses to the structure.

Reviwed by:	kib
Tested by:	pluknet
2011-05-27 15:50:14 +00:00
Attilio Rao 4b547324c0 Disconnect sun4v architecture from the three.
Some files keep the SUN4V tags as a code reference, for the future,
if any rewamped sun4v support wants to be added again.

Reviewed by:	marius
Tested by:	sbruno
Approved by:	re
2011-05-14 01:53:38 +00:00
Ulrich Spörlein 948db0b9e9 libkvm: fix logic inversion introduced with last commit
Reported by:	Brandon Gooch <jamesbrandongooch@gmail.com>
Pointy hat to:	uqs
2011-02-02 17:01:26 +00:00
Ulrich Spörlein 6ee6ac7fec libkvm: Unbreak build for powerpc64/powerpc
This slipped through my testing due to the recent roto-tiling of the
ARCH/TARGET parts that I need to catch up with. Mea culpa.
2011-01-24 11:06:40 +00:00
Ulrich Spörlein de788839e2 libkvm: fix process runtime calculation on crashdumps
Fix a long standing bug, where the procs ticks where assumed to be in
us. Instead, read cpu_tick_frequency from the kernel and use the same
logic to convert runtime. This is still too optimistic in that it
assumes cpu_tick_frequency is available and fixed. Since this function
is only called on crashdumps, I think we can live with that. Testing has
shown the values to be correct for different kern.hz inside Virtualbox.

Bump WARNS. Alignment issues on some archs mean this is still at 3.

Reviewed by:	bde
2011-01-23 11:08:36 +00:00
Ulrich Spörlein c10970dd7d libkvm code janitoring
- make WARNS=6 clean for archs w/o strict alignment requirments
- add const, ANSIfy, remove unused vars, cast types for comparison
- thanks to differing definitions of VM_MIN_ADDRESS across our archs, we
  need to trick the compiler to not complain about signedness. We could
  either fix VM_MIN_ADDRESS to always be a simple integer or make the
  check conditional on $ARCH.

Closes PRs:	kern/42386, kern/83364
Reviewed by:	bde
2011-01-23 11:08:28 +00:00
Ulrich Spörlein 20a95cd6fc Revert most of r210764, now that mdocml does the right
thing with empty quotation macros.

Requested by:	Alex Kozlov
2010-12-28 10:08:50 +00:00
Dimitry Andric 5f67450d3a Similar to sys/net/vnet.h, define the linker set name for sys/sys/pcpu.h
as a macro, and use it instead of literal strings.
2010-11-14 20:14:25 +00:00
Andriy Gapon 290e14f881 amd64: introduce minidump version 2
After KVA space was increased to 512GB on amd64 it became impractical
to use PTEs as entries in the minidump map of dumped pages, because size
of that map alone would already be 1GB.
Instead, we now use PDEs as page map entries and employ two stage lookup
in libkvm: virtual address -> PDE -> PTE -> physical address.  PTEs are
now dumped as regular pages.  Fixed page map size now is 2MB.

libkvm keeps support for accessing amd64 minidumps of version 1.
Support for 1GB pages is added.

Many thanks to Alan Cox for his guidance, numerous reviews, suggestions,
enhancments and corrections.

Reviewed by:	alc [kernel part]
MFC after:	15 days
2010-11-11 18:35:28 +00:00
Oleksandr Tymoshenko 99b7f1da55 Add minidump support for MIPS 2010-11-07 03:26:22 +00:00
Nathan Whitehorn b12277d1d4 Repair some build breakage introduced in r211725 and garbage collect some
code made obsolete in the same commit.
2010-08-28 15:03:11 +00:00
Warner Losh 25faff346c MFtbemd:
Prefer MACHNE_CPUARCH to MACHINE_ARCH in most contexts where you want
to test of all the CPUs of a given family conform.
2010-08-23 22:24:11 +00:00
Ulrich Spörlein c0da74038d mdoc: make sure to pass at least one argument to quotation macros 2010-08-02 13:11:35 +00:00
Nathan Whitehorn b5d529643a 64-bit PowerPC KVM support. 2010-07-10 15:15:00 +00:00
Sean Bruno 5f494640de Much closer approximation of the kernel's calculation of this value.
Reviewed by:	alc
Obtained from:	Yahoo Inc.
2010-06-18 01:17:16 +00:00
Jilles Tjoelker 886ae81fa3 kvm(3): Mention that some of the functions use sysctl(3) instead of kmem.
Additionally, because of sysctl(3) use (which is generally good), behaviour
for crash dumps differs slightly from behaviour for live kernels and this
will probably never be fixed entirely, so weaken that claim.

MFC after:	1 week
2010-04-25 12:50:30 +00:00
Ulrich Spörlein 63d46d1d5e Fix several typos in macros or macro misusage.
Found by:	make manlint
Reviewed by:	ru
Approved by:	philip (mentor)
2010-03-12 10:01:06 +00:00
Robert Watson 57a6239f94 Not all programs including kvm.h include the necessary headers to use
u_int, so prefer unsigned int.

MFC after:	6 days
Pointed out by:	bz, kib, Mr Tinderbox
2010-03-01 09:46:27 +00:00
Robert Watson ccd8bad0bb A first cut at teaching libkvm how to deal with dynamic per-CPU storage
(DPCPU):

A new API, kvm_dpcpu_setcpu(3), selects the active CPU for the purposes
of DPCPU.  Calls to kvm_nlist(3) will automatically translate DPCPU
symbols and return a pointer to the current CPU's version of the data.
Consumers needing to read the same symbol on several CPUs will invoke a
series of setcpu/nlist calls, one per CPU of interest.

This addition makes it possible for tools like netstat(1) to query the
values of DPCPU variables during crashdump analysis, and is based on
similar code handling virtualized global variables.

MFC after:	1 week
Sponsored by:	Juniper Networks, Inc.
2010-03-01 00:27:55 +00:00
Robert Watson f0506e896f Fix typo in comment.
MFC after:	3 days
2010-02-27 21:58:55 +00:00
Ed Schouten daaf575910 Build lib/ with WARNS=6 by default.
Similar to libexec/, do the same with lib/. Make WARNS=6 the norm and
lower it when needed.

I'm setting WARNS?=0 for secure/. It seems secure/ includes the
Makefile.inc provided by lib/. I'm not going to touch that directory.
Most of the code there is contributed anyway.
2010-01-02 09:58:07 +00:00
Brooks Davis 68a5cc39d3 Add a missing else that negated the truncation of ki_ngroups to
NGROUPS.

Submitted by:	Dmitry Pryanishnikov <lynx dot ripe at gmail dot com>
2009-12-10 21:16:16 +00:00
John Baldwin 50c3239e85 Fix a copy-paste bug when reading data from the last 3 (7 for PAE) bytes of
a page mapped by a large page in the kernel.

Submitted by:	Dorr H. Clark  dclark of engr.scu.edu
MFC after:	1 week
2009-11-06 13:10:12 +00:00
Brooks Davis d534b0c238 cr_groups is no longer embedded in struct ucred and is instead stored
in a seperate array.  As such we need to use kvm_read rather than bcopy
to populate the ki_groups field.

This fixes a crash when running ps -ax on a coredump.

Reported by:	brucec
Tested by:	brucec
MFC after:	3 days
2009-09-08 19:37:59 +00:00
Bjoern A. Zeeb 87a61ebd4c Rather than replicating the maths from the kernel, use the
value the kernel calculated directly as we already read it
with struct vnet.  This will make kvm_vnet.c more resilent
in case of possible kernel changes.

Reviewed by:	rwatson
Approved by:	re (kib)
2009-08-13 14:59:04 +00:00
Robert Watson 530c006014 Merge the remainder of kern_vimage.c and vimage.h into vnet.c and
vnet.h, we now use jails (rather than vimages) as the abstraction
for virtualization management, and what remained was specific to
virtual network stacks.  Minor cleanups are done in the process,
and comments updated to reflect these changes.

Reviewed by:	bz
Approved by:	re (vimage blanket)
2009-08-01 19:26:27 +00:00
Brooks Davis 1b5768be71 Revert the changes to struct kinfo_proc in r194498. Instead, fill
in up to 16 (KI_NGROUPS) values and steal a bit from ki_cr_flags
(all bits currently unused) to indicate overflow with the new flag
KI_CRF_GRP_OVERFLOW.

This fixes procstat -s.

Approved by: re (kib)
2009-07-24 15:03:10 +00:00
Bjoern A. Zeeb 7cf8b4b933 Make libkvm work on live systems and crashdumps with and
without VIMAGE virtualization in the kernel.

If we cannot resolve a symbol try to see if we can find it with
prefix of the virtualized subsystem, currently only "vnet_entry"
by identifying either the vnet of the current process for a
live system or the vnet of proc0 (or of dumptid if compiled
in a non-default way).

The way this is done currently allows us to only touch libkvm
but no single application. Once we are going to virtualize more
subsystems we will have to review this decision for better scaling.

Submitted by:	rwatson (initial version of kvm_vnet.c, lots of ideas)
Reviewed by:	rwatson
Approved by:	re (kib)
2009-07-23 21:12:21 +00:00
Brooks Davis 838d985825 Rework the credential code to support larger values of NGROUPS and
NGROUPS_MAX, eliminate ABI dependencies on them, and raise the to 1024
and 1023 respectively.  (Previously they were equal, but under a close
reading of POSIX, NGROUPS_MAX was defined to be too large by 1 since it
is the number of supplemental groups, not total number of groups.)

The bulk of the change consists of converting the struct ucred member
cr_groups from a static array to a pointer.  Do the equivalent in
kinfo_proc.

Introduce new interfaces crcopysafe() and crsetgroups() for duplicating
a process credential before modifying it and for setting group lists
respectively.  Both interfaces take care for the details of allocating
groups array. crsetgroups() takes care of truncating the group list
to the current maximum (NGROUPS) if necessary.  In the future,
crsetgroups() may be responsible for insuring invariants such as sorting
the supplemental groups to allow groupmember() to be implemented as a
binary search.

Because we can not change struct xucred without breaking application
ABIs, we leave it alone and introduce a new XU_NGROUPS value which is
always 16 and is to be used or NGRPS as appropriate for things such as
NFS which need to use no more than 16 groups.  When feasible, truncate
the group list rather than generating an error.

Minor changes:
  - Reduce the number of hand rolled versions of groupmember().
  - Do not assign to both cr_gid and cr_groups[0].
  - Modify ipfw to cache ucreds instead of part of their contents since
    they are immutable once referenced by more than one entity.

Submitted by:	Isilon Systems (initial implementation)
X-MFC after:	never
PR:		bin/113398 kern/133867
2009-06-19 17:10:35 +00:00
Ed Schouten 953e4134b5 Fix missing includes of <string.h>, to silence some compiler warnings.
Submitted by:	Pawel Worach
2009-06-14 12:42:06 +00:00
Marcel Moolenaar a5a8dffc5b Add support for PowerPC kernel core files. This commit only adds
support for virtual core files (aka minidumps). physical core
files are not supported.

The implementation is cross-tool ready and can be used in a non-
powerpc hosted debugger to analyze PowerPC core files. It also
accepts core files that still have the dump header, as can be
the case within Juniper where TFTP-based kernel core files are
supported and savecore is not used to "extract" the core file
from some dump device.

Obtained from:	Juniper Networks, Inc.
2009-04-06 21:52:10 +00:00
Bjoern A. Zeeb 413628a7e3 MFp4:
Bring in updated jail support from bz_jail branch.

This enhances the current jail implementation to permit multiple
addresses per jail. In addtion to IPv4, IPv6 is supported as well.
Due to updated checks it is even possible to have jails without
an IP address at all, which basically gives one a chroot with
restricted process view, no networking,..

SCTP support was updated and supports IPv6 in jails as well.

Cpuset support permits jails to be bound to specific processor
sets after creation.

Jails can have an unrestricted (no duplicate protection, etc.) name
in addition to the hostname. The jail name cannot be changed from
within a jail and is considered to be used for management purposes
or as audit-token in the future.

DDB 'show jails' command was added to aid debugging.

Proper compat support permits 32bit jail binaries to be used on 64bit
systems to manage jails. Also backward compatibility was preserved where
possible: for jail v1 syscalls, as well as with user space management
utilities.

Both jail as well as prison version were updated for the new features.
A gap was intentionally left as the intermediate versions had been
used by various patches floating around the last years.

Bump __FreeBSD_version for the afore mentioned and in kernel changes.

Special thanks to:
- Pawel Jakub Dawidek (pjd) for his multi-IPv4 patches
  and Olivier Houchard (cognet) for initial single-IPv6 patches.
- Jeff Roberson (jeff) and Randall Stewart (rrs) for their
  help, ideas and review on cpuset and SCTP support.
- Robert Watson (rwatson) for lots and lots of help, discussions,
  suggestions and review of most of the patch at various stages.
- John Baldwin (jhb) for his help.
- Simon L. Nielsen (simon) as early adopter testing changes
  on cluster machines as well as all the testers and people
  who provided feedback the last months on freebsd-jail and
  other channels.
- My employer, CK Software GmbH, for the support so I could work on this.

Reviewed by:	(see above)
MFC after:	3 months (this is just so that I get the mail)
X-MFC Before:   7.2-RELEASE if possible
2008-11-29 14:32:14 +00:00
Rafal Jaworowski 8e321b7943 Support kernel crash mini dumps on ARM architecture.
Obtained from:	Juniper Networks, Semihalf
2008-11-06 16:20:27 +00:00
Xin LI 01c56ef230 Reduce code duplication: use calloc() intead of malloc()
and memset afterward.
2008-10-17 20:11:28 +00:00
Xin LI b7f8e2dab3 _kvm_malloc allocates memory through calloc() which
returns zeroed memory, so don't redo the initialization.
2008-10-17 20:09:00 +00:00
John Baldwin cd11f01e4a Add a "CACHING" section regarding the internal caching of kernel variables
and the ability to clear that cache.
2008-08-21 19:22:13 +00:00
John Baldwin f110b23b7d Add a new routine kvm_getcptime(3) for fetching the equivalent of
'kern.cp_time'.  For a live kernel it uses the sysctl.  For a crashdump,
it first checks to see if the kernel has a 'cp_time' global symbol.  If
it does, it uses that.  If that doesn't work, when it uses the recently
added kvm_getmaxcpu(3) and kvm_getpcpu(3) routines to walk all the CPUs
and sum up their counters.

MFC after:	1 week
2008-08-19 21:30:36 +00:00
John Baldwin 794a9a6c96 Add two new routines to libkvm for working with per-CPU data:
kvm_getmaxcpu() and kvm_getpcpu().

MFC after:	1 week
2008-08-19 19:55:33 +00:00
Warner Losh 84ecaa02f9 First cut at doing the kvm file needed for mips.
Obtained from:	gonzo@
2008-07-23 07:24:55 +00:00
Pawel Jakub Dawidek 037dab5792 Use _WANT_FILE to make struct file visible from userland. This is
similar to _WANT_UCRED and _WANT_PRISON and seems to be much nicer than
defining _KERNEL.
It is also needed for my sys/refcount.h change going in soon.
2008-05-26 15:12:47 +00:00
Jeff Roberson 1e71e49d12 - Don't inspect the P_SA flag. It's being removed. 2008-03-12 10:00:33 +00:00
Xin LI 8b8ffe64e9 Plug memory leaks that is observed when argbuf or argspc is used in the
context.

Submitted by:	Michal Vranek <michal.vranek seznam cz>
PR:		bin/118380
MFC after:	1 month
2008-01-12 00:54:47 +00:00
Jeff Roberson 5c556b8aee - Update kvm_deadfiles to be compatible with the new system which has no
global list of all files.
 - Mark kvm_getfiles() as broken since the live version exports struct xfile
   with no filelist at the head and does so incorrectly and the deadfiles
   version exports struct file with a filelist at the head.  It is not known
   if either version works or complies to the manpage.
2007-12-30 01:43:51 +00:00
Julian Elischer cfe127f5bc Aparrently MACXOCOMLEN exisrts only on my machine 2007-10-26 15:25:28 +00:00
Julian Elischer 7ab24ea3b9 Introduce a way to make pure kernal threads.
kthread_add() takes the same parameters as the old kthread_create()
plus a pointer to a process structure, and adds a kernel thread
to that process.

kproc_kthread_add() takes the parameters for kthread_add,
plus a process name and a pointer to a pointer to a process instead of just
a pointer, and if the proc * is NULL, it creates the process to the
specifications required, before adding the thread to it.

All other old kthread_xxx() calls return, but act on (struct thread *)
instead of (struct proc *). One reason to change the name is so that
any old kernel modules that are lying around and expect kthread_create()
to make a process will not just accidentally link.

fix top to show  kernel threads by their thread name in -SH mode
add a tdnam formatting option to ps to show thread names.

make all idle threads actual kthreads and put them into their own idled process.
make all interrupt threads kthreads and put them in an interd process
(mainly for aesthetic and accounting reasons)
rename proc 0 to be 'kernel' and it's swapper thread is now 'swapper'

man page fixes to follow.
2007-10-26 08:00:41 +00:00
Jeff Roberson 84a0b303a9 - When using kvm use the new conversion method to derive swtime.
Approved by:	re
2007-09-21 04:11:34 +00:00
Jeff Roberson b61ce5b0e6 - Move all of the PS_ flags into either p_flag or td_flags.
- p_sflag was mostly protected by PROC_LOCK rather than the PROC_SLOCK or
   previously the sched_lock.  These bugs have existed for some time.
 - Allow swapout to try each thread in a process individually and then
   swapin the whole process if any of these fail.  This allows us to move
   most scheduler related swap flags into td_flags.
 - Keep ki_sflag for backwards compat but change all in source tools to
   use the new and more correct location of P_INMEM.

Reported by:	pho
Reviewed by:	attilio, kib
Approved by:	re (kensmith)
2007-09-17 05:31:39 +00:00
Hidetoshi Shimokawa d7dc9f7649 Re-enable raw dump format support on i386 and amd64 for /dev/fwmem. 2007-06-15 11:35:11 +00:00
Jeff Roberson 8ef6b1429f - Work-around the already partially broken rusage support in kvm by
completely disabling it until a full solution is agreed upon.

Pointy hat to:	me
2007-06-01 04:14:57 +00:00
Marcel Moolenaar aea0bb5c9b Add a level of indirection to the kernel PTE table. The old
scheme allowed for 1024 PTE pages, each containing 256 PTEs.
This yielded 2GB of KVA. This is not enough to boot a kernel
on a 16GB box and in general too low for a 64-bit machine.
By adding a level of indirection we now have 1024 2nd-level
directory pages, each capable of supporting 2GB of KVA. This
brings the grand total to 2TB of KVA.
2007-05-19 13:11:27 +00:00
John Baldwin e8865caffb - Move 'struct swdevt' back into swap_pager.h and expose it to userland.
- Restore support for fetching swap information from crash dumps via
  kvm_get_swapinfo(3) to fix pstat -T/-s on crash dumps.

Reviewed by:	arch@, phk
MFC after:	1 week
2007-02-07 17:43:11 +00:00
Warner Losh 5fa78ac5b8 Per Olivier Houchard, use the proper license for this file. He
bogusly used the kvm_powerpc.c file as a template for the license, but
then either wrote the code himself, or cribbed it from the kvm_i386
file.  The only thing from the kvm_powerpc.c file was the license.
Correct this mistake with his blessing.
2007-01-08 18:25:58 +00:00
Warner Losh 67e405315d Remove the advertising clause. UCB did this some time ago, but these
files were never updated to reflect that.

MFC After: 2 days
2007-01-08 17:35:36 +00:00
Julian Elischer 2d2f0b92c7 remove already commented out code 2006-12-06 06:44:20 +00:00
John Birrell 8460a577a4 Make KSE a kernel option, turned on by default in all GENERIC
kernel configs except sun4v (which doesn't process signals properly
with KSE).

Reviewed by:	davidxu@
2006-10-26 21:42:22 +00:00
Kip Macy cab68f571e unbreak build for sparc64 etc.
TARGET won't be defined on non subarches

Approved by: rwatson (mentor)
Reviewed by: jmg
2006-10-09 05:12:54 +00:00
Kip Macy ddd5342909 buildworld fixes for sun4v
not sure why pmap.c is included as it is unchanged

Approved by: rwatson (mentor)
Reviewed by: jmg
2006-10-09 04:58:45 +00:00
Wojciech A. Koszek 6e6dfbf26e Don't forget to set internal error message in kvm_nlist().
Approved by:	cognet (mentor)
2006-09-20 12:09:21 +00:00
Ruslan Ermilov 2d05c776ef Remove alpha-specific stuff. 2006-08-23 12:12:56 +00:00
Yaroslav Tykhiy 42e4359156 Rev. 1.44 of this file didn't introduce a right solution,
but we don't seem to have one yet, so just add an XXX comment on
passing rux_runtime to bintime2timeval() wrongly.

Spotted by:	gcc(1) (warning)
2006-07-25 22:39:57 +00:00
Xin LI 60555db2e2 Include strings.h for bzero() 2006-06-05 08:51:14 +00:00
Peter Wemm e9ca6fe47e Teach libkvm how to read minidumps. It turns out that minidumps are
far more convenient for libkvm to work with because of the page table
block at the beginning.  As a result, the MD code is smaller.

libkvm will automatically detect old vs mini dumps on i386 and amd64.

libkvm will handle i386 PAE and non-PAE modes.  There is a PAE flag in
the i386 minidump header to signal the width of the entries in the
page table block.

Other convenient values are also present, such as kernbase and the direct
map addresses on amd64.
2006-04-21 04:32:51 +00:00
Christian S.J. Peron 65efc5ee23 Validate that the supplied file is not empty before trying mmap(2) it
and access the pages associated with it.

Submitted by:	Wojciech A. Koszek
PR:		bin/91411
MFC after:	1 week
2006-01-15 20:30:13 +00:00
Peter Wemm add112ff65 Fix a well duplicated fencepost error that stopped crashdumps being
readable on certain random memory configurations.  If the libkvm consumer
tried to read something that was in the very last pdpe, pde or pte slot,
it would bogusly fail.

This is broken in RELENG_6 too.
2005-10-20 05:41:38 +00:00
Olivier Houchard 9960ac47e9 libkvm bits for arm. 2005-10-03 14:21:14 +00:00
Scott Long dd3d1a98d5 Fix the alpha build by using the correct argument types for _kvm_kvatop().
Submitted by: marcel
Approved by: re (implicit)
2005-07-02 05:49:29 +00:00
Paul Saab da2ef70999 Match _kvm_kvatop to it's prototype in kvm_i386.c. This unbreaks
the build.

Approved by:	re
2005-06-30 01:25:21 +00:00
Peter Wemm e55a0cd805 Support crash dumps > 4GB in size on 32 bit platforms. _kvm_kvatop()
returned an lseek offset in a "u_long *" value, which can't express >4GB
offsets on 32 bit machines (eg: PAE).  Change to "off_t *" for all.

Support ELF crashdumps on i386 and amd64.

Support PAE crashdumps on i386.  This is done by auto-detecting the
presence of the IdlePDPT which means that PAE is active.

I used Marcel's _kvm_pa2off strategy and ELF header reader for ELF support
on amd64.  Paul Saab ported the amd64 changes to i386 and we implemented
the PAE support from there.

Note that gdb6 in the src tree uses whatever libkvm supports.  If you want
to debug an old crash dump, you might want to keep an old libkvm.so handy
and use LD_PRELOAD or the like.  This does not detect the old raw dump
format.

Approved by: re
2005-06-29 22:39:41 +00:00
Peter Wemm 2cfe3fda19 Set ki_tdev to NODEV rather than NULL.
Approved by:  re
2005-06-24 00:37:04 +00:00
Pawel Jakub Dawidek f8197bf090 Make kvm(3) aware of ki_jid field.
Reviewed by:	gad
MFC after:	3 days
2005-03-20 10:37:56 +00:00
Poul-Henning Kamp 9c4fb6619c Dike out unwarranted reference to si_udev. 2005-03-15 14:26:14 +00:00
Ruslan Ermilov 24a0682c64 Sort sections. 2005-01-20 09:17:07 +00:00
David Schultz 7a62aa8a18 In preparation to remove U areas, don't refer to p_uarea in libkvm.
Reviewed by:	arch@
2004-11-20 02:28:26 +00:00
Christian S.J. Peron 668e800b6f Remove un-needed call to close(2). The fd that close is being
called on is invalid and has no use.

Reviewed by:	smkelly
2004-11-13 14:30:34 +00:00
Christian S.J. Peron 2f5d3f6f6a Document the fact that kvm_getenvv(3) requires procfs to be mounted
on /proc in order to operate correctly.

Reviewed by:	simon@, wes@
2004-11-13 14:26:13 +00:00
Peter Wemm 2bdd560907 Belatedly catch up with the dev_t/cdev changes from a few months back.
Extract the struct cdev pointer and the tty device from inside rather than
incorrectly casting the 'struct cdev *' pointer to a 'dev_t' int.  Not
that this was particularly important since it was only used for reading
vmcore files.
2004-10-11 21:56:27 +00:00
John Baldwin 09ff687c38 - Fix the compile to chase the p_rux changes.
- Add a comment noting that the ru_[us]times values being read aren't
  actually valid and need to be computed from the raw values.

Submitted by:	many (1)
2004-10-06 17:10:56 +00:00
Marcel Moolenaar 0c32530bb7 Redefine a PTE as a 64-bit integral type instead of a struct of
bit-fields. Unify the PTE defines accordingly and update all
uses.
2004-09-23 00:05:20 +00:00
Marcel Moolenaar 6d77d031fd The offset argument to mmap(2) is not a pointer. Use 0 instead of NULL. 2004-09-22 20:26:33 +00:00
Julian Elischer ed062c8d66 Refactor a bunch of scheduler code to give basically the same behaviour
but with slightly cleaned up interfaces.

The KSE structure has become the same as the "per thread scheduler
private data" structure. In order to not make the diffs too great
one is #defined as the other at this time.

The KSE (or td_sched) structure is  now allocated per thread and has no
allocation code of its own.

Concurrency for a KSEGRP is now kept track of via a simple pair of counters
rather than using KSE structures as tokens.

Since the KSE structure is different in each scheduler, kern_switch.c
is now included at the end of each scheduler. Nothing outside the
scheduler knows the contents of the KSE (aka td_sched) structure.

The fields in the ksegrp structure that are to do with the scheduler's
queueing mechanisms are now moved to the kg_sched structure.
(per ksegrp scheduler private data structure). In other words how the
scheduler queues and keeps track of threads is no-one's business except
the scheduler's. This should allow people to write experimental
schedulers with completely different internal structuring.

A scheduler call sched_set_concurrency(kg, N) has been added that
notifies teh scheduler that no more than N threads from that ksegrp
should be allowed to be on concurrently scheduled. This is also
used to enforce 'fainess' at this time so that a ksegrp with
10000 threads can not swamp a the run queue and force out a process
with 1 thread, since the current code will not set the concurrency above
NCPU, and both schedulers will not allow more than that many
onto the system run queue at a time. Each scheduler should eventualy develop
their own methods to do this now that they are effectively separated.

Rejig libthr's kernel interface to follow the same code paths as
linkse for scope system threads. This has slightly hurt libthr's performance
but I will work to recover as much of it as I can.

Thread exit code has been cleaned up greatly.
exit and exec code now transitions a process back to
'standard non-threaded mode' before taking the next step.
Reviewed by:	scottl, peter
MFC after:	1 week
2004-09-05 02:09:54 +00:00
Warner Losh 9e749cc9c5 Expand the license referenced indirectly inline. 2004-07-31 18:49:53 +00:00
Alexander Kabaev e1f91dbd18 Remove stale code protected by #ifdef sparc. GCC 3.4.x adds sparc to
predefined symbols on all SPARC platforms and FreeBSD follows the crowd.
2004-07-28 05:43:08 +00:00
Ruslan Ermilov 1a0a934547 Mechanically kill hard sentence breaks. 2004-07-02 23:52:20 +00:00
Ruslan Ermilov 862b46f607 Markup, grammar, punctuation. 2004-07-01 18:20:57 +00:00
Garance A Drosehn 1566329b0f Fix a test of bit-flag "P_SA" by adding parenthesis around the expression.
Submitted by:	Cyrille Lefevre
2004-06-23 21:59:56 +00:00
Garance A Drosehn b7e7c21adf Replace a call to strncpy() with a call to strlcpy()
Submitted by:	Cyrille Lefevre
2004-06-23 21:31:43 +00:00
Garance A Drosehn 276de18cc9 Fill in the some new fields 'struct kinfo_proc', namely ki_childstime,
ki_childutime, and ki_emul.  Also uses the timeradd() macro to correct
the calculation of ki_childtime.  That will correct the value returned
when ki_childtime.tv_usec > 1,000,000.

This also implements a new KERN_PROC_GID option for kvm_getprocs().
It also implements the KERN_PROC_RGID and KERN_PROC_SESSION options
which were added to sys/kern/kern_proc.c revision 1.203.

PR:		bin/65803  (a very tiny piece of the PR)
Submitted by:	Cyrille Lefevre
2004-06-19 14:08:10 +00:00
Poul-Henning Kamp f3732fd15b Second half of the dev_t cleanup.
The big lines are:
	NODEV -> NULL
	NOUDEV -> NODEV
	udev_t -> dev_t
	udev2dev() -> findcdev()

Various minor adjustments including handling of userland access to kernel
space struct cdev etc.
2004-06-17 17:16:53 +00:00
Julian Elischer 3010536674 This library has to change whenever the kernel process structure changes. 2004-06-16 00:34:31 +00:00