sysctl: SYS_CTL_HW_CPUS_ONLINE

This commit is contained in:
Matheus
2026-08-13 00:43:15 -03:00
parent 4add208558
commit 65358e6705
3 changed files with 49 additions and 0 deletions
+3
View File
@@ -7,9 +7,11 @@
#define SYS_CTL_NAME_MAX 6
#define SYS_CTL_KERN 1
#define SYS_CTL_HW 2
#define SYS_CTL_KERN_PROC 1
#define SYS_CTL_KERN_PROC_ALL 1
#define SYS_CTL_KERN_CONSOLE_LOCK 2
#define SYS_CTL_HW_CPUS_ONLINE 1
#define SYS_CTL_KERN_PROC_INFO_NAME_SIZE 64
#define SYS_CTL_KERN_PROC_INFO_TTY_NAME_SIZE 64
@@ -39,5 +41,6 @@ typedef struct {
int sysctl(const int *name, size_t name_len, void *oldp, size_t *old_lenp, void *newp, size_t new_len);
int sysctl_kern(const int *name, size_t name_len, void *oldp, size_t *old_lenp, void *newp, size_t new_len);
int sysctl_hw(const int *name, size_t name_len, void *oldp, size_t *old_lenp, void *newp, size_t new_len);
#endif
+44
View File
@@ -0,0 +1,44 @@
#include <kernel/sysctl.h>
#include <kernel/usercopy.h>
#include <arch/smp.h>
static int ctl_cpus_online(const int *, size_t name_len, void *oldp, size_t *old_lenp, void *newp, size_t) {
if (name_len != 0)
return EINVAL;
if (newp)
return EPERM;
if (!old_lenp)
return EINVAL;
size_t old_len = 0;
if (oldp) {
int error = USERCOPY_POSSIBLY_FROM_USER(&old_len, old_lenp, sizeof(old_len));
if (error)
return error;
}
size_t required_len = sizeof(size_t);
int error = USERCOPY_POSSIBLY_TO_USER(old_lenp, &required_len, sizeof(required_len));
if (error)
return error;
if (!oldp)
return 0;
if (old_len < required_len)
return ENOMEM;
size_t cpus_online = arch_smp_get_cpu_count();
return USERCOPY_POSSIBLY_TO_USER(oldp, &cpus_online, sizeof(cpus_online));
}
int sysctl_hw(const int *name, size_t name_len, void *oldp, size_t *old_lenp, void *newp, size_t new_len) {
switch (*name) {
case SYS_CTL_HW_CPUS_ONLINE:
return ctl_cpus_online(name + 1, name_len - 1, oldp, old_lenp, newp, new_len);
}
return EINVAL;
}
+2
View File
@@ -9,6 +9,8 @@ int sysctl(const int *name, size_t name_len, void *oldp, size_t *old_lenp, void
switch (*name) {
case SYS_CTL_KERN:
return sysctl_kern(name + 1, name_len - 1, oldp, old_lenp, newp, new_len);
case SYS_CTL_HW:
return sysctl_hw(name + 1, name_len - 1, oldp, old_lenp, newp, new_len);
default:
return EINVAL;
}