int sys_osethostname(struct sethostname_args *uap) { struct thread *td = curthread; size_t len; char *hostname; int name[2]; int error; name[0] = CTL_KERN; name[1] = KERN_HOSTNAME; error = priv_check_cred(td->td_ucred, PRIV_SETHOSTNAME, 0); if (error) return (error); len = MIN(uap->len, MAXHOSTNAMELEN); hostname = kmalloc(MAXHOSTNAMELEN, M_TEMP, M_WAITOK); error = copyin(uap->hostname, hostname, len); if (error) { kfree(hostname, M_TEMP); return (error); } error = kernel_sysctl(name, 2, NULL, 0, hostname, len, NULL); kfree(hostname, M_TEMP); return (error); }
/* ARGSUSED */ int osethostid(struct thread *td, struct osethostid_args *uap) { int name[2]; name[0] = CTL_KERN; name[1] = KERN_HOSTID; return (kernel_sysctl(td, name, 2, NULL, NULL, &uap->hostid, sizeof(uap->hostid), NULL, 0)); }
/* ARGSUSED */ int ogethostid(struct thread *td, struct ogethostid_args *uap) { size_t len = sizeof(long); int name[2]; name[0] = CTL_KERN; name[1] = KERN_HOSTID; return (kernel_sysctl(td, name, 2, (long *)td->td_retval, &len, NULL, 0, NULL, 0)); }
/*ARGSUSED*/ int nwfs_init(struct vfsconf *vfsp) { #ifndef SMP int name[2]; int ncpu, error; size_t olen, plen; name[0] = CTL_HW; name[1] = HW_NCPU; error = kernel_sysctl(name, 2, &ncpu, &olen, NULL, 0, &plen); if (error == 0 && ncpu > 1) kprintf("warning: nwfs module compiled without SMP support."); #endif nwfs_hash_init(); nwfs_pbuf_freecnt = nswbuf / 2 + 1; NCPVODEBUG("always happy to load!\n"); return (0); }
int sys_ogethostname(struct gethostname_args *uap) { size_t len; char *hostname; int error, name[2]; name[0] = CTL_KERN; name[1] = KERN_HOSTNAME; len = MIN(uap->len, MAXHOSTNAMELEN); hostname = kmalloc(MAXHOSTNAMELEN, M_TEMP, M_WAITOK); error = kernel_sysctl(name, 2, hostname, &len, NULL, 0, NULL); if (error == 0) error = copyout(hostname, uap->hostname, len); kfree(hostname, M_TEMP); return (error); }
int smb_checksmp(void) { int name[2]; int olen, ncpu, plen, error; name[0] = CTL_HW; name[1] = HW_NCPU; error = kernel_sysctl(curproc, name, 2, &ncpu, &olen, NULL, 0, &plen); if (error) return error; #ifndef SMP if (ncpu > 1) { printf("error: module compiled without SMP support\n"); return EPERM; } #else if (ncpu < 2) { printf("warning: only one CPU active on in SMP kernel ?\n"); } #endif return 0; }
int sysctl( const int *name, u_int namelen, void *oldp, size_t *oldlenp, const void *newp, size_t newlen ) { int eno = EINVAL; if (namelen <= CTL_MAXNAME) { int namedup [CTL_MAXNAME]; memcpy(namedup, name, namelen * sizeof(*name)); eno = kernel_sysctl( NULL, namedup, namelen, oldp, oldlenp, newp, newlen, oldlenp, 0 ); } if (eno == 0) { return 0; } else { errno = eno; return -1; } }
static int est_init(void) { char hwmodel[128]; int mib[] = { CTL_HW, HW_MODEL }; size_t modellen = sizeof(hwmodel); struct sysctl_oid *oid, *leaf; uint64_t msr; int mv; size_t len, freq_len; int err; size_t i; if ((cpu_feature2 & CPUID2_EST) == 0) { kprintf("Enhanced SpeedStep unsupported on this hardware.\n"); return(EOPNOTSUPP); } modellen = sizeof(hwmodel); err = kernel_sysctl(mib, 2, hwmodel, &modellen, NULL, 0, NULL); if (err) { kprintf("kernel_sysctl hw.model failed\n"); return(err); } msr = rdmsr(MSR_PERF_STATUS); mv = MSR2MV(msr); kprintf("%s (%d mV) ", est_desc, mv); est_fqlist = findcpu(hwmodel, mv); if (est_fqlist == NULL) { kprintf(" - unknown CPU or operating point" "(cpu_id:%#x, msr:%#jx).\n", cpu_id, (intmax_t)msr); return(EOPNOTSUPP); } /* * OK, tell the user the available frequencies. */ fsbmult = est_fqlist->fsbmult; kprintf("%d MHz\n", MSR2MHZ(msr)); freq_len = est_fqlist->tablec * (sizeof("9999 ")-1) + 1; if (freq_len >= sizeof(freqs_available)) { kprintf("increase the size of freqs_available[]\n"); return(ENOMEM); } freqs_available[0] = '\0'; len = 0; for (i = 0; i < est_fqlist->tablec; i++) { len += ksnprintf(freqs_available + len, freq_len - len, "%d%s", est_fqlist->table[i].mhz, i < est_fqlist->tablec - 1 ? " " : ""); } kprintf("%s frequencies available (MHz): %s\n", est_desc, freqs_available); /* * Setup the sysctl sub-tree machdep.est.* */ oid = SYSCTL_ADD_NODE(&machdep_est_ctx, SYSCTL_STATIC_CHILDREN(_machdep), OID_AUTO, "est", CTLFLAG_RD, NULL, ""); if (oid == NULL) return(EOPNOTSUPP); oid = SYSCTL_ADD_NODE(&machdep_est_ctx, SYSCTL_CHILDREN(oid), OID_AUTO, "frequency", CTLFLAG_RD, NULL, ""); if (oid == NULL) return(EOPNOTSUPP); leaf = SYSCTL_ADD_PROC(&machdep_est_ctx, SYSCTL_CHILDREN(oid), OID_AUTO, "target", CTLTYPE_INT | CTLFLAG_RW, NULL, 0, est_sysctl_helper, "I", "Target CPU frequency for Enhanced SpeedStep"); if (leaf == NULL) return(EOPNOTSUPP); leaf = SYSCTL_ADD_PROC(&machdep_est_ctx, SYSCTL_CHILDREN(oid), OID_AUTO, "current", CTLTYPE_INT | CTLFLAG_RD, NULL, 0, est_sysctl_helper, "I", "Current CPU frequency for Enhanced SpeedStep"); if (leaf == NULL) return(EOPNOTSUPP); leaf = SYSCTL_ADD_STRING(&machdep_est_ctx, SYSCTL_CHILDREN(oid), OID_AUTO, "available", CTLFLAG_RD, freqs_available, sizeof(freqs_available), "CPU frequencies supported by Enhanced SpeedStep"); if (leaf == NULL) return(EOPNOTSUPP); return(0); }