[llvm-commits] [compiler-rt] r171967 - in /compiler-rt/trunk/lib/tsan: lit_tests/user_fopen.cc rtl/tsan_interceptors.cc rtl/tsan_mman.cc rtl/tsan_stat.cc rtl/tsan_stat.h
Dmitry Vyukov
dvyukov at google.com
Wed Jan 9 03:54:52 PST 2013
Author: dvyukov
Date: Wed Jan 9 05:54:52 2013
New Revision: 171967
URL: http://llvm.org/viewvc/llvm-project?rev=171967&view=rev
Log:
tsan: fix crash when user defines own fopen/fileno
Modified:
compiler-rt/trunk/lib/tsan/lit_tests/user_fopen.cc
compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc
compiler-rt/trunk/lib/tsan/rtl/tsan_mman.cc
compiler-rt/trunk/lib/tsan/rtl/tsan_stat.cc
compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h
Modified: compiler-rt/trunk/lib/tsan/lit_tests/user_fopen.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/user_fopen.cc?rev=171967&r1=171966&r2=171967&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/lit_tests/user_fopen.cc (original)
+++ compiler-rt/trunk/lib/tsan/lit_tests/user_fopen.cc Wed Jan 9 05:54:52 2013
@@ -17,7 +17,7 @@
static int first = 0;
if (__sync_lock_test_and_set(&first, 1) == 0)
printf("user fileno\n");
- return __interceptor_fileno(f);
+ return 1;
}
int main() {
Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc?rev=171967&r1=171966&r2=171967&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc Wed Jan 9 05:54:52 2013
@@ -55,6 +55,7 @@
extern "C" void _exit(int status);
extern "C" int __cxa_atexit(void (*func)(void *arg), void *arg, void *dso);
extern "C" int *__errno_location();
+extern "C" int fileno_unlocked(void *stream);
const int PTHREAD_MUTEX_RECURSIVE = 1;
const int PTHREAD_MUTEX_RECURSIVE_NP = 1;
const int kPthreadAttrSize = 56;
@@ -1366,17 +1367,12 @@
return res;
}
-TSAN_INTERCEPTOR(int, fileno, void *f) {
- SCOPED_TSAN_INTERCEPTOR(fileno, f);
- return REAL(fileno)(f);
-}
-
TSAN_INTERCEPTOR(void*, fopen, char *path, char *mode) {
SCOPED_TSAN_INTERCEPTOR(fopen, path, mode);
void *res = REAL(fopen)(path, mode);
Acquire(thr, pc, File2addr(path));
if (res) {
- int fd = REAL(fileno)(res);
+ int fd = fileno_unlocked(res);
if (fd >= 0)
FdFileCreate(thr, pc, fd);
}
@@ -1386,14 +1382,14 @@
TSAN_INTERCEPTOR(void*, freopen, char *path, char *mode, void *stream) {
SCOPED_TSAN_INTERCEPTOR(freopen, path, mode, stream);
if (stream) {
- int fd = REAL(fileno)(stream);
+ int fd = fileno_unlocked(stream);
if (fd >= 0)
FdClose(thr, pc, fd);
}
void *res = REAL(freopen)(path, mode, stream);
Acquire(thr, pc, File2addr(path));
if (res) {
- int fd = REAL(fileno)(res);
+ int fd = fileno_unlocked(res);
if (fd >= 0)
FdFileCreate(thr, pc, fd);
}
@@ -1401,25 +1397,30 @@
}
TSAN_INTERCEPTOR(int, fclose, void *stream) {
- SCOPED_TSAN_INTERCEPTOR(fclose, stream);
- if (stream) {
- int fd = REAL(fileno)(stream);
- if (fd >= 0)
- FdClose(thr, pc, fd);
+ {
+ SCOPED_TSAN_INTERCEPTOR(fclose, stream);
+ if (stream) {
+ int fd = fileno_unlocked(stream);
+ if (fd >= 0)
+ FdClose(thr, pc, fd);
+ }
}
- int res = REAL(fclose)(stream);
- return res;
+ return REAL(fclose)(stream);
}
TSAN_INTERCEPTOR(uptr, fread, void *ptr, uptr size, uptr nmemb, void *f) {
- SCOPED_TSAN_INTERCEPTOR(fread, ptr, size, nmemb, f);
- MemoryAccessRange(thr, pc, (uptr)ptr, size * nmemb, true);
+ {
+ SCOPED_TSAN_INTERCEPTOR(fread, ptr, size, nmemb, f);
+ MemoryAccessRange(thr, pc, (uptr)ptr, size * nmemb, true);
+ }
return REAL(fread)(ptr, size, nmemb, f);
}
TSAN_INTERCEPTOR(uptr, fwrite, const void *p, uptr size, uptr nmemb, void *f) {
- SCOPED_TSAN_INTERCEPTOR(fwrite, p, size, nmemb, f);
- MemoryAccessRange(thr, pc, (uptr)p, size * nmemb, false);
+ {
+ SCOPED_TSAN_INTERCEPTOR(fwrite, p, size, nmemb, f);
+ MemoryAccessRange(thr, pc, (uptr)p, size * nmemb, false);
+ }
return REAL(fwrite)(p, size, nmemb, f);
}
@@ -1823,7 +1824,6 @@
TSAN_INTERCEPT(recvmsg);
TSAN_INTERCEPT(unlink);
- TSAN_INTERCEPT(fileno);
TSAN_INTERCEPT(fopen);
TSAN_INTERCEPT(freopen);
TSAN_INTERCEPT(fclose);
Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_mman.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_mman.cc?rev=171967&r1=171966&r2=171967&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_mman.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_mman.cc Wed Jan 9 05:54:52 2013
@@ -121,7 +121,9 @@
MBlock *user_mblock(ThreadState *thr, void *p) {
CHECK_NE(p, (void*)0);
Allocator *a = allocator();
- return (MBlock*)a->GetMetaData(a->GetBlockBegin(p));
+ void *b = a->GetBlockBegin(p);
+ CHECK_NE(b, 0);
+ return (MBlock*)a->GetMetaData(b);
}
void invoke_malloc_hook(void *ptr, uptr size) {
Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_stat.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_stat.cc?rev=171967&r1=171966&r2=171967&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_stat.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_stat.cc Wed Jan 9 05:54:52 2013
@@ -218,7 +218,6 @@
name[StatInt_recv] = " recv ";
name[StatInt_recvmsg] = " recvmsg ";
name[StatInt_unlink] = " unlink ";
- name[StatInt_fileno] = " fileno ";
name[StatInt_fopen] = " fopen ";
name[StatInt_freopen] = " freopen ";
name[StatInt_fclose] = " fclose ";
Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h?rev=171967&r1=171966&r2=171967&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h Wed Jan 9 05:54:52 2013
@@ -213,7 +213,6 @@
StatInt_recv,
StatInt_recvmsg,
StatInt_unlink,
- StatInt_fileno,
StatInt_fopen,
StatInt_freopen,
StatInt_fclose,
More information about the llvm-commits
mailing list