diff --git a/Kernel/subsystem/linux/include/defs.hpp b/Kernel/subsystem/linux/include/defs.hpp index 59f6c85d..739faa91 100644 --- a/Kernel/subsystem/linux/include/defs.hpp +++ b/Kernel/subsystem/linux/include/defs.hpp @@ -428,4 +428,23 @@ typedef struct cpu_set_t #define CPU_SET(i, set) CPU_BIT_OP(i, sizeof(cpu_set_t), set, |=) #define CPU_ZERO(set) (memset((set), 0, sizeof(cpu_set_t))) +/* taken from https://man7.org/linux/man-pages/man2/sysinfo.2.html */ +struct sysinfo +{ + long uptime; /* Seconds since boot */ + unsigned long loads[3]; /* 1, 5, and 15 minute load averages */ + unsigned long totalram; /* Total usable main memory size */ + unsigned long freeram; /* Available memory size */ + unsigned long sharedram; /* Amount of shared memory */ + unsigned long bufferram; /* Memory used by buffers */ + unsigned long totalswap; /* Total swap space size */ + unsigned long freeswap; /* Swap space still available */ + unsigned short procs; /* Number of current processes */ + unsigned long totalhigh; /* Total high memory size */ + unsigned long freehigh; /* Available high memory size */ + unsigned int mem_unit; /* Memory unit size in bytes */ + + char _f[20 - 2 * sizeof(long) - sizeof(int)]; /* Padding to 64 bytes */ +}; + #endif // !__FENNIX_KERNEL_LINUX_DEFS_H__ diff --git a/Kernel/subsystem/linux/syscall.cpp b/Kernel/subsystem/linux/syscall.cpp index af5dbe20..b2b2c4dc 100644 --- a/Kernel/subsystem/linux/syscall.cpp +++ b/Kernel/subsystem/linux/syscall.cpp @@ -2547,6 +2547,38 @@ static int linux_getrusage(SysFrm *, int who, struct rusage *usage) return 0; } +static int linux_sysinfo(SysFrm *, struct sysinfo *info) +{ + PCB *pcb = thisProcess; + Memory::VirtualMemoryArea *vma = pcb->vma; + + auto pInfo = vma->UserCheckAndGetAddress(info); + if (pInfo == nullptr) + return -linux_EFAULT; + + uint64_t nano = TimeManager->GetNanosecondsSinceClassCreation(); + if (nano != 0) + nano /= 10000000; + + pInfo->uptime = nano; + pInfo->loads[0] = 0; + pInfo->loads[1] = 0; + pInfo->loads[2] = 0; + pInfo->totalram = KernelAllocator.GetTotalMemory() - KernelAllocator.GetReservedMemory(); + pInfo->freeram = KernelAllocator.GetFreeMemory(); + pInfo->sharedram = 0; + pInfo->bufferram = 0; + pInfo->totalswap = 0; + pInfo->freeswap = 0; + pInfo->procs = TaskManager->GetProcessList().size(); + pInfo->totalhigh = 0; + pInfo->freehigh = 0; + pInfo->mem_unit = 1; + if (sizeof(pInfo->_f) != 0) + memset(pInfo->_f, 0, sizeof(pInfo->_f)); + return 0; +} + static int linux_syslog(SysFrm *, int type, char *bufp, int size) { PCB *pcb = thisProcess; @@ -3629,7 +3661,7 @@ static SyscallData LinuxSyscallsTableAMD64[] = { [__NR_amd64_gettimeofday] = {"gettimeofday", (void *)nullptr}, [__NR_amd64_getrlimit] = {"getrlimit", (void *)nullptr}, [__NR_amd64_getrusage] = {"getrusage", (void *)linux_getrusage}, - [__NR_amd64_sysinfo] = {"sysinfo", (void *)nullptr}, + [__NR_amd64_sysinfo] = {"sysinfo", (void *)linux_sysinfo}, [__NR_amd64_times] = {"times", (void *)nullptr}, [__NR_amd64_ptrace] = {"ptrace", (void *)nullptr}, [__NR_amd64_getuid] = {"getuid", (void *)linux_getuid}, @@ -4096,7 +4128,7 @@ static SyscallData LinuxSyscallsTableI386[] = { [__NR_i386_vm86old] = {"vm86old", (void *)nullptr}, [__NR_i386_wait4] = {"wait4", (void *)linux_wait4}, [__NR_i386_swapoff] = {"swapoff", (void *)nullptr}, - [__NR_i386_sysinfo] = {"sysinfo", (void *)nullptr}, + [__NR_i386_sysinfo] = {"sysinfo", (void *)linux_sysinfo}, [__NR_i386_ipc] = {"ipc", (void *)nullptr}, [__NR_i386_fsync] = {"fsync", (void *)nullptr}, [__NR_i386_sigreturn] = {"sigreturn", (void *)nullptr},