Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Format
  • Loading branch information
speednoisemovement committed Apr 1, 2025
commit 081ce760c09dd7e35ecb805c328d72186952cde9
4 changes: 1 addition & 3 deletions compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -563,9 +563,7 @@ uptr TlsBaseAddr() {
// defined as `_INTERNAL_POSIX_THREAD_KEYS_MAX +
// `_INTERNAL_POSIX_THREAD_KEYS_END` (512 pointers on iPhone and 768 elsewhere).
// Keep at 1024 for backwards compatibility.
uptr TlsSize() {
return 1024 * sizeof(uptr);
}
uptr TlsSize() { return 1024 * sizeof(uptr); }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#if TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR
#define _EXTERNAL_POSIX_THREAD_KEYS_MAX 256
#define _INTERNAL_POSIX_THREAD_KEYS_MAX 256
#define _INTERNAL_POSIX_THREAD_KEYS_END 512
#else
#define _EXTERNAL_POSIX_THREAD_KEYS_MAX 512
#define _INTERNAL_POSIX_THREAD_KEYS_MAX 256
#define _INTERNAL_POSIX_THREAD_KEYS_END 768
#endif

void *tsd[_EXTERNAL_POSIX_THREAD_KEYS_MAX + _INTERNAL_POSIX_THREAD_KEYS_MAX];

https://github.com/apple-oss-distributions/libpthread/blob/libpthread-535/src/types_internal.h#L418

512 pointers on iPhone and 768 elsewhere

👍

Currently we are returning 1024 on macOS/Intel or 0 elsewhere, both wrong! :/

@speednoisemovement, can you comment on the "why?", which problem is this solving?

TlsSize() is used only in GetThreadStackAndTls(). What is the nature of this function? Is the conservative answer to return a lower ("only touch this much") or upper ("at least poison this much") bound? Depending on that we should return 512 or 768.

We could also sidestep this question and return the exact answer. Not too much worse since we are already hardcoding a value derived from an internal header in any case.

// Derived from:
// https://github.com/apple-oss-distributions/libpthread/blob/libpthread-535/src/types_internal.h#L418
uptr TlsSize() {
#if SANITIZER_IOS && !SANITIZER_IOSSIM
  return 512 * sizeof(uptr);
#else
  return 768 * sizeof(uptr);
#endif
}

⬆️ Voting for this if others don't have concerns.


void GetThreadStackAndTls(bool main, uptr *stk_begin, uptr *stk_end,
uptr *tls_begin, uptr *tls_end) {
Expand Down
Loading