aboutsummaryrefslogtreecommitdiff
path: root/nptl
diff options
context:
space:
mode:
authorFlorian Weimer <fweimer@redhat.com>2020-05-18 18:25:18 +0200
committerFlorian Weimer <fweimer@redhat.com>2020-06-02 10:32:37 +0200
commitc2322a561f74b8fa41b9d9c6b8eb57e28de46f3e (patch)
tree85673d97ee3c4a1d79d67e3e267a12c63cf7946f /nptl
parent86ed0774cf0de1d281ca3c773758c9fe6f2784b4 (diff)
downloadglibc-c2322a561f74b8fa41b9d9c6b8eb57e28de46f3e.zip
glibc-c2322a561f74b8fa41b9d9c6b8eb57e28de46f3e.tar.gz
glibc-c2322a561f74b8fa41b9d9c6b8eb57e28de46f3e.tar.bz2
nptl: Change type of __default_pthread_attr
union pthread_attr_transparent has always the correct size, even if pthread_attr_t has padding that is not present in struct pthread_attr. This should not result in an observable behavioral change. The existing code appears to have been correct, but it was brittle because it was not clear which functions were allowed to write to an entire pthread_attr_t argument (e.g., by copying it). Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Diffstat (limited to 'nptl')
-rw-r--r--nptl/allocatestack.c2
-rw-r--r--nptl/nptl-init.c4
-rw-r--r--nptl/pthreadP.h2
-rw-r--r--nptl/pthread_attr_getstacksize.c2
-rw-r--r--nptl/pthread_create.c8
-rw-r--r--nptl/pthread_getattr_default_np.c3
-rw-r--r--nptl/pthread_setattr_default_np.c6
-rw-r--r--nptl/vars.c2
8 files changed, 14 insertions, 15 deletions
diff --git a/nptl/allocatestack.c b/nptl/allocatestack.c
index c94980c..d16f3d7 100644
--- a/nptl/allocatestack.c
+++ b/nptl/allocatestack.c
@@ -425,7 +425,7 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp,
else
{
lll_lock (__default_pthread_attr_lock, LLL_PRIVATE);
- size = __default_pthread_attr.stacksize;
+ size = __default_pthread_attr.internal.stacksize;
lll_unlock (__default_pthread_attr_lock, LLL_PRIVATE);
}
diff --git a/nptl/nptl-init.c b/nptl/nptl-init.c
index 96b1444..d4cf20e 100644
--- a/nptl/nptl-init.c
+++ b/nptl/nptl-init.c
@@ -318,8 +318,8 @@ __pthread_initialize_minimal_internal (void)
/* Round the resource limit up to page size. */
limit.rlim_cur = ALIGN_UP (limit.rlim_cur, pagesz);
lll_lock (__default_pthread_attr_lock, LLL_PRIVATE);
- __default_pthread_attr.stacksize = limit.rlim_cur;
- __default_pthread_attr.guardsize = GLRO (dl_pagesize);
+ __default_pthread_attr.internal.stacksize = limit.rlim_cur;
+ __default_pthread_attr.internal.guardsize = GLRO (dl_pagesize);
lll_unlock (__default_pthread_attr_lock, LLL_PRIVATE);
#ifdef SHARED
diff --git a/nptl/pthreadP.h b/nptl/pthreadP.h
index 9c6dd41..acc8e88 100644
--- a/nptl/pthreadP.h
+++ b/nptl/pthreadP.h
@@ -199,7 +199,7 @@ enum
/* Default pthread attributes. */
-extern struct pthread_attr __default_pthread_attr attribute_hidden;
+extern union pthread_attr_transparent __default_pthread_attr attribute_hidden;
extern int __default_pthread_attr_lock attribute_hidden;
/* Size and alignment of static TLS block. */
diff --git a/nptl/pthread_attr_getstacksize.c b/nptl/pthread_attr_getstacksize.c
index 346b375..9830a63 100644
--- a/nptl/pthread_attr_getstacksize.c
+++ b/nptl/pthread_attr_getstacksize.c
@@ -33,7 +33,7 @@ __pthread_attr_getstacksize (const pthread_attr_t *attr, size_t *stacksize)
if (size == 0)
{
lll_lock (__default_pthread_attr_lock, LLL_PRIVATE);
- size = __default_pthread_attr.stacksize;
+ size = __default_pthread_attr.internal.stacksize;
lll_unlock (__default_pthread_attr_lock, LLL_PRIVATE);
}
*stacksize = size;
diff --git a/nptl/pthread_create.c b/nptl/pthread_create.c
index 347d510..86fbeb5 100644
--- a/nptl/pthread_create.c
+++ b/nptl/pthread_create.c
@@ -612,16 +612,16 @@ __pthread_create_2_1 (pthread_t *newthread, const pthread_attr_t *attr,
STACK_VARIABLES;
const struct pthread_attr *iattr = (struct pthread_attr *) attr;
- struct pthread_attr default_attr;
+ union pthread_attr_transparent default_attr;
bool destroy_default_attr = false;
bool c11 = (attr == ATTR_C11_THREAD);
if (iattr == NULL || c11)
{
- int ret = __pthread_getattr_default_np ((pthread_attr_t *) &default_attr);
+ int ret = __pthread_getattr_default_np (&default_attr.external);
if (ret != 0)
return ret;
destroy_default_attr = true;
- iattr = &default_attr;
+ iattr = &default_attr.internal;
}
struct pthread *pd = NULL;
@@ -852,7 +852,7 @@ __pthread_create_2_1 (pthread_t *newthread, const pthread_attr_t *attr,
out:
if (destroy_default_attr)
- __pthread_attr_destroy ((pthread_attr_t *) &default_attr);
+ __pthread_attr_destroy (&default_attr.external);
return retval;
}
diff --git a/nptl/pthread_getattr_default_np.c b/nptl/pthread_getattr_default_np.c
index 5c99f98..f3ce1c2 100644
--- a/nptl/pthread_getattr_default_np.c
+++ b/nptl/pthread_getattr_default_np.c
@@ -22,8 +22,7 @@ int
__pthread_getattr_default_np (pthread_attr_t *out)
{
lll_lock (__default_pthread_attr_lock, LLL_PRIVATE);
- int ret = __pthread_attr_copy (out,
- (pthread_attr_t *) &__default_pthread_attr);
+ int ret = __pthread_attr_copy (out, &__default_pthread_attr.external);
lll_unlock (__default_pthread_attr_lock, LLL_PRIVATE);
return ret;
}
diff --git a/nptl/pthread_setattr_default_np.c b/nptl/pthread_setattr_default_np.c
index eb5d24d..c4cfb4e 100644
--- a/nptl/pthread_setattr_default_np.c
+++ b/nptl/pthread_setattr_default_np.c
@@ -68,15 +68,15 @@ pthread_setattr_default_np (const pthread_attr_t *in)
/* Preserve the previous stack size (see above). */
if (temp.internal.stacksize == 0)
- temp.internal.stacksize = __default_pthread_attr.stacksize;
+ temp.internal.stacksize = __default_pthread_attr.internal.stacksize;
/* Destroy the old attribute structure because it will be
overwritten. */
- __pthread_attr_destroy ((pthread_attr_t *) &__default_pthread_attr);
+ __pthread_attr_destroy (&__default_pthread_attr.external);
/* __default_pthread_attr takes ownership, so do not free
attrs.internal after this point. */
- __default_pthread_attr = temp.internal;
+ __default_pthread_attr = temp;
lll_unlock (__default_pthread_attr_lock, LLL_PRIVATE);
return ret;
diff --git a/nptl/vars.c b/nptl/vars.c
index b88300d..3696020 100644
--- a/nptl/vars.c
+++ b/nptl/vars.c
@@ -22,7 +22,7 @@
/* Default thread attributes for the case when the user does not
provide any. */
-struct pthread_attr __default_pthread_attr attribute_hidden;
+union pthread_attr_transparent __default_pthread_attr attribute_hidden;
/* Mutex protecting __default_pthread_attr. */
int __default_pthread_attr_lock = LLL_LOCK_INITIALIZER;