diff --git a/arch/arm/src/a1x/Make.defs b/arch/arm/src/a1x/Make.defs index 8cb5a8fb26..a547ebecdc 100644 --- a/arch/arm/src/a1x/Make.defs +++ b/arch/arm/src/a1x/Make.defs @@ -74,6 +74,7 @@ endif ifeq ($(CONFIG_BUILD_KERNEL),y) CMN_CSRCS += arm_task_start.c arm_pthread_start.c arm_signal_dispatch.c +CMN_CSRCS += arm_pthread_exit.c endif ifeq ($(CONFIG_ARCH_ADDRENV),y) diff --git a/arch/arm/src/am335x/Make.defs b/arch/arm/src/am335x/Make.defs index b8a7ed51bd..df6f7fec44 100644 --- a/arch/arm/src/am335x/Make.defs +++ b/arch/arm/src/am335x/Make.defs @@ -70,6 +70,7 @@ endif ifeq ($(CONFIG_BUILD_KERNEL),y) CMN_CSRCS += arm_task_start.c arm_pthread_start.c arm_signal_dispatch.c +CMN_CSRCS += arm_pthread_exit.c endif ifeq ($(CONFIG_ARCH_ADDRENV),y) diff --git a/arch/arm/src/armv6-m/arm_svcall.c b/arch/arm/src/armv6-m/arm_svcall.c index 0339cccd13..6517b4c0f1 100644 --- a/arch/arm/src/armv6-m/arm_svcall.c +++ b/arch/arm/src/armv6-m/arm_svcall.c @@ -298,26 +298,28 @@ int arm_svcall(int irq, FAR void *context, FAR void *arg) break; #endif +#if !defined(CONFIG_BUILD_FLAT) && !defined(CONFIG_DISABLE_PTHREAD) + /* R0=SYS_pthread_start: This a user pthread start * - * void up_pthread_start(pthread_startroutine_t entrypt, - * pthread_addr_t arg) noreturn_function; + * void up_pthread_start(pthread_trampoline_t startup, + * pthread_startroutine_t entrypt, pthread_addr_t arg) * * At this point, the following values are saved in context: * * R0 = SYS_pthread_start - * R1 = entrypt - * R2 = arg + * R1 = startup + * R2 = entrypt + * R3 = arg */ -#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)regs[REG_R1]; /* startup */ + 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 the @@ -328,6 +330,35 @@ int arm_svcall(int irq, FAR void *context, FAR void *arg) regs[REG_R1] = regs[REG_R3]; /* arg */ } break; + + /* R0=SYS_pthread_exit: This pthread_exit call in user-space + * + * void up_pthread_exit(pthread_exitroutine_t exit, + * FAR void *exit_value) + * + * At this point, the following values are saved in context: + * + * R0 = SYS_pthread_exit + * R1 = pthread_exit trampoline routine + * R2 = exit_value + */ + + case SYS_pthread_exit: + { + /* Set up to return to the user-space pthread start-up function in + * unprivileged mode. + */ + + 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 the + * user space pthread_startup: + */ + + regs[REG_R0] = regs[REG_R2]; /* exit_value */ + } + break; #endif /* R0=SYS_signal_handler: This a user signal handler callback diff --git a/arch/arm/src/armv6-m/svcall.h b/arch/arm/src/armv6-m/svcall.h index a790f58d4d..0b0f8d7cd8 100644 --- a/arch/arm/src/armv6-m/svcall.h +++ b/arch/arm/src/armv6-m/svcall.h @@ -45,9 +45,9 @@ #ifdef CONFIG_LIB_SYSCALL # ifdef CONFIG_BUILD_PROTECTED # ifndef CONFIG_SYS_RESERVED -# error "CONFIG_SYS_RESERVED must be defined to have the value 8" -# elif CONFIG_SYS_RESERVED != 8 -# error "CONFIG_SYS_RESERVED must have the value 8" +# error "CONFIG_SYS_RESERVED must be defined to have the value 9" +# elif CONFIG_SYS_RESERVED != 9 +# error "CONFIG_SYS_RESERVED must have the value 9" # endif # else # ifndef CONFIG_SYS_RESERVED diff --git a/arch/arm/src/armv7-a/arm_syscall.c b/arch/arm/src/armv7-a/arm_syscall.c index 985dc637d3..999d1b1df2 100644 --- a/arch/arm/src/armv7-a/arm_syscall.c +++ b/arch/arm/src/armv7-a/arm_syscall.c @@ -278,30 +278,23 @@ uint32_t *arm_syscall(uint32_t *regs) break; #endif +#if !defined(CONFIG_BUILD_FLAT) && !defined(CONFIG_DISABLE_PTHREAD) + /* R0=SYS_pthread_start: This a user pthread start * - * void up_pthread_start(pthread_startroutine_t entrypt, - * pthread_addr_t arg) noreturn_function; + * void up_pthread_start(pthread_trampoline_t startup, + * pthread_startroutine_t entrypt, pthread_addr_t arg) * * At this point, the following values are saved in context: * * R0 = SYS_pthread_start - * R1 = entrypt - * R2 = arg + * R1 = startup + * R2 = entrypt + * R3 = arg */ -#if !defined(CONFIG_BUILD_FLAT) && !defined(CONFIG_DISABLE_PTHREAD) case SYS_pthread_start: { - /* Set up to enter the user-space pthread start-up function in - * unprivileged mode. We need: - * - * R0 = entrypt - * R1 = arg - * PC = startup - * CSPR = user mode - */ - regs[REG_PC] = regs[REG_R0]; regs[REG_R0] = regs[REG_R1]; regs[REG_R1] = regs[REG_R2]; @@ -310,6 +303,28 @@ uint32_t *arm_syscall(uint32_t *regs) regs[REG_CPSR] = cpsr | PSR_MODE_USR; } break; + + /* R0=SYS_pthread_exit: This pthread_exit call in user-space + * + * void up_pthread_exit(pthread_exitroutine_t exit, + * FAR void *exit_value) + * + * At this point, the following values are saved in context: + * + * R0 = SYS_pthread_exit + * R1 = pthread_exit trampoline routine + * R2 = exit_value + */ + + case SYS_pthread_exit: + { + regs[REG_PC] = regs[REG_R0]; + regs[REG_R0] = regs[REG_R1]; + + cpsr = regs[REG_CPSR] & ~PSR_MODE_MASK; + regs[REG_CPSR] = cpsr | PSR_MODE_USR; + } + break; #endif #ifdef CONFIG_BUILD_KERNEL diff --git a/arch/arm/src/armv7-a/svcall.h b/arch/arm/src/armv7-a/svcall.h index 27dc875510..d22fde1c87 100644 --- a/arch/arm/src/armv7-a/svcall.h +++ b/arch/arm/src/armv7-a/svcall.h @@ -44,8 +44,8 @@ #ifdef CONFIG_BUILD_KERNEL # ifndef CONFIG_SYS_RESERVED -# error "CONFIG_SYS_RESERVED must be defined to have the value 6" -# elif CONFIG_SYS_RESERVED != 6 +# error "CONFIG_SYS_RESERVED must be defined to have the value 7" +# elif CONFIG_SYS_RESERVED != 7 # error "CONFIG_SYS_RESERVED must have the value 6" # endif #else @@ -109,6 +109,13 @@ #define SYS_pthread_start (3) +/* SYS call 8: + * + * void up_pthread_exit(pthread_exitroutine_t exit, FAR void *exit_value) + */ + +#define SYS_pthread_exit (6) + #endif /* CONFIG_BUILD_KERNEL */ /**************************************************************************** diff --git a/arch/arm/src/armv7-m/arm_svcall.c b/arch/arm/src/armv7-m/arm_svcall.c index 6119ee6297..ca38d1b60a 100644 --- a/arch/arm/src/armv7-m/arm_svcall.c +++ b/arch/arm/src/armv7-m/arm_svcall.c @@ -312,19 +312,21 @@ int arm_svcall(int irq, FAR void *context, FAR void *arg) break; #endif +#if !defined(CONFIG_BUILD_FLAT) && !defined(CONFIG_DISABLE_PTHREAD) + /* R0=SYS_pthread_start: This a user pthread start * - * void up_pthread_start(pthread_startroutine_t entrypt, - * pthread_addr_t arg) noreturn_function; + * void up_pthread_start(pthread_trampoline_t startup, + * pthread_startroutine_t entrypt, pthread_addr_t arg) * * At this point, the following values are saved in context: * * R0 = SYS_pthread_start - * R1 = entrypt - * R2 = arg + * R1 = startup + * R2 = entrypt + * R3 = arg */ -#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 @@ -342,6 +344,35 @@ int arm_svcall(int irq, FAR void *context, FAR void *arg) regs[REG_R1] = regs[REG_R3]; /* arg */ } break; + + /* R0=SYS_pthread_exit: This pthread_exit call in user-space + * + * void up_pthread_exit(pthread_exitroutine_t exit, + * FAR void *exit_value) + * + * At this point, the following values are saved in context: + * + * R0 = SYS_pthread_exit + * R1 = pthread_exit trampoline routine + * R2 = exit_value + */ + + case SYS_pthread_exit: + { + /* Set up to return to the user-space pthread start-up function in + * unprivileged mode. + */ + + 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 the + * user space pthread_startup: + */ + + regs[REG_R0] = regs[REG_R2]; /* exit_value */ + } + break; #endif /* R0=SYS_signal_handler: This a user signal handler callback diff --git a/arch/arm/src/armv7-m/svcall.h b/arch/arm/src/armv7-m/svcall.h index 98a574e870..1fd56ea4c4 100644 --- a/arch/arm/src/armv7-m/svcall.h +++ b/arch/arm/src/armv7-m/svcall.h @@ -45,9 +45,9 @@ #ifdef CONFIG_LIB_SYSCALL # ifdef CONFIG_BUILD_PROTECTED # ifndef CONFIG_SYS_RESERVED -# error "CONFIG_SYS_RESERVED must be defined to have the value 8" -# elif CONFIG_SYS_RESERVED != 8 -# error "CONFIG_SYS_RESERVED must have the value 8" +# error "CONFIG_SYS_RESERVED must be defined to have the value 9" +# elif CONFIG_SYS_RESERVED != 9 +# error "CONFIG_SYS_RESERVED must have the value 9" # endif # else # ifndef CONFIG_SYS_RESERVED @@ -126,6 +126,13 @@ #define SYS_pthread_start (5) +/* SYS call 8: + * + * void up_pthread_exit(pthread_exitroutine_t exit, FAR void *exit_value) + */ + +#define SYS_pthread_exit (8) + #endif /* !CONFIG_BUILD_FLAT */ #endif /* CONFIG_LIB_SYSCALL */ diff --git a/arch/arm/src/armv7-r/arm_syscall.c b/arch/arm/src/armv7-r/arm_syscall.c index 29095d0588..367c41cf8e 100644 --- a/arch/arm/src/armv7-r/arm_syscall.c +++ b/arch/arm/src/armv7-r/arm_syscall.c @@ -273,33 +273,48 @@ uint32_t *arm_syscall(uint32_t *regs) break; #endif +#if !defined(CONFIG_BUILD_FLAT) && !defined(CONFIG_DISABLE_PTHREAD) + /* R0=SYS_pthread_start: This a user pthread start * - * void up_pthread_start(pthread_startroutine_t entrypt, - * pthread_addr_t arg) noreturn_function; + * void up_pthread_start(pthread_trampoline_t startup, + * pthread_startroutine_t entrypt, pthread_addr_t arg) * * At this point, the following values are saved in context: * * R0 = SYS_pthread_start - * R1 = entrypt - * R2 = arg + * R1 = startup + * R2 = entrypt + * R3 = arg */ -#if !defined(CONFIG_BUILD_FLAT) && !defined(CONFIG_DISABLE_PTHREAD) case SYS_pthread_start: { - /* Set up to enter the user-space pthread start-up function in - * unprivileged mode. We need: - * - * R0 = startup - * R1 = arg - * PC = entrypt - * CSPR = user mode - */ + regs[REG_PC] = regs[REG_R0]; + regs[REG_R0] = regs[REG_R1]; + regs[REG_R1] = regs[REG_R2]; - 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; + } + break; + + /* R0=SYS_pthread_exit: This pthread_exit call in user-space + * + * void up_pthread_exit(pthread_exitroutine_t exit, + * FAR void *exit_value) + * + * At this point, the following values are saved in context: + * + * R0 = SYS_pthread_exit + * R1 = pthread_exit trampoline routine + * R2 = exit_value + */ + + case SYS_pthread_exit: + { + regs[REG_PC] = regs[REG_R0]; + regs[REG_R0] = regs[REG_R1]; cpsr = regs[REG_CPSR] & ~PSR_MODE_MASK; regs[REG_CPSR] = cpsr | PSR_MODE_USR; diff --git a/arch/arm/src/armv8-m/arm_svcall.c b/arch/arm/src/armv8-m/arm_svcall.c index f0757c7712..4f57fb3027 100644 --- a/arch/arm/src/armv8-m/arm_svcall.c +++ b/arch/arm/src/armv8-m/arm_svcall.c @@ -311,19 +311,21 @@ int arm_svcall(int irq, FAR void *context, FAR void *arg) break; #endif +#if !defined(CONFIG_BUILD_FLAT) && !defined(CONFIG_DISABLE_PTHREAD) + /* R0=SYS_pthread_start: This a user pthread start * - * void up_pthread_start(pthread_startroutine_t entrypt, - * pthread_addr_t arg) noreturn_function; + * void up_pthread_start(pthread_trampoline_t startup, + * pthread_startroutine_t entrypt, pthread_addr_t arg) * * At this point, the following values are saved in context: * * R0 = SYS_pthread_start - * R1 = entrypt - * R2 = arg + * R1 = startup + * R2 = entrypt + * R3 = arg */ -#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 @@ -338,7 +340,36 @@ int arm_svcall(int irq, FAR void *context, FAR void *arg) */ regs[REG_R0] = regs[REG_R2]; /* pthread entry */ - regs[REG_R1] = regs[REG_R2]; /* arg */ + regs[REG_R1] = regs[REG_R3]; /* arg */ + } + break; + + /* R0=SYS_pthread_exit: This pthread_exit call in user-space + * + * void up_pthread_exit(pthread_exitroutine_t exit, + * FAR void *exit_value) + * + * At this point, the following values are saved in context: + * + * R0 = SYS_pthread_exit + * R1 = pthread_exit trampoline routine + * R2 = exit_value + */ + + case SYS_pthread_exit: + { + /* Set up to return to the user-space pthread start-up function in + * unprivileged mode. + */ + + 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 the + * user space pthread_startup: + */ + + regs[REG_R0] = regs[REG_R2]; /* exit_value */ } break; #endif diff --git a/arch/arm/src/common/arm_pthread_exit.c b/arch/arm/src/common/arm_pthread_exit.c new file mode 100644 index 0000000000..ba7eb825d2 --- /dev/null +++ b/arch/arm/src/common/arm_pthread_exit.c @@ -0,0 +1,62 @@ +/**************************************************************************** + * arch/arm/src/common/arm_pthread_exit.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include +#include + +#include "svcall.h" +#include "arm_internal.h" + +#if !defined(CONFIG_BUILD_FLAT) && defined(__KERNEL__) && \ + !defined(CONFIG_DISABLE_PTHREAD) + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: up_pthread_exit + * + * Description: + * In this kernel mode build, this function will be called to execute a + * pthread in user-space. This kernel-mode stub will then be called + * transfer control to the user-mode pthread_exit. + * + * Input Parameters: + * exit - The user-space pthread_exit function + * exit_value - The pointer of the pthread exit parameter + * + * Returned Value: + * None + ****************************************************************************/ + +void up_pthread_exit(pthread_exitroutine_t exit, FAR void *exit_value) +{ + /* Let sys_call2() do all of the work */ + + sys_call2(SYS_pthread_exit, (uintptr_t)exit, (uintptr_t)exit_value); +} + +#endif /* !CONFIG_BUILD_FLAT && __KERNEL__ && !CONFIG_DISABLE_PTHREAD */ diff --git a/arch/arm/src/cxd56xx/Make.defs b/arch/arm/src/cxd56xx/Make.defs index c61a72fcb9..9ffb394d37 100644 --- a/arch/arm/src/cxd56xx/Make.defs +++ b/arch/arm/src/cxd56xx/Make.defs @@ -51,6 +51,7 @@ endif ifeq ($(CONFIG_BUILD_PROTECTED),y) CMN_CSRCS += arm_mpu.c arm_task_start.c arm_pthread_start.c +CMN_CSRCS += arm_pthread_exit.c CMN_CSRCS += arm_signal_dispatch.c CMN_UASRCS += arm_signal_handler.S endif diff --git a/arch/arm/src/efm32/Make.defs b/arch/arm/src/efm32/Make.defs index 2f763950eb..670d1a9132 100644 --- a/arch/arm/src/efm32/Make.defs +++ b/arch/arm/src/efm32/Make.defs @@ -43,6 +43,7 @@ endif ifeq ($(CONFIG_BUILD_PROTECTED),y) CMN_CSRCS += arm_mpu.c arm_task_start.c arm_pthread_start.c +CMN_CSRCS += arm_pthread_exit.c CMN_CSRCS += arm_signal_dispatch.c CMN_UASRCS += arm_signal_handler.S endif diff --git a/arch/arm/src/eoss3/Make.defs b/arch/arm/src/eoss3/Make.defs index 3e2bc2f325..61492fe065 100644 --- a/arch/arm/src/eoss3/Make.defs +++ b/arch/arm/src/eoss3/Make.defs @@ -43,6 +43,7 @@ endif ifeq ($(CONFIG_BUILD_PROTECTED),y) CMN_CSRCS += arm_task_start.c arm_pthread_start.c +CMN_CSRCS += arm_pthread_exit.c CMN_CSRCS += arm_signal_dispatch.c CMN_UASRCS += arm_signal_handler.S endif diff --git a/arch/arm/src/imx6/Make.defs b/arch/arm/src/imx6/Make.defs index f04bd17b4c..bc9884e103 100644 --- a/arch/arm/src/imx6/Make.defs +++ b/arch/arm/src/imx6/Make.defs @@ -90,6 +90,7 @@ endif ifeq ($(CONFIG_BUILD_KERNEL),y) CMN_CSRCS += arm_task_start.c arm_pthread_start.c arm_signal_dispatch.c +CMN_CSRCS += arm_pthread_exit.c endif ifeq ($(CONFIG_ARCH_ADDRENV),y) diff --git a/arch/arm/src/imxrt/Make.defs b/arch/arm/src/imxrt/Make.defs index 5d5946b234..ba9195ae93 100644 --- a/arch/arm/src/imxrt/Make.defs +++ b/arch/arm/src/imxrt/Make.defs @@ -55,6 +55,7 @@ endif ifeq ($(CONFIG_BUILD_PROTECTED),y) CMN_CSRCS += arm_task_start.c arm_pthread_start.c +CMN_CSRCS += arm_pthread_exit.c CMN_CSRCS += arm_signal_dispatch.c CMN_UASRCS += arm_signal_handler.S endif diff --git a/arch/arm/src/kinetis/Make.defs b/arch/arm/src/kinetis/Make.defs index 0f2fd14063..6b3426647e 100644 --- a/arch/arm/src/kinetis/Make.defs +++ b/arch/arm/src/kinetis/Make.defs @@ -51,6 +51,7 @@ endif ifeq ($(CONFIG_BUILD_PROTECTED),y) CMN_CSRCS += arm_task_start.c arm_pthread_start.c +CMN_CSRCS += arm_pthread_exit.c CMN_CSRCS += arm_signal_dispatch.c CMN_UASRCS += arm_signal_handler.S endif diff --git a/arch/arm/src/kl/Make.defs b/arch/arm/src/kl/Make.defs index 912223bd06..2f7691745a 100644 --- a/arch/arm/src/kl/Make.defs +++ b/arch/arm/src/kl/Make.defs @@ -32,6 +32,7 @@ CMN_CSRCS += arm_hardfault.c arm_svcall.c arm_vectors.c arm_vfork.c ifeq ($(CONFIG_BUILD_PROTECTED),y) CMN_CSRCS += arm_task_start.c arm_pthread_start.c +CMN_CSRCS += arm_pthread_exit.c CMN_CSRCS += arm_signal_dispatch.c CMN_UASRCS += arm_signal_handler.S endif diff --git a/arch/arm/src/lc823450/Make.defs b/arch/arm/src/lc823450/Make.defs index 74e92be97b..4f37e68a7c 100644 --- a/arch/arm/src/lc823450/Make.defs +++ b/arch/arm/src/lc823450/Make.defs @@ -42,6 +42,7 @@ endif ifeq ($(CONFIG_BUILD_PROTECTED),y) CMN_CSRCS += arm_task_start.c arm_pthread_start.c +CMN_CSRCS += arm_pthread_exit.c CMN_CSRCS += arm_signal_dispatch.c CMN_UASRCS += arm_signal_handler.S endif diff --git a/arch/arm/src/lpc17xx_40xx/Make.defs b/arch/arm/src/lpc17xx_40xx/Make.defs index 96b01fd0b8..81a1515dfc 100644 --- a/arch/arm/src/lpc17xx_40xx/Make.defs +++ b/arch/arm/src/lpc17xx_40xx/Make.defs @@ -54,6 +54,7 @@ endif ifeq ($(CONFIG_BUILD_PROTECTED),y) CMN_CSRCS += arm_task_start.c arm_pthread_start.c +CMN_CSRCS += arm_pthread_exit.c CMN_CSRCS += arm_signal_dispatch.c CMN_UASRCS += arm_signal_handler.S endif diff --git a/arch/arm/src/lpc43xx/Make.defs b/arch/arm/src/lpc43xx/Make.defs index 05d8ba44de..c42b7774d0 100644 --- a/arch/arm/src/lpc43xx/Make.defs +++ b/arch/arm/src/lpc43xx/Make.defs @@ -47,6 +47,7 @@ endif ifeq ($(CONFIG_BUILD_PROTECTED),y) CMN_CSRCS += arm_task_start.c arm_pthread_start.c +CMN_CSRCS += arm_pthread_exit.c CMN_CSRCS += arm_signal_dispatch.c CMN_UASRCS += arm_signal_handler.S endif diff --git a/arch/arm/src/lpc54xx/Make.defs b/arch/arm/src/lpc54xx/Make.defs index d40a65d3a1..2f89791d6a 100644 --- a/arch/arm/src/lpc54xx/Make.defs +++ b/arch/arm/src/lpc54xx/Make.defs @@ -47,6 +47,7 @@ endif ifeq ($(CONFIG_BUILD_PROTECTED),y) CMN_CSRCS += arm_task_start.c arm_pthread_start.c +CMN_CSRCS += arm_pthread_exit.c CMN_CSRCS += arm_signal_dispatch.c CMN_UASRCS += arm_signal_handler.S endif diff --git a/arch/arm/src/max326xx/Make.defs b/arch/arm/src/max326xx/Make.defs index 628bcdd051..b4f7e63c93 100644 --- a/arch/arm/src/max326xx/Make.defs +++ b/arch/arm/src/max326xx/Make.defs @@ -45,6 +45,7 @@ endif ifeq ($(CONFIG_BUILD_PROTECTED),y) CMN_CSRCS += arm_mpu.c arm_task_start.c arm_pthread_start.c +CMN_CSRCS += arm_pthread_exit.c CMN_CSRCS += arm_signal_dispatch.c CMN_UASRCS += arm_signal_handler.S endif diff --git a/arch/arm/src/nrf52/Make.defs b/arch/arm/src/nrf52/Make.defs index b6b4970593..b5091bc5c2 100644 --- a/arch/arm/src/nrf52/Make.defs +++ b/arch/arm/src/nrf52/Make.defs @@ -51,6 +51,7 @@ endif ifeq ($(CONFIG_BUILD_PROTECTED),y) CMN_CSRCS += arm_mpu.c arm_task_start.c arm_pthread_start.c +CMN_CSRCS += arm_pthread_exit.c CMN_CSRCS += arm_signal_dispatch.c CMN_UASRCS += arm_signal_handler.S endif diff --git a/arch/arm/src/nuc1xx/Make.defs b/arch/arm/src/nuc1xx/Make.defs index 85152e72dc..cd19f8ec88 100644 --- a/arch/arm/src/nuc1xx/Make.defs +++ b/arch/arm/src/nuc1xx/Make.defs @@ -32,6 +32,7 @@ CMN_CSRCS += arm_hardfault.c arm_svcall.c arm_vectors.c arm_vfork.c ifeq ($(CONFIG_BUILD_PROTECTED),y) CMN_CSRCS += arm_task_start.c arm_pthread_start.c +CMN_CSRCS += arm_pthread_exit.c CMN_CSRCS += arm_signal_dispatch.c CMN_UASRCS += arm_signal_handler.S endif diff --git a/arch/arm/src/rp2040/Make.defs b/arch/arm/src/rp2040/Make.defs index a640d43c70..a918e10770 100644 --- a/arch/arm/src/rp2040/Make.defs +++ b/arch/arm/src/rp2040/Make.defs @@ -36,6 +36,7 @@ endif ifeq ($(CONFIG_BUILD_PROTECTED),y) CMN_CSRCS += arm_task_start.c arm_pthread_start.c +CMN_CSRCS += arm_pthread_exit.c CMN_CSRCS += arm_signal_dispatch.c CMN_UASRCS += arm_signal_handler.S endif diff --git a/arch/arm/src/s32k1xx/Make.defs b/arch/arm/src/s32k1xx/Make.defs index b9efbae12a..f2cf13047b 100644 --- a/arch/arm/src/s32k1xx/Make.defs +++ b/arch/arm/src/s32k1xx/Make.defs @@ -31,6 +31,7 @@ endif ifeq ($(CONFIG_BUILD_PROTECTED),y) CMN_CSRCS += arm_pthread_start.c +CMN_CSRCS += arm_pthread_exit.c endif # Source files common to all S32K1xx chip families. diff --git a/arch/arm/src/sam34/Make.defs b/arch/arm/src/sam34/Make.defs index 2aa370ec18..8f321eee4f 100644 --- a/arch/arm/src/sam34/Make.defs +++ b/arch/arm/src/sam34/Make.defs @@ -59,6 +59,7 @@ endif ifeq ($(CONFIG_BUILD_PROTECTED),y) CMN_CSRCS += arm_task_start.c arm_pthread_start.c +CMN_CSRCS += arm_pthread_exit.c CMN_CSRCS += arm_signal_dispatch.c CMN_UASRCS += arm_signal_handler.S endif diff --git a/arch/arm/src/sama5/Make.defs b/arch/arm/src/sama5/Make.defs index 9d9f9d2246..99c58d348e 100644 --- a/arch/arm/src/sama5/Make.defs +++ b/arch/arm/src/sama5/Make.defs @@ -76,6 +76,7 @@ endif ifeq ($(CONFIG_BUILD_KERNEL),y) CMN_CSRCS += arm_task_start.c arm_pthread_start.c arm_signal_dispatch.c +CMN_CSRCS += arm_pthread_exit.c endif ifeq ($(CONFIG_ARCH_ADDRENV),y) diff --git a/arch/arm/src/samd2l2/Make.defs b/arch/arm/src/samd2l2/Make.defs index 7fcf0f3045..9e30a0eb0a 100644 --- a/arch/arm/src/samd2l2/Make.defs +++ b/arch/arm/src/samd2l2/Make.defs @@ -32,6 +32,7 @@ CMN_CSRCS += arm_hardfault.c arm_svcall.c arm_vectors.c arm_vfork.c ifeq ($(CONFIG_BUILD_PROTECTED),y) CMN_CSRCS += arm_task_start.c arm_pthread_start.c +CMN_CSRCS += arm_pthread_exit.c CMN_CSRCS += arm_signal_dispatch.c CMN_UASRCS += arm_signal_handler.S endif diff --git a/arch/arm/src/samd5e5/Make.defs b/arch/arm/src/samd5e5/Make.defs index 1750513a0d..70371810f3 100644 --- a/arch/arm/src/samd5e5/Make.defs +++ b/arch/arm/src/samd5e5/Make.defs @@ -49,6 +49,7 @@ endif ifeq ($(CONFIG_BUILD_PROTECTED),y) CMN_CSRCS += arm_mpu.c arm_task_start.c arm_pthread_start.c +CMN_CSRCS += arm_pthread_exit.c CMN_CSRCS += arm_signal_dispatch.c CMN_UASRCS += arm_signal_handler.S endif diff --git a/arch/arm/src/samv7/Make.defs b/arch/arm/src/samv7/Make.defs index a49c36982d..7be09383c9 100644 --- a/arch/arm/src/samv7/Make.defs +++ b/arch/arm/src/samv7/Make.defs @@ -67,6 +67,7 @@ ifeq ($(CONFIG_ARM_MPU),y) CMN_CSRCS += arm_mpu.c ifeq ($(CONFIG_BUILD_PROTECTED),y) CMN_CSRCS += arm_task_start.c arm_pthread_start.c +CMN_CSRCS += arm_pthread_exit.c CMN_CSRCS += arm_signal_dispatch.c CMN_UASRCS += arm_signal_handler.S endif diff --git a/arch/arm/src/stm32/Make.defs b/arch/arm/src/stm32/Make.defs index c5f5a7f7ea..72852241e0 100644 --- a/arch/arm/src/stm32/Make.defs +++ b/arch/arm/src/stm32/Make.defs @@ -58,7 +58,7 @@ CMN_CSRCS += arm_mpu.c endif ifeq ($(CONFIG_BUILD_PROTECTED),y) -CMN_CSRCS += arm_task_start.c arm_pthread_start.c +CMN_CSRCS += arm_task_start.c arm_pthread_start.c arm_pthread_exit.c CMN_CSRCS += arm_signal_dispatch.c CMN_UASRCS += arm_signal_handler.S endif diff --git a/arch/arm/src/stm32f0l0g0/Make.defs b/arch/arm/src/stm32f0l0g0/Make.defs index 7ad308c042..a108459296 100644 --- a/arch/arm/src/stm32f0l0g0/Make.defs +++ b/arch/arm/src/stm32f0l0g0/Make.defs @@ -32,6 +32,7 @@ CMN_CSRCS += arm_hardfault.c arm_svcall.c arm_vectors.c arm_vfork.c ifeq ($(CONFIG_BUILD_PROTECTED),y) CMN_CSRCS += arm_task_start.c arm_pthread_start.c +CMN_CSRCS += arm_pthread_exit.c CMN_CSRCS += arm_signal_dispatch.c CMN_UASRCS += arm_signal_handler.S endif diff --git a/arch/arm/src/stm32f7/Make.defs b/arch/arm/src/stm32f7/Make.defs index 94bb463268..71c5981c3b 100644 --- a/arch/arm/src/stm32f7/Make.defs +++ b/arch/arm/src/stm32f7/Make.defs @@ -73,6 +73,7 @@ endif ifeq ($(CONFIG_BUILD_PROTECTED),y) CMN_CSRCS += arm_task_start.c arm_pthread_start.c +CMN_CSRCS += arm_pthread_exit.c CMN_CSRCS += arm_signal_dispatch.c CMN_UASRCS += arm_signal_handler.S endif diff --git a/arch/arm/src/stm32h7/Make.defs b/arch/arm/src/stm32h7/Make.defs index d401d0625f..2a24c0d954 100644 --- a/arch/arm/src/stm32h7/Make.defs +++ b/arch/arm/src/stm32h7/Make.defs @@ -72,6 +72,7 @@ endif ifeq ($(CONFIG_BUILD_PROTECTED),y) CMN_CSRCS += arm_task_start.c arm_pthread_start.c +CMN_CSRCS += arm_pthread_exit.c CMN_CSRCS += arm_signal_dispatch.c CMN_UASRCS += arm_signal_handler.S endif diff --git a/arch/arm/src/stm32l4/Make.defs b/arch/arm/src/stm32l4/Make.defs index 59051e66e5..ca695c82d2 100644 --- a/arch/arm/src/stm32l4/Make.defs +++ b/arch/arm/src/stm32l4/Make.defs @@ -63,6 +63,7 @@ endif ifeq ($(CONFIG_BUILD_PROTECTED),y) CMN_CSRCS += arm_task_start.c arm_pthread_start.c +CMN_CSRCS += arm_pthread_exit.c CMN_CSRCS += arm_signal_dispatch.c CMN_UASRCS += arm_signal_handler.S endif diff --git a/arch/arm/src/stm32l5/Make.defs b/arch/arm/src/stm32l5/Make.defs index ec53d494b9..0ce8155a11 100644 --- a/arch/arm/src/stm32l5/Make.defs +++ b/arch/arm/src/stm32l5/Make.defs @@ -64,6 +64,7 @@ endif ifeq ($(CONFIG_BUILD_PROTECTED),y) CMN_CSRCS += arm_mpu.c arm_task_start.c arm_pthread_start.c +CMN_CSRCS += arm_pthread_exit.c CMN_CSRCS += arm_signal_dispatch.c CMN_UASRCS += arm_signal_handler.S endif diff --git a/arch/arm/src/tiva/Make.defs b/arch/arm/src/tiva/Make.defs index 272de114aa..2483799a86 100644 --- a/arch/arm/src/tiva/Make.defs +++ b/arch/arm/src/tiva/Make.defs @@ -65,6 +65,7 @@ endif ifeq ($(CONFIG_BUILD_PROTECTED),y) CMN_CSRCS += arm_task_start.c arm_pthread_start.c + CMN_CSRCS += arm_pthread_exit.c CMN_CSRCS += arm_signal_dispatch.c CMN_UASRCS += arm_signal_handler.S else diff --git a/arch/arm/src/tms570/Make.defs b/arch/arm/src/tms570/Make.defs index 98d5ce5667..6899d55786 100644 --- a/arch/arm/src/tms570/Make.defs +++ b/arch/arm/src/tms570/Make.defs @@ -59,6 +59,7 @@ endif ifeq ($(CONFIG_BUILD_PROTECTED),y) CMN_CSRCS += arm_mpu.c arm_task_start.c arm_pthread_start.c +CMN_CSRCS += arm_pthread_exit.c CMN_CSRCS += arm_signal_dispatch.c CMN_UASRCS += arm_signal_handler.S endif diff --git a/arch/arm/src/xmc4/Make.defs b/arch/arm/src/xmc4/Make.defs index f9ea0450d1..66d7669c31 100644 --- a/arch/arm/src/xmc4/Make.defs +++ b/arch/arm/src/xmc4/Make.defs @@ -51,6 +51,7 @@ endif ifeq ($(CONFIG_BUILD_PROTECTED),y) CMN_CSRCS += arm_task_start.c arm_pthread_start.c +CMN_CSRCS += arm_pthread_exit.c CMN_CSRCS += arm_signal_dispatch.c CMN_UASRCS += arm_signal_handler.S endif diff --git a/arch/or1k/src/common/up_pthread_start.c b/arch/or1k/src/common/up_pthread_start.c index 8edbd0632e..29640b698a 100644 --- a/arch/or1k/src/common/up_pthread_start.c +++ b/arch/or1k/src/common/up_pthread_start.c @@ -63,7 +63,7 @@ void up_pthread_start(pthread_startroutine_t entrypt, pthread_addr_t arg) { - /* Let sys_call2() do all of the work */ + /* Let sys_call3() do all of the work */ sinfo("entry %p arg %p\n", entrypt, arg); diff --git a/arch/risc-v/src/c906/Make.defs b/arch/risc-v/src/c906/Make.defs index a367c4d79a..8088b46151 100644 --- a/arch/risc-v/src/c906/Make.defs +++ b/arch/risc-v/src/c906/Make.defs @@ -55,6 +55,7 @@ CHIP_CSRCS += c906_start.c c906_timerisr.c ifeq ($(CONFIG_BUILD_PROTECTED),y) CMN_CSRCS += riscv_task_start.c riscv_pthread_start.c +CMN_CSRCS += riscv_pthread_exit.c CMN_CSRCS += riscv_signal_dispatch.c riscv_pmp.c CMN_UASRCS += riscv_signal_handler.S diff --git a/arch/risc-v/src/common/riscv_pthread_exit.c b/arch/risc-v/src/common/riscv_pthread_exit.c new file mode 100644 index 0000000000..39964ea1ff --- /dev/null +++ b/arch/risc-v/src/common/riscv_pthread_exit.c @@ -0,0 +1,60 @@ +/**************************************************************************** + * arch/risc-v/src/common/riscv_pthread_exit.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include +#include + +#include "svcall.h" +#include "riscv_internal.h" + +#if !defined(CONFIG_BUILD_FLAT) && defined(__KERNEL__) && \ + !defined(CONFIG_DISABLE_PTHREAD) + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: up_pthread_exit + * + * Description: + * In this kernel mode build, this function will be called to execute a + * pthread in user-space. This kernel-mode stub will then be called + * transfer control to the user-mode pthread_exit. + * + * Input Parameters: + * exit - The user-space pthread_exit function + * exit_value - The pointer of the pthread exit parameter + * + * Returned Value: + * None + ****************************************************************************/ + +void up_pthread_exit(pthread_exitroutine_t exit, FAR void *exit_value) +{ + sys_call2(SYS_pthread_exit, (uintptr_t)exit, (uintptr_t)exit_value); +} + +#endif /* !CONFIG_BUILD_FLAT && __KERNEL__ && !CONFIG_DISABLE_PTHREAD */ diff --git a/arch/risc-v/src/k210/Make.defs b/arch/risc-v/src/k210/Make.defs index 5c5cb22de5..a8bf25e506 100644 --- a/arch/risc-v/src/k210/Make.defs +++ b/arch/risc-v/src/k210/Make.defs @@ -57,7 +57,8 @@ CHIP_CSRCS += k210_cpupause.c k210_cpustart.c endif ifeq ($(CONFIG_BUILD_PROTECTED),y) -CMN_CSRCS += riscv_task_start.c riscv_pthread_start.c +CMN_CSRCS += riscv_task_start.c +CMN_CSRCS += riscv_pthread_start.c riscv_pthread_exit.c CMN_CSRCS += riscv_signal_dispatch.c CMN_UASRCS += riscv_signal_handler.S diff --git a/arch/risc-v/src/rv64gc/riscv_swint.c b/arch/risc-v/src/rv64gc/riscv_swint.c index 7e6d90b553..8cd2528ad7 100644 --- a/arch/risc-v/src/rv64gc/riscv_swint.c +++ b/arch/risc-v/src/rv64gc/riscv_swint.c @@ -282,19 +282,21 @@ int riscv_swint(int irq, FAR void *context, FAR void *arg) break; #endif - /* R0=SYS_pthread_start: This a user pthread start +#if !defined(CONFIG_BUILD_FLAT) && !defined(CONFIG_DISABLE_PTHREAD) + + /* A0=SYS_pthread_start: This a user pthread start * - * void up_pthread_start(pthread_startroutine_t entrypt, - * pthread_addr_t arg) noreturn_function; + * void up_pthread_start(pthread_trampoline_t startup, + * pthread_startroutine_t entrypt, pthread_addr_t arg) * * At this point, the following values are saved in context: * - * R0 = SYS_pthread_start - * R1 = entrypt - * R2 = arg + * A0 = SYS_pthread_start + * A1 = startup + * A2 = entrypt + * A3 = arg */ -#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 @@ -312,6 +314,35 @@ int riscv_swint(int irq, FAR void *context, FAR void *arg) regs[REG_INT_CTX] &= ~MSTATUS_MPPM; /* User mode */ } break; + + /* R0=SYS_pthread_exit: This pthread_exit call in user-space + * + * void up_pthread_exit(pthread_exitroutine_t exit, + * FAR void *exit_value) + * + * At this point, the following values are saved in context: + * + * R0 = SYS_pthread_exit + * R1 = pthread_exit trampoline routine + * R2 = exit_value + */ + + case SYS_pthread_exit: + { + /* Set up to enter the user-space pthread exit function in + * unprivileged mode. + */ + + regs[REG_EPC] = (uintptr_t)regs[REG_A1] & ~1; /* exit */ + + /* Change the parameter ordering to match the expectation of the + * user space pthread_exit: + */ + + regs[REG_A0] = regs[REG_A2]; /* exit_value */ + regs[REG_INT_CTX] &= ~MSTATUS_MPPM; /* User mode */ + } + break; #endif /* R0=SYS_signal_handler: This a user signal handler callback diff --git a/arch/risc-v/src/rv64gc/svcall.h b/arch/risc-v/src/rv64gc/svcall.h index 80c8c15080..6ecb889c67 100644 --- a/arch/risc-v/src/rv64gc/svcall.h +++ b/arch/risc-v/src/rv64gc/svcall.h @@ -46,9 +46,9 @@ #ifdef CONFIG_LIB_SYSCALL # ifdef CONFIG_BUILD_PROTECTED # ifndef CONFIG_SYS_RESERVED -# error "CONFIG_SYS_RESERVED must be defined to have the value 8" -# elif CONFIG_SYS_RESERVED != 8 -# error "CONFIG_SYS_RESERVED must have the value 8" +# error "CONFIG_SYS_RESERVED must be defined to have the value 9" +# elif CONFIG_SYS_RESERVED != 9 +# error "CONFIG_SYS_RESERVED must have the value 9" # endif # else # ifndef CONFIG_SYS_RESERVED @@ -118,13 +118,20 @@ /* SYS call 5: * - * void up_pthread_start(pthread_startroutine_t startup, + * void up_pthread_start(pthread_trampoline_t startup, * pthread_startroutine_t entrypt, pthread_addr_t arg) * noreturn_function */ #define SYS_pthread_start (5) +/* SYS call 8: + * + * void up_pthread_exit(pthread_exitroutine_t exit, FAR void *exit_value) + */ + +#define SYS_pthread_exit (8) + #endif /* !CONFIG_BUILD_FLAT */ #endif /* CONFIG_LIB_SYSCALL */ diff --git a/boards/arm/imxrt/imxrt1050-evk/configs/knsh/defconfig b/boards/arm/imxrt/imxrt1050-evk/configs/knsh/defconfig index b13be81872..df3c6112ae 100644 --- a/boards/arm/imxrt/imxrt1050-evk/configs/knsh/defconfig +++ b/boards/arm/imxrt/imxrt1050-evk/configs/knsh/defconfig @@ -40,5 +40,5 @@ CONFIG_SCHED_WAITPID=y CONFIG_START_DAY=8 CONFIG_START_MONTH=6 CONFIG_SYSTEM_NSH=y -CONFIG_SYS_RESERVED=8 +CONFIG_SYS_RESERVED=9 CONFIG_USER_ENTRYPOINT="nsh_main" diff --git a/boards/arm/imxrt/imxrt1060-evk/configs/knsh/defconfig b/boards/arm/imxrt/imxrt1060-evk/configs/knsh/defconfig index 2fe1cdadbb..9f9ba3f786 100644 --- a/boards/arm/imxrt/imxrt1060-evk/configs/knsh/defconfig +++ b/boards/arm/imxrt/imxrt1060-evk/configs/knsh/defconfig @@ -40,5 +40,5 @@ CONFIG_SCHED_WAITPID=y CONFIG_START_DAY=8 CONFIG_START_MONTH=6 CONFIG_SYSTEM_NSH=y -CONFIG_SYS_RESERVED=8 +CONFIG_SYS_RESERVED=9 CONFIG_USER_ENTRYPOINT="nsh_main" diff --git a/boards/arm/imxrt/imxrt1064-evk/configs/knsh/defconfig b/boards/arm/imxrt/imxrt1064-evk/configs/knsh/defconfig index 1c0ed8c7c7..1b33c0d6ac 100644 --- a/boards/arm/imxrt/imxrt1064-evk/configs/knsh/defconfig +++ b/boards/arm/imxrt/imxrt1064-evk/configs/knsh/defconfig @@ -40,5 +40,5 @@ CONFIG_SCHED_WAITPID=y CONFIG_START_DAY=8 CONFIG_START_MONTH=6 CONFIG_SYSTEM_NSH=y -CONFIG_SYS_RESERVED=8 +CONFIG_SYS_RESERVED=9 CONFIG_USER_ENTRYPOINT="nsh_main" diff --git a/boards/arm/lc823450/lc823450-xgevk/configs/knsh/defconfig b/boards/arm/lc823450/lc823450-xgevk/configs/knsh/defconfig index 3eae4178cd..05109c55c2 100644 --- a/boards/arm/lc823450/lc823450-xgevk/configs/knsh/defconfig +++ b/boards/arm/lc823450/lc823450-xgevk/configs/knsh/defconfig @@ -109,7 +109,7 @@ CONFIG_START_YEAR=2013 CONFIG_SYSTEM_I2CTOOL=y CONFIG_SYSTEM_NSH=y CONFIG_SYSTEM_TIME64=y -CONFIG_SYS_RESERVED=8 +CONFIG_SYS_RESERVED=9 CONFIG_TASK_NAME_SIZE=24 CONFIG_UART0_RXBUFSIZE=512 CONFIG_UART0_SERIAL_CONSOLE=y diff --git a/boards/arm/lc823450/lc823450-xgevk/configs/kostest/defconfig b/boards/arm/lc823450/lc823450-xgevk/configs/kostest/defconfig index a50cc7a574..f97b0fa8e4 100644 --- a/boards/arm/lc823450/lc823450-xgevk/configs/kostest/defconfig +++ b/boards/arm/lc823450/lc823450-xgevk/configs/kostest/defconfig @@ -40,7 +40,7 @@ CONFIG_START_MONTH=10 CONFIG_START_YEAR=2013 CONFIG_SYMTAB_ORDEREDBYNAME=y CONFIG_SYSTEM_TIME64=y -CONFIG_SYS_RESERVED=8 +CONFIG_SYS_RESERVED=9 CONFIG_TESTING_OSTEST=y CONFIG_TESTING_OSTEST_NBARRIER_THREADS=3 CONFIG_TESTING_OSTEST_STACKSIZE=2048 diff --git a/boards/arm/lc823450/lc823450-xgevk/configs/krndis/defconfig b/boards/arm/lc823450/lc823450-xgevk/configs/krndis/defconfig index 1816c5b24c..813094b19c 100644 --- a/boards/arm/lc823450/lc823450-xgevk/configs/krndis/defconfig +++ b/boards/arm/lc823450/lc823450-xgevk/configs/krndis/defconfig @@ -173,7 +173,7 @@ CONFIG_SYSTEM_NSH_SYMTAB_COUNTNAME="g_nsymbols" CONFIG_SYSTEM_NXPLAYER=y CONFIG_SYSTEM_PING=y CONFIG_SYSTEM_TIME64=y -CONFIG_SYS_RESERVED=8 +CONFIG_SYS_RESERVED=9 CONFIG_TASK_NAME_SIZE=24 CONFIG_TELNET_CHARACTER_MODE=y CONFIG_TESTING_OSTEST=y diff --git a/boards/arm/lpc17xx_40xx/lpc4088-devkit/configs/knsh/defconfig b/boards/arm/lpc17xx_40xx/lpc4088-devkit/configs/knsh/defconfig index 967e9c9cb4..0d08c2fb74 100644 --- a/boards/arm/lpc17xx_40xx/lpc4088-devkit/configs/knsh/defconfig +++ b/boards/arm/lpc17xx_40xx/lpc4088-devkit/configs/knsh/defconfig @@ -57,7 +57,7 @@ CONFIG_START_MONTH=3 CONFIG_START_YEAR=2013 CONFIG_SYMTAB_ORDEREDBYNAME=y CONFIG_SYSTEM_NSH=y -CONFIG_SYS_RESERVED=8 +CONFIG_SYS_RESERVED=9 CONFIG_TASK_NAME_SIZE=0 CONFIG_UART0_SERIAL_CONSOLE=y CONFIG_USER_ENTRYPOINT="nsh_main" diff --git a/boards/arm/lpc17xx_40xx/lpc4088-quickstart/configs/knsh/defconfig b/boards/arm/lpc17xx_40xx/lpc4088-quickstart/configs/knsh/defconfig index 72cfa7c1b6..56b1d6992a 100644 --- a/boards/arm/lpc17xx_40xx/lpc4088-quickstart/configs/knsh/defconfig +++ b/boards/arm/lpc17xx_40xx/lpc4088-quickstart/configs/knsh/defconfig @@ -53,7 +53,7 @@ CONFIG_START_MONTH=3 CONFIG_START_YEAR=2013 CONFIG_SYMTAB_ORDEREDBYNAME=y CONFIG_SYSTEM_NSH=y -CONFIG_SYS_RESERVED=8 +CONFIG_SYS_RESERVED=9 CONFIG_TASK_NAME_SIZE=0 CONFIG_UART0_SERIAL_CONSOLE=y CONFIG_USER_ENTRYPOINT="nsh_main" diff --git a/boards/arm/lpc17xx_40xx/open1788/configs/knsh/defconfig b/boards/arm/lpc17xx_40xx/open1788/configs/knsh/defconfig index d32e086df2..f57066cc1c 100644 --- a/boards/arm/lpc17xx_40xx/open1788/configs/knsh/defconfig +++ b/boards/arm/lpc17xx_40xx/open1788/configs/knsh/defconfig @@ -57,7 +57,7 @@ CONFIG_START_MONTH=3 CONFIG_START_YEAR=2013 CONFIG_SYMTAB_ORDEREDBYNAME=y CONFIG_SYSTEM_NSH=y -CONFIG_SYS_RESERVED=8 +CONFIG_SYS_RESERVED=9 CONFIG_TASK_NAME_SIZE=0 CONFIG_UART0_SERIAL_CONSOLE=y CONFIG_USER_ENTRYPOINT="nsh_main" diff --git a/boards/arm/lpc17xx_40xx/open1788/configs/knxterm/defconfig b/boards/arm/lpc17xx_40xx/open1788/configs/knxterm/defconfig index adbc0748d8..3af96a5f81 100644 --- a/boards/arm/lpc17xx_40xx/open1788/configs/knxterm/defconfig +++ b/boards/arm/lpc17xx_40xx/open1788/configs/knxterm/defconfig @@ -67,7 +67,7 @@ CONFIG_START_MONTH=3 CONFIG_START_YEAR=2019 CONFIG_SYMTAB_ORDEREDBYNAME=y CONFIG_SYSTEM_CLE=y -CONFIG_SYS_RESERVED=8 +CONFIG_SYS_RESERVED=9 CONFIG_TASK_NAME_SIZE=0 CONFIG_UART0_SERIAL_CONSOLE=y CONFIG_USER_ENTRYPOINT="nxterm_main" diff --git a/boards/arm/lpc17xx_40xx/pnev5180b/configs/knsh/defconfig b/boards/arm/lpc17xx_40xx/pnev5180b/configs/knsh/defconfig index 2d1f6cb0bd..542c60bac4 100644 --- a/boards/arm/lpc17xx_40xx/pnev5180b/configs/knsh/defconfig +++ b/boards/arm/lpc17xx_40xx/pnev5180b/configs/knsh/defconfig @@ -21,6 +21,6 @@ CONFIG_PASS1_BUILDIR="boards/arm/lpc17xx_40xx/pnev5180b/kernel" CONFIG_RAM_SIZE=32768 CONFIG_RAM_START=0x10000000 CONFIG_SYSTEM_NSH=y -CONFIG_SYS_RESERVED=8 +CONFIG_SYS_RESERVED=9 CONFIG_UART0_SERIAL_CONSOLE=y CONFIG_USER_ENTRYPOINT="nsh_main" diff --git a/boards/arm/lpc43xx/bambino-200e/configs/knsh/defconfig b/boards/arm/lpc43xx/bambino-200e/configs/knsh/defconfig index 153c52511c..38a66bf3cd 100644 --- a/boards/arm/lpc43xx/bambino-200e/configs/knsh/defconfig +++ b/boards/arm/lpc43xx/bambino-200e/configs/knsh/defconfig @@ -49,7 +49,7 @@ CONFIG_START_MONTH=7 CONFIG_START_YEAR=2012 CONFIG_SYMTAB_ORDEREDBYNAME=y CONFIG_SYSTEM_NSH=y -CONFIG_SYS_RESERVED=8 +CONFIG_SYS_RESERVED=9 CONFIG_TASK_NAME_SIZE=0 CONFIG_TIMER=y CONFIG_UART1_SERIAL_CONSOLE=y diff --git a/boards/arm/sam34/sam3u-ek/configs/knsh/defconfig b/boards/arm/sam34/sam3u-ek/configs/knsh/defconfig index 8f5fae050c..d2582b8831 100644 --- a/boards/arm/sam34/sam3u-ek/configs/knsh/defconfig +++ b/boards/arm/sam34/sam3u-ek/configs/knsh/defconfig @@ -48,7 +48,7 @@ CONFIG_START_DAY=10 CONFIG_START_MONTH=3 CONFIG_START_YEAR=2013 CONFIG_SYSTEM_NSH=y -CONFIG_SYS_RESERVED=8 +CONFIG_SYS_RESERVED=9 CONFIG_TASK_NAME_SIZE=0 CONFIG_UART0_SERIAL_CONSOLE=y CONFIG_USER_ENTRYPOINT="nsh_main" diff --git a/boards/arm/sama5/sama5d4-ek/configs/knsh/defconfig b/boards/arm/sama5/sama5d4-ek/configs/knsh/defconfig index c5f7f328dd..e550748ce9 100644 --- a/boards/arm/sama5/sama5d4-ek/configs/knsh/defconfig +++ b/boards/arm/sama5/sama5d4-ek/configs/knsh/defconfig @@ -85,5 +85,5 @@ CONFIG_SCHED_WAITPID=y CONFIG_SDIO_BLOCKSETUP=y CONFIG_SYSTEM_NSH=y CONFIG_SYSTEM_NSH_PROGNAME="init" -CONFIG_SYS_RESERVED=6 +CONFIG_SYS_RESERVED=7 CONFIG_USART3_SERIAL_CONSOLE=y diff --git a/boards/arm/samv7/samv71-xult/configs/knsh/defconfig b/boards/arm/samv7/samv71-xult/configs/knsh/defconfig index a5d351f018..442f9d2caa 100644 --- a/boards/arm/samv7/samv71-xult/configs/knsh/defconfig +++ b/boards/arm/samv7/samv71-xult/configs/knsh/defconfig @@ -80,6 +80,6 @@ CONFIG_START_YEAR=2015 CONFIG_SYSTEM_I2CTOOL=y CONFIG_SYSTEM_NSH=y CONFIG_SYSTEM_RAMTEST=y -CONFIG_SYS_RESERVED=8 +CONFIG_SYS_RESERVED=9 CONFIG_UART3_SERIAL_CONSOLE=y CONFIG_USER_ENTRYPOINT="nsh_main" diff --git a/boards/arm/stm32/clicker2-stm32/configs/knsh/defconfig b/boards/arm/stm32/clicker2-stm32/configs/knsh/defconfig index 4bf0db3027..32c2eff84a 100644 --- a/boards/arm/stm32/clicker2-stm32/configs/knsh/defconfig +++ b/boards/arm/stm32/clicker2-stm32/configs/knsh/defconfig @@ -52,7 +52,7 @@ CONFIG_STM32_JTAG_SW_ENABLE=y CONFIG_STM32_PWR=y CONFIG_STM32_USART3=y CONFIG_SYSTEM_NSH=y -CONFIG_SYS_RESERVED=8 +CONFIG_SYS_RESERVED=9 CONFIG_TASK_NAME_SIZE=32 CONFIG_USART3_SERIAL_CONSOLE=y CONFIG_USER_ENTRYPOINT="nsh_main" diff --git a/boards/arm/stm32/mikroe-stm32f4/configs/kostest/defconfig b/boards/arm/stm32/mikroe-stm32f4/configs/kostest/defconfig index c23192d832..32ed5f09b7 100644 --- a/boards/arm/stm32/mikroe-stm32f4/configs/kostest/defconfig +++ b/boards/arm/stm32/mikroe-stm32f4/configs/kostest/defconfig @@ -82,7 +82,7 @@ CONFIG_STM32_USART2=y CONFIG_SYSLOG_CHAR=y CONFIG_SYSLOG_DEVPATH="/dev/ttyS0" CONFIG_SYSTEM_NSH=y -CONFIG_SYS_RESERVED=8 +CONFIG_SYS_RESERVED=9 CONFIG_TASK_NAME_SIZE=11 CONFIG_TESTING_OSTEST=y CONFIG_USBDEV=y diff --git a/boards/arm/stm32/olimex-stm32-p407/configs/kelf/defconfig b/boards/arm/stm32/olimex-stm32-p407/configs/kelf/defconfig index e3fcc8e37c..e5a22d93be 100644 --- a/boards/arm/stm32/olimex-stm32-p407/configs/kelf/defconfig +++ b/boards/arm/stm32/olimex-stm32-p407/configs/kelf/defconfig @@ -56,7 +56,7 @@ CONFIG_STM32_SDIO=y CONFIG_STM32_USART3=y CONFIG_STM32_USBHOST=y CONFIG_SYMTAB_ORDEREDBYNAME=y -CONFIG_SYS_RESERVED=8 +CONFIG_SYS_RESERVED=9 CONFIG_USART3_SERIAL_CONSOLE=y CONFIG_USBHOST_ISOC_DISABLE=y CONFIG_USBHOST_MSC=y diff --git a/boards/arm/stm32/olimex-stm32-p407/configs/kmodule/defconfig b/boards/arm/stm32/olimex-stm32-p407/configs/kmodule/defconfig index 839827070d..74bad806f2 100644 --- a/boards/arm/stm32/olimex-stm32-p407/configs/kmodule/defconfig +++ b/boards/arm/stm32/olimex-stm32-p407/configs/kmodule/defconfig @@ -52,7 +52,7 @@ CONFIG_STM32_PWR=y CONFIG_STM32_USART3=y CONFIG_STM32_USBHOST=y CONFIG_SYMTAB_ORDEREDBYNAME=y -CONFIG_SYS_RESERVED=8 +CONFIG_SYS_RESERVED=9 CONFIG_USART3_SERIAL_CONSOLE=y CONFIG_USBHOST_ISOC_DISABLE=y CONFIG_USBHOST_MSC=y diff --git a/boards/arm/stm32/olimex-stm32-p407/configs/knsh/defconfig b/boards/arm/stm32/olimex-stm32-p407/configs/knsh/defconfig index 928051f05f..20eec21363 100644 --- a/boards/arm/stm32/olimex-stm32-p407/configs/knsh/defconfig +++ b/boards/arm/stm32/olimex-stm32-p407/configs/knsh/defconfig @@ -52,7 +52,7 @@ CONFIG_STM32_JTAG_SW_ENABLE=y CONFIG_STM32_PWR=y CONFIG_STM32_USART3=y CONFIG_SYSTEM_NSH=y -CONFIG_SYS_RESERVED=8 +CONFIG_SYS_RESERVED=9 CONFIG_TASK_NAME_SIZE=32 CONFIG_USART3_SERIAL_CONSOLE=y CONFIG_USER_ENTRYPOINT="nsh_main" diff --git a/boards/arm/stm32/stm3240g-eval/configs/knxwm/defconfig b/boards/arm/stm32/stm3240g-eval/configs/knxwm/defconfig index 8e33f7a80f..fbc23a616d 100644 --- a/boards/arm/stm32/stm3240g-eval/configs/knxwm/defconfig +++ b/boards/arm/stm32/stm3240g-eval/configs/knxwm/defconfig @@ -93,7 +93,7 @@ CONFIG_STMPE811_THRESHX=39 CONFIG_STMPE811_THRESHY=51 CONFIG_SYMTAB_ORDEREDBYNAME=y CONFIG_SYSTEM_READLINE=y -CONFIG_SYS_RESERVED=8 +CONFIG_SYS_RESERVED=9 CONFIG_TASK_NAME_SIZE=0 CONFIG_USART3_RXBUFSIZE=128 CONFIG_USART3_SERIAL_CONSOLE=y diff --git a/boards/arm/stm32/stm32f4discovery/configs/kostest/defconfig b/boards/arm/stm32/stm32f4discovery/configs/kostest/defconfig index 627462d8e7..5edb933c15 100644 --- a/boards/arm/stm32/stm32f4discovery/configs/kostest/defconfig +++ b/boards/arm/stm32/stm32f4discovery/configs/kostest/defconfig @@ -39,7 +39,7 @@ CONFIG_START_YEAR=2013 CONFIG_STM32_JTAG_SW_ENABLE=y CONFIG_STM32_USART2=y CONFIG_SYMTAB_ORDEREDBYNAME=y -CONFIG_SYS_RESERVED=8 +CONFIG_SYS_RESERVED=9 CONFIG_TESTING_OSTEST=y CONFIG_TESTING_OSTEST_NBARRIER_THREADS=3 CONFIG_TESTING_OSTEST_STACKSIZE=2048 diff --git a/boards/arm/stm32l4/stm32l476vg-disco/configs/knsh/defconfig b/boards/arm/stm32l4/stm32l476vg-disco/configs/knsh/defconfig index 37d88e2ec8..0c94cf8469 100644 --- a/boards/arm/stm32l4/stm32l476vg-disco/configs/knsh/defconfig +++ b/boards/arm/stm32l4/stm32l476vg-disco/configs/knsh/defconfig @@ -69,7 +69,7 @@ CONFIG_STM32L4_RTC=y CONFIG_STM32L4_SAI1PLL=y CONFIG_STM32L4_USART2=y CONFIG_SYSTEM_NSH=y -CONFIG_SYS_RESERVED=8 +CONFIG_SYS_RESERVED=9 CONFIG_TASK_NAME_SIZE=0 CONFIG_USART2_SERIAL_CONSOLE=y CONFIG_USER_ENTRYPOINT="nsh_main" diff --git a/boards/arm/stm32l4/stm32l4r9ai-disco/configs/knsh/defconfig b/boards/arm/stm32l4/stm32l4r9ai-disco/configs/knsh/defconfig index dfea95c178..2590e16978 100644 --- a/boards/arm/stm32l4/stm32l4r9ai-disco/configs/knsh/defconfig +++ b/boards/arm/stm32l4/stm32l4r9ai-disco/configs/knsh/defconfig @@ -73,7 +73,7 @@ CONFIG_STM32L4_SRAM2_HEAP=y CONFIG_STM32L4_UART4=y CONFIG_STM32L4_USART2=y CONFIG_SYSTEM_NSH=y -CONFIG_SYS_RESERVED=8 +CONFIG_SYS_RESERVED=9 CONFIG_TASK_NAME_SIZE=0 CONFIG_UART4_BAUD=2000000 CONFIG_UART4_RXBUFSIZE=512 diff --git a/boards/arm/tiva/lm3s6965-ek/configs/qemu-protected/defconfig b/boards/arm/tiva/lm3s6965-ek/configs/qemu-protected/defconfig index 99597dc9f8..da63d4bae9 100644 --- a/boards/arm/tiva/lm3s6965-ek/configs/qemu-protected/defconfig +++ b/boards/arm/tiva/lm3s6965-ek/configs/qemu-protected/defconfig @@ -98,7 +98,7 @@ CONFIG_SYSTEM_NETDB=y CONFIG_SYSTEM_NSH=y CONFIG_SYSTEM_NTPC=y CONFIG_SYSTEM_PING=y -CONFIG_SYS_RESERVED=8 +CONFIG_SYS_RESERVED=9 CONFIG_TASK_NAME_SIZE=0 CONFIG_TIVA_ETHERNET=y CONFIG_TIVA_GPIOA_IRQS=y diff --git a/boards/risc-v/c906/smartl-c906/configs/knsh/defconfig b/boards/risc-v/c906/smartl-c906/configs/knsh/defconfig index c22533fc90..5280531fcb 100644 --- a/boards/risc-v/c906/smartl-c906/configs/knsh/defconfig +++ b/boards/risc-v/c906/smartl-c906/configs/knsh/defconfig @@ -57,7 +57,7 @@ CONFIG_START_DAY=7 CONFIG_START_MONTH=3 CONFIG_START_YEAR=2021 CONFIG_SYSTEM_NSH=y -CONFIG_SYS_RESERVED=8 +CONFIG_SYS_RESERVED=9 CONFIG_TASK_NAME_SIZE=20 CONFIG_TESTING_GETPRIME=y CONFIG_TESTING_OSTEST=y diff --git a/boards/risc-v/k210/maix-bit/configs/knsh/defconfig b/boards/risc-v/k210/maix-bit/configs/knsh/defconfig index bf09a7db53..6a24cf8b54 100644 --- a/boards/risc-v/k210/maix-bit/configs/knsh/defconfig +++ b/boards/risc-v/k210/maix-bit/configs/knsh/defconfig @@ -46,7 +46,7 @@ CONFIG_START_DAY=12 CONFIG_START_MONTH=5 CONFIG_START_YEAR=2020 CONFIG_SYSTEM_NSH=y -CONFIG_SYS_RESERVED=8 +CONFIG_SYS_RESERVED=9 CONFIG_TASK_NAME_SIZE=20 CONFIG_TESTING_GETPRIME=y CONFIG_TESTING_OSTEST=y diff --git a/boards/risc-v/k210/maix-bit/configs/knsh_smp/defconfig b/boards/risc-v/k210/maix-bit/configs/knsh_smp/defconfig index 67debe2592..53e6dc91f6 100644 --- a/boards/risc-v/k210/maix-bit/configs/knsh_smp/defconfig +++ b/boards/risc-v/k210/maix-bit/configs/knsh_smp/defconfig @@ -51,7 +51,7 @@ CONFIG_START_YEAR=2021 CONFIG_SYSTEM_NSH=y CONFIG_SYSTEM_SYSTEM=y CONFIG_SYSTEM_TASKSET=y -CONFIG_SYS_RESERVED=8 +CONFIG_SYS_RESERVED=9 CONFIG_TASK_NAME_SIZE=20 CONFIG_TESTING_GETPRIME=y CONFIG_TESTING_OSTEST=y diff --git a/boards/risc-v/k210/maix-bit/configs/kostest/defconfig b/boards/risc-v/k210/maix-bit/configs/kostest/defconfig index f120882b49..db0b77e8ff 100644 --- a/boards/risc-v/k210/maix-bit/configs/kostest/defconfig +++ b/boards/risc-v/k210/maix-bit/configs/kostest/defconfig @@ -42,7 +42,7 @@ CONFIG_STACK_COLORATION=y CONFIG_START_DAY=14 CONFIG_START_MONTH=2 CONFIG_START_YEAR=2020 -CONFIG_SYS_RESERVED=8 +CONFIG_SYS_RESERVED=9 CONFIG_TASK_NAME_SIZE=20 CONFIG_TESTING_OSTEST=y CONFIG_UART0_SERIAL_CONSOLE=y diff --git a/include/nuttx/arch.h b/include/nuttx/arch.h index d3ef3d6208..37c5c7f893 100644 --- a/include/nuttx/arch.h +++ b/include/nuttx/arch.h @@ -558,6 +558,8 @@ void up_task_start(main_t taskentry, int argc, FAR char *argv[]) noreturn_function; #endif +#if !defined(CONFIG_BUILD_FLAT) && defined(__KERNEL__) && \ + !defined(CONFIG_DISABLE_PTHREAD) /**************************************************************************** * Name: up_pthread_start * @@ -583,11 +585,28 @@ 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_trampoline_t startup, pthread_startroutine_t entrypt, pthread_addr_t arg); noreturn_function; + +/**************************************************************************** + * Name: up_pthread_exit + * + * Description: + * In this kernel mode build, this function will be called to execute a + * pthread in user-space. This kernel-mode stub will then be called + * transfer control to the user-mode pthread_exit. + * + * Input Parameters: + * exit - The user-space pthread_exit function + * exit_value - The pointer of the pthread exit parameter + * + * Returned Value: + * None + ****************************************************************************/ + +void up_pthread_exit(pthread_exitroutine_t exit, FAR void *exit_value); + noreturn_function; #endif /**************************************************************************** diff --git a/include/nuttx/pthread.h b/include/nuttx/pthread.h index d8e30aa622..7c4b8ceba2 100644 --- a/include/nuttx/pthread.h +++ b/include/nuttx/pthread.h @@ -140,6 +140,7 @@ EXTERN const pthread_attr_t g_default_pthread_attr; * for the new thread * entry - The new thread starts execution by invoking entry * arg - It is passed as the sole argument of entry + * exit - The user-space pthread exit function * * Returned Value: * OK (0) on success; a (non-negated) errno value on failure. The errno @@ -149,7 +150,8 @@ EXTERN const pthread_attr_t g_default_pthread_attr; 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); + pthread_startroutine_t entry, pthread_addr_t arg, + pthread_exitroutine_t exit); /**************************************************************************** * Name: nx_pthread_exit @@ -163,8 +165,6 @@ int nx_pthread_create(pthread_trampoline_t trampoline, FAR pthread_t *thread, * Returned Value: * None * - * Assumptions: - * ****************************************************************************/ void nx_pthread_exit(FAR void *exit_value) noreturn_function; diff --git a/include/nuttx/sched.h b/include/nuttx/sched.h index 95c7ad7fa5..a7d0c4ffbe 100644 --- a/include/nuttx/sched.h +++ b/include/nuttx/sched.h @@ -95,16 +95,17 @@ #define TCB_FLAG_NONCANCELABLE (1 << 2) /* Bit 2: Pthread is non-cancelable */ #define TCB_FLAG_CANCEL_DEFERRED (1 << 3) /* Bit 3: Deferred (vs asynch) cancellation type */ #define TCB_FLAG_CANCEL_PENDING (1 << 4) /* Bit 4: Pthread cancel is pending */ -#define TCB_FLAG_POLICY_SHIFT (5) /* Bit 5-6: Scheduling policy */ +#define TCB_FLAG_CANCEL_DOING (1 << 5) /* Bit 4: Pthread cancel/exit is doing */ +#define TCB_FLAG_POLICY_SHIFT (6) /* Bit 5-6: Scheduling policy */ #define TCB_FLAG_POLICY_MASK (3 << TCB_FLAG_POLICY_SHIFT) # define TCB_FLAG_SCHED_FIFO (0 << TCB_FLAG_POLICY_SHIFT) /* FIFO scheding policy */ # define TCB_FLAG_SCHED_RR (1 << TCB_FLAG_POLICY_SHIFT) /* Round robin scheding policy */ # define TCB_FLAG_SCHED_SPORADIC (2 << TCB_FLAG_POLICY_SHIFT) /* Sporadic scheding policy */ # define TCB_FLAG_SCHED_OTHER (3 << TCB_FLAG_POLICY_SHIFT) /* Other scheding policy */ -#define TCB_FLAG_CPU_LOCKED (1 << 7) /* Bit 7: Locked to this CPU */ -#define TCB_FLAG_SIGNAL_ACTION (1 << 8) /* Bit 8: In a signal handler */ -#define TCB_FLAG_SYSCALL (1 << 9) /* Bit 9: In a system call */ -#define TCB_FLAG_EXIT_PROCESSING (1 << 10) /* Bit 10: Exitting */ +#define TCB_FLAG_CPU_LOCKED (1 << 8) /* Bit 7: Locked to this CPU */ +#define TCB_FLAG_SIGNAL_ACTION (1 << 9) /* Bit 8: In a signal handler */ +#define TCB_FLAG_SYSCALL (1 << 10) /* Bit 9: In a system call */ +#define TCB_FLAG_EXIT_PROCESSING (1 << 11) /* Bit 10: Exitting */ /* Bits 11-15: Available */ /* Values for struct task_group tg_flags */ @@ -761,6 +762,7 @@ struct pthread_tcb_s pthread_trampoline_t trampoline; /* User-space pthread startup function */ pthread_addr_t arg; /* Startup argument */ + pthread_exitroutine_t exit; /* User-space pthread exit function */ FAR void *joininfo; /* Detach-able info to support join */ }; #endif /* !CONFIG_DISABLE_PTHREAD */ diff --git a/include/pthread.h b/include/pthread.h index fb8a458ca4..e7618bae0c 100644 --- a/include/pthread.h +++ b/include/pthread.h @@ -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_exitroutine_t)(pthread_addr_t); + typedef void (*pthread_trampoline_t)(pthread_startroutine_t, pthread_addr_t); struct pthread_attr_s diff --git a/include/sys/syscall_lookup.h b/include/sys/syscall_lookup.h index 7781f09051..5a66d8f517 100644 --- a/include/sys/syscall_lookup.h +++ b/include/sys/syscall_lookup.h @@ -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(nx_pthread_create, 5) + SYSCALL_LOOKUP(nx_pthread_create, 6) SYSCALL_LOOKUP(pthread_detach, 1) SYSCALL_LOOKUP(nx_pthread_exit, 1) SYSCALL_LOOKUP(pthread_getschedparam, 3) diff --git a/libs/libc/pthread/pthread_create.c b/libs/libc/pthread/pthread_create.c index e81c63e047..fe85127c60 100644 --- a/libs/libc/pthread/pthread_create.c +++ b/libs/libc/pthread/pthread_create.c @@ -87,5 +87,5 @@ 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); + arg, pthread_exit); } diff --git a/libs/libc/pthread/pthread_exit.c b/libs/libc/pthread/pthread_exit.c index 2e456b6c08..ce1324c571 100644 --- a/libs/libc/pthread/pthread_exit.c +++ b/libs/libc/pthread/pthread_exit.c @@ -40,7 +40,7 @@ * Terminate execution of a thread started with pthread_create. * * Input Parameters: - * exit_value + * exit_value - The pointer of the pthread_exit parameter * * Returned Value: * None diff --git a/sched/pthread/pthread_cancel.c b/sched/pthread/pthread_cancel.c index d2dc2f3833..e4088ba8c1 100644 --- a/sched/pthread/pthread_cancel.c +++ b/sched/pthread/pthread_cancel.c @@ -24,6 +24,8 @@ #include +#include + #include #include #include @@ -82,7 +84,15 @@ int pthread_cancel(pthread_t thread) if (tcb == this_task()) { +#if !defined(CONFIG_BUILD_FLAT) && defined(__KERNEL__) + tcb->flags &= ~TCB_FLAG_CANCEL_PENDING; + tcb->flags |= TCB_FLAG_CANCEL_DOING; + + up_pthread_exit(((FAR struct pthread_tcb_s *)tcb)->exit, + PTHREAD_CANCELED); +#else pthread_exit(PTHREAD_CANCELED); +#endif } /* Complete pending join operations */ diff --git a/sched/pthread/pthread_create.c b/sched/pthread/pthread_create.c index ade4dc6550..507cc6c94d 100644 --- a/sched/pthread/pthread_create.c +++ b/sched/pthread/pthread_create.c @@ -79,6 +79,7 @@ const pthread_attr_t g_default_pthread_attr = PTHREAD_ATTR_INITIALIZER; * tcb - Address of the new task's TCB * trampoline - User space pthread startup function * arg - The argument to provide to the pthread on startup. + * exit - The user-space pthread exit function * * Returned Value: * None @@ -87,7 +88,8 @@ const pthread_attr_t g_default_pthread_attr = PTHREAD_ATTR_INITIALIZER; static inline void pthread_tcb_setup(FAR struct pthread_tcb_s *ptcb, pthread_trampoline_t trampoline, - pthread_addr_t arg) + pthread_addr_t arg, + pthread_exitroutine_t exit) { #if CONFIG_TASK_NAME_SIZE > 0 /* Copy the pthread name into the TCB */ @@ -102,6 +104,7 @@ static inline void pthread_tcb_setup(FAR struct pthread_tcb_s *ptcb, ptcb->trampoline = trampoline; ptcb->arg = arg; + ptcb->exit = exit; } /**************************************************************************** @@ -193,7 +196,12 @@ static void pthread_start(void) /* The thread has returned (should never happen) */ DEBUGPANIC(); - pthread_exit(NULL); +#ifndef CONFIG_BUILD_FLAT + ptcb->cmn.flags &= ~TCB_FLAG_CANCEL_PENDING; + ptcb->cmn.flags |= TCB_FLAG_CANCEL_DOING; + + up_pthread_exit(ptcb->exit, NULL); +#endif } /**************************************************************************** @@ -215,6 +223,7 @@ static void pthread_start(void) * for the new thread * entry - The new thread starts execution by invoking entry * arg - It is passed as the sole argument of entry + * exit - The user-space pthread exit function * * Returned Value: * OK (0) on success; a (non-negated) errno value on failure. The errno @@ -224,7 +233,8 @@ static void pthread_start(void) 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) + pthread_startroutine_t entry, pthread_addr_t arg, + pthread_exitroutine_t exit) { FAR struct pthread_tcb_s *ptcb; FAR struct tls_info_s *info; @@ -237,6 +247,7 @@ int nx_pthread_create(pthread_trampoline_t trampoline, FAR pthread_t *thread, bool group_joined = false; DEBUGASSERT(trampoline != NULL); + DEBUGASSERT(exit != NULL); /* If attributes were not supplied, use the default attributes */ @@ -450,7 +461,7 @@ int nx_pthread_create(pthread_trampoline_t trampoline, FAR pthread_t *thread, * passed by value */ - pthread_tcb_setup(ptcb, trampoline, arg); + pthread_tcb_setup(ptcb, trampoline, arg, exit); /* Join the parent's task group */ diff --git a/sched/signal/sig_default.c b/sched/signal/sig_default.c index 08b8f2e47e..7e87089e57 100644 --- a/sched/signal/sig_default.c +++ b/sched/signal/sig_default.c @@ -224,7 +224,15 @@ static void nxsig_abnormal_termination(int signo) * REVISIT: This will not work if HAVE_GROUP_MEMBERS is not set. */ - pthread_exit(NULL); +#if !defined(CONFIG_BUILD_FLAT) && defined(__KERNEL__) + rtcb->flags &= ~TCB_FLAG_CANCEL_PENDING; + rtcb->flags |= TCB_FLAG_CANCEL_DOING; + + up_pthread_exit(((FAR struct pthread_tcb_s *)rtcb)->exit, + PTHREAD_CANCELED); +#else + pthread_exit(PTHREAD_CANCELED); +#endif } else #endif diff --git a/sched/task/task_cancelpt.c b/sched/task/task_cancelpt.c index 8fcada3569..659e5db6d1 100644 --- a/sched/task/task_cancelpt.c +++ b/sched/task/task_cancelpt.c @@ -57,6 +57,7 @@ #include #include +#include #include "sched/sched.h" #include "semaphore/semaphore.h" @@ -139,7 +140,15 @@ bool enter_cancellation_point(void) if ((tcb->flags & TCB_FLAG_TTYPE_MASK) == TCB_FLAG_TTYPE_PTHREAD) { +#if !defined(CONFIG_BUILD_FLAT) && defined(__KERNEL__) + tcb->flags &= ~TCB_FLAG_CANCEL_PENDING; + tcb->flags |= TCB_FLAG_CANCEL_DOING; + + up_pthread_exit(((FAR struct pthread_tcb_s *)tcb)->exit, + PTHREAD_CANCELED); +#else pthread_exit(PTHREAD_CANCELED); +#endif } else #endif @@ -226,7 +235,15 @@ void leave_cancellation_point(void) if ((tcb->flags & TCB_FLAG_TTYPE_MASK) == TCB_FLAG_TTYPE_PTHREAD) { +#if !defined(CONFIG_BUILD_FLAT) && defined(__KERNEL__) + tcb->flags &= ~TCB_FLAG_CANCEL_PENDING; + tcb->flags |= TCB_FLAG_CANCEL_DOING; + + up_pthread_exit(((FAR struct pthread_tcb_s *)tcb)->exit, + PTHREAD_CANCELED); +#else pthread_exit(PTHREAD_CANCELED); +#endif } else #endif diff --git a/sched/task/task_setcancelstate.c b/sched/task/task_setcancelstate.c index bb08b542c3..6b61632e99 100644 --- a/sched/task/task_setcancelstate.c +++ b/sched/task/task_setcancelstate.c @@ -112,7 +112,15 @@ int task_setcancelstate(int state, FAR int *oldstate) if ((tcb->flags & TCB_FLAG_TTYPE_MASK) == TCB_FLAG_TTYPE_PTHREAD) { +#if !defined(CONFIG_BUILD_FLAT) && defined(__KERNEL__) + tcb->flags &= ~TCB_FLAG_CANCEL_PENDING; + tcb->flags |= TCB_FLAG_CANCEL_DOING; + + up_pthread_exit(((FAR struct pthread_tcb_s *)tcb)->exit, + PTHREAD_CANCELED); +#else pthread_exit(PTHREAD_CANCELED); +#endif } else #endif diff --git a/sched/task/task_setcanceltype.c b/sched/task/task_setcanceltype.c index b14fec53e0..d57cc6408a 100644 --- a/sched/task/task_setcanceltype.c +++ b/sched/task/task_setcanceltype.c @@ -100,7 +100,15 @@ int task_setcanceltype(int type, FAR int *oldtype) #ifndef CONFIG_DISABLE_PTHREAD if ((tcb->flags & TCB_FLAG_TTYPE_MASK) == TCB_FLAG_TTYPE_PTHREAD) { - pthread_exit(PTHREAD_CANCELED); +#if !defined(CONFIG_BUILD_FLAT) && defined(__KERNEL__) + tcb->flags &= ~TCB_FLAG_CANCEL_PENDING; + tcb->flags |= TCB_FLAG_CANCEL_DOING; + + up_pthread_exit(((FAR struct pthread_tcb_s *)tcb)->exit, + PTHREAD_CANCELED); +#else + pthread_exit(PTHREAD_CANCELED); +#endif } else #endif diff --git a/syscall/syscall.csv b/syscall/syscall.csv index 8502cc0b51..c39442f30d 100644 --- a/syscall/syscall.csv +++ b/syscall/syscall.csv @@ -66,7 +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_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","pthread_exitroutine_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 *"