1 /* $NetBSD: compat_50_mod.c,v 1.4 2021/12/10 20:36:03 andvar 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 /*
33 * Linkage for the compat module: spaghetti.
34 */
35
36 #include <sys/cdefs.h>
37 __KERNEL_RCSID(0, "$NetBSD: compat_50_mod.c,v 1.4 2021/12/10 20:36:03 andvar Exp $");
38
39 #if defined(_KERNEL_OPT)
40 #include "opt_compat_netbsd.h"
41 #endif
42
43 #include <sys/systm.h>
44 #include <sys/module.h>
45 #include <sys/sysctl.h>
46 #include <sys/syscall.h>
47 #include <sys/syscallvar.h>
48 #include <sys/syscallargs.h>
49
50 #include <compat/sys/clockctl.h>
51
52 #include <compat/common/compat_util.h>
53 #include <compat/common/compat_mod.h>
54 #include <compat/common/if_spppsubr50.h>
55
56 #include <dev/wscons/wsevent_50.h>
57
58 #include <fs/puffs/puffs_sys.h>
59
60 int
compat_50_init(void)61 compat_50_init(void)
62 {
63 int error = 0;
64
65 error = kern_50_init();
66 if (error != 0)
67 return error;
68
69 error = kern_time_50_init();
70 if (error != 0)
71 goto err1;
72
73 error = kern_select_50_init();
74 if (error != 0)
75 goto err2;
76
77 error = vfs_syscalls_50_init();
78 if (error != 0)
79 goto err3;
80
81 uvm_50_init();
82 uipc_syscalls_50_init();
83 clockctl_50_init();
84 if_spppsubr_50_init();
85 puffs_50_init();
86 wsevent_50_init();
87 vnd_50_init();
88 rndpseudo_50_init();
89 rtsock_50_init();
90 kern_uipc_socket_50_init();
91
92 return error;
93
94 /* If an error occurred, undo all previous set-up before returning */
95
96 err3:
97 kern_select_50_fini();
98 err2:
99 kern_time_50_fini();
100 err1:
101 kern_50_fini();
102
103 return error;
104 }
105
106 int
compat_50_fini(void)107 compat_50_fini(void)
108 {
109 int error = 0;
110
111 kern_uipc_socket_50_fini();
112 rtsock_50_fini();
113 rndpseudo_50_fini();
114 vnd_50_fini();
115 wsevent_50_fini();
116 puffs_50_fini();
117 if_spppsubr_50_fini();
118 clockctl_50_fini();
119 uipc_syscalls_50_fini();
120 uvm_50_fini();
121
122 error = vfs_syscalls_50_fini();
123 if (error != 0)
124 goto err1;
125
126 error = kern_select_50_fini();
127 if (error != 0)
128 goto err2;
129
130 error = kern_time_50_fini();
131 if (error != 0)
132 goto err3;
133
134 error = kern_50_fini();
135 if (error != 0)
136 goto err4;
137
138 return error;
139
140 /* If an error occurred while removing something, restore everything! */
141 err4:
142 kern_time_50_init();
143 err3:
144 kern_select_50_init();
145 err2:
146 vfs_syscalls_50_init();
147 err1:
148 uvm_50_init();
149 uipc_syscalls_50_init();
150 clockctl_50_init();
151 if_spppsubr_50_init();
152 puffs_50_init();
153 wsevent_50_init();
154 vnd_50_init();
155 rndpseudo_50_init();
156 rtsock_50_init();
157 kern_uipc_socket_50_init();
158
159 return error;
160 }
161
162 MODULE(MODULE_CLASS_EXEC, compat_50, "compat_60");
163
164 static int
compat_50_modcmd(modcmd_t cmd,void * arg)165 compat_50_modcmd(modcmd_t cmd, void *arg)
166 {
167
168 switch (cmd) {
169 case MODULE_CMD_INIT:
170 return compat_50_init();
171 case MODULE_CMD_FINI:
172 return compat_50_fini();
173 default:
174 return ENOTTY;
175 }
176 }
177