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 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the University of
21 * California, Berkeley and its contributors.
22 * 4. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 *
38 * @(#)systm.h 8.7 (Berkeley) 3/29/95
39 * $FreeBSD: releng/5.1/sys/sys/systm.h 113090 2003-04-04 17:29:55Z des $
40 */
41
42 #ifndef _SYS_SYSTM_H_
43 #define _SYS_SYSTM_H_
44
45 #include <machine/atomic.h>
46 #include <machine/cpufunc.h>
47 #include <sys/callout.h>
48 #include <sys/queue.h>
49 #include <sys/stdint.h> /* for people using printf mainly */
50
51 extern int securelevel; /* system security level (see init(8)) */
52 extern int suser_enabled; /* suser() is permitted to return 0 */
53
54 extern int cold; /* nonzero if we are doing a cold boot */
55 extern const char *panicstr; /* panic message */
56 extern char version[]; /* system version */
57 extern char copyright[]; /* system copyright */
58 extern int kstack_pages; /* number of kernel stack pages */
59 extern int uarea_pages; /* number of user struct pages */
60
61 extern int nswap; /* size of swap space */
62
63 extern u_int nselcoll; /* select collisions since boot */
64 extern struct mtx sellock; /* select lock variable */
65 extern struct cv selwait; /* select conditional variable */
66
67 extern long physmem; /* physical memory */
68
69 extern dev_t rootdev; /* root device */
70 extern dev_t rootdevs[2]; /* possible root devices */
71 extern char *rootdevnames[2]; /* names of possible root devices */
72 extern struct vnode *rootvp; /* vnode equivalent to above */
73
74 extern int boothowto; /* reboot flags, from console subsystem */
75 extern int bootverbose; /* nonzero to print verbose messages */
76
77 extern int maxusers; /* system tune hint */
78
79 #ifdef INVARIANTS /* The option is always available */
80 #define KASSERT(exp,msg) do { if (!(exp)) panic msg; } while (0)
81 #else
82 #define KASSERT(exp,msg)
83 #endif
84
85 #ifndef CTASSERT /* Allow lint to override */
86 #define CTASSERT(x) _CTASSERT(x, __LINE__)
87 #define _CTASSERT(x, y) __CTASSERT(x, y)
88 #define __CTASSERT(x, y) typedef char __assert ## y[(x) ? 1 : -1]
89 #endif
90
91 /*
92 * XXX the hints declarations are even more misplaced than most declarations
93 * in this file, since they are needed in one file (per arch) and only used
94 * in two files.
95 * XXX most of these variables should be const.
96 */
97 extern int envmode;
98 extern int hintmode; /* 0 = off. 1 = config, 2 = fallback */
99 extern int dynamic_kenv;
100 extern struct sx kenv_lock;
101 extern char *kern_envp;
102 extern char static_env[];
103 extern char static_hints[]; /* by config for now */
104
105 extern char **kenvp;
106
107 /*
108 * General function declarations.
109 */
110
111 struct clockframe;
112 struct malloc_type;
113 struct mtx;
114 struct proc;
115 struct kse;
116 struct socket;
117 struct thread;
118 struct tty;
119 struct ucred;
120 struct uio;
121 struct _jmp_buf;
122
123 int setjmp(struct _jmp_buf *);
124 void longjmp(struct _jmp_buf *, int) __dead2;
125 void Debugger(const char *msg);
126 int dumpstatus(vm_offset_t addr, off_t count);
127 int nullop(void);
128 int eopnotsupp(void);
129 int seltrue(dev_t dev, int which, struct thread *td);
130 int ureadc(int, struct uio *);
131 void hashdestroy(void *, struct malloc_type *, u_long);
132 void *hashinit(int count, struct malloc_type *type, u_long *hashmask);
133 void *phashinit(int count, struct malloc_type *type, u_long *nentries);
134
135 #ifdef RESTARTABLE_PANICS
136 void panic(const char *, ...) __printflike(1, 2);
137 #else
138 void panic(const char *, ...) __dead2 __printflike(1, 2);
139 #endif
140
141 void backtrace(void);
142 void cpu_boot(int);
143 void cpu_rootconf(void);
144 extern uint32_t crc32_tab[];
145 uint32_t crc32(const void *buf, size_t size);
146 void critical_enter(void);
147 void critical_exit(void);
148 void init_param1(void);
149 void init_param2(long physpages);
150 void tablefull(const char *);
151 int kvprintf(char const *, void (*)(int, void*), void *, int,
152 __va_list) __printflike(1, 0);
153 void log(int, const char *, ...) __printflike(2, 3);
154 void log_console(struct uio *);
155 int printf(const char *, ...) __printflike(1, 2);
156 int snprintf(char *, size_t, const char *, ...) __printflike(3, 4);
157 int sprintf(char *buf, const char *, ...) __printflike(2, 3);
158 int uprintf(const char *, ...) __printflike(1, 2);
159 int vprintf(const char *, __va_list) __printflike(1, 0);
160 int vsnprintf(char *, size_t, const char *, __va_list) __printflike(3, 0);
161 int vsnrprintf(char *, size_t, int, const char *, __va_list) __printflike(4, 0);
162 int vsprintf(char *buf, const char *, __va_list) __printflike(2, 0);
163 int ttyprintf(struct tty *, const char *, ...) __printflike(2, 3);
164 int sscanf(const char *, char const *, ...);
165 int vsscanf(const char *, char const *, __va_list);
166 long strtol(const char *, char **, int);
167 u_long strtoul(const char *, char **, int);
168 quad_t strtoq(const char *, char **, int);
169 u_quad_t strtouq(const char *, char **, int);
170 void tprintf(struct proc *p, int pri, const char *, ...) __printflike(3, 4);
171
172 #define ovbcopy(f, t, l) bcopy((f), (t), (l))
173 void bcopy(const void *from, void *to, size_t len);
174 void bzero(void *buf, size_t len);
175
176 void *memcpy(void *to, const void *from, size_t len);
177
178 int copystr(const void *kfaddr, void *kdaddr, size_t len,
179 size_t *lencopied);
180 int copyinstr(const void *udaddr, void *kaddr, size_t len,
181 size_t *lencopied);
182 int copyin(const void *udaddr, void *kaddr, size_t len);
183 int copyout(const void *kaddr, void *udaddr, size_t len);
184
185 int fubyte(const void *base);
186 long fuword(const void *base);
187 int fuword16(void *base);
188 int32_t fuword32(const void *base);
189 int64_t fuword64(const void *base);
190 int subyte(void *base, int byte);
191 int suword(void *base, long word);
192 int suword16(void *base, int word);
193 int suword32(void *base, int32_t word);
194 int suword64(void *base, int64_t word);
195 intptr_t casuptr(intptr_t *p, intptr_t old, intptr_t new);
196
197 void realitexpire(void *);
198
199 void hardclock(struct clockframe *frame);
200 void hardclock_process(struct clockframe *frame);
201 void softclock(void *);
202 void statclock(struct clockframe *frame);
203 void profclock(struct clockframe *frame);
204
205 void startprofclock(struct proc *);
206 void stopprofclock(struct proc *);
207 void cpu_startprofclock(void);
208 void cpu_stopprofclock(void);
209
210 /* flags for suser() and suser_cred() */
211 #define PRISON_ROOT 1
212
213 int suser(struct thread *td);
214 int suser_cred(struct ucred *cred, int flag);
215 int cr_cansee(struct ucred *u1, struct ucred *u2);
216 int cr_canseesocket(struct ucred *cred, struct socket *so);
217
218 char *getenv(const char *name);
219 void freeenv(char *env);
220 int getenv_int(const char *name, int *data);
221 int getenv_string(const char *name, char *data, int size);
222 int getenv_quad(const char *name, quad_t *data);
223 int setenv(const char *name, const char *value);
224 int unsetenv(const char *name);
225 int testenv(const char *name);
226
227 #ifdef APM_FIXUP_CALLTODO
228 struct timeval;
229 void adjust_timeout_calltodo(struct timeval *time_change);
230 #endif /* APM_FIXUP_CALLTODO */
231
232 #include <sys/libkern.h>
233
234 /* Initialize the world */
235 void consinit(void);
236 void cpu_initclocks(void);
237 void usrinfoinit(void);
238
239 /* Finalize the world. */
240 void shutdown_nice(int);
241
242 /*
243 * Kernel to clock driver interface.
244 */
245 void inittodr(time_t base);
246 void resettodr(void);
247 void startrtclock(void);
248
249 /* Timeouts */
250 typedef void timeout_t(void *); /* timeout function type */
251 #define CALLOUT_HANDLE_INITIALIZER(handle) \
252 { NULL }
253
254 void callout_handle_init(struct callout_handle *);
255 struct callout_handle timeout(timeout_t *, void *, int);
256 void untimeout(timeout_t *, void *, struct callout_handle);
257 caddr_t kern_timeout_callwheel_alloc(caddr_t v);
258 void kern_timeout_callwheel_init(void);
259
260 /* Stubs for obsolete functions that used to be for interrupt management */
261 static __inline void spl0(void) { return; }
262 static __inline intrmask_t splbio(void) { return 0; }
263 static __inline intrmask_t splcam(void) { return 0; }
264 static __inline intrmask_t splclock(void) { return 0; }
265 static __inline intrmask_t splhigh(void) { return 0; }
266 static __inline intrmask_t splimp(void) { return 0; }
267 static __inline intrmask_t splnet(void) { return 0; }
268 static __inline intrmask_t splsoftcam(void) { return 0; }
269 static __inline intrmask_t splsoftclock(void) { return 0; }
270 static __inline intrmask_t splsofttty(void) { return 0; }
271 static __inline intrmask_t splsoftvm(void) { return 0; }
272 static __inline intrmask_t splsofttq(void) { return 0; }
273 static __inline intrmask_t splstatclock(void) { return 0; }
274 static __inline intrmask_t spltty(void) { return 0; }
275 static __inline intrmask_t splvm(void) { return 0; }
276 static __inline void splx(intrmask_t ipl __unused) { return; }
277
278 /*
279 * Various callout lists.
280 */
281
282 /*
283 * Not exactly a callout LIST, but a callout entry.
284 * Allow an external module to define a hardware watchdog tickler.
285 * Normally a process would do this, but there are times when the
286 * kernel needs to be able to hold off the watchdog, when the process
287 * is not active, e.g., when dumping core.
288 */
289 typedef void (*watchdog_tickle_fn)(void);
290
291 extern watchdog_tickle_fn wdog_tickler;
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 void abortsleep(struct thread *td);
300 #define tsleep(chan, pri, wmesg, timo) msleep(chan, NULL, pri, wmesg, timo)
301 void wakeup(void *chan);
302 void wakeup_one(void *chan);
303
304 /*
305 * Common `dev_t' stuff are declared here to avoid #include poisoning
306 */
307
308 int major(dev_t x);
309 int minor(dev_t x);
310 dev_t makedev(int x, int y);
311 udev_t dev2udev(dev_t x);
312 dev_t udev2dev(udev_t x, int b);
313 int uminor(udev_t dev);
314 int umajor(udev_t dev);
315 udev_t makeudev(int x, int y);
316
317 /* XXX: Should be void nanodelay(u_int nsec); */
318 void DELAY(int usec);
319
320 #endif /* !_SYS_SYSTM_H_ */
Cache object: d07fcb3c30cdd0be11ab904d5c3403f1
|