1 //===-- sanitizer_platform_limits_linux.cc --------------------------------===// 2 // 3 // This file is distributed under the University of Illinois Open Source 4 // License. See LICENSE.TXT for details. 5 // 6 //===----------------------------------------------------------------------===// 7 // 8 // This file is a part of Sanitizer common code. 9 // 10 // Sizes and layouts of linux kernel data structures. 11 //===----------------------------------------------------------------------===// 12 13 // This is a separate compilation unit for linux headers that conflict with 14 // userspace headers. 15 // Most "normal" includes go in sanitizer_platform_limits_posix.cc 16 17 #include "sanitizer_platform.h" 18 #if SANITIZER_LINUX 19 20 #include "sanitizer_internal_defs.h" 21 #include "sanitizer_platform_limits_posix.h" 22 23 // For offsetof -> __builtin_offsetof definition. 24 #include <stddef.h> 25 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 <linux/posix_types.h> 30 #if defined(__x86_64__) || defined(__mips__) 31 #include <sys/stat.h> 32 #else 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. 41 #include <asm/stat.h> 42 #undef ino_t 43 #undef mode_t 44 #undef nlink_t 45 #undef uid_t 46 #undef gid_t 47 #undef off_t 48 #endif 49 50 #include <linux/aio_abi.h> 51 52 #if !SANITIZER_ANDROID 53 #include <sys/statfs.h> 54 #include <linux/perf_event.h> 55 #endif 56 57 using namespace __sanitizer; 58 59 namespace __sanitizer { 60 #if !SANITIZER_ANDROID 61 unsigned struct_statfs64_sz = sizeof(struct statfs64); 62 #endif 63 } // namespace __sanitizer 64 65 #if !defined(__powerpc64__) && !defined(__x86_64__) && !defined(__aarch64__)\ 66 && !defined(__mips__) && !defined(__s390__)\ 67 && !defined(__sparc__) 68 COMPILER_CHECK(struct___old_kernel_stat_sz == sizeof(struct __old_kernel_stat)); 69 #endif 70 71 COMPILER_CHECK(struct_kernel_stat_sz == sizeof(struct stat)); 72 73 #if defined(__i386__) 74 COMPILER_CHECK(struct_kernel_stat64_sz == sizeof(struct stat64)); 75 #endif 76 77 CHECK_TYPE_SIZE(io_event); 78 CHECK_SIZE_AND_OFFSET(io_event, data); 79 CHECK_SIZE_AND_OFFSET(io_event, obj); 80 CHECK_SIZE_AND_OFFSET(io_event, res); 81 CHECK_SIZE_AND_OFFSET(io_event, res2); 82 83 #if !SANITIZER_ANDROID 84 COMPILER_CHECK(sizeof(struct __sanitizer_perf_event_attr) <= 85 sizeof(struct perf_event_attr)); 86 CHECK_SIZE_AND_OFFSET(perf_event_attr, type); 87 CHECK_SIZE_AND_OFFSET(perf_event_attr, size); 88 #endif 89 90 COMPILER_CHECK(iocb_cmd_pread == IOCB_CMD_PREAD); 91 COMPILER_CHECK(iocb_cmd_pwrite == IOCB_CMD_PWRITE); 92 #if !SANITIZER_ANDROID 93 COMPILER_CHECK(iocb_cmd_preadv == IOCB_CMD_PREADV); 94 COMPILER_CHECK(iocb_cmd_pwritev == IOCB_CMD_PWRITEV); 95 #endif 96 97 CHECK_TYPE_SIZE(iocb); 98 CHECK_SIZE_AND_OFFSET(iocb, aio_data); 99 // Skip aio_key, it's weird. 100 CHECK_SIZE_AND_OFFSET(iocb, aio_lio_opcode); 101 CHECK_SIZE_AND_OFFSET(iocb, aio_reqprio); 102 CHECK_SIZE_AND_OFFSET(iocb, aio_fildes); 103 CHECK_SIZE_AND_OFFSET(iocb, aio_buf); 104 CHECK_SIZE_AND_OFFSET(iocb, aio_nbytes); 105 CHECK_SIZE_AND_OFFSET(iocb, aio_offset); 106 107 #endif // SANITIZER_LINUX 108