|
16 | 16 |
|
17 | 17 | #if SWIFT_THREADING_PTHREADS |
18 | 18 |
|
| 19 | +#if defined(__FreeBSD__) || defined(__OpenBSD__) |
| 20 | +#include <pthread_np.h> |
| 21 | +#endif |
| 22 | + |
19 | 23 | #include "swift/Threading/Impl/Pthreads.h" |
20 | 24 | #include "swift/Threading/Errors.h" |
21 | 25 |
|
@@ -72,4 +76,43 @@ void swift::threading_impl::once_slow(once_t &predicate, void (*fn)(void *), |
72 | 76 | pthread_mutex_unlock(&onceMutex); |
73 | 77 | } |
74 | 78 |
|
| 79 | +#if defined(__OpenBSD__) |
| 80 | +swift::threading_impl::stack_bounds |
| 81 | +swift::threading_impl::thread_get_current_stack_bounds() { |
| 82 | + stack_bounds result = { nullptr, nullptr }; |
| 83 | + stack_t sinfo; |
| 84 | + |
| 85 | + if (!pthread_stackseg_np(pthread_self(), &sinfo)) { |
| 86 | + result.low = (char *)sinfo.ss_sp - sinfo.ss_size; |
| 87 | + result.high = sinfo.ss_sp; |
| 88 | + } |
| 89 | + |
| 90 | + return result; |
| 91 | +} |
| 92 | +#else |
| 93 | +swift::threading_impl::stack_bounds |
| 94 | +swift::threading_impl::thread_get_current_stack_bounds() { |
| 95 | + stack_bounds result = { nullptr, nullptr }; |
| 96 | + pthread_attr_t attr; |
| 97 | + size_t size = 0; |
| 98 | + void *begin = nullptr; |
| 99 | + |
| 100 | +#if defined(__FreeBSD__) |
| 101 | + if (pthread_attr_init(&attr)) |
| 102 | + return result; |
| 103 | +#endif |
| 104 | + |
| 105 | + if (!pthread_getattr_np(pthread_self(), &attr)) { |
| 106 | + if (!pthread_attr_getstack(&attr, &begin, &size)) { |
| 107 | + result.low = begin; |
| 108 | + result.high = (char *)begin + size; |
| 109 | + } |
| 110 | + |
| 111 | + pthread_attr_destroy(&attr); |
| 112 | + } |
| 113 | + |
| 114 | + return result; |
| 115 | +} |
| 116 | +#endif |
| 117 | + |
75 | 118 | #endif // SWIFT_THREADING_PTHREADS |
0 commit comments