11573Srgrimes/*- 21573Srgrimes * Copyright (c) 1992, 1993 31573Srgrimes * The Regents of the University of California. All rights reserved. 41573Srgrimes * 51573Srgrimes * This code is derived from software developed by the Computer Systems 61573Srgrimes * Engineering group at Lawrence Berkeley Laboratory under DARPA contract 71573Srgrimes * BG 91-66 and contributed to Berkeley. 81573Srgrimes * 91573Srgrimes * Redistribution and use in source and binary forms, with or without 101573Srgrimes * modification, are permitted provided that the following conditions 111573Srgrimes * are met: 121573Srgrimes * 1. Redistributions of source code must retain the above copyright 131573Srgrimes * notice, this list of conditions and the following disclaimer. 141573Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 151573Srgrimes * notice, this list of conditions and the following disclaimer in the 161573Srgrimes * documentation and/or other materials provided with the distribution. 171573Srgrimes * 4. Neither the name of the University nor the names of its contributors 181573Srgrimes * may be used to endorse or promote products derived from this software 191573Srgrimes * without specific prior written permission. 201573Srgrimes * 211573Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 221573Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 231573Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 241573Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 251573Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 261573Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 271573Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 281573Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 291573Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 301573Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 311573Srgrimes * SUCH DAMAGE. 321573Srgrimes * 331573Srgrimes * @(#)kvm_private.h 8.1 (Berkeley) 6/4/93 3455127Speter * $FreeBSD: releng/11.0/lib/libkvm/kvm_private.h 291406 2015-11-27 18:58:26Z jhb $ 351573Srgrimes */ 361573Srgrimes 37291406Sjhb#include <sys/endian.h> 38291406Sjhb#include <sys/linker_set.h> 39291406Sjhb#include <gelf.h> 40291406Sjhb 41291406Sjhbstruct kvm_arch { 42291406Sjhb int (*ka_probe)(kvm_t *); 43291406Sjhb int (*ka_initvtop)(kvm_t *); 44291406Sjhb void (*ka_freevtop)(kvm_t *); 45291406Sjhb int (*ka_kvatop)(kvm_t *, kvaddr_t, off_t *); 46291406Sjhb int (*ka_native)(kvm_t *); 47291406Sjhb}; 48291406Sjhb 49291406Sjhb#define KVM_ARCH(ka) DATA_SET(kvm_arch, ka) 50291406Sjhb 511573Srgrimesstruct __kvm { 52291406Sjhb struct kvm_arch *arch; 531573Srgrimes /* 541573Srgrimes * a string to be prepended to error messages 551573Srgrimes * provided for compatibility with sun's interface 561573Srgrimes * if this value is null, errors are saved in errbuf[] 571573Srgrimes */ 581573Srgrimes const char *program; 591573Srgrimes char *errp; /* XXX this can probably go away */ 601573Srgrimes char errbuf[_POSIX2_LINE_MAX]; 611573Srgrimes#define ISALIVE(kd) ((kd)->vmfd >= 0) 621573Srgrimes int pmfd; /* physical memory file (or crashdump) */ 631573Srgrimes int vmfd; /* virtual memory file (-1 if crashdump) */ 641856Sdg int nlfd; /* namelist file (e.g., /kernel) */ 65291406Sjhb GElf_Ehdr nlehdr; /* ELF file header for namelist file */ 66291406Sjhb int (*resolve_symbol)(const char *, kvaddr_t *); 671573Srgrimes struct kinfo_proc *procbase; 681573Srgrimes char *argspc; /* (dynamic) storage for argv strings */ 691573Srgrimes int arglen; /* length of the above */ 701573Srgrimes char **argv; /* (dynamic) storage for argv pointers */ 711573Srgrimes int argc; /* length of above (not actual # present) */ 7212682Speter char *argbuf; /* (dynamic) temporary storage */ 731573Srgrimes /* 741573Srgrimes * Kernel virtual address translation state. This only gets filled 751573Srgrimes * in for dead kernels; otherwise, the running kernel (i.e. kmem) 761573Srgrimes * will do the translations for us. It could be big, so we 771573Srgrimes * only allocate it if necessary. 781573Srgrimes */ 791573Srgrimes struct vmstate *vmst; 80170772Ssimokawa int rawdump; /* raw dump format */ 81195838Sbz 82195838Sbz int vnet_initialized; /* vnet fields set up */ 83291406Sjhb kvaddr_t vnet_start; /* start of kernel's vnet region */ 84291406Sjhb kvaddr_t vnet_stop; /* stop of kernel's vnet region */ 85291406Sjhb kvaddr_t vnet_current; /* vnet we're working with */ 86291406Sjhb kvaddr_t vnet_base; /* vnet base of current vnet */ 87204494Srwatson 88204494Srwatson /* 89204494Srwatson * Dynamic per-CPU kernel memory. We translate symbols, on-demand, 90204494Srwatson * to the data associated with dpcpu_curcpu, set with 91204494Srwatson * kvm_dpcpu_setcpu(). 92204494Srwatson */ 93204494Srwatson int dpcpu_initialized; /* dpcpu fields set up */ 94291406Sjhb kvaddr_t dpcpu_start; /* start of kernel's dpcpu region */ 95291406Sjhb kvaddr_t dpcpu_stop; /* stop of kernel's dpcpu region */ 96204494Srwatson u_int dpcpu_maxcpus; /* size of base array */ 97204494Srwatson uintptr_t *dpcpu_off; /* base array, indexed by CPU ID */ 98204494Srwatson u_int dpcpu_curcpu; /* CPU we're currently working with */ 99291406Sjhb kvaddr_t dpcpu_curoff; /* dpcpu base of current CPU */ 1001573Srgrimes}; 1011573Srgrimes 1021573Srgrimes/* 103291406Sjhb * Page table hash used by minidump backends to map physical addresses 104291406Sjhb * to file offsets. 105291406Sjhb */ 106291406Sjhbstruct hpte { 107291406Sjhb struct hpte *next; 108291406Sjhb uint64_t pa; 109291406Sjhb off_t off; 110291406Sjhb}; 111291406Sjhb 112291406Sjhb#define HPT_SIZE 1024 113291406Sjhb 114291406Sjhbstruct hpt { 115291406Sjhb struct hpte *hpt_head[HPT_SIZE]; 116291406Sjhb}; 117291406Sjhb 118291406Sjhb/* 1191573Srgrimes * Functions used internally by kvm, but across kvm modules. 1201573Srgrimes */ 121291406Sjhbstatic inline uint32_t 122291406Sjhb_kvm32toh(kvm_t *kd, uint32_t val) 123291406Sjhb{ 124291406Sjhb 125291406Sjhb if (kd->nlehdr.e_ident[EI_DATA] == ELFDATA2LSB) 126291406Sjhb return (le32toh(val)); 127291406Sjhb else 128291406Sjhb return (be32toh(val)); 129291406Sjhb} 130291406Sjhb 131291406Sjhbstatic inline uint64_t 132291406Sjhb_kvm64toh(kvm_t *kd, uint64_t val) 133291406Sjhb{ 134291406Sjhb 135291406Sjhb if (kd->nlehdr.e_ident[EI_DATA] == ELFDATA2LSB) 136291406Sjhb return (le64toh(val)); 137291406Sjhb else 138291406Sjhb return (be64toh(val)); 139291406Sjhb} 140291406Sjhb 14192941Sobrienvoid _kvm_err(kvm_t *kd, const char *program, const char *fmt, ...) 14292941Sobrien __printflike(3, 4); 14392917Sobrienvoid _kvm_freeprocs(kvm_t *kd); 14492917Sobrienvoid *_kvm_malloc(kvm_t *kd, size_t); 145291406Sjhbint _kvm_nlist(kvm_t *, struct kvm_nlist *, int); 14692917Sobrienvoid *_kvm_realloc(kvm_t *kd, void *, size_t); 14792941Sobrienvoid _kvm_syserr (kvm_t *kd, const char *program, const char *fmt, ...) 14892941Sobrien __printflike(3, 4); 149195838Sbzint _kvm_vnet_selectpid(kvm_t *, pid_t); 150195838Sbzint _kvm_vnet_initialized(kvm_t *, int); 151291406Sjhbkvaddr_t _kvm_vnet_validaddr(kvm_t *, kvaddr_t); 152204494Srwatsonint _kvm_dpcpu_initialized(kvm_t *, int); 153291406Sjhbkvaddr_t _kvm_dpcpu_validaddr(kvm_t *, kvaddr_t); 154291406Sjhbint _kvm_probe_elf_kernel(kvm_t *, int, int); 155291406Sjhbint _kvm_is_minidump(kvm_t *); 156291406Sjhbint _kvm_read_core_phdrs(kvm_t *, size_t *, GElf_Phdr **); 157291406Sjhbvoid _kvm_hpt_init(kvm_t *, struct hpt *, void *, size_t, off_t, int, int); 158291406Sjhboff_t _kvm_hpt_find(struct hpt *, uint64_t); 159291406Sjhbvoid _kvm_hpt_free(struct hpt *); 160