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