[msan] Intercept eventfd_read, eventfd_write.

llvm-svn: 273748
This commit is contained in:
Evgeniy Stepanov 2016-06-24 23:32:30 +00:00
parent 83b753d430
commit dd9e03ed87
3 changed files with 49 additions and 0 deletions

View File

@ -5667,6 +5667,35 @@ INTERCEPTOR(SSIZE_T, sendto, int fd, void *buf, SIZE_T len, int flags,
#define INIT_SEND_SENDTO
#endif
#if SANITIZER_INTERCEPT_EVENTFD_READ_WRITE
INTERCEPTOR(int, eventfd_read, int fd, u64 *value) {
void *ctx;
COMMON_INTERCEPTOR_ENTER(ctx, eventfd_read, fd, value);
COMMON_INTERCEPTOR_FD_ACCESS(ctx, fd);
int res = REAL(eventfd_read)(fd, value);
if (res == 0) {
COMMON_INTERCEPTOR_WRITE_RANGE(ctx, value, sizeof(*value));
if (fd >= 0) COMMON_INTERCEPTOR_FD_ACQUIRE(ctx, fd);
}
return res;
}
INTERCEPTOR(int, eventfd_write, int fd, u64 value) {
void *ctx;
COMMON_INTERCEPTOR_ENTER(ctx, eventfd_write, fd, value);
if (fd >= 0) {
COMMON_INTERCEPTOR_FD_ACCESS(ctx, fd);
COMMON_INTERCEPTOR_FD_RELEASE(ctx, fd);
}
int res = REAL(eventfd_write)(fd, value);
return res;
}
#define INIT_EVENTFD_READ_WRITE \
COMMON_INTERCEPT_FUNCTION(eventfd_read); \
COMMON_INTERCEPT_FUNCTION(eventfd_write)
#else
#define INIT_EVENTFD_READ_WRITE
#endif
#if SANITIZER_INTERCEPT_STAT
INTERCEPTOR(int, stat, const char *path, void *buf) {
void *ctx;
@ -5937,6 +5966,7 @@ static void InitializeCommonInterceptors() {
INIT_RECV_RECVFROM;
INIT_SEND_SENDTO;
INIT_STAT;
INIT_EVENTFD_READ_WRITE;
INIT___XSTAT;
INIT___XSTAT64;
INIT___LXSTAT;

View File

@ -310,6 +310,7 @@
#define SANITIZER_INTERCEPTOR_HOOKS SI_LINUX
#define SANITIZER_INTERCEPT_RECV_RECVFROM SI_NOT_WINDOWS
#define SANITIZER_INTERCEPT_SEND_SENDTO SI_NOT_WINDOWS
#define SANITIZER_INTERCEPT_EVENTFD_READ_WRITE SI_LINUX
#define SANITIZER_INTERCEPT_STAT (SI_FREEBSD || SI_MAC || SI_ANDROID)
#define SANITIZER_INTERCEPT___XSTAT !SANITIZER_INTERCEPT_STAT && SI_NOT_WINDOWS

View File

@ -0,0 +1,18 @@
// RUN: %clangxx_msan -O0 %s -o %t && %run %t 2>&1
#include <assert.h>
#include <sys/eventfd.h>
#include <sanitizer/msan_interface.h>
int main(int argc, char *argv[]) {
int efd = eventfd(42, 0);
assert(efd >= 0);
eventfd_t v;
int ret = eventfd_read(efd, &v);
assert(ret == 0);
__msan_check_mem_is_initialized(&v, sizeof(v));
assert(v == 42);
}