You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by pk...@apache.org on 2023/01/25 12:31:43 UTC
[nuttx] branch master updated (d7ee492fc4 -> c05cdd6598)
This is an automated email from the ASF dual-hosted git repository.
pkarashchenko pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
from d7ee492fc4 board/arch: Remove FAR decorator
new bcd1ebf260 libc: Implement quick_exit and at_quick_exit
new 5333c30d45 libc: abort should always call exit not pthread_exit
new c05cdd6598 libc: Move on_exit and __cxa_atexit in lib_atexit.c
The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
include/cxx/cstdlib | 2 +
include/nuttx/atexit.h | 6 ++-
include/stdlib.h | 2 +
libs/libc/stdlib/Make.defs | 4 +-
libs/libc/stdlib/lib_abort.c | 15 +------
libs/libc/stdlib/lib_atexit.c | 93 +++++++++++++++++++++++++++++++++++++--
libs/libc/stdlib/lib_cxa_atexit.c | 56 -----------------------
libs/libc/stdlib/lib_exit.c | 83 +++++++++++++++++++++++++++++++++-
libs/libc/stdlib/lib_onexit.c | 68 ----------------------------
9 files changed, 182 insertions(+), 147 deletions(-)
delete mode 100644 libs/libc/stdlib/lib_cxa_atexit.c
delete mode 100644 libs/libc/stdlib/lib_onexit.c
[nuttx] 03/03: libc: Move on_exit and __cxa_atexit in lib_atexit.c
Posted by pk...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
pkarashchenko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit c05cdd6598b1d9c948b7dc6c809acddc44d5331f
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Sat Jan 21 00:11:33 2023 +0800
libc: Move on_exit and __cxa_atexit in lib_atexit.c
Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
libs/libc/stdlib/Make.defs | 4 +--
libs/libc/stdlib/lib_atexit.c | 62 +++++++++++++++++++++++++++++++++++
libs/libc/stdlib/lib_cxa_atexit.c | 56 --------------------------------
libs/libc/stdlib/lib_onexit.c | 68 ---------------------------------------
4 files changed, 63 insertions(+), 127 deletions(-)
diff --git a/libs/libc/stdlib/Make.defs b/libs/libc/stdlib/Make.defs
index b150568112..2484d9e05a 100644
--- a/libs/libc/stdlib/Make.defs
+++ b/libs/libc/stdlib/Make.defs
@@ -27,9 +27,7 @@ CSRCS += lib_rand.c lib_rand48.c lib_qsort.c lib_srand.c lib_strtol.c
CSRCS += lib_strtoll.c lib_strtoul.c lib_strtoull.c lib_strtold.c
CSRCS += lib_checkbase.c lib_mktemp.c lib_mkstemp.c lib_mkdtemp.c
CSRCS += lib_aligned_alloc.c lib_posix_memalign.c lib_valloc.c lib_mblen.c
-CSRCS += lib_mbtowc.c lib_wctomb.c lib_mbstowcs.c lib_wcstombs.c
-CSRCS += lib_atexit.c lib_cxa_atexit.c lib_onexit.c
-
+CSRCS += lib_mbtowc.c lib_wctomb.c lib_mbstowcs.c lib_wcstombs.c lib_atexit.c
ifeq ($(CONFIG_PSEUDOTERM),y)
CSRCS += lib_ptsname.c lib_ptsnamer.c lib_unlockpt.c lib_openpty.c
diff --git a/libs/libc/stdlib/lib_atexit.c b/libs/libc/stdlib/lib_atexit.c
index eab0894667..b2cfceaed2 100644
--- a/libs/libc/stdlib/lib_atexit.c
+++ b/libs/libc/stdlib/lib_atexit.c
@@ -206,3 +206,65 @@ int at_quick_exit(CODE void (*func)(void))
{
return atexit_register(ATTYPE_ATQUICKEXIT, func, NULL, NULL);
}
+
+/****************************************************************************
+ * 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.
+ *
+ * Limitations in the current implementation:
+ *
+ * 1. Only a single on_exit function can be registered unless
+ * CONFIG_LIBC_MAX_EXITFUNS 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)
+{
+ return atexit_register(ATTYPE_ONEXIT, (CODE void (*)(void))func, arg,
+ NULL);
+}
+
+/****************************************************************************
+ * 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(CODE void (*func)(FAR void *), FAR void *arg,
+ FAR void *dso_handle)
+{
+ return atexit_register(ATTYPE_CXA, (CODE void (*)(void))func, arg,
+ dso_handle);
+}
diff --git a/libs/libc/stdlib/lib_cxa_atexit.c b/libs/libc/stdlib/lib_cxa_atexit.c
deleted file mode 100644
index 3e68eedfb5..0000000000
--- a/libs/libc/stdlib/lib_cxa_atexit.c
+++ /dev/null
@@ -1,56 +0,0 @@
-/****************************************************************************
- * libs/libc/stdlib/lib_cxa_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 <nuttx/config.h>
-
-#include <nuttx/atexit.h>
-
-/****************************************************************************
- * 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(CODE void (*func)(FAR void *), FAR void *arg,
- FAR void *dso_handle)
-{
- return atexit_register(ATTYPE_CXA, (CODE void (*)(void))func, arg,
- dso_handle);
-}
diff --git a/libs/libc/stdlib/lib_onexit.c b/libs/libc/stdlib/lib_onexit.c
deleted file mode 100644
index f3a34d9827..0000000000
--- a/libs/libc/stdlib/lib_onexit.c
+++ /dev/null
@@ -1,68 +0,0 @@
-/****************************************************************************
- * libs/libc/stdlib/lib_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 <nuttx/config.h>
-
-#include <nuttx/atexit.h>
-
-/****************************************************************************
- * 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.
- *
- * Limitations in the current implementation:
- *
- * 1. Only a single on_exit function can be registered unless
- * CONFIG_LIBC_MAX_EXITFUNS 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)
-{
- return atexit_register(ATTYPE_ONEXIT, (CODE void (*)(void))func, arg,
- NULL);
-}
[nuttx] 01/03: libc: Implement quick_exit and at_quick_exit
Posted by pk...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
pkarashchenko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit bcd1ebf26056fb1ebbd0abfdd081c1568f299d32
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Sat Jan 21 00:23:16 2023 +0800
libc: Implement quick_exit and at_quick_exit
Defined by c11:
https://en.cppreference.com/w/c/program/quick_exit
https://en.cppreference.com/w/c/program/at_quick_exit
Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
include/cxx/cstdlib | 2 ++
include/nuttx/atexit.h | 6 ++--
include/stdlib.h | 2 ++
libs/libc/stdlib/lib_atexit.c | 31 ++++++++++++++--
libs/libc/stdlib/lib_exit.c | 83 ++++++++++++++++++++++++++++++++++++++++++-
5 files changed, 118 insertions(+), 6 deletions(-)
diff --git a/include/cxx/cstdlib b/include/cxx/cstdlib
index 51bc3d8d26..34483cdf9c 100644
--- a/include/cxx/cstdlib
+++ b/include/cxx/cstdlib
@@ -51,8 +51,10 @@ namespace std
// Process exit functions
using ::exit;
+ using ::quick_exit;
using ::abort;
using ::atexit;
+ using ::at_quick_exit;
using ::on_exit;
#ifndef __KERNEL__
diff --git a/include/nuttx/atexit.h b/include/nuttx/atexit.h
index ad511290b5..84a0167f3a 100644
--- a/include/nuttx/atexit.h
+++ b/include/nuttx/atexit.h
@@ -26,6 +26,7 @@
****************************************************************************/
#include <nuttx/config.h>
+#include <stdbool.h>
#include <stdlib.h>
/****************************************************************************
@@ -44,6 +45,7 @@ enum atexit_type_e
{
ATTYPE_NONE,
ATTYPE_ATEXIT,
+ ATTYPE_ATQUICKEXIT,
ATTYPE_ONEXIT,
ATTYPE_CXA
};
@@ -106,10 +108,10 @@ int atexit_register(int type, CODE void (*func)(void), FAR void *arg,
*
****************************************************************************/
-void atexit_call_exitfuncs(int status);
+void atexit_call_exitfuncs(int status, bool quick);
#else
# define atexit_register(type, func, arg, dso) (0)
-# define atexit_call_exitfuncs(status)
+# define atexit_call_exitfuncs(status, quick)
#endif /* CONFIG_LIBC_MAX_EXITFUNS */
#if defined(__cplusplus)
diff --git a/include/stdlib.h b/include/stdlib.h
index a522680a65..5e90eb5d08 100644
--- a/include/stdlib.h
+++ b/include/stdlib.h
@@ -166,8 +166,10 @@ int unsetenv(FAR const char *name);
/* Process exit functions */
void exit(int status) noreturn_function;
+void quick_exit(int status) noreturn_function;
void abort(void) noreturn_function;
int atexit(CODE void (*func)(void));
+int at_quick_exit(CODE void (*func)(void));
int on_exit(CODE void (*func)(int, FAR void *), FAR void *arg);
/* _Exit() is a stdlib.h equivalent to the unistd.h _exit() function */
diff --git a/libs/libc/stdlib/lib_atexit.c b/libs/libc/stdlib/lib_atexit.c
index 0486cdf63b..eab0894667 100644
--- a/libs/libc/stdlib/lib_atexit.c
+++ b/libs/libc/stdlib/lib_atexit.c
@@ -50,7 +50,7 @@
*
****************************************************************************/
-static FAR struct atexit_list_s * get_exitfuncs(void)
+static FAR struct atexit_list_s *get_exitfuncs(void)
{
FAR struct task_info_s *info;
@@ -105,7 +105,7 @@ int atexit_register(int type, CODE void (*func)(void), FAR void *arg,
return ret;
}
-void atexit_call_exitfuncs(int status)
+void atexit_call_exitfuncs(int status, bool quick)
{
FAR struct atexit_list_s *aehead;
CODE void (*func)(void);
@@ -134,9 +134,14 @@ void atexit_call_exitfuncs(int status)
continue;
}
+ if (quick != (type == ATTYPE_ATQUICKEXIT))
+ {
+ continue;
+ }
+
/* Call the atexit/on_exit/cxa_atexit() function */
- if (type == ATTYPE_ATEXIT)
+ if (type == ATTYPE_ATEXIT || type == ATTYPE_ATQUICKEXIT)
{
(*func)();
}
@@ -181,3 +186,23 @@ int atexit(CODE void (*func)(void))
{
return atexit_register(ATTYPE_ATEXIT, func, NULL, NULL);
}
+
+/****************************************************************************
+ * Name: at_quick_exit
+ *
+ * Description:
+ * Registers the function pointed to by func to be called on quick
+ * program termination (via quick_exit).
+ *
+ * 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 at_quick_exit(CODE void (*func)(void))
+{
+ return atexit_register(ATTYPE_ATQUICKEXIT, func, NULL, NULL);
+}
diff --git a/libs/libc/stdlib/lib_exit.c b/libs/libc/stdlib/lib_exit.c
index c2e81206c5..2cef9eff1b 100644
--- a/libs/libc/stdlib/lib_exit.c
+++ b/libs/libc/stdlib/lib_exit.c
@@ -46,11 +46,47 @@ FAR void *__dso_handle = &__dso_handle;
* Public Functions
****************************************************************************/
+/****************************************************************************
+ * Name: exit
+ *
+ * Description:
+ * The exit() function causes normal process termination and the
+ * least significant byte of status (i.e., status & 0xFF) is
+ * returned to the parent (see wait(2)).
+ *
+ * All functions registered with atexit(3) and on_exit(3) are
+ * called, in the reverse order of their registration. (It is
+ * possible for one of these functions to use atexit(3) or
+ * on_exit(3) to register an additional function to be executed
+ * during exit processing; the new registration is added to the
+ * front of the list of functions that remain to be called.) If one
+ * of these functions does not return (e.g., it calls _exit(2), or
+ * kills itself with a signal), then none of the remaining functions
+ * is called, and further exit processing (in particular, flushing
+ * of stdio(3) streams) is abandoned. If a function has been
+ * registered multiple times using atexit(3) or on_exit(3), then it
+ * is called as many times as it was registered.
+ *
+ * All open stdio(3) streams are flushed and closed. Files created
+ * by tmpfile(3) are removed.
+ *
+ * The C standard specifies two constants, EXIT_SUCCESS and
+ * EXIT_FAILURE, that may be passed to exit() to indicate successful
+ * or unsuccessful termination, respectively.
+ *
+ * Input Parameters:
+ * status - Exit status code
+ *
+ * Returned Value:
+ * Does not return.
+ *
+ ****************************************************************************/
+
void exit(int status)
{
/* Run the registered exit functions */
- atexit_call_exitfuncs(status);
+ atexit_call_exitfuncs(status, false);
/* Flush all streams */
@@ -61,6 +97,51 @@ void exit(int status)
_exit(status);
}
+/****************************************************************************
+ * Name: quick_exit
+ *
+ * Description:
+ * The quick_exit() function exits the program quickly calling any cleanup
+ * functions registered with at_quick_exit(3) but not any C++ destructors
+ * or cleanup code registered with atexit(3). The stdio(3) file buffers
+ * are not flushed.
+ *
+ * Input Parameters:
+ * status - Exit status code
+ *
+ * Returned Value:
+ * Does not return.
+ *
+ ****************************************************************************/
+
+void quick_exit(int status)
+{
+ /* Run the registered exit functions */
+
+ atexit_call_exitfuncs(status, true);
+
+ /* Then perform the exit */
+
+ _exit(status);
+}
+
+/****************************************************************************
+ * Name: _Exit
+ *
+ * Description:
+ * The _Exit() functions shall not call functions registered with atexit()
+ * nor any registered signal handlers. Open streams shall not be flushed.
+ * Whether open streams are closed (without flushing) is implementation
+ * defined.
+ *
+ * Input Parameters:
+ * status - Exit status code
+ *
+ * Returned Value:
+ * Does not return.
+ *
+ ****************************************************************************/
+
void _Exit(int status)
{
_exit(status);
[nuttx] 02/03: libc: abort should always call exit not pthread_exit
Posted by pk...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
pkarashchenko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 5333c30d45b3ca60247e382d020f21575a055bd8
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Fri Jan 20 23:41:01 2023 +0800
libc: abort should always call exit not pthread_exit
since pthread_exit just exit the calling thread not the whole process
Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
libs/libc/stdlib/lib_abort.c | 15 +--------------
1 file changed, 1 insertion(+), 14 deletions(-)
diff --git a/libs/libc/stdlib/lib_abort.c b/libs/libc/stdlib/lib_abort.c
index 903e3f6223..663e224274 100644
--- a/libs/libc/stdlib/lib_abort.c
+++ b/libs/libc/stdlib/lib_abort.c
@@ -63,21 +63,8 @@ void abort(void)
* a conformant version of abort() at this time. This version does not
* signal the calling thread all.
*
- * Note that pthread_exit() is called instead of exit(). That is because
- * we do no know if abort was called from a pthread or a normal thread
- * (we could find out, of course). If abort() is called from a
- * non-pthread, then pthread_exit() should fail and fall back to call
- * exit() anyway.
- *
- * If exit() is called (either below or via pthread_exit()), then exit()
- * will flush and close all open files and terminate the thread. If this
- * function was called from a pthread, then pthread_exit() will complete
- * any joins, but will not flush or close any streams.
+ * exit() will flush and close all open files and terminate the thread.
*/
-#ifdef CONFIG_DISABLE_PTHREAD
exit(EXIT_FAILURE);
-#else
- pthread_exit(NULL);
-#endif
}