The Pedigree Project 0.1
system-information-syscalls.cc
1/* Copyright (c) 2026, Pedigree Developers. */
2#include "pedigree/kernel/process/Scheduler.h"
3#include "pedigree/kernel/process/Thread.h"
4#include "pedigree/kernel/processor/PhysicalMemoryManager.h"
5#include "pedigree/kernel/processor/Processor.h"
6#include "pedigree/kernel/processor/ProcessorInformation.h"
7#include "pedigree/kernel/syscallError.h"
8#include "pedigree/kernel/time/Time.h"
9
10#include "PosixSubsystem.h"
12#include "system-information-abi.h"
13#include "system-information-syscalls.h"
14
15int posix_sysinfo(void* information) {
17 const auto memory = PhysicalMemoryManager::instance().memorySnapshot();
18 if (!memory.available) {
19 SYSCALL_ERROR(OperationNotSupported);
20 return -1;
21 }
22 const auto swap = MemoryMapManager::instance().swapSnapshot();
23 if (!PosixSystemInformation::setMemory(
24 snapshot, memory.totalPages, memory.freePages, swap.active ? swap.totalPages : 0,
25 swap.active ? swap.usedPages : 0, PhysicalMemoryManager::getPageSize())) {
26 SYSCALL_ERROR(ValueTooLarge);
27 return -1;
28 }
29 const uint64_t ticks = Time::getTicks();
30 snapshot.uptime = ticks / Time::Multiplier::Second + (ticks % Time::Multiplier::Second != 0);
31 const auto activity = Scheduler::instance().systemActivity();
32 snapshot.procs = activity.tasks > 65535 ? 65535 : activity.tasks;
33 for (size_t i = 0; i < 3; ++i)
34 snapshot.loads[i] = activity.loads[i];
35 // Separate shared-memory and buffer accounting is unavailable. amd64 has
36 // no high-memory zone. The explicit zero fields do not imply reclaimability.
37 if (!PosixSubsystem::copyToUser(information, &snapshot, sizeof(snapshot))) {
38 SYSCALL_ERROR(BadAddress);
39 return -1;
40 }
41 return 0;
42}
43
44int posix_personality(unsigned long requested) {
45 Thread& thread = *Processor::information().getCurrentThread();
46 uint32_t previous;
47 // Linux's argument is unsigned int even though musl exposes unsigned long.
48 const uint32_t value = static_cast<uint32_t>(requested);
49#if !X64
50 if (value == ExecutionPersonality::Linux32) {
51 SYSCALL_ERROR(InvalidArgument);
52 return -1;
53 }
54#endif
55 if (!thread.executionPersonality().select(value, previous)) {
56 SYSCALL_ERROR(InvalidArgument);
57 return -1;
58 }
59 return previous;
60}
Memory-mapped file interface.
static MemoryMapManager & instance()
static PhysicalMemoryManager & instance()
static bool copyToUser(void *destination, const void *source, size_t count, size_t elementSize=1)
static ProcessorInformation & information()
static Scheduler & instance()
Definition Scheduler.h:96