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/5.3/sys/sys/systm.h 136588 2004-10-16 08:43:07Z 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 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 extern int uarea_pages; /* number of user struct 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
66 extern struct cdev *rootdev; /* root device */
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 #else
80 #define KASSERT(exp,msg)
81 #endif
82
83 #ifndef CTASSERT /* Allow lint to override */
84 #define CTASSERT(x) _CTASSERT(x, __LINE__)
85 #define _CTASSERT(x, y) __CTASSERT(x, y)
86 #define __CTASSERT(x, y) typedef char __assert ## y[(x) ? 1 : -1]
87 #endif
88
89 /*
90 * XXX the hints declarations are even more misplaced than most declarations
91 * in this file, since they are needed in one file (per arch) and only used
92 * in two files.
93 * XXX most of these variables should be const.
94 */
95 extern int envmode;
96 extern int hintmode; /* 0 = off. 1 = config, 2 = fallback */
97 extern int dynamic_kenv;
98 extern struct sx kenv_lock;
99 extern char *kern_envp;
100 extern char static_env[];
101 extern char static_hints[]; /* by config for now */
102
103 extern char **kenvp;
104
105 /*
106 * General function declarations.
107 */
108
109 struct clockframe;
110 struct malloc_type;
111 struct mtx;
112 struct proc;
113 struct kse;
114 struct socket;
115 struct thread;
116 struct tty;
117 struct ucred;
118 struct uio;
119 struct _jmp_buf;
120
121 int setjmp(struct _jmp_buf *);
122 void longjmp(struct _jmp_buf *, int) __dead2;
123 int dumpstatus(vm_offset_t addr, off_t count);
124 int nullop(void);
125 int eopnotsupp(void);
126 int ureadc(int, struct uio *);
127 void hashdestroy(void *, struct malloc_type *, u_long);
128 void *hashinit(int count, struct malloc_type *type, u_long *hashmask);
129 void *phashinit(int count, struct malloc_type *type, u_long *nentries);
130
131 #ifdef RESTARTABLE_PANICS
132 void panic(const char *, ...) __printflike(1, 2);
133 #else
134 void panic(const char *, ...) __dead2 __printflike(1, 2);
135 #endif
136
137 void cpu_boot(int);
138 void cpu_rootconf(void);
139 extern uint32_t crc32_tab[];
140 uint32_t crc32(const void *buf, size_t size);
141 void critical_enter(void);
142 void critical_exit(void);
143 void init_param1(void);
144 void init_param2(long physpages);
145 void init_param3(long kmempages);
146 void tablefull(const char *);
147 int kvprintf(char const *, void (*)(int, void*), void *, int,
148 __va_list) __printflike(1, 0);
149 void log(int, const char *, ...) __printflike(2, 3);
150 void log_console(struct uio *);
151 int printf(const char *, ...) __printflike(1, 2);
152 int snprintf(char *, size_t, const char *, ...) __printflike(3, 4);
153 int sprintf(char *buf, const char *, ...) __printflike(2, 3);
154 int uprintf(const char *, ...) __printflike(1, 2);
155 int vprintf(const char *, __va_list) __printflike(1, 0);
156 int vsnprintf(char *, size_t, const char *, __va_list) __printflike(3, 0);
157 int vsnrprintf(char *, size_t, int, const char *, __va_list) __printflike(4, 0);
158 int vsprintf(char *buf, const char *, __va_list) __printflike(2, 0);
159 int ttyprintf(struct tty *, const char *, ...) __printflike(2, 3);
160 int sscanf(const char *, char const *, ...) __nonnull(1) __nonnull(2);
161 int vsscanf(const char *, char const *, __va_list) __nonnull(1) __nonnull(2);
162 long strtol(const char *, char **, int) __nonnull(1);
163 u_long strtoul(const char *, char **, int) __nonnull(1);
164 quad_t strtoq(const char *, char **, int) __nonnull(1);
165 u_quad_t strtouq(const char *, char **, int) __nonnull(1);
166 void tprintf(struct proc *p, int pri, const char *, ...) __printflike(3, 4);
167 void hexdump(void *ptr, int length, const char *hdr, int flags);
168 #define HD_COLUMN_MASK 0xff
169 #define HD_DELIM_MASK 0xff00
170 #define HD_OMIT_COUNT (1 << 16)
171 #define HD_OMIT_HEX (1 << 17)
172 #define HD_OMIT_CHARS (1 << 18)
173
174 #define ovbcopy(f, t, l) bcopy((f), (t), (l))
175 void bcopy(const void *from, void *to, size_t len) __nonnull(1) __nonnull(2);
176 void bzero(void *buf, size_t len) __nonnull(1);
177
178 void *memcpy(void *to, const void *from, size_t len) __nonnull(1) __nonnull(2);
179
180 int copystr(const void * __restrict kfaddr, void * __restrict kdaddr,
181 size_t len, size_t * __restrict lencopied)
182 __nonnull(1) __nonnull(2);
183 int copyinstr(const void * __restrict udaddr, void * __restrict kaddr,
184 size_t len, size_t * __restrict lencopied)
185 __nonnull(1) __nonnull(2);
186 int copyin(const void * __restrict udaddr, void * __restrict kaddr,
187 size_t len) __nonnull(1) __nonnull(2);
188 int copyout(const void * __restrict kaddr, void * __restrict udaddr,
189 size_t len) __nonnull(1) __nonnull(2);
190
191 int fubyte(const void *base);
192 long fuword(const void *base);
193 int fuword16(void *base);
194 int32_t fuword32(const void *base);
195 int64_t fuword64(const void *base);
196 int subyte(void *base, int byte);
197 int suword(void *base, long word);
198 int suword16(void *base, int word);
199 int suword32(void *base, int32_t word);
200 int suword64(void *base, int64_t word);
201 intptr_t casuptr(intptr_t *p, intptr_t old, intptr_t new);
202
203 void realitexpire(void *);
204
205 void hardclock(struct clockframe *frame);
206 void hardclock_process(struct clockframe *frame);
207 void softclock(void *);
208 void statclock(struct clockframe *frame);
209 void profclock(struct clockframe *frame);
210
211 void startprofclock(struct proc *);
212 void stopprofclock(struct proc *);
213 void cpu_startprofclock(void);
214 void cpu_stopprofclock(void);
215
216 /* flags for suser() and suser_cred() */
217 #define SUSER_ALLOWJAIL 1
218 #define SUSER_RUID 2
219
220 int suser(struct thread *td);
221 int suser_cred(struct ucred *cred, int flag);
222 int cr_cansee(struct ucred *u1, struct ucred *u2);
223 int cr_canseesocket(struct ucred *cred, struct socket *so);
224
225 char *getenv(const char *name);
226 void freeenv(char *env);
227 int getenv_int(const char *name, int *data);
228 int getenv_string(const char *name, char *data, int size);
229 int getenv_quad(const char *name, quad_t *data);
230 int setenv(const char *name, const char *value);
231 int unsetenv(const char *name);
232 int testenv(const char *name);
233
234 #ifdef APM_FIXUP_CALLTODO
235 struct timeval;
236 void adjust_timeout_calltodo(struct timeval *time_change);
237 #endif /* APM_FIXUP_CALLTODO */
238
239 #include <sys/libkern.h>
240
241 /* Initialize the world */
242 void consinit(void);
243 void cpu_initclocks(void);
244 void usrinfoinit(void);
245
246 /* Finalize the world. */
247 void shutdown_nice(int);
248
249 /*
250 * Kernel to clock driver interface.
251 */
252 void inittodr(time_t base);
253 void resettodr(void);
254 void startrtclock(void);
255
256 /* Timeouts */
257 typedef void timeout_t(void *); /* timeout function type */
258 #define CALLOUT_HANDLE_INITIALIZER(handle) \
259 { NULL }
260
261 void callout_handle_init(struct callout_handle *);
262 struct callout_handle timeout(timeout_t *, void *, int);
263 void untimeout(timeout_t *, void *, struct callout_handle);
264 caddr_t kern_timeout_callwheel_alloc(caddr_t v);
265 void kern_timeout_callwheel_init(void);
266
267 /* Stubs for obsolete functions that used to be for interrupt management */
268 static __inline void spl0(void) { return; }
269 static __inline intrmask_t splbio(void) { return 0; }
270 static __inline intrmask_t splcam(void) { return 0; }
271 static __inline intrmask_t splclock(void) { return 0; }
272 static __inline intrmask_t splhigh(void) { return 0; }
273 static __inline intrmask_t splimp(void) { return 0; }
274 static __inline intrmask_t splnet(void) { return 0; }
275 static __inline intrmask_t splsoftcam(void) { return 0; }
276 static __inline intrmask_t splsoftclock(void) { return 0; }
277 static __inline intrmask_t splsofttty(void) { return 0; }
278 static __inline intrmask_t splsoftvm(void) { return 0; }
279 static __inline intrmask_t splsofttq(void) { return 0; }
280 static __inline intrmask_t splstatclock(void) { return 0; }
281 static __inline intrmask_t spltty(void) { return 0; }
282 static __inline intrmask_t splvm(void) { return 0; }
283 static __inline void splx(intrmask_t ipl __unused) { return; }
284
285 /*
286 * Various callout lists.
287 */
288
289 /*
290 * Not exactly a callout LIST, but a callout entry.
291 * Allow an external module to define a hardware watchdog tickler.
292 * Normally a process would do this, but there are times when the
293 * kernel needs to be able to hold off the watchdog, when the process
294 * is not active, e.g., when dumping core.
295 */
296 typedef void (*watchdog_tickle_fn)(void);
297
298 extern watchdog_tickle_fn wdog_tickler;
299
300 /*
301 * Common `proc' functions are declared here so that proc.h can be included
302 * less often.
303 */
304 int msleep(void *chan, struct mtx *mtx, int pri, const char *wmesg,
305 int timo);
306 #define tsleep(chan, pri, wmesg, timo) msleep(chan, NULL, pri, wmesg, timo)
307 void wakeup(void *chan) __nonnull(1);
308 void wakeup_one(void *chan) __nonnull(1);
309
310 /*
311 * Common `struct cdev *' stuff are declared here to avoid #include poisoning
312 */
313
314 int major(struct cdev *x);
315 int minor(struct cdev *x);
316 dev_t dev2udev(struct cdev *x);
317 struct cdev *findcdev(dev_t x);
318 int uminor(dev_t dev);
319 int umajor(dev_t dev);
320
321 /* XXX: Should be void nanodelay(u_int nsec); */
322 void DELAY(int usec);
323
324 #endif /* !_SYS_SYSTM_H_ */
Cache object: 48d912e8b476482bcfd4fbb26cee2555
|