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.4/sys/sys/systm.h 170945 2007-06-18 22:44:59Z jhb $
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 int32_t casuword32(volatile uint32_t *base, uint32_t oldval, uint32_t newval);
208 intptr_t casuptr(intptr_t *p, intptr_t old, intptr_t new);
209
210 void realitexpire(void *);
211
212 void hardclock(struct clockframe *frame);
213 void hardclock_process(struct clockframe *frame);
214 void softclock(void *);
215 void statclock(struct clockframe *frame);
216 void profclock(struct clockframe *frame);
217
218 void startprofclock(struct proc *);
219 void stopprofclock(struct proc *);
220 void cpu_startprofclock(void);
221 void cpu_stopprofclock(void);
222
223 /* flags for suser() and suser_cred() */
224 #define SUSER_ALLOWJAIL 1
225 #define SUSER_RUID 2
226
227 int suser(struct thread *td);
228 int suser_cred(struct ucred *cred, int flag);
229 int cr_cansee(struct ucred *u1, struct ucred *u2);
230 int cr_canseesocket(struct ucred *cred, struct socket *so);
231
232 char *getenv(const char *name);
233 void freeenv(char *env);
234 int getenv_int(const char *name, int *data);
235 long getenv_long(const char *name, long *data);
236 unsigned long getenv_ulong(const char *name, unsigned long *data);
237 int getenv_string(const char *name, char *data, int size);
238 int getenv_quad(const char *name, quad_t *data);
239 int setenv(const char *name, const char *value);
240 int unsetenv(const char *name);
241 int testenv(const char *name);
242
243 #ifdef APM_FIXUP_CALLTODO
244 struct timeval;
245 void adjust_timeout_calltodo(struct timeval *time_change);
246 #endif /* APM_FIXUP_CALLTODO */
247
248 #include <sys/libkern.h>
249
250 /* Initialize the world */
251 void consinit(void);
252 void cpu_initclocks(void);
253 void usrinfoinit(void);
254
255 /* Finalize the world. */
256 void shutdown_nice(int);
257
258 /*
259 * Kernel to clock driver interface.
260 */
261 void inittodr(time_t base);
262 void resettodr(void);
263 void startrtclock(void);
264
265 /* Timeouts */
266 typedef void timeout_t(void *); /* timeout function type */
267 #define CALLOUT_HANDLE_INITIALIZER(handle) \
268 { NULL }
269
270 void callout_handle_init(struct callout_handle *);
271 struct callout_handle timeout(timeout_t *, void *, int);
272 void untimeout(timeout_t *, void *, struct callout_handle);
273 caddr_t kern_timeout_callwheel_alloc(caddr_t v);
274 void kern_timeout_callwheel_init(void);
275
276 /* Stubs for obsolete functions that used to be for interrupt management */
277 static __inline void spl0(void) { return; }
278 static __inline intrmask_t splbio(void) { return 0; }
279 static __inline intrmask_t splcam(void) { return 0; }
280 static __inline intrmask_t splclock(void) { return 0; }
281 static __inline intrmask_t splhigh(void) { return 0; }
282 static __inline intrmask_t splimp(void) { return 0; }
283 static __inline intrmask_t splnet(void) { return 0; }
284 static __inline intrmask_t splsoftcam(void) { return 0; }
285 static __inline intrmask_t splsoftclock(void) { return 0; }
286 static __inline intrmask_t splsofttty(void) { return 0; }
287 static __inline intrmask_t splsoftvm(void) { return 0; }
288 static __inline intrmask_t splsofttq(void) { return 0; }
289 static __inline intrmask_t splstatclock(void) { return 0; }
290 static __inline intrmask_t spltty(void) { return 0; }
291 static __inline intrmask_t splvm(void) { return 0; }
292 static __inline void splx(intrmask_t ipl __unused) { return; }
293
294 /*
295 * Common `proc' functions are declared here so that proc.h can be included
296 * less often.
297 */
298 int msleep(void *chan, struct mtx *mtx, int pri, const char *wmesg,
299 int timo);
300 int msleep_spin(void *chan, struct mtx *mtx, const char *wmesg, int timo);
301 #define tsleep(chan, pri, wmesg, timo) msleep(chan, NULL, pri, wmesg, timo)
302 void wakeup(void *chan) __nonnull(1);
303 void wakeup_one(void *chan) __nonnull(1);
304
305 /*
306 * Common `struct cdev *' stuff are declared here to avoid #include poisoning
307 */
308
309 struct cdev;
310 int minor(struct cdev *x);
311 dev_t dev2udev(struct cdev *x);
312 int uminor(dev_t dev);
313 int umajor(dev_t dev);
314 const char *devtoname(struct cdev *cdev);
315
316 /* XXX: Should be void nanodelay(u_int nsec); */
317 void DELAY(int usec);
318
319 /* Root mount holdback API */
320 struct root_hold_token;
321
322 struct root_hold_token *root_mount_hold(const char *identifier);
323 void root_mount_rel(struct root_hold_token *h);
324
325
326 /*
327 * Unit number allocation API. (kern/subr_unit.c)
328 */
329 struct unrhdr;
330 struct unrhdr *new_unrhdr(int low, int high, struct mtx *mutex);
331 void delete_unrhdr(struct unrhdr *uh);
332 int alloc_unr(struct unrhdr *uh);
333 int alloc_unrl(struct unrhdr *uh);
334 void free_unr(struct unrhdr *uh, u_int item);
335
336 /*
337 * This is about as magic as it gets. fortune(1) has got similar code
338 * for reversing bits in a word. Who thinks up this stuff??
339 *
340 * Yes, it does appear to be consistently faster than:
341 * while (i = ffs(m)) {
342 * m >>= i;
343 * bits++;
344 * }
345 * and
346 * while (lsb = (m & -m)) { // This is magic too
347 * m &= ~lsb; // or: m ^= lsb
348 * bits++;
349 * }
350 * Both of these latter forms do some very strange things on gcc-3.1 with
351 * -mcpu=pentiumpro and/or -march=pentiumpro and/or -O or -O2.
352 * There is probably an SSE or MMX popcnt instruction.
353 *
354 * I wonder if this should be in libkern?
355 *
356 * XXX Stop the presses! Another one:
357 * static __inline u_int32_t
358 * popcnt1(u_int32_t v)
359 * {
360 * v -= ((v >> 1) & 0x55555555);
361 * v = (v & 0x33333333) + ((v >> 2) & 0x33333333);
362 * v = (v + (v >> 4)) & 0x0F0F0F0F;
363 * return (v * 0x01010101) >> 24;
364 * }
365 * The downside is that it has a multiply. With a pentium3 with
366 * -mcpu=pentiumpro and -march=pentiumpro then gcc-3.1 will use
367 * an imull, and in that case it is faster. In most other cases
368 * it appears slightly slower.
369 *
370 * Another variant (also from fortune):
371 * #define BITCOUNT(x) (((BX_(x)+(BX_(x)>>4)) & 0x0F0F0F0F) % 255)
372 * #define BX_(x) ((x) - (((x)>>1)&0x77777777) \
373 * - (((x)>>2)&0x33333333) \
374 * - (((x)>>3)&0x11111111))
375 */
376 static __inline uint32_t
377 bitcount32(uint32_t x)
378 {
379
380 x = (x & 0x55555555) + ((x & 0xaaaaaaaa) >> 1);
381 x = (x & 0x33333333) + ((x & 0xcccccccc) >> 2);
382 x = (x & 0x0f0f0f0f) + ((x & 0xf0f0f0f0) >> 4);
383 x = (x & 0x00ff00ff) + ((x & 0xff00ff00) >> 8);
384 x = (x & 0x0000ffff) + ((x & 0xffff0000) >> 16);
385 return (x);
386 }
387
388 #endif /* !_SYS_SYSTM_H_ */
Cache object: 648e93737f586937274455369260d792
|