Compare commits

..

2 Commits

21 changed files with 99 additions and 36 deletions

View File

@ -11,6 +11,7 @@ CFLAGS += -I. \
-I$(ROOT)/std/include \ -I$(ROOT)/std/include \
-I./std \ -I./std \
-I./flanterm/src \ -I./flanterm/src \
-I$(ROOT)/share \
-DPRINTF_INCLUDE_CONFIG_H=1 \ -DPRINTF_INCLUDE_CONFIG_H=1 \
-DLFS_NO_ASSERT \ -DLFS_NO_ASSERT \
-DLFS_NO_DEBUG \ -DLFS_NO_DEBUG \

View File

@ -2,7 +2,7 @@
#include <stdbool.h> #include <stdbool.h>
#include "fs/littlefs/lfs.h" #include "fs/littlefs/lfs.h"
#include "vfs/vfs.h" #include "vfs/vfs.h"
#include "errors.h" #include "hdrs/errors.h"
#include "kprintf.h" #include "kprintf.h"
#include "dlmalloc/malloc.h" #include "dlmalloc/malloc.h"
#include "hal/hal.h" #include "hal/hal.h"
@ -74,7 +74,6 @@ struct VfsObj *littlefs_open(struct VfsMountPoint *vmp, const char *path, uint32
} }
hal_memset(vobj, 0, sizeof(*vobj)); hal_memset(vobj, 0, sizeof(*vobj));
spinlock_init(&vobj->spinlock); spinlock_init(&vobj->spinlock);
vobj->refs++;
int lfs_flags = 0; int lfs_flags = 0;
lfs_file_t *file = dlmalloc(sizeof(*file)); lfs_file_t *file = dlmalloc(sizeof(*file));

View File

