diff options
author | jhb <jhb@FreeBSD.org> | 2015-11-27 18:58:26 +0000 |
---|---|---|
committer | jhb <jhb@FreeBSD.org> | 2015-11-27 18:58:26 +0000 |
commit | ab35544b83d7494b58b4327d7a9e6d66da7ab579 (patch) | |
tree | 0b881610c55721cfde72c0eaeb1df3d9d654fd26 /lib/libkvm/kvm_powerpc64.c | |
parent | fd20cedd093bc1221cdc050bac05276a1b9a36ba (diff) | |
download | FreeBSD-src-ab35544b83d7494b58b4327d7a9e6d66da7ab579.zip FreeBSD-src-ab35544b83d7494b58b4327d7a9e6d66da7ab579.tar.gz |
Add support to libkvm for reading vmcores from other architectures.
- Add a kvaddr_type to represent kernel virtual addresses instead of
unsigned long.
- Add a struct kvm_nlist which is a stripped down version of struct nlist
that uses kvaddr_t for n_value.
- Add a kvm_native() routine that returns true if an open kvm descriptor
is for a native kernel and memory image.
- Add a kvm_open2() function similar to kvm_openfiles(). It drops the
unused 'swapfile' argument and adds a new function pointer argument for
a symbol resolving function. Native kernels still use _fdnlist() from
libc to resolve symbols if a resolver function is not supplied, but cross
kernels require a resolver.
- Add a kvm_nlist2() function similar to kvm_nlist() except that it uses
struct kvm_nlist instead of struct nlist.
- Add a kvm_read2() function similar to kvm_read() except that it uses
kvaddr_t instead of unsigned long for the kernel virtual address.
- Add a new kvm_arch switch of routines needed by a vmcore backend.
Each backend is responsible for implementing kvm_read2() for a given
vmcore format.
- Use libelf to read headers from ELF kernels and cores (except for
powerpc cores).
- Add internal helper routines for the common page offset hash table used
by the minidump backends.
- Port all of the existing kvm backends to implement a kvm_arch switch and
to be cross-friendly by using private constants instead of ones that
vary by platform (e.g. PAGE_SIZE). Static assertions are present when
a given backend is compiled natively to ensure the private constants
match the real ones.
- Enable all of the existing vmcore backends on all platforms. This means
that libkvm on any platform should be able to perform KVA translation
and read data from a vmcore of any platform.
Tested on: amd64, i386, sparc64 (marius)
Differential Revision: https://reviews.freebsd.org/D3341
Diffstat (limited to 'lib/libkvm/kvm_powerpc64.c')
-rw-r--r-- | lib/libkvm/kvm_powerpc64.c | 77 |
1 files changed, 47 insertions, 30 deletions
diff --git a/lib/libkvm/kvm_powerpc64.c b/lib/libkvm/kvm_powerpc64.c index f3a2b24..7912185 100644 --- a/lib/libkvm/kvm_powerpc64.c +++ b/lib/libkvm/kvm_powerpc64.c @@ -34,12 +34,9 @@ __FBSDID("$FreeBSD$"); #include <sys/kerneldump.h> #include <sys/mman.h> -#include <vm/vm.h> - -#include <db.h> #include <elf.h> -#include <limits.h> #include <kvm.h> +#include <limits.h> #include <stdlib.h> #include <string.h> @@ -100,7 +97,7 @@ powerpc_maphdrs(kvm_t *kd) vm = kd->vmst; - vm->mapsz = PAGE_SIZE; + vm->mapsz = sizeof(*vm->eh) + sizeof(struct kerneldumpheader); vm->map = mmap(NULL, vm->mapsz, PROT_READ, MAP_PRIVATE, kd->pmfd, 0); if (vm->map == MAP_FAILED) { _kvm_err(kd, kd->program, "cannot map corefile"); @@ -130,16 +127,15 @@ powerpc_maphdrs(kvm_t *kd) vm->mapsz = vm->dmphdrsz + mapsz; vm->map = mmap(NULL, vm->mapsz, PROT_READ, MAP_PRIVATE, kd->pmfd, 0); if (vm->map == MAP_FAILED) { - _kvm_err(kd, kd->program, "cannot map corefle headers"); + _kvm_err(kd, kd->program, "cannot map corefile headers"); return (-1); } vm->eh = (void *)((uintptr_t)vm->map + vm->dmphdrsz); - vm->ph = (void *)((uintptr_t)vm->eh + be64toh(vm->eh->e_phoff)); + vm->ph = (void *)((uintptr_t)vm->eh + + (uintptr_t)be64toh(vm->eh->e_phoff)); return (0); inval: - munmap(vm->map, vm->mapsz); - vm->map = MAP_FAILED; _kvm_err(kd, kd->program, "invalid corefile"); return (-1); } @@ -150,7 +146,7 @@ powerpc_maphdrs(kvm_t *kd) * 0 when the virtual address is invalid. */ static size_t -powerpc64_va2off(kvm_t *kd, u_long va, off_t *ofs) +powerpc64_va2off(kvm_t *kd, kvaddr_t va, off_t *ofs) { struct vmstate *vm = kd->vmst; Elf64_Phdr *ph; @@ -172,48 +168,69 @@ powerpc64_va2off(kvm_t *kd, u_long va, off_t *ofs) return (be64toh(ph->p_memsz) - (va - be64toh(ph->p_vaddr))); } -void -_kvm_freevtop(kvm_t *kd) +static void +_powerpc64_freevtop(kvm_t *kd) { struct vmstate *vm = kd->vmst; - if (vm == NULL) - return; - - if (vm->eh != MAP_FAILED) { + if (vm->eh != MAP_FAILED) munmap(vm->eh, vm->mapsz); - vm->eh = MAP_FAILED; - } free(vm); kd->vmst = NULL; } -int -_kvm_initvtop(kvm_t *kd) +static int +_powerpc64_probe(kvm_t *kd) +{ + + return (_kvm_probe_elf_kernel(kd, ELFCLASS64, EM_PPC64) && + kd->nlehdr.e_ident[EI_DATA] == ELFDATA2MSB); +} + +static int +_powerpc64_initvtop(kvm_t *kd) { kd->vmst = (struct vmstate *)_kvm_malloc(kd, sizeof(*kd->vmst)); - if (kd->vmst == NULL) { - _kvm_err(kd, kd->program, "out of virtual memory"); + if (kd->vmst == NULL) return (-1); - } - if (powerpc_maphdrs(kd) == -1) { - free(kd->vmst); - kd->vmst = NULL; + + if (powerpc_maphdrs(kd) == -1) return (-1); - } + return (0); } -int -_kvm_kvatop(kvm_t *kd, u_long va, off_t *ofs) +static int +_powerpc64_kvatop(kvm_t *kd, kvaddr_t va, off_t *ofs) { struct vmstate *vm; vm = kd->vmst; - if (vm->ph->p_paddr == ~0UL) + if (be64toh(vm->ph->p_paddr) == 0xffffffffffffffff) return ((int)powerpc64_va2off(kd, va, ofs)); _kvm_err(kd, kd->program, "Raw corefile not supported"); return (0); } + +static int +_powerpc64_native(kvm_t *kd) +{ + +#ifdef __powerpc64__ + return (1); +#else + return (0); +#endif +} + +struct kvm_arch kvm_powerpc64 = { + .ka_probe = _powerpc64_probe, + .ka_initvtop = _powerpc64_initvtop, + .ka_freevtop = _powerpc64_freevtop, + .ka_kvatop = _powerpc64_kvatop, + .ka_native = _powerpc64_native, +}; + +KVM_ARCH(kvm_powerpc64); |