xref: /netbsd-src/sys/compat/sunos32/sunos32_mod.c (revision 8a031a1d1e0aac23d43015c71ae6350b917c8347)
1*8a031a1dSpgoyette /*	$NetBSD: sunos32_mod.c,v 1.7 2019/12/12 02:15:42 pgoyette Exp $	*/
292ce8c6aSad 
392ce8c6aSad /*-
492ce8c6aSad  * Copyright (c) 2008 The NetBSD Foundation, Inc.
592ce8c6aSad  * All rights reserved.
692ce8c6aSad  *
792ce8c6aSad  * This code is derived from software developed for The NetBSD Foundation
892ce8c6aSad  * by Andrew Doran.
992ce8c6aSad  *
1092ce8c6aSad  * Redistribution and use in source and binary forms, with or without
1192ce8c6aSad  * modification, are permitted provided that the following conditions
1292ce8c6aSad  * are met:
1392ce8c6aSad  * 1. Redistributions of source code must retain the above copyright
1492ce8c6aSad  *    notice, this list of conditions and the following disclaimer.
1592ce8c6aSad  * 2. Redistributions in binary form must reproduce the above copyright
1692ce8c6aSad  *    notice, this list of conditions and the following disclaimer in the
1792ce8c6aSad  *    documentation and/or other materials provided with the distribution.
1892ce8c6aSad  *
1992ce8c6aSad  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2092ce8c6aSad  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2192ce8c6aSad  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2292ce8c6aSad  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2392ce8c6aSad  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2492ce8c6aSad  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2592ce8c6aSad  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2692ce8c6aSad  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2792ce8c6aSad  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2892ce8c6aSad  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2992ce8c6aSad  * POSSIBILITY OF SUCH DAMAGE.
3092ce8c6aSad  */
3192ce8c6aSad 
3292ce8c6aSad #include <sys/cdefs.h>
33*8a031a1dSpgoyette __KERNEL_RCSID(0, "$NetBSD: sunos32_mod.c,v 1.7 2019/12/12 02:15:42 pgoyette Exp $");
3492ce8c6aSad 
3592ce8c6aSad #include <sys/param.h>
3692ce8c6aSad #include <sys/module.h>
3792ce8c6aSad #include <sys/exec.h>
3892ce8c6aSad #include <sys/exec_aout.h>
3992ce8c6aSad #include <sys/signalvar.h>
40d91f98a8Spgoyette #include <sys/compat_stub.h>
4192ce8c6aSad 
4292ce8c6aSad #include <machine/sunos_machdep.h>
4392ce8c6aSad 
4492ce8c6aSad #include <compat/sunos32/sunos32_exec.h>
4592ce8c6aSad 
4692ce8c6aSad #include <compat/netbsd32/netbsd32_exec.h>
4792ce8c6aSad 
48d91f98a8Spgoyette MODULE(MODULE_CLASS_EXEC, compat_sunos,
49ffe81881Spgoyette     "compat_09,compat_util,compat_netbsd32,exec_aout");
5092ce8c6aSad 
5154b7adb1Schristos static struct execsw sunos_execsw = {
5254b7adb1Schristos 	.es_hdrsz = SUNOS32_AOUT_HDR_SIZE,
5354b7adb1Schristos 	.es_makecmds = exec_sunos32_aout_makecmds,
5454b7adb1Schristos 	.u = {
5554b7adb1Schristos 		.elf_probe_func = NULL,
5654b7adb1Schristos 	},
5754b7adb1Schristos 	.es_emul = &emul_sunos,
5854b7adb1Schristos 	.es_prio = EXECSW_PRIO_ANY,
5954b7adb1Schristos 	.es_arglen = 0,
6054b7adb1Schristos 	.es_copyargs = netbsd32_copyargs,
6154b7adb1Schristos 	.es_setregs = NULL,
6254b7adb1Schristos 	.es_coredump = coredump_netbsd,
6354b7adb1Schristos 	.es_setup_stack = exec_setup_stack,
6492ce8c6aSad };
6592ce8c6aSad 
6692ce8c6aSad static int
get_sunos_emul(const struct emul ** e)67d91f98a8Spgoyette get_sunos_emul(const struct emul **e)
68d91f98a8Spgoyette {
69d91f98a8Spgoyette 
70d91f98a8Spgoyette 	*e = &emul_sunos;
71d91f98a8Spgoyette 	return 0;
72d91f98a8Spgoyette }
73d91f98a8Spgoyette 
74d91f98a8Spgoyette static int
compat_sunos_modcmd(modcmd_t cmd,void * arg)7592ce8c6aSad compat_sunos_modcmd(modcmd_t cmd, void *arg)
7692ce8c6aSad {
7792ce8c6aSad 
7892ce8c6aSad 	switch (cmd) {
7992ce8c6aSad 	case MODULE_CMD_INIT:
80*8a031a1dSpgoyette 		MODULE_HOOK_SET(get_emul_sunos_hook, get_sunos_emul);
8154b7adb1Schristos 		return exec_add(&sunos_execsw, 1);
8292ce8c6aSad 
8392ce8c6aSad 	case MODULE_CMD_FINI:
848c2f80f1Spgoyette 		MODULE_HOOK_UNSET(get_emul_sunos_hook);
8554b7adb1Schristos 		return exec_remove(&sunos_execsw, 1);
8692ce8c6aSad 
8792ce8c6aSad 	default:
8892ce8c6aSad 		return ENOTTY;
8992ce8c6aSad 	}
9092ce8c6aSad }
91