xref: /netbsd-src/sys/kern/kern_stub.c (revision 7863ba460b0a05b553c754e5dbc29247dddec322)
1 /*	$NetBSD: kern_stub.c,v 1.44 2017/12/16 18:42:22 christos Exp $	*/
2 
3 /*-
4  * Copyright (c) 2007, 2008 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  * POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 /*
30  * Copyright (c) 1982, 1986, 1991, 1993
31  *	The Regents of the University of California.  All rights reserved.
32  *
33  * Redistribution and use in source and binary forms, with or without
34  * modification, are permitted provided that the following conditions
35  * are met:
36  * 1. Redistributions of source code must retain the above copyright
37  *    notice, this list of conditions and the following disclaimer.
38  * 2. Redistributions in binary form must reproduce the above copyright
39  *    notice, this list of conditions and the following disclaimer in the
40  *    documentation and/or other materials provided with the distribution.
41  * 3. Neither the name of the University nor the names of its contributors
42  *    may be used to endorse or promote products derived from this software
43  *    without specific prior written permission.
44  *
45  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
46  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
47  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
48  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
49  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
50  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
51  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
52  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
53  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
54  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
55  * SUCH DAMAGE.
56  *
57  *	@(#)subr_xxx.c	8.3 (Berkeley) 3/29/95
58  */
59 
60 /*
61  * Stubs for system calls and facilities not included in the system.
62  */
63 
64 #include <sys/cdefs.h>
65 __KERNEL_RCSID(0, "$NetBSD: kern_stub.c,v 1.44 2017/12/16 18:42:22 christos Exp $");
66 
67 #ifdef _KERNEL_OPT
68 #include "opt_ktrace.h"
69 #include "opt_sysv.h"
70 #endif
71 
72 #include <sys/param.h>
73 #include <sys/kernel.h>
74 #include <sys/proc.h>
75 #include <sys/fstypes.h>
76 #include <sys/signalvar.h>
77 #include <sys/syscall.h>
78 #include <sys/ktrace.h>
79 #include <sys/intr.h>
80 #include <sys/cpu.h>
81 #include <sys/module.h>
82 #include <sys/bus.h>
83 #include <sys/userconf.h>
84 
85 bool default_bus_space_is_equal(bus_space_tag_t, bus_space_tag_t);
86 bool default_bus_space_handle_is_equal(bus_space_tag_t, bus_space_handle_t,
87     bus_space_handle_t);
88 
89 /*
90  * SYSV Semaphores, Shared Memory, Message Queues
91  */
92 #ifndef SYSVMSG
93 __strong_alias(msgctl1,enosys);
94 #endif
95 #ifndef SYSVSHM
96 __strong_alias(shmctl1,enosys);
97 #endif
98 #ifndef SYSVSEM
99 __strong_alias(semctl1,enosys);
100 #endif
101 
102 /*
103  * ktrace stubs.  ktruser() goes to enosys as we want to fail the syscall,
104  * but not kill the process: utrace() is a debugging feature.
105  */
106 #ifndef KTRACE
107 __strong_alias(ktr_csw,nullop);		/* Probes */
108 __strong_alias(ktr_emul,nullop);
109 __strong_alias(ktr_geniov,nullop);
110 __strong_alias(ktr_genio,nullop);
111 __strong_alias(ktr_mibio,nullop);
112 __strong_alias(ktr_namei,nullop);
113 __strong_alias(ktr_namei2,nullop);
114 __strong_alias(ktr_psig,nullop);
115 __strong_alias(ktr_syscall,nullop);
116 __strong_alias(ktr_sysret,nullop);
117 __strong_alias(ktr_kuser,nullop);
118 __strong_alias(ktr_mib,nullop);
119 __strong_alias(ktr_execarg,nullop);
120 __strong_alias(ktr_execenv,nullop);
121 __strong_alias(ktr_execfd,nullop);
122 
123 __strong_alias(sys_fktrace,sys_nosys);	/* Syscalls */
124 __strong_alias(sys_ktrace,sys_nosys);
125 __strong_alias(sys_utrace,sys_nosys);
126 
127 int	ktrace_on;			/* Misc */
128 __strong_alias(ktruser,enosys);
129 __strong_alias(ktr_point,nullop);
130 #endif	/* KTRACE */
131 
132 __weak_alias(device_register, voidop);
133 __weak_alias(device_register_post_config, voidop);
134 __weak_alias(spldebug_start, voidop);
135 __weak_alias(spldebug_stop, voidop);
136 __weak_alias(machdep_init,nullop);
137 __weak_alias(pci_chipset_tag_create, eopnotsupp);
138 __weak_alias(pci_chipset_tag_destroy, voidop);
139 __weak_alias(bus_space_reserve, eopnotsupp);
140 __weak_alias(bus_space_reserve_subregion, eopnotsupp);
141 __weak_alias(bus_space_release, voidop);
142 __weak_alias(bus_space_reservation_map, eopnotsupp);
143 __weak_alias(bus_space_reservation_unmap, voidop);
144 __weak_alias(bus_dma_tag_create, eopnotsupp);
145 __weak_alias(bus_dma_tag_destroy, voidop);
146 __weak_alias(bus_space_tag_create, eopnotsupp);
147 __weak_alias(bus_space_tag_destroy, voidop);
148 __strict_weak_alias(bus_space_is_equal, default_bus_space_is_equal);
149 __strict_weak_alias(bus_space_handle_is_equal,
150     default_bus_space_handle_is_equal);
151 __weak_alias(userconf_bootinfo, voidop);
152 __weak_alias(userconf_init, voidop);
153 __weak_alias(userconf_prompt, voidop);
154 
155 __weak_alias(kobj_renamespace, nullop);
156 
157 __weak_alias(interrupt_get_count, nullop);
158 __weak_alias(interrupt_get_assigned, voidop);
159 __weak_alias(interrupt_get_available, voidop);
160 __weak_alias(interrupt_get_devname, voidop);
161 __weak_alias(interrupt_construct_intrids, nullret);
162 __weak_alias(interrupt_destruct_intrids, voidop);
163 __weak_alias(interrupt_distribute, eopnotsupp);
164 __weak_alias(interrupt_distribute_handler, eopnotsupp);
165 
166 /*
167  * Scheduler activations system calls.  These need to remain until libc's
168  * major version is bumped.
169  */
170 __strong_alias(sys_sa_register,sys_nosys);
171 __strong_alias(sys_sa_stacks,sys_nosys);
172 __strong_alias(sys_sa_enable,sys_nosys);
173 __strong_alias(sys_sa_setconcurrency,sys_nosys);
174 __strong_alias(sys_sa_yield,sys_nosys);
175 __strong_alias(sys_sa_preempt,sys_nosys);
176 __strong_alias(sys_sa_unblockyield,sys_nosys);
177 
178 /*
179  * Stubs for compat_netbsd32.
180  */
181 __strong_alias(dosa_register,sys_nosys);
182 __strong_alias(sa_stacks1,sys_nosys);
183 
184 /*
185  * Stubs for architectures that do not support kernel preemption.
186  */
187 #ifndef __HAVE_PREEMPTION
188 bool
189 cpu_kpreempt_enter(uintptr_t where, int s)
190 {
191 
192 	return false;
193 }
194 
195 void
196 cpu_kpreempt_exit(uintptr_t where)
197 {
198 
199 }
200 
201 bool
202 cpu_kpreempt_disabled(void)
203 {
204 
205 	return true;
206 }
207 #else
208 # ifndef MULTIPROCESSOR
209 #   error __HAVE_PREEMPTION requires MULTIPROCESSOR
210 # endif
211 #endif	/* !__HAVE_PREEMPTION */
212 
213 int
214 sys_nosys(struct lwp *l, const void *v, register_t *retval)
215 {
216 
217 	mutex_enter(proc_lock);
218 	psignal(l->l_proc, SIGSYS);
219 	mutex_exit(proc_lock);
220 	return ENOSYS;
221 }
222 
223 /*
224  * Unsupported device function (e.g. writing to read-only device).
225  */
226 int
227 enodev(void)
228 {
229 
230 	return (ENODEV);
231 }
232 
233 /*
234  * Unconfigured device function; driver not configured.
235  */
236 int
237 enxio(void)
238 {
239 
240 	return (ENXIO);
241 }
242 
243 /*
244  * Unsupported ioctl function.
245  */
246 int
247 enoioctl(void)
248 {
249 
250 	return (ENOTTY);
251 }
252 
253 /*
254  * Unsupported system function.
255  * This is used for an otherwise-reasonable operation
256  * that is not supported by the current system binary.
257  */
258 int
259 enosys(void)
260 {
261 
262 	return (ENOSYS);
263 }
264 
265 /*
266  * Return error for operation not supported
267  * on a specific object or file type.
268  */
269 int
270 eopnotsupp(void)
271 {
272 
273 	return (EOPNOTSUPP);
274 }
275 
276 /*
277  * Generic null operation, void return value.
278  */
279 void
280 voidop(void)
281 {
282 }
283 
284 /*
285  * Generic null operation, always returns success.
286  */
287 int
288 nullop(void *v)
289 {
290 
291 	return (0);
292 }
293 
294 /*
295  * Generic null operation, always returns null.
296  */
297 void *
298 nullret(void)
299 {
300 
301 	return (NULL);
302 }
303 
304 bool
305 default_bus_space_handle_is_equal(bus_space_tag_t t,
306     bus_space_handle_t h1, bus_space_handle_t h2)
307 {
308 
309 	return memcmp(&h1, &h2, sizeof(h1)) == 0;
310 }
311 
312 bool
313 default_bus_space_is_equal(bus_space_tag_t t1, bus_space_tag_t t2)
314 {
315 
316 	return memcmp(&t1, &t2, sizeof(t1)) == 0;
317 }
318