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(); }
|
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];
|
struct malloc_info_t
|
||||||
|
|
||||||
void _init_malloc()
|
|
||||||
{
|
{
|
||||||
size_t pool_size = s_malloc_pool_size_initial;
|
consteval malloc_info_t()
|
||||||
for (size_t i = 0; i < s_malloc_pool_count; i++)
|
|
||||||
{
|
{
|
||||||
s_malloc_pools[i].start = nullptr;
|
size_t pool_size = s_malloc_pool_size_initial;
|
||||||
s_malloc_pools[i].size = pool_size;
|
for (auto& pool : pools)
|
||||||
s_malloc_pools[i].free_list = nullptr;;
|
{
|
||||||
pool_size *= s_malloc_pool_size_multiplier;
|
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)
|
static bool allocate_pool(size_t pool_index)
|
||||||
{
|
{
|
||||||
|
|
|
@ -94,7 +94,8 @@ static int drop_read_buffer(FILE* file)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void _init_stdio()
|
__attribute__((constructor))
|
||||||
|
static void _init_stdio()
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < FOPEN_MAX; i++)
|
for (size_t i = 0; i < FOPEN_MAX; i++)
|
||||||
{
|
{
|
||||||
|
|
|
@ -19,8 +19,6 @@
|
||||||
char** __environ;
|
char** __environ;
|
||||||
extern char** environ __attribute__((weak, alias("__environ")));
|
extern char** environ __attribute__((weak, alias("__environ")));
|
||||||
|
|
||||||
extern void _init_malloc();
|
|
||||||
extern void _init_stdio();
|
|
||||||
extern "C" void _init_libc(char** _environ)
|
extern "C" void _init_libc(char** _environ)
|
||||||
{
|
{
|
||||||
static bool is_initialized = false;
|
static bool is_initialized = false;
|
||||||
|
@ -28,9 +26,6 @@ extern "C" void _init_libc(char** _environ)
|
||||||
return;
|
return;
|
||||||
is_initialized = true;
|
is_initialized = true;
|
||||||
|
|
||||||
_init_malloc();
|
|
||||||
_init_stdio();
|
|
||||||
|
|
||||||
if (!_environ)
|
if (!_environ)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue