diff --git a/include/nuttx/sched.h b/include/nuttx/sched.h index 468b32dea3..9738724487 100644 --- a/include/nuttx/sched.h +++ b/include/nuttx/sched.h @@ -172,18 +172,6 @@ # define _SCHED_ERRVAL(r) (-errno) #endif -/* The number of callback can be saved */ - -#if defined(CONFIG_SCHED_ONEXIT_MAX) -# define CONFIG_SCHED_EXIT_MAX CONFIG_SCHED_ONEXIT_MAX -#elif defined(CONFIG_SCHED_ATEXIT_MAX) -# define CONFIG_SCHED_EXIT_MAX CONFIG_SCHED_ATEXIT_MAX -#endif - -#if defined(CONFIG_SCHED_EXIT_MAX) && CONFIG_SCHED_EXIT_MAX < 1 -# error "CONFIG_SCHED_EXIT_MAX < 1" -#endif - #ifdef CONFIG_DEBUG_TCBINFO # define TCB_PID_OFF offsetof(struct tcb_s, pid) # define TCB_STATE_OFF offsetof(struct tcb_s, task_state) @@ -273,18 +261,6 @@ typedef union entry_u entry_t; typedef CODE void (*starthook_t)(FAR void *arg); #endif -/* These are the types of the functions that are executed with exit() is - * called (if registered via atexit() on on_exit()). - */ - -#ifdef CONFIG_SCHED_ATEXIT -typedef CODE void (*atexitfunc_t)(void); -#endif - -#ifdef CONFIG_SCHED_ONEXIT -typedef CODE void (*onexitfunc_t)(int exitcode, FAR void *arg); -#endif - /* struct sporadic_s ********************************************************/ #ifdef CONFIG_SCHED_SPORADIC @@ -392,24 +368,6 @@ struct stackinfo_s /* from the stack. */ }; -/* struct exitinfo_s ********************************************************/ - -struct exitinfo_s -{ - union - { -#ifdef CONFIG_SCHED_ATEXIT - atexitfunc_t at; -#endif -#ifdef CONFIG_SCHED_ONEXIT - onexitfunc_t on; -#endif - } func; -#ifdef CONFIG_SCHED_ONEXIT - FAR void *arg; -#endif -}; - /* struct task_group_s ******************************************************/ /* All threads created by pthread_create belong in the same task group (along @@ -468,12 +426,6 @@ struct task_group_s FAR pid_t *tg_members; /* Members of the group */ #endif - /* [at|on]exit support ****************************************************/ - -#ifdef CONFIG_SCHED_EXIT_MAX - struct exitinfo_s tg_exit[CONFIG_SCHED_EXIT_MAX]; -#endif - #ifdef CONFIG_BINFMT_LOADABLE /* Loadable module support ************************************************/ diff --git a/include/sys/syscall_lookup.h b/include/sys/syscall_lookup.h index 6da43cbe55..1df3eda2ce 100644 --- a/include/sys/syscall_lookup.h +++ b/include/sys/syscall_lookup.h @@ -116,14 +116,6 @@ SYSCALL_LOOKUP(up_assert, 2) SYSCALL_LOOKUP(vfork, 0) #endif -#ifdef CONFIG_SCHED_ATEXIT - SYSCALL_LOOKUP(atexit, 1) -#endif - -#ifdef CONFIG_SCHED_ONEXIT - SYSCALL_LOOKUP(on_exit, 2) -#endif - #ifdef CONFIG_SCHED_WAITPID SYSCALL_LOOKUP(waitpid, 3) #ifdef CONFIG_SCHED_HAVE_PARENT diff --git a/libs/libc/pthread/pthread_cleanup.c b/libs/libc/pthread/pthread_cleanup.c index 6aabcb4a7c..b8aca803ad 100644 --- a/libs/libc/pthread/pthread_cleanup.c +++ b/libs/libc/pthread/pthread_cleanup.c @@ -75,12 +75,7 @@ static void pthread_cleanup_pop_tls(FAR struct tls_info_s *tls, int execute) { FAR struct pthread_cleanup_s *cb; - /* Yes.. Execute the clean-up routine. - * - * REVISIT: This is a security problem In the PROTECTED and KERNEL - * builds: We must not call the registered function in supervisor - * mode! See also on_exit() and atexit() callbacks. - */ + /* Yes.. Execute the clean-up routine. */ cb = &tls->stack[ndx]; cb->pc_cleaner(cb->pc_arg); diff --git a/libs/libxx/Makefile b/libs/libxx/Makefile index 50cf35aaad..aa3d7950ce 100644 --- a/libs/libxx/Makefile +++ b/libs/libxx/Makefile @@ -41,8 +41,6 @@ ifeq ($(CONFIG_LIBCXXABI),y) include libcxxabi.defs endif -CXXSRCS += libxx_cxa_atexit.cxx - # Object Files AOBJS = $(ASRCS:.S=$(OBJEXT)) diff --git a/libs/libxx/libxx_cxa_atexit.cxx b/libs/libxx/libxx_cxa_atexit.cxx deleted file mode 100644 index 6f50fa1035..0000000000 --- a/libs/libxx/libxx_cxa_atexit.cxx +++ /dev/null @@ -1,130 +0,0 @@ -//*************************************************************************** -// libs/libxx/libxx_eabi_atexit.cxx -// -// 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 -// -//*************************************************************************** - -//*************************************************************************** -// Included Files -//*************************************************************************** - -#include - -#include -#include - -#include "libxx.hxx" - -//*************************************************************************** -// Pre-processor Definitions -//*************************************************************************** - -//*************************************************************************** -// Private Types -//*************************************************************************** - -struct __cxa_atexit_s -{ - __cxa_exitfunc_t func; - FAR void *arg; -}; - -//*************************************************************************** -// Private Data -//*************************************************************************** - -extern "C" -{ - //************************************************************************* - // Public Data - //************************************************************************* - - FAR void *__dso_handle = &__dso_handle; - - //************************************************************************* - // Private Functions - //************************************************************************* - - //************************************************************************* - // Name: __cxa_callback - // - // Description: - // This is really just an "adaptor" function that matches the form of - // the __cxa_exitfunc_t to an onexitfunc_t using an allocated structure - // to marshall the call parameters. - // - //************************************************************************* - -#ifdef CONFIG_SCHED_ONEXIT - static void __cxa_callback(int exitcode, FAR void *arg) - { - FAR struct __cxa_atexit_s *alloc = (FAR struct __cxa_atexit_s *)arg; - DEBUGASSERT(alloc && alloc->func); - - alloc->func(alloc->arg); - lib_free(alloc); - } -#endif - - //************************************************************************* - // Public Functions - //************************************************************************* - - //************************************************************************* - // Name: __cxa_atexit - // - // Description: - // __cxa_atexit() registers a destructor function to be called by exit(). - // On a call to exit(), the registered functions should be called with - // the single argument 'arg'. Destructor functions shall always be - // called in the reverse order to their registration (i.e. the most - // recently registered function shall be called first), - // - // If shared libraries were supported, the callbacks should be invoked - // when the shared library is unloaded as well. - // - // Reference: - // Linux base - // - //************************************************************************* - - int __cxa_atexit(__cxa_exitfunc_t func, FAR void *arg, FAR void *dso_handle) - { -#ifdef CONFIG_SCHED_ONEXIT - // Allocate memory to hold the marshaled __cxa_exitfunc_t call - // information. - - FAR struct __cxa_atexit_s *alloc = - (FAR struct __cxa_atexit_s *)lib_malloc(sizeof(struct __cxa_atexit_s)); - - if (alloc) - { - // Register the function to be called when the task/thread exists. - - alloc->func = func; - alloc->arg = arg; - - return on_exit(__cxa_callback, alloc); - } - else -#endif - { - // What else can we do? - - return 0; - } - } -} diff --git a/sched/Kconfig b/sched/Kconfig index f6695534d9..fdf8eb0cbe 100644 --- a/sched/Kconfig +++ b/sched/Kconfig @@ -1311,45 +1311,6 @@ config SCHED_STARTHOOK starthook is useful, for example, for setting up automatic configuration of C++ constructors. -config SCHED_ATEXIT - bool "Enable atexit() API" - default n - ---help--- - Enables the atexit() API - -config SCHED_ATEXIT_MAX - int "Max number of atexit() functions" - default 1 - depends on SCHED_ATEXIT && !SCHED_ONEXIT - ---help--- - By default if SCHED_ATEXIT is selected, only a single atexit() function - is supported. That number can be increased by defined this setting to - the number that you require. - - If both SCHED_ONEXIT and SCHED_ATEXIT are selected, then atexit() is built - on top of the on_exit() implementation. In that case, SCHED_ONEXIT_MAX - determines the size of the combined number of atexit(0) and on_exit calls - and SCHED_ATEXIT_MAX is not used. - -config SCHED_ONEXIT - bool "Enable on_exit() API" - default n - ---help--- - Enables the on_exit() API - -config SCHED_ONEXIT_MAX - int "Max number of on_exit() functions" - default 1 - depends on SCHED_ONEXIT - ---help--- - By default if SCHED_ONEXIT is selected, only a single on_exit() function - is supported. That number can be increased by defined this setting to the - number that you require. - - If both SCHED_ONEXIT and SCHED_ATEXIT are selected, then atexit() is built - on top of the on_exit() implementation. In that case, SCHED_ONEXIT_MAX - determines the size of the combined number of atexit(0) and on_exit calls. - endmenu # RTOS hooks menu "Signal Configuration" diff --git a/sched/task/Make.defs b/sched/task/Make.defs index 406ea35a0b..a3a3f34993 100644 --- a/sched/task/Make.defs +++ b/sched/task/Make.defs @@ -53,14 +53,6 @@ ifeq ($(CONFIG_SCHED_STARTHOOK),y) CSRCS += task_starthook.c endif -ifeq ($(CONFIG_SCHED_ATEXIT),y) -CSRCS += task_atexit.c -endif - -ifeq ($(CONFIG_SCHED_ONEXIT),y) -CSRCS += task_onexit.c -endif - # Include task build support DEPPATH += --dep-path task diff --git a/sched/task/task_atexit.c b/sched/task/task_atexit.c deleted file mode 100644 index c5b7c2b4e5..0000000000 --- a/sched/task/task_atexit.c +++ /dev/null @@ -1,133 +0,0 @@ -/**************************************************************************** - * sched/task/task_atexit.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 -#include -#include - -#include - -#include "sched/sched.h" -#include "task/task.h" - -#ifdef CONFIG_SCHED_ATEXIT - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -#ifdef CONFIG_SCHED_ONEXIT -static void exitfunc(int exitcode, FAR void *arg) -{ - (*(atexitfunc_t)arg)(); -} -#endif - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: atexit - * - * Description: - * Registers a function to be called at program exit. - * The atexit() function registers the given function to be called - * at normal process termination, whether via exit or via return from - * the program's main(). - * - * NOTE: CONFIG_SCHED_ATEXIT must be defined to enable this function - * - * Limitations in the current implementation: - * - * 1. Only a single atexit function can be registered unless - * CONFIG_SCHED_ATEXIT_MAX defines a larger number. - * 2. atexit functions are not inherited when a new task is - * created. - * 3. If both SCHED_ONEXIT and SCHED_ATEXIT are selected, then atexit() - * is built on top of the on_exit() implementation. In that case, - * CONFIG_SCHED_ONEXIT_MAX determines the size of the combined - * number of atexit() and on_exit() calls and SCHED_ATEXIT_MAX is - * not used. - * - * Input Parameters: - * func - A pointer to the function to be called when the task exits. - * - * Returned Value: - * Zero on success. Non-zero on failure. - * - ****************************************************************************/ - -int atexit(void (*func)(void)) -{ -#if defined(CONFIG_SCHED_ONEXIT) - /* atexit is equivalent to on_exit() with no argument (Assuming that the - * ABI can handle a callback function that receives more parameters than - * it expects). - */ - - return on_exit(exitfunc, func); - -#else - FAR struct tcb_s *tcb = this_task(); - FAR struct task_group_s *group = tcb->group; - int index; - int ret = ERROR; - - DEBUGASSERT(group); - - /* The following must be atomic */ - - if (func) - { - sched_lock(); - - /* Search for the first available slot. atexit() functions are - * registered from lower to higher array indices; they must be called - * in the reverse order of registration when task exists, i.e., from - * higher to lower indices. - */ - - for (index = 0; index < CONFIG_SCHED_EXIT_MAX; index++) - { - if (!group->tg_exit[index].func.at) - { - group->tg_exit[index].func.at = func; - ret = OK; - break; - } - } - - sched_unlock(); - } - - return ret; -#endif -} - -#endif /* CONFIG_SCHED_ATEXIT */ diff --git a/sched/task/task_exithook.c b/sched/task/task_exithook.c index 0955658f5f..0a1cbcbb41 100644 --- a/sched/task/task_exithook.c +++ b/sched/task/task_exithook.c @@ -43,126 +43,6 @@ * Private Functions ****************************************************************************/ -/**************************************************************************** - * Name: nxtask_atexit - * - * Description: - * Call any registered atexit function(s) - * - ****************************************************************************/ - -#if defined(CONFIG_SCHED_ATEXIT) && !defined(CONFIG_SCHED_ONEXIT) -static inline void nxtask_atexit(FAR struct tcb_s *tcb) -{ - FAR struct task_group_s *group = tcb->group; - - /* Make sure that we have not already left the group. Only the final - * exiting thread in the task group should trigger the atexit() - * callbacks. - * - * REVISIT: This is a security problem In the PROTECTED and KERNEL builds: - * We must not call the registered function in supervisor mode! See also - * on_exit() and pthread_cleanup_pop() callbacks. - * - * REVISIT: In the case of task_delete(), the callback would execute in - * the context the caller of task_delete() cancel, not in the context of - * the exiting task (or process). - */ - - if (group && group->tg_nmembers == 1) - { - int index; - - /* Call each atexit function in reverse order of registration atexit() - * functions are registered from lower to higher array indices; they - * must be called in the reverse order of registration when the task - * group exits, i.e., from higher to lower indices. - */ - - for (index = CONFIG_SCHED_EXIT_MAX - 1; index >= 0; index--) - { - if (group->tg_exit[index].func.at) - { - atexitfunc_t func; - - /* Nullify the atexit function to prevent its reuse. */ - - func = group->tg_exit[index].func.at; - group->tg_exit[index].func.at = NULL; - - /* Call the atexit function */ - - (*func)(); - } - } - } -} -#else -# define nxtask_atexit(tcb) -#endif - -/**************************************************************************** - * Name: nxtask_onexit - * - * Description: - * Call any registered on_exit function(s) - * - ****************************************************************************/ - -#ifdef CONFIG_SCHED_ONEXIT -static inline void nxtask_onexit(FAR struct tcb_s *tcb, int status) -{ - FAR struct task_group_s *group = tcb->group; - - /* Make sure that we have not already left the group. Only the final - * exiting thread in the task group should trigger the atexit() - * callbacks. - * - * REVISIT: This is a security problem In the PROTECTED and KERNEL builds: - * We must not call the registered function in supervisor mode! See also - * atexit() and pthread_cleanup_pop() callbacks. - * - * REVISIT: In the case of task_delete(), the callback would execute in - * he context the caller of task_delete() cancel, not in the context of - * the exiting task (or process). - */ - - if (group && group->tg_nmembers == 1) - { - int index; - - /* Call each on_exit function in reverse order of registration. - * on_exit() functions are registered from lower to higher array - * indices; they must be called in the reverse order of registration - * when the task group exits, i.e., from higher to lower indices. - */ - - for (index = CONFIG_SCHED_EXIT_MAX - 1; index >= 0; index--) - { - if (group->tg_exit[index].func.on) - { - onexitfunc_t func; - FAR void *arg; - - /* Nullify the on_exit function to prevent its reuse. */ - - func = group->tg_exit[index].func.on; - arg = group->tg_exit[index].arg; - - group->tg_exit[index].func.on = NULL; - group->tg_exit[index].arg = NULL; - - /* Call the on_exit function */ - - (*func)(status, arg); - } - } - } -} -#else -# define nxtask_onexit(tcb,status) -#endif - /**************************************************************************** * Name: nxtask_exitstatus * @@ -579,31 +459,8 @@ void nxtask_exithook(FAR struct tcb_s *tcb, int status, bool nonblocking) tcb->cpcount = 0; #endif - /* If exit function(s) were registered, call them now before we do any un- - * initialization. - * - * NOTES: - * - * 1. In the case of task_delete(), the exit function will *not* be called - * on the thread execution of the task being deleted! That is probably - * a bug. - * 2. We cannot call the exit functions if nonblocking is requested: These - * functions might block. - * 3. This function will only be called with non-blocking == true - * only when called through _exit(). _exit() behaviors requires that - * the exit functions *not* be called. - */ - if (!nonblocking) { -#if defined(CONFIG_SCHED_ATEXIT) || defined(CONFIG_SCHED_ONEXIT) - nxtask_atexit(tcb); - - /* Call any registered on_exit function(s) */ - - nxtask_onexit(tcb, status); -#endif - /* If this is the last thread in the group, then flush all streams * (File descriptors will be closed when the TCB is deallocated). * diff --git a/sched/task/task_onexit.c b/sched/task/task_onexit.c deleted file mode 100644 index 2e11673fe6..0000000000 --- a/sched/task/task_onexit.c +++ /dev/null @@ -1,115 +0,0 @@ -/**************************************************************************** - * sched/task/task_onexit.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 -#include -#include - -#include - -#include "sched/sched.h" -#include "task/task.h" - -#ifdef CONFIG_SCHED_ONEXIT - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: on_exit - * - * Description: - * Registers a function to be called at program exit. - * The on_exit() function registers the given function to be called - * at normal process termination, whether via exit or via return from - * the program's main(). The function is passed the status argument - * given to the last call to exit and the arg argument from on_exit(). - * - * NOTE 1: This function comes from SunOS 4, but is also present in - * libc4, libc5 and glibc. It no longer occurs in Solaris (SunOS 5). - * Avoid this function, and use the standard atexit() instead. - * - * NOTE 2: CONFIG_SCHED_ONEXIT must be defined to enable this function - * - * Limitations in the current implementation: - * - * 1. Only a single on_exit function can be registered unless - * CONFIG_SCHED_ONEXIT_MAX defines a larger number. - * 2. on_exit functions are not inherited when a new task is - * created. - * - * Input Parameters: - * func - A pointer to the function to be called when the task exits. - * arg - An argument that will be provided to the on_exit() function when - * the task exits. - * - * Returned Value: - * Zero on success. Non-zero on failure. - * - ****************************************************************************/ - -int on_exit(CODE void (*func)(int, FAR void *), FAR void *arg) -{ - FAR struct tcb_s *tcb = this_task(); - FAR struct task_group_s *group = tcb->group; - int index; - int ret = ENOSPC; - - DEBUGASSERT(group); - - /* The following must be atomic */ - - if (func) - { - sched_lock(); - - /* Search for the first available slot. on_exit() functions are - * registered from lower to higher array indices; they must be called - * in the reverse order of registration when task exists, i.e., - * from higher to lower indices. - */ - - for (index = 0; index < CONFIG_SCHED_EXIT_MAX; index++) - { - if (!group->tg_exit[index].func.on) - { - group->tg_exit[index].func.on = func; - group->tg_exit[index].arg = arg; - ret = OK; - break; - } - } - - sched_unlock(); - } - - return ret; -} - -#endif /* CONFIG_SCHED_ONEXIT */ diff --git a/syscall/syscall.csv b/syscall/syscall.csv index 0b903a42c0..88d8c128a1 100644 --- a/syscall/syscall.csv +++ b/syscall/syscall.csv @@ -6,7 +6,6 @@ "aio_read","aio.h","defined(CONFIG_FS_AIO)","int","FAR struct aiocb *" "aio_write","aio.h","defined(CONFIG_FS_AIO)","int","FAR struct aiocb *" "arc4random_buf","stdlib.h","defined(CONFIG_CRYPTO_RANDOM_POOL)","void","FAR void *","size_t" -"atexit","stdlib.h","defined(CONFIG_SCHED_ATEXIT)","int","void (*)(void)" "bind","sys/socket.h","defined(CONFIG_NET)","int","int","FAR const struct sockaddr *","socklen_t" "boardctl","sys/boardctl.h","defined(CONFIG_BOARDCTL)","int","unsigned int","uintptr_t" "chmod","sys/stat.h","","int","FAR const char *","mode_t" @@ -78,7 +77,6 @@ "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 *" "nxsched_get_streams","nuttx/sched.h","defined(CONFIG_FILE_STREAM)","FAR struct streamlist *" -"on_exit","stdlib.h","defined(CONFIG_SCHED_ONEXIT)","int","CODE void (*)(int, FAR void *)","FAR void *" "open","fcntl.h","","int","FAR const char *","int","...","mode_t" "opendir","dirent.h","","FAR DIR *","FAR const char *" "pgalloc", "nuttx/arch.h", "defined(CONFIG_BUILD_KERNEL)", "uintptr_t", "uintptr_t", "unsigned int"