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

Cache object: d1006c3ccd225fae002cd84a69a9ae6a


[ 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.