FreeBSD/Linux Kernel Cross Reference
sys/sys/systm.h
1 /* $NetBSD: systm.h,v 1.228.4.2 2009/03/15 19:43:48 snj Exp $ */
2
3 /*-
4 * Copyright (c) 1982, 1988, 1991, 1993
5 * The Regents of the University of California. All rights reserved.
6 * (c) UNIX System Laboratories, Inc.
7 * All or some portions of this file are derived from material licensed
8 * to the University of California by American Telephone and Telegraph
9 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
10 * the permission of UNIX System Laboratories, Inc.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 * @(#)systm.h 8.7 (Berkeley) 3/29/95
37 */
38
39 #ifndef _SYS_SYSTM_H_
40 #define _SYS_SYSTM_H_
41
42 #if defined(_KERNEL_OPT)
43 #include "opt_ddb.h"
44 #include "opt_multiprocessor.h"
45 #endif
46
47 #include <machine/endian.h>
48
49 #ifdef _KERNEL
50 #include <sys/types.h>
51 #endif
52
53 struct clockframe;
54 struct device;
55 struct lwp;
56 struct proc;
57 struct timeval;
58 struct tty;
59 struct uio;
60 struct vnode;
61 struct vmspace;
62 struct vm_map;
63
64 extern const char *panicstr; /* panic message */
65 extern int doing_shutdown; /* shutting down */
66
67 extern const char copyright[]; /* system copyright */
68 extern char cpu_model[]; /* machine/cpu model name */
69 extern char machine[]; /* machine type */
70 extern char machine_arch[]; /* machine architecture */
71 extern const char osrelease[]; /* short system version */
72 extern const char ostype[]; /* system type */
73 extern const char kernel_ident[];/* kernel configuration ID */
74 extern const char version[]; /* system version */
75
76 extern int autonicetime; /* time (in seconds) before autoniceval */
77 extern int autoniceval; /* proc priority after autonicetime */
78
79 extern int selwait; /* select timeout address */
80
81 extern int maxmem; /* max memory per process */
82 extern int physmem; /* physical memory */
83
84 extern dev_t dumpdev; /* dump device */
85 extern dev_t dumpcdev; /* dump device (character equivalent) */
86 extern long dumplo; /* offset into dumpdev */
87 extern int dumpsize; /* size of dump in pages */
88 extern const char *dumpspec; /* how dump device was specified */
89
90 extern dev_t rootdev; /* root device */
91 extern struct vnode *rootvp; /* vnode equivalent to above */
92 extern struct device *root_device; /* device equivalent to above */
93 extern const char *rootspec; /* how root device was specified */
94
95 extern int ncpu; /* number of CPUs configured */
96 extern int ncpuonline; /* number of CPUs online */
97 #if defined(_KERNEL)
98 extern bool mp_online; /* secondary processors are started */
99 #endif /* defined(_KERNEL) */
100
101 extern const char hexdigits[]; /* "0123456789abcdef" in subr_prf2.c */
102 extern const char HEXDIGITS[]; /* "0123456789ABCDEF" in subr_prf2.c */
103
104 /*
105 * These represent the swap pseudo-device (`sw'). This device
106 * is used by the swap pager to indirect through the routines
107 * in sys/vm/vm_swap.c.
108 */
109 extern const dev_t swapdev; /* swapping device */
110 extern struct vnode *swapdev_vp;/* vnode equivalent to above */
111
112 extern const dev_t zerodev; /* /dev/zero */
113
114 typedef int sy_call_t(struct lwp *, const void *, register_t *);
115
116 extern struct sysent { /* system call table */
117 short sy_narg; /* number of args */
118 short sy_argsize; /* total size of arguments */
119 int sy_flags; /* flags. see below */
120 sy_call_t *sy_call; /* implementing function */
121 } sysent[];
122 extern int nsysent;
123 #if BYTE_ORDER == BIG_ENDIAN
124 #define SCARG(p,k) ((p)->k.be.datum) /* get arg from args pointer */
125 #elif BYTE_ORDER == LITTLE_ENDIAN
126 #define SCARG(p,k) ((p)->k.le.datum) /* get arg from args pointer */
127 #else
128 #error "what byte order is this machine?"
129 #endif
130
131 #define SYCALL_INDIRECT 0x0002 /* indirect (ie syscall() or __syscall()) */
132
133 extern int boothowto; /* reboot flags, from console subsystem */
134 #define bootverbose (boothowto & AB_VERBOSE)
135 #define bootquiet (boothowto & AB_QUIET)
136
137 extern void (*v_putc)(int); /* Virtual console putc routine */
138
139 /*
140 * General function declarations.
141 */
142 int nullop(void *);
143 int enodev(void);
144 int enosys(void);
145 int enoioctl(void);
146 int enxio(void);
147 int eopnotsupp(void);
148
149 enum hashtype {
150 HASH_LIST,
151 HASH_SLIST,
152 HASH_TAILQ
153 };
154
155 #ifdef _KERNEL
156 void *hashinit(u_int, enum hashtype, bool, u_long *);
157 void hashdone(void *, enum hashtype, u_long);
158 int seltrue(dev_t, int, struct lwp *);
159 int sys_nosys(struct lwp *, const void *, register_t *);
160
161 void aprint_normal(const char *, ...)
162 __attribute__((__format__(__printf__,1,2)));
163 void aprint_error(const char *, ...)
164 __attribute__((__format__(__printf__,1,2)));
165 void aprint_naive(const char *, ...)
166 __attribute__((__format__(__printf__,1,2)));
167 void aprint_verbose(const char *, ...)
168 __attribute__((__format__(__printf__,1,2)));
169 void aprint_debug(const char *, ...)
170 __attribute__((__format__(__printf__,1,2)));
171
172 struct device;
173
174 void aprint_normal_dev(struct device *, const char *, ...)
175 __attribute__((__format__(__printf__,2,3)));
176 void aprint_error_dev(struct device *, const char *, ...)
177 __attribute__((__format__(__printf__,2,3)));
178 void aprint_naive_dev(struct device *, const char *, ...)
179 __attribute__((__format__(__printf__,2,3)));
180 void aprint_verbose_dev(struct device *, const char *, ...)
181 __attribute__((__format__(__printf__,2,3)));
182 void aprint_debug_dev(struct device *, const char *, ...)
183 __attribute__((__format__(__printf__,2,3)));
184
185 struct ifnet;
186
187 void aprint_normal_ifnet(struct ifnet *, const char *, ...)
188 __attribute__((__format__(__printf__,2,3)));
189 void aprint_error_ifnet(struct ifnet *, const char *, ...)
190 __attribute__((__format__(__printf__,2,3)));
191 void aprint_naive_ifnet(struct ifnet *, const char *, ...)
192 __attribute__((__format__(__printf__,2,3)));
193 void aprint_verbose_ifnet(struct ifnet *, const char *, ...)
194 __attribute__((__format__(__printf__,2,3)));
195 void aprint_debug_ifnet(struct ifnet *, const char *, ...)
196 __attribute__((__format__(__printf__,2,3)));
197
198 int aprint_get_error_count(void);
199
200 void printf_tolog(const char *, ...)
201 __attribute__((__format__(__printf__,1,2)));
202
203 void printf_nolog(const char *, ...)
204 __attribute__((__format__(__printf__,1,2)));
205
206 void printf(const char *, ...)
207 __attribute__((__format__(__printf__,1,2)));
208 int sprintf(char *, const char *, ...)
209 __attribute__((__format__(__printf__,2,3)));
210 int snprintf(char *, size_t, const char *, ...)
211 __attribute__((__format__(__printf__,3,4)));
212 void vprintf(const char *, _BSD_VA_LIST_);
213 int vsprintf(char *, const char *, _BSD_VA_LIST_);
214 int vsnprintf(char *, size_t, const char *, _BSD_VA_LIST_);
215 int humanize_number(char *, size_t, uint64_t, const char *, int);
216
217 void twiddle(void);
218 #endif /* _KERNEL */
219
220 void panic(const char *, ...)
221 __dead __attribute__((__format__(__printf__,1,2)));
222 void uprintf(const char *, ...)
223 __attribute__((__format__(__printf__,1,2)));
224 void uprintf_locked(const char *, ...)
225 __attribute__((__format__(__printf__,1,2)));
226 void ttyprintf(struct tty *, const char *, ...)
227 __attribute__((__format__(__printf__,2,3)));
228
229 char *bitmask_snprintf(u_quad_t, const char *, char *, size_t);
230
231 int format_bytes(char *, size_t, uint64_t);
232
233 void tablefull(const char *, const char *);
234
235 int kcopy(const void *, void *, size_t);
236
237 #ifdef _KERNEL
238 #define bcopy(src, dst, len) memcpy((dst), (src), (len))
239 #define bzero(src, len) memset((src), 0, (len))
240 #define bcmp(a, b, len) memcmp((a), (b), (len))
241 #endif /* KERNEL */
242
243 int copystr(const void *, void *, size_t, size_t *);
244 int copyinstr(const void *, void *, size_t, size_t *);
245 int copyoutstr(const void *, void *, size_t, size_t *);
246 int copyin(const void *, void *, size_t);
247 int copyout(const void *, void *, size_t);
248
249 #ifdef _KERNEL
250 typedef int (*copyin_t)(const void *, void *, size_t);
251 typedef int (*copyout_t)(const void *, void *, size_t);
252 #endif
253
254 int copyin_proc(struct proc *, const void *, void *, size_t);
255 int copyout_proc(struct proc *, const void *, void *, size_t);
256 int copyin_vmspace(struct vmspace *, const void *, void *, size_t);
257 int copyout_vmspace(struct vmspace *, const void *, void *, size_t);
258
259 int ioctl_copyin(int ioctlflags, const void *src, void *dst, size_t len);
260 int ioctl_copyout(int ioctlflags, const void *src, void *dst, size_t len);
261
262 int ucas_ptr(volatile void *, void *, void *, void *);
263 int ucas_int(volatile int *, int, int, int *);
264
265 int subyte(void *, int);
266 int suibyte(void *, int);
267 int susword(void *, short);
268 int suisword(void *, short);
269 int suswintr(void *, short);
270 int suword(void *, long);
271 int suiword(void *, long);
272
273 int fubyte(const void *);
274 int fuibyte(const void *);
275 int fusword(const void *);
276 int fuisword(const void *);
277 int fuswintr(const void *);
278 long fuword(const void *);
279 long fuiword(const void *);
280
281 void hardclock(struct clockframe *);
282 void softclock(void *);
283 void statclock(struct clockframe *);
284
285 #ifdef NTP
286 void ntp_init(void);
287 #ifdef PPS_SYNC
288 void hardpps(struct timespec *, long);
289 #endif /* PPS_SYNC */
290 #else
291 void ntp_init(void); /* also provides adjtime() functionality */
292 #endif /* NTP */
293
294 void ssp_init(void);
295
296 void initclocks(void);
297 void inittodr(time_t);
298 void resettodr(void);
299 void cpu_initclocks(void);
300 void setrootfstime(time_t);
301
302 void startprofclock(struct proc *);
303 void stopprofclock(struct proc *);
304 void proftick(struct clockframe *);
305 void setstatclockrate(int);
306
307 /*
308 * Shutdown hooks. Functions to be run with all interrupts disabled
309 * immediately before the system is halted or rebooted.
310 */
311 void *shutdownhook_establish(void (*)(void *), void *);
312 void shutdownhook_disestablish(void *);
313 void doshutdownhooks(void);
314
315 /*
316 * Power management hooks.
317 */
318 void *powerhook_establish(const char *, void (*)(int, void *), void *);
319 void powerhook_disestablish(void *);
320 void dopowerhooks(int);
321 #define PWR_RESUME 0
322 #define PWR_SUSPEND 1
323 #define PWR_STANDBY 2
324 #define PWR_SOFTRESUME 3
325 #define PWR_SOFTSUSPEND 4
326 #define PWR_SOFTSTANDBY 5
327 #define PWR_NAMES \
328 "resume", /* 0 */ \
329 "suspend", /* 1 */ \
330 "standby", /* 2 */ \
331 "softresume", /* 3 */ \
332 "softsuspend", /* 4 */ \
333 "softstandby" /* 5 */
334
335 /*
336 * Mountroot hooks (and mountroot declaration). Device drivers establish
337 * these to be executed just before (*mountroot)() if the passed device is
338 * selected as the root device.
339 */
340 extern int (*mountroot)(void);
341 void *mountroothook_establish(void (*)(struct device *), struct device *);
342 void mountroothook_disestablish(void *);
343 void mountroothook_destroy(void);
344 void domountroothook(void);
345
346 /*
347 * Exec hooks. Subsystems may want to do cleanup when a process
348 * execs.
349 */
350 void *exechook_establish(void (*)(struct proc *, void *), void *);
351 void exechook_disestablish(void *);
352 void doexechooks(struct proc *);
353
354 /*
355 * Exit hooks. Subsystems may want to do cleanup when a process exits.
356 */
357 void *exithook_establish(void (*)(struct proc *, void *), void *);
358 void exithook_disestablish(void *);
359 void doexithooks(struct proc *);
360
361 /*
362 * Fork hooks. Subsystems may want to do special processing when a process
363 * forks.
364 */
365 void *forkhook_establish(void (*)(struct proc *, struct proc *));
366 void forkhook_disestablish(void *);
367 void doforkhooks(struct proc *, struct proc *);
368
369 /*
370 * kernel syscall tracing/debugging hooks.
371 */
372 #ifdef _KERNEL
373 bool trace_is_enabled(struct proc *);
374 int trace_enter(register_t, const register_t *, int);
375 void trace_exit(register_t, register_t [], int);
376 #endif
377
378 int uiomove(void *, size_t, struct uio *);
379 int uiomove_frombuf(void *, size_t, struct uio *);
380
381 #ifdef _KERNEL
382 int setjmp(label_t *);
383 void longjmp(label_t *) __dead;
384 #endif
385
386 void consinit(void);
387
388 void cpu_startup(void);
389 void cpu_configure(void);
390 void cpu_rootconf(void);
391 void cpu_dumpconf(void);
392
393 #ifdef GPROF
394 void kmstartup(void);
395 #endif
396
397 #ifdef _KERNEL
398 #include <lib/libkern/libkern.h>
399
400 /*
401 * Stuff to handle debugger magic key sequences.
402 */
403 #define CNS_LEN 128
404 #define CNS_MAGIC_VAL(x) ((x)&0x1ff)
405 #define CNS_MAGIC_NEXT(x) (((x)>>9)&0x7f)
406 #define CNS_TERM 0x7f /* End of sequence */
407
408 typedef struct cnm_state {
409 int cnm_state;
410 u_short *cnm_magic;
411 } cnm_state_t;
412
413 /* Override db_console() in MD headers */
414 #ifndef cn_trap
415 #define cn_trap() console_debugger()
416 #endif
417 #ifndef cn_isconsole
418 #define cn_isconsole(d) (cn_tab != NULL && (d) == cn_tab->cn_dev)
419 #endif
420
421 void cn_init_magic(cnm_state_t *);
422 void cn_destroy_magic(cnm_state_t *);
423 int cn_set_magic(const char *);
424 int cn_get_magic(char *, size_t);
425 /* This should be called for each byte read */
426 #ifndef cn_check_magic
427 #define cn_check_magic(d, k, s) \
428 do { \
429 if (cn_isconsole(d)) { \
430 int _v = (s).cnm_magic[(s).cnm_state]; \
431 if ((k) == CNS_MAGIC_VAL(_v)) { \
432 (s).cnm_state = CNS_MAGIC_NEXT(_v); \
433 if ((s).cnm_state == CNS_TERM) { \
434 cn_trap(); \
435 (s).cnm_state = 0; \
436 } \
437 } else { \
438 (s).cnm_state = 0; \
439 } \
440 } \
441 } while (/* CONSTCOND */ 0)
442 #endif
443
444 /* Encode out-of-band events this way when passing to cn_check_magic() */
445 #define CNC_BREAK 0x100
446
447 #if defined(DDB) || defined(sun3) || defined(sun2)
448 /* note that cpu_Debugger() is always available on sun[23] */
449 void cpu_Debugger(void);
450 #define Debugger cpu_Debugger
451 #endif
452
453 #ifdef DDB
454 /*
455 * Enter debugger(s) from console attention if enabled
456 */
457 extern int db_fromconsole; /* XXX ddb/ddbvar.h */
458 #define console_debugger() if (db_fromconsole) Debugger()
459 #elif defined(Debugger)
460 #define console_debugger() Debugger()
461 #else
462 #define console_debugger() do {} while (/* CONSTCOND */ 0) /* NOP */
463 #endif
464 #endif /* _KERNEL */
465
466 /* For SYSCALL_DEBUG */
467 void scdebug_call(register_t, const register_t[]);
468 void scdebug_ret(register_t, int, const register_t[]);
469
470 void kernel_lock_init(void);
471 void _kernel_lock(int);
472 void _kernel_unlock(int, int *);
473
474 #if defined(MULTIPROCESSOR) || defined(_LKM)
475 #define KERNEL_LOCK(count, lwp) \
476 do { \
477 if ((count) != 0) \
478 _kernel_lock((count)); \
479 } while (/* CONSTCOND */ 0)
480 #define KERNEL_UNLOCK(all, lwp, p) _kernel_unlock((all), (p))
481 #else
482 #define KERNEL_LOCK(count, lwp) do {(void)(count); (void)(lwp);} while (/* CONSTCOND */ 0) /*NOP*/
483 #define KERNEL_UNLOCK(all, lwp, ptr) do {(void)(all); (void)(lwp); (void)(ptr);} while (/* CONSTCOND */ 0) /*NOP*/
484 #endif
485
486 #define KERNEL_UNLOCK_LAST(l) KERNEL_UNLOCK(-1, (l), NULL)
487 #define KERNEL_UNLOCK_ALL(l, p) KERNEL_UNLOCK(0, (l), (p))
488 #define KERNEL_UNLOCK_ONE(l) KERNEL_UNLOCK(1, (l), NULL)
489
490 /* Preemption control. */
491 #ifdef _KERNEL
492 void kpreempt_disable(void);
493 void kpreempt_enable(void);
494 bool kpreempt_disabled(void);
495 #endif
496
497 void assert_sleepable(void);
498 #if defined(DEBUG)
499 #define ASSERT_SLEEPABLE() assert_sleepable()
500 #else /* defined(DEBUG) */
501 #define ASSERT_SLEEPABLE() /* nothing */
502 #endif /* defined(DEBUG) */
503
504 vaddr_t calc_cache_size(struct vm_map *, int, int);
505
506 #endif /* !_SYS_SYSTM_H_ */
Cache object: 364e82522ee079884cdc689c35617118
|