From 6fc11482063abc03f51f4834d35af099847d5cc3 Mon Sep 17 00:00:00 2001 From: Tarry Singh Date: Mon, 10 Mar 2025 16:25:45 +0000 Subject: [PATCH] async/coro: make coroutines unwindable by zeroing the initial stack region, preventing random unwinding behavior and SIGSEGV during _Unwind_Backtrace. --- async/coro_base.zig | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/async/coro_base.zig b/async/coro_base.zig index 7f77750..9cd6f1c 100644 --- a/async/coro_base.zig +++ b/async/coro_base.zig @@ -60,6 +60,13 @@ pub const Coro = packed struct { return Error.StackTooSmall; } const register_space = stack[stack.len - register_bytes ..]; + + // Zero out the register space so that the initial stack swap + // of new coroutines doesn't poison ebp. + // + // A better solution would be to prepare the initial stack so that the + // stack is valid up to the caller. + @memset(register_space, 0); const jump_ptr: *Func = @ptrCast(@alignCast(®ister_space[arch_info.jump_idx * 8])); jump_ptr.* = func; return .{ .stack_pointer = register_space.ptr };