#include "sys/Syscall.h" #include "thread/Scheduler.h" Result sys_getpid(Registers*, SyscallArgs) { return Scheduler::current()->id; } Result sys_getppid(Registers*, SyscallArgs) { return Scheduler::current()->parent_id; } Result sys_getuid(Registers*, SyscallArgs) { return Scheduler::current()->auth.uid; } Result sys_geteuid(Registers*, SyscallArgs) { return Scheduler::current()->auth.euid; } Result sys_getgid(Registers*, SyscallArgs) { return Scheduler::current()->auth.gid; } Result sys_getegid(Registers*, SyscallArgs) { return Scheduler::current()->auth.egid; } Result sys_setuid(Registers*, SyscallArgs args) { u32 uid = (u32)args[0]; Credentials& auth = Scheduler::current()->auth; if (auth.euid == 0) { auth.uid = auth.euid = auth.suid = uid; return 0; } if (uid != auth.uid && uid != auth.suid) return err(EPERM); auth.euid = uid; return 0; } Result sys_seteuid(Registers*, SyscallArgs args) { u32 uid = (u32)args[0]; Credentials& auth = Scheduler::current()->auth; if (auth.euid != 0 && uid != auth.uid && uid != auth.suid) return err(EPERM); auth.euid = uid; return 0; } Result sys_setgid(Registers*, SyscallArgs args) { u32 gid = (u32)args[0]; Credentials& auth = Scheduler::current()->auth; if (auth.euid == 0) { auth.gid = auth.egid = auth.sgid = gid; return 0; } if (gid != auth.gid && gid != auth.sgid) return err(EPERM); auth.egid = gid; return 0; } Result sys_setegid(Registers*, SyscallArgs args) { u32 gid = (u32)args[0]; Credentials& auth = Scheduler::current()->auth; if (auth.euid != 0 && gid != auth.gid && gid != auth.sgid) return err(EPERM); auth.egid = gid; return 0; }