Move to new processctl syscall, share common kernel and ulib headers
This commit is contained in:
@ -11,6 +11,7 @@ CFLAGS += -I. \
|
||||
-I$(ROOT)/std/include \
|
||||
-I./std \
|
||||
-I./flanterm/src \
|
||||
-I$(ROOT)/share \
|
||||
-DPRINTF_INCLUDE_CONFIG_H=1 \
|
||||
-DLFS_NO_ASSERT \
|
||||
-DLFS_NO_DEBUG \
|
||||
|
@ -1,16 +0,0 @@
|
||||
#ifndef ERRORS_H_
|
||||
#define ERRORS_H_
|
||||
|
||||
enum {
|
||||
E_OK = 0,
|
||||
E_NOMEMORY = -1,
|
||||
E_UNKNOWN_FSTYPE = -2,
|
||||
E_NOENTRY = -3,
|
||||
E_OUTOFBOUNDS = -4,
|
||||
E_UNKNOWN_SDTYPE = -5,
|
||||
E_TODO = -6,
|
||||
E_BADIO = -7,
|
||||
E_BADSYSCALL = -8,
|
||||
};
|
||||
|
||||
#endif // ERRORS_H_
|
@ -2,7 +2,7 @@
|
||||
#include <stdbool.h>
|
||||
#include "fs/littlefs/lfs.h"
|
||||
#include "vfs/vfs.h"
|
||||
#include "errors.h"
|
||||
#include "hdrs/errors.h"
|
||||
#include "kprintf.h"
|
||||
#include "dlmalloc/malloc.h"
|
||||
#include "hal/hal.h"
|
||||
|
@ -12,7 +12,7 @@
|
||||
#include "pit.h"
|
||||
#include "proc/proc.h"
|
||||
#include "syscall/syscall.h"
|
||||
#include "errors.h"
|
||||
#include "hdrs/errors.h"
|
||||
|
||||
void hal_intr_disable(void) {
|
||||
asm volatile("cli");
|
||||
@ -165,7 +165,7 @@ void hal_syscalldispatch(IntrStackFrame *frame) {
|
||||
int32_t ret = fn(frame->regs.rdi, frame->regs.rsi, frame->regs.rdx,
|
||||
frame->regs.r10, frame->regs.r8, frame->regs.r9);
|
||||
|
||||
if (sysnum == SYS_QUITPROC) {
|
||||
if (ret == E_DOSCHEDULING) {
|
||||
proc_sched((void *)frame);
|
||||
}
|
||||
frame->regs.rax = *(uint64_t *)&ret;
|
||||
|
@ -9,7 +9,7 @@
|
||||
#include "util/util.h"
|
||||
#include "kprintf.h"
|
||||
#include "elf.h"
|
||||
#include "errors.h"
|
||||
#include "hdrs/errors.h"
|
||||
#include "vfs/vfs.h"
|
||||
#include "bootinfo/bootinfo.h"
|
||||
|
||||
|
@ -50,6 +50,7 @@ Proc *proc_spawnkern(void (*ent)(void), char *name);
|
||||
Proc *proc_spawnuser(char *mountpoint, char *path);
|
||||
void proc_sched(void *cpustate);
|
||||
void proc_killself(void);
|
||||
void proc_kill(Proc *proc);
|
||||
|
||||
#define PROC_DIE() \
|
||||
do { \
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include "spinlock/spinlock.h"
|
||||
#include "errors.h"
|
||||
#include "hdrs/errors.h"
|
||||
#include "dlmalloc/malloc.h"
|
||||
#include "ramsd.h"
|
||||
#include "storedev.h"
|
||||
|
@ -3,7 +3,7 @@
|
||||
#include "storedev.h"
|
||||
#include "spinlock/spinlock.h"
|
||||
#include "kprintf.h"
|
||||
#include "errors.h"
|
||||
#include "hdrs/errors.h"
|
||||
#include "dlmalloc/malloc.h"
|
||||
#include "ramsd.h"
|
||||
#include "util/util.h"
|
||||
|
53
kernel/syscall/processctl.c
Normal file
53
kernel/syscall/processctl.c
Normal 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;
|
||||
}
|
9
kernel/syscall/processctl.h
Normal file
9
kernel/syscall/processctl.h
Normal 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_
|
@ -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,
|
||||
};
|
||||
|
@ -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];
|
||||
|
@ -7,7 +7,7 @@
|
||||
#include "util/util.h"
|
||||
#include "hshtb.h"
|
||||
#include "assert.h"
|
||||
#include "errors.h"
|
||||
#include "hdrs/errors.h"
|
||||
#include "fs/portlfs/portlfs.h"
|
||||
#include "storedev/storedev.h"
|
||||
#include "baseimg/baseimg.h"
|
||||
|
Reference in New Issue
Block a user