summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorEvgeniy Stepanov <eugeni.stepanov@gmail.com>2013-11-22 09:01:50 +0000
committerEvgeniy Stepanov <eugeni.stepanov@gmail.com>2013-11-22 09:01:50 +0000
commit29d306afd9c2cab2eaac1dab237892df327d166f (patch)
treecd3926c49f0dfec5f9b02aceaa81de27f29ba53c /lib
parent233fddf8d0721b5c0a856a92611a6478805d9696 (diff)
[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). git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@195427 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/sanitizer_common/sanitizer_platform_limits_linux.cc22
-rw-r--r--lib/sanitizer_common/sanitizer_platform_limits_posix.cc1
-rw-r--r--lib/sanitizer_common/sanitizer_platform_limits_posix.h23
3 files changed, 26 insertions, 20 deletions
diff --git a/lib/sanitizer_common/sanitizer_platform_limits_linux.cc b/lib/sanitizer_common/sanitizer_platform_limits_linux.cc
index 18147daf8..5331a91db 100644
--- a/lib/sanitizer_common/sanitizer_platform_limits_linux.cc
+++ b/lib/sanitizer_common/sanitizer_platform_limits_linux.cc
@@ -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);
diff --git a/lib/sanitizer_common/sanitizer_platform_limits_posix.cc b/lib/sanitizer_common/sanitizer_platform_limits_posix.cc
index c46d33499..341ee59df 100644
--- a/lib/sanitizer_common/sanitizer_platform_limits_posix.cc
+++ b/lib/sanitizer_common/sanitizer_platform_limits_posix.cc
@@ -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
diff --git a/lib/sanitizer_common/sanitizer_platform_limits_posix.h b/lib/sanitizer_common/sanitizer_platform_limits_posix.h
index cbb652c9f..9df37121e 100644
--- a/lib/sanitizer_common/sanitizer_platform_limits_posix.h
+++ b/lib/sanitizer_common/sanitizer_platform_limits_posix.h
@@ -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
-