crabc-libc 0.7.7

A Rust no_std musl-compatible libc implementation
Documentation
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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
// Copyright (c) 2026 Meng Zhuo
// SPDX-License-Identifier: BSD-3-Clause

// Architecture layer for libc.
//
// Included from lib.rs.  Everything below is selected with target_arch:
// the syscall ABI, the active Arch alias and the syscall-number tables.
// Keep per-architecture changes in this file rather than scattering cfg
// blocks through the libc functional areas.

// ============================================================
// Architecture selection
// ============================================================

/// Read the thread pointer.  errno and static TLS use this before any
/// architecture-specific TLS helpers are available.
#[cfg(target_arch = "x86_64")]
unsafe fn arch_get_tp() -> usize {
    const ARCH_PRCTL: i64 = 158;
    const ARCH_GET_FS: i64 = 0x1003;
    let mut tp: usize = 0;
    let _ = <Arch as Syscalls>::syscall2(ARCH_PRCTL, ARCH_GET_FS, &mut tp as *mut usize as i64);
    tp
}

#[cfg(target_arch = "aarch64")]
unsafe fn arch_get_tp() -> usize {
    let tp: usize;
    core::arch::asm!("mrs {}, tpidr_el0", out(reg) tp, options(nostack, preserves_flags));
    tp
}

#[cfg(target_arch = "riscv64")]
unsafe fn arch_get_tp() -> usize {
    let tp: usize;
    core::arch::asm!("mv {}, tp", out(reg) tp, options(nostack, preserves_flags));
    tp
}

/// Read the thread pointer without a syscall.  Used on hot paths (vDSO
/// getrandom) where TLS is guaranteed to be set up already.
#[cfg(target_arch = "x86_64")]
unsafe fn arch_get_tp_fast() -> usize {
    let tp: usize;
    core::arch::asm!("mov {}, fs:[0]", out(reg) tp, options(nostack, preserves_flags));
    tp
}

#[cfg(target_arch = "aarch64")]
unsafe fn arch_get_tp_fast() -> usize {
    let tp: usize;
    core::arch::asm!("mrs {}, tpidr_el0", out(reg) tp, options(nostack, preserves_flags));
    tp
}

#[cfg(target_arch = "riscv64")]
unsafe fn arch_get_tp_fast() -> usize {
    let tp: usize;
    core::arch::asm!("mv {}, tp", out(reg) tp, options(nostack, preserves_flags));
    tp
}

// ============================================================
// Syscall ABI
// ============================================================

trait Syscalls {
    unsafe fn syscall0(n: i64) -> i64;
    unsafe fn syscall1(n: i64, a1: i64) -> i64;
    unsafe fn syscall2(n: i64, a1: i64, a2: i64) -> i64;
    unsafe fn syscall3(n: i64, a1: i64, a2: i64, a3: i64) -> i64;
    unsafe fn syscall4(n: i64, a1: i64, a2: i64, a3: i64, a4: i64) -> i64;
    unsafe fn syscall5(n: i64, a1: i64, a2: i64, a3: i64, a4: i64, a5: i64) -> i64;
    unsafe fn syscall6(n: i64, a1: i64, a2: i64, a3: i64, a4: i64, a5: i64, a6: i64) -> i64;
    unsafe fn syscall_noreturn1(n: i64, a1: i64) -> !;
}

struct X86_64;
struct Aarch64;
struct Riscv64;

// x86_64
#[cfg(target_arch = "x86_64")]
impl Syscalls for X86_64 {
    #[inline(always)]
    unsafe fn syscall0(n: i64) -> i64 {
        let result: i64;
        core::arch::asm!(
            "syscall",
            inlateout("rax") n => result,
            lateout("rcx") _,
            lateout("r11") _,
        );
        result
    }
    #[inline(always)]
    unsafe fn syscall1(n: i64, a1: i64) -> i64 {
        let result: i64;
        core::arch::asm!(
            "syscall",
            inlateout("rax") n => result,
            in("rdi") a1,
            lateout("rcx") _,
            lateout("r11") _,
        );
        result
    }
    #[inline(always)]
    unsafe fn syscall2(n: i64, a1: i64, a2: i64) -> i64 {
        let result: i64;
        core::arch::asm!(
            "syscall",
            inlateout("rax") n => result,
            in("rdi") a1,
            in("rsi") a2,
            lateout("rcx") _,
            lateout("r11") _,
        );
        result
    }
    #[inline(always)]
    unsafe fn syscall3(n: i64, a1: i64, a2: i64, a3: i64) -> i64 {
        let result: i64;
        core::arch::asm!(
            "syscall",
            inlateout("rax") n => result,
            in("rdi") a1,
            in("rsi") a2,
            in("rdx") a3,
            lateout("rcx") _,
            lateout("r11") _,
        );
        result
    }
    #[inline(always)]
    unsafe fn syscall4(n: i64, a1: i64, a2: i64, a3: i64, a4: i64) -> i64 {
        let result: i64;
        core::arch::asm!(
            "syscall",
            inlateout("rax") n => result,
            in("rdi") a1,
            in("rsi") a2,
            in("rdx") a3,
            in("r10") a4,
            lateout("rcx") _,
            lateout("r11") _,
        );
        result
    }
    #[inline(always)]
    unsafe fn syscall5(n: i64, a1: i64, a2: i64, a3: i64, a4: i64, a5: i64) -> i64 {
        let result: i64;
        core::arch::asm!(
            "syscall",
            inlateout("rax") n => result,
            in("rdi") a1,
            in("rsi") a2,
            in("rdx") a3,
            in("r10") a4,
            in("r8") a5,
            lateout("rcx") _,
            lateout("r11") _,
        );
        result
    }
    #[inline(always)]
    unsafe fn syscall6(n: i64, a1: i64, a2: i64, a3: i64, a4: i64, a5: i64, a6: i64) -> i64 {
        let result: i64;
        core::arch::asm!(
            "syscall",
            inlateout("rax") n => result,
            in("rdi") a1,
            in("rsi") a2,
            in("rdx") a3,
            in("r10") a4,
            in("r8") a5,
            in("r9") a6,
            lateout("rcx") _,
            lateout("r11") _,
        );
        result
    }
    #[inline(always)]
    unsafe fn syscall_noreturn1(n: i64, a1: i64) -> ! {
        core::arch::asm!(
            "syscall",
            in("rax") n,
            in("rdi") a1,
            options(noreturn)
        );
    }
}

