mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-27 20:58:22 +00:00
syscalls: implement sysctl and add process listing
This commit is contained in:
@@ -51,6 +51,18 @@ static syscallret_t execve(context_t *context, char *upath, char *uargv[], char
|
||||
return ret;
|
||||
}
|
||||
|
||||
char *last_component = strrchr(path, '/');
|
||||
if (last_component) {
|
||||
++last_component;
|
||||
if (*last_component == '\0') {
|
||||
ret.errno = EISDIR;
|
||||
free(path);
|
||||
return ret;
|
||||
}
|
||||
} else {
|
||||
last_component = path;
|
||||
}
|
||||
|
||||
size_t argsize = 0;
|
||||
size_t envsize = 0;
|
||||
char **argv = NULL;
|
||||
@@ -315,6 +327,10 @@ static syscallret_t execve(context_t *context, char *upath, char *uargv[], char
|
||||
|
||||
cred_doexec(¤t_thread()->proc->cred, suid, sgid);
|
||||
|
||||
strncpy(current_thread()->proc->name, last_component, sizeof(current_thread()->proc->name));
|
||||
proc->start_time = timekeeper_timefromboot();
|
||||
memset(&proc->total_runtime, 0, sizeof(proc->total_runtime));
|
||||
|
||||
error:
|
||||
free(path);
|
||||
if (argv)
|
||||
|
||||
@@ -76,10 +76,19 @@ syscallret_t syscall_fork(context_t *ctx) {
|
||||
memcpy(&nproc->signals.pending, &proc->signals.pending, sizeof(sigset_t));
|
||||
memcpy(&nproc->signals.actions, &proc->signals.actions[0], sizeof(sigaction_t) * NSIG);
|
||||
|
||||
strncpy(nproc->name, proc->name, sizeof(proc->name));
|
||||
nproc->start_time = proc->start_time;
|
||||
|
||||
// copy thread scheduling metrics over
|
||||
// raised to IPL_DPC to prevent scheduling
|
||||
long ipl = interrupt_raiseipl(IPL_DPC);
|
||||
|
||||
spinlock_acquire(&proc->runtime_lock);
|
||||
nproc->total_runtime = proc->total_runtime;
|
||||
spinlock_release(&proc->runtime_lock);
|
||||
|
||||
memcpy(&nthread->metrics, ¤t_thread()->metrics, sizeof(nthread->metrics));
|
||||
|
||||
interrupt_loweripl(ipl);
|
||||
|
||||
ret.ret = nproc->pid;
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
#include <kernel/syscalls.h>
|
||||
#include <kernel/sysctl.h>
|
||||
#include <arch/mmu.h>
|
||||
|
||||
syscallret_t syscall_sysctl(context_t *, int *namep, size_t name_len, void *oldp, size_t *old_lenp, void *newp, size_t new_len) {
|
||||
syscallret_t ret = {
|
||||
.ret = -1
|
||||
};
|
||||
|
||||
if (name_len > SYS_CTL_NAME_MAX) {
|
||||
ret.errno = EINVAL;
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (!IS_USER_ADDRESS(namep) || !IS_USER_ADDRESS(oldp) || !IS_USER_ADDRESS(old_lenp) || !IS_USER_ADDRESS(newp)) {
|
||||
ret.errno = EFAULT;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int name[name_len];
|
||||
ret.errno = usercopy_fromuser(name, namep, sizeof(name));
|
||||
if (ret.errno)
|
||||
return ret;
|
||||
|
||||
ret.errno = sysctl(name, name_len, oldp, old_lenp, newp, new_len);
|
||||
ret.ret = ret.errno ? -1 : 0;
|
||||
return ret;
|
||||
}
|
||||
Reference in New Issue
Block a user