1/*
2 * Copyright 2019, Data61
3 * Commonwealth Scientific and Industrial Research Organisation (CSIRO)
4 * ABN 41 687 119 230.
5 *
6 * This software may be distributed and modified according to the terms of
7 * the BSD 2-Clause license. Note that NO WARRANTY is provided.
8 * See "LICENSE_BSD2.txt" for details.
9 *
10 * @TAG(DATA61_BSD)
11 */
12/*
13 * Constructor and destructor handling.
14 */
15
16typedef void (*routine)(void);
17
18/*
19 * Constructors
20 */
21void _init(void);
22extern routine __preinit_array_start[];
23extern routine __preinit_array_end[];
24extern routine __init_array_start[];
25extern routine __init_array_end[];
26
27/*
28 * Destructors
29 */
30void _fini(void);
31extern routine __fini_array_start[];
32extern routine __fini_array_end[];
33
34void __sel4runtime_run_constructors(void)
35{
36    int preinit_array_len
37        = &__preinit_array_end[0]
38          - &__preinit_array_start[0];
39    for (int f = 0; f < preinit_array_len; f++) {
40        __preinit_array_start[f]();
41    }
42    _init();
43    int init_array_len
44        = &__init_array_end[0]
45          - &__init_array_start[0];
46    for (int f = 0; f < init_array_len; f++) {
47        __init_array_start[f]();
48    }
49}
50
51void __sel4runtime_run_destructors(void)
52{
53    int fini_array_len
54        = &__fini_array_end[0]
55          - &__fini_array_start[0];
56    for (int f = fini_array_len - 1; f >= 0; f--) {
57        __fini_array_start[f]();
58    }
59    _fini();
60}
61