#ifndef __SYSTM_H__
#define __SYSTM_H__
#include <sys/queue.h>
#include <sys/stdarg.h>
extern int securelevel;
extern const char *panicstr;
extern const char version[];
extern const char copyright[];
extern const char ostype[];
extern const char osversion[];
extern const char osrelease[];
extern int cold;
extern int db_active;
extern char *hw_vendor;
extern char *hw_prod;
extern char *hw_uuid;
extern char *hw_serial;
extern char *hw_ver;
extern int ncpus;
extern int ncpusfound;
extern int nblkdev;
extern int nchrdev;
extern int physmem;
extern dev_t dumpdev;
extern long dumplo;
extern dev_t rootdev;
extern u_char bootduid[8];
extern u_char rootduid[8];
extern struct vnode *rootvp;
extern struct device *rootdv;
extern dev_t swapdev;
extern struct vnode *swapdev_vp;
extern int nowake;
#ifdef MP_LOCKDEBUG
extern long __mp_lock_spinout;
#endif
struct proc;
struct process;
#define curproc curcpu()->ci_curproc
typedef int sy_call_t(struct proc *, void *, register_t *);
extern const struct sysent {
short sy_narg;
short sy_argsize;
int sy_flags;
sy_call_t *sy_call;
} sysent[];
#define SY_NOLOCK 0x01
#if _BYTE_ORDER == _BIG_ENDIAN
#define SCARG(p, k) ((p)->k.be.datum)
#elif _BYTE_ORDER == _LITTLE_ENDIAN
#define SCARG(p, k) ((p)->k.le.datum)
#else
#error "what byte order is this machine?"
#endif
#if defined(_KERNEL) && defined(SYSCALL_DEBUG)
void scdebug_call(struct proc *p, register_t code, const register_t retval[]);
void scdebug_ret(struct proc *p, register_t code, int error,
const register_t retval[]);
#endif
extern int boothowto;
extern void (*v_putc)(int);
int nullop(void *);
int enodev(void);
int enosys(void);
int enoioctl(void);
int enxio(void);
int eopnotsupp(void *);
void *hashinit(int, int, int, u_long *);
void hashfree(void *, int, int);
int sys_nosys(struct proc *, void *, register_t *);
void panic(const char *, ...)
__attribute__((__noreturn__,__format__(__kprintf__,1,2)));
void __assert(const char *, const char *, int, const char *)
__attribute__((__noreturn__));
int printf(const char *, ...)
__attribute__((__format__(__kprintf__,1,2)));
void uprintf(const char *, ...)
__attribute__((__format__(__kprintf__,1,2)));
int vprintf(const char *, va_list)
__attribute__((__format__(__kprintf__,1,0)));
int vsnprintf(char *, size_t, const char *, va_list)
__attribute__((__format__(__kprintf__,3,0)));
int snprintf(char *buf, size_t, const char *, ...)
__attribute__((__format__(__kprintf__,3,4)));
struct tty;
void ttyprintf(struct tty *, const char *, ...)
__attribute__((__format__(__kprintf__,2,3)));
void splassert_fail(int, int, const char *);
extern int splassert_ctl;
void assertwaitok(void);
void tablefull(const char *);
int kcopy(const void *, void *, size_t)
__attribute__ ((__bounded__(__buffer__,1,3)))
__attribute__ ((__bounded__(__buffer__,2,3)));
void bcopy(const void *, void *, size_t)
__attribute__ ((__bounded__(__buffer__,1,3)))
__attribute__ ((__bounded__(__buffer__,2,3)));
void bzero(void *, size_t)
__attribute__ ((__bounded__(__buffer__,1,2)));
void explicit_bzero(void *, size_t)
__attribute__ ((__bounded__(__buffer__,1,2)));
int bcmp(const void *, const void *, size_t);
void *memcpy(void *, const void *, size_t)
__attribute__ ((__bounded__(__buffer__,1,3)))
__attribute__ ((__bounded__(__buffer__,2,3)));
void *memmove(void *, const void *, size_t)
__attribute__ ((__bounded__(__buffer__,1,3)))
__attribute__ ((__bounded__(__buffer__,2,3)));
void *memset(void *, int, size_t)
__attribute__ ((__bounded__(__buffer__,1,3)));
int copyinstr(const void *, void *, size_t, size_t *)
__attribute__ ((__bounded__(__string__,2,3)));
int _copyinstr(const void *, void *, size_t, size_t *)
__attribute__ ((__bounded__(__string__,2,3)));
int copyoutstr(const void *, void *, size_t, size_t *);
int copyin(const void *, void *, size_t)
__attribute__ ((__bounded__(__buffer__,2,3)));
int _copyin(const void *, void *, size_t)
__attribute__ ((__bounded__(__buffer__,2,3)));
int copyout(const void *, void *, size_t);
int copyin32(const uint32_t *, uint32_t *);
void random_start(int);
void enqueue_randomness(unsigned int);
void suspend_randomness(void);
void resume_randomness(char *, size_t);
struct arc4random_ctx;
void arc4random_buf(void *, size_t)
__attribute__ ((__bounded__(__buffer__,1,2)));
struct arc4random_ctx *arc4random_ctx_new(void);
void arc4random_ctx_free(struct arc4random_ctx *);
void arc4random_ctx_buf(struct arc4random_ctx *, void *, size_t);
u_int32_t arc4random(void);
u_int32_t arc4random_uniform(u_int32_t);
struct timeval;
struct timespec;
int tvtohz(const struct timeval *);
int tstohz(const struct timespec *);
void realitexpire(void *);
extern uint64_t hardclock_period;
extern uint64_t statclock_avg;
extern int statclock_is_randomized;
struct clockframe;
void hardclock(struct clockframe *);
struct clockrequest;
void statclock(struct clockrequest *, void *, void *);
void initclocks(void);
void inittodr(time_t);
void resettodr(void);
void cpu_initclocks(void);
void cpu_startclock(void);
void startprofclock(struct process *);
void stopprofclock(struct process *);
void setstatclockrate(int);
void prof_fork(struct process *);
void prof_exec(struct process *);
void prof_write(struct proc *);
void start_periodic_resettodr(void);
void stop_periodic_resettodr(void);
void sleep_setup(const volatile void *, int, const char *);
int sleep_finish(uint64_t, int);
void sleep_queue_init(void);
struct cond;
void cond_init(struct cond *);
void cond_wait(struct cond *, const char *);
void cond_signal_handler(void *);
static inline void
cond_signal(struct cond *c)
{
cond_signal_handler(c);
}
#define INFSLP UINT64_MAX
#define MAXTSLP (UINT64_MAX - 1)
struct mutex;
struct rwlock;
void wakeup_n(const volatile void *, int);
void wakeup(const volatile void *);
#define wakeup_one(c) wakeup_n((c), 1)
int tsleep(const volatile void *, int, const char *, int);
int tsleep_nsec(const volatile void *, int, const char *, uint64_t);
int msleep(const volatile void *, struct mutex *, int, const char*, int);
int msleep_nsec(const volatile void *, struct mutex *, int, const char*,
uint64_t);
int rwsleep(const volatile void *, struct rwlock *, int, const char *, int);
int rwsleep_nsec(const volatile void *, struct rwlock *, int, const char *,
uint64_t);
void yield(void);
void wdog_register(int (*)(void *, int), void *);
void wdog_shutdown(void *);
struct hook_desc {
TAILQ_ENTRY(hook_desc) hd_list;
void (*hd_fn)(void *);
void *hd_arg;
};
TAILQ_HEAD(hook_desc_head, hook_desc);
extern struct hook_desc_head startuphook_list;
void *hook_establish(struct hook_desc_head *, int, void (*)(void *), void *);
void hook_disestablish(struct hook_desc_head *, void *);
void dohooks(struct hook_desc_head *, int);
#define HOOK_REMOVE 0x01
#define HOOK_FREE 0x02
#define startuphook_establish(fn, arg) \
hook_establish(&startuphook_list, 1, (fn), (arg))
#define startuphook_disestablish(vhook) \
hook_disestablish(&startuphook_list, (vhook))
#define dostartuphooks() dohooks(&startuphook_list, HOOK_REMOVE|HOOK_FREE)
struct uio;
int uiomove(void *, size_t, struct uio *);
#if defined(_KERNEL)
#include <sys/rwlock.h>
extern struct rwlock netlock;
#define NET_LOCK() do { rw_enter_write(&netlock); } while (0)
#define NET_UNLOCK() do { rw_exit_write(&netlock); } while (0)
#define NET_LOCK_SHARED() do { rw_enter_read(&netlock); } while (0)
#define NET_UNLOCK_SHARED() do { rw_exit_read(&netlock); } while (0)
#ifdef DIAGNOSTIC
#define NET_ASSERT_UNLOCKED() \
do { \
int _s = rw_status(&netlock); \
if ((splassert_ctl > 0) && (_s == RW_WRITE)) \
splassert_fail(0, RW_WRITE, __func__); \
} while (0)
#define NET_ASSERT_LOCKED() \
do { \
int _s = rw_status(&netlock); \
if ((splassert_ctl > 0) && (_s != RW_WRITE && _s != RW_READ)) \
splassert_fail(RW_READ, _s, __func__); \
} while (0)
#define NET_ASSERT_LOCKED_EXCLUSIVE() \
do { \
int _s = rw_status(&netlock); \
if ((splassert_ctl > 0) && (_s != RW_WRITE)) \
splassert_fail(RW_WRITE, _s, __func__); \
} while (0)
#else
#define NET_ASSERT_UNLOCKED() do {} while (0)
#define NET_ASSERT_LOCKED() do {} while (0)
#define NET_ASSERT_LOCKED_EXCLUSIVE() do {} while (0)
#endif
__returns_twice int setjmp(label_t *);
__dead void longjmp(label_t *);
#endif
void consinit(void);
void cpu_startup(void);
void cpu_configure(void);
void diskconf(void);
void powerbutton_event(void);
int nfs_mountroot(void);
int dk_mountroot(void);
extern int (*mountroot)(void);
#include <lib/libkern/libkern.h>
#define bzero(b, n) __builtin_bzero((b), (n))
#define memcmp(b1, b2, n) __builtin_memcmp((b1), (b2), (n))
#define memcpy(d, s, n) __builtin_memcpy((d), (s), (n))
#define memset(b, c, n) __builtin_memset((b), (c), (n))
#if (defined(__GNUC__) && __GNUC__ >= 4)
#define memmove(d, s, n) __builtin_memmove((d), (s), (n))
#endif
#if !defined(__clang__) && (defined(__GNUC__) && __GNUC__ >= 4)
#define bcmp(b1, b2, n) __builtin_bcmp((b1), (b2), (n))
#define bcopy(s, d, n) __builtin_bcopy((s), (d), (n))
#endif
#if defined(DDB)
void db_enter(void);
int db_rint(int);
#endif
#ifdef BOOT_CONFIG
void user_config(void);
#endif
#if defined(MULTIPROCESSOR)
void _kernel_lock_init(void);
void _kernel_lock(void);
void _kernel_unlock(void);
int _kernel_lock_held(void);
#define KERNEL_LOCK_INIT() _kernel_lock_init()
#define KERNEL_LOCK() _kernel_lock()
#define KERNEL_UNLOCK() _kernel_unlock()
#define KERNEL_ASSERT_LOCKED() KASSERT(_kernel_lock_held())
#define KERNEL_ASSERT_UNLOCKED() KASSERT(panicstr || db_active || !_kernel_lock_held())
#else
#define KERNEL_LOCK_INIT()
#define KERNEL_LOCK()
#define KERNEL_UNLOCK()
#define KERNEL_ASSERT_LOCKED()
#define KERNEL_ASSERT_UNLOCKED()
#endif
#endif