linux32_mod.c revision 1.2.6.2 1 1.2.6.2 mjf /* $NetBSD: linux32_mod.c,v 1.2.6.2 2009/01/17 13:28:45 mjf Exp $ */
2 1.2.6.2 mjf
3 1.2.6.2 mjf /*-
4 1.2.6.2 mjf * Copyright (c) 2008 The NetBSD Foundation, Inc.
5 1.2.6.2 mjf * All rights reserved.
6 1.2.6.2 mjf *
7 1.2.6.2 mjf * This code is derived from software developed for The NetBSD Foundation
8 1.2.6.2 mjf * by Andrew Doran.
9 1.2.6.2 mjf *
10 1.2.6.2 mjf * Redistribution and use in source and binary forms, with or without
11 1.2.6.2 mjf * modification, are permitted provided that the following conditions
12 1.2.6.2 mjf * are met:
13 1.2.6.2 mjf * 1. Redistributions of source code must retain the above copyright
14 1.2.6.2 mjf * notice, this list of conditions and the following disclaimer.
15 1.2.6.2 mjf * 2. Redistributions in binary form must reproduce the above copyright
16 1.2.6.2 mjf * notice, this list of conditions and the following disclaimer in the
17 1.2.6.2 mjf * documentation and/or other materials provided with the distribution.
18 1.2.6.2 mjf *
19 1.2.6.2 mjf * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.2.6.2 mjf * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.2.6.2 mjf * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.2.6.2 mjf * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.2.6.2 mjf * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.2.6.2 mjf * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.2.6.2 mjf * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.2.6.2 mjf * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.2.6.2 mjf * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.2.6.2 mjf * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.2.6.2 mjf * POSSIBILITY OF SUCH DAMAGE.
30 1.2.6.2 mjf */
31 1.2.6.2 mjf
32 1.2.6.2 mjf #include <sys/cdefs.h>
33 1.2.6.2 mjf __KERNEL_RCSID(0, "$NetBSD: linux32_mod.c,v 1.2.6.2 2009/01/17 13:28:45 mjf Exp $");
34 1.2.6.2 mjf
35 1.2.6.2 mjf #ifdef _KERNEL_OPT
36 1.2.6.2 mjf #include "opt_execfmt.h"
37 1.2.6.2 mjf #endif
38 1.2.6.2 mjf
39 1.2.6.2 mjf #ifndef ELFSIZE
40 1.2.6.2 mjf #define ELFSIZE ARCH_ELFSIZE
41 1.2.6.2 mjf #endif
42 1.2.6.2 mjf
43 1.2.6.2 mjf #include <sys/param.h>
44 1.2.6.2 mjf #include <sys/module.h>
45 1.2.6.2 mjf #include <sys/exec.h>
46 1.2.6.2 mjf #include <sys/signalvar.h>
47 1.2.6.2 mjf
48 1.2.6.2 mjf #include <compat/linux32/common/linux32_sysctl.h>
49 1.2.6.2 mjf #include <compat/linux32/common/linux32_exec.h>
50 1.2.6.2 mjf
51 1.2.6.2 mjf #if defined(EXEC_ELF32)
52 1.2.6.2 mjf # define MD1 ",exec_elf32,compat_netbsd32"
53 1.2.6.2 mjf #else
54 1.2.6.2 mjf # define MD1 ""
55 1.2.6.2 mjf #endif
56 1.2.6.2 mjf
57 1.2.6.2 mjf MODULE(MODULE_CLASS_MISC, compat_linux32, "compat_linux" MD1);
58 1.2.6.2 mjf
59 1.2.6.2 mjf static struct execsw linux32_execsw[] = {
60 1.2.6.2 mjf #if defined(EXEC_ELF32)
61 1.2.6.2 mjf { sizeof (Elf32_Ehdr),
62 1.2.6.2 mjf exec_elf32_makecmds,
63 1.2.6.2 mjf { linux32_elf32_probe },
64 1.2.6.2 mjf &emul_linux32,
65 1.2.6.2 mjf EXECSW_PRIO_FIRST,
66 1.2.6.2 mjf LINUX32_ELF_AUX_ARGSIZ,
67 1.2.6.2 mjf linux32_elf32_copyargs,
68 1.2.6.2 mjf NULL,
69 1.2.6.2 mjf coredump_elf32,
70 1.2.6.2 mjf exec_setup_stack },
71 1.2.6.2 mjf #endif
72 1.2.6.2 mjf };
73 1.2.6.2 mjf
74 1.2.6.2 mjf static int
75 1.2.6.2 mjf compat_linux32_modcmd(modcmd_t cmd, void *arg)
76 1.2.6.2 mjf {
77 1.2.6.2 mjf int error;
78 1.2.6.2 mjf
79 1.2.6.2 mjf switch (cmd) {
80 1.2.6.2 mjf case MODULE_CMD_INIT:
81 1.2.6.2 mjf linux32_sysctl_init();
82 1.2.6.2 mjf error = exec_add(linux32_execsw,
83 1.2.6.2 mjf __arraycount(linux32_execsw));
84 1.2.6.2 mjf if (error != 0)
85 1.2.6.2 mjf linux32_sysctl_fini();
86 1.2.6.2 mjf return error;
87 1.2.6.2 mjf
88 1.2.6.2 mjf case MODULE_CMD_FINI:
89 1.2.6.2 mjf error = exec_remove(linux32_execsw,
90 1.2.6.2 mjf __arraycount(linux32_execsw));
91 1.2.6.2 mjf if (error == 0)
92 1.2.6.2 mjf linux32_sysctl_fini();
93 1.2.6.2 mjf return error;
94 1.2.6.2 mjf
95 1.2.6.2 mjf default:
96 1.2.6.2 mjf return ENOTTY;
97 1.2.6.2 mjf }
98 1.2.6.2 mjf }
99