brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.3 KiB · bf0f355 Raw
104 lines · cpp
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-exception6//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 with15// userspace headers.16// Most "normal" includes go in sanitizer_platform_limits_posix.cpp17 18#include "sanitizer_platform.h"19#if SANITIZER_LINUX20 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 that28// are not defined anywhere in userspace headers. Fake them. This seems to work29// fine with newer headers, too.30#include <linux/posix_types.h>31#  if defined(__x86_64__) || defined(__mips__) || defined(__hexagon__)32#    include <sys/stat.h>33#  else34#    define ino_t __kernel_ino_t35#    define mode_t __kernel_mode_t36#    define nlink_t __kernel_nlink_t37#    define uid_t __kernel_uid_t38#    define gid_t __kernel_gid_t39#    define off_t __kernel_off_t40#    define time_t __kernel_time_t41// This header seems to contain the definitions of _kernel_ stat* structs.42#    include <asm/stat.h>43#    undef ino_t44#    undef mode_t45#    undef nlink_t46#    undef uid_t47#    undef gid_t48#    undef off_t49#  endif50 51#  include <linux/aio_abi.h>52 53#  if !SANITIZER_ANDROID54#    include <sys/statfs.h>55#    include <linux/perf_event.h>56#  endif57 58using namespace __sanitizer;59 60#  if !defined(__powerpc64__) && !defined(__x86_64__) &&                   \61      !defined(__aarch64__) && !defined(__mips__) && !defined(__s390__) && \62      !defined(__sparc__) && !defined(__riscv) && !defined(__hexagon__) && \63      !defined(__loongarch__)64COMPILER_CHECK(struct___old_kernel_stat_sz == sizeof(struct __old_kernel_stat));65#endif66 67COMPILER_CHECK(struct_kernel_stat_sz == sizeof(struct stat));68 69#if defined(__i386__)70COMPILER_CHECK(struct_kernel_stat64_sz == sizeof(struct stat64));71#endif72 73CHECK_TYPE_SIZE(io_event);74CHECK_SIZE_AND_OFFSET(io_event, data);75CHECK_SIZE_AND_OFFSET(io_event, obj);76CHECK_SIZE_AND_OFFSET(io_event, res);77CHECK_SIZE_AND_OFFSET(io_event, res2);78 79#if !SANITIZER_ANDROID80COMPILER_CHECK(sizeof(struct __sanitizer_perf_event_attr) <=81               sizeof(struct perf_event_attr));82CHECK_SIZE_AND_OFFSET(perf_event_attr, type);83CHECK_SIZE_AND_OFFSET(perf_event_attr, size);84#endif85 86COMPILER_CHECK(iocb_cmd_pread == IOCB_CMD_PREAD);87COMPILER_CHECK(iocb_cmd_pwrite == IOCB_CMD_PWRITE);88#if !SANITIZER_ANDROID89COMPILER_CHECK(iocb_cmd_preadv == IOCB_CMD_PREADV);90COMPILER_CHECK(iocb_cmd_pwritev == IOCB_CMD_PWRITEV);91#endif92 93CHECK_TYPE_SIZE(iocb);94CHECK_SIZE_AND_OFFSET(iocb, aio_data);95// Skip aio_key, it's weird.96CHECK_SIZE_AND_OFFSET(iocb, aio_lio_opcode);97CHECK_SIZE_AND_OFFSET(iocb, aio_reqprio);98CHECK_SIZE_AND_OFFSET(iocb, aio_fildes);99CHECK_SIZE_AND_OFFSET(iocb, aio_buf);100CHECK_SIZE_AND_OFFSET(iocb, aio_nbytes);101CHECK_SIZE_AND_OFFSET(iocb, aio_offset);102 103#endif  // SANITIZER_LINUX104