// aarch64
#[cfg(target_arch = "aarch64")]
impl Syscalls for Aarch64 {
    #[inline(always)]
    unsafe fn syscall0(n: i64) -> i64 {
        let result: i64;
        core::arch::asm!(
            "svc #0",
            inlateout("x8") n => _,
            lateout("x0") result,
            options(nostack),
        );
        result
    }
    #[inline(always)]
    unsafe fn syscall1(n: i64, a1: i64) -> i64 {
        let result: i64;
        core::arch::asm!(
            "svc #0",
            inlateout("x8") n => _,
            inlateout("x0") a1 => result,
            options(nostack),
        );
        result
    }
    #[inline(always)]
    unsafe fn syscall2(n: i64, a1: i64, a2: i64) -> i64 {
        let result: i64;
        core::arch::asm!(
            "svc #0",
            inlateout("x8") n => _,
            inlateout("x0") a1 => result,
            inlateout("x1") a2 => _,
            options(nostack),
        );
        result
    }
    #[inline(always)]
    unsafe fn syscall3(n: i64, a1: i64, a2: i64, a3: i64) -> i64 {
        let result: i64;
        core::arch::asm!(
            "svc #0",
            inlateout("x8") n => _,
            inlateout("x0") a1 => result,
            inlateout("x1") a2 => _,
            inlateout("x2") a3 => _,
            options(nostack),
        );
        result
    }
    #[inline(always)]
    unsafe fn syscall4(n: i64, a1: i64, a2: i64, a3: i64, a4: i64) -> i64 {
        let result: i64;
        core::arch::asm!(
            "svc #0",
            inlateout("x8") n => _,
            inlateout("x0") a1 => result,
            inlateout("x1") a2 => _,
            inlateout("x2") a3 => _,
            inlateout("x3") a4 => _,
            options(nostack),
        );
        result
    }
    #[inline(always)]
    unsafe fn syscall5(n: i64, a1: i64, a2: i64, a3: i64, a4: i64, a5: i64) -> i64 {
        let result: i64;
        core::arch::asm!(
            "svc #0",
            inlateout("x8") n => _,
            inlateout("x0") a1 => result,
            inlateout("x1") a2 => _,
            inlateout("x2") a3 => _,
            inlateout("x3") a4 => _,
            inlateout("x4") a5 => _,
            options(nostack),
        );
        result
    }
    #[inline(always)]
    unsafe fn syscall6(n: i64, a1: i64, a2: i64, a3: i64, a4: i64, a5: i64, a6: i64) -> i64 {
        let result: i64;
        core::arch::asm!(
            "svc #0",
            inlateout("x8") n => _,
            inlateout("x0") a1 => result,
            inlateout("x1") a2 => _,
            inlateout("x2") a3 => _,
            inlateout("x3") a4 => _,
            inlateout("x4") a5 => _,
            inlateout("x5") a6 => _,
            options(nostack),
        );
        result
    }
    #[inline(always)]
    unsafe fn syscall_noreturn1(n: i64, a1: i64) -> ! {
        core::arch::asm!(
            "svc #0",
            in("x8") n,
            in("x0") a1,
            options(noreturn, nostack),
        );
    }
}

