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