libc: Move pthread_create to user space

Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
Change-Id: I5c447d94077debc79158686935f288e4c8e51e01
This commit is contained in:
Gregory Nutt 2020-06-29 08:26:29 -06:00 committed by patacongo
parent a876f0253a
commit bb9b58bdde
50 changed files with 239 additions and 269 deletions

View File

@ -310,22 +310,22 @@ int arm_svcall(int irq, FAR void *context, FAR void *arg)
* R2 = arg
*/
#if defined(CONFIG_BUILD_PROTECTED) && !defined(CONFIG_DISABLE_PTHREAD)
#if !defined(CONFIG_BUILD_FLAT) && !defined(CONFIG_DISABLE_PTHREAD)
case SYS_pthread_start:
{
/* Set up to return to the user-space pthread start-up function in
* unprivileged mode.
*/
regs[REG_PC] = (uint32_t)USERSPACE->pthread_startup;
regs[REG_PC] = (uint32_t)regs[REG_R1]; /* startup */
regs[REG_EXC_RETURN] = EXC_RETURN_UNPRIVTHR;
/* Change the parameter ordering to match the expectation of struct
* userpace_s pthread_startup:
/* Change the parameter ordering to match the expectation of the
* user space pthread_startup:
*/
regs[REG_R0] = regs[REG_R1]; /* pthread entry */
regs[REG_R1] = regs[REG_R2]; /* arg */
regs[REG_R0] = regs[REG_R2]; /* pthread entry */
regs[REG_R1] = regs[REG_R3]; /* arg */
}
break;
#endif

View File

