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