/
Kernel.h
260 lines (233 loc) · 6.71 KB
/
Kernel.h
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
#import <errno.h>
#import <linux/net.h>
#import <netinet/in.h>
#import <sys/syscall.h>
#import "Types.h"
#import "String.h"
#if defined(__x86_64__)
#define __NR_stat64 __NR_stat
#define __NR_lstat64 __NR_lstat
#define __NR_fstat64 __NR_fstat
#define __NR_sendfile64 __NR_sendfile
#define __NR_truncate64 __NR_truncate
#define __NR_ftruncate64 __NR_ftruncate
#define __NR__llseek __NR_lseek
#endif
set(ClockType) {
/* System clock which measures the real time. May move forwards and
* backwards.
*/
ClockType_Realtime = 0,
/* System clock which increases monotonically. Not affected by changes in
* the current system time.
*/
ClockType_Monotonic = 1,
/* Per-process clock which measures the processor time spent by the process.
*/
ClockType_Process_CpuTimeId = 2,
/* Per-thread clock which measures the processor time spent by the thread.
*/
ClockType_Thread_CpuTimeId = 3
};
set(FcntlMode) {
FcntlMode_GetDescriptorFlags = 1,
FcntlMode_SetDescriptorFlags = 2,
FcntlMode_GetStatus = 3,
FcntlMode_SetStatus = 4
};
set(FileDescriptorFlags) {
FileDescriptorFlags_CloseOnExec = 1
};
set(FileStatus) {
FileStatus_ReadOnly = 00,
FileStatus_WriteOnly = 01,
FileStatus_ReadWrite = 02,
FileStatus_Folder = 0200000,
FileStatus_NoFollow = 0400000,
FileStatus_Append = 02000,
FileStatus_Create = 0100,
FileStatus_NonBlock = 04000,
FileStatus_Truncate = 01000
};
set(FileMode) {
FileMode_Mask = 0170000,
FileMode_Folder = 0040000,
FileMode_CharDevice = 0020000,
FileMode_BlockDevice = 0060000,
FileMode_Regular = 0100000,
FileMode_FIFO = 0010000,
FileMode_Link = 0120000,
FileMode_Socket = 0140000
};
set(FileAttribute) {
FileAttribute_Sticky = 01000,
FileAttribute_ExecuteAsUser = 04000,
FileAttribute_ExecuteAsGroup = 02000
};
set(Permission) {
Permission_OwnerMask = 00700,
Permission_OwnerRead = 0400,
Permission_OwnerWrite = 0200,
Permission_OwnerExecute = 0100,
Permission_GroupMask = 00070,
Permission_GroupRead = 00040,
Permission_GroupWrite = 00020,
Permission_GroupExecute = 00010,
Permission_OthersMask = 00007,
Permission_OthersRead = 00004,
Permission_OthersWrite = 00002,
Permission_OthersExecute = 00001
};
record(Time_UnixEpoch) {
time_t sec;
long nsec;
};
#if defined(__x86_64__)
record(Stat) {
unsigned long dev;
unsigned long ino;
unsigned long nlink;
unsigned int mode;
unsigned int uid;
unsigned int gid;
unsigned int __pad0;
unsigned long rdev;
long size;
long blksize;
long blocks;
unsigned long atime;
unsigned long atime_nsec;
unsigned long mtime;
unsigned long mtime_nsec;
unsigned long ctime;
unsigned long ctime_nsec;
long unused[3];
};
record(Stat64) {
__dev_t device;
__ino64_t inode;
__nlink_t hardlinks;
__mode_t mode;
__uid_t uid;
__gid_t gid;
int __pad0;
__dev_t rdev;
__off_t size;
__blksize_t blksize;
__blkcnt64_t blocks;
Time_UnixEpoch atime;
Time_UnixEpoch mtime;
Time_UnixEpoch ctime;
long int unused[3];
};
#else
record(Stat) {
unsigned long device;
unsigned long inode;
unsigned short mode;
unsigned short nlink;
unsigned short uid;
unsigned short gid;
unsigned long rdev;
unsigned long size;
unsigned long blksize;
unsigned long blocks;
unsigned long atime;
unsigned long atime_nsec;
unsigned long mtime;
unsigned long mtime_nsec;
unsigned long ctime;
unsigned long ctime_nsec;
unsigned long unused[2];
};
record(Stat64) {
__dev_t device;
unsigned int __pad1;
__ino_t __inode;
__mode_t mode;
__nlink_t hardlinks;
__uid_t uid;
__gid_t gid;
__dev_t rdev;
unsigned int __pad2;
__off64_t size;
__blksize_t blksize;
__blkcnt64_t blocks;
Time_UnixEpoch atime;
Time_UnixEpoch mtime;
Time_UnixEpoch ctime;
__ino64_t inode;
};
#endif
set(ExitStatus) {
ExitStatus_Success = 0,
ExitStatus_Failure = 1
};
set(EpollCtl) {
EpollCtl_Add = 1,
EpollCtl_Delete = 2,
EpollCtl_Modify = 3
};
#if defined(__x86_64__)
#define __epollPacked __packed
#else
#define __epollPacked
#endif
record(EpollEvent) {
u32 events;
union {
void *addr;
u64 u64;
};
} __epollPacked;
/* Constants to be used with *at() system calls. */
enum {
At_Id_CurrentWorkingFolder = -100, /* Use the CWF for relative paths. */
At_Flag_NoFollow = 0x100 /* Don't follow symbolic links. */
};
#define self Kernel
sdef(int, open, RdString path, int flags, int mode);
sdef(bool, close, int id);
sdef(bool, rename, RdString src, RdString dest);
sdef(bool, access, RdString path, int mode);
sdef(void, exit, ExitStatus status);
sdef(ssize_t, read, int id, void *buf, size_t len);
sdef(ssize_t, write, int id, void *buf, size_t len);
sdef(ssize_t, getdents, int id, char *buf, size_t len);
sdef(bool, llseek, int id, u64 offset, u64 *pos, int whence);
sdef(bool, mkdir, RdString path, int flags);
sdef(bool, unlink, RdString path);
sdef(bool, rmdir, RdString path);
sdef(ssize_t, readlink, RdString path, char *buf, size_t size);
sdef(bool, setxattr, RdString path, RdString name, char *buf, size_t size, int flags);
sdef(bool, fsetxattr, int id, RdString name, char *buf, size_t size, int flags);
sdef(ssize_t, getxattr, RdString path, RdString name, char *buf, size_t size);
sdef(ssize_t, fgetxattr, int id, RdString name, char *buf, size_t size);
sdef(bool, symlink, RdString path1, RdString path2);
sdef(bool, utimensat, int dirId, RdString path, Time_UnixEpoch t, int flags);
sdef(bool, chdir, RdString path);
sdef(bool, fchdir, int id);
sdef(bool, lstat, RdString path, Stat *attr);
sdef(bool, stat, RdString path, Stat *attr);
sdef(size_t, getcwd, char *buf, size_t size);
sdef(bool, lstat64, RdString path, Stat64 *attr);
sdef(bool, stat64, RdString path, Stat64 *attr);
sdef(bool, fstat64, int id, Stat64 *attr);
sdef(bool, truncate64, RdString path, u64 len);
sdef(bool, ftruncate64, int id, u64 len);
sdef(bool, clock_gettime, ClockType type, Time_UnixEpoch *res);
sdef(ssize_t, epoll_create, size_t n);
sdef(bool, epoll_ctl, int epollId, EpollCtl op, int id, EpollEvent *event);
sdef(ssize_t, epoll_wait, int epollId, EpollEvent *events, int maxevents, int timeout);
sdef(int, fcntl, int id, int cmd, int arg);
sdef(int, socket, int namespace, int style, int protocol);
sdef(bool, setsockopt, int id, int level, int option, const void *value, int size);
sdef(bool, bind, int id, struct sockaddr_in addr);
sdef(bool, listen, int id, int backlog);
sdef(bool, shutdown, int id, int how);
sdef(bool, connect, int id, void *addr, size_t size);
sdef(int, accept4, int id, void *addr, int *len, int flags);
sdef(ssize_t, recv, int id, void *buf, size_t len, int flags);
sdef(ssize_t, send, int id, void *buf, size_t len, int flags);
sdef(ssize_t, sendfile64, int outId, int inId, u64 *offset, size_t len);
#undef self