2017-11-18 14:26:50 +00:00
|
|
|
/*-
|
|
|
|
* SPDX-License-Identifier: BSD-4-Clause
|
|
|
|
*
|
2003-04-01 03:46:29 +00:00
|
|
|
* Copyright (c) 2003 Craig Rodrigues <rodrigc@attbi.com>.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by Craig Rodrigues.
|
|
|
|
* 4. Neither the name of the author nor the names of any co-contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY CRAIG RODRIGUES AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1998 Daniel Eischen <eischen@vigrid.com>.
|
|
|
|
* Copyright (C) 2001 Jason Evans <jasone@freebsd.org>.
|
|
|
|
* Copyright (c) 2002,2003 Alexey Zelkin <phantom@FreeBSD.org>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice(s), this list of conditions and the following disclaimer
|
|
|
|
* unmodified other than the allowable addition of one or more
|
|
|
|
* copyright notices.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice(s), this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
|
|
|
|
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
|
|
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
|
|
|
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
|
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
|
|
|
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
|
|
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2005-04-02 01:20:00 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1996 John Birrell <jb@cimlogic.com.au>.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2007-01-12 07:26:21 +00:00
|
|
|
* 3. Neither the name of the author nor the names of any co-contributors
|
2005-04-02 01:20:00 +00:00
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
2003-04-01 03:46:29 +00:00
|
|
|
|
2016-04-08 11:15:26 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2006-04-04 02:57:49 +00:00
|
|
|
#include "namespace.h"
|
2003-04-01 03:46:29 +00:00
|
|
|
#include <errno.h>
|
|
|
|
#include <pthread.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2005-04-02 01:20:00 +00:00
|
|
|
#include <pthread_np.h>
|
2008-03-05 06:55:48 +00:00
|
|
|
#include <sys/sysctl.h>
|
2006-04-04 02:57:49 +00:00
|
|
|
#include "un-namespace.h"
|
2003-04-01 03:46:29 +00:00
|
|
|
|
|
|
|
#include "thr_private.h"
|
|
|
|
|
2010-10-25 09:16:04 +00:00
|
|
|
static size_t _get_kern_cpuset_size(void);
|
|
|
|
|
2019-07-31 19:27:20 +00:00
|
|
|
__weak_reference(_thr_attr_destroy, _pthread_attr_destroy);
|
|
|
|
__weak_reference(_thr_attr_destroy, pthread_attr_destroy);
|
2003-04-01 03:46:29 +00:00
|
|
|
|
|
|
|
int
|
2019-07-31 19:27:20 +00:00
|
|
|
_thr_attr_destroy(pthread_attr_t *attr)
|
2003-04-01 03:46:29 +00:00
|
|
|
{
|
2005-04-02 01:20:00 +00:00
|
|
|
int ret;
|
2003-04-01 03:46:29 +00:00
|
|
|
|
2005-04-02 01:20:00 +00:00
|
|
|
/* Check for invalid arguments: */
|
|
|
|
if (attr == NULL || *attr == NULL)
|
|
|
|
/* Invalid argument: */
|
|
|
|
ret = EINVAL;
|
|
|
|
else {
|
2010-10-25 09:16:04 +00:00
|
|
|
if ((*attr)->cpuset != NULL)
|
|
|
|
free((*attr)->cpuset);
|
2005-04-02 01:20:00 +00:00
|
|
|
/* Free the memory allocated to the attribute object: */
|
|
|
|
free(*attr);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Leave the attribute pointer NULL now that the memory
|
|
|
|
* has been freed:
|
|
|
|
*/
|
|
|
|
*attr = NULL;
|
|
|
|
ret = 0;
|
|
|
|
}
|
2020-11-26 20:23:17 +00:00
|
|
|
return (ret);
|
2003-04-01 03:46:29 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 19:27:20 +00:00
|
|
|
__weak_reference(_thr_attr_get_np, pthread_attr_get_np);
|
|
|
|
__weak_reference(_thr_attr_get_np, _pthread_attr_get_np);
|
2005-04-02 01:20:00 +00:00
|
|
|
|
2003-04-01 03:46:29 +00:00
|
|
|
int
|
2019-07-31 19:27:20 +00:00
|
|
|
_thr_attr_get_np(pthread_t pthread, pthread_attr_t *dstattr)
|
2003-04-01 03:46:29 +00:00
|
|
|
{
|
2005-04-02 01:20:00 +00:00
|
|
|
struct pthread *curthread;
|
2010-10-25 09:16:04 +00:00
|
|
|
struct pthread_attr attr, *dst;
|
2005-04-02 01:20:00 +00:00
|
|
|
int ret;
|
2010-10-27 09:59:43 +00:00
|
|
|
size_t kern_size;
|
2005-04-02 01:20:00 +00:00
|
|
|
|
2010-10-25 11:16:50 +00:00
|
|
|
if (pthread == NULL || dstattr == NULL || (dst = *dstattr) == NULL)
|
2003-04-01 03:46:29 +00:00
|
|
|
return (EINVAL);
|
2010-10-27 09:59:43 +00:00
|
|
|
kern_size = _get_kern_cpuset_size();
|
|
|
|
if (dst->cpuset == NULL) {
|
|
|
|
dst->cpuset = calloc(1, kern_size);
|
|
|
|
dst->cpusetsize = kern_size;
|
2010-10-25 09:16:04 +00:00
|
|
|
}
|
2005-04-02 01:20:00 +00:00
|
|
|
curthread = _get_curthread();
|
2010-09-13 07:03:01 +00:00
|
|
|
if ((ret = _thr_find_thread(curthread, pthread, /*include dead*/0)) != 0)
|
2005-04-02 01:20:00 +00:00
|
|
|
return (ret);
|
2010-09-13 07:03:01 +00:00
|
|
|
attr = pthread->attr;
|
|
|
|
if (pthread->flags & THR_FLAGS_DETACHED)
|
2006-01-09 03:59:51 +00:00
|
|
|
attr.flags |= PTHREAD_DETACHED;
|
2010-10-25 09:16:04 +00:00
|
|
|
ret = cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TID, TID(pthread),
|
|
|
|
dst->cpusetsize, dst->cpuset);
|
|
|
|
if (ret == -1)
|
|
|
|
ret = errno;
|
2010-09-13 07:03:01 +00:00
|
|
|
THR_THREAD_UNLOCK(curthread, pthread);
|
2010-10-25 09:16:04 +00:00
|
|
|
if (ret == 0) {
|
|
|
|
memcpy(&dst->pthread_attr_start_copy,
|
|
|
|
&attr.pthread_attr_start_copy,
|
|
|
|
offsetof(struct pthread_attr, pthread_attr_end_copy) -
|
|
|
|
offsetof(struct pthread_attr, pthread_attr_start_copy));
|
|
|
|
}
|
|
|
|
return (ret);
|
2003-04-01 03:46:29 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 19:27:20 +00:00
|
|
|
__weak_reference(_thr_attr_getdetachstate, pthread_attr_getdetachstate);
|
|
|
|
__weak_reference(_thr_attr_getdetachstate, _pthread_attr_getdetachstate);
|
2005-04-02 01:20:00 +00:00
|
|
|
|
2003-04-01 03:46:29 +00:00
|
|
|
int
|
2019-07-31 19:27:20 +00:00
|
|
|
_thr_attr_getdetachstate(const pthread_attr_t *attr, int *detachstate)
|
2003-04-01 03:46:29 +00:00
|
|
|
{
|
2005-04-02 01:20:00 +00:00
|
|
|
int ret;
|
2003-04-01 03:46:29 +00:00
|
|
|
|
2005-04-02 01:20:00 +00:00
|
|
|
/* Check for invalid arguments: */
|
|
|
|
if (attr == NULL || *attr == NULL || detachstate == NULL)
|
|
|
|
ret = EINVAL;
|
|
|
|
else {
|
|
|
|
/* Check if the detached flag is set: */
|
|
|
|
if ((*attr)->flags & PTHREAD_DETACHED)
|
|
|
|
/* Return detached: */
|
|
|
|
*detachstate = PTHREAD_CREATE_DETACHED;
|
|
|
|
else
|
|
|
|
/* Return joinable: */
|
|
|
|
*detachstate = PTHREAD_CREATE_JOINABLE;
|
|
|
|
ret = 0;
|
|
|
|
}
|
2020-11-26 20:23:17 +00:00
|
|
|
return (ret);
|
2003-04-01 03:46:29 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 19:27:20 +00:00
|
|
|
__weak_reference(_thr_attr_getguardsize, pthread_attr_getguardsize);
|
|
|
|
__weak_reference(_thr_attr_getguardsize, _pthread_attr_getguardsize);
|
2005-04-02 01:20:00 +00:00
|
|
|
|
2003-04-01 03:46:29 +00:00
|
|
|
int
|
2019-07-31 19:27:20 +00:00
|
|
|
_thr_attr_getguardsize(const pthread_attr_t * __restrict attr,
|
2018-08-21 01:33:25 +00:00
|
|
|
size_t * __restrict guardsize)
|
2003-04-01 03:46:29 +00:00
|
|
|
{
|
2005-04-02 01:20:00 +00:00
|
|
|
int ret;
|
2003-04-01 03:46:29 +00:00
|
|
|
|
2005-04-02 01:20:00 +00:00
|
|
|
/* Check for invalid arguments: */
|
|
|
|
if (attr == NULL || *attr == NULL || guardsize == NULL)
|
|
|
|
ret = EINVAL;
|
|
|
|
else {
|
|
|
|
/* Return the guard size: */
|
|
|
|
*guardsize = (*attr)->guardsize_attr;
|
|
|
|
ret = 0;
|
|
|
|
}
|
2020-11-26 20:23:17 +00:00
|
|
|
return (ret);
|
2003-04-01 03:46:29 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 19:27:20 +00:00
|
|
|
__weak_reference(_thr_attr_getinheritsched, pthread_attr_getinheritsched);
|
|
|
|
__weak_reference(_thr_attr_getinheritsched, _pthread_attr_getinheritsched);
|
2005-04-02 01:20:00 +00:00
|
|
|
|
2003-04-01 03:46:29 +00:00
|
|
|
int
|
2019-07-31 19:27:20 +00:00
|
|
|
_thr_attr_getinheritsched(const pthread_attr_t * __restrict attr,
|
2018-08-18 01:05:38 +00:00
|
|
|
int * __restrict sched_inherit)
|
2003-04-01 03:46:29 +00:00
|
|
|
{
|
2005-04-02 01:20:00 +00:00
|
|
|
int ret = 0;
|
2003-04-01 03:46:29 +00:00
|
|
|
|
2005-04-02 01:20:00 +00:00
|
|
|
if ((attr == NULL) || (*attr == NULL))
|
|
|
|
ret = EINVAL;
|
|
|
|
else
|
|
|
|
*sched_inherit = (*attr)->sched_inherit;
|
2003-04-01 03:46:29 +00:00
|
|
|
|
2020-11-26 20:23:17 +00:00
|
|
|
return (ret);
|
2003-04-01 03:46:29 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 19:27:20 +00:00
|
|
|
__weak_reference(_thr_attr_getschedparam, pthread_attr_getschedparam);
|
|
|
|
__weak_reference(_thr_attr_getschedparam, _pthread_attr_getschedparam);
|
2005-04-02 01:20:00 +00:00
|
|
|
|
2003-04-01 03:46:29 +00:00
|
|
|
int
|
2019-07-31 19:27:20 +00:00
|
|
|
_thr_attr_getschedparam(const pthread_attr_t * __restrict attr,
|
2018-08-18 01:05:38 +00:00
|
|
|
struct sched_param * __restrict param)
|
2003-04-01 03:46:29 +00:00
|
|
|
{
|
2005-04-02 01:20:00 +00:00
|
|
|
int ret = 0;
|
2003-04-01 03:46:29 +00:00
|
|
|
|
2005-04-02 01:20:00 +00:00
|
|
|
if ((attr == NULL) || (*attr == NULL) || (param == NULL))
|
|
|
|
ret = EINVAL;
|
|
|
|
else
|
|
|
|
param->sched_priority = (*attr)->prio;
|
2003-04-01 03:46:29 +00:00
|
|
|
|
2020-11-26 20:23:17 +00:00
|
|
|
return (ret);
|
2003-04-01 03:46:29 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 19:27:20 +00:00
|
|
|
__weak_reference(_thr_attr_getschedpolicy, pthread_attr_getschedpolicy);
|
|
|
|
__weak_reference(_thr_attr_getschedpolicy, _pthread_attr_getschedpolicy);
|
2005-04-02 01:20:00 +00:00
|
|
|
|
2003-04-01 03:46:29 +00:00
|
|
|
int
|
2019-07-31 19:27:20 +00:00
|
|
|
_thr_attr_getschedpolicy(const pthread_attr_t * __restrict attr,
|
2018-08-18 01:05:38 +00:00
|
|
|
int * __restrict policy)
|
2003-04-01 03:46:29 +00:00
|
|
|
{
|
2005-04-02 01:20:00 +00:00
|
|
|
int ret = 0;
|
2003-04-01 03:46:29 +00:00
|
|
|
|
2005-04-02 01:20:00 +00:00
|
|
|
if ((attr == NULL) || (*attr == NULL) || (policy == NULL))
|
|
|
|
ret = EINVAL;
|
|
|
|
else
|
|
|
|
*policy = (*attr)->sched_policy;
|
2003-04-01 03:46:29 +00:00
|
|
|
|
2020-11-26 20:23:17 +00:00
|
|
|
return (ret);
|
2003-04-01 03:46:29 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 19:27:20 +00:00
|
|
|
__weak_reference(_thr_attr_getscope, pthread_attr_getscope);
|
|
|
|
__weak_reference(_thr_attr_getscope, _pthread_attr_getscope);
|
2005-04-02 01:20:00 +00:00
|
|
|
|
2003-04-01 03:46:29 +00:00
|
|
|
int
|
2019-07-31 19:27:20 +00:00
|
|
|
_thr_attr_getscope(const pthread_attr_t * __restrict attr,
|
2018-08-18 01:05:38 +00:00
|
|
|
int * __restrict contentionscope)
|
2003-04-01 03:46:29 +00:00
|
|
|
{
|
2005-04-02 01:20:00 +00:00
|
|
|
int ret = 0;
|
2003-04-01 03:46:29 +00:00
|
|
|
|
2005-04-02 01:20:00 +00:00
|
|
|
if ((attr == NULL) || (*attr == NULL) || (contentionscope == NULL))
|
|
|
|
/* Return an invalid argument: */
|
|
|
|
ret = EINVAL;
|
2003-04-01 03:46:29 +00:00
|
|
|
|
2005-04-02 01:20:00 +00:00
|
|
|
else
|
|
|
|
*contentionscope = (*attr)->flags & PTHREAD_SCOPE_SYSTEM ?
|
|
|
|
PTHREAD_SCOPE_SYSTEM : PTHREAD_SCOPE_PROCESS;
|
2003-04-01 03:46:29 +00:00
|
|
|
|
2020-11-26 20:23:17 +00:00
|
|
|
return (ret);
|
2003-04-01 03:46:29 +00:00
|
|
|
}
|
|
|
|
|
2005-04-02 01:20:00 +00:00
|
|
|
__weak_reference(_pthread_attr_getstack, pthread_attr_getstack);
|
|
|
|
|
2003-04-01 03:46:29 +00:00
|
|
|
int
|
2005-04-02 01:20:00 +00:00
|
|
|
_pthread_attr_getstack(const pthread_attr_t * __restrict attr,
|
2019-07-31 19:27:20 +00:00
|
|
|
void ** __restrict stackaddr, size_t * __restrict stacksize)
|
2003-04-01 03:46:29 +00:00
|
|
|
{
|
2005-04-02 01:20:00 +00:00
|
|
|
int ret;
|
2003-04-01 03:46:29 +00:00
|
|
|
|
2005-04-02 01:20:00 +00:00
|
|
|
/* Check for invalid arguments: */
|
|
|
|
if (attr == NULL || *attr == NULL || stackaddr == NULL
|
|
|
|
|| stacksize == NULL )
|
|
|
|
ret = EINVAL;
|
|
|
|
else {
|
|
|
|
/* Return the stack address and size */
|
|
|
|
*stackaddr = (*attr)->stackaddr_attr;
|
|
|
|
*stacksize = (*attr)->stacksize_attr;
|
|
|
|
ret = 0;
|
|
|
|
}
|
2020-11-26 20:23:17 +00:00
|
|
|
return (ret);
|
2003-04-01 03:46:29 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 19:27:20 +00:00
|
|
|
__weak_reference(_thr_attr_getstackaddr, pthread_attr_getstackaddr);
|
|
|
|
__weak_reference(_thr_attr_getstackaddr, _pthread_attr_getstackaddr);
|
2005-04-02 01:20:00 +00:00
|
|
|
|
2003-04-01 03:46:29 +00:00
|
|
|
int
|
2019-07-31 19:27:20 +00:00
|
|
|
_thr_attr_getstackaddr(const pthread_attr_t *attr, void **stackaddr)
|
2003-04-01 03:46:29 +00:00
|
|
|
{
|
2005-04-02 01:20:00 +00:00
|
|
|
int ret;
|
2003-04-01 03:46:29 +00:00
|
|
|
|
2005-04-02 01:20:00 +00:00
|
|
|
/* Check for invalid arguments: */
|
|
|
|
if (attr == NULL || *attr == NULL || stackaddr == NULL)
|
|
|
|
ret = EINVAL;
|
|
|
|
else {
|
|
|
|
/* Return the stack address: */
|
|
|
|
*stackaddr = (*attr)->stackaddr_attr;
|
|
|
|
ret = 0;
|
|
|
|
}
|
2020-11-26 20:23:17 +00:00
|
|
|
return (ret);
|
2003-04-01 03:46:29 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 19:27:20 +00:00
|
|
|
__weak_reference(_thr_attr_getstacksize, pthread_attr_getstacksize);
|
|
|
|
__weak_reference(_thr_attr_getstacksize, _pthread_attr_getstacksize);
|
2005-04-02 01:20:00 +00:00
|
|
|
|
2003-04-01 03:46:29 +00:00
|
|
|
int
|
2019-07-31 19:27:20 +00:00
|
|
|
_thr_attr_getstacksize(const pthread_attr_t * __restrict attr,
|
2018-08-18 01:05:38 +00:00
|
|
|
size_t * __restrict stacksize)
|
2003-04-01 03:46:29 +00:00
|
|
|
{
|
2005-04-02 01:20:00 +00:00
|
|
|
int ret;
|
2003-04-01 03:46:29 +00:00
|
|
|
|
2005-04-02 01:20:00 +00:00
|
|
|
/* Check for invalid arguments: */
|
|
|
|
if (attr == NULL || *attr == NULL || stacksize == NULL)
|
|
|
|
ret = EINVAL;
|
|
|
|
else {
|
|
|
|
/* Return the stack size: */
|
|
|
|
*stacksize = (*attr)->stacksize_attr;
|
|
|
|
ret = 0;
|
|
|
|
}
|
2020-11-26 20:23:17 +00:00
|
|
|
return (ret);
|
2003-04-01 03:46:29 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 19:27:20 +00:00
|
|
|
__weak_reference(_thr_attr_init, pthread_attr_init);
|
|
|
|
__weak_reference(_thr_attr_init, _pthread_attr_init);
|
2005-04-02 01:20:00 +00:00
|
|
|
|
2003-04-01 03:46:29 +00:00
|
|
|
int
|
2019-07-31 19:27:20 +00:00
|
|
|
_thr_attr_init(pthread_attr_t *attr)
|
2003-04-01 03:46:29 +00:00
|
|
|
{
|
2005-04-02 01:20:00 +00:00
|
|
|
int ret;
|
|
|
|
pthread_attr_t pattr;
|
2003-04-01 03:46:29 +00:00
|
|
|
|
2005-04-02 01:20:00 +00:00
|
|
|
_thr_check_init();
|
2003-04-01 03:46:29 +00:00
|
|
|
|
2005-04-02 01:20:00 +00:00
|
|
|
/* Allocate memory for the attribute object: */
|
|
|
|
if ((pattr = (pthread_attr_t) malloc(sizeof(struct pthread_attr))) == NULL)
|
|
|
|
/* Insufficient memory: */
|
|
|
|
ret = ENOMEM;
|
|
|
|
else {
|
|
|
|
/* Initialise the attribute object with the defaults: */
|
|
|
|
memcpy(pattr, &_pthread_attr_default, sizeof(struct pthread_attr));
|
|
|
|
|
|
|
|
/* Return a pointer to the attribute object: */
|
|
|
|
*attr = pattr;
|
|
|
|
ret = 0;
|
|
|
|
}
|
2020-11-26 20:23:17 +00:00
|
|
|
return (ret);
|
2003-04-01 03:46:29 +00:00
|
|
|
}
|
|
|
|
|
2005-04-02 01:20:00 +00:00
|
|
|
__weak_reference(_pthread_attr_setcreatesuspend_np, pthread_attr_setcreatesuspend_np);
|
|
|
|
|
2003-04-01 03:46:29 +00:00
|
|
|
int
|
2005-04-02 01:20:00 +00:00
|
|
|
_pthread_attr_setcreatesuspend_np(pthread_attr_t *attr)
|
2003-04-01 03:46:29 +00:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2005-04-02 01:20:00 +00:00
|
|
|
if (attr == NULL || *attr == NULL) {
|
|
|
|
ret = EINVAL;
|
|
|
|
} else {
|
|
|
|
(*attr)->suspend = THR_CREATE_SUSPENDED;
|
|
|
|
ret = 0;
|
|
|
|
}
|
2020-11-26 20:23:17 +00:00
|
|
|
return (ret);
|
2003-04-01 03:46:29 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 19:27:20 +00:00
|
|
|
__weak_reference(_thr_attr_setdetachstate, pthread_attr_setdetachstate);
|
|
|
|
__weak_reference(_thr_attr_setdetachstate, _pthread_attr_setdetachstate);
|
2005-04-02 01:20:00 +00:00
|
|
|
|
2003-04-01 03:46:29 +00:00
|
|
|
int
|
2019-07-31 19:27:20 +00:00
|
|
|
_thr_attr_setdetachstate(pthread_attr_t *attr, int detachstate)
|
2003-04-01 03:46:29 +00:00
|
|
|
{
|
2005-04-02 01:20:00 +00:00
|
|
|
int ret;
|
2003-04-01 03:46:29 +00:00
|
|
|
|
2005-04-02 01:20:00 +00:00
|
|
|
/* Check for invalid arguments: */
|
|
|
|
if (attr == NULL || *attr == NULL ||
|
|
|
|
(detachstate != PTHREAD_CREATE_DETACHED &&
|
|
|
|
detachstate != PTHREAD_CREATE_JOINABLE))
|
|
|
|
ret = EINVAL;
|
|
|
|
else {
|
|
|
|
/* Check if detached state: */
|
|
|
|
if (detachstate == PTHREAD_CREATE_DETACHED)
|
|
|
|
/* Set the detached flag: */
|
|
|
|
(*attr)->flags |= PTHREAD_DETACHED;
|
|
|
|
else
|
|
|
|
/* Reset the detached flag: */
|
|
|
|
(*attr)->flags &= ~PTHREAD_DETACHED;
|
|
|
|
ret = 0;
|
|
|
|
}
|
2020-11-26 20:23:17 +00:00
|
|
|
return (ret);
|
2003-04-01 03:46:29 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 19:27:20 +00:00
|
|
|
__weak_reference(_thr_attr_setguardsize, pthread_attr_setguardsize);
|
|
|
|
__weak_reference(_thr_attr_setguardsize, _pthread_attr_setguardsize);
|
2005-04-02 01:20:00 +00:00
|
|
|
|
2003-04-01 03:46:29 +00:00
|
|
|
int
|
2019-07-31 19:27:20 +00:00
|
|
|
_thr_attr_setguardsize(pthread_attr_t *attr, size_t guardsize)
|
2003-04-01 03:46:29 +00:00
|
|
|
{
|
2005-04-02 01:20:00 +00:00
|
|
|
int ret;
|
2003-04-01 03:46:29 +00:00
|
|
|
|
2005-04-02 01:20:00 +00:00
|
|
|
/* Check for invalid arguments. */
|
|
|
|
if (attr == NULL || *attr == NULL)
|
|
|
|
ret = EINVAL;
|
|
|
|
else {
|
|
|
|
/* Save the stack size. */
|
|
|
|
(*attr)->guardsize_attr = guardsize;
|
|
|
|
ret = 0;
|
|
|
|
}
|
2020-11-26 20:23:17 +00:00
|
|
|
return (ret);
|
2003-04-01 03:46:29 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 19:27:20 +00:00
|
|
|
__weak_reference(_thr_attr_setinheritsched, pthread_attr_setinheritsched);
|
|
|
|
__weak_reference(_thr_attr_setinheritsched, _pthread_attr_setinheritsched);
|
2005-04-02 01:20:00 +00:00
|
|
|
|
2003-04-01 03:46:29 +00:00
|
|
|
int
|
2019-07-31 19:27:20 +00:00
|
|
|
_thr_attr_setinheritsched(pthread_attr_t *attr, int sched_inherit)
|
2003-04-01 03:46:29 +00:00
|
|
|
{
|
2005-04-02 01:20:00 +00:00
|
|
|
int ret = 0;
|
2003-04-01 03:46:29 +00:00
|
|
|
|
2005-04-02 01:20:00 +00:00
|
|
|
if ((attr == NULL) || (*attr == NULL))
|
|
|
|
ret = EINVAL;
|
|
|
|
else if (sched_inherit != PTHREAD_INHERIT_SCHED &&
|
|
|
|
sched_inherit != PTHREAD_EXPLICIT_SCHED)
|
|
|
|
ret = ENOTSUP;
|
|
|
|
else
|
|
|
|
(*attr)->sched_inherit = sched_inherit;
|
2003-04-01 03:46:29 +00:00
|
|
|
|
2020-11-26 20:23:17 +00:00
|
|
|
return (ret);
|
2003-04-01 03:46:29 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 19:27:20 +00:00
|
|
|
__weak_reference(_thr_attr_setschedparam, pthread_attr_setschedparam);
|
|
|
|
__weak_reference(_thr_attr_setschedparam, _pthread_attr_setschedparam);
|
2005-04-02 01:20:00 +00:00
|
|
|
|
2003-04-01 03:46:29 +00:00
|
|
|
int
|
2019-07-31 19:27:20 +00:00
|
|
|
_thr_attr_setschedparam(pthread_attr_t * __restrict attr,
|
2018-08-18 01:05:38 +00:00
|
|
|
const struct sched_param * __restrict param)
|
2003-04-01 03:46:29 +00:00
|
|
|
{
|
2006-04-27 08:18:23 +00:00
|
|
|
int policy;
|
2005-04-02 01:20:00 +00:00
|
|
|
|
|
|
|
if ((attr == NULL) || (*attr == NULL))
|
2006-04-27 08:18:23 +00:00
|
|
|
return (EINVAL);
|
2005-04-02 01:20:00 +00:00
|
|
|
|
2006-04-27 08:18:23 +00:00
|
|
|
if (param == NULL)
|
|
|
|
return (ENOTSUP);
|
|
|
|
|
|
|
|
policy = (*attr)->sched_policy;
|
|
|
|
|
2006-07-12 06:13:18 +00:00
|
|
|
if (policy == SCHED_FIFO || policy == SCHED_RR) {
|
|
|
|
if (param->sched_priority < _thr_priorities[policy-1].pri_min ||
|
|
|
|
param->sched_priority > _thr_priorities[policy-1].pri_max)
|
2006-04-27 08:18:23 +00:00
|
|
|
return (ENOTSUP);
|
2006-07-12 06:13:18 +00:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Ignore it for SCHED_OTHER now, patches for glib ports
|
|
|
|
* are wrongly using M:N thread library's internal macro
|
|
|
|
* THR_MIN_PRIORITY and THR_MAX_PRIORITY.
|
|
|
|
*/
|
|
|
|
}
|
2006-04-27 08:18:23 +00:00
|
|
|
|
|
|
|
(*attr)->prio = param->sched_priority;
|
|
|
|
|
|
|
|
return (0);
|
2003-04-01 03:46:29 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 19:27:20 +00:00
|
|
|
__weak_reference(_thr_attr_setschedpolicy, pthread_attr_setschedpolicy);
|
|
|
|
__weak_reference(_thr_attr_setschedpolicy, _pthread_attr_setschedpolicy);
|
2005-04-02 01:20:00 +00:00
|
|
|
|
2003-04-01 03:46:29 +00:00
|
|
|
int
|
2019-07-31 19:27:20 +00:00
|
|
|
_thr_attr_setschedpolicy(pthread_attr_t *attr, int policy)
|
2003-04-01 03:46:29 +00:00
|
|
|
{
|
2005-04-02 01:20:00 +00:00
|
|
|
int ret = 0;
|
2003-04-01 03:46:29 +00:00
|
|
|
|
2005-04-02 01:20:00 +00:00
|
|
|
if ((attr == NULL) || (*attr == NULL))
|
|
|
|
ret = EINVAL;
|
|
|
|
else if ((policy < SCHED_FIFO) || (policy > SCHED_RR)) {
|
|
|
|
ret = ENOTSUP;
|
2006-04-27 08:18:23 +00:00
|
|
|
} else {
|
2005-04-02 01:20:00 +00:00
|
|
|
(*attr)->sched_policy = policy;
|
2006-04-27 08:18:23 +00:00
|
|
|
(*attr)->prio = _thr_priorities[policy-1].pri_default;
|
|
|
|
}
|
2020-11-26 20:23:17 +00:00
|
|
|
return (ret);
|
2003-04-01 03:46:29 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 19:27:20 +00:00
|
|
|
__weak_reference(_thr_attr_setscope, pthread_attr_setscope);
|
|
|
|
__weak_reference(_thr_attr_setscope, _pthread_attr_setscope);
|
2005-04-02 01:20:00 +00:00
|
|
|
|
2003-04-01 03:46:29 +00:00
|
|
|
int
|
2019-07-31 19:27:20 +00:00
|
|
|
_thr_attr_setscope(pthread_attr_t *attr, int contentionscope)
|
2003-04-01 03:46:29 +00:00
|
|
|
{
|
2005-04-02 01:20:00 +00:00
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if ((attr == NULL) || (*attr == NULL)) {
|
|
|
|
/* Return an invalid argument: */
|
|
|
|
ret = EINVAL;
|
|
|
|
} else if ((contentionscope != PTHREAD_SCOPE_PROCESS) &&
|
|
|
|
(contentionscope != PTHREAD_SCOPE_SYSTEM)) {
|
|
|
|
ret = EINVAL;
|
|
|
|
} else if (contentionscope == PTHREAD_SCOPE_SYSTEM) {
|
|
|
|
(*attr)->flags |= contentionscope;
|
|
|
|
} else {
|
|
|
|
(*attr)->flags &= ~PTHREAD_SCOPE_SYSTEM;
|
|
|
|
}
|
|
|
|
return (ret);
|
2003-04-01 03:46:29 +00:00
|
|
|
}
|
|
|
|
|
2005-04-02 01:20:00 +00:00
|
|
|
__weak_reference(_pthread_attr_setstack, pthread_attr_setstack);
|
|
|
|
|
2003-04-01 03:46:29 +00:00
|
|
|
int
|
2005-04-02 01:20:00 +00:00
|
|
|
_pthread_attr_setstack(pthread_attr_t *attr, void *stackaddr,
|
|
|
|
size_t stacksize)
|
2003-04-01 03:46:29 +00:00
|
|
|
{
|
2005-04-02 01:20:00 +00:00
|
|
|
int ret;
|
2003-04-01 03:46:29 +00:00
|
|
|
|
2005-04-02 01:20:00 +00:00
|
|
|
/* Check for invalid arguments: */
|
|
|
|
if (attr == NULL || *attr == NULL || stackaddr == NULL
|
|
|
|
|| stacksize < PTHREAD_STACK_MIN)
|
|
|
|
ret = EINVAL;
|
|
|
|
else {
|
|
|
|
/* Save the stack address and stack size */
|
|
|
|
(*attr)->stackaddr_attr = stackaddr;
|
|
|
|
(*attr)->stacksize_attr = stacksize;
|
|
|
|
ret = 0;
|
|
|
|
}
|
2020-11-26 20:23:17 +00:00
|
|
|
return (ret);
|
2003-04-01 03:46:29 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 19:27:20 +00:00
|
|
|
__weak_reference(_thr_attr_setstackaddr, pthread_attr_setstackaddr);
|
|
|
|
__weak_reference(_thr_attr_setstackaddr, _pthread_attr_setstackaddr);
|
2005-04-02 01:20:00 +00:00
|
|
|
|
2003-04-01 03:46:29 +00:00
|
|
|
int
|
2019-07-31 19:27:20 +00:00
|
|
|
_thr_attr_setstackaddr(pthread_attr_t *attr, void *stackaddr)
|
2003-04-01 03:46:29 +00:00
|
|
|
{
|
2005-04-02 01:20:00 +00:00
|
|
|
int ret;
|
2003-04-01 03:46:29 +00:00
|
|
|
|
2005-04-02 01:20:00 +00:00
|
|
|
/* Check for invalid arguments: */
|
|
|
|
if (attr == NULL || *attr == NULL || stackaddr == NULL)
|
|
|
|
ret = EINVAL;
|
|
|
|
else {
|
|
|
|
/* Save the stack address: */
|
|
|
|
(*attr)->stackaddr_attr = stackaddr;
|
|
|
|
ret = 0;
|
|
|
|
}
|
|
|
|
return(ret);
|
2003-04-01 03:46:29 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 19:27:20 +00:00
|
|
|
__weak_reference(_thr_attr_setstacksize, pthread_attr_setstacksize);
|
|
|
|
__weak_reference(_thr_attr_setstacksize, _pthread_attr_setstacksize);
|
2005-04-02 01:20:00 +00:00
|
|
|
|
2003-04-01 03:46:29 +00:00
|
|
|
int
|
2019-07-31 19:27:20 +00:00
|
|
|
_thr_attr_setstacksize(pthread_attr_t *attr, size_t stacksize)
|
2003-04-01 03:46:29 +00:00
|
|
|
{
|
2005-04-02 01:20:00 +00:00
|
|
|
int ret;
|
2003-04-01 03:46:29 +00:00
|
|
|
|
2005-04-02 01:20:00 +00:00
|
|
|
/* Check for invalid arguments: */
|
|
|
|
if (attr == NULL || *attr == NULL || stacksize < PTHREAD_STACK_MIN)
|
|
|
|
ret = EINVAL;
|
|
|
|
else {
|
|
|
|
/* Save the stack size: */
|
|
|
|
(*attr)->stacksize_attr = stacksize;
|
|
|
|
ret = 0;
|
|
|
|
}
|
2020-11-26 20:23:17 +00:00
|
|
|
return (ret);
|
2003-04-01 03:46:29 +00:00
|
|
|
}
|
2008-03-04 03:03:24 +00:00
|
|
|
|
2008-03-25 13:28:12 +00:00
|
|
|
static size_t
|
|
|
|
_get_kern_cpuset_size(void)
|
2008-03-05 06:55:48 +00:00
|
|
|
{
|
|
|
|
static int kern_cpuset_size = 0;
|
|
|
|
|
|
|
|
if (kern_cpuset_size == 0) {
|
2008-03-25 13:28:12 +00:00
|
|
|
size_t len;
|
2010-11-02 02:13:13 +00:00
|
|
|
|
|
|
|
len = sizeof(kern_cpuset_size);
|
|
|
|
if (sysctlbyname("kern.sched.cpusetsize", &kern_cpuset_size,
|
|
|
|
&len, NULL, 0))
|
|
|
|
PANIC("failed to get sysctl kern.sched.cpusetsize");
|
2008-03-05 06:55:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return (kern_cpuset_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
__weak_reference(_pthread_attr_setaffinity_np, pthread_attr_setaffinity_np);
|
2008-03-04 03:03:24 +00:00
|
|
|
int
|
2008-03-05 06:55:48 +00:00
|
|
|
_pthread_attr_setaffinity_np(pthread_attr_t *pattr, size_t cpusetsize,
|
2008-04-23 21:06:51 +00:00
|
|
|
const cpuset_t *cpusetp)
|
2008-03-04 03:03:24 +00:00
|
|
|
{
|
|
|
|
pthread_attr_t attr;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (pattr == NULL || (attr = (*pattr)) == NULL)
|
|
|
|
ret = EINVAL;
|
|
|
|
else {
|
2008-04-23 21:06:51 +00:00
|
|
|
if (cpusetsize == 0 || cpusetp == NULL) {
|
2008-03-04 03:03:24 +00:00
|
|
|
if (attr->cpuset != NULL) {
|
|
|
|
free(attr->cpuset);
|
|
|
|
attr->cpuset = NULL;
|
|
|
|
attr->cpusetsize = 0;
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
2010-10-27 09:59:43 +00:00
|
|
|
size_t kern_size = _get_kern_cpuset_size();
|
|
|
|
/* Kernel rejects small set, we check it here too. */
|
|
|
|
if (cpusetsize < kern_size)
|
|
|
|
return (ERANGE);
|
|
|
|
if (cpusetsize > kern_size) {
|
|
|
|
/* Kernel checks invalid bits, we check it here too. */
|
|
|
|
size_t i;
|
|
|
|
for (i = kern_size; i < cpusetsize; ++i) {
|
2017-05-19 13:04:05 +00:00
|
|
|
if (((const char *)cpusetp)[i])
|
2010-10-27 09:59:43 +00:00
|
|
|
return (EINVAL);
|
2008-03-05 06:55:48 +00:00
|
|
|
}
|
2008-03-04 03:03:24 +00:00
|
|
|
}
|
2010-10-27 09:59:43 +00:00
|
|
|
if (attr->cpuset == NULL) {
|
|
|
|
attr->cpuset = calloc(1, kern_size);
|
|
|
|
if (attr->cpuset == NULL)
|
|
|
|
return (errno);
|
|
|
|
attr->cpusetsize = kern_size;
|
|
|
|
}
|
|
|
|
memcpy(attr->cpuset, cpusetp, kern_size);
|
2008-03-04 03:03:24 +00:00
|
|
|
ret = 0;
|
|
|
|
}
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
2008-03-05 06:55:48 +00:00
|
|
|
__weak_reference(_pthread_attr_getaffinity_np, pthread_attr_getaffinity_np);
|
2008-03-04 03:03:24 +00:00
|
|
|
int
|
2008-03-05 06:55:48 +00:00
|
|
|
_pthread_attr_getaffinity_np(const pthread_attr_t *pattr, size_t cpusetsize,
|
2008-04-23 21:06:51 +00:00
|
|
|
cpuset_t *cpusetp)
|
2008-03-04 03:03:24 +00:00
|
|
|
{
|
|
|
|
pthread_attr_t attr;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if (pattr == NULL || (attr = (*pattr)) == NULL)
|
|
|
|
ret = EINVAL;
|
2010-10-27 09:59:43 +00:00
|
|
|
else {
|
|
|
|
/* Kernel rejects small set, we check it here too. */
|
2008-03-25 13:28:12 +00:00
|
|
|
size_t kern_size = _get_kern_cpuset_size();
|
2010-10-27 09:59:43 +00:00
|
|
|
if (cpusetsize < kern_size)
|
|
|
|
return (ERANGE);
|
|
|
|
if (attr->cpuset != NULL)
|
|
|
|
memcpy(cpusetp, attr->cpuset, MIN(cpusetsize,
|
|
|
|
attr->cpusetsize));
|
|
|
|
else
|
|
|
|
memset(cpusetp, -1, kern_size);
|
2008-03-05 06:55:48 +00:00
|
|
|
if (cpusetsize > kern_size)
|
2010-10-27 09:59:43 +00:00
|
|
|
memset(((char *)cpusetp) + kern_size, 0,
|
2008-03-05 06:55:48 +00:00
|
|
|
cpusetsize - kern_size);
|
2008-03-04 03:03:24 +00:00
|
|
|
}
|
|
|
|
return (ret);
|
|
|
|
}
|