diff options
author | Rich Felker <dalias@aerifal.cx> | 2018-09-18 23:06:50 -0400 |
---|---|---|
committer | Rich Felker <dalias@aerifal.cx> | 2018-09-18 23:06:50 -0400 |
commit | 792f32772e64a32527cd455ebfa087ef434a6f4f (patch) | |
tree | 529bab8e8047cdd70f64a4113fb4bc1932180964 /src/thread/pthread_setattr_default_np.c | |
parent | c7ed3e909a69d34a7821f7db644c2fa590a1a690 (diff) | |
download | musl-792f32772e64a32527cd455ebfa087ef434a6f4f.tar.gz musl-792f32772e64a32527cd455ebfa087ef434a6f4f.tar.bz2 musl-792f32772e64a32527cd455ebfa087ef434a6f4f.tar.xz musl-792f32772e64a32527cd455ebfa087ef434a6f4f.zip |
limit the configurable default stack/guard size for threads
limit to 8MB/1MB, repectively. since the defaults cannot be reduced
once increased, excessively large settings would lead to an
unrecoverably broken state. this change is in preparation to allow
defaults to be increased via program headers at the linker level.
creation of threads that really need larger sizes needs to be done
with an explicit attribute.
Diffstat (limited to 'src/thread/pthread_setattr_default_np.c')
-rw-r--r-- | src/thread/pthread_setattr_default_np.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/thread/pthread_setattr_default_np.c b/src/thread/pthread_setattr_default_np.c index 256f0685..58486220 100644 --- a/src/thread/pthread_setattr_default_np.c +++ b/src/thread/pthread_setattr_default_np.c @@ -2,6 +2,9 @@ #include "pthread_impl.h" #include <string.h> +#define MIN(a,b) ((a)<(b) ? (a) : (b)) +#define MAX(a,b) ((a)>(b) ? (a) : (b)) + int pthread_setattr_default_np(const pthread_attr_t *attrp) { /* Reject anything in the attr object other than stack/guard size. */ @@ -11,11 +14,12 @@ int pthread_setattr_default_np(const pthread_attr_t *attrp) if (memcmp(&tmp, &zero, sizeof tmp)) return EINVAL; + unsigned stack = MIN(attrp->_a_stacksize, DEFAULT_STACK_MAX); + unsigned guard = MIN(attrp->_a_guardsize, DEFAULT_GUARD_MAX); + __inhibit_ptc(); - if (attrp->_a_stacksize >= __default_stacksize) - __default_stacksize = attrp->_a_stacksize; - if (attrp->_a_guardsize >= __default_guardsize) - __default_guardsize = attrp->_a_guardsize; + __default_stacksize = MAX(__default_stacksize, stack); + __default_guardsize = MAX(__default_guardsize, guard); __release_ptc(); return 0; |