Use lock-less printf() in assert macro
This allows to use assertions in interrupt context (which we do in
some places currently). Before this patch, a CPU could dead lock
itself by:
1. acquiring the printf lock in the normal execution context;
2. taking an interrupt while still holding the lock;
3. inside the interrupt handler, executing an assertion check that
fails and thus tries to print an error message on the UART.
In a situation where several CPUs might be executing assert() at the
same time, we will now get interleaved messages but that should be
pretty rare.
Change-Id: I6d1603300f6a3ea5756a46338cb950b7ca3e7956
Signed-off-by: Sandrine Bailleux <sandrine.bailleux@arm.com>
diff --git a/lib/stdlib/assert.c b/lib/stdlib/assert.c
index 39f30d1..4b53d1e 100644
--- a/lib/stdlib/assert.c
+++ b/lib/stdlib/assert.c
@@ -4,7 +4,7 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
-#include <debug.h>
+#include <stdio.h>
/*
* This is a basic implementation. This could be improved.
@@ -12,6 +12,8 @@
void __assert (const char *function, const char *file, unsigned int line,
const char *assertion)
{
- mp_printf("ASSERT: %s <%d> : %s\n", function, line, assertion);
- while (1);
+ printf("ASSERT: %s <%d> : %s\n", function, line, assertion);
+
+ while (1)
+ ;
}