]>
Commit | Line | Data |
---|---|---|
b667dd70 | 1 | //===-- sanitizer_platform_limits_linux.cpp -------------------------------===// |
ef1b3fda | 2 | // |
b667dd70 ML |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. | |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | |
ef1b3fda KS |
6 | // |
7 | //===----------------------------------------------------------------------===// | |
8 | // | |
9 | // This file is a part of Sanitizer common code. | |
10 | // | |
11 | // Sizes and layouts of linux kernel data structures. | |
12 | //===----------------------------------------------------------------------===// | |
13 | ||
14 | // This is a separate compilation unit for linux headers that conflict with | |
15 | // userspace headers. | |
b667dd70 | 16 | // Most "normal" includes go in sanitizer_platform_limits_posix.cpp |
ef1b3fda KS |
17 | |
18 | #include "sanitizer_platform.h" | |
19 | #if SANITIZER_LINUX | |
20 | ||
df77f0e4 KS |
21 | #include "sanitizer_internal_defs.h" |
22 | #include "sanitizer_platform_limits_posix.h" | |
23 | ||
24 | // For offsetof -> __builtin_offsetof definition. | |
25 | #include <stddef.h> | |
26 | ||
27 | // With old kernels (and even new kernels on powerpc) asm/stat.h uses types that | |
28 | // are not defined anywhere in userspace headers. Fake them. This seems to work | |
f18ab180 ML |
29 | // fine with newer headers, too. Beware that with <sys/stat.h>, struct stat |
30 | // takes the form of struct stat64 on 32-bit platforms if _FILE_OFFSET_BITS=64. | |
31 | // Also, for some platforms (e.g. mips) there are additional members in the | |
32 | // <sys/stat.h> struct stat:s. | |
10189819 | 33 | #include <linux/posix_types.h> |
f18ab180 | 34 | #if defined(__x86_64__) |
7efb96c0 L |
35 | #include <sys/stat.h> |
36 | #else | |
df77f0e4 KS |
37 | #define ino_t __kernel_ino_t |
38 | #define mode_t __kernel_mode_t | |
39 | #define nlink_t __kernel_nlink_t | |
40 | #define uid_t __kernel_uid_t | |
41 | #define gid_t __kernel_gid_t | |
42 | #define off_t __kernel_off_t | |
fe7913f6 | 43 | #define time_t __kernel_time_t |
ef1b3fda KS |
44 | // This header seems to contain the definitions of _kernel_ stat* structs. |
45 | #include <asm/stat.h> | |
df77f0e4 KS |
46 | #undef ino_t |
47 | #undef mode_t | |
48 | #undef nlink_t | |
49 | #undef uid_t | |
50 | #undef gid_t | |
51 | #undef off_t | |
7efb96c0 | 52 | #endif |
df77f0e4 | 53 | |
ef1b3fda KS |
54 | #include <linux/aio_abi.h> |
55 | ||
56 | #if !SANITIZER_ANDROID | |
866e32ad | 57 | #include <sys/statfs.h> |
ef1b3fda KS |
58 | #include <linux/perf_event.h> |
59 | #endif | |
60 | ||
10189819 MO |
61 | using namespace __sanitizer; |
62 | ||
ef1b3fda | 63 | namespace __sanitizer { |
866e32ad | 64 | #if !SANITIZER_ANDROID |
df77f0e4 | 65 | unsigned struct_statfs64_sz = sizeof(struct statfs64); |
866e32ad | 66 | #endif |
df77f0e4 | 67 | } // namespace __sanitizer |
ef1b3fda | 68 | |
866e32ad | 69 | #if !defined(__powerpc64__) && !defined(__x86_64__) && !defined(__aarch64__)\ |
fe7913f6 | 70 | && !defined(__mips__) && !defined(__s390__)\ |
cb7dc4da | 71 | && !defined(__sparc__) && !defined(__riscv) |
df77f0e4 KS |
72 | COMPILER_CHECK(struct___old_kernel_stat_sz == sizeof(struct __old_kernel_stat)); |
73 | #endif | |
74 | ||
75 | COMPILER_CHECK(struct_kernel_stat_sz == sizeof(struct stat)); | |
76 | ||
77 | #if defined(__i386__) | |
78 | COMPILER_CHECK(struct_kernel_stat64_sz == sizeof(struct stat64)); | |
ef1b3fda KS |
79 | #endif |
80 | ||
df77f0e4 KS |
81 | CHECK_TYPE_SIZE(io_event); |
82 | CHECK_SIZE_AND_OFFSET(io_event, data); | |
83 | CHECK_SIZE_AND_OFFSET(io_event, obj); | |
84 | CHECK_SIZE_AND_OFFSET(io_event, res); | |
85 | CHECK_SIZE_AND_OFFSET(io_event, res2); | |
86 | ||
ef1b3fda | 87 | #if !SANITIZER_ANDROID |
df77f0e4 KS |
88 | COMPILER_CHECK(sizeof(struct __sanitizer_perf_event_attr) <= |
89 | sizeof(struct perf_event_attr)); | |
90 | CHECK_SIZE_AND_OFFSET(perf_event_attr, type); | |
91 | CHECK_SIZE_AND_OFFSET(perf_event_attr, size); | |
ef1b3fda | 92 | #endif |
ef1b3fda | 93 | |
df77f0e4 KS |
94 | COMPILER_CHECK(iocb_cmd_pread == IOCB_CMD_PREAD); |
95 | COMPILER_CHECK(iocb_cmd_pwrite == IOCB_CMD_PWRITE); | |
96 | #if !SANITIZER_ANDROID | |
97 | COMPILER_CHECK(iocb_cmd_preadv == IOCB_CMD_PREADV); | |
98 | COMPILER_CHECK(iocb_cmd_pwritev == IOCB_CMD_PWRITEV); | |
d00106f4 | 99 | #endif |
df77f0e4 KS |
100 | |
101 | CHECK_TYPE_SIZE(iocb); | |
102 | CHECK_SIZE_AND_OFFSET(iocb, aio_data); | |
103 | // Skip aio_key, it's weird. | |
104 | CHECK_SIZE_AND_OFFSET(iocb, aio_lio_opcode); | |
105 | CHECK_SIZE_AND_OFFSET(iocb, aio_reqprio); | |
106 | CHECK_SIZE_AND_OFFSET(iocb, aio_fildes); | |
107 | CHECK_SIZE_AND_OFFSET(iocb, aio_buf); | |
108 | CHECK_SIZE_AND_OFFSET(iocb, aio_nbytes); | |
109 | CHECK_SIZE_AND_OFFSET(iocb, aio_offset); | |
110 | ||
111 | #endif // SANITIZER_LINUX |