// riscv64
#[cfg(target_arch = "riscv64")]
impl Syscalls for Riscv64 {
    #[inline(always)]
    unsafe fn syscall0(n: i64) -> i64 {
        let result: i64;
        core::arch::asm!(
            "ecall",
            inlateout("a7") n => _,
            lateout("a0") result,
            options(nostack),
        );
        result
    }
    #[inline(always)]
    unsafe fn syscall1(n: i64, a1: i64) -> i64 {
        let result: i64;
        core::arch::asm!(
            "ecall",
            inlateout("a7") n => _,
            inlateout("a0") a1 => result,
            options(nostack),
        );
        result
    }
    #[inline(always)]
    unsafe fn syscall2(n: i64, a1: i64, a2: i64) -> i64 {
        let result: i64;
        core::arch::asm!(
            "ecall",
            inlateout("a7") n => _,
            inlateout("a0") a1 => result,
            inlateout("a1") a2 => _,
            options(nostack),
        );
        result
    }
    #[inline(always)]
    unsafe fn syscall3(n: i64, a1: i64, a2: i64, a3: i64) -> i64 {
        let result: i64;
        core::arch::asm!(
            "ecall",
            inlateout("a7") n => _,
            inlateout("a0") a1 => result,
            inlateout("a1") a2 => _,
            inlateout("a2") a3 => _,
            options(nostack),
        );
        result
    }
    #[inline(always)]
    unsafe fn syscall4(n: i64, a1: i64, a2: i64, a3: i64, a4: i64) -> i64 {
        let result: i64;
        core::arch::asm!(
            "ecall",
            inlateout("a7") n => _,
            inlateout("a0") a1 => result,
            inlateout("a1") a2 => _,
            inlateout("a2") a3 => _,
            inlateout("a3") a4 => _,
            options(nostack),
        );
        result
    }
    #[inline(always)]
    unsafe fn syscall5(n: i64, a1: i64, a2: i64, a3: i64, a4: i64, a5: i64) -> i64 {
        let result: i64;
        core::arch::asm!(
            "ecall",
            inlateout("a7") n => _,
            inlateout("a0") a1 => result,
            inlateout("a1") a2 => _,
            inlateout("a2") a3 => _,
            inlateout("a3") a4 => _,
            inlateout("a4") a5 => _,
            options(nostack),
        );
        result
    }
    #[inline(always)]
    unsafe fn syscall6(n: i64, a1: i64, a2: i64, a3: i64, a4: i64, a5: i64, a6: i64) -> i64 {
        let result: i64;
        core::arch::asm!(
            "ecall",
            inlateout("a7") n => _,
            inlateout("a0") a1 => result,
            inlateout("a1") a2 => _,
            inlateout("a2") a3 => _,
            inlateout("a3") a4 => _,
            inlateout("a4") a5 => _,
            inlateout("a5") a6 => _,
            options(nostack),
        );
        result
    }
    #[inline(always)]
    unsafe fn syscall_noreturn1(n: i64, a1: i64) -> ! {
        core::arch::asm!(
            "ecall",
            in("a7") n,
            in("a0") a1,
            options(noreturn, nostack),
        );
    }
}

// ============================================================
// Selected architecture
// ============================================================

// x86_64
#[cfg(target_arch = "x86_64")]
type Arch = X86_64;
// aarch64
#[cfg(target_arch = "aarch64")]
type Arch = Aarch64;
// riscv64
#[cfg(target_arch = "riscv64")]
type Arch = Riscv64;

// ============================================================
// Syscall numbers
// ============================================================

