[compiler-rt] r185913 - [sanitizer] Syscall handlers for clock_gettime and clock_getres.
Evgeniy Stepanov
eugeni.stepanov at gmail.com
Tue Jul 9 01:55:00 PDT 2013
Author: eugenis
Date: Tue Jul 9 03:54:59 2013
New Revision: 185913
URL: http://llvm.org/viewvc/llvm-project?rev=185913&view=rev
Log:
[sanitizer] Syscall handlers for clock_gettime and clock_getres.
Modified:
compiler-rt/trunk/include/sanitizer/linux_syscall_hooks.h
compiler-rt/trunk/lib/msan/lit_tests/Linux/syscalls.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_syscalls.inc
Modified: compiler-rt/trunk/include/sanitizer/linux_syscall_hooks.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/include/sanitizer/linux_syscall_hooks.h?rev=185913&r1=185912&r2=185913&view=diff
==============================================================================
--- compiler-rt/trunk/include/sanitizer/linux_syscall_hooks.h (original)
+++ compiler-rt/trunk/include/sanitizer/linux_syscall_hooks.h Tue Jul 9 03:54:59 2013
@@ -31,6 +31,8 @@ void __sanitizer_syscall_pre_getdents64(
void __sanitizer_syscall_pre_recvmsg(int sockfd, void *msg, int flags);
void __sanitizer_syscall_pre_wait4(int pid, int *status, int options, void *r);
void __sanitizer_syscall_pre_waitpid(int pid, int *status, int options);
+void __sanitizer_syscall_pre_clock_gettime(int clk_id, void *tp);
+void __sanitizer_syscall_pre_clock_getres(int clk_id, void *tp);
void __sanitizer_syscall_post_rt_sigpending(long res, void *p, size_t s);
void __sanitizer_syscall_post_getdents(long res, int fd, void *dirp, int count);
@@ -42,6 +44,8 @@ void __sanitizer_syscall_post_wait4(long
void *r);
void __sanitizer_syscall_post_waitpid(long res, int pid, int *status,
int options);
+void __sanitizer_syscall_post_clock_gettime(long res, int clk_id, void *tp);
+void __sanitizer_syscall_post_clock_getres(long res, int clk_id, void *tp);
// And now a few syscalls we don't handle yet.
@@ -66,8 +70,6 @@ void __sanitizer_syscall_post_waitpid(lo
#define __sanitizer_syscall_pre_chown32(...)
#define __sanitizer_syscall_pre_chroot(...)
#define __sanitizer_syscall_pre_clock_adjtime(...)
-#define __sanitizer_syscall_pre_clock_getres(...)
-#define __sanitizer_syscall_pre_clock_gettime(...)
#define __sanitizer_syscall_pre_clock_nanosleep(...)
#define __sanitizer_syscall_pre_clock_settime(...)
#define __sanitizer_syscall_pre_clone(...)
@@ -441,8 +443,6 @@ void __sanitizer_syscall_post_waitpid(lo
#define __sanitizer_syscall_post_chown(res, ...)
#define __sanitizer_syscall_post_chroot(res, ...)
#define __sanitizer_syscall_post_clock_adjtime(res, ...)
-#define __sanitizer_syscall_post_clock_getres(res, ...)
-#define __sanitizer_syscall_post_clock_gettime(res, ...)
#define __sanitizer_syscall_post_clock_nanosleep(res, ...)
#define __sanitizer_syscall_post_clock_settime(res, ...)
#define __sanitizer_syscall_post_clone(res, ...)
Modified: compiler-rt/trunk/lib/msan/lit_tests/Linux/syscalls.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/lit_tests/Linux/syscalls.cc?rev=185913&r1=185912&r2=185913&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/lit_tests/Linux/syscalls.cc (original)
+++ compiler-rt/trunk/lib/msan/lit_tests/Linux/syscalls.cc Tue Jul 9 03:54:59 2013
@@ -46,5 +46,18 @@ int main(int argc, char *argv[]) {
__msan_poison(buf, kTen + 1);
__sanitizer_syscall_post_getdents64(kTen, 0, buf, kTen);
assert(__msan_test_shadow(buf, sizeof(buf)) == kTen);
+
+ __msan_poison(buf, sizeof(buf));
+ __sanitizer_syscall_post_clock_getres(0, 0, buf);
+ assert(__msan_test_shadow(buf, sizeof(buf)) == sizeof(long) * 2);
+
+ __msan_poison(buf, sizeof(buf));
+ __sanitizer_syscall_post_clock_gettime(0, 0, buf);
+ assert(__msan_test_shadow(buf, sizeof(buf)) == sizeof(long) * 2);
+
+ // Failed syscall does not write to the buffer.
+ __msan_poison(buf, sizeof(buf));
+ __sanitizer_syscall_post_clock_gettime(-1, 0, buf);
+ assert(__msan_test_shadow(buf, sizeof(buf)) == 0);
return 0;
}
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_syscalls.inc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_syscalls.inc?rev=185913&r1=185912&r2=185913&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_syscalls.inc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_syscalls.inc Tue Jul 9 03:54:59 2013
@@ -55,6 +55,11 @@ struct sanitizer_kernel_msghdr {
unsigned msg_flags;
};
+struct sanitizer_kernel_timespec {
+ long tv_sec;
+ long tv_nsec;
+};
+
struct sanitizer_kernel_timeval {
long tv_sec;
long tv_usec;
@@ -138,6 +143,23 @@ POST_SYSCALL(waitpid)(long res, int pid,
POST_WRITE(status, sizeof(*status));
}
}
+
+PRE_SYSCALL(clock_gettime)(int clk_id, struct sanitizer_kernel_timespec *tp) {
+ if (tp) PRE_WRITE(tp, sizeof(*tp));
+}
+
+POST_SYSCALL(clock_gettime)(long res, int clk_id, struct sanitizer_kernel_timespec *tp) {
+ if (res == 0 && tp) POST_WRITE(tp, sizeof(*tp));
+}
+
+PRE_SYSCALL(clock_getres)(int clk_id, struct sanitizer_kernel_timespec *tp) {
+ if (tp) PRE_WRITE(tp, sizeof(*tp));
+}
+
+POST_SYSCALL(clock_getres)(long res, int clk_id, struct sanitizer_kernel_timespec *tp) {
+ if (res == 0 && tp) POST_WRITE(tp, sizeof(*tp));
+}
+
} // extern "C"
#undef PRE_SYSCALL
More information about the llvm-commits
mailing list