@ -12,7 +12,7 @@
#include "pit.h" #include "pit.h"
#include "proc/proc.h" #include "proc/proc.h"
#include "syscall/syscall.h" #include "syscall/syscall.h"
#include "errors.h" #include "hdrs/errors.h"
void hal_intr_disable(void) { void hal_intr_disable(void) {
asm volatile("cli"); 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, int32_t ret = fn(frame->regs.rdi, frame->regs.rsi, frame->regs.rdx,
frame->regs.r10, frame->regs.r8, frame->regs.r9); frame->regs.r10, frame->regs.r8, frame->regs.r9);
if (sysnum == SYS_QUITPROC) { if (ret == E_DOSCHEDULING) {
proc_sched((void *)frame); proc_sched((void *)frame);
} }
frame->regs.rax = *(uint64_t *)&ret; frame->regs.rax = *(uint64_t *)&ret;

View File

@ -9,7 +9,7 @@
#include "util/util.h" #include "util/util.h"
#include "kprintf.h" #include "kprintf.h"
#include "elf.h" #include "elf.h"
#include "errors.h" #include "hdrs/errors.h"
#include "vfs/vfs.h" #include "vfs/vfs.h"
#include "bootinfo/bootinfo.h" #include "bootinfo/bootinfo.h"

View File

@ -50,6 +50,7 @@ Proc *proc_spawnkern(void (*ent)(void), char *name);
Proc *proc_spawnuser(char *mountpoint, char *path); Proc *proc_spawnuser(char *mountpoint, char *path);
void proc_sched(void *cpustate); void proc_sched(void *cpustate);
void proc_killself(void); void proc_killself(void);
void proc_kill(Proc *proc);
#define PROC_DIE() \ #define PROC_DIE() \
do { \ do { \

View File

@ -1,7 +1,7 @@
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include "spinlock/spinlock.h" #include "spinlock/spinlock.h"
#include "errors.h" #include "hdrs/errors.h"
#include "dlmalloc/malloc.h" #include "dlmalloc/malloc.h"
#include "ramsd.h" #include "ramsd.h"
#include "storedev.h" #include "storedev.h"

View File

@ -3,7 +3,7 @@
#include "storedev.h" #include "storedev.h"
#include "spinlock/spinlock.h" #include "spinlock/spinlock.h"
#include "kprintf.h" #include "kprintf.h"
#include "errors.h" #include "hdrs/errors.h"
#include "dlmalloc/malloc.h" #include "dlmalloc/malloc.h"
#include "ramsd.h" #include "ramsd.h"
#include "util/util.h" #include "util/util.h"

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

View File

@ -69,11 +69,6 @@
uint64_t arg6 \ 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); typedef int32_t (*SyscallFn)(uint64_t, uint64_t, uint64_t, uint64_t, uint64_t, uint64_t);
extern SyscallFn SYSCALL_TABLE[SYSCALLS_MAX]; extern SyscallFn SYSCALL_TABLE[SYSCALLS_MAX];

View File

@ -7,7 +7,7 @@
#include "util/util.h" #include "util/util.h"
#include "hshtb.h" #include "hshtb.h"
#include "assert.h" #include "assert.h"
#include "errors.h" #include "hdrs/errors.h"
#include "fs/portlfs/portlfs.h" #include "fs/portlfs/portlfs.h"
#include "storedev/storedev.h" #include "storedev/storedev.h"
#include "baseimg/baseimg.h" #include "baseimg/baseimg.h"
@ -107,13 +107,7 @@ VfsObj *vfs_open(char *mountpoint, const char *path, uint32_t flags) {
} }
void vfs_close(VfsObj *vobj) { void vfs_close(VfsObj *vobj) {
if (vobj->refs < 0) {
return;
}
vobj->refs--;
if (vobj->refs == 0) {
vobj->cleanup(vobj); vobj->cleanup(vobj);
}
} }
void vfs_init(void) { void vfs_init(void) {

View File

@ -39,7 +39,6 @@ typedef struct VfsStat {
typedef struct VfsObj { typedef struct VfsObj {
SpinLock spinlock; SpinLock spinlock;
int32_t refs;
void *extra; void *extra;
size_t extrasize; size_t extrasize;
struct VfsMountPoint *vmp; struct VfsMountPoint *vmp;

View File

@ -11,6 +11,8 @@ enum {
E_TODO = -6, E_TODO = -6,
E_BADIO = -7, E_BADIO = -7,
E_BADSYSCALL = -8, E_BADSYSCALL = -8,
E_DOSCHEDULING = -9,
E_INVALIDARGUMENT = -10,
}; };
#endif // ERRORS_H_ #endif // ERRORS_H_

9
share/hdrs/syscall.h Normal file
View File

@ -0,0 +1,9 @@
#ifndef SHARE_HDRS_SYSCALL_H_
#define SHARE_HDRS_SYSCALL_H_
enum {
SYS_DEBUGPRINT = 1,
SYS_PROCESSCTL = 2,
};
#endif // SHARE_HDRS_SYSCALL_H_

View File

@ -11,7 +11,7 @@ SRCFILES := $(call GRABSRC, \
system \ system \
) )
CFLAGS += -isystem $(ROOT)/ulib -isystem $(ROOT)/std/include CFLAGS += -isystem $(ROOT)/share/hdrs -isystem $(ROOT)/ulib -isystem $(ROOT)/std/include
ASFILES := $(call GET_ASFILES, $(SRCFILES)) ASFILES := $(call GET_ASFILES, $(SRCFILES))
CFILES := $(call GET_CFILES, $(SRCFILES)) CFILES := $(call GET_CFILES, $(SRCFILES))

View File

@ -6,5 +6,7 @@
_start: _start:
call _premain call _premain
mov $SYS_QUITPROC, %rax movq $2, %rax // sys processctl
movq $0x5E1F, %rdi // self magic num
movq $0, %rsi // kill cmd
int $0x80 int $0x80

Binary file not shown.

View File

@ -1,9 +1,6 @@
#ifndef ULIB_SYSCALL_SYSCALL_H_ #ifndef ULIB_SYSCALL_SYSCALL_H_
#define ULIB_SYSCALL_SYSCALL_H_ #define ULIB_SYSCALL_SYSCALL_H_
#define SYS_DEBUGPRINT 1
#define SYS_QUITPROC 2
#if !defined(__ASSEMBLER__) #if !defined(__ASSEMBLER__)
uint64_t syscall(uint64_t num, uint64_t arg1, uint64_t arg2, uint64_t syscall(uint64_t num, uint64_t arg1, uint64_t arg2,

View File

@ -1,9 +1,13 @@
#include <stdint.h> #include <stdint.h>
#include <system/system.h> #include <system/system.h>
#include <syscall/syscall.h> #include <syscall/syscall.h>
#include <syscall.h>
void sys_debugprint(const char *string) { void sys_debugprint(const char *string) {
syscall(SYS_DEBUGPRINT, (uint64_t)string, 0, 0, 0, 0, 0); syscall(SYS_DEBUGPRINT, (uint64_t)string, 0, 0, 0, 0, 0);
} }
int32_t sys_processctl(uint64_t pid, uint64_t cmd, void *extra) {
return syscall(SYS_PROCESSCTL, pid, cmd, (uint64_t)extra, 0, 0, 0);
}

View File

@ -1,6 +1,9 @@
#ifndef ULIB_SYSTEM_SYSTEM_H_ #ifndef ULIB_SYSTEM_SYSTEM_H_
#define ULIB_SYSTEM_SYSTEM_H_ #define ULIB_SYSTEM_SYSTEM_H_
#include <stdint.h>
void sys_debugprint(const char *string); void sys_debugprint(const char *string);
int32_t sys_processctl(uint64_t pid, uint64_t cmd, void *extra);
#endif // ULIB_SYSTEM_SYSTEM_H_ #endif // ULIB_SYSTEM_SYSTEM_H_