1 /* $NetBSD: core_machdep.c,v 1.9 2024/09/08 09:36:50 rillig Exp $ */ 2 3 /* 4 * Copyright (c) 1994 Ludd, University of Lule}, Sweden. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 */ 27 28 #include <sys/cdefs.h> 29 __KERNEL_RCSID(0, "$NetBSD: core_machdep.c,v 1.9 2024/09/08 09:36:50 rillig Exp $"); 30 31 #include <sys/param.h> 32 #include <sys/systm.h> 33 #include <sys/proc.h> 34 #include <sys/exec.h> 35 #include <sys/core.h> 36 #include <sys/compat_stub.h> 37 38 #include <sys/exec_aout.h> 39 40 #include <machine/pcb.h> 41 #include <machine/frame.h> 42 43 /* 44 * Dump the machine specific header information at the start of a core dump. 45 * First put all regs in PCB for debugging purposes. This is not a good 46 * way to do this, but good for my purposes so far. 47 */ 48 int 49 cpu_coredump(struct lwp *l, struct coredump_iostate *iocookie, 50 struct core *chdr) 51 { 52 struct md_coredump md_core; 53 struct coreseg cseg; 54 int error; 55 56 if (iocookie == NULL) { 57 CORE_SETMAGIC(*chdr, COREMAGIC, MID_MACHINE, 0); 58 chdr->c_hdrsize = sizeof(struct core); 59 chdr->c_seghdrsize = sizeof(struct coreseg); 60 chdr->c_cpusize = sizeof(struct md_coredump); 61 chdr->c_nseg++; 62 return 0; 63 } 64 65 md_core.md_tf = *l->l_md.md_utf; /*XXX*/ 66 67 CORE_SETMAGIC(cseg, CORESEGMAGIC, MID_MACHINE, CORE_CPU); 68 cseg.c_addr = 0; 69 cseg.c_size = chdr->c_cpusize; 70 71 MODULE_HOOK_CALL(coredump_write_hook, (iocookie, UIO_SYSSPACE, &cseg, 72 chdr->c_seghdrsize), ENOSYS, error); 73 if (error) 74 return error; 75 76 MODULE_HOOK_CALL(coredump_write_hook, (iocookie, UIO_SYSSPACE, &md_core, 77 sizeof(md_core)), ENOSYS, error); 78 79 return error; 80 } 81