forked from SonjayaJetBrain/animated-gogglases
-
Notifications
You must be signed in to change notification settings - Fork 0
/
linux_syscall_support.h
4487 lines (4325 loc) · 179 KB
/
linux_syscall_support.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
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
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Copyright (c) 2005-2011, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* ---
* Author: Markus Gutschke
*/
/* This file includes Linux-specific support functions common to the
* coredumper and the thread lister; primarily, this is a collection
* of direct system calls, and a couple of symbols missing from
* standard header files.
* There are a few options that the including file can set to control
* the behavior of this file:
*
* SYS_CPLUSPLUS:
* The entire header file will normally be wrapped in 'extern "C" { }",
* making it suitable for compilation as both C and C++ source. If you
* do not want to do this, you can set the SYS_CPLUSPLUS macro to inhibit
* the wrapping. N.B. doing so will suppress inclusion of all prerequisite
* system header files, too. It is the caller's responsibility to provide
* the necessary definitions.
*
* SYS_ERRNO:
* All system calls will update "errno" unless overriden by setting the
* SYS_ERRNO macro prior to including this file. SYS_ERRNO should be
* an l-value.
*
* SYS_INLINE:
* New symbols will be defined "static inline", unless overridden by
* the SYS_INLINE macro.
*
* SYS_LINUX_SYSCALL_SUPPORT_H
* This macro is used to avoid multiple inclusions of this header file.
* If you need to include this file more than once, make sure to
* unset SYS_LINUX_SYSCALL_SUPPORT_H before each inclusion.
*
* SYS_PREFIX:
* New system calls will have a prefix of "sys_" unless overridden by
* the SYS_PREFIX macro. Valid values for this macro are [0..9] which
* results in prefixes "sys[0..9]_". It is also possible to set this
* macro to -1, which avoids all prefixes.
*
* SYS_SYSCALL_ENTRYPOINT:
* Some applications (such as sandboxes that filter system calls), need
* to be able to run custom-code each time a system call is made. If this
* macro is defined, it expands to the name of a "common" symbol. If
* this symbol is assigned a non-NULL pointer value, it is used as the
* address of the system call entrypoint.
* A pointer to this symbol can be obtained by calling
* get_syscall_entrypoint()
*
* This file defines a few internal symbols that all start with "LSS_".
* Do not access these symbols from outside this file. They are not part
* of the supported API.
*/
#ifndef SYS_LINUX_SYSCALL_SUPPORT_H
#define SYS_LINUX_SYSCALL_SUPPORT_H
/* We currently only support x86-32, x86-64, ARM, MIPS, PPC, s390 and s390x
* on Linux.
* Porting to other related platforms should not be difficult.
*/
#if (defined(__i386__) || defined(__x86_64__) || defined(__ARM_ARCH_3__) || \
defined(__mips__) || defined(__PPC__) || defined(__ARM_EABI__) || \
defined(__aarch64__) || defined(__s390__)) \
&& (defined(__linux) || defined(__ANDROID__))
#ifndef SYS_CPLUSPLUS
#ifdef __cplusplus
/* Some system header files in older versions of gcc neglect to properly
* handle being included from C++. As it appears to be harmless to have
* multiple nested 'extern "C"' blocks, just add another one here.
*/
extern "C" {
#endif
#include <errno.h>
#include <fcntl.h>
#include <sched.h>
#include <signal.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdint.h>
#include <string.h>
#include <sys/ptrace.h>
#include <sys/resource.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/syscall.h>
#include <unistd.h>
#include <linux/unistd.h>
#include <endian.h>
#ifdef __mips__
/* Include definitions of the ABI currently in use. */
#ifdef __ANDROID__
/* Android doesn't have sgidefs.h, but does have asm/sgidefs.h,
* which has the definitions we need.
*/
#include <asm/sgidefs.h>
#else
#include <sgidefs.h>
#endif
#endif
#endif
/* The Android NDK's <sys/stat.h> #defines these macros as aliases
* to their non-64 counterparts. To avoid naming conflict, remove them. */
#ifdef __ANDROID__
/* These are restored by the corresponding #pragma pop_macro near
* the end of this file. */
# pragma push_macro("stat64")
# pragma push_macro("fstat64")
# pragma push_macro("lstat64")
# undef stat64
# undef fstat64
# undef lstat64
#endif
/* As glibc often provides subtly incompatible data structures (and implicit
* wrapper functions that convert them), we provide our own kernel data
* structures for use by the system calls.
* These structures have been developed by using Linux 2.6.23 headers for
* reference. Note though, we do not care about exact API compatibility
* with the kernel, and in fact the kernel often does not have a single
* API that works across architectures. Instead, we try to mimic the glibc
* API where reasonable, and only guarantee ABI compatibility with the
* kernel headers.
* Most notably, here are a few changes that were made to the structures
* defined by kernel headers:
*
* - we only define structures, but not symbolic names for kernel data
* types. For the latter, we directly use the native C datatype
* (i.e. "unsigned" instead of "mode_t").
* - in a few cases, it is possible to define identical structures for
* both 32bit (e.g. i386) and 64bit (e.g. x86-64) platforms by
* standardizing on the 64bit version of the data types. In particular,
* this means that we use "unsigned" where the 32bit headers say
* "unsigned long".
* - overall, we try to minimize the number of cases where we need to
* conditionally define different structures.
* - the "struct kernel_sigaction" class of structures have been
* modified to more closely mimic glibc's API by introducing an
* anonymous union for the function pointer.
* - a small number of field names had to have an underscore appended to
* them, because glibc defines a global macro by the same name.
*/
/* include/linux/dirent.h */
struct kernel_dirent64 {
unsigned long long d_ino;
long long d_off;
unsigned short d_reclen;
unsigned char d_type;
char d_name[256];
};
/* include/linux/dirent.h */
#if defined(__aarch64__)
// aarch64 only defines dirent64, just uses that for dirent too.
#define kernel_dirent kernel_dirent64
#else
struct kernel_dirent {
long d_ino;
long d_off;
unsigned short d_reclen;
char d_name[256];
};
#endif
/* include/linux/uio.h */
struct kernel_iovec {
void *iov_base;
unsigned long iov_len;
};
/* include/linux/socket.h */
struct kernel_msghdr {
void *msg_name;
int msg_namelen;
struct kernel_iovec*msg_iov;
unsigned long msg_iovlen;
void *msg_control;
unsigned long msg_controllen;
unsigned msg_flags;
};
/* include/asm-generic/poll.h */
struct kernel_pollfd {
int fd;
short events;
short revents;
};
/* include/linux/resource.h */
struct kernel_rlimit {
unsigned long rlim_cur;
unsigned long rlim_max;
};
/* include/linux/time.h */
struct kernel_timespec {
long tv_sec;
long tv_nsec;
};
/* include/linux/time.h */
struct kernel_timeval {
long tv_sec;
long tv_usec;
};
/* include/linux/resource.h */
struct kernel_rusage {
struct kernel_timeval ru_utime;
struct kernel_timeval ru_stime;
long ru_maxrss;
long ru_ixrss;
long ru_idrss;
long ru_isrss;
long ru_minflt;
long ru_majflt;
long ru_nswap;
long ru_inblock;
long ru_oublock;
long ru_msgsnd;
long ru_msgrcv;
long ru_nsignals;
long ru_nvcsw;
long ru_nivcsw;
};
#if defined(__i386__) || defined(__ARM_EABI__) || defined(__ARM_ARCH_3__) \
|| defined(__PPC__) || (defined(__s390__) && !defined(__s390x__))
/* include/asm-{arm,i386,mips,ppc}/signal.h */
struct kernel_old_sigaction {
union {
void (*sa_handler_)(int);
void (*sa_sigaction_)(int, siginfo_t *, void *);
};
unsigned long sa_mask;
unsigned long sa_flags;
void (*sa_restorer)(void);
} __attribute__((packed,aligned(4)));
#elif (defined(__mips__) && _MIPS_SIM == _MIPS_SIM_ABI32)
#define kernel_old_sigaction kernel_sigaction
#elif defined(__aarch64__)
// No kernel_old_sigaction defined for arm64.
#endif
/* Some kernel functions (e.g. sigaction() in 2.6.23) require that the
* exactly match the size of the signal set, even though the API was
* intended to be extensible. We define our own KERNEL_NSIG to deal with
* this.
* Please note that glibc provides signals [1.._NSIG-1], whereas the
* kernel (and this header) provides the range [1..KERNEL_NSIG]. The
* actual number of signals is obviously the same, but the constants
* differ by one.
*/
#ifdef __mips__
#define KERNEL_NSIG 128
#else
#define KERNEL_NSIG 64
#endif
/* include/asm-{arm,aarch64,i386,mips,x86_64}/signal.h */
struct kernel_sigset_t {
unsigned long sig[(KERNEL_NSIG + 8*sizeof(unsigned long) - 1)/
(8*sizeof(unsigned long))];
};
/* include/asm-{arm,i386,mips,x86_64,ppc}/signal.h */
struct kernel_sigaction {
#ifdef __mips__
unsigned long sa_flags;
union {
void (*sa_handler_)(int);
void (*sa_sigaction_)(int, siginfo_t *, void *);
};
struct kernel_sigset_t sa_mask;
#else
union {
void (*sa_handler_)(int);
void (*sa_sigaction_)(int, siginfo_t *, void *);
};
unsigned long sa_flags;
void (*sa_restorer)(void);
struct kernel_sigset_t sa_mask;
#endif
};
/* include/linux/socket.h */
struct kernel_sockaddr {
unsigned short sa_family;
char sa_data[14];
};
/* include/asm-{arm,aarch64,i386,mips,ppc,s390}/stat.h */
#ifdef __mips__
#if _MIPS_SIM == _MIPS_SIM_ABI64
struct kernel_stat {
#else
struct kernel_stat64 {
#endif
unsigned st_dev;
unsigned __pad0[3];
unsigned long long st_ino;
unsigned st_mode;
unsigned st_nlink;
unsigned st_uid;
unsigned st_gid;
unsigned st_rdev;
unsigned __pad1[3];
long long st_size;
unsigned st_atime_;
unsigned st_atime_nsec_;
unsigned st_mtime_;
unsigned st_mtime_nsec_;
unsigned st_ctime_;
unsigned st_ctime_nsec_;
unsigned st_blksize;
unsigned __pad2;
unsigned long long st_blocks;
};
#elif defined __PPC__
struct kernel_stat64 {
unsigned long long st_dev;
unsigned long long st_ino;
unsigned st_mode;
unsigned st_nlink;
unsigned st_uid;
unsigned st_gid;
unsigned long long st_rdev;
unsigned short int __pad2;
long long st_size;
long st_blksize;
long long st_blocks;
long st_atime_;
unsigned long st_atime_nsec_;
long st_mtime_;
unsigned long st_mtime_nsec_;
long st_ctime_;
unsigned long st_ctime_nsec_;
unsigned long __unused4;
unsigned long __unused5;
};
#else
struct kernel_stat64 {
unsigned long long st_dev;
unsigned char __pad0[4];
unsigned __st_ino;
unsigned st_mode;
unsigned st_nlink;
unsigned st_uid;
unsigned st_gid;
unsigned long long st_rdev;
unsigned char __pad3[4];
long long st_size;
unsigned st_blksize;
unsigned long long st_blocks;
unsigned st_atime_;
unsigned st_atime_nsec_;
unsigned st_mtime_;
unsigned st_mtime_nsec_;
unsigned st_ctime_;
unsigned st_ctime_nsec_;
unsigned long long st_ino;
};
#endif
/* include/asm-{arm,aarch64,i386,mips,x86_64,ppc,s390}/stat.h */
#if defined(__i386__) || defined(__ARM_ARCH_3__) || defined(__ARM_EABI__)
struct kernel_stat {
/* The kernel headers suggest that st_dev and st_rdev should be 32bit
* quantities encoding 12bit major and 20bit minor numbers in an interleaved
* format. In reality, we do not see useful data in the top bits. So,
* we'll leave the padding in here, until we find a better solution.
*/
unsigned short st_dev;
short pad1;
unsigned st_ino;
unsigned short st_mode;
unsigned short st_nlink;
unsigned short st_uid;
unsigned short st_gid;
unsigned short st_rdev;
short pad2;
unsigned st_size;
unsigned st_blksize;
unsigned st_blocks;
unsigned st_atime_;
unsigned st_atime_nsec_;
unsigned st_mtime_;
unsigned st_mtime_nsec_;
unsigned st_ctime_;
unsigned st_ctime_nsec_;
unsigned __unused4;
unsigned __unused5;
};
#elif defined(__x86_64__)
struct kernel_stat {
uint64_t st_dev;
uint64_t st_ino;
uint64_t st_nlink;
unsigned st_mode;
unsigned st_uid;
unsigned st_gid;
unsigned __pad0;
uint64_t st_rdev;
int64_t st_size;
int64_t st_blksize;
int64_t st_blocks;
uint64_t st_atime_;
uint64_t st_atime_nsec_;
uint64_t st_mtime_;
uint64_t st_mtime_nsec_;
uint64_t st_ctime_;
uint64_t st_ctime_nsec_;
int64_t __unused4[3];
};
#elif defined(__PPC__)
struct kernel_stat {
unsigned st_dev;
unsigned long st_ino; // ino_t
unsigned long st_mode; // mode_t
unsigned short st_nlink; // nlink_t
unsigned st_uid; // uid_t
unsigned st_gid; // gid_t
unsigned st_rdev;
long st_size; // off_t
unsigned long st_blksize;
unsigned long st_blocks;
unsigned long st_atime_;
unsigned long st_atime_nsec_;
unsigned long st_mtime_;
unsigned long st_mtime_nsec_;
unsigned long st_ctime_;
unsigned long st_ctime_nsec_;
unsigned long __unused4;
unsigned long __unused5;
};
#elif (defined(__mips__) && _MIPS_SIM != _MIPS_SIM_ABI64)
struct kernel_stat {
unsigned st_dev;
int st_pad1[3];
unsigned st_ino;
unsigned st_mode;
unsigned st_nlink;
unsigned st_uid;
unsigned st_gid;
unsigned st_rdev;
int st_pad2[2];
long st_size;
int st_pad3;
long st_atime_;
long st_atime_nsec_;
long st_mtime_;
long st_mtime_nsec_;
long st_ctime_;
long st_ctime_nsec_;
int st_blksize;
int st_blocks;
int st_pad4[14];
};
#elif defined(__aarch64__)
struct kernel_stat {
unsigned long st_dev;
unsigned long st_ino;
unsigned int st_mode;
unsigned int st_nlink;
unsigned int st_uid;
unsigned int st_gid;
unsigned long st_rdev;
unsigned long __pad1;
long st_size;
int st_blksize;
int __pad2;
long st_blocks;
long st_atime_;
unsigned long st_atime_nsec_;
long st_mtime_;
unsigned long st_mtime_nsec_;
long st_ctime_;
unsigned long st_ctime_nsec_;
unsigned int __unused4;
unsigned int __unused5;
};
#elif defined(__s390x__)
struct kernel_stat {
unsigned long st_dev;
unsigned long st_ino;
unsigned long st_nlink;
unsigned int st_mode;
unsigned int st_uid;
unsigned int st_gid;
unsigned int __pad1;
unsigned long st_rdev;
unsigned long st_size;
unsigned long st_atime_;
unsigned long st_atime_nsec_;
unsigned long st_mtime_;
unsigned long st_mtime_nsec_;
unsigned long st_ctime_;
unsigned long st_ctime_nsec_;
unsigned long st_blksize;
long st_blocks;
unsigned long __unused[3];
};
#elif defined(__s390__)
struct kernel_stat {
unsigned short st_dev;
unsigned short __pad1;
unsigned long st_ino;
unsigned short st_mode;
unsigned short st_nlink;
unsigned short st_uid;
unsigned short st_gid;
unsigned short st_rdev;
unsigned short __pad2;
unsigned long st_size;
unsigned long st_blksize;
unsigned long st_blocks;
unsigned long st_atime_;
unsigned long st_atime_nsec_;
unsigned long st_mtime_;
unsigned long st_mtime_nsec_;
unsigned long st_ctime_;
unsigned long st_ctime_nsec_;
unsigned long __unused4;
unsigned long __unused5;
};
#endif
/* include/asm-{arm,aarch64,i386,mips,x86_64,ppc,s390}/statfs.h */
#ifdef __mips__
#if _MIPS_SIM != _MIPS_SIM_ABI64
struct kernel_statfs64 {
unsigned long f_type;
unsigned long f_bsize;
unsigned long f_frsize;
unsigned long __pad;
unsigned long long f_blocks;
unsigned long long f_bfree;
unsigned long long f_files;
unsigned long long f_ffree;
unsigned long long f_bavail;
struct { int val[2]; } f_fsid;
unsigned long f_namelen;
unsigned long f_spare[6];
};
#endif
#elif defined(__s390__)
/* See also arch/s390/include/asm/compat.h */
struct kernel_statfs64 {
unsigned int f_type;
unsigned int f_bsize;
unsigned long long f_blocks;
unsigned long long f_bfree;
unsigned long long f_bavail;
unsigned long long f_files;
unsigned long long f_ffree;
struct { int val[2]; } f_fsid;
unsigned int f_namelen;
unsigned int f_frsize;
unsigned int f_flags;
unsigned int f_spare[4];
};
#elif !defined(__x86_64__)
struct kernel_statfs64 {
unsigned long f_type;
unsigned long f_bsize;
unsigned long long f_blocks;
unsigned long long f_bfree;
unsigned long long f_bavail;
unsigned long long f_files;
unsigned long long f_ffree;
struct { int val[2]; } f_fsid;
unsigned long f_namelen;
unsigned long f_frsize;
unsigned long f_spare[5];
};
#endif
/* include/asm-{arm,i386,mips,x86_64,ppc,generic,s390}/statfs.h */
#ifdef __mips__
struct kernel_statfs {
long f_type;
long f_bsize;
long f_frsize;
long f_blocks;
long f_bfree;
long f_files;
long f_ffree;
long f_bavail;
struct { int val[2]; } f_fsid;
long f_namelen;
long f_spare[6];
};
#elif defined(__x86_64__)
struct kernel_statfs {
/* x86_64 actually defines all these fields as signed, whereas all other */
/* platforms define them as unsigned. Leaving them at unsigned should not */
/* cause any problems. Make sure these are 64-bit even on x32. */
uint64_t f_type;
uint64_t f_bsize;
uint64_t f_blocks;
uint64_t f_bfree;
uint64_t f_bavail;
uint64_t f_files;
uint64_t f_ffree;
struct { int val[2]; } f_fsid;
uint64_t f_namelen;
uint64_t f_frsize;
uint64_t f_spare[5];
};
#elif defined(__s390__)
struct kernel_statfs {
unsigned int f_type;
unsigned int f_bsize;
unsigned long f_blocks;
unsigned long f_bfree;
unsigned long f_bavail;
unsigned long f_files;
unsigned long f_ffree;
struct { int val[2]; } f_fsid;
unsigned int f_namelen;
unsigned int f_frsize;
unsigned int f_flags;
unsigned int f_spare[4];
};
#else
struct kernel_statfs {
unsigned long f_type;
unsigned long f_bsize;
unsigned long f_blocks;
unsigned long f_bfree;
unsigned long f_bavail;
unsigned long f_files;
unsigned long f_ffree;
struct { int val[2]; } f_fsid;
unsigned long f_namelen;
unsigned long f_frsize;
unsigned long f_spare[5];
};
#endif
/* Definitions missing from the standard header files */
#ifndef O_DIRECTORY
#if defined(__ARM_ARCH_3__) || defined(__ARM_EABI__) || defined(__aarch64__)
#define O_DIRECTORY 0040000
#else
#define O_DIRECTORY 0200000
#endif
#endif
#ifndef NT_PRXFPREG
#define NT_PRXFPREG 0x46e62b7f
#endif
#ifndef PTRACE_GETFPXREGS
#define PTRACE_GETFPXREGS ((enum __ptrace_request)18)
#endif
#ifndef PR_GET_DUMPABLE
#define PR_GET_DUMPABLE 3
#endif
#ifndef PR_SET_DUMPABLE
#define PR_SET_DUMPABLE 4
#endif
#ifndef PR_GET_SECCOMP
#define PR_GET_SECCOMP 21
#endif
#ifndef PR_SET_SECCOMP
#define PR_SET_SECCOMP 22
#endif
#ifndef AT_FDCWD
#define AT_FDCWD (-100)
#endif
#ifndef AT_SYMLINK_NOFOLLOW
#define AT_SYMLINK_NOFOLLOW 0x100
#endif
#ifndef AT_REMOVEDIR
#define AT_REMOVEDIR 0x200
#endif
#ifndef MREMAP_FIXED
#define MREMAP_FIXED 2
#endif
#ifndef SA_RESTORER
#define SA_RESTORER 0x04000000
#endif
#ifndef CPUCLOCK_PROF
#define CPUCLOCK_PROF 0
#endif
#ifndef CPUCLOCK_VIRT
#define CPUCLOCK_VIRT 1
#endif
#ifndef CPUCLOCK_SCHED
#define CPUCLOCK_SCHED 2
#endif
#ifndef CPUCLOCK_PERTHREAD_MASK
#define CPUCLOCK_PERTHREAD_MASK 4
#endif
#ifndef MAKE_PROCESS_CPUCLOCK
#define MAKE_PROCESS_CPUCLOCK(pid, clock) \
((int)(~(unsigned)(pid) << 3) | (int)(clock))
#endif
#ifndef MAKE_THREAD_CPUCLOCK
#define MAKE_THREAD_CPUCLOCK(tid, clock) \
((int)(~(unsigned)(tid) << 3) | \
(int)((clock) | CPUCLOCK_PERTHREAD_MASK))
#endif
#ifndef FUTEX_WAIT
#define FUTEX_WAIT 0
#endif
#ifndef FUTEX_WAKE
#define FUTEX_WAKE 1
#endif
#ifndef FUTEX_FD
#define FUTEX_FD 2
#endif
#ifndef FUTEX_REQUEUE
#define FUTEX_REQUEUE 3
#endif
#ifndef FUTEX_CMP_REQUEUE
#define FUTEX_CMP_REQUEUE 4
#endif
#ifndef FUTEX_WAKE_OP
#define FUTEX_WAKE_OP 5
#endif
#ifndef FUTEX_LOCK_PI
#define FUTEX_LOCK_PI 6
#endif
#ifndef FUTEX_UNLOCK_PI
#define FUTEX_UNLOCK_PI 7
#endif
#ifndef FUTEX_TRYLOCK_PI
#define FUTEX_TRYLOCK_PI 8
#endif
#ifndef FUTEX_PRIVATE_FLAG
#define FUTEX_PRIVATE_FLAG 128
#endif
#ifndef FUTEX_CMD_MASK
#define FUTEX_CMD_MASK ~FUTEX_PRIVATE_FLAG
#endif
#ifndef FUTEX_WAIT_PRIVATE
#define FUTEX_WAIT_PRIVATE (FUTEX_WAIT | FUTEX_PRIVATE_FLAG)
#endif
#ifndef FUTEX_WAKE_PRIVATE
#define FUTEX_WAKE_PRIVATE (FUTEX_WAKE | FUTEX_PRIVATE_FLAG)
#endif
#ifndef FUTEX_REQUEUE_PRIVATE
#define FUTEX_REQUEUE_PRIVATE (FUTEX_REQUEUE | FUTEX_PRIVATE_FLAG)
#endif
#ifndef FUTEX_CMP_REQUEUE_PRIVATE
#define FUTEX_CMP_REQUEUE_PRIVATE (FUTEX_CMP_REQUEUE | FUTEX_PRIVATE_FLAG)
#endif
#ifndef FUTEX_WAKE_OP_PRIVATE
#define FUTEX_WAKE_OP_PRIVATE (FUTEX_WAKE_OP | FUTEX_PRIVATE_FLAG)
#endif
#ifndef FUTEX_LOCK_PI_PRIVATE
#define FUTEX_LOCK_PI_PRIVATE (FUTEX_LOCK_PI | FUTEX_PRIVATE_FLAG)
#endif
#ifndef FUTEX_UNLOCK_PI_PRIVATE
#define FUTEX_UNLOCK_PI_PRIVATE (FUTEX_UNLOCK_PI | FUTEX_PRIVATE_FLAG)
#endif
#ifndef FUTEX_TRYLOCK_PI_PRIVATE
#define FUTEX_TRYLOCK_PI_PRIVATE (FUTEX_TRYLOCK_PI | FUTEX_PRIVATE_FLAG)
#endif
#if defined(__x86_64__)
#ifndef ARCH_SET_GS
#define ARCH_SET_GS 0x1001
#endif
#ifndef ARCH_GET_GS
#define ARCH_GET_GS 0x1004
#endif
#endif
#if defined(__i386__)
#ifndef __NR_quotactl
#define __NR_quotactl 131
#endif
#ifndef __NR_setresuid
#define __NR_setresuid 164
#define __NR_getresuid 165
#define __NR_setresgid 170
#define __NR_getresgid 171
#endif
#ifndef __NR_rt_sigaction
#define __NR_rt_sigreturn 173
#define __NR_rt_sigaction 174
#define __NR_rt_sigprocmask 175
#define __NR_rt_sigpending 176
#define __NR_rt_sigsuspend 179
#endif
#ifndef __NR_pread64
#define __NR_pread64 180
#endif
#ifndef __NR_pwrite64
#define __NR_pwrite64 181
#endif
#ifndef __NR_ugetrlimit
#define __NR_ugetrlimit 191
#endif
#ifndef __NR_stat64
#define __NR_stat64 195
#endif
#ifndef __NR_fstat64
#define __NR_fstat64 197
#endif
#ifndef __NR_setresuid32
#define __NR_setresuid32 208
#define __NR_getresuid32 209
#define __NR_setresgid32 210
#define __NR_getresgid32 211
#endif
#ifndef __NR_setfsuid32
#define __NR_setfsuid32 215
#define __NR_setfsgid32 216
#endif
#ifndef __NR_getdents64
#define __NR_getdents64 220
#endif
#ifndef __NR_gettid
#define __NR_gettid 224
#endif
#ifndef __NR_readahead
#define __NR_readahead 225
#endif
#ifndef __NR_setxattr
#define __NR_setxattr 226
#endif
#ifndef __NR_lsetxattr
#define __NR_lsetxattr 227
#endif
#ifndef __NR_getxattr
#define __NR_getxattr 229
#endif
#ifndef __NR_lgetxattr
#define __NR_lgetxattr 230
#endif
#ifndef __NR_listxattr
#define __NR_listxattr 232
#endif
#ifndef __NR_llistxattr
#define __NR_llistxattr 233
#endif
#ifndef __NR_tkill
#define __NR_tkill 238
#endif
#ifndef __NR_futex
#define __NR_futex 240
#endif
#ifndef __NR_sched_setaffinity
#define __NR_sched_setaffinity 241
#define __NR_sched_getaffinity 242
#endif
#ifndef __NR_set_tid_address
#define __NR_set_tid_address 258
#endif
#ifndef __NR_clock_gettime
#define __NR_clock_gettime 265
#endif
#ifndef __NR_clock_getres
#define __NR_clock_getres 266
#endif
#ifndef __NR_statfs64
#define __NR_statfs64 268
#endif
#ifndef __NR_fstatfs64
#define __NR_fstatfs64 269
#endif
#ifndef __NR_fadvise64_64
#define __NR_fadvise64_64 272
#endif
#ifndef __NR_ioprio_set
#define __NR_ioprio_set 289
#endif
#ifndef __NR_ioprio_get
#define __NR_ioprio_get 290
#endif
#ifndef __NR_openat
#define __NR_openat 295
#endif
#ifndef __NR_fstatat64
#define __NR_fstatat64 300
#endif
#ifndef __NR_unlinkat
#define __NR_unlinkat 301
#endif
#ifndef __NR_move_pages
#define __NR_move_pages 317
#endif
#ifndef __NR_getcpu
#define __NR_getcpu 318
#endif
#ifndef __NR_fallocate
#define __NR_fallocate 324
#endif
/* End of i386 definitions */
#elif defined(__ARM_ARCH_3__) || defined(__ARM_EABI__)
#ifndef __NR_setresuid
#define __NR_setresuid (__NR_SYSCALL_BASE + 164)
#define __NR_getresuid (__NR_SYSCALL_BASE + 165)
#define __NR_setresgid (__NR_SYSCALL_BASE + 170)
#define __NR_getresgid (__NR_SYSCALL_BASE + 171)
#endif
#ifndef __NR_rt_sigaction
#define __NR_rt_sigreturn (__NR_SYSCALL_BASE + 173)
#define __NR_rt_sigaction (__NR_SYSCALL_BASE + 174)
#define __NR_rt_sigprocmask (__NR_SYSCALL_BASE + 175)
#define __NR_rt_sigpending (__NR_SYSCALL_BASE + 176)
#define __NR_rt_sigsuspend (__NR_SYSCALL_BASE + 179)
#endif
#ifndef __NR_pread64
#define __NR_pread64 (__NR_SYSCALL_BASE + 180)
#endif
#ifndef __NR_pwrite64
#define __NR_pwrite64 (__NR_SYSCALL_BASE + 181)
#endif
#ifndef __NR_ugetrlimit
#define __NR_ugetrlimit (__NR_SYSCALL_BASE + 191)
#endif
#ifndef __NR_stat64
#define __NR_stat64 (__NR_SYSCALL_BASE + 195)
#endif
#ifndef __NR_fstat64
#define __NR_fstat64 (__NR_SYSCALL_BASE + 197)
#endif
#ifndef __NR_setresuid32
#define __NR_setresuid32 (__NR_SYSCALL_BASE + 208)
#define __NR_getresuid32 (__NR_SYSCALL_BASE + 209)
#define __NR_setresgid32 (__NR_SYSCALL_BASE + 210)
#define __NR_getresgid32 (__NR_SYSCALL_BASE + 211)
#endif
#ifndef __NR_setfsuid32
#define __NR_setfsuid32 (__NR_SYSCALL_BASE + 215)
#define __NR_setfsgid32 (__NR_SYSCALL_BASE + 216)
#endif
#ifndef __NR_getdents64
#define __NR_getdents64 (__NR_SYSCALL_BASE + 217)
#endif
#ifndef __NR_gettid
#define __NR_gettid (__NR_SYSCALL_BASE + 224)
#endif
#ifndef __NR_readahead
#define __NR_readahead (__NR_SYSCALL_BASE + 225)
#endif
#ifndef __NR_setxattr
#define __NR_setxattr (__NR_SYSCALL_BASE + 226)
#endif
#ifndef __NR_lsetxattr
#define __NR_lsetxattr (__NR_SYSCALL_BASE + 227)
#endif
#ifndef __NR_getxattr
#define __NR_getxattr (__NR_SYSCALL_BASE + 229)
#endif
#ifndef __NR_lgetxattr
#define __NR_lgetxattr (__NR_SYSCALL_BASE + 230)
#endif
#ifndef __NR_listxattr
#define __NR_listxattr (__NR_SYSCALL_BASE + 232)
#endif
#ifndef __NR_llistxattr
#define __NR_llistxattr (__NR_SYSCALL_BASE + 233)
#endif
#ifndef __NR_tkill
#define __NR_tkill (__NR_SYSCALL_BASE + 238)
#endif
#ifndef __NR_futex
#define __NR_futex (__NR_SYSCALL_BASE + 240)
#endif
#ifndef __NR_sched_setaffinity