properly call global destructors

This commit is contained in:
Wolfgang Thaller 2015-08-29 20:11:53 +02:00
parent b3dcb7f981
commit 836a8acb7b
3 changed files with 15 additions and 0 deletions

View File

@ -48,6 +48,7 @@
void Retro68Relocate();
void Retro68CallConstructors();
void Retro68CallDestructors();
void Retro68FreeGlobals();
#define RETRO68_RELOCATE() RETRO68_CALL_UNRELOCATED(Retro68Relocate,())

View File

@ -223,6 +223,19 @@ void Retro68CallConstructors()
}
}
void Retro68CallDestructors()
{
char *p = (char*)&__fini_section;
char *e = (char*)&__fini_section_end;
p += 2;
while( p < e )
{
(*(voidFunction)(*(long*)p))();
p += 6;
}
}
void Retro68FreeGlobals()
{
if(relocState.bssPtr != (Ptr) -1)

View File

@ -33,6 +33,7 @@ int main(int argc, char* argv[]);
void _start()
{
RETRO68_RELOCATE();
atexit(&Retro68CallDestructors);
Retro68CallConstructors();
int result;