xref: /netbsd-src/sys/compat/common/compat_50_mod.c (revision cbf5c65aff7a9fb3766c02a179c5c934c4485837)
1*cbf5c65aSandvar /*	$NetBSD: compat_50_mod.c,v 1.4 2021/12/10 20:36:03 andvar Exp $	*/
2d91f98a8Spgoyette 
3d91f98a8Spgoyette /*-
4d91f98a8Spgoyette  * Copyright (c) 2018 The NetBSD Foundation, Inc.
5d91f98a8Spgoyette  * All rights reserved.
6d91f98a8Spgoyette  *
7d91f98a8Spgoyette  * This code is derived from software developed for The NetBSD Foundation
8d91f98a8Spgoyette  * by Paul Goyette
9d91f98a8Spgoyette  *
10d91f98a8Spgoyette  * Redistribution and use in source and binary forms, with or without
11d91f98a8Spgoyette  * modification, are permitted provided that the following conditions
12d91f98a8Spgoyette  * are met:
13d91f98a8Spgoyette  * 1. Redistributions of source code must retain the above copyright
14d91f98a8Spgoyette  *    notice, this list of conditions and the following disclaimer.
15d91f98a8Spgoyette  * 2. Redistributions in binary form must reproduce the above copyright
16d91f98a8Spgoyette  *    notice, this list of conditions and the following disclaimer in the
17d91f98a8Spgoyette  *    documentation and/or other materials provided with the distribution.
18d91f98a8Spgoyette  *
19d91f98a8Spgoyette  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20d91f98a8Spgoyette  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21d91f98a8Spgoyette  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22d91f98a8Spgoyette  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23d91f98a8Spgoyette  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24d91f98a8Spgoyette  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25d91f98a8Spgoyette  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26d91f98a8Spgoyette  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27d91f98a8Spgoyette  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28d91f98a8Spgoyette  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29d91f98a8Spgoyette  * POSSIBILITY OF SUCH DAMAGE.
30d91f98a8Spgoyette  */
31d91f98a8Spgoyette 
32d91f98a8Spgoyette /*
33d91f98a8Spgoyette  * Linkage for the compat module: spaghetti.
34d91f98a8Spgoyette  */
35d91f98a8Spgoyette 
36d91f98a8Spgoyette #include <sys/cdefs.h>
37*cbf5c65aSandvar __KERNEL_RCSID(0, "$NetBSD: compat_50_mod.c,v 1.4 2021/12/10 20:36:03 andvar Exp $");
38d91f98a8Spgoyette 
39d91f98a8Spgoyette #if defined(_KERNEL_OPT)
40d91f98a8Spgoyette #include "opt_compat_netbsd.h"
41d91f98a8Spgoyette #endif
42d91f98a8Spgoyette 
43d91f98a8Spgoyette #include <sys/systm.h>
44d91f98a8Spgoyette #include <sys/module.h>
45d91f98a8Spgoyette #include <sys/sysctl.h>
46d91f98a8Spgoyette #include <sys/syscall.h>
47d91f98a8Spgoyette #include <sys/syscallvar.h>
48d91f98a8Spgoyette #include <sys/syscallargs.h>
49d91f98a8Spgoyette 
50d91f98a8Spgoyette #include <compat/sys/clockctl.h>
51d91f98a8Spgoyette 
52d91f98a8Spgoyette #include <compat/common/compat_util.h>
53d91f98a8Spgoyette #include <compat/common/compat_mod.h>
54d91f98a8Spgoyette #include <compat/common/if_spppsubr50.h>
55d91f98a8Spgoyette 
56d91f98a8Spgoyette #include <dev/wscons/wsevent_50.h>
57d91f98a8Spgoyette 
58d91f98a8Spgoyette #include <fs/puffs/puffs_sys.h>
59d91f98a8Spgoyette 
60d91f98a8Spgoyette int
compat_50_init(void)61d91f98a8Spgoyette compat_50_init(void)
62d91f98a8Spgoyette {
63d91f98a8Spgoyette 	int error = 0;
64d91f98a8Spgoyette 
65d91f98a8Spgoyette 	error = kern_50_init();
66d91f98a8Spgoyette 	if (error != 0)
67d91f98a8Spgoyette 		return error;
68d91f98a8Spgoyette 
69d91f98a8Spgoyette 	error = kern_time_50_init();
70d91f98a8Spgoyette 	if (error != 0)
71d91f98a8Spgoyette 		goto err1;
72d91f98a8Spgoyette 
73d91f98a8Spgoyette 	error = kern_select_50_init();
74d91f98a8Spgoyette 	if (error != 0)
75d91f98a8Spgoyette 		goto err2;
76d91f98a8Spgoyette 
77d91f98a8Spgoyette 	error = vfs_syscalls_50_init();
78d91f98a8Spgoyette 	if (error != 0)
79d91f98a8Spgoyette 		goto err3;
80d91f98a8Spgoyette 
81d91f98a8Spgoyette 	uvm_50_init();
82d91f98a8Spgoyette 	uipc_syscalls_50_init();
83d91f98a8Spgoyette 	clockctl_50_init();
84d91f98a8Spgoyette 	if_spppsubr_50_init();
85d91f98a8Spgoyette 	puffs_50_init();
86d91f98a8Spgoyette 	wsevent_50_init();
87d91f98a8Spgoyette 	vnd_50_init();
88d91f98a8Spgoyette 	rndpseudo_50_init();
89d91f98a8Spgoyette 	rtsock_50_init();
9068c01b4bSpgoyette 	kern_uipc_socket_50_init();
91d91f98a8Spgoyette 
92d91f98a8Spgoyette 	return error;
93d91f98a8Spgoyette 
94*cbf5c65aSandvar /* If an error occurred, undo all previous set-up before returning */
95d91f98a8Spgoyette 
96d91f98a8Spgoyette  err3:
97d91f98a8Spgoyette 	kern_select_50_fini();
98d91f98a8Spgoyette  err2:
99d91f98a8Spgoyette 	kern_time_50_fini();
100d91f98a8Spgoyette  err1:
101d91f98a8Spgoyette 	kern_50_fini();
102d91f98a8Spgoyette 
103d91f98a8Spgoyette 	return error;
104d91f98a8Spgoyette }
105d91f98a8Spgoyette 
106d91f98a8Spgoyette int
compat_50_fini(void)107d91f98a8Spgoyette compat_50_fini(void)
108d91f98a8Spgoyette {
109d91f98a8Spgoyette 	int error = 0;
110d91f98a8Spgoyette 
11168c01b4bSpgoyette 	kern_uipc_socket_50_fini();
112d91f98a8Spgoyette 	rtsock_50_fini();
113d91f98a8Spgoyette 	rndpseudo_50_fini();
114d91f98a8Spgoyette 	vnd_50_fini();
115d91f98a8Spgoyette 	wsevent_50_fini();
116d91f98a8Spgoyette 	puffs_50_fini();
117d91f98a8Spgoyette 	if_spppsubr_50_fini();
118d91f98a8Spgoyette 	clockctl_50_fini();
119d91f98a8Spgoyette 	uipc_syscalls_50_fini();
120d91f98a8Spgoyette 	uvm_50_fini();
121d91f98a8Spgoyette 
122d91f98a8Spgoyette 	error = vfs_syscalls_50_fini();
123d91f98a8Spgoyette 	if (error != 0)
124d91f98a8Spgoyette 		goto err1;
125d91f98a8Spgoyette 
126d91f98a8Spgoyette 	error = kern_select_50_fini();
127d91f98a8Spgoyette 	if (error != 0)
128d91f98a8Spgoyette 		goto err2;
129d91f98a8Spgoyette 
130d91f98a8Spgoyette 	error = kern_time_50_fini();
131d91f98a8Spgoyette 	if (error != 0)
132d91f98a8Spgoyette 		goto err3;
133d91f98a8Spgoyette 
134d91f98a8Spgoyette 	error = kern_50_fini();
135d91f98a8Spgoyette 	if (error != 0)
136d91f98a8Spgoyette 		goto err4;
137d91f98a8Spgoyette 
138d91f98a8Spgoyette 	return error;
139d91f98a8Spgoyette 
140d91f98a8Spgoyette /* If an error occurred while removing something, restore everything! */
141d91f98a8Spgoyette  err4:
142d91f98a8Spgoyette 	kern_time_50_init();
143d91f98a8Spgoyette  err3:
144d91f98a8Spgoyette 	kern_select_50_init();
145d91f98a8Spgoyette  err2:
146d91f98a8Spgoyette 	vfs_syscalls_50_init();
147d91f98a8Spgoyette  err1:
148d91f98a8Spgoyette 	uvm_50_init();
149d91f98a8Spgoyette 	uipc_syscalls_50_init();
150d91f98a8Spgoyette 	clockctl_50_init();
151d91f98a8Spgoyette 	if_spppsubr_50_init();
152d91f98a8Spgoyette 	puffs_50_init();
153d91f98a8Spgoyette 	wsevent_50_init();
154d91f98a8Spgoyette 	vnd_50_init();
155d91f98a8Spgoyette 	rndpseudo_50_init();
156d91f98a8Spgoyette 	rtsock_50_init();
15768c01b4bSpgoyette 	kern_uipc_socket_50_init();
158d91f98a8Spgoyette 
159d91f98a8Spgoyette 	return error;
160d91f98a8Spgoyette }
161d91f98a8Spgoyette 
162d91f98a8Spgoyette MODULE(MODULE_CLASS_EXEC, compat_50, "compat_60");
163d91f98a8Spgoyette 
164d91f98a8Spgoyette static int
compat_50_modcmd(modcmd_t cmd,void * arg)165d91f98a8Spgoyette compat_50_modcmd(modcmd_t cmd, void *arg)
166d91f98a8Spgoyette {
167d91f98a8Spgoyette 
168d91f98a8Spgoyette 	switch (cmd) {
169d91f98a8Spgoyette 	case MODULE_CMD_INIT:
170d91f98a8Spgoyette 		return compat_50_init();
171d91f98a8Spgoyette 	case MODULE_CMD_FINI:
172d91f98a8Spgoyette 		return compat_50_fini();
173d91f98a8Spgoyette 	default:
174d91f98a8Spgoyette 		return ENOTTY;
175d91f98a8Spgoyette 	}
176d91f98a8Spgoyette }
177