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