1 //===-- sanitizer_platform_limits_linux.cc --------------------------------===//
3 // This file is distributed under the University of Illinois Open Source
4 // License. See LICENSE.TXT for details.
6 //===----------------------------------------------------------------------===//
8 // This file is a part of Sanitizer common code.
10 // Sizes and layouts of linux kernel data structures.
11 //===----------------------------------------------------------------------===//
13 // This is a separate compilation unit for linux headers that conflict with
15 // Most "normal" includes go in sanitizer_platform_limits_posix.cc
17 #include "sanitizer_platform.h"
20 #include "sanitizer_internal_defs.h"
21 #include "sanitizer_platform_limits_posix.h"
23 // For offsetof -> __builtin_offsetof definition.
26 // With old kernels (and even new kernels on powerpc) asm/stat.h uses types that
27 // are not defined anywhere in userspace headers. Fake them. This seems to work
28 // fine with newer headers, too.
29 #include <linux/posix_types.h>
30 #if defined(__x86_64__) || defined(__mips__)
33 #define ino_t __kernel_ino_t
34 #define mode_t __kernel_mode_t
35 #define nlink_t __kernel_nlink_t
36 #define uid_t __kernel_uid_t
37 #define gid_t __kernel_gid_t
38 #define off_t __kernel_off_t
39 #define time_t __kernel_time_t
40 // This header seems to contain the definitions of _kernel_ stat* structs.
50 #include <linux/aio_abi.h>
52 #if !SANITIZER_ANDROID
53 #include <sys/statfs.h>
54 #include <linux/perf_event.h>
57 using namespace __sanitizer
;
59 namespace __sanitizer
{
60 #if !SANITIZER_ANDROID
61 unsigned struct_statfs64_sz
= sizeof(struct statfs64
);
63 } // namespace __sanitizer
65 #if !defined(__powerpc64__) && !defined(__x86_64__) && !defined(__aarch64__)\
66 && !defined(__mips__) && !defined(__s390__)\
67 && !defined(__sparc__)
68 COMPILER_CHECK(struct___old_kernel_stat_sz
== sizeof(struct __old_kernel_stat
));
71 COMPILER_CHECK(struct_kernel_stat_sz
== sizeof(struct stat
));
74 COMPILER_CHECK(struct_kernel_stat64_sz
== sizeof(struct stat64
));
77 CHECK_TYPE_SIZE(io_event
);
78 CHECK_SIZE_AND_OFFSET(io_event
, data
);
79 CHECK_SIZE_AND_OFFSET(io_event
, obj
);
80 CHECK_SIZE_AND_OFFSET(io_event
, res
);
81 CHECK_SIZE_AND_OFFSET(io_event
, res2
);
83 #if !SANITIZER_ANDROID
84 COMPILER_CHECK(sizeof(struct __sanitizer_perf_event_attr
) <=
85 sizeof(struct perf_event_attr
));
86 CHECK_SIZE_AND_OFFSET(perf_event_attr
, type
);
87 CHECK_SIZE_AND_OFFSET(perf_event_attr
, size
);
90 COMPILER_CHECK(iocb_cmd_pread
== IOCB_CMD_PREAD
);
91 COMPILER_CHECK(iocb_cmd_pwrite
== IOCB_CMD_PWRITE
);
92 #if !SANITIZER_ANDROID
93 COMPILER_CHECK(iocb_cmd_preadv
== IOCB_CMD_PREADV
);
94 COMPILER_CHECK(iocb_cmd_pwritev
== IOCB_CMD_PWRITEV
);
97 CHECK_TYPE_SIZE(iocb
);
98 CHECK_SIZE_AND_OFFSET(iocb
, aio_data
);
99 // Skip aio_key, it's weird.
100 CHECK_SIZE_AND_OFFSET(iocb
, aio_lio_opcode
);
101 CHECK_SIZE_AND_OFFSET(iocb
, aio_reqprio
);
102 CHECK_SIZE_AND_OFFSET(iocb
, aio_fildes
);
103 CHECK_SIZE_AND_OFFSET(iocb
, aio_buf
);
104 CHECK_SIZE_AND_OFFSET(iocb
, aio_nbytes
);
105 CHECK_SIZE_AND_OFFSET(iocb
, aio_offset
);
107 #endif // SANITIZER_LINUX