This commit is contained in:
2026-09-17 03:19:43 +02:00
parent 6719239036
commit 27fe15f83d
85 changed files with 945 additions and 901 deletions
+6
View File
@@ -0,0 +1,6 @@
#include <zinnia/syscall.h>
#include <arch/archctl.h>
void sys_archctl(struct arch_context* ctx) {
ctx->ARCH_CTX_RET0 = arch_archctl(ctx->ARCH_CTX_A0, ctx->ARCH_CTX_A1);
}
+191
View File
@@ -0,0 +1,191 @@
#include <zinnia/compiler.h>
#include <zinnia/errno.h>
#include <zinnia/print.h>
#include <zinnia/sched.h>
#include <zinnia/syscall.h>
#include <zinnia/syscall_list.h>
#include <zinnia/types.h>
#include <zinnia/utils.h>
#include <bits/sched.h>
const struct syscall syscall_table[256] = {
// [0] = {sys_exit, 0},
// [1] = {sys_syslog, 0},
[2] = {sys_getuname, 0},
// [3] = {sys_setuname, 0},
[4] = {sys_archctl, 0},
// [5] = {sys_reboot, 0},
// [6] = {sys_mmap, 0},
// [7] = {sys_munmap, 0},
// [8] = {sys_mprotect, 0},
// [9] = {sys_madvise, 0},
// [10] = {sys_sigprocmask, 0},
// [11] = {sys_sigsuspend, 0},
// [12] = {sys_sigpending, 0},
// [13] = {sys_sigaction, 0},
// [14] = {sys_sigtimedwait, 0},
// [15] = {sys_sigaltstack, 0},
// [16] = {sys_sigreturn, 0},
// [17] = {sys_sigqueue, 0},
// [18] = {sys_execve, 0},
// [19] = {sys_fexecve, 0},
// [20] = {sys_fork, 0},
// [21] = {sys_kill, 0},
// [22] = {sys_gettid, 0},
// [23] = {sys_getpid, 0},
// [24] = {sys_getppid, 0},
// [25] = {sys_waitid, 0},
// [26] = {sys_waitpid, 0},
// [27] = {sys_pread, 0},
// [28] = {sys_readv, 0},
// [29] = {sys_pwrite, 0},
// [30] = {sys_writev, 0},
// [31] = {sys_seek, 0},
// [32] = {sys_ioctl, 0},
// [33] = {sys_openat, 0},
// [34] = {sys_close, 0},
// [35] = {sys_fstat, 0},
// [36] = {sys_fstatat, 0},
// [37] = {sys_statvfs, 0},
// [38] = {sys_fstatvfs, 0},
// [39] = {sys_faccessat, 0},
// [40] = {sys_fcntl, 0},
// [41] = {sys_ftruncate, 0},
// [42] = {sys_truncate, 0},
// [43] = {sys_fallocate, 0},
// [44] = {sys_fadvise, 0},
// [45] = {sys_utimensat, 0},
// [46] = {sys_mknodat, 0},
// [47] = {sys_getcwd, 0},
// [48] = {sys_chdir, 0},
// [49] = {sys_fchdir, 0},
// [50] = {sys_mkdirat, 0},
// [51] = {sys_rmdirat, 0},
// [52] = {sys_getdents, 0},
// [53] = {sys_renameat, 0},
// [54] = {sys_fchmod, 0},
// [55] = {sys_fchmodat, 0},
// [56] = {sys_fchownat, 0},
// [57] = {sys_linkat, 0},
// [58] = {sys_symlinkat, 0},
// [59] = {sys_unlinkat, 0},
// [60] = {sys_readlinkat, 0},
// [61] = {sys_flock, 0},
// [62] = {sys_ppoll, 0},
// [63] = {sys_dup, 0},
// [64] = {sys_dup3, 0},
// [65] = {sys_sync, 0},
// [66] = {sys_fsync, 0},
// [67] = {sys_fdatasync, 0},
// [68] = {sys_getgroups, 0},
// [69] = {sys_setgroups, 0},
// [70] = {sys_getsid, 0},
// [71] = {sys_setsid, 0},
// [72] = {sys_setuid, 0},
// [73] = {sys_getuid, 0},
// [74] = {sys_setgid, 0},
// [75] = {sys_getgid, 0},
// [76] = {sys_geteuid, 0},
// [77] = {sys_seteuid, 0},
// [78] = {sys_getegid, 0},
// [79] = {sys_setegid, 0},
// [80] = {sys_getpgid, 0},
// [81] = {sys_setpgid, 0},
// [82] = {sys_getresuid, 0},
// [83] = {sys_setresuid, 0},
// [84] = {sys_getresgid, 0},
// [85] = {sys_setresgid, 0},
// [86] = {sys_setreuid, 0},
// [87] = {sys_setregid, 0},
// [88] = {sys_umask, 0},
// [89] = {sys_pipe, 0},
// [90] = {sys_futex_wait, 0},
// [91] = {sys_futex_wake, 0},
// [92] = {sys_thread_create, 0},
// [93] = {sys_thread_kill, 0},
// [94] = {sys_thread_exit, 0},
// [95] = {sys_thread_setname, 0},
// [96] = {sys_thread_getname, 0},
// [97] = {sys_timer_create, 0},
// [98] = {sys_timer_set, 0},
// [99] = {sys_timer_get, 0},
// [100] = {sys_timer_getoverrun, 0},
// [101] = {sys_timer_delete, 0},
// [102] = {sys_itimer_get, 0},
// [103] = {sys_itimer_set, 0},
// [104] = {sys_clock_get, 0},
// [105] = {sys_clock_getres, 0},
// [106] = {sys_clock_set, 0},
// [107] = {sys_sleep, 0},
// [108] = {sys_yield, 0},
// [109] = {sys_chroot, 0},
// [110] = {sys_mount, 0},
// [111] = {sys_umount, 0},
// [112] = {sys_socket, 0},
// [113] = {sys_socketpair, 0},
// [114] = {sys_shutdown, 0},
// [115] = {sys_bind, 0},
// [116] = {sys_connect, 0},
// [117] = {sys_accept, 0},
// [118] = {sys_listen, 0},
// [119] = {sys_getpeername, 0},
// [120] = {sys_getsockname, 0},
// [121] = {sys_getsockopt, 0},
// [122] = {sys_setsockopt, 0},
// [123] = {sys_sendmsg, 0},
// [124] = {sys_recvmsg, 0},
// [125] = {sys_getentropy, 0},
// [126] = {sys_getrusage, 0},
// [127] = {sys_getrlimit, 0},
// [128] = {sys_setrlimit, 0},
// [129] = {sys_getpriority, 0},
// [130] = {sys_setpriority, 0},
// [131] = {sys_sched_getparam, 0},
// [132] = {sys_sched_setparam, 0},
// [133] = {sys_module_insert, 0},
// [134] = {sys_module_remove, 0},
// [135] = {sys_epoll_create, 0},
// [136] = {sys_epoll_ctl, 0},
// [137] = {sys_epoll_pwait, 0},
// [138] = {sys_timerfd_create, 0},
// [139] = {sys_timerfd_gettime, 0},
// [140] = {sys_timerfd_settime, 0},
// [141] = {sys_signalfd_create, 0},
// [142] = {sys_eventfd_create, 0},
// [143] = {sys_msync, 0},
// [144] = {sys_sysconf, 0},
};
[[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);
}
+17
View File
@@ -0,0 +1,17 @@
#include <zinnia/errno.h>
#include <zinnia/futex.h>
#include <zinnia/syscall.h>
errno_t syscall_futex_wait(struct arch_context* ctx) {
__user int* addr = (__user int*)ctx->ARCH_CTX_A0;
int expected = (int)ctx->ARCH_CTX_A1;
return futex_wait(addr, expected);
}
errno_t syscall_futex_wake(struct arch_context* ctx) {
__user int* addr = (__user int*)ctx->ARCH_CTX_A0;
int count = (int)ctx->ARCH_CTX_A1;
return futex_wake(addr, count);
}
+33
View File
@@ -0,0 +1,33 @@
#include <zinnia/spin.h>
#include <zinnia/syscall.h>
#include <zinnia/usercopy.h>
#include <config.h>
#include <uapi/utsname.h>
static spinlock_t 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_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;
}
+6
View File
@@ -0,0 +1,6 @@
kernel_sources += files(
'archctl.c',
'dispatch.c',
'futex.c',
'getuname.c',
)