summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2018-07-27 12:05:00 -0400
committerRich Felker <dalias@aerifal.cx>2018-07-27 12:05:00 -0400
commit14992d4384990d40f6d3cfb799780fb696d77762 (patch)
tree5eb66dfe33b2908bc387f8801bbfbd1f256596e8 /src
parent3d8322c7ad659210a4c8770ef455ca729ce7f395 (diff)
downloadmusl-14992d4384990d40f6d3cfb799780fb696d77762.tar.gz
musl-14992d4384990d40f6d3cfb799780fb696d77762.tar.bz2
musl-14992d4384990d40f6d3cfb799780fb696d77762.tar.xz
musl-14992d4384990d40f6d3cfb799780fb696d77762.zip
make pthread_attr_init honor defaults set by pthread_setattr_default_np
this fixes a major gap in the intended functionality of pthread_setattr_default_np. if application/library code creating a thread does not pass a null attribute pointer to pthread_create, but sets up an attribute object to change other properties while leaving the stack alone, the created thread will get a stack with size DEFAULT_STACK_SIZE. this makes pthread_setattr_default_np useless for working around stack overflow issues in such applications, and leaves a major risk of regression if previously-working code switches from using a null attribute pointer to an attribute object. this change aligns the behavior more closely with the glibc pthread_setattr_default_np functionality too, albeit via a different mechanism. glibc encodes "default" specially in the attribute object and reads the actual default at thread creation time. with this commit, we now copy the current default into the attribute object at pthread_attr_init time, so that applications that query the properties of the attribute object will see the right values.
Diffstat (limited to 'src')
-rw-r--r--src/thread/default_attr.c4
-rw-r--r--src/thread/pthread_attr_init.c7
-rw-r--r--src/thread/pthread_create.c4
3 files changed, 11 insertions, 4 deletions
diff --git a/src/thread/default_attr.c b/src/thread/default_attr.c
new file mode 100644
index 00000000..46fe98ee
--- /dev/null
+++ b/src/thread/default_attr.c
@@ -0,0 +1,4 @@
+#include "pthread_impl.h"
+
+size_t __default_stacksize = DEFAULT_STACK_SIZE;
+size_t __default_guardsize = DEFAULT_GUARD_SIZE;
diff --git a/src/thread/pthread_attr_init.c b/src/thread/pthread_attr_init.c
index 8f6e3374..a962b460 100644
--- a/src/thread/pthread_attr_init.c
+++ b/src/thread/pthread_attr_init.c
@@ -1,9 +1,12 @@
#include "pthread_impl.h"
+extern size_t __default_stacksize;
+extern size_t __default_guardsize;
+
int pthread_attr_init(pthread_attr_t *a)
{
*a = (pthread_attr_t){0};
- a->_a_stacksize = DEFAULT_STACK_SIZE;
- a->_a_guardsize = DEFAULT_GUARD_SIZE;
+ a->_a_stacksize = __default_stacksize;
+ a->_a_guardsize = __default_guardsize;
return 0;
}
diff --git a/src/thread/pthread_create.c b/src/thread/pthread_create.c
index 2c066cff..2df2e9f9 100644
--- a/src/thread/pthread_create.c
+++ b/src/thread/pthread_create.c
@@ -165,8 +165,8 @@ static void *dummy_tsd[1] = { 0 };
weak_alias(dummy_tsd, __pthread_tsd_main);
volatile int __block_new_threads = 0;
-size_t __default_stacksize = DEFAULT_STACK_SIZE;
-size_t __default_guardsize = DEFAULT_GUARD_SIZE;
+extern size_t __default_stacksize;
+extern size_t __default_guardsize;
static FILE *volatile dummy_file = 0;
weak_alias(dummy_file, __stdin_used);