This commit is contained in:
2026-09-25 15:39:16 +02:00
committed by Marvin Friedrich
parent b9ee87aed4
commit 6e92817f3f
35 changed files with 271 additions and 157 deletions
+6
View File
@@ -0,0 +1,6 @@
#include <zinnia/syscall.h>
#include <arch/archctl.h>
struct syscall_ret sys_archctl(uintptr_t op, uintptr_t arg) {
return arch_archctl(op, arg);
}
+53
View File
@@ -0,0 +1,53 @@
#include <zinnia/compiler.h>
#include <zinnia/errno.h>
#include <zinnia/print.h>
#include <zinnia/sched.h>
#include <zinnia/syscall.h>
#include <zinnia/types.h>
#include <zinnia/utils.h>
#include <bits/sched.h>
// Declare all syscalls.
#include <zinnia/syscall_list.inc>
#undef SYSCALL_DECLARE
// Define them.
const struct syscall syscall_table[256] = {
#define SYSCALL_DECLARE(number, name, num_args) [number] = {sys_##name, num_args},
#include <zinnia/syscall_list.inc>
};
// TODO: Implement this
[[gnu::no_caller_saved_registers]]
struct syscall_ret syscall_dispatch_fast(
uintptr_t a0,
uintptr_t a1,
uintptr_t a2,
uintptr_t a3,
uintptr_t a4,
uintptr_t a5,
size_t num
) {
// No need to check the table size here. In order to get to this point,
// we already have to check if this is a fast syscall.
if (syscall_table[num].func == nullptr) {
return (struct syscall_ret){.errno = ENOSYS};
}
struct syscall_ret (*func)(uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t) =
syscall_table[num].func;
return func(a0, a1, a2, a3, a4, a5);
}
void syscall_dispatch(struct arch_context* ctx) {
const size_t num = ctx->ARCH_CTX_NUM;
if (num >= ARRAY_SIZE(syscall_table) || syscall_table[num].func == nullptr) {
ctx->ARCH_CTX_RET0 = ENOSYS;
return;
}
void (*func)(struct arch_context* ctx) = syscall_table[num].func;
func(ctx);
}
+5
View File
@@ -0,0 +1,5 @@
kernel_sources += files(
'archctl.c',
'dispatch.c',
'uname.c',
)
+63
View File
@@ -0,0 +1,63 @@
#include <zinnia/spin.h>
#include <zinnia/syscall.h>
#include <zinnia/usercopy.h>
#include <config.h>
#include <string.h>
#include <uapi/utsname.h>
static struct spinlock uname_lock = {};
static struct __utsname uname_buf = {
.sysname = "Zinnia",
.release = ZINNIA_VERSION,
.version = CONFIG_KERNEL_FLAVOR,
.nodename = "localhost",
.machine = ZINNIA_ARCH,
};
struct syscall_ret sys_setuname(__user const struct __utsname* ptr) {
struct syscall_ret ret = {};
if (!ptr) {
ret.errno = EINVAL;
return ret;
}
// TODO: User has to be root to do this.
struct __utsname read_buf;
if (!usercopy_read(&read_buf, ptr, sizeof(read_buf))) {
ret.errno = EFAULT;
return ret;
}
spin_lock(&uname_lock);
strncpy(uname_buf.sysname, read_buf.sysname, sizeof(uname_buf.sysname));
strncpy(uname_buf.release, read_buf.release, sizeof(uname_buf.release));
strncpy(uname_buf.version, read_buf.version, sizeof(uname_buf.version));
strncpy(uname_buf.nodename, read_buf.nodename, sizeof(uname_buf.nodename));
strncpy(uname_buf.machine, read_buf.machine, sizeof(uname_buf.machine));
spin_unlock(&uname_lock);
return ret;
}
struct syscall_ret sys_getuname(__user struct __utsname* ptr) {
struct syscall_ret ret = {};
if (!ptr) {
ret.errno = EINVAL;
return ret;
}
spin_lock(&uname_lock);
if (!usercopy_write(ptr, &uname_buf, sizeof(uname_buf)))
ret.errno = EFAULT;
spin_unlock(&uname_lock);
return ret;
}