summaryrefslogtreecommitdiff
path: root/src/thread/pthread_setattr_default_np.c
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2016-11-08 12:09:05 -0500
committerRich Felker <dalias@aerifal.cx>2016-11-08 12:45:03 -0500
commit31fb174dd295e50f7c5cf18d31fcfd5fe5a063b7 (patch)
treed0cc757d2280d4711d40de2fa7ca3121593f11be /src/thread/pthread_setattr_default_np.c
parentea7891a651dc4abc1305438470f1e4cc3b64ece2 (diff)
downloadmusl-31fb174dd295e50f7c5cf18d31fcfd5fe5a063b7.tar.gz
add limited pthread_setattr_default_np API to set stack size defaults
based on patch by Timo Teräs: While generally this is a bad API, it is the only existing API to affect c++ (std::thread) and c11 (thrd_create) thread stack size. This patch allows applications only to increate stack and guard page sizes.
Diffstat (limited to 'src/thread/pthread_setattr_default_np.c')
-rw-r--r--src/thread/pthread_setattr_default_np.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/thread/pthread_setattr_default_np.c b/src/thread/pthread_setattr_default_np.c
new file mode 100644
index 00000000..ffd2712b
--- /dev/null
+++ b/src/thread/pthread_setattr_default_np.c
@@ -0,0 +1,35 @@
+#include "pthread_impl.h"
+#include <string.h>
+
+extern size_t __default_stacksize;
+extern size_t __default_guardsize;
+
+int pthread_setattr_default_np(const pthread_attr_t *attrp)
+{
+ /* Reject anything in the attr object other than stack/guard size. */
+ pthread_attr_t tmp = *attrp, zero = { 0 };
+ tmp._a_stacksize = 0;
+ tmp._a_guardsize = 0;
+ if (memcmp(&tmp, &zero, sizeof tmp))
+ return EINVAL;
+
+ __inhibit_ptc();
+ if (attrp->_a_stacksize >= __default_stacksize)
+ __default_stacksize = attrp->_a_stacksize;
+ if (attrp->_a_guardsize >= __default_guardsize)
+ __default_guardsize = attrp->_a_guardsize;
+ __release_ptc();
+
+ return 0;
+}
+
+int pthread_getattr_default_np(pthread_attr_t *attrp)
+{
+ __acquire_ptc();
+ *attrp = (pthread_attr_t) {
+ ._a_stacksize = __default_stacksize,
+ ._a_guardsize = __default_guardsize,
+ };
+ __release_ptc();
+ return 0;
+}