Home | History | Annotate | Line # | Download | only in kern
kern_stub.c revision 1.13
      1 /*	$NetBSD: kern_stub.c,v 1.13 2008/11/14 23:33:45 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.13 2008/11/14 23:33:45 ad 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/signalvar.h>
     75 #include <sys/syscall.h>
     76 #include <sys/syscallargs.h>
     77 #include <sys/syscallvar.h>
     78 #include <sys/ktrace.h>
     79 #include <sys/intr.h>
     80 #include <sys/cpu.h>
     81 #include <sys/module.h>
     82 
     83 /*
     84  * Nonexistent system call-- signal process (may want to handle it).  Flag
     85  * error in case process won't see signal immediately (blocked or ignored).
     86  */
     87 #ifndef PTRACE
     88 __weak_alias(sys_ptrace,sys_nosys);
     89 #endif	/* PTRACE */
     90 
     91 /*
     92  * ktrace stubs.  ktruser() goes to enosys as we want to fail the syscall,
     93  * but not kill the process: utrace() is a debugging feature.
     94  */
     95 #ifndef KTRACE
     96 __weak_alias(ktr_csw,nullop);		/* Probes */
     97 __weak_alias(ktr_emul,nullop);
     98 __weak_alias(ktr_geniov,nullop);
     99 __weak_alias(ktr_genio,nullop);
    100 __weak_alias(ktr_mibio,nullop);
    101 __weak_alias(ktr_namei,nullop);
    102 __weak_alias(ktr_namei2,nullop);
    103 __weak_alias(ktr_psig,nullop);
    104 __weak_alias(ktr_saupcall,nullop);
    105 __weak_alias(ktr_syscall,nullop);
    106 __weak_alias(ktr_sysret,nullop);
    107 __weak_alias(ktr_kuser,nullop);
    108 __weak_alias(ktr_mmsg,nullop);
    109 __weak_alias(ktr_mib,nullop);
    110 __weak_alias(ktr_mool,nullop);
    111 __weak_alias(ktr_execarg,nullop);
    112 __weak_alias(ktr_execenv,nullop);
    113 
    114 __weak_alias(sys_fktrace,sys_nosys);	/* Syscalls */
    115 __weak_alias(sys_ktrace,sys_nosys);
    116 __weak_alias(sys_utrace,sys_nosys);
    117 
    118 int	ktrace_on;			/* Misc */
    119 __weak_alias(ktruser,enosys);
    120 __weak_alias(ktr_point,nullop);
    121 #endif	/* KTRACE */
    122 
    123 /*
    124  * Scheduler activations system calls.  These need to remain, even when
    125  * KERN_SA isn't defined, until libc's major version is bumped.
    126  */
    127 #if !defined(KERN_SA)
    128 __strong_alias(sys_sa_register,sys_nosys);
    129 __strong_alias(sys_sa_stacks,sys_nosys);
    130 __strong_alias(sys_sa_enable,sys_nosys);
    131 __strong_alias(sys_sa_setconcurrency,sys_nosys);
    132 __strong_alias(sys_sa_yield,sys_nosys);
    133 __strong_alias(sys_sa_preempt,sys_nosys);
    134 __strong_alias(sys_sa_unblockyield,sys_nosys);
    135 #endif
    136 
    137 /*
    138  * Stubs for architectures that do not support kernel preemption.
    139  */
    140 #ifndef __HAVE_PREEMPTION
    141 bool
    142 cpu_kpreempt_enter(uintptr_t where, int s)
    143 {
    144 
    145 	return false;
    146 }
    147 
    148 void
    149 cpu_kpreempt_exit(uintptr_t where)
    150 {
    151 
    152 }
    153 
    154 bool
    155 cpu_kpreempt_disabled(void)
    156 {
    157 
    158 	return true;
    159 }
    160 #else
    161 # ifndef MULTIPROCESSOR
    162 #   error __HAVE_PREEMPTION requires MULTIPROCESSOR
    163 # endif
    164 #endif	/* !__HAVE_PREEMPTION */
    165 
    166 int
    167 sys_nosys(struct lwp *l, const void *v, register_t *retval)
    168 {
    169 
    170 	mutex_enter(proc_lock);
    171 	psignal(l->l_proc, SIGSYS);
    172 	mutex_exit(proc_lock);
    173 	return ENOSYS;
    174 }
    175 
    176 int
    177 sys_nomodule(struct lwp *l, const void *v, register_t *retval)
    178 {
    179 #ifdef MODULAR
    180 	static struct {
    181 		u_int		al_code;
    182 		const char	*al_module;
    183 	} const autoload[] = {
    184 	    { SYS_aio_cancel, "aio" },
    185 	    { SYS_aio_error, "aio" },
    186 	    { SYS_aio_fsync, "aio" },
    187 	    { SYS_aio_read, "aio" },
    188 	    { SYS_aio_return, "aio" },
    189 	    { SYS_aio_suspend, "aio" },
    190 	    { SYS_aio_write, "aio" },
    191 	    { SYS_lio_listio, "aio" },
    192 	    { SYS__ksem_init, "ksem" },
    193 	    { SYS__ksem_open, "ksem" },
    194 	    { SYS__ksem_unlink, "ksem" },
    195 	    { SYS__ksem_close, "ksem" },
    196 	    { SYS__ksem_post, "ksem" },
    197 	    { SYS__ksem_wait, "ksem" },
    198 	    { SYS__ksem_trywait, "ksem" },
    199 	    { SYS__ksem_getvalue, "ksem" },
    200 	    { SYS__ksem_destroy, "ksem" },
    201 	};
    202 	const struct sysent *sy;
    203 	const struct emul *em;
    204 	int code, i;
    205 
    206 	/*
    207 	 * Restart the syscall if we interrupted a module unload that
    208 	 * failed.  Acquiring module_lock delays us until any unload
    209 	 * has been completed or rolled back.
    210 	 */
    211 	mutex_enter(&module_lock);
    212 	sy = l->l_sysent;
    213 	if (sy->sy_call != sys_nomodule) {
    214 		mutex_exit(&module_lock);
    215 		return ERESTART;
    216 	}
    217 	/*
    218 	 * Try to autoload a module to satisfy the request.  If it
    219 	 * works, retry the request.
    220 	 */
    221 	em = l->l_proc->p_emul;
    222 	if (em == &emul_netbsd) {
    223 		code = sy - em->e_sysent;
    224 		for (i = 0; i < __arraycount(autoload); i++) {
    225 			if (autoload[i].al_code != code) {
    226 				continue;
    227 			}
    228 			if (module_autoload(autoload[i].al_module,
    229 			    MODULE_CLASS_ANY) != 0 ||
    230 			    sy->sy_call == sys_nomodule) {
    231 			    	break;
    232 			}
    233 			mutex_exit(&module_lock);
    234 			return ERESTART;
    235 		}
    236 	}
    237 	mutex_exit(&module_lock);
    238 #endif	/* MODULAR */
    239 
    240 	return sys_nosys(l, v, retval);
    241 }
    242 
    243 /*
    244  * Unsupported device function (e.g. writing to read-only device).
    245  */
    246 int
    247 enodev(void)
    248 {
    249 
    250 	return (ENODEV);
    251 }
    252 
    253 /*
    254  * Unconfigured device function; driver not configured.
    255  */
    256 int
    257 enxio(void)
    258 {
    259 
    260 	return (ENXIO);
    261 }
    262 
    263 /*
    264  * Unsupported ioctl function.
    265  */
    266 int
    267 enoioctl(void)
    268 {
    269 
    270 	return (ENOTTY);
    271 }
    272 
    273 /*
    274  * Unsupported system function.
    275  * This is used for an otherwise-reasonable operation
    276  * that is not supported by the current system binary.
    277  */
    278 int
    279 enosys(void)
    280 {
    281 
    282 	return (ENOSYS);
    283 }
    284 
    285 /*
    286  * Return error for operation not supported
    287  * on a specific object or file type.
    288  */
    289 int
    290 eopnotsupp(void)
    291 {
    292 
    293 	return (EOPNOTSUPP);
    294 }
    295 
    296 /*
    297  * Generic null operation, always returns success.
    298  */
    299 /*ARGSUSED*/
    300 int
    301 nullop(void *v)
    302 {
    303 
    304 	return (0);
    305 }
    306