Compare commits
2 Commits
90266f044b
...
708c53c64d
Author | SHA1 | Date | |
---|---|---|---|
708c53c64d | |||
ca92a0e6a8 |
@ -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 \
|
||||
|
@ -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"
|
||||
@ -74,7 +74,6 @@ struct VfsObj *littlefs_open(struct VfsMountPoint *vmp, const char *path, uint32
|
||||
}
|
||||
hal_memset(vobj, 0, sizeof(*vobj));
|
||||
spinlock_init(&vobj->spinlock);
|
||||
vobj->refs++;
|
||||
|
||||
int lfs_flags = 0;
|
||||
lfs_file_t *file = dlmalloc(sizeof(*file));
|
||||
|
@ -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"
|
||||
@ -107,13 +107,7 @@ VfsObj *vfs_open(char *mountpoint, const char *path, uint32_t flags) {
|
||||
}
|
||||
|
||||
void vfs_close(VfsObj *vobj) {
|
||||
if (vobj->refs < 0) {
|
||||
return;
|
||||
}
|
||||
vobj->refs--;
|
||||
if (vobj->refs == 0) {
|
||||
vobj->cleanup(vobj);
|
||||
}
|
||||
}
|
||||
|
||||
void vfs_init(void) {
|
||||
|
@ -39,7 +39,6 @@ typedef struct VfsStat {
|
||||
|
||||
typedef struct VfsObj {
|
||||
SpinLock spinlock;
|
||||
int32_t refs;
|
||||
void *extra;
|
||||
size_t extrasize;
|
||||
struct VfsMountPoint *vmp;
|
||||
|
@ -11,6 +11,8 @@ enum {
|
||||
E_TODO = -6,
|
||||
E_BADIO = -7,
|
||||
E_BADSYSCALL = -8,
|
||||
E_DOSCHEDULING = -9,
|
||||
E_INVALIDARGUMENT = -10,
|
||||
};
|
||||
|
||||
#endif // ERRORS_H_
|
9
share/hdrs/syscall.h
Normal file
9
share/hdrs/syscall.h
Normal 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_
|
@ -11,7 +11,7 @@ SRCFILES := $(call GRABSRC, \
|
||||
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))
|
||||
CFILES := $(call GET_CFILES, $(SRCFILES))
|
||||
|
@ -6,5 +6,7 @@
|
||||
_start:
|
||||
call _premain
|
||||
|
||||
mov $SYS_QUITPROC, %rax
|
||||
movq $2, %rax // sys processctl
|
||||
movq $0x5E1F, %rdi // self magic num
|
||||
movq $0, %rsi // kill cmd
|
||||
int $0x80
|
||||
|
BIN
ulib/libulib.a
BIN
ulib/libulib.a
Binary file not shown.
@ -1,9 +1,6 @@
|
||||
#ifndef ULIB_SYSCALL_SYSCALL_H_
|
||||
#define ULIB_SYSCALL_SYSCALL_H_
|
||||
|
||||
#define SYS_DEBUGPRINT 1
|
||||
#define SYS_QUITPROC 2
|
||||
|
||||
#if !defined(__ASSEMBLER__)
|
||||
|
||||
uint64_t syscall(uint64_t num, uint64_t arg1, uint64_t arg2,
|
||||
|
@ -1,9 +1,13 @@
|
||||
#include <stdint.h>
|
||||
#include <system/system.h>
|
||||
#include <syscall/syscall.h>
|
||||
|
||||
#include <syscall.h>
|
||||
|
||||
void sys_debugprint(const char *string) {
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,9 @@
|
||||
#ifndef ULIB_SYSTEM_SYSTEM_H_
|
||||
#define ULIB_SYSTEM_SYSTEM_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
void sys_debugprint(const char *string);
|
||||
int32_t sys_processctl(uint64_t pid, uint64_t cmd, void *extra);
|
||||
|
||||
#endif // ULIB_SYSTEM_SYSTEM_H_
|
||||
|
Reference in New Issue
Block a user