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.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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.
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
34 * @(#)systm.h 8.7 (Berkeley) 3/29/95
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 */
48 extern int securelevel; /* system security level (see init(8)) */
49 extern int suser_enabled; /* suser() is permitted to return 0 */
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 */
57 extern int nswap; /* size of swap space */
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 */
63 extern long physmem; /* physical memory */
64 extern long realmem; /* 'real' memory */
66 extern char *rootdevnames[2]; /* names of possible root devices */
68 extern int boothowto; /* reboot flags, from console subsystem */
69 extern int bootverbose; /* nonzero to print verbose messages */
71 extern int maxusers; /* system tune hint */
73 #ifdef INVARIANTS /* The option is always available */
74 #define KASSERT(exp,msg) do { \
75 if (__predict_false(!(exp))) \
78 #define VNASSERT(exp, vp, msg) do { \
79 if (__predict_false(!(exp))) { \
80 vn_printf(vp, "VNASSERT failed\n"); \
85 #define KASSERT(exp,msg)
86 #define VNASSERT(exp, vp, msg)
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]
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
99 * XXX most of these variables should be const.
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 */
112 * General function declarations.
127 int setjmp(struct _jmp_buf *);
128 void longjmp(struct _jmp_buf *, int) __dead2;
129 int dumpstatus(vm_offset_t addr, off_t count);
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);
138 #ifdef RESTARTABLE_PANICS
139 void panic(const char *, ...) __printflike(1, 2);
141 void panic(const char *, ...) __dead2 __printflike(1, 2);
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)
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);
183 void *memcpy(void *to, const void *from, size_t len) __nonnull(1) __nonnull(2);
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);
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);
208 void realitexpire(void *);
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);
216 void startprofclock(struct proc *);
217 void stopprofclock(struct proc *);
218 void cpu_startprofclock(void);
219 void cpu_stopprofclock(void);
221 /* flags for suser() and suser_cred() */
222 #define SUSER_ALLOWJAIL 1
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);
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);
241 #ifdef APM_FIXUP_CALLTODO
243 void adjust_timeout_calltodo(struct timeval *time_change);
244 #endif /* APM_FIXUP_CALLTODO */
246 #include <sys/libkern.h>
248 /* Initialize the world */
250 void cpu_initclocks(void);
251 void usrinfoinit(void);
253 /* Finalize the world. */
254 void shutdown_nice(int);
257 * Kernel to clock driver interface.
259 void inittodr(time_t base);
260 void resettodr(void);
261 void startrtclock(void);
264 typedef void timeout_t(void *); /* timeout function type */
265 #define CALLOUT_HANDLE_INITIALIZER(handle) \
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);
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; }
293 * Common `proc' functions are declared here so that proc.h can be included
296 int msleep(void *chan, struct mtx *mtx, int pri, const char *wmesg,
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);
303 * Common `struct cdev *' stuff are declared here to avoid #include poisoning
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);
313 /* XXX: Should be void nanodelay(u_int nsec); */
314 void DELAY(int usec);
316 /* Root mount holdback API */
317 struct root_hold_token;
319 struct root_hold_token *root_mount_hold(const char *identifier);
320 void root_mount_rel(struct root_hold_token *h);
324 * Unit number allocation API. (kern/subr_unit.c)
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);
333 #endif /* !_SYS_SYSTM_H_ */