+ rval = sysctl_handle_string(oidp, arg1, arg2, req);
+
+ if (req->newptr) {
+ IORegistrySetOSBuildVersion((char *)arg1);
+ }
+
+ return rval;
+}
+
+SYSCTL_PROC(_kern, KERN_OSVERSION, osversion,
+ CTLFLAG_RW | CTLFLAG_KERN | CTLTYPE_STRING | CTLFLAG_LOCKED,
+ osversion, 256 /* OSVERSIZE*/,
+ sysctl_osversion, "A", "");
+
+STATIC int
+sysctl_sysctl_bootargs
+(__unused struct sysctl_oid *oidp, __unused void *arg1, __unused int arg2, struct sysctl_req *req)
+{
+ int error;
+ char buf[256];
+
+ strlcpy(buf, PE_boot_args(), 256);
+ error = sysctl_io_string(req, buf, 256, 0, NULL);
+ return(error);
+}
+
+SYSCTL_PROC(_kern, OID_AUTO, bootargs,
+ CTLFLAG_LOCKED | CTLFLAG_RD | CTLFLAG_KERN | CTLTYPE_STRING,
+ NULL, 0,
+ sysctl_sysctl_bootargs, "A", "bootargs");
+
+SYSCTL_INT(_kern, KERN_MAXFILES, maxfiles,
+ CTLFLAG_RW | CTLFLAG_KERN | CTLFLAG_LOCKED,
+ &maxfiles, 0, "");
+SYSCTL_INT(_kern, KERN_ARGMAX, argmax,
+ CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED,
+ (int *)NULL, ARG_MAX, "");
+SYSCTL_INT(_kern, KERN_POSIX1, posix1version,
+ CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED,
+ (int *)NULL, _POSIX_VERSION, "");
+SYSCTL_INT(_kern, KERN_NGROUPS, ngroups,
+ CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED,
+ (int *)NULL, NGROUPS_MAX, "");
+SYSCTL_INT(_kern, KERN_JOB_CONTROL, job_control,
+ CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED,
+ (int *)NULL, 1, "");
+#if 1 /* _POSIX_SAVED_IDS from <unistd.h> */
+SYSCTL_INT(_kern, KERN_SAVED_IDS, saved_ids,
+ CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED,
+ (int *)NULL, 1, "");
+#else
+SYSCTL_INT(_kern, KERN_SAVED_IDS, saved_ids,
+ CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED,
+ NULL, 0, "");
+#endif
+SYSCTL_INT(_kern, OID_AUTO, num_files,
+ CTLFLAG_RD | CTLFLAG_LOCKED,
+ &nfiles, 0, "");
+SYSCTL_COMPAT_INT(_kern, OID_AUTO, num_vnodes,
+ CTLFLAG_RD | CTLFLAG_LOCKED,
+ &numvnodes, 0, "");
+SYSCTL_INT(_kern, OID_AUTO, num_tasks,
+ CTLFLAG_RD | CTLFLAG_LOCKED,
+ &task_max, 0, "");
+SYSCTL_INT(_kern, OID_AUTO, num_threads,
+ CTLFLAG_RD | CTLFLAG_LOCKED,
+ &thread_max, 0, "");
+SYSCTL_INT(_kern, OID_AUTO, num_taskthreads,
+ CTLFLAG_RD | CTLFLAG_LOCKED,
+ &task_threadmax, 0, "");
+
+STATIC int
+sysctl_maxvnodes (__unused struct sysctl_oid *oidp, __unused void *arg1, __unused int arg2, struct sysctl_req *req)
+{
+ int oldval = desiredvnodes;
+ int error = sysctl_io_number(req, desiredvnodes, sizeof(int), &desiredvnodes, NULL);
+
+ if (oldval != desiredvnodes) {
+ reset_vmobjectcache(oldval, desiredvnodes);
+ resize_namecache(desiredvnodes);
+ }
+
+ return(error);
+}
+
+SYSCTL_INT(_kern, OID_AUTO, namecache_disabled,
+ CTLFLAG_RW | CTLFLAG_LOCKED,
+ &nc_disabled, 0, "");
+
+SYSCTL_PROC(_kern, KERN_MAXVNODES, maxvnodes,
+ CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_LOCKED,
+ 0, 0, sysctl_maxvnodes, "I", "");
+
+SYSCTL_PROC(_kern, KERN_MAXPROC, maxproc,
+ CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_LOCKED,
+ 0, 0, sysctl_maxproc, "I", "");
+
+SYSCTL_PROC(_kern, KERN_AIOMAX, aiomax,
+ CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_LOCKED,
+ 0, 0, sysctl_aiomax, "I", "");
+
+SYSCTL_PROC(_kern, KERN_AIOPROCMAX, aioprocmax,
+ CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_LOCKED,
+ 0, 0, sysctl_aioprocmax, "I", "");
+
+SYSCTL_PROC(_kern, KERN_AIOTHREADS, aiothreads,
+ CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_LOCKED,
+ 0, 0, sysctl_aiothreads, "I", "");
+
+STATIC int
+sysctl_securelvl
+(__unused struct sysctl_oid *oidp, __unused void *arg1, __unused int arg2, struct sysctl_req *req)
+{
+ int new_value, changed;
+ int error = sysctl_io_number(req, securelevel, sizeof(int), &new_value, &changed);
+ if (changed) {
+ if (!(new_value < securelevel && req->p->p_pid != 1)) {
+ proc_list_lock();
+ securelevel = new_value;
+ proc_list_unlock();
+ } else {
+ error = EPERM;
+ }
+ }
+ return(error);
+}
+
+SYSCTL_PROC(_kern, KERN_SECURELVL, securelevel,
+ CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_LOCKED,
+ 0, 0, sysctl_securelvl, "I", "");
+
+
+STATIC int
+sysctl_domainname
+(__unused struct sysctl_oid *oidp, __unused void *arg1, __unused int arg2, struct sysctl_req *req)
+{
+ int error, changed;
+ error = sysctl_io_string(req, domainname, sizeof(domainname), 0, &changed);
+ if (changed) {
+ domainnamelen = strlen(domainname);
+ }
+ return(error);
+}
+
+SYSCTL_PROC(_kern, KERN_DOMAINNAME, nisdomainname,
+ CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_LOCKED,
+ 0, 0, sysctl_domainname, "A", "");
+
+SYSCTL_COMPAT_INT(_kern, KERN_HOSTID, hostid,
+ CTLFLAG_RW | CTLFLAG_KERN | CTLFLAG_LOCKED,
+ &hostid, 0, "");
+
+STATIC int
+sysctl_hostname
+(__unused struct sysctl_oid *oidp, __unused void *arg1, __unused int arg2, struct sysctl_req *req)
+{
+ int error, changed;
+ error = sysctl_io_string(req, hostname, sizeof(hostname), 1, &changed);
+ if (changed) {
+ hostnamelen = req->newlen;
+ }
+ return(error);
+}
+
+
+SYSCTL_PROC(_kern, KERN_HOSTNAME, hostname,
+ CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_LOCKED,
+ 0, 0, sysctl_hostname, "A", "");
+
+STATIC int
+sysctl_procname
+(__unused struct sysctl_oid *oidp, __unused void *arg1, __unused int arg2, struct sysctl_req *req)
+{
+ /* Original code allowed writing, I'm copying this, although this all makes
+ no sense to me. Besides, this sysctl is never used. */
+ return sysctl_io_string(req, &req->p->p_name[0], (2*MAXCOMLEN+1), 1, NULL);
+}
+
+SYSCTL_PROC(_kern, KERN_PROCNAME, procname,
+ CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_ANYBODY | CTLFLAG_LOCKED,
+ 0, 0, sysctl_procname, "A", "");
+
+SYSCTL_INT(_kern, KERN_SPECULATIVE_READS, speculative_reads_disabled,
+ CTLFLAG_RW | CTLFLAG_KERN | CTLFLAG_LOCKED,
+ &speculative_reads_disabled, 0, "");
+
+SYSCTL_INT(_kern, OID_AUTO, ignore_is_ssd,
+ CTLFLAG_RW | CTLFLAG_KERN | CTLFLAG_LOCKED,
+ &ignore_is_ssd, 0, "");
+
+SYSCTL_UINT(_kern, OID_AUTO, preheat_pages_max,
+ CTLFLAG_RW | CTLFLAG_KERN | CTLFLAG_LOCKED,
+ &preheat_pages_max, 0, "");
+
+SYSCTL_UINT(_kern, OID_AUTO, preheat_pages_min,
+ CTLFLAG_RW | CTLFLAG_KERN | CTLFLAG_LOCKED,
+ &preheat_pages_min, 0, "");
+
+SYSCTL_UINT(_kern, OID_AUTO, speculative_prefetch_max,
+ CTLFLAG_RW | CTLFLAG_KERN | CTLFLAG_LOCKED,
+ &speculative_prefetch_max, 0, "");
+
+SYSCTL_UINT(_kern, OID_AUTO, speculative_prefetch_max_iosize,
+ CTLFLAG_RW | CTLFLAG_KERN | CTLFLAG_LOCKED,
+ &speculative_prefetch_max_iosize, 0, "");
+
+SYSCTL_UINT(_kern, OID_AUTO, vm_page_free_target,
+ CTLFLAG_RW | CTLFLAG_KERN | CTLFLAG_LOCKED,
+ &vm_page_free_target, 0, "");
+
+SYSCTL_UINT(_kern, OID_AUTO, vm_page_free_min,
+ CTLFLAG_RW | CTLFLAG_KERN | CTLFLAG_LOCKED,
+ &vm_page_free_min, 0, "");
+
+SYSCTL_UINT(_kern, OID_AUTO, vm_page_free_reserved,
+ CTLFLAG_RW | CTLFLAG_KERN | CTLFLAG_LOCKED,
+ &vm_page_free_reserved, 0, "");
+
+SYSCTL_UINT(_kern, OID_AUTO, vm_page_speculative_percentage,
+ CTLFLAG_RW | CTLFLAG_KERN | CTLFLAG_LOCKED,
+ &vm_page_speculative_percentage, 0, "");
+
+SYSCTL_UINT(_kern, OID_AUTO, vm_page_speculative_q_age_ms,
+ CTLFLAG_RW | CTLFLAG_KERN | CTLFLAG_LOCKED,
+ &vm_page_speculative_q_age_ms, 0, "");
+
+SYSCTL_UINT(_kern, OID_AUTO, vm_max_delayed_work_limit,
+ CTLFLAG_RW | CTLFLAG_KERN | CTLFLAG_LOCKED,
+ &vm_max_delayed_work_limit, 0, "");
+
+SYSCTL_UINT(_kern, OID_AUTO, vm_max_batch,
+ CTLFLAG_RW | CTLFLAG_KERN | CTLFLAG_LOCKED,
+ &vm_max_batch, 0, "");
+
+
+STATIC int
+sysctl_boottime
+(__unused struct sysctl_oid *oidp, __unused void *arg1, __unused int arg2, struct sysctl_req *req)
+{
+ time_t tv_sec = boottime_sec();
+ struct proc *p = req->p;
+
+ if (proc_is64bit(p)) {
+ struct user64_timeval t;
+ t.tv_sec = tv_sec;
+ t.tv_usec = 0;
+ return sysctl_io_opaque(req, &t, sizeof(t), NULL);
+ } else {
+ struct user32_timeval t;
+ t.tv_sec = tv_sec;
+ t.tv_usec = 0;
+ return sysctl_io_opaque(req, &t, sizeof(t), NULL);
+ }
+}
+
+SYSCTL_PROC(_kern, KERN_BOOTTIME, boottime,
+ CTLTYPE_STRUCT | CTLFLAG_RD | CTLFLAG_LOCKED,
+ 0, 0, sysctl_boottime, "S,timeval", "");
+
+STATIC int
+sysctl_symfile
+(__unused struct sysctl_oid *oidp, __unused void *arg1, __unused int arg2, struct sysctl_req *req)
+{
+ char *str;
+ int error = get_kernel_symfile(req->p, &str);
+ if (error)
+ return (error);
+ return sysctl_io_string(req, str, 0, 0, NULL);
+}
+
+
+SYSCTL_PROC(_kern, KERN_SYMFILE, symfile,
+ CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_LOCKED,
+ 0, 0, sysctl_symfile, "A", "");
+
+#if NFSCLIENT
+STATIC int
+sysctl_netboot
+(__unused struct sysctl_oid *oidp, __unused void *arg1, __unused int arg2, struct sysctl_req *req)
+{
+ return sysctl_io_number(req, netboot_root(), sizeof(int), NULL, NULL);
+}
+
+SYSCTL_PROC(_kern, KERN_NETBOOT, netboot,
+ CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED,
+ 0, 0, sysctl_netboot, "I", "");
+#endif
+
+#ifdef CONFIG_IMGSRC_ACCESS
+/*
+ * Legacy--act as if only one layer of nesting is possible.
+ */
+STATIC int
+sysctl_imgsrcdev
+(__unused struct sysctl_oid *oidp, __unused void *arg1, __unused int arg2, struct sysctl_req *req)
+{
+ vfs_context_t ctx = vfs_context_current();
+ vnode_t devvp;
+ int result;
+
+ if (!vfs_context_issuser(ctx)) {
+ return EPERM;
+ }
+
+ if (imgsrc_rootvnodes[0] == NULL) {
+ return ENOENT;
+ }
+
+ result = vnode_getwithref(imgsrc_rootvnodes[0]);
+ if (result != 0) {
+ return result;
+ }
+
+ devvp = vnode_mount(imgsrc_rootvnodes[0])->mnt_devvp;
+ result = vnode_getwithref(devvp);
+ if (result != 0) {
+ goto out;
+ }
+
+ result = sysctl_io_number(req, vnode_specrdev(devvp), sizeof(dev_t), NULL, NULL);
+
+ vnode_put(devvp);
+out:
+ vnode_put(imgsrc_rootvnodes[0]);
+ return result;
+}
+
+SYSCTL_PROC(_kern, OID_AUTO, imgsrcdev,
+ CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED,
+ 0, 0, sysctl_imgsrcdev, "I", "");
+
+STATIC int
+sysctl_imgsrcinfo
+(__unused struct sysctl_oid *oidp, __unused void *arg1, __unused int arg2, struct sysctl_req *req)
+{
+ int error;
+ struct imgsrc_info info[MAX_IMAGEBOOT_NESTING]; /* 2 for now, no problem */
+ uint32_t i;
+ vnode_t rvp, devvp;
+
+ if (imgsrc_rootvnodes[0] == NULLVP) {
+ return ENXIO;
+ }
+
+ for (i = 0; i < MAX_IMAGEBOOT_NESTING; i++) {
+ /*
+ * Go get the root vnode.
+ */
+ rvp = imgsrc_rootvnodes[i];
+ if (rvp == NULLVP) {
+ break;
+ }
+
+ error = vnode_get(rvp);
+ if (error != 0) {
+ return error;
+ }
+
+ /*
+ * For now, no getting at a non-local volume.
+ */
+ devvp = vnode_mount(rvp)->mnt_devvp;
+ if (devvp == NULL) {
+ vnode_put(rvp);
+ return EINVAL;