Daily bump.
[official-gcc.git] / libsanitizer / sanitizer_common / sanitizer_platform_limits_linux.cpp
blobc278c8797f7555aeaedc9ca5192c4adb1a4fd32b
1 //===-- sanitizer_platform_limits_linux.cpp -------------------------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file is a part of Sanitizer common code.
11 // Sizes and layouts of linux kernel data structures.
12 //===----------------------------------------------------------------------===//
14 // This is a separate compilation unit for linux headers that conflict with
15 // userspace headers.
16 // Most "normal" includes go in sanitizer_platform_limits_posix.cpp
18 #include "sanitizer_platform.h"
19 #if SANITIZER_LINUX
21 #include "sanitizer_internal_defs.h"
22 #include "sanitizer_platform_limits_posix.h"
24 // For offsetof -> __builtin_offsetof definition.
25 #include <stddef.h>
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
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.
33 #include <linux/posix_types.h>
34 # if defined(__x86_64__) || defined(__mips__) || defined(__hexagon__)
35 # include <sys/stat.h>
36 # else
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
43 # define time_t __kernel_time_t
44 // This header seems to contain the definitions of _kernel_ stat* structs.
45 # include <asm/stat.h>
46 # undef ino_t
47 # undef mode_t
48 # undef nlink_t
49 # undef uid_t
50 # undef gid_t
51 # undef off_t
52 # endif
54 # include <linux/aio_abi.h>
56 # if !SANITIZER_ANDROID
57 # include <sys/statfs.h>
58 # include <linux/perf_event.h>
59 # endif
61 using namespace __sanitizer;
63 # if !defined(__powerpc64__) && !defined(__x86_64__) && \
64 !defined(__aarch64__) && !defined(__mips__) && !defined(__s390__) && \
65 !defined(__sparc__) && !defined(__riscv) && !defined(__hexagon__) && \
66 !defined(__loongarch__)
67 COMPILER_CHECK(struct___old_kernel_stat_sz == sizeof(struct __old_kernel_stat));
68 #endif
70 COMPILER_CHECK(struct_kernel_stat_sz == sizeof(struct stat));
72 #if defined(__i386__)
73 COMPILER_CHECK(struct_kernel_stat64_sz == sizeof(struct stat64));
74 #endif
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);
87 #endif
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);
94 #endif
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