systm.h revision 92976
11541Srgrimes/*-
21541Srgrimes * Copyright (c) 1982, 1988, 1991, 1993
31541Srgrimes *	The Regents of the University of California.  All rights reserved.
41541Srgrimes * (c) UNIX System Laboratories, Inc.
51541Srgrimes * All or some portions of this file are derived from material licensed
61541Srgrimes * to the University of California by American Telephone and Telegraph
71541Srgrimes * Co. or Unix System Laboratories, Inc. and are reproduced herein with
81541Srgrimes * the permission of UNIX System Laboratories, Inc.
91541Srgrimes *
101541Srgrimes * Redistribution and use in source and binary forms, with or without
111541Srgrimes * modification, are permitted provided that the following conditions
121541Srgrimes * are met:
131541Srgrimes * 1. Redistributions of source code must retain the above copyright
141541Srgrimes *    notice, this list of conditions and the following disclaimer.
151541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
161541Srgrimes *    notice, this list of conditions and the following disclaimer in the
171541Srgrimes *    documentation and/or other materials provided with the distribution.
181541Srgrimes * 3. All advertising materials mentioning features or use of this software
191541Srgrimes *    must display the following acknowledgement:
201541Srgrimes *	This product includes software developed by the University of
211541Srgrimes *	California, Berkeley and its contributors.
221541Srgrimes * 4. Neither the name of the University nor the names of its contributors
231541Srgrimes *    may be used to endorse or promote products derived from this software
241541Srgrimes *    without specific prior written permission.
251541Srgrimes *
261541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
271541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
281541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
291541Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
301541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
311541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
321541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
331541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
341541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
351541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
361541Srgrimes * SUCH DAMAGE.
371541Srgrimes *
3814508Shsu *	@(#)systm.h	8.7 (Berkeley) 3/29/95
3950477Speter * $FreeBSD: head/sys/sys/systm.h 92976 2002-03-22 19:57:41Z rwatson $
401541Srgrimes */
411541Srgrimes
422165Spaul#ifndef _SYS_SYSTM_H_
432865Sbde#define	_SYS_SYSTM_H_
442165Spaul
4549043Salc#include <machine/atomic.h>
461549Srgrimes#include <machine/cpufunc.h>
4729683Sgibbs#include <sys/callout.h>
481549Srgrimes
4918883Sbdeextern int securelevel;		/* system security level (see init(8)) */
5082693Srwatsonextern int suser_enabled;	/* suser_xxx() is permitted to return 0 */
517090Sbde
527090Sbdeextern int cold;		/* nonzero if we are doing a cold boot */
531541Srgrimesextern const char *panicstr;	/* panic message */
5467093Spsextern int dumping;		/* system is dumping */
551541Srgrimesextern char version[];		/* system version */
561541Srgrimesextern char copyright[];	/* system copyright */
571541Srgrimes
581541Srgrimesextern int nswap;		/* size of swap space */
591541Srgrimes
6092252Salfredextern int nselcoll;		/* select collisions since boot */
6192252Salfredextern struct mtx sellock;	/* select lock variable */
6276564Stanimuraextern struct cv selwait;	/* select conditional variable */
631541Srgrimes
641541Srgrimesextern int physmem;		/* physical memory */
651541Srgrimes
661541Srgrimesextern dev_t dumpdev;		/* dump device */
671541Srgrimesextern long dumplo;		/* offset into dumpdev */
681541Srgrimes
691541Srgrimesextern dev_t rootdev;		/* root device */
7036809Sbdeextern dev_t rootdevs[2];	/* possible root devices */
7136809Sbdeextern char *rootdevnames[2];	/* names of possible root devices */
721541Srgrimesextern struct vnode *rootvp;	/* vnode equivalent to above */
731541Srgrimes
741541Srgrimesextern int boothowto;		/* reboot flags, from console subsystem */
7515113Sbdeextern int bootverbose;		/* nonzero to print verbose messages */
761541Srgrimes
7780418Speterextern int maxusers;		/* system tune hint */
7880418Speter
7942453Seivind#ifdef	INVARIANTS		/* The option is always available */
8042453Seivind#define	KASSERT(exp,msg)	do { if (!(exp)) panic msg; } while (0)
8142408Seivind#else
8242453Seivind#define	KASSERT(exp,msg)
8342408Seivind#endif
8442408Seivind
851541Srgrimes/*
8683595Speter * XXX the hints declarations are even more misplaced than most declarations
8783595Speter * in this file, since they are needed in one file (per arch) and only used
8883595Speter * in two files.
8983595Speter * XXX most of these variables should be const.
9083595Speter */
9183595Speterextern int envmode;
9283595Speterextern int hintmode;		/* 0 = off. 1 = config, 2 = fallback */
9383595Speterextern char *kern_envp;
9483595Speterextern char static_env[];
9583595Speterextern char static_hints[];	/* by config for now */
9683595Speter
9783595Speter/*
981541Srgrimes * General function declarations.
991541Srgrimes */
10030282Sphk
10133777Sbdestruct clockframe;
10230282Sphkstruct malloc_type;
10365708Sjakestruct mtx;
10433777Sbdestruct proc;
10583366Sjulianstruct kse;
10692976Srwatsonstruct socket;
10783366Sjulianstruct thread;
10833777Sbdestruct tty;
10967893Sphkstruct ucred;
11033777Sbdestruct uio;
11179418Sjulianstruct _jmp_buf;
11230282Sphk
11392719Salfredint	setjmp(struct _jmp_buf *);
11492719Salfredvoid	longjmp(struct _jmp_buf *, int) __dead2;
11592719Salfredvoid	Debugger(const char *msg);
11692719Salfredint	dumpstatus(vm_offset_t addr, off_t count);
11792719Salfredint	nullop(void);
11892719Salfredint	eopnotsupp(void);
11992719Salfredint	seltrue(dev_t dev, int which, struct thread *td);
12092719Salfredint	ureadc(int, struct uio *);
12192719Salfredvoid	*hashinit(int count, struct malloc_type *type, u_long *hashmask);
12292719Salfredvoid	*phashinit(int count, struct malloc_type *type, u_long *nentries);
1231541Srgrimes
12490503Sbde#ifdef RESTARTABLE_PANICS
12592719Salfredvoid	panic(const char *, ...) __printflike(1, 2);
12690503Sbde#else
12792719Salfredvoid	panic(const char *, ...) __dead2 __printflike(1, 2);
12890503Sbde#endif
12990503Sbde
13092719Salfredvoid	cpu_boot(int);
13192719Salfredvoid	cpu_rootconf(void);
13292719Salfredvoid	critical_enter(void);
13392719Salfredvoid	critical_exit(void);
13492719Salfredvoid	init_param1(void);
13592719Salfredvoid	init_param2(int physpages);
13692719Salfredvoid	tablefull(const char *);
13792719Salfredint	kvprintf(char const *, void (*)(int, void*), void *, int,
13892719Salfred		      _BSD_VA_LIST_) __printflike(1, 0);
13992719Salfredvoid	log(int, const char *, ...) __printflike(2, 3);
14092719Salfredvoid	log_console(struct uio *);
14192719Salfredint	printf(const char *, ...) __printflike(1, 2);
14292719Salfredint	snprintf(char *, size_t, const char *, ...) __printflike(3, 4);
14392719Salfredint	sprintf(char *buf, const char *, ...) __printflike(2, 3);
14492719Salfredint	uprintf(const char *, ...) __printflike(1, 2);
14592719Salfredint	vprintf(const char *, _BSD_VA_LIST_) __printflike(1, 0);
14692719Salfredint	vsnprintf(char *, size_t, const char *, _BSD_VA_LIST_) __printflike(3, 0);
14792719Salfredint     vsprintf(char *buf, const char *, _BSD_VA_LIST_) __printflike(2, 0);
14892719Salfredint	ttyprintf(struct tty *, const char *, ...) __printflike(2, 3);
14992719Salfredint	sscanf(const char *, char const *, ...);
15092719Salfredint	vsscanf(const char *, char const *, _BSD_VA_LIST_);
15192719Salfredlong	strtol(const char *, char **, int);
15292719Salfredu_long	strtoul(const char *, char **, int);
15392719Salfredquad_t	strtoq(const char *, char **, int);
15492719Salfredu_quad_t strtouq(const char *, char **, int);
15592719Salfredvoid	tprintf(struct proc *p, int pri, const char *, ...) __printflike(3, 4);
1561541Srgrimes
15792719Salfredvoid	bcopy(const void *from, void *to, size_t len);
15892719Salfredvoid	ovbcopy(const void *from, void *to, size_t len);
15956079Sjmb
16036735Sdfr#ifdef __i386__
16192719Salfredextern void	(*bzero)(void *buf, size_t len);
16236735Sdfr#else
16392719Salfredvoid	bzero(void *buf, size_t len);
16436735Sdfr#endif
1651541Srgrimes
16692719Salfredvoid	*memcpy(void *to, const void *from, size_t len);
1678215Sdg
16892719Salfredint	copystr(const void *kfaddr, void *kdaddr, size_t len,
16992719Salfred		size_t *lencopied);
17092719Salfredint	copyinstr(const void *udaddr, void *kaddr, size_t len,
17192719Salfred		size_t *lencopied);
17292719Salfredint	copyin(const void *udaddr, void *kaddr, size_t len);
17392719Salfredint	copyout(const void *kaddr, void *udaddr, size_t len);
1741541Srgrimes
17592719Salfredint	fubyte(const void *base);
17692719Salfredint	subyte(void *base, int byte);
17792719Salfredint	suibyte(void *base, int byte);
17892719Salfredlong	fuword(const void *base);
17992719Salfredint	suword(void *base, long word);
18092719Salfredint	fusword(void *base);
18192719Salfredint	susword(void *base, int word);
1821541Srgrimes
18392719Salfredvoid	realitexpire(void *);
1841541Srgrimes
18592719Salfredvoid	hardclock(struct clockframe *frame);
18692719Salfredvoid	hardclock_process(struct thread *td, int user);
18792719Salfredvoid	softclock(void *);
18892719Salfredvoid	statclock(struct clockframe *frame);
18992719Salfredvoid	statclock_process(struct kse *ke, register_t pc, int user);
1901541Srgrimes
19192719Salfredvoid	startprofclock(struct proc *);
19292719Salfredvoid	stopprofclock(struct proc *);
19392719Salfredvoid	setstatclockrate(int hzrate);
1941541Srgrimes
19567893Sphk/* flags for suser_xxx() */
19667893Sphk#define PRISON_ROOT	1
19767893Sphk
19892719Salfredint	suser(struct proc *);
19992719Salfredint	suser_td(struct thread *);
20092719Salfredint	suser_xxx(struct ucred *cred, struct proc *proc, int flag);
20192719Salfredint	suser_xxx_td(struct ucred *cred, struct thread *thread, int flag);
20292719Salfredint	cr_cansee(struct ucred *u1, struct ucred *u2);
20392976Srwatsonint	cr_canseesocket(struct ucred *cred, struct socket *so);
20467893Sphk
20592719Salfredchar	*getenv(const char *name);
20692719Salfredint	getenv_int(const char *name, int *data);
20792719Salfredint	getenv_string(const char *name, char *data, int size);
20892719Salfredint	getenv_quad(const char *name, quad_t *data);
20940096Smsmith
21031960Snate#ifdef APM_FIXUP_CALLTODO
21183595Speterstruct timeval;
21292719Salfredvoid	adjust_timeout_calltodo(struct timeval *time_change);
21331960Snate#endif /* APM_FIXUP_CALLTODO */
21431960Snate
2157109Sphk#include <sys/libkern.h>
2162112Swollman
2172112Swollman/* Initialize the world */
21892719Salfredvoid	consinit(void);
21992719Salfredvoid	cpu_initclocks(void);
22092719Salfredvoid	usrinfoinit(void);
2212112Swollman
2227090Sbde/* Finalize the world. */
22392719Salfredvoid	shutdown_nice(int);
2247090Sbde
2257090Sbde/*
2267090Sbde * Kernel to clock driver interface.
2277090Sbde */
22892719Salfredvoid	inittodr(time_t base);
22992719Salfredvoid	resettodr(void);
23092719Salfredvoid	startrtclock(void);
2317090Sbde
2322112Swollman/* Timeouts */
23392719Salfredtypedef void timeout_t(void *);	/* timeout function type */
23429683Sgibbs#define CALLOUT_HANDLE_INITIALIZER(handle)	\
23529683Sgibbs	{ NULL }
2362112Swollman
23792719Salfredvoid	callout_handle_init(struct callout_handle *);
23892719Salfredstruct	callout_handle timeout(timeout_t *, void *, int);
23992719Salfredvoid	untimeout(timeout_t *, void *, struct callout_handle);
24092719Salfredcaddr_t	kern_timeout_callwheel_alloc(caddr_t v);
24192719Salfredvoid	kern_timeout_callwheel_init(void);
2422165Spaul
24371240Speter/* Stubs for obsolete functions that used to be for interrupt  management */
24471240Speterstatic __inline void		spl0(void)		{ return; }
24571240Speterstatic __inline intrmask_t	splbio(void)		{ return 0; }
24671240Speterstatic __inline intrmask_t	splcam(void)		{ return 0; }
24771240Speterstatic __inline intrmask_t	splclock(void)		{ return 0; }
24871240Speterstatic __inline intrmask_t	splhigh(void)		{ return 0; }
24971240Speterstatic __inline intrmask_t	splimp(void)		{ return 0; }
25071240Speterstatic __inline intrmask_t	splnet(void)		{ return 0; }
25171240Speterstatic __inline intrmask_t	splsoftcam(void)	{ return 0; }
25271240Speterstatic __inline intrmask_t	splsoftclock(void)	{ return 0; }
25371240Speterstatic __inline intrmask_t	splsofttty(void)	{ return 0; }
25471240Speterstatic __inline intrmask_t	splsoftvm(void)		{ return 0; }
25571240Speterstatic __inline intrmask_t	splsofttq(void)		{ return 0; }
25671240Speterstatic __inline intrmask_t	splstatclock(void)	{ return 0; }
25771240Speterstatic __inline intrmask_t	spltty(void)		{ return 0; }
25871240Speterstatic __inline intrmask_t	splvm(void)		{ return 0; }
25971240Speterstatic __inline void		splx(intrmask_t ipl)	{ return; }
26026312Speter
26126312Speter/*
26229509Sbde * Various callout lists.
26329509Sbde */
26417658Sjulian
26529509Sbde/* Exit callout list declarations. */
26692719Salfredtypedef void (*exitlist_fn)(struct proc *procp);
26717658Sjulian
26892719Salfredint	at_exit(exitlist_fn function);
26992719Salfredint	rm_at_exit(exitlist_fn function);
27017658Sjulian
27129509Sbde/* Fork callout list declarations. */
27292719Salfredtypedef void (*forklist_fn)(struct proc *parent, struct proc *child,
27392719Salfred				 int flags);
27427997Sjulian
27592719Salfredint	at_fork(forklist_fn function);
27692719Salfredint	rm_at_fork(forklist_fn function);
27727997Sjulian
27888633Salfred/* Exec callout list declarations. */
27992719Salfredtypedef void (*execlist_fn)(struct proc *procp);
28088633Salfred
28192719Salfredint	at_exec(execlist_fn function);
28292719Salfredint	rm_at_exec(execlist_fn function);
28388633Salfred
28429509Sbde/*
28529509Sbde * Not exactly a callout LIST, but a callout entry.
28629509Sbde * Allow an external module to define a hardware watchdog tickler.
28729509Sbde * Normally a process would do this, but there are times when the
28829509Sbde * kernel needs to be able to hold off the watchdog, when the process
28929509Sbde * is not active, e.g., when dumping core.
29029509Sbde */
29192719Salfredtypedef void (*watchdog_tickle_fn)(void);
29229509Sbde
29329509Sbdeextern watchdog_tickle_fn	wdog_tickler;
29429509Sbde
29518884Sbde/*
29618884Sbde * Common `proc' functions are declared here so that proc.h can be included
29718884Sbde * less often.
29818884Sbde */
29992719Salfredint	msleep(void *chan, struct mtx *mtx, int pri, const char *wmesg,
30092719Salfred		    int timo);
30165708Sjake#define	tsleep(chan, pri, wmesg, timo)	msleep(chan, NULL, pri, wmesg, timo)
30292719Salfredvoid	wakeup(void *chan);
30392719Salfredvoid	wakeup_one(void *chan);
30418884Sbde
30547028Sphk/*
30647028Sphk * Common `dev_t' stuff are declared here to avoid #include poisoning
30747028Sphk */
30847028Sphk
30947028Sphkint major(dev_t x);
31047028Sphkint minor(dev_t x);
31147028Sphkdev_t makedev(int x, int y);
31247028Sphkudev_t dev2udev(dev_t x);
31347028Sphkdev_t udev2dev(udev_t x, int b);
31447028Sphkint uminor(udev_t dev);
31547028Sphkint umajor(udev_t dev);
31648859Sphkudev_t makeudev(int x, int y);
31767158Sphk
31867158Sphk/* XXX: Should be void nanodelay(u_int nsec); */
31992719Salfredvoid	DELAY(int usec);
32067158Sphk
3212865Sbde#endif /* !_SYS_SYSTM_H_ */
322