-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkernel.h
More file actions
80 lines (63 loc) · 2.9 KB
/
kernel.h
File metadata and controls
80 lines (63 loc) · 2.9 KB
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
78
79
80
#pragma once
#include "syscalls.h"
// https://x64.syscall.sh/
// https://filippo.io/linux-syscall-table/
// ░░░ Constants ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
#define PROT_NONE 0x0
#define PROT_READ 0x1
#define PROT_WRITE 0x2
#define PROT_EXEC 0x4
#define MAP_ANONYMOUS 0x20
#define MAP_PRIVATE 0x02
#define CLOCK_REALTIME 0
#define CLOCK_MONOTONIC 1
#define CLOCK_BOOTTIME 7
#define CLOCK_MONOTONIC_RAW 4
#define CLOCK_PROCESS_CPUTIME_ID 2
#define TIMER_ABSTIME 1
#define GRND_RANDOM 0x02
#define GRND_NONBLOCK 0x01
// ░░░ Structs ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
typedef struct TIMESPEC
{
uint64_t tv_sec;
uint64_t tv_nsec;
} TIMESPEC;
// ░░░ Syscall Wrapper ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
// https://man7.org/linux/man-pages/man2/exit.2.html
__attribute__((noreturn))
static inline void exit(uint8_t const status)
{
syscall1(60, status);
__builtin_unreachable();
}
// https://manpages.debian.org/unstable/manpages-dev/getrandom.2.en.html
static inline int64_t getrandom(void *const buffer, uint64_t const size, uint32_t const flags)
{
return (int64_t)syscall3(318, (uint64_t)buffer, size, flags);
}
// https://man7.org/linux/man-pages/man2/mmap.2.html
static inline int32_t munmap(void *const addr, uint64_t const length)
{
return (int32_t)syscall2(11, (uint64_t)addr, length);
}
//__attribute__((malloc, malloc(munmap, 1)))
static inline void *mmap(void *const addr, uint64_t const length, uint32_t const prot, uint32_t const flags, uint32_t const fd, uint64_t const offset)
{
return (void *)syscall6(9, (uint64_t)addr, length, prot, flags, fd, offset);
}
// https://manpages.debian.org/unstable/manpages-dev/write.2.en.html
static inline int64_t write(uint32_t const fd, void const *const buf, uint64_t const count)
{
return (int64_t)syscall3(1, fd, (uint64_t)buf, count);
}
// https://manpages.debian.org/unstable/manpages-dev/clock_nanosleep.2.en.html
static inline int64_t clock_nanosleep(uint32_t const clockId, uint32_t flags, TIMESPEC const *const restrict t, TIMESPEC *const restrict remain)
{
return (int64_t)syscall4(230, clockId, flags, (uint64_t)t, (uint64_t)remain);
}
// https://manpages.debian.org/unstable/manpages-dev/read.2.en.html
static inline int64_t read(uint32_t const fd, void *const buf, uint64_t const count)
{
return (int64_t)syscall3(0, fd, (uint64_t)buf, count);
}