lib_abort.c: Change tall to user-space exit() into system call _exit()#8606
Conversation
|
./libs/libc/assert/lib_assert.c:47: abort(); I think the first 3 are fine, the rest I'm not sure what to do. I think the purpose is to do abnormal termination so _exit(EXIT_FAILURE) should be enough ? Any comments from @tmedicci and co. from Espressif ? |
Hi @pussuw ! Yes, I'd say that just calling @acassis , @gustavonihei and @lucasssvaz , could you please take a look too? |
|
@pussuw It is fine to just change all those |
Except the one from |
|
Thank you for going through the list, I'll create a patch momentarily. I assume changing abort() to PANIC() essentially achieves the same thing here ? abort() in this case crashes the system as only the idle task (if even that?) is running ? |
In the Kernel case nuttx/libs/libc/assert/lib_assert.c Lines 34 to 38 in 1d41182 I am afraid it will end up in a recursion, but that would be a different issue. |
This is a recent addition by me and the visibility of this re-definition is only for lib_assert.c, this is not visible anywhere else. The reason was to prevent calling abort() from assert. This is why I was trying to understand your use-case. abort() in this case just kills the task/process that was running. Changing that to PANIC will crash the whole system. I'm trying to understand the use-case, so I don't create a fatal regression for you. |
ESP32 wireless drivers call abort with the intent of crashing the system, it is a heritage from IDF. |
The POSIX standard dictates that during abnormal termination the functions registered by atexit() are _not_ called, also flushing the streams is optional. So in this case, it is perfectly legal / better to call the kernel system call _exit() instead. This fixes regression issues caused by removal exit() from the kernel.
4c82674 to
9d959d4
Compare
This should now be irrelevant, as abort() is forwarded to _exit() instead.
|
I ended up removing the call to the user-space exit() and now abort() calls _exit() instead. I think this is more correct behavior (closer to what abort() is supposed to do). This should fix the regression sufficiently. |
|
Let's ignore the ci broken which is fixed by #8611 and merge this simple change. |
Summary
The POSIX standard dictates that during abnormal termination the functions
registered by atexit() are not called, also flushing the streams is
optional. So in this case, it is perfectly legal / better to call the
kernel system call _exit() instead.
GCC stdlib also dictates that a call to abort will not call the atexit() on_exit() registered functions.
This fixes regression issues caused by removal exit() from the kernel.
https://pubs.opengroup.org/onlinepubs/9699919799/functions/abort.html
https://en.cppreference.com/w/c/program/abort
Impact
Fix regression for calls to abort()
Testing
CI and icicle:knsh