[PATCH 9/9] bthread: fix use of ASAN fiber stack switch API
Ahmad Fatoum
a.fatoum at pengutronix.de
Mon Nov 25 07:35:23 PST 2024
We misused the fiber API so far and ASAN complained about it.
Fix this.
Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
common/bthread.c | 23 ++++++++++-------------
1 file changed, 10 insertions(+), 13 deletions(-)
diff --git a/common/bthread.c b/common/bthread.c
index 943f4c22b346..d8f1350f2e36 100644
--- a/common/bthread.c
+++ b/common/bthread.c
@@ -23,9 +23,6 @@ static struct bthread {
void *stack;
u32 stack_size;
struct list_head list;
-#ifdef CONFIG_ARCH_HAS_ASAN_FIBER_API
- void *fake_stack_save;
-#endif
u8 awake :1;
u8 should_stop :1;
u8 should_clean :1;
@@ -41,21 +38,21 @@ struct bthread *current = &main_thread;
/*
* When using ASAN, it needs to be told when we switch stacks.
*/
-static void bthread_finish_switch_fiber(struct bthread *bthread)
+static void bthread_finish_switch_fiber(void *stack_save)
{
- finish_switch_fiber(bthread->fake_stack_save,
+ finish_switch_fiber(stack_save,
&main_thread.stack, &main_thread.stack_size);
}
-static void bthread_start_switch_fiber(struct bthread *to, bool terminate_old)
+static void bthread_start_switch_fiber(void **stack_save)
{
- start_switch_fiber(terminate_old ? &to->fake_stack_save : NULL,
- to->stack, to->stack_size);
+ start_switch_fiber(stack_save,
+ current->stack, current->stack_size);
}
static void __noreturn bthread_trampoline(void)
{
- bthread_finish_switch_fiber(current);
+ bthread_finish_switch_fiber(NULL);
bthread_reschedule();
@@ -65,7 +62,7 @@ static void __noreturn bthread_trampoline(void)
current->has_stopped = true;
current = &main_thread;
- bthread_start_switch_fiber(current, true);
+ bthread_start_switch_fiber(NULL);
longjmp(current->jmp_buf, 1);
}
@@ -202,15 +199,15 @@ void bthread_reschedule(void)
void bthread_schedule(struct bthread *to)
{
struct bthread *from = current;
+ void *stack_save = NULL;
int ret;
- bthread_start_switch_fiber(to, false);
-
ret = setjmp(from->jmp_buf);
if (ret == 0) {
current = to;
+ bthread_start_switch_fiber(&stack_save);
longjmp(to->jmp_buf, 1);
}
- bthread_finish_switch_fiber(from);
+ bthread_finish_switch_fiber(stack_save);
}
--
2.39.5
More information about the barebox
mailing list