This commit is contained in:
2026-09-16 05:12:52 +02:00
parent 3e9bdf72c9
commit 6719239036
5 changed files with 344 additions and 310 deletions
+5 -7
View File
@@ -5,7 +5,6 @@
#include <zinnia/pmap.h>
#include <zinnia/sched.h>
#include <zinnia/vas.h>
#include <zinnia/virt.h>
#include <bits/sched.h>
#include <stddef.h>
#include <stdint.h>
@@ -21,7 +20,7 @@ struct task_frame {
};
[[__naked]]
static void perform_switch(uint64_t* old_rsp, uint64_t new_rsp) {
static struct task* perform_switch(uint64_t* old_rsp, uint64_t new_rsp, struct task* prev) {
asm volatile(
"sub rsp, 0x30\n" // Make room for all regs (except RIP).
"mov [rsp + %c0], rbx\n"
@@ -39,7 +38,7 @@ static void perform_switch(uint64_t* old_rsp, uint64_t new_rsp) {
"mov r14, [rsp + %c4]\n"
"mov r15, [rsp + %c5]\n"
"add rsp, 0x30\n"
"call %c6\n"
"mov rax, rdx\n"
"ret" // This will conveniently move us to the RIP we put at this stack entry.
:
: "i"(offsetof(struct task_frame, rbx)),
@@ -47,13 +46,12 @@ static void perform_switch(uint64_t* old_rsp, uint64_t new_rsp) {
"i"(offsetof(struct task_frame, r12)),
"i"(offsetof(struct task_frame, r13)),
"i"(offsetof(struct task_frame, r14)),
"i"(offsetof(struct task_frame, r15)),
"i"(irq_unlock)
"i"(offsetof(struct task_frame, r15))
: "memory"
);
}
void arch_sched_switch(struct task* from, struct task* to) {
struct task* arch_sched_switch(struct task* from, struct task* to) {
struct arch_percpu* cpu = &percpu_get()->arch;
struct arch_task_context* from_ctx = &from->context;
struct arch_task_context* to_ctx = &to->context;
@@ -87,7 +85,7 @@ void arch_sched_switch(struct task* from, struct task* to) {
asm_wrmsr(MSR_KERNEL_GS_BASE, to_ctx->gs_base);
}
perform_switch(&from_ctx->rsp, to_ctx->rsp);
return perform_switch(&from_ctx->rsp, to_ctx->rsp, from);
}
[[__naked]]
+1 -1
View File
@@ -88,7 +88,7 @@ struct task_start_info {
void arch_sched_preempt_disable();
bool arch_sched_preempt_enable();
void arch_sched_switch(struct task* from, struct task* to);
struct task* arch_sched_switch(struct task* from, struct task* to);
errno_t arch_task_init(
struct arch_task_context* context,
void* entry,
+20 -10
View File
@@ -2,24 +2,34 @@
#include <zinnia/sched.h>
enum syscall_kind {
enum syscall_kind : uint8_t {
SYSKIND_CALL = 0, // Regular call, returns error and/or value.
SYSKIND_CONTEXT, // Consumes the entire register image.
SYSKIND_NORETURN, // Does not resume control to the calling process.
};
struct syscall {
void (*handler)(struct arch_context*);
enum syscall_kind kind;
};
struct syscall_return {
int errno;
uintptr_t value;
int errno;
};
struct syscall {
union {
struct syscall_return (*call)(uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t);
void (*context)(struct arch_context*);
};
enum syscall_kind kind;
};
struct syscall_return syscall_dispatch_call(
size_t num,
uintptr_t a0,
uintptr_t a1,
uintptr_t a2,
uintptr_t a3,
uintptr_t a4,
uintptr_t a5
);
void syscall_dispatch(struct arch_context* ctx);
#include <zinnia/syscall_list.h>
extern const struct syscall syscall_table[256];
+152 -145
View File
@@ -1,149 +1,156 @@
#pragma once
#include <zinnia/sched.h>
#include <zinnia/syscall.h>
#include <stdint.h>
extern void sys_exit(struct arch_context* ctx);
extern void sys_syslog(struct arch_context* ctx);
extern void sys_getuname(struct arch_context* ctx);
extern void sys_setuname(struct arch_context* ctx);
extern void sys_archctl(struct arch_context* ctx);
extern void sys_reboot(struct arch_context* ctx);
extern void sys_mmap(struct arch_context* ctx);
extern void sys_munmap(struct arch_context* ctx);
extern void sys_mprotect(struct arch_context* ctx);
extern void sys_madvise(struct arch_context* ctx);
extern void sys_sigprocmask(struct arch_context* ctx);
extern void sys_sigsuspend(struct arch_context* ctx);
extern void sys_sigpending(struct arch_context* ctx);
extern void sys_sigaction(struct arch_context* ctx);
extern void sys_sigtimedwait(struct arch_context* ctx);
extern void sys_sigaltstack(struct arch_context* ctx);
extern void sys_sigreturn(struct arch_context* ctx);
extern void sys_sigqueue(struct arch_context* ctx);
extern void sys_execve(struct arch_context* ctx);
extern void sys_fexecve(struct arch_context* ctx);
extern void sys_fork(struct arch_context* ctx);
extern void sys_kill(struct arch_context* ctx);
extern void sys_gettid(struct arch_context* ctx);
extern void sys_getpid(struct arch_context* ctx);
extern void sys_getppid(struct arch_context* ctx);
extern void sys_waitid(struct arch_context* ctx);
extern void sys_waitpid(struct arch_context* ctx);
extern void sys_pread(struct arch_context* ctx);
extern void sys_readv(struct arch_context* ctx);
extern void sys_pwrite(struct arch_context* ctx);
extern void sys_writev(struct arch_context* ctx);
extern void sys_seek(struct arch_context* ctx);
extern void sys_ioctl(struct arch_context* ctx);
extern void sys_openat(struct arch_context* ctx);
extern void sys_close(struct arch_context* ctx);
extern void sys_fstat(struct arch_context* ctx);
extern void sys_fstatat(struct arch_context* ctx);
extern void sys_statvfs(struct arch_context* ctx);
extern void sys_fstatvfs(struct arch_context* ctx);
extern void sys_faccessat(struct arch_context* ctx);
extern void sys_fcntl(struct arch_context* ctx);
extern void sys_ftruncate(struct arch_context* ctx);
extern void sys_truncate(struct arch_context* ctx);
extern void sys_fallocate(struct arch_context* ctx);
extern void sys_fadvise(struct arch_context* ctx);
extern void sys_utimensat(struct arch_context* ctx);
extern void sys_mknodat(struct arch_context* ctx);
extern void sys_getcwd(struct arch_context* ctx);
extern void sys_chdir(struct arch_context* ctx);
extern void sys_fchdir(struct arch_context* ctx);
extern void sys_mkdirat(struct arch_context* ctx);
extern void sys_rmdirat(struct arch_context* ctx);
extern void sys_getdents(struct arch_context* ctx);
extern void sys_renameat(struct arch_context* ctx);
extern void sys_fchmod(struct arch_context* ctx);
extern void sys_fchmodat(struct arch_context* ctx);
extern void sys_fchownat(struct arch_context* ctx);
extern void sys_linkat(struct arch_context* ctx);
extern void sys_symlinkat(struct arch_context* ctx);
extern void sys_unlinkat(struct arch_context* ctx);
extern void sys_readlinkat(struct arch_context* ctx);
extern void sys_flock(struct arch_context* ctx);
extern void sys_ppoll(struct arch_context* ctx);
extern void sys_dup(struct arch_context* ctx);
extern void sys_dup3(struct arch_context* ctx);
extern void sys_sync(struct arch_context* ctx);
extern void sys_fsync(struct arch_context* ctx);
extern void sys_fdatasync(struct arch_context* ctx);
extern void sys_getgroups(struct arch_context* ctx);
extern void sys_setgroups(struct arch_context* ctx);
extern void sys_getsid(struct arch_context* ctx);
extern void sys_setsid(struct arch_context* ctx);
extern void sys_setuid(struct arch_context* ctx);
extern void sys_getuid(struct arch_context* ctx);
extern void sys_setgid(struct arch_context* ctx);
extern void sys_getgid(struct arch_context* ctx);
extern void sys_geteuid(struct arch_context* ctx);
extern void sys_seteuid(struct arch_context* ctx);
extern void sys_getegid(struct arch_context* ctx);
extern void sys_setegid(struct arch_context* ctx);
extern void sys_getpgid(struct arch_context* ctx);
extern void sys_setpgid(struct arch_context* ctx);
extern void sys_getresuid(struct arch_context* ctx);
extern void sys_setresuid(struct arch_context* ctx);
extern void sys_getresgid(struct arch_context* ctx);
extern void sys_setresgid(struct arch_context* ctx);
extern void sys_setreuid(struct arch_context* ctx);
extern void sys_setregid(struct arch_context* ctx);
extern void sys_umask(struct arch_context* ctx);
extern void sys_pipe(struct arch_context* ctx);
extern void sys_futex_wait(struct arch_context* ctx);
extern void sys_futex_wake(struct arch_context* ctx);
extern void sys_thread_create(struct arch_context* ctx);
extern void sys_thread_kill(struct arch_context* ctx);
extern void sys_thread_exit(struct arch_context* ctx);
extern void sys_thread_setname(struct arch_context* ctx);
extern void sys_thread_getname(struct arch_context* ctx);
extern void sys_timer_create(struct arch_context* ctx);
extern void sys_timer_set(struct arch_context* ctx);
extern void sys_timer_get(struct arch_context* ctx);
extern void sys_timer_getoverrun(struct arch_context* ctx);
extern void sys_timer_delete(struct arch_context* ctx);
extern void sys_itimer_get(struct arch_context* ctx);
extern void sys_itimer_set(struct arch_context* ctx);
extern void sys_clock_get(struct arch_context* ctx);
extern void sys_clock_getres(struct arch_context* ctx);
extern void sys_clock_set(struct arch_context* ctx);
extern void sys_sleep(struct arch_context* ctx);
extern void sys_yield(struct arch_context* ctx);
extern void sys_chroot(struct arch_context* ctx);
extern void sys_mount(struct arch_context* ctx);
extern void sys_umount(struct arch_context* ctx);
extern void sys_socket(struct arch_context* ctx);
extern void sys_socketpair(struct arch_context* ctx);
extern void sys_shutdown(struct arch_context* ctx);
extern void sys_bind(struct arch_context* ctx);
extern void sys_connect(struct arch_context* ctx);
extern void sys_accept(struct arch_context* ctx);
extern void sys_listen(struct arch_context* ctx);
extern void sys_getpeername(struct arch_context* ctx);
extern void sys_getsockname(struct arch_context* ctx);
extern void sys_getsockopt(struct arch_context* ctx);
extern void sys_setsockopt(struct arch_context* ctx);
extern void sys_sendmsg(struct arch_context* ctx);
extern void sys_recvmsg(struct arch_context* ctx);
extern void sys_getentropy(struct arch_context* ctx);
extern void sys_getrusage(struct arch_context* ctx);
extern void sys_getrlimit(struct arch_context* ctx);
extern void sys_setrlimit(struct arch_context* ctx);
extern void sys_getpriority(struct arch_context* ctx);
extern void sys_setpriority(struct arch_context* ctx);
extern void sys_sched_getparam(struct arch_context* ctx);
extern void sys_sched_setparam(struct arch_context* ctx);
extern void sys_module_insert(struct arch_context* ctx);
extern void sys_module_remove(struct arch_context* ctx);
extern void sys_epoll_create(struct arch_context* ctx);
extern void sys_epoll_ctl(struct arch_context* ctx);
extern void sys_epoll_pwait(struct arch_context* ctx);
extern void sys_timerfd_create(struct arch_context* ctx);
extern void sys_timerfd_gettime(struct arch_context* ctx);
extern void sys_timerfd_settime(struct arch_context* ctx);
extern void sys_signalfd_create(struct arch_context* ctx);
extern void sys_eventfd_create(struct arch_context* ctx);
extern void sys_msync(struct arch_context* ctx);
extern void sys_sysconf(struct arch_context* ctx);
#define __SYSCALL_CALL(name) \
struct syscall_return sys_##name(uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t)
#define __SYSCALL_CONTEXT(name) void sys_##name(struct arch_context*)
__SYSCALL_CALL(exit);
__SYSCALL_CALL(syslog);
__SYSCALL_CALL(getuname);
__SYSCALL_CALL(setuname);
__SYSCALL_CALL(archctl);
__SYSCALL_CALL(reboot);
__SYSCALL_CALL(mmap);
__SYSCALL_CALL(munmap);
__SYSCALL_CALL(mprotect);
__SYSCALL_CALL(madvise);
__SYSCALL_CALL(sigprocmask);
__SYSCALL_CALL(sigsuspend);
__SYSCALL_CALL(sigpending);
__SYSCALL_CALL(sigaction);
__SYSCALL_CALL(sigtimedwait);
__SYSCALL_CALL(sigaltstack);
__SYSCALL_CALL(sigreturn);
__SYSCALL_CALL(sigqueue);
__SYSCALL_CALL(execve);
__SYSCALL_CALL(fexecve);
__SYSCALL_CONTEXT(fork);
__SYSCALL_CALL(kill);
__SYSCALL_CALL(gettid);
__SYSCALL_CALL(getpid);
__SYSCALL_CALL(getppid);
__SYSCALL_CALL(waitid);
__SYSCALL_CALL(waitpid);
__SYSCALL_CALL(pread);
__SYSCALL_CALL(readv);
__SYSCALL_CALL(pwrite);
__SYSCALL_CALL(writev);
__SYSCALL_CALL(seek);
__SYSCALL_CALL(ioctl);
__SYSCALL_CALL(openat);
__SYSCALL_CALL(close);
__SYSCALL_CALL(fstat);
__SYSCALL_CALL(fstatat);
__SYSCALL_CALL(statvfs);
__SYSCALL_CALL(fstatvfs);
__SYSCALL_CALL(faccessat);
__SYSCALL_CALL(fcntl);
__SYSCALL_CALL(ftruncate);
__SYSCALL_CALL(truncate);
__SYSCALL_CALL(fallocate);
__SYSCALL_CALL(fadvise);
__SYSCALL_CALL(utimensat);
__SYSCALL_CALL(mknodat);
__SYSCALL_CALL(getcwd);
__SYSCALL_CALL(chdir);
__SYSCALL_CALL(fchdir);
__SYSCALL_CALL(mkdirat);
__SYSCALL_CALL(rmdirat);
__SYSCALL_CALL(getdents);
__SYSCALL_CALL(renameat);
__SYSCALL_CALL(fchmod);
__SYSCALL_CALL(fchmodat);
__SYSCALL_CALL(fchownat);
__SYSCALL_CALL(linkat);
__SYSCALL_CALL(symlinkat);
__SYSCALL_CALL(unlinkat);
__SYSCALL_CALL(readlinkat);
__SYSCALL_CALL(flock);
__SYSCALL_CALL(ppoll);
__SYSCALL_CALL(dup);
__SYSCALL_CALL(dup3);
__SYSCALL_CALL(sync);
__SYSCALL_CALL(fsync);
__SYSCALL_CALL(fdatasync);
__SYSCALL_CALL(getgroups);
__SYSCALL_CALL(setgroups);
__SYSCALL_CALL(getsid);
__SYSCALL_CALL(setsid);
__SYSCALL_CALL(setuid);
__SYSCALL_CALL(getuid);
__SYSCALL_CALL(setgid);
__SYSCALL_CALL(getgid);
__SYSCALL_CALL(geteuid);
__SYSCALL_CALL(seteuid);
__SYSCALL_CALL(getegid);
__SYSCALL_CALL(setegid);
__SYSCALL_CALL(getpgid);
__SYSCALL_CALL(setpgid);
__SYSCALL_CALL(getresuid);
__SYSCALL_CALL(setresuid);
__SYSCALL_CALL(getresgid);
__SYSCALL_CALL(setresgid);
__SYSCALL_CALL(setreuid);
__SYSCALL_CALL(setregid);
__SYSCALL_CALL(umask);
__SYSCALL_CALL(pipe);
__SYSCALL_CALL(futex_wait);
__SYSCALL_CALL(futex_wake);
__SYSCALL_CALL(thread_create);
__SYSCALL_CALL(thread_kill);
__SYSCALL_CALL(thread_exit);
__SYSCALL_CALL(thread_setname);
__SYSCALL_CALL(thread_getname);
__SYSCALL_CALL(timer_create);
__SYSCALL_CALL(timer_set);
__SYSCALL_CALL(timer_get);
__SYSCALL_CALL(timer_getoverrun);
__SYSCALL_CALL(timer_delete);
__SYSCALL_CALL(itimer_get);
__SYSCALL_CALL(itimer_set);
__SYSCALL_CALL(clock_get);
__SYSCALL_CALL(clock_getres);
__SYSCALL_CALL(clock_set);
__SYSCALL_CALL(sleep);
__SYSCALL_CALL(yield);
__SYSCALL_CALL(chroot);
__SYSCALL_CALL(mount);
__SYSCALL_CALL(umount);
__SYSCALL_CALL(socket);
__SYSCALL_CALL(socketpair);
__SYSCALL_CALL(shutdown);
__SYSCALL_CALL(bind);
__SYSCALL_CALL(connect);
__SYSCALL_CALL(accept);
__SYSCALL_CALL(listen);
__SYSCALL_CALL(getpeername);
__SYSCALL_CALL(getsockname);
__SYSCALL_CALL(getsockopt);
__SYSCALL_CALL(setsockopt);
__SYSCALL_CALL(sendmsg);
__SYSCALL_CALL(recvmsg);
__SYSCALL_CALL(getentropy);
__SYSCALL_CALL(getrusage);
__SYSCALL_CALL(getrlimit);
__SYSCALL_CALL(setrlimit);
__SYSCALL_CALL(getpriority);
__SYSCALL_CALL(setpriority);
__SYSCALL_CALL(sched_getparam);
__SYSCALL_CALL(sched_setparam);
__SYSCALL_CALL(module_insert);
__SYSCALL_CALL(module_remove);
__SYSCALL_CALL(epoll_create);
__SYSCALL_CALL(epoll_ctl);
__SYSCALL_CALL(epoll_pwait);
__SYSCALL_CALL(timerfd_create);
__SYSCALL_CALL(timerfd_gettime);
__SYSCALL_CALL(timerfd_settime);
__SYSCALL_CALL(signalfd_create);
__SYSCALL_CALL(eventfd_create);
__SYSCALL_CALL(msync);
__SYSCALL_CALL(sysconf);
+166 -147
View File
@@ -3,164 +3,183 @@
#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>
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, SYSKIND_CONTEXT},
[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},
[0] = {.call = sys_exit},
[1] = {.call = sys_syslog},
[2] = {.call = sys_getuname},
[3] = {.call = sys_setuname},
[4] = {.call = sys_archctl},
[5] = {.call = sys_reboot},
[6] = {.call = sys_mmap},
[7] = {.call = sys_munmap},
[8] = {.call = sys_mprotect},
[9] = {.call = sys_madvise},
[10] = {.call = sys_sigprocmask},
[11] = {.call = sys_sigsuspend},
[12] = {.call = sys_sigpending},
[13] = {.call = sys_sigaction},
[14] = {.call = sys_sigtimedwait},
[15] = {.call = sys_sigaltstack},
[16] = {.call = sys_sigreturn},
[17] = {.call = sys_sigqueue},
[18] = {.call = sys_execve},
[19] = {.call = sys_fexecve},
[20] = {.context = sys_fork, SYSKIND_CONTEXT},
[21] = {.call = sys_kill},
[22] = {.call = sys_gettid},
[23] = {.call = sys_getpid},
[24] = {.call = sys_getppid},
[25] = {.call = sys_waitid},
[26] = {.call = sys_waitpid},
[27] = {.call = sys_pread},
[28] = {.call = sys_readv},
[29] = {.call = sys_pwrite},
[30] = {.call = sys_writev},
[31] = {.call = sys_seek},
[32] = {.call = sys_ioctl},
[33] = {.call = sys_openat},
[34] = {.call = sys_close},
[35] = {.call = sys_fstat},
[36] = {.call = sys_fstatat},
[37] = {.call = sys_statvfs},
[38] = {.call = sys_fstatvfs},
[39] = {.call = sys_faccessat},
[40] = {.call = sys_fcntl},
[41] = {.call = sys_ftruncate},
[42] = {.call = sys_truncate},
[43] = {.call = sys_fallocate},
[44] = {.call = sys_fadvise},
[45] = {.call = sys_utimensat},
[46] = {.call = sys_mknodat},
[47] = {.call = sys_getcwd},
[48] = {.call = sys_chdir},
[49] = {.call = sys_fchdir},
[50] = {.call = sys_mkdirat},
[51] = {.call = sys_rmdirat},
[52] = {.call = sys_getdents},
[53] = {.call = sys_renameat},
[54] = {.call = sys_fchmod},
[55] = {.call = sys_fchmodat},
[56] = {.call = sys_fchownat},
[57] = {.call = sys_linkat},
[58] = {.call = sys_symlinkat},
[59] = {.call = sys_unlinkat},
[60] = {.call = sys_readlinkat},
[61] = {.call = sys_flock},
[62] = {.call = sys_ppoll},
[63] = {.call = sys_dup},
[64] = {.call = sys_dup3},
[65] = {.call = sys_sync},
[66] = {.call = sys_fsync},
[67] = {.call = sys_fdatasync},
[68] = {.call = sys_getgroups},
[69] = {.call = sys_setgroups},
[70] = {.call = sys_getsid},
[71] = {.call = sys_setsid},
[72] = {.call = sys_setuid},
[73] = {.call = sys_getuid},
[74] = {.call = sys_setgid},
[75] = {.call = sys_getgid},
[76] = {.call = sys_geteuid},
[77] = {.call = sys_seteuid},
[78] = {.call = sys_getegid},
[79] = {.call = sys_setegid},
[80] = {.call = sys_getpgid},
[81] = {.call = sys_setpgid},
[82] = {.call = sys_getresuid},
[83] = {.call = sys_setresuid},
[84] = {.call = sys_getresgid},
[85] = {.call = sys_setresgid},
[86] = {.call = sys_setreuid},
[87] = {.call = sys_setregid},
[88] = {.call = sys_umask},
[89] = {.call = sys_pipe},
[90] = {.call = sys_futex_wait},
[91] = {.call = sys_futex_wake},
[92] = {.call = sys_thread_create},
[93] = {.call = sys_thread_kill},
[94] = {.call = sys_thread_exit},
[95] = {.call = sys_thread_setname},
[96] = {.call = sys_thread_getname},
[97] = {.call = sys_timer_create},
[98] = {.call = sys_timer_set},
[99] = {.call = sys_timer_get},
[100] = {.call = sys_timer_getoverrun},
[101] = {.call = sys_timer_delete},
[102] = {.call = sys_itimer_get},
[103] = {.call = sys_itimer_set},
[104] = {.call = sys_clock_get},
[105] = {.call = sys_clock_getres},
[106] = {.call = sys_clock_set},
[107] = {.call = sys_sleep},
[108] = {.call = sys_yield},
[109] = {.call = sys_chroot},
[110] = {.call = sys_mount},
[111] = {.call = sys_umount},
[112] = {.call = sys_socket},
[113] = {.call = sys_socketpair},
[114] = {.call = sys_shutdown},
[115] = {.call = sys_bind},
[116] = {.call = sys_connect},
[117] = {.call = sys_accept},
[118] = {.call = sys_listen},
[119] = {.call = sys_getpeername},
[120] = {.call = sys_getsockname},
[121] = {.call = sys_getsockopt},
[122] = {.call = sys_setsockopt},
[123] = {.call = sys_sendmsg},
[124] = {.call = sys_recvmsg},
[125] = {.call = sys_getentropy},
[126] = {.call = sys_getrusage},
[127] = {.call = sys_getrlimit},
[128] = {.call = sys_setrlimit},
[129] = {.call = sys_getpriority},
[130] = {.call = sys_setpriority},
[131] = {.call = sys_sched_getparam},
[132] = {.call = sys_sched_setparam},
[133] = {.call = sys_module_insert},
[134] = {.call = sys_module_remove},
[135] = {.call = sys_epoll_create},
[136] = {.call = sys_epoll_ctl},
[137] = {.call = sys_epoll_pwait},
[138] = {.call = sys_timerfd_create},
[139] = {.call = sys_timerfd_gettime},
[140] = {.call = sys_timerfd_settime},
[141] = {.call = sys_signalfd_create},
[142] = {.call = sys_eventfd_create},
[143] = {.call = sys_msync},
[144] = {.call = sys_sysconf},
};
struct syscall_return syscall_dispatch_call(
size_t num,
uintptr_t a0,
uintptr_t a1,
uintptr_t a2,
uintptr_t a3,
uintptr_t a4,
uintptr_t a5
) {
// 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].call == nullptr) {
return (struct syscall_return){.errno = ENOSYS};
}
return syscall_table[num].call(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].handler == nullptr) {
if (num >= ARRAY_SIZE(syscall_table) || syscall_table[num].context == nullptr) {
ctx->ARCH_CTX_RET0 = ENOSYS;
return;
}
syscall_table[num].handler(ctx);
syscall_table[num].context(ctx);
}