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 /*      $OpenBSD: systm.h,v 1.161 2023/01/31 15:18:56 deraadt Exp $     */
    2 /*      $NetBSD: systm.h,v 1.50 1996/06/09 04:55:09 briggs Exp $        */
    3 
    4 /*-
    5  * Copyright (c) 1982, 1988, 1991, 1993
    6  *      The Regents of the University of California.  All rights reserved.
    7  * (c) UNIX System Laboratories, Inc.
    8  * All or some portions of this file are derived from material licensed
    9  * to the University of California by American Telephone and Telegraph
   10  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
   11  * the permission of UNIX System Laboratories, Inc.
   12  *
   13  * Redistribution and use in source and binary forms, with or without
   14  * modification, are permitted provided that the following conditions
   15  * are met:
   16  * 1. Redistributions of source code must retain the above copyright
   17  *    notice, this list of conditions and the following disclaimer.
   18  * 2. Redistributions in binary form must reproduce the above copyright
   19  *    notice, this list of conditions and the following disclaimer in the
   20  *    documentation and/or other materials provided with the distribution.
   21  * 3. Neither the name of the University nor the names of its contributors
   22  *    may be used to endorse or promote products derived from this software
   23  *    without specific prior written permission.
   24  *
   25  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
   26  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   27  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   28  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
   29  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   30  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   31  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   32  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   34  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   35  * SUCH DAMAGE.
   36  *
   37  *      @(#)systm.h     8.4 (Berkeley) 2/23/94
   38  */
   39 
   40 #ifndef __SYSTM_H__
   41 #define __SYSTM_H__
   42 
   43 #include <sys/queue.h>
   44 #include <sys/stdarg.h>
   45 
   46 /*
   47  * The `securelevel' variable controls the security level of the system.
   48  * It can only be decreased by process 1 (/sbin/init).
   49  *
   50  * Security levels are as follows:
   51  *   -1 permanently insecure mode - always run system in level 0 mode.
   52  *    0 insecure mode - immutable and append-only flags may be turned off.
   53  *      All devices may be read or written subject to permission modes.
   54  *    1 secure mode - immutable and append-only flags may not be changed;
   55  *      raw disks of mounted filesystems, /dev/mem, and /dev/kmem are
   56  *      read-only.
   57  *    2 highly secure mode - same as (1) plus raw disks are always
   58  *      read-only whether mounted or not. This level precludes tampering
   59  *      with filesystems by unmounting them, but also inhibits running
   60  *      newfs while the system is secured.
   61  *
   62  * In normal operation, the system runs in level 0 mode while single user
   63  * and in level 1 mode while multiuser. If level 2 mode is desired while
   64  * running multiuser, it can be set in the multiuser startup script
   65  * (/etc/rc.local) using sysctl(1). If it is desired to run the system
   66  * in level 0 mode while multiuser, initialize the variable securelevel
   67  * in /sys/kern/kern_sysctl.c to -1. Note that it is NOT initialized to
   68  * zero as that would allow the vmunix binary to be patched to -1.
   69  * Without initialization, securelevel loads in the BSS area which only
   70  * comes into existence when the kernel is loaded and hence cannot be
   71  * patched by a stalking hacker.
   72  */
   73 extern int securelevel;         /* system security level */
   74 extern const char *panicstr;    /* panic message */
   75 extern const char version[];            /* system version */
   76 extern const char copyright[];  /* system copyright */
   77 extern const char ostype[];
   78 extern const char osversion[];
   79 extern const char osrelease[];
   80 extern int cold;                /* cold start flag initialized in locore */
   81 extern int db_active;           /* running currently inside ddb(4) */
   82 
   83 extern char *hw_vendor;         /* sysctl hw.vendor */
   84 extern char *hw_prod;           /* sysctl hw.product */
   85 extern char *hw_uuid;           /* sysctl hw.uuid */
   86 extern char *hw_serial;         /* sysctl hw.serialno */
   87 extern char *hw_ver;            /* sysctl hw.version */
   88 
   89 extern int ncpus;               /* number of CPUs used */
   90 extern int ncpusfound;          /* number of CPUs found */
   91 extern int nblkdev;             /* number of entries in bdevsw */
   92 extern int nchrdev;             /* number of entries in cdevsw */
   93 
   94 extern int maxmem;              /* max memory per process */
   95 extern int physmem;             /* physical memory */
   96 
   97 extern dev_t dumpdev;           /* dump device */
   98 extern long dumplo;             /* offset into dumpdev */
   99 
  100 extern dev_t rootdev;           /* root device */
  101 extern u_char bootduid[8];      /* boot device disklabel uid */
  102 extern u_char rootduid[8];      /* root device disklabel uid */
  103 extern struct vnode *rootvp;    /* vnode equivalent to above */
  104 extern struct device *rootdv;   /* device equivalent to above */
  105 
  106 extern dev_t swapdev;           /* swapping device */
  107 extern struct vnode *swapdev_vp;/* vnode equivalent to above */
  108 
  109 extern int nowake;              /* dead wakeup(9) channel */
  110 
  111 struct proc;
  112 struct process;
  113 #define curproc curcpu()->ci_curproc
  114 
  115 typedef int     sy_call_t(struct proc *, void *, register_t *);
  116 
  117 extern const struct sysent {    /* system call table */
  118         short   sy_narg;        /* number of args */
  119         short   sy_argsize;     /* total size of arguments */
  120         int     sy_flags;
  121         sy_call_t *sy_call;     /* implementing function */
  122 } sysent[];
  123 
  124 #define SY_NOLOCK               0x01
  125 
  126 #if     _BYTE_ORDER == _BIG_ENDIAN
  127 #define SCARG(p, k)     ((p)->k.be.datum)       /* get arg from args pointer */
  128 #elif   _BYTE_ORDER == _LITTLE_ENDIAN
  129 #define SCARG(p, k)     ((p)->k.le.datum)       /* get arg from args pointer */
  130 #else
  131 #error  "what byte order is this machine?"
  132 #endif
  133 
  134 #if defined(_KERNEL) && defined(SYSCALL_DEBUG)
  135 void scdebug_call(struct proc *p, register_t code, const register_t retval[]);
  136 void scdebug_ret(struct proc *p, register_t code, int error,
  137     const register_t retval[]);
  138 #endif /* _KERNEL && SYSCALL_DEBUG */
  139 
  140 extern int boothowto;           /* reboot flags, from console subsystem */
  141 
  142 extern void (*v_putc)(int); /* Virtual console putc routine */
  143 
  144 /*
  145  * General function declarations.
  146  */
  147 int     nullop(void *);
  148 int     enodev(void);
  149 int     enosys(void);
  150 int     enoioctl(void);
  151 int     enxio(void);
  152 int     eopnotsupp(void *);
  153 
  154 void    *hashinit(int, int, int, u_long *);
  155 void     hashfree(void *, int, int);
  156 int     sys_nosys(struct proc *, void *, register_t *);
  157 
  158 void    panic(const char *, ...)
  159     __attribute__((__noreturn__,__format__(__kprintf__,1,2)));
  160 void    __assert(const char *, const char *, int, const char *)
  161     __attribute__((__noreturn__));
  162 int     printf(const char *, ...)
  163     __attribute__((__format__(__kprintf__,1,2)));
  164 void    uprintf(const char *, ...)
  165     __attribute__((__format__(__kprintf__,1,2)));
  166 int     vprintf(const char *, va_list)
  167     __attribute__((__format__(__kprintf__,1,0)));
  168 int     vsnprintf(char *, size_t, const char *, va_list)
  169     __attribute__((__format__(__kprintf__,3,0)));
  170 int     snprintf(char *buf, size_t, const char *, ...)
  171     __attribute__((__format__(__kprintf__,3,4)));
  172 struct tty;
  173 void    ttyprintf(struct tty *, const char *, ...)
  174     __attribute__((__format__(__kprintf__,2,3)));
  175 
  176 void    splassert_fail(int, int, const char *);
  177 extern  int splassert_ctl;
  178 
  179 void    assertwaitok(void);
  180 
  181 void    tablefull(const char *);
  182 
  183 int     kcopy(const void *, void *, size_t)
  184                 __attribute__ ((__bounded__(__buffer__,1,3)))
  185                 __attribute__ ((__bounded__(__buffer__,2,3)));
  186 
  187 void    bcopy(const void *, void *, size_t)
  188                 __attribute__ ((__bounded__(__buffer__,1,3)))
  189                 __attribute__ ((__bounded__(__buffer__,2,3)));
  190 void    bzero(void *, size_t)
  191                 __attribute__ ((__bounded__(__buffer__,1,2)));
  192 void    explicit_bzero(void *, size_t)
  193                 __attribute__ ((__bounded__(__buffer__,1,2)));
  194 int     bcmp(const void *, const void *, size_t);
  195 void    *memcpy(void *, const void *, size_t)
  196                 __attribute__ ((__bounded__(__buffer__,1,3)))
  197                 __attribute__ ((__bounded__(__buffer__,2,3)));
  198 void    *memmove(void *, const void *, size_t)
  199                 __attribute__ ((__bounded__(__buffer__,1,3)))
  200                 __attribute__ ((__bounded__(__buffer__,2,3)));
  201 void    *memset(void *, int, size_t)
  202                 __attribute__ ((__bounded__(__buffer__,1,3)));
  203 
  204 int     copyinstr(const void *, void *, size_t, size_t *)
  205                 __attribute__ ((__bounded__(__string__,2,3)));
  206 int     _copyinstr(const void *, void *, size_t, size_t *)
  207                 __attribute__ ((__bounded__(__string__,2,3)));
  208 int     copyoutstr(const void *, void *, size_t, size_t *);
  209 int     copyin(const void *, void *, size_t)
  210                 __attribute__ ((__bounded__(__buffer__,2,3)));
  211 int     _copyin(const void *, void *, size_t)
  212                 __attribute__ ((__bounded__(__buffer__,2,3)));
  213 int     copyout(const void *, void *, size_t);
  214 int     copyin32(const uint32_t *, uint32_t *);
  215 
  216 void    random_start(int);
  217 void    enqueue_randomness(unsigned int);
  218 void    suspend_randomness(void);
  219 void    resume_randomness(char *, size_t);
  220 
  221 struct arc4random_ctx;
  222 void    arc4random_buf(void *, size_t)
  223                 __attribute__ ((__bounded__(__buffer__,1,2)));
  224 struct arc4random_ctx   *arc4random_ctx_new(void);
  225 void    arc4random_ctx_free(struct arc4random_ctx *);
  226 void    arc4random_ctx_buf(struct arc4random_ctx *, void *, size_t);
  227 u_int32_t arc4random(void);
  228 u_int32_t arc4random_uniform(u_int32_t);
  229 
  230 struct timeval;
  231 struct timespec;
  232 int     tvtohz(const struct timeval *);
  233 int     tstohz(const struct timespec *);
  234 void    realitexpire(void *);
  235 
  236 struct clockframe;
  237 void    hardclock(struct clockframe *);
  238 void    statclock(struct clockframe *);
  239 
  240 void    initclocks(void);
  241 void    inittodr(time_t);
  242 void    resettodr(void);
  243 void    cpu_initclocks(void);
  244 
  245 void    startprofclock(struct process *);
  246 void    stopprofclock(struct process *);
  247 void    setstatclockrate(int);
  248 
  249 void    start_periodic_resettodr(void);
  250 void    stop_periodic_resettodr(void);
  251 
  252 struct sleep_state;
  253 void    sleep_setup(struct sleep_state *, const volatile void *, int,
  254             const char *, int);
  255 int     sleep_finish(struct sleep_state *, int);
  256 void    sleep_queue_init(void);
  257 
  258 struct cond;
  259 void    cond_init(struct cond *);
  260 void    cond_wait(struct cond *, const char *);
  261 void    cond_signal(struct cond *);
  262 
  263 #define INFSLP  UINT64_MAX
  264 #define MAXTSLP (UINT64_MAX - 1)
  265 
  266 struct mutex;
  267 struct rwlock;
  268 void    wakeup_n(const volatile void *, int);
  269 void    wakeup(const volatile void *);
  270 #define wakeup_one(c) wakeup_n((c), 1)
  271 int     tsleep(const volatile void *, int, const char *, int);
  272 int     tsleep_nsec(const volatile void *, int, const char *, uint64_t);
  273 int     msleep(const volatile void *, struct mutex *, int,  const char*, int);
  274 int     msleep_nsec(const volatile void *, struct mutex *, int,  const char*,
  275             uint64_t);
  276 int     rwsleep(const volatile void *, struct rwlock *, int, const char *, int);
  277 int     rwsleep_nsec(const volatile void *, struct rwlock *, int, const char *,
  278             uint64_t);
  279 void    yield(void);
  280 
  281 void    wdog_register(int (*)(void *, int), void *);
  282 void    wdog_shutdown(void *);
  283 
  284 /*
  285  * Startup hooks are functions running after the scheduler has started
  286  * but before any threads have been created or root has been mounted.
  287  */
  288 
  289 struct hook_desc {
  290         TAILQ_ENTRY(hook_desc) hd_list;
  291         void    (*hd_fn)(void *);
  292         void    *hd_arg;
  293 };
  294 TAILQ_HEAD(hook_desc_head, hook_desc);
  295 
  296 extern struct hook_desc_head startuphook_list;
  297 
  298 void    *hook_establish(struct hook_desc_head *, int, void (*)(void *), void *);
  299 void    hook_disestablish(struct hook_desc_head *, void *);
  300 void    dohooks(struct hook_desc_head *, int);
  301 
  302 #define HOOK_REMOVE     0x01
  303 #define HOOK_FREE       0x02
  304 
  305 #define startuphook_establish(fn, arg) \
  306         hook_establish(&startuphook_list, 1, (fn), (arg))
  307 #define startuphook_disestablish(vhook) \
  308         hook_disestablish(&startuphook_list, (vhook))
  309 #define dostartuphooks() dohooks(&startuphook_list, HOOK_REMOVE|HOOK_FREE)
  310 
  311 struct uio;
  312 int     uiomove(void *, size_t, struct uio *);
  313 
  314 #if defined(_KERNEL)
  315 
  316 #include <sys/rwlock.h>
  317 
  318 extern struct rwlock netlock;
  319 
  320 /*
  321  * Network stack data structures are, unless stated otherwise, protected
  322  * by the NET_LOCK().  It's a single non-recursive lock for the whole
  323  * subsystem.
  324  */
  325 #define NET_LOCK()      do { rw_enter_write(&netlock); } while (0)
  326 #define NET_UNLOCK()    do { rw_exit_write(&netlock); } while (0)
  327 
  328 /*
  329  * Reader version of NET_LOCK().
  330  * The "softnet" thread should be the only thread processing packets
  331  * without holding an exclusive lock.  This is done to allow read-only
  332  * ioctl(2) to not block.
  333  * Shared lock can be grabbed instead of the exclusive version if no field
  334  * protected by the NET_LOCK() is modified by the ioctl/sysctl.
  335  * Socket system call can use shared netlock if it has additional locks
  336  * to protect socket and pcb data structures.
  337  */
  338 #define NET_LOCK_SHARED()       do { rw_enter_read(&netlock); } while (0)
  339 #define NET_UNLOCK_SHARED()     do { rw_exit_read(&netlock); } while (0)
  340 
  341 #ifdef DIAGNOSTIC
  342 
  343 #define NET_ASSERT_UNLOCKED()                                           \
  344 do {                                                                    \
  345         int _s = rw_status(&netlock);                                   \
  346         if ((splassert_ctl > 0) && (_s == RW_WRITE))                    \
  347                 splassert_fail(0, RW_WRITE, __func__);                  \
  348 } while (0)
  349 
  350 #define NET_ASSERT_LOCKED()                                             \
  351 do {                                                                    \
  352         int _s = rw_status(&netlock);                                   \
  353         if ((splassert_ctl > 0) && (_s != RW_WRITE && _s != RW_READ))   \
  354                 splassert_fail(RW_READ, _s, __func__);                  \
  355 } while (0)
  356 
  357 #define NET_ASSERT_LOCKED_EXCLUSIVE()                                   \
  358 do {                                                                    \
  359         int _s = rw_status(&netlock);                                   \
  360         if ((splassert_ctl > 0) && (_s != RW_WRITE))                    \
  361                 splassert_fail(RW_WRITE, _s, __func__);                 \
  362 } while (0)
  363 
  364 #else /* DIAGNOSTIC */
  365 #define NET_ASSERT_UNLOCKED()           do {} while (0)
  366 #define NET_ASSERT_LOCKED()             do {} while (0)
  367 #define NET_ASSERT_LOCKED_EXCLUSIVE()   do {} while (0)
  368 #endif /* !DIAGNOSTIC */
  369 
  370 __returns_twice int     setjmp(label_t *);
  371 __dead void     longjmp(label_t *);
  372 #endif
  373 
  374 void    consinit(void);
  375 
  376 void    cpu_startup(void);
  377 void    cpu_configure(void);
  378 void    diskconf(void);
  379 
  380 int nfs_mountroot(void);
  381 int dk_mountroot(void);
  382 extern int (*mountroot)(void);
  383 
  384 #include <lib/libkern/libkern.h>
  385 
  386 #define bzero(b, n)             __builtin_bzero((b), (n))
  387 #define memcmp(b1, b2, n)       __builtin_memcmp((b1), (b2), (n))
  388 #define memcpy(d, s, n)         __builtin_memcpy((d), (s), (n))
  389 #define memset(b, c, n)         __builtin_memset((b), (c), (n))
  390 #if (defined(__GNUC__) && __GNUC__ >= 4)
  391 #define memmove(d, s, n)        __builtin_memmove((d), (s), (n))
  392 #endif
  393 #if !defined(__clang__) && (defined(__GNUC__) && __GNUC__ >= 4)
  394 #define bcmp(b1, b2, n)         __builtin_bcmp((b1), (b2), (n))
  395 #define bcopy(s, d, n)          __builtin_bcopy((s), (d), (n))
  396 #endif
  397 
  398 #if defined(DDB)
  399 /* debugger entry points */
  400 void    db_enter(void); /* in DDB only */
  401 int     db_rint(int);
  402 #endif
  403 
  404 #ifdef BOOT_CONFIG
  405 void    user_config(void);
  406 #endif
  407 
  408 #if defined(MULTIPROCESSOR)
  409 void    _kernel_lock_init(void);
  410 void    _kernel_lock(void);
  411 void    _kernel_unlock(void);
  412 int     _kernel_lock_held(void);
  413 
  414 #define KERNEL_LOCK_INIT()              _kernel_lock_init()
  415 #define KERNEL_LOCK()                   _kernel_lock()
  416 #define KERNEL_UNLOCK()                 _kernel_unlock()
  417 #define KERNEL_ASSERT_LOCKED()          KASSERT(_kernel_lock_held())
  418 #define KERNEL_ASSERT_UNLOCKED()        KASSERT(!_kernel_lock_held())
  419 
  420 #else /* ! MULTIPROCESSOR */
  421 
  422 #define KERNEL_LOCK_INIT()              /* nothing */
  423 #define KERNEL_LOCK()                   /* nothing */
  424 #define KERNEL_UNLOCK()                 /* nothing */
  425 #define KERNEL_ASSERT_LOCKED()          /* nothing */
  426 #define KERNEL_ASSERT_UNLOCKED()        /* nothing */
  427 
  428 #endif /* MULTIPROCESSOR */
  429 
  430 #endif /* __SYSTM_H__ */

Cache object: 53f60941592a522f9b22633bcdf11301


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