diff options
author | b'Nigel Croxon <allura@localhost> | 2023-05-16 13:06:32 +0000 |
---|---|---|
committer | b'Nigel Croxon <allura@localhost> | 2023-05-16 13:06:32 +0000 |
commit | 9835e11ebe95ed8372ac2a6671de07cc970cdee0 (patch) | |
tree | f2f1d166ba12123605c3dc3e12790e9391d2a31c /lib/entry.c | |
parent | bbc2b528e08e5b99e08e103302ee90046135a039 (diff) | |
parent | 99730f29b2f8874bc7bfad383ea8eb52679e8897 (diff) | |
download | gnu-efi-master.tar.gz |
https://sourceforge.net/p/gnu-efi/code/merge-requests/51/
Diffstat (limited to 'lib/entry.c')
-rw-r--r-- | lib/entry.c | 42 |
1 files changed, 24 insertions, 18 deletions
diff --git a/lib/entry.c b/lib/entry.c index d852608..3baa91d 100644 --- a/lib/entry.c +++ b/lib/entry.c @@ -7,45 +7,51 @@ #include <efi.h> #include <efilib.h> +typedef void (*funcp)(void); + /* * Note that these aren't the using the GNU "CONSTRUCTOR" output section * command, so they don't start with a size. Because of p2align and the * end/END definitions, and the fact that they're mergeable, they can also * have NULLs which aren't guaranteed to be at the end. */ -extern UINTN _init_array, _init_array_end; -extern UINTN __CTOR_LIST__, __CTOR_END__; -extern UINTN _fini_array, _fini_array_end; -extern UINTN __DTOR_LIST__, __DTOR_END__; - -typedef void (*funcp)(void); +extern funcp __init_array_start[], __init_array_end[]; +extern funcp __CTOR_LIST__[], __CTOR_END__[]; +extern funcp __fini_array_start[], __fini_array_end[]; +extern funcp __DTOR_LIST__[], __DTOR_END__[]; static void ctors(void) { - for (funcp *location = (void *)&_init_array; location < (funcp *)&_init_array_end; location++) { - funcp func = *location; - if (location != NULL) + size_t __init_array_length = __init_array_end - __init_array_start; + for (size_t i = 0; i < __init_array_length; i++) { + funcp func = __init_array_start[i]; + if (func != NULL) func(); } - for (funcp *location = (void *)&__CTOR_LIST__; location < (funcp *)&__CTOR_END__; location++) { - funcp func = *location; - if (location != NULL) + size_t __CTOR_length = __CTOR_END__ - __CTOR_LIST__; + for (size_t i = 0; i < __CTOR_length; i++) { + size_t current = __CTOR_length - i - 1; + funcp func = __CTOR_LIST__[current]; + if (func != NULL) func(); } } static void dtors(void) { - for (funcp *location = (void *)&__DTOR_LIST__; location < (funcp *)&__DTOR_END__; location++) { - funcp func = *location; - if (location != NULL) + size_t __DTOR_length = __DTOR_END__ - __DTOR_LIST__; + for (size_t i = 0; i < __DTOR_length; i++) { + funcp func = __DTOR_LIST__[i]; + if (func != NULL) func(); } - for (funcp *location = (void *)&_fini_array; location < (funcp *)&_fini_array_end; location++) { - funcp func = *location; - if (location != NULL) + size_t __fini_array_length = __fini_array_end - __fini_array_start; + for (size_t i = 0; i < __fini_array_length; i++) { + size_t current = __fini_array_length - i - 1; + funcp func = __fini_array_start[current]; + if (func != NULL) func(); } } |