[llvm-commits] [compiler-rt] r159264 - in /compiler-rt/trunk/lib/tsan/rtl: tsan_interceptors.cc tsan_report.cc tsan_report.h
Dmitry Vyukov
dvyukov at google.com
Wed Jun 27 06:54:47 PDT 2012
Author: dvyukov
Date: Wed Jun 27 08:54:46 2012
New Revision: 159264
URL: http://llvm.org/viewvc/llvm-project?rev=159264&view=rev
Log:
tsan: check that signal handlers do not spoil errno.
Modified:
compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc
compiler-rt/trunk/lib/tsan/rtl/tsan_report.cc
compiler-rt/trunk/lib/tsan/rtl/tsan_report.h
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=159264&r1=159263&r2=159264&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc Wed Jun 27 08:54:46 2012
@@ -66,6 +66,8 @@
typedef void (*sighandler_t)(int sig);
+#define errno (*__errno_location())
+
union pthread_attr_t {
char size[kPthreadAttrSize];
void *align;
@@ -450,7 +452,7 @@
if (*addr) {
if (!IsAppMem((uptr)*addr) || !IsAppMem((uptr)*addr + sz - 1)) {
if (flags & MAP_FIXED) {
- *__errno_location() = EINVAL;
+ errno = EINVAL;
return false;
} else {
*addr = 0;
@@ -1349,10 +1351,25 @@
signal->armed = false;
if (sigactions[sig].sa_handler != SIG_DFL
&& sigactions[sig].sa_handler != SIG_IGN) {
+ // Insure that the handler does not spoil errno.
+ const int saved_errno = errno;
+ errno = 0;
if (signal->sigaction)
sigactions[sig].sa_sigaction(sig, &signal->siginfo, &uctx);
else
sigactions[sig].sa_handler(sig);
+ if (errno != 0) {
+ ScopedInRtl in_rtl;
+ StackTrace stack;
+ uptr pc = signal->sigaction ?
+ (uptr)sigactions[sig].sa_sigaction :
+ (uptr)sigactions[sig].sa_handler;
+ stack.Init(&pc, 1);
+ ScopedReport rep(ReportTypeErrnoInSignal);
+ rep.AddStack(&stack);
+ OutputReport(rep, rep.GetReport()->stacks[0]);
+ }
+ errno = saved_errno;
}
}
}
Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_report.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_report.cc?rev=159264&r1=159263&r2=159264&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_report.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_report.cc Wed Jun 27 08:54:46 2012
@@ -40,6 +40,8 @@
TsanPrintf("destroy of a locked mutex");
else if (typ == ReportTypeSignalUnsafe)
TsanPrintf("signal-unsafe call inside of a signal");
+ else if (typ == ReportTypeErrnoInSignal)
+ TsanPrintf("signal handler spoils errno");
TsanPrintf(" (pid=%d)\n", GetPid());
}
Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_report.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_report.h?rev=159264&r1=159263&r2=159264&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_report.h (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_report.h Wed Jun 27 08:54:46 2012
@@ -24,6 +24,7 @@
ReportTypeThreadLeak,
ReportTypeMutexDestroyLocked,
ReportTypeSignalUnsafe,
+ ReportTypeErrnoInSignal,
};
struct ReportStack {
More information about the llvm-commits
mailing list