systm.h revision 138509
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 * 4. Neither the name of the University nor the names of its contributors 19 * may be used to endorse or promote products derived from this software 20 * without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 * 34 * @(#)systm.h 8.7 (Berkeley) 3/29/95 35 * $FreeBSD: head/sys/sys/systm.h 138509 2004-12-07 08:15:41Z phk $ 36 */ 37 38#ifndef _SYS_SYSTM_H_ 39#define _SYS_SYSTM_H_ 40 41#include <machine/atomic.h> 42#include <machine/cpufunc.h> 43#include <sys/callout.h> 44#include <sys/cdefs.h> 45#include <sys/queue.h> 46#include <sys/stdint.h> /* for people using printf mainly */ 47 48extern int securelevel; /* system security level (see init(8)) */ 49extern int suser_enabled; /* suser() is permitted to return 0 */ 50 51extern int cold; /* nonzero if we are doing a cold boot */ 52extern const char *panicstr; /* panic message */ 53extern char version[]; /* system version */ 54extern char copyright[]; /* system copyright */ 55extern int kstack_pages; /* number of kernel stack pages */ 56 57extern int nswap; /* size of swap space */ 58 59extern u_int nselcoll; /* select collisions since boot */ 60extern struct mtx sellock; /* select lock variable */ 61extern struct cv selwait; /* select conditional variable */ 62 63extern long physmem; /* physical memory */ 64 65extern char *rootdevnames[2]; /* names of possible root devices */ 66 67extern int boothowto; /* reboot flags, from console subsystem */ 68extern int bootverbose; /* nonzero to print verbose messages */ 69 70extern int maxusers; /* system tune hint */ 71 72#ifdef INVARIANTS /* The option is always available */ 73#define KASSERT(exp,msg) do { \ 74 if (__predict_false(!(exp))) \ 75 panic msg; \ 76} while (0) 77#else 78#define KASSERT(exp,msg) 79#endif 80 81#ifndef CTASSERT /* Allow lint to override */ 82#define CTASSERT(x) _CTASSERT(x, __LINE__) 83#define _CTASSERT(x, y) __CTASSERT(x, y) 84#define __CTASSERT(x, y) typedef char __assert ## y[(x) ? 1 : -1] 85#endif 86 87/* 88 * XXX the hints declarations are even more misplaced than most declarations 89 * in this file, since they are needed in one file (per arch) and only used 90 * in two files. 91 * XXX most of these variables should be const. 92 */ 93extern int envmode; 94extern int hintmode; /* 0 = off. 1 = config, 2 = fallback */ 95extern int dynamic_kenv; 96extern struct sx kenv_lock; 97extern char *kern_envp; 98extern char static_env[]; 99extern char static_hints[]; /* by config for now */ 100 101extern char **kenvp; 102 103/* 104 * General function declarations. 105 */ 106 107struct clockframe; 108struct malloc_type; 109struct mtx; 110struct proc; 111struct kse; 112struct socket; 113struct thread; 114struct tty; 115struct ucred; 116struct uio; 117struct _jmp_buf; 118 119int setjmp(struct _jmp_buf *); 120void longjmp(struct _jmp_buf *, int) __dead2; 121int dumpstatus(vm_offset_t addr, off_t count); 122int nullop(void); 123int eopnotsupp(void); 124int ureadc(int, struct uio *); 125void hashdestroy(void *, struct malloc_type *, u_long); 126void *hashinit(int count, struct malloc_type *type, u_long *hashmask); 127void *phashinit(int count, struct malloc_type *type, u_long *nentries); 128void g_waitidle(void); 129 130#ifdef RESTARTABLE_PANICS 131void panic(const char *, ...) __printflike(1, 2); 132#else 133void panic(const char *, ...) __dead2 __printflike(1, 2); 134#endif 135 136void cpu_boot(int); 137void cpu_rootconf(void); 138extern uint32_t crc32_tab[]; 139uint32_t crc32(const void *buf, size_t size); 140void critical_enter(void); 141void critical_exit(void); 142void init_param1(void); 143void init_param2(long physpages); 144void init_param3(long kmempages); 145void tablefull(const char *); 146int kvprintf(char const *, void (*)(int, void*), void *, int, 147 __va_list) __printflike(1, 0); 148void log(int, const char *, ...) __printflike(2, 3); 149void log_console(struct uio *); 150int printf(const char *, ...) __printflike(1, 2); 151int snprintf(char *, size_t, const char *, ...) __printflike(3, 4); 152int sprintf(char *buf, const char *, ...) __printflike(2, 3); 153int uprintf(const char *, ...) __printflike(1, 2); 154int vprintf(const char *, __va_list) __printflike(1, 0); 155int vsnprintf(char *, size_t, const char *, __va_list) __printflike(3, 0); 156int vsnrprintf(char *, size_t, int, const char *, __va_list) __printflike(4, 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 *, ...) __nonnull(1) __nonnull(2); 160int vsscanf(const char *, char const *, __va_list) __nonnull(1) __nonnull(2); 161long strtol(const char *, char **, int) __nonnull(1); 162u_long strtoul(const char *, char **, int) __nonnull(1); 163quad_t strtoq(const char *, char **, int) __nonnull(1); 164u_quad_t strtouq(const char *, char **, int) __nonnull(1); 165void tprintf(struct proc *p, int pri, const char *, ...) __printflike(3, 4); 166void hexdump(void *ptr, int length, const char *hdr, int flags); 167#define HD_COLUMN_MASK 0xff 168#define HD_DELIM_MASK 0xff00 169#define HD_OMIT_COUNT (1 << 16) 170#define HD_OMIT_HEX (1 << 17) 171#define HD_OMIT_CHARS (1 << 18) 172 173#define ovbcopy(f, t, l) bcopy((f), (t), (l)) 174void bcopy(const void *from, void *to, size_t len) __nonnull(1) __nonnull(2); 175void bzero(void *buf, size_t len) __nonnull(1); 176 177void *memcpy(void *to, const void *from, size_t len) __nonnull(1) __nonnull(2); 178 179int copystr(const void * __restrict kfaddr, void * __restrict kdaddr, 180 size_t len, size_t * __restrict lencopied) 181 __nonnull(1) __nonnull(2); 182int copyinstr(const void * __restrict udaddr, void * __restrict kaddr, 183 size_t len, size_t * __restrict lencopied) 184 __nonnull(1) __nonnull(2); 185int copyin(const void * __restrict udaddr, void * __restrict kaddr, 186 size_t len) __nonnull(1) __nonnull(2); 187int copyout(const void * __restrict kaddr, void * __restrict udaddr, 188 size_t len) __nonnull(1) __nonnull(2); 189 190int fubyte(const void *base); 191long fuword(const void *base); 192int fuword16(void *base); 193int32_t fuword32(const void *base); 194int64_t fuword64(const void *base); 195int subyte(void *base, int byte); 196int suword(void *base, long word); 197int suword16(void *base, int word); 198int suword32(void *base, int32_t word); 199int suword64(void *base, int64_t word); 200intptr_t casuptr(intptr_t *p, intptr_t old, intptr_t new); 201 202void realitexpire(void *); 203 204void hardclock(struct clockframe *frame); 205void hardclock_process(struct clockframe *frame); 206void softclock(void *); 207void statclock(struct clockframe *frame); 208void profclock(struct clockframe *frame); 209 210void startprofclock(struct proc *); 211void stopprofclock(struct proc *); 212void cpu_startprofclock(void); 213void cpu_stopprofclock(void); 214 215/* flags for suser() and suser_cred() */ 216#define SUSER_ALLOWJAIL 1 217#define SUSER_RUID 2 218 219int suser(struct thread *td); 220int suser_cred(struct ucred *cred, int flag); 221int cr_cansee(struct ucred *u1, struct ucred *u2); 222int cr_canseesocket(struct ucred *cred, struct socket *so); 223 224char *getenv(const char *name); 225void freeenv(char *env); 226int getenv_int(const char *name, int *data); 227long getenv_long(const char *name, long *data); 228unsigned long getenv_ulong(const char *name, unsigned long *data); 229int getenv_string(const char *name, char *data, int size); 230int getenv_quad(const char *name, quad_t *data); 231int setenv(const char *name, const char *value); 232int unsetenv(const char *name); 233int testenv(const char *name); 234 235#ifdef APM_FIXUP_CALLTODO 236struct timeval; 237void adjust_timeout_calltodo(struct timeval *time_change); 238#endif /* APM_FIXUP_CALLTODO */ 239 240#include <sys/libkern.h> 241 242/* Initialize the world */ 243void consinit(void); 244void cpu_initclocks(void); 245void usrinfoinit(void); 246 247/* Finalize the world. */ 248void shutdown_nice(int); 249 250/* 251 * Kernel to clock driver interface. 252 */ 253void inittodr(time_t base); 254void resettodr(void); 255void startrtclock(void); 256 257/* Timeouts */ 258typedef void timeout_t(void *); /* timeout function type */ 259#define CALLOUT_HANDLE_INITIALIZER(handle) \ 260 { NULL } 261 262void callout_handle_init(struct callout_handle *); 263struct callout_handle timeout(timeout_t *, void *, int); 264void untimeout(timeout_t *, void *, struct callout_handle); 265caddr_t kern_timeout_callwheel_alloc(caddr_t v); 266void kern_timeout_callwheel_init(void); 267 268/* Stubs for obsolete functions that used to be for interrupt management */ 269static __inline void spl0(void) { return; } 270static __inline intrmask_t splbio(void) { return 0; } 271static __inline intrmask_t splcam(void) { return 0; } 272static __inline intrmask_t splclock(void) { return 0; } 273static __inline intrmask_t splhigh(void) { return 0; } 274static __inline intrmask_t splimp(void) { return 0; } 275static __inline intrmask_t splnet(void) { return 0; } 276static __inline intrmask_t splsoftcam(void) { return 0; } 277static __inline intrmask_t splsoftclock(void) { return 0; } 278static __inline intrmask_t splsofttty(void) { return 0; } 279static __inline intrmask_t splsoftvm(void) { return 0; } 280static __inline intrmask_t splsofttq(void) { return 0; } 281static __inline intrmask_t splstatclock(void) { return 0; } 282static __inline intrmask_t spltty(void) { return 0; } 283static __inline intrmask_t splvm(void) { return 0; } 284static __inline void splx(intrmask_t ipl __unused) { return; } 285 286/* 287 * Common `proc' functions are declared here so that proc.h can be included 288 * less often. 289 */ 290int msleep(void *chan, struct mtx *mtx, int pri, const char *wmesg, 291 int timo); 292#define tsleep(chan, pri, wmesg, timo) msleep(chan, NULL, pri, wmesg, timo) 293void wakeup(void *chan) __nonnull(1); 294void wakeup_one(void *chan) __nonnull(1); 295 296/* 297 * Common `struct cdev *' stuff are declared here to avoid #include poisoning 298 */ 299 300struct cdev; 301int major(struct cdev *x); 302int minor(struct cdev *x); 303dev_t dev2udev(struct cdev *x); 304struct cdev *findcdev(dev_t x); 305int uminor(dev_t dev); 306int umajor(dev_t dev); 307 308/* XXX: Should be void nanodelay(u_int nsec); */ 309void DELAY(int usec); 310 311/* 312 * Unit number allocation API. (kern/subr_unit.c) 313 */ 314struct unrhdr; 315struct unrhdr *new_unrhdr(u_int low, u_int high); 316void delete_unrhdr(struct unrhdr *uh); 317u_int alloc_unr(struct unrhdr *uh); 318void free_unr(struct unrhdr *uh, u_int item); 319 320#endif /* !_SYS_SYSTM_H_ */ 321