trampoline.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #include "impl.h"
  2. #include "trampoline.h"
  3. #include "stack/stack_allocator.h"
  4. #include <util/system/info.h>
  5. #include <util/system/protect.h>
  6. #include <util/system/valgrind.h>
  7. #include <util/system/yassert.h>
  8. #include <cstdlib>
  9. #include <util/stream/format.h>
  10. namespace NCoro {
  11. TTrampoline::TTrampoline(NStack::IAllocator& allocator, ui32 stackSize, TFunc f, TCont* cont) noexcept
  12. : Stack_(allocator, stackSize, cont->Name())
  13. , Clo_{this, Stack_.Get(), cont->Name()}
  14. , Ctx_(Clo_)
  15. , Func_(std::move(f))
  16. , Cont_(cont)
  17. {}
  18. void TTrampoline::DoRun() {
  19. if (Cont_->Executor()->FailOnError()) {
  20. Func_(Cont_);
  21. } else {
  22. try {
  23. Func_(Cont_);
  24. } catch (...) {}
  25. }
  26. Cont_->Terminate();
  27. }
  28. TArrayRef<char> TTrampoline::Stack() noexcept {
  29. return Stack_.Get();
  30. }
  31. const char* TTrampoline::ContName() const noexcept {
  32. return Cont_->Name();
  33. }
  34. void TTrampoline::DoRunNaked() {
  35. DoRun();
  36. abort();
  37. }
  38. }