Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions include/boost/capy/task.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,21 @@ struct [[nodiscard]] BOOST_CAPY_CORO_AWAIT_ELIDABLE
template<class Promise>
auto await_suspend(std::coroutine_handle<Promise> h) noexcept
{
#ifdef _MSC_VER
// Workaround: MSVC stores the coroutine_handle<> return
// value on the coroutine frame via hidden __$ReturnUdt$.
// After await_suspend publishes the handle to another
// thread, that thread can resume/destroy the frame before
// __resume reads the handle back for the symmetric
// transfer tail-call, causing a use-after-free.
using R = decltype(a_.await_suspend(h, p_->environment()));
if constexpr (std::is_same_v<R, std::coroutine_handle<>>)
a_.await_suspend(h, p_->environment()).resume();
else
return a_.await_suspend(h, p_->environment());
#else
return a_.await_suspend(h, p_->environment());
#endif
}
};

Expand Down
8 changes: 8 additions & 0 deletions include/boost/capy/when_all.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,15 @@ struct when_all_runner
template<class Promise>
auto await_suspend(std::coroutine_handle<Promise> h)
{
#ifdef _MSC_VER
using R = decltype(a_.await_suspend(h, &p_->env_));
if constexpr (std::is_same_v<R, std::coroutine_handle<>>)
a_.await_suspend(h, &p_->env_).resume();
else
return a_.await_suspend(h, &p_->env_);
#else
return a_.await_suspend(h, &p_->env_);
#endif
}
};

Expand Down
8 changes: 8 additions & 0 deletions include/boost/capy/when_any.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,15 @@ struct when_any_runner
template<class Promise>
auto await_suspend(std::coroutine_handle<Promise> h)
{
#ifdef _MSC_VER
using R = decltype(a_.await_suspend(h, &p_->env_));
if constexpr (std::is_same_v<R, std::coroutine_handle<>>)
a_.await_suspend(h, &p_->env_).resume();
else
return a_.await_suspend(h, &p_->env_);
#else
return a_.await_suspend(h, &p_->env_);
#endif
}
};

Expand Down
Loading