FreeBSD/Linux Kernel Cross Reference
sys/sys/systm.h
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: releng/6.1/sys/sys/systm.h 158179 2006-04-30 16:44:43Z cvs2svn $
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
48 extern int securelevel; /* system security level (see init(8)) */
49 extern int suser_enabled; /* suser() is permitted to return 0 */
50
51 extern int cold; /* nonzero if we are doing a cold boot */
52 extern int rebooting; /* boot() has been called. */
53 extern const char *panicstr; /* panic message */
54 extern char version[]; /* system version */
55 extern char copyright[]; /* system copyright */
56 extern int kstack_pages; /* number of kernel stack pages */
57
58 extern int nswap; /* size of swap space */
59
60 extern u_int nselcoll; /* select collisions since boot */
61 extern struct mtx sellock; /* select lock variable */
62 extern struct cv selwait; /* select conditional variable */
63
64 extern long physmem; /* physical memory */
65 extern long realmem; /* 'real' memory */
66
67 extern char *rootdevnames[2]; /* names of possible root devices */
68
69 extern int boothowto; /* reboot flags, from console subsystem */
70 extern int bootverbose; /* nonzero to print verbose messages */
71
72 extern int maxusers; /* system tune hint */
73
74 #ifdef INVARIANTS /* The option is always available */
75 #define KASSERT(exp,msg) do { \
76 if (__predict_false(!(exp))) \
77 panic msg; \
78 } while (0)
79 #define VNASSERT(exp, vp, msg) do { \
80 if (__predict_false(!(exp))) { \
81 vn_printf(vp, "VNASSERT failed\n"); \
82 panic msg; \
83 } \
84 } while (0)
85 #else
86 #define KASSERT(exp,msg)
87 #define VNASSERT(exp, vp, msg)
88 #endif
89
90 #ifndef CTASSERT /* Allow lint to override */
91 #define CTASSERT(x) _CTASSERT(x, __LINE__)
92 #define _CTASSERT(x, y) __CTASSERT(x, y)
93 #define __CTASSERT(x, y) typedef char __assert ## y[(x) ? 1 : -1]
94 #endif
95
96 /*
97 * XXX the hints declarations are even more misplaced than most declarations
98 * in this file, since they are needed in one file (per arch) and only used
99 * in two files.
100 * XXX most of these variables should be const.
101 */
102 extern int envmode;
103 extern int hintmode; /* 0 = off. 1 = config, 2 = fallback */
104 extern int dynamic_kenv;
105 extern struct sx kenv_lock;
106 extern char *kern_envp;
107 extern char static_env[];
108 extern char static_hints[]; /* by config for now */
109
110 extern char **kenvp;
111
112 /*
113 * General function declarations.
114 */
115
116 struct clockframe;
117 struct malloc_type;
118 struct mtx;
119 struct proc;
120 struct kse;
121 struct socket;
122 struct thread;
123 struct tty;
124 struct ucred;
125 struct uio;
126 struct _jmp_buf;
127
128 int setjmp(struct _jmp_buf *);
129 void longjmp(struct _jmp_buf *, int) __dead2;
130 int dumpstatus(vm_offset_t addr, off_t count);
131 int nullop(void);
132 int eopnotsupp(void);
133 int ureadc(int, struct uio *);
134 void hashdestroy(void *, struct malloc_type *, u_long);
135 void *hashinit(int count, struct malloc_type *type, u_long *hashmask);
136 void *phashinit(int count, struct malloc_type *type, u_long *nentries);
137 void g_waitidle(void);
138
139 #ifdef RESTARTABLE_PANICS
140 void panic(const char *, ...) __printflike(1, 2);
141 #else
142 void panic(const char *, ...) __dead2 __printflike(1, 2);
143 #endif
144
145 void cpu_boot(int);
146 void cpu_rootconf(void);
147 void critical_enter(void);
148 void critical_exit(void);
149 void init_param1(void);
150 void init_param2(long physpages);
151 void init_param3(long kmempages);
152 void tablefull(const char *);
153 int kvprintf(char const *, void (*)(int, void*), void *, int,
154 __va_list) __printflike(1, 0);
155 void log(int, const char *, ...) __printflike(2, 3);
156 void log_console(struct uio *);
157 int printf(const char *, ...) __printflike(1, 2);
158 int snprintf(char *, size_t, const char *, ...) __printflike(3, 4);
159 int sprintf(char *buf, const char *, ...) __printflike(2, 3);
160 int uprintf(const char *, ...) __printflike(1, 2);
161 int vprintf(const char *, __va_list) __printflike(1, 0);
162 int vsnprintf(char *, size_t, const char *, __va_list) __printflike(3, 0);
163 int vsnrprintf(char *, size_t, int, const char *, __va_list) __printflike(4, 0);
164 int vsprintf(char *buf, const char *, __va_list) __printflike(2, 0);
165 int ttyprintf(struct tty *, const char *, ...) __printflike(2, 3);
166 int sscanf(const char *, char const *, ...) __nonnull(1) __nonnull(2);
167 int vsscanf(const char *, char const *, __va_list) __nonnull(1) __nonnull(2);
168 long strtol(const char *, char **, int) __nonnull(1);
169 u_long strtoul(const char *, char **, int) __nonnull(1);
170 quad_t strtoq(const char *, char **, int) __nonnull(1);
171 u_quad_t strtouq(const char *, char **, int) __nonnull(1);
172 void tprintf(struct proc *p, int pri, const char *, ...) __printflike(3, 4);
173 void hexdump(const void *ptr, int length, const char *hdr, int flags);
174 #define HD_COLUMN_MASK 0xff
175 #define HD_DELIM_MASK 0xff00
176 #define HD_OMIT_COUNT (1 << 16)
177 #define HD_OMIT_HEX (1 << 17)
178 #define HD_OMIT_CHARS (1 << 18)
179
180 #define ovbcopy(f, t, l) bcopy((f), (t), (l))
181 void bcopy(const void *from, void *to, size_t len) __nonnull(1) __nonnull(2);
182 void bzero(void *buf, size_t len) __nonnull(1);
183
184 void *memcpy(void *to, const void *from, size_t len) __nonnull(1) __nonnull(2);
185
186 int copystr(const void * __restrict kfaddr, void * __restrict kdaddr,
187 size_t len, size_t * __restrict lencopied)
188 __nonnull(1) __nonnull(2);
189 int copyinstr(const void * __restrict udaddr, void * __restrict kaddr,
190 size_t len, size_t * __restrict lencopied)
191 __nonnull(1) __nonnull(2);
192 int copyin(const void * __restrict udaddr, void * __restrict kaddr,
193 size_t len) __nonnull(1) __nonnull(2);
194 int copyout(const void * __restrict kaddr, void * __restrict udaddr,
195 size_t len) __nonnull(1) __nonnull(2);
196
197 int fubyte(const void *base);
198 long fuword(const void *base);
199 int fuword16(void *base);
200 int32_t fuword32(const void *base);
201 int64_t fuword64(const void *base);
202 int subyte(void *base, int byte);
203 int suword(void *base, long word);
204 int suword16(void *base, int word);
205 int suword32(void *base, int32_t word);
206 int suword64(void *base, int64_t word);
207 intptr_t casuptr(intptr_t *p, intptr_t old, intptr_t new);
208
209 void realitexpire(void *);
210
211 void hardclock(struct clockframe *frame);
212 void hardclock_process(struct clockframe *frame);
213 void softclock(void *);
214 void statclock(struct clockframe *frame);
215 void profclock(struct clockframe *frame);
216
217 void startprofclock(struct proc *);
218 void stopprofclock(struct proc *);
219 void cpu_startprofclock(void);
220 void cpu_stopprofclock(void);
221
222 /* flags for suser() and suser_cred() */
223 #define SUSER_ALLOWJAIL 1
224 #define SUSER_RUID 2
225
226 int suser(struct thread *td);
227 int suser_cred(struct ucred *cred, int flag);
228 int cr_cansee(struct ucred *u1, struct ucred *u2);
229 int cr_canseesocket(struct ucred *cred, struct socket *so);
230
231 char *getenv(const char *name);
232 void freeenv(char *env);
233 int getenv_int(const char *name, int *data);
234 long getenv_long(const char *name, long *data);
235 unsigned long getenv_ulong(const char *name, unsigned long *data);
236 int getenv_string(const char *name, char *data, int size);
237 int getenv_quad(const char *name, quad_t *data);
238 int setenv(const char *name, const char *value);
239 int unsetenv(const char *name);
240 int testenv(const char *name);
241
242 #ifdef APM_FIXUP_CALLTODO
243 struct timeval;
244 void adjust_timeout_calltodo(struct timeval *time_change);
245 #endif /* APM_FIXUP_CALLTODO */
246
247 #include <sys/libkern.h>
248
249 /* Initialize the world */
250 void consinit(void);
251 void cpu_initclocks(void);
252 void usrinfoinit(void);
253
254 /* Finalize the world. */
255 void shutdown_nice(int);
256
257 /*
258 * Kernel to clock driver interface.
259 */
260 void inittodr(time_t base);
261 void resettodr(void);
262 void startrtclock(void);
263
264 /* Timeouts */
265 typedef void timeout_t(void *); /* timeout function type */
266 #define CALLOUT_HANDLE_INITIALIZER(handle) \
267 { NULL }
268
269 void callout_handle_init(struct callout_handle *);
270 struct callout_handle timeout(timeout_t *, void *, int);
271 void untimeout(timeout_t *, void *, struct callout_handle);
272 caddr_t kern_timeout_callwheel_alloc(caddr_t v);
273 void kern_timeout_callwheel_init(void);
274
275 /* Stubs for obsolete functions that used to be for interrupt management */
276 static __inline void spl0(void) { return; }
277 static __inline intrmask_t splbio(void) { return 0; }
278 static __inline intrmask_t splcam(void) { return 0; }
279 static __inline intrmask_t splclock(void) { return 0; }
280 static __inline intrmask_t splhigh(void) { return 0; }
281 static __inline intrmask_t splimp(void) { return 0; }
282 static __inline intrmask_t splnet(void) { return 0; }
283 static __inline intrmask_t splsoftcam(void) { return 0; }
284 static __inline intrmask_t splsoftclock(void) { return 0; }
285 static __inline intrmask_t splsofttty(void) { return 0; }
286 static __inline intrmask_t splsoftvm(void) { return 0; }
287 static __inline intrmask_t splsofttq(void) { return 0; }
288 static __inline intrmask_t splstatclock(void) { return 0; }
289 static __inline intrmask_t spltty(void) { return 0; }
290 static __inline intrmask_t splvm(void) { return 0; }
291 static __inline void splx(intrmask_t ipl __unused) { return; }
292
293 /*
294 * Common `proc' functions are declared here so that proc.h can be included
295 * less often.
296 */
297 int msleep(void *chan, struct mtx *mtx, int pri, const char *wmesg,
298 int timo);
299 #define tsleep(chan, pri, wmesg, timo) msleep(chan, NULL, pri, wmesg, timo)
300 void wakeup(void *chan) __nonnull(1);
301 void wakeup_one(void *chan) __nonnull(1);
302
303 /*
304 * Common `struct cdev *' stuff are declared here to avoid #include poisoning
305 */
306
307 struct cdev;
308 int minor(struct cdev *x);
309 dev_t dev2udev(struct cdev *x);
310 int uminor(dev_t dev);
311 int umajor(dev_t dev);
312 const char *devtoname(struct cdev *cdev);
313
314 /* XXX: Should be void nanodelay(u_int nsec); */
315 void DELAY(int usec);
316
317 /* Root mount holdback API */
318 struct root_hold_token;
319
320 struct root_hold_token *root_mount_hold(const char *identifier);
321 void root_mount_rel(struct root_hold_token *h);
322
323
324 /*
325 * Unit number allocation API. (kern/subr_unit.c)
326 */
327 struct unrhdr;
328 struct unrhdr *new_unrhdr(int low, int high, struct mtx *mutex);
329 void delete_unrhdr(struct unrhdr *uh);
330 int alloc_unr(struct unrhdr *uh);
331 int alloc_unrl(struct unrhdr *uh);
332 void free_unr(struct unrhdr *uh, u_int item);
333
334 /*
335 * This is about as magic as it gets. fortune(1) has got similar code
336 * for reversing bits in a word. Who thinks up this stuff??
337 *
338 * Yes, it does appear to be consistently faster than:
339 * while (i = ffs(m)) {
340 * m >>= i;
341 * bits++;
342 * }
343 * and
344 * while (lsb = (m & -m)) { // This is magic too
345 * m &= ~lsb; // or: m ^= lsb
346 * bits++;
347 * }
348 * Both of these latter forms do some very strange things on gcc-3.1 with
349 * -mcpu=pentiumpro and/or -march=pentiumpro and/or -O or -O2.
350 * There is probably an SSE or MMX popcnt instruction.
351 *
352 * I wonder if this should be in libkern?
353 *
354 * XXX Stop the presses! Another one:
355 * static __inline u_int32_t
356 * popcnt1(u_int32_t v)
357 * {
358 * v -= ((v >> 1) & 0x55555555);
359 * v = (v & 0x33333333) + ((v >> 2) & 0x33333333);
360 * v = (v + (v >> 4)) & 0x0F0F0F0F;
361 * return (v * 0x01010101) >> 24;
362 * }
363 * The downside is that it has a multiply. With a pentium3 with
364 * -mcpu=pentiumpro and -march=pentiumpro then gcc-3.1 will use
365 * an imull, and in that case it is faster. In most other cases
366 * it appears slightly slower.
367 *
368 * Another variant (also from fortune):
369 * #define BITCOUNT(x) (((BX_(x)+(BX_(x)>>4)) & 0x0F0F0F0F) % 255)
370 * #define BX_(x) ((x) - (((x)>>1)&0x77777777) \
371 * - (((x)>>2)&0x33333333) \
372 * - (((x)>>3)&0x11111111))
373 */
374 static __inline uint32_t
375 bitcount32(uint32_t x)
376 {
377
378 x = (x & 0x55555555) + ((x & 0xaaaaaaaa) >> 1);
379 x = (x & 0x33333333) + ((x & 0xcccccccc) >> 2);
380 x = (x & 0x0f0f0f0f) + ((x & 0xf0f0f0f0) >> 4);
381 x = (x & 0x00ff00ff) + ((x & 0xff00ff00) >> 8);
382 x = (x & 0x0000ffff) + ((x & 0xffff0000) >> 16);
383 return (x);
384 }
385
386 #endif /* !_SYS_SYSTM_H_ */
Cache object: 21226ce09531e012bcedd4203f7958b0
|