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 <asm/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 namespace __sanitizer
{
58 #if !SANITIZER_ANDROID
59 unsigned struct_statfs64_sz
= sizeof(struct statfs64
);
61 } // namespace __sanitizer
63 #if !defined(__powerpc64__) && !defined(__x86_64__) && !defined(__aarch64__)\
64 && !defined(__mips__) && !defined(__sparc__)
65 COMPILER_CHECK(struct___old_kernel_stat_sz
== sizeof(struct __old_kernel_stat
));
68 COMPILER_CHECK(struct_kernel_stat_sz
== sizeof(struct stat
));
71 COMPILER_CHECK(struct_kernel_stat64_sz
== sizeof(struct stat64
));
74 CHECK_TYPE_SIZE(io_event
);
75 CHECK_SIZE_AND_OFFSET(io_event
, data
);
76 CHECK_SIZE_AND_OFFSET(io_event
, obj
);
77 CHECK_SIZE_AND_OFFSET(io_event
, res
);
78 CHECK_SIZE_AND_OFFSET(io_event
, res2
);
80 #if !SANITIZER_ANDROID
81 COMPILER_CHECK(sizeof(struct __sanitizer_perf_event_attr
) <=
82 sizeof(struct perf_event_attr
));
83 CHECK_SIZE_AND_OFFSET(perf_event_attr
, type
);
84 CHECK_SIZE_AND_OFFSET(perf_event_attr
, size
);
87 COMPILER_CHECK(iocb_cmd_pread
== IOCB_CMD_PREAD
);
88 COMPILER_CHECK(iocb_cmd_pwrite
== IOCB_CMD_PWRITE
);
89 #if !SANITIZER_ANDROID
90 COMPILER_CHECK(iocb_cmd_preadv
== IOCB_CMD_PREADV
);
91 COMPILER_CHECK(iocb_cmd_pwritev
== IOCB_CMD_PWRITEV
);
94 CHECK_TYPE_SIZE(iocb
);
95 CHECK_SIZE_AND_OFFSET(iocb
, aio_data
);
96 // Skip aio_key, it's weird.
97 CHECK_SIZE_AND_OFFSET(iocb
, aio_lio_opcode
);
98 CHECK_SIZE_AND_OFFSET(iocb
, aio_reqprio
);
99 CHECK_SIZE_AND_OFFSET(iocb
, aio_fildes
);
100 CHECK_SIZE_AND_OFFSET(iocb
, aio_buf
);
101 CHECK_SIZE_AND_OFFSET(iocb
, aio_nbytes
);
102 CHECK_SIZE_AND_OFFSET(iocb
, aio_offset
);
104 #endif // SANITIZER_LINUX