// x86_64
#[cfg(target_arch = "x86_64")]
mod sysnr {
    pub const SYS_READ: i64 = 0;
    pub const SYS_WRITE: i64 = 1;
    pub const SYS_OPEN: i64 = 2;
    pub const SYS_CLOSE: i64 = 3;
    pub const SYS_STAT: i64 = 4;
    pub const SYS_FSTAT: i64 = 5;
    pub const SYS_LSEEK: i64 = 8;
    pub const SYS_MMAP: i64 = 9;
    pub const SYS_MUNMAP: i64 = 11;
    pub const SYS_MPROTECT: i64 = 10;
    pub const SYS_RT_SIGACTION: i64 = 13;
    pub const SYS_RT_SIGPROCMASK: i64 = 14;
    pub const SYS_IOCTL: i64 = 16;
    pub const SYS_ACCESS: i64 = 21;
    pub const SYS_SHMGET: i64 = 29;
    pub const SYS_SHMAT: i64 = 30;
    pub const SYS_SHMCTL: i64 = 31;
    pub const SYS_DUP: i64 = 32;
    pub const SYS_NANOSLEEP: i64 = 35;
    pub const SYS_SETITIMER: i64 = 38;
    pub const SYS_ALARM: i64 = 37;
    pub const SYS_SOCKET: i64 = 41;
    pub const SYS_CONNECT: i64 = 42;
    pub const SYS_ACCEPT: i64 = 43;
    pub const SYS_ACCEPT4: i64 = 288;
    pub const SYS_SENDTO: i64 = 44;
    pub const SYS_RECVFROM: i64 = 45;
    pub const SYS_SENDMSG: i64 = 46;
    pub const SYS_RECVMSG: i64 = 47;
    pub const SYS_SHUTDOWN: i64 = 48;
    pub const SYS_BIND: i64 = 49;
    pub const SYS_LISTEN: i64 = 50;
    pub const SYS_GETSOCKNAME: i64 = 51;
    pub const SYS_SOCKETPAIR: i64 = 53;
    pub const SYS_SETSOCKOPT: i64 = 54;
    pub const SYS_EXECVE: i64 = 59;
    pub const SYS_WAIT4: i64 = 61;
    pub const SYS_KILL: i64 = 62;
    pub const SYS_UNAME: i64 = 63;
    pub const SYS_SEMGET: i64 = 64;
    pub const SYS_SEMOP: i64 = 65;
    pub const SYS_SEMCTL: i64 = 66;
    pub const SYS_SHMDT: i64 = 67;
    pub const SYS_MSGGET: i64 = 68;
    pub const SYS_MSGSND: i64 = 69;
    pub const SYS_MSGRCV: i64 = 70;
    pub const SYS_MSGCTL: i64 = 71;
    pub const SYS_FCNTL: i64 = 72;
    pub const SYS_FSYNC: i64 = 74;
    pub const SYS_TRUNCATE: i64 = 76;
    pub const SYS_FTRUNCATE: i64 = 77;
    pub const SYS_GETCWD: i64 = 79;
    pub const SYS_CHDIR: i64 = 80;
    pub const SYS_SYMLINK: i64 = 88;
    pub const SYS_FCHMOD: i64 = 91;
    pub const SYS_UMASK: i64 = 95;
    pub const SYS_GETRLIMIT: i64 = 97;
    pub const SYS_SETUID: i64 = 105;
    pub const SYS_SETGID: i64 = 106;
    pub const SYS_SETPGID: i64 = 109;
    pub const SYS_GETGROUPS: i64 = 115;
    pub const SYS_GETPGID: i64 = 121;
    pub const SYS_GETSID: i64 = 124;
    pub const SYS_RT_SIGPENDING: i64 = 127;
    pub const SYS_RT_SIGTIMEDWAIT: i64 = 128;
    pub const SYS_RT_SIGSUSPEND: i64 = 130;
    pub const SYS_SIGALTSTACK: i64 = 131;
    pub const SYS_SETRLIMIT: i64 = 160;
    pub const SYS_SETHOSTNAME: i64 = 170;
    pub const SYS_FUTEX: i64 = 202;
    pub const SYS_CLOCK_GETTIME: i64 = 228;
    pub const SYS_CLOCK_GETRES: i64 = 229;
    pub const SYS_CLOCK_NANOSLEEP: i64 = 230;
    pub const SYS_EXIT_GROUP: i64 = 231;
    pub const SYS_TGKILL: i64 = 234;
    pub const SYS_MKDIRAT: i64 = 258;
    pub const SYS_NEWFSTATAT: i64 = 262;
    pub const SYS_UNLINKAT: i64 = 263;
    pub const SYS_LINKAT: i64 = 265;
    pub const SYS_SYMLINKAT: i64 = 266;
    pub const SYS_READLINKAT: i64 = 267;
    pub const SYS_FCHMODAT: i64 = 268;
    pub const SYS_SET_ROBUST_LIST: i64 = 273;
    pub const SYS_UTIMENSAT: i64 = 280;
    pub const SYS_OPENAT: i64 = 257;
    pub const SYS_FACCESSAT: i64 = 269;
    pub const SYS_DUP3: i64 = 292;
    pub const SYS_PIPE2: i64 = 293;
    pub const SYS_SYNCFS: i64 = 306;
    pub const SYS_RENAMEAT2: i64 = 316;
    pub const SYS_STATFS: i64 = 137;
    pub const SYS_FSTATFS: i64 = 138;
    pub const SYS_FDATASYNC: i64 = 75;
    pub const SYS_PAUSE: i64 = 34;
    pub const SYS_POLL: i64 = 7;
    pub const SYS_PPOLL: i64 = 271;
    pub const SYS_PSELECT6: i64 = 270;
    pub const SYS_GETPID: i64 = 39;
    pub const SYS_FORK: i64 = 57;
    pub const SYS_EXIT: i64 = 60;
    pub const SYS_GETPPID: i64 = 110;
    pub const SYS_SETSID: i64 = 112;
    pub const SYS_SYNC: i64 = 162;
    pub const SYS_GETUID: i64 = 102;
    pub const SYS_GETGID: i64 = 104;
    pub const SYS_GETEUID: i64 = 107;
    pub const SYS_GETEGID: i64 = 108;
    pub const SYS_GETTID: i64 = 186;
    pub const SYS_CLOCK_SETTIME: i64 = 227;
    pub const SYS_CLONE: i64 = 56;
    pub const SYS_PREAD64: i64 = 17;
    pub const SYS_MREMAP: i64 = 25;
    pub const SYS_SYSINFO: i64 = 99;
    pub const SYS_MEMBARRIER: i64 = 324;
    pub const SYS_VHANGUP: i64 = 153;
    pub const SYS_VMSPLICE: i64 = 278;
    pub const SYS_GETDENTS64: i64 = 217;
    pub const SYS_EPOLL_CREATE: i64 = 213;
    pub const SYS_EPOLL_CREATE1: i64 = 291;
    pub const SYS_EPOLL_CTL: i64 = 233;
    pub const SYS_EPOLL_WAIT: i64 = 232;
    pub const SYS_EPOLL_PWAIT: i64 = 281;
    pub const SYS_EVENTFD2: i64 = 290;
    pub const SYS_SIGNALFD4: i64 = 289;
    pub const SYS_TIMERFD_CREATE: i64 = 283;
    pub const SYS_TIMERFD_SETTIME: i64 = 286;
    pub const SYS_TIMERFD_GETTIME: i64 = 287;
    pub const SYS_PRCTL: i64 = 157;
    pub const SYS_FALLOCATE: i64 = 285;
    pub const SYS_FLOCK: i64 = 73;
    pub const SYS_SETGROUPS: i64 = 116;
    pub const SYS_SETRESUID: i64 = 117;
    pub const SYS_SETRESGID: i64 = 119;
    pub const SYS_GETRESUID: i64 = 118;
    pub const SYS_GETRESGID: i64 = 120;
    pub const SYS_MKNOD: i64 = 133;
    pub const SYS_FCHDIR: i64 = 81;
    pub const SYS_FCHOWN: i64 = 93;
    pub const SYS_ACCT: i64 = 163;
    pub const SYS_ADJTIMEX: i64 = 159;
    pub const SYS_CAPGET: i64 = 125;
    pub const SYS_CAPSET: i64 = 126;
    pub const SYS_CHROOT: i64 = 161;
    pub const SYS_COPY_FILE_RANGE: i64 = 326;
    pub const SYS_DELETE_MODULE: i64 = 176;
    pub const SYS_INIT_MODULE: i64 = 175;
    pub const SYS_FCHOWNAT: i64 = 260;
    pub const SYS_MKNODAT: i64 = 259;
    pub const SYS_SETNS: i64 = 308;
    pub const SYS_UNSHARE: i64 = 272;
    pub const SYS_REBOOT: i64 = 169;
    pub const SYS_NICE: i64 = 34;
    pub const SYS_SETPRIORITY: i64 = 141;
    pub const SYS_GETPRIORITY: i64 = 140;
    pub const SYS_IOPERM: i64 = 173;
    pub const SYS_IOPL: i64 = 172;
    pub const SYS_SWAPON: i64 = 167;
    pub const SYS_SWAPOFF: i64 = 168;
    pub const SYS_MOUNT: i64 = 165;
    pub const SYS_UMOUNT2: i64 = 166;
    pub const SYS_PIVOT_ROOT: i64 = 155;
    pub const SYS_SETTIMEOFDAY: i64 = 164;
    pub const SYS_GETTIMEOFDAY: i64 = 96;
}
// aarch64
#[cfg(target_arch = "aarch64")]
mod sysnr {
    pub const SYS_READ: i64 = 63;
    pub const SYS_WRITE: i64 = 64;
    // pub const SYS_OPEN: i64 = ???; // missing in aarch64 table
    pub const SYS_CLOSE: i64 = 57;
    // pub const SYS_STAT: i64 = ???; // missing in aarch64 table
    pub const SYS_FSTAT: i64 = 80;
    pub const SYS_LSEEK: i64 = 62;
    pub const SYS_MMAP: i64 = 222;
    pub const SYS_MUNMAP: i64 = 215;
    pub const SYS_RT_SIGACTION: i64 = 134;
    pub const SYS_RT_SIGPROCMASK: i64 = 135;
    pub const SYS_IOCTL: i64 = 29;
    // pub const SYS_ACCESS: i64 = ???; // missing in aarch64 table
    pub const SYS_SHMGET: i64 = 194;
    pub const SYS_SHMAT: i64 = 196;
    pub const SYS_SHMCTL: i64 = 195;
    pub const SYS_DUP: i64 = 23;
    pub const SYS_NANOSLEEP: i64 = 101;
    pub const SYS_SETITIMER: i64 = 103;
    // pub const SYS_ALARM: i64 = ???; // missing in aarch64 table
    pub const SYS_SOCKET: i64 = 198;
    pub const SYS_CONNECT: i64 = 203;
    pub const SYS_ACCEPT: i64 = 202;
    pub const SYS_SENDTO: i64 = 206;
    pub const SYS_RECVFROM: i64 = 207;
    pub const SYS_SHUTDOWN: i64 = 210;
    pub const SYS_BIND: i64 = 200;
    pub const SYS_LISTEN: i64 = 201;
    pub const SYS_GETSOCKNAME: i64 = 204;
    pub const SYS_SOCKETPAIR: i64 = 199;
    pub const SYS_SETSOCKOPT: i64 = 208;
    pub const SYS_EXECVE: i64 = 221;
    pub const SYS_WAIT4: i64 = 260;
    pub const SYS_KILL: i64 = 129;
    pub const SYS_UNAME: i64 = 160;
    pub const SYS_SEMGET: i64 = 190;
    pub const SYS_SEMOP: i64 = 193;
    pub const SYS_SEMCTL: i64 = 191;
    pub const SYS_SHMDT: i64 = 197;
    pub const SYS_MSGGET: i64 = 186;
    pub const SYS_MSGSND: i64 = 189;
    pub const SYS_MSGRCV: i64 = 188;
    pub const SYS_MSGCTL: i64 = 187;
    pub const SYS_FCNTL: i64 = 25;
    pub const SYS_FSYNC: i64 = 82;
    pub const SYS_TRUNCATE: i64 = 45;
    pub const SYS_FTRUNCATE: i64 = 46;
    pub const SYS_GETCWD: i64 = 17;
    pub const SYS_CHDIR: i64 = 49;
    // pub const SYS_SYMLINK: i64 = ???; // missing in aarch64 table
    pub const SYS_FCHMOD: i64 = 52;
    pub const SYS_UMASK: i64 = 166;
    pub const SYS_GETRLIMIT: i64 = 163;
    pub const SYS_SETUID: i64 = 146;
    pub const SYS_SETGID: i64 = 144;
    pub const SYS_SETPGID: i64 = 154;
    pub const SYS_GETGROUPS: i64 = 158;
    pub const SYS_GETPGID: i64 = 155;
    pub const SYS_GETSID: i64 = 156;
    pub const SYS_RT_SIGPENDING: i64 = 136;
    pub const SYS_RT_SIGTIMEDWAIT: i64 = 137;
    pub const SYS_RT_SIGSUSPEND: i64 = 133;
    pub const SYS_SIGALTSTACK: i64 = 132;
    pub const SYS_SETRLIMIT: i64 = 164;
    pub const SYS_SETHOSTNAME: i64 = 161;
    pub const SYS_FUTEX: i64 = 98;
    pub const SYS_CLOCK_GETTIME: i64 = 113;
    pub const SYS_CLOCK_GETRES: i64 = 114;
    pub const SYS_CLOCK_NANOSLEEP: i64 = 115;
    pub const SYS_EXIT_GROUP: i64 = 94;
    pub const SYS_TGKILL: i64 = 131;
    pub const SYS_MKDIRAT: i64 = 34;
    pub const SYS_NEWFSTATAT: i64 = 79;
    pub const SYS_UNLINKAT: i64 = 35;
    pub const SYS_LINKAT: i64 = 37;
    pub const SYS_SYMLINKAT: i64 = 36;
    pub const SYS_READLINKAT: i64 = 78;
    pub const SYS_FCHMODAT: i64 = 53;
    pub const SYS_SET_ROBUST_LIST: i64 = 99;
    pub const SYS_UTIMENSAT: i64 = 88;
    pub const SYS_OPENAT: i64 = 56;
    pub const SYS_FACCESSAT: i64 = 48;
    pub const SYS_DUP3: i64 = 24;
    pub const SYS_PIPE2: i64 = 59;
    pub const SYS_SYNCFS: i64 = 267;
    pub const SYS_RENAMEAT2: i64 = 276;
    pub const SYS_STATFS: i64 = 43;
    pub const SYS_FSTATFS: i64 = 44;
    pub const SYS_FDATASYNC: i64 = 83;
    pub const SYS_GETPID: i64 = 172;
    pub const SYS_EXIT: i64 = 93;
    pub const SYS_GETPPID: i64 = 173;
    pub const SYS_SETSID: i64 = 157;
    pub const SYS_SYNC: i64 = 81;
    pub const SYS_GETUID: i64 = 174;
    pub const SYS_GETGID: i64 = 176;
    pub const SYS_GETEUID: i64 = 175;
    pub const SYS_GETEGID: i64 = 177;
    pub const SYS_GETTID: i64 = 178;
    pub const SYS_CLOCK_SETTIME: i64 = 112;
    pub const SYS_CLONE: i64 = 220;
    pub const SYS_PPOLL: i64 = 73;
    pub const SYS_PREAD64: i64 = 67;
    pub const SYS_MREMAP: i64 = 216;
    pub const SYS_SYSINFO: i64 = 179;
    pub const SYS_MEMBARRIER: i64 = 283;
    pub const SYS_VHANGUP: i64 = 58;
    pub const SYS_VMSPLICE: i64 = 75;
    pub const SYS_GETTIMEOFDAY: i64 = 169;
    pub const SYS_SETTIMEOFDAY: i64 = 170;
    pub const SYS_ADJTIMEX: i64 = 171;
    pub const SYS_EPOLL_CREATE1: i64 = 20;
    pub const SYS_EPOLL_CTL: i64 = 21;
    pub const SYS_EPOLL_WAIT: i64 = 22;
    pub const SYS_EPOLL_PWAIT: i64 = 22;
    pub const SYS_EVENTFD2: i64 = 19;
    pub const SYS_SIGNALFD4: i64 = 74;
    pub const SYS_TIMERFD_CREATE: i64 = 85;
    pub const SYS_TIMERFD_SETTIME: i64 = 86;
    pub const SYS_TIMERFD_GETTIME: i64 = 87;
    pub const SYS_ACCEPT4: i64 = 242;
    pub const SYS_ACCT: i64 = 89;
    pub const SYS_CAPGET: i64 = 90;
    pub const SYS_CAPSET: i64 = 91;
    pub const SYS_CHROOT: i64 = 51;
    pub const SYS_COPY_FILE_RANGE: i64 = 285;
    pub const SYS_DELETE_MODULE: i64 = 106;
    pub const SYS_FALLOCATE: i64 = 47;
    pub const SYS_FCHDIR: i64 = 50;
    pub const SYS_FCHOWN: i64 = 55;
    pub const SYS_FCHOWNAT: i64 = 54;
    pub const SYS_FLOCK: i64 = 32;
    pub const SYS_GETDENTS64: i64 = 61;
    pub const SYS_GETPRIORITY: i64 = 141;
    pub const SYS_GETRESGID: i64 = 150;
    pub const SYS_GETRESUID: i64 = 148;
    pub const SYS_INIT_MODULE: i64 = 105;
    pub const SYS_MKNODAT: i64 = 33;
    pub const SYS_MOUNT: i64 = 40;
    pub const SYS_MPROTECT: i64 = 226;
    pub const SYS_PIVOT_ROOT: i64 = 41;
    pub const SYS_PRCTL: i64 = 167;
    pub const SYS_PSELECT6: i64 = 72;
    pub const SYS_REBOOT: i64 = 142;
    pub const SYS_RECVMSG: i64 = 212;
    pub const SYS_SENDMSG: i64 = 211;
    pub const SYS_SETGROUPS: i64 = 159;
    pub const SYS_SETNS: i64 = 268;
    pub const SYS_SETPRIORITY: i64 = 140;
    pub const SYS_SETRESGID: i64 = 149;
    pub const SYS_SETRESUID: i64 = 147;
    pub const SYS_SWAPOFF: i64 = 225;
    pub const SYS_SWAPON: i64 = 224;
    pub const SYS_UMOUNT2: i64 = 39;
    pub const SYS_UNSHARE: i64 = 97;
}
// riscv64 uses the same new-style syscall table as aarch64
// riscv64 uses the same new-style syscall table as aarch64
#[cfg(target_arch = "riscv64")]
mod sysnr {
    pub const SYS_READ: i64 = 63;
    pub const SYS_WRITE: i64 = 64;
    pub const SYS_CLOSE: i64 = 57;
    pub const SYS_FSTAT: i64 = 80;
    pub const SYS_LSEEK: i64 = 62;
    pub const SYS_MMAP: i64 = 222;
    pub const SYS_MUNMAP: i64 = 215;
    pub const SYS_RT_SIGACTION: i64 = 134;
    pub const SYS_RT_SIGPROCMASK: i64 = 135;
    pub const SYS_IOCTL: i64 = 29;
    pub const SYS_SHMGET: i64 = 194;
    pub const SYS_SHMAT: i64 = 196;
    pub const SYS_SHMCTL: i64 = 195;
    pub const SYS_DUP: i64 = 23;
    pub const SYS_NANOSLEEP: i64 = 101;
    pub const SYS_SETITIMER: i64 = 103;
    pub const SYS_SOCKET: i64 = 198;
    pub const SYS_CONNECT: i64 = 203;
    pub const SYS_ACCEPT: i64 = 202;
    pub const SYS_SENDTO: i64 = 206;
    pub const SYS_RECVFROM: i64 = 207;
    pub const SYS_SHUTDOWN: i64 = 210;
    pub const SYS_BIND: i64 = 200;
    pub const SYS_LISTEN: i64 = 201;
    pub const SYS_GETSOCKNAME: i64 = 204;
    pub const SYS_SOCKETPAIR: i64 = 199;
    pub const SYS_SETSOCKOPT: i64 = 208;
    pub const SYS_EXECVE: i64 = 221;
    pub const SYS_WAIT4: i64 = 260;
    pub const SYS_KILL: i64 = 129;
    pub const SYS_UNAME: i64 = 160;
    pub const SYS_SEMGET: i64 = 190;
    pub const SYS_SEMOP: i64 = 193;
    pub const SYS_SEMCTL: i64 = 191;
    pub const SYS_SHMDT: i64 = 197;
    pub const SYS_MSGGET: i64 = 186;
    pub const SYS_MSGSND: i64 = 189;
    pub const SYS_MSGRCV: i64 = 188;
    pub const SYS_MSGCTL: i64 = 187;
    pub const SYS_FCNTL: i64 = 25;
    pub const SYS_FSYNC: i64 = 82;
    pub const SYS_TRUNCATE: i64 = 45;
    pub const SYS_FTRUNCATE: i64 = 46;
    pub const SYS_GETCWD: i64 = 17;
    pub const SYS_CHDIR: i64 = 49;
    pub const SYS_FCHMOD: i64 = 52;
    pub const SYS_UMASK: i64 = 166;
    pub const SYS_GETRLIMIT: i64 = 163;
    pub const SYS_SETUID: i64 = 146;
    pub const SYS_SETGID: i64 = 144;
    pub const SYS_SETPGID: i64 = 154;
    pub const SYS_GETGROUPS: i64 = 158;
    pub const SYS_GETPGID: i64 = 155;
    pub const SYS_GETSID: i64 = 156;
    pub const SYS_RT_SIGPENDING: i64 = 136;
    pub const SYS_RT_SIGTIMEDWAIT: i64 = 137;
    pub const SYS_RT_SIGSUSPEND: i64 = 133;
    pub const SYS_SIGALTSTACK: i64 = 132;
    pub const SYS_SETRLIMIT: i64 = 164;
    pub const SYS_SETHOSTNAME: i64 = 161;
    pub const SYS_FUTEX: i64 = 98;
    pub const SYS_CLOCK_GETTIME: i64 = 113;
    pub const SYS_CLOCK_GETRES: i64 = 114;
    pub const SYS_CLOCK_NANOSLEEP: i64 = 115;
    pub const SYS_EXIT_GROUP: i64 = 94;
    pub const SYS_TGKILL: i64 = 131;
    pub const SYS_MKDIRAT: i64 = 34;
    pub const SYS_NEWFSTATAT: i64 = 79;
    pub const SYS_UNLINKAT: i64 = 35;
    pub const SYS_LINKAT: i64 = 37;
    pub const SYS_SYMLINKAT: i64 = 36;
    pub const SYS_READLINKAT: i64 = 78;
    pub const SYS_FCHMODAT: i64 = 53;
    pub const SYS_SET_ROBUST_LIST: i64 = 99;
    pub const SYS_UTIMENSAT: i64 = 88;
    pub const SYS_OPENAT: i64 = 56;
    pub const SYS_FACCESSAT: i64 = 48;
    pub const SYS_DUP3: i64 = 24;
    pub const SYS_PIPE2: i64 = 59;
    pub const SYS_SYNCFS: i64 = 267;
    pub const SYS_RENAMEAT2: i64 = 276;
    pub const SYS_STATFS: i64 = 43;
    pub const SYS_FSTATFS: i64 = 44;
    pub const SYS_FDATASYNC: i64 = 83;
    pub const SYS_GETPID: i64 = 172;
    pub const SYS_EXIT: i64 = 93;
    pub const SYS_GETPPID: i64 = 173;
    pub const SYS_SETSID: i64 = 157;
    pub const SYS_SYNC: i64 = 81;
    pub const SYS_GETUID: i64 = 174;
    pub const SYS_GETGID: i64 = 176;
    pub const SYS_GETEUID: i64 = 175;
    pub const SYS_GETEGID: i64 = 177;
    pub const SYS_GETTID: i64 = 178;
    pub const SYS_CLOCK_SETTIME: i64 = 112;
    pub const SYS_CLONE: i64 = 220;
    pub const SYS_PPOLL: i64 = 73;
    pub const SYS_PREAD64: i64 = 67;
    pub const SYS_MREMAP: i64 = 216;
    pub const SYS_SYSINFO: i64 = 179;
    pub const SYS_MEMBARRIER: i64 = 283;
    pub const SYS_VHANGUP: i64 = 58;
    pub const SYS_VMSPLICE: i64 = 75;
    pub const SYS_GETTIMEOFDAY: i64 = 169;
    pub const SYS_SETTIMEOFDAY: i64 = 170;
    pub const SYS_ADJTIMEX: i64 = 171;
    pub const SYS_EPOLL_CREATE1: i64 = 20;
    pub const SYS_EPOLL_CTL: i64 = 21;
    pub const SYS_EPOLL_WAIT: i64 = 22;
    pub const SYS_EPOLL_PWAIT: i64 = 22;
    pub const SYS_EVENTFD2: i64 = 19;
    pub const SYS_SIGNALFD4: i64 = 74;
    pub const SYS_TIMERFD_CREATE: i64 = 85;
    pub const SYS_TIMERFD_SETTIME: i64 = 86;
    pub const SYS_TIMERFD_GETTIME: i64 = 87;
    pub const SYS_ACCEPT4: i64 = 242;
    pub const SYS_ACCT: i64 = 89;
    pub const SYS_CAPGET: i64 = 90;
    pub const SYS_CAPSET: i64 = 91;
    pub const SYS_CHROOT: i64 = 51;
    pub const SYS_COPY_FILE_RANGE: i64 = 285;
    pub const SYS_DELETE_MODULE: i64 = 106;
    pub const SYS_FALLOCATE: i64 = 47;
    pub const SYS_FCHDIR: i64 = 50;
    pub const SYS_FCHOWN: i64 = 55;
    pub const SYS_FCHOWNAT: i64 = 54;
    pub const SYS_FLOCK: i64 = 32;
    pub const SYS_GETDENTS64: i64 = 61;
    pub const SYS_GETPRIORITY: i64 = 141;
    pub const SYS_GETRESGID: i64 = 150;
    pub const SYS_GETRESUID: i64 = 148;
    pub const SYS_INIT_MODULE: i64 = 105;
    pub const SYS_MKNODAT: i64 = 33;
    pub const SYS_MOUNT: i64 = 40;
    pub const SYS_MPROTECT: i64 = 226;
    pub const SYS_PIVOT_ROOT: i64 = 41;
    pub const SYS_PRCTL: i64 = 167;
    pub const SYS_PSELECT6: i64 = 72;
    pub const SYS_REBOOT: i64 = 142;
    pub const SYS_RECVMSG: i64 = 212;
    pub const SYS_SENDMSG: i64 = 211;
    pub const SYS_SETGROUPS: i64 = 159;
    pub const SYS_SETNS: i64 = 268;
    pub const SYS_SETPRIORITY: i64 = 140;
    pub const SYS_SETRESGID: i64 = 149;
    pub const SYS_SETRESUID: i64 = 147;
    pub const SYS_SWAPOFF: i64 = 225;
    pub const SYS_SWAPON: i64 = 224;
    pub const SYS_UMOUNT2: i64 = 39;
    pub const SYS_UNSHARE: i64 = 97;
}
pub use sysnr::*;