Home | History | Annotate | Line # | Download | only in kern
core_netbsd.c revision 1.24
      1  1.24  pgoyette /*	$NetBSD: core_netbsd.c,v 1.24 2019/11/20 19:37:53 pgoyette Exp $	*/
      2   1.1   thorpej 
      3   1.1   thorpej /*
      4   1.1   thorpej  * Copyright (c) 1997 Charles D. Cranor and Washington University.
      5   1.1   thorpej  * Copyright (c) 1991, 1993 The Regents of the University of California.
      6   1.1   thorpej  * Copyright (c) 1988 University of Utah.
      7   1.1   thorpej  *
      8   1.1   thorpej  * All rights reserved.
      9   1.1   thorpej  *
     10   1.1   thorpej  * This code is derived from software contributed to Berkeley by
     11   1.1   thorpej  * the Systems Programming Group of the University of Utah Computer
     12   1.1   thorpej  * Science Department.
     13   1.1   thorpej  *
     14   1.1   thorpej  * Redistribution and use in source and binary forms, with or without
     15   1.1   thorpej  * modification, are permitted provided that the following conditions
     16   1.1   thorpej  * are met:
     17   1.1   thorpej  * 1. Redistributions of source code must retain the above copyright
     18   1.1   thorpej  *    notice, this list of conditions and the following disclaimer.
     19   1.1   thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     20   1.1   thorpej  *    notice, this list of conditions and the following disclaimer in the
     21   1.1   thorpej  *    documentation and/or other materials provided with the distribution.
     22  1.18     chuck  * 3. Neither the name of the University nor the names of its contributors
     23   1.1   thorpej  *    may be used to endorse or promote products derived from this software
     24   1.1   thorpej  *    without specific prior written permission.
     25   1.1   thorpej  *
     26   1.1   thorpej  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     27   1.1   thorpej  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     28   1.1   thorpej  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     29   1.1   thorpej  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     30   1.1   thorpej  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     31   1.1   thorpej  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     32   1.1   thorpej  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     33   1.1   thorpej  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     34   1.1   thorpej  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     35   1.1   thorpej  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     36   1.1   thorpej  * SUCH DAMAGE.
     37   1.1   thorpej  *
     38   1.1   thorpej  * from: Utah $Hdr: vm_unix.c 1.1 89/11/07$
     39   1.1   thorpej  *      @(#)vm_unix.c   8.1 (Berkeley) 6/11/93
     40   1.1   thorpej  * from: NetBSD: uvm_unix.c,v 1.25 2001/11/10 07:37:01 lukem Exp
     41   1.1   thorpej  */
     42   1.1   thorpej 
     43   1.1   thorpej /*
     44   1.1   thorpej  * core_netbsd.c: Support for the historic NetBSD core file format.
     45   1.1   thorpej  */
     46   1.1   thorpej 
     47   1.1   thorpej #include <sys/cdefs.h>
     48  1.24  pgoyette __KERNEL_RCSID(0, "$NetBSD: core_netbsd.c,v 1.24 2019/11/20 19:37:53 pgoyette Exp $");
     49   1.1   thorpej 
     50   1.1   thorpej #include <sys/param.h>
     51   1.1   thorpej #include <sys/systm.h>
     52  1.11      matt #include <sys/exec.h>
     53   1.1   thorpej #include <sys/proc.h>
     54   1.1   thorpej #include <sys/vnode.h>
     55   1.1   thorpej #include <sys/core.h>
     56  1.24  pgoyette #include <sys/module.h>
     57  1.24  pgoyette #include <sys/compat_stub.h>
     58  1.24  pgoyette #include <sys/signalvar.h>
     59   1.1   thorpej 
     60   1.2   thorpej #include <uvm/uvm_extern.h>
     61   1.2   thorpej 
     62  1.11      matt #ifndef CORENAME
     63  1.11      matt #define	CORENAME(x)	x
     64  1.11      matt #endif
     65  1.11      matt #ifdef COREINC
     66  1.11      matt #include COREINC
     67  1.11      matt #endif
     68  1.11      matt 
     69   1.2   thorpej struct coredump_state {
     70  1.20       dsl 	struct coredump_iostate *iocookie;
     71  1.11      matt 	struct CORENAME(core) core;
     72   1.2   thorpej };
     73   1.2   thorpej 
     74  1.21       dsl static int	CORENAME(coredump_writesegs_netbsd)(struct uvm_coredump_state *);
     75   1.1   thorpej 
     76   1.1   thorpej int
     77  1.24  pgoyette CORENAME(real_coredump_netbsd)(struct lwp *l, struct coredump_iostate *iocookie)
     78   1.1   thorpej {
     79   1.2   thorpej 	struct coredump_state cs;
     80  1.11      matt 	struct proc *p = l->l_proc;
     81  1.11      matt 	struct vmspace *vm = p->p_vmspace;
     82   1.2   thorpej 	int error;
     83   1.9     perry 
     84  1.20       dsl 	cs.iocookie = iocookie;
     85   1.2   thorpej 	cs.core.c_midmag = 0;
     86   1.2   thorpej 	strncpy(cs.core.c_name, p->p_comm, MAXCOMLEN);
     87   1.2   thorpej 	cs.core.c_nseg = 0;
     88  1.23     kamil 	cs.core.c_signo = p->p_sigctx.ps_info._signo;
     89  1.23     kamil 	cs.core.c_ucode = p->p_sigctx.ps_info._code;
     90   1.2   thorpej 	cs.core.c_cpusize = 0;
     91   1.2   thorpej 	cs.core.c_tsize = (u_long)ctob(vm->vm_tsize);
     92   1.2   thorpej 	cs.core.c_dsize = (u_long)ctob(vm->vm_dsize);
     93   1.2   thorpej 	cs.core.c_ssize = (u_long)round_page(ctob(vm->vm_ssize));
     94   1.1   thorpej 
     95  1.11      matt 	error = CORENAME(cpu_coredump)(l, NULL, &cs.core);
     96  1.11      matt 	if (error)
     97  1.11      matt 		return (error);
     98  1.24  pgoyette 	MODULE_HOOK_CALL(uvm_coredump_count_segs_hook, (p), 0, cs.core.c_nseg);
     99   1.1   thorpej 
    100  1.11      matt 	/* First write out the core header. */
    101  1.24  pgoyette 	MODULE_HOOK_CALL(coredump_write_hook, (iocookie, UIO_SYSSPACE, &cs.core,
    102  1.24  pgoyette 	    cs.core.c_hdrsize), ENOSYS, error);
    103   1.2   thorpej 	if (error)
    104   1.2   thorpej 		return (error);
    105   1.1   thorpej 
    106  1.11      matt 	/* Then the CPU specific stuff */
    107  1.11      matt 	error = CORENAME(cpu_coredump)(l, iocookie, &cs.core);
    108  1.11      matt 	if (error)
    109  1.11      matt 		return (error);
    110   1.1   thorpej 
    111  1.11      matt 	/* Finally, the address space dump */
    112  1.24  pgoyette 	MODULE_HOOK_CALL(uvm_coredump_walkmap_hook,
    113  1.24  pgoyette 	    (p, CORENAME(coredump_writesegs_netbsd), &cs), ENOSYS, error);
    114  1.24  pgoyette 
    115  1.24  pgoyette 	return error;
    116  1.11      matt }
    117  1.11      matt 
    118  1.12   thorpej static int
    119  1.21       dsl CORENAME(coredump_writesegs_netbsd)(struct uvm_coredump_state *us)
    120  1.11      matt {
    121  1.11      matt 	struct coredump_state *cs = us->cookie;
    122  1.11      matt 	struct CORENAME(coreseg) cseg;
    123   1.2   thorpej 	int flag, error;
    124   1.2   thorpej 
    125   1.2   thorpej 	if (us->flags & UVM_COREDUMP_STACK)
    126   1.2   thorpej 		flag = CORE_STACK;
    127   1.2   thorpej 	else
    128   1.2   thorpej 		flag = CORE_DATA;
    129   1.2   thorpej 
    130   1.2   thorpej 	/*
    131   1.2   thorpej 	 * Set up a new core file segment.
    132   1.2   thorpej 	 */
    133   1.2   thorpej 	CORE_SETMAGIC(cseg, CORESEGMAGIC, CORE_GETMID(cs->core), flag);
    134   1.2   thorpej 	cseg.c_addr = us->start;
    135  1.22       dsl 
    136  1.22       dsl 	if (us->start == us->realend)
    137  1.22       dsl 		/* Not really wanted, but counted... */
    138  1.22       dsl 		cseg.c_size = 0;
    139  1.22       dsl 	else
    140  1.22       dsl 		cseg.c_size = us->end - us->start;
    141   1.2   thorpej 
    142  1.24  pgoyette 	MODULE_HOOK_CALL(coredump_write_hook, (cs->iocookie, UIO_SYSSPACE,
    143  1.24  pgoyette 	    &cseg, cs->core.c_seghdrsize), ENOSYS, error);
    144   1.2   thorpej 	if (error)
    145   1.2   thorpej 		return (error);
    146   1.2   thorpej 
    147  1.24  pgoyette 	MODULE_HOOK_CALL(coredump_write_hook, (cs->iocookie, UIO_USERSPACE,
    148  1.24  pgoyette 	    (void *)(vaddr_t)us->start, cseg.c_size), ENOSYS, error);
    149  1.16        ad 
    150  1.24  pgoyette 	return error;
    151  1.16        ad }
    152