Skip to content

Commit 14b43d4

Browse files
authored
gh-159603: Call pthread_attr_init() in hardware_stack_limits() (#159857)
Always call pthread_attr_init() in hardware_stack_limits(), not only on FreeBSD (if pthread_attr_get_np() is available). Emscripten: add pthread_attr_init() workaround.
1 parent 6fa2d64 commit 14b43d4

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

‎Python/ceval.c‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ _Py_ReachedRecursionLimitWithMargin(PyThreadState *tstate, int margin_count)
7979
#include "emscripten/stack.h"
8080

8181
#define pthread_attr_t workaround_pthread_attr_t
82+
#define pthread_attr_init workaround_pthread_attr_init
8283
#define pthread_getattr_np workaround_pthread_getattr_np
8384
#define pthread_attr_getguardsize workaround_pthread_attr_getguardsize
8485
#define pthread_attr_getstack workaround_pthread_attr_getstack
@@ -91,6 +92,11 @@ typedef struct {
9192

9293
extern __attribute__((__visibility__("hidden"))) unsigned __default_guardsize;
9394

95+
int pthread_attr_init(pthread_attr_t *a)
96+
{
97+
return 0;
98+
}
99+
94100
// Modified version of pthread_getattr_np from the upstream PR.
95101

96102
int pthread_getattr_np(pthread_t thread, pthread_attr_t *attr) {
@@ -158,11 +164,12 @@ hardware_stack_limits(uintptr_t *base, uintptr_t *top, uintptr_t sp)
158164
size_t stack_size, guard_size;
159165
void *stack_addr;
160166
pthread_attr_t attr;
161-
#ifdef _Py_HAVE_PTHREAD_ATTR_GET_NP
167+
162168
int err = pthread_attr_init(&attr);
169+
#ifdef _Py_HAVE_PTHREAD_ATTR_GET_NP
163170
err |= pthread_attr_get_np(pthread_self(), &attr);
164171
#else
165-
int err = pthread_getattr_np(pthread_self(), &attr);
172+
err |= pthread_getattr_np(pthread_self(), &attr);
166173
#endif
167174
if (err == 0) {
168175
err = pthread_attr_getguardsize(&attr, &guard_size);
@@ -175,6 +182,7 @@ hardware_stack_limits(uintptr_t *base, uintptr_t *top, uintptr_t sp)
175182
return;
176183
}
177184
# endif
185+
178186
// Add some space for caller function then round to minimum page size
179187
// This is a guess at the top of the stack, but should be a reasonably
180188
// good guess if called from _PyThreadState_Attach when creating a thread.

0 commit comments

Comments
 (0)