1 /* $NetBSD: systm.h,v 1.308 2026/05/26 14:57:25 simonb Exp $ */ 2 3 /*- 4 * Copyright (c) 1982, 1988, 1991, 1993 5 * The Regents of the University of California. All rights reserved. 6 * (c) UNIX System Laboratories, Inc. 7 * All or some portions of this file are derived from material licensed 8 * to the University of California by American Telephone and Telegraph 9 * Co. or Unix System Laboratories, Inc. and are reproduced herein with 10 * the permission of UNIX System Laboratories, Inc. 11 * 12 * Redistribution and use in source and binary forms, with or without 13 * modification, are permitted provided that the following conditions 14 * are met: 15 * 1. Redistributions of source code must retain the above copyright 16 * notice, this list of conditions and the following disclaimer. 17 * 2. Redistributions in binary form must reproduce the above copyright 18 * notice, this list of conditions and the following disclaimer in the 19 * documentation and/or other materials provided with the distribution. 20 * 3. Neither the name of the University nor the names of its contributors 21 * may be used to endorse or promote products derived from this software 22 * without specific prior written permission. 23 * 24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 * SUCH DAMAGE. 35 * 36 * @(#)systm.h 8.7 (Berkeley) 3/29/95 37 */ 38 39 #ifndef _SYS_SYSTM_H_ 40 #define _SYS_SYSTM_H_ 41 42 #if defined(_KERNEL_OPT) 43 #include "opt_ddb.h" 44 #include "opt_multiprocessor.h" 45 #include "opt_gprof.h" 46 #include "opt_kasan.h" 47 #include "opt_kcsan.h" 48 #include "opt_kmsan.h" 49 #include "opt_modular.h" 50 #include "opt_wsdisplay_compat.h" 51 #endif 52 #if !defined(_KERNEL) && !defined(_STANDALONE) 53 #include <stdbool.h> 54 #endif 55 56 #include <machine/endian.h> 57 58 #include <sys/types.h> 59 #include <sys/stdarg.h> 60 61 #include <sys/device_if.h> 62 63 struct clockframe; 64 struct lwp; 65 struct proc; 66 struct rootspechook; 67 struct sysent; 68 struct timeval; 69 struct tty; 70 struct uio; 71 struct vmspace; 72 struct vnode; 73 74 extern const char *panicstr; /* panic message */ 75 extern int doing_shutdown; /* shutting down */ 76 77 extern const char copyright[]; /* system copyright */ 78 extern char machine[]; /* machine type */ 79 extern char machine_arch[]; /* machine architecture */ 80 extern const char osrelease[]; /* short system version */ 81 extern const char ostype[]; /* system type */ 82 extern const char kernel_ident[];/* kernel configuration ID */ 83 extern const char version[]; /* system version */ 84 extern const char buildinfo[]; /* information from build environment */ 85 86 extern int autonicetime; /* time (in seconds) before autoniceval */ 87 extern int autoniceval; /* proc priority after autonicetime */ 88 89 extern int selwait; /* select timeout address */ 90 91 extern int maxmem; /* max memory per process */ 92 extern psize_t physmem; /* physical memory */ 93 94 extern dev_t dumpdev; /* dump device */ 95 extern dev_t dumpcdev; /* dump device (character equivalent) */ 96 extern long dumplo; /* offset into dumpdev */ 97 extern int dumpsize; /* size of dump in pages */ 98 extern const char *dumpspec; /* how dump device was specified */ 99 100 extern dev_t rootdev; /* root device */ 101 extern struct vnode *rootvp; /* vnode equivalent to above */ 102 extern device_t root_device; /* device equivalent to above */ 103 extern const char *rootspec; /* how root device was specified */ 104 105 extern int ncpu; /* number of CPUs configured */ 106 extern int ncpuonline; /* number of CPUs online */ 107 #if defined(_KERNEL) 108 extern bool mp_online; /* secondary processors are started */ 109 #endif /* defined(_KERNEL) */ 110 111 extern const char hexdigits[]; /* "0123456789abcdef" in subr_prf.c */ 112 extern const char HEXDIGITS[]; /* "0123456789ABCDEF" in subr_prf.c */ 113 114 /* 115 * These represent the swap pseudo-device (`sw'). This device 116 * is used by the swap pager to indirect through the routines 117 * in sys/vm/vm_swap.c. 118 */ 119 extern const dev_t swapdev; /* swapping device */ 120 extern struct vnode *swapdev_vp;/* vnode equivalent to above */ 121 122 extern const dev_t zerodev; /* /dev/zero */ 123 124 #if defined(_KERNEL) 125 typedef int sy_call_t(struct lwp *, const void *, register_t *); 126 127 extern struct sysent { /* system call table */ 128 short sy_narg; /* number of args */ 129 short sy_argsize; /* total size of arguments */ 130 int sy_flags; /* flags. see below */ 131 sy_call_t *sy_call; /* implementing function */ 132 uint32_t sy_entry; /* DTrace entry ID for systrace. */ 133 uint32_t sy_return; /* DTrace return ID for systrace. */ 134 } sysent[]; 135 extern int nsysent; 136 extern const uint32_t sysent_nomodbits[]; 137 #endif 138 139 #if BYTE_ORDER == BIG_ENDIAN 140 #define SCARG(p,k) ((p)->k.be.datum) /* get arg from args pointer */ 141 #elif BYTE_ORDER == LITTLE_ENDIAN 142 #define SCARG(p,k) ((p)->k.le.datum) /* get arg from args pointer */ 143 #else 144 #error "what byte order is this machine?" 145 #endif 146 147 #define SYCALL_INDIRECT 0x0000002 /* indirect (ie syscall() or __syscall()) */ 148 #define SYCALL_NARGS64_MASK 0x000f000 /* count of 64bit args */ 149 #define SYCALL_RET_64 0x0010000 /* retval is a 64bit integer value */ 150 #define SYCALL_ARG0_64 0x0020000 151 #define SYCALL_ARG1_64 0x0040000 152 #define SYCALL_ARG2_64 0x0080000 153 #define SYCALL_ARG3_64 0x0100000 154 #define SYCALL_ARG4_64 0x0200000 155 #define SYCALL_ARG5_64 0x0400000 156 #define SYCALL_ARG6_64 0x0800000 157 #define SYCALL_ARG7_64 0x1000000 158 #define SYCALL_NOSYS 0x2000000 /* permanent nosys in sysent[] */ 159 #define SYCALL_ARG_PTR 0x4000000 /* at least one argument is a pointer */ 160 #define SYCALL_RET_WIDE 0x8000000 /* retval wider than 32 bits on LP64 */ 161 #define SYCALL_RET_64_P(sy) ((sy)->sy_flags & SYCALL_RET_64) 162 #define SYCALL_RET_WIDE_P(sy) ((sy)->sy_flags & SYCALL_RET_WIDE) 163 #define SYCALL_ARG_64_P(sy, n) ((sy)->sy_flags & (SYCALL_ARG0_64 << (n))) 164 #define SYCALL_ARG_64_MASK(sy) (((sy)->sy_flags >> 17) & 0xff) 165 #define SYCALL_ARG_PTR_P(sy) ((sy)->sy_flags & SYCALL_ARG_PTR) 166 #define SYCALL_NARGS64(sy) (((sy)->sy_flags >> 12) & 0x0f) 167 #define SYCALL_NARGS64_VAL(n) ((n) << 12) 168 169 extern int boothowto; /* reboot flags, from console subsystem */ 170 #define bootverbose (boothowto & AB_VERBOSE) 171 #define bootquiet (boothowto & AB_QUIET) 172 173 extern const char *get_booted_kernel(void); 174 175 extern void (*v_putc)(int); /* Virtual console putc routine */ 176 177 /* 178 * General function declarations. 179 */ 180 void voidop(void); 181 int nullop(void *); 182 void* nullret(void); 183 int enodev(void); 184 int enosys(void); 185 int enoioctl(void); 186 int enxio(void); 187 int eopnotsupp(void); 188 189 enum hashtype { 190 HASH_LIST, 191 HASH_SLIST, 192 HASH_TAILQ, 193 HASH_PSLIST 194 }; 195 196 #ifdef _KERNEL 197 #define COND_SET_STRUCT(dst, src, allow) \ 198 do { \ 199 /* \ 200 * Make sure we don't end up hashing/assigning large \ 201 * structure for performance. Upper-bound is arbitrary, \ 202 * but consider before bumping. \ 203 */ \ 204 CTASSERT(sizeof(src) < 32); \ 205 if (allow) \ 206 dst = src; \ 207 else \ 208 hash_value(&dst, sizeof(dst), &src, sizeof(src)); \ 209 } while (0) 210 211 #define COND_SET_CPTR(dst, src, allow) \ 212 do { \ 213 if (allow) \ 214 dst = src; \ 215 else { \ 216 void *__v; \ 217 hash_value(&__v, sizeof(__v), &src, sizeof(src)); \ 218 dst = __v; \ 219 } \ 220 } while (0) 221 222 #define COND_SET_PTR(dst, src, allow) \ 223 do { \ 224 if (allow) \ 225 dst = src; \ 226 else \ 227 hash_value(&dst, sizeof(dst), &src, sizeof(src)); \ 228 } while (0) 229 230 #define COND_SET_VALUE(dst, src, allow) \ 231 do { \ 232 if (allow) \ 233 dst = src; \ 234 else { \ 235 uint64_t __v = src; \ 236 hash_value(&dst, sizeof(dst), &__v, sizeof(__v)); \ 237 } \ 238 } while (0) 239 240 void hash_value(void *, size_t, const void *, size_t); 241 void hash_value_ensure_initialized(void); 242 243 bool get_expose_address(struct proc *); 244 void *hashinit(u_int, enum hashtype, bool, u_long *); 245 void hashdone(void *, enum hashtype, u_long); 246 int seltrue(dev_t, int, struct lwp *); 247 int sys_nosys(struct lwp *, const void *, register_t *); 248 int sys_nomodule(struct lwp *, const void *, register_t *); 249 250 void aprint_normal(const char *, ...) __printflike(1, 2); 251 void aprint_error(const char *, ...) __printflike(1, 2); 252 void aprint_naive(const char *, ...) __printflike(1, 2); 253 void aprint_verbose(const char *, ...) __printflike(1, 2); 254 void aprint_debug(const char *, ...) __printflike(1, 2); 255 256 void aprint_normal_dev(device_t, const char *, ...) __printflike(2, 3); 257 void aprint_error_dev(device_t, const char *, ...) __printflike(2, 3); 258 void aprint_naive_dev(device_t, const char *, ...) __printflike(2, 3); 259 void aprint_verbose_dev(device_t, const char *, ...) __printflike(2, 3); 260 void aprint_debug_dev(device_t, const char *, ...) __printflike(2, 3); 261 262 void device_printf(device_t, const char *fmt, ...) __printflike(2, 3); 263 264 struct ifnet; 265 266 void aprint_normal_ifnet(struct ifnet *, const char *, ...) 267 __printflike(2, 3); 268 void aprint_error_ifnet(struct ifnet *, const char *, ...) 269 __printflike(2, 3); 270 void aprint_naive_ifnet(struct ifnet *, const char *, ...) 271 __printflike(2, 3); 272 void aprint_verbose_ifnet(struct ifnet *, const char *, ...) 273 __printflike(2, 3); 274 void aprint_debug_ifnet(struct ifnet *, const char *, ...) 275 __printflike(2, 3); 276 277 int aprint_get_error_count(void); 278 279 void printf_tolog(const char *, ...) __printflike(1, 2); 280 281 void printf_nolog(const char *, ...) __printflike(1, 2); 282 283 void printf_nostamp(const char *, ...) __printflike(1, 2); 284 285 void printf(const char *, ...) __printflike(1, 2); 286 287 int snprintf(char *, size_t, const char *, ...) __printflike(3, 4); 288 289 int vasprintf(char **, const char *, va_list) __printflike(2, 0); 290 291 void vprintf(const char *, va_list) __printflike(1, 0); 292 293 int vsnprintf(char *, size_t, const char *, va_list) __printflike(3, 0); 294 295 void vprintf_flags(int, const char *, va_list) __printflike(2, 0); 296 297 void printf_flags(int, const char *, ...) __printflike(2, 3); 298 299 int humanize_number(char *, size_t, uint64_t, const char *, int); 300 301 void twiddle(void); 302 void banner(void); 303 #endif /* _KERNEL */ 304 305 void panic(const char *, ...) __dead __printflike(1, 2); 306 void vpanic(const char *, va_list) __dead __printflike(1, 0); 307 void uprintf(const char *, ...) __printflike(1, 2); 308 void uprintf_locked(const char *, ...) __printflike(1, 2); 309 void ttyprintf(struct tty *, const char *, ...) __printflike(2, 3); 310 311 int format_bytes(char *, size_t, uint64_t); 312 313 void tablefull(const char *, const char *); 314 315 #if defined(_KERNEL) && defined(KASAN) 316 int kasan_kcopy(const void *, void *, size_t); 317 #define kcopy kasan_kcopy 318 #elif defined(_KERNEL) && defined(KCSAN) 319 int kcsan_kcopy(const void *, void *, size_t); 320 #define kcopy kcsan_kcopy 321 #elif defined(_KERNEL) && defined(KMSAN) 322 int kmsan_kcopy(const void *, void *, size_t); 323 #define kcopy kmsan_kcopy 324 #else 325 int kcopy(const void *, void *, size_t); 326 #endif 327 328 #ifdef _KERNEL 329 #define bcopy(src, dst, len) memcpy((dst), (src), (len)) 330 #define bzero(src, len) memset((src), 0, (len)) 331 #define bcmp(a, b, len) memcmp((a), (b), (len)) 332 #endif /* KERNEL */ 333 334 int copystr(const void *, void *, size_t, size_t *); 335 #if defined(_KERNEL) && defined(KASAN) 336 int kasan_copyinstr(const void *, void *, size_t, size_t *); 337 int kasan_copyoutstr(const void *, void *, size_t, size_t *); 338 int kasan_copyin(const void *, void *, size_t); 339 int copyout(const void *, void *, size_t); 340 #define copyinstr kasan_copyinstr 341 #define copyoutstr kasan_copyoutstr 342 #define copyin kasan_copyin 343 #elif defined(_KERNEL) && defined(KCSAN) 344 int kcsan_copyinstr(const void *, void *, size_t, size_t *); 345 int kcsan_copyoutstr(const void *, void *, size_t, size_t *); 346 int kcsan_copyin(const void *, void *, size_t); 347 int kcsan_copyout(const void *, void *, size_t); 348 #define copyinstr kcsan_copyinstr 349 #define copyoutstr kcsan_copyoutstr 350 #define copyin kcsan_copyin 351 #define copyout kcsan_copyout 352 #elif defined(_KERNEL) && defined(KMSAN) 353 int kmsan_copyinstr(const void *, void *, size_t, size_t *); 354 int kmsan_copyoutstr(const void *, void *, size_t, size_t *); 355 int kmsan_copyin(const void *, void *, size_t); 356 int kmsan_copyout(const void *, void *, size_t); 357 #define copyinstr kmsan_copyinstr 358 #define copyoutstr kmsan_copyoutstr 359 #define copyin kmsan_copyin 360 #define copyout kmsan_copyout 361 #else 362 int copyinstr(const void *, void *, size_t, size_t *); 363 int copyoutstr(const void *, void *, size_t, size_t *); 364 int copyin(const void *, void *, size_t); 365 int copyout(const void *, void *, size_t); 366 #endif 367 368 #ifdef _KERNEL 369 typedef int (*copyin_t)(const void *, void *, size_t); 370 typedef int (*copyout_t)(const void *, void *, size_t); 371 #endif 372 373 int copyin_proc(struct proc *, const void *, void *, size_t); 374 int copyout_proc(struct proc *, const void *, void *, size_t); 375 int copyin_pid(pid_t, const void *, void *, size_t); 376 int copyin_vmspace(struct vmspace *, const void *, void *, size_t); 377 int copyout_vmspace(struct vmspace *, const void *, void *, size_t); 378 379 int ioctl_copyin(int ioctlflags, const void *src, void *dst, size_t len); 380 int ioctl_copyout(int ioctlflags, const void *src, void *dst, size_t len); 381 382 int ucas_32(volatile uint32_t *, uint32_t, uint32_t, uint32_t *); 383 #ifdef _LP64 384 int ucas_64(volatile uint64_t *, uint64_t, uint64_t, uint64_t *); 385 #endif 386 int ucas_ptr(volatile void *, void *, void *, void *); 387 int ucas_int(volatile unsigned int *, unsigned int, unsigned int, 388 unsigned int *); 389 int ufetch_8(const uint8_t *, uint8_t *); 390 int ufetch_16(const uint16_t *, uint16_t *); 391 int ufetch_32(const uint32_t *, uint32_t *); 392 #ifdef _LP64 393 int ufetch_64(const uint64_t *, uint64_t *); 394 #endif 395 int ufetch_char(const unsigned char *, unsigned char *); 396 int ufetch_short(const unsigned short *, unsigned short *); 397 int ufetch_int(const unsigned int *, unsigned int *); 398 int ufetch_long(const unsigned long *, unsigned long *); 399 int ufetch_ptr(const void **, void **); 400 int ustore_8(uint8_t *, uint8_t); 401 int ustore_16(uint16_t *, uint16_t); 402 int ustore_32(uint32_t *, uint32_t); 403 #ifdef _LP64 404 int ustore_64(uint64_t *, uint64_t); 405 #endif 406 int ustore_char(unsigned char *, unsigned char); 407 int ustore_short(unsigned short *, unsigned short); 408 int ustore_int(unsigned int *, unsigned int); 409 int ustore_long(unsigned long *, unsigned long); 410 int ustore_ptr(void **, void *); 411 412 #ifdef __UCAS_PRIVATE 413 414 #if defined(__HAVE_UCAS_FULL) && defined(KASAN) 415 int kasan__ucas_32(volatile uint32_t *, uint32_t, uint32_t, uint32_t *); 416 #ifdef __HAVE_UCAS_MP 417 int kasan__ucas_32_mp(volatile uint32_t *, uint32_t, uint32_t, uint32_t *); 418 #endif /* __HAVE_UCAS_MP */ 419 #ifdef _LP64 420 int kasan__ucas_64(volatile uint64_t *, uint64_t, uint64_t, uint64_t *); 421 #ifdef __HAVE_UCAS_MP 422 int kasan__ucas_64_mp(volatile uint64_t *, uint64_t, uint64_t, uint64_t *); 423 #endif /* __HAVE_UCAS_MP */ 424 #endif /* _LP64 */ 425 #define _ucas_32 kasan__ucas_32 426 #define _ucas_32_mp kasan__ucas_32_mp 427 #define _ucas_64 kasan__ucas_64 428 #define _ucas_64_mp kasan__ucas_64_mp 429 #elif defined(__HAVE_UCAS_FULL) && defined(KMSAN) 430 int kmsan__ucas_32(volatile uint32_t *, uint32_t, uint32_t, uint32_t *); 431 #ifdef __HAVE_UCAS_MP 432 int kmsan__ucas_32_mp(volatile uint32_t *, uint32_t, uint32_t, uint32_t *); 433 #endif /* __HAVE_UCAS_MP */ 434 #ifdef _LP64 435 int kmsan__ucas_64(volatile uint64_t *, uint64_t, uint64_t, uint64_t *); 436 #ifdef __HAVE_UCAS_MP 437 int kmsan__ucas_64_mp(volatile uint64_t *, uint64_t, uint64_t, uint64_t *); 438 #endif /* __HAVE_UCAS_MP */ 439 #endif /* _LP64 */ 440 #define _ucas_32 kmsan__ucas_32 441 #define _ucas_32_mp kmsan__ucas_32_mp 442 #define _ucas_64 kmsan__ucas_64 443 #define _ucas_64_mp kmsan__ucas_64_mp 444 #else 445 int _ucas_32(volatile uint32_t *, uint32_t, uint32_t, uint32_t *); 446 #ifdef __HAVE_UCAS_MP 447 int _ucas_32_mp(volatile uint32_t *, uint32_t, uint32_t, uint32_t *); 448 #endif /* __HAVE_UCAS_MP */ 449 #ifdef _LP64 450 int _ucas_64(volatile uint64_t *, uint64_t, uint64_t, uint64_t *); 451 #ifdef __HAVE_UCAS_MP 452 int _ucas_64_mp(volatile uint64_t *, uint64_t, uint64_t, uint64_t *); 453 #endif /* __HAVE_UCAS_MP */ 454 #endif /* _LP64 */ 455 #endif 456 457 #endif /* __UCAS_PRIVATE */ 458 459 #ifdef __UFETCHSTORE_PRIVATE 460 461 #if defined(KASAN) 462 int kasan__ufetch_8(const uint8_t *, uint8_t *); 463 int kasan__ufetch_16(const uint16_t *, uint16_t *); 464 int kasan__ufetch_32(const uint32_t *, uint32_t *); 465 #ifdef _LP64 466 int kasan__ufetch_64(const uint64_t *, uint64_t *); 467 #endif 468 int _ustore_8(uint8_t *, uint8_t); 469 int _ustore_16(uint16_t *, uint16_t); 470 int _ustore_32(uint32_t *, uint32_t); 471 #ifdef _LP64 472 int _ustore_64(uint64_t *, uint64_t); 473 #endif 474 #define _ufetch_8 kasan__ufetch_8 475 #define _ufetch_16 kasan__ufetch_16 476 #define _ufetch_32 kasan__ufetch_32 477 #define _ufetch_64 kasan__ufetch_64 478 #elif defined(KMSAN) 479 int kmsan__ufetch_8(const uint8_t *, uint8_t *); 480 int kmsan__ufetch_16(const uint16_t *, uint16_t *); 481 int kmsan__ufetch_32(const uint32_t *, uint32_t *); 482 #ifdef _LP64 483 int kmsan__ufetch_64(const uint64_t *, uint64_t *); 484 #endif 485 int kmsan__ustore_8(uint8_t *, uint8_t); 486 int kmsan__ustore_16(uint16_t *, uint16_t); 487 int kmsan__ustore_32(uint32_t *, uint32_t); 488 #ifdef _LP64 489 int kmsan__ustore_64(uint64_t *, uint64_t); 490 #endif 491 #define _ufetch_8 kmsan__ufetch_8 492 #define _ufetch_16 kmsan__ufetch_16 493 #define _ufetch_32 kmsan__ufetch_32 494 #define _ufetch_64 kmsan__ufetch_64 495 #define _ustore_8 kmsan__ustore_8 496 #define _ustore_16 kmsan__ustore_16 497 #define _ustore_32 kmsan__ustore_32 498 #define _ustore_64 kmsan__ustore_64 499 #else 500 int _ufetch_8(const uint8_t *, uint8_t *); 501 int _ufetch_16(const uint16_t *, uint16_t *); 502 int _ufetch_32(const uint32_t *, uint32_t *); 503 #ifdef _LP64 504 int _ufetch_64(const uint64_t *, uint64_t *); 505 #endif 506 int _ustore_8(uint8_t *, uint8_t); 507 int _ustore_16(uint16_t *, uint16_t); 508 int _ustore_32(uint32_t *, uint32_t); 509 #ifdef _LP64 510 int _ustore_64(uint64_t *, uint64_t); 511 #endif 512 #endif 513 514 #endif /* __UFETCHSTORE_PRIVATE */ 515 516 void hardclock(struct clockframe *); 517 void softclock(void *); 518 void statclock(struct clockframe *); 519 520 #ifdef NTP 521 void ntp_init(void); 522 #ifdef PPS_SYNC 523 struct timespec; 524 void hardpps(struct timespec *, long); 525 #endif /* PPS_SYNC */ 526 #else 527 void ntp_init(void); /* also provides adjtime() functionality */ 528 #endif /* NTP */ 529 530 void ssp_init(void); 531 532 void initclocks(void); 533 void inittodr(time_t); 534 void resettodr(void); 535 void cpu_initclocks(void); 536 void setrootfstime(time_t); 537 538 void startprofclock(struct proc *); 539 void stopprofclock(struct proc *); 540 void proftick(struct clockframe *); 541 void setstatclockrate(int); 542 543 /* 544 * Critical polling hooks. Functions to be run while the kernel stays 545 * elevated IPL for a "long" time. (watchdogs). 546 */ 547 void *critpollhook_establish(void (*)(void *), void *); 548 void critpollhook_disestablish(void *); 549 void docritpollhooks(void); 550 551 /* 552 * Shutdown hooks. Functions to be run with all interrupts disabled 553 * immediately before the system is halted or rebooted. 554 */ 555 void *shutdownhook_establish(void (*)(void *), void *); 556 void shutdownhook_disestablish(void *); 557 void doshutdownhooks(void); 558 559 /* 560 * Power management hooks. 561 */ 562 void *powerhook_establish(const char *, void (*)(int, void *), void *); 563 void powerhook_disestablish(void *); 564 void dopowerhooks(int); 565 #define PWR_RESUME 0 566 #define PWR_SUSPEND 1 567 #define PWR_STANDBY 2 568 #define PWR_SOFTRESUME 3 569 #define PWR_SOFTSUSPEND 4 570 #define PWR_SOFTSTANDBY 5 571 #define PWR_NAMES \ 572 "resume", /* 0 */ \ 573 "suspend", /* 1 */ \ 574 "standby", /* 2 */ \ 575 "softresume", /* 3 */ \ 576 "softsuspend", /* 4 */ \ 577 "softstandby" /* 5 */ 578 579 /* 580 * Mountroot hooks (and mountroot declaration). Device drivers establish 581 * these to be executed just before (*mountroot)() if the passed device is 582 * selected as the root device. 583 */ 584 585 #define ROOT_FSTYPE_ANY "?" 586 587 extern const char *rootfstype; 588 void *mountroothook_establish(void (*)(device_t), device_t); 589 void mountroothook_disestablish(void *); 590 void mountroothook_destroy(void); 591 void domountroothook(device_t); 592 593 /* Register rootspec/bootdevice prefixes for per-driver handling. */ 594 struct rootspechook *rootspechook_establish(const char *, 595 device_t (*)(const char *), void (*)(void)); 596 void rootspechook_disestablish(struct rootspechook *); 597 device_t dorootspechooks(const char *); 598 void dorootspecprint(void); 599 600 /* 601 * Exec hooks. Subsystems may want to do cleanup when a process 602 * execs. 603 */ 604 void *exechook_establish(void (*)(struct proc *, void *), void *); 605 void exechook_disestablish(void *); 606 void doexechooks(struct proc *); 607 608 /* 609 * Exit hooks. Subsystems may want to do cleanup when a process exits. 610 */ 611 void *exithook_establish(void (*)(struct proc *, void *), void *); 612 void exithook_disestablish(void *); 613 void doexithooks(struct proc *); 614 615 /* 616 * Fork hooks. Subsystems may want to do special processing when a process 617 * forks. 618 */ 619 void *forkhook_establish(void (*)(struct proc *, struct proc *)); 620 void forkhook_disestablish(void *); 621 void doforkhooks(struct proc *, struct proc *); 622 623 /* 624 * kernel syscall tracing/debugging hooks. 625 */ 626 #ifdef _KERNEL 627 bool trace_is_enabled(struct proc *); 628 int trace_enter(register_t, const struct sysent *, const void *); 629 void trace_exit(register_t, const struct sysent *, const void *, 630 register_t [], int); 631 #endif 632 633 int uiomove(void *, size_t, struct uio *); 634 int uiomove_frombuf(void *, size_t, struct uio *); 635 int uiopeek(void *, size_t, struct uio *); 636 void uioskip(size_t, struct uio *); 637 638 #ifdef _KERNEL 639 int setjmp(label_t *) __returns_twice; 640 void longjmp(label_t *) __dead; 641 #endif 642 643 void consinit(void); 644 645 void cpu_startup(void); 646 void cpu_configure(void); 647 void cpu_bootconf(void); 648 void cpu_rootconf(void); 649 void cpu_dumpconf(void); 650 651 #ifdef GPROF 652 void kmstartup(void); 653 #endif 654 655 void machdep_init(void); 656 657 #ifdef _KERNEL 658 #include <lib/libkern/libkern.h> 659 660 /* 661 * Stuff to handle debugger magic key sequences. 662 */ 663 #define CNS_LEN 128 664 #define CNS_MAGIC_VAL(x) ((x)&0x1ff) 665 #define CNS_MAGIC_NEXT(x) (((x)>>9)&0x7f) 666 #define CNS_TERM 0x7f /* End of sequence */ 667 668 typedef struct cnm_state { 669 int cnm_state; 670 u_short *cnm_magic; 671 } cnm_state_t; 672 673 /* Override db_console() in MD headers */ 674 #ifndef cn_trap 675 #define cn_trap() console_debugger() 676 #endif 677 #ifndef cn_isconsole 678 #ifndef WSDISPLAY_MULTICONS 679 #define cn_isconsole(d) (cn_tab != NULL && (d) == cn_tab->cn_dev) 680 #else 681 bool wsdisplay_cn_isconsole(dev_t); 682 #define cn_isconsole(d) wsdisplay_cn_isconsole(d) 683 #endif 684 #endif 685 686 void cn_init_magic(cnm_state_t *); 687 void cn_destroy_magic(cnm_state_t *); 688 int cn_set_magic(const char *); 689 int cn_get_magic(char *, size_t); 690 /* This should be called for each byte read */ 691 #ifndef cn_check_magic 692 #define cn_check_magic(d, k, s) \ 693 do { \ 694 if (cn_isconsole(d)) { \ 695 int _v = (s).cnm_magic[(s).cnm_state]; \ 696 if ((k) == CNS_MAGIC_VAL(_v)) { \ 697 (s).cnm_state = CNS_MAGIC_NEXT(_v); \ 698 if ((s).cnm_state == CNS_TERM) { \ 699 cn_trap(); \ 700 (s).cnm_state = 0; \ 701 } \ 702 } else { \ 703 (s).cnm_state = 0; \ 704 } \ 705 } \ 706 } while (0) 707 #endif 708 709 /* Encode out-of-band events this way when passing to cn_check_magic() */ 710 #define CNC_BREAK 0x100 711 712 #if defined(DDB) || defined(sun3) || defined(sun2) 713 /* note that cpu_Debugger() is always available on sun[23] */ 714 void cpu_Debugger(void); 715 #define Debugger cpu_Debugger 716 #endif 717 718 #ifdef DDB 719 /* 720 * Enter debugger(s) from console attention if enabled 721 */ 722 extern int db_fromconsole; /* XXX ddb/ddbvar.h */ 723 #define console_debugger() if (db_fromconsole) Debugger() 724 #elif defined(Debugger) 725 #define console_debugger() Debugger() 726 #else 727 #define console_debugger() do {} while (0) /* NOP */ 728 #endif 729 730 /* For SYSCALL_DEBUG */ 731 void scdebug_init(void); 732 void scdebug_call(register_t, const register_t[]); 733 void scdebug_ret(register_t, int, const register_t[]); 734 735 void kernel_lock_init(void); 736 void _kernel_lock(int); 737 void _kernel_unlock(int, int *); 738 bool _kernel_locked_p(void); 739 740 void kernconfig_lock_init(void); 741 void kernconfig_lock(void); 742 void kernconfig_unlock(void); 743 bool kernconfig_is_held(void); 744 #endif 745 746 #if defined(MULTIPROCESSOR) || defined(MODULAR) || defined(_MODULE) 747 #define KERNEL_LOCK(count, lwp) \ 748 do { \ 749 if ((count) != 0) \ 750 _kernel_lock((count)); \ 751 } while (0) 752 #define KERNEL_UNLOCK(all, lwp, p) _kernel_unlock((all), (p)) 753 #define KERNEL_LOCKED_P() _kernel_locked_p() 754 #else 755 #define KERNEL_LOCK(count, lwp) do {(void)(count); (void)(lwp);} while (0) /*NOP*/ 756 #define KERNEL_UNLOCK(all, lwp, ptr) do {(void)(all); (void)(lwp); (void)(ptr);} while (0) /*NOP*/ 757 #define KERNEL_LOCKED_P() (true) 758 #endif 759 760 #define KERNEL_UNLOCK_LAST(l) KERNEL_UNLOCK(-1, (l), NULL) 761 #define KERNEL_UNLOCK_ALL(l, p) KERNEL_UNLOCK(0, (l), (p)) 762 #define KERNEL_UNLOCK_ONE(l) KERNEL_UNLOCK(1, (l), NULL) 763 764 #ifdef _KERNEL 765 /* Preemption control. */ 766 void kpreempt_disable(void); 767 void kpreempt_enable(void); 768 bool kpreempt_disabled(void); 769 770 vaddr_t calc_cache_size(vsize_t , int, int); 771 #endif 772 773 void assert_sleepable(void); 774 #if defined(DEBUG) 775 #define ASSERT_SLEEPABLE() assert_sleepable() 776 #else /* defined(DEBUG) */ 777 #define ASSERT_SLEEPABLE() do {} while (0) 778 #endif /* defined(DEBUG) */ 779 780 781 #endif /* !_SYS_SYSTM_H_ */ 782