Home | History | Annotate | Line # | Download | only in common
      1 /*	$NetBSD: compat_43_mod.c,v 1.3 2019/01/28 15:46:49 christos Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2018 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software developed for The NetBSD Foundation
      8  * by Paul Goyette
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  * POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 #include <sys/cdefs.h>
     33 __KERNEL_RCSID(0, "$NetBSD: compat_43_mod.c,v 1.3 2019/01/28 15:46:49 christos Exp $");
     34 
     35 #if defined(_KERNEL_OPT)
     36 #include "opt_compat_netbsd.h"
     37 #endif
     38 
     39 #include <sys/systm.h>
     40 #include <sys/module.h>
     41 #include <sys/sysctl.h>
     42 #include <sys/syscall.h>
     43 #include <sys/syscallvar.h>
     44 #include <sys/syscallargs.h>
     45 
     46 #include <compat/common/compat_util.h>
     47 #include <compat/common/compat_mod.h>
     48 
     49 int
     50 compat_43_init(void)
     51 {
     52 	int error;
     53 
     54 	error = kern_exit_43_init();
     55 	if (error != 0)
     56 		return error;
     57 
     58 	error = kern_info_43_init();
     59 	if (error != 0)
     60 		goto out8;
     61 
     62 	error = kern_resource_43_init();
     63 	if (error != 0)
     64 		goto out7;
     65 
     66 	error = kern_sig_43_init();
     67 	if (error != 0)
     68 		goto out6;
     69 
     70 	error = kern_tty_43_init();
     71 	if (error != 0)
     72 		goto out5;
     73 
     74 	error = uipc_syscalls_43_init();
     75 	if (error != 0)
     76 		goto out4;
     77 
     78 	error = vfs_syscalls_43_init();
     79 	if (error != 0)
     80 		goto out3;
     81 
     82 	error = vm_43_init();
     83 	if (error != 0)
     84 		goto out2;
     85 
     86 	error = if_43_init();
     87 	if (error != 0)
     88 		goto out1;
     89 
     90 	return 0;
     91 
     92  out1:
     93 	vm_43_fini();
     94  out2:
     95 	vfs_syscalls_43_fini();
     96  out3:
     97 	uipc_syscalls_43_fini();
     98  out4:
     99 	kern_tty_43_fini();
    100  out5:
    101 	kern_sig_43_fini();
    102  out6:
    103 	kern_resource_43_fini();
    104  out7:
    105 	kern_info_43_fini();
    106  out8:
    107 	kern_exit_43_fini();
    108 
    109 	return error;
    110 }
    111 
    112 int
    113 compat_43_fini(void)
    114 {
    115 	int error;
    116 
    117 	error = if_43_fini();
    118 	if (error != 0)
    119 		return error;
    120 
    121 	error = vm_43_fini();
    122 	if (error != 0)
    123 		goto out8;
    124 
    125 	error = vfs_syscalls_43_fini();
    126 	if (error != 0)
    127 		goto out7;
    128 
    129 	error = uipc_syscalls_43_fini();
    130 	if (error != 0)
    131 		goto out6;
    132 
    133 	error = kern_tty_43_fini();
    134 	if (error != 0)
    135 		goto out5;
    136 
    137 	error = kern_sig_43_fini();
    138 	if (error != 0)
    139 		goto out4;
    140 
    141 	error = kern_resource_43_fini();
    142 	if (error != 0)
    143 		goto out3;
    144 
    145 	error = kern_info_43_fini();
    146 	if (error != 0)
    147 		goto out2;
    148 
    149 	error = kern_exit_43_fini();
    150 	if (error != 0)
    151 		goto out1;
    152 
    153 	return 0;
    154 
    155  out1:
    156 	kern_info_43_init();
    157  out2:
    158 	kern_resource_43_init();
    159  out3:
    160 	kern_sig_43_init();
    161  out4:
    162 	kern_tty_43_init();
    163  out5:
    164 	uipc_syscalls_43_init();
    165  out6:
    166 	vfs_syscalls_43_init();
    167  out7:
    168 	vm_43_init();
    169  out8:
    170 	if_43_init();
    171 
    172 	return error;
    173 }
    174 
    175 /*
    176  * XXX We "require" the compat_60 module to ensure proper ordering of
    177  * XXX vectoring the ttcompatvec replacement routine!
    178  */
    179 MODULE(MODULE_CLASS_EXEC, compat_43,
    180     "compat_sysctl_09_43,compat_util,compat_60");
    181 
    182 static int
    183 compat_43_modcmd(modcmd_t cmd, void *arg)
    184 {
    185 
    186 	switch (cmd) {
    187 	case MODULE_CMD_INIT:
    188 		return compat_43_init();
    189 	case MODULE_CMD_FINI:
    190 		return compat_43_fini();
    191 	default:
    192 		return ENOTTY;
    193 	}
    194 }
    195