1/*	$NetBSD: kern_stub.c,v 1.50 2020/08/01 02:04:55 riastradh 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.50 2020/08/01 02:04:55 riastradh Exp $");
66
67#ifdef _KERNEL_OPT
68#include "opt_ktrace.h"
69#include "opt_sysv.h"
70#include "opt_modular.h"
71#endif
72
73#include <sys/param.h>
74#include <sys/kernel.h>
75#include <sys/proc.h>
76#include <sys/fstypes.h>
77#include <sys/signalvar.h>
78#include <sys/syscall.h>
79#include <sys/ktrace.h>
80#include <sys/intr.h>
81#include <sys/cpu.h>
82#include <sys/module.h>
83#include <sys/bus.h>
84#include <sys/userconf.h>
85
86bool default_bus_space_is_equal(bus_space_tag_t, bus_space_tag_t);
87bool default_bus_space_handle_is_equal(bus_space_tag_t, bus_space_handle_t,
88    bus_space_handle_t);
89
90/*
91 * SYSV Semaphores, Shared Memory, Message Queues
92 */
93#ifndef MODULAR
94#ifndef SYSVMSG
95__strong_alias(msgctl1,enosys);
96#endif
97#ifndef SYSVSHM
98__strong_alias(shmctl1,enosys);
99#endif
100#ifndef SYSVSEM
101 __strong_alias(semctl1,enosys);
102#endif
103#endif
104
105/*
106 * ktrace stubs.  ktruser() goes to enosys as we want to fail the syscall,
107 * but not kill the process: utrace() is a debugging feature.
108 */
109#ifndef KTRACE
110__strong_alias(ktr_csw,nullop);		/* Probes */
111__strong_alias(ktr_emul,nullop);
112__strong_alias(ktr_geniov,nullop);
113__strong_alias(ktr_genio,nullop);
114__strong_alias(ktr_mibio,nullop);
115__strong_alias(ktr_namei,nullop);
116__strong_alias(ktr_namei2,nullop);
117__strong_alias(ktr_psig,nullop);
118__strong_alias(ktr_syscall,nullop);
119__strong_alias(ktr_sysret,nullop);
120__strong_alias(ktr_kuser,nullop);
121__strong_alias(ktr_mib,nullop);
122__strong_alias(ktr_execarg,nullop);
123__strong_alias(ktr_execenv,nullop);
124__strong_alias(ktr_execfd,nullop);
125
126__strong_alias(sys_fktrace,sys_nosys);	/* Syscalls */
127__strong_alias(sys_ktrace,sys_nosys);
128__strong_alias(sys_utrace,sys_nosys);
129
130int	ktrace_on;			/* Misc */
131__strong_alias(ktruser,enosys);
132__strong_alias(ktr_point,nullop);
133#endif	/* KTRACE */
134
135__weak_alias(device_register, voidop);
136__weak_alias(device_register_post_config, voidop);
137__weak_alias(spldebug_start, voidop);
138__weak_alias(spldebug_stop, voidop);
139__weak_alias(machdep_init,nullop);
140__weak_alias(pci_chipset_tag_create, eopnotsupp);
141__weak_alias(pci_chipset_tag_destroy, voidop);
142__weak_alias(bus_space_reserve, eopnotsupp);
143__weak_alias(bus_space_reserve_subregion, eopnotsupp);
144__weak_alias(bus_space_release, voidop);
145__weak_alias(bus_space_reservation_map, eopnotsupp);
146__weak_alias(bus_space_reservation_unmap, voidop);
147__weak_alias(bus_dma_tag_create, eopnotsupp);
148__weak_alias(bus_dma_tag_destroy, voidop);
149__weak_alias(bus_space_tag_create, eopnotsupp);
150__weak_alias(bus_space_tag_destroy, voidop);
151__strict_weak_alias(bus_space_is_equal, default_bus_space_is_equal);
152__strict_weak_alias(bus_space_handle_is_equal,
153    default_bus_space_handle_is_equal);
154__weak_alias(userconf_bootinfo, voidop);
155__weak_alias(userconf_init, voidop);
156__weak_alias(userconf_prompt, voidop);
157
158__weak_alias(kobj_renamespace, nullop);
159
160__weak_alias(interrupt_get_count, nullop);
161__weak_alias(interrupt_get_assigned, voidop);
162__weak_alias(interrupt_get_available, voidop);
163__weak_alias(interrupt_get_devname, voidop);
164__weak_alias(interrupt_construct_intrids, nullret);
165__weak_alias(interrupt_destruct_intrids, voidop);
166__weak_alias(interrupt_distribute, eopnotsupp);
167__weak_alias(interrupt_distribute_handler, eopnotsupp);
168
169/*
170 * Scheduler activations system calls.  These need to remain until libc's
171 * major version is bumped.
172 */
173__strong_alias(sys_sa_register,sys_nosys);
174__strong_alias(sys_sa_stacks,sys_nosys);
175__strong_alias(sys_sa_enable,sys_nosys);
176__strong_alias(sys_sa_setconcurrency,sys_nosys);
177__strong_alias(sys_sa_yield,sys_nosys);
178__strong_alias(sys_sa_preempt,sys_nosys);
179__strong_alias(sys_sa_unblockyield,sys_nosys);
180
181/*
182 * Stubs for compat_netbsd32.
183 */
184__strong_alias(dosa_register,sys_nosys);
185__strong_alias(sa_stacks1,sys_nosys);
186
187/*
188 * Stubs for drivers.  See sys/conf.h.
189 */
190__strong_alias(devenodev,enodev);
191__strong_alias(deveopnotsupp,eopnotsupp);
192__strong_alias(devnullop,nullop);
193__strong_alias(ttyenodev,enodev);
194__strong_alias(ttyvenodev,voidop);
195__strong_alias(ttyvnullop,nullop);
196
197/*
198 * Stubs for architectures that do not support kernel preemption.
199 */
200#ifndef __HAVE_PREEMPTION
201bool
202cpu_kpreempt_enter(uintptr_t where, int s)
203{
204
205	return false;
206}
207
208void
209cpu_kpreempt_exit(uintptr_t where)
210{
211
212}
213
214bool
215cpu_kpreempt_disabled(void)
216{
217
218	return true;
219}
220#else
221# ifndef MULTIPROCESSOR
222#   error __HAVE_PREEMPTION requires MULTIPROCESSOR
223# endif
224#endif	/* !__HAVE_PREEMPTION */
225
226int
227sys_nosys(struct lwp *l, const void *v, register_t *retval)
228{
229
230	mutex_enter(&proc_lock);
231	psignal(l->l_proc, SIGSYS);
232	mutex_exit(&proc_lock);
233	return ENOSYS;
234}
235
236/*
237 * Unsupported device function (e.g. writing to read-only device).
238 */
239int
240enodev(void)
241{
242
243	return (ENODEV);
244}
245
246/*
247 * Unconfigured device function; driver not configured.
248 */
249int
250enxio(void)
251{
252
253	return (ENXIO);
254}
255
256/*
257 * Unsupported ioctl function.
258 */
259int
260enoioctl(void)
261{
262
263	return (ENOTTY);
264}
265
266/*
267 * Unsupported system function.
268 * This is used for an otherwise-reasonable operation
269 * that is not supported by the current system binary.
270 */
271int
272enosys(void)
273{
274
275	return (ENOSYS);
276}
277
278/*
279 * Return error for operation not supported
280 * on a specific object or file type.
281 */
282int
283eopnotsupp(void)
284{
285
286	return (EOPNOTSUPP);
287}
288
289/*
290 * Generic null operation, void return value.
291 */
292void
293voidop(void)
294{
295}
296
297/*
298 * Generic null operation, always returns success.
299 */
300int
301nullop(void *v)
302{
303
304	return (0);
305}
306
307/*
308 * Generic null operation, always returns null.
309 */
310void *
311nullret(void)
312{
313
314	return (NULL);
315}
316
317bool
318default_bus_space_handle_is_equal(bus_space_tag_t t,
319    bus_space_handle_t h1, bus_space_handle_t h2)
320{
321
322	return memcmp(&h1, &h2, sizeof(h1)) == 0;
323}
324
325bool
326default_bus_space_is_equal(bus_space_tag_t t1, bus_space_tag_t t2)
327{
328
329	return memcmp(&t1, &t2, sizeof(t1)) == 0;
330}
331
332/* Stubs for architectures with no kernel FPU access.  */
333__weak_alias(kthread_fpu_enter_md, voidop);
334__weak_alias(kthread_fpu_exit_md, voidop);
335