]> git.ipfire.org Git - thirdparty/gcc.git/blame - libsanitizer/sanitizer_common/sanitizer_platform_limits_linux.cpp
libsanitizer: merge from master (75f9e83ace52773af65dcebca543005ec8a2705d).
[thirdparty/gcc.git] / libsanitizer / sanitizer_common / sanitizer_platform_limits_linux.cpp
CommitLineData
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
8996894d 29// fine with newer headers, too.
10189819 30#include <linux/posix_types.h>
76288e1c
L
31# if defined(__x86_64__) || defined(__mips__) || defined(__hexagon__)
32# include <sys/stat.h>
33# else
34# define ino_t __kernel_ino_t
35# define mode_t __kernel_mode_t
36# define nlink_t __kernel_nlink_t
37# define uid_t __kernel_uid_t
38# define gid_t __kernel_gid_t
39# define off_t __kernel_off_t
40# define time_t __kernel_time_t
ef1b3fda 41// This header seems to contain the definitions of _kernel_ stat* structs.
76288e1c
L
42# include <asm/stat.h>
43# undef ino_t
44# undef mode_t
45# undef nlink_t
46# undef uid_t
47# undef gid_t
48# undef off_t
49# endif
df77f0e4 50
76288e1c 51# include <linux/aio_abi.h>
ef1b3fda 52
76288e1c
L
53# if !SANITIZER_ANDROID
54# include <sys/statfs.h>
55# include <linux/perf_event.h>
56# endif
ef1b3fda 57
10189819
MO
58using namespace __sanitizer;
59
ef1b3fda 60namespace __sanitizer {
866e32ad 61#if !SANITIZER_ANDROID
df77f0e4 62 unsigned struct_statfs64_sz = sizeof(struct statfs64);
866e32ad 63#endif
df77f0e4 64} // namespace __sanitizer
ef1b3fda 65
76288e1c
L
66# if !defined(__powerpc64__) && !defined(__x86_64__) && \
67 !defined(__aarch64__) && !defined(__mips__) && !defined(__s390__) && \
68 !defined(__sparc__) && !defined(__riscv) && !defined(__hexagon__)
df77f0e4
KS
69COMPILER_CHECK(struct___old_kernel_stat_sz == sizeof(struct __old_kernel_stat));
70#endif
71
72COMPILER_CHECK(struct_kernel_stat_sz == sizeof(struct stat));
73
74#if defined(__i386__)
75COMPILER_CHECK(struct_kernel_stat64_sz == sizeof(struct stat64));
ef1b3fda
KS
76#endif
77
df77f0e4
KS
78CHECK_TYPE_SIZE(io_event);
79CHECK_SIZE_AND_OFFSET(io_event, data);
80CHECK_SIZE_AND_OFFSET(io_event, obj);
81CHECK_SIZE_AND_OFFSET(io_event, res);
82CHECK_SIZE_AND_OFFSET(io_event, res2);
83
ef1b3fda 84#if !SANITIZER_ANDROID
df77f0e4
KS
85COMPILER_CHECK(sizeof(struct __sanitizer_perf_event_attr) <=
86 sizeof(struct perf_event_attr));
87CHECK_SIZE_AND_OFFSET(perf_event_attr, type);
88CHECK_SIZE_AND_OFFSET(perf_event_attr, size);
ef1b3fda 89#endif
ef1b3fda 90
df77f0e4
KS
91COMPILER_CHECK(iocb_cmd_pread == IOCB_CMD_PREAD);
92COMPILER_CHECK(iocb_cmd_pwrite == IOCB_CMD_PWRITE);
93#if !SANITIZER_ANDROID
94COMPILER_CHECK(iocb_cmd_preadv == IOCB_CMD_PREADV);
95COMPILER_CHECK(iocb_cmd_pwritev == IOCB_CMD_PWRITEV);
d00106f4 96#endif
df77f0e4
KS
97
98CHECK_TYPE_SIZE(iocb);
99CHECK_SIZE_AND_OFFSET(iocb, aio_data);
100// Skip aio_key, it's weird.
101CHECK_SIZE_AND_OFFSET(iocb, aio_lio_opcode);
102CHECK_SIZE_AND_OFFSET(iocb, aio_reqprio);
103CHECK_SIZE_AND_OFFSET(iocb, aio_fildes);
104CHECK_SIZE_AND_OFFSET(iocb, aio_buf);
105CHECK_SIZE_AND_OFFSET(iocb, aio_nbytes);
106CHECK_SIZE_AND_OFFSET(iocb, aio_offset);
107
108#endif // SANITIZER_LINUX