LibC: Make stdio and malloc initialization constructors
This commit is contained in:
parent
5539d5eed0
commit
3721dadd72
|
@ -50,19 +50,27 @@ struct malloc_pool_t
|
|||
bool contains(malloc_node_t* node) { return start <= (uint8_t*)node && (uint8_t*)node < end(); }
|
||||
};
|
||||
|
||||
static malloc_pool_t s_malloc_pools[s_malloc_pool_count];
|
||||
|
||||
void _init_malloc()
|
||||
struct malloc_info_t
|
||||
{
|
||||
size_t pool_size = s_malloc_pool_size_initial;
|
||||
for (size_t i = 0; i < s_malloc_pool_count; i++)
|
||||
consteval malloc_info_t()
|
||||
{
|
||||
s_malloc_pools[i].start = nullptr;
|
||||
s_malloc_pools[i].size = pool_size;
|
||||
s_malloc_pools[i].free_list = nullptr;;
|
||||
pool_size *= s_malloc_pool_size_multiplier;
|
||||
size_t pool_size = s_malloc_pool_size_initial;
|
||||
for (auto& pool : pools)
|
||||
{
|
||||
pool = {
|
||||
.start = nullptr,
|
||||
.size = pool_size,
|
||||
.free_list = nullptr,
|
||||
};
|
||||
pool_size *= s_malloc_pool_size_multiplier;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
malloc_pool_t pools[s_malloc_pool_count];
|
||||
};
|
||||
|
||||
static malloc_info_t s_malloc_info;
|
||||
static auto& s_malloc_pools = s_malloc_info.pools;
|
||||
|
||||
static bool allocate_pool(size_t pool_index)
|
||||
{
|
||||
|
|
|
@ -94,7 +94,8 @@ static int drop_read_buffer(FILE* file)
|
|||
return 0;
|
||||
}
|
||||
|
||||
void _init_stdio()
|
||||
__attribute__((constructor))
|
||||
static void _init_stdio()
|
||||
{
|
||||
for (size_t i = 0; i < FOPEN_MAX; i++)
|
||||
{
|
||||
|
|
|
@ -19,8 +19,6 @@
|
|||
char** __environ;
|
||||
extern char** environ __attribute__((weak, alias("__environ")));
|
||||
|
||||
extern void _init_malloc();
|
||||
extern void _init_stdio();
|
||||
extern "C" void _init_libc(char** _environ)
|
||||
{
|
||||
static bool is_initialized = false;
|
||||
|
@ -28,9 +26,6 @@ extern "C" void _init_libc(char** _environ)
|
|||
return;
|
||||
is_initialized = true;
|
||||
|
||||
_init_malloc();
|
||||
_init_stdio();
|
||||
|
||||
if (!_environ)
|
||||
return;
|
||||
|
||||
|
|
Loading…
Reference in New Issue