systm.h revision 641:057d58d31499
1/* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 23/* All Rights Reserved */ 24 25 26/* 27 * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 * Use is subject to license terms. 29 */ 30 31#ifndef _SYS_SYSTM_H 32#define _SYS_SYSTM_H 33 34#pragma ident "%Z%%M% %I% %E% SMI" 35 36#include <sys/types.h> 37#include <sys/t_lock.h> 38#include <sys/proc.h> 39#include <sys/dditypes.h> 40 41#ifdef __cplusplus 42extern "C" { 43#endif 44 45/* 46 * The pc_t is the type of the kernel's program counter. In general, a 47 * pc_t is a uintptr_t -- except for a sparcv9 kernel, in which case all 48 * instruction text is below 4G, and a pc_t is thus a uint32_t. 49 */ 50#ifdef __sparcv9 51typedef uint32_t pc_t; 52#else 53typedef uintptr_t pc_t; 54#endif 55 56/* 57 * Random set of variables used by more than one routine. 58 */ 59 60#ifdef _KERNEL 61#include <sys/varargs.h> 62 63extern int hz; /* system clock rate */ 64extern struct vnode *rootdir; /* pointer to vnode of root directory */ 65extern struct vnode *devicesdir; /* pointer to /devices vnode */ 66extern volatile clock_t lbolt; /* time in HZ since last boot */ 67extern volatile int64_t lbolt64; /* lbolt computed as 64-bit value */ 68extern int interrupts_unleashed; /* set after the spl0() in main() */ 69 70extern char runin; /* scheduling flag */ 71extern char runout; /* scheduling flag */ 72extern char wake_sched; /* causes clock to wake swapper on next tick */ 73extern char wake_sched_sec; /* causes clock to wake swapper after a sec */ 74 75extern pgcnt_t maxmem; /* max available memory (pages) */ 76extern pgcnt_t physmem; /* physical memory (pages) on this CPU */ 77extern pfn_t physmax; /* highest numbered physical page present */ 78extern pgcnt_t physinstalled; /* physical pages including PROM/boot use */ 79 80extern caddr_t s_text; /* start of kernel text segment */ 81extern caddr_t e_text; /* end of kernel text segment */ 82extern caddr_t s_data; /* start of kernel text segment */ 83extern caddr_t e_data; /* end of kernel text segment */ 84 85extern pgcnt_t availrmem; /* Available resident (not swapable) */ 86 /* memory in pages. */ 87extern pgcnt_t availrmem_initial; /* initial value of availrmem */ 88extern pgcnt_t segspt_minfree; /* low water mark for availrmem in seg_spt */ 89extern pgcnt_t freemem; /* Current free memory. */ 90 91extern dev_t rootdev; /* device of the root */ 92extern struct vnode *rootvp; /* vnode of root device */ 93extern int root_is_svm; /* root is a mirrored device flag */ 94extern char *volatile panicstr; /* panic string pointer */ 95extern va_list panicargs; /* panic arguments */ 96 97extern int rstchown; /* 1 ==> restrictive chown(2) semantics */ 98extern int klustsize; 99 100extern int abort_enable; /* Platform input-device abort policy */ 101 102#ifdef C2_AUDIT 103extern int audit_active; /* C2 auditing activate 1, absent 0. */ 104#endif 105 106extern int avenrun[]; /* array of load averages */ 107 108extern char *isa_list; /* For sysinfo's isalist option */ 109 110extern int noexec_user_stack; /* patchable via /etc/system */ 111extern int noexec_user_stack_log; /* patchable via /etc/system */ 112 113extern void report_stack_exec(proc_t *, caddr_t); 114 115extern void startup(void); 116extern void clkstart(void); 117extern void post_startup(void); 118extern void kern_setup1(void); 119extern void ka_init(void); 120extern void nodename_set(void); 121 122/* 123 * for tod fault detection 124 */ 125enum tod_fault_type { 126 TOD_REVERSED = 0, 127 TOD_STALLED, 128 TOD_JUMPED, 129 TOD_RATECHANGED, 130 TOD_NOFAULT 131}; 132 133extern time_t tod_validate(time_t); 134extern void tod_fault_reset(void); 135extern void plat_tod_fault(enum tod_fault_type); 136 137#ifndef _LP64 138#ifndef min 139int min(int, int); 140#endif 141 142#ifndef max 143int max(int, int); 144#endif 145 146uint_t umin(uint_t, uint_t); 147uint_t umax(uint_t, uint_t); 148#endif /* !_LP64 */ 149int grow(caddr_t); 150int grow_internal(caddr_t, uint_t); 151int brk_internal(caddr_t, uint_t); 152timeout_id_t timeout(void (*)(void *), void *, clock_t); 153timeout_id_t realtime_timeout(void (*)(void *), void *, clock_t); 154clock_t untimeout(timeout_id_t); 155void delay(clock_t); 156int delay_sig(clock_t); 157int nodev(); 158int nulldev(); 159major_t getudev(void); 160int cmpldev(dev32_t *, dev_t); 161dev_t expldev(dev32_t); 162int bcmp(const void *, const void *, size_t) __PURE; 163int stoi(char **); 164void numtos(ulong_t, char *); 165size_t strlen(const char *) __PURE; 166char *strcat(char *, const char *); 167char *strncat(char *, const char *, size_t); 168char *strcpy(char *, const char *); 169char *strncpy(char *, const char *, size_t); 170/* Need to be consistent with <string.h> C++ definitions */ 171#if __cplusplus >= 199711L 172extern const char *strchr(const char *, int); 173#ifndef _STRCHR_INLINE 174#define _STRCHR_INLINE 175extern "C++" { 176 inline char *strchr(char *__s, int __c) { 177 return (char *)strchr((const char *)__s, __c); 178 } 179} 180#endif /* _STRCHR_INLINE */ 181extern const char *strrchr(const char *, int); 182#ifndef _STRRCHR_INLINE 183#define _STRRCHR_INLINE 184extern "C++" { 185 inline char *strrchr(char *__s, int __c) { 186 return (char *)strrchr((const char *)__s, __c); 187 } 188} 189#endif /* _STRRCHR_INLINE */ 190extern const char *strstr(const char *, const char *); 191#ifndef _STRSTR_INLINE 192#define _STRSTR_INLINE 193extern "C++" { 194 inline char *strstr(char *__s1, const char *__s2) { 195 return (char *)strstr((const char *)__s1, __s2); 196 } 197} 198#endif /* _STRSTR_INLINE */ 199#else /* __cplusplus >= 199711L */ 200char *strchr(const char *, int); 201char *strrchr(const char *, int); 202char *strstr(const char *, const char *); 203#endif /* __cplusplus >= 199711L */ 204char *strnrchr(const char *, int, size_t); 205int strcmp(const char *, const char *) __PURE; 206int strncmp(const char *, const char *, size_t) __PURE; 207int strcasecmp(const char *, const char *) __PURE; 208int strncasecmp(const char *, const char *, size_t) __PURE; 209/* Need to be consistent with <string.h> C++ definitions */ 210#if __cplusplus >= 199711L 211extern const char *strpbrk(const char *, const char *); 212#ifndef _STRPBRK_INLINE 213#define _STRPBRK_INLINE 214extern "C++" { 215 inline char *strpbrk(char *__s1, const char *__s2) { 216 return (char *)strpbrk((const char *)__s1, __s2); 217 } 218} 219#endif /* _STRPBRK_INLINE */ 220#else /* __cplusplus >= 199711L */ 221char *strpbrk(const char *, const char *); 222#endif /* __cplusplus >= 199711L */ 223int strident_valid(const char *); 224void strident_canon(char *, size_t); 225int getsubopt(char **optionsp, char * const *tokens, char **valuep); 226char *append_subopt(const char *, size_t, char *, const char *); 227int ffs(long); 228int copyin(const void *, void *, size_t); 229void copyin_noerr(const void *, void *, size_t); 230int xcopyin(const void *, void *, size_t); 231int xcopyin_nta(const void *, void *, size_t, int); 232int copyout(const void *, void *, size_t); 233void copyout_noerr(const void *, void *, size_t); 234int xcopyout(const void *, void *, size_t); 235int xcopyout_nta(const void *, void *, size_t, int); 236int copyinstr(const char *, char *, size_t, size_t *); 237int copyinstr_noerr(const char *, char *, size_t, size_t *); 238int copyoutstr(const char *, char *, size_t, size_t *); 239int copyoutstr_noerr(const char *, char *, size_t, size_t *); 240int copystr(const char *, char *, size_t, size_t *); 241void bcopy(const void *, void *, size_t); 242void ucopy(const void *, void *, size_t); 243void pgcopy(const void *, void *, size_t); 244void ovbcopy(const void *, void *, size_t); 245void bzero(void *, size_t); 246void uzero(void *, size_t); 247int kcopy(const void *, void *, size_t); 248int kcopy_nta(const void *, void *, size_t, int); 249int kzero(void *, size_t); 250 251extern void *memset(void *, int, size_t); 252extern void *memcpy(void *, const void *, size_t); 253extern void *memmove(void *, const void *, size_t); 254extern int memcmp(const void *, const void *, size_t); 255 256int fuword8(const void *, uint8_t *); 257int fuword16(const void *, uint16_t *); 258int fuword32(const void *, uint32_t *); 259int fulword(const void *, ulong_t *); 260void fuword8_noerr(const void *, uint8_t *); 261void fuword16_noerr(const void *, uint16_t *); 262void fuword32_noerr(const void *, uint32_t *); 263void fulword_noerr(const void *, ulong_t *); 264 265#ifdef _LP64 266int fuword64(const void *, uint64_t *); 267void fuword64_noerr(const void *, uint64_t *); 268#endif 269 270int subyte(void *, uint8_t); 271int suword8(void *, uint8_t); 272int suword16(void *, uint16_t); 273int suword32(void *, uint32_t); 274int sulword(void *, ulong_t); 275void subyte_noerr(void *, uint8_t); 276void suword8_noerr(void *, uint8_t); 277void suword16_noerr(void *, uint16_t); 278void suword32_noerr(void *, uint32_t); 279void sulword_noerr(void *, ulong_t); 280 281#ifdef _LP64 282int suword64(void *, uint64_t); 283void suword64_noerr(void *, uint64_t); 284#endif 285 286#if !defined(_BOOT) 287int setjmp(label_t *); 288extern void longjmp(label_t *) 289 __NORETURN; 290#pragma unknown_control_flow(setjmp) 291#endif 292 293caddr_t caller(void); 294caddr_t callee(void); 295int getpcstack(pc_t *, int); 296int on_fault(label_t *); 297void no_fault(void); 298void halt(char *); 299int scanc(size_t, uchar_t *, uchar_t *, uchar_t); 300int movtuc(size_t, uchar_t *, uchar_t *, uchar_t *); 301int splr(int); 302int splhigh(void); 303int splhi(void); 304int splzs(void); 305int spl0(void); 306int spl6(void); 307int spl7(void); 308int spl8(void); 309void splx(int); 310void set_base_spl(void); 311int __ipltospl(int); 312 313void softcall_init(void); 314void softcall(void (*)(void *), void *); 315void softint(void); 316 317extern void sync_icache(caddr_t, uint_t); 318extern void sync_data_memory(caddr_t, size_t); 319extern void hot_patch_kernel_text(caddr_t, uint32_t, uint_t); 320 321void _insque(caddr_t, caddr_t); 322void _remque(caddr_t); 323 324/* casts to keep lint happy */ 325#define insque(q, p) _insque((caddr_t)q, (caddr_t)p) 326#define remque(q) _remque((caddr_t)q) 327 328#pragma unknown_control_flow(on_fault) 329 330struct timeval; 331extern void uniqtime(struct timeval *); 332struct timeval32; 333extern void uniqtime32(struct timeval32 *); 334 335uint_t page_num_pagesizes(void); 336size_t page_get_pagesize(uint_t n); 337 338extern int maxusers; 339extern int pidmax; 340 341extern void param_preset(void); 342extern void param_calc(int); 343extern void param_init(void); 344extern void param_check(void); 345 346#endif /* _KERNEL */ 347 348/* 349 * Structure of the system-entry table. 350 * 351 * Changes to struct sysent should maintain binary compatibility with 352 * loadable system calls, although the interface is currently private. 353 * 354 * This means it should only be expanded on the end, and flag values 355 * should not be reused. 356 * 357 * It is desirable to keep the size of this struct a power of 2 for quick 358 * indexing. 359 */ 360struct sysent { 361 char sy_narg; /* total number of arguments */ 362#ifdef _LP64 363 unsigned short sy_flags; /* various flags as defined below */ 364#else 365 unsigned char sy_flags; /* various flags as defined below */ 366#endif 367 int (*sy_call)(); /* argp, rvalp-style handler */ 368 krwlock_t *sy_lock; /* lock for loadable system calls */ 369 int64_t (*sy_callc)(); /* C-style call hander or wrapper */ 370}; 371 372extern struct sysent sysent[]; 373#ifdef _SYSCALL32_IMPL 374extern struct sysent sysent32[]; 375#endif 376 377extern struct sysent nosys_ent; /* entry for invalid system call */ 378 379#define NSYSCALL 256 /* number of system calls */ 380 381#define LOADABLE_SYSCALL(s) (s->sy_flags & SE_LOADABLE) 382#define LOADED_SYSCALL(s) (s->sy_flags & SE_LOADED) 383 384/* 385 * sy_flags values 386 * Values 1, 2, and 4 were used previously for SETJUMP, ASYNC, and IOSYS. 387 */ 388#define SE_32RVAL1 0x0 /* handler returns int32_t in rval1 */ 389#define SE_32RVAL2 0x1 /* handler returns int32_t in rval2 */ 390#define SE_64RVAL 0x2 /* handler returns int64_t in rvals */ 391#define SE_RVAL_MASK 0x3 /* mask of rval_t bits */ 392 393#define SE_LOADABLE 0x08 /* syscall is loadable */ 394#define SE_LOADED 0x10 /* syscall is completely loaded */ 395#define SE_NOUNLOAD 0x20 /* syscall never needs unload */ 396#define SE_ARGC 0x40 /* syscall takes C-style args */ 397 398/* 399 * Structure of the return-value parameter passed by reference to 400 * system entries. 401 */ 402union rval { 403 struct { 404 int r_v1; 405 int r_v2; 406 } r_v; 407 off_t r_off; 408 offset_t r_offset; 409 time_t r_time; 410 int64_t r_vals; 411}; 412#define r_val1 r_v.r_v1 413#define r_val2 r_v.r_v2 414 415typedef union rval rval_t; 416 417#ifdef _KERNEL 418 419extern void reset_syscall_args(void); 420extern int save_syscall_args(void); 421extern uint_t get_syscall_args(klwp_t *lwp, long *argp, int *nargsp); 422#ifdef _SYSCALL32_IMPL 423extern uint_t get_syscall32_args(klwp_t *lwp, int *argp, int *nargp); 424#endif 425 426extern uint_t set_errno(uint_t error); 427#pragma rarely_called(set_errno) 428 429extern int64_t syscall_ap(void); 430extern int64_t loadable_syscall(long, long, long, long, long, long, long, long); 431extern int64_t nosys(void); 432 433extern void swtch(void); 434 435extern uint_t kcpc_key; /* TSD key for performance counter context */ 436 437#ifdef __lint 438extern int __lintzero; /* for spoofing lint */ 439#endif 440 441 442/* 443 * initname holds the path to init. It is defined by main.c, may be set by 444 * bootflags.c, and is used by main.c:exec_init(). 445 */ 446#define INITNAME_SZ 32 447#define INITARGS_SZ 80 448 449extern char initname[INITNAME_SZ]; 450extern char initargs[INITARGS_SZ]; 451 452extern int exec_init(const char *, int, const char *); 453 454#endif /* _KERNEL */ 455 456#ifdef __cplusplus 457} 458#endif 459 460#endif /* _SYS_SYSTM_H */ 461