sched/assert: Call abort() instead of exit() in assert

POSIX dictates that assert() terminates via abort(), even though in NuttX
abort() just calls exit(EXIT_FAILURE) it is better to use the correct
API here, if at some point a proper implementation for abort() is made.

Also, as the kernel must not use abort() which is a userspace API, direct
the exit to PANIC() if for some reason _assert() returns (it should not
but trap it here just in case).
This commit is contained in:
Ville Juven 2023-02-17 12:00:29 +02:00 committed by Xiang Xiao
parent df1d7dd480
commit e9ef70e24b
1 changed files with 11 additions and 1 deletions

View File

@ -27,6 +27,16 @@
#include <assert.h>
#include <stdlib.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* If assert() is called from kernel, must not call user API abort */
#ifdef __KERNEL__
# define abort PANIC
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
@ -34,5 +44,5 @@
void __assert(FAR const char *filename, int linenum, FAR const char *msg)
{
_assert(filename, linenum, msg);
exit(EXIT_FAILURE);
abort();
}