@ -89,6 +89,7 @@
#define SYS_syscall_return (3)
#ifndef CONFIG_BUILD_FLAT
#ifdef CONFIG_BUILD_PROTECTED
/* SYS call 4:
*
@ -98,15 +99,6 @@
#define SYS_task_start (4)
/* SYS call 5:
*
* void up_pthread_start(pthread_startroutine_t entrypt,
* pthread_addr_t arg)
* noreturn_function
*/
#define SYS_pthread_start (5)
/* SYS call 6:
*
* void signal_handler(_sa_sigaction_t sighand, int signo,
@ -124,6 +116,17 @@
#define SYS_signal_handler_return (7)
#endif /* CONFIG_BUILD_PROTECTED */
/* SYS call 5:
*
* void up_pthread_start(pthread_startroutine_t startup,
* pthread_startroutine_t entrypt, pthread_addr_t arg)
* noreturn_function
*/
#define SYS_pthread_start (5)
#endif /* !CONFIG_BUILD_FLAT */
#endif /* CONFIG_LIB_SYSCALL */
/****************************************************************************

View File

@ -290,19 +290,21 @@ uint32_t *arm_syscall(uint32_t *regs)
* R2 = arg
*/
#if defined(CONFIG_BUILD_KERNEL) && !defined(CONFIG_DISABLE_PTHREAD)
#if !defined(CONFIG_BUILD_FLAT) && !defined(CONFIG_DISABLE_PTHREAD)
case SYS_pthread_start:
{
/* Set up to return to the user-space pthread start-up function in
* unprivileged mode. We need:
*
* R0 = arg
* PC = entrypt
* R0 = entrypt
* R1 = arg
* PC = startup
* CSPR = user mode
*/
regs[REG_PC] = regs[REG_R1];
regs[REG_R0] = regs[REG_R2];
regs[REG_PC] = regs[REG_R0];
regs[REG_R0] = regs[REG_R1];
regs[REG_R1] = regs[REG_R2];
cpsr = regs[REG_CPSR] & ~PSR_MODE_MASK;
regs[REG_CPSR] = cpsr | PSR_MODE_USR;

View File

@ -65,6 +65,7 @@
#define SYS_syscall_return (0)
#ifndef CONFIG_BUILD_FLAT
#ifdef CONFIG_BUILD_KERNEL
/* SYS call 1:
*
@ -81,14 +82,6 @@
#define SYS_task_start (2)
/* SYS call 3:
*
* void up_pthread_start(pthread_startroutine_t entrypt, pthread_addr_t arg)
* noreturn_function
*/
#define SYS_pthread_start (3)
/* SYS call 4:
*
* void signal_handler(_sa_sigaction_t sighand,
@ -105,6 +98,17 @@
#define SYS_signal_handler_return (5)
#endif /* !CONFIG_BUILD_FLAT */
/* SYS call 3:
*
* void up_pthread_start(pthread_startroutine_t startup,
* pthread_startroutine_t entrypt, pthread_addr_t arg)
* noreturn_function
*/
#define SYS_pthread_start (3)
#endif /* CONFIG_BUILD_KERNEL */
/****************************************************************************

View File

@ -324,22 +324,22 @@ int arm_svcall(int irq, FAR void *context, FAR void *arg)
* R2 = arg
*/
#if defined(CONFIG_BUILD_PROTECTED) && !defined(CONFIG_DISABLE_PTHREAD)
#if !defined(CONFIG_BUILD_FLAT) && !defined(CONFIG_DISABLE_PTHREAD)
case SYS_pthread_start:
{
/* Set up to return to the user-space pthread start-up function in
* unprivileged mode.
*/
regs[REG_PC] = (uint32_t)USERSPACE->pthread_startup & ~1;
regs[REG_PC] = (uint32_t)regs[REG_R1] & ~1; /* startup */
regs[REG_EXC_RETURN] = EXC_RETURN_UNPRIVTHR;
/* Change the parameter ordering to match the expectation of struct
* userpace_s pthread_startup:
/* Change the parameter ordering to match the expectation of the
* user space pthread_startup:
*/
regs[REG_R0] = regs[REG_R1]; /* pthread entry */
regs[REG_R1] = regs[REG_R2]; /* arg */
regs[REG_R0] = regs[REG_R2]; /* pthread entry */
regs[REG_R1] = regs[REG_R3]; /* arg */
}
break;
#endif

View File

@ -81,6 +81,7 @@
#define SYS_switch_context (2)
#ifndef CONFIG_BUILD_FLAT
#ifdef CONFIG_LIB_SYSCALL
/* SYS call 3:
*
@ -98,14 +99,6 @@
#define SYS_task_start (4)
/* SYS call 5:
*
* void up_pthread_start(pthread_startroutine_t entrypt, pthread_addr_t arg)
* noreturn_function
*/
#define SYS_pthread_start (5)
/* SYS call 6:
*
* void signal_handler(_sa_sigaction_t sighand,
@ -123,6 +116,17 @@
#define SYS_signal_handler_return (7)
#endif /* CONFIG_BUILD_PROTECTED */
/* SYS call 5:
*
* void up_pthread_start((pthread_startroutine_t startup,
* pthread_startroutine_t entrypt, pthread_addr_t arg)
* noreturn_function
*/
#define SYS_pthread_start (5)
#endif /* !CONFIG_BUILD_FLAT */
#endif /* CONFIG_LIB_SYSCALL */
/****************************************************************************

View File

@ -285,19 +285,21 @@ uint32_t *arm_syscall(uint32_t *regs)
* R2 = arg
*/
#if defined(CONFIG_BUILD_PROTECTED) && !defined(CONFIG_DISABLE_PTHREAD)
#if !defined(CONFIG_BUILD_FLAT) && !defined(CONFIG_DISABLE_PTHREAD)
case SYS_pthread_start:
{
/* Set up to return to the user-space pthread start-up function in
* unprivileged mode. We need:
*
* R0 = arg
* R0 = startup
* R1 = arg
* PC = entrypt
* CSPR = user mode
*/
regs[REG_PC] = regs[REG_R1];
regs[REG_R0] = regs[REG_R2];
regs[REG_R1] = regs[REG_R3];
cpsr = regs[REG_CPSR] & ~PSR_MODE_MASK;
regs[REG_CPSR] = cpsr | PSR_MODE_USR;

View File

@ -66,6 +66,7 @@
#define SYS_syscall_return (0)
#ifndef CONFIG_BUILD_FLAT
#ifdef CONFIG_BUILD_PROTECTED
/* SYS call 1:
*
@ -82,14 +83,6 @@
#define SYS_task_start (2)
/* SYS call 3:
*
* void up_pthread_start(pthread_startroutine_t entrypt, pthread_addr_t arg)
* noreturn_function
*/
#define SYS_pthread_start (3)
/* SYS call 4:
*
* void signal_handler(_sa_sigaction_t sighand, int signo,
@ -108,6 +101,17 @@
#endif /* CONFIG_BUILD_PROTECTED */
/* SYS call 3:
*
* void up_pthread_start(pthread_startroutine_t startup,
* pthread_startroutine_t entrypt, pthread_addr_t arg)
* noreturn_function
*/
#define SYS_pthread_start (3)
#endif /* !CONFIG_BUILD_FLAT */
/****************************************************************************
* Inline Functions
****************************************************************************/

View File

@ -323,21 +323,21 @@ int arm_svcall(int irq, FAR void *context, FAR void *arg)
* R2 = arg
*/
#if defined(CONFIG_BUILD_PROTECTED) && !defined(CONFIG_DISABLE_PTHREAD)
#if !defined(CONFIG_BUILD_FLAT) && !defined(CONFIG_DISABLE_PTHREAD)
case SYS_pthread_start:
{
/* Set up to return to the user-space pthread start-up function in
* unprivileged mode.
*/
regs[REG_PC] = (uint32_t)USERSPACE->pthread_startup & ~1;
regs[REG_PC] = (uint32_t)regs[REG_R1] & ~1; /* startup */
regs[REG_EXC_RETURN] = EXC_RETURN_UNPRIVTHR;
/* Change the parameter ordering to match the expectation of struct
* userpace_s pthread_startup:
/* Change the parameter ordering to match the expectation of the
* user space pthread_startup:
*/
regs[REG_R0] = regs[REG_R1]; /* pthread entry */
regs[REG_R0] = regs[REG_R2]; /* pthread entry */
regs[REG_R1] = regs[REG_R2]; /* arg */
}
break;

View File

@ -88,6 +88,7 @@
#define SYS_syscall_return (3)
#ifndef CONFIG_BUILD_FLAT
#ifdef CONFIG_BUILD_PROTECTED
/* SYS call 4:
*
@ -97,14 +98,6 @@
#define SYS_task_start (4)
/* SYS call 5:
*
* void up_pthread_start(pthread_startroutine_t entrypt, pthread_addr_t arg)
* noreturn_function
*/
#define SYS_pthread_start (5)
/* SYS call 6:
*
* void signal_handler(_sa_sigaction_t sighand,
@ -122,6 +115,17 @@
#define SYS_signal_handler_return (7)
#endif /* CONFIG_BUILD_PROTECTED */
/* SYS call 5:
*
* void up_pthread_start(pthread_startroutine_t startup,
* pthread_startroutine_t entrypt, pthread_addr_t arg)
* noreturn_function
*/
#define SYS_pthread_start (5)
#endif /* !CONFIG_BUILD_FLAT */
#endif /* CONFIG_LIB_SYSCALL */
/****************************************************************************

View File

@ -47,9 +47,10 @@
* pthread.
*
* Normally the a user-mode start-up stub will also execute before the
* pthread actually starts. See libc/pthread/pthread_startup.c
* pthread actually starts. See libc/pthread/pthread_create.c
*
* Input Parameters:
* startup - The user-space pthread startup function
* entrypt - The user-space address of the pthread entry point
* arg - Standard argument for the pthread entry point
*
@ -60,11 +61,13 @@
*
****************************************************************************/
void up_pthread_start(pthread_startroutine_t entrypt, pthread_addr_t arg)
void up_pthread_start(pthread_trampoline_t startup,
pthread_startroutine_t entrypt, pthread_addr_t arg)
{
/* Let sys_call2() do all of the work */
/* Let sys_call3() do all of the work */
sys_call2(SYS_pthread_start, (uintptr_t)entrypt, (uintptr_t)arg);
sys_call3(SYS_pthread_start, (uintptr_t)startup, (uintptr_t)entrypt,
(uintptr_t)arg);
PANIC();
}

View File

@ -47,9 +47,10 @@
* pthread.
*
* Normally the a user-mode start-up stub will also execute before the
* pthread actually starts. See libc/pthread/pthread_startup.c
* pthread actually starts. See libc/pthread/pthread_create.c
*
* Input Parameters:
* startup - The user-space pthread startup function
* entrypt - The user-space address of the pthread entry point
* arg - Standard argument for the pthread entry point
*
@ -66,7 +67,8 @@ void up_pthread_start(pthread_startroutine_t entrypt, pthread_addr_t arg)
sinfo("entry %p arg %p\n", entrypt, arg);
sys_call2(SYS_pthread_start, (uintptr_t)entrypt, (uintptr_t)arg);
sys_call3(SYS_pthread_start, (uintptr_t)startup, (uintptr_t)entrypt,
(uintptr_t)arg);
PANIC();
}

View File

@ -47,9 +47,10 @@
* pthread.
*
* Normally the a user-mode start-up stub will also execute before the
* pthread actually starts. See libc/pthread/pthread_startup.c
* pthread actually starts. See libc/pthread/pthread_create.c
*
* Input Parameters:
* startup - The user-space pthread startup function
* entrypt - The user-space address of the pthread entry point
* arg - Standard argument for the pthread entry point
*
@ -60,11 +61,13 @@
*
****************************************************************************/
void up_pthread_start(pthread_startroutine_t entrypt, pthread_addr_t arg)
void up_pthread_start(pthread_trampoline_t startup,
pthread_startroutine_t entrypt, pthread_addr_t arg)
{
/* Let sys_call2() do all of the work */
sys_call2(SYS_pthread_start, (uintptr_t)entrypt, (uintptr_t)arg);
sys_call3(SYS_pthread_start, (uintptr_t)startup, (uintptr_t)entrypt,
(uintptr_t)arg);
PANIC();
}

View File

@ -294,21 +294,21 @@ int riscv_swint(int irq, FAR void *context, FAR void *arg)
* R2 = arg
*/
#if defined(CONFIG_BUILD_PROTECTED) && !defined(CONFIG_DISABLE_PTHREAD)
#if !defined(CONFIG_BUILD_FLAT) && !defined(CONFIG_DISABLE_PTHREAD)
case SYS_pthread_start:
{
/* Set up to return to the user-space pthread start-up function in
* unprivileged mode.
*/
regs[REG_EPC] = (uintptr_t)USERSPACE->pthread_startup & ~1;
regs[REG_EPC] = (uintptr_t)regs[REG_A1] & ~1; /* startup */
/* Change the parameter ordering to match the expectation of struct
* userpace_s pthread_startup:
/* Change the parameter ordering to match the expectation of the
* user space pthread_startup:
*/
regs[REG_A0] = regs[REG_A1]; /* pthread entry */
regs[REG_A1] = regs[REG_A2]; /* arg */
regs[REG_A0] = regs[REG_A2]; /* pthread entry */
regs[REG_A1] = regs[REG_A3]; /* arg */
regs[REG_INT_CTX] &= ~MSTATUS_MPPM; /* User mode */
}
break;

View File

@ -82,6 +82,7 @@
#define SYS_switch_context (2)
#ifndef CONFIG_BUILD_FLAT
#ifdef CONFIG_LIB_SYSCALL
/* SYS call 3:
*
@ -98,15 +99,6 @@
*/
#define SYS_task_start (4)
/* SYS call 5:
*
* void up_pthread_start(pthread_startroutine_t entrypt, pthread_addr_t arg)
* noreturn_function
*/
#define SYS_pthread_start (5)
/* SYS call 6:
*
* void signal_handler(_sa_sigaction_t sighand, int signo,
@ -123,6 +115,17 @@
#define SYS_signal_handler_return (7)
#endif /* CONFIG_BUILD_PROTECTED */
/* SYS call 5:
*
* void up_pthread_start(pthread_startroutine_t startup,
* pthread_startroutine_t entrypt, pthread_addr_t arg)
* noreturn_function
*/
#define SYS_pthread_start (5)
#endif /* !CONFIG_BUILD_FLAT */
#endif /* CONFIG_LIB_SYSCALL */
#endif /* __ARCH_RISCV_SRC_RV64GC_SVCALL_H */

View File

@ -94,9 +94,6 @@ const struct userspace_s userspace __attribute__ ((section (".userspace"))) =
/* Task/thread startup routines */
.task_startup = nxtask_startup,
#ifndef CONFIG_DISABLE_PTHREAD
.pthread_startup = pthread_startup,
#endif
/* Signal handler trampoline */

View File

@ -94,9 +94,6 @@ const struct userspace_s userspace __attribute__ ((section (".userspace"))) =
/* Task/thread startup routines */
.task_startup = nxtask_startup,
#ifndef CONFIG_DISABLE_PTHREAD
.pthread_startup = pthread_startup,
#endif
/* Signal handler trampoline */

View File

@ -95,9 +95,6 @@ const struct userspace_s userspace __attribute__ ((section (".userspace"))) =
/* Task/thread startup routines */
.task_startup = nxtask_startup,
#ifndef CONFIG_DISABLE_PTHREAD
.pthread_startup = pthread_startup,
#endif
/* Signal handler trampoline */

View File

@ -94,9 +94,6 @@ const struct userspace_s userspace __attribute__ ((section (".userspace"))) =
/* Task/thread startup routines */
.task_startup = nxtask_startup,
#ifndef CONFIG_DISABLE_PTHREAD
.pthread_startup = pthread_startup,
#endif
/* Signal handler trampoline */

View File

@ -94,9 +94,6 @@ const struct userspace_s userspace __attribute__ ((section (".userspace"))) =
/* Task/thread startup routines */
.task_startup = nxtask_startup,
#ifndef CONFIG_DISABLE_PTHREAD
.pthread_startup = pthread_startup,
#endif
/* Signal handler trampoline */

View File

@ -94,9 +94,6 @@ const struct userspace_s userspace __attribute__ ((section (".userspace"))) =
/* Task/thread startup routines */
.task_startup = nxtask_startup,
#ifndef CONFIG_DISABLE_PTHREAD
.pthread_startup = pthread_startup,
#endif
/* Signal handler trampoline */

View File

@ -94,9 +94,6 @@ const struct userspace_s userspace __attribute__ ((section (".userspace"))) =
/* Task/thread startup routines */
.task_startup = nxtask_startup,
#ifndef CONFIG_DISABLE_PTHREAD
.pthread_startup = pthread_startup,
#endif
/* Signal handler trampoline */

View File

@ -95,9 +95,6 @@ const struct userspace_s userspace __attribute__ ((section (".userspace"))) =
/* Task/thread startup routines */
.task_startup = nxtask_startup,
#ifndef CONFIG_DISABLE_PTHREAD
.pthread_startup = pthread_startup,
#endif
/* Signal handler trampoline */

View File

@ -94,9 +94,6 @@ const struct userspace_s userspace __attribute__ ((section (".userspace"))) =
/* Task/thread startup routines */
.task_startup = nxtask_startup,
#ifndef CONFIG_DISABLE_PTHREAD
.pthread_startup = pthread_startup,
#endif
/* Signal handler trampoline */

View File

@ -94,9 +94,6 @@ const struct userspace_s userspace __attribute__ ((section (".userspace"))) =
/* Task/thread startup routines */
.task_startup = nxtask_startup,
#ifndef CONFIG_DISABLE_PTHREAD
.pthread_startup = pthread_startup,
#endif
/* Signal handler trampoline */

View File

@ -94,9 +94,6 @@ const struct userspace_s userspace __attribute__ ((section (".userspace"))) =
/* Task/thread startup routines */
.task_startup = nxtask_startup,
#ifndef CONFIG_DISABLE_PTHREAD
.pthread_startup = pthread_startup,
#endif
/* Signal handler trampoline */

View File

@ -95,9 +95,6 @@ const struct userspace_s userspace __attribute__ ((section (".userspace"))) =
/* Task/thread startup routines */
.task_startup = nxtask_startup,
#ifndef CONFIG_DISABLE_PTHREAD
.pthread_startup = pthread_startup,
#endif
/* Signal handler trampoline */

View File

@ -94,9 +94,6 @@ const struct userspace_s userspace __attribute__ ((section (".userspace"))) =
/* Task/thread startup routines */
.task_startup = nxtask_startup,
#ifndef CONFIG_DISABLE_PTHREAD
.pthread_startup = pthread_startup,
#endif
/* Signal handler trampoline */

View File

@ -95,9 +95,6 @@ const struct userspace_s userspace __attribute__ ((section (".userspace"))) =
/* Task/thread startup routines */
.task_startup = nxtask_startup,
#ifndef CONFIG_DISABLE_PTHREAD
.pthread_startup = pthread_startup,
#endif
/* Signal handler trampoline */

View File

@ -112,9 +112,6 @@ const struct userspace_s userspace __attribute__ ((section (".userspace"))) =
/* Task/thread startup routines */
.task_startup = nxtask_startup,
#ifndef CONFIG_DISABLE_PTHREAD
.pthread_startup = pthread_startup,
#endif
/* Signal handler trampoline */

View File

@ -94,9 +94,6 @@ const struct userspace_s userspace __attribute__ ((section (".userspace"))) =
/* Task/thread startup routines */
.task_startup = nxtask_startup,
#ifndef CONFIG_DISABLE_PTHREAD
.pthread_startup = pthread_startup,
#endif
/* Signal handler trampoline */

View File

@ -95,9 +95,6 @@ const struct userspace_s userspace __attribute__ ((section (".userspace"))) =
/* Task/thread startup routines */
.task_startup = nxtask_startup,
#ifndef CONFIG_DISABLE_PTHREAD
.pthread_startup = pthread_startup,
#endif
/* Signal handler trampoline */

View File

@ -95,9 +95,6 @@ const struct userspace_s userspace __attribute__ ((section (".userspace"))) =
/* Task/thread startup routines */
.task_startup = nxtask_startup,
#ifndef CONFIG_DISABLE_PTHREAD
.pthread_startup = pthread_startup,
#endif
/* Signal handler trampoline */

View File

@ -95,9 +95,6 @@ const struct userspace_s userspace __attribute__ ((section (".userspace"))) =
/* Task/thread startup routines */
.task_startup = nxtask_startup,
#ifndef CONFIG_DISABLE_PTHREAD
.pthread_startup = pthread_startup,
#endif
/* Signal handler trampoline */

View File

@ -95,9 +95,6 @@ const struct userspace_s userspace __attribute__ ((section (".userspace"))) =
/* Task/thread startup routines */
.task_startup = nxtask_startup,
#ifndef CONFIG_DISABLE_PTHREAD
.pthread_startup = pthread_startup,
#endif
/* Signal handler trampoline */

View File

@ -95,9 +95,6 @@ const struct userspace_s userspace __attribute__ ((section (".userspace"))) =
/* Task/thread startup routines */
.task_startup = nxtask_startup,
#ifndef CONFIG_DISABLE_PTHREAD
.pthread_startup = pthread_startup,
#endif
/* Signal handler trampoline */

View File

@ -95,9 +95,6 @@ const struct userspace_s userspace __attribute__ ((section (".userspace"))) =
/* Task/thread startup routines */
.task_startup = nxtask_startup,
#ifndef CONFIG_DISABLE_PTHREAD
.pthread_startup = pthread_startup,
#endif
/* Signal handler trampoline */

View File

@ -95,9 +95,6 @@ const struct userspace_s userspace __attribute__ ((section (".userspace"))) =
/* Task/thread startup routines */
.task_startup = nxtask_startup,
#ifndef CONFIG_DISABLE_PTHREAD
.pthread_startup = pthread_startup,
#endif
/* Signal handler trampoline */

View File

@ -95,9 +95,6 @@ const struct userspace_s userspace __attribute__ ((section (".userspace"))) =
/* Task/thread startup routines */
.task_startup = nxtask_startup,
#ifndef CONFIG_DISABLE_PTHREAD
.pthread_startup = pthread_startup,
#endif
/* Signal handler trampoline */

View File

@ -95,9 +95,6 @@ const struct userspace_s userspace __attribute__ ((section (".userspace"))) =
/* Task/thread startup routines */
.task_startup = nxtask_startup,
#ifndef CONFIG_DISABLE_PTHREAD
.pthread_startup = pthread_startup,
#endif
/* Signal handler trampoline */

View File

@ -569,9 +569,10 @@ void up_task_start(main_t taskentry, int argc, FAR char *argv[])
* pthread by calling this function.
*
* Normally the a user-mode start-up stub will also execute before the
* pthread actually starts. See libc/pthread/pthread_startup.c
* pthread actually starts. See libc/pthread/pthread_create.c
*
* Input Parameters:
* startup - The user-space pthread startup function
* entrypt - The user-space address of the pthread entry point
* arg - Standard argument for the pthread entry point
*
@ -584,7 +585,8 @@ void up_task_start(main_t taskentry, int argc, FAR char *argv[])
#if !defined(CONFIG_BUILD_FLAT) && defined(__KERNEL__) && \
!defined(CONFIG_DISABLE_PTHREAD)
void up_pthread_start(pthread_startroutine_t entrypt, pthread_addr_t arg)
void up_pthread_start(pthread_trampoline_t startup,
pthread_startroutine_t entrypt, pthread_addr_t arg);
noreturn_function;
#endif

View File

@ -100,7 +100,7 @@
#endif
/****************************************************************************
* Public Data
* Public Types
****************************************************************************/
#ifdef __cplusplus
@ -111,6 +111,10 @@ extern "C"
#define EXTERN extern
#endif
/****************************************************************************
* Public Data
****************************************************************************/
/* Default pthread attributes. This global can only be shared within the
* kernel- or within the user- address space.
*/
@ -121,6 +125,30 @@ EXTERN const pthread_attr_t g_default_pthread_attr;
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: nx_pthread_create
*
* Description:
* This function creates and activates a new thread with specified
* attributes.
*
* Input Parameters:
* trampoline
* thread
* attr
* start_routine
* arg
*
* Returned Value:
* OK (0) on success; a (non-negated) errno value on failure. The errno
* variable is not set.
*
****************************************************************************/
int nx_pthread_create(pthread_trampoline_t trampoline, FAR pthread_t *thread,
FAR const pthread_attr_t *attr,
pthread_startroutine_t entry, pthread_addr_t arg);
#undef EXTERN
#ifdef __cplusplus
}

