sched/pthread: Added non-standard pthread_get_stackaddr_np() and pthread_get_stacksize_np().

This commit is contained in:
Joao Matos 2019-04-04 10:30:46 -06:00 committed by Gregory Nutt
parent c6dd9274e6
commit 08ff68edec
8 changed files with 184 additions and 14 deletions

View File

@ -466,13 +466,18 @@ int pthread_attr_getaffinity_np(FAR const pthread_attr_t *attr,
int pthread_attr_setstacksize(FAR pthread_attr_t *attr, long stacksize); int pthread_attr_setstacksize(FAR pthread_attr_t *attr, long stacksize);
int pthread_attr_getstacksize(FAR const pthread_attr_t *attr, long *stackaddr); int pthread_attr_getstacksize(FAR const pthread_attr_t *attr, long *stackaddr);
/* Set or obtain stack address and size */ /* Set or obtain stack address and size attributes */
int pthread_attr_setstack(FAR pthread_attr_t *attr, int pthread_attr_setstack(FAR pthread_attr_t *attr,
FAR void *stackaddr, long stacksize); FAR void *stackaddr, long stacksize);
int pthread_attr_getstack(FAR pthread_attr_t *attr, int pthread_attr_getstack(FAR pthread_attr_t *attr,
FAR void **stackaddr, FAR long *stacksize); FAR void **stackaddr, FAR long *stacksize);
/* Get run-time stack address and size */
FAR void *pthread_get_stackaddr_np(FAR pthread_t thread);
ssize_t pthread_get_stacksize_np(FAR pthread_t thread);
/* To create a thread object and runnable thread, a routine must be specified /* To create a thread object and runnable thread, a routine must be specified
* as the new thread's start routine. An argument may be passed to this * as the new thread's start routine. An argument may be passed to this
* routine, as an untyped address; an untyped address may also be returned as * routine, as an untyped address; an untyped address may also be returned as

View File

@ -425,22 +425,24 @@
# define SYS_pthread_create (__SYS_pthread + 4) # define SYS_pthread_create (__SYS_pthread + 4)
# define SYS_pthread_detach (__SYS_pthread + 5) # define SYS_pthread_detach (__SYS_pthread + 5)
# define SYS_pthread_exit (__SYS_pthread + 6) # define SYS_pthread_exit (__SYS_pthread + 6)
# define SYS_pthread_getschedparam (__SYS_pthread + 7) # define SYS_pthread_get_stackaddr_np (__SYS_pthread + 7)
# define SYS_pthread_getspecific (__SYS_pthread + 8) # define SYS_pthread_get_stacksize_np (__SYS_pthread + 8)
# define SYS_pthread_join (__SYS_pthread + 9) # define SYS_pthread_getschedparam (__SYS_pthread + 9)
# define SYS_pthread_key_create (__SYS_pthread + 10) # define SYS_pthread_getspecific (__SYS_pthread + 10)
# define SYS_pthread_key_delete (__SYS_pthread + 11) # define SYS_pthread_join (__SYS_pthread + 11)
# define SYS_pthread_mutex_destroy (__SYS_pthread + 12) # define SYS_pthread_key_create (__SYS_pthread + 12)
# define SYS_pthread_mutex_init (__SYS_pthread + 13) # define SYS_pthread_key_delete (__SYS_pthread + 13)
# define SYS_pthread_mutex_timedlock (__SYS_pthread + 14) # define SYS_pthread_mutex_destroy (__SYS_pthread + 14)
# define SYS_pthread_mutex_trylock (__SYS_pthread + 15) # define SYS_pthread_mutex_init (__SYS_pthread + 15)
# define SYS_pthread_mutex_unlock (__SYS_pthread + 16) # define SYS_pthread_mutex_timedlock (__SYS_pthread + 16)
# define SYS_pthread_mutex_trylock (__SYS_pthread + 17)
# define SYS_pthread_mutex_unlock (__SYS_pthread + 18)
#ifndef CONFIG_PTHREAD_MUTEX_UNSAFE #ifndef CONFIG_PTHREAD_MUTEX_UNSAFE
# define SYS_pthread_mutex_consistent (__SYS_pthread + 17) # define SYS_pthread_mutex_consistent (__SYS_pthread + 19)
# define __SYS_pthread_setschedparam (__SYS_pthread + 18) # define __SYS_pthread_setschedparam (__SYS_pthread + 20)
#else #else
# define __SYS_pthread_setschedparam (__SYS_pthread + 17) # define __SYS_pthread_setschedparam (__SYS_pthread + 19)
#endif #endif
# define SYS_pthread_setschedparam (__SYS_pthread_setschedparam + 0) # define SYS_pthread_setschedparam (__SYS_pthread_setschedparam + 0)

View File

@ -46,6 +46,7 @@ CSRCS += pthread_condwait.c pthread_condsignal.c pthread_condbroadcast.c
CSRCS += pthread_cancel.c CSRCS += pthread_cancel.c
CSRCS += pthread_initialize.c pthread_completejoin.c pthread_findjoininfo.c CSRCS += pthread_initialize.c pthread_completejoin.c pthread_findjoininfo.c
CSRCS += pthread_release.c pthread_setschedprio.c CSRCS += pthread_release.c pthread_setschedprio.c
CSRCS += pthread_get_stackaddr_np.c pthread_get_stacksize_np.c
ifneq ($(CONFIG_PTHREAD_MUTEX_UNSAFE),y) ifneq ($(CONFIG_PTHREAD_MUTEX_UNSAFE),y)
CSRCS += pthread_mutex.c pthread_mutexconsistent.c pthread_mutexinconsistent.c CSRCS += pthread_mutex.c pthread_mutexconsistent.c pthread_mutexinconsistent.c

View File

@ -0,0 +1,77 @@
/****************************************************************************
* sched/pthread/pthread_get_stackaddr_np.c
*
* Copyright (C) 2018 Geoff Norton. All rights reserved.
* Author: Geoff Norton <grompf@gmail.com>
*
* 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. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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
* COPYRIGHT OWNER 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.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <sys/types.h>
#include <pthread.h>
#include "pthread/pthread.h"
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: pthread_get_stackaddr_np
*
* Description:
* Get a pointer to the base of the pthread stack
*
* Parameters:
* pthread_t - The pthread being queried
*
* Returned Value:
* The pthread stack address is returned on success. NULL is returned
* if the 'thread' argument does not refer to a valid pthread.
*
****************************************************************************/
void *pthread_get_stackaddr_np(FAR pthread_t thread)
{
FAR struct pthread_tcb_s *tcb =
(FAR struct pthread_tcb_s *)sched_gettcb((pid_t)thread);
if (tcb == NULL)
{
return NULL;
}
return tcb->cmn.adj_stack_ptr;
}

View File

@ -0,0 +1,79 @@
/****************************************************************************
* sched/pthread/pthread_get_stacksize_np.c
*
* Copyright (C) 2018 Geoff Norton. All rights reserved.
* Author: Geoff Norton <grompf@gmail.com>
*
* 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. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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
* COPYRIGHT OWNER 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.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <sys/types.h>
#include <pthread.h>
#include <errno.h>
#include "pthread/pthread.h"
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: pthread_get_stacksize_np
*
* Description:
* Get a pointer to the base of the pthread stack
*
* Parameters:
* pthread_t - The pthread being queried
*
* Returned Value:
* A positive, non-zerp pthread stack address is returned on success. A
* negative value is returned in the case that the 'thread' argument does
* not refer to a valid thread.
*
****************************************************************************/
ssize_t pthread_get_stacksize_np(FAR pthread_t thread)
{
FAR struct pthread_tcb_s *tcb =
(FAR struct pthread_tcb_s *)sched_gettcb((pid_t)thread);
if (tcb == NULL)
{
return -EINVAL;
}
return tcb->cmn.adj_stack_size;
}

View File

@ -84,6 +84,8 @@
"pthread_create","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_t*","FAR const pthread_attr_t*","pthread_startroutine_t","pthread_addr_t" "pthread_create","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_t*","FAR const pthread_attr_t*","pthread_startroutine_t","pthread_addr_t"
"pthread_detach","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","pthread_t" "pthread_detach","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","pthread_t"
"pthread_exit","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","void","pthread_addr_t" "pthread_exit","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","void","pthread_addr_t"
"pthread_get_stackaddr_np","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","void*","pthread_t"
"pthread_get_stacksize_np","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","size_t","pthread_t"
"pthread_getaffinity_np","pthread.h","!defined(CONFIG_DISABLE_PTHREAD) && defined(CONFIG_SMP)","int","pthread_t","size_t","FAR cpu_set_t*" "pthread_getaffinity_np","pthread.h","!defined(CONFIG_DISABLE_PTHREAD) && defined(CONFIG_SMP)","int","pthread_t","size_t","FAR cpu_set_t*"
"pthread_getschedparam","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","pthread_t","FAR int*","FAR struct sched_param*" "pthread_getschedparam","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","pthread_t","FAR int*","FAR struct sched_param*"
"pthread_getspecific","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","FAR void*","pthread_key_t" "pthread_getspecific","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","FAR void*","pthread_key_t"

Can't render this file because it has a wrong number of fields in line 2.

View File

@ -304,6 +304,8 @@ SYSCALL_LOOKUP(up_assert, 2, STUB_up_assert)
SYSCALL_LOOKUP(pthread_join, 2, STUB_pthread_join) SYSCALL_LOOKUP(pthread_join, 2, STUB_pthread_join)
SYSCALL_LOOKUP(pthread_key_create, 2, STUB_pthread_key_create) SYSCALL_LOOKUP(pthread_key_create, 2, STUB_pthread_key_create)
SYSCALL_LOOKUP(pthread_key_delete, 1, STUB_pthread_key_delete) SYSCALL_LOOKUP(pthread_key_delete, 1, STUB_pthread_key_delete)
SYSCALL_LOOKUP(pthread_get_stackaddr_np, 1, STUB_pthread_get_stackaddr_np)
SYSCALL_LOOKUP(pthread_get_stacksize_np, 1, STUB_pthread_get_stacksize_np)
SYSCALL_LOOKUP(pthread_mutex_destroy, 1, STUB_pthread_mutex_destroy) SYSCALL_LOOKUP(pthread_mutex_destroy, 1, STUB_pthread_mutex_destroy)
SYSCALL_LOOKUP(pthread_mutex_init, 2, STUB_pthread_mutex_init) SYSCALL_LOOKUP(pthread_mutex_init, 2, STUB_pthread_mutex_init)
SYSCALL_LOOKUP(pthread_mutex_timedlock, 2, STUB_pthread_mutex_timedlock) SYSCALL_LOOKUP(pthread_mutex_timedlock, 2, STUB_pthread_mutex_timedlock)

View File

@ -308,6 +308,8 @@ uintptr_t STUB_pthread_join(int nbr, uintptr_t parm1, uintptr_t parm2);
uintptr_t STUB_pthread_key_create(int nbr, uintptr_t parm1, uintptr_t STUB_pthread_key_create(int nbr, uintptr_t parm1,
uintptr_t parm2); uintptr_t parm2);
uintptr_t STUB_pthread_key_delete(int nbr, uintptr_t parm1); uintptr_t STUB_pthread_key_delete(int nbr, uintptr_t parm1);
uintptr_t STUB_pthread_get_stackaddr_np(int nbr, uintptr_t parm1);
uintptr_t STUB_pthread_get_stacksize_np(int nbr, uintptr_t parm1);
uintptr_t STUB_pthread_mutex_destroy(int nbr, uintptr_t parm1); uintptr_t STUB_pthread_mutex_destroy(int nbr, uintptr_t parm1);
uintptr_t STUB_pthread_mutex_init(int nbr, uintptr_t parm1, uintptr_t STUB_pthread_mutex_init(int nbr, uintptr_t parm1,
uintptr_t parm2); uintptr_t parm2);