[PATCH v3 2/6] support: Add use_stack_min option to support_small_thread_stack_size
Adhemerval Zanella
adhemerval.zanella@linaro.org
Tue May 19 13:23:52 GMT 2026
It allows it to return PTHREAD_STACK_MIN if defined.
Checked on x86_64-linux-gnu and with a build for i686-gnu.
Suggested-by: H.J. Lu <hjl.tools@gmail.com>
---
elf/tst-bz26577-minstack.c | 7 +------
elf/tst-decorate-maps.c | 2 +-
nptl/tst-guard1.c | 4 ++--
stdlib/tst-canon-bz26341.c | 2 +-
support/support_set_small_thread_stack_size.c | 13 +++++++++----
support/support_small_stack_thread_attribute.c | 2 +-
support/xthread.h | 12 +++++++-----
sysdeps/unix/sysv/linux/tst-sem_getvalue-affinity.c | 2 +-
.../unix/sysv/linux/tst-skeleton-thread-affinity.c | 2 +-
9 files changed, 24 insertions(+), 22 deletions(-)
diff --git a/elf/tst-bz26577-minstack.c b/elf/tst-bz26577-minstack.c
index 741b307392a..9d5ecd85939 100644
--- a/elf/tst-bz26577-minstack.c
+++ b/elf/tst-bz26577-minstack.c
@@ -51,12 +51,7 @@ static int
do_test (void)
{
char *path = xasprintf ("%s/elf/tst-bz26577-mod.so", support_objdir_root);
- size_t stacksize =
-#ifdef PTHREAD_STACK_MIN
- PTHREAD_STACK_MIN;
-#else
- support_small_thread_stack_size ();
-#endif
+ size_t stacksize = support_small_thread_stack_size (true);
pthread_attr_t attr;
xpthread_attr_init (&attr);
diff --git a/elf/tst-decorate-maps.c b/elf/tst-decorate-maps.c
index fa3637af899..b6af31c7274 100644
--- a/elf/tst-decorate-maps.c
+++ b/elf/tst-decorate-maps.c
@@ -128,7 +128,7 @@ do_test_threads (bool set_guard)
{
pthread_attr_t attr;
xpthread_attr_init (&attr);
- size_t stacksize = support_small_thread_stack_size ();
+ size_t stacksize = support_small_thread_stack_size (false);
void *stack = xmmap (0,
stacksize,
PROT_READ | PROT_WRITE,
diff --git a/nptl/tst-guard1.c b/nptl/tst-guard1.c
index b97ad23de41..3486cba9e4d 100644
--- a/nptl/tst-guard1.c
+++ b/nptl/tst-guard1.c
@@ -176,7 +176,7 @@ do_test1 (void *closure)
pthread_attr_t attr;
xpthread_attr_init (&attr);
- size_t stacksize = support_small_thread_stack_size ();
+ size_t stacksize = support_small_thread_stack_size (false);
void *stack = xmmap (0,
stacksize,
PROT_READ | PROT_WRITE,
@@ -201,7 +201,7 @@ do_test2 (void *closure)
pthread_attr_t attr;
xpthread_attr_init (&attr);
- size_t stacksize = support_small_thread_stack_size ();
+ size_t stacksize = support_small_thread_stack_size (false);
void *stack = xmmap (0,
stacksize,
PROT_READ | PROT_WRITE,
diff --git a/stdlib/tst-canon-bz26341.c b/stdlib/tst-canon-bz26341.c
index 4860818a4e7..e94c924ac1c 100644
--- a/stdlib/tst-canon-bz26341.c
+++ b/stdlib/tst-canon-bz26341.c
@@ -81,7 +81,7 @@ do_realpath (void *arg)
const size_t syscall_usage = 1 * PATH_MAX + 1024;
const size_t realpath_usage = 2 * PATH_MAX + 1024;
const size_t thread_usage = 1 * PATH_MAX + 1024;
- size_t stack_size = support_small_thread_stack_size ()
+ size_t stack_size = support_small_thread_stack_size (false)
- syscall_usage - realpath_usage - thread_usage;
char stack[stack_size];
char *resolved = stack + stack_size - thread_usage + 1024;
diff --git a/support/support_set_small_thread_stack_size.c b/support/support_set_small_thread_stack_size.c
index 6c2cd4f92ba..51ec05b3229 100644
--- a/support/support_set_small_thread_stack_size.c
+++ b/support/support_set_small_thread_stack_size.c
@@ -21,13 +21,16 @@
#include <support/xthread.h>
size_t
-support_small_thread_stack_size (void)
+support_small_thread_stack_size (bool use_stack_min)
{
/* Some architectures have too small values for PTHREAD_STACK_MIN
which cannot be used for creating threads. Ensure that the stack
- size is at least 256 KiB. */
+ size is at least 256 KiB if USE_STACK_MIN is false. */
size_t stack_size = 256 * 1024;
#ifdef PTHREAD_STACK_MIN
+ if (use_stack_min)
+ return PTHREAD_STACK_MIN;
+
if (stack_size < PTHREAD_STACK_MIN)
stack_size = PTHREAD_STACK_MIN;
#endif
@@ -35,7 +38,9 @@ support_small_thread_stack_size (void)
}
void
-support_set_small_thread_stack_size (pthread_attr_t *attr)
+support_set_small_thread_stack_size (pthread_attr_t *attr,
+ bool use_stack_min)
{
- xpthread_attr_setstacksize (attr, support_small_thread_stack_size ());
+ xpthread_attr_setstacksize
+ (attr, support_small_thread_stack_size (use_stack_min));
}
diff --git a/support/support_small_stack_thread_attribute.c b/support/support_small_stack_thread_attribute.c
index dd97e421464..229deabe9e4 100644
--- a/support/support_small_stack_thread_attribute.c
+++ b/support/support_small_stack_thread_attribute.c
@@ -24,7 +24,7 @@ allocate (void *closure)
{
pthread_attr_t *result = malloc (sizeof (*result));
xpthread_attr_init (result);
- support_set_small_thread_stack_size (result);
+ support_set_small_thread_stack_size (result, false);
return result;
}
diff --git a/support/xthread.h b/support/xthread.h
index d585bd0c3c6..3bdc6907aab 100644
--- a/support/xthread.h
+++ b/support/xthread.h
@@ -90,11 +90,13 @@ void xpthread_attr_setguardsize (pthread_attr_t *attr,
void xpthread_kill (pthread_t thr, int signo);
-/* Return the stack size used on support_set_small_thread_stack_size. */
-size_t support_small_thread_stack_size (void);
-/* Set the stack size in ATTR to a small value, but still large enough
- to cover most internal glibc stack usage. */
-void support_set_small_thread_stack_size (pthread_attr_t *attr);
+/* Return the stack size used on support_set_small_thread_stack_size,
+ or PTHREAD_STACK_MIN (if defined) is USE_STACK_MIN is set. */
+size_t support_small_thread_stack_size (bool use_stack_min);
+/* Set the stack size in ATTR to a small value. Use PTHREAD_STACK_MIN (if
+ defined) or a large enough to cover most internal glibc stack usage. */
+void support_set_small_thread_stack_size (pthread_attr_t *attr,
+ bool use_stack_min);
/* Return a pointer to a thread attribute which requests a small
stack. The caller must not free this pointer. */
diff --git a/sysdeps/unix/sysv/linux/tst-sem_getvalue-affinity.c b/sysdeps/unix/sysv/linux/tst-sem_getvalue-affinity.c
index c4c430edebd..f30e0bbed51 100644
--- a/sysdeps/unix/sysv/linux/tst-sem_getvalue-affinity.c
+++ b/sysdeps/unix/sysv/linux/tst-sem_getvalue-affinity.c
@@ -136,7 +136,7 @@ early_test (struct conf *conf)
printf ("error: pthread_attr_init failed: %s\n", strerror (ret));
return false;
}
- support_set_small_thread_stack_size (&attr);
+ support_set_small_thread_stack_size (&attr, false);
/* Spawn a thread pinned to each available CPU. */
for (int cpu = 0; cpu <= conf->last_cpu; ++cpu)
diff --git a/sysdeps/unix/sysv/linux/tst-skeleton-thread-affinity.c b/sysdeps/unix/sysv/linux/tst-skeleton-thread-affinity.c
index 323b2e0ffc4..4477fde150d 100644
--- a/sysdeps/unix/sysv/linux/tst-skeleton-thread-affinity.c
+++ b/sysdeps/unix/sysv/linux/tst-skeleton-thread-affinity.c
@@ -208,7 +208,7 @@ early_test (struct conf *conf)
printf ("error: pthread_attr_init failed: %s\n", strerror (ret));
return false;
}
- support_set_small_thread_stack_size (&attr);
+ support_set_small_thread_stack_size (&attr, false);
/* This count assumes that all the threads below are created
successfully, and call pthread_barrier_wait(). If any threads
--
2.43.0
More information about the Libc-alpha
mailing list