Skip to content

Commit af215ca

Browse files
sethjacksonjkotas
andauthored
Add OpenBSD support in CPalThread (#129057)
Add OpenBSD support for `CPalThread::GetStackBase()` and `CPalThread::GetStackLimit()`. OpenBSD does not have `pthread_attr_get_np` or `pthread_getattr_np` to get the current thread's stack attributes. Instead there is a standalone function [pthread_stackseg_np](https://man.openbsd.org/pthread_stackseg_np.3) that does the same via [stack_t](https://man.openbsd.org/sigaltstack.2). Since we do not actually need a standard pthread attr in this case I put this case inside a `TARGET_OPENBSD` check similar to macOS. Contributes to #124911 --------- Co-authored-by: Jan Kotas <jkotas@microsoft.com>
1 parent 10aeb7b commit af215ca

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

src/coreclr/pal/src/thread/thread.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1423,7 +1423,7 @@ CPalThread::ThreadEntry(
14231423
// vendor-modified Android kernels with strict SELinux policy) block
14241424
// sched_setaffinity even when passed a mask extracted via sched_getaffinity.
14251425
// Treat this as non-fatal — the thread will continue running on any
1426-
// available CPU rather than the originally affinitized one.
1426+
// available CPU rather than the originally affinitized one.
14271427
WARN("sched_setaffinity failed with EPERM/EACCES, ignoring\n");
14281428
}
14291429
else
@@ -2316,6 +2316,12 @@ CPalThread::GetStackBase()
23162316
#ifdef TARGET_APPLE
23172317
// This is a Mac specific method
23182318
stackBase = pthread_get_stackaddr_np(pthread_self());
2319+
#elif defined(TARGET_OPENBSD)
2320+
stack_t stack;
2321+
int status = pthread_stackseg_np(pthread_self(), &stack);
2322+
_ASSERT_MSG(status == 0, "pthread_stackseg_np call failed");
2323+
2324+
stackBase = stack.ss_sp;
23192325
#else
23202326
pthread_attr_t attr;
23212327
void* stackAddr;
@@ -2361,6 +2367,12 @@ CPalThread::GetStackLimit()
23612367
// This is a Mac specific method
23622368
stackLimit = ((BYTE *)pthread_get_stackaddr_np(pthread_self()) -
23632369
pthread_get_stacksize_np(pthread_self()));
2370+
#elif defined(TARGET_OPENBSD)
2371+
stack_t stack;
2372+
int status = pthread_stackseg_np(pthread_self(), &stack);
2373+
_ASSERT_MSG(status == 0, "pthread_stackseg_np call failed");
2374+
2375+
stackLimit = (void*)stack.ss_size;
23642376
#else
23652377
pthread_attr_t attr;
23662378
size_t stackSize;

0 commit comments

Comments
 (0)