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