libkvm: fix build failures

This commit is contained in:
Will Andrews 2017-11-12 01:36:48 +00:00
parent 2aa6a4f3c8
commit 8baaf913be
10 changed files with 39 additions and 17 deletions

View File

@ -36,7 +36,14 @@
#include <sys/cdefs.h>
#include <sys/types.h>
#include <nlist.h>
#include <vm/vm.h>
/*
* Including vm/vm.h causes namespace pollution issues. For the
* most part, only things using kvm_walk_pages() need to #include it.
*/
#ifndef VM_H
typedef u_char vm_prot_t;
#endif
/* Default version symbol. */
#define VRS_SYM "_version"

View File

@ -42,8 +42,8 @@ typedef uint64_t aarch64_pte_t;
/* Source: arm64/include/pte.h */
#define AARCH64_ATTR_MASK 0xfff0000000000fff
#define AARCH64_ATTR_UXN (1UL << 54)
#define AARCH64_ATTR_PXN (1UL << 53)
#define AARCH64_ATTR_UXN (1ULL << 54)
#define AARCH64_ATTR_PXN (1ULL << 53)
#define AARCH64_ATTR_XN (AARCH64_ATTR_PXN | AARCH64_ATTR_UXN)
#define AARCH64_ATTR_AP(x) ((x) << 6)
#define AARCH64_ATTR_AP_RO (1 << 1)

View File

@ -51,6 +51,7 @@ static char sccsid[] = "@(#)kvm_hp300.c 8.1 (Berkeley) 6/4/93";
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <vm/vm.h>
#include <kvm.h>
#include <limits.h>

View File

@ -55,7 +55,9 @@ typedef uint64_t amd64_pml4e_t;
#define AMD64_NPML4EPG (AMD64_PAGE_SIZE / sizeof(amd64_pml4e_t))
#define AMD64_PML4SHIFT 39
#define AMD64_PG_NX (1ULL << 63)
#define AMD64_PG_V 0x001
#define AMD64_PG_RW 0x002
#define AMD64_PG_PS 0x080
#define AMD64_PG_FRAME (0x000ffffffffff000)
#define AMD64_PG_PS_FRAME (0x000fffffffe00000)

View File

@ -37,6 +37,7 @@ __FBSDID("$FreeBSD$");
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <vm/vm.h>
#include <kvm.h>
#include "../../sys/arm64/include/minidump.h"

View File

