The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/sys/systm.h

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*      $NetBSD: systm.h,v 1.190 2006/09/30 11:59:37 yamt 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 /*
   40  * The `securelevel' variable controls the security level of the system.
   41  * It can only be decreased by process 1 (/sbin/init).
   42  *
   43  * Security levels are as follows:
   44  *   -1 permanently insecure mode - always run system in level 0 mode.
   45  *    0 insecure mode - immutable and append-only flags may be turned off.
   46  *      All devices may be read or written subject to permission modes.
   47  *    1 secure mode - immutable and append-only flags may not be changed;
   48  *      raw disks of mounted filesystems, /dev/mem, and /dev/kmem are
   49  *      read-only.
   50  *    2 highly secure mode - same as (1) plus raw disks are always
   51  *      read-only whether mounted or not. This level precludes tampering
   52  *      with filesystems by unmounting them, but also inhibits running
   53  *      newfs while the system is secured.
   54  *
   55  * In normal operation, the system runs in level 0 mode while single user
   56  * and in level 1 mode while multiuser. If level 2 mode is desired while
   57  * running multiuser, it can be set in the multiuser startup script
   58  * (/etc/rc.local) using sysctl(8). If it is desired to run the system
   59  * in level 0 mode while multiuser, initialize the variable securelevel
   60  * in /sys/kern/kern_sysctl.c to -1. Note that it is NOT initialized to
   61  * zero as that would allow the vmunix binary to be patched to -1.
   62  * Without initialization, securelevel loads in the BSS area which only
   63  * comes into existence when the kernel is loaded and hence cannot be
   64  * patched by a stalking hacker.
   65  */
   66 
   67 #ifndef _SYS_SYSTM_H_
   68 #define _SYS_SYSTM_H_
   69 
   70 #if defined(_KERNEL_OPT)
   71 #include "opt_ddb.h"
   72 #include "opt_multiprocessor.h"
   73 #include "opt_syscall_debug.h"
   74 #endif
   75 
   76 #include <machine/endian.h>
   77 
   78 #ifdef _KERNEL
   79 #include <sys/types.h>
   80 #endif
   81 
   82 struct clockframe;
   83 struct device;
   84 struct lwp;
   85 struct proc;
   86 struct timeval;
   87 struct tty;
   88 struct uio;
   89 struct vnode;
   90 struct vmspace;
   91 
   92 extern int securelevel;         /* system security level */
   93 extern const char *panicstr;    /* panic message */
   94 extern int doing_shutdown;      /* shutting down */
   95 
   96 extern const char copyright[];  /* system copyright */
   97 extern char cpu_model[];        /* machine/cpu model name */
   98 extern char machine[];          /* machine type */
   99 extern char machine_arch[];     /* machine architecture */
  100 extern const char osrelease[];  /* short system version */
  101 extern const char ostype[];     /* system type */
  102 extern const char kernel_ident[];/* kernel configuration ID */
  103 extern const char version[];    /* system version */
  104 
  105 extern int autonicetime;        /* time (in seconds) before autoniceval */
  106 extern int autoniceval;         /* proc priority after autonicetime */
  107 
  108 extern int selwait;             /* select timeout address */
  109 
  110 extern int maxmem;              /* max memory per process */
  111 extern int physmem;             /* physical memory */
  112 
  113 extern dev_t dumpdev;           /* dump device */
  114 extern long dumplo;             /* offset into dumpdev */
  115 extern int dumpsize;            /* size of dump in pages */
  116 extern const char *dumpspec;    /* how dump device was specified */
  117 
  118 extern dev_t rootdev;           /* root device */
  119 extern struct vnode *rootvp;    /* vnode equivalent to above */
  120 extern struct device *root_device; /* device equivalent to above */
  121 extern const char *rootspec;    /* how root device was specified */
  122 
  123 extern const char hexdigits[];  /* "0123456789abcdef" in subr_prf.c */
  124 extern const char HEXDIGITS[];  /* "0123456789ABCDEF" in subr_prf.c */
  125 
  126 /*
  127  * These represent the swap pseudo-device (`sw').  This device
  128  * is used by the swap pager to indirect through the routines
  129  * in sys/vm/vm_swap.c.
  130  */
  131 extern const dev_t swapdev;     /* swapping device */
  132 extern struct vnode *swapdev_vp;/* vnode equivalent to above */
  133 
  134 extern const dev_t zerodev;     /* /dev/zero */
  135 
  136 typedef int     sy_call_t(struct lwp *, void *, register_t *);
  137 
  138 extern struct sysent {          /* system call table */
  139         short   sy_narg;        /* number of args */
  140         short   sy_argsize;     /* total size of arguments */
  141         int     sy_flags;       /* flags. see below */
  142         sy_call_t *sy_call;     /* implementing function */
  143 } sysent[];
  144 extern int nsysent;
  145 #if     BYTE_ORDER == BIG_ENDIAN
  146 #define SCARG(p,k)      ((p)->k.be.datum)       /* get arg from args pointer */
  147 #elif   BYTE_ORDER == LITTLE_ENDIAN
  148 #define SCARG(p,k)      ((p)->k.le.datum)       /* get arg from args pointer */
  149 #else
  150 #error  "what byte order is this machine?"
  151 #endif
  152 
  153 #define SYCALL_MPSAFE   0x0001  /* syscall is MP-safe */
  154 
  155 extern int boothowto;           /* reboot flags, from console subsystem */
  156 #define bootverbose     (boothowto & AB_VERBOSE)
  157 #define bootquiet       (boothowto & AB_QUIET)
  158 
  159 extern void (*v_putc)(int); /* Virtual console putc routine */
  160 
  161 extern  void    _insque(void *, void *);
  162 extern  void    _remque(void *);
  163 
  164 /* casts to keep lint happy, but it should be happy with void * */
  165 #define insque(q,p)     _insque(q, p)
  166 #define remque(q)       _remque(q)
  167 
  168 /*
  169  * General function declarations.
  170  */
  171 int     nullop(void *);
  172 int     enodev(void);
  173 int     enosys(void);
  174 int     enoioctl(void);
  175 int     enxio(void);
  176 int     eopnotsupp(void);
  177 
  178 enum hashtype {
  179         HASH_LIST,
  180         HASH_TAILQ
  181 };
  182 
  183 struct malloc_type;
  184 void    *hashinit(u_int, enum hashtype, struct malloc_type *, int, u_long *);
  185 void    hashdone(void *, struct malloc_type *);
  186 int     seltrue(dev_t, int, struct lwp *);
  187 int     sys_nosys(struct lwp *, void *, register_t *);
  188 
  189 
  190 #ifdef _KERNEL
  191 void    aprint_normal(const char *, ...)
  192     __attribute__((__format__(__printf__,1,2)));
  193 void    aprint_error(const char *, ...)
  194     __attribute__((__format__(__printf__,1,2)));
  195 void    aprint_naive(const char *, ...)
  196     __attribute__((__format__(__printf__,1,2)));
  197 void    aprint_verbose(const char *, ...)
  198     __attribute__((__format__(__printf__,1,2)));
  199 void    aprint_debug(const char *, ...)
  200     __attribute__((__format__(__printf__,1,2)));
  201 
  202 int     aprint_get_error_count(void);
  203 
  204 void    printf_nolog(const char *, ...)
  205     __attribute__((__format__(__printf__,1,2)));
  206 
  207 void    printf(const char *, ...)
  208     __attribute__((__format__(__printf__,1,2)));
  209 int     sprintf(char *, const char *, ...)
  210     __attribute__((__format__(__printf__,2,3)));
  211 int     snprintf(char *, size_t, const char *, ...)
  212     __attribute__((__format__(__printf__,3,4)));
  213 void    vprintf(const char *, _BSD_VA_LIST_);
  214 int     vsprintf(char *, const char *, _BSD_VA_LIST_);
  215 int     vsnprintf(char *, size_t, const char *, _BSD_VA_LIST_);
  216 int     humanize_number(char *, size_t, uint64_t, const char *, int);
  217 
  218 void    twiddle(void);
  219 #endif /* _KERNEL */
  220 
  221 void    panic(const char *, ...)
  222     __attribute__((__noreturn__,__format__(__printf__,1,2)));
  223 void    uprintf(const char *, ...)
  224     __attribute__((__format__(__printf__,1,2)));
  225 void    ttyprintf(struct tty *, const char *, ...)
  226     __attribute__((__format__(__printf__,2,3)));
  227 
  228 char    *bitmask_snprintf(u_quad_t, const char *, char *, size_t);
  229 
  230 int     format_bytes(char *, size_t, uint64_t);
  231 
  232 void    tablefull(const char *, const char *);
  233 
  234 int     kcopy(const void *, void *, size_t);
  235 
  236 #ifdef _KERNEL
  237 #define bcopy(src, dst, len)    memcpy((dst), (src), (len))
  238 #define bzero(src, len)         memset((src), 0, (len))
  239 #define bcmp(a, b, len)         memcmp((a), (b), (len))
  240 #endif /* KERNEL */
  241 
  242 int     copystr(const void *, void *, size_t, size_t *);
  243 int     copyinstr(const void *, void *, size_t, size_t *);
  244 int     copyoutstr(const void *, void *, size_t, size_t *);
  245 int     copyin(const void *, void *, size_t);
  246 int     copyout(const void *, void *, size_t);
  247 
  248 #ifdef _KERNEL
  249 typedef int     (*copyin_t)(const void *, void *, size_t);
  250 typedef int     (*copyout_t)(const void *, void *, size_t);
  251 #endif
  252 
  253 int     copyin_proc(struct proc *, const void *, void *, size_t);
  254 int     copyout_proc(struct proc *, const void *, void *, size_t);
  255 int     copyin_vmspace(struct vmspace *, const void *, void *, size_t);
  256 int     copyout_vmspace(struct vmspace *, const void *, void *, size_t);
  257 
  258 int     ioctl_copyin(int ioctlflags, const void *src, void *dst, size_t len);
  259 int     ioctl_copyout(int ioctlflags, const void *src, void *dst, size_t len);
  260 
  261 int     subyte(void *, int);
  262 int     suibyte(void *, int);
  263 int     susword(void *, short);
  264 int     suisword(void *, short);
  265 int     suswintr(void *, short);
  266 int     suword(void *, long);
  267 int     suiword(void *, long);
  268 
  269 int     fubyte(const void *);
  270 int     fuibyte(const void *);
  271 int     fusword(const void *);
  272 int     fuisword(const void *);
  273 int     fuswintr(const void *);
  274 long    fuword(const void *);
  275 long    fuiword(const void *);
  276 
  277 void    hardclock(struct clockframe *);
  278 void    softclock(void *);
  279 void    statclock(struct clockframe *);
  280 
  281 #ifdef NTP
  282 void    ntp_init(void);
  283 #ifndef __HAVE_TIMECOUNTER
  284 void    hardupdate(long offset);
  285 #endif /* !__HAVE_TIMECOUNTER */
  286 #ifdef PPS_SYNC
  287 #ifdef __HAVE_TIMECOUNTER
  288 void    hardpps(struct timespec *, long);
  289 #else /* !__HAVE_TIMECOUNTER */
  290 void    hardpps(struct timeval *, long);
  291 extern void *pps_kc_hardpps_source;
  292 extern int pps_kc_hardpps_mode;
  293 #endif /* !__HAVE_TIMECOUNTER */
  294 #endif /* PPS_SYNC */
  295 #else
  296 #ifdef __HAVE_TIMECOUNTER
  297 void    ntp_init(void); /* also provides adjtime() functionality */
  298 #endif /* __HAVE_TIMECOUNTER */
  299 #endif /* NTP */
  300 
  301 void    initclocks(void);
  302 void    inittodr(time_t);
  303 void    resettodr(void);
  304 void    cpu_initclocks(void);
  305 void    setrootfstime(time_t);
  306 
  307 void    startprofclock(struct proc *);
  308 void    stopprofclock(struct proc *);
  309 void    proftick(struct clockframe *);
  310 void    setstatclockrate(int);
  311 
  312 /*
  313  * Shutdown hooks.  Functions to be run with all interrupts disabled
  314  * immediately before the system is halted or rebooted.
  315  */
  316 void    *shutdownhook_establish(void (*)(void *), void *);
  317 void    shutdownhook_disestablish(void *);
  318 void    doshutdownhooks(void);
  319 
  320 /*
  321  * Power management hooks.
  322  */
  323 void    *powerhook_establish(const char *, void (*)(int, void *), void *);
  324 void    powerhook_disestablish(void *);
  325 void    dopowerhooks(int);
  326 #define PWR_RESUME      0
  327 #define PWR_SUSPEND     1
  328 #define PWR_STANDBY     2
  329 #define PWR_SOFTRESUME  3
  330 #define PWR_SOFTSUSPEND 4
  331 #define PWR_SOFTSTANDBY 5
  332 
  333 /*
  334  * Mountroot hooks (and mountroot declaration).  Device drivers establish
  335  * these to be executed just before (*mountroot)() if the passed device is
  336  * selected as the root device.
  337  */
  338 extern int (*mountroot)(void);
  339 void    *mountroothook_establish(void (*)(struct device *), struct device *);
  340 void    mountroothook_disestablish(void *);
  341 void    mountroothook_destroy(void);
  342 void    domountroothook(void);
  343 
  344 /*
  345  * Exec hooks. Subsystems may want to do cleanup when a process
  346  * execs.
  347  */
  348 void    *exechook_establish(void (*)(struct proc *, void *), void *);
  349 void    exechook_disestablish(void *);
  350 void    doexechooks(struct proc *);
  351 
  352 /*
  353  * Exit hooks. Subsystems may want to do cleanup when a process exits.
  354  */
  355 void    *exithook_establish(void (*)(struct proc *, void *), void *);
  356 void    exithook_disestablish(void *);
  357 void    doexithooks(struct proc *);
  358 
  359 /*
  360  * Fork hooks.  Subsystems may want to do special processing when a process
  361  * forks.
  362  */
  363 void    *forkhook_establish(void (*)(struct proc *, struct proc *));
  364 void    forkhook_disestablish(void *);
  365 void    doforkhooks(struct proc *, struct proc *);
  366 
  367 /*
  368  * kernel syscall tracing/debugging hooks.
  369  */
  370 #ifdef _KERNEL
  371 boolean_t trace_is_enabled(struct proc *);
  372 int     trace_enter(struct lwp *, register_t, register_t,
  373             const struct sysent *, void *);
  374 void    trace_exit(struct lwp *, register_t, void *, register_t [], int);
  375 #endif
  376 
  377 int     uiomove(void *, size_t, struct uio *);
  378 int     uiomove_frombuf(void *, size_t, struct uio *);
  379 
  380 #ifdef _KERNEL
  381 int     setjmp(label_t *);
  382 void    longjmp(label_t *) __attribute__((__noreturn__));
  383 #endif
  384 
  385 void    consinit(void);
  386 
  387 void    cpu_startup(void);
  388 void    cpu_configure(void);
  389 void    cpu_rootconf(void);
  390 void    cpu_dumpconf(void);
  391 
  392 #ifdef GPROF
  393 void    kmstartup(void);
  394 #endif
  395 
  396 #ifdef _KERNEL
  397 #include <lib/libkern/libkern.h>
  398 
  399 /*
  400  * Stuff to handle debugger magic key sequences.
  401  */
  402 #define CNS_LEN                 128
  403 #define CNS_MAGIC_VAL(x)        ((x)&0x1ff)
  404 #define CNS_MAGIC_NEXT(x)       (((x)>>9)&0x7f)
  405 #define CNS_TERM                0x7f    /* End of sequence */
  406 
  407 typedef struct cnm_state {
  408         int     cnm_state;
  409         u_short *cnm_magic;
  410 } cnm_state_t;
  411 
  412 /* Override db_console() in MD headers */
  413 #ifndef cn_trap
  414 #define cn_trap()       console_debugger()
  415 #endif
  416 #ifndef cn_isconsole
  417 #define cn_isconsole(d) (cn_tab != NULL && (d) == cn_tab->cn_dev)
  418 #endif
  419 
  420 void cn_init_magic(cnm_state_t *);
  421 void cn_destroy_magic(cnm_state_t *);
  422 int cn_set_magic(const char *);
  423 int cn_get_magic(char *, size_t);
  424 /* This should be called for each byte read */
  425 #ifndef cn_check_magic
  426 #define cn_check_magic(d, k, s)                                         \
  427         do {                                                            \
  428                 if (cn_isconsole(d)) {                                  \
  429                         int _v = (s).cnm_magic[(s).cnm_state];          \
  430                         if ((k) == CNS_MAGIC_VAL(_v)) {                 \
  431                                 (s).cnm_state = CNS_MAGIC_NEXT(_v);     \
  432                                 if ((s).cnm_state == CNS_TERM) {        \
  433                                         cn_trap();                      \
  434                                         (s).cnm_state = 0;              \
  435                                 }                                       \
  436                         } else {                                        \
  437                                 (s).cnm_state = 0;                      \
  438                         }                                               \
  439                 }                                                       \
  440         } while (/* CONSTCOND */ 0)
  441 #endif
  442 
  443 /* Encode out-of-band events this way when passing to cn_check_magic() */
  444 #define CNC_BREAK               0x100
  445 
  446 #if defined(DDB) || defined(sun3) || defined(sun2)
  447 /* note that cpu_Debugger() is always available on sun[23] */
  448 void    cpu_Debugger(void);
  449 #define Debugger        cpu_Debugger
  450 #endif
  451 
  452 #ifdef DDB
  453 /*
  454  * Enter debugger(s) from console attention if enabled
  455  */
  456 extern int db_fromconsole; /* XXX ddb/ddbvar.h */
  457 #define console_debugger() if (db_fromconsole) Debugger()
  458 #elif defined(Debugger)
  459 #define console_debugger() Debugger()
  460 #else
  461 #define console_debugger() do {} while (/* CONSTCOND */ 0) /* NOP */
  462 #endif
  463 #endif /* _KERNEL */
  464 
  465 #ifdef SYSCALL_DEBUG
  466 void scdebug_call(struct lwp *, register_t, register_t[]);
  467 void scdebug_ret(struct lwp *, register_t, int, register_t[]);
  468 #endif /* SYSCALL_DEBUG */
  469 
  470 #if defined(MULTIPROCESSOR)
  471 void    _kernel_lock_init(void);
  472 void    _kernel_lock(int);
  473 void    _kernel_unlock(void);
  474 void    _kernel_proc_lock(struct lwp *);
  475 void    _kernel_proc_unlock(struct lwp *);
  476 int     _kernel_lock_release_all(void);
  477 void    _kernel_lock_acquire_count(int);
  478 
  479 #define KERNEL_LOCK_INIT()              _kernel_lock_init()
  480 #define KERNEL_LOCK(flag)               _kernel_lock((flag))
  481 #define KERNEL_UNLOCK()                 _kernel_unlock()
  482 #define KERNEL_PROC_LOCK(l)             _kernel_proc_lock((l))
  483 #define KERNEL_PROC_UNLOCK(l)           _kernel_proc_unlock((l))
  484 #define KERNEL_LOCK_RELEASE_ALL()       _kernel_lock_release_all()
  485 #define KERNEL_LOCK_ACQUIRE_COUNT(count) _kernel_lock_acquire_count(count)
  486 
  487 #else /* ! MULTIPROCESSOR */
  488 
  489 #define KERNEL_LOCK_INIT()              /* nothing */
  490 #define KERNEL_LOCK(flag)               /* nothing */
  491 #define KERNEL_UNLOCK()                 /* nothing */
  492 #define KERNEL_PROC_LOCK(l)             /* nothing */
  493 #define KERNEL_PROC_UNLOCK(l)           /* nothing */
  494 #define KERNEL_LOCK_RELEASE_ALL()       (0)
  495 #define KERNEL_LOCK_ACQUIRE_COUNT(count) /* nothing */
  496 
  497 #endif /* MULTIPROCESSOR */
  498 
  499 #if defined(MULTIPROCESSOR) && defined(DEBUG)
  500 #define KERNEL_LOCK_ASSERT_LOCKED()     _kernel_lock_assert_locked()
  501 #define KERNEL_LOCK_ASSERT_UNLOCKED()   _kernel_lock_assert_unlocked()
  502 void _kernel_lock_assert_locked(void);
  503 void _kernel_lock_assert_unlocked(void);
  504 #else
  505 #define KERNEL_LOCK_ASSERT_LOCKED()     /* nothing */
  506 #define KERNEL_LOCK_ASSERT_UNLOCKED()   /* nothing */
  507 #endif
  508 
  509 #endif  /* !_SYS_SYSTM_H_ */

Cache object: 63d85f687f612fa12e6b7075fefbe5b9


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.