Handout
This commit is contained in:
45
compiler/libc.cc
Normal file
45
compiler/libc.cc
Normal file
@@ -0,0 +1,45 @@
|
||||
#include "libc.h"
|
||||
|
||||
/*! \brief Function pointer for initialization/finalization functions for global
|
||||
* objects required since GCC 4.7 and later.
|
||||
*
|
||||
* These symbols appear kind of magically due to the compiler
|
||||
*/
|
||||
extern void (*__preinit_array_start[])();
|
||||
extern void (*__preinit_array_end[])();
|
||||
extern void (*__init_array_start[])();
|
||||
extern void (*__init_array_end[])();
|
||||
extern void (*__fini_array_start[])();
|
||||
extern void (*__fini_array_end[])();
|
||||
|
||||
namespace CSU {
|
||||
|
||||
void initializer() {
|
||||
const unsigned int preinit_size = __preinit_array_end - __preinit_array_start;
|
||||
for (unsigned int i = 0; i != preinit_size; ++i) {
|
||||
(*__preinit_array_start[i])();
|
||||
}
|
||||
|
||||
const size_t size = __init_array_end - __init_array_start;
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
(*__init_array_start[i])();
|
||||
}
|
||||
}
|
||||
|
||||
void finalizer() {
|
||||
const unsigned int fini_size = __fini_array_end - __fini_array_start;
|
||||
for (unsigned int i = 0; i != fini_size; ++i) {
|
||||
(*__fini_array_start[i])();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace CSU
|
||||
|
||||
extern "C" int atexit(void (*func)(void)) {
|
||||
// Registers a function that will be executed on exit.
|
||||
// We simply ignore those functions, as we don't need them for our operating
|
||||
// systems.
|
||||
(void)func;
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user