summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeniy Stepanov <eugeni.stepanov@gmail.com>2013-07-30 13:04:43 +0000
committerEvgeniy Stepanov <eugeni.stepanov@gmail.com>2013-07-30 13:04:43 +0000
commit9d34659cd3570423fb1fa49248887e2bd4b762f9 (patch)
tree91bdcf06b6b0edabf9ea58ae00d9627cfb51e87e
parent6567092b06b37195cd93d57204bcbfe6843b2a48 (diff)
downloadcompiler-rt-9d34659cd3570423fb1fa49248887e2bd4b762f9.tar.gz
compiler-rt-9d34659cd3570423fb1fa49248887e2bd4b762f9.tar.bz2
compiler-rt-9d34659cd3570423fb1fa49248887e2bd4b762f9.tar.xz
[sanitizer] read() syscall hook.
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@187414 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/sanitizer/linux_syscall_hooks.h4
-rw-r--r--lib/msan/lit_tests/Linux/syscalls.cc5
-rw-r--r--lib/sanitizer_common/sanitizer_common_syscalls.inc9
3 files changed, 16 insertions, 2 deletions
diff --git a/include/sanitizer/linux_syscall_hooks.h b/include/sanitizer/linux_syscall_hooks.h
index ef8bf72b..710e6893 100644
--- a/include/sanitizer/linux_syscall_hooks.h
+++ b/include/sanitizer/linux_syscall_hooks.h
@@ -33,6 +33,7 @@ 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_pre_read(unsigned int fd, char *buf, size_t count);
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);
@@ -46,6 +47,7 @@ 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);
+void __sanitizer_syscall_post_read(long res, unsigned int fd, char *buf, size_t count);
// And now a few syscalls we don't handle yet.
@@ -268,7 +270,6 @@ void __sanitizer_syscall_post_clock_getres(long res, int clk_id, void *tp);
#define __sanitizer_syscall_pre_pwritev(...)
#define __sanitizer_syscall_pre_query_module(...)
#define __sanitizer_syscall_pre_quotactl(...)
-#define __sanitizer_syscall_pre_read(...)
#define __sanitizer_syscall_pre_readahead(...)
#define __sanitizer_syscall_pre_readdir(...)
#define __sanitizer_syscall_pre_readlink(...)
@@ -645,7 +646,6 @@ void __sanitizer_syscall_post_clock_getres(long res, int clk_id, void *tp);
#define __sanitizer_syscall_post_readdir(res, ...)
#define __sanitizer_syscall_post_readlinkat(res, ...)
#define __sanitizer_syscall_post_readlink(res, ...)
-#define __sanitizer_syscall_post_read(res, ...)
#define __sanitizer_syscall_post_readv(res, ...)
#define __sanitizer_syscall_post_reboot(res, ...)
#define __sanitizer_syscall_post_recvfrom(res, ...)
diff --git a/lib/msan/lit_tests/Linux/syscalls.cc b/lib/msan/lit_tests/Linux/syscalls.cc
index c716cfa2..afab18db 100644
--- a/lib/msan/lit_tests/Linux/syscalls.cc
+++ b/lib/msan/lit_tests/Linux/syscalls.cc
@@ -59,5 +59,10 @@ int main(int argc, char *argv[]) {
__msan_poison(buf, sizeof(buf));
__sanitizer_syscall_post_clock_gettime(-1, 0, buf);
assert(__msan_test_shadow(buf, sizeof(buf)) == 0);
+
+ __msan_poison(buf, sizeof(buf));
+ __sanitizer_syscall_post_read(5, 42, buf, 10);
+ assert(__msan_test_shadow(buf, sizeof(buf)) == 5);
+
return 0;
}
diff --git a/lib/sanitizer_common/sanitizer_common_syscalls.inc b/lib/sanitizer_common/sanitizer_common_syscalls.inc
index 5a8b13fe..5f4b24c0 100644
--- a/lib/sanitizer_common/sanitizer_common_syscalls.inc
+++ b/lib/sanitizer_common/sanitizer_common_syscalls.inc
@@ -161,6 +161,15 @@ POST_SYSCALL(clock_getres)(long res, int clk_id,
struct sanitizer_kernel_timespec *tp) {
if (res == 0 && tp) POST_WRITE(tp, sizeof(*tp));
}
+
+PRE_SYSCALL(read)(unsigned int fd, char *buf, uptr count) {
+ if (buf) PRE_WRITE(buf, count);
+}
+
+POST_SYSCALL(read)(long res, unsigned int fd, char *buf, uptr count) {
+ if (res > 0 && buf) POST_WRITE(buf, res);
+}
+
} // extern "C"
#undef PRE_SYSCALL