View File

@ -770,6 +770,7 @@ struct pthread_tcb_s
/* Task Management Fields *****************************************************/
pthread_trampoline_t trampoline; /* User-space pthread startup function */
pthread_addr_t arg; /* Startup argument */
FAR void *joininfo; /* Detach-able info to support join */
};

View File

@ -100,13 +100,9 @@ struct userspace_s
FAR struct mm_heap_s *us_heap;
/* Task/thread startup routines */
/* Task startup routine */
CODE void (*task_startup)(main_t entrypt, int argc, FAR char *argv[]);
#ifndef CONFIG_DISABLE_PTHREAD
CODE void (*pthread_startup)(pthread_startroutine_t entrypt,
pthread_addr_t arg);
#endif
/* Signal handler trampoline */
@ -136,26 +132,6 @@ extern "C"
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: pthread_startup
*
* Description:
* This function is the user-space, pthread startup function. It is called
* from up_pthread_start() in user-mode.
*
* Input Parameters:
* entrypt - The user-space address of the pthread entry point
* arg - Standard argument for the pthread entry point
*
* Returned Value:
* None. This function does not return.
*
****************************************************************************/
#if !defined(__KERNEL__) && !defined(CONFIG_DISABLE_PTHREAD)
void pthread_startup(pthread_startroutine_t entrypt, pthread_addr_t arg);
#endif
#undef EXTERN
#ifdef __cplusplus
}

