This is an archive of the discontinued LLVM Phabricator instance.

Correct NetBSD support in pthread_once(3)/TSan
ClosedPublic

Authored by krytarowski on Nov 20 2017, 12:10 PM.

Details

Summary

The pthread_once(3)/NetBSD type is built with the following structure:

struct __pthread_once_st {
pthread_mutex_t pto_mutex;
int pto_done;
};

Set the pto_done position as shifted by __sanitizer::pthread_mutex_t_sz
from the beginning of the pthread_once struct.

This corrects deadlocks when the pthread_once(3) function
is used.

Sponsored by <The NetBSD Foundation>

Diff Detail

Repository
rL LLVM

Event Timeline

krytarowski created this revision.Nov 20 2017, 12:10 PM
dvyukov added inline comments.Nov 20 2017, 12:24 PM
lib/tsan/rtl/tsan_interceptors.cc
1360

No, Kostya will not approve this.

1364

You said first field is pthread_mutex_t, why is this pthread_t_sz?

krytarowski added inline comments.Nov 20 2017, 12:31 PM
lib/tsan/rtl/tsan_interceptors.cc
1360

OK, I will change it back to if().

1364

My mistake. I will try to add pthread_mutex_t_sz in sanitizer_platform_limits_netbsd.{cc,h} and reuse it.

krytarowski edited the summary of this revision. (Show Details)

Correct type of shift: pthread_t_sz -> pthread_mutex_t_sz.
Add new value pthread_mutex_t_sz.
Revert ifdef change to if(){}

This version still works. Apparently by an accident the wrong previous one functioned ok.

dvyukov accepted this revision.Nov 21 2017, 1:30 AM
This revision is now accepted and ready to land.Nov 21 2017, 1:30 AM
krytarowski closed this revision.Nov 21 2017, 1:36 AM