[sanitizer] Change the way we use certain linux kernel headers.

Some linux headers are broken on older kernels.
Instead of depending on the constants and types from such headers directly,
we provide our own definitions and then verify them with compile-time
assertions. This makes the dependency on the headers test-only and would allow
switching to some other way of testing on older kernels, or even disable the
tests as the last resort (after all, kernel interfaces are supposed to be
stable).

llvm-svn: 195427
This commit is contained in:
Evgeniy Stepanov 2013-11-22 09:01:50 +00:00
parent f798172419
commit 39cc337e20
3 changed files with 26 additions and 20 deletions

View File

@ -40,24 +40,24 @@
#endif
namespace __sanitizer {
unsigned struct___old_kernel_stat_sz = sizeof(struct __old_kernel_stat);
unsigned struct_kernel_stat_sz = sizeof(struct stat);
unsigned struct_io_event_sz = sizeof(struct io_event);
unsigned struct_statfs64_sz = sizeof(struct statfs64);
} // namespace __sanitizer
unsigned iocb_cmd_pread = IOCB_CMD_PREAD;
unsigned iocb_cmd_pwrite = IOCB_CMD_PWRITE;
COMPILER_CHECK(struct___old_kernel_stat_sz == sizeof(struct __old_kernel_stat));
COMPILER_CHECK(struct_kernel_stat_sz == sizeof(struct stat));
#if !defined(_LP64) && !defined(__x86_64__)
unsigned struct_kernel_stat64_sz = sizeof(struct stat64);
#else
unsigned struct_kernel_stat64_sz = 0;
#if defined(__i386__)
COMPILER_CHECK(struct_kernel_stat64_sz == sizeof(struct stat64));
#endif
COMPILER_CHECK(struct_io_event_sz == sizeof(struct io_event));
#if !SANITIZER_ANDROID
unsigned struct_perf_event_attr_sz = sizeof(struct perf_event_attr);
COMPILER_CHECK(struct_perf_event_attr_sz == sizeof(struct perf_event_attr));
#endif
} // namespace __sanitizer
COMPILER_CHECK(iocb_cmd_pread == IOCB_CMD_PREAD);
COMPILER_CHECK(iocb_cmd_pwrite == IOCB_CMD_PWRITE);
CHECK_TYPE_SIZE(iocb);
CHECK_SIZE_AND_OFFSET(iocb, aio_data);

View File

@ -108,7 +108,6 @@
#include <link.h>
#include <sys/vfs.h>
#include <sys/epoll.h>
// #include <asm/stat.h>
#include <linux/capability.h>
#endif // SANITIZER_LINUX

View File

@ -48,17 +48,25 @@ namespace __sanitizer {
#endif // !SANITIZER_ANDROID
#if SANITIZER_LINUX
extern unsigned struct___old_kernel_stat_sz;
extern unsigned struct_kernel_stat_sz;
extern unsigned struct_kernel_stat64_sz;
extern unsigned struct_io_event_sz;
#if defined(__x86_64__)
const unsigned struct___old_kernel_stat_sz = 32;
const unsigned struct_kernel_stat_sz = 144;
const unsigned struct_kernel_stat64_sz = 0;
#elif defined(__i386__)
const unsigned struct___old_kernel_stat_sz = 32;
const unsigned struct_kernel_stat_sz = 64;
const unsigned struct_kernel_stat64_sz = 96;
#endif
const unsigned struct_io_event_sz = 32;
const unsigned struct_perf_event_attr_sz = 72;
extern unsigned struct_utimbuf_sz;
extern unsigned struct_new_utsname_sz;
extern unsigned struct_old_utsname_sz;
extern unsigned struct_oldold_utsname_sz;
extern unsigned struct_msqid_ds_sz;
extern unsigned struct_mq_attr_sz;
extern unsigned struct_perf_event_attr_sz;
extern unsigned struct_timex_sz;
extern unsigned struct_ustat_sz;
@ -85,8 +93,8 @@ namespace __sanitizer {
u64 aio_reserved3;
};
extern unsigned iocb_cmd_pread;
extern unsigned iocb_cmd_pwrite;
const unsigned iocb_cmd_pread = 0;
const unsigned iocb_cmd_pwrite = 1;
struct __sanitizer___sysctl_args {
int *name;
@ -942,4 +950,3 @@ namespace __sanitizer {
offsetof(struct CLASS, MEMBER))
#endif