[Threading] Move stack bounds fetching into the threading library.

Fetching the current stack bounds is done using threading functions, so
should be in the threading library.

rdar://90776105
This commit is contained in:
Alastair Houghton
2022-05-06 10:59:48 +01:00
parent 69f0b03a73
commit fc4f941185
12 changed files with 134 additions and 82 deletions

View File

@@ -57,4 +57,23 @@ void swift::threading_impl::once_slow(once_t &predicate, void (*fn)(void *),
linux::ulock_unlock(&predicate.lock);
}
swift::threading_impl::stack_bounds
swift::threading_impl::thread_get_current_stack_bounds() {
stack_bounds result = { nullptr, nullptr };
pthread_attr_t attr;
size_t size = 0;
void *begin = nullptr;
if (!pthread_getattr_np(pthread_self(), &attr)) {
if (!pthread_attr_getstack(&attr, &begin, &size)) {
result.low = begin;
result.high = (char *)begin + size;
}
pthread_attr_destroy(&attr);
}
return result;
}
#endif // SWIFT_THREADING_LINUX