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