This commit is contained in:
purplerain 2023-05-18 12:23:26 +00:00
parent 9e7f51724c
commit 4b78db449c
Signed by: purplerain
GPG key ID: F42C07F07E2E35B7
42 changed files with 1110 additions and 143 deletions

View file

@ -1,10 +1,10 @@
/* $OpenBSD: init_sysent.c,v 1.265 2023/05/04 09:41:15 mvs Exp $ */
/* $OpenBSD: init_sysent.c,v 1.266 2023/05/18 10:24:28 mvs Exp $ */
/*
* System call switch table.
*
* DO NOT EDIT-- this file is automatically generated.
* created from; OpenBSD: syscalls.master,v 1.247 2023/05/04 09:40:36 mvs Exp
* created from; OpenBSD: syscalls.master,v 1.248 2023/05/18 10:23:19 mvs Exp
*/
#include <sys/param.h>
@ -441,7 +441,7 @@ const struct sysent sysent[] = {
sys_nosys }, /* 200 = obsolete pad_truncate */
{ 0, 0, 0,
sys_nosys }, /* 201 = obsolete pad_ftruncate */
{ 6, s(struct sys_sysctl_args), SY_NOLOCK | 0,
{ 6, s(struct sys_sysctl_args), 0,
sys_sysctl }, /* 202 = sysctl */
{ 2, s(struct sys_mlock_args), 0,
sys_mlock }, /* 203 = mlock */

View file

@ -1,4 +1,4 @@
/* $OpenBSD: kern_sysctl.c,v 1.412 2023/05/04 09:40:36 mvs Exp $ */
/* $OpenBSD: kern_sysctl.c,v 1.414 2023/05/18 10:23:19 mvs Exp $ */
/* $NetBSD: kern_sysctl.c,v 1.17 1996/05/20 17:49:05 mrg Exp $ */
/*-
@ -143,6 +143,7 @@ int sysctl_audio(int *, u_int, void *, size_t *, void *, size_t);
int sysctl_video(int *, u_int, void *, size_t *, void *, size_t);
int sysctl_cpustats(int *, u_int, void *, size_t *, void *, size_t);
int sysctl_utc_offset(void *, size_t *, void *, size_t);
int sysctl_hwbattery(int *, u_int, void *, size_t *, void *, size_t);
void fill_file(struct kinfo_file *, struct file *, struct filedesc *, int,
struct vnode *, struct process *, struct proc *, struct socket *, int);
@ -168,7 +169,7 @@ sys_sysctl(struct proc *p, void *v, register_t *retval)
syscallarg(void *) new;
syscallarg(size_t) newlen;
} */ *uap = v;
int error, dokernellock = 1, dolock = 1;
int error, dolock = 1;
size_t savelen = 0, oldlen = 0;
sysctlfn *fn;
int name[CTL_MAXNAME];
@ -203,7 +204,6 @@ sys_sysctl(struct proc *p, void *v, register_t *retval)
break;
case CTL_NET:
fn = net_sysctl;
dokernellock = 0;
break;
case CTL_FS:
fn = fs_sysctl;
@ -231,22 +231,19 @@ sys_sysctl(struct proc *p, void *v, register_t *retval)
if (SCARG(uap, oldlenp) &&
(error = copyin(SCARG(uap, oldlenp), &oldlen, sizeof(oldlen))))
return (error);
if (dokernellock)
KERNEL_LOCK();
if (SCARG(uap, old) != NULL) {
if ((error = rw_enter(&sysctl_lock, RW_WRITE|RW_INTR)) != 0)
goto unlock;
return (error);
if (dolock) {
if (atop(oldlen) > uvmexp.wiredmax - uvmexp.wired) {
rw_exit_write(&sysctl_lock);
error = ENOMEM;
goto unlock;
return (ENOMEM);
}
error = uvm_vslock(p, SCARG(uap, old), oldlen,
PROT_READ | PROT_WRITE);
if (error) {
rw_exit_write(&sysctl_lock);
goto unlock;
return (error);
}
}
savelen = oldlen;
@ -258,9 +255,6 @@ sys_sysctl(struct proc *p, void *v, register_t *retval)
uvm_vsunlock(p, SCARG(uap, old), savelen);
rw_exit_write(&sysctl_lock);
}
unlock:
if (dokernellock)
KERNEL_UNLOCK();
if (error)
return (error);
if (SCARG(uap, oldlenp))
@ -689,8 +683,11 @@ hw_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp,
extern char machine[], cpu_model[];
int err, cpuspeed;
/* all sysctl names at this level except sensors are terminal */
if (name[0] != HW_SENSORS && namelen != 1)
/*
* all sysctl names at this level except sensors and battery
* are terminal
*/
if (name[0] != HW_SENSORS && name[0] != HW_BATTERY && namelen != 1)
return (ENOTDIR); /* overloaded */
switch (name[0]) {
@ -776,6 +773,11 @@ hw_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp,
#ifdef __HAVE_CPU_TOPOLOGY
case HW_SMT:
return (sysctl_hwsmt(oldp, oldlenp, newp, newlen));
#endif
#ifndef SMALL_KERNEL
case HW_BATTERY:
return (sysctl_hwbattery(name + 1, namelen - 1, oldp, oldlenp,
newp, newlen));
#endif
default:
return sysctl_bounded_arr(hw_vars, nitems(hw_vars), name,
@ -784,6 +786,97 @@ hw_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp,
/* NOTREACHED */
}
#ifndef SMALL_KERNEL
int hw_battery_chargemode;
int hw_battery_chargestart;
int hw_battery_chargestop;
int (*hw_battery_setchargemode)(int);
int (*hw_battery_setchargestart)(int);
int (*hw_battery_setchargestop)(int);
int
sysctl_hwchargemode(void *oldp, size_t *oldlenp, void *newp, size_t newlen)
{
int mode = hw_battery_chargemode;
int error;
if (!hw_battery_setchargemode)
return EOPNOTSUPP;
error = sysctl_int_bounded(oldp, oldlenp, newp, newlen,
&mode, -1, 1);
if (error)
return error;
if (newp != NULL)
error = hw_battery_setchargemode(mode);
return error;
}
int
sysctl_hwchargestart(void *oldp, size_t *oldlenp, void *newp, size_t newlen)
{
int start = hw_battery_chargestart;
int error;
if (!hw_battery_setchargestart)
return EOPNOTSUPP;
error = sysctl_int_bounded(oldp, oldlenp, newp, newlen,
&start, 0, 100);
if (error)
return error;
if (newp != NULL)
error = hw_battery_setchargestart(start);
return error;
}
int
sysctl_hwchargestop(void *oldp, size_t *oldlenp, void *newp, size_t newlen)
{
int stop = hw_battery_chargestop;
int error;
if (!hw_battery_setchargestart)
return EOPNOTSUPP;
error = sysctl_int_bounded(oldp, oldlenp, newp, newlen,
&stop, 0, 100);
if (error)
return error;
if (newp != NULL)
error = hw_battery_setchargestop(stop);
return error;
}
int
sysctl_hwbattery(int *name, u_int namelen, void *oldp, size_t *oldlenp,
void *newp, size_t newlen)
{
if (namelen != 1)
return (ENOTDIR);
switch (name[0]) {
case HW_BATTERY_CHARGEMODE:
return (sysctl_hwchargemode(oldp, oldlenp, newp, newlen));
case HW_BATTERY_CHARGESTART:
return (sysctl_hwchargestart(oldp, oldlenp, newp, newlen));
case HW_BATTERY_CHARGESTOP:
return (sysctl_hwchargestop(oldp, oldlenp, newp, newlen));
default:
return (EOPNOTSUPP);
}
/* NOTREACHED */
}
#endif
#ifdef DEBUG_SYSCTL
/*
* Debugging related system variables.

View file

@ -1,10 +1,10 @@
/* $OpenBSD: syscalls.c,v 1.263 2023/05/04 09:41:15 mvs Exp $ */
/* $OpenBSD: syscalls.c,v 1.264 2023/05/18 10:24:28 mvs Exp $ */
/*
* System call names.
*
* DO NOT EDIT-- this file is automatically generated.
* created from; OpenBSD: syscalls.master,v 1.247 2023/05/04 09:40:36 mvs Exp
* created from; OpenBSD: syscalls.master,v 1.248 2023/05/18 10:23:19 mvs Exp
*/
const char *const syscallnames[] = {

View file

@ -1,4 +1,4 @@
; $OpenBSD: syscalls.master,v 1.247 2023/05/04 09:40:36 mvs Exp $
; $OpenBSD: syscalls.master,v 1.248 2023/05/18 10:23:19 mvs Exp $
; $NetBSD: syscalls.master,v 1.32 1996/04/23 10:24:21 mycroft Exp $
; @(#)syscalls.master 8.2 (Berkeley) 1/13/94
@ -361,7 +361,7 @@
199 OBSOL pad_lseek
200 OBSOL pad_truncate
201 OBSOL pad_ftruncate
202 STD NOLOCK { int sys_sysctl(const int *name, u_int namelen, \
202 STD { int sys_sysctl(const int *name, u_int namelen, \
void *old, size_t *oldlenp, void *new, \
size_t newlen); }
203 STD { int sys_mlock(const void *addr, size_t len); }

View file

@ -1,4 +1,4 @@
/* $OpenBSD: uipc_domain.c,v 1.62 2023/05/16 19:36:00 mvs Exp $ */
/* $OpenBSD: uipc_domain.c,v 1.64 2023/05/18 10:23:19 mvs Exp $ */
/* $NetBSD: uipc_domain.c,v 1.14 1996/02/09 19:00:44 christos Exp $ */
/*
@ -188,7 +188,7 @@ net_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp,
{
const struct domain *dp;
const struct protosw *pr;
int error, family, protocol;
int family, protocol;
/*
* All sysctl names at this level are nonterminal.
@ -213,13 +213,9 @@ net_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp,
newp, newlen));
#endif
#if NPFLOW > 0
if (family == PF_PFLOW) {
KERNEL_LOCK();
error = pflow_sysctl(name + 1, namelen - 1, oldp, oldlenp,
newp, newlen);
KERNEL_UNLOCK();
return (error);
}
if (family == PF_PFLOW)
return (pflow_sysctl(name + 1, namelen - 1, oldp, oldlenp,
newp, newlen));
#endif
#ifdef PIPEX
if (family == PF_PIPEX)
@ -227,13 +223,9 @@ net_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp,
newp, newlen));
#endif
#ifdef MPLS
if (family == PF_MPLS) {
KERNEL_LOCK();
error = mpls_sysctl(name + 1, namelen - 1, oldp, oldlenp,
newp, newlen);
KERNEL_UNLOCK();
return (error);
}
if (family == PF_MPLS)
return (mpls_sysctl(name + 1, namelen - 1, oldp, oldlenp,
newp, newlen));
#endif
dp = pffinddomain(family);
if (dp == NULL)
@ -243,15 +235,9 @@ net_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp,
return (EISDIR); /* overloaded */
protocol = name[1];
for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
if (pr->pr_protocol == protocol && pr->pr_sysctl) {
if ((pr->pr_flags & PR_MPSYSCTL) == 0)
KERNEL_LOCK();
error = (*pr->pr_sysctl)(name + 2, namelen - 2,
oldp, oldlenp, newp, newlen);
if ((pr->pr_flags & PR_MPSYSCTL) == 0)
KERNEL_UNLOCK();
return (error);
}
if (pr->pr_protocol == protocol && pr->pr_sysctl)
return ((*pr->pr_sysctl)(name + 2, namelen - 2,
oldp, oldlenp, newp, newlen));
return (ENOPROTOOPT);
}