1 /** $MirOS: src/sys/sys/systm.h,v 1.9 2013/10/31 20:07:00 tg Exp $ */ 2 /* $OpenBSD: systm.h,v 1.60 2004/01/05 00:16:56 espie Exp $ */ 3 /* $NetBSD: systm.h,v 1.50 1996/06/09 04:55:09 briggs Exp $ */ 4 5 /*- 6 * Copyright © 2013 7 * Thorsten “mirabilos” Glaser <tg@mirbsd.org> 8 * Copyright (c) 1982, 1988, 1991, 1993 9 * The Regents of the University of California. All rights reserved. 10 * (c) UNIX System Laboratories, Inc. 11 * All or some portions of this file are derived from material licensed 12 * to the University of California by American Telephone and Telegraph 13 * Co. or Unix System Laboratories, Inc. and are reproduced herein with 14 * the permission of UNIX System Laboratories, Inc. 15 * 16 * Redistribution and use in source and binary forms, with or without 17 * modification, are permitted provided that the following conditions 18 * are met: 19 * 1. Redistributions of source code must retain the above copyright 20 * notice, this list of conditions and the following disclaimer. 21 * 2. Redistributions in binary form must reproduce the above copyright 22 * notice, this list of conditions and the following disclaimer in the 23 * documentation and/or other materials provided with the distribution. 24 * 3. Neither the name of the University nor the names of its contributors 25 * may be used to endorse or promote products derived from this software 26 * without specific prior written permission. 27 * 28 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 29 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 31 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 32 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 37 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 38 * SUCH DAMAGE. 39 * 40 * @(#)systm.h 8.4 (Berkeley) 2/23/94 41 */ 42 43 #ifndef __SYSTM_H__ 44 #define __SYSTM_H__ 45 46 #include <sys/queue.h> 47 #include <sys/slibkern.h> 48 #include <sys/stdarg.h> 49 50 /* 51 * The `securelevel' variable controls the security level of the system. 52 * It can only be decreased by process 1 (/sbin/init). 53 * 54 * Security levels are as follows: 55 * -1 permanently insecure mode - always run system in level 0 mode. 56 * 0 insecure mode - immutable and append-only flags make be turned off. 57 * All devices may be read or written subject to permission modes. 58 * 1 secure mode - immutable and append-only flags may not be changed; 59 * raw disks of mounted filesystems, /dev/mem, and /dev/kmem are 60 * read-only. 61 * 2 highly secure mode - same as (1) plus raw disks are always 62 * read-only whether mounted or not. This level precludes tampering 63 * with filesystems by unmounting them, but also inhibits running 64 * newfs while the system is secured. 65 * 66 * In normal operation, the system runs in level 0 mode while single user 67 * and in level 1 mode while multiuser. If level 2 mode is desired while 68 * running multiuser, it can be set in the multiuser startup script 69 * (/etc/rc.local) using sysctl(1). If it is desired to run the system 70 * in level 0 mode while multiuser, initialize the variable securelevel 71 * in /sys/kern/kern_sysctl.c to -1. Note that it is NOT initialized to 72 * zero as that would allow the vmunix binary to be patched to -1. 73 * Without initialization, securelevel loads in the BSS area which only 74 * comes into existence when the kernel is loaded and hence cannot be 75 * patched by a stalking hacker. 76 */ 77 extern int securelevel; /* system security level */ 78 extern const char *panicstr; /* panic message */ 79 extern void (*panic_hook)(void); /* for resetting video */ 80 extern const char version[]; /* system version */ 81 extern const char copyright[]; /* system copyright */ 82 extern const char ostype[]; 83 extern const char osversion[]; 84 extern const char ospatchlevel[]; 85 extern const char osrelease[]; 86 extern int cold; /* cold start flag initialized in locore */ 87 88 extern int nblkdev; /* number of entries in bdevsw */ 89 extern int nchrdev; /* number of entries in cdevsw */ 90 91 extern int selwait; /* select timeout address */ 92 93 extern u_char curpriority; /* priority of current process */ 94 95 extern int maxmem; /* max memory per process */ 96 extern int physmem; /* physical memory */ 97 98 extern dev_t dumpdev; /* dump device */ 99 extern long dumplo; /* offset into dumpdev */ 100 101 extern dev_t rootdev; /* root device */ 102 extern struct vnode *rootvp; /* vnode equivalent to above */ 103 104 extern dev_t swapdev; /* swapping device */ 105 extern struct vnode *swapdev_vp;/* vnode equivalent to above */ 106 107 struct proc; 108 109 typedef int sy_call_t(struct proc *, void *, register_t *); 110 111 extern struct sysent { /* system call table */ 112 short sy_narg; /* number of args */ 113 short sy_argsize; /* total size of arguments */ 114 sy_call_t *sy_call; /* implementing function */ 115 } sysent[]; 116 #if BYTE_ORDER == BIG_ENDIAN 117 #define SCARG(p, k) ((p)->k.be.datum) /* get arg from args pointer */ 118 #elif BYTE_ORDER == LITTLE_ENDIAN 119 #define SCARG(p, k) ((p)->k.le.datum) /* get arg from args pointer */ 120 #else 121 #error "what byte order is this machine?" 122 #endif 123 124 #if defined(_KERNEL) && defined(SYSCALL_DEBUG) 125 void scdebug_call(struct proc *p, register_t code, register_t retval[]); 126 void scdebug_ret(struct proc *p, register_t code, int error, register_t retval[]); 127 #endif /* _KERNEL && SYSCALL_DEBUG */ 128 129 extern int boothowto; /* reboot flags, from console subsystem */ 130 131 extern void (*v_putc)(int); /* Virtual console putc routine */ 132 133 extern void _insque(void *, void *); 134 extern void _remque(void *); 135 136 /* casts to keep lint happy, but it should be happy with void * */ 137 #define insque(q,p) _insque(q, p) 138 #define remque(q) _remque(q) 139 140 /* 141 * General function declarations. 142 */ 143 int nullop(void *); 144 int enodev(void); 145 int enosys(void); 146 int enoioctl(void); 147 int enxio(void); 148 int eopnotsupp(void *); 149 150 int lkmenodev(void); 151 152 struct vnodeopv_desc; 153 void vfs_opv_init(void); 154 void vfs_opv_init_explicit(struct vnodeopv_desc *); 155 void vfs_opv_init_default(struct vnodeopv_desc *); 156 void vfs_op_init(void); 157 158 int seltrue(dev_t dev, int which, struct proc *); 159 void *hashinit(int, int, int, u_long *); 160 int sys_nosys(struct proc *, void *, register_t *); 161 162 void panic(const char *, ...) 163 __attribute__((__noreturn__,__format__(__kprintf__, 1, 2))); 164 void __assert(const char *, const char *, int, const char *) 165 __attribute__((__noreturn__)); 166 int printf(const char *, ...) 167 __attribute__((__format__(__kprintf__, 1, 2))); 168 void uprintf(const char *, ...) 169 __attribute__((__format__(__kprintf__, 1, 2))); 170 int vprintf(const char *, va_list); 171 int vsprintf(char *, const char *, va_list); 172 int sprintf(char *buf, const char *, ...) 173 __attribute__((__format__(__kprintf__, 2, 3))); 174 int vsnprintf(char *, size_t, const char *, va_list); 175 int snprintf(char *buf, size_t, const char *, ...) 176 __attribute__((__format__(__kprintf__, 3, 4))); 177 struct tty; 178 void ttyprintf(struct tty *, const char *, ...) 179 __attribute__((__format__(__kprintf__, 2, 3))); 180 181 void splassert_fail(int, int, const char *); 182 extern int splassert_ctl; 183 184 void tablefull(const char *); 185 186 int kcopy(const void *, void *, size_t); 187 #ifdef __i386__ 188 #define ovbcopy bcopy 189 #else 190 void ovbcopy(const void *, void *, size_t); 191 #endif 192 193 int copystr(const void *, void *, size_t, size_t *); 194 int copyinstr(const void *, void *, size_t, size_t *); 195 int copyoutstr(const void *, void *, size_t, size_t *); 196 int copyin(const void *, void *, size_t); 197 int copyout(const void *, void *, size_t); 198 199 struct timeval; 200 int hzto(struct timeval *); 201 int tvtohz(struct timeval *); 202 void realitexpire(void *); 203 204 struct clockframe; 205 void hardclock(struct clockframe *); 206 void softclock(void); 207 void statclock(struct clockframe *); 208 209 void initclocks(void); 210 void inittodr(time_t); 211 void resettodr(void); 212 void cpu_initclocks(void); 213 214 void startprofclock(struct proc *); 215 void stopprofclock(struct proc *); 216 void setstatclockrate(int); 217 218 void wdog_register(void *, int (*)(void *, int)); 219 220 /* 221 * Startup/shutdown hooks. Startup hooks are functions running after 222 * the scheduler has started but before any threads have been created 223 * or root has been mounted The shutdown hooks are functions to be run 224 * with all interrupts disabled immediately before the system is 225 * halted or rebooted. 226 */ 227 228 struct hook_desc { 229 TAILQ_ENTRY(hook_desc) hd_list; 230 void (*hd_fn)(void *); 231 void *hd_arg; 232 }; 233 TAILQ_HEAD(hook_desc_head, hook_desc); 234 235 extern struct hook_desc_head shutdownhook_list, startuphook_list; 236 237 void *hook_establish(struct hook_desc_head *, int, void (*)(void *), void *); 238 void hook_disestablish(struct hook_desc_head *, void *); 239 void dohooks(struct hook_desc_head *, int); 240 241 #define HOOK_REMOVE 0x01 242 #define HOOK_FREE 0x02 243 244 #define startuphook_establish(fn, arg) \ 245 hook_establish(&startuphook_list, 1, (fn), (arg)) 246 #define startuphook_disestablish(vhook) \ 247 hook_disestablish(&startuphook_list, (vhook)) 248 #define dostartuphooks() dohooks(&startuphook_list, HOOK_REMOVE|HOOK_FREE) 249 250 #define shutdownhook_establish(fn, arg) \ 251 hook_establish(&shutdownhook_list, 0, (fn), (arg)) 252 #define shutdownhook_disestablish(vhook) \ 253 hook_disestablish(&shutdownhook_list, (vhook)) 254 #define doshutdownhooks() dohooks(&shutdownhook_list, HOOK_REMOVE) 255 256 /* 257 * Power management hooks. 258 */ 259 void *powerhook_establish(void (*)(int, void *), void *); 260 void powerhook_disestablish(void *); 261 void dopowerhooks(int); 262 #define PWR_RESUME 0 263 #define PWR_SUSPEND 1 264 #define PWR_STANDBY 2 265 266 struct uio; 267 int uiomove(void *, int, struct uio *); 268 269 int setjmp(label_t *); 270 void longjmp(label_t *); 271 272 void consinit(void); 273 274 void cpu_startup(void); 275 void cpu_configure(void); 276 extern void (*md_diskconf)(void); 277 278 279 int nfs_mountroot(void); 280 int dk_mountroot(void); 281 extern int (*mountroot)(void); 282 283 #if defined(DDB) || defined(KGDB) 284 /* debugger entry points */ 285 void Debugger(void); /* in DDB only */ 286 int read_symtab_from_file(struct proc *,struct vnode *,const char *); 287 #endif 288 289 #ifdef BOOT_CONFIG 290 void user_config(void); 291 #endif 292 293 #endif /* __SYSTM_H__ */ 294