Bug 1281581 - save and restore errno in the profiler's signal handler; r=BenWa

The profiler's signal handler clobbers errno, via its calls to sem_post,
or via other functions that it transitively calls.  TSan complains about
this, as a sample arriving at the wrong time could make it look like a
function that failed actually succeeded, or vice versa.  Ensure that the
signal handler preserves the state of the world by saving and restoring
errno around its operation.
This commit is contained in:
Nathan Froyd 2016-06-28 19:17:43 -04:00
Родитель 206dc72425
Коммит b4dc060490
1 изменённых файлов: 5 добавлений и 0 удалений

Просмотреть файл

@ -231,8 +231,12 @@ static void SetSampleContext(TickSample* sample, void* context)
namespace {
void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) {
// Avoid TSan warning about clobbering errno.
int savedErrno = errno;
if (!Sampler::GetActiveSampler()) {
sem_post(&sSignalHandlingDone);
errno = savedErrno;
return;
}
@ -253,6 +257,7 @@ void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) {
sCurrentThreadProfile = NULL;
sem_post(&sSignalHandlingDone);
errno = savedErrno;
}
} // namespace