mirror of
https://github.com/ARM-software/arm-trusted-firmware.git
synced 2025-04-18 02:24:18 +00:00
Add atexit function to libc
We had exit but we didn't have atexit, and we were calling panic and tf_printf from exit, which generated a dependency from exit to them. Having atexit allows to set a different function pointer in every image. Change-Id: I95b9556d680d96249ed3b14da159b6f417da7661 Signed-off-by: Roberto Vargas <roberto.vargas@arm.com>
This commit is contained in:
parent
ea7a57a3a5
commit
6c37334567
3 changed files with 27 additions and 4 deletions
|
@ -17,6 +17,7 @@
|
||||||
#include <platform_def.h>
|
#include <platform_def.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* This function is responsible to:
|
* This function is responsible to:
|
||||||
* Load SCP_BL2U if platform has defined SCP_BL2U_BASE
|
* Load SCP_BL2U if platform has defined SCP_BL2U_BASE
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <debug.h>
|
#include <debug.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
/* mbed TLS headers */
|
/* mbed TLS headers */
|
||||||
#include <mbedtls/memory_buffer_alloc.h>
|
#include <mbedtls/memory_buffer_alloc.h>
|
||||||
|
@ -23,6 +24,12 @@
|
||||||
#endif
|
#endif
|
||||||
static unsigned char heap[MBEDTLS_HEAP_SIZE];
|
static unsigned char heap[MBEDTLS_HEAP_SIZE];
|
||||||
|
|
||||||
|
static void cleanup(void)
|
||||||
|
{
|
||||||
|
ERROR("EXIT from BL2\n");
|
||||||
|
panic();
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* mbed TLS initialization function
|
* mbed TLS initialization function
|
||||||
*/
|
*/
|
||||||
|
@ -31,6 +38,9 @@ void mbedtls_init(void)
|
||||||
static int ready;
|
static int ready;
|
||||||
|
|
||||||
if (!ready) {
|
if (!ready) {
|
||||||
|
if (atexit(cleanup))
|
||||||
|
panic();
|
||||||
|
|
||||||
/* Initialize the mbed TLS heap */
|
/* Initialize the mbed TLS heap */
|
||||||
mbedtls_memory_buffer_alloc_init(heap, MBEDTLS_HEAP_SIZE);
|
mbedtls_memory_buffer_alloc_init(heap, MBEDTLS_HEAP_SIZE);
|
||||||
|
|
||||||
|
|
|
@ -4,11 +4,23 @@
|
||||||
* SPDX-License-Identifier: BSD-3-Clause
|
* SPDX-License-Identifier: BSD-3-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <debug.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
void exit(int v)
|
static void (*exitfun)(void);
|
||||||
|
|
||||||
|
void exit(int status)
|
||||||
{
|
{
|
||||||
ERROR("EXIT\n");
|
if (exitfun)
|
||||||
panic();
|
(*exitfun)();
|
||||||
|
for (;;)
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
int atexit(void (*fun)(void))
|
||||||
|
{
|
||||||
|
if (exitfun)
|
||||||
|
return -1;
|
||||||
|
exitfun = fun;
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue