From af7960b264def8f2553735ea2e619c2fbc412f52 Mon Sep 17 00:00:00 2001 From: Alessandre Laguierce Date: Fri, 4 Apr 2025 17:42:31 +0200 Subject: [PATCH] feat: create a pool of threads when setuping main thread --- src/thread/thread.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/thread/thread.c b/src/thread/thread.c index a55f2c4..f7038ca 100644 --- a/src/thread/thread.c +++ b/src/thread/thread.c @@ -343,6 +343,24 @@ void __attribute__((constructor)) setup_main_thread() { TRACE("premain"); // Create an entry for the main thread. + + struct context_entry_t *new_entry; + for (int i = 0; i < 1000; ++i) { + + new_entry = malloc(sizeof(*new_entry)); + memset(new_entry->stack, 0, STACK_SIZE); + + new_entry->context.uc_stack.ss_sp = new_entry->stack; + new_entry->context.uc_stack.ss_size = STACK_SIZE; + new_entry->context.uc_stack.ss_flags = 0; + + // Tell Valgrind that the memory area of the future stack is a stack + new_entry->valgrind_id = VALGRIND_STACK_REGISTER( + new_entry->context.uc_stack.ss_sp, + new_entry->context.uc_stack.ss_sp + new_entry->context.uc_stack.ss_size); + TAILQ_INSERT_TAIL(&context_to_freed, new_entry, link); + } + struct context_entry_t* main = malloc(sizeof(*main)); // memset(main, 0, sizeof(*main)); getcontext(&main->context);