2020-06-15 14:18:57 +00:00
|
|
|
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
|
|
|
│ vi: set et ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi │
|
|
|
|
╞══════════════════════════════════════════════════════════════════════════════╡
|
|
|
|
│ Copyright 2020 Justine Alexandra Roberts Tunney │
|
|
|
|
│ │
|
2020-12-28 01:18:44 +00:00
|
|
|
│ Permission to use, copy, modify, and/or distribute this software for │
|
|
|
|
│ any purpose with or without fee is hereby granted, provided that the │
|
|
|
|
│ above copyright notice and this permission notice appear in all copies. │
|
2020-06-15 14:18:57 +00:00
|
|
|
│ │
|
2020-12-28 01:18:44 +00:00
|
|
|
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
|
|
|
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
|
|
|
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
|
|
|
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
|
|
|
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
|
|
|
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
|
|
|
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
|
|
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
2020-06-15 14:18:57 +00:00
|
|
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
2023-11-01 13:08:58 +00:00
|
|
|
#include "libc/calls/struct/sigset.internal.h"
|
2020-06-15 14:18:57 +00:00
|
|
|
#include "libc/calls/struct/sysinfo.h"
|
2023-11-01 13:08:58 +00:00
|
|
|
#include "libc/calls/struct/sysinfo.internal.h"
|
|
|
|
#include "libc/calls/syscall-nt.internal.h"
|
|
|
|
#include "libc/intrin/weaken.h"
|
|
|
|
#include "libc/mem/mem.h"
|
2020-06-15 14:18:57 +00:00
|
|
|
#include "libc/nt/accounting.h"
|
2023-11-01 13:08:58 +00:00
|
|
|
#include "libc/nt/process.h"
|
2020-06-15 14:18:57 +00:00
|
|
|
#include "libc/nt/struct/memorystatusex.h"
|
2023-10-11 18:45:31 +00:00
|
|
|
#include "libc/nt/synchronization.h"
|
2023-11-01 13:08:58 +00:00
|
|
|
|
|
|
|
static textwindows uint16_t GetProcessCount(void) {
|
|
|
|
uint16_t res;
|
|
|
|
uint32_t have, got, *pids;
|
|
|
|
uint32_t stack_memory[1000];
|
|
|
|
have = 0xFFFF * 4;
|
|
|
|
if (!_weaken(malloc) || !(pids = _weaken(malloc)(have))) {
|
|
|
|
pids = stack_memory;
|
|
|
|
have = sizeof(stack_memory);
|
|
|
|
}
|
|
|
|
if (EnumProcesses(pids, have, &got)) {
|
|
|
|
res = got / 4;
|
|
|
|
} else {
|
|
|
|
res = 0;
|
|
|
|
}
|
|
|
|
if (pids != stack_memory && _weaken(free)) {
|
|
|
|
_weaken(free)(pids);
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
2020-06-15 14:18:57 +00:00
|
|
|
|
2021-02-04 03:35:29 +00:00
|
|
|
textwindows int sys_sysinfo_nt(struct sysinfo *info) {
|
2023-11-01 13:08:58 +00:00
|
|
|
int i;
|
|
|
|
double load[3];
|
2020-06-15 14:18:57 +00:00
|
|
|
struct NtMemoryStatusEx memstat;
|
2023-11-01 13:08:58 +00:00
|
|
|
BLOCK_SIGNALS;
|
|
|
|
if (sys_getloadavg_nt(load, 3) != -1) {
|
|
|
|
for (i = 0; i < 3; ++i) {
|
|
|
|
info->loads[i] = load[i] * 65536;
|
|
|
|
}
|
|
|
|
}
|
2020-06-15 14:18:57 +00:00
|
|
|
memstat.dwLength = sizeof(struct NtMemoryStatusEx);
|
|
|
|
if (GlobalMemoryStatusEx(&memstat)) {
|
|
|
|
info->totalram = memstat.ullTotalPhys;
|
|
|
|
info->freeram = memstat.ullAvailPhys;
|
|
|
|
}
|
2023-11-01 13:08:58 +00:00
|
|
|
info->uptime = GetTickCount64() / 1000;
|
|
|
|
info->procs = GetProcessCount();
|
|
|
|
info->mem_unit = 1;
|
|
|
|
ALLOW_SIGNALS;
|
|
|
|
return 0;
|
2020-06-15 14:18:57 +00:00
|
|
|
}
|