mirror of
https://git.planet-casio.com/Vhex-Kernel-Core/fxlibc.git
synced 2024-12-28 04:23:38 +01:00
dso: dynamically allocate destructor table
This saves static memory on mono targets where it's scarce.
This commit is contained in:
parent
1da9d10226
commit
465655674b
1 changed files with 9 additions and 3 deletions
12
src/dso.c
12
src/dso.c
|
@ -1,4 +1,4 @@
|
|||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/* We don't support shared object loading, so provide a single handle */
|
||||
__attribute__((visibility("hidden")))
|
||||
|
@ -13,12 +13,18 @@ struct dtor {
|
|||
void *d;
|
||||
};
|
||||
|
||||
static struct dtor _dtors[ATEXIT_MAX];
|
||||
static struct dtor *_dtors;
|
||||
static int _dtor_count = 0;
|
||||
|
||||
__attribute__((constructor))
|
||||
static void alloc_dtors(void)
|
||||
{
|
||||
_dtors = malloc(ATEXIT_MAX * sizeof *_dtors);
|
||||
}
|
||||
|
||||
int __cxa_atexit(void (*f)(void *), void *p, void *d)
|
||||
{
|
||||
if(_dtor_count >= ATEXIT_MAX)
|
||||
if(!_dtors || _dtor_count >= ATEXIT_MAX)
|
||||
return 1;
|
||||
_dtors[_dtor_count++] = (struct dtor){ f, p, d };
|
||||
return 0;
|
||||
|
|
Loading…
Reference in a new issue