forked from ish-app/ish
-
Notifications
You must be signed in to change notification settings - Fork 11
/
uname.c
77 lines (68 loc) · 2.04 KB
/
uname.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <sys/utsname.h>
#include <string.h>
#include "kernel/calls.h"
#include "platform/platform.h"
#if __APPLE__
#include <sys/sysctl.h>
#elif __linux__
#include <sys/sysinfo.h>
#endif
const char *uname_version = "SUPER AWESOME";
void do_uname(struct uname *uts) {
struct utsname real_uname;
uname(&real_uname);
memset(uts, 0, sizeof(struct uname));
strcpy(uts->system, "Linux");
strcpy(uts->hostname, real_uname.nodename);
strcpy(uts->release, "3.2.0-ish");
snprintf(uts->version, sizeof(uts->version), "%s %s %s", uname_version, __DATE__, __TIME__);
strcpy(uts->arch, "i686");
strcpy(uts->domain, "(none)");
}
dword_t sys_uname(addr_t uts_addr) {
struct uname uts;
do_uname(&uts);
if (user_put(uts_addr, uts))
return _EFAULT;
return 0;
}
dword_t sys_sethostname(addr_t UNUSED(hostname_addr), dword_t UNUSED(hostname_len)) {
return _EPERM;
}
#if __APPLE__
static uint64_t get_total_ram() {
uint64_t total_ram;
sysctl((int []) {CTL_DEBUG, HW_PHYSMEM}, 2, &total_ram, NULL, NULL, 0);
return total_ram;
}
static void sysinfo_specific(struct sys_info *info) {
info->totalram = get_total_ram();
// TODO: everything else
}
#elif __linux__
static void sysinfo_specific(struct sys_info *info) {
struct sysinfo host_info;
sysinfo(&host_info);
info->totalram = host_info.totalram;
info->freeram = host_info.freeram;
info->sharedram = host_info.sharedram;
info->totalswap = host_info.totalswap;
info->freeswap = host_info.freeswap;
info->procs = host_info.procs;
info->totalhigh = host_info.totalhigh;
info->freehigh = host_info.freehigh;
info->mem_unit = host_info.mem_unit;
}
#endif
dword_t sys_sysinfo(addr_t info_addr) {
struct sys_info info = {0};
struct uptime_info uptime = get_uptime();
info.uptime = uptime.uptime_ticks;
info.loads[0] = uptime.load_1m;
info.loads[1] = uptime.load_5m;
info.loads[2] = uptime.load_15m;
sysinfo_specific(&info);
if (user_put(info_addr, info))
return _EFAULT;
return 0;
}