systm.h revision 103083
1/*- 2 * Copyright (c) 1982, 1988, 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * (c) UNIX System Laboratories, Inc. 5 * All or some portions of this file are derived from material licensed 6 * to the University of California by American Telephone and Telegraph 7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with 8 * the permission of UNIX System Laboratories, Inc. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the University of 21 * California, Berkeley and its contributors. 22 * 4. Neither the name of the University nor the names of its contributors 23 * may be used to endorse or promote products derived from this software 24 * without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 * SUCH DAMAGE. 37 * 38 * @(#)systm.h 8.7 (Berkeley) 3/29/95 39 * $FreeBSD: head/sys/sys/systm.h 103083 2002-09-07 22:11:45Z peter $ 40 */ 41 42#ifndef _SYS_SYSTM_H_ 43#define _SYS_SYSTM_H_ 44 45#include <machine/atomic.h> 46#include <machine/cpufunc.h> 47#include <sys/callout.h> 48#include <sys/queue.h> 49 50extern int securelevel; /* system security level (see init(8)) */ 51extern int suser_enabled; /* suser() is permitted to return 0 */ 52 53extern int cold; /* nonzero if we are doing a cold boot */ 54extern const char *panicstr; /* panic message */ 55extern char version[]; /* system version */ 56extern char copyright[]; /* system copyright */ 57extern int kstack_pages; /* number of kernel stack pages */ 58extern int uarea_pages; /* number of user struct pages */ 59 60extern int nswap; /* size of swap space */ 61 62extern u_int nselcoll; /* select collisions since boot */ 63extern struct mtx sellock; /* select lock variable */ 64extern struct cv selwait; /* select conditional variable */ 65 66extern long physmem; /* physical memory */ 67 68extern dev_t rootdev; /* root device */ 69extern dev_t rootdevs[2]; /* possible root devices */ 70extern char *rootdevnames[2]; /* names of possible root devices */ 71extern struct vnode *rootvp; /* vnode equivalent to above */ 72 73extern int boothowto; /* reboot flags, from console subsystem */ 74extern int bootverbose; /* nonzero to print verbose messages */ 75 76extern int maxusers; /* system tune hint */ 77 78#ifdef INVARIANTS /* The option is always available */ 79#define KASSERT(exp,msg) do { if (!(exp)) panic msg; } while (0) 80#else 81#define KASSERT(exp,msg) 82#endif 83 84#define CTASSERT(x) _CTASSERT(x, __LINE__) 85#define _CTASSERT(x, y) __CTASSERT(x, y) 86#define __CTASSERT(x, y) typedef char __assert ## y[(x) ? 1 : -1] 87 88/* 89 * XXX the hints declarations are even more misplaced than most declarations 90 * in this file, since they are needed in one file (per arch) and only used 91 * in two files. 92 * XXX most of these variables should be const. 93 */ 94extern int envmode; 95extern int hintmode; /* 0 = off. 1 = config, 2 = fallback */ 96extern int dynamic_kenv; 97extern struct sx kenv_lock; 98extern char *kern_envp; 99extern char static_env[]; 100extern char static_hints[]; /* by config for now */ 101 102extern char **kenvp; 103 104/* 105 * General function declarations. 106 */ 107 108struct clockframe; 109struct malloc_type; 110struct mtx; 111struct proc; 112struct kse; 113struct socket; 114struct thread; 115struct tty; 116struct ucred; 117struct uio; 118struct _jmp_buf; 119 120int setjmp(struct _jmp_buf *); 121void longjmp(struct _jmp_buf *, int) __dead2; 122void Debugger(const char *msg); 123int dumpstatus(vm_offset_t addr, off_t count); 124int nullop(void); 125int eopnotsupp(void); 126int seltrue(dev_t dev, int which, struct thread *td); 127int ureadc(int, struct uio *); 128void hashdestroy(void *, struct malloc_type *, u_long); 129void *hashinit(int count, struct malloc_type *type, u_long *hashmask); 130void *phashinit(int count, struct malloc_type *type, u_long *nentries); 131 132#ifdef RESTARTABLE_PANICS 133void panic(const char *, ...) __printflike(1, 2); 134#else 135void panic(const char *, ...) __dead2 __printflike(1, 2); 136#endif 137 138void cpu_boot(int); 139void cpu_rootconf(void); 140extern uint32_t crc32_tab[]; 141uint32_t crc32(const void *buf, size_t size); 142void critical_enter(void); 143void critical_exit(void); 144void init_param1(void); 145void init_param2(long physpages); 146void tablefull(const char *); 147int kvprintf(char const *, void (*)(int, void*), void *, int, 148 __va_list) __printflike(1, 0); 149void log(int, const char *, ...) __printflike(2, 3); 150void log_console(struct uio *); 151int printf(const char *, ...) __printflike(1, 2); 152int snprintf(char *, size_t, const char *, ...) __printflike(3, 4); 153int sprintf(char *buf, const char *, ...) __printflike(2, 3); 154int uprintf(const char *, ...) __printflike(1, 2); 155int vprintf(const char *, __va_list) __printflike(1, 0); 156int vsnprintf(char *, size_t, const char *, __va_list) __printflike(3, 0); 157int vsprintf(char *buf, const char *, __va_list) __printflike(2, 0); 158int ttyprintf(struct tty *, const char *, ...) __printflike(2, 3); 159int sscanf(const char *, char const *, ...); 160int vsscanf(const char *, char const *, __va_list); 161long strtol(const char *, char **, int); 162u_long strtoul(const char *, char **, int); 163quad_t strtoq(const char *, char **, int); 164u_quad_t strtouq(const char *, char **, int); 165void tprintf(struct proc *p, int pri, const char *, ...) __printflike(3, 4); 166 167void bcopy(const void *from, void *to, size_t len); 168void ovbcopy(const void *from, void *to, size_t len); 169 170#ifdef __i386__ 171extern void (*bzero)(void *buf, size_t len); 172#else 173void bzero(void *buf, size_t len); 174#endif 175 176void *memcpy(void *to, const void *from, size_t len); 177 178int copystr(const void *kfaddr, void *kdaddr, size_t len, 179 size_t *lencopied); 180int copyinstr(const void *udaddr, void *kaddr, size_t len, 181 size_t *lencopied); 182int copyin(const void *udaddr, void *kaddr, size_t len); 183int copyout(const void *kaddr, void *udaddr, size_t len); 184 185int fubyte(const void *base); 186long fuword(const void *base); 187int fuword16(void *base); 188int32_t fuword32(const void *base); 189int64_t fuword64(const void *base); 190int subyte(void *base, int byte); 191int suword(void *base, long word); 192int suword16(void *base, int word); 193int suword32(void *base, int32_t word); 194int suword64(void *base, int64_t word); 195 196void realitexpire(void *); 197 198void hardclock(struct clockframe *frame); 199void hardclock_process(struct thread *td, int user); 200void softclock(void *); 201void statclock(struct clockframe *frame); 202void statclock_process(struct kse *ke, register_t pc, int user); 203 204void startprofclock(struct proc *); 205void stopprofclock(struct proc *); 206void setstatclockrate(int hzrate); 207 208/* flags for suser() and suser_cred() */ 209#define PRISON_ROOT 1 210 211int suser(struct thread *td); 212int suser_cred(struct ucred *cred, int flag); 213int cr_cansee(struct ucred *u1, struct ucred *u2); 214int cr_canseesocket(struct ucred *cred, struct socket *so); 215 216char *getenv(const char *name); 217void freeenv(char *env); 218int getenv_int(const char *name, int *data); 219int getenv_string(const char *name, char *data, int size); 220int getenv_quad(const char *name, quad_t *data); 221int setenv(const char *name, const char *value); 222int unsetenv(const char *name); 223int testenv(const char *name); 224 225#ifdef APM_FIXUP_CALLTODO 226struct timeval; 227void adjust_timeout_calltodo(struct timeval *time_change); 228#endif /* APM_FIXUP_CALLTODO */ 229 230#include <sys/libkern.h> 231 232/* Initialize the world */ 233void consinit(void); 234void cpu_initclocks(void); 235void usrinfoinit(void); 236 237/* Finalize the world. */ 238void shutdown_nice(int); 239 240/* 241 * Kernel to clock driver interface. 242 */ 243void inittodr(time_t base); 244void resettodr(void); 245void startrtclock(void); 246 247/* Timeouts */ 248typedef void timeout_t(void *); /* timeout function type */ 249#define CALLOUT_HANDLE_INITIALIZER(handle) \ 250 { NULL } 251 252void callout_handle_init(struct callout_handle *); 253struct callout_handle timeout(timeout_t *, void *, int); 254void untimeout(timeout_t *, void *, struct callout_handle); 255caddr_t kern_timeout_callwheel_alloc(caddr_t v); 256void kern_timeout_callwheel_init(void); 257 258/* Stubs for obsolete functions that used to be for interrupt management */ 259static __inline void spl0(void) { return; } 260static __inline intrmask_t splbio(void) { return 0; } 261static __inline intrmask_t splcam(void) { return 0; } 262static __inline intrmask_t splclock(void) { return 0; } 263static __inline intrmask_t splhigh(void) { return 0; } 264static __inline intrmask_t splimp(void) { return 0; } 265static __inline intrmask_t splnet(void) { return 0; } 266static __inline intrmask_t splsoftcam(void) { return 0; } 267static __inline intrmask_t splsoftclock(void) { return 0; } 268static __inline intrmask_t splsofttty(void) { return 0; } 269static __inline intrmask_t splsoftvm(void) { return 0; } 270static __inline intrmask_t splsofttq(void) { return 0; } 271static __inline intrmask_t splstatclock(void) { return 0; } 272static __inline intrmask_t spltty(void) { return 0; } 273static __inline intrmask_t splvm(void) { return 0; } 274static __inline void splx(intrmask_t ipl __unused) { return; } 275 276/* 277 * Various callout lists. 278 */ 279 280/* Exit callout list declarations. */ 281typedef void (*exitlist_fn)(struct proc *procp); 282 283int at_exit(exitlist_fn function); 284int rm_at_exit(exitlist_fn function); 285 286/* Fork callout list declarations. */ 287typedef void (*forklist_fn)(struct proc *parent, struct proc *child, int flags); 288 289int at_fork(forklist_fn function); 290int rm_at_fork(forklist_fn function); 291 292/* Exec callout list declarations. */ 293typedef void (*execlist_fn)(struct proc *procp); 294 295int at_exec(execlist_fn function); 296int rm_at_exec(execlist_fn function); 297 298/* 299 * Not exactly a callout LIST, but a callout entry. 300 * Allow an external module to define a hardware watchdog tickler. 301 * Normally a process would do this, but there are times when the 302 * kernel needs to be able to hold off the watchdog, when the process 303 * is not active, e.g., when dumping core. 304 */ 305typedef void (*watchdog_tickle_fn)(void); 306 307extern watchdog_tickle_fn wdog_tickler; 308 309/* 310 * Common `proc' functions are declared here so that proc.h can be included 311 * less often. 312 */ 313int msleep(void *chan, struct mtx *mtx, int pri, const char *wmesg, 314 int timo); 315void abortsleep(struct thread *td); 316#define tsleep(chan, pri, wmesg, timo) msleep(chan, NULL, pri, wmesg, timo) 317void wakeup(void *chan); 318void wakeup_one(void *chan); 319 320/* 321 * Common `dev_t' stuff are declared here to avoid #include poisoning 322 */ 323 324int major(dev_t x); 325int minor(dev_t x); 326dev_t makedev(int x, int y); 327udev_t dev2udev(dev_t x); 328dev_t udev2dev(udev_t x, int b); 329int uminor(udev_t dev); 330int umajor(udev_t dev); 331udev_t makeudev(int x, int y); 332 333/* XXX: Should be void nanodelay(u_int nsec); */ 334void DELAY(int usec); 335 336#endif /* !_SYS_SYSTM_H_ */ 337