kern_stub.c revision 1.18 1 /* $NetBSD: kern_stub.c,v 1.18 2009/02/13 22:41:04 apb 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.18 2009/02/13 22:41:04 apb Exp $");
66
67 #include "opt_ptrace.h"
68 #include "opt_ktrace.h"
69 #include "opt_modular.h"
70 #include "opt_sa.h"
71 #ifdef _KERNEL_OPT
72 #include "fs_lfs.h"
73 #endif
74
75 /* XXX To get syscall prototypes. */
76 #define SYSVSHM
77 #define SYSVSEM
78 #define SYSVMSG
79
80 #include <sys/param.h>
81 #include <sys/kernel.h>
82 #include <sys/proc.h>
83 #include <sys/fstypes.h>
84 #include <sys/signalvar.h>
85 #include <sys/syscall.h>
86 #include <sys/syscallargs.h>
87 #include <sys/syscallvar.h>
88 #include <sys/ktrace.h>
89 #include <sys/intr.h>
90 #include <sys/cpu.h>
91 #include <sys/module.h>
92
93 /*
94 * Nonexistent system call-- signal process (may want to handle it). Flag
95 * error in case process won't see signal immediately (blocked or ignored).
96 */
97 #ifndef PTRACE
98 __weak_alias(sys_ptrace,sys_nosys);
99 #endif /* PTRACE */
100
101 /*
102 * ktrace stubs. ktruser() goes to enosys as we want to fail the syscall,
103 * but not kill the process: utrace() is a debugging feature.
104 */
105 #ifndef KTRACE
106 __weak_alias(ktr_csw,nullop); /* Probes */
107 __weak_alias(ktr_emul,nullop);
108 __weak_alias(ktr_geniov,nullop);
109 __weak_alias(ktr_genio,nullop);
110 __weak_alias(ktr_mibio,nullop);
111 __weak_alias(ktr_namei,nullop);
112 __weak_alias(ktr_namei2,nullop);
113 __weak_alias(ktr_psig,nullop);
114 __weak_alias(ktr_saupcall,nullop);
115 __weak_alias(ktr_syscall,nullop);
116 __weak_alias(ktr_sysret,nullop);
117 __weak_alias(ktr_kuser,nullop);
118 __weak_alias(ktr_mmsg,nullop);
119 __weak_alias(ktr_mib,nullop);
120 __weak_alias(ktr_mool,nullop);
121 __weak_alias(ktr_execarg,nullop);
122 __weak_alias(ktr_execenv,nullop);
123
124 __weak_alias(sys_fktrace,sys_nosys); /* Syscalls */
125 __weak_alias(sys_ktrace,sys_nosys);
126 __weak_alias(sys_utrace,sys_nosys);
127
128 int ktrace_on; /* Misc */
129 __weak_alias(ktruser,enosys);
130 __weak_alias(ktr_point,nullop);
131 #endif /* KTRACE */
132
133 #if !defined(KERN_SA)
134 /*
135 * Scheduler activations system calls. These need to remain, even when
136 * KERN_SA isn't defined, until libc's major version is bumped.
137 */
138 __strong_alias(sys_sa_register,sys_nosys);
139 __strong_alias(sys_sa_stacks,sys_nosys);
140 __strong_alias(sys_sa_enable,sys_nosys);
141 __strong_alias(sys_sa_setconcurrency,sys_nosys);
142 __strong_alias(sys_sa_yield,sys_nosys);
143 __strong_alias(sys_sa_preempt,sys_nosys);
144 __strong_alias(sys_sa_unblockyield,sys_nosys);
145
146 /*
147 * Stubs for compat_netbsd32.
148 */
149 __strong_alias(dosa_register,sys_nosys);
150 __strong_alias(sa_stacks1,sys_nosys);
151 #endif
152
153 /*
154 * Stubs for architectures that do not support kernel preemption.
155 */
156 #ifndef __HAVE_PREEMPTION
157 bool
158 cpu_kpreempt_enter(uintptr_t where, int s)
159 {
160
161 return false;
162 }
163
164 void
165 cpu_kpreempt_exit(uintptr_t where)
166 {
167
168 }
169
170 bool
171 cpu_kpreempt_disabled(void)
172 {
173
174 return true;
175 }
176 #else
177 # ifndef MULTIPROCESSOR
178 # error __HAVE_PREEMPTION requires MULTIPROCESSOR
179 # endif
180 #endif /* !__HAVE_PREEMPTION */
181
182 int
183 sys_nosys(struct lwp *l, const void *v, register_t *retval)
184 {
185
186 mutex_enter(proc_lock);
187 psignal(l->l_proc, SIGSYS);
188 mutex_exit(proc_lock);
189 return ENOSYS;
190 }
191
192 int
193 sys_nomodule(struct lwp *l, const void *v, register_t *retval)
194 {
195 #ifdef MODULAR
196 static struct {
197 u_int al_code;
198 const char *al_module;
199 } const autoload[] = {
200 { SYS_aio_cancel, "aio" },
201 { SYS_aio_error, "aio" },
202 { SYS_aio_fsync, "aio" },
203 { SYS_aio_read, "aio" },
204 { SYS_aio_return, "aio" },
205 { SYS___aio_suspend50, "aio" },
206 { SYS_aio_write, "aio" },
207 { SYS_lio_listio, "aio" },
208 { SYS_compat_43_fstat43, "compat" },
209 { SYS_compat_43_lstat43, "compat" },
210 { SYS_compat_43_oaccept, "compat" },
211 { SYS_compat_43_ocreat, "compat" },
212 { SYS_compat_43_oftruncate, "compat" },
213 { SYS_compat_43_ogetdirentries, "compat" },
214 { SYS_compat_43_ogetdtablesize, "compat" },
215 { SYS_compat_43_ogethostid, "compat" },
216 { SYS_compat_43_ogethostname, "compat" },
217 { SYS_compat_43_ogetkerninfo, "compat" },
218 { SYS_compat_43_ogetpagesize, "compat" },
219 { SYS_compat_43_ogetpeername, "compat" },
220 { SYS_compat_43_ogetrlimit, "compat" },
221 { SYS_compat_43_ogetsockname, "compat" },
222 { SYS_compat_43_okillpg, "compat" },
223 { SYS_compat_43_olseek, "compat" },
224 { SYS_compat_43_ommap, "compat" },
225 { SYS_compat_43_oquota, "compat" },
226 { SYS_compat_43_orecv, "compat" },
227 { SYS_compat_43_orecvfrom, "compat" },
228 { SYS_compat_43_orecvmsg, "compat" },
229 { SYS_compat_43_osend, "compat" },
230 { SYS_compat_43_osendmsg, "compat" },
231 { SYS_compat_43_osethostid, "compat" },
232 { SYS_compat_43_osethostname, "compat" },
233 { SYS_compat_43_osetrlimit, "compat" },
234 { SYS_compat_43_osigblock, "compat" },
235 { SYS_compat_43_osigsetmask, "compat" },
236 { SYS_compat_43_osigstack, "compat" },
237 { SYS_compat_43_osigvec, "compat" },
238 { SYS_compat_43_otruncate, "compat" },
239 { SYS_compat_43_owait, "compat" },
240 { SYS_compat_43_stat43, "compat" },
241 { SYS_compat_09_ogetdomainname, "compat" },
242 { SYS_compat_09_osetdomainname, "compat" },
243 { SYS_compat_09_ouname, "compat" },
244 #ifndef _LP64
245 { SYS_compat_10_omsgsys, "compat" },
246 { SYS_compat_10_osemsys, "compat" },
247 { SYS_compat_10_oshmsys, "compat" },
248 #endif
249 { SYS_compat_12_fstat12, "compat" },
250 { SYS_compat_12_getdirentries, "compat" },
251 { SYS_compat_12_lstat12, "compat" },
252 { SYS_compat_12_msync, "compat" },
253 { SYS_compat_12_oreboot, "compat" },
254 { SYS_compat_12_oswapon, "compat" },
255 { SYS_compat_12_stat12, "compat" },
256 { SYS_compat_13_sigaction13, "compat" },
257 { SYS_compat_13_sigaltstack13, "compat" },
258 { SYS_compat_13_sigpending13, "compat" },
259 { SYS_compat_13_sigprocmask13, "compat" },
260 { SYS_compat_13_sigreturn13, "compat" },
261 { SYS_compat_13_sigsuspend13, "compat" },
262 { SYS_compat_14___semctl, "compat" },
263 { SYS_compat_14_msgctl, "compat" },
264 { SYS_compat_14_shmctl, "compat" },
265 { SYS_compat_16___sigaction14, "compat" },
266 { SYS_compat_16___sigreturn14, "compat" },
267 { SYS_compat_20_fhstatfs, "compat" },
268 { SYS_compat_20_fstatfs, "compat" },
269 { SYS_compat_20_getfsstat, "compat" },
270 { SYS_compat_20_statfs, "compat" },
271 { SYS_compat_30___fhstat30, "compat" },
272 { SYS_compat_30___fstat13, "compat" },
273 { SYS_compat_30___lstat13, "compat" },
274 { SYS_compat_30___stat13, "compat" },
275 { SYS_compat_30_fhopen, "compat" },
276 { SYS_compat_30_fhstat, "compat" },
277 { SYS_compat_30_fhstatvfs1, "compat" },
278 { SYS_compat_30_getdents, "compat" },
279 { SYS_compat_30_getfh, "compat" },
280 { SYS_compat_30_socket, "compat" },
281 { SYS_compat_40_mount, "compat" },
282 { SYS_compat_50_wait4, "compat" },
283 { SYS_compat_50_mknod, "compat" },
284 { SYS_compat_50_setitimer, "compat" },
285 { SYS_compat_50_getitimer, "compat" },
286 { SYS_compat_50_select, "compat" },
287 { SYS_compat_50_gettimeofday, "compat" },
288 { SYS_compat_50_getrusage, "compat" },
289 { SYS_compat_50_settimeofday, "compat" },
290 { SYS_compat_50_utimes, "compat" },
291 { SYS_compat_50_adjtime, "compat" },
292 #ifdef LFS
293 { SYS_compat_50_lfs_segwait, "compat" },
294 #endif
295 { SYS_compat_50_futimes, "compat" },
296 { SYS_compat_50_clock_gettime, "compat" },
297 { SYS_compat_50_clock_settime, "compat" },
298 { SYS_compat_50_clock_getres, "compat" },
299 { SYS_compat_50_timer_settime, "compat" },
300 { SYS_compat_50_timer_gettime, "compat" },
301 { SYS_compat_50_nanosleep, "compat" },
302 { SYS_compat_50___sigtimedwait, "compat" },
303 { SYS_compat_50_mq_timedsend, "compat" },
304 { SYS_compat_50_mq_timedreceive, "compat" },
305 { SYS_compat_50_lutimes, "compat" },
306 { SYS_compat_50_____semctl13, "compat" },
307 { SYS_compat_50___msgctl13, "compat" },
308 { SYS_compat_50___shmctl13, "compat" },
309 { SYS_compat_50__lwp_park, "compat" },
310 { SYS_compat_50_kevent, "compat" },
311 { SYS_compat_50_pselect, "compat" },
312 { SYS_compat_50_pollts, "compat" },
313 { SYS_compat_50___stat30, "compat" },
314 { SYS_compat_50___fstat30, "compat" },
315 { SYS_compat_50___lstat30, "compat" },
316 { SYS_compat_50___ntp_gettime30, "compat" },
317 { SYS_compat_50___fhstat40, "compat" },
318 { SYS_compat_50_aio_suspend, "compat" },
319 { SYS__ksem_init, "ksem" },
320 { SYS__ksem_open, "ksem" },
321 { SYS__ksem_unlink, "ksem" },
322 { SYS__ksem_close, "ksem" },
323 { SYS__ksem_post, "ksem" },
324 { SYS__ksem_wait, "ksem" },
325 { SYS__ksem_trywait, "ksem" },
326 { SYS__ksem_getvalue, "ksem" },
327 { SYS__ksem_destroy, "ksem" },
328 { SYS_nfssvc, "nfsserver" },
329 };
330 const struct sysent *sy;
331 const struct emul *em;
332 int code, i;
333
334 /*
335 * Restart the syscall if we interrupted a module unload that
336 * failed. Acquiring module_lock delays us until any unload
337 * has been completed or rolled back.
338 */
339 mutex_enter(&module_lock);
340 sy = l->l_sysent;
341 if (sy->sy_call != sys_nomodule) {
342 mutex_exit(&module_lock);
343 return ERESTART;
344 }
345 /*
346 * Try to autoload a module to satisfy the request. If it
347 * works, retry the request.
348 */
349 em = l->l_proc->p_emul;
350 if (em == &emul_netbsd) {
351 code = sy - em->e_sysent;
352 for (i = 0; i < __arraycount(autoload); i++) {
353 if (autoload[i].al_code != code) {
354 continue;
355 }
356 if (module_autoload(autoload[i].al_module,
357 MODULE_CLASS_ANY) != 0 ||
358 sy->sy_call == sys_nomodule) {
359 break;
360 }
361 mutex_exit(&module_lock);
362 return ERESTART;
363 }
364 }
365 mutex_exit(&module_lock);
366 #endif /* MODULAR */
367
368 return sys_nosys(l, v, retval);
369 }
370
371 /*
372 * Unsupported device function (e.g. writing to read-only device).
373 */
374 int
375 enodev(void)
376 {
377
378 return (ENODEV);
379 }
380
381 /*
382 * Unconfigured device function; driver not configured.
383 */
384 int
385 enxio(void)
386 {
387
388 return (ENXIO);
389 }
390
391 /*
392 * Unsupported ioctl function.
393 */
394 int
395 enoioctl(void)
396 {
397
398 return (ENOTTY);
399 }
400
401 /*
402 * Unsupported system function.
403 * This is used for an otherwise-reasonable operation
404 * that is not supported by the current system binary.
405 */
406 int
407 enosys(void)
408 {
409
410 return (ENOSYS);
411 }
412
413 /*
414 * Return error for operation not supported
415 * on a specific object or file type.
416 */
417 int
418 eopnotsupp(void)
419 {
420
421 return (EOPNOTSUPP);
422 }
423
424 /*
425 * Generic null operation, always returns success.
426 */
427 /*ARGSUSED*/
428 int
429 nullop(void *v)
430 {
431
432 return (0);
433 }
434