GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-159320: use pthread_getattr_np for stack limit checks even on musl by Yhg1s · Pull Request #159376 · python/cpython

Conversation

@Yhg1s

@Yhg1s Yhg1s commented Oct 13, 2026 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Adjust the use of pthread_getattr_np for stack size limit detection to avoid the problem on musl of it reporting the stack limit of the main thread incorrectly. On platforms where pthread_getattr_np underreports the main thread's stack size, use RLIMIT_STACK for the main thread instead. (Cross-compiles targeting musl will have to pass ac_cv_unreliable_pthread_getattr_np=yes to configure.)

  • Issue: Broken stack size detection on Android #159320

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@Yhg1s
Rewrite the pthread_getattr_np usage to avoid the problem on musl of it
723c722
reporting the stack limit of the main thread incorrectly. On platforms where
pthread_getattr_np underreports the main thread's stack size, use
RLIMIT_STACK for the main thread instead.
@Yhg1s
Yhg1s requested review from AA-Turner, Eclips4, corona10, emmatyping, erlend-aasland, itamaro, markshannon and tomasr8 as code owners October 13, 2026 21:31
@bedevere-app bedevere-app Bot mentioned this pull request Oct 13, 2026
Broken stack size detection on Android #159320
Open
@bedevere-app bedevere-app Bot added the awaiting core review label Oct 13, 2026
@Yhg1s

Yhg1s commented Oct 13, 2026

Copy link
Copy Markdown
Member Author

This is a more general fix than #159321, and incidentally also lets us have proper stack overflow protections on musl.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Yhg1s Yhg1s mentioned this pull request Oct 13, 2026
gh-159320: Enable stack size detection on Android #159321
Merged
Yhg1s added 4 commits October 13, 2026 23:37
@Yhg1s
Add HAVE_UNRELIABLE_PTHREAD_GETATTR_NP to the long, long list of ignored
9569c07
symbols for the Py check.
@Yhg1s
Merge branch 'main' into musl-stack-check
8793527
@Yhg1s
Merge branch 'main' into musl-stack-check
79f0f93
@Yhg1s
Fix punctuation/formatting.
036f753
@Yhg1s

Yhg1s commented Oct 14, 2026

Copy link
Copy Markdown
Member Author

For the record, I think this should not be backported.

encukou reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Yhg1s Yhg1s mentioned this pull request Oct 15, 2026
gh-159288: Avoid segfault by adding missing recursion checks when walking lazy import chains #159289
Merged
@vstinner vstinner mentioned this pull request Oct 16, 2026
test_lazy_import.test_deeply_dotted_name() does crash on Alpine Linux (SIGSEGV) and FreeBSD (SIGILL) #159535
Open
encukou
encukou reviewed Oct 16, 2026
View reviewed changes
Comment thread Python/ceval.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

@Yhg1s
Fix a comment to make it clear the correctness of pthread_getattr_np …
e78cfd2
…doesn't

depend on explicitly setting the stack size. It's correct for new threads
regardless of that call.
@vstinner

vstinner commented Oct 17, 2026

Copy link
Copy Markdown
Member

Can you please make the new "HAVE" macro private? Replace the macro in configure.ac:

