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__)
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>
53 #include <asm/statfs.h>
55 #include <sys/statfs.h>
58 #if !SANITIZER_ANDROID
59 #include <linux/perf_event.h>
62 namespace __sanitizer
{
63 unsigned struct_statfs64_sz
= sizeof(struct statfs64
);
64 } // namespace __sanitizer
66 #if !defined(__powerpc64__) && !defined(__x86_64__) && !defined(__sparc__)
67 COMPILER_CHECK(struct___old_kernel_stat_sz
== sizeof(struct __old_kernel_stat
));
70 COMPILER_CHECK(struct_kernel_stat_sz
== sizeof(struct stat
));
73 COMPILER_CHECK(struct_kernel_stat64_sz
== sizeof(struct stat64
));
76 CHECK_TYPE_SIZE(io_event
);
77 CHECK_SIZE_AND_OFFSET(io_event
, data
);
78 CHECK_SIZE_AND_OFFSET(io_event
, obj
);
79 CHECK_SIZE_AND_OFFSET(io_event
, res
);
80 CHECK_SIZE_AND_OFFSET(io_event
, res2
);
82 #if !SANITIZER_ANDROID
83 COMPILER_CHECK(sizeof(struct __sanitizer_perf_event_attr
) <=
84 sizeof(struct perf_event_attr
));
85 CHECK_SIZE_AND_OFFSET(perf_event_attr
, type
);
86 CHECK_SIZE_AND_OFFSET(perf_event_attr
, size
);
89 COMPILER_CHECK(iocb_cmd_pread
== IOCB_CMD_PREAD
);
90 COMPILER_CHECK(iocb_cmd_pwrite
== IOCB_CMD_PWRITE
);
91 #if !SANITIZER_ANDROID
92 COMPILER_CHECK(iocb_cmd_preadv
== IOCB_CMD_PREADV
);
93 COMPILER_CHECK(iocb_cmd_pwritev
== IOCB_CMD_PWRITEV
);
96 CHECK_TYPE_SIZE(iocb
);
97 CHECK_SIZE_AND_OFFSET(iocb
, aio_data
);
98 // Skip aio_key, it's weird.
99 CHECK_SIZE_AND_OFFSET(iocb
, aio_lio_opcode
);
100 CHECK_SIZE_AND_OFFSET(iocb
, aio_reqprio
);
101 CHECK_SIZE_AND_OFFSET(iocb
, aio_fildes
);
102 CHECK_SIZE_AND_OFFSET(iocb
, aio_buf
);
103 CHECK_SIZE_AND_OFFSET(iocb
, aio_nbytes
);
104 CHECK_SIZE_AND_OFFSET(iocb
, aio_offset
);
106 #endif // SANITIZER_LINUX