|
11 | 11 | #define SYSCALL_FAULT_(name) ((uint64_t)-(name)) |
12 | 12 | #define FD_SETSIZE 1024 |
13 | 13 |
|
14 | | -#define syscall_(name) \ |
| 14 | +// 一个非常取巧的宏魔法, 可以简化 syscall 函数的定义 |
| 15 | +#define __EXPAND_PARAMS(...) __VA_ARGS__ |
| 16 | +#define __CONCAT_IMPL(a, b) a##b |
| 17 | +#define __CONCAT(a, b) __CONCAT_IMPL(a, b) |
| 18 | + |
| 19 | +#define __ARGS_COUNT_IMPL(_0, _1, _2, _3, _4, _5, _6, N, ...) N |
| 20 | + |
| 21 | +#define __ARGS_COUNT(...) __EXPAND_PARAMS(__ARGS_COUNT_IMPL(__VA_ARGS__, 6, 5, 4, 3, 2, 1, 0)) |
| 22 | + |
| 23 | +#define __SYSCALL_IMPL_0(NAME) \ |
| 24 | + uint64_t syscall_##NAME(uint64_t arg0, uint64_t arg1, uint64_t arg2, uint64_t arg3, \ |
| 25 | + uint64_t arg4, uint64_t arg5, struct syscall_regs *regs) |
| 26 | + |
| 27 | +#define __SYSCALL_IMPL_1(NAME, P1) \ |
| 28 | + uint64_t syscall_##NAME(P1, uint64_t arg1, uint64_t arg2, uint64_t arg3, uint64_t arg4, \ |
| 29 | + uint64_t arg5, struct syscall_regs *regs) |
| 30 | + |
| 31 | +#define __SYSCALL_IMPL_2(NAME, P1, P2) \ |
| 32 | + uint64_t syscall_##NAME(P1, P2, uint64_t arg2, uint64_t arg3, uint64_t arg4, uint64_t arg5, \ |
| 33 | + struct syscall_regs *regs) |
| 34 | + |
| 35 | +#define __SYSCALL_IMPL_3(NAME, P1, P2, P3) \ |
| 36 | + uint64_t syscall_##NAME(P1, P2, P3, uint64_t arg3, uint64_t arg4, uint64_t arg5, \ |
| 37 | + struct syscall_regs *regs) |
| 38 | + |
| 39 | +#define __SYSCALL_IMPL_4(NAME, P1, P2, P3, P4) \ |
| 40 | + uint64_t syscall_##NAME(P1, P2, P3, P4, uint64_t arg4, uint64_t arg5, struct syscall_regs *regs) |
| 41 | + |
| 42 | +#define __SYSCALL_IMPL_5(NAME, P1, P2, P3, P4, P5) \ |
| 43 | + uint64_t syscall_##NAME(P1, P2, P3, P4, P5, uint64_t arg5, struct syscall_regs *regs) |
| 44 | + |
| 45 | +#define __SYSCALL_IMPL_6(NAME, P1, P2, P3, P4, P5, P6) \ |
| 46 | + uint64_t syscall_##NAME(P1, P2, P3, P4, P5, P6, struct syscall_regs *regs) |
| 47 | + |
| 48 | +#define __SYSCALL_DISPATCH(N, NAME, ...) __CONCAT(__SYSCALL_IMPL_, N)(NAME, ##__VA_ARGS__) |
| 49 | + |
| 50 | +#define syscall_(NAME, ...) __SYSCALL_DISPATCH(__ARGS_COUNT(0, ##__VA_ARGS__), NAME, ##__VA_ARGS__) |
| 51 | + |
| 52 | +#define syscall_def_(name) \ |
15 | 53 | uint64_t syscall_##name( \ |
16 | 54 | uint64_t arg0 __attribute__((unused)), uint64_t arg1 __attribute__((unused)), \ |
17 | 55 | uint64_t arg2 __attribute__((unused)), uint64_t arg3 __attribute__((unused)), \ |
|
114 | 152 | #define SYSCALL_LINK 86 |
115 | 153 | #define SYSCALL_UNLINK 87 |
116 | 154 | #define SYSCALL_SYMLINK 88 |
| 155 | +#define SYSCALL_READLINK 89 |
| 156 | +#define SYSCALL_SYSINFO 99 |
117 | 157 | #define SYSCALL_GETUID 102 |
| 158 | +#define SYSCALL_GETGID 104 |
118 | 159 | #define SYSCALL_SETUID 105 |
119 | 160 | #define SYSCALL_SETGID 106 |
120 | 161 | #define SYSCALL_GETEUID 107 |
121 | 162 | #define SYSCALL_GETEGID 108 |
122 | 163 | #define SYSCALL_SETPGID 109 |
| 164 | +#define SYSCALL_GETPPID 110 |
123 | 165 | #define SYSCALL_GETGROUPS 115 |
124 | 166 | #define SYScall_GETPGID 121 |
125 | 167 | #define SYSCALL_SIGSUSPEND 130 |
|
128 | 170 | #define SYSCALL_ARCH_PRCTL 158 |
129 | 171 | #define SYSCALL_G_AFFINITY 160 |
130 | 172 | #define SYSCALL_MOUNT 165 |
| 173 | +#define SYSCALL_UMOUNT2 166 |
131 | 174 | #define SYSCALL_REBOOT 169 |
132 | 175 | #define SYSCALL_GET_TID 186 |
133 | 176 | #define SYSCALL_FUTEX 202 |
|
146 | 189 | #define SYSCALL_PIPE2 293 |
147 | 190 | #define SYSCALL_CP_F_RANGE 326 |
148 | 191 | #define SYSCALL_STATX 332 |
| 192 | +#define SYSCALL_FSOPEN 430 |
149 | 193 | #define SYSCALL_FACCESSAT2 439 |
150 | 194 |
|
151 | 195 | // CoolPotOS 平台特有系统调用号定义 |
@@ -287,6 +331,23 @@ struct statx { |
287 | 331 | /* 0x100 */ |
288 | 332 | }; |
289 | 333 |
|
| 334 | +struct sysinfo { |
| 335 | + int64_t uptime; /* Seconds since boot */ |
| 336 | + uint64_t loads[3]; /* 1, 5, and 15 minute load averages */ |
| 337 | + uint64_t totalram; /* Total usable main memory size */ |
| 338 | + uint64_t freeram; /* Available memory size */ |
| 339 | + uint64_t sharedram; /* Amount of shared memory */ |
| 340 | + uint64_t bufferram; /* Memory used by buffers */ |
| 341 | + uint64_t totalswap; /* Total swap space size */ |
| 342 | + uint64_t freeswap; /* swap space still available */ |
| 343 | + uint16_t procs; /* Number of current processes */ |
| 344 | + uint16_t pad; /* Explicit padding for m68k */ |
| 345 | + uint64_t totalhigh; /* Total high memory size */ |
| 346 | + uint64_t freehigh; /* Available high memory size */ |
| 347 | + uint32_t mem_unit; /* Memory unit size in bytes */ |
| 348 | + char _f[20 - 2 * sizeof(uint64_t) - sizeof(uint32_t)]; /* Padding: libc5 uses this.. */ |
| 349 | +}; |
| 350 | + |
290 | 351 | struct cpos_meminfo { |
291 | 352 | uint64_t used; // 已用内存 |
292 | 353 | uint64_t available; // 未使用内存 |
|
0 commit comments