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 22 /* 23 * Copyright 2014 Nexenta Systems, Inc. All rights reserved. 24 * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved. 25 */ 26 27 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ 28 /* All Rights Reserved */ 29 30 /* 31 * University Copyright- Copyright (c) 1982, 1986, 1988 32 * The Regents of the University of California 33 * All Rights Reserved 34 * 35 * University Acknowledgment- Portions of this document are derived from 36 * software developed by the University of California, Berkeley, and its 37 * contributors. 38 */ 39 40 #ifndef _SYS_PARAM_H 41 #define _SYS_PARAM_H 42 43 #ifndef _ASM /* Avoid typedef headaches for assembly files */ 44 #include <sys/types.h> 45 #include <sys/isa_defs.h> 46 #endif /* _ASM */ 47 48 #include <sys/null.h> 49 50 #ifdef __cplusplus 51 extern "C" { 52 #endif 53 54 /* 55 * Fundamental variables; don't change too often. 56 */ 57 58 /* 59 * _POSIX_VDISABLE has historically been defined in <sys/param.h> since 60 * an early merge with AT&T source. It has also historically been defined 61 * in <sys/termios.h>. The POSIX standard, IEEE Std. 1003.1-1988 initially 62 * required the existence of _POSIX_VDISABLE in <sys/termios.h>. 63 * Subsequent versions of the IEEE Standard as well as the X/Open 64 * specifications required that _POSIX_VDISABLE be defined in <unistd.h> 65 * while still allowing for it's existence in other headers. With the 66 * introduction of XPG6, _POSIX_VDISABLE can only be defined in <unistd.h>. 67 */ 68 #if !defined(_XPG6) || defined(__EXTENSIONS__) 69 #ifndef _POSIX_VDISABLE 70 #define _POSIX_VDISABLE 0 /* Disable special character functions */ 71 #endif 72 #endif /* !defined(_XPG6) || defined(__EXTENSIONS__) */ 73 74 /* The actual size of the TTY input queue */ 75 #define _TTY_BUFSIZ 2048 76 77 /* 78 * These defines all have their historical value. The actual size of the tty 79 * buffer both for the line-editor in ldterm, and in general, is above as 80 * _TTY_BUFSIZ. 81 * 82 * We leave these defines at their historical value to match the behaviour of 83 * BSD and Linux. 84 */ 85 #ifndef MAX_INPUT 86 #define MAX_INPUT 512 /* Maximum bytes stored in the input queue */ 87 #endif 88 #ifndef MAX_CANON 89 #define MAX_CANON 256 /* Maximum bytes for canonical processing */ 90 #endif 91 #define CANBSIZ 256 /* max size of typewriter line */ 92 93 94 #define UID_NOBODY 60001 /* user ID no body */ 95 #define GID_NOBODY UID_NOBODY 96 #define UID_UNKNOWN 96 97 #define GID_UNKNOWN UID_UNKNOWN 98 #define UID_DLADM 15 99 #define UID_NETADM 16 100 #define GID_NETADM 65 101 #define GID_TTY 7 /* traditional tty group id */ 102 #define UID_NOACCESS 60002 /* user ID no access */ 103 104 #ifdef _KERNEL 105 #define MAX_TASKID 999999 106 #define MAX_MAXPID 999999 107 #define MAXEPHUID 0xfffffffcu /* max ephemeral user id */ 108 109 #define FAMOUS_PID_SCHED 0 110 #define FAMOUS_PID_INIT 1 111 #define FAMOUS_PID_PAGEOUT 2 112 #define FAMOUS_PID_FSFLUSH 3 113 #define FAMOUS_PIDS 4 114 #endif 115 116 #ifdef DEBUG 117 #define DEFAULT_MAXPID 999999 118 #define DEFAULT_JUMPPID 100000 119 #else 120 #define DEFAULT_MAXPID 30000 121 #define DEFAULT_JUMPPID 0 122 #endif 123 124 #define MAXUID 2147483647 /* max user id */ 125 126 #define MAXPROJID MAXUID /* max project id */ 127 #define MAXLINK 32767 /* max links */ 128 129 #define MINEPHUID 0x80000000u /* min ephemeral user id */ 130 131 #define NMOUNT 40 /* est. of # mountable fs for quota calc */ 132 133 #define NOFILE 20 /* this define is here for */ 134 /* compatibility purposes only */ 135 /* and will be removed in a */ 136 /* later release */ 137 138 /* 139 * These define the maximum and minimum allowable values of the 140 * configurable parameter NGROUPS_MAX. 141 */ 142 #define NGROUPS_UMIN 0 143 #define NGROUPS_UMAX 1024 144 #define NGROUPS_OLDMAX 32 145 146 /* 147 * NGROUPS_MAX_DEFAULT: *MUST* match NGROUPS_MAX value in limits.h. 148 */ 149 #define NGROUPS_MAX_DEFAULT 16 150 151 /* 152 * Default process priority. Keep it in sync with limits.h. 153 */ 154 #define NZERO 20 155 156 /* 157 * Fundamental constants of the implementation--cannot be changed easily. 158 */ 159 160 #if !defined(_ASM) 161 #define NBPW sizeof (int) /* number of bytes in an integer */ 162 #endif /* _ASM */ 163 164 #define CMASK 022 /* default mask for file creation */ 165 #define CDLIMIT (1L<<11) /* default max write address */ 166 #define NBPS 0x20000 /* Number of bytes per segment */ 167 #define NBPSCTR 512 /* Bytes per disk sector. */ 168 #define UBSIZE 512 /* unix block size. */ 169 #define SCTRSHFT 9 /* Shift for BPSECT. */ 170 171 #ifdef _LITTLE_ENDIAN 172 #define lobyte(X) (((unsigned char *)&(X))[0]) 173 #define hibyte(X) (((unsigned char *)&(X))[1]) 174 #define loword(X) (((ushort_t *)&(X))[0]) 175 #define hiword(X) (((ushort_t *)&(X))[1]) 176 #endif 177 #ifdef _BIG_ENDIAN 178 #define lobyte(X) (((unsigned char *)&(X))[1]) 179 #define hibyte(X) (((unsigned char *)&(X))[0]) 180 #define loword(X) (((ushort_t *)&(X))[1]) 181 #define hiword(X) (((ushort_t *)&(X))[0]) 182 #endif 183 184 /* REMOTE -- whether machine is primary, secondary, or regular */ 185 #define SYSNAME 9 /* # chars in system name */ 186 #define PREMOTE 39 187 188 /* 189 * MAXPATHLEN defines the longest permissible path length, 190 * including the terminating null, after expanding symbolic links. 191 * TYPICALMAXPATHLEN is used in a few places as an optimization 192 * with a local buffer on the stack to avoid kmem_alloc(). 193 * MAXSYMLINKS defines the maximum number of symbolic links 194 * that may be expanded in a path name. It should be set high 195 * enough to allow all legitimate uses, but halt infinite loops 196 * reasonably quickly. 197 * MAXNAMELEN is the length (including the terminating null) of 198 * the longest permissible file (component) name. 199 */ 200 #define MAXPATHLEN 1024 201 #define TYPICALMAXPATHLEN 64 202 #define MAXSYMLINKS 20 203 #define MAXNAMELEN 256 204 205 /* 206 * MAXLINKNAMELEN defines the longest possible permitted datalink name, 207 * including the terminating NUL. Note that this must not be larger 208 * than related networking constants such as LIFNAMSIZ. 209 */ 210 #define MAXLINKNAMELEN 32 211 212 #ifndef NADDR 213 #define NADDR 13 214 #endif 215 216 /* 217 * The following are defined to be the same as 218 * defined in /usr/include/limits.h. They are 219 * needed for pipe and FIFO compatibility. 220 */ 221 #ifndef PIPE_BUF /* max # bytes atomic in write to a pipe */ 222 #define PIPE_BUF 5120 223 #endif /* PIPE_BUF */ 224 225 #ifndef PIPE_MAX /* max # bytes written to a pipe in a write */ 226 #define PIPE_MAX 5120 227 #endif /* PIPE_MAX */ 228 229 #ifndef NBBY 230 #define NBBY 8 /* number of bits per byte */ 231 #endif 232 233 /* macros replacing interleaving functions */ 234 #define dkblock(bp) ((bp)->b_blkno) 235 #define dkunit(bp) (minor((bp)->b_dev) >> 3) 236 237 /* 238 * File system parameters and macros. 239 * 240 * The file system is made out of blocks of at most MAXBSIZE units, 241 * with smaller units (fragments) only in the last direct block. 242 * MAXBSIZE primarily determines the size of buffers in the buffer 243 * pool. It may be made larger without any effect on existing 244 * file systems; however making it smaller make make some file 245 * systems unmountable. 246 * 247 * Note that the blocked devices are assumed to have DEV_BSIZE 248 * "sectors" and that fragments must be some multiple of this size. 249 */ 250 #define MAXBSIZE 8192 251 #define DEV_BSIZE 512 252 #define DEV_BSHIFT 9 /* log2(DEV_BSIZE) */ 253 #define MAXFRAG 8 254 #ifdef _SYSCALL32 255 #define MAXOFF32_T 0x7fffffff 256 #endif 257 #ifdef _LP64 258 #define MAXOFF_T 0x7fffffffffffffffl 259 #define MAXOFFSET_T 0x7fffffffffffffffl 260 #else 261 #define MAXOFF_T 0x7fffffffl 262 #ifdef _LONGLONG_TYPE 263 #define MAXOFFSET_T 0x7fffffffffffffffLL 264 #else 265 #define MAXOFFSET_T 0x7fffffff 266 #endif 267 #endif /* _LP64 */ 268 269 #define btodb(bytes) /* calculates (bytes / DEV_BSIZE) */ \ 270 ((unsigned long)(bytes) >> DEV_BSHIFT) 271 #define dbtob(db) /* calculates (db * DEV_BSIZE) */ \ 272 ((unsigned long)(db) << DEV_BSHIFT) 273 274 /* 64 bit versions of btodb and dbtob */ 275 #define lbtodb(bytes) /* calculates (bytes / DEV_BSIZE) */ \ 276 ((u_offset_t)(bytes) >> DEV_BSHIFT) 277 #define ldbtob(db) /* calculates (db * DEV_BSIZE) */ \ 278 ((u_offset_t)(db) << DEV_BSHIFT) 279 280 #ifndef _ASM /* Avoid typedef headaches for assembly files */ 281 #ifndef NODEV 282 #define NODEV (dev_t)(-1l) 283 #ifdef _SYSCALL32 284 #define NODEV32 (dev32_t)(-1) 285 #endif /* _SYSCALL32 */ 286 #endif /* NODEV */ 287 #endif /* _ASM */ 288 289 /* 290 * Size of arg list passed in by user. 291 */ 292 #define NCARGS32 0x100000 293 #define NCARGS64 0x200000 294 #ifdef _LP64 295 #define NCARGS NCARGS64 296 #else /* _LP64 */ 297 #define NCARGS NCARGS32 298 #endif /* _LP64 */ 299 300 /* 301 * Scale factor for scaled integers used to count 302 * %cpu time and load averages. 303 */ 304 #define FSHIFT 8 /* bits to right of fixed binary point */ 305 #define FSCALE (1<<FSHIFT) 306 307 /* 308 * Delay units are in microseconds. 309 * 310 * XXX These macros are not part of the DDI! 311 */ 312 #if defined(_KERNEL) && !defined(_ASM) 313 extern void drv_usecwait(clock_t); 314 #define DELAY(n) drv_usecwait(n) 315 #define CDELAY(c, n) \ 316 { \ 317 register int N = n; \ 318 while (--N > 0) { \ 319 if (c) \ 320 break; \ 321 drv_usecwait(1); \ 322 } \ 323 } 324 #endif /* defined(_KERNEL) && !defined(_ASM) */ 325 326 #ifdef __cplusplus 327 } 328 #endif 329 330 /* 331 * The following is to free utilities from machine dependencies within 332 * an architecture. Must be included after definition of DEV_BSIZE. 333 */ 334 335 #if defined(_KERNEL) || defined(_KMEMUSER) || defined(_BOOT) 336 337 #if defined(_MACHDEP) 338 #include <sys/machparam.h> 339 #endif 340 341 #ifdef __cplusplus 342 extern "C" { 343 #endif 344 345 #if defined(_KERNEL) && !defined(_ASM) 346 extern int cpu_decay_factor; 347 extern pid_t maxpid; 348 extern pid_t jump_pid; 349 350 extern uintptr_t _kernelbase; 351 extern uintptr_t _userlimit; 352 extern uintptr_t _userlimit32; 353 #endif /* defined(_KERNEL) && !defined(_ASM) */ 354 355 /* 356 * These three variables have been added within the #if defined(lint) 357 * below to ensure visibility to lint. This is a short term workaround 358 * to handle poor interaction between SS12 lint and these variables. 359 * CR 6742611 has been logged to address these issues. 360 */ 361 #if defined(lint) 362 extern int snooping; 363 extern uint_t snoop_interval; 364 extern const unsigned int _pageshift; 365 #endif /* lint */ 366 367 #if !defined(_MACHDEP) 368 369 /* 370 * Implementation architecture independent sections of the kernel use 371 * this section. 372 */ 373 #if defined(_KERNEL) && !defined(_ASM) 374 extern int hz; 375 extern int snooping; 376 extern uint_t snoop_interval; 377 extern const unsigned long _pagesize; 378 extern const unsigned int _pageshift; 379 extern const unsigned long _pageoffset; 380 extern const unsigned long long _pagemask; 381 extern const unsigned long _mmu_pagesize; 382 extern const unsigned int _mmu_pageshift; 383 extern const unsigned long _mmu_pageoffset; 384 extern const unsigned long _mmu_pagemask; 385 extern const unsigned long _defaultstksz; 386 extern const unsigned int _nbpg; 387 extern const int _ncpu; 388 extern const int _ncpu_log2; 389 extern const int _ncpu_p2; 390 extern const int _clsize; 391 #endif /* defined(_KERNEL) && !defined(_ASM) */ 392 393 /* Any additions to these #defines must be reflected in mdb_param.h+mdb_ks.c */ 394 #define PAGESIZE _pagesize 395 #define PAGESHIFT _pageshift 396 #define PAGEOFFSET _pageoffset 397 #define PAGEMASK _pagemask 398 #define MMU_PAGESIZE _mmu_pagesize 399 #define MMU_PAGESHIFT _mmu_pageshift 400 #define MMU_PAGEOFFSET _mmu_pageoffset 401 #define MMU_PAGEMASK _mmu_pagemask 402 403 #define KERNELBASE _kernelbase 404 #define USERLIMIT _userlimit 405 #define USERLIMIT32 _userlimit32 406 #define DEFAULTSTKSZ _defaultstksz 407 #define NCPU _ncpu 408 #define NCPU_LOG2 _ncpu_log2 409 #define NCPU_P2 _ncpu_p2 410 411 #endif /* defined(_MACHDEP) */ 412 413 /* 414 * Some random macros for units conversion. 415 * 416 * These are machine independent but contain constants (*PAGESHIFT) which 417 * are only defined in the machine dependent file. 418 */ 419 420 /* 421 * MMU pages to bytes, and back (with and without rounding) 422 */ 423 #define mmu_ptob(x) ((x) << MMU_PAGESHIFT) 424 #define mmu_btop(x) (((x)) >> MMU_PAGESHIFT) 425 #define mmu_btopr(x) ((((x) + MMU_PAGEOFFSET) >> MMU_PAGESHIFT)) 426 427 /* 428 * 2 versions of pages to disk blocks 429 */ 430 #define mmu_ptod(x) ((x) << (MMU_PAGESHIFT - DEV_BSHIFT)) 431 #define ptod(x) ((x) << (PAGESHIFT - DEV_BSHIFT)) 432 433 /* 434 * pages to bytes, and back (with and without rounding) 435 * Large Files: The explicit cast of x to unsigned int is deliberately 436 * removed as part of large files work. We pass longlong values to 437 * theses macros. 438 * 439 * Cast the input to ptob() to be a page count. This enforces 64-bit 440 * math on 64-bit kernels. For 32-bit kernels, callers must explicitly 441 * cast the input to be a 64-bit type if values greater than 4GB/PAGESIZE 442 * are possible. 443 */ 444 445 #ifdef _LP64 446 #define ptob(x) (((pgcnt_t)(x)) << PAGESHIFT) 447 #else 448 #define ptob(x) ((x) << PAGESHIFT) 449 #endif /* _LP64 */ 450 #define btop(x) (((x) >> PAGESHIFT)) 451 #define btopr(x) ((((x) + PAGEOFFSET) >> PAGESHIFT)) 452 453 /* 454 * disk blocks to pages, rounded and truncated 455 */ 456 #define NDPP (PAGESIZE/DEV_BSIZE) /* # of disk blocks per page */ 457 #define dtop(DD) (((DD) + NDPP - 1) >> (PAGESHIFT - DEV_BSHIFT)) 458 #define dtopt(DD) ((DD) >> (PAGESHIFT - DEV_BSHIFT)) 459 460 /* 461 * kB to pages and back 462 */ 463 #define kbtop(x) ((x) >> (PAGESHIFT - 10)) 464 #define ptokb(x) ((x) << (PAGESHIFT - 10)) 465 466 /* 467 * POSIX.4 related configuration parameters 468 */ 469 #define _AIO_LISTIO_MAX (4096) 470 #define _AIO_MAX (-1) 471 #define _MQ_OPEN_MAX (-1) 472 #define _MQ_PRIO_MAX (32) 473 #define _SEM_NSEMS_MAX INT_MAX 474 #define _SEM_VALUE_MAX INT_MAX 475 476 #ifdef __cplusplus 477 } 478 #endif 479 480 #else /* defined(_KERNEL) || defined(_KMEMUSER) || defined(_BOOT) */ 481 482 /* 483 * The following are assorted machine dependent values which can be 484 * obtained in a machine independent manner through sysconf(2) or 485 * sysinfo(2). In order to guarantee that these provide the expected 486 * value at all times, the System Private interface (leading underscore) 487 * is used. 488 */ 489 490 #include <sys/unistd.h> 491 492 #ifdef __cplusplus 493 extern "C" { 494 #endif 495 496 #if !defined(_ASM) 497 extern long _sysconf(int); /* System Private interface to sysconf() */ 498 #endif /* !defined(_ASM) */ 499 500 #define HZ ((clock_t)_sysconf(_SC_CLK_TCK)) 501 #define TICK (1000000000/((clock_t)_sysconf(_SC_CLK_TCK))) 502 #define PAGESIZE (_sysconf(_SC_PAGESIZE)) 503 #define PAGEOFFSET (PAGESIZE - 1) 504 #define PAGEMASK (~PAGEOFFSET) 505 #define MAXPID ((pid_t)_sysconf(_SC_MAXPID)) 506 #define MAXEPHUID ((uid_t)_sysconf(_SC_EPHID_MAX)) 507 508 #ifdef __cplusplus 509 } 510 #endif 511 512 #endif /* defined(_KERNEL) || defined(_KMEMUSER) || defined(_BOOT) */ 513 514 #endif /* _SYS_PARAM_H */ 515