2#ifndef POSIX_SYSTEM_INFORMATION_ABI_H
3#define POSIX_SYSTEM_INFORMATION_ABI_H
7namespace PosixSystemInformation {
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;
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");
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)
28 record.totalram = total * pageSize;
29 record.freeram = free * pageSize;
30 record.totalswap = swapTotal * pageSize;
31 record.freeswap = (swapTotal - swapUsed) * pageSize;