1 /* $NetBSD: kern_stub.c,v 1.58 2026/11/10 03:43:27 thorpej 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.58 2026/11/10 03:43:27 thorpej Exp $"); 66 67 #ifdef _KERNEL_OPT 68 #include "opt_ddb.h" 69 #include "opt_ktrace.h" 70 #include "opt_sysv.h" 71 #include "opt_modular.h" 72 #endif 73 74 #include <sys/param.h> 75 76 #include <sys/bus.h> 77 #include <sys/cpu.h> 78 #include <sys/fstypes.h> 79 #include <sys/intr.h> 80 #include <sys/kernel.h> 81 #include <sys/ktrace.h> 82 #include <sys/module.h> 83 #include <sys/proc.h> 84 #include <sys/sdt.h> 85 #include <sys/signalvar.h> 86 #include <sys/syscall.h> 87 #include <sys/userconf.h> 88 89 #include <ddb/db_active.h> 90 #ifdef DDB 91 #include <ddb/ddbvar.h> 92 #endif 93 94 bool default_bus_space_is_equal(bus_space_tag_t, bus_space_tag_t); 95 bool default_bus_space_handle_is_equal(bus_space_tag_t, bus_space_handle_t, 96 bus_space_handle_t); 97 98 /* 99 * SYSV Semaphores, Shared Memory, Message Queues 100 */ 101 #ifndef MODULAR 102 #ifndef SYSVMSG 103 __strong_alias(msgctl1,enosys); 104 #endif 105 #ifndef SYSVSHM 106 __strong_alias(shmctl1,enosys); 107 #endif 108 #ifndef SYSVSEM 109 __strong_alias(semctl1,enosys); 110 #endif 111 #endif 112 113 /* 114 * ktrace stubs. ktruser() goes to enosys as we want to fail the syscall, 115 * but not kill the process: utrace() is a debugging feature. 116 */ 117 #ifndef KTRACE 118 __strong_alias(ktr_csw,nullop); /* Probes */ 119 __strong_alias(ktr_emul,nullop); 120 __strong_alias(ktr_geniov,nullop); 121 __strong_alias(ktr_genio,nullop); 122 __strong_alias(ktr_mibio,nullop); 123 __strong_alias(ktr_namei,nullop); 124 __strong_alias(ktr_namei2,nullop); 125 __strong_alias(ktr_psig,nullop); 126 __strong_alias(ktr_syscall,nullop); 127 __strong_alias(ktr_sysret,nullop); 128 __strong_alias(ktr_kuser,nullop); 129 __strong_alias(ktr_mib,nullop); 130 __strong_alias(ktr_execarg,nullop); 131 __strong_alias(ktr_execenv,nullop); 132 __strong_alias(ktr_execfd,nullop); 133 __strong_alias(ktr_sigmask,nullop); 134 135 __strong_alias(sys_fktrace,sys_nosys); /* Syscalls */ 136 __strong_alias(sys_ktrace,sys_nosys); 137 __strong_alias(sys_utrace,sys_nosys); 138 139 int ktrace_on; /* Misc */ 140 __strong_alias(ktruser,enosys); 141 __strong_alias(ktr_point,nullop); 142 #endif /* KTRACE */ 143 144 __weak_alias(device_register, voidop); 145 __weak_alias(device_register_post_config, voidop); 146 __weak_alias(spldebug_start, voidop); 147 __weak_alias(spldebug_stop, voidop); 148 __weak_alias(machdep_init,nullop); 149 __weak_alias(pci_chipset_tag_create, eopnotsupp); 150 __weak_alias(pci_chipset_tag_destroy, voidop); 151 __weak_alias(bus_space_reserve, eopnotsupp); 152 __weak_alias(bus_space_reserve_subregion, eopnotsupp); 153 __weak_alias(bus_space_release, voidop); 154 __weak_alias(bus_space_reservation_map, eopnotsupp); 155 __weak_alias(bus_space_reservation_unmap, voidop); 156 __weak_alias(bus_dma_tag_create, eopnotsupp); 157 __weak_alias(bus_dma_tag_destroy, voidop); 158 __weak_alias(bus_space_tag_create, eopnotsupp); 159 __weak_alias(bus_space_tag_destroy, voidop); 160 __strict_weak_alias(bus_space_is_equal, default_bus_space_is_equal); 161 __strict_weak_alias(bus_space_handle_is_equal, 162 default_bus_space_handle_is_equal); 163 __weak_alias(userconf_bootinfo, voidop); 164 __weak_alias(userconf_init, voidop); 165 __weak_alias(userconf_prompt, voidop); 166 167 #ifdef MODULAR 168 __weak_alias(module_init_md, voidop); 169 #endif 170 171 __weak_alias(kobj_renamespace, nullop); 172 173 __weak_alias(interrupt_get_count, nullop); 174 __weak_alias(interrupt_get_assigned, voidop); 175 __weak_alias(interrupt_get_available, voidop); 176 __weak_alias(interrupt_get_devname, voidop); 177 __weak_alias(interrupt_construct_intrids, nullret); 178 __weak_alias(interrupt_destruct_intrids, voidop); 179 __weak_alias(interrupt_distribute, eopnotsupp); 180 __weak_alias(interrupt_distribute_handler, eopnotsupp); 181 182 __weak_alias(ipi_register, trueop); /* just a low non-zero value */ 183 __weak_alias(ipi_unregister, voidop); 184 __weak_alias(ipi_trigger, voidop); 185 __weak_alias(ipi_trigger_multi, voidop); 186 __weak_alias(ipi_trigger_broadcast, voidop); 187 188 __weak_alias(ipi_unicast, trueop); 189 __weak_alias(ipi_multicast, voidop); 190 __weak_alias(ipi_broadcast, voidop); 191 __weak_alias(ipi_wait, voidop); 192 193 /* 194 * Scheduler activations system calls. These need to remain until libc's 195 * major version is bumped. 196 */ 197 __strong_alias(sys_sa_register,sys_nosys); 198 __strong_alias(sys_sa_stacks,sys_nosys); 199 __strong_alias(sys_sa_enable,sys_nosys); 200 __strong_alias(sys_sa_setconcurrency,sys_nosys); 201 __strong_alias(sys_sa_yield,sys_nosys); 202 __strong_alias(sys_sa_preempt,sys_nosys); 203 __strong_alias(sys_sa_unblockyield,sys_nosys); 204 205 /* 206 * Stubs for compat_netbsd32. 207 */ 208 __strong_alias(dosa_register,sys_nosys); 209 __strong_alias(sa_stacks1,sys_nosys); 210 211 /* 212 * Stubs for drivers. See sys/conf.h. 213 */ 214 __strong_alias(devenodev,enodev); 215 __strong_alias(deveopnotsupp,eopnotsupp); 216 __strong_alias(devnullop,nullop); 217 __strong_alias(ttyenodev,enodev); 218 __strong_alias(ttyvenodev,voidop); 219 __strong_alias(ttyvnullop,nullop); 220 221 /* 222 * Stubs for architectures that do not support kernel preemption. 223 */ 224 #ifndef __HAVE_PREEMPTION 225 bool 226 cpu_kpreempt_enter(uintptr_t where, int s) 227 { 228 229 return false; 230 } 231 232 void 233 cpu_kpreempt_exit(uintptr_t where) 234 { 235 236 } 237 238 bool 239 cpu_kpreempt_disabled(void) 240 { 241 242 return true; 243 } 244 #else 245 # ifndef MULTIPROCESSOR 246 # error __HAVE_PREEMPTION requires MULTIPROCESSOR 247 # endif 248 #endif /* !__HAVE_PREEMPTION */ 249 250 int 251 sys_nosys(struct lwp *l, const void *v, register_t *retval) 252 { 253 254 mutex_enter(&proc_lock); 255 psignal(l->l_proc, SIGSYS); 256 mutex_exit(&proc_lock); 257 return SET_ERROR(ENOSYS); 258 } 259 260 /* 261 * Unsupported device function (e.g. writing to read-only device). 262 */ 263 int 264 enodev(void) 265 { 266 267 return SET_ERROR(ENODEV); 268 } 269 270 /* 271 * Unconfigured device function; driver not configured. 272 */ 273 int 274 enxio(void) 275 { 276 277 return SET_ERROR(ENXIO); 278 } 279 280 /* 281 * Unsupported ioctl function. 282 */ 283 int 284 enoioctl(void) 285 { 286 287 return SET_ERROR(ENOTTY); 288 } 289 290 /* 291 * Unsupported system function. 292 * This is used for an otherwise-reasonable operation 293 * that is not supported by the current system binary. 294 */ 295 int 296 enosys(void) 297 { 298 299 return SET_ERROR(ENOSYS); 300 } 301 302 /* 303 * Return error for operation not supported 304 * on a specific object or file type. 305 */ 306 int 307 eopnotsupp(void) 308 { 309 310 return SET_ERROR(EOPNOTSUPP); 311 } 312 313 /* 314 * Generic null operation, void return value. 315 */ 316 void 317 voidop(void) 318 { 319 } 320 321 /* 322 * Generic null operation, always returns success. 323 */ 324 int 325 nullop(void *v) 326 { 327 328 return (0); 329 } 330 331 /* 332 * Generic "true" operation, always returns true (but as an int). 333 */ 334 int 335 trueop(void) 336 { 337 return true; 338 } 339 340 /* 341 * Generic null operation, always returns null. 342 */ 343 void * 344 nullret(void) 345 { 346 347 return (NULL); 348 } 349 350 bool 351 default_bus_space_handle_is_equal(bus_space_tag_t t, 352 bus_space_handle_t h1, bus_space_handle_t h2) 353 { 354 355 return memcmp(&h1, &h2, sizeof(h1)) == 0; 356 } 357 358 bool 359 default_bus_space_is_equal(bus_space_tag_t t1, bus_space_tag_t t2) 360 { 361 362 return memcmp(&t1, &t2, sizeof(t1)) == 0; 363 } 364 365 /* Stubs for architectures with no kernel FPU access. */ 366 __weak_alias(kthread_fpu_enter_md, voidop); 367 __weak_alias(kthread_fpu_exit_md, voidop); 368 369 /* 370 * Kernel debugger-related stubs. 371 * 372 * N.B. Always declare db_active; it's referenced by drivers for certain 373 * kinds of console-related logic. 374 */ 375 int db_active; 376 377 __weak_alias(cpu_Debugger, voidop); 378 379 void 380 console_debugger(void) 381 { 382 #ifdef DDB 383 if (db_fromconsole) { 384 cpu_Debugger(); 385 } 386 #endif 387 } 388