Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libpthread Use the pta_magic field in pthread attribute



details:   https://anonhg.NetBSD.org/src/rev/f32830b90592
branches:  trunk
changeset: 1006859:f32830b90592
user:      kamil <kamil%NetBSD.org@localhost>
date:      Wed Jan 29 13:47:31 2020 +0000

description:
Use the pta_magic field in pthread attribute

Set PT_ATTR_DEAD on pthread_attr_destroy().
Check pta_magic before using pthread_attr_t in a bunch of other functions.

diffstat:

 lib/libpthread/pthread_attr.c |  76 +++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 74 insertions(+), 2 deletions(-)

diffs (261 lines):

diff -r 6c52d6a5df5f -r f32830b90592 lib/libpthread/pthread_attr.c
--- a/lib/libpthread/pthread_attr.c     Wed Jan 29 13:40:23 2020 +0000
+++ b/lib/libpthread/pthread_attr.c     Wed Jan 29 13:47:31 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pthread_attr.c,v 1.18 2017/08/01 12:31:45 martin Exp $ */
+/*     $NetBSD: pthread_attr.c,v 1.19 2020/01/29 13:47:31 kamil Exp $  */
 
 /*-
  * Copyright (c) 2001, 2002, 2003, 2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: pthread_attr.c,v 1.18 2017/08/01 12:31:45 martin Exp $");
+__RCSID("$NetBSD: pthread_attr.c,v 1.19 2020/01/29 13:47:31 kamil Exp $");
 
 #include <errno.h>
 #include <stdio.h>
@@ -86,9 +86,14 @@
 {
        struct pthread_attr_private *p;
 
+       pthread__error(EINVAL, "Invalid attribute",
+           attr->pta_magic == PT_ATTR_MAGIC);
+
        if ((p = attr->pta_private) != NULL)
                free(p);
 
+       attr->pta_magic = PT_ATTR_DEAD;
+
        return 0;
 }
 
@@ -98,6 +103,9 @@
 {
        struct pthread_attr_private *p;
 
+       pthread__error(EINVAL, "Invalid attribute",
+           attr->pta_magic == PT_ATTR_MAGIC);
+
        p = pthread__attr_init_private(attr);
        if (p == NULL)
                return ENOMEM;
@@ -117,6 +125,9 @@
 pthread_attr_getdetachstate(const pthread_attr_t *attr, int *detachstate)
 {
 
+       pthread__error(EINVAL, "Invalid attribute",
+           attr->pta_magic == PT_ATTR_MAGIC);
+
        if (attr->pta_flags & PT_FLAG_DETACHED)
                *detachstate = PTHREAD_CREATE_DETACHED;
        else
@@ -130,6 +141,9 @@
 pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate)
 {
 
+       pthread__error(EINVAL, "Invalid attribute",
+           attr->pta_magic == PT_ATTR_MAGIC);
+
        switch (detachstate) {
        case PTHREAD_CREATE_JOINABLE:
                attr->pta_flags &= ~PT_FLAG_DETACHED;
@@ -150,6 +164,9 @@
 {
        struct pthread_attr_private *p;
 
+       pthread__error(EINVAL, "Invalid attribute",
+           attr->pta_magic == PT_ATTR_MAGIC);
+
        if ((p = attr->pta_private) == NULL)
                *guard = pthread__guardsize;
        else
@@ -164,6 +181,9 @@
 {
        struct pthread_attr_private *p;
 
+       pthread__error(EINVAL, "Invalid attribute",
+           attr->pta_magic == PT_ATTR_MAGIC);
+
        p = pthread__attr_init_private(attr);
        if (p == NULL)
                return ENOMEM;
@@ -178,6 +198,9 @@
 pthread_attr_getinheritsched(const pthread_attr_t *attr, int *inherit)
 {
 
+       pthread__error(EINVAL, "Invalid attribute",
+           attr->pta_magic == PT_ATTR_MAGIC);
+
        if (attr->pta_flags & PT_FLAG_EXPLICIT_SCHED)
                *inherit = PTHREAD_EXPLICIT_SCHED;
        else
@@ -191,6 +214,9 @@
 pthread_attr_setinheritsched(pthread_attr_t *attr, int inherit)
 {
 
+       pthread__error(EINVAL, "Invalid attribute",
+           attr->pta_magic == PT_ATTR_MAGIC);
+
        switch (inherit) {
        case PTHREAD_INHERIT_SCHED:
                attr->pta_flags &= ~PT_FLAG_EXPLICIT_SCHED;
@@ -210,6 +236,9 @@
 pthread_attr_getscope(const pthread_attr_t *attr, int *scope)
 {
 
+       pthread__error(EINVAL, "Invalid attribute",
+           attr->pta_magic == PT_ATTR_MAGIC);
+
        if (attr->pta_flags & PT_FLAG_SCOPE_SYSTEM)
                *scope = PTHREAD_SCOPE_SYSTEM;
        else
@@ -223,6 +252,9 @@
 pthread_attr_setscope(pthread_attr_t *attr, int scope)
 {
 
+       pthread__error(EINVAL, "Invalid attribute",
+           attr->pta_magic == PT_ATTR_MAGIC);
+
        switch (scope) {
        case PTHREAD_SCOPE_PROCESS:
                attr->pta_flags &= ~PT_FLAG_SCOPE_SYSTEM;
@@ -245,6 +277,9 @@
        struct pthread_attr_private *p;
        int error;
 
+       pthread__error(EINVAL, "Invalid attribute",
+           attr->pta_magic == PT_ATTR_MAGIC);
+
        if (param == NULL)
                return EINVAL;
        p = pthread__attr_init_private(attr);
@@ -263,6 +298,9 @@
 {
        struct pthread_attr_private *p;
 
+       pthread__error(EINVAL, "Invalid attribute",
+           attr->pta_magic == PT_ATTR_MAGIC);
+
        if (param == NULL)
                return EINVAL;
        p = attr->pta_private;
@@ -279,6 +317,8 @@
 {
        struct pthread_attr_private *p;
 
+       pthread__error(EINVAL, "Invalid attribute",
+           attr->pta_magic == PT_ATTR_MAGIC);
 
        switch (policy) {
        case SCHED_OTHER:
@@ -300,6 +340,9 @@
 {
        struct pthread_attr_private *p;
 
+       pthread__error(EINVAL, "Invalid attribute",
+           attr->pta_magic == PT_ATTR_MAGIC);
+
        p = attr->pta_private;
        if (p == NULL) {
                *policy = SCHED_OTHER;
@@ -315,6 +358,9 @@
 {
        struct pthread_attr_private *p;
 
+       pthread__error(EINVAL, "Invalid attribute",
+           attr->pta_magic == PT_ATTR_MAGIC);
+
        if ((p = attr->pta_private) == NULL) {
                *addr = NULL;
                *size = pthread__stacksize;
@@ -332,6 +378,9 @@
 {
        struct pthread_attr_private *p;
 
+       pthread__error(EINVAL, "Invalid attribute",
+           attr->pta_magic == PT_ATTR_MAGIC);
+
        p = pthread__attr_init_private(attr);
        if (p == NULL)
                return ENOMEM;
@@ -348,6 +397,9 @@
 {
        struct pthread_attr_private *p;
 
+       pthread__error(EINVAL, "Invalid attribute",
+           attr->pta_magic == PT_ATTR_MAGIC);
+
        if ((p = attr->pta_private) == NULL)
                *size = pthread__stacksize;
        else
@@ -362,6 +414,9 @@
 {
        struct pthread_attr_private *p;
 
+       pthread__error(EINVAL, "Invalid attribute",
+           attr->pta_magic == PT_ATTR_MAGIC);
+
        if (size < (size_t)sysconf(_SC_THREAD_STACK_MIN))
                return EINVAL;
 
@@ -380,6 +435,9 @@
 {
        struct pthread_attr_private *p;
 
+       pthread__error(EINVAL, "Invalid attribute",
+           attr->pta_magic == PT_ATTR_MAGIC);
+
        if ((p = attr->pta_private) == NULL)
                *addr = NULL;
        else
@@ -394,6 +452,9 @@
 {
        struct pthread_attr_private *p;
 
+       pthread__error(EINVAL, "Invalid attribute",
+           attr->pta_magic == PT_ATTR_MAGIC);
+
        p = pthread__attr_init_private(attr);
        if (p == NULL)
                return ENOMEM;
@@ -410,6 +471,9 @@
 {
        struct pthread_attr_private *p;
 
+       pthread__error(EINVAL, "Invalid attribute",
+           attr->pta_magic == PT_ATTR_MAGIC);
+
        if ((p = attr->pta_private) == NULL) {
                name[0] = '\0';
                if (argp != NULL)
@@ -430,6 +494,9 @@
        struct pthread_attr_private *p;
        int namelen;
 
+       pthread__error(EINVAL, "Invalid attribute",
+           attr->pta_magic == PT_ATTR_MAGIC);
+
        p = pthread__attr_init_private(attr);
        if (p == NULL)
                return ENOMEM;
@@ -447,6 +514,10 @@
 int
 pthread_attr_setcreatesuspend_np(pthread_attr_t *attr)
 {
+
+       pthread__error(EINVAL, "Invalid attribute",
+           attr->pta_magic == PT_ATTR_MAGIC);
+
        attr->pta_flags |= PT_FLAG_SUSPENDED;
        return 0;
 }
@@ -455,6 +526,7 @@
 pthread_getattr_np(pthread_t thread, pthread_attr_t *attr)
 {
        int error;
+
        if ((error = pthread_attr_init(attr)) != 0)
                return error;
        if ((error = pthread_attr_get_np(thread, attr)) != 0) {



Home | Main Index | Thread Index | Old Index