The Pedigree Project 0.1
system-information-abi.h
1/* Copyright (c) 2026, Pedigree Developers. */
2#ifndef POSIX_SYSTEM_INFORMATION_ABI_H
3#define POSIX_SYSTEM_INFORMATION_ABI_H
4
5#include <stdint.h>
6
7namespace PosixSystemInformation {
8struct Record {
9 int64_t uptime = 0;
10 uint64_t loads[3] = {};
11 uint64_t totalram = 0, freeram = 0, sharedram = 0, bufferram = 0;
12 uint64_t totalswap = 0, freeswap = 0;
13 uint16_t procs = 0, pad = 0;
14 uint32_t alignment = 0;
15 uint64_t totalhigh = 0, freehigh = 0;
16 uint32_t mem_unit = 1, tail = 0;
17};
18static_assert(sizeof(Record) == 112, "Linux amd64 sysinfo ABI");
19static_assert(__builtin_offsetof(Record, totalhigh) == 88, "Linux sysinfo high-memory offset");
20static_assert(__builtin_offsetof(Record, mem_unit) == 104, "Linux sysinfo units offset");
21
22inline bool setMemory(Record& record, uint64_t total, uint64_t free, uint64_t swapTotal,
23 uint64_t swapUsed, uint64_t pageSize) {
24 const uint64_t maximum = ~uint64_t(0);
25 if (!pageSize || free > total || swapUsed > swapTotal || total > maximum / pageSize ||
26 swapTotal > maximum / pageSize)
27 return false;
28 record.totalram = total * pageSize;
29 record.freeram = free * pageSize;
30 record.totalswap = swapTotal * pageSize;
31 record.freeswap = (swapTotal - swapUsed) * pageSize;
32 return true;
33}
34} // namespace PosixSystemInformation
35
36#endif