From 7ca16c45a2ecfbf415fffd384eb5efd32180c5da Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Sat, 5 Oct 2024 21:50:49 -0600 Subject: fixes, valgrind --- libcr/coroutine.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'libcr') diff --git a/libcr/coroutine.c b/libcr/coroutine.c index df9cad3..176590a 100644 --- a/libcr/coroutine.c +++ b/libcr/coroutine.c @@ -32,6 +32,13 @@ #ifndef CONFIG_COROUTINE_DEBUG # error config.h must define CONFIG_COROUTINE_DEBUG #endif +#ifndef CONFIG_COROUTINE_VALGRIND +# error config.h must define CONFIG_COROUTINE_VALGRIND +#endif + +#if CONFIG_COROUTINE_VALGRIND +# include +#endif /* Implementation *************************************************************/ @@ -271,6 +278,9 @@ struct coroutine { #endif size_t stack_size; void *stack; +#if CONFIG_COROUTINE_VALGRIND + unsigned stack_id; +#endif }; /* constants ******************************************************************/ @@ -433,6 +443,11 @@ cid_t coroutine_add_with_stack_size(size_t stack_size, cr_fn_t fn, void *args) { ((uint8_t *)coroutine_table[child-1].stack)[i] = stack_pattern[i%sizeof(stack_pattern)]; #endif +#if CONFIG_COROUTINE_VALGRIND + coroutine_table[child-1].stack_id = VALGRIND_STACK_REGISTER( + coroutine_table[child-1].stack + STACK_GUARD_SIZE, + coroutine_table[child-1].stack + stack_size - STACK_GUARD_SIZE); +#endif coroutine_running = child; coroutine_table[child-1].state = CR_INITIALIZING; @@ -488,6 +503,9 @@ void coroutine_main(void) { /* This is where we jump to from cr_exit(), and from * nowhere else. */ assert_cid_state(coroutine_running, state == CR_NONE); +#if CONFIG_COROUTINE_VALGRIND + VALGRIND_STACK_DEREGISTER(coroutine_table[coroutine_running-1].stack_id); +#endif free(coroutine_table[coroutine_running-1].stack); coroutine_table[coroutine_running-1] = (struct coroutine){0}; } -- cgit v1.2.3-2-g168b