freebsd_mod.c revision 1.4
11.4Schristos/* $NetBSD: freebsd_mod.c,v 1.4 2014/03/07 01:33:43 christos Exp $ */ 21.1Sad 31.1Sad/*- 41.1Sad * Copyright (c) 2008 The NetBSD Foundation, Inc. 51.1Sad * All rights reserved. 61.1Sad * 71.1Sad * This code is derived from software developed for The NetBSD Foundation 81.1Sad * by Andrew Doran. 91.1Sad * 101.1Sad * Redistribution and use in source and binary forms, with or without 111.1Sad * modification, are permitted provided that the following conditions 121.1Sad * are met: 131.1Sad * 1. Redistributions of source code must retain the above copyright 141.1Sad * notice, this list of conditions and the following disclaimer. 151.1Sad * 2. Redistributions in binary form must reproduce the above copyright 161.1Sad * notice, this list of conditions and the following disclaimer in the 171.1Sad * documentation and/or other materials provided with the distribution. 181.1Sad * 191.1Sad * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 201.1Sad * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 211.1Sad * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 221.1Sad * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 231.1Sad * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 241.1Sad * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 251.1Sad * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 261.1Sad * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 271.1Sad * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 281.1Sad * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 291.1Sad * POSSIBILITY OF SUCH DAMAGE. 301.1Sad */ 311.1Sad 321.1Sad#include <sys/cdefs.h> 331.4Schristos__KERNEL_RCSID(0, "$NetBSD: freebsd_mod.c,v 1.4 2014/03/07 01:33:43 christos Exp $"); 341.1Sad 351.1Sad#ifdef _KERNEL_OPT 361.1Sad#include "opt_execfmt.h" 371.1Sad#endif 381.1Sad 391.1Sad#include <sys/param.h> 401.1Sad#include <sys/module.h> 411.1Sad#include <sys/exec.h> 421.1Sad#include <sys/exec_elf.h> 431.2Smartin#include <sys/exec_aout.h> 441.1Sad#include <sys/signalvar.h> 451.1Sad 461.1Sad#include <compat/freebsd/freebsd_exec.h> 471.1Sad#include <compat/freebsd/freebsd_sysctl.h> 481.1Sad 491.1Sad#if defined(EXEC_ELF32) 501.1Sad# define MD1 ",exec_elf32" 511.1Sad#else 521.1Sad# define MD1 "" 531.1Sad#endif 541.1Sad#if defined(EXEC_AOUT) 551.1Sad# define MD2 ",exec_aout" 561.1Sad#else 571.1Sad# define MD2 "" 581.1Sad#endif 591.1Sad 601.1Sad#define ELF32_AUXSIZE (howmany(ELF_AUX_ENTRIES * sizeof(Aux32Info), \ 611.1Sad sizeof(Elf32_Addr)) + MAXPATHLEN + ALIGN(1)) 621.1Sad 631.3SchristosMODULE(MODULE_CLASS_EXEC, compat_freebsd, "compat,compat_ossaudio" MD1 MD2); 641.1Sad 651.1Sadstatic struct execsw freebsd_execsw[] = { 661.1Sad#ifdef EXEC_ELF32 671.1Sad /* FreeBSD Elf32 (probe not 64-bit safe) */ 681.4Schristos { 691.4Schristos .es_hdrsz = sizeof (Elf32_Ehdr), 701.4Schristos .es_makecmds = exec_elf32_makecmds, 711.4Schristos .u = { 721.4Schristos .elf_probe_func = freebsd_elf32_probe, 731.4Schristos }, 741.4Schristos .es_emul = &emul_freebsd, 751.4Schristos .es_prio = EXECSW_PRIO_ANY, 761.4Schristos .es_arglen = ELF32_AUXSIZE, 771.4Schristos .es_copyargs = elf32_copyargs, 781.4Schristos .es_setregs = NULL, 791.4Schristos .es_coredump = coredump_elf32, 801.4Schristos .es_setup_stack = exec_setup_stack, 811.4Schristos }, 821.1Sad#endif 831.1Sad#ifdef EXEC_AOUT 841.1Sad /* FreeBSD a.out (native word size) */ 851.4Schristos { 861.4Schristos .es_hdrsz = FREEBSD_AOUT_HDR_SIZE, 871.4Schristos .es_makecmds = exec_freebsd_aout_makecmds, 881.4Schristos .u = { 891.4Schristos .elf_probe_function = NULL, 901.4Schristos }, 911.4Schristos .es_emul = &emul_freebsd, 921.4Schristos .es_prio = EXECSW_PRIO_ANY, 931.4Schristos .es_arglen = 0, 941.4Schristos .es_copyargs = copyargs, 951.4Schristos .se_setregs = NULL, 961.4Schristos .es_coredump = coredump_netbsd, 971.4Schristos .es_setup_stack = exec_setup_stack, 981.4Schristos }, 991.1Sad#endif 1001.1Sad}; 1011.1Sad 1021.1Sadstatic int 1031.1Sadcompat_freebsd_modcmd(modcmd_t cmd, void *arg) 1041.1Sad{ 1051.1Sad int error; 1061.1Sad 1071.1Sad switch (cmd) { 1081.1Sad case MODULE_CMD_INIT: 1091.1Sad freebsd_sysctl_init(); 1101.1Sad error = exec_add(freebsd_execsw, 1111.1Sad __arraycount(freebsd_execsw)); 1121.1Sad if (error != 0) 1131.1Sad freebsd_sysctl_fini(); 1141.1Sad return error; 1151.1Sad 1161.1Sad case MODULE_CMD_FINI: 1171.1Sad error = exec_remove(freebsd_execsw, 1181.1Sad __arraycount(freebsd_execsw)); 1191.1Sad if (error == 0) 1201.1Sad freebsd_sysctl_fini(); 1211.1Sad return error; 1221.1Sad 1231.1Sad default: 1241.1Sad return ENOTTY; 1251.1Sad } 1261.1Sad} 127