@ -36,6 +36,7 @@ __FBSDID("$FreeBSD$");
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <vm/vm.h>
#include <kvm.h>
#include "../../sys/amd64/include/minidump.h"
@ -59,9 +60,9 @@ _amd64_entry_to_prot(uint64_t entry)
{
vm_prot_t prot = VM_PROT_READ;
if ((entry & PG_RW) != 0)
if ((entry & AMD64_PG_RW) != 0)
prot |= VM_PROT_WRITE;
if ((entry & PG_NX) == 0)
if ((entry & AMD64_PG_NX) == 0)
prot |= VM_PROT_EXECUTE;
return prot;
}
@ -351,12 +352,12 @@ _amd64_minidump_walk_pages(kvm_t *kd, kvm_walk_pages_cb_t *cb, void *arg)
return (0);
for (pdeindex = 0; pdeindex < npdes; pdeindex++) {
pd_entry_t pde = _amd64_pde_get(kd, pdeindex);
pt_entry_t *ptes;
amd64_pde_t pde = _amd64_pde_get(kd, pdeindex);
amd64_pte_t *ptes;
u_long i;
va = vm->hdr.kernbase + (pdeindex << AMD64_PDRSHIFT);
if ((pde & PG_V) == 0)
if ((pde & AMD64_PG_V) == 0)
continue;
if ((pde & AMD64_PG_PS) != 0) {
@ -366,7 +367,7 @@ _amd64_minidump_walk_pages(kvm_t *kd, kvm_walk_pages_cb_t *cb, void *arg)
* that every page here uses the same PDE to
* generate permissions.
*/
pa = pde & AMD64_PG_PS_FRAME +
pa = (pde & AMD64_PG_PS_FRAME) +
((va & AMD64_PDRMASK) ^ VA_OFF(vm, va));
dva = vm->hdr.dmapbase + pa;
_kvm_bitmap_set(&bm, pa, AMD64_PAGE_SIZE);
@ -383,12 +384,12 @@ _amd64_minidump_walk_pages(kvm_t *kd, kvm_walk_pages_cb_t *cb, void *arg)
if (ptes == NULL)
continue;
for (i = 0; i < NPTEPG; i++) {
pt_entry_t pte = (u_long)ptes[i];
for (i = 0; i < AMD64_NPTEPG; i++) {
amd64_pte_t pte = (u_long)ptes[i];
pa = pte & AMD64_PG_FRAME;
dva = vm->hdr.dmapbase + pa;
if ((pte & PG_V) != 0) {
if ((pte & AMD64_PG_V) != 0) {
_kvm_bitmap_set(&bm, pa, AMD64_PAGE_SIZE);
if (!_kvm_visit_cb(kd, cb, arg, pa, va, dva,
_amd64_entry_to_prot(pte), pgsz, 0)) {

View File

@ -35,6 +35,7 @@ __FBSDID("$FreeBSD$");
#include <sys/endian.h>
#include <sys/param.h>
#include <vm/vm.h>
#include <kvm.h>
#include <limits.h>
#include <stdint.h>

View File

@ -36,6 +36,7 @@ __FBSDID("$FreeBSD$");
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <vm/vm.h>
#include <kvm.h>
#include "../../sys/i386/include/minidump.h"
@ -285,6 +286,10 @@ _i386_iterator_next(struct i386_iter *it, u_long *pa, u_long *va, u_long *dva,
int found = 0;
*dva = 0;
*pa = 0;
*va = 0;
*dva = 0;
*prot = 0;
for (; it->pteindex < it->nptes && found == 0; it->pteindex++) {
if (vm->hdr.paemode) {
pte64 = _i386_pte_pae_get(it->kd, it->pteindex);

View File

@ -35,6 +35,7 @@ __FBSDID("$FreeBSD$");
*/
#include <sys/param.h>
#include <vm/vm.h>
#include <kvm.h>
#include <limits.h>
#include <stdint.h>
@ -296,6 +297,8 @@ _mips_iterator_next(struct mips_iter *it, u_long *pa, u_long *va, u_long *dva,
* pages are R|X at least.
*/
*prot = VM_PROT_READ | VM_PROT_EXECUTE;
*pa = 0;
*va = 0;
*dva = 0;
for (;it->pteindex < it->nptes && found == 0; it->pteindex++) {
if (vm->pte_size == 64) {

View File

@ -49,6 +49,7 @@ __FBSDID("$FreeBSD$");
#include <assert.h>
#include <fcntl.h>
#include <vm/vm.h>
#include <kvm.h>
#include <limits.h>
#include <paths.h>
@ -263,9 +264,9 @@ popcount_bytes(uint64_t *addr, uint32_t bit0, uint32_t bitN)
void *
_kvm_pmap_get(kvm_t *kd, u_long idx, size_t len)
{
off_t off = idx * len;
uintptr_t off = idx * len;
if (off >= kd->pt_sparse_off)
if ((off_t)off >= kd->pt_sparse_off)
return (NULL);
return (void *)((uintptr_t)kd->page_map + off);
}
@ -362,9 +363,9 @@ _kvm_pt_init(kvm_t *kd, size_t map_len, off_t map_off, off_t sparse_off,
MAP_PRIVATE, kd->pmfd, kd->pt_sparse_off);
if (kd->sparse_map == MAP_FAILED) {
_kvm_err(kd, kd->program, "cannot map %" PRIu64
" bytes from fd %d offset %ld for sparse map: %s",
" bytes from fd %d offset %jd for sparse map: %s",
kd->pt_sparse_size, kd->pmfd,
kd->pt_sparse_off, strerror(errno));
(intmax_t)kd->pt_sparse_off, strerror(errno));
return (-1);
}
return (0);
@ -385,7 +386,7 @@ _kvm_pmap_init(kvm_t *kd, uint32_t pmap_size, off_t pmap_off)
}
if (pread(kd->pmfd, kd->page_map, pmap_size, pmap_off) != exp_len) {
_kvm_err(kd, kd->program, "cannot read %d bytes from "
"offset %ld for page map", pmap_size, pmap_off);
"offset %jd for page map", pmap_size, (intmax_t)pmap_off);
return (-1);
}
return (0);