View File

@ -225,6 +225,8 @@ typedef FAR void *pthread_addr_t;
typedef CODE pthread_addr_t (*pthread_startroutine_t)(pthread_addr_t);
typedef pthread_startroutine_t pthread_func_t;
typedef void (*pthread_trampoline_t)(pthread_startroutine_t, pthread_addr_t);
struct pthread_attr_s
{
uint8_t priority; /* Priority of the pthread */

View File

@ -305,7 +305,7 @@ SYSCALL_LOOKUP(telldir, 1)
SYSCALL_LOOKUP(pthread_cond_broadcast, 1)
SYSCALL_LOOKUP(pthread_cond_signal, 1)
SYSCALL_LOOKUP(pthread_cond_wait, 2)
SYSCALL_LOOKUP(pthread_create, 4)
SYSCALL_LOOKUP(nx_pthread_create, 5)
SYSCALL_LOOKUP(pthread_detach, 1)
SYSCALL_LOOKUP(pthread_exit, 1)
SYSCALL_LOOKUP(pthread_getschedparam, 3)

View File

@ -38,19 +38,20 @@ CSRCS += pthread_barrierattr_init.c pthread_barrierattr_destroy.c
CSRCS += pthread_barrierattr_getpshared.c pthread_barrierattr_setpshared.c
CSRCS += pthread_barrierinit.c pthread_barrierdestroy.c pthread_barrierwait.c
CSRCS += pthread_condattr_init.c pthread_condattr_destroy.c
CSRCS += pthread_condattr_setclock.c pthread_condattr_getclock.c
CSRCS += pthread_condinit.c pthread_conddestroy.c pthread_condtimedwait.c
CSRCS += pthread_create.c
CSRCS += pthread_get_stackaddr_np.c pthread_get_stacksize_np.c
CSRCS += pthread_mutexattr_init.c pthread_mutexattr_destroy.c
CSRCS += pthread_mutexattr_getpshared.c pthread_mutexattr_setpshared.c
CSRCS += pthread_mutexattr_setprotocol.c pthread_mutexattr_getprotocol.c
CSRCS += pthread_mutexattr_settype.c pthread_mutexattr_gettype.c
CSRCS += pthread_mutexattr_setrobust.c pthread_mutexattr_getrobust.c
CSRCS += pthread_mutex_lock.c
CSRCS += pthread_once.c pthread_yield.c
CSRCS += pthread_rwlock.c pthread_rwlock_rdlock.c pthread_rwlock_wrlock.c
CSRCS += pthread_setcancelstate.c pthread_setcanceltype.c
CSRCS += pthread_testcancel.c
CSRCS += pthread_rwlock.c pthread_rwlock_rdlock.c pthread_rwlock_wrlock.c
CSRCS += pthread_once.c pthread_yield.c
CSRCS += pthread_get_stackaddr_np.c pthread_get_stacksize_np.c
CSRCS += pthread_condattr_setclock.c pthread_condattr_getclock.c
ifeq ($(CONFIG_SMP),y)
CSRCS += pthread_attr_getaffinity.c pthread_attr_setaffinity.c
@ -60,14 +61,9 @@ ifeq ($(CONFIG_PTHREAD_SPINLOCKS),y)
CSRCS += pthread_spinlock.c
endif
ifeq ($(CONFIG_BUILD_PROTECTED),y)
CSRCS += pthread_startup.c
endif
endif # CONFIG_DISABLE_PTHREAD
# Add the pthread directory to the build
DEPPATH += --dep-path pthread
VPATH += :pthread

View File

@ -1,5 +1,5 @@
/****************************************************************************
* libs/libc/pthread/pthread_startup.c
* libs/libc/pthread/pthread_create.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
@ -24,70 +24,68 @@
#include <nuttx/config.h>
#include <pthread.h>
#include <assert.h>
#include <debug.h>
#include <nuttx/userspace.h>
#if !defined(CONFIG_BUILD_FLAT) && !defined(__KERNEL__)
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Private Type Declarations
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
#include <nuttx/pthread.h>
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: pthread_startup
*
* Description:
* This function is the user-space, pthread startup function. It is called
* from up_pthread_start() in user-mode.
* This function is the user space pthread startup function. Its purpose
* is to catch the return from the pthread main function so that
* pthread_exit() can be called from user space
*
* Input Parameters:
* entrypt - The user-space address of the pthread entry point
* arg - Standard argument for the pthread entry point
* entry - The user-space address of the pthread entry point
* arg - Standard argument for the pthread entry point
*
* Returned Value:
* None. This function does not return.
*
****************************************************************************/
void pthread_startup(pthread_startroutine_t entrypt, pthread_addr_t arg)
static void pthread_startup(pthread_startroutine_t entry,
pthread_addr_t arg)
{
pthread_addr_t exit_status;
DEBUGASSERT(entry != NULL);
DEBUGASSERT(entrypt);
/* Pass control to the thread entry point. Handle any returned value. */
/* Pass control to the thread entry point. */
exit_status = entrypt(arg);
/* The pthread has returned */
pthread_exit(exit_status);
pthread_exit(entry(arg));
}
#endif /* !CONFIG_BUILD_FLAT && !__KERNEL__ */
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: pthread_create
*
* Description:
* This function creates and activates a new thread with specified
* attributes. It is simply a wrapper around the nx_pthread_create system
* call.
*
* Input Parameters:
* thread
* attr
* pthread_entry
* arg
*
* Returned Value:
* OK (0) on success; a (non-negated) errno value on failure. The errno
* variable is not set.
*
****************************************************************************/
int pthread_create(FAR pthread_t *thread, FAR const pthread_attr_t *attr,
pthread_startroutine_t pthread_entry, pthread_addr_t arg)
{
return nx_pthread_create(pthread_startup, thread, attr, pthread_entry,
arg);
}

View File

@ -64,19 +64,20 @@ const pthread_attr_t g_default_pthread_attr = PTHREAD_ATTR_INITIALIZER;
****************************************************************************/
/****************************************************************************
* Name: pthread_argsetup
* Name: pthread_tcb_setup
*
* Description:
* This functions sets up parameters in the Task Control Block (TCB) in
* This function sets up parameters in the Task Control Block (TCB) in
* preparation for starting a new thread.
*
* pthread_argsetup() is called from nxtask_init() and nxtask_start() to
* pthread_tcb_setup() is called from nxtask_init() and nxtask_start() to
* create a new task (with arguments cloned via strdup) or pthread_create()
* which has one argument passed by value (distinguished by the pthread
* boolean argument).
*
* Input Parameters:
* tcb - Address of the new task's TCB
* trampoline - User space pthread startup function
* arg - The argument to provide to the pthread on startup.
*
* Returned Value:
@ -84,21 +85,23 @@ const pthread_attr_t g_default_pthread_attr = PTHREAD_ATTR_INITIALIZER;
*
****************************************************************************/
static inline void pthread_argsetup(FAR struct pthread_tcb_s *tcb,
pthread_addr_t arg)
static inline void pthread_tcb_setup(FAR struct pthread_tcb_s *ptcb,
pthread_trampoline_t trampoline,
pthread_addr_t arg)
{
#if CONFIG_TASK_NAME_SIZE > 0
/* Copy the pthread name into the TCB */
snprintf(tcb->cmn.name, CONFIG_TASK_NAME_SIZE,
"pt-%p", tcb->cmn.entry.pthread);
snprintf(ptcb->cmn.name, CONFIG_TASK_NAME_SIZE,
"pt-%p", ptcb->cmn.entry.pthread);
#endif /* CONFIG_TASK_NAME_SIZE */
/* For pthreads, args are strictly pass-by-value; that actual
* type wrapped by pthread_addr_t is unknown.
*/
tcb->arg = arg;
ptcb->trampoline = trampoline;
ptcb->arg = arg;
}
/****************************************************************************
@ -150,9 +153,8 @@ static void pthread_start(void)
FAR struct pthread_tcb_s *ptcb = (FAR struct pthread_tcb_s *)this_task();
FAR struct task_group_s *group = ptcb->cmn.group;
FAR struct join_s *pjoin = (FAR struct join_s *)ptcb->joininfo;
pthread_addr_t exit_status;
DEBUGASSERT(group && pjoin);
DEBUGASSERT(group != NULL && pjoin != NULL);
/* Successfully spawned, add the pjoin to our data set. */
@ -180,16 +182,18 @@ static void pthread_start(void)
* to switch to user-mode before calling into the pthread.
*/
DEBUGASSERT(ptcb->trampoline != NULL && ptcb->cmn.entry.pthread != NULL);
#ifdef CONFIG_BUILD_FLAT
exit_status = (*ptcb->cmn.entry.pthread)(ptcb->arg);
ptcb->trampoline(ptcb->cmn.entry.pthread, ptcb->arg);
#else
up_pthread_start(ptcb->cmn.entry.pthread, ptcb->arg);
exit_status = NULL;
up_pthread_start(ptcb->trampoline, ptcb->cmn.entry.pthread, ptcb->arg);
#endif
/* The thread has returned (should never happen in the kernel mode case) */
/* The thread has returned (should never happen) */
pthread_exit(exit_status);
DEBUGPANIC();
pthread_exit(NULL);
}
/****************************************************************************
@ -197,13 +201,14 @@ static void pthread_start(void)
****************************************************************************/
/****************************************************************************
* Name: pthread_create
* Name: nx_pthread_create
*
* Description:
* This function creates and activates a new thread with a specified
* This function creates and activates a new thread with specified
* attributes.
*
* Input Parameters:
* trampoline
* thread
* attr
* start_routine
@ -215,8 +220,9 @@ static void pthread_start(void)
*
****************************************************************************/
int pthread_create(FAR pthread_t *thread, FAR const pthread_attr_t *attr,
pthread_startroutine_t start_routine, pthread_addr_t arg)
int nx_pthread_create(pthread_trampoline_t trampoline, FAR pthread_t *thread,
FAR const pthread_attr_t *attr,
pthread_startroutine_t entry, pthread_addr_t arg)
{
FAR struct pthread_tcb_s *ptcb;
FAR struct tls_info_s *info;
@ -228,6 +234,8 @@ int pthread_create(FAR pthread_t *thread, FAR const pthread_attr_t *attr,
int ret;
bool group_joined = false;
DEBUGASSERT(trampoline != NULL);
/* If attributes were not supplied, use the default attributes */
if (!attr)
@ -415,7 +423,7 @@ int pthread_create(FAR pthread_t *thread, FAR const pthread_attr_t *attr,
/* Initialize the task control block */
ret = pthread_setup_scheduler(ptcb, param.sched_priority, pthread_start,
start_routine);
entry);
if (ret != OK)
{
errcode = EBUSY;
@ -440,7 +448,7 @@ int pthread_create(FAR pthread_t *thread, FAR const pthread_attr_t *attr,
* passed by value
*/
pthread_argsetup(ptcb, arg);
pthread_tcb_setup(ptcb, trampoline, arg);
/* Join the parent's task group */

View File

@ -66,6 +66,7 @@
"munmap","sys/mman.h","defined(CONFIG_FS_RAMMAP)","int","FAR void *","size_t"
"nx_mkfifo","nuttx/fs/fs.h","defined(CONFIG_PIPES) && CONFIG_DEV_FIFO_SIZE > 0","int","FAR const char *","mode_t","size_t"
"nx_pipe","nuttx/fs/fs.h","defined(CONFIG_PIPES) && CONFIG_DEV_PIPE_SIZE > 0","int","int [2]|FAR int *","size_t","int"
"nx_pthread_create","nuttx/pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","pthread_trampoline_t","FAR pthread_t *","FAR const pthread_attr_t *","pthread_startroutine_t","pthread_addr_t"
"nx_task_spawn","nuttx/spawn.h","defined(CONFIG_LIB_SYSCALL) && !defined(CONFIG_BUILD_KERNEL)","int","FAR const struct spawn_syscall_parms_s *"
"nx_vsyslog","nuttx/syslog/syslog.h","","int","int","FAR const IPTR char *","FAR va_list *"
"nxsched_get_stackinfo","nuttx/sched.h","","int","pid_t","FAR struct stackinfo_s *"
@ -88,7 +89,6 @@
"pthread_cond_clockwait","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_cond_t *","FAR pthread_mutex_t *","clockid_t","FAR const struct timespec *"
"pthread_cond_signal","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_cond_t *"
"pthread_cond_wait","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_cond_t *","FAR pthread_mutex_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_exit","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","noreturn","pthread_addr_t"
"pthread_getaffinity_np","pthread.h","!defined(CONFIG_DISABLE_PTHREAD) && defined(CONFIG_SMP)","int","pthread_t","size_t","FAR cpu_set_t*"

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