[tsan] add write_range/read_range hooks to common interceptors called from tsan (to find races on read/pread/etc)

llvm-svn: 172714
This commit is contained in:
Kostya Serebryany 2013-01-17 13:18:40 +00:00
parent 93ebdb5d64
commit 125e26d49b
2 changed files with 36 additions and 2 deletions

View File

@ -0,0 +1,32 @@
// RUN: %clangxx_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s
#include <pthread.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int fd;
char buf;
void *Thread(void *x) {
read(fd, &buf, 1);
return NULL;
}
int main() {
fd = open("/dev/random", O_RDONLY);
if (fd < 0) return 1;
pthread_t t[2];
pthread_create(&t[0], NULL, Thread, NULL);
pthread_create(&t[1], NULL, Thread, NULL);
pthread_join(t[0], NULL);
pthread_join(t[1], NULL);
close(fd);
}
// CHECK: WARNING: ThreadSanitizer: data race
// CHECK: Write of size 1
// CHECK: #0 read
// CHECK: Previous write of size 1
// CHECK: #0 read

View File

@ -1618,8 +1618,10 @@ TSAN_INTERCEPTOR(int, fork, int fake) {
return pid;
}
#define COMMON_INTERCEPTOR_WRITE_RANGE(ptr, size) // FIXME
#define COMMON_INTERCEPTOR_READ_RANGE(ptr, size) // FIXME
#define COMMON_INTERCEPTOR_WRITE_RANGE(ptr, size) \
MemoryAccessRange(thr, pc, (uptr)ptr, size, true)
#define COMMON_INTERCEPTOR_READ_RANGE(ptr, size) \
MemoryAccessRange(thr, pc, (uptr)ptr, size, false)
#define COMMON_INTERCEPTOR_ENTER(func, ...) \
SCOPED_TSAN_INTERCEPTOR(func, __VA_ARGS__)
#define COMMON_INTERCEPTOR_FD_ACQUIRE(fd) FdAcquire(thr, pc, fd)