From 9a1fda6903c5d56824cdec1e80aa8c0d313a0cc8 Mon Sep 17 00:00:00 2001 From: Seth Jackson Date: Thu, 4 Jun 2026 17:38:32 -0400 Subject: [PATCH 1/3] Add OpenBSD support --- src/coreclr/pal/src/thread/thread.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/coreclr/pal/src/thread/thread.cpp b/src/coreclr/pal/src/thread/thread.cpp index 7e9c3baa6a0cd1..c4c354bfa7deae 100644 --- a/src/coreclr/pal/src/thread/thread.cpp +++ b/src/coreclr/pal/src/thread/thread.cpp @@ -1423,7 +1423,7 @@ CPalThread::ThreadEntry( // vendor-modified Android kernels with strict SELinux policy) block // sched_setaffinity even when passed a mask extracted via sched_getaffinity. // Treat this as non-fatal — the thread will continue running on any - // available CPU rather than the originally affinitized one. + // available CPU rather than the originally affinitized one. WARN("sched_setaffinity failed with EPERM/EACCES, ignoring\n"); } else @@ -2316,6 +2316,12 @@ CPalThread::GetStackBase() #ifdef TARGET_APPLE // This is a Mac specific method stackBase = pthread_get_stackaddr_np(pthread_self()); +#elif TARGET_OPENBSD + stack_t stack; + int status = pthread_stackseg_np(pthread_self(), &stack); + _ASSERT_MSG(status == 0, "pthread_stackseg_np call failed"); + + stackBase = stack.ss_sp; #else pthread_attr_t attr; void* stackAddr; @@ -2361,6 +2367,12 @@ CPalThread::GetStackLimit() // This is a Mac specific method stackLimit = ((BYTE *)pthread_get_stackaddr_np(pthread_self()) - pthread_get_stacksize_np(pthread_self())); +#elif TARGET_OPENBSD + stack_t stack; + int status = pthread_stackseg_np(pthread_self(), &stack); + _ASSERT_MSG(status == 0, "pthread_stackseg_np call failed"); + + stackLimit = (void*)stack.ss_size; #else pthread_attr_t attr; size_t stackSize; From 62e1672b1859b5dcde6142e76cd407aa347a3d7c Mon Sep 17 00:00:00 2001 From: Seth Jackson Date: Fri, 5 Jun 2026 22:33:48 -0400 Subject: [PATCH 2/3] Update src/coreclr/pal/src/thread/thread.cpp Co-authored-by: Jan Kotas --- src/coreclr/pal/src/thread/thread.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/pal/src/thread/thread.cpp b/src/coreclr/pal/src/thread/thread.cpp index c4c354bfa7deae..f530a29a69582a 100644 --- a/src/coreclr/pal/src/thread/thread.cpp +++ b/src/coreclr/pal/src/thread/thread.cpp @@ -2316,7 +2316,7 @@ CPalThread::GetStackBase() #ifdef TARGET_APPLE // This is a Mac specific method stackBase = pthread_get_stackaddr_np(pthread_self()); -#elif TARGET_OPENBSD +#elif defined(TARGET_OPENBSD) stack_t stack; int status = pthread_stackseg_np(pthread_self(), &stack); _ASSERT_MSG(status == 0, "pthread_stackseg_np call failed"); From 81bd365c09317976bf8f1f84514f6f7412838592 Mon Sep 17 00:00:00 2001 From: Seth Jackson Date: Fri, 5 Jun 2026 22:33:59 -0400 Subject: [PATCH 3/3] Update src/coreclr/pal/src/thread/thread.cpp Co-authored-by: Jan Kotas --- src/coreclr/pal/src/thread/thread.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/pal/src/thread/thread.cpp b/src/coreclr/pal/src/thread/thread.cpp index f530a29a69582a..f7174e69ba5be0 100644 --- a/src/coreclr/pal/src/thread/thread.cpp +++ b/src/coreclr/pal/src/thread/thread.cpp @@ -2367,7 +2367,7 @@ CPalThread::GetStackLimit() // This is a Mac specific method stackLimit = ((BYTE *)pthread_get_stackaddr_np(pthread_self()) - pthread_get_stacksize_np(pthread_self())); -#elif TARGET_OPENBSD +#elif defined(TARGET_OPENBSD) stack_t stack; int status = pthread_stackseg_np(pthread_self(), &stack); _ASSERT_MSG(status == 0, "pthread_stackseg_np call failed");