1 /* $NetBSD: kern_stub.c,v 1.15 2008/11/20 09:30:32 ad 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.15 2008/11/20 09:30:32 ad Exp $"); 66 67 #include "opt_ptrace.h" 68 #include "opt_ktrace.h" 69 #include "opt_sa.h" 70 71 /* XXX To get syscall prototypes. */ 72 #define SYSVSHM 73 #define SYSVSEM 74 #define SYSVMSG 75 76 #include <sys/param.h> 77 #include <sys/kernel.h> 78 #include <sys/proc.h> 79 #include <sys/signalvar.h> 80 #include <sys/syscall.h> 81 #include <sys/syscallargs.h> 82 #include <sys/syscallvar.h> 83 #include <sys/ktrace.h> 84 #include <sys/intr.h> 85 #include <sys/cpu.h> 86 #include <sys/module.h> 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_mmsg,nullop); 114 __weak_alias(ktr_mib,nullop); 115 __weak_alias(ktr_mool,nullop); 116 __weak_alias(ktr_execarg,nullop); 117 __weak_alias(ktr_execenv,nullop); 118 119 __weak_alias(sys_fktrace,sys_nosys); /* Syscalls */ 120 __weak_alias(sys_ktrace,sys_nosys); 121 __weak_alias(sys_utrace,sys_nosys); 122 123 int ktrace_on; /* Misc */ 124 __weak_alias(ktruser,enosys); 125 __weak_alias(ktr_point,nullop); 126 #endif /* KTRACE */ 127 128 #if !defined(KERN_SA) 129 /* 130 * Scheduler activations system calls. These need to remain, even when 131 * KERN_SA isn't defined, until libc's major version is bumped. 132 */ 133 __strong_alias(sys_sa_register,sys_nosys); 134 __strong_alias(sys_sa_stacks,sys_nosys); 135 __strong_alias(sys_sa_enable,sys_nosys); 136 __strong_alias(sys_sa_setconcurrency,sys_nosys); 137 __strong_alias(sys_sa_yield,sys_nosys); 138 __strong_alias(sys_sa_preempt,sys_nosys); 139 __strong_alias(sys_sa_unblockyield,sys_nosys); 140 141 /* 142 * Stubs for compat_netbsd32. 143 */ 144 __strong_alias(dosa_register,sys_nosys); 145 __strong_alias(sa_stacks1,sys_nosys); 146 #endif 147 148 /* 149 * Stubs for architectures that do not support kernel preemption. 150 */ 151 #ifndef __HAVE_PREEMPTION 152 bool 153 cpu_kpreempt_enter(uintptr_t where, int s) 154 { 155 156 return false; 157 } 158 159 void 160 cpu_kpreempt_exit(uintptr_t where) 161 { 162 163 } 164 165 bool 166 cpu_kpreempt_disabled(void) 167 { 168 169 return true; 170 } 171 #else 172 # ifndef MULTIPROCESSOR 173 # error __HAVE_PREEMPTION requires MULTIPROCESSOR 174 # endif 175 #endif /* !__HAVE_PREEMPTION */ 176 177 int 178 sys_nosys(struct lwp *l, const void *v, register_t *retval) 179 { 180 181 mutex_enter(proc_lock); 182 psignal(l->l_proc, SIGSYS); 183 mutex_exit(proc_lock); 184 return ENOSYS; 185 } 186 187 int 188 sys_nomodule(struct lwp *l, const void *v, register_t *retval) 189 { 190 #ifdef MODULAR 191 static struct { 192 u_int al_code; 193 const char *al_module; 194 } const autoload[] = { 195 { SYS_aio_cancel, "aio" }, 196 { SYS_aio_error, "aio" }, 197 { SYS_aio_fsync, "aio" }, 198 { SYS_aio_read, "aio" }, 199 { SYS_aio_return, "aio" }, 200 { SYS_aio_suspend, "aio" }, 201 { SYS_aio_write, "aio" }, 202 { SYS_lio_listio, "aio" }, 203 { SYS_compat_43_fstat43, "compat" }, 204 { SYS_compat_43_lstat43, "compat" }, 205 { SYS_compat_43_oaccept, "compat" }, 206 { SYS_compat_43_ocreat, "compat" }, 207 { SYS_compat_43_oftruncate, "compat" }, 208 { SYS_compat_43_ogetdirentries, "compat" }, 209 { SYS_compat_43_ogetdtablesize, "compat" }, 210 { SYS_compat_43_ogethostid, "compat" }, 211 { SYS_compat_43_ogethostname, "compat" }, 212 { SYS_compat_43_ogetkerninfo, "compat" }, 213 { SYS_compat_43_ogetpagesize, "compat" }, 214 { SYS_compat_43_ogetpeername, "compat" }, 215 { SYS_compat_43_ogetrlimit, "compat" }, 216 { SYS_compat_43_ogetsockname, "compat" }, 217 { SYS_compat_43_okillpg, "compat" }, 218 { SYS_compat_43_olseek, "compat" }, 219 { SYS_compat_43_ommap, "compat" }, 220 { SYS_compat_43_oquota, "compat" }, 221 { SYS_compat_43_orecv, "compat" }, 222 { SYS_compat_43_orecvfrom, "compat" }, 223 { SYS_compat_43_orecvmsg, "compat" }, 224 { SYS_compat_43_osend, "compat" }, 225 { SYS_compat_43_osendmsg, "compat" }, 226 { SYS_compat_43_osethostid, "compat" }, 227 { SYS_compat_43_osethostname, "compat" }, 228 { SYS_compat_43_osetrlimit, "compat" }, 229 { SYS_compat_43_osigblock, "compat" }, 230 { SYS_compat_43_osigsetmask, "compat" }, 231 { SYS_compat_43_osigstack, "compat" }, 232 { SYS_compat_43_osigvec, "compat" }, 233 { SYS_compat_43_otruncate, "compat" }, 234 { SYS_compat_43_owait, "compat" }, 235 { SYS_compat_43_stat43, "compat" }, 236 { SYS_compat_09_ogetdomainname, "compat" }, 237 { SYS_compat_09_osetdomainname, "compat" }, 238 { SYS_compat_09_ouname, "compat" }, 239 #ifndef _LP64 240 { SYS_compat_10_omsgsys, "compat" }, 241 { SYS_compat_10_osemsys, "compat" }, 242 { SYS_compat_10_oshmsys, "compat" }, 243 #endif 244 { SYS_compat_12_fstat12, "compat" }, 245 { SYS_compat_12_getdirentries, "compat" }, 246 { SYS_compat_12_lstat12, "compat" }, 247 { SYS_compat_12_msync, "compat" }, 248 { SYS_compat_12_oreboot, "compat" }, 249 { SYS_compat_12_oswapon, "compat" }, 250 { SYS_compat_12_stat12, "compat" }, 251 { SYS_compat_13_sigaction13, "compat" }, 252 { SYS_compat_13_sigaltstack13, "compat" }, 253 { SYS_compat_13_sigpending13, "compat" }, 254 { SYS_compat_13_sigprocmask13, "compat" }, 255 { SYS_compat_13_sigreturn13, "compat" }, 256 { SYS_compat_13_sigsuspend13, "compat" }, 257 { SYS_compat_14___semctl, "compat" }, 258 { SYS_compat_14_msgctl, "compat" }, 259 { SYS_compat_14_shmctl, "compat" }, 260 { SYS_compat_16___sigaction14, "compat" }, 261 { SYS_compat_16___sigreturn14, "compat" }, 262 { SYS_compat_20_fhstatfs, "compat" }, 263 { SYS_compat_20_fstatfs, "compat" }, 264 { SYS_compat_20_getfsstat, "compat" }, 265 { SYS_compat_20_statfs, "compat" }, 266 { SYS_compat_30___fhstat30, "compat" }, 267 { SYS_compat_30___fstat13, "compat" }, 268 { SYS_compat_30___lstat13, "compat" }, 269 { SYS_compat_30___stat13, "compat" }, 270 { SYS_compat_30_fhopen, "compat" }, 271 { SYS_compat_30_fhstat, "compat" }, 272 { SYS_compat_30_fhstatvfs1, "compat" }, 273 { SYS_compat_30_getdents, "compat" }, 274 { SYS_compat_30_getfh, "compat" }, 275 { SYS_compat_30_socket, "compat" }, 276 { SYS_compat_40_mount, "compat" }, 277 { SYS__ksem_init, "ksem" }, 278 { SYS__ksem_open, "ksem" }, 279 { SYS__ksem_unlink, "ksem" }, 280 { SYS__ksem_close, "ksem" }, 281 { SYS__ksem_post, "ksem" }, 282 { SYS__ksem_wait, "ksem" }, 283 { SYS__ksem_trywait, "ksem" }, 284 { SYS__ksem_getvalue, "ksem" }, 285 { SYS__ksem_destroy, "ksem" }, 286 { SYS_nfssvc, "nfsserver" }, 287 }; 288 const struct sysent *sy; 289 const struct emul *em; 290 int code, i; 291 292 /* 293 * Restart the syscall if we interrupted a module unload that 294 * failed. Acquiring module_lock delays us until any unload 295 * has been completed or rolled back. 296 */ 297 mutex_enter(&module_lock); 298 sy = l->l_sysent; 299 if (sy->sy_call != sys_nomodule) { 300 mutex_exit(&module_lock); 301 return ERESTART; 302 } 303 /* 304 * Try to autoload a module to satisfy the request. If it 305 * works, retry the request. 306 */ 307 em = l->l_proc->p_emul; 308 if (em == &emul_netbsd) { 309 code = sy - em->e_sysent; 310 for (i = 0; i < __arraycount(autoload); i++) { 311 if (autoload[i].al_code != code) { 312 continue; 313 } 314 if (module_autoload(autoload[i].al_module, 315 MODULE_CLASS_ANY) != 0 || 316 sy->sy_call == sys_nomodule) { 317 break; 318 } 319 mutex_exit(&module_lock); 320 return ERESTART; 321 } 322 } 323 mutex_exit(&module_lock); 324 #endif /* MODULAR */ 325 326 return sys_nosys(l, v, retval); 327 } 328 329 /* 330 * Unsupported device function (e.g. writing to read-only device). 331 */ 332 int 333 enodev(void) 334 { 335 336 return (ENODEV); 337 } 338 339 /* 340 * Unconfigured device function; driver not configured. 341 */ 342 int 343 enxio(void) 344 { 345 346 return (ENXIO); 347 } 348 349 /* 350 * Unsupported ioctl function. 351 */ 352 int 353 enoioctl(void) 354 { 355 356 return (ENOTTY); 357 } 358 359 /* 360 * Unsupported system function. 361 * This is used for an otherwise-reasonable operation 362 * that is not supported by the current system binary. 363 */ 364 int 365 enosys(void) 366 { 367 368 return (ENOSYS); 369 } 370 371 /* 372 * Return error for operation not supported 373 * on a specific object or file type. 374 */ 375 int 376 eopnotsupp(void) 377 { 378 379 return (EOPNOTSUPP); 380 } 381 382 /* 383 * Generic null operation, always returns success. 384 */ 385 /*ARGSUSED*/ 386 int 387 nullop(void *v) 388 { 389 390 return (0); 391 } 392