kern_stub.c revision 1.15 1 1.15 ad /* $NetBSD: kern_stub.c,v 1.15 2008/11/20 09:30:32 ad Exp $ */
2 1.1 ad
3 1.1 ad /*-
4 1.8 ad * Copyright (c) 2007, 2008 The NetBSD Foundation, Inc.
5 1.1 ad * All rights reserved.
6 1.1 ad *
7 1.1 ad * Redistribution and use in source and binary forms, with or without
8 1.1 ad * modification, are permitted provided that the following conditions
9 1.1 ad * are met:
10 1.1 ad * 1. Redistributions of source code must retain the above copyright
11 1.1 ad * notice, this list of conditions and the following disclaimer.
12 1.1 ad * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 ad * notice, this list of conditions and the following disclaimer in the
14 1.1 ad * documentation and/or other materials provided with the distribution.
15 1.1 ad *
16 1.1 ad * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 1.1 ad * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 1.1 ad * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 1.1 ad * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 1.1 ad * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 1.1 ad * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 1.1 ad * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 1.1 ad * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 1.1 ad * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 1.1 ad * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 1.1 ad * POSSIBILITY OF SUCH DAMAGE.
27 1.1 ad */
28 1.1 ad
29 1.1 ad /*
30 1.3 ad * Copyright (c) 1982, 1986, 1991, 1993
31 1.3 ad * The Regents of the University of California. All rights reserved.
32 1.3 ad *
33 1.3 ad * Redistribution and use in source and binary forms, with or without
34 1.3 ad * modification, are permitted provided that the following conditions
35 1.3 ad * are met:
36 1.3 ad * 1. Redistributions of source code must retain the above copyright
37 1.3 ad * notice, this list of conditions and the following disclaimer.
38 1.3 ad * 2. Redistributions in binary form must reproduce the above copyright
39 1.3 ad * notice, this list of conditions and the following disclaimer in the
40 1.3 ad * documentation and/or other materials provided with the distribution.
41 1.3 ad * 3. Neither the name of the University nor the names of its contributors
42 1.3 ad * may be used to endorse or promote products derived from this software
43 1.3 ad * without specific prior written permission.
44 1.3 ad *
45 1.3 ad * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
46 1.3 ad * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
47 1.3 ad * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
48 1.3 ad * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
49 1.3 ad * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
50 1.3 ad * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
51 1.3 ad * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
52 1.3 ad * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
53 1.3 ad * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
54 1.3 ad * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
55 1.3 ad * SUCH DAMAGE.
56 1.3 ad *
57 1.3 ad * @(#)subr_xxx.c 8.3 (Berkeley) 3/29/95
58 1.3 ad */
59 1.3 ad
60 1.3 ad /*
61 1.1 ad * Stubs for system calls and facilities not included in the system.
62 1.1 ad */
63 1.1 ad
64 1.1 ad #include <sys/cdefs.h>
65 1.15 ad __KERNEL_RCSID(0, "$NetBSD: kern_stub.c,v 1.15 2008/11/20 09:30:32 ad Exp $");
66 1.1 ad
67 1.1 ad #include "opt_ptrace.h"
68 1.3 ad #include "opt_ktrace.h"
69 1.10 wrstuden #include "opt_sa.h"
70 1.1 ad
71 1.14 ad /* XXX To get syscall prototypes. */
72 1.14 ad #define SYSVSHM
73 1.14 ad #define SYSVSEM
74 1.14 ad #define SYSVMSG
75 1.14 ad
76 1.1 ad #include <sys/param.h>
77 1.1 ad #include <sys/kernel.h>
78 1.1 ad #include <sys/proc.h>
79 1.1 ad #include <sys/signalvar.h>
80 1.12 ad #include <sys/syscall.h>
81 1.1 ad #include <sys/syscallargs.h>
82 1.12 ad #include <sys/syscallvar.h>
83 1.3 ad #include <sys/ktrace.h>
84 1.8 ad #include <sys/intr.h>
85 1.8 ad #include <sys/cpu.h>
86 1.12 ad #include <sys/module.h>
87 1.1 ad
88 1.1 ad /*
89 1.1 ad * Nonexistent system call-- signal process (may want to handle it). Flag
90 1.1 ad * error in case process won't see signal immediately (blocked or ignored).
91 1.1 ad */
92 1.1 ad #ifndef PTRACE
93 1.2 itohy __weak_alias(sys_ptrace,sys_nosys);
94 1.3 ad #endif /* PTRACE */
95 1.3 ad
96 1.3 ad /*
97 1.3 ad * ktrace stubs. ktruser() goes to enosys as we want to fail the syscall,
98 1.3 ad * but not kill the process: utrace() is a debugging feature.
99 1.3 ad */
100 1.3 ad #ifndef KTRACE
101 1.3 ad __weak_alias(ktr_csw,nullop); /* Probes */
102 1.3 ad __weak_alias(ktr_emul,nullop);
103 1.3 ad __weak_alias(ktr_geniov,nullop);
104 1.3 ad __weak_alias(ktr_genio,nullop);
105 1.3 ad __weak_alias(ktr_mibio,nullop);
106 1.3 ad __weak_alias(ktr_namei,nullop);
107 1.3 ad __weak_alias(ktr_namei2,nullop);
108 1.3 ad __weak_alias(ktr_psig,nullop);
109 1.11 wrstuden __weak_alias(ktr_saupcall,nullop);
110 1.3 ad __weak_alias(ktr_syscall,nullop);
111 1.3 ad __weak_alias(ktr_sysret,nullop);
112 1.3 ad __weak_alias(ktr_kuser,nullop);
113 1.3 ad __weak_alias(ktr_mmsg,nullop);
114 1.3 ad __weak_alias(ktr_mib,nullop);
115 1.3 ad __weak_alias(ktr_mool,nullop);
116 1.3 ad __weak_alias(ktr_execarg,nullop);
117 1.3 ad __weak_alias(ktr_execenv,nullop);
118 1.3 ad
119 1.3 ad __weak_alias(sys_fktrace,sys_nosys); /* Syscalls */
120 1.3 ad __weak_alias(sys_ktrace,sys_nosys);
121 1.3 ad __weak_alias(sys_utrace,sys_nosys);
122 1.3 ad
123 1.3 ad int ktrace_on; /* Misc */
124 1.3 ad __weak_alias(ktruser,enosys);
125 1.4 dsl __weak_alias(ktr_point,nullop);
126 1.3 ad #endif /* KTRACE */
127 1.1 ad
128 1.15 ad #if !defined(KERN_SA)
129 1.1 ad /*
130 1.10 wrstuden * Scheduler activations system calls. These need to remain, even when
131 1.10 wrstuden * KERN_SA isn't defined, until libc's major version is bumped.
132 1.1 ad */
133 1.2 itohy __strong_alias(sys_sa_register,sys_nosys);
134 1.2 itohy __strong_alias(sys_sa_stacks,sys_nosys);
135 1.2 itohy __strong_alias(sys_sa_enable,sys_nosys);
136 1.2 itohy __strong_alias(sys_sa_setconcurrency,sys_nosys);
137 1.2 itohy __strong_alias(sys_sa_yield,sys_nosys);
138 1.2 itohy __strong_alias(sys_sa_preempt,sys_nosys);
139 1.2 itohy __strong_alias(sys_sa_unblockyield,sys_nosys);
140 1.15 ad
141 1.15 ad /*
142 1.15 ad * Stubs for compat_netbsd32.
143 1.15 ad */
144 1.15 ad __strong_alias(dosa_register,sys_nosys);
145 1.15 ad __strong_alias(sa_stacks1,sys_nosys);
146 1.10 wrstuden #endif
147 1.1 ad
148 1.9 ad /*
149 1.9 ad * Stubs for architectures that do not support kernel preemption.
150 1.9 ad */
151 1.8 ad #ifndef __HAVE_PREEMPTION
152 1.8 ad bool
153 1.8 ad cpu_kpreempt_enter(uintptr_t where, int s)
154 1.8 ad {
155 1.8 ad
156 1.8 ad return false;
157 1.8 ad }
158 1.8 ad
159 1.8 ad void
160 1.8 ad cpu_kpreempt_exit(uintptr_t where)
161 1.8 ad {
162 1.8 ad
163 1.8 ad }
164 1.8 ad
165 1.8 ad bool
166 1.8 ad cpu_kpreempt_disabled(void)
167 1.8 ad {
168 1.8 ad
169 1.8 ad return true;
170 1.8 ad }
171 1.9 ad #else
172 1.9 ad # ifndef MULTIPROCESSOR
173 1.9 ad # error __HAVE_PREEMPTION requires MULTIPROCESSOR
174 1.9 ad # endif
175 1.8 ad #endif /* !__HAVE_PREEMPTION */
176 1.8 ad
177 1.1 ad int
178 1.5 dsl sys_nosys(struct lwp *l, const void *v, register_t *retval)
179 1.1 ad {
180 1.1 ad
181 1.6 ad mutex_enter(proc_lock);
182 1.1 ad psignal(l->l_proc, SIGSYS);
183 1.6 ad mutex_exit(proc_lock);
184 1.1 ad return ENOSYS;
185 1.1 ad }
186 1.3 ad
187 1.12 ad int
188 1.12 ad sys_nomodule(struct lwp *l, const void *v, register_t *retval)
189 1.12 ad {
190 1.12 ad #ifdef MODULAR
191 1.12 ad static struct {
192 1.12 ad u_int al_code;
193 1.12 ad const char *al_module;
194 1.12 ad } const autoload[] = {
195 1.13 ad { SYS_aio_cancel, "aio" },
196 1.13 ad { SYS_aio_error, "aio" },
197 1.13 ad { SYS_aio_fsync, "aio" },
198 1.13 ad { SYS_aio_read, "aio" },
199 1.13 ad { SYS_aio_return, "aio" },
200 1.13 ad { SYS_aio_suspend, "aio" },
201 1.13 ad { SYS_aio_write, "aio" },
202 1.13 ad { SYS_lio_listio, "aio" },
203 1.14 ad { SYS_compat_43_fstat43, "compat" },
204 1.14 ad { SYS_compat_43_lstat43, "compat" },
205 1.14 ad { SYS_compat_43_oaccept, "compat" },
206 1.14 ad { SYS_compat_43_ocreat, "compat" },
207 1.14 ad { SYS_compat_43_oftruncate, "compat" },
208 1.14 ad { SYS_compat_43_ogetdirentries, "compat" },
209 1.14 ad { SYS_compat_43_ogetdtablesize, "compat" },
210 1.14 ad { SYS_compat_43_ogethostid, "compat" },
211 1.14 ad { SYS_compat_43_ogethostname, "compat" },
212 1.14 ad { SYS_compat_43_ogetkerninfo, "compat" },
213 1.14 ad { SYS_compat_43_ogetpagesize, "compat" },
214 1.14 ad { SYS_compat_43_ogetpeername, "compat" },
215 1.14 ad { SYS_compat_43_ogetrlimit, "compat" },
216 1.14 ad { SYS_compat_43_ogetsockname, "compat" },
217 1.14 ad { SYS_compat_43_okillpg, "compat" },
218 1.14 ad { SYS_compat_43_olseek, "compat" },
219 1.14 ad { SYS_compat_43_ommap, "compat" },
220 1.14 ad { SYS_compat_43_oquota, "compat" },
221 1.14 ad { SYS_compat_43_orecv, "compat" },
222 1.14 ad { SYS_compat_43_orecvfrom, "compat" },
223 1.14 ad { SYS_compat_43_orecvmsg, "compat" },
224 1.14 ad { SYS_compat_43_osend, "compat" },
225 1.14 ad { SYS_compat_43_osendmsg, "compat" },
226 1.14 ad { SYS_compat_43_osethostid, "compat" },
227 1.14 ad { SYS_compat_43_osethostname, "compat" },
228 1.14 ad { SYS_compat_43_osetrlimit, "compat" },
229 1.14 ad { SYS_compat_43_osigblock, "compat" },
230 1.14 ad { SYS_compat_43_osigsetmask, "compat" },
231 1.14 ad { SYS_compat_43_osigstack, "compat" },
232 1.14 ad { SYS_compat_43_osigvec, "compat" },
233 1.14 ad { SYS_compat_43_otruncate, "compat" },
234 1.14 ad { SYS_compat_43_owait, "compat" },
235 1.14 ad { SYS_compat_43_stat43, "compat" },
236 1.14 ad { SYS_compat_09_ogetdomainname, "compat" },
237 1.14 ad { SYS_compat_09_osetdomainname, "compat" },
238 1.14 ad { SYS_compat_09_ouname, "compat" },
239 1.14 ad #ifndef _LP64
240 1.14 ad { SYS_compat_10_omsgsys, "compat" },
241 1.14 ad { SYS_compat_10_osemsys, "compat" },
242 1.14 ad { SYS_compat_10_oshmsys, "compat" },
243 1.14 ad #endif
244 1.14 ad { SYS_compat_12_fstat12, "compat" },
245 1.14 ad { SYS_compat_12_getdirentries, "compat" },
246 1.14 ad { SYS_compat_12_lstat12, "compat" },
247 1.14 ad { SYS_compat_12_msync, "compat" },
248 1.14 ad { SYS_compat_12_oreboot, "compat" },
249 1.14 ad { SYS_compat_12_oswapon, "compat" },
250 1.14 ad { SYS_compat_12_stat12, "compat" },
251 1.14 ad { SYS_compat_13_sigaction13, "compat" },
252 1.14 ad { SYS_compat_13_sigaltstack13, "compat" },
253 1.14 ad { SYS_compat_13_sigpending13, "compat" },
254 1.14 ad { SYS_compat_13_sigprocmask13, "compat" },
255 1.14 ad { SYS_compat_13_sigreturn13, "compat" },
256 1.14 ad { SYS_compat_13_sigsuspend13, "compat" },
257 1.14 ad { SYS_compat_14___semctl, "compat" },
258 1.14 ad { SYS_compat_14_msgctl, "compat" },
259 1.14 ad { SYS_compat_14_shmctl, "compat" },
260 1.14 ad { SYS_compat_16___sigaction14, "compat" },
261 1.14 ad { SYS_compat_16___sigreturn14, "compat" },
262 1.14 ad { SYS_compat_20_fhstatfs, "compat" },
263 1.14 ad { SYS_compat_20_fstatfs, "compat" },
264 1.14 ad { SYS_compat_20_getfsstat, "compat" },
265 1.14 ad { SYS_compat_20_statfs, "compat" },
266 1.14 ad { SYS_compat_30___fhstat30, "compat" },
267 1.14 ad { SYS_compat_30___fstat13, "compat" },
268 1.14 ad { SYS_compat_30___lstat13, "compat" },
269 1.14 ad { SYS_compat_30___stat13, "compat" },
270 1.14 ad { SYS_compat_30_fhopen, "compat" },
271 1.14 ad { SYS_compat_30_fhstat, "compat" },
272 1.14 ad { SYS_compat_30_fhstatvfs1, "compat" },
273 1.14 ad { SYS_compat_30_getdents, "compat" },
274 1.14 ad { SYS_compat_30_getfh, "compat" },
275 1.14 ad { SYS_compat_30_socket, "compat" },
276 1.14 ad { SYS_compat_40_mount, "compat" },
277 1.13 ad { SYS__ksem_init, "ksem" },
278 1.13 ad { SYS__ksem_open, "ksem" },
279 1.13 ad { SYS__ksem_unlink, "ksem" },
280 1.13 ad { SYS__ksem_close, "ksem" },
281 1.13 ad { SYS__ksem_post, "ksem" },
282 1.13 ad { SYS__ksem_wait, "ksem" },
283 1.13 ad { SYS__ksem_trywait, "ksem" },
284 1.13 ad { SYS__ksem_getvalue, "ksem" },
285 1.13 ad { SYS__ksem_destroy, "ksem" },
286 1.14 ad { SYS_nfssvc, "nfsserver" },
287 1.12 ad };
288 1.12 ad const struct sysent *sy;
289 1.12 ad const struct emul *em;
290 1.12 ad int code, i;
291 1.12 ad
292 1.12 ad /*
293 1.12 ad * Restart the syscall if we interrupted a module unload that
294 1.12 ad * failed. Acquiring module_lock delays us until any unload
295 1.12 ad * has been completed or rolled back.
296 1.12 ad */
297 1.12 ad mutex_enter(&module_lock);
298 1.12 ad sy = l->l_sysent;
299 1.12 ad if (sy->sy_call != sys_nomodule) {
300 1.12 ad mutex_exit(&module_lock);
301 1.12 ad return ERESTART;
302 1.12 ad }
303 1.12 ad /*
304 1.12 ad * Try to autoload a module to satisfy the request. If it
305 1.12 ad * works, retry the request.
306 1.12 ad */
307 1.12 ad em = l->l_proc->p_emul;
308 1.12 ad if (em == &emul_netbsd) {
309 1.12 ad code = sy - em->e_sysent;
310 1.12 ad for (i = 0; i < __arraycount(autoload); i++) {
311 1.12 ad if (autoload[i].al_code != code) {
312 1.12 ad continue;
313 1.12 ad }
314 1.12 ad if (module_autoload(autoload[i].al_module,
315 1.12 ad MODULE_CLASS_ANY) != 0 ||
316 1.12 ad sy->sy_call == sys_nomodule) {
317 1.12 ad break;
318 1.12 ad }
319 1.12 ad mutex_exit(&module_lock);
320 1.12 ad return ERESTART;
321 1.12 ad }
322 1.12 ad }
323 1.12 ad mutex_exit(&module_lock);
324 1.12 ad #endif /* MODULAR */
325 1.12 ad
326 1.12 ad return sys_nosys(l, v, retval);
327 1.12 ad }
328 1.12 ad
329 1.3 ad /*
330 1.3 ad * Unsupported device function (e.g. writing to read-only device).
331 1.3 ad */
332 1.3 ad int
333 1.3 ad enodev(void)
334 1.3 ad {
335 1.3 ad
336 1.3 ad return (ENODEV);
337 1.3 ad }
338 1.3 ad
339 1.3 ad /*
340 1.3 ad * Unconfigured device function; driver not configured.
341 1.3 ad */
342 1.3 ad int
343 1.3 ad enxio(void)
344 1.3 ad {
345 1.3 ad
346 1.3 ad return (ENXIO);
347 1.3 ad }
348 1.3 ad
349 1.3 ad /*
350 1.3 ad * Unsupported ioctl function.
351 1.3 ad */
352 1.3 ad int
353 1.3 ad enoioctl(void)
354 1.3 ad {
355 1.3 ad
356 1.3 ad return (ENOTTY);
357 1.3 ad }
358 1.3 ad
359 1.3 ad /*
360 1.3 ad * Unsupported system function.
361 1.3 ad * This is used for an otherwise-reasonable operation
362 1.3 ad * that is not supported by the current system binary.
363 1.3 ad */
364 1.3 ad int
365 1.3 ad enosys(void)
366 1.3 ad {
367 1.3 ad
368 1.3 ad return (ENOSYS);
369 1.3 ad }
370 1.3 ad
371 1.3 ad /*
372 1.3 ad * Return error for operation not supported
373 1.3 ad * on a specific object or file type.
374 1.3 ad */
375 1.3 ad int
376 1.3 ad eopnotsupp(void)
377 1.3 ad {
378 1.3 ad
379 1.3 ad return (EOPNOTSUPP);
380 1.3 ad }
381 1.3 ad
382 1.3 ad /*
383 1.3 ad * Generic null operation, always returns success.
384 1.3 ad */
385 1.3 ad /*ARGSUSED*/
386 1.3 ad int
387 1.3 ad nullop(void *v)
388 1.3 ad {
389 1.3 ad
390 1.3 ad return (0);
391 1.3 ad }
392