2020-03-21 14:12:26 +01:00
# ifndef __CLOVER_STDLIB_H__
# define __CLOVER_STDLIB_H__
2024-01-10 14:08:21 +01:00
2020-09-07 00:19:48 +02:00
# ifdef __cplusplus
2020-03-21 14:12:26 +01:00
extern " C " {
2020-09-07 00:19:48 +02:00
# endif
2020-03-21 14:12:26 +01:00
# include <Library/MemoryAllocationLib.h>
2023-11-06 23:51:16 +01:00
# include <Library/MemLogLib.h>
2020-09-07 00:19:48 +02:00
# ifdef __cplusplus
2020-03-21 14:12:26 +01:00
}
2020-09-07 00:19:48 +02:00
# endif
2020-03-21 14:12:26 +01:00
# include "stddef.h" // for size_t
2021-05-08 11:34:17 +02:00
# ifdef __cplusplus
extern " C " {
# endif
2020-03-21 14:12:26 +01:00
2024-01-10 14:08:21 +01:00
void abort ( void ) ; // abort() is defined in stdlib.h
# ifndef OPENSSL_SMALL_FOOTPRINT
// can't use these memory function with OpenSslLib
static inline __attribute__ ( ( always_inline ) ) void * malloc ( size_t size )
2020-03-21 14:12:26 +01:00
{
2023-11-06 23:51:16 +01:00
void * ptr = AllocatePool ( size ) ;
// MemLogf(false, 0, "malloc(%zd) %llx\n", size, uintptr_t(ptr));
return ptr ;
2020-03-21 14:12:26 +01:00
}
2024-01-10 14:08:21 +01:00
static inline __attribute__ ( ( always_inline ) ) void * reallocWithOldSize ( void * ptr , size_t newsize , size_t oldsize ) // not the posix realloc. For EFI we need oldsize
2020-03-21 14:12:26 +01:00
{
2023-11-06 23:51:16 +01:00
void * newptr = ReallocatePool ( oldsize , newsize , ptr ) ;
// MemLogf(false, 0, "reallocWithOldSize(%llx %zd %zd) %llx\n", uintptr_t(ptr), newsize, oldsize, uintptr_t(newptr));
return newptr ;
2020-03-21 14:12:26 +01:00
}
2024-01-10 14:08:21 +01:00
static inline __attribute__ ( ( always_inline ) ) void free ( void * ptr )
2020-03-21 14:12:26 +01:00
{
2023-11-06 23:51:16 +01:00
// MemLogf(false, 0, "free(%llx)\n", uintptr_t(ptr));
2021-05-09 16:13:37 +02:00
FreePool ( ptr ) ;
2020-03-21 14:12:26 +01:00
}
2024-01-10 14:08:21 +01:00
# endif
2021-05-09 16:13:37 +02:00
# ifdef __cplusplus
}
# endif
2020-03-21 14:12:26 +01:00
# endif