diff options
| author | Ryan Prichard <rprichard@google.com> | 2018-06-12 01:32:25 +0000 |
|---|---|---|
| committer | Ryan Prichard <rprichard@google.com> | 2018-06-12 01:32:25 +0000 |
| commit | 31e4a550a37fc895483c4d5011f2934444d0ecb0 (patch) | |
| tree | 68678ee9a8f046ca761b8474e918fb46a01ff34f /compiler-rt/lib/builtins | |
| parent | 95f3a430a8d96713cc8cbe2178763ea100785940 (diff) | |
| download | bcm5719-llvm-31e4a550a37fc895483c4d5011f2934444d0ecb0.tar.gz bcm5719-llvm-31e4a550a37fc895483c4d5011f2934444d0ecb0.zip | |
[builtins] emutls cleanup: determine header size using sizeof
Summary: Also add a few post-#else/#endif comments
Reviewers: echristo, srhines
Reviewed By: echristo
Subscribers: chh, delcypher, llvm-commits, #sanitizers
Differential Revision: https://reviews.llvm.org/D47861
llvm-svn: 334462
Diffstat (limited to 'compiler-rt/lib/builtins')
| -rw-r--r-- | compiler-rt/lib/builtins/emutls.c | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/compiler-rt/lib/builtins/emutls.c b/compiler-rt/lib/builtins/emutls.c index 5dd8dd15477..063ddfa06e4 100644 --- a/compiler-rt/lib/builtins/emutls.c +++ b/compiler-rt/lib/builtins/emutls.c @@ -96,7 +96,7 @@ static __inline emutls_address_array* emutls_getspecific() { return (emutls_address_array*) pthread_getspecific(emutls_pthread_key); } -#else +#else /* _WIN32 */ #include <windows.h> #include <malloc.h> @@ -222,11 +222,11 @@ static __inline void __atomic_store_n(void *ptr, uintptr_t val, unsigned type) { InterlockedExchangePointer((void *volatile *)ptr, (void *)val); } -#endif +#endif /* __ATOMIC_RELEASE */ #pragma warning (pop) -#endif +#endif /* _WIN32 */ static size_t emutls_num_object = 0; /* number of allocated TLS objects */ @@ -314,11 +314,12 @@ static __inline void emutls_check_array_set_size(emutls_address_array *array, * which must be no smaller than the given index. */ static __inline uintptr_t emutls_new_data_array_size(uintptr_t index) { - /* Need to allocate emutls_address_array with one extra slot - * to store the data array size. + /* Need to allocate emutls_address_array with extra slots + * to store the header. * Round up the emutls_address_array size to multiple of 16. */ - return ((index + 1 + 15) & ~((uintptr_t)15)) - 1; + uintptr_t header_words = sizeof(emutls_address_array) / sizeof(void *); + return ((index + header_words + 15) & ~((uintptr_t)15)) - header_words; } /* Returns the size in bytes required for an emutls_address_array with |

