1*e1cb6e2eSjsg /* $OpenBSD: kvm_private.h,v 1.27 2024/05/21 11:13:08 jsg Exp $ */ 25a9ac2daSderaadt /* $NetBSD: kvm_private.h,v 1.7 1996/05/05 04:32:15 gwr Exp $ */ 33fbbad10Sniklas 4df930be7Sderaadt /*- 5df930be7Sderaadt * Copyright (c) 1992, 1993 6df930be7Sderaadt * The Regents of the University of California. All rights reserved. 7df930be7Sderaadt * 8df930be7Sderaadt * This code is derived from software developed by the Computer Systems 9df930be7Sderaadt * Engineering group at Lawrence Berkeley Laboratory under DARPA contract 10df930be7Sderaadt * BG 91-66 and contributed to Berkeley. 11df930be7Sderaadt * 12df930be7Sderaadt * Redistribution and use in source and binary forms, with or without 13df930be7Sderaadt * modification, are permitted provided that the following conditions 14df930be7Sderaadt * are met: 15df930be7Sderaadt * 1. Redistributions of source code must retain the above copyright 16df930be7Sderaadt * notice, this list of conditions and the following disclaimer. 17df930be7Sderaadt * 2. Redistributions in binary form must reproduce the above copyright 18df930be7Sderaadt * notice, this list of conditions and the following disclaimer in the 19df930be7Sderaadt * documentation and/or other materials provided with the distribution. 206580fee3Smillert * 3. Neither the name of the University nor the names of its contributors 21df930be7Sderaadt * may be used to endorse or promote products derived from this software 22df930be7Sderaadt * without specific prior written permission. 23df930be7Sderaadt * 24df930be7Sderaadt * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 25df930be7Sderaadt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26df930be7Sderaadt * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27df930be7Sderaadt * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 28df930be7Sderaadt * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29df930be7Sderaadt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30df930be7Sderaadt * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31df930be7Sderaadt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32df930be7Sderaadt * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33df930be7Sderaadt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34df930be7Sderaadt * SUCH DAMAGE. 35df930be7Sderaadt * 36df930be7Sderaadt * @(#)kvm_private.h 8.1 (Berkeley) 6/4/93 37df930be7Sderaadt */ 38df930be7Sderaadt 39df930be7Sderaadt struct __kvm { 40df930be7Sderaadt /* 41df930be7Sderaadt * a string to be prepended to error messages 42df930be7Sderaadt * provided for compatibility with sun's interface 43df930be7Sderaadt * if this value is null, errors are saved in errbuf[] 44df930be7Sderaadt */ 45df930be7Sderaadt const char *program; 46df930be7Sderaadt char errbuf[_POSIX2_LINE_MAX]; 47df930be7Sderaadt DB *db; 48df930be7Sderaadt int pmfd; /* physical memory file (or crashdump) */ 49df930be7Sderaadt int vmfd; /* virtual memory file (-1 if crashdump) */ 50df930be7Sderaadt int swfd; /* swap file (e.g., /dev/drum) */ 51df930be7Sderaadt int nlfd; /* namelist file (e.g., /vmunix) */ 52df930be7Sderaadt struct kinfo_proc *procbase; 539dc8fca8Smillert struct kinfo_file *filebase; 54df930be7Sderaadt int nbpg; /* page size */ 55df930be7Sderaadt char *swapspc; /* (dynamic) storage for swapped pages */ 5659133b9fSzhuk 57df930be7Sderaadt char *argspc, *argbuf; /* (dynamic) storage for argv strings */ 58df930be7Sderaadt int arglen; /* length of the above */ 59df930be7Sderaadt char **argv; /* (dynamic) storage for argv pointers */ 60df930be7Sderaadt int argc; /* length of above (not actual # present) */ 613fbbad10Sniklas 6259133b9fSzhuk char *envspc, *envbuf; /* (dynamic) storage for environ strings */ 6359133b9fSzhuk int envlen; /* length of the above */ 6459133b9fSzhuk char **envp; /* (dynamic) storage for environ pointers */ 6559133b9fSzhuk int envc; /* length of above (not actual # present) */ 6659133b9fSzhuk 673fbbad10Sniklas /* 683fbbad10Sniklas * Header structures for kernel dumps. Only gets filled in for 693fbbad10Sniklas * dead kernels. 703fbbad10Sniklas */ 713fbbad10Sniklas struct kcore_hdr *kcore_hdr; 725a9ac2daSderaadt size_t cpu_dsize; 735a9ac2daSderaadt void *cpu_data; 743fbbad10Sniklas off_t dump_off; /* Where the actual dump starts */ 753fbbad10Sniklas 76df930be7Sderaadt /* 77df930be7Sderaadt * Kernel virtual address translation state. This only gets filled 78df930be7Sderaadt * in for dead kernels; otherwise, the running kernel (i.e. kmem) 79df930be7Sderaadt * will do the translations for us. It could be big, so we 80df930be7Sderaadt * only allocate it if necessary. 81df930be7Sderaadt */ 823fbbad10Sniklas struct vmstate *vmst; /* XXX: should become obsoleted */ 83df930be7Sderaadt /* 84df930be7Sderaadt * These kernel variables are used for looking up user addresses, 85df930be7Sderaadt * and are cached for efficiency. 86df930be7Sderaadt */ 87df930be7Sderaadt struct pglist *vm_page_buckets; 88df930be7Sderaadt int vm_page_hash_mask; 892d420eafSart int alive; /* Dead or alive. */ 902d420eafSart #define ISALIVE(kd) ((kd)->alive) 91df930be7Sderaadt }; 92df930be7Sderaadt 9343a9ad52Smillert #define KREAD(kd, addr, obj) \ 9443a9ad52Smillert (kvm_read(kd, addr, (void *)(obj), sizeof(*obj)) != sizeof(*obj)) 9543a9ad52Smillert 96df930be7Sderaadt /* 97df930be7Sderaadt * Functions used internally by kvm, but across kvm modules. 98df930be7Sderaadt */ 993e334d28Sguenther __BEGIN_HIDDEN_DECLS 100b3c702ccSguenther void _kvm_err(kvm_t *kd, const char *program, const char *fmt, ...) 101b3c702ccSguenther __attribute__((__format__ (printf, 3, 4))); 102c72b5b24Smillert void _kvm_freevtop(kvm_t *); 103c72b5b24Smillert int _kvm_initvtop(kvm_t *); 104fdd3f45bSmickey int _kvm_kvatop(kvm_t *, u_long, paddr_t *); 105c72b5b24Smillert void *_kvm_malloc(kvm_t *kd, size_t); 10653e67138Sdlg void *_kvm_realloc(kvm_t *kd, void *, size_t); 107fdd3f45bSmickey off_t _kvm_pa2off(kvm_t *, paddr_t); 108f4ccacb3Sderaadt void *_kvm_reallocarray(kvm_t *kd, void *, size_t, size_t); 109e331da57Sguenther void _kvm_syserr(kvm_t *kd, const char *program, const char *fmt, ...) 110e331da57Sguenther __attribute__((__format__ (printf, 3, 4))); 1119db2f38bSderaadt ssize_t _kvm_pread(kvm_t *, int, void *, size_t, off_t); 1129db2f38bSderaadt ssize_t _kvm_pwrite(kvm_t *, int, const void *, size_t, off_t); 1133e334d28Sguenther __END_HIDDEN_DECLS 114cfd60b50Sguenther 115cfd60b50Sguenther 116cfd60b50Sguenther #define PROTO(x) __dso_hidden typeof(x) x asm("__"#x) 117cfd60b50Sguenther #define DEF(x) __strong_alias(x, __##x) 118cfd60b50Sguenther 119cfd60b50Sguenther PROTO(kvm_close); 120cfd60b50Sguenther PROTO(kvm_nlist); 121cfd60b50Sguenther PROTO(kvm_read); 122