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