-     [AC_DEFINE([HAVE_UNRELIABLE_PTHREAD_GETATTR_NP], [1],
+     [AC_DEFINE([_Py_HAVE_UNRELIABLE_PTHREAD_GETATTR_NP], [1],

Something like that:

Details
diff --git a/Python/ceval.c b/Python/ceval.c
index 3ed070a5846..e0623293670 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -65,7 +65,7 @@ _Py_ReachedRecursionLimitWithMargin(PyThreadState *tstate, int margin_count)
 #  define Py_C_STACK_SIZE 4000000
 #endif
 
-#ifdef HAVE_UNRELIABLE_PTHREAD_GETATTR_NP
+#ifdef _Py_HAVE_UNRELIABLE_PTHREAD_GETATTR_NP
 #ifdef HAVE_SYS_RESOURCE_H
 #  include <sys/resource.h>
 #endif
@@ -165,7 +165,7 @@ hardware_stack_limits(uintptr_t *base, uintptr_t *top, uintptr_t sp)
         err |= pthread_attr_destroy(&attr);
     }
     if (err == 0) {
-#    ifdef HAVE_UNRELIABLE_PTHREAD_GETATTR_NP
+#    ifdef _Py_HAVE_UNRELIABLE_PTHREAD_GETATTR_NP
         /* pthread_getattr_np on the main thread of a musl process reports a
          * stack size based on the current stack rather than RLIMIT_STACK.
          * New threads are reported correctly even on musl, so this fallback
diff --git a/Tools/build/check_capi_macros_ignored.txt b/Tools/build/check_capi_macros_ignored.txt
index cfa37c2b137..238c29b7039 100644
--- a/Tools/build/check_capi_macros_ignored.txt
+++ b/Tools/build/check_capi_macros_ignored.txt
@@ -627,7 +627,6 @@ HAVE_UNAME
 HAVE_UNISTD_H
 HAVE_UNLINKAT
 HAVE_UNLOCKPT
-HAVE_UNRELIABLE_PTHREAD_GETATTR_NP
 HAVE_UNSHARE
 HAVE_USABLE_WCHAR_T
 HAVE_UTIL_H
diff --git a/configure b/configure
index 221907add48..744ee2beef4 100755
--- a/configure
+++ b/configure
@@ -21875,7 +21875,7 @@ printf "%s\n" "$ac_cv_unreliable_pthread_getattr_np" >&6; }
    if test "x$ac_cv_unreliable_pthread_getattr_np" = xyes
 then :
 
-printf "%s\n" "#define HAVE_UNRELIABLE_PTHREAD_GETATTR_NP 1" >>confdefs.h
+printf "%s\n" "#define _Py_HAVE_UNRELIABLE_PTHREAD_GETATTR_NP 1" >>confdefs.h
 
 fi
 fi
diff --git a/configure.ac b/configure.ac
index e523314b492..42844ab64ca 100644
--- a/configure.ac
+++ b/configure.ac
@@ -5620,7 +5620,7 @@ int main(void) {
       [ac_cv_unreliable_pthread_getattr_np=yes],
       [ac_cv_unreliable_pthread_getattr_np=no])])
    AS_VAR_IF([ac_cv_unreliable_pthread_getattr_np], [yes],
-     [AC_DEFINE([HAVE_UNRELIABLE_PTHREAD_GETATTR_NP], [1],
+     [AC_DEFINE([_Py_HAVE_UNRELIABLE_PTHREAD_GETATTR_NP], [1],
        [Define if pthread_getattr_np under-reports the main thread's stack size (musl behaviour).])])])
 
 # os.statx uses Linux's statx function.  AIX also has a function named statx,
diff --git a/pyconfig.h.in b/pyconfig.h.in
index 4193d536f3b..1fdeb7d9f2f 100644
--- a/pyconfig.h.in
+++ b/pyconfig.h.in
@@ -1706,10 +1706,6 @@
 /* Define to 1 if you have the 'unlockpt' function. */
 #undef HAVE_UNLOCKPT
 
-/* Define if pthread_getattr_np under-reports the main thread's stack size
-   (musl behaviour). */
-#undef HAVE_UNRELIABLE_PTHREAD_GETATTR_NP
-
 /* Define to 1 if you have the 'unshare' function. */
 #undef HAVE_UNSHARE
 
@@ -2227,6 +2223,10 @@
 /* Define if you have the 'tanpi' function. */
 #undef _Py_HAVE_TANPI
 
+/* Define if pthread_getattr_np under-reports the main thread's stack size
+   (musl behaviour). */
+#undef _Py_HAVE_UNRELIABLE_PTHREAD_GETATTR_NP
+
 /* Thread stack size set by the linker (in bytes). */
 #undef _Py_LINKER_THREAD_STACK_SIZE
 
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner

vstinner commented Oct 17, 2026

Copy link
Copy Markdown
Member

See also #159604 for FreeBSD.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

encukou added 2 commits November 5, 2026 15:50
@encukou
Merge in the main branch
8feae85
@encukou
Use a private name for the macro
a44a16c
@encukou

encukou commented Nov 5, 2026

Copy link
Copy Markdown
Member

Sorry, this dropped off my radar. I'll resolve the conflict and rename the macro.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@encukou encukou added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Nov 5, 2026
@bedevere-bot

bedevere-bot commented Nov 5, 2026

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @encukou for commit a44a16c 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F159376%2Fmerge

If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Nov 5, 2026
@encukou encukou mentioned this pull request Nov 10, 2026
gh-159320: use pthread_getattr_np for stack limit checks even on musl #161749
Open
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@encukou encukou encukou left review comments
@markshannon markshannon Awaiting requested review from markshannon markshannon is a code owner
@Eclips4 Eclips4 Awaiting requested review from Eclips4
@tomasr8 tomasr8 Awaiting requested review from tomasr8
@erlend-aasland erlend-aasland Awaiting requested review from erlend-aasland erlend-aasland is a code owner
@corona10 corona10 Awaiting requested review from corona10 corona10 is a code owner
@AA-Turner AA-Turner Awaiting requested review from AA-Turner AA-Turner is a code owner
@emmatyping emmatyping Awaiting requested review from emmatyping emmatyping is a code owner
@itamaro itamaro Awaiting requested review from itamaro itamaro is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

awaiting core review

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@Yhg1s @vstinner @encukou @bedevere-bot
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.