Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

assert: use abort() instead of exit() #307

Merged
merged 1 commit into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions include/assert.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ extern "C" {

#ifndef NDEBUG
#define assert(__expr) \
((__expr) \
? (void)0 \
: ({ printf("Assertion '%s' failed in file %s:%d, function %s.\n", #__expr, __FILE__, __LINE__, __func__); exit(1);}))
((__expr) ? (void)0 : ({ printf("Assertion '%s' failed in file %s:%d, function %s.\n", #__expr, __FILE__, __LINE__, __func__); abort(); }))
#else


Expand Down
2 changes: 1 addition & 1 deletion include/stdlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ extern size_t malloc_usable_size(void *ptr);


/* Causes an abnormal program termination. */
extern void abort(void);
extern void abort(void) __attribute__((__noreturn__));


/* Causes the specified function func to be called when the program terminates normally. */
Expand Down
22 changes: 18 additions & 4 deletions stdlib/abort.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,33 @@
*
* abort.c
*
* Copyright 2018 Phoenix Systems
* Author: Kamil Amanowicz
* Copyright 2018,2023 Phoenix Systems
* Author: Kamil Amanowicz, Marek Bialowas
*
* This file is part of Phoenix-RTOS.
*
* %LICENSE%
*/
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>

void abort(void)
{
/* unblock SIGABRT */
sigset_t sigs;
sigemptyset(&sigs);
sigaddset(&sigs, SIGABRT);
sigprocmask(SIG_UNBLOCK, &sigs, NULL);

raise(SIGABRT);

/* should not return even for user-specified signal handler, but retry with default handler */
signal(SIGABRT, SIG_DFL);
raise(SIGABRT);
while(1)
exit(EXIT_FAILURE);

/* should not return, finish program however we can */
for (;;) {
_exit(127);
}
}
Loading