diff options
author | Kostya Kortchinsky <kostyak@google.com> | 2017-10-12 15:01:09 +0000 |
---|---|---|
committer | Kostya Kortchinsky <kostyak@google.com> | 2017-10-12 15:01:09 +0000 |
commit | 389cffef8d650b3dd60e9f76badb083c241fbd0b (patch) | |
tree | 315fe36a577fbc4429384ae0aa46b8bbf60ff6a8 /lib/scudo/scudo_tsd_shared.cpp | |
parent | 286d9a10aba57923d2a1c193b930580f34f3123b (diff) |
[scudo] Allow for non-Android Shared TSD platforms, part 1
Summary:
This first part just prepares the grounds for part 2 and doesn't add any new
functionality. It mostly consists of small refactors:
- move the `pthread.h` include higher as it will be used in the headers;
- use `errno.h` in `scudo_allocator.cpp` instead of the sanitizer one, update
the `errno` assignments accordingly (otherwise it creates conflicts on some
platforms due to `pthread.h` including `errno.h`);
- introduce and use `getCurrentTSD` and `setCurrentTSD` for the shared TSD
model code;
Reviewers: alekseyshl
Reviewed By: alekseyshl
Subscribers: llvm-commits, srhines
Differential Revision: https://reviews.llvm.org/D38826
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@315583 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/scudo/scudo_tsd_shared.cpp')
-rw-r--r-- | lib/scudo/scudo_tsd_shared.cpp | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/lib/scudo/scudo_tsd_shared.cpp b/lib/scudo/scudo_tsd_shared.cpp index 481635e6a..54aec842a 100644 --- a/lib/scudo/scudo_tsd_shared.cpp +++ b/lib/scudo/scudo_tsd_shared.cpp @@ -15,8 +15,6 @@ #if !SCUDO_TSD_EXCLUSIVE -#include <pthread.h> - namespace __scudo { static pthread_once_t GlobalInitialized = PTHREAD_ONCE_INIT; @@ -51,12 +49,15 @@ static void initOnce() { TSDs[i].init(/*Shared=*/true); } +ALWAYS_INLINE void setCurrentTSD(ScudoTSD *TSD) { + *get_android_tls_ptr() = reinterpret_cast<uptr>(TSD); +} + void initThread(bool MinimalInit) { pthread_once(&GlobalInitialized, initOnce); // Initial context assignment is done in a plain round-robin fashion. u32 Index = atomic_fetch_add(&CurrentIndex, 1, memory_order_relaxed); - ScudoTSD *TSD = &TSDs[Index % NumberOfTSDs]; - *get_android_tls_ptr() = reinterpret_cast<uptr>(TSD); + setCurrentTSD(&TSDs[Index % NumberOfTSDs]); } ScudoTSD *getTSDAndLockSlow() { @@ -66,7 +67,7 @@ ScudoTSD *getTSDAndLockSlow() { for (u32 i = 0; i < NumberOfTSDs; i++) { TSD = &TSDs[i]; if (TSD->tryLock()) { - *get_android_tls_ptr() = reinterpret_cast<uptr>(TSD); + setCurrentTSD(TSD); return TSD; } } @@ -81,12 +82,12 @@ ScudoTSD *getTSDAndLockSlow() { } if (LIKELY(LowestPrecedence != UINT64_MAX)) { TSD->lock(); - *get_android_tls_ptr() = reinterpret_cast<uptr>(TSD); + setCurrentTSD(TSD); return TSD; } } // Last resort, stick with the current one. - TSD = reinterpret_cast<ScudoTSD *>(*get_android_tls_ptr()); + TSD = getCurrentTSD(); TSD->lock(); return TSD; } |