Skip to main content

c/
arch.rs

1// Copyright (c) 2026 Meng Zhuo
2// SPDX-License-Identifier: BSD-3-Clause
3
4// Architecture layer for libc.
5//
6// Included from lib.rs.  Everything below is selected with target_arch:
7// the syscall ABI, the active Arch alias and the syscall-number tables.
8// Keep per-architecture changes in this file rather than scattering cfg
9// blocks through the libc functional areas.
10
11// ============================================================
12// Architecture selection
13// ============================================================
14
15/// Read the thread pointer.  errno and static TLS use this before any
16/// architecture-specific TLS helpers are available.
17#[cfg(target_arch = "x86_64")]
18unsafe fn arch_get_tp() -> usize {
19    const ARCH_PRCTL: i64 = 158;
20    const ARCH_GET_FS: i64 = 0x1003;
21    let mut tp: usize = 0;
22    let _ = <Arch as Syscalls>::syscall2(ARCH_PRCTL, ARCH_GET_FS, &mut tp as *mut usize as i64);
23    tp
24}
25
26#[cfg(target_arch = "aarch64")]
27unsafe fn arch_get_tp() -> usize {
28    let tp: usize;
29    core::arch::asm!("mrs {}, tpidr_el0", out(reg) tp, options(nostack, preserves_flags));
30    tp
31}
32
33#[cfg(target_arch = "riscv64")]
34unsafe fn arch_get_tp() -> usize {
35    let tp: usize;
36    core::arch::asm!("mv {}, tp", out(reg) tp, options(nostack, preserves_flags));
37    tp
38}
39
40/// Read the thread pointer without a syscall.  Used on hot paths (vDSO
41/// getrandom) where TLS is guaranteed to be set up already.
42#[cfg(target_arch = "x86_64")]
43unsafe fn arch_get_tp_fast() -> usize {
44    let tp: usize;
45    core::arch::asm!("mov {}, fs:[0]", out(reg) tp, options(nostack, preserves_flags));
46    tp
47}
48
49#[cfg(target_arch = "aarch64")]
50unsafe fn arch_get_tp_fast() -> usize {
51    let tp: usize;
52    core::arch::asm!("mrs {}, tpidr_el0", out(reg) tp, options(nostack, preserves_flags));
53    tp
54}
55
56#[cfg(target_arch = "riscv64")]
57unsafe fn arch_get_tp_fast() -> usize {
58    let tp: usize;
59    core::arch::asm!("mv {}, tp", out(reg) tp, options(nostack, preserves_flags));
60    tp
61}
62
63// ============================================================
64// Syscall ABI
65// ============================================================
66
67trait Syscalls {
68    unsafe fn syscall0(n: i64) -> i64;
69    unsafe fn syscall1(n: i64, a1: i64) -> i64;
70    unsafe fn syscall2(n: i64, a1: i64, a2: i64) -> i64;
71    unsafe fn syscall3(n: i64, a1: i64, a2: i64, a3: i64) -> i64;
72    unsafe fn syscall4(n: i64, a1: i64, a2: i64, a3: i64, a4: i64) -> i64;
73    unsafe fn syscall5(n: i64, a1: i64, a2: i64, a3: i64, a4: i64, a5: i64) -> i64;
74    unsafe fn syscall6(n: i64, a1: i64, a2: i64, a3: i64, a4: i64, a5: i64, a6: i64) -> i64;
75    unsafe fn syscall_noreturn1(n: i64, a1: i64) -> !;
76}
77
78struct X86_64;
79struct Aarch64;
80struct Riscv64;
81
82// x86_64
83#[cfg(target_arch = "x86_64")]
84impl Syscalls for X86_64 {
85    #[inline(always)]
86    unsafe fn syscall0(n: i64) -> i64 {
87        let result: i64;
88        core::arch::asm!(
89            "syscall",
90            inlateout("rax") n => result,
91            lateout("rcx") _,
92            lateout("r11") _,
93        );
94        result
95    }
96    #[inline(always)]
97    unsafe fn syscall1(n: i64, a1: i64) -> i64 {
98        let result: i64;
99        core::arch::asm!(
100            "syscall",
101            inlateout("rax") n => result,
102            in("rdi") a1,
103            lateout("rcx") _,
104            lateout("r11") _,
105        );
106        result
107    }
108    #[inline(always)]
109    unsafe fn syscall2(n: i64, a1: i64, a2: i64) -> i64 {
110        let result: i64;
111        core::arch::asm!(
112            "syscall",
113            inlateout("rax") n => result,
114            in("rdi") a1,
115            in("rsi") a2,
116            lateout("rcx") _,
117            lateout("r11") _,
118        );
119        result
120    }
121    #[inline(always)]
122    unsafe fn syscall3(n: i64, a1: i64, a2: i64, a3: i64) -> i64 {
123        let result: i64;
124        core::arch::asm!(
125            "syscall",
126            inlateout("rax") n => result,
127            in("rdi") a1,
128            in("rsi") a2,
129            in("rdx") a3,
130            lateout("rcx") _,
131            lateout("r11") _,
132        );
133        result
134    }
135    #[inline(always)]
136    unsafe fn syscall4(n: i64, a1: i64, a2: i64, a3: i64, a4: i64) -> i64 {
137        let result: i64;
138        core::arch::asm!(
139            "syscall",
140            inlateout("rax") n => result,
141            in("rdi") a1,
142            in("rsi") a2,
143            in("rdx") a3,
144            in("r10") a4,
145            lateout("rcx") _,
146            lateout("r11") _,
147        );
148        result
149    }
150    #[inline(always)]
151    unsafe fn syscall5(n: i64, a1: i64, a2: i64, a3: i64, a4: i64, a5: i64) -> i64 {
152        let result: i64;
153        core::arch::asm!(
154            "syscall",
155            inlateout("rax") n => result,
156            in("rdi") a1,
157            in("rsi") a2,
158            in("rdx") a3,
159            in("r10") a4,
160            in("r8") a5,
161            lateout("rcx") _,
162            lateout("r11") _,
163        );
164        result
165    }
166    #[inline(always)]
167    unsafe fn syscall6(n: i64, a1: i64, a2: i64, a3: i64, a4: i64, a5: i64, a6: i64) -> i64 {
168        let result: i64;
169        core::arch::asm!(
170            "syscall",
171            inlateout("rax") n => result,
172            in("rdi") a1,
173            in("rsi") a2,
174            in("rdx") a3,
175            in("r10") a4,
176            in("r8") a5,
177            in("r9") a6,
178            lateout("rcx") _,
179            lateout("r11") _,
180        );
181        result
182    }
183    #[inline(always)]
184    unsafe fn syscall_noreturn1(n: i64, a1: i64) -> ! {
185        core::arch::asm!(
186            "syscall",
187            in("rax") n,
188            in("rdi") a1,
189            options(noreturn)
190        );
191    }
192}
193
194// aarch64
195#[cfg(target_arch = "aarch64")]
196impl Syscalls for Aarch64 {
197    #[inline(always)]
198    unsafe fn syscall0(n: i64) -> i64 {
199        let result: i64;
200        core::arch::asm!(
201            "svc #0",
202            inlateout("x8") n => _,
203            lateout("x0") result,
204            options(nostack),
205        );
206        result
207    }
208    #[inline(always)]
209    unsafe fn syscall1(n: i64, a1: i64) -> i64 {
210        let result: i64;
211        core::arch::asm!(
212            "svc #0",
213            inlateout("x8") n => _,
214            inlateout("x0") a1 => result,
215            options(nostack),
216        );
217        result
218    }
219    #[inline(always)]
220    unsafe fn syscall2(n: i64, a1: i64, a2: i64) -> i64 {
221        let result: i64;
222        core::arch::asm!(
223            "svc #0",
224            inlateout("x8") n => _,
225            inlateout("x0") a1 => result,
226            inlateout("x1") a2 => _,
227            options(nostack),
228        );
229        result
230    }
231    #[inline(always)]
232    unsafe fn syscall3(n: i64, a1: i64, a2: i64, a3: i64) -> i64 {
233        let result: i64;
234        core::arch::asm!(
235            "svc #0",
236            inlateout("x8") n => _,
237            inlateout("x0") a1 => result,
238            inlateout("x1") a2 => _,
239            inlateout("x2") a3 => _,
240            options(nostack),
241        );
242        result
243    }
244    #[inline(always)]
245    unsafe fn syscall4(n: i64, a1: i64, a2: i64, a3: i64, a4: i64) -> i64 {
246        let result: i64;
247        core::arch::asm!(
248            "svc #0",
249            inlateout("x8") n => _,
250            inlateout("x0") a1 => result,
251            inlateout("x1") a2 => _,
252            inlateout("x2") a3 => _,
253            inlateout("x3") a4 => _,
254            options(nostack),
255        );
256        result
257    }
258    #[inline(always)]
259    unsafe fn syscall5(n: i64, a1: i64, a2: i64, a3: i64, a4: i64, a5: i64) -> i64 {
260        let result: i64;
261        core::arch::asm!(
262            "svc #0",
263            inlateout("x8") n => _,
264            inlateout("x0") a1 => result,
265            inlateout("x1") a2 => _,
266            inlateout("x2") a3 => _,
267            inlateout("x3") a4 => _,
268            inlateout("x4") a5 => _,
269            options(nostack),
270        );
271        result
272    }
273    #[inline(always)]
274    unsafe fn syscall6(n: i64, a1: i64, a2: i64, a3: i64, a4: i64, a5: i64, a6: i64) -> i64 {
275        let result: i64;
276        core::arch::asm!(
277            "svc #0",
278            inlateout("x8") n => _,
279            inlateout("x0") a1 => result,
280            inlateout("x1") a2 => _,
281            inlateout("x2") a3 => _,
282            inlateout("x3") a4 => _,
283            inlateout("x4") a5 => _,
284            inlateout("x5") a6 => _,
285            options(nostack),
286        );
287        result
288    }
289    #[inline(always)]
290    unsafe fn syscall_noreturn1(n: i64, a1: i64) -> ! {
291        core::arch::asm!(
292            "svc #0",
293            in("x8") n,
294            in("x0") a1,
295            options(noreturn, nostack),
296        );
297    }
298}
299
300// riscv64
301#[cfg(target_arch = "riscv64")]
302impl Syscalls for Riscv64 {
303    #[inline(always)]
304    unsafe fn syscall0(n: i64) -> i64 {
305        let result: i64;
306        core::arch::asm!(
307            "ecall",
308            inlateout("a7") n => _,
309            lateout("a0") result,
310            options(nostack),
311        );
312        result
313    }
314    #[inline(always)]
315    unsafe fn syscall1(n: i64, a1: i64) -> i64 {
316        let result: i64;
317        core::arch::asm!(
318            "ecall",
319            inlateout("a7") n => _,
320            inlateout("a0") a1 => result,
321            options(nostack),
322        );
323        result
324    }
325    #[inline(always)]
326    unsafe fn syscall2(n: i64, a1: i64, a2: i64) -> i64 {
327        let result: i64;
328        core::arch::asm!(
329            "ecall",
330            inlateout("a7") n => _,
331            inlateout("a0") a1 => result,
332            inlateout("a1") a2 => _,
333            options(nostack),
334        );
335        result
336    }
337    #[inline(always)]
338    unsafe fn syscall3(n: i64, a1: i64, a2: i64, a3: i64) -> i64 {
339        let result: i64;
340        core::arch::asm!(
341            "ecall",
342            inlateout("a7") n => _,
343            inlateout("a0") a1 => result,
344            inlateout("a1") a2 => _,
345            inlateout("a2") a3 => _,
346            options(nostack),
347        );
348        result
349    }
350    #[inline(always)]
351    unsafe fn syscall4(n: i64, a1: i64, a2: i64, a3: i64, a4: i64) -> i64 {
352        let result: i64;
353        core::arch::asm!(
354            "ecall",
355            inlateout("a7") n => _,
356            inlateout("a0") a1 => result,
357            inlateout("a1") a2 => _,
358            inlateout("a2") a3 => _,
359            inlateout("a3") a4 => _,
360            options(nostack),
361        );
362        result
363    }
364    #[inline(always)]
365    unsafe fn syscall5(n: i64, a1: i64, a2: i64, a3: i64, a4: i64, a5: i64) -> i64 {
366        let result: i64;
367        core::arch::asm!(
368            "ecall",
369            inlateout("a7") n => _,
370            inlateout("a0") a1 => result,
371            inlateout("a1") a2 => _,
372            inlateout("a2") a3 => _,
373            inlateout("a3") a4 => _,
374            inlateout("a4") a5 => _,
375            options(nostack),
376        );
377        result
378    }
379    #[inline(always)]
380    unsafe fn syscall6(n: i64, a1: i64, a2: i64, a3: i64, a4: i64, a5: i64, a6: i64) -> i64 {
381        let result: i64;
382        core::arch::asm!(
383            "ecall",
384            inlateout("a7") n => _,
385            inlateout("a0") a1 => result,
386            inlateout("a1") a2 => _,
387            inlateout("a2") a3 => _,
388            inlateout("a3") a4 => _,
389            inlateout("a4") a5 => _,
390            inlateout("a5") a6 => _,
391            options(nostack),
392        );
393        result
394    }
395    #[inline(always)]
396    unsafe fn syscall_noreturn1(n: i64, a1: i64) -> ! {
397        core::arch::asm!(
398            "ecall",
399            in("a7") n,
400            in("a0") a1,
401            options(noreturn, nostack),
402        );
403    }
404}
405
406// ============================================================
407// Selected architecture
408// ============================================================
409
410// x86_64
411#[cfg(target_arch = "x86_64")]
412type Arch = X86_64;
413// aarch64
414#[cfg(target_arch = "aarch64")]
415type Arch = Aarch64;
416// riscv64
417#[cfg(target_arch = "riscv64")]
418type Arch = Riscv64;
419
420// ============================================================
421// Syscall numbers
422// ============================================================
423
424// x86_64
425#[cfg(target_arch = "x86_64")]
426mod sysnr {
427    pub const SYS_READ: i64 = 0;
428    pub const SYS_WRITE: i64 = 1;
429    pub const SYS_OPEN: i64 = 2;
430    pub const SYS_CLOSE: i64 = 3;
431    pub const SYS_STAT: i64 = 4;
432    pub const SYS_FSTAT: i64 = 5;
433    pub const SYS_LSEEK: i64 = 8;
434    pub const SYS_MMAP: i64 = 9;
435    pub const SYS_MUNMAP: i64 = 11;
436    pub const SYS_MPROTECT: i64 = 10;
437    pub const SYS_RT_SIGACTION: i64 = 13;
438    pub const SYS_RT_SIGPROCMASK: i64 = 14;
439    pub const SYS_IOCTL: i64 = 16;
440    pub const SYS_ACCESS: i64 = 21;
441    pub const SYS_SHMGET: i64 = 29;
442    pub const SYS_SHMAT: i64 = 30;
443    pub const SYS_SHMCTL: i64 = 31;
444    pub const SYS_DUP: i64 = 32;
445    pub const SYS_NANOSLEEP: i64 = 35;
446    pub const SYS_SETITIMER: i64 = 38;
447    pub const SYS_ALARM: i64 = 37;
448    pub const SYS_SOCKET: i64 = 41;
449    pub const SYS_CONNECT: i64 = 42;
450    pub const SYS_ACCEPT: i64 = 43;
451    pub const SYS_ACCEPT4: i64 = 288;
452    pub const SYS_SENDTO: i64 = 44;
453    pub const SYS_RECVFROM: i64 = 45;
454    pub const SYS_SENDMSG: i64 = 46;
455    pub const SYS_RECVMSG: i64 = 47;
456    pub const SYS_SHUTDOWN: i64 = 48;
457    pub const SYS_BIND: i64 = 49;
458    pub const SYS_LISTEN: i64 = 50;
459    pub const SYS_GETSOCKNAME: i64 = 51;
460    pub const SYS_SOCKETPAIR: i64 = 53;
461    pub const SYS_SETSOCKOPT: i64 = 54;
462    pub const SYS_EXECVE: i64 = 59;
463    pub const SYS_WAIT4: i64 = 61;
464    pub const SYS_KILL: i64 = 62;
465    pub const SYS_UNAME: i64 = 63;
466    pub const SYS_SEMGET: i64 = 64;
467    pub const SYS_SEMOP: i64 = 65;
468    pub const SYS_SEMCTL: i64 = 66;
469    pub const SYS_SHMDT: i64 = 67;
470    pub const SYS_MSGGET: i64 = 68;
471    pub const SYS_MSGSND: i64 = 69;
472    pub const SYS_MSGRCV: i64 = 70;
473    pub const SYS_MSGCTL: i64 = 71;
474    pub const SYS_FCNTL: i64 = 72;
475    pub const SYS_FSYNC: i64 = 74;
476    pub const SYS_TRUNCATE: i64 = 76;
477    pub const SYS_FTRUNCATE: i64 = 77;
478    pub const SYS_GETCWD: i64 = 79;
479    pub const SYS_CHDIR: i64 = 80;
480    pub const SYS_SYMLINK: i64 = 88;
481    pub const SYS_FCHMOD: i64 = 91;
482    pub const SYS_UMASK: i64 = 95;
483    pub const SYS_GETRLIMIT: i64 = 97;
484    pub const SYS_SETUID: i64 = 105;
485    pub const SYS_SETGID: i64 = 106;
486    pub const SYS_SETPGID: i64 = 109;
487    pub const SYS_GETGROUPS: i64 = 115;
488    pub const SYS_GETPGID: i64 = 121;
489    pub const SYS_GETSID: i64 = 124;
490    pub const SYS_RT_SIGPENDING: i64 = 127;
491    pub const SYS_RT_SIGTIMEDWAIT: i64 = 128;
492    pub const SYS_RT_SIGSUSPEND: i64 = 130;
493    pub const SYS_SIGALTSTACK: i64 = 131;
494    pub const SYS_SETRLIMIT: i64 = 160;
495    pub const SYS_SETHOSTNAME: i64 = 170;
496    pub const SYS_FUTEX: i64 = 202;
497    pub const SYS_CLOCK_GETTIME: i64 = 228;
498    pub const SYS_CLOCK_GETRES: i64 = 229;
499    pub const SYS_CLOCK_NANOSLEEP: i64 = 230;
500    pub const SYS_EXIT_GROUP: i64 = 231;
501    pub const SYS_TGKILL: i64 = 234;
502    pub const SYS_MKDIRAT: i64 = 258;
503    pub const SYS_NEWFSTATAT: i64 = 262;
504    pub const SYS_UNLINKAT: i64 = 263;
505    pub const SYS_LINKAT: i64 = 265;
506    pub const SYS_SYMLINKAT: i64 = 266;
507    pub const SYS_READLINKAT: i64 = 267;
508    pub const SYS_FCHMODAT: i64 = 268;
509    pub const SYS_SET_ROBUST_LIST: i64 = 273;
510    pub const SYS_UTIMENSAT: i64 = 280;
511    pub const SYS_OPENAT: i64 = 257;
512    pub const SYS_FACCESSAT: i64 = 269;
513    pub const SYS_DUP3: i64 = 292;
514    pub const SYS_PIPE2: i64 = 293;
515    pub const SYS_SYNCFS: i64 = 306;
516    pub const SYS_RENAMEAT2: i64 = 316;
517    pub const SYS_STATFS: i64 = 137;
518    pub const SYS_FSTATFS: i64 = 138;
519    pub const SYS_FDATASYNC: i64 = 75;
520    pub const SYS_PAUSE: i64 = 34;
521    pub const SYS_POLL: i64 = 7;
522    pub const SYS_PPOLL: i64 = 271;
523    pub const SYS_PSELECT6: i64 = 270;
524    pub const SYS_GETPID: i64 = 39;
525    pub const SYS_FORK: i64 = 57;
526    pub const SYS_EXIT: i64 = 60;
527    pub const SYS_GETPPID: i64 = 110;
528    pub const SYS_SETSID: i64 = 112;
529    pub const SYS_SYNC: i64 = 162;
530    pub const SYS_GETUID: i64 = 102;
531    pub const SYS_GETGID: i64 = 104;
532    pub const SYS_GETEUID: i64 = 107;
533    pub const SYS_GETEGID: i64 = 108;
534    pub const SYS_GETTID: i64 = 186;
535    pub const SYS_CLOCK_SETTIME: i64 = 227;
536    pub const SYS_CLONE: i64 = 56;
537    pub const SYS_PREAD64: i64 = 17;
538    pub const SYS_MREMAP: i64 = 25;
539    pub const SYS_SYSINFO: i64 = 99;
540    pub const SYS_MEMBARRIER: i64 = 324;
541    pub const SYS_VHANGUP: i64 = 153;
542    pub const SYS_VMSPLICE: i64 = 278;
543    pub const SYS_GETDENTS64: i64 = 217;
544    pub const SYS_EPOLL_CREATE: i64 = 213;
545    pub const SYS_EPOLL_CREATE1: i64 = 291;
546    pub const SYS_EPOLL_CTL: i64 = 233;
547    pub const SYS_EPOLL_WAIT: i64 = 232;
548    pub const SYS_EPOLL_PWAIT: i64 = 281;
549    pub const SYS_EVENTFD2: i64 = 290;
550    pub const SYS_SIGNALFD4: i64 = 289;
551    pub const SYS_TIMERFD_CREATE: i64 = 283;
552    pub const SYS_TIMERFD_SETTIME: i64 = 286;
553    pub const SYS_TIMERFD_GETTIME: i64 = 287;
554    pub const SYS_PRCTL: i64 = 157;
555    pub const SYS_FALLOCATE: i64 = 285;
556    pub const SYS_FLOCK: i64 = 73;
557    pub const SYS_SETGROUPS: i64 = 116;
558    pub const SYS_SETRESUID: i64 = 117;
559    pub const SYS_SETRESGID: i64 = 119;
560    pub const SYS_GETRESUID: i64 = 118;
561    pub const SYS_GETRESGID: i64 = 120;
562    pub const SYS_MKNOD: i64 = 133;
563    pub const SYS_FCHDIR: i64 = 81;
564    pub const SYS_FCHOWN: i64 = 93;
565    pub const SYS_ACCT: i64 = 163;
566    pub const SYS_ADJTIMEX: i64 = 159;
567    pub const SYS_CAPGET: i64 = 125;
568    pub const SYS_CAPSET: i64 = 126;
569    pub const SYS_CHROOT: i64 = 161;
570    pub const SYS_COPY_FILE_RANGE: i64 = 326;
571    pub const SYS_DELETE_MODULE: i64 = 176;
572    pub const SYS_INIT_MODULE: i64 = 175;
573    pub const SYS_FCHOWNAT: i64 = 260;
574    pub const SYS_MKNODAT: i64 = 259;
575    pub const SYS_SETNS: i64 = 308;
576    pub const SYS_UNSHARE: i64 = 272;
577    pub const SYS_REBOOT: i64 = 169;
578    pub const SYS_NICE: i64 = 34;
579    pub const SYS_SETPRIORITY: i64 = 141;
580    pub const SYS_GETPRIORITY: i64 = 140;
581    pub const SYS_IOPERM: i64 = 173;
582    pub const SYS_IOPL: i64 = 172;
583    pub const SYS_SWAPON: i64 = 167;
584    pub const SYS_SWAPOFF: i64 = 168;
585    pub const SYS_MOUNT: i64 = 165;
586    pub const SYS_UMOUNT2: i64 = 166;
587    pub const SYS_PIVOT_ROOT: i64 = 155;
588    pub const SYS_SETTIMEOFDAY: i64 = 164;
589    pub const SYS_GETTIMEOFDAY: i64 = 96;
590}
591// aarch64
592#[cfg(target_arch = "aarch64")]
593mod sysnr {
594    pub const SYS_READ: i64 = 63;
595    pub const SYS_WRITE: i64 = 64;
596    // pub const SYS_OPEN: i64 = ???; // missing in aarch64 table
597    pub const SYS_CLOSE: i64 = 57;
598    // pub const SYS_STAT: i64 = ???; // missing in aarch64 table
599    pub const SYS_FSTAT: i64 = 80;
600    pub const SYS_LSEEK: i64 = 62;
601    pub const SYS_MMAP: i64 = 222;
602    pub const SYS_MUNMAP: i64 = 215;
603    pub const SYS_RT_SIGACTION: i64 = 134;
604    pub const SYS_RT_SIGPROCMASK: i64 = 135;
605    pub const SYS_IOCTL: i64 = 29;
606    // pub const SYS_ACCESS: i64 = ???; // missing in aarch64 table
607    pub const SYS_SHMGET: i64 = 194;
608    pub const SYS_SHMAT: i64 = 196;
609    pub const SYS_SHMCTL: i64 = 195;
610    pub const SYS_DUP: i64 = 23;
611    pub const SYS_NANOSLEEP: i64 = 101;
612    pub const SYS_SETITIMER: i64 = 103;
613    // pub const SYS_ALARM: i64 = ???; // missing in aarch64 table
614    pub const SYS_SOCKET: i64 = 198;
615    pub const SYS_CONNECT: i64 = 203;
616    pub const SYS_ACCEPT: i64 = 202;
617    pub const SYS_SENDTO: i64 = 206;
618    pub const SYS_RECVFROM: i64 = 207;
619    pub const SYS_SHUTDOWN: i64 = 210;
620    pub const SYS_BIND: i64 = 200;
621    pub const SYS_LISTEN: i64 = 201;
622    pub const SYS_GETSOCKNAME: i64 = 204;
623    pub const SYS_SOCKETPAIR: i64 = 199;
624    pub const SYS_SETSOCKOPT: i64 = 208;
625    pub const SYS_EXECVE: i64 = 221;
626    pub const SYS_WAIT4: i64 = 260;
627    pub const SYS_KILL: i64 = 129;
628    pub const SYS_UNAME: i64 = 160;
629    pub const SYS_SEMGET: i64 = 190;
630    pub const SYS_SEMOP: i64 = 193;
631    pub const SYS_SEMCTL: i64 = 191;
632    pub const SYS_SHMDT: i64 = 197;
633    pub const SYS_MSGGET: i64 = 186;
634    pub const SYS_MSGSND: i64 = 189;
635    pub const SYS_MSGRCV: i64 = 188;
636    pub const SYS_MSGCTL: i64 = 187;
637    pub const SYS_FCNTL: i64 = 25;
638    pub const SYS_FSYNC: i64 = 82;
639    pub const SYS_TRUNCATE: i64 = 45;
640    pub const SYS_FTRUNCATE: i64 = 46;
641    pub const SYS_GETCWD: i64 = 17;
642    pub const SYS_CHDIR: i64 = 49;
643    // pub const SYS_SYMLINK: i64 = ???; // missing in aarch64 table
644    pub const SYS_FCHMOD: i64 = 52;
645    pub const SYS_UMASK: i64 = 166;
646    pub const SYS_GETRLIMIT: i64 = 163;
647    pub const SYS_SETUID: i64 = 146;
648    pub const SYS_SETGID: i64 = 144;
649    pub const SYS_SETPGID: i64 = 154;
650    pub const SYS_GETGROUPS: i64 = 158;
651    pub const SYS_GETPGID: i64 = 155;
652    pub const SYS_GETSID: i64 = 156;
653    pub const SYS_RT_SIGPENDING: i64 = 136;
654    pub const SYS_RT_SIGTIMEDWAIT: i64 = 137;
655    pub const SYS_RT_SIGSUSPEND: i64 = 133;
656    pub const SYS_SIGALTSTACK: i64 = 132;
657    pub const SYS_SETRLIMIT: i64 = 164;
658    pub const SYS_SETHOSTNAME: i64 = 161;
659    pub const SYS_FUTEX: i64 = 98;
660    pub const SYS_CLOCK_GETTIME: i64 = 113;
661    pub const SYS_CLOCK_GETRES: i64 = 114;
662    pub const SYS_CLOCK_NANOSLEEP: i64 = 115;
663    pub const SYS_EXIT_GROUP: i64 = 94;
664    pub const SYS_TGKILL: i64 = 131;
665    pub const SYS_MKDIRAT: i64 = 34;
666    pub const SYS_NEWFSTATAT: i64 = 79;
667    pub const SYS_UNLINKAT: i64 = 35;
668    pub const SYS_LINKAT: i64 = 37;
669    pub const SYS_SYMLINKAT: i64 = 36;
670    pub const SYS_READLINKAT: i64 = 78;
671    pub const SYS_FCHMODAT: i64 = 53;
672    pub const SYS_SET_ROBUST_LIST: i64 = 99;
673    pub const SYS_UTIMENSAT: i64 = 88;
674    pub const SYS_OPENAT: i64 = 56;
675    pub const SYS_FACCESSAT: i64 = 48;
676    pub const SYS_DUP3: i64 = 24;
677    pub const SYS_PIPE2: i64 = 59;
678    pub const SYS_SYNCFS: i64 = 267;
679    pub const SYS_RENAMEAT2: i64 = 276;
680    pub const SYS_STATFS: i64 = 43;
681    pub const SYS_FSTATFS: i64 = 44;
682    pub const SYS_FDATASYNC: i64 = 83;
683    pub const SYS_GETPID: i64 = 172;
684    pub const SYS_EXIT: i64 = 93;
685    pub const SYS_GETPPID: i64 = 173;
686    pub const SYS_SETSID: i64 = 157;
687    pub const SYS_SYNC: i64 = 81;
688    pub const SYS_GETUID: i64 = 174;
689    pub const SYS_GETGID: i64 = 176;
690    pub const SYS_GETEUID: i64 = 175;
691    pub const SYS_GETEGID: i64 = 177;
692    pub const SYS_GETTID: i64 = 178;
693    pub const SYS_CLOCK_SETTIME: i64 = 112;
694    pub const SYS_CLONE: i64 = 220;
695    pub const SYS_PPOLL: i64 = 73;
696    pub const SYS_PREAD64: i64 = 67;
697    pub const SYS_MREMAP: i64 = 216;
698    pub const SYS_SYSINFO: i64 = 179;
699    pub const SYS_MEMBARRIER: i64 = 283;
700    pub const SYS_VHANGUP: i64 = 58;
701    pub const SYS_VMSPLICE: i64 = 75;
702    pub const SYS_GETTIMEOFDAY: i64 = 169;
703    pub const SYS_SETTIMEOFDAY: i64 = 170;
704    pub const SYS_ADJTIMEX: i64 = 171;
705    pub const SYS_EPOLL_CREATE1: i64 = 20;
706    pub const SYS_EPOLL_CTL: i64 = 21;
707    pub const SYS_EPOLL_WAIT: i64 = 22;
708    pub const SYS_EPOLL_PWAIT: i64 = 22;
709    pub const SYS_EVENTFD2: i64 = 19;
710    pub const SYS_SIGNALFD4: i64 = 74;
711    pub const SYS_TIMERFD_CREATE: i64 = 85;
712    pub const SYS_TIMERFD_SETTIME: i64 = 86;
713    pub const SYS_TIMERFD_GETTIME: i64 = 87;
714    pub const SYS_ACCEPT4: i64 = 242;
715    pub const SYS_ACCT: i64 = 89;
716    pub const SYS_CAPGET: i64 = 90;
717    pub const SYS_CAPSET: i64 = 91;
718    pub const SYS_CHROOT: i64 = 51;
719    pub const SYS_COPY_FILE_RANGE: i64 = 285;
720    pub const SYS_DELETE_MODULE: i64 = 106;
721    pub const SYS_FALLOCATE: i64 = 47;
722    pub const SYS_FCHDIR: i64 = 50;
723    pub const SYS_FCHOWN: i64 = 55;
724    pub const SYS_FCHOWNAT: i64 = 54;
725    pub const SYS_FLOCK: i64 = 32;
726    pub const SYS_GETDENTS64: i64 = 61;
727    pub const SYS_GETPRIORITY: i64 = 141;
728    pub const SYS_GETRESGID: i64 = 150;
729    pub const SYS_GETRESUID: i64 = 148;
730    pub const SYS_INIT_MODULE: i64 = 105;
731    pub const SYS_MKNODAT: i64 = 33;
732    pub const SYS_MOUNT: i64 = 40;
733    pub const SYS_MPROTECT: i64 = 226;
734    pub const SYS_PIVOT_ROOT: i64 = 41;
735    pub const SYS_PRCTL: i64 = 167;
736    pub const SYS_PSELECT6: i64 = 72;
737    pub const SYS_REBOOT: i64 = 142;
738    pub const SYS_RECVMSG: i64 = 212;
739    pub const SYS_SENDMSG: i64 = 211;
740    pub const SYS_SETGROUPS: i64 = 159;
741    pub const SYS_SETNS: i64 = 268;
742    pub const SYS_SETPRIORITY: i64 = 140;
743    pub const SYS_SETRESGID: i64 = 149;
744    pub const SYS_SETRESUID: i64 = 147;
745    pub const SYS_SWAPOFF: i64 = 225;
746    pub const SYS_SWAPON: i64 = 224;
747    pub const SYS_UMOUNT2: i64 = 39;
748    pub const SYS_UNSHARE: i64 = 97;
749}
750// riscv64 uses the same new-style syscall table as aarch64
751// riscv64 uses the same new-style syscall table as aarch64
752#[cfg(target_arch = "riscv64")]
753mod sysnr {
754    pub const SYS_READ: i64 = 63;
755    pub const SYS_WRITE: i64 = 64;
756    pub const SYS_CLOSE: i64 = 57;
757    pub const SYS_FSTAT: i64 = 80;
758    pub const SYS_LSEEK: i64 = 62;
759    pub const SYS_MMAP: i64 = 222;
760    pub const SYS_MUNMAP: i64 = 215;
761    pub const SYS_RT_SIGACTION: i64 = 134;
762    pub const SYS_RT_SIGPROCMASK: i64 = 135;
763    pub const SYS_IOCTL: i64 = 29;
764    pub const SYS_SHMGET: i64 = 194;
765    pub const SYS_SHMAT: i64 = 196;
766    pub const SYS_SHMCTL: i64 = 195;
767    pub const SYS_DUP: i64 = 23;
768    pub const SYS_NANOSLEEP: i64 = 101;
769    pub const SYS_SETITIMER: i64 = 103;
770    pub const SYS_SOCKET: i64 = 198;
771    pub const SYS_CONNECT: i64 = 203;
772    pub const SYS_ACCEPT: i64 = 202;
773    pub const SYS_SENDTO: i64 = 206;
774    pub const SYS_RECVFROM: i64 = 207;
775    pub const SYS_SHUTDOWN: i64 = 210;
776    pub const SYS_BIND: i64 = 200;
777    pub const SYS_LISTEN: i64 = 201;
778    pub const SYS_GETSOCKNAME: i64 = 204;
779    pub const SYS_SOCKETPAIR: i64 = 199;
780    pub const SYS_SETSOCKOPT: i64 = 208;
781    pub const SYS_EXECVE: i64 = 221;
782    pub const SYS_WAIT4: i64 = 260;
783    pub const SYS_KILL: i64 = 129;
784    pub const SYS_UNAME: i64 = 160;
785    pub const SYS_SEMGET: i64 = 190;
786    pub const SYS_SEMOP: i64 = 193;
787    pub const SYS_SEMCTL: i64 = 191;
788    pub const SYS_SHMDT: i64 = 197;
789    pub const SYS_MSGGET: i64 = 186;
790    pub const SYS_MSGSND: i64 = 189;
791    pub const SYS_MSGRCV: i64 = 188;
792    pub const SYS_MSGCTL: i64 = 187;
793    pub const SYS_FCNTL: i64 = 25;
794    pub const SYS_FSYNC: i64 = 82;
795    pub const SYS_TRUNCATE: i64 = 45;
796    pub const SYS_FTRUNCATE: i64 = 46;
797    pub const SYS_GETCWD: i64 = 17;
798    pub const SYS_CHDIR: i64 = 49;
799    pub const SYS_FCHMOD: i64 = 52;
800    pub const SYS_UMASK: i64 = 166;
801    pub const SYS_GETRLIMIT: i64 = 163;
802    pub const SYS_SETUID: i64 = 146;
803    pub const SYS_SETGID: i64 = 144;
804    pub const SYS_SETPGID: i64 = 154;
805    pub const SYS_GETGROUPS: i64 = 158;
806    pub const SYS_GETPGID: i64 = 155;
807    pub const SYS_GETSID: i64 = 156;
808    pub const SYS_RT_SIGPENDING: i64 = 136;
809    pub const SYS_RT_SIGTIMEDWAIT: i64 = 137;
810    pub const SYS_RT_SIGSUSPEND: i64 = 133;
811    pub const SYS_SIGALTSTACK: i64 = 132;
812    pub const SYS_SETRLIMIT: i64 = 164;
813    pub const SYS_SETHOSTNAME: i64 = 161;
814    pub const SYS_FUTEX: i64 = 98;
815    pub const SYS_CLOCK_GETTIME: i64 = 113;
816    pub const SYS_CLOCK_GETRES: i64 = 114;
817    pub const SYS_CLOCK_NANOSLEEP: i64 = 115;
818    pub const SYS_EXIT_GROUP: i64 = 94;
819    pub const SYS_TGKILL: i64 = 131;
820    pub const SYS_MKDIRAT: i64 = 34;
821    pub const SYS_NEWFSTATAT: i64 = 79;
822    pub const SYS_UNLINKAT: i64 = 35;
823    pub const SYS_LINKAT: i64 = 37;
824    pub const SYS_SYMLINKAT: i64 = 36;
825    pub const SYS_READLINKAT: i64 = 78;
826    pub const SYS_FCHMODAT: i64 = 53;
827    pub const SYS_SET_ROBUST_LIST: i64 = 99;
828    pub const SYS_UTIMENSAT: i64 = 88;
829    pub const SYS_OPENAT: i64 = 56;
830    pub const SYS_FACCESSAT: i64 = 48;
831    pub const SYS_DUP3: i64 = 24;
832    pub const SYS_PIPE2: i64 = 59;
833    pub const SYS_SYNCFS: i64 = 267;
834    pub const SYS_RENAMEAT2: i64 = 276;
835    pub const SYS_STATFS: i64 = 43;
836    pub const SYS_FSTATFS: i64 = 44;
837    pub const SYS_FDATASYNC: i64 = 83;
838    pub const SYS_GETPID: i64 = 172;
839    pub const SYS_EXIT: i64 = 93;
840    pub const SYS_GETPPID: i64 = 173;
841    pub const SYS_SETSID: i64 = 157;
842    pub const SYS_SYNC: i64 = 81;
843    pub const SYS_GETUID: i64 = 174;
844    pub const SYS_GETGID: i64 = 176;
845    pub const SYS_GETEUID: i64 = 175;
846    pub const SYS_GETEGID: i64 = 177;
847    pub const SYS_GETTID: i64 = 178;
848    pub const SYS_CLOCK_SETTIME: i64 = 112;
849    pub const SYS_CLONE: i64 = 220;
850    pub const SYS_PPOLL: i64 = 73;
851    pub const SYS_PREAD64: i64 = 67;
852    pub const SYS_MREMAP: i64 = 216;
853    pub const SYS_SYSINFO: i64 = 179;
854    pub const SYS_MEMBARRIER: i64 = 283;
855    pub const SYS_VHANGUP: i64 = 58;
856    pub const SYS_VMSPLICE: i64 = 75;
857    pub const SYS_GETTIMEOFDAY: i64 = 169;
858    pub const SYS_SETTIMEOFDAY: i64 = 170;
859    pub const SYS_ADJTIMEX: i64 = 171;
860    pub const SYS_EPOLL_CREATE1: i64 = 20;
861    pub const SYS_EPOLL_CTL: i64 = 21;
862    pub const SYS_EPOLL_WAIT: i64 = 22;
863    pub const SYS_EPOLL_PWAIT: i64 = 22;
864    pub const SYS_EVENTFD2: i64 = 19;
865    pub const SYS_SIGNALFD4: i64 = 74;
866    pub const SYS_TIMERFD_CREATE: i64 = 85;
867    pub const SYS_TIMERFD_SETTIME: i64 = 86;
868    pub const SYS_TIMERFD_GETTIME: i64 = 87;
869    pub const SYS_ACCEPT4: i64 = 242;
870    pub const SYS_ACCT: i64 = 89;
871    pub const SYS_CAPGET: i64 = 90;
872    pub const SYS_CAPSET: i64 = 91;
873    pub const SYS_CHROOT: i64 = 51;
874    pub const SYS_COPY_FILE_RANGE: i64 = 285;
875    pub const SYS_DELETE_MODULE: i64 = 106;
876    pub const SYS_FALLOCATE: i64 = 47;
877    pub const SYS_FCHDIR: i64 = 50;
878    pub const SYS_FCHOWN: i64 = 55;
879    pub const SYS_FCHOWNAT: i64 = 54;
880    pub const SYS_FLOCK: i64 = 32;
881    pub const SYS_GETDENTS64: i64 = 61;
882    pub const SYS_GETPRIORITY: i64 = 141;
883    pub const SYS_GETRESGID: i64 = 150;
884    pub const SYS_GETRESUID: i64 = 148;
885    pub const SYS_INIT_MODULE: i64 = 105;
886    pub const SYS_MKNODAT: i64 = 33;
887    pub const SYS_MOUNT: i64 = 40;
888    pub const SYS_MPROTECT: i64 = 226;
889    pub const SYS_PIVOT_ROOT: i64 = 41;
890    pub const SYS_PRCTL: i64 = 167;
891    pub const SYS_PSELECT6: i64 = 72;
892    pub const SYS_REBOOT: i64 = 142;
893    pub const SYS_RECVMSG: i64 = 212;
894    pub const SYS_SENDMSG: i64 = 211;
895    pub const SYS_SETGROUPS: i64 = 159;
896    pub const SYS_SETNS: i64 = 268;
897    pub const SYS_SETPRIORITY: i64 = 140;
898    pub const SYS_SETRESGID: i64 = 149;
899    pub const SYS_SETRESUID: i64 = 147;
900    pub const SYS_SWAPOFF: i64 = 225;
901    pub const SYS_SWAPON: i64 = 224;
902    pub const SYS_UMOUNT2: i64 = 39;
903    pub const SYS_UNSHARE: i64 = 97;
904}
905pub use sysnr::*;