#include <sys/types.h>
#include <sys/time.h>
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/signal.h>
#include <sys/sysmacros.h>
#include <sys/cmn_err.h>
#include <sys/user.h>
#include <sys/proc.h>
#include <sys/task.h>
#include <sys/project.h>
#include <sys/klwp.h>
#include <sys/vnode.h>
#include <sys/file.h>
#include <sys/fcntl.h>
#include <sys/flock.h>
#include <sys/var.h>
#include <sys/stream.h>
#include <sys/strsubr.h>
#include <sys/conf.h>
#include <sys/class.h>
#include <sys/ts.h>
#include <sys/rt.h>
#include <sys/exec.h>
#include <sys/exechdr.h>
#include <sys/buf.h>
#include <sys/resource.h>
#include <vm/seg.h>
#include <vm/pvn.h>
#include <vm/seg_kmem.h>
#include <sys/vmparam.h>
#include <sys/machparam.h>
#include <sys/utsname.h>
#include <sys/kmem.h>
#include <sys/stack.h>
#include <sys/modctl.h>
#include <sys/fdbuffer.h>
#include <sys/cyclic_impl.h>
#include <sys/disp.h>
#include <sys/tuneable.h>
#include <sys/systeminfo.h>
#include <sys/vmem.h>
#include <sys/clock.h>
#include <sys/clock_impl.h>
#include <sys/serializer.h>
struct modctl modules;
char *default_path;
struct swapinfo *swapinfo;
proc_t *practive;
uint_t nproc;
proc_t p0;
struct plock p0lock;
klwp_t lwp0;
task_t *task0p;
kproject_t *proj0p;
const unsigned long _pagesize = (unsigned long)PAGESIZE;
const unsigned int _pageshift = (unsigned int)PAGESHIFT;
const unsigned long _pageoffset = (unsigned long)PAGEOFFSET;
const u_longlong_t _pagemask = (u_longlong_t)PAGEMASK;
const unsigned long _mmu_pagesize = (unsigned long)MMU_PAGESIZE;
const unsigned int _mmu_pageshift = (unsigned int)MMU_PAGESHIFT;
const unsigned long _mmu_pageoffset = (unsigned long)MMU_PAGEOFFSET;
const unsigned long _mmu_pagemask = (unsigned long)MMU_PAGEMASK;
uintptr_t _kernelbase = (uintptr_t)KERNELBASE;
uintptr_t _userlimit = (uintptr_t)USERLIMIT;
uintptr_t _userlimit32 = (uintptr_t)USERLIMIT32;
const unsigned int _diskrpm = (unsigned int)DISKRPM;
const unsigned long _pgthresh = (unsigned long)PGTHRESH;
const unsigned int _maxslp = (unsigned int)MAXSLP;
const unsigned long _maxhandspreadpages = (unsigned long)MAXHANDSPREADPAGES;
const int _ncpu = (int)NCPU;
const int _ncpu_log2 = (int)NCPU_LOG2;
const int _ncpu_p2 = (int)NCPU_P2;
const unsigned long _defaultstksz = (unsigned long)DEFAULTSTKSZ;
const unsigned int _nbpg = (unsigned int)MMU_PAGESIZE;
#define HIRES_HZ_DEFAULT 1000
int hz = HZ_DEFAULT;
int hires_hz = HIRES_HZ_DEFAULT;
int hires_tick = 1;
int cpu_decay_factor = 10;
int max_hres_adj;
int tick_per_msec;
int msec_per_tick;
int usec_per_tick;
int nsec_per_tick;
time_res_t time_res[TR_COUNT];
#define SNOOP_INTERVAL_MIN (MICROSEC)
#define SNOOP_INTERVAL_DEFAULT (50 * MICROSEC)
int snooping = 0;
uint_t snoop_interval = SNOOP_INTERVAL_DEFAULT;
extern void system_taskq_init(void);
extern void binit(void);
extern void space_init(void);
extern void dnlc_init(void);
extern void vfsinit(void);
extern void finit(void);
extern void strinit(void);
extern void flk_init(void);
extern void ftrace_init(void);
extern void softcall_init(void);
extern void ttyinit(void);
extern void schedctl_init(void);
extern void deadman_init(void);
extern void clock_timer_init(void);
extern void clock_realtime_init(void);
extern void clock_highres_init(void);
extern void clock_thread_init(void);
extern void clock_process_init(void);
extern void clock_tick_mp_init(void);
extern void cu_init(void);
extern void callout_mp_init(void);
extern void cpu_seq_tbl_init(void);
void (*init_tbl[])(void) = {
system_taskq_init,
binit,
space_init,
dnlc_init,
vfsinit,
finit,
strinit,
serializer_init,
softcall_init,
ttyinit,
as_init,
pvn_init,
anon_init,
segvn_init,
flk_init,
cpu_seq_tbl_init,
schedctl_init,
fdb_init,
deadman_init,
clock_timer_init,
clock_realtime_init,
clock_highres_init,
clock_thread_init,
clock_process_init,
NULL
};
#if defined(__sparc)
extern void siron_mp_init();
#endif
void (*mp_init_tbl[])(void) = {
ftrace_init,
cyclic_mp_init,
#if defined(__sparc)
siron_mp_init,
#endif
clock_tick_mp_init,
cu_init,
callout_mp_init,
0
};
int maxusers;
int pidmax = DEFAULT_MAXPID;
pid_t jump_pid = DEFAULT_JUMPPID;
#define DEFAULT_AUTOUP 30
int autoup = DEFAULT_AUTOUP;
int bufhwm = 0;
int bufhwm_pct = 0;
int maxpid;
int max_nprocs;
int maxuprc;
int reserved_procs;
int nthread = 1;
int ufs_ninode;
int ndquot;
short elfmagic = 0x7f45;
short intpmagic = 0x2321;
short jmagic = 0x504b;
short nomagic = 0;
#define ELF32MAGIC_STRING "\x7f""ELF\x1"
#define ELF64MAGIC_STRING "\x7f""ELF\x2"
#define INTPMAGIC_STRING "#!"
#define JAVAMAGIC_STRING "PK\003\004"
#define NOMAGIC_STRING ""
#define SHBIN_CNTL(x) ((x)&037)
#define SHBINMAGIC_STRING {SHBIN_CNTL('k'), SHBIN_CNTL('s'), SHBIN_CNTL('h'), 0}
#define SHBINMAGIC_LEN 4
char elf32magicstr[] = ELF32MAGIC_STRING;
char elf64magicstr[] = ELF64MAGIC_STRING;
char intpmagicstr[] = INTPMAGIC_STRING;
char shbinmagicstr[] = SHBINMAGIC_STRING;
char javamagicstr[] = JAVAMAGIC_STRING;
char nomagicstr[] = NOMAGIC_STRING;
char *execswnames[] = {
"elfexec",
#ifdef _LP64
"elfexec",
#endif
"intpexec",
"shbinexec",
"javaexec",
NULL,
NULL,
NULL
};
struct execsw execsw[] = {
{ elf32magicstr, 0, 5, NULL, NULL, NULL },
#ifdef _LP64
{ elf64magicstr, 0, 5, NULL, NULL, NULL },
#endif
{ intpmagicstr, 0, 2, NULL, NULL, NULL },
{ shbinmagicstr, 0, SHBINMAGIC_LEN, NULL, NULL, NULL },
{ javamagicstr, 0, 4, NULL, NULL, NULL },
{ nomagicstr, 0, 0, NULL, NULL, NULL },
{ nomagicstr, 0, 0, NULL, NULL, NULL },
{ nomagicstr, 0, 0, NULL, NULL, NULL },
{ nomagicstr, 0, 0, NULL, NULL, NULL }
};
int nexectype = sizeof (execsw) / sizeof (execsw[0]);
kmutex_t execsw_lock;
#define RLIM_FD_CUR 0x10000
#define RLIM_FD_MAX 0x10000
uint_t rlim_fd_cur = RLIM_FD_CUR;
uint_t rlim_fd_max = RLIM_FD_MAX;
int nstrpush = 9;
ssize_t strctlsz = 1024;
ssize_t strmsgsz = 0x10000;
int rstchown = 1;
int ngroups_max = NGROUPS_MAX_DEFAULT;
pri_t maxclsyspri = MAXCLSYSPRI;
pri_t minclsyspri = MINCLSYSPRI;
char sys_name[] = "SYS";
extern pri_t sys_init(id_t, int, classfuncs_t **);
extern classfuncs_t sys_classfuncs;
sclass_t sclass[] = {
{ "SYS", sys_init, &sys_classfuncs, STATIC_SCHED, 0 },
{ "", NULL, NULL, NULL, 0 },
{ "", NULL, NULL, NULL, 0 },
{ "", NULL, NULL, NULL, 0 },
{ "", NULL, NULL, NULL, 0 },
{ "", NULL, NULL, NULL, 0 },
{ "", NULL, NULL, NULL, 0 },
{ "", NULL, NULL, NULL, 0 },
{ "", NULL, NULL, NULL, 0 },
{ "", NULL, NULL, NULL, 0 }
};
int loaded_classes = 1;
kmutex_t class_lock;
int nclass = sizeof (sclass) / sizeof (sclass_t);
char initcls[] = "TS";
char *defaultclass = initcls;
tune_t tune;
int tune_t_gpgslo = 25;
#define DEFAULT_TUNE_T_FSFLUSHR 1
int tune_t_fsflushr = DEFAULT_TUNE_T_FSFLUSHR;
int tune_t_minarmem = 25;
int tune_t_minasmem = 25;
int tune_t_flckrec = 512;
pgcnt_t pages_pp_maximum = 0;
int boothowto;
struct var v;
char hw_serial[HW_HOSTID_LEN] = "0";
#if defined(__sparc)
char architecture[] = "sparcv9";
char architecture_32[] = "sparc";
char hw_provider[] = "Oracle Corporation";
#elif defined(__amd64)
char architecture[] = "amd64";
char architecture_32[] = "i386";
char hw_provider[SYS_NMLN] = "";
#else
#error "unknown processor architecture"
#endif
char srpc_domain[SYS_NMLN] = "";
char platform[SYS_NMLN] = "";
char *isa_list = architecture;
static pgcnt_t original_physmem = 0;
#define MIN_DEFAULT_MAXUSERS 8u
#define MAX_DEFAULT_MAXUSERS 2048u
#define MAX_MAXUSERS 4096u
void
param_preset(void)
{
original_physmem = physmem;
}
void
param_calc(int platform_max_nprocs)
{
#if defined(__sparc)
if (physmem > original_physmem) {
physmem = original_physmem;
cmn_err(CE_NOTE, "physmem limited to %ld", physmem);
}
#endif
if (maxusers == 0) {
pgcnt_t physmegs = physmem >> (20 - PAGESHIFT);
pgcnt_t virtmegs = vmem_size(heap_arena, VMEM_FREE) >> 20;
maxusers = MIN(MAX(MIN(physmegs, virtmegs),
MIN_DEFAULT_MAXUSERS), MAX_DEFAULT_MAXUSERS);
}
if (maxusers > MAX_MAXUSERS) {
maxusers = MAX_MAXUSERS;
cmn_err(CE_NOTE, "maxusers limited to %d", MAX_MAXUSERS);
}
#ifdef DEBUG
maxusers = (3 * maxusers) / 4;
#endif
if (reserved_procs == 0)
reserved_procs = 5;
if (pidmax < reserved_procs || pidmax > MAX_MAXPID)
maxpid = MAX_MAXPID;
else
maxpid = pidmax;
if (max_nprocs == 0)
max_nprocs = (10 + 16 * maxusers);
if (platform_max_nprocs > 0 && max_nprocs > platform_max_nprocs)
max_nprocs = platform_max_nprocs;
if (max_nprocs > maxpid)
max_nprocs = maxpid;
if (maxuprc == 0)
maxuprc = (max_nprocs - reserved_procs);
}
void
param_init(void)
{
v.v_proc = max_nprocs;
v.v_maxupttl = max_nprocs - reserved_procs;
v.v_maxsyspri = (int)maxclsyspri;
v.v_maxup = MIN(maxuprc, v.v_maxupttl);
v.v_autoup = autoup;
tune.t_gpgslo = tune_t_gpgslo;
tune.t_fsflushr = tune_t_fsflushr;
tune.t_minarmem = tune_t_minarmem;
tune.t_minasmem = tune_t_minasmem;
tune.t_flckrec = tune_t_flckrec;
if (rlim_fd_cur > rlim_fd_max)
rlim_fd_cur = rlim_fd_max;
if (hires_tick)
hz = hires_hz;
tick_per_msec = hz / MILLISEC;
msec_per_tick = MILLISEC / hz;
usec_per_tick = MICROSEC / hz;
nsec_per_tick = NANOSEC / hz;
max_hres_adj = nsec_per_tick >> ADJ_SHIFT;
time_res[TR_NANOSEC] = NANOSEC / NANOSEC;
time_res[TR_MICROSEC] = NANOSEC / MICROSEC;
time_res[TR_MILLISEC] = NANOSEC / MILLISEC;
time_res[TR_SEC] = NANOSEC / SEC;
time_res[TR_CLOCK_TICK] = nsec_per_tick;
}
void
param_check(void)
{
#if defined(__x86)
if (physmem != original_physmem) {
cmn_err(CE_NOTE, "physmem cannot be modified to 0x%lx"
" via /etc/system. Please use eeprom(8) instead.",
physmem);
physmem = original_physmem;
}
#endif
if (ngroups_max < NGROUPS_UMIN)
ngroups_max = NGROUPS_UMIN;
if (ngroups_max > NGROUPS_UMAX)
ngroups_max = NGROUPS_UMAX;
if (ngroups_max > NGROUPS_OLDMAX &&
strctlsz < (ngroups_max - NGROUPS_OLDMAX) * sizeof (gid_t) + 1024) {
strctlsz = (ngroups_max - NGROUPS_OLDMAX) * sizeof (gid_t) +
1024;
}
if (autoup <= 0) {
autoup = DEFAULT_AUTOUP;
cmn_err(CE_WARN, "autoup <= 0; defaulting to %d", autoup);
}
if (tune_t_fsflushr <= 0) {
tune_t_fsflushr = DEFAULT_TUNE_T_FSFLUSHR;
cmn_err(CE_WARN, "tune_t_fsflushr <= 0; defaulting to %d",
tune_t_fsflushr);
}
if (jump_pid < 0 || jump_pid >= pidmax) {
jump_pid = 0;
cmn_err(CE_WARN, "jump_pid < 0 or >= pidmax; ignored");
}
if (snoop_interval < SNOOP_INTERVAL_MIN) {
snoop_interval = SNOOP_INTERVAL_DEFAULT;
cmn_err(CE_WARN, "snoop_interval < minimum (%d); defaulting"
" to %d", SNOOP_INTERVAL_MIN, SNOOP_INTERVAL_DEFAULT);
}
}