Move to new processctl syscall, share common kernel and ulib headers

This commit is contained in:
2025-09-05 15:44:57 +02:00
parent ca92a0e6a8
commit 708c53c64d
20 changed files with 98 additions and 27 deletions

View File

@ -0,0 +1,53 @@
#include <stdint.h>
#include "syscall.h"
#include "proc/proc.h"
#include "spinlock/spinlock.h"
#include "hdrs/errors.h"
#include "util/util.h"
#define PID_SELF_MAGIC 0x5E1F
enum {
PCTL_KILL = 0,
};
typedef struct {
} ProcessCtl;
int32_t SYSCALL3(sys_processctl, pid1, cmd1, optsptr1) {
uint64_t pid = pid1;
uint64_t cmd = cmd1;
ProcessCtl *pctl = (ProcessCtl *)(void *)optsptr1;
int32_t ret = E_OK;
spinlock_acquire(&PROCS.spinlock);
if (pid == PID_SELF_MAGIC) {
pid = PROCS.current->pid;
}
Proc *proc = NULL;
LL_FINDPROP(PROCS.procs, proc, pid, pid);
if (proc == NULL) {
ret = E_INVALIDARGUMENT;
goto done;
}
switch (cmd) {
case PCTL_KILL: {
proc_kill(proc);
ret = E_DOSCHEDULING;
goto done;
} break;
default: {
ret = E_INVALIDARGUMENT;
goto done;
} break;
}
done:
spinlock_release(&PROCS.spinlock);
return ret;
}

View File

@ -0,0 +1,9 @@
#ifndef SYSCALL_PROCESSCTL_H_
#define SYSCALL_PROCESSCTL_H_
#include <stdint.h>
#include "syscall.h"
int32_t SYSCALL3(sys_processctl, pid1, cmd1, optsptr1);
#endif // SYSCALL_PROCESSCTL_H_

View File

@ -1,9 +1,9 @@
#include <stdint.h>
#include "syscall.h"
#include "errors.h"
#include "dlmalloc/malloc.h"
#include "hdrs/errors.h"
#include "kprintf.h"
#include "proc/proc.h"
#include "processctl.h"
#include "hdrs/syscall.h"
int32_t SYSCALL1(sys_debugprint, string) {
char *p = (char *)string;
@ -11,12 +11,7 @@ int32_t SYSCALL1(sys_debugprint, string) {
return E_OK;
}
int32_t SYSCALL0(sys_quitproc) {
proc_killself();
return E_OK;
}
SyscallFn SYSCALL_TABLE[SYSCALLS_MAX] = {
[SYS_DEBUGPRINT] = &sys_debugprint,
[SYS_QUITPROC] = &sys_quitproc,
[SYS_PROCESSCTL] = &sys_processctl,
};

View File

@ -69,11 +69,6 @@
uint64_t arg6 \
)
enum {
SYS_DEBUGPRINT = 1,
SYS_QUITPROC = 2,
};
typedef int32_t (*SyscallFn)(uint64_t, uint64_t, uint64_t, uint64_t, uint64_t, uint64_t);
extern SyscallFn SYSCALL_TABLE[SYSCALLS_MAX];