systm.h revision 97307
11541Srgrimes/*- 21541Srgrimes * Copyright (c) 1982, 1988, 1991, 1993 31541Srgrimes * The Regents of the University of California. All rights reserved. 41541Srgrimes * (c) UNIX System Laboratories, Inc. 51541Srgrimes * All or some portions of this file are derived from material licensed 61541Srgrimes * to the University of California by American Telephone and Telegraph 71541Srgrimes * Co. or Unix System Laboratories, Inc. and are reproduced herein with 81541Srgrimes * the permission of UNIX System Laboratories, Inc. 91541Srgrimes * 101541Srgrimes * Redistribution and use in source and binary forms, with or without 111541Srgrimes * modification, are permitted provided that the following conditions 121541Srgrimes * are met: 131541Srgrimes * 1. Redistributions of source code must retain the above copyright 141541Srgrimes * notice, this list of conditions and the following disclaimer. 151541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 161541Srgrimes * notice, this list of conditions and the following disclaimer in the 171541Srgrimes * documentation and/or other materials provided with the distribution. 181541Srgrimes * 3. All advertising materials mentioning features or use of this software 191541Srgrimes * must display the following acknowledgement: 201541Srgrimes * This product includes software developed by the University of 211541Srgrimes * California, Berkeley and its contributors. 221541Srgrimes * 4. Neither the name of the University nor the names of its contributors 231541Srgrimes * may be used to endorse or promote products derived from this software 241541Srgrimes * without specific prior written permission. 251541Srgrimes * 261541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 271541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 281541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 291541Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 301541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 311541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 321541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 331541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 341541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 351541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 361541Srgrimes * SUCH DAMAGE. 371541Srgrimes * 3814508Shsu * @(#)systm.h 8.7 (Berkeley) 3/29/95 3950477Speter * $FreeBSD: head/sys/sys/systm.h 97307 2002-05-26 16:03:13Z dfr $ 401541Srgrimes */ 411541Srgrimes 422165Spaul#ifndef _SYS_SYSTM_H_ 432865Sbde#define _SYS_SYSTM_H_ 442165Spaul 4549043Salc#include <machine/atomic.h> 461549Srgrimes#include <machine/cpufunc.h> 4729683Sgibbs#include <sys/callout.h> 4894936Smux#include <sys/queue.h> 491549Srgrimes 5018883Sbdeextern int securelevel; /* system security level (see init(8)) */ 5193593Sjhbextern int suser_enabled; /* suser() is permitted to return 0 */ 527090Sbde 537090Sbdeextern int cold; /* nonzero if we are doing a cold boot */ 541541Srgrimesextern const char *panicstr; /* panic message */ 551541Srgrimesextern char version[]; /* system version */ 561541Srgrimesextern char copyright[]; /* system copyright */ 571541Srgrimes 581541Srgrimesextern int nswap; /* size of swap space */ 591541Srgrimes 6092252Salfredextern int nselcoll; /* select collisions since boot */ 6192252Salfredextern struct mtx sellock; /* select lock variable */ 6276564Stanimuraextern struct cv selwait; /* select conditional variable */ 631541Srgrimes 641541Srgrimesextern int physmem; /* physical memory */ 651541Srgrimes 661541Srgrimesextern dev_t rootdev; /* root device */ 6736809Sbdeextern dev_t rootdevs[2]; /* possible root devices */ 6836809Sbdeextern char *rootdevnames[2]; /* names of possible root devices */ 691541Srgrimesextern struct vnode *rootvp; /* vnode equivalent to above */ 701541Srgrimes 711541Srgrimesextern int boothowto; /* reboot flags, from console subsystem */ 7215113Sbdeextern int bootverbose; /* nonzero to print verbose messages */ 731541Srgrimes 7480418Speterextern int maxusers; /* system tune hint */ 7580418Speter 7642453Seivind#ifdef INVARIANTS /* The option is always available */ 7742453Seivind#define KASSERT(exp,msg) do { if (!(exp)) panic msg; } while (0) 7842408Seivind#else 7942453Seivind#define KASSERT(exp,msg) 8042408Seivind#endif 8142408Seivind 8293600Sjake#define CTASSERT(x) _CTASSERT(x, __LINE__) 8393600Sjake#define _CTASSERT(x, y) __CTASSERT(x, y) 8493600Sjake#define __CTASSERT(x, y) typedef char __assert ## y[(x) ? 1 : -1] 8593600Sjake 861541Srgrimes/* 8783595Speter * XXX the hints declarations are even more misplaced than most declarations 8883595Speter * in this file, since they are needed in one file (per arch) and only used 8983595Speter * in two files. 9083595Speter * XXX most of these variables should be const. 9183595Speter */ 9283595Speterextern int envmode; 9383595Speterextern int hintmode; /* 0 = off. 1 = config, 2 = fallback */ 9494936Smuxextern int dynamic_kenv; 9594936Smuxextern struct sx kenv_lock; 9683595Speterextern char *kern_envp; 9783595Speterextern char static_env[]; 9883595Speterextern char static_hints[]; /* by config for now */ 9983595Speter 10094936Smuxextern char **kenvp; 10194936Smux 10283595Speter/* 1031541Srgrimes * General function declarations. 1041541Srgrimes */ 10530282Sphk 10633777Sbdestruct clockframe; 10730282Sphkstruct malloc_type; 10865708Sjakestruct mtx; 10933777Sbdestruct proc; 11083366Sjulianstruct kse; 11192976Srwatsonstruct socket; 11283366Sjulianstruct thread; 11333777Sbdestruct tty; 11467893Sphkstruct ucred; 11533777Sbdestruct uio; 11679418Sjulianstruct _jmp_buf; 11730282Sphk 11892719Salfredint setjmp(struct _jmp_buf *); 11992719Salfredvoid longjmp(struct _jmp_buf *, int) __dead2; 12092719Salfredvoid Debugger(const char *msg); 12192719Salfredint dumpstatus(vm_offset_t addr, off_t count); 12292719Salfredint nullop(void); 12392719Salfredint eopnotsupp(void); 12492719Salfredint seltrue(dev_t dev, int which, struct thread *td); 12592719Salfredint ureadc(int, struct uio *); 12692719Salfredvoid *hashinit(int count, struct malloc_type *type, u_long *hashmask); 12792719Salfredvoid *phashinit(int count, struct malloc_type *type, u_long *nentries); 1281541Srgrimes 12990503Sbde#ifdef RESTARTABLE_PANICS 13092719Salfredvoid panic(const char *, ...) __printflike(1, 2); 13190503Sbde#else 13292719Salfredvoid panic(const char *, ...) __dead2 __printflike(1, 2); 13390503Sbde#endif 13490503Sbde 13592719Salfredvoid cpu_boot(int); 13692719Salfredvoid cpu_rootconf(void); 13792719Salfredvoid critical_enter(void); 13892719Salfredvoid critical_exit(void); 13992719Salfredvoid init_param1(void); 14092719Salfredvoid init_param2(int physpages); 14192719Salfredvoid tablefull(const char *); 14292719Salfredint kvprintf(char const *, void (*)(int, void*), void *, int, 14393008Sbde _BSD_VA_LIST_) __printflike(1, 0); 14492719Salfredvoid log(int, const char *, ...) __printflike(2, 3); 14592719Salfredvoid log_console(struct uio *); 14692719Salfredint printf(const char *, ...) __printflike(1, 2); 14792719Salfredint snprintf(char *, size_t, const char *, ...) __printflike(3, 4); 14892719Salfredint sprintf(char *buf, const char *, ...) __printflike(2, 3); 14992719Salfredint uprintf(const char *, ...) __printflike(1, 2); 15092719Salfredint vprintf(const char *, _BSD_VA_LIST_) __printflike(1, 0); 15192719Salfredint vsnprintf(char *, size_t, const char *, _BSD_VA_LIST_) __printflike(3, 0); 15292719Salfredint vsprintf(char *buf, const char *, _BSD_VA_LIST_) __printflike(2, 0); 15392719Salfredint ttyprintf(struct tty *, const char *, ...) __printflike(2, 3); 15492719Salfredint sscanf(const char *, char const *, ...); 15592719Salfredint vsscanf(const char *, char const *, _BSD_VA_LIST_); 15692719Salfredlong strtol(const char *, char **, int); 15792719Salfredu_long strtoul(const char *, char **, int); 15892719Salfredquad_t strtoq(const char *, char **, int); 15992719Salfredu_quad_t strtouq(const char *, char **, int); 16092719Salfredvoid tprintf(struct proc *p, int pri, const char *, ...) __printflike(3, 4); 1611541Srgrimes 16292719Salfredvoid bcopy(const void *from, void *to, size_t len); 16392719Salfredvoid ovbcopy(const void *from, void *to, size_t len); 16456079Sjmb 16536735Sdfr#ifdef __i386__ 16692719Salfredextern void (*bzero)(void *buf, size_t len); 16736735Sdfr#else 16892719Salfredvoid bzero(void *buf, size_t len); 16936735Sdfr#endif 1701541Srgrimes 17192719Salfredvoid *memcpy(void *to, const void *from, size_t len); 1728215Sdg 17392719Salfredint copystr(const void *kfaddr, void *kdaddr, size_t len, 17493008Sbde size_t *lencopied); 17592719Salfredint copyinstr(const void *udaddr, void *kaddr, size_t len, 17693008Sbde size_t *lencopied); 17792719Salfredint copyin(const void *udaddr, void *kaddr, size_t len); 17892719Salfredint copyout(const void *kaddr, void *udaddr, size_t len); 1791541Srgrimes 18092719Salfredint fubyte(const void *base); 18192719Salfredint subyte(void *base, int byte); 18292719Salfredint suibyte(void *base, int byte); 18397307Sdfrint32_t fuword32(const void *base); 18497307Sdfrint64_t fuword64(const void *base); 18592719Salfredlong fuword(const void *base); 18692719Salfredint suword(void *base, long word); 18797307Sdfrint suword32(void *base, int32_t word); 18897307Sdfrint suword64(void *base, int64_t word); 18992719Salfredint fusword(void *base); 19092719Salfredint susword(void *base, int word); 1911541Srgrimes 19292719Salfredvoid realitexpire(void *); 1931541Srgrimes 19492719Salfredvoid hardclock(struct clockframe *frame); 19592719Salfredvoid hardclock_process(struct thread *td, int user); 19692719Salfredvoid softclock(void *); 19792719Salfredvoid statclock(struct clockframe *frame); 19892719Salfredvoid statclock_process(struct kse *ke, register_t pc, int user); 1991541Srgrimes 20092719Salfredvoid startprofclock(struct proc *); 20192719Salfredvoid stopprofclock(struct proc *); 20292719Salfredvoid setstatclockrate(int hzrate); 2031541Srgrimes 20493593Sjhb/* flags for suser() and suser_cred() */ 20567893Sphk#define PRISON_ROOT 1 20667893Sphk 20793593Sjhbint suser(struct thread *td); 20893593Sjhbint suser_cred(struct ucred *cred, int flag); 20992719Salfredint cr_cansee(struct ucred *u1, struct ucred *u2); 21092976Srwatsonint cr_canseesocket(struct ucred *cred, struct socket *so); 21167893Sphk 21292719Salfredchar *getenv(const char *name); 21394936Smuxvoid freeenv(char *env); 21492719Salfredint getenv_int(const char *name, int *data); 21592719Salfredint getenv_string(const char *name, char *data, int size); 21692719Salfredint getenv_quad(const char *name, quad_t *data); 21794959Smuxint setenv(const char *name, const char *value); 21894936Smuxint unsetenv(const char *name); 21994936Smuxint testenv(const char *name); 22040096Smsmith 22131960Snate#ifdef APM_FIXUP_CALLTODO 22283595Speterstruct timeval; 22392719Salfredvoid adjust_timeout_calltodo(struct timeval *time_change); 22431960Snate#endif /* APM_FIXUP_CALLTODO */ 22531960Snate 2267109Sphk#include <sys/libkern.h> 2272112Swollman 2282112Swollman/* Initialize the world */ 22992719Salfredvoid consinit(void); 23092719Salfredvoid cpu_initclocks(void); 23192719Salfredvoid usrinfoinit(void); 2322112Swollman 2337090Sbde/* Finalize the world. */ 23492719Salfredvoid shutdown_nice(int); 2357090Sbde 2367090Sbde/* 2377090Sbde * Kernel to clock driver interface. 2387090Sbde */ 23992719Salfredvoid inittodr(time_t base); 24092719Salfredvoid resettodr(void); 24192719Salfredvoid startrtclock(void); 2427090Sbde 2432112Swollman/* Timeouts */ 24492719Salfredtypedef void timeout_t(void *); /* timeout function type */ 24529683Sgibbs#define CALLOUT_HANDLE_INITIALIZER(handle) \ 24629683Sgibbs { NULL } 2472112Swollman 24892719Salfredvoid callout_handle_init(struct callout_handle *); 24992719Salfredstruct callout_handle timeout(timeout_t *, void *, int); 25092719Salfredvoid untimeout(timeout_t *, void *, struct callout_handle); 25192719Salfredcaddr_t kern_timeout_callwheel_alloc(caddr_t v); 25292719Salfredvoid kern_timeout_callwheel_init(void); 2532165Spaul 25471240Speter/* Stubs for obsolete functions that used to be for interrupt management */ 25571240Speterstatic __inline void spl0(void) { return; } 25671240Speterstatic __inline intrmask_t splbio(void) { return 0; } 25771240Speterstatic __inline intrmask_t splcam(void) { return 0; } 25871240Speterstatic __inline intrmask_t splclock(void) { return 0; } 25971240Speterstatic __inline intrmask_t splhigh(void) { return 0; } 26071240Speterstatic __inline intrmask_t splimp(void) { return 0; } 26171240Speterstatic __inline intrmask_t splnet(void) { return 0; } 26271240Speterstatic __inline intrmask_t splsoftcam(void) { return 0; } 26371240Speterstatic __inline intrmask_t splsoftclock(void) { return 0; } 26471240Speterstatic __inline intrmask_t splsofttty(void) { return 0; } 26571240Speterstatic __inline intrmask_t splsoftvm(void) { return 0; } 26671240Speterstatic __inline intrmask_t splsofttq(void) { return 0; } 26771240Speterstatic __inline intrmask_t splstatclock(void) { return 0; } 26871240Speterstatic __inline intrmask_t spltty(void) { return 0; } 26971240Speterstatic __inline intrmask_t splvm(void) { return 0; } 27071240Speterstatic __inline void splx(intrmask_t ipl) { return; } 27126312Speter 27226312Speter/* 27329509Sbde * Various callout lists. 27429509Sbde */ 27517658Sjulian 27629509Sbde/* Exit callout list declarations. */ 27792719Salfredtypedef void (*exitlist_fn)(struct proc *procp); 27817658Sjulian 27992719Salfredint at_exit(exitlist_fn function); 28092719Salfredint rm_at_exit(exitlist_fn function); 28117658Sjulian 28229509Sbde/* Fork callout list declarations. */ 28393008Sbdetypedef void (*forklist_fn)(struct proc *parent, struct proc *child, int flags); 28427997Sjulian 28592719Salfredint at_fork(forklist_fn function); 28692719Salfredint rm_at_fork(forklist_fn function); 28727997Sjulian 28888633Salfred/* Exec callout list declarations. */ 28992719Salfredtypedef void (*execlist_fn)(struct proc *procp); 29088633Salfred 29192719Salfredint at_exec(execlist_fn function); 29292719Salfredint rm_at_exec(execlist_fn function); 29388633Salfred 29429509Sbde/* 29529509Sbde * Not exactly a callout LIST, but a callout entry. 29629509Sbde * Allow an external module to define a hardware watchdog tickler. 29729509Sbde * Normally a process would do this, but there are times when the 29829509Sbde * kernel needs to be able to hold off the watchdog, when the process 29929509Sbde * is not active, e.g., when dumping core. 30029509Sbde */ 30192719Salfredtypedef void (*watchdog_tickle_fn)(void); 30229509Sbde 30329509Sbdeextern watchdog_tickle_fn wdog_tickler; 30429509Sbde 30518884Sbde/* 30618884Sbde * Common `proc' functions are declared here so that proc.h can be included 30718884Sbde * less often. 30818884Sbde */ 30992719Salfredint msleep(void *chan, struct mtx *mtx, int pri, const char *wmesg, 31093008Sbde int timo); 31165708Sjake#define tsleep(chan, pri, wmesg, timo) msleep(chan, NULL, pri, wmesg, timo) 31292719Salfredvoid wakeup(void *chan); 31392719Salfredvoid wakeup_one(void *chan); 31418884Sbde 31547028Sphk/* 31647028Sphk * Common `dev_t' stuff are declared here to avoid #include poisoning 31747028Sphk */ 31847028Sphk 31947028Sphkint major(dev_t x); 32047028Sphkint minor(dev_t x); 32147028Sphkdev_t makedev(int x, int y); 32247028Sphkudev_t dev2udev(dev_t x); 32347028Sphkdev_t udev2dev(udev_t x, int b); 32447028Sphkint uminor(udev_t dev); 32547028Sphkint umajor(udev_t dev); 32648859Sphkudev_t makeudev(int x, int y); 32767158Sphk 32867158Sphk/* XXX: Should be void nanodelay(u_int nsec); */ 32992719Salfredvoid DELAY(int usec); 33067158Sphk 3312865Sbde#endif /* !_SYS_SYSTM_H_ */ 332