summaryrefslogtreecommitdiff
path: root/src/PowerPC_EABI_Support/Runtime/Src/global_destructor_chain.c
blob: ec01e8f38cc79641cfc1747c89e9e37c9ec9407a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include "NMWException.h"

DestructorChain* __global_destructor_chain;

void* __register_global_object(void* object, void* destructor, void* regmem) {
    ((DestructorChain*)regmem)->next = __global_destructor_chain;
    ((DestructorChain*)regmem)->destructor = destructor;
    ((DestructorChain*)regmem)->object = object;
    __global_destructor_chain = (DestructorChain*)regmem;
    return object;
}

void __destroy_global_chain(void) {
    DestructorChain* iter;
    while ((iter = __global_destructor_chain) != 0) {
        __global_destructor_chain = iter->next;
        DTORCALL(iter->destructor, iter->object);
    }
}

/* clang-format off */
__declspec(section ".dtors")
static void* const __destroy_global_chain_reference = __destroy_global_chain;
/* clang-format on */