Home | History | Annotate | Line # | Download | only in libpthread
pthread_attr.c revision 1.18.4.1
      1  1.18.4.1    martin /*	$NetBSD: pthread_attr.c,v 1.18.4.1 2020/04/08 14:07:15 martin Exp $	*/
      2       1.1   nathanw 
      3       1.1   nathanw /*-
      4      1.10        ad  * Copyright (c) 2001, 2002, 2003, 2008 The NetBSD Foundation, Inc.
      5       1.1   nathanw  * All rights reserved.
      6       1.1   nathanw  *
      7       1.1   nathanw  * This code is derived from software contributed to The NetBSD Foundation
      8       1.1   nathanw  * by Nathan J. Williams.
      9       1.1   nathanw  *
     10       1.1   nathanw  * Redistribution and use in source and binary forms, with or without
     11       1.1   nathanw  * modification, are permitted provided that the following conditions
     12       1.1   nathanw  * are met:
     13       1.1   nathanw  * 1. Redistributions of source code must retain the above copyright
     14       1.1   nathanw  *    notice, this list of conditions and the following disclaimer.
     15       1.1   nathanw  * 2. Redistributions in binary form must reproduce the above copyright
     16       1.1   nathanw  *    notice, this list of conditions and the following disclaimer in the
     17       1.1   nathanw  *    documentation and/or other materials provided with the distribution.
     18       1.1   nathanw  *
     19       1.1   nathanw  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20       1.1   nathanw  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21       1.1   nathanw  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22       1.1   nathanw  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23       1.1   nathanw  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24       1.1   nathanw  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25       1.1   nathanw  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26       1.1   nathanw  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27       1.1   nathanw  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28       1.1   nathanw  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29       1.1   nathanw  * POSSIBILITY OF SUCH DAMAGE.
     30       1.1   nathanw  */
     31       1.1   nathanw 
     32       1.1   nathanw #include <sys/cdefs.h>
     33  1.18.4.1    martin __RCSID("$NetBSD: pthread_attr.c,v 1.18.4.1 2020/04/08 14:07:15 martin Exp $");
     34       1.1   nathanw 
     35       1.1   nathanw #include <errno.h>
     36       1.1   nathanw #include <stdio.h>
     37       1.1   nathanw #include <stdlib.h>
     38       1.1   nathanw #include <string.h>
     39       1.1   nathanw #include <unistd.h>
     40       1.1   nathanw 
     41      1.14  christos #ifndef __lint__
     42      1.14  christos #define pthread_attr_get_np _pthread_attr_get_np
     43      1.14  christos #endif
     44      1.14  christos 
     45      1.15  christos #include "pthread.h"
     46      1.15  christos #include "pthread_int.h"
     47      1.15  christos 
     48      1.14  christos __weak_alias(pthread_attr_get_np, _pthread_attr_get_np)
     49      1.14  christos 
     50       1.7  christos static struct pthread_attr_private *pthread__attr_init_private(
     51       1.7  christos     pthread_attr_t *);
     52       1.1   nathanw 
     53       1.1   nathanw static struct pthread_attr_private *
     54       1.1   nathanw pthread__attr_init_private(pthread_attr_t *attr)
     55       1.1   nathanw {
     56       1.1   nathanw 	struct pthread_attr_private *p;
     57       1.1   nathanw 
     58       1.1   nathanw 	if ((p = attr->pta_private) != NULL)
     59       1.1   nathanw 		return p;
     60       1.1   nathanw 
     61      1.18    martin 	p = calloc(1, sizeof(*p));
     62       1.1   nathanw 	if (p != NULL) {
     63       1.1   nathanw 		attr->pta_private = p;
     64      1.10        ad 		p->ptap_policy = SCHED_OTHER;
     65      1.18    martin 		p->ptap_stacksize = pthread__stacksize;
     66      1.18    martin 		p->ptap_guardsize = pthread__guardsize;
     67       1.1   nathanw 	}
     68       1.1   nathanw 	return p;
     69       1.1   nathanw }
     70       1.1   nathanw 
     71       1.1   nathanw 
     72       1.1   nathanw int
     73       1.1   nathanw pthread_attr_init(pthread_attr_t *attr)
     74       1.1   nathanw {
     75       1.1   nathanw 
     76       1.1   nathanw 	attr->pta_magic = PT_ATTR_MAGIC;
     77       1.1   nathanw 	attr->pta_flags = 0;
     78       1.1   nathanw 	attr->pta_private = NULL;
     79       1.1   nathanw 
     80       1.1   nathanw 	return 0;
     81       1.1   nathanw }
     82       1.1   nathanw 
     83       1.1   nathanw 
     84       1.1   nathanw int
     85       1.1   nathanw pthread_attr_destroy(pthread_attr_t *attr)
     86       1.1   nathanw {
     87       1.1   nathanw 	struct pthread_attr_private *p;
     88       1.1   nathanw 
     89  1.18.4.1    martin 	pthread__error(EINVAL, "Invalid attribute",
     90  1.18.4.1    martin 	    attr->pta_magic == PT_ATTR_MAGIC);
     91  1.18.4.1    martin 
     92       1.1   nathanw 	if ((p = attr->pta_private) != NULL)
     93       1.1   nathanw 		free(p);
     94       1.1   nathanw 
     95  1.18.4.1    martin 	attr->pta_magic = PT_ATTR_DEAD;
     96  1.18.4.1    martin 
     97       1.1   nathanw 	return 0;
     98       1.1   nathanw }
     99       1.1   nathanw 
    100       1.1   nathanw 
    101       1.1   nathanw int
    102       1.1   nathanw pthread_attr_get_np(pthread_t thread, pthread_attr_t *attr)
    103       1.1   nathanw {
    104       1.1   nathanw 	struct pthread_attr_private *p;
    105       1.1   nathanw 
    106  1.18.4.1    martin 	pthread__error(EINVAL, "Invalid attribute",
    107  1.18.4.1    martin 	    attr->pta_magic == PT_ATTR_MAGIC);
    108  1.18.4.1    martin 
    109       1.1   nathanw 	p = pthread__attr_init_private(attr);
    110       1.1   nathanw 	if (p == NULL)
    111       1.1   nathanw 		return ENOMEM;
    112       1.1   nathanw 
    113       1.1   nathanw 	attr->pta_flags = thread->pt_flags &
    114       1.1   nathanw 	    (PT_FLAG_DETACHED | PT_FLAG_SCOPE_SYSTEM | PT_FLAG_EXPLICIT_SCHED);
    115       1.1   nathanw 
    116       1.1   nathanw 	p->ptap_namearg = thread->pt_name;
    117       1.1   nathanw 	p->ptap_stackaddr = thread->pt_stack.ss_sp;
    118       1.1   nathanw 	p->ptap_stacksize = thread->pt_stack.ss_size;
    119      1.17     joerg 	p->ptap_guardsize = thread->pt_guardsize;
    120      1.10        ad 	return pthread_getschedparam(thread, &p->ptap_policy, &p->ptap_sp);
    121       1.1   nathanw }
    122       1.1   nathanw 
    123       1.1   nathanw 
    124       1.1   nathanw int
    125       1.1   nathanw pthread_attr_getdetachstate(const pthread_attr_t *attr, int *detachstate)
    126       1.1   nathanw {
    127       1.1   nathanw 
    128  1.18.4.1    martin 	pthread__error(EINVAL, "Invalid attribute",
    129  1.18.4.1    martin 	    attr->pta_magic == PT_ATTR_MAGIC);
    130  1.18.4.1    martin 
    131       1.1   nathanw 	if (attr->pta_flags & PT_FLAG_DETACHED)
    132       1.1   nathanw 		*detachstate = PTHREAD_CREATE_DETACHED;
    133       1.1   nathanw 	else
    134       1.1   nathanw 		*detachstate = PTHREAD_CREATE_JOINABLE;
    135       1.1   nathanw 
    136       1.1   nathanw 	return 0;
    137       1.1   nathanw }
    138       1.1   nathanw 
    139       1.1   nathanw 
    140       1.1   nathanw int
    141       1.1   nathanw pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate)
    142       1.1   nathanw {
    143       1.1   nathanw 
    144  1.18.4.1    martin 	pthread__error(EINVAL, "Invalid attribute",
    145  1.18.4.1    martin 	    attr->pta_magic == PT_ATTR_MAGIC);
    146  1.18.4.1    martin 
    147       1.1   nathanw 	switch (detachstate) {
    148       1.1   nathanw 	case PTHREAD_CREATE_JOINABLE:
    149       1.1   nathanw 		attr->pta_flags &= ~PT_FLAG_DETACHED;
    150       1.1   nathanw 		break;
    151       1.1   nathanw 	case PTHREAD_CREATE_DETACHED:
    152       1.1   nathanw 		attr->pta_flags |= PT_FLAG_DETACHED;
    153       1.1   nathanw 		break;
    154       1.1   nathanw 	default:
    155       1.1   nathanw 		return EINVAL;
    156       1.1   nathanw 	}
    157       1.1   nathanw 
    158       1.1   nathanw 	return 0;
    159       1.1   nathanw }
    160       1.1   nathanw 
    161       1.1   nathanw 
    162       1.1   nathanw int
    163       1.1   nathanw pthread_attr_getguardsize(const pthread_attr_t *attr, size_t *guard)
    164       1.1   nathanw {
    165       1.1   nathanw 	struct pthread_attr_private *p;
    166       1.1   nathanw 
    167  1.18.4.1    martin 	pthread__error(EINVAL, "Invalid attribute",
    168  1.18.4.1    martin 	    attr->pta_magic == PT_ATTR_MAGIC);
    169  1.18.4.1    martin 
    170       1.1   nathanw 	if ((p = attr->pta_private) == NULL)
    171      1.17     joerg 		*guard = pthread__guardsize;
    172       1.1   nathanw 	else
    173       1.1   nathanw 		*guard = p->ptap_guardsize;
    174       1.1   nathanw 
    175       1.1   nathanw 	return 0;
    176       1.1   nathanw }
    177       1.1   nathanw 
    178       1.1   nathanw 
    179       1.1   nathanw int
    180       1.1   nathanw pthread_attr_setguardsize(pthread_attr_t *attr, size_t guard)
    181       1.1   nathanw {
    182       1.1   nathanw 	struct pthread_attr_private *p;
    183       1.1   nathanw 
    184  1.18.4.1    martin 	pthread__error(EINVAL, "Invalid attribute",
    185  1.18.4.1    martin 	    attr->pta_magic == PT_ATTR_MAGIC);
    186  1.18.4.1    martin 
    187       1.1   nathanw 	p = pthread__attr_init_private(attr);
    188       1.1   nathanw 	if (p == NULL)
    189       1.1   nathanw 		return ENOMEM;
    190       1.1   nathanw 
    191       1.1   nathanw 	p->ptap_guardsize = guard;
    192       1.1   nathanw 
    193       1.1   nathanw 	return 0;
    194       1.1   nathanw }
    195       1.1   nathanw 
    196       1.1   nathanw 
    197       1.1   nathanw int
    198       1.1   nathanw pthread_attr_getinheritsched(const pthread_attr_t *attr, int *inherit)
    199       1.1   nathanw {
    200       1.1   nathanw 
    201  1.18.4.1    martin 	pthread__error(EINVAL, "Invalid attribute",
    202  1.18.4.1    martin 	    attr->pta_magic == PT_ATTR_MAGIC);
    203  1.18.4.1    martin 
    204       1.1   nathanw 	if (attr->pta_flags & PT_FLAG_EXPLICIT_SCHED)
    205       1.1   nathanw 		*inherit = PTHREAD_EXPLICIT_SCHED;
    206       1.1   nathanw 	else
    207       1.1   nathanw 		*inherit = PTHREAD_INHERIT_SCHED;
    208       1.1   nathanw 
    209       1.1   nathanw 	return 0;
    210       1.1   nathanw }
    211       1.1   nathanw 
    212       1.1   nathanw 
    213       1.1   nathanw int
    214       1.1   nathanw pthread_attr_setinheritsched(pthread_attr_t *attr, int inherit)
    215       1.1   nathanw {
    216       1.1   nathanw 
    217  1.18.4.1    martin 	pthread__error(EINVAL, "Invalid attribute",
    218  1.18.4.1    martin 	    attr->pta_magic == PT_ATTR_MAGIC);
    219  1.18.4.1    martin 
    220       1.1   nathanw 	switch (inherit) {
    221       1.1   nathanw 	case PTHREAD_INHERIT_SCHED:
    222       1.1   nathanw 		attr->pta_flags &= ~PT_FLAG_EXPLICIT_SCHED;
    223       1.1   nathanw 		break;
    224       1.1   nathanw 	case PTHREAD_EXPLICIT_SCHED:
    225       1.1   nathanw 		attr->pta_flags |= PT_FLAG_EXPLICIT_SCHED;
    226       1.1   nathanw 		break;
    227       1.1   nathanw 	default:
    228       1.1   nathanw 		return EINVAL;
    229       1.1   nathanw 	}
    230       1.1   nathanw 
    231       1.1   nathanw 	return 0;
    232       1.1   nathanw }
    233       1.1   nathanw 
    234       1.1   nathanw 
    235       1.1   nathanw int
    236       1.1   nathanw pthread_attr_getscope(const pthread_attr_t *attr, int *scope)
    237       1.1   nathanw {
    238       1.1   nathanw 
    239  1.18.4.1    martin 	pthread__error(EINVAL, "Invalid attribute",
    240  1.18.4.1    martin 	    attr->pta_magic == PT_ATTR_MAGIC);
    241  1.18.4.1    martin 
    242       1.1   nathanw 	if (attr->pta_flags & PT_FLAG_SCOPE_SYSTEM)
    243       1.1   nathanw 		*scope = PTHREAD_SCOPE_SYSTEM;
    244       1.1   nathanw 	else
    245       1.1   nathanw 		*scope = PTHREAD_SCOPE_PROCESS;
    246       1.1   nathanw 
    247       1.1   nathanw 	return 0;
    248       1.1   nathanw }
    249       1.1   nathanw 
    250       1.1   nathanw 
    251       1.1   nathanw int
    252       1.1   nathanw pthread_attr_setscope(pthread_attr_t *attr, int scope)
    253       1.1   nathanw {
    254       1.1   nathanw 
    255  1.18.4.1    martin 	pthread__error(EINVAL, "Invalid attribute",
    256  1.18.4.1    martin 	    attr->pta_magic == PT_ATTR_MAGIC);
    257  1.18.4.1    martin 
    258       1.1   nathanw 	switch (scope) {
    259       1.1   nathanw 	case PTHREAD_SCOPE_PROCESS:
    260       1.1   nathanw 		attr->pta_flags &= ~PT_FLAG_SCOPE_SYSTEM;
    261       1.1   nathanw 		break;
    262       1.1   nathanw 	case PTHREAD_SCOPE_SYSTEM:
    263       1.1   nathanw 		attr->pta_flags |= PT_FLAG_SCOPE_SYSTEM;
    264       1.1   nathanw 		break;
    265       1.1   nathanw 	default:
    266       1.1   nathanw 		return EINVAL;
    267       1.1   nathanw 	}
    268       1.1   nathanw 
    269       1.1   nathanw 	return 0;
    270       1.1   nathanw }
    271       1.1   nathanw 
    272       1.1   nathanw 
    273       1.1   nathanw int
    274       1.1   nathanw pthread_attr_setschedparam(pthread_attr_t *attr,
    275      1.10        ad 			   const struct sched_param *param)
    276       1.1   nathanw {
    277      1.10        ad 	struct pthread_attr_private *p;
    278      1.10        ad 	int error;
    279       1.1   nathanw 
    280  1.18.4.1    martin 	pthread__error(EINVAL, "Invalid attribute",
    281  1.18.4.1    martin 	    attr->pta_magic == PT_ATTR_MAGIC);
    282  1.18.4.1    martin 
    283       1.1   nathanw 	if (param == NULL)
    284       1.1   nathanw 		return EINVAL;
    285      1.10        ad 	p = pthread__attr_init_private(attr);
    286      1.10        ad 	if (p == NULL)
    287      1.10        ad 		return ENOMEM;
    288      1.10        ad 	error = pthread__checkpri(param->sched_priority);
    289      1.10        ad 	if (error == 0)
    290      1.10        ad 		p->ptap_sp = *param;
    291      1.10        ad 	return error;
    292       1.1   nathanw }
    293       1.1   nathanw 
    294       1.1   nathanw 
    295       1.1   nathanw int
    296       1.1   nathanw pthread_attr_getschedparam(const pthread_attr_t *attr,
    297      1.10        ad 			   struct sched_param *param)
    298       1.1   nathanw {
    299      1.10        ad 	struct pthread_attr_private *p;
    300       1.1   nathanw 
    301  1.18.4.1    martin 	pthread__error(EINVAL, "Invalid attribute",
    302  1.18.4.1    martin 	    attr->pta_magic == PT_ATTR_MAGIC);
    303  1.18.4.1    martin 
    304       1.1   nathanw 	if (param == NULL)
    305       1.1   nathanw 		return EINVAL;
    306      1.10        ad 	p = attr->pta_private;
    307      1.10        ad 	if (p == NULL)
    308      1.11        ad 		memset(param, 0, sizeof(*param));
    309      1.11        ad 	else
    310      1.11        ad 		*param = p->ptap_sp;
    311       1.1   nathanw 	return 0;
    312       1.1   nathanw }
    313       1.1   nathanw 
    314       1.1   nathanw 
    315       1.1   nathanw int
    316      1.10        ad pthread_attr_setschedpolicy(pthread_attr_t *attr, int policy)
    317       1.4   nathanw {
    318      1.10        ad 	struct pthread_attr_private *p;
    319      1.10        ad 
    320  1.18.4.1    martin 	pthread__error(EINVAL, "Invalid attribute",
    321  1.18.4.1    martin 	    attr->pta_magic == PT_ATTR_MAGIC);
    322       1.4   nathanw 
    323      1.10        ad 	switch (policy) {
    324      1.10        ad 	case SCHED_OTHER:
    325      1.10        ad 	case SCHED_FIFO:
    326      1.10        ad 	case SCHED_RR:
    327      1.10        ad 		p = pthread__attr_init_private(attr);
    328      1.10        ad 		if (p == NULL)
    329      1.10        ad 			return ENOMEM;
    330      1.10        ad 		p->ptap_policy = policy;
    331      1.10        ad 		return 0;
    332      1.10        ad 	default:
    333       1.4   nathanw 		return ENOTSUP;
    334      1.10        ad 	}
    335       1.4   nathanw }
    336       1.4   nathanw 
    337       1.4   nathanw 
    338       1.4   nathanw int
    339      1.10        ad pthread_attr_getschedpolicy(const pthread_attr_t *attr, int *policy)
    340       1.4   nathanw {
    341      1.10        ad 	struct pthread_attr_private *p;
    342       1.4   nathanw 
    343  1.18.4.1    martin 	pthread__error(EINVAL, "Invalid attribute",
    344  1.18.4.1    martin 	    attr->pta_magic == PT_ATTR_MAGIC);
    345  1.18.4.1    martin 
    346      1.10        ad 	p = attr->pta_private;
    347      1.10        ad 	if (p == NULL) {
    348      1.10        ad 		*policy = SCHED_OTHER;
    349      1.10        ad 		return 0;
    350      1.10        ad 	}
    351      1.10        ad 	*policy = p->ptap_policy;
    352       1.4   nathanw 	return 0;
    353       1.4   nathanw }
    354       1.4   nathanw 
    355       1.4   nathanw 
    356       1.4   nathanw int
    357       1.1   nathanw pthread_attr_getstack(const pthread_attr_t *attr, void **addr, size_t *size)
    358       1.1   nathanw {
    359       1.1   nathanw 	struct pthread_attr_private *p;
    360       1.1   nathanw 
    361  1.18.4.1    martin 	pthread__error(EINVAL, "Invalid attribute",
    362  1.18.4.1    martin 	    attr->pta_magic == PT_ATTR_MAGIC);
    363  1.18.4.1    martin 
    364       1.1   nathanw 	if ((p = attr->pta_private) == NULL) {
    365       1.1   nathanw 		*addr = NULL;
    366       1.6        ad 		*size = pthread__stacksize;
    367       1.1   nathanw 	} else {
    368       1.1   nathanw 		*addr = p->ptap_stackaddr;
    369       1.1   nathanw 		*size = p->ptap_stacksize;
    370       1.1   nathanw 	}
    371       1.1   nathanw 
    372       1.1   nathanw 	return 0;
    373       1.1   nathanw }
    374       1.1   nathanw 
    375       1.1   nathanw 
    376       1.1   nathanw int
    377       1.1   nathanw pthread_attr_setstack(pthread_attr_t *attr, void *addr, size_t size)
    378       1.1   nathanw {
    379       1.1   nathanw 	struct pthread_attr_private *p;
    380       1.1   nathanw 
    381  1.18.4.1    martin 	pthread__error(EINVAL, "Invalid attribute",
    382  1.18.4.1    martin 	    attr->pta_magic == PT_ATTR_MAGIC);
    383  1.18.4.1    martin 
    384       1.1   nathanw 	p = pthread__attr_init_private(attr);
    385       1.1   nathanw 	if (p == NULL)
    386       1.1   nathanw 		return ENOMEM;
    387       1.1   nathanw 
    388       1.1   nathanw 	p->ptap_stackaddr = addr;
    389       1.1   nathanw 	p->ptap_stacksize = size;
    390       1.1   nathanw 
    391       1.1   nathanw 	return 0;
    392       1.1   nathanw }
    393       1.1   nathanw 
    394       1.1   nathanw 
    395       1.1   nathanw int
    396       1.1   nathanw pthread_attr_getstacksize(const pthread_attr_t *attr, size_t *size)
    397       1.1   nathanw {
    398       1.1   nathanw 	struct pthread_attr_private *p;
    399       1.1   nathanw 
    400  1.18.4.1    martin 	pthread__error(EINVAL, "Invalid attribute",
    401  1.18.4.1    martin 	    attr->pta_magic == PT_ATTR_MAGIC);
    402  1.18.4.1    martin 
    403       1.1   nathanw 	if ((p = attr->pta_private) == NULL)
    404       1.6        ad 		*size = pthread__stacksize;
    405       1.1   nathanw 	else
    406       1.1   nathanw 		*size = p->ptap_stacksize;
    407       1.1   nathanw 
    408       1.1   nathanw 	return 0;
    409       1.1   nathanw }
    410       1.1   nathanw 
    411       1.1   nathanw 
    412       1.1   nathanw int
    413       1.1   nathanw pthread_attr_setstacksize(pthread_attr_t *attr, size_t size)
    414       1.1   nathanw {
    415       1.1   nathanw 	struct pthread_attr_private *p;
    416       1.1   nathanw 
    417  1.18.4.1    martin 	pthread__error(EINVAL, "Invalid attribute",
    418  1.18.4.1    martin 	    attr->pta_magic == PT_ATTR_MAGIC);
    419  1.18.4.1    martin 
    420      1.12     lukem 	if (size < (size_t)sysconf(_SC_THREAD_STACK_MIN))
    421       1.9        ad 		return EINVAL;
    422       1.9        ad 
    423       1.1   nathanw 	p = pthread__attr_init_private(attr);
    424       1.1   nathanw 	if (p == NULL)
    425       1.1   nathanw 		return ENOMEM;
    426       1.1   nathanw 
    427       1.1   nathanw 	p->ptap_stacksize = size;
    428       1.1   nathanw 
    429       1.1   nathanw 	return 0;
    430       1.1   nathanw }
    431       1.1   nathanw 
    432       1.1   nathanw 
    433       1.1   nathanw int
    434       1.1   nathanw pthread_attr_getstackaddr(const pthread_attr_t *attr, void **addr)
    435       1.1   nathanw {
    436       1.1   nathanw 	struct pthread_attr_private *p;
    437       1.1   nathanw 
    438  1.18.4.1    martin 	pthread__error(EINVAL, "Invalid attribute",
    439  1.18.4.1    martin 	    attr->pta_magic == PT_ATTR_MAGIC);
    440  1.18.4.1    martin 
    441       1.1   nathanw 	if ((p = attr->pta_private) == NULL)
    442       1.1   nathanw 		*addr = NULL;
    443       1.1   nathanw 	else
    444       1.1   nathanw 		*addr = p->ptap_stackaddr;
    445       1.1   nathanw 
    446       1.1   nathanw 	return 0;
    447       1.1   nathanw }
    448       1.1   nathanw 
    449       1.1   nathanw 
    450       1.1   nathanw int
    451       1.1   nathanw pthread_attr_setstackaddr(pthread_attr_t *attr, void *addr)
    452       1.1   nathanw {
    453       1.1   nathanw 	struct pthread_attr_private *p;
    454       1.1   nathanw 
    455  1.18.4.1    martin 	pthread__error(EINVAL, "Invalid attribute",
    456  1.18.4.1    martin 	    attr->pta_magic == PT_ATTR_MAGIC);
    457  1.18.4.1    martin 
    458       1.1   nathanw 	p = pthread__attr_init_private(attr);
    459       1.1   nathanw 	if (p == NULL)
    460       1.1   nathanw 		return ENOMEM;
    461       1.1   nathanw 
    462       1.1   nathanw 	p->ptap_stackaddr = addr;
    463       1.1   nathanw 
    464       1.1   nathanw 	return 0;
    465       1.1   nathanw }
    466       1.1   nathanw 
    467       1.1   nathanw 
    468       1.1   nathanw int
    469       1.1   nathanw pthread_attr_getname_np(const pthread_attr_t *attr, char *name, size_t len,
    470       1.1   nathanw     void **argp)
    471       1.1   nathanw {
    472       1.1   nathanw 	struct pthread_attr_private *p;
    473       1.1   nathanw 
    474  1.18.4.1    martin 	pthread__error(EINVAL, "Invalid attribute",
    475  1.18.4.1    martin 	    attr->pta_magic == PT_ATTR_MAGIC);
    476  1.18.4.1    martin 
    477       1.1   nathanw 	if ((p = attr->pta_private) == NULL) {
    478       1.1   nathanw 		name[0] = '\0';
    479       1.1   nathanw 		if (argp != NULL)
    480       1.1   nathanw 			*argp = NULL;
    481       1.1   nathanw 	} else {
    482       1.1   nathanw 		strlcpy(name, p->ptap_name, len);
    483       1.1   nathanw 		if (argp != NULL)
    484       1.1   nathanw 			*argp = p->ptap_namearg;
    485       1.1   nathanw 	}
    486       1.1   nathanw 
    487       1.1   nathanw 	return 0;
    488       1.1   nathanw }
    489       1.1   nathanw 
    490       1.1   nathanw 
    491       1.1   nathanw int
    492       1.1   nathanw pthread_attr_setname_np(pthread_attr_t *attr, const char *name, void *arg)
    493       1.1   nathanw {
    494       1.1   nathanw 	struct pthread_attr_private *p;
    495       1.1   nathanw 	int namelen;
    496       1.1   nathanw 
    497  1.18.4.1    martin 	pthread__error(EINVAL, "Invalid attribute",
    498  1.18.4.1    martin 	    attr->pta_magic == PT_ATTR_MAGIC);
    499  1.18.4.1    martin 
    500       1.1   nathanw 	p = pthread__attr_init_private(attr);
    501       1.1   nathanw 	if (p == NULL)
    502       1.1   nathanw 		return ENOMEM;
    503       1.1   nathanw 
    504       1.1   nathanw 	namelen = snprintf(p->ptap_name, PTHREAD_MAX_NAMELEN_NP, name, arg);
    505       1.1   nathanw 	if (namelen >= PTHREAD_MAX_NAMELEN_NP) {
    506       1.1   nathanw 		p->ptap_name[0] = '\0';
    507       1.1   nathanw 		return EINVAL;
    508       1.1   nathanw 	}
    509       1.1   nathanw 	p->ptap_namearg = arg;
    510       1.1   nathanw 
    511       1.3  christos 	return 0;
    512       1.3  christos }
    513       1.3  christos 
    514       1.3  christos int
    515       1.3  christos pthread_attr_setcreatesuspend_np(pthread_attr_t *attr)
    516       1.3  christos {
    517  1.18.4.1    martin 
    518  1.18.4.1    martin 	pthread__error(EINVAL, "Invalid attribute",
    519  1.18.4.1    martin 	    attr->pta_magic == PT_ATTR_MAGIC);
    520  1.18.4.1    martin 
    521       1.3  christos 	attr->pta_flags |= PT_FLAG_SUSPENDED;
    522       1.1   nathanw 	return 0;
    523       1.1   nathanw }
    524      1.13  christos 
    525      1.13  christos int
    526      1.13  christos pthread_getattr_np(pthread_t thread, pthread_attr_t *attr)
    527      1.13  christos {
    528      1.13  christos 	int error;
    529  1.18.4.1    martin 
    530      1.13  christos 	if ((error = pthread_attr_init(attr)) != 0)
    531      1.13  christos 		return error;
    532      1.13  christos 	if ((error = pthread_attr_get_np(thread, attr)) != 0) {
    533      1.13  christos 		(void)pthread_attr_destroy(attr);
    534      1.13  christos 		return error;
    535      1.13  christos 	}
    536      1.13  christos 	return 0;
    537      1.13  christos }
    538