11.18Srin/*	$NetBSD: netbsd32_core.c,v 1.18 2020/11/08 07:30:09 rin Exp $	*/
21.1Sthorpej
31.1Sthorpej/*
41.1Sthorpej * Copyright (c) 1997 Charles D. Cranor and Washington University.
51.1Sthorpej * Copyright (c) 1991, 1993 The Regents of the University of California.
61.1Sthorpej * Copyright (c) 1988 University of Utah.
71.1Sthorpej *
81.1Sthorpej * All rights reserved.
91.1Sthorpej *
101.1Sthorpej * This code is derived from software contributed to Berkeley by
111.1Sthorpej * the Systems Programming Group of the University of Utah Computer
121.1Sthorpej * Science Department.
131.1Sthorpej *
141.1Sthorpej * Redistribution and use in source and binary forms, with or without
151.1Sthorpej * modification, are permitted provided that the following conditions
161.1Sthorpej * are met:
171.1Sthorpej * 1. Redistributions of source code must retain the above copyright
181.1Sthorpej *    notice, this list of conditions and the following disclaimer.
191.1Sthorpej * 2. Redistributions in binary form must reproduce the above copyright
201.1Sthorpej *    notice, this list of conditions and the following disclaimer in the
211.1Sthorpej *    documentation and/or other materials provided with the distribution.
221.14Schuck * 3. Neither the name of the University nor the names of its contributors
231.1Sthorpej *    may be used to endorse or promote products derived from this software
241.1Sthorpej *    without specific prior written permission.
251.1Sthorpej *
261.1Sthorpej * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
271.1Sthorpej * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
281.1Sthorpej * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
291.1Sthorpej * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
301.1Sthorpej * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
311.1Sthorpej * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
321.1Sthorpej * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
331.1Sthorpej * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
341.1Sthorpej * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
351.1Sthorpej * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
361.1Sthorpej * SUCH DAMAGE.
371.1Sthorpej *
381.1Sthorpej * from: Utah $Hdr: vm_unix.c 1.1 89/11/07$
391.1Sthorpej *      @(#)vm_unix.c   8.1 (Berkeley) 6/11/93
401.1Sthorpej * from: NetBSD: uvm_unix.c,v 1.25 2001/11/10 07:37:01 lukem Exp
411.1Sthorpej */
421.1Sthorpej
431.1Sthorpej/*
441.3Sthorpej * core_netbsd.c: Support for the historic NetBSD core file format.
451.1Sthorpej */
461.1Sthorpej
471.1Sthorpej#include <sys/cdefs.h>
481.18Srin__KERNEL_RCSID(0, "$NetBSD: netbsd32_core.c,v 1.18 2020/11/08 07:30:09 rin Exp $");
491.15Spgoyette
501.16Spgoyette#include <sys/compat_stub.h>
511.16Spgoyette#include <sys/exec_elf.h>
521.15Spgoyette#include <sys/lwp.h>
531.16Spgoyette#include <sys/module.h>
541.16Spgoyette
551.17Spgoyette#ifdef _KERNEL_OPT
561.17Spgoyette#include "opt_execfmt.h"
571.17Spgoyette#endif
581.17Spgoyette
591.16Spgoyette#define DEPS "compat_netbsd32,compat_netbsd32_ptrace,coredump"
601.16Spgoyette
611.16SpgoyetteMODULE(MODULE_CLASS_MISC, compat_netbsd32_coredump, DEPS);
621.1Sthorpej
631.12Smatt#define	CORENAME(x)	__CONCAT(x,32)
641.12Smatt#define	COREINC		<compat/netbsd32/netbsd32.h>
651.1Sthorpej
661.12Smatt#include "../../kern/core_netbsd.c"
671.15Spgoyette
681.16Spgoyettestatic int
691.16Spgoyettecompat_netbsd32_coredump_modcmd(modcmd_t cmd, void *arg)
701.15Spgoyette{
711.16Spgoyette
721.16Spgoyette	switch (cmd) {
731.16Spgoyette	case MODULE_CMD_INIT:
741.16Spgoyette		MODULE_HOOK_SET(coredump_netbsd32_hook, real_coredump_netbsd32);
751.18Srin#if defined(EXEC_ELF32) && defined(_LP64)
761.16Spgoyette		MODULE_HOOK_SET(coredump_elf32_hook, real_coredump_elf32);
771.17Spgoyette#endif
781.16Spgoyette		return 0;
791.16Spgoyette	case MODULE_CMD_FINI:
801.16Spgoyette		MODULE_HOOK_UNSET(coredump_netbsd32_hook);
811.18Srin#if defined(EXEC_ELF32) && defined(_LP64)
821.16Spgoyette		MODULE_HOOK_UNSET(coredump_elf32_hook);
831.17Spgoyette#endif
841.16Spgoyette		return 0;
851.16Spgoyette	default:
861.16Spgoyette		return ENOTTY;
871.16Spgoyette	}
881.15Spgoyette}
89