From 7321310b1fa2ca2d36185d42326ac4135c3d063d Mon Sep 17 00:00:00 2001 From: tqcq <99722391+tqcq@users.noreply.github.com> Date: Tue, 11 Jun 2024 22:11:37 +0800 Subject: [PATCH 01/56] feat new fiber --- CMakeLists.txt | 11 +-- tile/fiber/detail/fiber.cc | 93 +++++++++++++++++++++ tile/fiber/detail/fiber.h | 65 +++++++++++++++ tile/fiber/detail/fiber_test.cc | 45 ++++++++++ tile/fiber/detail/os_fiber.cc | 79 ------------------ tile/fiber/detail/os_fiber.h | 62 -------------- tile/fiber/detail/posix_os_fiber.cc | 102 ----------------------- tile/fiber/detail/posix_os_fiber.h | 31 ------- tile/fiber/detail/posix_os_fiber_test.cc | 91 -------------------- tile/fiber/detail/scheduler.cc | 45 ---------- tile/fiber/detail/scheduler.h | 15 ++-- tile/fiber/detail/ucontext.c | 9 +- tile/fiber/fiber.h | 4 +- 13 files changed, 219 insertions(+), 433 deletions(-) create mode 100644 tile/fiber/detail/fiber.cc create mode 100644 tile/fiber/detail/fiber.h create mode 100644 tile/fiber/detail/fiber_test.cc delete mode 100644 tile/fiber/detail/os_fiber.cc delete mode 100644 tile/fiber/detail/os_fiber.h delete mode 100644 tile/fiber/detail/posix_os_fiber.cc delete mode 100644 tile/fiber/detail/posix_os_fiber.h delete mode 100644 tile/fiber/detail/posix_os_fiber_test.cc diff --git a/CMakeLists.txt b/CMakeLists.txt index 303c45b..8889804 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -160,11 +160,10 @@ set(TILE_SRCS "tile/base/thread/rw_mutex.cc" "tile/base/thread/scoped_lock.cc" "tile/base/thread/spinlock.cc" - "tile/fiber/fiber.cc" - "tile/fiber/detail/os_fiber.cc" - "tile/fiber/detail/mutex.cc" + "tile/fiber/detail/fiber.cc" + # "tile/fiber/detail/os_fiber.cc" "tile/fiber/detail/posix_os_fiber.cc" + # "tile/fiber/detail/mutex.cc" "tile/fiber/detail/ucontext.c" - "tile/fiber/detail/posix_os_fiber.cc" "tile/fiber/scheduler.cc" "tile/io/detail/eintr_safe.cc" "tile/io/native/acceptor.cc" @@ -267,9 +266,7 @@ if(TILE_BUILD_TESTS) target_sources(${PROJECT_NAME}_test_all PRIVATE ${test_file}) endmacro() - # -> fiber - tile_add_test(fiber_detail_posix_os_fiber_test - "tile/fiber/detail/posix_os_fiber_test.cc") + tile_add_test(fiber_detail_fiber_test "tile/fiber/detail/fiber_test.cc") tile_add_test(base_internal_meta_test "tile/base/internal/meta_test.cc") # tile_add_test(net_internal_http_engine_test diff --git a/tile/fiber/detail/fiber.cc b/tile/fiber/detail/fiber.cc new file mode 100644 index 0000000..64a7908 --- /dev/null +++ b/tile/fiber/detail/fiber.cc @@ -0,0 +1,93 @@ +#include "tile/fiber/detail/fiber.h" + +#include "tile/base/align.h" +#include "tile/base/internal/move_on_copy.h" +#include "tile/base/logging.h" +#include "tile/base/make_unique.h" +#include "tile/base/object_pool.h" +#include "tile/fiber/detail/ucontext.h" + +namespace tile { +namespace fiber { +namespace detail { + +static thread_local Fiber *tls_current_fiber = nullptr; +static thread_local Fiber *tls_master_fiber = nullptr; + +constexpr auto kStackSize = 8192; +constexpr auto kAlignSize = 16; + +void RunProc(void *arg) { + auto proc = static_cast *>(arg); + if (proc) { + (*proc)(); + } + Fiber::MasterFiber()->Resume(); +} + +struct alignas(hardware_destructive_interference_size) Fiber::FiberContext { + tile_ucontext_t uctx; + std::aligned_storage::type stack; +}; + +Fiber *Fiber::Current() noexcept { return tls_current_fiber; } +void Fiber::SetCurrent(Fiber *fiber) noexcept { tls_current_fiber = fiber; } + +Fiber *Fiber::MasterFiber() noexcept { return tls_master_fiber; } +void Fiber::SetMasterFiber(Fiber *fiber) noexcept { tls_master_fiber = fiber; } + +std::unique_ptr Fiber::Create(std::function proc) noexcept { + return std::unique_ptr(new Fiber(std::move(proc))); + // return make_unique(std::move(proc)); +} + +Fiber::Fiber(std::function proc) + : ctx_(object_pool::Get().Leak()), proc_(std::move(proc)) { + + memset(&ctx_->uctx, 0, sizeof(tile_ucontext_t)); + if (proc_) { + tile_ucontext_set_target(&ctx_->uctx, &ctx_->stack, kStackSize, RunProc, + &proc_); + } +} + +Fiber::~Fiber() { + if (ctx_) { + object_pool::Put(ctx_.release()); + } +} + +void Fiber::Resume() { + auto caller = Current(); + TILE_CHECK_NE(caller, this, "Can't `Resume()` self"); + SetCurrent(this); + tile_ucontext_swap(&caller->ctx_->uctx, &ctx_->uctx); + SetCurrent(caller); +} + +} // namespace detail +} // namespace fiber + +template <> struct PoolTraits { + static constexpr auto kType = PoolType::MemoryNodeShared; + static constexpr std::size_t kLowWaterMark = 128; + static constexpr std::size_t kHighWaterMark = + std::numeric_limits::max(); + static constexpr std::chrono::seconds kMaxIdle = std::chrono::seconds(10); + static constexpr std::size_t kMinimumThreadCacheSize = 64; + static constexpr std::size_t kTransferBatchSize = 16; +}; + +constexpr PoolType PoolTraits::kType; +constexpr std::size_t + PoolTraits::kLowWaterMark; +constexpr std::size_t + PoolTraits::kHighWaterMark; +constexpr std::chrono::seconds + PoolTraits::kMaxIdle; +constexpr std::size_t + PoolTraits::kMinimumThreadCacheSize; +constexpr std::size_t + PoolTraits::kTransferBatchSize; + +} // namespace tile diff --git a/tile/fiber/detail/fiber.h b/tile/fiber/detail/fiber.h new file mode 100644 index 0000000..0536f24 --- /dev/null +++ b/tile/fiber/detail/fiber.h @@ -0,0 +1,65 @@ +#ifndef TILE_FIBER_DETAIL_FIBER_H +#define TILE_FIBER_DETAIL_FIBER_H + +#pragma once + +#include "tile/base/align.h" +#include "tile/base/internal/test_prod.h" +#include "tile/base/object_pool.h" +#include "tile/base/ref_ptr.h" +#include + +struct tile_ucontext_t; + +namespace tile { +namespace fiber { +namespace detail { +void RunProc(void *arg); + +class Scheduler; + +class alignas(hardware_destructive_interference_size) Fiber { +public: + enum FiberState { + Ready, + Waiting, + Terminated, + }; + + static Fiber *Current() noexcept; + static void SetCurrent(Fiber *fiber) noexcept; + static Fiber *MasterFiber() noexcept; + static void SetMasterFiber(Fiber *fiber) noexcept; + + static std::unique_ptr + Create(std::function proc = nullptr) noexcept; + + ~Fiber(); + + Fiber(const Fiber &) = delete; + Fiber &operator=(const Fiber &) = delete; + Fiber(Fiber &&other) noexcept = default; + Fiber &operator=(Fiber &&other) noexcept = default; + +private: + TILE_FRIEND_TEST(Fiber, Base); + friend void RunProc(void *); + friend Scheduler; + struct FiberContext; + friend class ::tile::PoolTraits; + + Fiber(std::function proc = nullptr); + + void Resume(); + +private: + std::unique_ptr ctx_; + std::function proc_; + FiberState state_{Ready}; +}; + +} // namespace detail +} // namespace fiber +} // namespace tile + +#endif // TILE_FIBER_DETAIL_FIBER_H diff --git a/tile/fiber/detail/fiber_test.cc b/tile/fiber/detail/fiber_test.cc new file mode 100644 index 0000000..3481e44 --- /dev/null +++ b/tile/fiber/detail/fiber_test.cc @@ -0,0 +1,45 @@ +#include "tile/base/random.h" +#include "tile/fiber/detail/fiber.h" + +#include "gtest/gtest.h" +namespace tile { +namespace fiber { +namespace detail { + +TEST(Fiber, Base) { + constexpr auto kMaxCnt = 5000; + int cnt = 0; + + // 0 -> master fiber + // [1, 9] -> worker fibers + std::vector> fibers; + + fibers.emplace_back(Fiber::Create()); + Fiber::SetMasterFiber(fibers[0].get()); + Fiber::SetCurrent(fibers[0].get()); + + for (int i = 1; i != 10; ++i) { + fibers.emplace_back(Fiber::Create([&, i] { + while (cnt < kMaxCnt) { + ASSERT_EQ(Fiber::Current(), fibers[i].get()); + ++cnt; + Fiber::MasterFiber()->Resume(); + TILE_LOG_INFO("worke cnt: {}", cnt); + } + })); + } + + while (cnt < kMaxCnt) { + int old = cnt; + auto next_fiber = fibers[Random(1, 1)].get(); + + TILE_LOG_INFO("cnt: {}", cnt); + next_fiber->Resume(); + ASSERT_EQ(old + 1, cnt); + ASSERT_EQ(Fiber::Current(), Fiber::MasterFiber()); + } +} + +} // namespace detail +} // namespace fiber +} // namespace tile diff --git a/tile/fiber/detail/os_fiber.cc b/tile/fiber/detail/os_fiber.cc deleted file mode 100644 index 21e1513..0000000 --- a/tile/fiber/detail/os_fiber.cc +++ /dev/null @@ -1,79 +0,0 @@ -#include "tile/fiber/detail/os_fiber.h" - -namespace tile { -namespace fiber { -namespace detail { -TILE_DEFINE_CLASS_DEPENDENCY_REGISTRY(os_fiber_registry, OSFiber); - -static thread_local OSFiber *current_fiber = nullptr; -static thread_local OSFiber *main_fiber = nullptr; - -OSFiber *OSFiber::Current() noexcept { return current_fiber; } -OSFiber *OSFiber::MainFiber() noexcept { return main_fiber; } - -void OSFiber::SetCurrent(OSFiber *fiber) noexcept { - if (current_fiber && current_fiber->IsAlive()) { - current_fiber->state_ = Fiber::FiberState::Waiting; - } - - if (fiber) { - fiber->state_ = Fiber::FiberState::Running; - } - - current_fiber = fiber; -} - -void OSFiber::SetMainFiber(OSFiber *fiber) noexcept { - if (TILE_UNLIKELY(main_fiber == nullptr && fiber)) { - fiber->state_ = Fiber::FiberState::Running; - } - main_fiber = fiber; - if (main_fiber) { - TILE_LOG_INFO("Upate Main Fiber [{}]", main_fiber->GetId()); - } -} - -OSFiber::~OSFiber() { - if (MainFiber() == this) { - SetMainFiber(nullptr); - } - if (Current() == this) { - SetCurrent(nullptr); - } -} - -bool OSFiber::SwitchTo(OSFiber *to) { - if (to == this) { - return true; - } - - TILE_DCHECK(to); - TILE_DCHECK(to->GetFiberState() == Fiber::FiberState::Waiting || - to->GetFiberState() == Fiber::FiberState::Idle); - - // TILE_LOG_INFO("SwitchTo fiber from [{}] to [{}]", GetId(), to->GetId()); - SetCurrent(to); - bool rc = SwitchToImpl(to); - SetCurrent(this); - - TILE_LOG_WARNING_IF_EVERY_SECOND( - !rc, "SwitchToImpl fiber from [{}] to [{}] failed.", GetId(), - to->GetId()); - - return rc; -} - -void OSFiber::Yield() { - TILE_DCHECK(MainFiber()); - TILE_DCHECK(state_ == Fiber::FiberState::Running || - state_ == Fiber::FiberState::Terminated, - "Fiber [{}] is can't call `Yield()`", GetId()); - - SwitchTo(MainFiber()); -} - -bool OSFiber::IsAlive() const { return alive_.load(std::memory_order_relaxed); } - -} // namespace detail -} // namespace fiber -} // namespace tile diff --git a/tile/fiber/detail/os_fiber.h b/tile/fiber/detail/os_fiber.h deleted file mode 100644 index 9e34999..0000000 --- a/tile/fiber/detail/os_fiber.h +++ /dev/null @@ -1,62 +0,0 @@ -#ifndef TILE_FIBER_DETAIL_OS_FIBER_H -#define TILE_FIBER_DETAIL_OS_FIBER_H - -#pragma once - -#include "tile/base/dependency_registry.h" -#include "tile/base/thread/spinlock.h" -#include "tile/fiber/fiber.h" - -namespace tile { -namespace fiber { -namespace detail { - -class OSFiber { -public: - // static tool - static OSFiber *Current() noexcept; - static OSFiber *MainFiber() noexcept; - static void SetCurrent(OSFiber *fiber) noexcept; - static void SetMainFiber(OSFiber *fiber) noexcept; - -public: - struct Options { - Fiber::Task task; - std::size_t stack_size; - }; - - virtual ~OSFiber(); - - virtual Fiber::Id GetId() const = 0; - virtual bool Initialize(Options options) = 0; - - Fiber::FiberState GetFiberState() const { return state_; }; - - bool SwitchTo(OSFiber *to); - void Yield(); - -protected: - virtual bool SwitchToImpl(OSFiber *to) = 0; - - bool IsAlive() const; - - enum Fiber::FiberState state_; - std::atomic alive_{true}; - -private: - friend class Scheduler; - friend class Fiber; - Spinlock scheduler_lock_; -}; - -// 1. WorkerProc == nullptr, Fiber for current contextz. -// 2. WorkerProc != nullptr, Fiber for new func -TILE_DECLARE_CLASS_DEPENDENCY_REGISTRY(os_fiber_registry, OSFiber); - -inline bool IsFiberEnv() noexcept { return OSFiber::Current() != nullptr; } - -} // namespace detail -} // namespace fiber -} // namespace tile - -#endif // TILE_FIBER_DETAIL_OS_FIBER_H diff --git a/tile/fiber/detail/posix_os_fiber.cc b/tile/fiber/detail/posix_os_fiber.cc deleted file mode 100644 index c733e14..0000000 --- a/tile/fiber/detail/posix_os_fiber.cc +++ /dev/null @@ -1,102 +0,0 @@ -#include "tile/fiber/detail/posix_os_fiber.h" - -#include "tile/base/down_cast.h" -#include "tile/base/internal/macro.h" -#include "tile/base/internal/move_on_copy.h" -#include "tile/base/likely.h" -#include "tile/base/make_unique.h" - -#include - -#include "tile/fiber/detail/ucontext.h" - -#include - -namespace tile { -namespace fiber { -namespace detail { - -TILE_REGISTER_CLASS_DEPENDENCY(os_fiber_registry, "os_fiber", PosixOSFiber); - -namespace { -struct AlignMemoryDeleter { - void operator()(char *ptr) const { - if (ptr) { - delete[] ptr; - } - } -}; - -static void UContextAdaptor(int a1, int a2, int a3, int a4) { - int array[] = {a1, a2, a3, a4}; - auto ptr = *reinterpret_cast(array); - (**reinterpret_cast(array))(); -} - -static void SampleAdaptor(void *arg) { - (*reinterpret_cast(arg))(); -} - -template struct InvokeHelper { - template - static void Invoke(const Array &array, F &&f, Args &&...args) { - return InvokeHelper::Invoke(array, f, std::forward(args)..., - array[4 - N]); - }; -}; -template <> struct InvokeHelper<0> { - template - static void Invoke(const Array &array, F &&f, Args &&...args) { - f(std::forward(args)...); - }; -}; - -} // namespace - -struct alignas(hardware_destructive_interference_size) PosixOSFiber::Context { - tile_ucontext_t ctx; - std::unique_ptr stack; - std::function worker_proc; -}; - -PosixOSFiber::PosixOSFiber() : context_(make_unique()) {} - -PosixOSFiber::~PosixOSFiber() { - // TILE_LOG_INFO("Release fiber [{}]", GetId()); -} - -bool PosixOSFiber::Initialize(Options options) { - memset(&context_->ctx, 0, sizeof(context_->ctx)); - - if (options.task) { - const auto kAllocSize = 128 + options.stack_size; - context_->stack = make_unique(kAllocSize); - auto moved_task = MakeMoveOnCopy(options.task); - - context_->worker_proc = [this, moved_task] { - moved_task.Ref()(); - state_ = Fiber::FiberState::Terminated; - TILE_CHECK(this != MainFiber()); - SwitchToImpl(MainFiber()); - }; - - tile_ucontext_set_target(&context_->ctx, context_->stack.get(), kAllocSize, - SampleAdaptor, &context_->worker_proc); - } - // TILE_LOG_INFO("init fiber id [{}]", GetId()); - - return true; -} - -Fiber::Id PosixOSFiber::GetId() const { - return reinterpret_cast(this); -} -bool PosixOSFiber::SwitchToImpl(OSFiber *to) { - TILE_DCHECK(down_cast(to)); - auto to_fiber = down_cast(to); - tile_ucontext_swap(&context_->ctx, &to_fiber->context_->ctx); - return true; -} -} // namespace detail -} // namespace fiber -} // namespace tile diff --git a/tile/fiber/detail/posix_os_fiber.h b/tile/fiber/detail/posix_os_fiber.h deleted file mode 100644 index 5c9ff83..0000000 --- a/tile/fiber/detail/posix_os_fiber.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef TILE_FIBER_DETAIL_POSIX_OS_FIBER_H -#define TILE_FIBER_DETAIL_POSIX_OS_FIBER_H - -#pragma once - -#include "tile/fiber/detail/os_fiber.h" - -namespace tile { -namespace fiber { -namespace detail { -class PosixOSFiber : public OSFiber { -public: - PosixOSFiber(); - ~PosixOSFiber() override; - - bool Initialize(Options options) override; - Fiber::Id GetId() const override; - -protected: - bool SwitchToImpl(OSFiber *to) override; - -private: - struct Context; - std::unique_ptr context_; -}; - -} // namespace detail -} // namespace fiber -} // namespace tile - -#endif // TILE_FIBER_DETAIL_POSIX_OS_FIBER_H diff --git a/tile/fiber/detail/posix_os_fiber_test.cc b/tile/fiber/detail/posix_os_fiber_test.cc deleted file mode 100644 index fe41e4c..0000000 --- a/tile/fiber/detail/posix_os_fiber_test.cc +++ /dev/null @@ -1,91 +0,0 @@ -#include "tile/fiber/detail/posix_os_fiber.h" - -#include "gtest/gtest.h" - -namespace tile { -namespace fiber { -namespace detail { - -void DisplayAllFiberId() { - TILE_LOG_INFO("CurrentFiber: {}, MainFiber: {}", - OSFiber::Current() ? OSFiber::Current()->GetId() : 0, - OSFiber::MainFiber() ? OSFiber::MainFiber()->GetId() : 0); -} - -std::unique_ptr BuildMainFiber() { - auto main_fiber = os_fiber_registry.New("os_fiber"); - EXPECT_TRUE(main_fiber != nullptr); - { - OSFiber::Options main_options; - main_options.task = nullptr; - main_options.stack_size = 8192; - main_fiber->Initialize(main_options); - } - - OSFiber::SetMainFiber(main_fiber.get()); - OSFiber::SetCurrent(main_fiber.get()); - return main_fiber; -} - -std::unique_ptr BuildWorkerFiber(Fiber::Task task) { - auto worker_fiber = os_fiber_registry.New("os_fiber"); - EXPECT_TRUE(worker_fiber != nullptr); - { - OSFiber::Options worker_options; - worker_options.task = task; - worker_options.stack_size = 8192; - worker_fiber->Initialize(worker_options); - } - return worker_fiber; -} - -TEST(PosixOSFiber, Base) { - DisplayAllFiberId(); - { - int called = 1; - auto main_fiber = BuildMainFiber(); - std::unique_ptr worker_fiber = BuildWorkerFiber([&] { - DisplayAllFiberId(); - TILE_LOG_INFO("task start"); - ASSERT_EQ(OSFiber::Current(), worker_fiber.get()); - ASSERT_EQ(OSFiber::MainFiber(), main_fiber.get()); - called = 2; - TILE_LOG_INFO("task end"); - }); - DisplayAllFiberId(); - ASSERT_EQ(called, 1); - main_fiber->SwitchTo(worker_fiber.get()); - DisplayAllFiberId(); - ASSERT_EQ(called, 2); - ASSERT_EQ(OSFiber::Current(), main_fiber.get()); - ASSERT_EQ(OSFiber::MainFiber(), main_fiber.get()); - DisplayAllFiberId(); - } - TILE_LOG_INFO("End"); -} - -TEST(PosixOSFiber, Yield) { - constexpr int kYieldCount = 1000; - - auto main_fiber = BuildMainFiber(); - for (int i = 0; i != 1000; ++i) { - int yield = 0; - int schedule_cnt = 0; - auto worker_fiber = BuildWorkerFiber([&] { - for (int j = 0; j != kYieldCount; ++j) { - ++yield; - ASSERT_EQ(yield, schedule_cnt); - OSFiber::Current()->Yield(); - } - }); - - while (yield != kYieldCount) { - ++schedule_cnt; - main_fiber->SwitchTo(worker_fiber.get()); - } - } -} - -} // namespace detail -} // namespace fiber -} // namespace tile diff --git a/tile/fiber/detail/scheduler.cc b/tile/fiber/detail/scheduler.cc index 47ad18e..fe53245 100644 --- a/tile/fiber/detail/scheduler.cc +++ b/tile/fiber/detail/scheduler.cc @@ -1,48 +1,3 @@ #include "tile/fiber/detail/scheduler.h" -#include "tile/fiber/detail/os_fiber.h" -namespace tile { -namespace fiber { -namespace detail { -thread_local Scheduler *current_scheduler = nullptr; - -Scheduler::Scheduler() { main_fiber_ = os_fiber_registry.New("os_fiber"); } - -Scheduler::~Scheduler() {} - -Scheduler *Scheduler::Current() noexcept { return current_scheduler; } - -void Scheduler::Yield(OSFiber *self) noexcept { - auto main_fiber = OSFiber::MainFiber(); - SwitchTo(self, main_fiber); -} - -void Scheduler::Halt(OSFiber *self) noexcept {} - -void Scheduler::SwitchTo(OSFiber *self, OSFiber *to) noexcept { - TILE_CHECK_EQ(self, OSFiber::Current()); - TILE_CHECK_NE(to->GetFiberState(), Fiber::FiberState::Terminated, - "Fiber `to` is terminated."); - TILE_CHECK_NE(self, to, "Fiber `self` is the same as fiber `to`."); - - self->SwitchTo(to); - - TILE_CHECK_EQ(self, OSFiber::Current()); -} - -OSFiber *Scheduler::StartFiber(std::function task) { - auto os_fiber = os_fiber_registry.New("os_fiber"); - OSFiber::Options options; - options.stack_size = FLAGS_tile_fiber_stack_size; - options.task = std::move(task); - if (!os_fiber->Initialize(options)) { - return nullptr; - } - - return os_fiber.get(); -} - -} // namespace detail -} // namespace fiber -} // namespace tile diff --git a/tile/fiber/detail/scheduler.h b/tile/fiber/detail/scheduler.h index b597a41..fb30bac 100644 --- a/tile/fiber/detail/scheduler.h +++ b/tile/fiber/detail/scheduler.h @@ -2,19 +2,21 @@ #define TILE_FIBER_DETAIL_SCHEDULER_H #pragma once - +#include "tile/base/thread/event.h" #include "tile/base/thread/spinlock.h" #include "tile/fiber/fiber.h" #include #include +#include #include #include +#include namespace tile { namespace fiber { namespace detail { -class OSFiber; +class Fiber; class Scheduler { public: @@ -23,17 +25,18 @@ public: void Yield(OSFiber *self) noexcept; void Halt(OSFiber *self) noexcept; void SwitchTo(OSFiber *self, OSFiber *to) noexcept; - OSFiber *StartFiber(std::function task); + + void Queue(std::function task); private: + OSFiber *StartFiber(std::function task); Scheduler(); ~Scheduler(); private: - std::unique_ptr main_fiber_; - std::map> fibers_; Spinlock fibers_lock_; - // std::array, 64> fibers_; + std::list> tasks_; + Event new_task_event_; }; } // namespace detail } // namespace fiber diff --git a/tile/fiber/detail/ucontext.c b/tile/fiber/detail/ucontext.c index a677cea..f512513 100644 --- a/tile/fiber/detail/ucontext.c +++ b/tile/fiber/detail/ucontext.c @@ -34,15 +34,8 @@ void tile_ucontext_set_target(struct tile_ucontext_t *ctx, void *stack, __hwasan_tag_memory(stack, 0, stack_size); } #endif - assert(((stack_size & ~((uintptr_t)15)) >= 1024) && - "stack size must be greater than 16 bytes"); uintptr_t *stack_top = (uintptr_t *)((uint8_t *)(stack) + stack_size); - - // align by 2^15=32796 bytes - { - stack_size -= ((uintptr_t)stack_top & 15); - stack_top -= ((uintptr_t)stack_top) & 15; - } + assert(((uintptr_t)stack_top & 15) == 0); #if defined(__x86_64__) TILE_UCONTEXT_ARG0(ctx, stack_top) = (uintptr_t)&tile_ucontext_trampoline; diff --git a/tile/fiber/fiber.h b/tile/fiber/fiber.h index 81049e0..11ab3c2 100644 --- a/tile/fiber/fiber.h +++ b/tile/fiber/fiber.h @@ -28,8 +28,8 @@ public: using Id = std::uint64_t; using Task = std::function; enum class FiberState { - Idle, // No task - Running, // Process task + Ready, // No task + // Running, // Process task Waiting, // Blocked Terminated, // Terminated }; From 2a09d4cef786e24aa6172ac079bc73c5f9a13f22 Mon Sep 17 00:00:00 2001 From: tqcq <99722391+tqcq@users.noreply.github.com> Date: Tue, 11 Jun 2024 22:22:29 +0800 Subject: [PATCH 02/56] feat delete log --- tile/fiber/detail/fiber_test.cc | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tile/fiber/detail/fiber_test.cc b/tile/fiber/detail/fiber_test.cc index 3481e44..dd4e852 100644 --- a/tile/fiber/detail/fiber_test.cc +++ b/tile/fiber/detail/fiber_test.cc @@ -7,7 +7,7 @@ namespace fiber { namespace detail { TEST(Fiber, Base) { - constexpr auto kMaxCnt = 5000; + constexpr auto kMaxCnt = 5000000; int cnt = 0; // 0 -> master fiber @@ -24,16 +24,14 @@ TEST(Fiber, Base) { ASSERT_EQ(Fiber::Current(), fibers[i].get()); ++cnt; Fiber::MasterFiber()->Resume(); - TILE_LOG_INFO("worke cnt: {}", cnt); } })); } while (cnt < kMaxCnt) { int old = cnt; - auto next_fiber = fibers[Random(1, 1)].get(); + auto next_fiber = fibers[Random(1, 9)].get(); - TILE_LOG_INFO("cnt: {}", cnt); next_fiber->Resume(); ASSERT_EQ(old + 1, cnt); ASSERT_EQ(Fiber::Current(), Fiber::MasterFiber()); From 5c89d3667cd8246059ffdb43129063af9439db7c Mon Sep 17 00:00:00 2001 From: tqcq <99722391+tqcq@users.noreply.github.com> Date: Tue, 11 Jun 2024 22:34:57 +0800 Subject: [PATCH 03/56] feat test balign --- tile/fiber/detail/asm/ucontext_aarch64.S | 2 +- tile/fiber/detail/asm/ucontext_aarch64.h | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/tile/fiber/detail/asm/ucontext_aarch64.S b/tile/fiber/detail/asm/ucontext_aarch64.S index 721a901..bff94d3 100644 --- a/tile/fiber/detail/asm/ucontext_aarch64.S +++ b/tile/fiber/detail/asm/ucontext_aarch64.S @@ -50,7 +50,7 @@ // x1: to .text .global TILE_ASM_SYMBOL(tile_ucontext_swap) -.align 4 +.balign 16 TILE_ASM_SYMBOL(tile_ucontext_swap): // Save context 'from' diff --git a/tile/fiber/detail/asm/ucontext_aarch64.h b/tile/fiber/detail/asm/ucontext_aarch64.h index 5c3e530..b40d639 100644 --- a/tile/fiber/detail/asm/ucontext_aarch64.h +++ b/tile/fiber/detail/asm/ucontext_aarch64.h @@ -1,8 +1,7 @@ -#ifndef TILE_FIBER_DETAIL_AARCH64_UCONTEXT_H -#define TILE_FIBER_DETAIL_AARCH64_UCONTEXT_H +#ifndef TILE_FIBER_DETAIL_ASM_UCONTEXT_AARCH64_H +#define TILE_FIBER_DETAIL_ASM_UCONTEXT_AARCH64_H #pragma once - #define TILE_REG_r0 0x00 #define TILE_REG_r1 0x08 #define TILE_REG_r16 0x10 @@ -37,6 +36,7 @@ #endif #ifndef TILE_BUILD_ASM + #include // Procedure Call Standard for the ARM 64-bit Architecture @@ -76,6 +76,7 @@ struct tile_ucontext_t { uintptr_t SP; // stack pointer uintptr_t LR; // link register (R30) }; + #define TILE_UCONTEXT_ARG0(ctx, stack_top) (ctx)->LR #define TILE_UCONTEXT_ARG1(ctx, stack_top) (ctx)->r0 #define TILE_UCONTEXT_ARG2(ctx, stack_top) (ctx)->r1 @@ -138,4 +139,5 @@ static_assert(offsetof(tile_ucontext_t, LR) == TILE_REG_LR, #endif // __cplusplus #endif // TILE_BUILD_ASM -#endif // TILE_FIBER_DETAIL_AARCH64_UCONTEXT_H + +#endif // TILE_FIBER_DETAIL_ASM_UCONTEXT_AARCH64_H From 0dce11b0dde9eb6e38a825089434b14dd04376d9 Mon Sep 17 00:00:00 2001 From: tqcq <99722391+tqcq@users.noreply.github.com> Date: Tue, 11 Jun 2024 22:48:08 +0800 Subject: [PATCH 04/56] feat remove unused files --- CMakeLists.txt | 1 - tile/fiber/detail/asm/ucontext_mips32.h | 18 ++---- tile/fiber/detail/asm/ucontext_mips64.h | 18 ++---- tile/fiber/detail/asm/ucontext_riscv64.h | 6 +- tile/fiber/detail/asm/ucontext_x64.h | 18 ++---- tile/fiber/detail/asm/ucontext_x86.h | 6 ++ tile/fiber/detail/fiber_test.cc | 3 + tile/fiber/detail/scheduler.cc | 3 - tile/fiber/detail/scheduler.h | 45 -------------- tile/fiber/fiber.cc | 54 ----------------- tile/fiber/fiber.h | 75 ------------------------ tile/fiber/scheduler.cc | 22 ------- tile/fiber/scheduler.h | 39 ------------ 13 files changed, 27 insertions(+), 281 deletions(-) delete mode 100644 tile/fiber/detail/scheduler.cc delete mode 100644 tile/fiber/detail/scheduler.h delete mode 100644 tile/fiber/fiber.cc delete mode 100644 tile/fiber/fiber.h delete mode 100644 tile/fiber/scheduler.cc delete mode 100644 tile/fiber/scheduler.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 8889804..688cd54 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -164,7 +164,6 @@ set(TILE_SRCS # "tile/fiber/detail/os_fiber.cc" "tile/fiber/detail/posix_os_fiber.cc" # "tile/fiber/detail/mutex.cc" "tile/fiber/detail/ucontext.c" - "tile/fiber/scheduler.cc" "tile/io/detail/eintr_safe.cc" "tile/io/native/acceptor.cc" "tile/io/descriptor.cc" diff --git a/tile/fiber/detail/asm/ucontext_mips32.h b/tile/fiber/detail/asm/ucontext_mips32.h index 35769ba..510b7d7 100644 --- a/tile/fiber/detail/asm/ucontext_mips32.h +++ b/tile/fiber/detail/asm/ucontext_mips32.h @@ -1,17 +1,7 @@ -// Copyright 2021 The Marl Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +#ifndef TILE_FIBER_DETAIL_ASM_UCONTEXT_MIPS32_H +#define TILE_FIBER_DETAIL_ASM_UCONTEXT_MIPS32_H +#pragma once #define TILE_REG_f20 0x00 #define TILE_REG_f22 0x08 #define TILE_REG_f24 0x10 @@ -129,3 +119,5 @@ static_assert(offsetof(tile_ucontext_t, ra) == TILE_REG_ra, #endif // __cplusplus #endif // TILE_BUILD_ASM + +#endif // TILE_FIBER_DETAIL_ASM_UCONTEXT_MIPS32_H diff --git a/tile/fiber/detail/asm/ucontext_mips64.h b/tile/fiber/detail/asm/ucontext_mips64.h index 93f9c8f..5573ce1 100644 --- a/tile/fiber/detail/asm/ucontext_mips64.h +++ b/tile/fiber/detail/asm/ucontext_mips64.h @@ -1,17 +1,7 @@ -// Copyright 2020 The Marl Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +#ifndef TILE_FIBER_DETAIL_ASM_UCONTEXT_MIPS64_H +#define TILE_FIBER_DETAIL_ASM_UCONTEXT_MIPS64_H +#pragma once #define TILE_REG_a0 0x00 #define TILE_REG_a1 0x08 #define TILE_REG_s0 0x10 @@ -129,3 +119,5 @@ static_assert(offsetof(tile_ucontext_t, ra) == TILE_REG_ra, #endif // __cplusplus #endif // TILE_BUILD_ASM + +#endif // TILE_FIBER_DETAIL_ASM_UCONTEXT_MIPS64_H diff --git a/tile/fiber/detail/asm/ucontext_riscv64.h b/tile/fiber/detail/asm/ucontext_riscv64.h index d513b60..5a058ef 100644 --- a/tile/fiber/detail/asm/ucontext_riscv64.h +++ b/tile/fiber/detail/asm/ucontext_riscv64.h @@ -1,5 +1,5 @@ -#ifndef TILE_FIBER_DETAIL_UCONTEXT_RISCV64_H -#define TILE_FIBER_DETAIL_UCONTEXT_RISCV64_H +#ifndef TILE_FIBER_DETAIL_ASM_UCONTEXT_RISCV64_H +#define TILE_FIBER_DETAIL_ASM_UCONTEXT_RISCV64_H #pragma once #define TILE_REG_a0 0x00 @@ -138,4 +138,4 @@ static_assert(offsetof(tile_ucontext_t, ra) == TILE_REG_ra, #endif // TILE_BUILD_ASM -#endif // TILE_FIBER_DETAIL_UCONTEXT_RISCV64_H +#endif // TILE_FIBER_DETAIL_ASM_UCONTEXT_RISCV64_H diff --git a/tile/fiber/detail/asm/ucontext_x64.h b/tile/fiber/detail/asm/ucontext_x64.h index b524f9a..369a246 100644 --- a/tile/fiber/detail/asm/ucontext_x64.h +++ b/tile/fiber/detail/asm/ucontext_x64.h @@ -1,17 +1,7 @@ -// Copyright 2019 The Marl Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +#ifndef TILE_FIBER_DETAIL_ASM_UCONTEXT_X64_H +#define TILE_FIBER_DETAIL_ASM_UCONTEXT_X64_H +#pragma once #define TILE_REG_RBX 0x00 #define TILE_REG_RBP 0x08 #define TILE_REG_R12 0x10 @@ -81,3 +71,5 @@ static_assert(offsetof(tile_ucontext_t, RIP) == TILE_REG_RIP, #endif // __cplusplus #endif // TILE_BUILD_ASM + +#endif // TILE_FIBER_DETAIL_ASM_UCONTEXT_X64_H diff --git a/tile/fiber/detail/asm/ucontext_x86.h b/tile/fiber/detail/asm/ucontext_x86.h index 4a7c7b7..3d4e9d6 100644 --- a/tile/fiber/detail/asm/ucontext_x86.h +++ b/tile/fiber/detail/asm/ucontext_x86.h @@ -1,3 +1,7 @@ +#ifndef TILE_FIBER_DETAIL_ASM_UCONTEXT_X86_H +#define TILE_FIBER_DETAIL_ASM_UCONTEXT_X86_H + +#pragma once #define TILE_REG_EBX 0x00 #define TILE_REG_EBP 0x04 #define TILE_REG_ESI 0x08 @@ -44,3 +48,5 @@ static_assert(offsetof(tile_ucontext_t, EIP) == TILE_REG_EIP, #endif // __cplusplus #endif // TILE_BUILD_ASM + +#endif // TILE_FIBER_DETAIL_ASM_UCONTEXT_X86_H diff --git a/tile/fiber/detail/fiber_test.cc b/tile/fiber/detail/fiber_test.cc index dd4e852..497b3c1 100644 --- a/tile/fiber/detail/fiber_test.cc +++ b/tile/fiber/detail/fiber_test.cc @@ -9,6 +9,7 @@ namespace detail { TEST(Fiber, Base) { constexpr auto kMaxCnt = 5000000; int cnt = 0; + int resume_cnt = 0; // 0 -> master fiber // [1, 9] -> worker fibers @@ -33,9 +34,11 @@ TEST(Fiber, Base) { auto next_fiber = fibers[Random(1, 9)].get(); next_fiber->Resume(); + ++resume_cnt; ASSERT_EQ(old + 1, cnt); ASSERT_EQ(Fiber::Current(), Fiber::MasterFiber()); } + ASSERT_EQ(resume_cnt, kMaxCnt); } } // namespace detail diff --git a/tile/fiber/detail/scheduler.cc b/tile/fiber/detail/scheduler.cc deleted file mode 100644 index fe53245..0000000 --- a/tile/fiber/detail/scheduler.cc +++ /dev/null @@ -1,3 +0,0 @@ -#include "tile/fiber/detail/scheduler.h" - - diff --git a/tile/fiber/detail/scheduler.h b/tile/fiber/detail/scheduler.h deleted file mode 100644 index fb30bac..0000000 --- a/tile/fiber/detail/scheduler.h +++ /dev/null @@ -1,45 +0,0 @@ -#ifndef TILE_FIBER_DETAIL_SCHEDULER_H -#define TILE_FIBER_DETAIL_SCHEDULER_H - -#pragma once -#include "tile/base/thread/event.h" -#include "tile/base/thread/spinlock.h" -#include "tile/fiber/fiber.h" -#include -#include -#include -#include -#include -#include - -namespace tile { -namespace fiber { -namespace detail { - -class Fiber; - -class Scheduler { -public: - static Scheduler *Current() noexcept; - - void Yield(OSFiber *self) noexcept; - void Halt(OSFiber *self) noexcept; - void SwitchTo(OSFiber *self, OSFiber *to) noexcept; - - void Queue(std::function task); - -private: - OSFiber *StartFiber(std::function task); - Scheduler(); - ~Scheduler(); - -private: - Spinlock fibers_lock_; - std::list> tasks_; - Event new_task_event_; -}; -} // namespace detail -} // namespace fiber -} // namespace tile - -#endif // TILE_FIBER_DETAIL_SCHEDULER_H diff --git a/tile/fiber/fiber.cc b/tile/fiber/fiber.cc deleted file mode 100644 index 1012a3f..0000000 --- a/tile/fiber/fiber.cc +++ /dev/null @@ -1,54 +0,0 @@ -#include "tile/fiber/fiber.h" -#include "tile/base/internal/index_alloc.h" -#include "tile/fiber/detail/os_fiber.h" - -#include "gflags/gflags.h" - -DEFINE_int32(tile_fiber_stack_size, 1024 * 1024, "Fiber stack size"); - -namespace tile { -namespace fiber { -namespace { -Fiber::Id AllocFiberId() noexcept { - return internal::IndexAlloc::For()->Next(); -} -void FreeFiberId(Fiber::Id id) noexcept { - internal::IndexAlloc::For()->Free(id); -} - -} // namespace - -Fiber::Fiber() - : id_(AllocFiberId()), exit_latch_(std::make_shared(1)), - impl_(detail::os_fiber_registry.New("os_fiber")) {} - -Fiber::Fiber(Fiber &&) noexcept = default; - -Fiber &Fiber::operator=(Fiber &&) noexcept = default; - -Fiber::~Fiber() = default; - -Fiber::Id Fiber::GetId() const { return id_; } - -void Fiber::WorkerProc() { - TILE_LOG_INFO("Only display log"); - FreeFiberId(id_); - exit_latch_->CountDown(); -} - -void Fiber::SwitchTo(Fiber *to) { - TILE_CHECK(to); - impl_->SwitchTo(to->impl_.get()); -} - -} // namespace fiber -} // namespace tile - -namespace tile { -constexpr PoolType PoolTraits::kType; -constexpr std::size_t PoolTraits::kLowWaterMark; -constexpr std::size_t PoolTraits::kHighWaterMark; -constexpr std::chrono::nanoseconds PoolTraits::kMaxIdle; -constexpr std::size_t PoolTraits::kMinimumThreadCacheSize; -constexpr std::size_t PoolTraits::kTransferBatchSize; -} // namespace tile diff --git a/tile/fiber/fiber.h b/tile/fiber/fiber.h deleted file mode 100644 index 11ab3c2..0000000 --- a/tile/fiber/fiber.h +++ /dev/null @@ -1,75 +0,0 @@ -#ifndef TILE_FIBER_FIBER_H -#define TILE_FIBER_FIBER_H - -#pragma once - -#include "tile/base/internal/test_prod.h" -#include "tile/base/object_pool.h" -#include "tile/base/thread/latch.h" - -#include "gflags/gflags_declare.h" - -DECLARE_int32(tile_fiber_stack_size); - -namespace tile { -namespace fiber { -namespace detail { -class OSFiber; -} // namespace detail -} // namespace fiber -} // namespace tile - -namespace tile { -namespace fiber { -class Scheduler; - -class Fiber { -public: - using Id = std::uint64_t; - using Task = std::function; - enum class FiberState { - Ready, // No task - // Running, // Process task - Waiting, // Blocked - Terminated, // Terminated - }; - - Fiber(Fiber &&) noexcept; - Fiber &operator=(Fiber &&) noexcept; - - ~Fiber(); - - Id GetId() const; - void Yield(); - -private: - friend class ::tile::fiber::Scheduler; - TILE_FRIEND_TEST(Fiber, Base); - - Fiber(); - Fiber(Fiber *main_fiber); - - void WorkerProc(); - void SwitchTo(Fiber *to); - -private: - Id id_; - std::shared_ptr exit_latch_; - std::unique_ptr<::tile::fiber::detail::OSFiber> impl_{nullptr}; -}; -} // namespace fiber -} // namespace tile - -namespace tile { -template <> struct PoolTraits<::tile::fiber::Fiber> { - static constexpr auto kType = PoolType::MemoryNodeShared; - static constexpr std::size_t kLowWaterMark = 32768; - static constexpr std::size_t kHighWaterMark = - std::numeric_limits::max(); - static constexpr std::chrono::nanoseconds kMaxIdle = std::chrono::seconds(5); - static constexpr std::size_t kMinimumThreadCacheSize = 8192; - static constexpr std::size_t kTransferBatchSize = 1024; -}; -} // namespace tile - -#endif // TILE_FIBER_FIBER_H diff --git a/tile/fiber/scheduler.cc b/tile/fiber/scheduler.cc deleted file mode 100644 index 97c7f1d..0000000 --- a/tile/fiber/scheduler.cc +++ /dev/null @@ -1,22 +0,0 @@ -#include "tile/fiber/scheduler.h" -#include "tile/fiber/fiber.h" - -namespace tile { -namespace fiber { -namespace detail { -static thread_local Scheduler *current_scheduler = nullptr; -} - -Scheduler *Scheduler::Current() noexcept { return detail::current_scheduler; } - -Scheduler::Scheduler(Options options) : options_(std::move(options)) { - detail::current_scheduler = this; - // main_fiber_ = std::make_unique(); - // fibers_.reserve(options_.affinity.size()); - // for (auto i : options_.affinity) { - // fibers_.push_back(std::make_unique()); - // } -} - -} // namespace fiber -} // namespace tile diff --git a/tile/fiber/scheduler.h b/tile/fiber/scheduler.h deleted file mode 100644 index d4b5a1b..0000000 --- a/tile/fiber/scheduler.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef TILE_FIBER_DETAIL_SCHEDULER_H -#define TILE_FIBER_DETAIL_SCHEDULER_H - -#pragma once - -#include "tile/base/align.h" -#include "tile/fiber/fiber.h" - -#include - -namespace tile { -namespace fiber { - -class alignas(hardware_destructive_interference_size) Scheduler { -public: - struct Options { - std::vector affinity; - std::size_t fiber_stack_size = 1024 * 1024; - }; - - Scheduler(Options options); - ~Scheduler(); - - static Scheduler *Current() noexcept; - -private: - void WorkerProc(); - -private: - Options options_; - - std::unique_ptr main_fiber_; - std::vector> fibers_; -}; - -} // namespace fiber -} // namespace tile - -#endif // TILE_FIBER_DETAIL_SCHEDULER_H From 70aa82c37cc56c9c39ab231b7d9badaced6a51b3 Mon Sep 17 00:00:00 2001 From: tqcq <99722391+tqcq@users.noreply.github.com> Date: Tue, 11 Jun 2024 23:34:48 +0800 Subject: [PATCH 05/56] feat update aarch64 asm --- CMakeLists.txt | 4 +++- tile/fiber/detail/asm/ucontext_aarch64.S | 3 ++- tile/fiber/detail/fiber.cc | 3 ++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 688cd54..fff12c3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,7 +27,9 @@ endif() if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static") set(CMAKE_C_FLAGS - # "${CMAKE_CXX_FLAGS} -static") + # "${CMAKE_CXX_FLAGS} -static") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} + # -fsanitize=address ") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address + # ") set(WHOLE_ARCHIVE_PREFIX "-Wl,-force_load") # set(NO_WHOLE_ARCHIVE_PREFIX "") diff --git a/tile/fiber/detail/asm/ucontext_aarch64.S b/tile/fiber/detail/asm/ucontext_aarch64.S index bff94d3..8c682e7 100644 --- a/tile/fiber/detail/asm/ucontext_aarch64.S +++ b/tile/fiber/detail/asm/ucontext_aarch64.S @@ -50,7 +50,8 @@ // x1: to .text .global TILE_ASM_SYMBOL(tile_ucontext_swap) -.balign 16 +// .balign 16 +.align 8 TILE_ASM_SYMBOL(tile_ucontext_swap): // Save context 'from' diff --git a/tile/fiber/detail/fiber.cc b/tile/fiber/detail/fiber.cc index 64a7908..c633fd1 100644 --- a/tile/fiber/detail/fiber.cc +++ b/tile/fiber/detail/fiber.cc @@ -44,7 +44,8 @@ std::unique_ptr Fiber::Create(std::function proc) noexcept { Fiber::Fiber(std::function proc) : ctx_(object_pool::Get().Leak()), proc_(std::move(proc)) { - memset(&ctx_->uctx, 0, sizeof(tile_ucontext_t)); + // memset(&ctx_->uctx, 0, sizeof(tile_ucontext_t)); + // memset(&ctx_->stack, 0, kStackSize); if (proc_) { tile_ucontext_set_target(&ctx_->uctx, &ctx_->stack, kStackSize, RunProc, &proc_); From f84711702dba4eaa37184d4cf62e638366eb02e9 Mon Sep 17 00:00:00 2001 From: tqcq <99722391+tqcq@users.noreply.github.com> Date: Wed, 12 Jun 2024 00:16:26 +0800 Subject: [PATCH 06/56] feat add context --- CMakeLists.txt | 10 +- third_party/context/.gitignore | 59 ++++ third_party/context/CMakeLists.txt | 277 ++++++++++++++++++ third_party/context/LICENSE | 21 ++ .../cmake/CMakeASM_ARMASMInformation.cmake | 13 + .../CMakeDetermineASM_ARMASMCompiler.cmake | 12 + .../cmake/CMakeTestASM_ARMASMCompiler.cmake | 13 + .../context/include/nova/context/asan.h | 26 ++ .../context/include/nova/context/config.h | 34 +++ .../context/include/nova/context/fcontext.h | 42 +++ .../context/include/nova/context/tsan.h | 28 ++ .../src/asm/jump_arm64_aapcs_elf_gas.S | 114 +++++++ .../src/asm/jump_arm64_aapcs_macho_gas.S | 109 +++++++ .../src/asm/jump_arm64_aapcs_pe_armasm.asm | 133 +++++++++ .../context/src/asm/jump_arm_aapcs_elf_gas.S | 88 ++++++ .../src/asm/jump_arm_aapcs_macho_gas.S | 95 ++++++ .../src/asm/jump_arm_aapcs_pe_armasm.asm | 81 +++++ .../src/asm/jump_combined_sysv_macho_gas.S | 24 ++ .../src/asm/jump_i386_ms_pe_clang_gas.S | 123 ++++++++ .../context/src/asm/jump_i386_ms_pe_gas.asm | 123 ++++++++ .../context/src/asm/jump_i386_ms_pe_masm.asm | 116 ++++++++ .../context/src/asm/jump_i386_sysv_elf_gas.S | 93 ++++++ .../src/asm/jump_i386_sysv_macho_gas.S | 74 +++++ .../src/asm/jump_i386_x86_64_sysv_macho_gas.S | 16 + .../src/asm/jump_loongarch64_sysv_elf_gas.S | 121 ++++++++ .../context/src/asm/jump_mips32_o32_elf_gas.S | 119 ++++++++ .../context/src/asm/jump_mips64_n64_elf_gas.S | 124 ++++++++ .../src/asm/jump_ppc32_ppc64_sysv_macho_gas.S | 16 + .../context/src/asm/jump_ppc32_sysv_elf_gas.S | 201 +++++++++++++ .../src/asm/jump_ppc32_sysv_macho_gas.S | 201 +++++++++++++ .../src/asm/jump_ppc32_sysv_xcoff_gas.S | 216 ++++++++++++++ .../context/src/asm/jump_ppc64_sysv_elf_gas.S | 221 ++++++++++++++ .../src/asm/jump_ppc64_sysv_macho_gas.S | 164 +++++++++++ .../src/asm/jump_ppc64_sysv_xcoff_gas.S | 173 +++++++++++ .../src/asm/jump_riscv64_sysv_elf_gas.S | 150 ++++++++++ .../context/src/asm/jump_s390x_sysv_elf_gas.S | 156 ++++++++++ .../src/asm/jump_x86_64_ms_pe_clang_gas.S | 209 +++++++++++++ .../context/src/asm/jump_x86_64_ms_pe_gas.asm | 209 +++++++++++++ .../src/asm/jump_x86_64_ms_pe_masm.asm | 205 +++++++++++++ .../src/asm/jump_x86_64_sysv_elf_gas.S | 142 +++++++++ .../src/asm/jump_x86_64_sysv_macho_gas.S | 75 +++++ .../src/asm/make_arm64_aapcs_elf_gas.S | 85 ++++++ .../src/asm/make_arm64_aapcs_macho_gas.S | 83 ++++++ .../src/asm/make_arm64_aapcs_pe_armasm.asm | 107 +++++++ .../context/src/asm/make_arm_aapcs_elf_gas.S | 81 +++++ .../src/asm/make_arm_aapcs_macho_gas.S | 71 +++++ .../src/asm/make_arm_aapcs_pe_armasm.asm | 77 +++++ .../src/asm/make_combined_sysv_macho_gas.S | 24 ++ .../src/asm/make_i386_ms_pe_clang_gas.S | 153 ++++++++++ .../context/src/asm/make_i386_ms_pe_gas.asm | 153 ++++++++++ .../context/src/asm/make_i386_ms_pe_masm.asm | 140 +++++++++ .../context/src/asm/make_i386_sysv_elf_gas.S | 113 +++++++ .../src/asm/make_i386_sysv_macho_gas.S | 90 ++++++ .../src/asm/make_i386_x86_64_sysv_macho_gas.S | 16 + .../src/asm/make_loongarch64_sysv_elf_gas.S | 72 +++++ .../context/src/asm/make_mips32_o32_elf_gas.S | 97 ++++++ .../context/src/asm/make_mips64_n64_elf_gas.S | 96 ++++++ .../src/asm/make_ppc32_ppc64_sysv_macho_gas.S | 16 + .../context/src/asm/make_ppc32_sysv_elf_gas.S | 146 +++++++++ .../src/asm/make_ppc32_sysv_macho_gas.S | 154 ++++++++++ .../src/asm/make_ppc32_sysv_xcoff_gas.S | 125 ++++++++ .../context/src/asm/make_ppc64_sysv_elf_gas.S | 177 +++++++++++ .../src/asm/make_ppc64_sysv_macho_gas.S | 126 ++++++++ .../src/asm/make_ppc64_sysv_xcoff_gas.S | 137 +++++++++ .../src/asm/make_riscv64_sysv_elf_gas.S | 91 ++++++ .../context/src/asm/make_s390x_sysv_elf_gas.S | 108 +++++++ .../src/asm/make_x86_64_ms_pe_clang_gas.S | 174 +++++++++++ .../context/src/asm/make_x86_64_ms_pe_gas.asm | 174 +++++++++++ .../src/asm/make_x86_64_ms_pe_masm.asm | 163 +++++++++++ .../src/asm/make_x86_64_sysv_elf_gas.S | 147 ++++++++++ .../src/asm/make_x86_64_sysv_macho_gas.S | 76 +++++ .../src/asm/ontop_arm64_aapcs_elf_gas.S | 113 +++++++ .../src/asm/ontop_arm64_aapcs_macho_gas.S | 108 +++++++ .../src/asm/ontop_arm64_aapcs_pe_armasm.asm | 132 +++++++++ .../context/src/asm/ontop_arm_aapcs_elf_gas.S | 93 ++++++ .../src/asm/ontop_arm_aapcs_macho_gas.S | 100 +++++++ .../src/asm/ontop_arm_aapcs_pe_armasm.asm | 86 ++++++ .../src/asm/ontop_combined_sysv_macho_gas.S | 24 ++ .../src/asm/ontop_i386_ms_pe_clang_gas.S | 131 +++++++++ .../context/src/asm/ontop_i386_ms_pe_gas.asm | 131 +++++++++ .../context/src/asm/ontop_i386_ms_pe_masm.asm | 124 ++++++++ .../context/src/asm/ontop_i386_sysv_elf_gas.S | 100 +++++++ .../src/asm/ontop_i386_sysv_macho_gas.S | 81 +++++ .../asm/ontop_i386_x86_64_sysv_macho_gas.S | 16 + .../src/asm/ontop_loongarch64_sysv_elf_gas.S | 118 ++++++++ .../src/asm/ontop_mips32_o32_elf_gas.S | 120 ++++++++ .../src/asm/ontop_mips64_n64_elf_gas.S | 123 ++++++++ .../asm/ontop_ppc32_ppc64_sysv_macho_gas.S | 16 + .../src/asm/ontop_ppc32_sysv_elf_gas.S | 193 ++++++++++++ .../src/asm/ontop_ppc32_sysv_macho_gas.S | 201 +++++++++++++ .../src/asm/ontop_ppc32_sysv_xcoff_gas.S | 230 +++++++++++++++ .../src/asm/ontop_ppc64_sysv_elf_gas.S | 244 +++++++++++++++ .../src/asm/ontop_ppc64_sysv_macho_gas.S | 151 ++++++++++ .../src/asm/ontop_ppc64_sysv_xcoff_gas.S | 187 ++++++++++++ .../src/asm/ontop_riscv64_sysv_elf_gas.S | 149 ++++++++++ .../src/asm/ontop_s390x_sysv_elf_gas.S | 146 +++++++++ .../src/asm/ontop_x86_64_ms_pe_clang_gas.S | 211 +++++++++++++ .../src/asm/ontop_x86_64_ms_pe_gas.asm | 211 +++++++++++++ .../src/asm/ontop_x86_64_ms_pe_masm.asm | 207 +++++++++++++ .../src/asm/ontop_x86_64_sysv_elf_gas.S | 138 +++++++++ .../src/asm/ontop_x86_64_sysv_macho_gas.S | 78 +++++ .../context/src/asm/tail_ontop_ppc32_sysv.cpp | 16 + tile/fiber/detail/fiber.cc | 23 +- tile/fiber/detail/fiber.h | 3 + 104 files changed, 11696 insertions(+), 6 deletions(-) create mode 100644 third_party/context/.gitignore create mode 100644 third_party/context/CMakeLists.txt create mode 100644 third_party/context/LICENSE create mode 100644 third_party/context/cmake/CMakeASM_ARMASMInformation.cmake create mode 100644 third_party/context/cmake/CMakeDetermineASM_ARMASMCompiler.cmake create mode 100644 third_party/context/cmake/CMakeTestASM_ARMASMCompiler.cmake create mode 100644 third_party/context/include/nova/context/asan.h create mode 100644 third_party/context/include/nova/context/config.h create mode 100644 third_party/context/include/nova/context/fcontext.h create mode 100644 third_party/context/include/nova/context/tsan.h create mode 100644 third_party/context/src/asm/jump_arm64_aapcs_elf_gas.S create mode 100644 third_party/context/src/asm/jump_arm64_aapcs_macho_gas.S create mode 100644 third_party/context/src/asm/jump_arm64_aapcs_pe_armasm.asm create mode 100644 third_party/context/src/asm/jump_arm_aapcs_elf_gas.S create mode 100644 third_party/context/src/asm/jump_arm_aapcs_macho_gas.S create mode 100644 third_party/context/src/asm/jump_arm_aapcs_pe_armasm.asm create mode 100644 third_party/context/src/asm/jump_combined_sysv_macho_gas.S create mode 100644 third_party/context/src/asm/jump_i386_ms_pe_clang_gas.S create mode 100644 third_party/context/src/asm/jump_i386_ms_pe_gas.asm create mode 100644 third_party/context/src/asm/jump_i386_ms_pe_masm.asm create mode 100644 third_party/context/src/asm/jump_i386_sysv_elf_gas.S create mode 100644 third_party/context/src/asm/jump_i386_sysv_macho_gas.S create mode 100644 third_party/context/src/asm/jump_i386_x86_64_sysv_macho_gas.S create mode 100644 third_party/context/src/asm/jump_loongarch64_sysv_elf_gas.S create mode 100644 third_party/context/src/asm/jump_mips32_o32_elf_gas.S create mode 100644 third_party/context/src/asm/jump_mips64_n64_elf_gas.S create mode 100644 third_party/context/src/asm/jump_ppc32_ppc64_sysv_macho_gas.S create mode 100644 third_party/context/src/asm/jump_ppc32_sysv_elf_gas.S create mode 100644 third_party/context/src/asm/jump_ppc32_sysv_macho_gas.S create mode 100644 third_party/context/src/asm/jump_ppc32_sysv_xcoff_gas.S create mode 100644 third_party/context/src/asm/jump_ppc64_sysv_elf_gas.S create mode 100644 third_party/context/src/asm/jump_ppc64_sysv_macho_gas.S create mode 100644 third_party/context/src/asm/jump_ppc64_sysv_xcoff_gas.S create mode 100644 third_party/context/src/asm/jump_riscv64_sysv_elf_gas.S create mode 100644 third_party/context/src/asm/jump_s390x_sysv_elf_gas.S create mode 100644 third_party/context/src/asm/jump_x86_64_ms_pe_clang_gas.S create mode 100644 third_party/context/src/asm/jump_x86_64_ms_pe_gas.asm create mode 100644 third_party/context/src/asm/jump_x86_64_ms_pe_masm.asm create mode 100644 third_party/context/src/asm/jump_x86_64_sysv_elf_gas.S create mode 100644 third_party/context/src/asm/jump_x86_64_sysv_macho_gas.S create mode 100644 third_party/context/src/asm/make_arm64_aapcs_elf_gas.S create mode 100644 third_party/context/src/asm/make_arm64_aapcs_macho_gas.S create mode 100644 third_party/context/src/asm/make_arm64_aapcs_pe_armasm.asm create mode 100644 third_party/context/src/asm/make_arm_aapcs_elf_gas.S create mode 100644 third_party/context/src/asm/make_arm_aapcs_macho_gas.S create mode 100644 third_party/context/src/asm/make_arm_aapcs_pe_armasm.asm create mode 100644 third_party/context/src/asm/make_combined_sysv_macho_gas.S create mode 100644 third_party/context/src/asm/make_i386_ms_pe_clang_gas.S create mode 100644 third_party/context/src/asm/make_i386_ms_pe_gas.asm create mode 100644 third_party/context/src/asm/make_i386_ms_pe_masm.asm create mode 100644 third_party/context/src/asm/make_i386_sysv_elf_gas.S create mode 100644 third_party/context/src/asm/make_i386_sysv_macho_gas.S create mode 100644 third_party/context/src/asm/make_i386_x86_64_sysv_macho_gas.S create mode 100644 third_party/context/src/asm/make_loongarch64_sysv_elf_gas.S create mode 100644 third_party/context/src/asm/make_mips32_o32_elf_gas.S create mode 100644 third_party/context/src/asm/make_mips64_n64_elf_gas.S create mode 100644 third_party/context/src/asm/make_ppc32_ppc64_sysv_macho_gas.S create mode 100644 third_party/context/src/asm/make_ppc32_sysv_elf_gas.S create mode 100644 third_party/context/src/asm/make_ppc32_sysv_macho_gas.S create mode 100644 third_party/context/src/asm/make_ppc32_sysv_xcoff_gas.S create mode 100644 third_party/context/src/asm/make_ppc64_sysv_elf_gas.S create mode 100644 third_party/context/src/asm/make_ppc64_sysv_macho_gas.S create mode 100644 third_party/context/src/asm/make_ppc64_sysv_xcoff_gas.S create mode 100644 third_party/context/src/asm/make_riscv64_sysv_elf_gas.S create mode 100644 third_party/context/src/asm/make_s390x_sysv_elf_gas.S create mode 100644 third_party/context/src/asm/make_x86_64_ms_pe_clang_gas.S create mode 100644 third_party/context/src/asm/make_x86_64_ms_pe_gas.asm create mode 100644 third_party/context/src/asm/make_x86_64_ms_pe_masm.asm create mode 100644 third_party/context/src/asm/make_x86_64_sysv_elf_gas.S create mode 100644 third_party/context/src/asm/make_x86_64_sysv_macho_gas.S create mode 100644 third_party/context/src/asm/ontop_arm64_aapcs_elf_gas.S create mode 100644 third_party/context/src/asm/ontop_arm64_aapcs_macho_gas.S create mode 100644 third_party/context/src/asm/ontop_arm64_aapcs_pe_armasm.asm create mode 100644 third_party/context/src/asm/ontop_arm_aapcs_elf_gas.S create mode 100644 third_party/context/src/asm/ontop_arm_aapcs_macho_gas.S create mode 100644 third_party/context/src/asm/ontop_arm_aapcs_pe_armasm.asm create mode 100644 third_party/context/src/asm/ontop_combined_sysv_macho_gas.S create mode 100644 third_party/context/src/asm/ontop_i386_ms_pe_clang_gas.S create mode 100644 third_party/context/src/asm/ontop_i386_ms_pe_gas.asm create mode 100644 third_party/context/src/asm/ontop_i386_ms_pe_masm.asm create mode 100644 third_party/context/src/asm/ontop_i386_sysv_elf_gas.S create mode 100644 third_party/context/src/asm/ontop_i386_sysv_macho_gas.S create mode 100644 third_party/context/src/asm/ontop_i386_x86_64_sysv_macho_gas.S create mode 100644 third_party/context/src/asm/ontop_loongarch64_sysv_elf_gas.S create mode 100644 third_party/context/src/asm/ontop_mips32_o32_elf_gas.S create mode 100644 third_party/context/src/asm/ontop_mips64_n64_elf_gas.S create mode 100644 third_party/context/src/asm/ontop_ppc32_ppc64_sysv_macho_gas.S create mode 100644 third_party/context/src/asm/ontop_ppc32_sysv_elf_gas.S create mode 100644 third_party/context/src/asm/ontop_ppc32_sysv_macho_gas.S create mode 100644 third_party/context/src/asm/ontop_ppc32_sysv_xcoff_gas.S create mode 100644 third_party/context/src/asm/ontop_ppc64_sysv_elf_gas.S create mode 100644 third_party/context/src/asm/ontop_ppc64_sysv_macho_gas.S create mode 100644 third_party/context/src/asm/ontop_ppc64_sysv_xcoff_gas.S create mode 100644 third_party/context/src/asm/ontop_riscv64_sysv_elf_gas.S create mode 100644 third_party/context/src/asm/ontop_s390x_sysv_elf_gas.S create mode 100644 third_party/context/src/asm/ontop_x86_64_ms_pe_clang_gas.S create mode 100644 third_party/context/src/asm/ontop_x86_64_ms_pe_gas.asm create mode 100644 third_party/context/src/asm/ontop_x86_64_ms_pe_masm.asm create mode 100644 third_party/context/src/asm/ontop_x86_64_sysv_elf_gas.S create mode 100644 third_party/context/src/asm/ontop_x86_64_sysv_macho_gas.S create mode 100644 third_party/context/src/asm/tail_ontop_ppc32_sysv.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index fff12c3..59a083b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -64,6 +64,7 @@ get_git_commit_subject(GIT_COMMIT_SUBJECT) include_directories("third_party/json" "third_party/inja" "third_party/sigslot") include_directories("${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include") +add_subdirectory("third_party/context") add_subdirectory("third_party/zlib") add_subdirectory("third_party/fmt") add_subdirectory("third_party/googletest") @@ -220,9 +221,14 @@ target_include_directories( target_link_libraries( tile PUBLIC # -Wl,--start-group - zlib gflags::gflags glog::glog + nova_context + zlib + gflags::gflags + glog::glog # -Wl,--end-group - libcurl fmt Threads::Threads) + libcurl + fmt + Threads::Threads) if((CMAKE_SYSTEM_PROCESSOR MATCHES "riscv64") OR (CMAKE_SYSTEM_PROCESSOR MATCHES "mips*")) if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") diff --git a/third_party/context/.gitignore b/third_party/context/.gitignore new file mode 100644 index 0000000..f700568 --- /dev/null +++ b/third_party/context/.gitignore @@ -0,0 +1,59 @@ +# .gitignore - The Nova Project + +# Prerequisites +*.d + +# Object files +*.o +*.ko +*.obj +*.elf + +# Linker output +*.ilk +*.map +*.exp + +# Precompiled Headers +*.gch +*.pch + +# Libraries +*.lib +*.a +*.la +*.lo + +# Shared objects (inc. Windows DLLs) +*.dll +*.so +*.so.* +*.dylib + +# Executables +*.exe +*.out +*.app +*.i*86 +*.x86_64 +*.hex + +# Debug files +*.dSYM/ +*.su +*.idb +*.pdb + +# CMake +build/ +cmake-build/ +CMakeLists.txt.user +CMakeCache.txt +CMakeFiles +CMakeScripts +Makefile +cmake_install.cmake +install_manifest.txt +compile_commands.json +CTestTestfile.cmake +_deps diff --git a/third_party/context/CMakeLists.txt b/third_party/context/CMakeLists.txt new file mode 100644 index 0000000..5174108 --- /dev/null +++ b/third_party/context/CMakeLists.txt @@ -0,0 +1,277 @@ +# Nova-Context This file is part of the Nova-Context library source code. +# Copyright (c) 2023 - The Nova Project +# +# Parts of this build configuration have been brazenly stolen from the +# boost.context foundational library: https://github.com/boostorg/context +# Copyright (c) 2009 - Oliver Kowalke, licensed under the Boost Software License +# 1.0: http://www.boost.org/LICENSE_1_0.txt + +cmake_minimum_required(VERSION 3.5...3.16) +project( + nova_context + VERSION 0.1.0 + LANGUAGES C) + +list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) + +option(NOVA_CONTEXT_BUILD_STATIC "Build Nova-Context as static library" ON) +# option(NOVA_CONTEXT_BUILD_TEST "Nova-Context build test app" OFF) +option(NOVA_CONTEXT_PIC + "Compile Nova-Context with position independent code (PIC)" ON) +option(NOVA_CONTEXT_INSTALL "Generate installation target for Nova-Context" OFF) + +# Binary format +if(WIN32) + set(_default_binfmt pe) +elseif(APPLE) + set(_default_binfmt mach-o) +else() + set(_default_binfmt elf) +endif() + +set(NOVA_CONTEXT_BINARY_FORMAT + "${_default_binfmt}" + CACHE STRING "Nova-Context binary format (elf, mach-o, pe, xcoff)") +set_property(CACHE NOVA_CONTEXT_BINARY_FORMAT PROPERTY STRINGS elf mach-o pe + xcoff) +unset(_default_binfmt) + +# ABI +math(EXPR _bits "${CMAKE_SIZEOF_VOID_P} * 8") + +if(CMAKE_SYSTEM_PROCESSOR MATCHES "^[Aa][Rr][Mm]" OR CMAKE_SYSTEM_PROCESSOR + STREQUAL "aarch64") + set(_default_abi aapcs) +elseif(WIN32) + set(_default_abi ms) +elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^mips") + if(_bits EQUAL 32) + set(_default_abi o32) + else() + set(_default_abi n64) + endif() +else() + set(_default_abi sysv) +endif() + +set(NOVA_CONTEXT_ABI + "${_default_abi}" + CACHE STRING + "Nova-Context ABI (aapcs, eabi, ms, n32, n64, o32, o64, sysv, x32)") +set_property( + CACHE NOVA_CONTEXT_ABI + PROPERTY STRINGS + aapcs + eabi + ms + n32 + n64 + o32 + o64 + sysv + x32) +unset(_default_abi) + +# Arch-and-model +set(_all_archs + arm + arm64 + loongarch64 + mips32 + mips64 + ppc32 + ppc64 + riscv64 + s390x + i386 + x86_64 + combined) + +# Try at start to auto determine arch from CMake. +if(CMAKE_SYSTEM_PROCESSOR IN_LIST _all_archs) + set(_default_arch ${CMAKE_SYSTEM_PROCESSOR}) +elseif(_bits EQUAL 32) + if(CMAKE_SYSTEM_PROCESSOR MATCHES "^[Aa][Rr][Mm]") + set(_default_arch arm) + elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^mips") + set(_default_arch mips32) + else() + set(_default_arch i386) + endif() +else() + if(CMAKE_SYSTEM_PROCESSOR MATCHES "^[Aa][Rr][Mm]" OR CMAKE_SYSTEM_PROCESSOR + STREQUAL "aarch64" + )# armv8 + set(_default_arch arm64) + elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^mips") + set(_default_arch mips64) + else() + set(_default_arch x86_64) + endif() +endif() + +set(NOVA_CONTEXT_ARCHITECTURE + "${_default_arch}" + CACHE + STRING + "Nova-Context architecture (arm, arm64, loongarch64, mips32, mips64, ppc32, ppc64, riscv64, s390x, i386, x86_64, combined)" +) +set_property(CACHE NOVA_CONTEXT_ARCHITECTURE PROPERTY STRINGS ${_all_archs}) + +unset(_all_archs) +unset(_bits) +unset(_default_arch) + +# Assembler type +if(MSVC) + if(NOVA_CONTEXT_ARCHITECTURE STREQUAL arm64 OR NOVA_CONTEXT_ARCHITECTURE + STREQUAL arm) + set(_default_asm armasm) + else() + set(_default_asm masm) + endif() +else() + set(_default_asm gas) +endif() + +set(NOVA_CONTEXT_ASSEMBLER + "${_default_asm}" + CACHE STRING "Nova-Context assembler (masm, gas, armasm)") +set_property(CACHE NOVA_CONTEXT_ASSEMBLER PROPERTY STRINGS masm gas armasm) +unset(_default_asm) + +# Assembler source suffix +if(NOVA_CONTEXT_BINARY_FORMAT STREQUAL pe) + set(_default_ext .asm) +elseif(NOVA_CONTEXT_ASSEMBLER STREQUAL gas) + set(_default_ext .S) +else() + set(_default_ext .asm) +endif() + +set(NOVA_CONTEXT_ASM_SUFFIX + "${_default_ext}" + CACHE STRING "Nova-Context assembler source suffix (.asm, .S)") +set_property(CACHE NOVA_CONTEXT_ASM_SUFFIX PROPERTY STRINGS .asm .S) +unset(_default_ext) + +message( + STATUS "Nova-Context: " + "architecture ${NOVA_CONTEXT_ARCHITECTURE}, " + "binary format ${NOVA_CONTEXT_BINARY_FORMAT}, " + "ABI ${NOVA_CONTEXT_ABI}, " + "assembler ${NOVA_CONTEXT_ASSEMBLER}, " + "suffix ${NOVA_CONTEXT_ASM_SUFFIX}") + +# Enable the right assembler +if(NOVA_CONTEXT_ASSEMBLER STREQUAL gas) + if(CMAKE_CXX_PLATFORM_ID MATCHES "Cygwin") + enable_language(CXX ASM-ATT) + else() + enable_language(CXX ASM) + endif() +elseif(NOVA_CONTEXT_ASSEMBLER STREQUAL armasm) + enable_language(CXX ASM_ARMASM) +else() + enable_language(CXX ASM_MASM) + + # NOTE(julian): workaround for CMake MSVC ASM_MASM building bug #18889: + # https://gitlab.kitware.com/cmake/cmake/-/issues/18889 + set(CMAKE_ASM_MASM_CREATE_STATIC_LIBRARY + " ${CMAKE_CL_NOLOGO} /out: ") +endif() + +# Choose .asm sources +if(NOVA_CONTEXT_BINARY_FORMAT STREQUAL mach-o) + set(NOVA_CONTEXT_BINARY_FORMAT macho) +endif() + +set(_asm_suffix + "${NOVA_CONTEXT_ARCHITECTURE}_${NOVA_CONTEXT_ABI}_${NOVA_CONTEXT_BINARY_FORMAT}_${NOVA_CONTEXT_ASSEMBLER}${NOVA_CONTEXT_ASM_SUFFIX}" +) + +set(ASM_SRC + ${CMAKE_CURRENT_SOURCE_DIR}/src/asm/make_${_asm_suffix} + ${CMAKE_CURRENT_SOURCE_DIR}/src/asm/jump_${_asm_suffix} + ${CMAKE_CURRENT_SOURCE_DIR}/src/asm/ontop_${_asm_suffix}) + +unset(_asm_suffix) + +# POWERPC_32/SYSV Special case: https://github.com/boostorg/context/issues/120 +if((NOVA_CONTEXT_ARCHITECTURE STREQUAL ppc32) AND (NOVA_CONTEXT_ABI STREQUAL + sysv)) + string(APPEND ASM_SRC " ${CMAKE_CURRENT_SOURCE_DIR}/asm/tail_ppc32_sysv.cpp") +endif() + +# Assembly source file properties +if(NOVA_CONTEXT_ASSEMBLER STREQUAL masm AND NOVA_CONTEXT_ARCHITECTURE STREQUAL + i386) + set_source_files_properties(${ASM_SRC} PROPERTIES COMPILE_FLAGS "/safeseh") +endif() + +if(CMAKE_CXX_COMPILER_ID STREQUAL GNU) + set_source_files_properties(${ASM_SRC} PROPERTIES COMPILE_OPTIONS + "-x assembler-with-cpp") +endif() + +# Boost specific definitions +if(MSVC) + add_definitions(-D_ITERATOR_DEBUG_LEVEL=0) + add_definitions(-D_HAS_EXCEPTIONS=0) +endif() + +# Find project sources +file(GLOB_RECURSE INC ${CMAKE_CURRENT_SOURCE_DIR}/include/*.h) +file(GLOB_RECURSE SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/*.c) + +# Create target +if(NOVA_CONTEXT_BUILD_STATIC) + add_library(nova_context STATIC ${INC} ${SRC} ${ASM_SRC}) + target_compile_definitions(nova_context PUBLIC NOVA_CONTEXT_STATIC + BOOST_CONTEXT_EXPORT=) +else() + add_library(nova_context SHARED ${INC} ${SRC} ${ASM_SRC}) + target_compile_definitions(nova_context PUBLIC BOOST_CONTEXT_EXPORT=EXPORT) +endif() + +# Link threading system dependencies if(WIN32) +# target_link_libraries(nova_context wsock32 ws2_32) endif() if +# (CMAKE_SYSTEM_NAME STREQUAL "Linux") target_link_libraries(nova_context +# pthread) endif() + +# Position-independent code +if(NOVA_CONTEXT_PIC) + set_target_properties(nova_context PROPERTIES POSITION_INDEPENDENT_CODE ON) +endif() + +# Include directories +target_include_directories( + nova_context PUBLIC $ + $) + +if(NOVA_CONTEXT_BUILD_TEST) + # TODO(julian): Build test project +endif() + +# Install library +if(NOVA_CONTEXT_INSTALL) + include(GNUInstallDirs) + + install( + DIRECTORY ${PROJECT_SOURCE_DIR}/include/ + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + FILES_MATCHING + PATTERN *.h) + + install( + TARGETS nova_context + EXPORT nova-context-export + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + + install( + EXPORT nova-context-export + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/nova-context + FILE nova-context-config.cmake) +endif() diff --git a/third_party/context/LICENSE b/third_party/context/LICENSE new file mode 100644 index 0000000..48d0908 --- /dev/null +++ b/third_party/context/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 Julian Schönbächler + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/third_party/context/cmake/CMakeASM_ARMASMInformation.cmake b/third_party/context/cmake/CMakeASM_ARMASMInformation.cmake new file mode 100644 index 0000000..796cdbf --- /dev/null +++ b/third_party/context/cmake/CMakeASM_ARMASMInformation.cmake @@ -0,0 +1,13 @@ +# For the armasm assembler, armasm or armasm64 +set(ASM_DIALECT "_ARMASM") +set(CMAKE_ASM${ASM_DIALECT}_SOURCE_FILE_EXTENSIONS asm) +set(CMAKE_ASM${ASM_DIALECT}_COMPILE_OBJECT " -o ") + +# The ASM_ARMASM compiler id for this compiler is "MSVC", so fill out the runtime library table. +set(CMAKE_ASM${ASM_DIALECT}_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreaded "") +set(CMAKE_ASM${ASM_DIALECT}_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDLL "") +set(CMAKE_ASM${ASM_DIALECT}_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDebug "") +set(CMAKE_ASM${ASM_DIALECT}_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDebugDLL "") + +include(CMakeASMInformation) +set(ASM_DIALECT) diff --git a/third_party/context/cmake/CMakeDetermineASM_ARMASMCompiler.cmake b/third_party/context/cmake/CMakeDetermineASM_ARMASMCompiler.cmake new file mode 100644 index 0000000..30efd3d --- /dev/null +++ b/third_party/context/cmake/CMakeDetermineASM_ARMASMCompiler.cmake @@ -0,0 +1,12 @@ +# Find the armasm assembler, armasm or armasm64 +set(ASM_DIALECT "_ARMASM") + +# If we are using the 64bit cl compiler, assume we also want the 64bit assembler +if (";${CMAKE_VS_PLATFORM_NAME};${MSVC_C_ARCHITECTURE_ID};${MSVC_CXX_ARCHITECTURE_ID};" MATCHES ";ARM64;") + set(CMAKE_ASM${ASM_DIALECT}_COMPILER_INIT armasm64) +else () + set(CMAKE_ASM${ASM_DIALECT}_COMPILER_INIT armasm) +endif () + +include(CMakeDetermineASMCompiler) +set(ASM_DIALECT) diff --git a/third_party/context/cmake/CMakeTestASM_ARMASMCompiler.cmake b/third_party/context/cmake/CMakeTestASM_ARMASMCompiler.cmake new file mode 100644 index 0000000..ddaf928 --- /dev/null +++ b/third_party/context/cmake/CMakeTestASM_ARMASMCompiler.cmake @@ -0,0 +1,13 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file Copyright.txt or https://cmake.org/licensing for details. + + +# This file is used by EnableLanguage in cmGlobalGenerator to +# determine that the selected ASM_MASM "compiler" (should be masm or masm64) +# works. For assembler this can only check whether the compiler has been found, +# because otherwise there would have to be a separate assembler source file +# for each assembler on every architecture. + +set(ASM_DIALECT "_ARMASM") +include(CMakeTestASMCompiler) +set(ASM_DIALECT) diff --git a/third_party/context/include/nova/context/asan.h b/third_party/context/include/nova/context/asan.h new file mode 100644 index 0000000..ca03c22 --- /dev/null +++ b/third_party/context/include/nova/context/asan.h @@ -0,0 +1,26 @@ +/* + * Nova-Context + * This file is part of the Nova-Context library source code. + * Copyright (c) 2023 - The Nova Project + */ + +#ifndef NOVA_CONTEXT_ASAN_H +#define NOVA_CONTEXT_ASAN_H + +#if defined(__SANITIZE_ADDRESS__) || __has_feature(address_sanitizer) + #define NOVA_CONTEXT_ASAN + + #ifdef __cplusplus +extern "C" { + #endif + +void __sanitizer_start_switch_fiber(void **fake_stack_save, const void *bottom, size_t size); +void __sanitizer_finish_switch_fiber(void *fake_stack_save, const void **bottom_old, size_t *size_old); + + #ifdef __cplusplus +} + #endif + +#endif + +#endif //NOVA_CONTEXT_ASAN_H diff --git a/third_party/context/include/nova/context/config.h b/third_party/context/include/nova/context/config.h new file mode 100644 index 0000000..73b56d7 --- /dev/null +++ b/third_party/context/include/nova/context/config.h @@ -0,0 +1,34 @@ +/* + * Nova-Context + * This file is part of the Nova-Context library source code. + * Copyright (c) 2023 - The Nova Project + */ + +#ifndef NOVA_CONTEXT_CONFIG_H +#define NOVA_CONTEXT_CONFIG_H + +#ifndef NOVA_CONTEXT_STATIC + #ifdef nova_context_EXPORTS + #if defined(_MSC_VER) || defined(__MINGW32__) + #define NOVA_CONTEXT_API __declspec(dllexport) + #else + #define NOVA_CONTEXT_API __attribute__((__visibility__("default"))) + #endif + #elif defined(_MSC_VER) + #define NOVA_CONTEXT_API __declspec(dllimport) + #endif +#else + #define NOVA_CONTEXT_API +#endif + +#if (defined(i386) || defined(__i386__) || defined(__i386) || \ + defined(__i486__) || defined(__i586__) || defined(__i686__) || \ + defined(__X86__) || defined(_X86_) || defined(__THW_INTEL__) || \ + defined(__I86__) || defined(__INTEL__) || defined(__IA32__) || \ + defined(_M_IX86) || defined(_I86_)) && defined(BOOST_WINDOWS) + #define NOVA_CONTEXT_CALLDECL __cdecl +#else + #define NOVA_CONTEXT_CALLDECL +#endif + +#endif //NOVA_CONTEXT_CONFIG_H diff --git a/third_party/context/include/nova/context/fcontext.h b/third_party/context/include/nova/context/fcontext.h new file mode 100644 index 0000000..63373a4 --- /dev/null +++ b/third_party/context/include/nova/context/fcontext.h @@ -0,0 +1,42 @@ +/* + * Nova-Context + * This file is part of the Nova-Context library source code. + * Copyright (c) 2023 - The Nova Project + */ + +#ifndef NOVA_CONTEXT_FCONTEXT_H +#define NOVA_CONTEXT_FCONTEXT_H + +#include +#include +#include "config.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef void *fcontext_t; + +typedef struct fcontext_transfer +{ + fcontext_t fctx; + void *data; +} fcontext_transfer_t; + +NOVA_CONTEXT_API +fcontext_t NOVA_CONTEXT_CALLDECL +make_fcontext(void *sp, size_t size, void (*fn)(fcontext_transfer_t)); + +NOVA_CONTEXT_API +fcontext_transfer_t NOVA_CONTEXT_CALLDECL +jump_fcontext(fcontext_t const to, void *vp); + +NOVA_CONTEXT_API +fcontext_transfer_t NOVA_CONTEXT_CALLDECL +ontop_fcontext(fcontext_t const to, void *vp, fcontext_transfer_t (*fn)(fcontext_transfer_t)); + +#ifdef __cplusplus +} +#endif + +#endif //NOVA_CONTEXT_FCONTEXT_H diff --git a/third_party/context/include/nova/context/tsan.h b/third_party/context/include/nova/context/tsan.h new file mode 100644 index 0000000..c6275bc --- /dev/null +++ b/third_party/context/include/nova/context/tsan.h @@ -0,0 +1,28 @@ +/* + * Nova-Context + * This file is part of the Nova-Context library source code. + * Copyright (c) 2023 - The Nova Project + */ + +#ifndef NOVA_CONTEXT_TSAN_H +#define NOVA_CONTEXT_TSAN_H + +#if defined(__SANITIZER_THREAD__) || __has_feature(thread_sanitizer) + #define NOVA_CONTEXT_TSAN + + #ifdef __cplusplus +extern "C" { + #endif + +void *__tsan_get_current_fiber(void); +void *__tsan_create_fiber(unsigned flags); +void __tsan_destroy_fiber(void *fiber); +void __tsan_switch_to_fiber(void *fiber, unsigned flags); + + #ifdef __cplusplus +} + #endif + +#endif + +#endif //NOVA_CONTEXT_TSAN_H diff --git a/third_party/context/src/asm/jump_arm64_aapcs_elf_gas.S b/third_party/context/src/asm/jump_arm64_aapcs_elf_gas.S new file mode 100644 index 0000000..cefd183 --- /dev/null +++ b/third_party/context/src/asm/jump_arm64_aapcs_elf_gas.S @@ -0,0 +1,114 @@ +/* + Copyright Edward Nevill + Oliver Kowalke 2015 + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ +/******************************************************* + * * + * ------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ------------------------------------------------- * + * | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| * + * ------------------------------------------------- * + * | d8 | d9 | d10 | d11 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ------------------------------------------------- * + * | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| * + * ------------------------------------------------- * + * | d12 | d13 | d14 | d15 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * + * ------------------------------------------------- * + * | 0x40| 0x44| 0x48| 0x4c| 0x50| 0x54| 0x58| 0x5c| * + * ------------------------------------------------- * + * | x19 | x20 | x21 | x22 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * + * ------------------------------------------------- * + * | 0x60| 0x64| 0x68| 0x6c| 0x70| 0x74| 0x78| 0x7c| * + * ------------------------------------------------- * + * | x23 | x24 | x25 | x26 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * + * ------------------------------------------------- * + * | 0x80| 0x84| 0x88| 0x8c| 0x90| 0x94| 0x98| 0x9c| * + * ------------------------------------------------- * + * | x27 | x28 | FP | LR | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 40 | 41 | 42 | 43 | | | * + * ------------------------------------------------- * + * | 0xa0| 0xa4| 0xa8| 0xac| | | * + * ------------------------------------------------- * + * | PC | align | | | * + * ------------------------------------------------- * + * * + *******************************************************/ + +.file "jump_arm64_aapcs_elf_gas.S" +.text +.align 2 +.global jump_fcontext +.type jump_fcontext, %function +jump_fcontext: + # prepare stack for GP + FPU + sub sp, sp, #0xb0 + + # save d8 - d15 + stp d8, d9, [sp, #0x00] + stp d10, d11, [sp, #0x10] + stp d12, d13, [sp, #0x20] + stp d14, d15, [sp, #0x30] + + # save x19-x30 + stp x19, x20, [sp, #0x40] + stp x21, x22, [sp, #0x50] + stp x23, x24, [sp, #0x60] + stp x25, x26, [sp, #0x70] + stp x27, x28, [sp, #0x80] + stp x29, x30, [sp, #0x90] + + # save LR as PC + str x30, [sp, #0xa0] + + # store RSP (pointing to context-data) in X0 + mov x4, sp + + # restore RSP (pointing to context-data) from X1 + mov sp, x0 + + # load d8 - d15 + ldp d8, d9, [sp, #0x00] + ldp d10, d11, [sp, #0x10] + ldp d12, d13, [sp, #0x20] + ldp d14, d15, [sp, #0x30] + + # load x19-x30 + ldp x19, x20, [sp, #0x40] + ldp x21, x22, [sp, #0x50] + ldp x23, x24, [sp, #0x60] + ldp x25, x26, [sp, #0x70] + ldp x27, x28, [sp, #0x80] + ldp x29, x30, [sp, #0x90] + + # return transfer_t from jump + # pass transfer_t as first arg in context function + # X0 == FCTX, X1 == DATA + mov x0, x4 + + # load pc + ldr x4, [sp, #0xa0] + + # restore stack from GP + FPU + add sp, sp, #0xb0 + + ret x4 +.size jump_fcontext,.-jump_fcontext +# Mark that we don't need executable stack. +.section .note.GNU-stack,"",%progbits diff --git a/third_party/context/src/asm/jump_arm64_aapcs_macho_gas.S b/third_party/context/src/asm/jump_arm64_aapcs_macho_gas.S new file mode 100644 index 0000000..31738f7 --- /dev/null +++ b/third_party/context/src/asm/jump_arm64_aapcs_macho_gas.S @@ -0,0 +1,109 @@ +/* + Copyright Edward Nevill + Oliver Kowalke 2015 + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ +/******************************************************* + * * + * ------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ------------------------------------------------- * + * | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| * + * ------------------------------------------------- * + * | d8 | d9 | d10 | d11 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ------------------------------------------------- * + * | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| * + * ------------------------------------------------- * + * | d12 | d13 | d14 | d15 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * + * ------------------------------------------------- * + * | 0x40| 0x44| 0x48| 0x4c| 0x50| 0x54| 0x58| 0x5c| * + * ------------------------------------------------- * + * | x19 | x20 | x21 | x22 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * + * ------------------------------------------------- * + * | 0x60| 0x64| 0x68| 0x6c| 0x70| 0x74| 0x78| 0x7c| * + * ------------------------------------------------- * + * | x23 | x24 | x25 | x26 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * + * ------------------------------------------------- * + * | 0x80| 0x84| 0x88| 0x8c| 0x90| 0x94| 0x98| 0x9c| * + * ------------------------------------------------- * + * | x27 | x28 | FP | LR | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 40 | 41 | 42 | 43 | | | * + * ------------------------------------------------- * + * | 0xa0| 0xa4| 0xa8| 0xac| | | * + * ------------------------------------------------- * + * | PC | align | | | * + * ------------------------------------------------- * + * * + *******************************************************/ + +.text +.globl _jump_fcontext +.balign 16 +_jump_fcontext: + ; prepare stack for GP + FPU + sub sp, sp, #0xb0 + + ; save d8 - d15 + stp d8, d9, [sp, #0x00] + stp d10, d11, [sp, #0x10] + stp d12, d13, [sp, #0x20] + stp d14, d15, [sp, #0x30] + + ; save x19-x30 + stp x19, x20, [sp, #0x40] + stp x21, x22, [sp, #0x50] + stp x23, x24, [sp, #0x60] + stp x25, x26, [sp, #0x70] + stp x27, x28, [sp, #0x80] + stp fp, lr, [sp, #0x90] + + ; save LR as PC + str lr, [sp, #0xa0] + + ; store RSP (pointing to context-data) in X0 + mov x4, sp + + ; restore RSP (pointing to context-data) from X1 + mov sp, x0 + + ; load d8 - d15 + ldp d8, d9, [sp, #0x00] + ldp d10, d11, [sp, #0x10] + ldp d12, d13, [sp, #0x20] + ldp d14, d15, [sp, #0x30] + + ; load x19-x30 + ldp x19, x20, [sp, #0x40] + ldp x21, x22, [sp, #0x50] + ldp x23, x24, [sp, #0x60] + ldp x25, x26, [sp, #0x70] + ldp x27, x28, [sp, #0x80] + ldp fp, lr, [sp, #0x90] + + ; return transfer_t from jump + ; pass transfer_t as first arg in context function + ; X0 == FCTX, X1 == DATA + mov x0, x4 + + ; load pc + ldr x4, [sp, #0xa0] + + ; restore stack from GP + FPU + add sp, sp, #0xb0 + + ret x4 diff --git a/third_party/context/src/asm/jump_arm64_aapcs_pe_armasm.asm b/third_party/context/src/asm/jump_arm64_aapcs_pe_armasm.asm new file mode 100644 index 0000000..3100243 --- /dev/null +++ b/third_party/context/src/asm/jump_arm64_aapcs_pe_armasm.asm @@ -0,0 +1,133 @@ +; Copyright Edward Nevill + Oliver Kowalke 2015 +; Distributed under the Boost Software License, Version 1.0. +; (See accompanying file LICENSE_1_0.txt or copy at +; http://www.boost.org/LICENSE_1_0.txt) + +;******************************************************* +;* * +;* ------------------------------------------------- * +;* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * +;* ------------------------------------------------- * +;* | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| * +;* ------------------------------------------------- * +;* | d8 | d9 | d10 | d11 | * +;* ------------------------------------------------- * +;* ------------------------------------------------- * +;* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * +;* ------------------------------------------------- * +;* | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| * +;* ------------------------------------------------- * +;* | d12 | d13 | d14 | d15 | * +;* ------------------------------------------------- * +;* ------------------------------------------------- * +;* | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * +;* ------------------------------------------------- * +;* | 0x40| 0x44| 0x48| 0x4c| 0x50| 0x54| 0x58| 0x5c| * +;* ------------------------------------------------- * +;* | x19 | x20 | x21 | x22 | * +;* ------------------------------------------------- * +;* ------------------------------------------------- * +;* | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * +;* ------------------------------------------------- * +;* | 0x60| 0x64| 0x68| 0x6c| 0x70| 0x74| 0x78| 0x7c| * +;* ------------------------------------------------- * +;* | x23 | x24 | x25 | x26 | * +;* ------------------------------------------------- * +;* ------------------------------------------------- * +;* | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * +;* ------------------------------------------------- * +;* | 0x80| 0x84| 0x88| 0x8c| 0x90| 0x94| 0x98| 0x9c| * +;* ------------------------------------------------- * +;* | x27 | x28 | FP | LR | * +;* ------------------------------------------------- * +;* ------------------------------------------------- * +;* | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | * +;* ------------------------------------------------- * +;* | 0xa0| 0xa4| 0xa8| 0xac| 0xb0| 0xb4| 0xb8| 0xbc| * +;* ------------------------------------------------- * +;* | fiber data| base | limit | dealloc | * +;* ------------------------------------------------- * +;* ------------------------------------------------- * +;* | 48 | 49 | 50 | 51 | | | * +;* ------------------------------------------------- * +;* | 0xc0| 0xc4| 0xc8| 0xcc| | | * +;* ------------------------------------------------- * +;* | PC | align | | | * +;* ------------------------------------------------- * +;* * +;******************************************************* + + AREA |.text|, CODE, READONLY, ALIGN=4, CODEALIGN + EXPORT jump_fcontext + +jump_fcontext proc + ; prepare stack for GP + FPU + sub sp, sp, #0xd0 + + ; save d8 - d15 + stp d8, d9, [sp, #0x00] + stp d10, d11, [sp, #0x10] + stp d12, d13, [sp, #0x20] + stp d14, d15, [sp, #0x30] + + ; save x19-x30 + stp x19, x20, [sp, #0x40] + stp x21, x22, [sp, #0x50] + stp x23, x24, [sp, #0x60] + stp x25, x26, [sp, #0x70] + stp x27, x28, [sp, #0x80] + stp x29, x30, [sp, #0x90] + + ; save LR as PC + str x30, [sp, #0xc0] + + ; save current stack base and limit + ldp x5, x6, [x18, #0x08] ; TeStackBase and TeStackLimit at ksarm64.h + stp x5, x6, [sp, #0xa0] + ; save current fiber data and deallocation stack + ldr x5, [x18, #0x1478] ; TeDeallocationStack at ksarm64.h + ldr x6, [x18, #0x20] ; TeFiberData at ksarm64.h + stp x5, x6, [sp, #0xb0] + + ; store RSP (pointing to context-data) in X0 + mov x4, sp + + ; restore RSP (pointing to context-data) from X1 + mov sp, x0 + + ; restore stack base and limit + ldp x5, x6, [sp, #0xa0] + stp x5, x6, [x18, #0x08] ; TeStackBase and TeStackLimit at ksarm64.h + ; restore fiber data and deallocation stack + ldp x5, x6, [sp, #0xb0] + str x5, [x18, #0x1478] ; TeDeallocationStack at ksarm64.h + str x6, [x18, #0x20] ; TeFiberData at ksarm64.h + + ; load d8 - d15 + ldp d8, d9, [sp, #0x00] + ldp d10, d11, [sp, #0x10] + ldp d12, d13, [sp, #0x20] + ldp d14, d15, [sp, #0x30] + + ; load x19-x30 + ldp x19, x20, [sp, #0x40] + ldp x21, x22, [sp, #0x50] + ldp x23, x24, [sp, #0x60] + ldp x25, x26, [sp, #0x70] + ldp x27, x28, [sp, #0x80] + ldp x29, x30, [sp, #0x90] + + ; return transfer_t from jump + ; pass transfer_t as first arg in context function + ; X0 == FCTX, X1 == DATA + mov x0, x4 + + ; load pc + ldr x4, [sp, #0xc0] + + ; restore stack from GP + FPU + add sp, sp, #0xd0 + + ret x4 + ENDP + END \ No newline at end of file diff --git a/third_party/context/src/asm/jump_arm_aapcs_elf_gas.S b/third_party/context/src/asm/jump_arm_aapcs_elf_gas.S new file mode 100644 index 0000000..86efe9d --- /dev/null +++ b/third_party/context/src/asm/jump_arm_aapcs_elf_gas.S @@ -0,0 +1,88 @@ +/* + Copyright Oliver Kowalke 2009. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/******************************************************* + * * + * ------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ------------------------------------------------- * + * | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| * + * ------------------------------------------------- * + * | s16 | s17 | s18 | s19 | s20 | s21 | s22 | s23 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ------------------------------------------------- * + * | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| * + * ------------------------------------------------- * + * | s24 | s25 | s26 | s27 | s28 | s29 | s30 | s31 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * + * ------------------------------------------------- * + * | 0x40| 0x44| 0x48| 0x4c| 0x50| 0x54| 0x58| 0x5c| * + * ------------------------------------------------- * + * |hiddn| v1 | v2 | v3 | v4 | v5 | v6 | v7 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * + * ------------------------------------------------- * + * | 0x60| 0x64| 0x68| 0x6c| 0x70| 0x74| 0x78| 0x7c| * + * ------------------------------------------------- * + * | v8 | lr | pc | FCTX| DATA| | * + * ------------------------------------------------- * + * * + *******************************************************/ + +.file "jump_arm_aapcs_elf_gas.S" +.text +.globl jump_fcontext +.align 2 +.type jump_fcontext,%function +.syntax unified +jump_fcontext: + @ save LR as PC + push {lr} + @ save hidden,V1-V8,LR + push {a1,v1-v8,lr} + + @ prepare stack for FPU + sub sp, sp, #64 +#if (defined(__VFP_FP__) && !defined(__SOFTFP__)) + @ save S16-S31 + vstmia sp, {d8-d15} +#endif + + @ store RSP (pointing to context-data) in A1 + mov a1, sp + + @ restore RSP (pointing to context-data) from A2 + mov sp, a2 + +#if (defined(__VFP_FP__) && !defined(__SOFTFP__)) + @ restore S16-S31 + vldmia sp, {d8-d15} +#endif + @ prepare stack for FPU + add sp, sp, #64 + + @ restore hidden,V1-V8,LR + pop {a4,v1-v8,lr} + + @ return transfer_t from jump + str a1, [a4, #0] + str a3, [a4, #4] + @ pass transfer_t as first arg in context function + @ A1 == FCTX, A2 == DATA + mov a2, a3 + + @ restore PC + pop {pc} +.size jump_fcontext,.-jump_fcontext + +@ Mark that we don't need executable stack. +.section .note.GNU-stack,"",%progbits diff --git a/third_party/context/src/asm/jump_arm_aapcs_macho_gas.S b/third_party/context/src/asm/jump_arm_aapcs_macho_gas.S new file mode 100644 index 0000000..077c364 --- /dev/null +++ b/third_party/context/src/asm/jump_arm_aapcs_macho_gas.S @@ -0,0 +1,95 @@ +/* + Copyright Oliver Kowalke 2009. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/******************************************************* + * * + * ------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ------------------------------------------------- * + * | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| * + * ------------------------------------------------- * + * | s16 | s17 | s18 | s19 | s20 | s21 | s22 | s23 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ------------------------------------------------- * + * | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| * + * ------------------------------------------------- * + * | s24 | s25 | s26 | s27 | s28 | s29 | s30 | s31 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * + * ------------------------------------------------- * + * | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| * + * ------------------------------------------------- * + * | sjlj|hiddn| v1 | v2 | v3 | v4 | v5 | v6 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * + * ------------------------------------------------- * + * | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| * + * ------------------------------------------------- * + * | v7 | v8 | lr | pc | FCTX| DATA| | * + * ------------------------------------------------- * + * * + *******************************************************/ + +.text +.globl _jump_fcontext +.align 2 +_jump_fcontext: + @ save LR as PC + push {lr} + @ save hidden,V1-V8,LR + push {a1,v1-v8,lr} + + @ locate TLS to save/restore SjLj handler + mrc p15, 0, v2, c13, c0, #3 + bic v2, v2, #3 + + @ load TLS[__PTK_LIBC_DYLD_Unwind_SjLj_Key] + ldr v1, [v2, #72] + @ save SjLj handler + push {v1} + + @ prepare stack for FPU + sub sp, sp, #64 +#if (defined(__VFP_FP__) && !defined(__SOFTFP__)) + @ save S16-S31 + vstmia sp, {d8-d15} +#endif + + @ store RSP (pointing to context-data) in A1 + mov a1, sp + + @ restore RSP (pointing to context-data) from A2 + mov sp, a2 + +#if (defined(__VFP_FP__) && !defined(__SOFTFP__)) + @ restore S16-S31 + vldmia sp, {d8-d15} +#endif + @ prepare stack for FPU + add sp, sp, #64 + + @ r#estore SjLj handler + pop {v1} + @ store SjLj handler in TLS + str v1, [v2, #72] + + @ restore hidden,V1-V8,LR + pop {a4,v1-v8,lr} + + @ return transfer_t from jump + str a1, [a4, #0] + str a3, [a4, #4] + @ pass transfer_t as first arg in context function + @ A1 == FCTX, A2 == DATA + mov a2, a3 + + @ restore PC + pop {pc} diff --git a/third_party/context/src/asm/jump_arm_aapcs_pe_armasm.asm b/third_party/context/src/asm/jump_arm_aapcs_pe_armasm.asm new file mode 100644 index 0000000..bca923c --- /dev/null +++ b/third_party/context/src/asm/jump_arm_aapcs_pe_armasm.asm @@ -0,0 +1,81 @@ +;/* +; Copyright Oliver Kowalke 2009. +; Distributed under the Boost Software License, Version 1.0. +; (See accompanying file LICENSE_1_0.txt or copy at +; http://www.boost.org/LICENSE_1_0.txt) +;*/ + +; ******************************************************* +; * * +; * ------------------------------------------------- * +; * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * +; * ------------------------------------------------- * +; * | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| * +; * ------------------------------------------------- * +; * |deall|limit| base|hiddn| v1 | v2 | v3 | v4 | * +; * ------------------------------------------------- * +; * ------------------------------------------------- * +; * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * +; * ------------------------------------------------- * +; * | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| * +; * ------------------------------------------------- * +; * | v5 | v6 | v7 | v8 | lr | pc | FCTX| DATA| * +; * ------------------------------------------------- * +; * * +; ******************************************************* + + AREA |.text|, CODE + ALIGN 4 + EXPORT jump_fcontext + +jump_fcontext PROC + ; save LR as PC + push {lr} + ; save hidden,V1-V8,LR + push {a1,v1-v8,lr} + + ; load TIB to save/restore thread size and limit. + ; we do not need preserve CPU flag and can use it's arg register + mrc p15, #0, v1, c13, c0, #2 + + ; save current stack base + ldr a5, [v1, #0x04] + push {a5} + ; save current stack limit + ldr a5, [v1, #0x08] + push {a5} + ; save current deallocation stack + ldr a5, [v1, #0xe0c] + push {a5} + + ; store RSP (pointing to context-data) in A1 + mov a1, sp + + ; restore RSP (pointing to context-data) from A2 + mov sp, a2 + + ; restore deallocation stack + pop {a5} + str a5, [v1, #0xe0c] + ; restore stack limit + pop {a5} + str a5, [v1, #0x08] + ; restore stack base + pop {a5} + str a5, [v1, #0x04] + + ; restore hidden,V1-V8,LR + pop {a4,v1-v8,lr} + + ; return transfer_t from jump + str a1, [a4, #0] + str a3, [a4, #4] + ; pass transfer_t as first arg in context function + ; A1 == FCTX, A2 == DATA + mov a2, a3 + + ; restore PC + pop {pc} + + ENDP + END diff --git a/third_party/context/src/asm/jump_combined_sysv_macho_gas.S b/third_party/context/src/asm/jump_combined_sysv_macho_gas.S new file mode 100644 index 0000000..34a32f7 --- /dev/null +++ b/third_party/context/src/asm/jump_combined_sysv_macho_gas.S @@ -0,0 +1,24 @@ +/* + Copyright Sergue E. Leontiev 2013. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +// Stub file for universal binary + +#if defined(__i386__) + #include "jump_i386_sysv_macho_gas.S" +#elif defined(__x86_64__) + #include "jump_x86_64_sysv_macho_gas.S" +#elif defined(__ppc__) + #include "jump_ppc32_sysv_macho_gas.S" +#elif defined(__ppc64__) + #include "jump_ppc64_sysv_macho_gas.S" +#elif defined(__arm__) + #include "jump_arm_aapcs_macho_gas.S" +#elif defined(__arm64__) + #include "jump_arm64_aapcs_macho_gas.S" +#else + #error "No arch's" +#endif diff --git a/third_party/context/src/asm/jump_i386_ms_pe_clang_gas.S b/third_party/context/src/asm/jump_i386_ms_pe_clang_gas.S new file mode 100644 index 0000000..cad2c13 --- /dev/null +++ b/third_party/context/src/asm/jump_i386_ms_pe_clang_gas.S @@ -0,0 +1,123 @@ +/* + Copyright Oliver Kowalke 2009. + Copyright Thomas Sailer 2013. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/************************************************************************************* +* --------------------------------------------------------------------------------- * +* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * +* --------------------------------------------------------------------------------- * +* | 0h | 04h | 08h | 0ch | 010h | 014h | 018h | 01ch | * +* --------------------------------------------------------------------------------- * +* | fc_mxcsr|fc_x87_cw| fc_strg |fc_deallo| limit | base | fc_seh | EDI | * +* --------------------------------------------------------------------------------- * +* --------------------------------------------------------------------------------- * +* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * +* --------------------------------------------------------------------------------- * +* | 020h | 024h | 028h | 02ch | 030h | 034h | 038h | 03ch | * +* --------------------------------------------------------------------------------- * +* | ESI | EBX | EBP | EIP | to | data | EH NXT |SEH HNDLR| * +* --------------------------------------------------------------------------------- * +**************************************************************************************/ + +.file "jump_i386_ms_pe_clang_gas.S" +.text +.p2align 4,,15 + +/* mark as using no unregistered SEH handlers */ +.globl @feat.00 +.def @feat.00; .scl 3; .type 0; .endef +.set @feat.00, 1 + +.globl _jump_fcontext +.def _jump_fcontext; .scl 2; .type 32; .endef +_jump_fcontext: + /* prepare stack */ + leal -0x2c(%esp), %esp + +#if !defined(BOOST_USE_TSX) + /* save MMX control- and status-word */ + stmxcsr (%esp) + /* save x87 control-word */ + fnstcw 0x4(%esp) +#endif + + /* load NT_TIB */ + movl %fs:(0x18), %edx + /* load fiber local storage */ + movl 0x10(%edx), %eax + movl %eax, 0x8(%esp) + /* load current dealloction stack */ + movl 0xe0c(%edx), %eax + movl %eax, 0xc(%esp) + /* load current stack limit */ + movl 0x8(%edx), %eax + movl %eax, 0x10(%esp) + /* load current stack base */ + movl 0x4(%edx), %eax + movl %eax, 0x14(%esp) + /* load current SEH exception list */ + movl (%edx), %eax + movl %eax, 0x18(%esp) + + movl %edi, 0x1c(%esp) /* save EDI */ + movl %esi, 0x20(%esp) /* save ESI */ + movl %ebx, 0x24(%esp) /* save EBX */ + movl %ebp, 0x28(%esp) /* save EBP */ + + /* store ESP (pointing to context-data) in EAX */ + movl %esp, %eax + + /* firstarg of jump_fcontext() == fcontext to jump to */ + movl 0x30(%esp), %ecx + + /* restore ESP (pointing to context-data) from ECX */ + movl %ecx, %esp + +#if !defined(BOOST_USE_TSX) + /* restore MMX control- and status-word */ + ldmxcsr (%esp) + /* restore x87 control-word */ + fldcw 0x4(%esp) +#endif + + /* restore NT_TIB into EDX */ + movl %fs:(0x18), %edx + /* restore fiber local storage */ + movl 0x8(%esp), %ecx + movl %ecx, 0x10(%edx) + /* restore current deallocation stack */ + movl 0xc(%esp), %ecx + movl %ecx, 0xe0c(%edx) + /* restore current stack limit */ + movl 0x10(%esp), %ecx + movl %ecx, 0x8(%edx) + /* restore current stack base */ + movl 0x14(%esp), %ecx + movl %ecx, 0x4(%edx) + /* restore current SEH exception list */ + movl 0x18(%esp), %ecx + movl %ecx, (%edx) + + movl 0x2c(%esp), %ecx /* restore EIP */ + + movl 0x1c(%esp), %edi /* restore EDI */ + movl 0x20(%esp), %esi /* restore ESI */ + movl 0x24(%esp), %ebx /* restore EBX */ + movl 0x28(%esp), %ebp /* restore EBP */ + + /* prepare stack */ + leal 0x30(%esp), %esp + + /* return transfer_t */ + /* FCTX == EAX, DATA == EDX */ + movl 0x34(%eax), %edx + + /* jump to context */ + jmp *%ecx + +.section .drectve +.ascii " -export:\"_jump_fcontext\"" diff --git a/third_party/context/src/asm/jump_i386_ms_pe_gas.asm b/third_party/context/src/asm/jump_i386_ms_pe_gas.asm new file mode 100644 index 0000000..6eb4532 --- /dev/null +++ b/third_party/context/src/asm/jump_i386_ms_pe_gas.asm @@ -0,0 +1,123 @@ +/* + Copyright Oliver Kowalke 2009. + Copyright Thomas Sailer 2013. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/************************************************************************************* +* --------------------------------------------------------------------------------- * +* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * +* --------------------------------------------------------------------------------- * +* | 0h | 04h | 08h | 0ch | 010h | 014h | 018h | 01ch | * +* --------------------------------------------------------------------------------- * +* | fc_mxcsr|fc_x87_cw| fc_strg |fc_deallo| limit | base | fc_seh | EDI | * +* --------------------------------------------------------------------------------- * +* --------------------------------------------------------------------------------- * +* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * +* --------------------------------------------------------------------------------- * +* | 020h | 024h | 028h | 02ch | 030h | 034h | 038h | 03ch | * +* --------------------------------------------------------------------------------- * +* | ESI | EBX | EBP | EIP | to | data | EH NXT |SEH HNDLR| * +* --------------------------------------------------------------------------------- * +**************************************************************************************/ + +.file "jump_i386_ms_pe_gas.asm" +.text +.p2align 4,,15 + +/* mark as using no unregistered SEH handlers */ +.globl @feat.00 +.def @feat.00; .scl 3; .type 0; .endef +.set @feat.00, 1 + +.globl _jump_fcontext +.def _jump_fcontext; .scl 2; .type 32; .endef +_jump_fcontext: + /* prepare stack */ + leal -0x2c(%esp), %esp + +#if !defined(BOOST_USE_TSX) + /* save MMX control- and status-word */ + stmxcsr (%esp) + /* save x87 control-word */ + fnstcw 0x4(%esp) +#endif + + /* load NT_TIB */ + movl %fs:(0x18), %edx + /* load fiber local storage */ + movl 0x10(%edx), %eax + movl %eax, 0x8(%esp) + /* load current dealloction stack */ + movl 0xe0c(%edx), %eax + movl %eax, 0xc(%esp) + /* load current stack limit */ + movl 0x8(%edx), %eax + movl %eax, 0x10(%esp) + /* load current stack base */ + movl 0x4(%edx), %eax + movl %eax, 0x14(%esp) + /* load current SEH exception list */ + movl (%edx), %eax + movl %eax, 0x18(%esp) + + movl %edi, 0x1c(%esp) /* save EDI */ + movl %esi, 0x20(%esp) /* save ESI */ + movl %ebx, 0x24(%esp) /* save EBX */ + movl %ebp, 0x28(%esp) /* save EBP */ + + /* store ESP (pointing to context-data) in EAX */ + movl %esp, %eax + + /* firstarg of jump_fcontext() == fcontext to jump to */ + movl 0x30(%esp), %ecx + + /* restore ESP (pointing to context-data) from ECX */ + movl %ecx, %esp + +#if !defined(BOOST_USE_TSX) + /* restore MMX control- and status-word */ + ldmxcsr (%esp) + /* restore x87 control-word */ + fldcw 0x4(%esp) +#endif + + /* restore NT_TIB into EDX */ + movl %fs:(0x18), %edx + /* restore fiber local storage */ + movl 0x8(%esp), %ecx + movl %ecx, 0x10(%edx) + /* restore current deallocation stack */ + movl 0xc(%esp), %ecx + movl %ecx, 0xe0c(%edx) + /* restore current stack limit */ + movl 0x10(%esp), %ecx + movl %ecx, 0x8(%edx) + /* restore current stack base */ + movl 0x14(%esp), %ecx + movl %ecx, 0x4(%edx) + /* restore current SEH exception list */ + movl 0x18(%esp), %ecx + movl %ecx, (%edx) + + movl 0x2c(%esp), %ecx /* restore EIP */ + + movl 0x1c(%esp), %edi /* restore EDI */ + movl 0x20(%esp), %esi /* restore ESI */ + movl 0x24(%esp), %ebx /* restore EBX */ + movl 0x28(%esp), %ebp /* restore EBP */ + + /* prepare stack */ + leal 0x30(%esp), %esp + + /* return transfer_t */ + /* FCTX == EAX, DATA == EDX */ + movl 0x34(%eax), %edx + + /* jump to context */ + jmp *%ecx + +.section .drectve +.ascii " -export:\"jump_fcontext\"" diff --git a/third_party/context/src/asm/jump_i386_ms_pe_masm.asm b/third_party/context/src/asm/jump_i386_ms_pe_masm.asm new file mode 100644 index 0000000..7a9e848 --- /dev/null +++ b/third_party/context/src/asm/jump_i386_ms_pe_masm.asm @@ -0,0 +1,116 @@ + +; Copyright Oliver Kowalke 2009. +; Distributed under the Boost Software License, Version 1.0. +; (See accompanying file LICENSE_1_0.txt or copy at +; http://www.boost.org/LICENSE_1_0.txt) + +; --------------------------------------------------------------------------------- +; | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | +; --------------------------------------------------------------------------------- +; | 0h | 04h | 08h | 0ch | 010h | 014h | 018h | 01ch | +; --------------------------------------------------------------------------------- +; | fc_mxcsr|fc_x87_cw| fc_strg |fc_deallo| limit | base | fc_seh | EDI | +; --------------------------------------------------------------------------------- +; --------------------------------------------------------------------------------- +; | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | +; --------------------------------------------------------------------------------- +; | 020h | 024h | 028h | 02ch | 030h | 034h | 038h | 03ch | +; --------------------------------------------------------------------------------- +; | ESI | EBX | EBP | EIP | to | data | EH NXT |SEH HNDLR| +; --------------------------------------------------------------------------------- + +.386 +.XMM +.model flat, c +.code + +jump_fcontext PROC BOOST_CONTEXT_EXPORT + ; prepare stack + lea esp, [esp-02ch] + +IFNDEF BOOST_USE_TSX + ; save MMX control- and status-word + stmxcsr [esp] + ; save x87 control-word + fnstcw [esp+04h] +ENDIF + + assume fs:nothing + ; load NT_TIB into ECX + mov edx, fs:[018h] + assume fs:error + ; load fiber local storage + mov eax, [edx+010h] + mov [esp+08h], eax + ; load current deallocation stack + mov eax, [edx+0e0ch] + mov [esp+0ch], eax + ; load current stack limit + mov eax, [edx+08h] + mov [esp+010h], eax + ; load current stack base + mov eax, [edx+04h] + mov [esp+014h], eax + ; load current SEH exception list + mov eax, [edx] + mov [esp+018h], eax + + mov [esp+01ch], edi ; save EDI + mov [esp+020h], esi ; save ESI + mov [esp+024h], ebx ; save EBX + mov [esp+028h], ebp ; save EBP + + ; store ESP (pointing to context-data) in EAX + mov eax, esp + + ; firstarg of jump_fcontext() == fcontext to jump to + mov ecx, [esp+030h] + + ; restore ESP (pointing to context-data) from ECX + mov esp, ecx + +IFNDEF BOOST_USE_TSX + ; restore MMX control- and status-word + ldmxcsr [esp] + ; restore x87 control-word + fldcw [esp+04h] +ENDIF + + assume fs:nothing + ; load NT_TIB into EDX + mov edx, fs:[018h] + assume fs:error + ; restore fiber local storage + mov ecx, [esp+08h] + mov [edx+010h], ecx + ; restore current deallocation stack + mov ecx, [esp+0ch] + mov [edx+0e0ch], ecx + ; restore current stack limit + mov ecx, [esp+010h] + mov [edx+08h], ecx + ; restore current stack base + mov ecx, [esp+014h] + mov [edx+04h], ecx + ; restore current SEH exception list + mov ecx, [esp+018h] + mov [edx], ecx + + mov ecx, [esp+02ch] ; restore EIP + + mov edi, [esp+01ch] ; restore EDI + mov esi, [esp+020h] ; restore ESI + mov ebx, [esp+024h] ; restore EBX + mov ebp, [esp+028h] ; restore EBP + + ; prepare stack + lea esp, [esp+030h] + + ; return transfer_t + ; FCTX == EAX, DATA == EDX + mov edx, [eax+034h] + + ; jump to context + jmp ecx +jump_fcontext ENDP +END diff --git a/third_party/context/src/asm/jump_i386_sysv_elf_gas.S b/third_party/context/src/asm/jump_i386_sysv_elf_gas.S new file mode 100644 index 0000000..47be9e7 --- /dev/null +++ b/third_party/context/src/asm/jump_i386_sysv_elf_gas.S @@ -0,0 +1,93 @@ +/* + Copyright Oliver Kowalke 2009. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/**************************************************************************************** + * * + * ---------------------------------------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ---------------------------------------------------------------------------------- * + * | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | * + * ---------------------------------------------------------------------------------- * + * | fc_mxcsr|fc_x87_cw| guard | EDI | ESI | EBX | EBP | EIP | * + * ---------------------------------------------------------------------------------- * + * ---------------------------------------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ---------------------------------------------------------------------------------- * + * | 0x20 | 0x24 | 0x28 | | * + * ---------------------------------------------------------------------------------- * + * | hidden | to | data | | * + * ---------------------------------------------------------------------------------- * + * * + ****************************************************************************************/ + +.file "jump_i386_sysv_elf_gas.S" +.text +.globl jump_fcontext +.align 2 +.type jump_fcontext,@function +jump_fcontext: + leal -0x1c(%esp), %esp /* prepare stack */ + +#if !defined(BOOST_USE_TSX) + stmxcsr (%esp) /* save MMX control- and status-word */ + fnstcw 0x4(%esp) /* save x87 control-word */ +#endif + +#if defined(BOOST_CONTEXT_TLS_STACK_PROTECTOR) + movl %gs:0x14, %ecx /* read stack guard from TLS record */ + movl %ecx, 0x8(%esp) /* save stack guard */ +#endif + + movl %edi, 0xc(%esp) /* save EDI */ + movl %esi, 0x10(%esp) /* save ESI */ + movl %ebx, 0x14(%esp) /* save EBX */ + movl %ebp, 0x18(%esp) /* save EBP */ + + /* store ESP (pointing to context-data) in ECX */ + movl %esp, %ecx + + /* first arg of jump_fcontext() == fcontext to jump to */ + movl 0x24(%esp), %eax + + /* second arg of jump_fcontext() == data to be transferred */ + movl 0x28(%esp), %edx + + /* restore ESP (pointing to context-data) from EAX */ + movl %eax, %esp + + /* address of returned transport_t */ + movl 0x20(%esp), %eax + /* return parent fcontext_t */ + movl %ecx, (%eax) + /* return data */ + movl %edx, 0x4(%eax) + + movl 0x1c(%esp), %ecx /* restore EIP */ + +#if !defined(BOOST_USE_TSX) + ldmxcsr (%esp) /* restore MMX control- and status-word */ + fldcw 0x4(%esp) /* restore x87 control-word */ +#endif + +#if defined(BOOST_CONTEXT_TLS_STACK_PROTECTOR) + movl 0x8(%esp), %edx /* load stack guard */ + movl %edx, %gs:0x14 /* restore stack guard to TLS record */ +#endif + + movl 0xc(%esp), %edi /* restore EDI */ + movl 0x10(%esp), %esi /* restore ESI */ + movl 0x14(%esp), %ebx /* restore EBX */ + movl 0x18(%esp), %ebp /* restore EBP */ + + leal 0x24(%esp), %esp /* prepare stack */ + + /* jump to context */ + jmp *%ecx +.size jump_fcontext,.-jump_fcontext + +/* Mark that we don't need executable stack. */ +.section .note.GNU-stack,"",%progbits diff --git a/third_party/context/src/asm/jump_i386_sysv_macho_gas.S b/third_party/context/src/asm/jump_i386_sysv_macho_gas.S new file mode 100644 index 0000000..8ab7c6f --- /dev/null +++ b/third_party/context/src/asm/jump_i386_sysv_macho_gas.S @@ -0,0 +1,74 @@ +/* + Copyright Oliver Kowalke 2009. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/**************************************************************************************** + * * + * ---------------------------------------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ---------------------------------------------------------------------------------- * + * | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | * + * ---------------------------------------------------------------------------------- * + * | fc_mxcsr|fc_x87_cw| EDI | ESI | EBX | EBP | EIP | to | * + * ---------------------------------------------------------------------------------- * + * ---------------------------------------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ---------------------------------------------------------------------------------- * + * | 0x20 | | * + * ---------------------------------------------------------------------------------- * + * | data | | * + * ---------------------------------------------------------------------------------- * + * * + ****************************************************************************************/ + +.text +.globl _jump_fcontext +.align 2 +_jump_fcontext: + leal -0x18(%esp), %esp /* prepare stack */ + +#if !defined(BOOST_USE_TSX) + stmxcsr (%esp) /* save MMX control- and status-word */ + fnstcw 0x4(%esp) /* save x87 control-word */ +#endif + + movl %edi, 0x8(%esp) /* save EDI */ + movl %esi, 0xc(%esp) /* save ESI */ + movl %ebx, 0x10(%esp) /* save EBX */ + movl %ebp, 0x14(%esp) /* save EBP */ + + /* store ESP (pointing to context-data) in ECX */ + movl %esp, %ecx + + /* first arg of jump_fcontext() == fcontext to jump to */ + movl 0x1c(%esp), %eax + + /* second arg of jump_fcontext() == data to be transferred */ + movl 0x20(%esp), %edx + + /* restore ESP (pointing to context-data) from EAX */ + movl %eax, %esp + + /* return parent fcontext_t */ + movl %ecx, %eax + /* returned data is stored in EDX */ + + movl 0x18(%esp), %ecx /* restore EIP */ + +#if !defined(BOOST_USE_TSX) + ldmxcsr (%esp) /* restore MMX control- and status-word */ + fldcw 0x4(%esp) /* restore x87 control-word */ +#endif + + movl 0x8(%esp), %edi /* restore EDI */ + movl 0xc(%esp), %esi /* restore ESI */ + movl 0x10(%esp), %ebx /* restore EBX */ + movl 0x14(%esp), %ebp /* restore EBP */ + + leal 0x1c(%esp), %esp /* prepare stack */ + + /* jump to context */ + jmp *%ecx diff --git a/third_party/context/src/asm/jump_i386_x86_64_sysv_macho_gas.S b/third_party/context/src/asm/jump_i386_x86_64_sysv_macho_gas.S new file mode 100644 index 0000000..959ddac --- /dev/null +++ b/third_party/context/src/asm/jump_i386_x86_64_sysv_macho_gas.S @@ -0,0 +1,16 @@ +/* + Copyright Sergue E. Leontiev 2013. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +// Stub file for universal binary + +#if defined(__i386__) + #include "jump_i386_sysv_macho_gas.S" +#elif defined(__x86_64__) + #include "jump_x86_64_sysv_macho_gas.S" +#else + #error "No arch's" +#endif diff --git a/third_party/context/src/asm/jump_loongarch64_sysv_elf_gas.S b/third_party/context/src/asm/jump_loongarch64_sysv_elf_gas.S new file mode 100644 index 0000000..74c081e --- /dev/null +++ b/third_party/context/src/asm/jump_loongarch64_sysv_elf_gas.S @@ -0,0 +1,121 @@ +/******************************************************* + * * + * ------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ------------------------------------------------- * + * | 0 | 8 | 16 | 24 | * + * ------------------------------------------------- * + * | FS0 | FS1 | FS2 | FS3 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ------------------------------------------------- * + * | 32 | 40 | 48 | 56 | * + * ------------------------------------------------- * + * | FS4 | FS5 | FS6 | FS7 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * + * ------------------------------------------------- * + * | 64 | 72 | 80 | 88 | * + * ------------------------------------------------- * + * | S0 | S1 | S2 | S3 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * + * ------------------------------------------------- * + * | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | * + * ------------------------------------------------- * + * | S4 | S5 | S6 | S7 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * + * ------------------------------------------------- * + * | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | * + * ------------------------------------------------- * + * | S8 | FP | RA | PC | * + * ------------------------------------------------- * + * * + * *****************************************************/ + +.file "jump_loongarch64_sysv_elf_gas.S" +.text +.globl jump_fcontext +.align 2 +.type jump_fcontext,@function +jump_fcontext: + # reserve space on stack + addi.d $sp, $sp, -160 + + # save fs0 - fs7 + fst.d $fs0, $sp, 0 + fst.d $fs1, $sp, 8 + fst.d $fs2, $sp, 16 + fst.d $fs3, $sp, 24 + fst.d $fs4, $sp, 32 + fst.d $fs5, $sp, 40 + fst.d $fs6, $sp, 48 + fst.d $fs7, $sp, 56 + + # save s0 - s8, fp, ra + st.d $s0, $sp, 64 + st.d $s1, $sp, 72 + st.d $s2, $sp, 80 + st.d $s3, $sp, 88 + st.d $s4, $sp, 96 + st.d $s5, $sp, 104 + st.d $s6, $sp, 112 + st.d $s7, $sp, 120 + st.d $s8, $sp, 128 + st.d $fp, $sp, 136 + st.d $ra, $sp, 144 + + # save RA as PC + st.d $ra, $sp, 152 + + # store SP (pointing to context-data) in A2 + move $a2, $sp + + # restore SP (pointing to context-data) from A0 + move $sp, $a0 + + # load fs0 - fs7 + fld.d $fs0, $sp, 0 + fld.d $fs1, $sp, 8 + fld.d $fs2, $sp, 16 + fld.d $fs3, $sp, 24 + fld.d $fs4, $sp, 32 + fld.d $fs5, $sp, 40 + fld.d $fs6, $sp, 48 + fld.d $fs7, $sp, 56 + + #load s0 - s7 + ld.d $s0, $sp, 64 + ld.d $s1, $sp, 72 + ld.d $s2, $sp, 80 + ld.d $s3, $sp, 88 + ld.d $s4, $sp, 96 + ld.d $s5, $sp, 104 + ld.d $s6, $sp, 112 + ld.d $s7, $sp, 120 + ld.d $s8, $sp, 128 + ld.d $fp, $sp, 136 + ld.d $ra, $sp, 144 + + # return transfer_t from jump + # pass transfer_t as first arg in context function + # a0 == FCTX, a1 == DATA + move $a0, $a2 + + # load PC + ld.d $a2, $sp, 152 + + # restore stack + addi.d $sp, $sp, 160 + + # jump to context + jr $a2 +.size jump_fcontext, .-jump_fcontext + +/* Mark that we don't need executable stack. */ +.section .note.GNU-stack,"",%progbits diff --git a/third_party/context/src/asm/jump_mips32_o32_elf_gas.S b/third_party/context/src/asm/jump_mips32_o32_elf_gas.S new file mode 100644 index 0000000..f2b8034 --- /dev/null +++ b/third_party/context/src/asm/jump_mips32_o32_elf_gas.S @@ -0,0 +1,119 @@ +/* + Copyright Oliver Kowalke 2009. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/******************************************************* + * * + * ------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ------------------------------------------------- * + * | 0 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | * + * ------------------------------------------------- * + * | F20 | F22 | F24 | F26 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ------------------------------------------------- * + * | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | * + * ------------------------------------------------- * + * | F28 | F30 | S0 | S1 | S2 | S3 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * + * ------------------------------------------------- * + * | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | * + * ------------------------------------------------- * + * | S4 | S5 | S6 | S7 | FP |hiddn| RA | PC | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * + * ------------------------------------------------- * + * | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | * + * ------------------------------------------------- * + * | ABI ARGS | GP | FCTX| DATA| | * + * ------------------------------------------------- * + * * + * *****************************************************/ + +.file "jump_mips32_o32_elf_gas.S" +.text +.globl jump_fcontext +.align 2 +.type jump_fcontext,@function +.ent jump_fcontext +jump_fcontext: + # reserve space on stack + addiu $sp, $sp, -96 + + sw $s0, 48($sp) # save S0 + sw $s1, 52($sp) # save S1 + sw $s2, 56($sp) # save S2 + sw $s3, 60($sp) # save S3 + sw $s4, 64($sp) # save S4 + sw $s5, 68($sp) # save S5 + sw $s6, 72($sp) # save S6 + sw $s7, 76($sp) # save S7 + sw $fp, 80($sp) # save FP + sw $a0, 84($sp) # save hidden, address of returned transfer_t + sw $ra, 88($sp) # save RA + sw $ra, 92($sp) # save RA as PC + +#if defined(__mips_hard_float) + s.d $f20, ($sp) # save F20 + s.d $f22, 8($sp) # save F22 + s.d $f24, 16($sp) # save F24 + s.d $f26, 24($sp) # save F26 + s.d $f28, 32($sp) # save F28 + s.d $f30, 40($sp) # save F30 +#endif + + # store SP (pointing to context-data) in A0 + move $a0, $sp + + # restore SP (pointing to context-data) from A1 + move $sp, $a1 + +#if defined(__mips_hard_float) + l.d $f20, ($sp) # restore F20 + l.d $f22, 8($sp) # restore F22 + l.d $f24, 16($sp) # restore F24 + l.d $f26, 24($sp) # restore F26 + l.d $f28, 32($sp) # restore F28 + l.d $f30, 40($sp) # restore F30 +#endif + + lw $s0, 48($sp) # restore S0 + lw $s1, 52($sp) # restore S1 + lw $s2, 56($sp) # restore S2 + lw $s3, 60($sp) # restore S3 + lw $s4, 64($sp) # restore S4 + lw $s5, 68($sp) # restore S5 + lw $s6, 72($sp) # restore S6 + lw $s7, 76($sp) # restore S7 + lw $fp, 80($sp) # restore FP + lw $v0, 84($sp) # restore hidden, address of returned transfer_t + lw $ra, 88($sp) # restore RA + + # load PC + lw $t9, 92($sp) + + # adjust stack + addiu $sp, $sp, 96 + + # return transfer_t from jump + sw $a0, ($v0) # fctx of transfer_t + sw $a2, 4($v0) # data of transfer_t + # pass transfer_t as first arg in context function + # A0 == fctx, A1 == data + move $a1, $a2 + + # jump to context + jr $t9 +.end jump_fcontext +.size jump_fcontext, .-jump_fcontext + +/* Mark that we don't need executable stack. */ +.section .note.GNU-stack,"",%progbits diff --git a/third_party/context/src/asm/jump_mips64_n64_elf_gas.S b/third_party/context/src/asm/jump_mips64_n64_elf_gas.S new file mode 100644 index 0000000..e338912 --- /dev/null +++ b/third_party/context/src/asm/jump_mips64_n64_elf_gas.S @@ -0,0 +1,124 @@ +/* + Copyright Jiaxun Yang 2018. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/******************************************************* + * * + * ------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ------------------------------------------------- * + * | 0 | 8 | 16 | 24 | * + * ------------------------------------------------- * + * | F24 | F25 | F26 | F27 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ------------------------------------------------- * + * | 32 | 40 | 48 | 56 | * + * ------------------------------------------------- * + * | F28 | F29 | F30 | F31 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * + * ------------------------------------------------- * + * | 64 | 72 | 80 | 88 | * + * ------------------------------------------------- * + * | S0 | S1 | S2 | S3 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * + * ------------------------------------------------- * + * | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | * + * ------------------------------------------------- * + * | S4 | S5 | S6 | S7 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * + * ------------------------------------------------- * + * | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | * + * ------------------------------------------------- * + * | FP | GP | RA | PC | * + * ------------------------------------------------- * + * * + * *****************************************************/ + +.file "jump_mips64_n64_elf_gas.S" +.text +.globl jump_fcontext +.align 3 +.type jump_fcontext,@function +.ent jump_fcontext +jump_fcontext: + # reserve space on stack + daddiu $sp, $sp, -160 + + sd $s0, 64($sp) # save S0 + sd $s1, 72($sp) # save S1 + sd $s2, 80($sp) # save S2 + sd $s3, 88($sp) # save S3 + sd $s4, 96($sp) # save S4 + sd $s5, 104($sp) # save S5 + sd $s6, 112($sp) # save S6 + sd $s7, 120($sp) # save S7 + sd $fp, 128($sp) # save FP + sd $ra, 144($sp) # save RA + sd $ra, 152($sp) # save RA as PC + +#if defined(__mips_hard_float) + s.d $f24, 0($sp) # save F24 + s.d $f25, 8($sp) # save F25 + s.d $f26, 16($sp) # save F26 + s.d $f27, 24($sp) # save F27 + s.d $f28, 32($sp) # save F28 + s.d $f29, 40($sp) # save F29 + s.d $f30, 48($sp) # save F30 + s.d $f31, 56($sp) # save F31 +#endif + + # store SP (pointing to old context-data) in v0 as return + move $v0, $sp + + # get SP (pointing to new context-data) from a0 param + move $sp, $a0 + +#if defined(__mips_hard_float) + l.d $f24, 0($sp) # restore F24 + l.d $f25, 8($sp) # restore F25 + l.d $f26, 16($sp) # restore F26 + l.d $f27, 24($sp) # restore F27 + l.d $f28, 32($sp) # restore F28 + l.d $f29, 40($sp) # restore F29 + l.d $f30, 48($sp) # restore F30 + l.d $f31, 56($sp) # restore F31 +#endif + + ld $s0, 64($sp) # restore S0 + ld $s1, 72($sp) # restore S1 + ld $s2, 80($sp) # restore S2 + ld $s3, 88($sp) # restore S3 + ld $s4, 96($sp) # restore S4 + ld $s5, 104($sp) # restore S5 + ld $s6, 112($sp) # restore S6 + ld $s7, 120($sp) # restore S7 + ld $fp, 128($sp) # restore FP + ld $ra, 144($sp) # restore RAa + + # load PC + ld $t9, 152($sp) + + # adjust stack + daddiu $sp, $sp, 160 + + move $a0, $v0 # move old sp from v0 to a0 as param + move $v1, $a1 # move *data from a1 to v1 as return + + # jump to context + jr $t9 +.end jump_fcontext +.size jump_fcontext, .-jump_fcontext + +/* Mark that we don't need executable stack. */ +.section .note.GNU-stack,"",%progbits diff --git a/third_party/context/src/asm/jump_ppc32_ppc64_sysv_macho_gas.S b/third_party/context/src/asm/jump_ppc32_ppc64_sysv_macho_gas.S new file mode 100644 index 0000000..f175e31 --- /dev/null +++ b/third_party/context/src/asm/jump_ppc32_ppc64_sysv_macho_gas.S @@ -0,0 +1,16 @@ +/* + Copyright Sergue E. Leontiev 2013. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +// Stub file for universal binary + +#if defined(__ppc__) + #include "jump_ppc32_sysv_macho_gas.S" +#elif defined(__ppc64__) + #include "jump_ppc64_sysv_macho_gas.S" +#else + #error "No arch's" +#endif diff --git a/third_party/context/src/asm/jump_ppc32_sysv_elf_gas.S b/third_party/context/src/asm/jump_ppc32_sysv_elf_gas.S new file mode 100644 index 0000000..48e09c9 --- /dev/null +++ b/third_party/context/src/asm/jump_ppc32_sysv_elf_gas.S @@ -0,0 +1,201 @@ +/* + Copyright Oliver Kowalke 2009. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/******************************************************* + * * + * ------------------------------------------------- * + * | 0 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | * + * ------------------------------------------------- * + * |bchai|hiddn| fpscr | PC | CR | R14 | R15 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | * + * ------------------------------------------------- * + * | R16 | R17 | R18 | R19 | R20 | R21 | R22 | R23 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | * + * ------------------------------------------------- * + * | R24 | R25 | R26 | R27 | R28 | R29 | R30 | R31 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | * + * ------------------------------------------------- * + * | F14 | F15 | F16 | F17 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | * + * ------------------------------------------------- * + * | F18 | F19 | F20 | F21 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 160 | 164 | 168 | 172 | 176 | 180 | 184 | 188 | * + * ------------------------------------------------- * + * | F22 | F23 | F24 | F25 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 192 | 196 | 200 | 204 | 208 | 212 | 216 | 220 | * + * ------------------------------------------------- * + * | F26 | F27 | F28 | F29 | * + * ------------------------------------------------- * + * ------------------------|------------ * + * | 224 | 228 | 232 | 236 | 240 | 244 | * + * ------------------------|------------ * + * | F30 | F31 |bchai| LR | * + * ------------------------|------------ * + * * + *******************************************************/ + +.file "jump_ppc32_sysv_elf_gas.S" +.text +.globl jump_fcontext +.align 2 +.type jump_fcontext,@function +jump_fcontext: + # Linux: jump_fcontext( hidden transfer_t * R3, R4, R5) + # Other: transfer_t R3:R4 = jump_fcontext( R3, R4) + + mflr %r0 # return address from LR + mffs %f0 # FPSCR + mfcr %r8 # condition register + + stwu %r1, -240(%r1) # allocate stack space, R1 % 16 == 0 + stw %r0, 244(%r1) # save LR in caller's frame + +#ifdef __linux__ + stw %r3, 4(%r1) # hidden pointer +#endif + + stfd %f0, 8(%r1) # FPSCR + stw %r0, 16(%r1) # LR as PC + stw %r8, 20(%r1) # CR + + # Save registers R14 to R31. + # Don't change R2, the thread-local storage pointer. + # Don't change R13, the small data pointer. + stw %r14, 24(%r1) + stw %r15, 28(%r1) + stw %r16, 32(%r1) + stw %r17, 36(%r1) + stw %r18, 40(%r1) + stw %r19, 44(%r1) + stw %r20, 48(%r1) + stw %r21, 52(%r1) + stw %r22, 56(%r1) + stw %r23, 60(%r1) + stw %r24, 64(%r1) + stw %r25, 68(%r1) + stw %r26, 72(%r1) + stw %r27, 76(%r1) + stw %r28, 80(%r1) + stw %r29, 84(%r1) + stw %r30, 88(%r1) + stw %r31, 92(%r1) + + # Save registers F14 to F31 in slots with 8-byte alignment. + # 4-byte alignment may stall the pipeline of some processors. + # Less than 4 may cause alignment traps. + stfd %f14, 96(%r1) + stfd %f15, 104(%r1) + stfd %f16, 112(%r1) + stfd %f17, 120(%r1) + stfd %f18, 128(%r1) + stfd %f19, 136(%r1) + stfd %f20, 144(%r1) + stfd %f21, 152(%r1) + stfd %f22, 160(%r1) + stfd %f23, 168(%r1) + stfd %f24, 176(%r1) + stfd %f25, 184(%r1) + stfd %f26, 192(%r1) + stfd %f27, 200(%r1) + stfd %f28, 208(%r1) + stfd %f29, 216(%r1) + stfd %f30, 224(%r1) + stfd %f31, 232(%r1) + + # store RSP (pointing to context-data) in R7/R6 + # restore RSP (pointing to context-data) from R4/R3 +#ifdef __linux__ + mr %r7, %r1 + mr %r1, %r4 + lwz %r3, 4(%r1) # hidden pointer +#else + mr %r6, %r1 + mr %r1, %r3 +#endif + + lfd %f0, 8(%r1) # FPSCR + lwz %r0, 16(%r1) # PC + lwz %r8, 20(%r1) # CR + + mtfsf 0xff, %f0 # restore FPSCR + mtctr %r0 # load CTR with PC + mtcr %r8 # restore CR + + # restore R14 to R31 + lwz %r14, 24(%r1) + lwz %r15, 28(%r1) + lwz %r16, 32(%r1) + lwz %r17, 36(%r1) + lwz %r18, 40(%r1) + lwz %r19, 44(%r1) + lwz %r20, 48(%r1) + lwz %r21, 52(%r1) + lwz %r22, 56(%r1) + lwz %r23, 60(%r1) + lwz %r24, 64(%r1) + lwz %r25, 68(%r1) + lwz %r26, 72(%r1) + lwz %r27, 76(%r1) + lwz %r28, 80(%r1) + lwz %r29, 84(%r1) + lwz %r30, 88(%r1) + lwz %r31, 92(%r1) + + # restore F14 to F31 + lfd %f14, 96(%r1) + lfd %f15, 104(%r1) + lfd %f16, 112(%r1) + lfd %f17, 120(%r1) + lfd %f18, 128(%r1) + lfd %f19, 136(%r1) + lfd %f20, 144(%r1) + lfd %f21, 152(%r1) + lfd %f22, 160(%r1) + lfd %f23, 168(%r1) + lfd %f24, 176(%r1) + lfd %f25, 184(%r1) + lfd %f26, 192(%r1) + lfd %f27, 200(%r1) + lfd %f28, 208(%r1) + lfd %f29, 216(%r1) + lfd %f30, 224(%r1) + lfd %f31, 232(%r1) + + # restore LR from caller's frame + lwz %r0, 244(%r1) + mtlr %r0 + + # adjust stack + addi %r1, %r1, 240 + + # return transfer_t +#ifdef __linux__ + stw %r7, 0(%r3) + stw %r5, 4(%r3) +#else + mr %r3, %r6 + # %r4, %r4 +#endif + + # jump to context + bctr +.size jump_fcontext, .-jump_fcontext + +/* Mark that we don't need executable stack. */ +.section .note.GNU-stack,"",%progbits diff --git a/third_party/context/src/asm/jump_ppc32_sysv_macho_gas.S b/third_party/context/src/asm/jump_ppc32_sysv_macho_gas.S new file mode 100644 index 0000000..fef90c2 --- /dev/null +++ b/third_party/context/src/asm/jump_ppc32_sysv_macho_gas.S @@ -0,0 +1,201 @@ +/* + Copyright Oliver Kowalke 2009. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/****************************************************** + * * + * ------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ------------------------------------------------- * + * | 0 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | * + * ------------------------------------------------- * + * | F14 | F15 | F16 | F17 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ------------------------------------------------- * + * | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | * + * ------------------------------------------------- * + * | F18 | F19 | F20 | F21 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * + * ------------------------------------------------- * + * | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | * + * ------------------------------------------------- * + * | F22 | F23 | F24 | F25 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * + * ------------------------------------------------- * + * | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | * + * ------------------------------------------------- * + * | F26 | F27 | F28 | F29 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * + * ------------------------------------------------- * + * | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | * + * ------------------------------------------------- * + * | F30 | F31 | fpscr | R13 | R14 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | * + * ------------------------------------------------- * + * | 160 | 164 | 168 | 172 | 176 | 180 | 184 | 188 | * + * ------------------------------------------------- * + * | R15 | R16 | R17 | R18 | R19 | R20 | R21 | R22 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | * + * ------------------------------------------------- * + * | 192 | 196 | 200 | 204 | 208 | 212 | 216 | 220 | * + * ------------------------------------------------- * + * | R23 | R24 | R25 | R26 | R27 | R28 | R29 | R30 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | * + * ------------------------------------------------- * + * | 224 | 228 | 232 | 236 | 240 | 244 | 248 | 252 | * + * ------------------------------------------------- * + * | R31 |hiddn| CR | LR | PC |bchai|linkr| FCTX| * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 64 | | * + * ------------------------------------------------- * + * | 256 | | * + * ------------------------------------------------- * + * | DATA| | * + * ------------------------------------------------- * + * * + *******************************************************/ + +.text +.globl _jump_fcontext +.align 2 +_jump_fcontext: + ; reserve space on stack + subi r1, r1, 244 + + stfd f14, 0(r1) ; save F14 + stfd f15, 8(r1) ; save F15 + stfd f16, 16(r1) ; save F16 + stfd f17, 24(r1) ; save F17 + stfd f18, 32(r1) ; save F18 + stfd f19, 40(r1) ; save F19 + stfd f20, 48(r1) ; save F20 + stfd f21, 56(r1) ; save F21 + stfd f22, 64(r1) ; save F22 + stfd f23, 72(r1) ; save F23 + stfd f24, 80(r1) ; save F24 + stfd f25, 88(r1) ; save F25 + stfd f26, 96(r1) ; save F26 + stfd f27, 104(r1) ; save F27 + stfd f28, 112(r1) ; save F28 + stfd f29, 120(r1) ; save F29 + stfd f30, 128(r1) ; save F30 + stfd f31, 136(r1) ; save F31 + mffs f0 ; load FPSCR + stfd f0, 144(r1) ; save FPSCR + + stw r13, 152(r1) ; save R13 + stw r14, 156(r1) ; save R14 + stw r15, 160(r1) ; save R15 + stw r16, 164(r1) ; save R16 + stw r17, 168(r1) ; save R17 + stw r18, 172(r1) ; save R18 + stw r19, 176(r1) ; save R19 + stw r20, 180(r1) ; save R20 + stw r21, 184(r1) ; save R21 + stw r22, 188(r1) ; save R22 + stw r23, 192(r1) ; save R23 + stw r24, 196(r1) ; save R24 + stw r25, 200(r1) ; save R25 + stw r26, 204(r1) ; save R26 + stw r27, 208(r1) ; save R27 + stw r28, 212(r1) ; save R28 + stw r29, 216(r1) ; save R29 + stw r30, 220(r1) ; save R30 + stw r31, 224(r1) ; save R31 + stw r3, 228(r1) ; save hidden + + ; save CR + mfcr r0 + stw r0, 232(r1) + ; save LR + mflr r0 + stw r0, 236(r1) + ; save LR as PC + stw r0, 240(r1) + + ; store RSP (pointing to context-data) in R6 + mr r6, r1 + + ; restore RSP (pointing to context-data) from R4 + mr r1, r4 + + lfd f14, 0(r1) ; restore F14 + lfd f15, 8(r1) ; restore F15 + lfd f16, 16(r1) ; restore F16 + lfd f17, 24(r1) ; restore F17 + lfd f18, 32(r1) ; restore F18 + lfd f19, 40(r1) ; restore F19 + lfd f20, 48(r1) ; restore F20 + lfd f21, 56(r1) ; restore F21 + lfd f22, 64(r1) ; restore F22 + lfd f23, 72(r1) ; restore F23 + lfd f24, 80(r1) ; restore F24 + lfd f25, 88(r1) ; restore F25 + lfd f26, 96(r1) ; restore F26 + lfd f27, 104(r1) ; restore F27 + lfd f28, 112(r1) ; restore F28 + lfd f29, 120(r1) ; restore F29 + lfd f30, 128(r1) ; restore F30 + lfd f31, 136(r1) ; restore F31 + lfd f0, 144(r1) ; load FPSCR + mtfsf 0xff, f0 ; restore FPSCR + + lwz r13, 152(r1) ; restore R13 + lwz r14, 156(r1) ; restore R14 + lwz r15, 160(r1) ; restore R15 + lwz r16, 164(r1) ; restore R16 + lwz r17, 168(r1) ; restore R17 + lwz r18, 172(r1) ; restore R18 + lwz r19, 176(r1) ; restore R19 + lwz r20, 180(r1) ; restore R20 + lwz r21, 184(r1) ; restore R21 + lwz r22, 188(r1) ; restore R22 + lwz r23, 192(r1) ; restore R23 + lwz r24, 196(r1) ; restore R24 + lwz r25, 200(r1) ; restore R25 + lwz r26, 204(r1) ; restore R26 + lwz r27, 208(r1) ; restore R27 + lwz r28, 212(r1) ; restore R28 + lwz r29, 216(r1) ; restore R29 + lwz r30, 220(r1) ; restore R30 + lwz r31, 224(r1) ; restore R31 + lwz r3, 228(r1) ; restore hidden + + ; restore CR + lwz r0, 232(r1) + mtcr r0 + ; restore LR + lwz r0, 236(r1) + mtlr r0 + ; load PC + lwz r0, 240(r1) + ; restore CTR + mtctr r0 + + ; adjust stack + addi r1, r1, 244 + + ; return transfer_t + stw r6, 0(r3) + stw r5, 4(r3) + + ; jump to context + bctr diff --git a/third_party/context/src/asm/jump_ppc32_sysv_xcoff_gas.S b/third_party/context/src/asm/jump_ppc32_sysv_xcoff_gas.S new file mode 100644 index 0000000..1854613 --- /dev/null +++ b/third_party/context/src/asm/jump_ppc32_sysv_xcoff_gas.S @@ -0,0 +1,216 @@ +/* + Copyright Oliver Kowalke 2009. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/******************************************************* + * * + * ------------------------------------------------- * + * | 0 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | * + * ------------------------------------------------- * + * |bchai| CR | LR |compl| link| TOC | R14 | R15 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | * + * ------------------------------------------------- * + * | R16 | R17 | R18 | R19 | R20 | R21 | R22 | R23 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | * + * ------------------------------------------------- * + * | R24 | R25 | R26 | R27 | R28 | R29 | R30 | R31 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | * + * ------------------------------------------------- * + * | F14 | F15 | F16 | F17 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | * + * ------------------------------------------------- * + * | F18 | F19 | F20 | F21 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 160 | 164 | 168 | 172 | 176 | 180 | 184 | 188 | * + * ------------------------------------------------- * + * | F22 | F23 | F24 | F25 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 192 | 196 | 200 | 204 | 208 | 212 | 216 | 220 | * + * ------------------------------------------------- * + * | F26 | F27 | F28 | F29 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 224 | 228 | 232 | 236 | 240 | 244 | 248 | 252 | * + * ------------------------------------------------- * + * | F30 | F31 | PC |hiddn| fpscr | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 256 | 260 | 264 | 268 | 272 | 276 | 280 | 284 | * + * ------------------------------------------------- * + * |bchai|savCR|savLR|compl| link|svTOC| FCTX| DATA| * + * ------------------------------------------------- * + * * + *******************************************************/ + + .file "jump_ppc32_sysv_xcoff_gas.S" + .toc + .csect .text[PR], 5 + .globl jump_fcontext[DS] + .globl .jump_fcontext + .csect jump_fcontext[DS] +jump_fcontext: + .long .jump_fcontext[PR], TOC[tc0], 0 + .csect .text[PR], 5 +.jump_fcontext: + # reserve space on stack + subi 1, 1, 256 + + # save CR + mfcr 0 + stw 0, 4(1) + # save LR + mflr 0 + stw 0, 8(1) + # save LR as PC + stw 0, 240(1) + # save TOC + stw 2, 20(1) + + # Save registers R14 to R31. + stw 14, 24(1) + stw 15, 28(1) + stw 16, 32(1) + stw 17, 36(1) + stw 18, 40(1) + stw 19, 44(1) + stw 20, 48(1) + stw 21, 52(1) + stw 22, 56(1) + stw 23, 60(1) + stw 24, 64(1) + stw 25, 68(1) + stw 26, 72(1) + stw 27, 76(1) + stw 28, 80(1) + stw 29, 84(1) + stw 30, 88(1) + stw 31, 92(1) + + # Save registers F14 to F31 in slots with 8-byte alignment. + # 4-byte alignment may stall the pipeline of some processors. + # Less than 4 may cause alignment traps. + stfd 14, 96(1) + stfd 15, 104(1) + stfd 16, 112(1) + stfd 17, 120(1) + stfd 18, 128(1) + stfd 19, 136(1) + stfd 20, 144(1) + stfd 21, 152(1) + stfd 22, 160(1) + stfd 23, 168(1) + stfd 24, 176(1) + stfd 25, 184(1) + stfd 26, 192(1) + stfd 27, 200(1) + stfd 28, 208(1) + stfd 29, 216(1) + stfd 30, 224(1) + stfd 31, 232(1) + + # hidden pointer + stw 3, 244(1) + + mffs 0 # load FPSCR + stfd 0, 248(1) # save FPSCR + + + # store RSP (pointing to context-data) in R6 + mr 6, 1 + + # restore RSP (pointing to context-data) from R4 + mr 1, 4 + + # restore CR + lwz 0, 4(1) + mtcr 0 + # restore LR + lwz 0, 8(1) + mtlr 0 + # load PC + lwz 0, 240(1) + mtctr 0 + + # restore TOC + lwz 2, 20(1) + + # restore R14 to R31 + lwz 14, 24(1) + lwz 15, 28(1) + lwz 16, 32(1) + lwz 17, 36(1) + lwz 18, 40(1) + lwz 19, 44(1) + lwz 20, 48(1) + lwz 21, 52(1) + lwz 22, 56(1) + lwz 23, 60(1) + lwz 24, 64(1) + lwz 25, 68(1) + lwz 26, 72(1) + lwz 27, 76(1) + lwz 28, 80(1) + lwz 29, 84(1) + lwz 30, 88(1) + lwz 31, 92(1) + + # restore F14 to F31 + lfd 14, 96(1) + lfd 15, 104(1) + lfd 16, 112(1) + lfd 17, 120(1) + lfd 18, 128(1) + lfd 19, 136(1) + lfd 20, 144(1) + lfd 21, 152(1) + lfd 22, 160(1) + lfd 23, 168(1) + lfd 24, 176(1) + lfd 25, 184(1) + lfd 26, 192(1) + lfd 27, 200(1) + lfd 28, 208(1) + lfd 29, 216(1) + lfd 30, 224(1) + lfd 31, 232(1) + + # hidden pointer + lwz 3, 244(1) + + lfd 0, 248(1) # load FPSCR + mtfsf 0xff, 0 # restore FPSCR + + # adjust stack + addi 1, 1, 256 + + # zero in r3 indicates first jump to context-function + cmpdi 3, 0 + beq use_entry_arg + + # return transfer_t + stw 6, 0(3) + stw 5, 4(3) + + # jump to context + bctr + +use_entry_arg: + # copy transfer_t into transfer_fn arg registers + mr 3, 6 + mr 4, 5 + + # jump to context + bctr diff --git a/third_party/context/src/asm/jump_ppc64_sysv_elf_gas.S b/third_party/context/src/asm/jump_ppc64_sysv_elf_gas.S new file mode 100644 index 0000000..28907db --- /dev/null +++ b/third_party/context/src/asm/jump_ppc64_sysv_elf_gas.S @@ -0,0 +1,221 @@ +/* + Copyright Oliver Kowalke 2009. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/******************************************************* + * * + * ------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ------------------------------------------------- * + * | 0 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | * + * ------------------------------------------------- * + * | TOC | R14 | R15 | R16 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ------------------------------------------------- * + * | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | * + * ------------------------------------------------- * + * | R17 | R18 | R19 | R20 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * + * ------------------------------------------------- * + * | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | * + * ------------------------------------------------- * + * | R21 | R22 | R23 | R24 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * + * ------------------------------------------------- * + * | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | * + * ------------------------------------------------- * + * | R25 | R26 | R27 | R28 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * + * ------------------------------------------------- * + * | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | * + * ------------------------------------------------- * + * | R29 | R30 | R31 | hidden | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | * + * ------------------------------------------------- * + * | 160 | 164 | 168 | 172 | 176 | 180 | 184 | 188 | * + * ------------------------------------------------- * + * | CR | LR | PC | back-chain| * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | * + * ------------------------------------------------- * + * | 192 | 196 | 200 | 204 | 208 | 212 | 216 | 220 | * + * ------------------------------------------------- * + * | cr saved | lr saved | compiler | linker | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | * + * ------------------------------------------------- * + * | 224 | 228 | 232 | 236 | 240 | 244 | 248 | 252 | * + * ------------------------------------------------- * + * | TOC saved | FCTX | DATA | | * + * ------------------------------------------------- * + * * + *******************************************************/ + +.file "jump_ppc64_sysv_elf_gas.S" +.globl jump_fcontext +#if _CALL_ELF == 2 + .text + .align 2 +jump_fcontext: + addis %r2, %r12, .TOC.-jump_fcontext@ha + addi %r2, %r2, .TOC.-jump_fcontext@l + .localentry jump_fcontext, . - jump_fcontext +#else + .section ".opd","aw" + .align 3 +jump_fcontext: +# ifdef _CALL_LINUX + .quad .L.jump_fcontext,.TOC.@tocbase,0 + .type jump_fcontext,@function + .text + .align 2 +.L.jump_fcontext: +# else + .hidden .jump_fcontext + .globl .jump_fcontext + .quad .jump_fcontext,.TOC.@tocbase,0 + .size jump_fcontext,24 + .type .jump_fcontext,@function + .text + .align 2 +.jump_fcontext: +# endif +#endif + # reserve space on stack + subi %r1, %r1, 184 + +#if _CALL_ELF != 2 + std %r2, 0(%r1) # save TOC +#endif + std %r14, 8(%r1) # save R14 + std %r15, 16(%r1) # save R15 + std %r16, 24(%r1) # save R16 + std %r17, 32(%r1) # save R17 + std %r18, 40(%r1) # save R18 + std %r19, 48(%r1) # save R19 + std %r20, 56(%r1) # save R20 + std %r21, 64(%r1) # save R21 + std %r22, 72(%r1) # save R22 + std %r23, 80(%r1) # save R23 + std %r24, 88(%r1) # save R24 + std %r25, 96(%r1) # save R25 + std %r26, 104(%r1) # save R26 + std %r27, 112(%r1) # save R27 + std %r28, 120(%r1) # save R28 + std %r29, 128(%r1) # save R29 + std %r30, 136(%r1) # save R30 + std %r31, 144(%r1) # save R31 +#if _CALL_ELF != 2 + std %r3, 152(%r1) # save hidden +#endif + + # save CR + mfcr %r0 + std %r0, 160(%r1) + # save LR + mflr %r0 + std %r0, 168(%r1) + # save LR as PC + std %r0, 176(%r1) + + # store RSP (pointing to context-data) in R6 + mr %r6, %r1 + +#if _CALL_ELF == 2 + # restore RSP (pointing to context-data) from R3 + mr %r1, %r3 +#else + # restore RSP (pointing to context-data) from R4 + mr %r1, %r4 + + ld %r2, 0(%r1) # restore TOC +#endif + ld %r14, 8(%r1) # restore R14 + ld %r15, 16(%r1) # restore R15 + ld %r16, 24(%r1) # restore R16 + ld %r17, 32(%r1) # restore R17 + ld %r18, 40(%r1) # restore R18 + ld %r19, 48(%r1) # restore R19 + ld %r20, 56(%r1) # restore R20 + ld %r21, 64(%r1) # restore R21 + ld %r22, 72(%r1) # restore R22 + ld %r23, 80(%r1) # restore R23 + ld %r24, 88(%r1) # restore R24 + ld %r25, 96(%r1) # restore R25 + ld %r26, 104(%r1) # restore R26 + ld %r27, 112(%r1) # restore R27 + ld %r28, 120(%r1) # restore R28 + ld %r29, 128(%r1) # restore R29 + ld %r30, 136(%r1) # restore R30 + ld %r31, 144(%r1) # restore R31 +#if _CALL_ELF != 2 + ld %r3, 152(%r1) # restore hidden +#endif + + # restore CR + ld %r0, 160(%r1) + mtcr %r0 + # restore LR + ld %r0, 168(%r1) + mtlr %r0 + + # load PC + ld %r12, 176(%r1) + # restore CTR + mtctr %r12 + + # adjust stack + addi %r1, %r1, 184 + +#if _CALL_ELF == 2 + # copy transfer_t into transfer_fn arg registers + mr %r3, %r6 + # arg pointer already in %r4 + + # jump to context + bctr + .size jump_fcontext, .-jump_fcontext +#else + # zero in r3 indicates first jump to context-function + cmpdi %r3, 0 + beq use_entry_arg + + # return transfer_t + std %r6, 0(%r3) + std %r5, 8(%r3) + + # jump to context + bctr + +use_entry_arg: + # copy transfer_t into transfer_fn arg registers + mr %r3, %r6 + mr %r4, %r5 + + # jump to context + bctr +# ifdef _CALL_LINUX + .size .jump_fcontext, .-.L.jump_fcontext +# else + .size .jump_fcontext, .-.jump_fcontext +# endif +#endif + + +/* Mark that we don't need executable stack. */ +.section .note.GNU-stack,"",%progbits diff --git a/third_party/context/src/asm/jump_ppc64_sysv_macho_gas.S b/third_party/context/src/asm/jump_ppc64_sysv_macho_gas.S new file mode 100644 index 0000000..dcc6c64 --- /dev/null +++ b/third_party/context/src/asm/jump_ppc64_sysv_macho_gas.S @@ -0,0 +1,164 @@ +/* + Copyright Oliver Kowalke 2009. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/******************************************************* + * * + * ------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ------------------------------------------------- * + * | 0 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | * + * ------------------------------------------------- * + * | R13 | R14 | R15 | R16 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ------------------------------------------------- * + * | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | * + * ------------------------------------------------- * + * | R17 | R18 | R19 | R20 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * + * ------------------------------------------------- * + * | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | * + * ------------------------------------------------- * + * | R21 | R22 | R23 | R24 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * + * ------------------------------------------------- * + * | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | * + * ------------------------------------------------- * + * | R25 | R26 | R27 | R28 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * + * ------------------------------------------------- * + * | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | * + * ------------------------------------------------- * + * | R29 | R30 | R31 | hidden | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | * + * ------------------------------------------------- * + * | 160 | 164 | 168 | 172 | 176 | 180 | 184 | 188 | * + * ------------------------------------------------- * + * | CR | LR | PC | back-chain| * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | * + * ------------------------------------------------- * + * | 192 | 196 | 200 | 204 | 208 | 212 | 216 | 220 | * + * ------------------------------------------------- * + * | cr saved | lr saved | compiler | linker | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | * + * ------------------------------------------------- * + * | 224 | 228 | 232 | 236 | 240 | 244 | 248 | 252 | * + * ------------------------------------------------- * + * | FCTX | DATA | | | * + * ------------------------------------------------- * + * * + *******************************************************/ + +.text +.align 2 +.globl _jump_fcontext + +_jump_fcontext: + ; reserve space on stack + subi r1, r1, 184 + + std r14, 8(r1) ; save R14 + std r15, 16(r1) ; save R15 + std r16, 24(r1) ; save R16 + std r17, 32(r1) ; save R17 + std r18, 40(r1) ; save R18 + std r19, 48(r1) ; save R19 + std r20, 56(r1) ; save R20 + std r21, 64(r1) ; save R21 + std r22, 72(r1) ; save R22 + std r23, 80(r1) ; save R23 + std r24, 88(r1) ; save R24 + std r25, 96(r1) ; save R25 + std r26, 104(r1) ; save R26 + std r27, 112(r1) ; save R27 + std r28, 120(r1) ; save R28 + std r29, 128(r1) ; save R29 + std r30, 136(r1) ; save R30 + std r31, 144(r1) ; save R31 + std r3, 152(r1) ; save hidden + + ; save CR + mfcr r0 + std r0, 160(r1) + ; save LR + mflr r0 + std r0, 168(r1) + ; save LR as PC + std r0, 176(r1) + + ; store RSP (pointing to context-data) in R6 + mr r6, r1 + + ; restore RSP (pointing to context-data) from R4 + mr r1, r4 + + ld r14, 8(r1) ; restore R14 + ld r15, 16(r1) ; restore R15 + ld r16, 24(r1) ; restore R16 + ld r17, 32(r1) ; restore R17 + ld r18, 40(r1) ; restore R18 + ld r19, 48(r1) ; restore R19 + ld r20, 56(r1) ; restore R20 + ld r21, 64(r1) ; restore R21 + ld r22, 72(r1) ; restore R22 + ld r23, 80(r1) ; restore R23 + ld r24, 88(r1) ; restore R24 + ld r25, 96(r1) ; restore R25 + ld r26, 104(r1) ; restore R26 + ld r27, 112(r1) ; restore R27 + ld r28, 120(r1) ; restore R28 + ld r29, 128(r1) ; restore R29 + ld r30, 136(r1) ; restore R30 + ld r31, 144(r1) ; restore R31 + ld r3, 152(r1) ; restore hidden + + ; restore CR + ld r0, 160(r1) + mtcr r0 + ; restore LR + ld r0, 168(r1) + mtlr r0 + + ; load PC + ld r12, 176(r1) + ; restore CTR + mtctr r12 + + ; adjust stack + addi r1, r1, 184 + + ; zero in r3 indicates first jump to context-function + cmpdi r3, 0 + beq use_entry_arg + + ; return transfer_t + std r6, 0(r3) + std r5, 8(r3) + + ; jump to context + bctr + +use_entry_arg: + ; copy transfer_t into transfer_fn arg registers + mr r3, r6 + mr r4, r5 + + ; jump to context + bctr diff --git a/third_party/context/src/asm/jump_ppc64_sysv_xcoff_gas.S b/third_party/context/src/asm/jump_ppc64_sysv_xcoff_gas.S new file mode 100644 index 0000000..f835d2a --- /dev/null +++ b/third_party/context/src/asm/jump_ppc64_sysv_xcoff_gas.S @@ -0,0 +1,173 @@ + +/* + Copyright Oliver Kowalke 2009. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/******************************************************* + * * + * ------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ------------------------------------------------- * + * | 0 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | * + * ------------------------------------------------- * + * | TOC | R14 | R15 | R16 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ------------------------------------------------- * + * | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | * + * ------------------------------------------------- * + * | R17 | R18 | R19 | R20 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * + * ------------------------------------------------- * + * | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | * + * ------------------------------------------------- * + * | R21 | R22 | R23 | R24 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * + * ------------------------------------------------- * + * | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | * + * ------------------------------------------------- * + * | R25 | R26 | R27 | R28 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * + * ------------------------------------------------- * + * | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | * + * ------------------------------------------------- * + * | R29 | R30 | R31 | hidden | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | * + * ------------------------------------------------- * + * | 160 | 164 | 168 | 172 | 176 | 180 | 184 | 188 | * + * ------------------------------------------------- * + * | CR | LR | PC | back-chain| * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | * + * ------------------------------------------------- * + * | 192 | 196 | 200 | 204 | 208 | 212 | 216 | 220 | * + * ------------------------------------------------- * + * | cr saved | lr saved | compiler | linker | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | * + * ------------------------------------------------- * + * | 224 | 228 | 232 | 236 | 240 | 244 | 248 | 252 | * + * ------------------------------------------------- * + * | TOC saved | FCTX | DATA | | * + * ------------------------------------------------- * + * * + *******************************************************/ + + .file "jump_ppc64_sysv_xcoff_gas.S" + .toc + .csect .text[PR], 5 + .align 2 + .globl jump_fcontext[DS] + .globl .jump_fcontext + .csect jump_fcontext[DS], 3 +jump_fcontext: + .llong .jump_fcontext[PR], TOC[tc0], 0 + .csect .text[PR], 5 +.jump_fcontext: + # reserve space on stack + subi 1, 1, 184 + + std 2, 0(1) # save TOC + std 14, 8(1) # save R14 + std 15, 16(1) # save R15 + std 16, 24(1) # save R16 + std 17, 32(1) # save R17 + std 18, 40(1) # save R18 + std 19, 48(1) # save R19 + std 20, 56(1) # save R20 + std 21, 64(1) # save R21 + std 22, 72(1) # save R22 + std 23, 80(1) # save R23 + std 24, 88(1) # save R24 + std 25, 96(1) # save R25 + std 26, 104(1) # save R26 + std 27, 112(1) # save R27 + std 28, 120(1) # save R28 + std 29, 128(1) # save R29 + std 30, 136(1) # save R30 + std 31, 144(1) # save R31 + std 3, 152(1) # save hidden + + # save CR + mfcr 0 + std 0, 160(1) + # save LR + mflr 0 + std 0, 168(1) + # save LR as PC + std 0, 176(1) + + # store RSP (pointing to context-data) in R6 + mr 6, 1 + + # restore RSP (pointing to context-data) from R4 + mr 1, 4 + + ld 2, 0(1) # restore TOC + ld 14, 8(1) # restore R14 + ld 15, 16(1) # restore R15 + ld 16, 24(1) # restore R16 + ld 17, 32(1) # restore R17 + ld 18, 40(1) # restore R18 + ld 19, 48(1) # restore R19 + ld 20, 56(1) # restore R20 + ld 21, 64(1) # restore R21 + ld 22, 72(1) # restore R22 + ld 23, 80(1) # restore R23 + ld 24, 88(1) # restore R24 + ld 25, 96(1) # restore R25 + ld 26, 104(1) # restore R26 + ld 27, 112(1) # restore R27 + ld 28, 120(1) # restore R28 + ld 29, 128(1) # restore R29 + ld 30, 136(1) # restore R30 + ld 31, 144(1) # restore R31 + ld 3, 152(1) # restore hidden + + # restore CR + ld 0, 160(1) + mtcr 0 + # restore LR + ld 0, 168(1) + mtlr 0 + + # load PC + ld 0, 176(1) + # restore CTR + mtctr 0 + + # adjust stack + addi 1, 1, 184 + + # zero in r3 indicates first jump to context-function + cmpdi 3, 0 + beq use_entry_arg + + # return transfer_t + std 6, 0(3) + std 5, 8(3) + + # jump to context + bctr + +use_entry_arg: + # copy transfer_t into transfer_fn arg registers + mr 3, 6 + mr 4, 5 + + # jump to context + bctr diff --git a/third_party/context/src/asm/jump_riscv64_sysv_elf_gas.S b/third_party/context/src/asm/jump_riscv64_sysv_elf_gas.S new file mode 100644 index 0000000..5417e5d --- /dev/null +++ b/third_party/context/src/asm/jump_riscv64_sysv_elf_gas.S @@ -0,0 +1,150 @@ +/* + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ +/******************************************************* + * * + * ------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ------------------------------------------------- * + * | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| * + * ------------------------------------------------- * + * | fs0 | fs1 | fs2 | fs3 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ------------------------------------------------- * + * | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| * + * ------------------------------------------------- * + * | fs4 | fs5 | fs6 | fs7 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * + * ------------------------------------------------- * + * | 0x40| 0x44| 0x48| 0x4c| 0x50| 0x54| 0x58| 0x5c| * + * ------------------------------------------------- * + * | fs8 | fs9 | fs10 | fs11 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * + * ------------------------------------------------- * + * | 0x60| 0x64| 0x68| 0x6c| 0x70| 0x74| 0x78| 0x7c| * + * ------------------------------------------------- * + * | s0 | s1 | s2 | s3 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * + * ------------------------------------------------- * + * | 0x80| 0x84| 0x88| 0x8c| 0x90| 0x94| 0x98| 0x9c| * + * ------------------------------------------------- * + * | s4 | s5 | s6 | s7 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | * + * ------------------------------------------------- * + * | 0xa0| 0xa4| 0xa8| 0xac| 0xb0| 0xb4| 0xb8| 0xbc| * + * ------------------------------------------------- * + * | s8 | s9 | s10 | s11 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 48 | 49 | 50 | 51 | | | | | * + * ------------------------------------------------- * + * | 0xc0| 0xc4| 0xc8| 0xcc| | | | | * + * ------------------------------------------------- * + * | ra | pc | | | * + * ------------------------------------------------- * + * * + *******************************************************/ + +.file "jump_riscv64_sysv_elf_gas.S" +.text +.align 1 +.global jump_fcontext +.type jump_fcontext, %function +jump_fcontext: + # prepare stack for GP + FPU + addi sp, sp, -0xd0 + + # save fs0 - fs11 + fsd fs0, 0x00(sp) + fsd fs1, 0x08(sp) + fsd fs2, 0x10(sp) + fsd fs3, 0x18(sp) + fsd fs4, 0x20(sp) + fsd fs5, 0x28(sp) + fsd fs6, 0x30(sp) + fsd fs7, 0x38(sp) + fsd fs8, 0x40(sp) + fsd fs9, 0x48(sp) + fsd fs10, 0x50(sp) + fsd fs11, 0x58(sp) + + # save s0-s11, ra + sd s0, 0x60(sp) + sd s1, 0x68(sp) + sd s2, 0x70(sp) + sd s3, 0x78(sp) + sd s4, 0x80(sp) + sd s5, 0x88(sp) + sd s6, 0x90(sp) + sd s7, 0x98(sp) + sd s8, 0xa0(sp) + sd s9, 0xa8(sp) + sd s10, 0xb0(sp) + sd s11, 0xb8(sp) + sd ra, 0xc0(sp) + + # save RA as PC + sd ra, 0xc8(sp) + + # store SP (pointing to context-data) in A2 + mv a2, sp + + # restore SP (pointing to context-data) from A0 + mv sp, a0 + + # load fs0 - fs11 + fld fs0, 0x00(sp) + fld fs1, 0x08(sp) + fld fs2, 0x10(sp) + fld fs3, 0x18(sp) + fld fs4, 0x20(sp) + fld fs5, 0x28(sp) + fld fs6, 0x30(sp) + fld fs7, 0x38(sp) + fld fs8, 0x40(sp) + fld fs9, 0x48(sp) + fld fs10, 0x50(sp) + fld fs11, 0x58(sp) + + # load s0-s11,ra + ld s0, 0x60(sp) + ld s1, 0x68(sp) + ld s2, 0x70(sp) + ld s3, 0x78(sp) + ld s4, 0x80(sp) + ld s5, 0x88(sp) + ld s6, 0x90(sp) + ld s7, 0x98(sp) + ld s8, 0xa0(sp) + ld s9, 0xa8(sp) + ld s10, 0xb0(sp) + ld s11, 0xb8(sp) + ld ra, 0xc0(sp) + + # return transfer_t from jump + # pass transfer_t as first arg in context function + # a0 == FCTX, a1 == DATA + mv a0, a2 + + # load pc + ld a2, 0xc8(sp) + + # restore stack from GP + FPU + addi sp, sp, 0xd0 + + jr a2 +.size jump_fcontext,.-jump_fcontext +# Mark that we don't need executable stack. +.section .note.GNU-stack,"",%progbits diff --git a/third_party/context/src/asm/jump_s390x_sysv_elf_gas.S b/third_party/context/src/asm/jump_s390x_sysv_elf_gas.S new file mode 100644 index 0000000..c2a578b --- /dev/null +++ b/third_party/context/src/asm/jump_s390x_sysv_elf_gas.S @@ -0,0 +1,156 @@ +/******************************************************* + * ------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ------------------------------------------------- * + * | 0 | 8 | 16 | 24 | * + * ------------------------------------------------- * + * | t.fctx | t.data | r2 | r6 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ------------------------------------------------- * + * | 32 | 40 | 48 | 56 | * + * ------------------------------------------------- * + * | r7 | r8 | r9 | r10 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * + * ------------------------------------------------- * + * | 64 | 72 | 80 | 88 | * + * ------------------------------------------------- * + * | r11 | r12 | r13 | r14 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * + * ------------------------------------------------- * + * | 96 | 104 | 112 | 120 | * + * ------------------------------------------------- * + * | f8 | f9 | f10 | f11 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * + * ------------------------------------------------- * + * | 128 | 136 | 144 | 152 | * + * ------------------------------------------------- * + * | f12 | f13 | f14 | f15 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | * + * ------------------------------------------------- * + * | 160 | 168 | 176 | | * + * ------------------------------------------------- * + * | fpc | pc | | | * + * ------------------------------------------------- * + *******************************************************/ + +.text +.align 8 +.global jump_fcontext +.type jump_fcontext, @function + +#define ARG_OFFSET 0 +#define GR_OFFSET 16 +#define FP_OFFSET 96 +#define FPC_OFFSET 160 +#define PC_OFFSET 168 +#define CONTEXT_SIZE 176 + +#define REG_SAVE_AREA_SIZE 160 + +/* + +typedef void* fcontext_t; + +struct transfer_t { + fcontext_t fctx; + void * data; +}; + +transfer_t jump_fcontext( fcontext_t const to, + void * data); + +Incoming args +r2 - Hidden argument to the location where the return transfer_t needs to be returned +r3 - Context we want to switch to +r4 - Data pointer + +*/ + +jump_fcontext: + .machine "z10" + /* Reserve stack space to store the current context. */ + aghi %r15,-CONTEXT_SIZE + + /* Save the argument register holding the location of the return value. */ + stg %r2,GR_OFFSET(%r15) + + /* Save the call-saved general purpose registers. */ + stmg %r6,%r14,GR_OFFSET+8(%r15) + + /* Save call-saved floating point registers. */ + std %f8,FP_OFFSET(%r15) + std %f9,FP_OFFSET+8(%r15) + std %f10,FP_OFFSET+16(%r15) + std %f11,FP_OFFSET+24(%r15) + std %f12,FP_OFFSET+32(%r15) + std %f13,FP_OFFSET+40(%r15) + std %f14,FP_OFFSET+48(%r15) + std %f15,FP_OFFSET+56(%r15) + + /* Save the return address as current pc. */ + stg %r14,PC_OFFSET(%r15) + + /* Save the floating point control register. */ + stfpc FPC_OFFSET(%r15) + + /* Backup the stack pointer pointing to the old context-data into r1. */ + lgr %r1,%r15 + + /* Load the new context pointer as stack pointer. */ + lgr %r15,%r3 + + /* Restore the call-saved GPRs from the new context. */ + lmg %r6,%r14,GR_OFFSET+8(%r15) + + /* Restore call-saved floating point registers. */ + ld %f8,FP_OFFSET(%r15) + ld %f9,FP_OFFSET+8(%r15) + ld %f10,FP_OFFSET+16(%r15) + ld %f11,FP_OFFSET+24(%r15) + ld %f12,FP_OFFSET+32(%r15) + ld %f13,FP_OFFSET+40(%r15) + ld %f14,FP_OFFSET+48(%r15) + ld %f15,FP_OFFSET+56(%r15) + + /* Load the floating point control register. */ + lfpc FPC_OFFSET(%r15) + + /* Restore PC - the location where we will jump to at the end. */ + lg %r5,PC_OFFSET(%r15) + + ltg %r2,GR_OFFSET(%r15) + jnz use_return_slot + + /* We restore a make_fcontext context. Use the function + argument slot in the context we just saved and allocate the + register save area for the target function. */ + la %r2,ARG_OFFSET(%r1) + aghi %r15,-REG_SAVE_AREA_SIZE + +use_return_slot: + /* Save the two fields in transfer_t. When calling a + make_fcontext function this becomes the function argument of + the target function, otherwise it will be the return value of + jump_fcontext. */ + stg %r1,0(%r2) + stg %r4,8(%r2) + + /* Free the restored context. */ + aghi %r15,CONTEXT_SIZE + + /* Jump to the PC loaded from the new context. */ + br %r5 + + +.size jump_fcontext,.-jump_fcontext +.section .note.GNU-stack,"",%progbits diff --git a/third_party/context/src/asm/jump_x86_64_ms_pe_clang_gas.S b/third_party/context/src/asm/jump_x86_64_ms_pe_clang_gas.S new file mode 100644 index 0000000..1f633f7 --- /dev/null +++ b/third_party/context/src/asm/jump_x86_64_ms_pe_clang_gas.S @@ -0,0 +1,209 @@ +/* + Copyright Oliver Kowalke 2009. + Copyright Thomas Sailer 2013. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/************************************************************************************* +* ---------------------------------------------------------------------------------- * +* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * +* ---------------------------------------------------------------------------------- * +* | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | * +* ---------------------------------------------------------------------------------- * +* | SEE registers (XMM6-XMM15) | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * +* ---------------------------------------------------------------------------------- * +* | 0x20 | 0x24 | 0x28 | 0x2c | 0x30 | 0x34 | 0x38 | 0x3c | * +* ---------------------------------------------------------------------------------- * +* | SEE registers (XMM6-XMM15) | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * +* ---------------------------------------------------------------------------------- * +* | 0xe40 | 0x44 | 0x48 | 0x4c | 0x50 | 0x54 | 0x58 | 0x5c | * +* ---------------------------------------------------------------------------------- * +* | SEE registers (XMM6-XMM15) | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * +* ---------------------------------------------------------------------------------- * +* | 0x60 | 0x64 | 0x68 | 0x6c | 0x70 | 0x74 | 0x78 | 0x7c | * +* ---------------------------------------------------------------------------------- * +* | SEE registers (XMM6-XMM15) | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 32 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | * +* ---------------------------------------------------------------------------------- * +* | 0x80 | 0x84 | 0x88 | 0x8c | 0x90 | 0x94 | 0x98 | 0x9c | * +* ---------------------------------------------------------------------------------- * +* | SEE registers (XMM6-XMM15) | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | * +* ---------------------------------------------------------------------------------- * +* | 0xa0 | 0xa4 | 0xa8 | 0xac | 0xb0 | 0xb4 | 0xb8 | 0xbc | * +* ---------------------------------------------------------------------------------- * +* | fc_mxcsr|fc_x87_cw| | fbr_strg | fc_dealloc | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | * +* ---------------------------------------------------------------------------------- * +* | 0xc0 | 0xc4 | 0xc8 | 0xcc | 0xd0 | 0xd4 | 0xd8 | 0xdc | * +* ---------------------------------------------------------------------------------- * +* | limit | base | R12 | R13 | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | * +* ---------------------------------------------------------------------------------- * +* | 0xe0 | 0xe4 | 0xe8 | 0xec | 0xf0 | 0xf4 | 0xf8 | 0xfc | * +* ---------------------------------------------------------------------------------- * +* | R14 | R15 | RDI | RSI | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | * +* ---------------------------------------------------------------------------------- * +* | 0x100 | 0x104 | 0x108 | 0x10c | 0x110 | 0x114 | 0x118 | 0x11c | * +* ---------------------------------------------------------------------------------- * +* | RBX | RBP | hidden | RIP | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | * +* ---------------------------------------------------------------------------------- * +* | 0x120 | 0x124 | 0x128 | 0x12c | 0x130 | 0x134 | 0x138 | 0x13c | * +* ---------------------------------------------------------------------------------- * +* | parameter area | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | * +* ---------------------------------------------------------------------------------- * +* | 0x140 | 0x144 | 0x148 | 0x14c | 0x150 | 0x154 | 0x158 | 0x15c | * +* ---------------------------------------------------------------------------------- * +* | FCTX | DATA | | * +* ---------------------------------------------------------------------------------- * +**************************************************************************************/ + +.file "jump_x86_64_ms_pe_clang_gas.S" +.text +.p2align 4,,15 +.globl jump_fcontext +.def jump_fcontext; .scl 2; .type 32; .endef +.seh_proc jump_fcontext +jump_fcontext: +.seh_endprologue + + leaq -0x118(%rsp), %rsp /* prepare stack */ + +#if !defined(BOOST_USE_TSX) + /* save XMM storage */ + movaps %xmm6, 0x0(%rsp) + movaps %xmm7, 0x10(%rsp) + movaps %xmm8, 0x20(%rsp) + movaps %xmm9, 0x30(%rsp) + movaps %xmm10, 0x40(%rsp) + movaps %xmm11, 0x50(%rsp) + movaps %xmm12, 0x60(%rsp) + movaps %xmm13, 0x70(%rsp) + movaps %xmm14, 0x80(%rsp) + movaps %xmm15, 0x90(%rsp) + stmxcsr 0xa0(%rsp) /* save MMX control- and status-word */ + fnstcw 0xa4(%rsp) /* save x87 control-word */ +#endif + + /* load NT_TIB */ + movq %gs:(0x30), %r10 + /* save fiber local storage */ + movq 0x20(%r10), %rax + movq %rax, 0xb0(%rsp) + /* save current deallocation stack */ + movq 0x1478(%r10), %rax + movq %rax, 0xb8(%rsp) + /* save current stack limit */ + movq 0x10(%r10), %rax + movq %rax, 0xc0(%rsp) + /* save current stack base */ + movq 0x08(%r10), %rax + movq %rax, 0xc8(%rsp) + + movq %r12, 0xd0(%rsp) /* save R12 */ + movq %r13, 0xd8(%rsp) /* save R13 */ + movq %r14, 0xe0(%rsp) /* save R14 */ + movq %r15, 0xe8(%rsp) /* save R15 */ + movq %rdi, 0xf0(%rsp) /* save RDI */ + movq %rsi, 0xf8(%rsp) /* save RSI */ + movq %rbx, 0x100(%rsp) /* save RBX */ + movq %rbp, 0x108(%rsp) /* save RBP */ + + movq %rcx, 0x110(%rsp) /* save hidden address of transport_t */ + + /* preserve RSP (pointing to context-data) in R9 */ + movq %rsp, %r9 + + /* restore RSP (pointing to context-data) from RDX */ + movq %rdx, %rsp + +#if !defined(BOOST_USE_TSX) + /* restore XMM storage */ + movaps 0x0(%rsp), %xmm6 + movaps 0x10(%rsp), %xmm7 + movaps 0x20(%rsp), %xmm8 + movaps 0x30(%rsp), %xmm9 + movaps 0x40(%rsp), %xmm10 + movaps 0x50(%rsp), %xmm11 + movaps 0x60(%rsp), %xmm12 + movaps 0x70(%rsp), %xmm13 + movaps 0x80(%rsp), %xmm14 + movaps 0x90(%rsp), %xmm15 + ldmxcsr 0xa0(%rsp) /* restore MMX control- and status-word */ + fldcw 0xa4(%rsp) /* restore x87 control-word */ +#endif + + /* load NT_TIB */ + movq %gs:(0x30), %r10 + /* restore fiber local storage */ + movq 0xb0(%rsp), %rax + movq %rax, 0x20(%r10) + /* restore current deallocation stack */ + movq 0xb8(%rsp), %rax + movq %rax, 0x1478(%r10) + /* restore current stack limit */ + movq 0xc0(%rsp), %rax + movq %rax, 0x10(%r10) + /* restore current stack base */ + movq 0xc8(%rsp), %rax + movq %rax, 0x08(%r10) + + movq 0xd0(%rsp), %r12 /* restore R12 */ + movq 0xd8(%rsp), %r13 /* restore R13 */ + movq 0xe0(%rsp), %r14 /* restore R14 */ + movq 0xe8(%rsp), %r15 /* restore R15 */ + movq 0xf0(%rsp), %rdi /* restore RDI */ + movq 0xf8(%rsp), %rsi /* restore RSI */ + movq 0x100(%rsp), %rbx /* restore RBX */ + movq 0x108(%rsp), %rbp /* restore RBP */ + + movq 0x110(%rsp), %rax /* restore hidden address of transport_t */ + + leaq 0x118(%rsp), %rsp /* prepare stack */ + + /* restore return-address */ + popq %r10 + + /* transport_t returned in RAX */ + /* return parent fcontext_t */ + movq %r9, 0x0(%rax) + /* return data */ + movq %r8, 0x8(%rax) + + /* transport_t as 1.arg of context-function */ + movq %rax, %rcx + + /* indirect jump to context */ + jmp *%r10 +.seh_endproc + +.section .drectve +.ascii " -export:\"jump_fcontext\"" diff --git a/third_party/context/src/asm/jump_x86_64_ms_pe_gas.asm b/third_party/context/src/asm/jump_x86_64_ms_pe_gas.asm new file mode 100644 index 0000000..ec4ecfe --- /dev/null +++ b/third_party/context/src/asm/jump_x86_64_ms_pe_gas.asm @@ -0,0 +1,209 @@ +/* + Copyright Oliver Kowalke 2009. + Copyright Thomas Sailer 2013. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/************************************************************************************* +* ---------------------------------------------------------------------------------- * +* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * +* ---------------------------------------------------------------------------------- * +* | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | * +* ---------------------------------------------------------------------------------- * +* | SEE registers (XMM6-XMM15) | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * +* ---------------------------------------------------------------------------------- * +* | 0x20 | 0x24 | 0x28 | 0x2c | 0x30 | 0x34 | 0x38 | 0x3c | * +* ---------------------------------------------------------------------------------- * +* | SEE registers (XMM6-XMM15) | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * +* ---------------------------------------------------------------------------------- * +* | 0xe40 | 0x44 | 0x48 | 0x4c | 0x50 | 0x54 | 0x58 | 0x5c | * +* ---------------------------------------------------------------------------------- * +* | SEE registers (XMM6-XMM15) | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * +* ---------------------------------------------------------------------------------- * +* | 0x60 | 0x64 | 0x68 | 0x6c | 0x70 | 0x74 | 0x78 | 0x7c | * +* ---------------------------------------------------------------------------------- * +* | SEE registers (XMM6-XMM15) | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 32 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | * +* ---------------------------------------------------------------------------------- * +* | 0x80 | 0x84 | 0x88 | 0x8c | 0x90 | 0x94 | 0x98 | 0x9c | * +* ---------------------------------------------------------------------------------- * +* | SEE registers (XMM6-XMM15) | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | * +* ---------------------------------------------------------------------------------- * +* | 0xa0 | 0xa4 | 0xa8 | 0xac | 0xb0 | 0xb4 | 0xb8 | 0xbc | * +* ---------------------------------------------------------------------------------- * +* | fc_mxcsr|fc_x87_cw| | fbr_strg | fc_dealloc | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | * +* ---------------------------------------------------------------------------------- * +* | 0xc0 | 0xc4 | 0xc8 | 0xcc | 0xd0 | 0xd4 | 0xd8 | 0xdc | * +* ---------------------------------------------------------------------------------- * +* | limit | base | R12 | R13 | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | * +* ---------------------------------------------------------------------------------- * +* | 0xe0 | 0xe4 | 0xe8 | 0xec | 0xf0 | 0xf4 | 0xf8 | 0xfc | * +* ---------------------------------------------------------------------------------- * +* | R14 | R15 | RDI | RSI | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | * +* ---------------------------------------------------------------------------------- * +* | 0x100 | 0x104 | 0x108 | 0x10c | 0x110 | 0x114 | 0x118 | 0x11c | * +* ---------------------------------------------------------------------------------- * +* | RBX | RBP | hidden | RIP | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | * +* ---------------------------------------------------------------------------------- * +* | 0x120 | 0x124 | 0x128 | 0x12c | 0x130 | 0x134 | 0x138 | 0x13c | * +* ---------------------------------------------------------------------------------- * +* | parameter area | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | * +* ---------------------------------------------------------------------------------- * +* | 0x140 | 0x144 | 0x148 | 0x14c | 0x150 | 0x154 | 0x158 | 0x15c | * +* ---------------------------------------------------------------------------------- * +* | FCTX | DATA | | * +* ---------------------------------------------------------------------------------- * +**************************************************************************************/ + +.file "jump_x86_64_ms_pe_gas.asm" +.text +.p2align 4,,15 +.globl jump_fcontext +.def jump_fcontext; .scl 2; .type 32; .endef +.seh_proc jump_fcontext +jump_fcontext: +.seh_endprologue + + leaq -0x118(%rsp), %rsp /* prepare stack */ + +#if !defined(BOOST_USE_TSX) + /* save XMM storage */ + movaps %xmm6, 0x0(%rsp) + movaps %xmm7, 0x10(%rsp) + movaps %xmm8, 0x20(%rsp) + movaps %xmm9, 0x30(%rsp) + movaps %xmm10, 0x40(%rsp) + movaps %xmm11, 0x50(%rsp) + movaps %xmm12, 0x60(%rsp) + movaps %xmm13, 0x70(%rsp) + movaps %xmm14, 0x80(%rsp) + movaps %xmm15, 0x90(%rsp) + stmxcsr 0xa0(%rsp) /* save MMX control- and status-word */ + fnstcw 0xa4(%rsp) /* save x87 control-word */ +#endif + + /* load NT_TIB */ + movq %gs:(0x30), %r10 + /* save fiber local storage */ + movq 0x20(%r10), %rax + movq %rax, 0xb0(%rsp) + /* save current deallocation stack */ + movq 0x1478(%r10), %rax + movq %rax, 0xb8(%rsp) + /* save current stack limit */ + movq 0x10(%r10), %rax + movq %rax, 0xc0(%rsp) + /* save current stack base */ + movq 0x08(%r10), %rax + movq %rax, 0xc8(%rsp) + + movq %r12, 0xd0(%rsp) /* save R12 */ + movq %r13, 0xd8(%rsp) /* save R13 */ + movq %r14, 0xe0(%rsp) /* save R14 */ + movq %r15, 0xe8(%rsp) /* save R15 */ + movq %rdi, 0xf0(%rsp) /* save RDI */ + movq %rsi, 0xf8(%rsp) /* save RSI */ + movq %rbx, 0x100(%rsp) /* save RBX */ + movq %rbp, 0x108(%rsp) /* save RBP */ + + movq %rcx, 0x110(%rsp) /* save hidden address of transport_t */ + + /* preserve RSP (pointing to context-data) in R9 */ + movq %rsp, %r9 + + /* restore RSP (pointing to context-data) from RDX */ + movq %rdx, %rsp + +#if !defined(BOOST_USE_TSX) + /* restore XMM storage */ + movaps 0x0(%rsp), %xmm6 + movaps 0x10(%rsp), %xmm7 + movaps 0x20(%rsp), %xmm8 + movaps 0x30(%rsp), %xmm9 + movaps 0x40(%rsp), %xmm10 + movaps 0x50(%rsp), %xmm11 + movaps 0x60(%rsp), %xmm12 + movaps 0x70(%rsp), %xmm13 + movaps 0x80(%rsp), %xmm14 + movaps 0x90(%rsp), %xmm15 + ldmxcsr 0xa0(%rsp) /* restore MMX control- and status-word */ + fldcw 0xa4(%rsp) /* restore x87 control-word */ +#endif + + /* load NT_TIB */ + movq %gs:(0x30), %r10 + /* restore fiber local storage */ + movq 0xb0(%rsp), %rax + movq %rax, 0x20(%r10) + /* restore current deallocation stack */ + movq 0xb8(%rsp), %rax + movq %rax, 0x1478(%r10) + /* restore current stack limit */ + movq 0xc0(%rsp), %rax + movq %rax, 0x10(%r10) + /* restore current stack base */ + movq 0xc8(%rsp), %rax + movq %rax, 0x08(%r10) + + movq 0xd0(%rsp), %r12 /* restore R12 */ + movq 0xd8(%rsp), %r13 /* restore R13 */ + movq 0xe0(%rsp), %r14 /* restore R14 */ + movq 0xe8(%rsp), %r15 /* restore R15 */ + movq 0xf0(%rsp), %rdi /* restore RDI */ + movq 0xf8(%rsp), %rsi /* restore RSI */ + movq 0x100(%rsp), %rbx /* restore RBX */ + movq 0x108(%rsp), %rbp /* restore RBP */ + + movq 0x110(%rsp), %rax /* restore hidden address of transport_t */ + + leaq 0x118(%rsp), %rsp /* prepare stack */ + + /* restore return-address */ + popq %r10 + + /* transport_t returned in RAX */ + /* return parent fcontext_t */ + movq %r9, 0x0(%rax) + /* return data */ + movq %r8, 0x8(%rax) + + /* transport_t as 1.arg of context-function */ + movq %rax, %rcx + + /* indirect jump to context */ + jmp *%r10 +.seh_endproc + +.section .drectve +.ascii " -export:\"jump_fcontext\"" diff --git a/third_party/context/src/asm/jump_x86_64_ms_pe_masm.asm b/third_party/context/src/asm/jump_x86_64_ms_pe_masm.asm new file mode 100644 index 0000000..c8a28a5 --- /dev/null +++ b/third_party/context/src/asm/jump_x86_64_ms_pe_masm.asm @@ -0,0 +1,205 @@ + +; Copyright Oliver Kowalke 2009. +; Distributed under the Boost Software License, Version 1.0. +; (See accompanying file LICENSE_1_0.txt or copy at +; http://www.boost.org/LICENSE_1_0.txt) + +; ---------------------------------------------------------------------------------- +; | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | +; ---------------------------------------------------------------------------------- +; | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | +; ---------------------------------------------------------------------------------- +; | SEE registers (XMM6-XMM15) | +; ---------------------------------------------------------------------------------- +; ---------------------------------------------------------------------------------- +; | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | +; ---------------------------------------------------------------------------------- +; | 0x20 | 0x24 | 0x28 | 0x2c | 0x30 | 0x34 | 0x38 | 0x3c | +; ---------------------------------------------------------------------------------- +; | SEE registers (XMM6-XMM15) | +; ---------------------------------------------------------------------------------- +; ---------------------------------------------------------------------------------- +; | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | +; ---------------------------------------------------------------------------------- +; | 0xe40 | 0x44 | 0x48 | 0x4c | 0x50 | 0x54 | 0x58 | 0x5c | +; ---------------------------------------------------------------------------------- +; | SEE registers (XMM6-XMM15) | +; ---------------------------------------------------------------------------------- +; ---------------------------------------------------------------------------------- +; | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | +; ---------------------------------------------------------------------------------- +; | 0x60 | 0x64 | 0x68 | 0x6c | 0x70 | 0x74 | 0x78 | 0x7c | +; ---------------------------------------------------------------------------------- +; | SEE registers (XMM6-XMM15) | +; ---------------------------------------------------------------------------------- +; ---------------------------------------------------------------------------------- +; | 32 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | +; ---------------------------------------------------------------------------------- +; | 0x80 | 0x84 | 0x88 | 0x8c | 0x90 | 0x94 | 0x98 | 0x9c | +; ---------------------------------------------------------------------------------- +; | SEE registers (XMM6-XMM15) | +; ---------------------------------------------------------------------------------- +; ---------------------------------------------------------------------------------- +; | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | +; ---------------------------------------------------------------------------------- +; | 0xa0 | 0xa4 | 0xa8 | 0xac | 0xb0 | 0xb4 | 0xb8 | 0xbc | +; ---------------------------------------------------------------------------------- +; | fc_mxcsr|fc_x87_cw| | fbr_strg | fc_dealloc | +; ---------------------------------------------------------------------------------- +; ---------------------------------------------------------------------------------- +; | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | +; ---------------------------------------------------------------------------------- +; | 0xc0 | 0xc4 | 0xc8 | 0xcc | 0xd0 | 0xd4 | 0xd8 | 0xdc | +; ---------------------------------------------------------------------------------- +; | limit | base | R12 | R13 | +; ---------------------------------------------------------------------------------- +; ---------------------------------------------------------------------------------- +; | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | +; ---------------------------------------------------------------------------------- +; | 0xe0 | 0xe4 | 0xe8 | 0xec | 0xf0 | 0xf4 | 0xf8 | 0xfc | +; ---------------------------------------------------------------------------------- +; | R14 | R15 | RDI | RSI | +; ---------------------------------------------------------------------------------- +; ---------------------------------------------------------------------------------- +; | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | +; ---------------------------------------------------------------------------------- +; | 0x100 | 0x104 | 0x108 | 0x10c | 0x110 | 0x114 | 0x118 | 0x11c | +; ---------------------------------------------------------------------------------- +; | RBX | RBP | hidden | RIP | +; ---------------------------------------------------------------------------------- +; ---------------------------------------------------------------------------------- +; | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | +; ---------------------------------------------------------------------------------- +; | 0x120 | 0x124 | 0x128 | 0x12c | 0x130 | 0x134 | 0x138 | 0x13c | +; ---------------------------------------------------------------------------------- +; | parameter area | +; ---------------------------------------------------------------------------------- +; ---------------------------------------------------------------------------------- +; | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | +; ---------------------------------------------------------------------------------- +; | 0x140 | 0x144 | 0x148 | 0x14c | 0x150 | 0x154 | 0x158 | 0x15c | +; ---------------------------------------------------------------------------------- +; | FCTX | DATA | | +; ---------------------------------------------------------------------------------- + +.code + +jump_fcontext PROC BOOST_CONTEXT_EXPORT FRAME + .endprolog + + ; prepare stack + lea rsp, [rsp-0118h] + +IFNDEF BOOST_USE_TSX + ; save XMM storage + movaps [rsp], xmm6 + movaps [rsp+010h], xmm7 + movaps [rsp+020h], xmm8 + movaps [rsp+030h], xmm9 + movaps [rsp+040h], xmm10 + movaps [rsp+050h], xmm11 + movaps [rsp+060h], xmm12 + movaps [rsp+070h], xmm13 + movaps [rsp+080h], xmm14 + movaps [rsp+090h], xmm15 + ; save MMX control- and status-word + stmxcsr [rsp+0a0h] + ; save x87 control-word + fnstcw [rsp+0a4h] +ENDIF + + ; load NT_TIB + mov r10, gs:[030h] + ; save fiber local storage + mov rax, [r10+020h] + mov [rsp+0b0h], rax + ; save current deallocation stack + mov rax, [r10+01478h] + mov [rsp+0b8h], rax + ; save current stack limit + mov rax, [r10+010h] + mov [rsp+0c0h], rax + ; save current stack base + mov rax, [r10+08h] + mov [rsp+0c8h], rax + + mov [rsp+0d0h], r12 ; save R12 + mov [rsp+0d8h], r13 ; save R13 + mov [rsp+0e0h], r14 ; save R14 + mov [rsp+0e8h], r15 ; save R15 + mov [rsp+0f0h], rdi ; save RDI + mov [rsp+0f8h], rsi ; save RSI + mov [rsp+0100h], rbx ; save RBX + mov [rsp+0108h], rbp ; save RBP + + mov [rsp+0110h], rcx ; save hidden address of transport_t + + ; preserve RSP (pointing to context-data) in R9 + mov r9, rsp + + ; restore RSP (pointing to context-data) from RDX + mov rsp, rdx + +IFNDEF BOOST_USE_TSX + ; restore XMM storage + movaps xmm6, [rsp] + movaps xmm7, [rsp+010h] + movaps xmm8, [rsp+020h] + movaps xmm9, [rsp+030h] + movaps xmm10, [rsp+040h] + movaps xmm11, [rsp+050h] + movaps xmm12, [rsp+060h] + movaps xmm13, [rsp+070h] + movaps xmm14, [rsp+080h] + movaps xmm15, [rsp+090h] + ; restore MMX control- and status-word + ldmxcsr [rsp+0a0h] + ; save x87 control-word + fldcw [rsp+0a4h] +ENDIF + + ; load NT_TIB + mov r10, gs:[030h] + ; restore fiber local storage + mov rax, [rsp+0b0h] + mov [r10+020h], rax + ; restore current deallocation stack + mov rax, [rsp+0b8h] + mov [r10+01478h], rax + ; restore current stack limit + mov rax, [rsp+0c0h] + mov [r10+010h], rax + ; restore current stack base + mov rax, [rsp+0c8h] + mov [r10+08h], rax + + mov r12, [rsp+0d0h] ; restore R12 + mov r13, [rsp+0d8h] ; restore R13 + mov r14, [rsp+0e0h] ; restore R14 + mov r15, [rsp+0e8h] ; restore R15 + mov rdi, [rsp+0f0h] ; restore RDI + mov rsi, [rsp+0f8h] ; restore RSI + mov rbx, [rsp+0100h] ; restore RBX + mov rbp, [rsp+0108h] ; restore RBP + + mov rax, [rsp+0110h] ; restore hidden address of transport_t + + ; prepare stack + lea rsp, [rsp+0118h] + + ; load return-address + pop r10 + + ; transport_t returned in RAX + ; return parent fcontext_t + mov [rax], r9 + ; return data + mov [rax+08h], r8 + + ; transport_t as 1.arg of context-function + mov rcx, rax + + ; indirect jump to context + jmp r10 +jump_fcontext ENDP +END diff --git a/third_party/context/src/asm/jump_x86_64_sysv_elf_gas.S b/third_party/context/src/asm/jump_x86_64_sysv_elf_gas.S new file mode 100644 index 0000000..58f0e24 --- /dev/null +++ b/third_party/context/src/asm/jump_x86_64_sysv_elf_gas.S @@ -0,0 +1,142 @@ +/* + Copyright Oliver Kowalke 2009. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/**************************************************************************************** + * * + * ---------------------------------------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ---------------------------------------------------------------------------------- * + * | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | * + * ---------------------------------------------------------------------------------- * + * | fc_mxcsr|fc_x87_cw| guard | R12 | R13 | * + * ---------------------------------------------------------------------------------- * + * ---------------------------------------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ---------------------------------------------------------------------------------- * + * | 0x20 | 0x24 | 0x28 | 0x2c | 0x30 | 0x34 | 0x38 | 0x3c | * + * ---------------------------------------------------------------------------------- * + * | R14 | R15 | RBX | RBP | * + * ---------------------------------------------------------------------------------- * + * ---------------------------------------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * + * ---------------------------------------------------------------------------------- * + * | 0x40 | 0x44 | | * + * ---------------------------------------------------------------------------------- * + * | RIP | | * + * ---------------------------------------------------------------------------------- * + * * + ****************************************************************************************/ + +# if defined __CET__ +# include +# define SHSTK_ENABLED (__CET__ & 0x2) +# define BOOST_CONTEXT_SHADOW_STACK (SHSTK_ENABLED && SHADOW_STACK_SYSCALL) +# else +# define _CET_ENDBR +# endif +.file "jump_x86_64_sysv_elf_gas.S" +.text +.globl jump_fcontext +.type jump_fcontext,@function +.align 16 +jump_fcontext: + _CET_ENDBR + leaq -0x40(%rsp), %rsp /* prepare stack */ + +#if !defined(BOOST_USE_TSX) + stmxcsr (%rsp) /* save MMX control- and status-word */ + fnstcw 0x4(%rsp) /* save x87 control-word */ +#endif + +#if defined(BOOST_CONTEXT_TLS_STACK_PROTECTOR) + movq %fs:0x28, %rcx /* read stack guard from TLS record */ + movq %rcx, 0x8(%rsp) /* save stack guard */ +#endif + + movq %r12, 0x10(%rsp) /* save R12 */ + movq %r13, 0x18(%rsp) /* save R13 */ + movq %r14, 0x20(%rsp) /* save R14 */ + movq %r15, 0x28(%rsp) /* save R15 */ + movq %rbx, 0x30(%rsp) /* save RBX */ + movq %rbp, 0x38(%rsp) /* save RBP */ + +#if BOOST_CONTEXT_SHADOW_STACK + /* grow the stack to reserve space for shadow stack pointer(SSP) */ + leaq -0x8(%rsp), %rsp + /* read the current SSP and store it */ + rdsspq %rcx + movq %rcx, (%rsp) +#endif + + /* store RSP (pointing to context-data) in RAX */ + movq %rsp, %rax + + /* restore RSP (pointing to context-data) from RDI */ + movq %rdi, %rsp + +#if BOOST_CONTEXT_SHADOW_STACK + /* first 8 bytes are SSP */ + movq (%rsp), %rcx + leaq 0x8(%rsp), %rsp + + /* Restore target(new) shadow stack */ + rstorssp -8(%rcx) + /* restore token for previous shadow stack is pushed */ + /* on previous shadow stack after saveprevssp */ + saveprevssp + + /* when return, jump_fcontext jump to restored return address */ + /* (r8) instead of RET. This miss of RET implies us to unwind */ + /* shadow stack accordingly. Otherwise mismatch occur */ + movq $1, %rcx + incsspq %rcx +#endif + + movq 0x40(%rsp), %r8 /* restore return-address */ + +#if !defined(BOOST_USE_TSX) + ldmxcsr (%rsp) /* restore MMX control- and status-word */ + fldcw 0x4(%rsp) /* restore x87 control-word */ +#endif + +#if defined(BOOST_CONTEXT_TLS_STACK_PROTECTOR) + movq 0x8(%rsp), %rdx /* load stack guard */ + movq %rdx, %fs:0x28 /* restore stack guard to TLS record */ +#endif + + movq 0x10(%rsp), %r12 /* restore R12 */ + movq 0x18(%rsp), %r13 /* restore R13 */ + movq 0x20(%rsp), %r14 /* restore R14 */ + movq 0x28(%rsp), %r15 /* restore R15 */ + movq 0x30(%rsp), %rbx /* restore RBX */ + movq 0x38(%rsp), %rbp /* restore RBP */ + + leaq 0x48(%rsp), %rsp /* prepare stack */ + + /* return transfer_t from jump */ +#if !defined(_ILP32) + /* RAX == fctx, RDX == data */ + movq %rsi, %rdx +#else + /* RAX == data:fctx */ + salq $32, %rsi + orq %rsi, %rax +#endif + /* pass transfer_t as first arg in context function */ +#if !defined(_ILP32) + /* RDI == fctx, RSI == data */ +#else + /* RDI == data:fctx */ +#endif + movq %rax, %rdi + + /* indirect jump to context */ + jmp *%r8 +.size jump_fcontext,.-jump_fcontext + +/* Mark that we don't need executable stack. */ +.section .note.GNU-stack,"",%progbits diff --git a/third_party/context/src/asm/jump_x86_64_sysv_macho_gas.S b/third_party/context/src/asm/jump_x86_64_sysv_macho_gas.S new file mode 100644 index 0000000..afc3e5c --- /dev/null +++ b/third_party/context/src/asm/jump_x86_64_sysv_macho_gas.S @@ -0,0 +1,75 @@ +/* + Copyright Oliver Kowalke 2009. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/**************************************************************************************** + * * + * ---------------------------------------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ---------------------------------------------------------------------------------- * + * | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | * + * ---------------------------------------------------------------------------------- * + * | fc_mxcsr|fc_x87_cw| R12 | R13 | R14 | * + * ---------------------------------------------------------------------------------- * + * ---------------------------------------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ---------------------------------------------------------------------------------- * + * | 0x20 | 0x24 | 0x28 | 0x2c | 0x30 | 0x34 | 0x38 | 0x3c | * + * ---------------------------------------------------------------------------------- * + * | R15 | RBX | RBP | RIP | * + * ---------------------------------------------------------------------------------- * + * * + ****************************************************************************************/ + +.text +.globl _jump_fcontext +.align 8 +_jump_fcontext: + leaq -0x38(%rsp), %rsp /* prepare stack */ + +#if !defined(BOOST_USE_TSX) + stmxcsr (%rsp) /* save MMX control- and status-word */ + fnstcw 0x4(%rsp) /* save x87 control-word */ +#endif + + movq %r12, 0x8(%rsp) /* save R12 */ + movq %r13, 0x10(%rsp) /* save R13 */ + movq %r14, 0x18(%rsp) /* save R14 */ + movq %r15, 0x20(%rsp) /* save R15 */ + movq %rbx, 0x28(%rsp) /* save RBX */ + movq %rbp, 0x30(%rsp) /* save RBP */ + + /* store RSP (pointing to context-data) in RAX */ + movq %rsp, %rax + + /* restore RSP (pointing to context-data) from RDI */ + movq %rdi, %rsp + + movq 0x38(%rsp), %r8 /* restore return-address */ + +#if !defined(BOOST_USE_TSX) + ldmxcsr (%rsp) /* restore MMX control- and status-word */ + fldcw 0x4(%rsp) /* restore x87 control-word */ +#endif + + movq 0x8(%rsp), %r12 /* restore R12 */ + movq 0x10(%rsp), %r13 /* restore R13 */ + movq 0x18(%rsp), %r14 /* restore R14 */ + movq 0x20(%rsp), %r15 /* restore R15 */ + movq 0x28(%rsp), %rbx /* restore RBX */ + movq 0x30(%rsp), %rbp /* restore RBP */ + + leaq 0x40(%rsp), %rsp /* prepare stack */ + + /* return transfer_t from jump */ + /* RAX == fctx, RDX == data */ + movq %rsi, %rdx + /* pass transfer_t as first arg in context function */ + /* RDI == fctx, RSI == data */ + movq %rax, %rdi + + /* indirect jump to context */ + jmp *%r8 diff --git a/third_party/context/src/asm/make_arm64_aapcs_elf_gas.S b/third_party/context/src/asm/make_arm64_aapcs_elf_gas.S new file mode 100644 index 0000000..66cfb2d --- /dev/null +++ b/third_party/context/src/asm/make_arm64_aapcs_elf_gas.S @@ -0,0 +1,85 @@ +/* + Copyright Edward Nevill + Oliver Kowalke 2015 + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ +/******************************************************* + * * + * ------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ------------------------------------------------- * + * | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| * + * ------------------------------------------------- * + * | d8 | d9 | d10 | d11 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ------------------------------------------------- * + * | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| * + * ------------------------------------------------- * + * | d12 | d13 | d14 | d15 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * + * ------------------------------------------------- * + * | 0x40| 0x44| 0x48| 0x4c| 0x50| 0x54| 0x58| 0x5c| * + * ------------------------------------------------- * + * | x19 | x20 | x21 | x22 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * + * ------------------------------------------------- * + * | 0x60| 0x64| 0x68| 0x6c| 0x70| 0x74| 0x78| 0x7c| * + * ------------------------------------------------- * + * | x23 | x24 | x25 | x26 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * + * ------------------------------------------------- * + * | 0x80| 0x84| 0x88| 0x8c| 0x90| 0x94| 0x98| 0x9c| * + * ------------------------------------------------- * + * | x27 | x28 | FP | LR | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 40 | 41 | 42 | 43 | | | * + * ------------------------------------------------- * + * | 0xa0| 0xa4| 0xa8| 0xac| | | * + * ------------------------------------------------- * + * | PC | align | | | * + * ------------------------------------------------- * + * * + *******************************************************/ + +.file "make_arm64_aapcs_elf_gas.S" +.text +.align 2 +.global make_fcontext +.type make_fcontext, %function +make_fcontext: + # shift address in x0 (allocated stack) to lower 16 byte boundary + and x0, x0, ~0xF + + # reserve space for context-data on context-stack + sub x0, x0, #0xb0 + + # third arg of make_fcontext() == address of context-function + # store address as a PC to jump in + str x2, [x0, #0xa0] + + # save address of finish as return-address for context-function + # will be entered after context-function returns (LR register) + adr x1, finish + str x1, [x0, #0x98] + + ret x30 // return pointer to context-data (x0) + +finish: + # exit code is zero + mov x0, #0 + # exit application + bl _exit + +.size make_fcontext,.-make_fcontext +# Mark that we don't need executable stack. +.section .note.GNU-stack,"",%progbits diff --git a/third_party/context/src/asm/make_arm64_aapcs_macho_gas.S b/third_party/context/src/asm/make_arm64_aapcs_macho_gas.S new file mode 100644 index 0000000..b30b1e3 --- /dev/null +++ b/third_party/context/src/asm/make_arm64_aapcs_macho_gas.S @@ -0,0 +1,83 @@ +/* + Copyright Edward Nevill + Oliver Kowalke 2015 + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ +/******************************************************* + * * + * ------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ------------------------------------------------- * + * | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| * + * ------------------------------------------------- * + * | d8 | d9 | d10 | d11 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ------------------------------------------------- * + * | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| * + * ------------------------------------------------- * + * | d12 | d13 | d14 | d15 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * + * ------------------------------------------------- * + * | 0x40| 0x44| 0x48| 0x4c| 0x50| 0x54| 0x58| 0x5c| * + * ------------------------------------------------- * + * | x19 | x20 | x21 | x22 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * + * ------------------------------------------------- * + * | 0x60| 0x64| 0x68| 0x6c| 0x70| 0x74| 0x78| 0x7c| * + * ------------------------------------------------- * + * | x23 | x24 | x25 | x26 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * + * ------------------------------------------------- * + * | 0x80| 0x84| 0x88| 0x8c| 0x90| 0x94| 0x98| 0x9c| * + * ------------------------------------------------- * + * | x27 | x28 | FP | LR | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 40 | 41 | 42 | 43 | | | * + * ------------------------------------------------- * + * | 0xa0| 0xa4| 0xa8| 0xac| | | * + * ------------------------------------------------- * + * | PC | align | | | * + * ------------------------------------------------- * + * * + *******************************************************/ + +.text +.globl _make_fcontext +.balign 16 + +_make_fcontext: + ; shift address in x0 (allocated stack) to lower 16 byte boundary + and x0, x0, ~0xF + + ; reserve space for context-data on context-stack + sub x0, x0, #0xb0 + + ; third arg of make_fcontext() == address of context-function + ; store address as a PC to jump in + str x2, [x0, #0xa0] + + adr x1, finish + + ; save address of finish as return-address for context-function + ; will be entered after context-function returns (LR register) + str x1, [x0, #0x98] + + ret lr ; return pointer to context-data (x0) + +finish: + ; exit code is zero + mov x0, #0 + ; exit application + bl __exit + + diff --git a/third_party/context/src/asm/make_arm64_aapcs_pe_armasm.asm b/third_party/context/src/asm/make_arm64_aapcs_pe_armasm.asm new file mode 100644 index 0000000..50f9b69 --- /dev/null +++ b/third_party/context/src/asm/make_arm64_aapcs_pe_armasm.asm @@ -0,0 +1,107 @@ +; Copyright Edward Nevill + Oliver Kowalke 2015 +; Distributed under the Boost Software License, Version 1.0. +; (See accompanying file LICENSE_1_0.txt or copy at +; http://www.boost.org/LICENSE_1_0.txt) + +;******************************************************* +;* * +;* ------------------------------------------------- * +;* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * +;* ------------------------------------------------- * +;* | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| * +;* ------------------------------------------------- * +;* | d8 | d9 | d10 | d11 | * +;* ------------------------------------------------- * +;* ------------------------------------------------- * +;* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * +;* ------------------------------------------------- * +;* | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| * +;* ------------------------------------------------- * +;* | d12 | d13 | d14 | d15 | * +;* ------------------------------------------------- * +;* ------------------------------------------------- * +;* | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * +;* ------------------------------------------------- * +;* | 0x40| 0x44| 0x48| 0x4c| 0x50| 0x54| 0x58| 0x5c| * +;* ------------------------------------------------- * +;* | x19 | x20 | x21 | x22 | * +;* ------------------------------------------------- * +;* ------------------------------------------------- * +;* | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * +;* ------------------------------------------------- * +;* | 0x60| 0x64| 0x68| 0x6c| 0x70| 0x74| 0x78| 0x7c| * +;* ------------------------------------------------- * +;* | x23 | x24 | x25 | x26 | * +;* ------------------------------------------------- * +;* ------------------------------------------------- * +;* | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * +;* ------------------------------------------------- * +;* | 0x80| 0x84| 0x88| 0x8c| 0x90| 0x94| 0x98| 0x9c| * +;* ------------------------------------------------- * +;* | x27 | x28 | FP | LR | * +;* ------------------------------------------------- * +;* ------------------------------------------------- * +;* | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | * +;* ------------------------------------------------- * +;* | 0xa0| 0xa4| 0xa8| 0xac| 0xb0| 0xb4| 0xb8| 0xbc| * +;* ------------------------------------------------- * +;* | base | limit | dealloc | fiber data| * +;* ------------------------------------------------- * +;* ------------------------------------------------- * +;* | 48 | 49 | 50 | 51 | | | * +;* ------------------------------------------------- * +;* | 0xc0| 0xc4| 0xc8| 0xcc| | | * +;* ------------------------------------------------- * +;* | PC | align | | | * +;* ------------------------------------------------- * +;* * +;******************************************************* + + AREA |.text|, CODE, READONLY, ALIGN=4, CODEALIGN + EXPORT make_fcontext + IMPORT _exit + +make_fcontext proc + ; save stack top address to x3 + mov x3, x0 + + ; shift address in x0 (allocated stack) to lower 16 byte boundary + and x0, x0, ~0xF + + ; reserve space for context-data on context-stack + sub x0, x0, #0xd0 + + ; save top address of context_stack as 'base' + str x3, [x0, #0xa0] + ; save bottom address of context-stack as 'limit' and 'dealloction stack' + sub x3, x3, x1 + stp x3, x3, [x0, #0xa8] + ; save 0 as 'fiber data' + str xzr, [x0, #0xb8] + + ; third arg of make_fcontext() == address of context-function + ; store address as x19 for trampoline + str x2, [x0, #0x40] + ; store trampoline address as pc + adr x2, trampoline + str x2, [x0, #0xc0] + + ; save address of finish as return-address for context-function + ; will be entered after context-function returns (LR register) + adr x1, finish + str x1, [x0, #0x98] + + ret x30 ; return pointer to context-data (x0) + +trampoline + stp fp, lr, [sp, #-0x10]! + mov fp, sp + blr x19 + +finish + ; exit code is zero + mov x0, #0 + ; exit application + bl _exit + ENDP + END diff --git a/third_party/context/src/asm/make_arm_aapcs_elf_gas.S b/third_party/context/src/asm/make_arm_aapcs_elf_gas.S new file mode 100644 index 0000000..98ae64b --- /dev/null +++ b/third_party/context/src/asm/make_arm_aapcs_elf_gas.S @@ -0,0 +1,81 @@ +/* + Copyright Oliver Kowalke 2009. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/******************************************************* + * * + * ------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ------------------------------------------------- * + * | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| * + * ------------------------------------------------- * + * | s16 | s17 | s18 | s19 | s20 | s21 | s22 | s23 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ------------------------------------------------- * + * | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| * + * ------------------------------------------------- * + * | s24 | s25 | s26 | s27 | s28 | s29 | s30 | s31 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * + * ------------------------------------------------- * + * | 0x40| 0x44| 0x48| 0x4c| 0x50| 0x54| 0x58| 0x5c| * + * ------------------------------------------------- * + * |hiddn| v1 | v2 | v3 | v4 | v5 | v6 | v7 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * + * ------------------------------------------------- * + * | 0x60| 0x64| 0x68| 0x6c| 0x70| 0x74| 0x78| 0x7c| * + * ------------------------------------------------- * + * | v8 | lr | pc | FCTX| DATA| | * + * ------------------------------------------------- * + * * + *******************************************************/ + +.file "make_arm_aapcs_elf_gas.S" +.text +.globl make_fcontext +.align 2 +.type make_fcontext,%function +.syntax unified +make_fcontext: + @ shift address in A1 to lower 16 byte boundary + bic a1, a1, #15 + + @ reserve space for context-data on context-stack + sub a1, a1, #124 + + @ third arg of make_fcontext() == address of context-function + str a3, [a1, #104] + + @ compute address of returned transfer_t + add a2, a1, #108 + mov a3, a2 + str a3, [a1, #64] + + @ compute abs address of label finish + adr a2, finish + @ save address of finish as return-address for context-function + @ will be entered after context-function returns + str a2, [a1, #100] + +#if (defined(__VFP_FP__) && !defined(__SOFTFP__)) +#endif + + bx lr @ return pointer to context-data + +finish: + @ exit code is zero + mov a1, #0 + @ exit application + bl _exit@PLT +.size make_fcontext,.-make_fcontext + +@ Mark that we don't need executable stack. +.section .note.GNU-stack,"",%progbits diff --git a/third_party/context/src/asm/make_arm_aapcs_macho_gas.S b/third_party/context/src/asm/make_arm_aapcs_macho_gas.S new file mode 100644 index 0000000..c909ae9 --- /dev/null +++ b/third_party/context/src/asm/make_arm_aapcs_macho_gas.S @@ -0,0 +1,71 @@ +/* + Copyright Oliver Kowalke 2009. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/******************************************************* + * * + * ------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ------------------------------------------------- * + * | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| * + * ------------------------------------------------- * + * | s16 | s17 | s18 | s19 | s20 | s21 | s22 | s23 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ------------------------------------------------- * + * | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| * + * ------------------------------------------------- * + * | s24 | s25 | s26 | s27 | s28 | s29 | s30 | s31 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * + * ------------------------------------------------- * + * | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| * + * ------------------------------------------------- * + * | sjlj|hiddn| v1 | v2 | v3 | v4 | v5 | v6 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * + * ------------------------------------------------- * + * | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| * + * ------------------------------------------------- * + * | v7 | v8 | lr | pc | FCTX| DATA| | * + * ------------------------------------------------- * + * * + *******************************************************/ + +.text +.globl _make_fcontext +.align 2 +_make_fcontext: + @ shift address in A1 to lower 16 byte boundary + bic a1, a1, #15 + + @ reserve space for context-data on context-stack + sub a1, a1, #124 + + @ third arg of make_fcontext() == address of context-function + str a3, [a1, #108] + + @ compute address of returned transfer_t + add a2, a1, #112 + mov a3, a2 + str a3, [a1, #68] + + @ compute abs address of label finish + adr a2, finish + @ save address of finish as return-address for context-function + @ will be entered after context-function returns + str a2, [a1, #104] + + bx lr @ return pointer to context-data + +finish: + @ exit code is zero + mov a1, #0 + @ exit application + bl __exit diff --git a/third_party/context/src/asm/make_arm_aapcs_pe_armasm.asm b/third_party/context/src/asm/make_arm_aapcs_pe_armasm.asm new file mode 100644 index 0000000..27cbfb0 --- /dev/null +++ b/third_party/context/src/asm/make_arm_aapcs_pe_armasm.asm @@ -0,0 +1,77 @@ +;/* +; Copyright Oliver Kowalke 2009. +; Distributed under the Boost Software License, Version 1.0. +; (See accompanying file LICENSE_1_0.txt or copy at +; http://www.boost.org/LICENSE_1_0.txt) +;*/ + +; ******************************************************* +; * * +; * ------------------------------------------------- * +; * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * +; * ------------------------------------------------- * +; * | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| * +; * ------------------------------------------------- * +; * |deall|limit| base|hiddn| v1 | v2 | v3 | v4 | * +; * ------------------------------------------------- * +; * ------------------------------------------------- * +; * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * +; * ------------------------------------------------- * +; * | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| * +; * ------------------------------------------------- * +; * | v5 | v6 | v7 | v8 | lr | pc | FCTX| DATA| * +; * ------------------------------------------------- * +; * * +; ******************************************************* + + + AREA |.text|, CODE + ALIGN 4 + EXPORT make_fcontext + IMPORT _exit + +make_fcontext PROC + ; first arg of make_fcontext() == top of context-stack + ; save top of context-stack (base) A4 + mov a4, a1 + + ; shift address in A1 to lower 16 byte boundary + bic a1, a1, #0x0f + + ; reserve space for context-data on context-stack + sub a1, a1, #0x48 + + ; save top address of context_stack as 'base' + str a4, [a1, #0x8] + ; second arg of make_fcontext() == size of context-stack + ; compute bottom address of context-stack (limit) + sub a4, a4, a2 + ; save bottom address of context-stack as 'limit' + str a4, [a1, #0x4] + ; save bottom address of context-stack as 'dealloction stack' + str a4, [a1, #0x0] + + ; third arg of make_fcontext() == address of context-function + str a3, [a1, #0x34] + + ; compute address of returned transfer_t + add a2, a1, #0x38 + mov a3, a2 + str a3, [a1, #0xc] + + ; compute abs address of label finish + adr a2, finish + ; save address of finish as return-address for context-function + ; will be entered after context-function returns + str a2, [a1, #0x30] + + bx lr ; return pointer to context-data + +finish + ; exit code is zero + mov a1, #0 + ; exit application + bl _exit + + ENDP + END diff --git a/third_party/context/src/asm/make_combined_sysv_macho_gas.S b/third_party/context/src/asm/make_combined_sysv_macho_gas.S new file mode 100644 index 0000000..b22fa7e --- /dev/null +++ b/third_party/context/src/asm/make_combined_sysv_macho_gas.S @@ -0,0 +1,24 @@ +/* + Copyright Sergue E. Leontiev 2013. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +// Stub file for universal binary + +#if defined(__i386__) + #include "make_i386_sysv_macho_gas.S" +#elif defined(__x86_64__) + #include "make_x86_64_sysv_macho_gas.S" +#elif defined(__ppc__) + #include "make_ppc32_sysv_macho_gas.S" +#elif defined(__ppc64__) + #include "make_ppc64_sysv_macho_gas.S" +#elif defined(__arm__) + #include "make_arm_aapcs_macho_gas.S" +#elif defined(__arm64__) + #include "make_arm64_aapcs_macho_gas.S" +#else + #error "No arch's" +#endif diff --git a/third_party/context/src/asm/make_i386_ms_pe_clang_gas.S b/third_party/context/src/asm/make_i386_ms_pe_clang_gas.S new file mode 100644 index 0000000..79f5024 --- /dev/null +++ b/third_party/context/src/asm/make_i386_ms_pe_clang_gas.S @@ -0,0 +1,153 @@ +/* + Copyright Oliver Kowalke 2009. + Copyright Thomas Sailer 2013. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/************************************************************************************* +* --------------------------------------------------------------------------------- * +* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * +* --------------------------------------------------------------------------------- * +* | 0h | 04h | 08h | 0ch | 010h | 014h | 018h | 01ch | * +* --------------------------------------------------------------------------------- * +* | fc_mxcsr|fc_x87_cw| fc_strg |fc_deallo| limit | base | fc_seh | EDI | * +* --------------------------------------------------------------------------------- * +* --------------------------------------------------------------------------------- * +* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * +* --------------------------------------------------------------------------------- * +* | 020h | 024h | 028h | 02ch | 030h | 034h | 038h | 03ch | * +* --------------------------------------------------------------------------------- * +* | ESI | EBX | EBP | EIP | to | data | EH NXT |SEH HNDLR| * +* --------------------------------------------------------------------------------- * +**************************************************************************************/ + +.file "make_i386_ms_pe_clang_gas.S" +.text +.p2align 4,,15 + +/* mark as using no unregistered SEH handlers */ +.globl @feat.00 +.def @feat.00; .scl 3; .type 0; .endef +.set @feat.00, 1 + +.globl _make_fcontext +.def _make_fcontext; .scl 2; .type 32; .endef +_make_fcontext: + /* first arg of make_fcontext() == top of context-stack */ + movl 0x04(%esp), %eax + + /* reserve space for first argument of context-function */ + /* EAX might already point to a 16byte border */ + leal -0x8(%eax), %eax + + /* shift address in EAX to lower 16 byte boundary */ + andl $-16, %eax + + /* reserve space for context-data on context-stack */ + /* size for fc_mxcsr .. EIP + return-address for context-function */ + /* on context-function entry: (ESP -0x4) % 8 == 0 */ + /* additional space is required for SEH */ + leal -0x40(%eax), %eax + + /* save MMX control- and status-word */ + stmxcsr (%eax) + /* save x87 control-word */ + fnstcw 0x4(%eax) + + /* first arg of make_fcontext() == top of context-stack */ + movl 0x4(%esp), %ecx + /* save top address of context stack as 'base' */ + movl %ecx, 0x14(%eax) + /* second arg of make_fcontext() == size of context-stack */ + movl 0x8(%esp), %edx + /* negate stack size for LEA instruction (== substraction) */ + negl %edx + /* compute bottom address of context stack (limit) */ + leal (%ecx,%edx), %ecx + /* save bottom address of context-stack as 'limit' */ + movl %ecx, 0x10(%eax) + /* save bottom address of context-stack as 'dealloction stack' */ + movl %ecx, 0xc(%eax) + /* set fiber-storage to zero */ + xorl %ecx, %ecx + movl %ecx, 0x8(%eax) + + /* third arg of make_fcontext() == address of context-function */ + /* stored in EBX */ + movl 0xc(%esp), %ecx + movl %ecx, 0x24(%eax) + + /* compute abs address of label trampoline */ + movl $trampoline, %ecx + /* save address of trampoline as return-address for context-function */ + /* will be entered after calling jump_fcontext() first time */ + movl %ecx, 0x2c(%eax) + + /* compute abs address of label finish */ + movl $finish, %ecx + /* save address of finish as return-address for context-function */ + /* will be entered after context-function returns */ + movl %ecx, 0x28(%eax) + + /* traverse current seh chain to get the last exception handler installed by Windows */ + /* note that on Windows Server 2008 and 2008 R2, SEHOP is activated by default */ + /* the exception handler chain is tested for the presence of ntdll.dll!FinalExceptionHandler */ + /* at its end by RaiseException all seh andlers are disregarded if not present and the */ + /* program is aborted */ + /* load NT_TIB into ECX */ + movl %fs:(0x0), %ecx + +walk: + /* load 'next' member of current SEH into EDX */ + movl (%ecx), %edx + /* test if 'next' of current SEH is last (== 0xffffffff) */ + incl %edx + jz found + decl %edx + /* exchange content; ECX contains address of next SEH */ + xchgl %ecx, %edx + /* inspect next SEH */ + jmp walk + +found: + /* load 'handler' member of SEH == address of last SEH handler installed by Windows */ + movl 0x04(%ecx), %ecx + /* save address in ECX as SEH handler for context */ + movl %ecx, 0x3c(%eax) + /* set ECX to -1 */ + movl $0xffffffff, %ecx + /* save ECX as next SEH item */ + movl %ecx, 0x38(%eax) + /* load address of next SEH item */ + leal 0x38(%eax), %ecx + /* save next SEH */ + movl %ecx, 0x18(%eax) + + /* return pointer to context-data */ + ret + +trampoline: + /* move transport_t for entering context-function */ + /* FCTX == EAX, DATA == EDX */ + movl %eax, (%esp) + movl %edx, 0x4(%esp) + /* label finish as return-address */ + pushl %ebp + /* jump to context-function */ + jmp *%ebx + +finish: + /* ESP points to same address as ESP on entry of context function + 0x4 */ + xorl %eax, %eax + /* exit code is zero */ + movl %eax, (%esp) + /* exit application */ + call __exit + hlt + +.def __exit; .scl 2; .type 32; .endef /* standard C library function */ + +.section .drectve +.ascii " -export:\"_make_fcontext\"" diff --git a/third_party/context/src/asm/make_i386_ms_pe_gas.asm b/third_party/context/src/asm/make_i386_ms_pe_gas.asm new file mode 100644 index 0000000..608ddf3 --- /dev/null +++ b/third_party/context/src/asm/make_i386_ms_pe_gas.asm @@ -0,0 +1,153 @@ +/* + Copyright Oliver Kowalke 2009. + Copyright Thomas Sailer 2013. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/************************************************************************************* +* --------------------------------------------------------------------------------- * +* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * +* --------------------------------------------------------------------------------- * +* | 0h | 04h | 08h | 0ch | 010h | 014h | 018h | 01ch | * +* --------------------------------------------------------------------------------- * +* | fc_mxcsr|fc_x87_cw| fc_strg |fc_deallo| limit | base | fc_seh | EDI | * +* --------------------------------------------------------------------------------- * +* --------------------------------------------------------------------------------- * +* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * +* --------------------------------------------------------------------------------- * +* | 020h | 024h | 028h | 02ch | 030h | 034h | 038h | 03ch | * +* --------------------------------------------------------------------------------- * +* | ESI | EBX | EBP | EIP | to | data | EH NXT |SEH HNDLR| * +* --------------------------------------------------------------------------------- * +**************************************************************************************/ + +.file "make_i386_ms_pe_gas.asm" +.text +.p2align 4,,15 + +/* mark as using no unregistered SEH handlers */ +.globl @feat.00 +.def @feat.00; .scl 3; .type 0; .endef +.set @feat.00, 1 + +.globl _make_fcontext +.def _make_fcontext; .scl 2; .type 32; .endef +_make_fcontext: + /* first arg of make_fcontext() == top of context-stack */ + movl 0x04(%esp), %eax + + /* reserve space for first argument of context-function */ + /* EAX might already point to a 16byte border */ + leal -0x8(%eax), %eax + + /* shift address in EAX to lower 16 byte boundary */ + andl $-16, %eax + + /* reserve space for context-data on context-stack */ + /* size for fc_mxcsr .. EIP + return-address for context-function */ + /* on context-function entry: (ESP -0x4) % 8 == 0 */ + /* additional space is required for SEH */ + leal -0x40(%eax), %eax + + /* save MMX control- and status-word */ + stmxcsr (%eax) + /* save x87 control-word */ + fnstcw 0x4(%eax) + + /* first arg of make_fcontext() == top of context-stack */ + movl 0x4(%esp), %ecx + /* save top address of context stack as 'base' */ + movl %ecx, 0x14(%eax) + /* second arg of make_fcontext() == size of context-stack */ + movl 0x8(%esp), %edx + /* negate stack size for LEA instruction (== substraction) */ + negl %edx + /* compute bottom address of context stack (limit) */ + leal (%ecx,%edx), %ecx + /* save bottom address of context-stack as 'limit' */ + movl %ecx, 0x10(%eax) + /* save bottom address of context-stack as 'dealloction stack' */ + movl %ecx, 0xc(%eax) + /* set fiber-storage to zero */ + xorl %ecx, %ecx + movl %ecx, 0x8(%eax) + + /* third arg of make_fcontext() == address of context-function */ + /* stored in EBX */ + movl 0xc(%esp), %ecx + movl %ecx, 0x24(%eax) + + /* compute abs address of label trampoline */ + movl $trampoline, %ecx + /* save address of trampoline as return-address for context-function */ + /* will be entered after calling jump_fcontext() first time */ + movl %ecx, 0x2c(%eax) + + /* compute abs address of label finish */ + movl $finish, %ecx + /* save address of finish as return-address for context-function */ + /* will be entered after context-function returns */ + movl %ecx, 0x28(%eax) + + /* traverse current seh chain to get the last exception handler installed by Windows */ + /* note that on Windows Server 2008 and 2008 R2, SEHOP is activated by default */ + /* the exception handler chain is tested for the presence of ntdll.dll!FinalExceptionHandler */ + /* at its end by RaiseException all seh andlers are disregarded if not present and the */ + /* program is aborted */ + /* load NT_TIB into ECX */ + movl %fs:(0x0), %ecx + +walk: + /* load 'next' member of current SEH into EDX */ + movl (%ecx), %edx + /* test if 'next' of current SEH is last (== 0xffffffff) */ + incl %edx + jz found + decl %edx + /* exchange content; ECX contains address of next SEH */ + xchgl %ecx, %edx + /* inspect next SEH */ + jmp walk + +found: + /* load 'handler' member of SEH == address of last SEH handler installed by Windows */ + movl 0x04(%ecx), %ecx + /* save address in ECX as SEH handler for context */ + movl %ecx, 0x3c(%eax) + /* set ECX to -1 */ + movl $0xffffffff, %ecx + /* save ECX as next SEH item */ + movl %ecx, 0x38(%eax) + /* load address of next SEH item */ + leal 0x38(%eax), %ecx + /* save next SEH */ + movl %ecx, 0x18(%eax) + + /* return pointer to context-data */ + ret + +trampoline: + /* move transport_t for entering context-function */ + /* FCTX == EAX, DATA == EDX */ + movl %eax, (%esp) + movl %edx, 0x4(%esp) + /* label finish as return-address */ + pushl %ebp + /* jump to context-function */ + jmp *%ebx + +finish: + /* ESP points to same address as ESP on entry of context function + 0x4 */ + xorl %eax, %eax + /* exit code is zero */ + movl %eax, (%esp) + /* exit application */ + call __exit + hlt + +.def __exit; .scl 2; .type 32; .endef /* standard C library function */ + +.section .drectve +.ascii " -export:\"make_fcontext\"" diff --git a/third_party/context/src/asm/make_i386_ms_pe_masm.asm b/third_party/context/src/asm/make_i386_ms_pe_masm.asm new file mode 100644 index 0000000..5246465 --- /dev/null +++ b/third_party/context/src/asm/make_i386_ms_pe_masm.asm @@ -0,0 +1,140 @@ + +; Copyright Oliver Kowalke 2009. +; Distributed under the Boost Software License, Version 1.0. +; (See accompanying file LICENSE_1_0.txt or copy at +; http://www.boost.org/LICENSE_1_0.txt) + +; --------------------------------------------------------------------------------- +; | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | +; --------------------------------------------------------------------------------- +; | 0h | 04h | 08h | 0ch | 010h | 014h | 018h | 01ch | +; --------------------------------------------------------------------------------- +; | fc_mxcsr|fc_x87_cw| fc_strg |fc_deallo| limit | base | fc_seh | EDI | +; --------------------------------------------------------------------------------- +; --------------------------------------------------------------------------------- +; | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | +; --------------------------------------------------------------------------------- +; | 020h | 024h | 028h | 02ch | 030h | 034h | 038h | 03ch | +; --------------------------------------------------------------------------------- +; | ESI | EBX | EBP | EIP | to | data | EH NXT |SEH HNDLR| +; --------------------------------------------------------------------------------- + +.386 +.XMM +.model flat, c +; standard C library function +_exit PROTO, value:SDWORD +.code + +make_fcontext PROC BOOST_CONTEXT_EXPORT + ; first arg of make_fcontext() == top of context-stack + mov eax, [esp+04h] + + ; reserve space for first argument of context-function + ; EAX might already point to a 16byte border + lea eax, [eax-08h] + + ; shift address in EAX to lower 16 byte boundary + and eax, -16 + + ; reserve space for context-data on context-stack + ; on context-function entry: (ESP -0x4) % 8 == 0 + ; additional space is required for SEH + lea eax, [eax-040h] + + ; save MMX control- and status-word + stmxcsr [eax] + ; save x87 control-word + fnstcw [eax+04h] + + ; first arg of make_fcontext() == top of context-stack + mov ecx, [esp+04h] + ; save top address of context stack as 'base' + mov [eax+014h], ecx + ; second arg of make_fcontext() == size of context-stack + mov edx, [esp+08h] + ; negate stack size for LEA instruction (== substraction) + neg edx + ; compute bottom address of context stack (limit) + lea ecx, [ecx+edx] + ; save bottom address of context-stack as 'limit' + mov [eax+010h], ecx + ; save bottom address of context-stack as 'dealloction stack' + mov [eax+0ch], ecx + ; set fiber-storage to zero + xor ecx, ecx + mov [eax+08h], ecx + + ; third arg of make_fcontext() == address of context-function + ; stored in EBX + mov ecx, [esp+0ch] + mov [eax+024h], ecx + + ; compute abs address of label trampoline + mov ecx, trampoline + ; save address of trampoline as return-address for context-function + ; will be entered after calling jump_fcontext() first time + mov [eax+02ch], ecx + + ; compute abs address of label finish + mov ecx, finish + ; save address of finish as return-address for context-function in EBP + ; will be entered after context-function returns + mov [eax+028h], ecx + + ; traverse current seh chain to get the last exception handler installed by Windows + ; note that on Windows Server 2008 and 2008 R2, SEHOP is activated by default + ; the exception handler chain is tested for the presence of ntdll.dll!FinalExceptionHandler + ; at its end by RaiseException all seh-handlers are disregarded if not present and the + ; program is aborted + assume fs:nothing + ; load NT_TIB into ECX + mov ecx, fs:[0h] + assume fs:error + +walk: + ; load 'next' member of current SEH into EDX + mov edx, [ecx] + ; test if 'next' of current SEH is last (== 0xffffffff) + inc edx + jz found + dec edx + ; exchange content; ECX contains address of next SEH + xchg edx, ecx + ; inspect next SEH + jmp walk + +found: + ; load 'handler' member of SEH == address of last SEH handler installed by Windows + mov ecx, [ecx+04h] + ; save address in ECX as SEH handler for context + mov [eax+03ch], ecx + ; set ECX to -1 + mov ecx, 0ffffffffh + ; save ECX as next SEH item + mov [eax+038h], ecx + ; load address of next SEH item + lea ecx, [eax+038h] + ; save next SEH + mov [eax+018h], ecx + + ret ; return pointer to context-data + +trampoline: + ; move transport_t for entering context-function + ; FCTX == EAX, DATA == EDX + mov [esp], eax + mov [esp+04h], edx + push ebp + ; jump to context-function + jmp ebx + +finish: + ; exit code is zero + xor eax, eax + mov [esp], eax + ; exit application + call _exit + hlt +make_fcontext ENDP +END diff --git a/third_party/context/src/asm/make_i386_sysv_elf_gas.S b/third_party/context/src/asm/make_i386_sysv_elf_gas.S new file mode 100644 index 0000000..9261e56 --- /dev/null +++ b/third_party/context/src/asm/make_i386_sysv_elf_gas.S @@ -0,0 +1,113 @@ +/* + Copyright Oliver Kowalke 2009. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/**************************************************************************************** + * * + * ---------------------------------------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ---------------------------------------------------------------------------------- * + * | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | * + * ---------------------------------------------------------------------------------- * + * | fc_mxcsr|fc_x87_cw| guard | EDI | ESI | EBX | EBP | EIP | * + * ---------------------------------------------------------------------------------- * + * ---------------------------------------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ---------------------------------------------------------------------------------- * + * | 0x20 | 0x24 | 0x28 | | * + * ---------------------------------------------------------------------------------- * + * | hidden | to | data | | * + * ---------------------------------------------------------------------------------- * + * * + ****************************************************************************************/ + +.file "make_i386_sysv_elf_gas.S" +.text +.globl make_fcontext +.align 2 +.type make_fcontext,@function +make_fcontext: + /* first arg of make_fcontext() == top of context-stack */ + movl 0x4(%esp), %eax + + /* reserve space for first argument of context-function + eax might already point to a 16byte border */ + leal -0x8(%eax), %eax + + /* shift address in EAX to lower 16 byte boundary */ + andl $-16, %eax + + /* reserve space for context-data on context-stack, and align the stack */ + leal -0x34(%eax), %eax + + /* third arg of make_fcontext() == address of context-function */ + /* stored in EBX */ + movl 0xc(%esp), %ecx + movl %ecx, 0x14(%eax) + + /* save MMX control- and status-word */ + stmxcsr (%eax) + /* save x87 control-word */ + fnstcw 0x4(%eax) + +#if defined(BOOST_CONTEXT_TLS_STACK_PROTECTOR) + /* save stack guard */ + movl %gs:0x14, %ecx /* read stack guard from TLS record */ + movl %ecx, 0x8(%eax) /* save stack guard */ +#endif + + /* return transport_t */ + /* FCTX == EDI, DATA == ESI */ + leal 0xc(%eax), %ecx + movl %ecx, 0x20(%eax) + + /* compute abs address of label trampoline */ + call 1f + /* address of trampoline 1 */ +1: popl %ecx + /* compute abs address of label trampoline */ + addl $trampoline-1b, %ecx + /* save address of trampoline as return address */ + /* will be entered after calling jump_fcontext() first time */ + movl %ecx, 0x1c(%eax) + + /* compute abs address of label finish */ + call 2f + /* address of label 2 */ +2: popl %ecx + /* compute abs address of label finish */ + addl $finish-2b, %ecx + /* save address of finish as return-address for context-function */ + /* will be entered after context-function returns */ + movl %ecx, 0x18(%eax) + + ret /* return pointer to context-data */ + +trampoline: + /* move transport_t for entering context-function */ + movl %edi, (%esp) + movl %esi, 0x4(%esp) + pushl %ebp + /* jump to context-function */ + jmp *%ebx + +finish: + call 3f + /* address of label 3 */ +3: popl %ebx + /* compute address of GOT and store it in EBX */ + addl $_GLOBAL_OFFSET_TABLE_+[.-3b], %ebx + + /* exit code is zero */ + xorl %eax, %eax + movl %eax, (%esp) + /* exit application */ + call _exit@PLT + hlt +.size make_fcontext,.-make_fcontext + +/* Mark that we don't need executable stack. */ +.section .note.GNU-stack,"",%progbits diff --git a/third_party/context/src/asm/make_i386_sysv_macho_gas.S b/third_party/context/src/asm/make_i386_sysv_macho_gas.S new file mode 100644 index 0000000..519e406 --- /dev/null +++ b/third_party/context/src/asm/make_i386_sysv_macho_gas.S @@ -0,0 +1,90 @@ +/* + Copyright Oliver Kowalke 2009. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/**************************************************************************************** + * * + * ---------------------------------------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ---------------------------------------------------------------------------------- * + * | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | * + * ---------------------------------------------------------------------------------- * + * | fc_mxcsr|fc_x87_cw| EDI | ESI | EBX | EBP | EIP | to | * + * ---------------------------------------------------------------------------------- * + * ---------------------------------------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ---------------------------------------------------------------------------------- * + * | 0x20 | | * + * ---------------------------------------------------------------------------------- * + * | data | | * + * ---------------------------------------------------------------------------------- * + * * + ****************************************************************************************/ + +.text +.globl _make_fcontext +.align 2 +_make_fcontext: + /* first arg of make_fcontext() == top of context-stack */ + movl 0x4(%esp), %eax + + /* reserve space for first argument of context-function + eax might already point to a 16byte border */ + leal -0x8(%eax), %eax + + /* shift address in EAX to lower 16 byte boundary */ + andl $-16, %eax + + /* reserve space for context-data on context-stack, and align the stack */ + leal -0x34(%eax), %eax + + /* third arg of make_fcontext() == address of context-function */ + /* stored in EBX */ + movl 0xc(%esp), %ecx + movl %ecx, 0x10(%eax) + + /* save MMX control- and status-word */ + stmxcsr (%eax) + /* save x87 control-word */ + fnstcw 0x4(%eax) + + /* compute abs address of label trampoline */ + call 1f + /* address of trampoline 1 */ +1: popl %ecx + /* compute abs address of label trampoline */ + addl $trampoline-1b, %ecx + /* save address of trampoline as return address */ + /* will be entered after calling jump_fcontext() first time */ + movl %ecx, 0x18(%eax) + + /* compute abs address of label finish */ + call 2f + /* address of label 2 */ +2: popl %ecx + /* compute abs address of label finish */ + addl $finish-2b, %ecx + /* save address of finish as return-address for context-function */ + /* will be entered after context-function returns */ + movl %ecx, 0x14(%eax) + + ret /* return pointer to context-data */ + +trampoline: + /* move transport_t for entering context-function */ + movl %eax, (%esp) + movl %edx, 0x4(%esp) + pushl %ebp + /* jump to context-function */ + jmp *%ebx + +finish: + /* exit code is zero */ + xorl %eax, %eax + movl %eax, (%esp) + /* exit application */ + call __exit + hlt diff --git a/third_party/context/src/asm/make_i386_x86_64_sysv_macho_gas.S b/third_party/context/src/asm/make_i386_x86_64_sysv_macho_gas.S new file mode 100644 index 0000000..e364b2d --- /dev/null +++ b/third_party/context/src/asm/make_i386_x86_64_sysv_macho_gas.S @@ -0,0 +1,16 @@ +/* + Copyright Sergue E. Leontiev 2013. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +// Stub file for universal binary + +#if defined(__i386__) + #include "make_i386_sysv_macho_gas.S" +#elif defined(__x86_64__) + #include "make_x86_64_sysv_macho_gas.S" +#else + #error "No arch's" +#endif diff --git a/third_party/context/src/asm/make_loongarch64_sysv_elf_gas.S b/third_party/context/src/asm/make_loongarch64_sysv_elf_gas.S new file mode 100644 index 0000000..5506270 --- /dev/null +++ b/third_party/context/src/asm/make_loongarch64_sysv_elf_gas.S @@ -0,0 +1,72 @@ +/******************************************************* + * * + * ------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ------------------------------------------------- * + * | 0 | 8 | 16 | 24 | * + * ------------------------------------------------- * + * | FS0 | FS1 | FS2 | FS3 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ------------------------------------------------- * + * | 32 | 40 | 48 | 56 | * + * ------------------------------------------------- * + * | FS4 | FS5 | FS6 | FS7 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * + * ------------------------------------------------- * + * | 64 | 72 | 80 | 88 | * + * ------------------------------------------------- * + * | S0 | S1 | S2 | S3 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * + * ------------------------------------------------- * + * | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | * + * ------------------------------------------------- * + * | S4 | S5 | S6 | S7 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * + * ------------------------------------------------- * + * | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | * + * ------------------------------------------------- * + * | S8 | FP | RA | PC | * + * ------------------------------------------------- * + * * + * *****************************************************/ + +.file "make_loongarch64_sysv_elf_gas.S" +.text +.globl make_fcontext +.align 2 +.type make_fcontext,@function +make_fcontext: + # shift address in A0 to lower 16 byte boundary + bstrins.d $a0, $zero, 3, 0 + + # reserve space for context-data on context-stack + addi.d $a0, $a0, -160 + + # third arg of make_fcontext() == address of context-function + st.d $a2, $a0, 152 + + # save address of finish as return-address for context-function + # will be entered after context-function returns + la.local $a4, finish + st.d $a4, $a0, 144 + + # return pointer to context-data + jr $ra + +finish: + # exit code is zero + li.d $a0, 0 + # call _exit(0) + b %plt(_exit) + +.size make_fcontext, .-make_fcontext +/* Mark that we don't need executable stack. */ +.section .note.GNU-stack,"",%progbits diff --git a/third_party/context/src/asm/make_mips32_o32_elf_gas.S b/third_party/context/src/asm/make_mips32_o32_elf_gas.S new file mode 100644 index 0000000..4e11e3d --- /dev/null +++ b/third_party/context/src/asm/make_mips32_o32_elf_gas.S @@ -0,0 +1,97 @@ +/* + Copyright Oliver Kowalke 2009. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/******************************************************* + * * + * ------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ------------------------------------------------- * + * | 0 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | * + * ------------------------------------------------- * + * | F20 | F22 | F24 | F26 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ------------------------------------------------- * + * | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | * + * ------------------------------------------------- * + * | F28 | F30 | S0 | S1 | S2 | S3 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * + * ------------------------------------------------- * + * | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | * + * ------------------------------------------------- * + * | S4 | S5 | S6 | S7 | FP |hiddn| RA | PC | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * + * ------------------------------------------------- * + * | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | * + * ------------------------------------------------- * + * | ABI ARGS | GP | FCTX| DATA| | * + * ------------------------------------------------- * + * * + * *****************************************************/ + +.file "make_mips32_o32_elf_gas.S" +.text +.globl make_fcontext +.align 2 +.type make_fcontext,@function +.ent make_fcontext +make_fcontext: +#ifdef __PIC__ +.set noreorder +.cpload $t9 +.set reorder +#endif + # shift address in A0 to lower 16 byte boundary + li $v1, -16 # 0xfffffffffffffff0 + and $v0, $v1, $a0 + + # reserve space for context-data on context-stack + # includes an extra 32 bytes for: + # - 16-byte incoming argument area required by mips ABI used when + # jump_context calls the initial function + # - 4 bytes to save our GP register used in finish + # - 8 bytes to as space for transfer_t returned to finish + # - 4 bytes for alignment + addiu $v0, $v0, -128 + + # third arg of make_fcontext() == address of context-function + sw $a2, 92($v0) + # save global pointer in context-data + sw $gp, 112($v0) + + # compute address of returned transfer_t + addiu $t0, $v0, 116 + sw $t0, 84($v0) + + # compute abs address of label finish + la $t9, finish + # save address of finish as return-address for context-function + # will be entered after context-function returns + sw $t9, 88($v0) + + jr $ra # return pointer to context-data + +finish: + # reload our gp register (needed for la) + lw $gp, 16($sp) + + # call _exit(0) + # the previous function should have left the 16 bytes incoming argument + # area on the stack which we reuse for calling _exit + la $t9, _exit + move $a0, $zero + jr $t9 +.end make_fcontext +.size make_fcontext, .-make_fcontext + +/* Mark that we don't need executable stack. */ +.section .note.GNU-stack,"",%progbits diff --git a/third_party/context/src/asm/make_mips64_n64_elf_gas.S b/third_party/context/src/asm/make_mips64_n64_elf_gas.S new file mode 100644 index 0000000..7bb30b1 --- /dev/null +++ b/third_party/context/src/asm/make_mips64_n64_elf_gas.S @@ -0,0 +1,96 @@ +/* + Copyright Jiaxun Yang 2018. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/******************************************************* + * * + * ------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ------------------------------------------------- * + * | 0 | 8 | 16 | 24 | * + * ------------------------------------------------- * + * | F24 | F25 | F26 | F27 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ------------------------------------------------- * + * | 32 | 40 | 48 | 56 | * + * ------------------------------------------------- * + * | F28 | F29 | F30 | F31 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * + * ------------------------------------------------- * + * | 64 | 72 | 80 | 88 | * + * ------------------------------------------------- * + * | S0 | S1 | S2 | S3 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * + * ------------------------------------------------- * + * | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | * + * ------------------------------------------------- * + * | S4 | S5 | S6 | S7 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * + * ------------------------------------------------- * + * | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | * + * ------------------------------------------------- * + * | FP | GP | RA | PC | * + * ------------------------------------------------- * + * * + * *****************************************************/ + +.file "make_mips64_n64_elf_gas.S" +.text +.globl make_fcontext +.align 3 +.type make_fcontext,@function +.ent make_fcontext +make_fcontext: +#ifdef __PIC__ +.set noreorder +.cpload $t9 +.set reorder +#endif + # shift address in A0 to lower 16 byte boundary + li $v1, 0xfffffffffffffff0 + and $v0, $v1, $a0 + + # reserve space for context-data on context-stack + daddiu $v0, $v0, -160 + + # third arg of make_fcontext() == address of context-function + sd $a2, 152($v0) + # save global pointer in context-data + sd $gp, 136($v0) + + # psudo instruction compute abs address of label finish based on GP + dla $t9, finish + + # save address of finish as return-address for context-function + # will be entered after context-function returns + sd $t9, 144($v0) + + jr $ra # return pointer to context-data + +finish: + # reload our gp register (needed for la) + daddiu $t0, $sp, -160 + ld $gp, 136($t0) + + # call _exit(0) + # the previous function should have left the 16 bytes incoming argument + # area on the stack which we reuse for calling _exit + dla $t9, _exit + move $a0, $zero + jr $t9 +.end make_fcontext +.size make_fcontext, .-make_fcontext + +/* Mark that we don't need executable stack. */ +.section .note.GNU-stack,"",%progbits diff --git a/third_party/context/src/asm/make_ppc32_ppc64_sysv_macho_gas.S b/third_party/context/src/asm/make_ppc32_ppc64_sysv_macho_gas.S new file mode 100644 index 0000000..52e7220 --- /dev/null +++ b/third_party/context/src/asm/make_ppc32_ppc64_sysv_macho_gas.S @@ -0,0 +1,16 @@ +/* + Copyright Sergue E. Leontiev 2013. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +// Stub file for universal binary + +#if defined(__ppc__) + #include "make_ppc32_sysv_macho_gas.S" +#elif defined(__ppc64__) + #include "make_ppc64_sysv_macho_gas.S" +#else + #error "No arch's" +#endif diff --git a/third_party/context/src/asm/make_ppc32_sysv_elf_gas.S b/third_party/context/src/asm/make_ppc32_sysv_elf_gas.S new file mode 100644 index 0000000..9616c4c --- /dev/null +++ b/third_party/context/src/asm/make_ppc32_sysv_elf_gas.S @@ -0,0 +1,146 @@ +/* + Copyright Oliver Kowalke 2009. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/******************************************************* + * * + * ------------------------------------------------- * + * | 0 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | * + * ------------------------------------------------- * + * |bchai|hiddn| fpscr | PC | CR | R14 | R15 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | * + * ------------------------------------------------- * + * | R16 | R17 | R18 | R19 | R20 | R21 | R22 | R23 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | * + * ------------------------------------------------- * + * | R24 | R25 | R26 | R27 | R28 | R29 | R30 | R31 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | * + * ------------------------------------------------- * + * | F14 | F15 | F16 | F17 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | * + * ------------------------------------------------- * + * | F18 | F19 | F20 | F21 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 160 | 164 | 168 | 172 | 176 | 180 | 184 | 188 | * + * ------------------------------------------------- * + * | F22 | F23 | F24 | F25 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 192 | 196 | 200 | 204 | 208 | 212 | 216 | 220 | * + * ------------------------------------------------- * + * | F26 | F27 | F28 | F29 | * + * ------------------------------------------------- * + * ------------------------|------------ * + * | 224 | 228 | 232 | 236 | 240 | 244 | * + * ------------------------|------------ * + * | F30 | F31 |bchai| LR | * + * ------------------------|------------ * + * * + *******************************************************/ + +.file "make_ppc32_sysv_elf_gas.S" +.text +.globl make_fcontext +.align 2 +.type make_fcontext,@function +make_fcontext: + # save return address into R6 + mflr %r6 + + # first arg of make_fcontext() == top address of context-function + # shift address in R3 to lower 16 byte boundary + clrrwi %r3, %r3, 4 + + # reserve space on context-stack, including 16 bytes of linkage + # and parameter area + 240 bytes of context-data (R1 % 16 == 0) + subi %r3, %r3, 16 + 240 + + # third arg of make_fcontext() == address of context-function +#ifdef __linux__ + # save context-function as PC + stw %r5, 16(%r3) +#else + # save context-function for trampoline + stw %r5, 248(%r3) +#endif + + # set back-chain to zero + li %r0, 0 + stw %r0, 240(%r3) + + # copy FPSCR to new context + mffs %f0 + stfd %f0, 8(%r3) + +#ifdef __linux__ + # set hidden pointer for returning transfer_t + la %r0, 248(%r3) + stw %r0, 4(%r3) +#endif + + # load address of label 1 into R4 + bl 1f +1: mflr %r4 +#ifndef __linux__ + # compute abs address of trampoline, use as PC + addi %r7, %r4, trampoline - 1b + stw %r7, 16(%r3) +#endif + # compute abs address of label finish + addi %r4, %r4, finish - 1b + # save address of finish as return-address for context-function + # will be entered after context-function returns + stw %r4, 244(%r3) + + # restore return address from R6 + mtlr %r6 + + blr # return pointer to context-data + +#ifndef __linux__ +trampoline: + # On systems other than Linux, jump_fcontext is returning the + # transfer_t in R3:R4, but we need to pass transfer_t * R3 to + # our context-function. + lwz %r0, 8(%r1) # address of context-function + mtctr %r0 + stw %r3, 8(%r1) + stw %r4, 12(%r1) + la %r3, 8(%r1) # address of transfer_t + bctr +#endif + +finish: + # Use the secure PLT for _exit(0). If we use the insecure BSS PLT + # here, then the linker may use the insecure BSS PLT even if the + # C++ compiler wanted the secure PLT. + + # set R30 for secure PLT, large model + bl 2f +2: mflr %r30 + addis %r30, %r30, .Ltoc - 2b@ha + addi %r30, %r30, .Ltoc - 2b@l + + # call _exit(0) with special addend 0x8000 for large model + li %r3, 0 + bl _exit + 0x8000@plt +.size make_fcontext, .-make_fcontext + +/* Provide the GOT pointer for secure PLT, large model. */ +.section .got2,"aw" +.Ltoc = . + 0x8000 + +/* Mark that we don't need executable stack. */ +.section .note.GNU-stack,"",%progbits diff --git a/third_party/context/src/asm/make_ppc32_sysv_macho_gas.S b/third_party/context/src/asm/make_ppc32_sysv_macho_gas.S new file mode 100644 index 0000000..1102ee9 --- /dev/null +++ b/third_party/context/src/asm/make_ppc32_sysv_macho_gas.S @@ -0,0 +1,154 @@ +/* + Copyright Oliver Kowalke 2009. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/****************************************************** + * * + * ------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ------------------------------------------------- * + * | 0 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | * + * ------------------------------------------------- * + * | F14 | F15 | F16 | F17 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ------------------------------------------------- * + * | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | * + * ------------------------------------------------- * + * | F18 | F19 | F20 | F21 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * + * ------------------------------------------------- * + * | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | * + * ------------------------------------------------- * + * | F22 | F23 | F24 | F25 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * + * ------------------------------------------------- * + * | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | * + * ------------------------------------------------- * + * | F26 | F27 | F28 | F29 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * + * ------------------------------------------------- * + * | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | * + * ------------------------------------------------- * + * | F30 | F31 | fpscr | R13 | R14 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | * + * ------------------------------------------------- * + * | 160 | 164 | 168 | 172 | 176 | 180 | 184 | 188 | * + * ------------------------------------------------- * + * | R15 | R16 | R17 | R18 | R19 | R20 | R21 | R22 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | * + * ------------------------------------------------- * + * | 192 | 196 | 200 | 204 | 208 | 212 | 216 | 220 | * + * ------------------------------------------------- * + * | R23 | R24 | R25 | R26 | R27 | R28 | R29 | R30 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | * + * ------------------------------------------------- * + * | 224 | 228 | 232 | 236 | 240 | 244 | 248 | 252 | * + * ------------------------------------------------- * + * | R31 |hiddn| CR | LR | PC |bchai|linkr| FCTX| * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 64 | | * + * ------------------------------------------------- * + * | 256 | | * + * ------------------------------------------------- * + * | DATA| | * + * ------------------------------------------------- * + * * + *******************************************************/ + +.text +.globl _make_fcontext +.align 2 +_make_fcontext: + ; save return address into R6 + mflr r6 + + ; first arg of make_fcontext() == top address of context-function + ; shift address in R3 to lower 16 byte boundary + clrrwi r3, r3, 4 + + ; reserve space for context-data on context-stack + ; including 64 byte of linkage + parameter area (R1 % 16 == 0) + subi r3, r3, 336 + + ; third arg of make_fcontext() == address of context-function + ; store as trampoline's R31 + stw r5, 224(r3) + + ; set back-chain to zero + li r0, 0 + stw r0, 244(r3) + + mffs f0 ; load FPSCR + stfd f0, 144(r3) ; save FPSCR + + ; compute address of returned transfer_t + addi r0, r3, 252 + mr r4, r0 + stw r4, 228(r3) + + ; load LR + mflr r0 + ; jump to label 1 + bcl 20, 31, L1 +L1: + ; load LR into R4 + mflr r4 + ; compute abs address of trampoline, use as PC + addi r5, r4, lo16(Ltrampoline - L1) + stw r5, 240(r3) + ; compute abs address of label finish + addi r4, r4, lo16(Lfinish - L1) + ; restore LR + mtlr r0 + ; save address of finish as return-address for context-function + ; will be entered after context-function returns + stw r4, 236(r3) + + ; restore return address from R6 + mtlr r6 + + blr ; return pointer to context-data + +Ltrampoline: + ; We get R31 = context-function, R3 = address of transfer_t, + ; but we need to pass R3:R4 = transfer_t. + mtctr r31 + lwz r4, 4(r3) + lwz r3, 0(r3) + bctr + +Lfinish: + ; load address of _exit into CTR + bcl 20, 31, L2 +L2: + mflr r4 + addis r4, r4, ha16(Lexitp - L2) + lwz r4, lo16(Lexitp - L2)(r4) + mtctr r4 + ; exit code is zero + li r3, 0 + ; exit application + bctr + +.const_data +.align 2 +Lexitp: + .long __exit diff --git a/third_party/context/src/asm/make_ppc32_sysv_xcoff_gas.S b/third_party/context/src/asm/make_ppc32_sysv_xcoff_gas.S new file mode 100644 index 0000000..e803757 --- /dev/null +++ b/third_party/context/src/asm/make_ppc32_sysv_xcoff_gas.S @@ -0,0 +1,125 @@ +/* + Copyright Oliver Kowalke 2009. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/******************************************************* + * * + * ------------------------------------------------- * + * | 0 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | * + * ------------------------------------------------- * + * |bchai| CR | LR |compl| link| TOC | R14 | R15 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | * + * ------------------------------------------------- * + * | R16 | R17 | R18 | R19 | R20 | R21 | R22 | R23 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | * + * ------------------------------------------------- * + * | R24 | R25 | R26 | R27 | R28 | R29 | R30 | R31 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | * + * ------------------------------------------------- * + * | F14 | F15 | F16 | F17 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | * + * ------------------------------------------------- * + * | F18 | F19 | F20 | F21 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 160 | 164 | 168 | 172 | 176 | 180 | 184 | 188 | * + * ------------------------------------------------- * + * | F22 | F23 | F24 | F25 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 192 | 196 | 200 | 204 | 208 | 212 | 216 | 220 | * + * ------------------------------------------------- * + * | F26 | F27 | F28 | F29 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 224 | 228 | 232 | 236 | 240 | 244 | 248 | 252 | * + * ------------------------------------------------- * + * | F30 | F31 | PC |hiddn| fpscr | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 256 | 260 | 264 | 268 | 272 | 276 | 280 | 284 | * + * ------------------------------------------------- * + * |bchai|savLR|savLR|compl| link|svTOC| FCTX| DATA| * + * ------------------------------------------------- * + * * + *******************************************************/ + .file "make_ppc32_sysv_xcoff_xas.S" + .toc + .csect .text[PR] + .align 2 + .globl make_fcontext[DS] + .globl .make_fcontext + .csect make_fcontext[DS] +make_fcontext: + .long .make_fcontext[PR], TOC[tc0], 0 + .csect .text[PR], 5 +.make_fcontext: + # save return address into R6 + mflr 6 + + # first arg of make_fcontext() == top address of context-function + # shift address in R3 to lower 16 byte boundary + clrrwi 3, 3, 4 + + # reserve space for context-data on context-stack + # including 32 byte of linkage + parameter area (R1 % 16 == 0) + subi 3, 3, 288 + + # third arg of make_fcontext() == address of context-function descriptor + lwz 4, 0(5) + stw 4, 240(3) + # save TOC of context-function + lwz 4, 4(5) + stw 4, 20(3) + + # set back-chain to zero + li 0, 0 + stw 0, 256(3) + + # zero in r3 indicates first jump to context-function + std 0, 244(3) + + # load LR + mflr 0 + # jump to label 1 + bl .Label +.Label: + # load LR into R4 + mflr 4 + # compute abs address of label .L_finish + addi 4, 4, .L_finish - .Label + # restore LR + mtlr 0 + # save address of finish as return-address for context-function + # will be entered after context-function returns + stw 4, 8(3) + + # restore return address from R6 + mtlr 6 + + blr # return pointer to context-data + +.L_finish: + # save return address into R0 + mflr 0 + # save return address on stack, set up stack frame + stw 0, 4(1) + # allocate stack space, R1 % 16 == 0 + stwu 1, -16(1) + + # exit code is zero + li 3, 0 + # exit application + bl ._exit + nop diff --git a/third_party/context/src/asm/make_ppc64_sysv_elf_gas.S b/third_party/context/src/asm/make_ppc64_sysv_elf_gas.S new file mode 100644 index 0000000..c4d7ee5 --- /dev/null +++ b/third_party/context/src/asm/make_ppc64_sysv_elf_gas.S @@ -0,0 +1,177 @@ +/* + Copyright Oliver Kowalke 2009. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/******************************************************* + * * + * ------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ------------------------------------------------- * + * | 0 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | * + * ------------------------------------------------- * + * | TOC | R14 | R15 | R16 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ------------------------------------------------- * + * | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | * + * ------------------------------------------------- * + * | R17 | R18 | R19 | R20 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * + * ------------------------------------------------- * + * | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | * + * ------------------------------------------------- * + * | R21 | R22 | R23 | R24 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * + * ------------------------------------------------- * + * | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | * + * ------------------------------------------------- * + * | R25 | R26 | R27 | R28 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * + * ------------------------------------------------- * + * | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | * + * ------------------------------------------------- * + * | R29 | R30 | R31 | hidden | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | * + * ------------------------------------------------- * + * | 160 | 164 | 168 | 172 | 176 | 180 | 184 | 188 | * + * ------------------------------------------------- * + * | CR | LR | PC | back-chain| * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | * + * ------------------------------------------------- * + * | 192 | 196 | 200 | 204 | 208 | 212 | 216 | 220 | * + * ------------------------------------------------- * + * | cr saved | lr saved | compiler | linker | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | * + * ------------------------------------------------- * + * | 224 | 228 | 232 | 236 | 240 | 244 | 248 | 252 | * + * ------------------------------------------------- * + * | TOC saved | FCTX | DATA | | * + * ------------------------------------------------- * + * * + *******************************************************/ + +.file "make_ppc64_sysv_elf_gas.S" +.globl make_fcontext +#if _CALL_ELF == 2 + .text + .align 2 +make_fcontext: + addis %r2, %r12, .TOC.-make_fcontext@ha + addi %r2, %r2, .TOC.-make_fcontext@l + .localentry make_fcontext, . - make_fcontext +#else + .section ".opd","aw" + .align 3 +make_fcontext: +# ifdef _CALL_LINUX + .quad .L.make_fcontext,.TOC.@tocbase,0 + .type make_fcontext,@function + .text + .align 2 +.L.make_fcontext: +# else + .hidden .make_fcontext + .globl .make_fcontext + .quad .make_fcontext,.TOC.@tocbase,0 + .size make_fcontext,24 + .type .make_fcontext,@function + .text + .align 2 +.make_fcontext: +# endif +#endif + # save return address into R6 + mflr %r6 + + # first arg of make_fcontext() == top address of context-stack + # shift address in R3 to lower 16 byte boundary + clrrdi %r3, %r3, 4 + + # reserve space for context-data on context-stack + # including 64 byte of linkage + parameter area (R1 % 16 == 0) + subi %r3, %r3, 248 + + # third arg of make_fcontext() == address of context-function + # entry point (ELFv2) or descriptor (ELFv1) +#if _CALL_ELF == 2 + # save address of context-function entry point + std %r5, 176(%r3) +#else + # save address of context-function entry point + ld %r4, 0(%r5) + std %r4, 176(%r3) + # save TOC of context-function + ld %r4, 8(%r5) + std %r4, 0(%r3) +#endif + + # set back-chain to zero + li %r0, 0 + std %r0, 184(%r3) + +#if _CALL_ELF != 2 + # zero in r3 indicates first jump to context-function + std %r0, 152(%r3) +#endif + + # load LR + mflr %r0 + # jump to label 1 + bl 1f +1: + # load LR into R4 + mflr %r4 + # compute abs address of label finish + addi %r4, %r4, finish - 1b + # restore LR + mtlr %r0 + # save address of finish as return-address for context-function + # will be entered after context-function returns + std %r4, 168(%r3) + + # restore return address from R6 + mtlr %r6 + + blr # return pointer to context-data + +finish: + # save return address into R0 + mflr %r0 + # save return address on stack, set up stack frame + std %r0, 8(%r1) + # allocate stack space, R1 % 16 == 0 + stdu %r1, -32(%r1) + + # exit code is zero + li %r3, 0 + # exit application + bl _exit + nop +#if _CALL_ELF == 2 + .size make_fcontext, .-make_fcontext +#else +# ifdef _CALL_LINUX + .size .make_fcontext, .-.L.make_fcontext +# else + .size .make_fcontext, .-.make_fcontext +# endif +#endif + +/* Mark that we don't need executable stack. */ +.section .note.GNU-stack,"",%progbits diff --git a/third_party/context/src/asm/make_ppc64_sysv_macho_gas.S b/third_party/context/src/asm/make_ppc64_sysv_macho_gas.S new file mode 100644 index 0000000..fb5cada --- /dev/null +++ b/third_party/context/src/asm/make_ppc64_sysv_macho_gas.S @@ -0,0 +1,126 @@ +/* + Copyright Oliver Kowalke 2009. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/******************************************************* + * * + * ------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ------------------------------------------------- * + * | 0 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | * + * ------------------------------------------------- * + * | R13 | R14 | R15 | R16 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ------------------------------------------------- * + * | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | * + * ------------------------------------------------- * + * | R17 | R18 | R19 | R20 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * + * ------------------------------------------------- * + * | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | * + * ------------------------------------------------- * + * | R21 | R22 | R23 | R24 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * + * ------------------------------------------------- * + * | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | * + * ------------------------------------------------- * + * | R25 | R26 | R27 | R28 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * + * ------------------------------------------------- * + * | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | * + * ------------------------------------------------- * + * | R29 | R30 | R31 | hidden | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | * + * ------------------------------------------------- * + * | 160 | 164 | 168 | 172 | 176 | 180 | 184 | 188 | * + * ------------------------------------------------- * + * | CR | LR | PC | back-chain| * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | * + * ------------------------------------------------- * + * | 192 | 196 | 200 | 204 | 208 | 212 | 216 | 220 | * + * ------------------------------------------------- * + * | cr saved | lr saved | compiler | linker | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | * + * ------------------------------------------------- * + * | 224 | 228 | 232 | 236 | 240 | 244 | 248 | 252 | * + * ------------------------------------------------- * + * | FCTX | DATA | | | * + * ------------------------------------------------- * + * * + +.text +.globl _make_fcontext +_make_fcontext: + ; save return address into R6 + mflr r6 + + ; first arg of make_fcontext() == top address of context-function + ; shift address in R3 to lower 16 byte boundary + clrrwi r3, r3, 4 + + ; reserve space for context-data on context-stack + ; including 64 byte of linkage + parameter area (R1 16 == 0) + subi r3, r3, 240 + + ; third arg of make_fcontext() == address of context-function + stw r5, 176(r3) + + ; set back-chain to zero + li r0, 0 + std r0, 184(r3) + + ; compute address of returned transfer_t + addi r0, r3, 224 + mr r4, r0 + std r4, 152(r3) + + ; load LR + mflr r0 + ; jump to label 1 + bl l1 +l1: + ; load LR into R4 + mflr r4 + ; compute abs address of label finish + addi r4, r4, lo16((finish - .) + 4) + ; restore LR + mtlr r0 + ; save address of finish as return-address for context-function + ; will be entered after context-function returns + std r4, 168(r3) + + ; restore return address from R6 + mtlr r6 + + blr ; return pointer to context-data + +finish: + ; save return address into R0 + mflr r0 + ; save return address on stack, set up stack frame + stw r0, 8(r1) + ; allocate stack space, R1 16 == 0 + stwu r1, -32(r1) + + ; set return value to zero + li r3, 0 + ; exit application + bl __exit + nop diff --git a/third_party/context/src/asm/make_ppc64_sysv_xcoff_gas.S b/third_party/context/src/asm/make_ppc64_sysv_xcoff_gas.S new file mode 100644 index 0000000..2374b50 --- /dev/null +++ b/third_party/context/src/asm/make_ppc64_sysv_xcoff_gas.S @@ -0,0 +1,137 @@ +/* + Copyright Oliver Kowalke 2009. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/******************************************************* + * * + * ------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ------------------------------------------------- * + * | 0 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | * + * ------------------------------------------------- * + * | TOC | R14 | R15 | R16 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ------------------------------------------------- * + * | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | * + * ------------------------------------------------- * + * | R17 | R18 | R19 | R20 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * + * ------------------------------------------------- * + * | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | * + * ------------------------------------------------- * + * | R21 | R22 | R23 | R24 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * + * ------------------------------------------------- * + * | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | * + * ------------------------------------------------- * + * | R25 | R26 | R27 | R28 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * + * ------------------------------------------------- * + * | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | * + * ------------------------------------------------- * + * | R29 | R30 | R31 | hidden | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | * + * ------------------------------------------------- * + * | 160 | 164 | 168 | 172 | 176 | 180 | 184 | 188 | * + * ------------------------------------------------- * + * | CR | LR | PC | back-chain| * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | * + * ------------------------------------------------- * + * | 192 | 196 | 200 | 204 | 208 | 212 | 216 | 220 | * + * ------------------------------------------------- * + * | cr saved | lr saved | compiler | linker | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | * + * ------------------------------------------------- * + * | 224 | 228 | 232 | 236 | 240 | 244 | 248 | 252 | * + * ------------------------------------------------- * + * | TOC saved | FCTX | DATA | | * + * ------------------------------------------------- * + * * + *******************************************************/ + + .file "make_ppc64_sysv_xcoff_gas.S" + .toc + .csect .text[PR], 5 + .align 2 + .globl make_fcontext[DS] + .globl .make_fcontext + .csect make_fcontext[DS], 3 +make_fcontext: + .llong .make_fcontext[PR], TOC[tc0], 0 + .csect .text[PR], 5 +.make_fcontext: + # save return address into R6 + mflr 6 + + # first arg of make_fcontext() == top address of context-function + # shift address in R3 to lower 16 byte boundary + clrrdi 3, 3, 4 + + # reserve space for context-data on context-stack + # including 64 byte of linkage + parameter area (R1 % 16 == 0) + subi 3, 3, 248 + + # third arg of make_fcontext() == address of context-function descriptor + ld 4, 0(5) + std 4, 176(3) + # save TOC of context-function + ld 4, 8(5) + std 4, 0(3) + + # set back-chain to zero + li 0, 0 + std 0, 184(3) + + # zero in r3 indicates first jump to context-function + std 0, 152(3) + + # load LR + mflr 0 + # jump to label 1 + bl .Label +.Label: + # load LR into R4 + mflr 4 + # compute abs address of label .L_finish + addi 4, 4, .L_finish - .Label + # restore LR + mtlr 0 + # save address of finish as return-address for context-function + # will be entered after context-function returns + std 4, 168(3) + + # restore return address from R6 + mtlr 6 + + blr # return pointer to context-data + +.L_finish: + # save return address into R0 + mflr 0 + # save return address on stack, set up stack frame + std 0, 8(1) + # allocate stack space, R1 % 16 == 0 + stdu 1, -32(1) + + # exit code is zero + li 3, 0 + # exit application + bl ._exit + nop diff --git a/third_party/context/src/asm/make_riscv64_sysv_elf_gas.S b/third_party/context/src/asm/make_riscv64_sysv_elf_gas.S new file mode 100644 index 0000000..5322e0f --- /dev/null +++ b/third_party/context/src/asm/make_riscv64_sysv_elf_gas.S @@ -0,0 +1,91 @@ +/* + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ +/******************************************************* + * * + * ------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ------------------------------------------------- * + * | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| * + * ------------------------------------------------- * + * | fs0 | fs1 | fs2 | fs3 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ------------------------------------------------- * + * | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| * + * ------------------------------------------------- * + * | fs4 | fs5 | fs6 | fs7 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * + * ------------------------------------------------- * + * | 0x40| 0x44| 0x48| 0x4c| 0x50| 0x54| 0x58| 0x5c| * + * ------------------------------------------------- * + * | fs8 | fs9 | fs10 | fs11 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * + * ------------------------------------------------- * + * | 0x60| 0x64| 0x68| 0x6c| 0x70| 0x74| 0x78| 0x7c| * + * ------------------------------------------------- * + * | s0 | s1 | s2 | s3 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * + * ------------------------------------------------- * + * | 0x80| 0x84| 0x88| 0x8c| 0x90| 0x94| 0x98| 0x9c| * + * ------------------------------------------------- * + * | s4 | s5 | s6 | s7 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | * + * ------------------------------------------------- * + * | 0xa0| 0xa4| 0xa8| 0xac| 0xb0| 0xb4| 0xb8| 0xbc| * + * ------------------------------------------------- * + * | s8 | s9 | s10 | s11 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 48 | 49 | 50 | 51 | | | | | * + * ------------------------------------------------- * + * | 0xc0| 0xc4| 0xc8| 0xcc| | | | | * + * ------------------------------------------------- * + * | ra | pc | | | * + * ------------------------------------------------- * + * * + *******************************************************/ + +.file "make_riscv64_sysv_elf_gas.S" +.text +.align 1 +.global make_fcontext +.type make_fcontext, %function +make_fcontext: + # shift address in a0 (allocated stack) to lower 16 byte boundary + andi a0, a0, ~0xF + + # reserve space for context-data on context-stack + addi a0, a0, -0xd0 + + # third arg of make_fcontext() == address of context-function + # store address as a PC to jump in + sd a2, 0xc8(a0) + + # save address of finish as return-address for context-function + # will be entered after context-function returns (RA register) + lla a4, finish + sd a4, 0xc0(a0) + + ret // return pointer to context-data (a0) + +finish: + # exit code is zero + li a0, 0 + # exit application + tail _exit@plt + +.size make_fcontext,.-make_fcontext +# Mark that we don't need executable stack. +.section .note.GNU-stack,"",%progbits diff --git a/third_party/context/src/asm/make_s390x_sysv_elf_gas.S b/third_party/context/src/asm/make_s390x_sysv_elf_gas.S new file mode 100644 index 0000000..e7e2d5f --- /dev/null +++ b/third_party/context/src/asm/make_s390x_sysv_elf_gas.S @@ -0,0 +1,108 @@ +/******************************************************* + * ------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ------------------------------------------------- * + * | 0 | 8 | 16 | 24 | * + * ------------------------------------------------- * + * | t.fctx | t.data | r2 | r6 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ------------------------------------------------- * + * | 32 | 40 | 48 | 56 | * + * ------------------------------------------------- * + * | r7 | r8 | r9 | r10 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * + * ------------------------------------------------- * + * | 64 | 72 | 80 | 88 | * + * ------------------------------------------------- * + * | r11 | r12 | r13 | r14 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * + * ------------------------------------------------- * + * | 96 | 104 | 112 | 120 | * + * ------------------------------------------------- * + * | f8 | f9 | f10 | f11 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * + * ------------------------------------------------- * + * | 128 | 136 | 144 | 152 | * + * ------------------------------------------------- * + * | f12 | f13 | f14 | f15 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | * + * ------------------------------------------------- * + * | 160 | 168 | 176 | | * + * ------------------------------------------------- * + * | fpc | pc | | | * + * ------------------------------------------------- * + *******************************************************/ + +.text +.align 8 +.global make_fcontext +.type make_fcontext, @function + +#define ARG_OFFSET 0 +#define GR_OFFSET 16 +#define R14_OFFSET 88 +#define FP_OFFSET 96 +#define FPC_OFFSET 160 +#define PC_OFFSET 168 +#define CONTEXT_SIZE 176 + +/* + +fcontext_t make_fcontext( void * sp, std::size_t size, void (* fn)( transfer_t) ); + +Create and return a context below SP to call FN. + +Incoming args +r2 - The stack location where to create the context +r3 - The size of the context +r4 - The address of the context function + +*/ + +make_fcontext: + .machine "z10" + /* Align the stack to an 8 byte boundary. */ + nill %r2,0xfff0 + + /* Allocate stack space for the context. */ + aghi %r2,-CONTEXT_SIZE + + /* Set the r2 save slot to zero. This indicates jump_fcontext + that this is a special context. */ + mvghi GR_OFFSET(%r2),0 + + /* Save the floating point control register. */ + stfpc FPC_OFFSET(%r2) + + /* Store the address of the target function as new pc. */ + stg %r4,PC_OFFSET(%r2) + + /* Store a pointer to the finish routine as r14. If a function + called via context routines just returns that value will be + loaded and used as return address. Hence the program will + just exit. */ + larl %r1,finish + stg %r1,R14_OFFSET(%r2) + + /* Return as usual with the new context returned in r2. */ + br %r14 + +finish: + /* In finish tasks, you load the exit code and exit the + make_fcontext This is called when the context-function is + entirely executed. */ + lghi %r2,0 + brasl %r14,_exit@PLT + +.size make_fcontext,.-make_fcontext +.section .note.GNU-stack,"",%progbits diff --git a/third_party/context/src/asm/make_x86_64_ms_pe_clang_gas.S b/third_party/context/src/asm/make_x86_64_ms_pe_clang_gas.S new file mode 100644 index 0000000..9b3a6fc --- /dev/null +++ b/third_party/context/src/asm/make_x86_64_ms_pe_clang_gas.S @@ -0,0 +1,174 @@ +/* + Copyright Oliver Kowalke 2009. + Copyright Thomas Sailer 2013. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/************************************************************************************* +* ---------------------------------------------------------------------------------- * +* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * +* ---------------------------------------------------------------------------------- * +* | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | * +* ---------------------------------------------------------------------------------- * +* | SEE registers (XMM6-XMM15) | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * +* ---------------------------------------------------------------------------------- * +* | 0x20 | 0x24 | 0x28 | 0x2c | 0x30 | 0x34 | 0x38 | 0x3c | * +* ---------------------------------------------------------------------------------- * +* | SEE registers (XMM6-XMM15) | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * +* ---------------------------------------------------------------------------------- * +* | 0xe40 | 0x44 | 0x48 | 0x4c | 0x50 | 0x54 | 0x58 | 0x5c | * +* ---------------------------------------------------------------------------------- * +* | SEE registers (XMM6-XMM15) | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * +* ---------------------------------------------------------------------------------- * +* | 0x60 | 0x64 | 0x68 | 0x6c | 0x70 | 0x74 | 0x78 | 0x7c | * +* ---------------------------------------------------------------------------------- * +* | SEE registers (XMM6-XMM15) | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 32 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | * +* ---------------------------------------------------------------------------------- * +* | 0x80 | 0x84 | 0x88 | 0x8c | 0x90 | 0x94 | 0x98 | 0x9c | * +* ---------------------------------------------------------------------------------- * +* | SEE registers (XMM6-XMM15) | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | * +* ---------------------------------------------------------------------------------- * +* | 0xa0 | 0xa4 | 0xa8 | 0xac | 0xb0 | 0xb4 | 0xb8 | 0xbc | * +* ---------------------------------------------------------------------------------- * +* | fc_mxcsr|fc_x87_cw| | fbr_strg | fc_dealloc | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | * +* ---------------------------------------------------------------------------------- * +* | 0xc0 | 0xc4 | 0xc8 | 0xcc | 0xd0 | 0xd4 | 0xd8 | 0xdc | * +* ---------------------------------------------------------------------------------- * +* | limit | base | R12 | R13 | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | * +* ---------------------------------------------------------------------------------- * +* | 0xe0 | 0xe4 | 0xe8 | 0xec | 0xf0 | 0xf4 | 0xf8 | 0xfc | * +* ---------------------------------------------------------------------------------- * +* | R14 | R15 | RDI | RSI | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | * +* ---------------------------------------------------------------------------------- * +* | 0x100 | 0x104 | 0x108 | 0x10c | 0x110 | 0x114 | 0x118 | 0x11c | * +* ---------------------------------------------------------------------------------- * +* | RBX | RBP | hidden | RIP | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | * +* ---------------------------------------------------------------------------------- * +* | 0x120 | 0x124 | 0x128 | 0x12c | 0x130 | 0x134 | 0x138 | 0x13c | * +* ---------------------------------------------------------------------------------- * +* | parameter area | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | * +* ---------------------------------------------------------------------------------- * +* | 0x140 | 0x144 | 0x148 | 0x14c | 0x150 | 0x154 | 0x158 | 0x15c | * +* ---------------------------------------------------------------------------------- * +* | FCTX | DATA | | * +* ---------------------------------------------------------------------------------- * +**************************************************************************************/ + +.file "make_x86_64_ms_pe_clang_gas.S" +.text +.p2align 4,,15 +.globl make_fcontext +.def make_fcontext; .scl 2; .type 32; .endef +.seh_proc make_fcontext +make_fcontext: +.seh_endprologue + + /* first arg of make_fcontext() == top of context-stack */ + movq %rcx, %rax + + /* shift address in RAX to lower 16 byte boundary */ + /* == pointer to fcontext_t and address of context stack */ + andq $-16, %rax + + /* reserve space for context-data on context-stack */ + /* on context-function entry: (RSP -0x8) % 16 == 0 */ + leaq -0x150(%rax), %rax + + /* third arg of make_fcontext() == address of context-function */ + movq %r8, 0x100(%rax) + + /* first arg of make_fcontext() == top of context-stack */ + /* save top address of context stack as 'base' */ + movq %rcx, 0xc8(%rax) + /* second arg of make_fcontext() == size of context-stack */ + /* negate stack size for LEA instruction (== substraction) */ + negq %rdx + /* compute bottom address of context stack (limit) */ + leaq (%rcx,%rdx), %rcx + /* save bottom address of context stack as 'limit' */ + movq %rcx, 0xc0(%rax) + /* save address of context stack limit as 'dealloction stack' */ + movq %rcx, 0xb8(%rax) + /* set fiber-storage to zero */ + xorq %rcx, %rcx + movq %rcx, 0xb0(%rax) + + /* save MMX control- and status-word */ + stmxcsr 0xa0(%rax) + /* save x87 control-word */ + fnstcw 0xa4(%rax) + + /* compute address of transport_t */ + leaq 0x140(%rax), %rcx + /* store address of transport_t in hidden field */ + movq %rcx, 0x110(%rax) + + /* compute abs address of label trampoline */ + leaq trampoline(%rip), %rcx + /* save address of finish as return-address for context-function */ + /* will be entered after jump_fcontext() first time */ + movq %rcx, 0x118(%rax) + + /* compute abs address of label finish */ + leaq finish(%rip), %rcx + /* save address of finish as return-address for context-function */ + /* will be entered after context-function returns */ + movq %rcx, 0x108(%rax) + + ret /* return pointer to context-data */ + +trampoline: + /* store return address on stack */ + /* fix stack alignment */ + pushq %rbp + /* jump to context-function */ + jmp *%rbx + +finish: + /* 32byte shadow-space for _exit() */ + andq $-32, %rsp + /* 32byte shadow-space for _exit() are */ + /* already reserved by make_fcontext() */ + /* exit code is zero */ + xorq %rcx, %rcx + /* exit application */ + call _exit + hlt +.seh_endproc + +.def _exit; .scl 2; .type 32; .endef /* standard C library function */ + +.section .drectve +.ascii " -export:\"make_fcontext\"" diff --git a/third_party/context/src/asm/make_x86_64_ms_pe_gas.asm b/third_party/context/src/asm/make_x86_64_ms_pe_gas.asm new file mode 100644 index 0000000..958a2a7 --- /dev/null +++ b/third_party/context/src/asm/make_x86_64_ms_pe_gas.asm @@ -0,0 +1,174 @@ +/* + Copyright Oliver Kowalke 2009. + Copyright Thomas Sailer 2013. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/************************************************************************************* +* ---------------------------------------------------------------------------------- * +* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * +* ---------------------------------------------------------------------------------- * +* | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | * +* ---------------------------------------------------------------------------------- * +* | SEE registers (XMM6-XMM15) | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * +* ---------------------------------------------------------------------------------- * +* | 0x20 | 0x24 | 0x28 | 0x2c | 0x30 | 0x34 | 0x38 | 0x3c | * +* ---------------------------------------------------------------------------------- * +* | SEE registers (XMM6-XMM15) | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * +* ---------------------------------------------------------------------------------- * +* | 0xe40 | 0x44 | 0x48 | 0x4c | 0x50 | 0x54 | 0x58 | 0x5c | * +* ---------------------------------------------------------------------------------- * +* | SEE registers (XMM6-XMM15) | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * +* ---------------------------------------------------------------------------------- * +* | 0x60 | 0x64 | 0x68 | 0x6c | 0x70 | 0x74 | 0x78 | 0x7c | * +* ---------------------------------------------------------------------------------- * +* | SEE registers (XMM6-XMM15) | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 32 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | * +* ---------------------------------------------------------------------------------- * +* | 0x80 | 0x84 | 0x88 | 0x8c | 0x90 | 0x94 | 0x98 | 0x9c | * +* ---------------------------------------------------------------------------------- * +* | SEE registers (XMM6-XMM15) | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | * +* ---------------------------------------------------------------------------------- * +* | 0xa0 | 0xa4 | 0xa8 | 0xac | 0xb0 | 0xb4 | 0xb8 | 0xbc | * +* ---------------------------------------------------------------------------------- * +* | fc_mxcsr|fc_x87_cw| | fbr_strg | fc_dealloc | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | * +* ---------------------------------------------------------------------------------- * +* | 0xc0 | 0xc4 | 0xc8 | 0xcc | 0xd0 | 0xd4 | 0xd8 | 0xdc | * +* ---------------------------------------------------------------------------------- * +* | limit | base | R12 | R13 | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | * +* ---------------------------------------------------------------------------------- * +* | 0xe0 | 0xe4 | 0xe8 | 0xec | 0xf0 | 0xf4 | 0xf8 | 0xfc | * +* ---------------------------------------------------------------------------------- * +* | R14 | R15 | RDI | RSI | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | * +* ---------------------------------------------------------------------------------- * +* | 0x100 | 0x104 | 0x108 | 0x10c | 0x110 | 0x114 | 0x118 | 0x11c | * +* ---------------------------------------------------------------------------------- * +* | RBX | RBP | hidden | RIP | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | * +* ---------------------------------------------------------------------------------- * +* | 0x120 | 0x124 | 0x128 | 0x12c | 0x130 | 0x134 | 0x138 | 0x13c | * +* ---------------------------------------------------------------------------------- * +* | parameter area | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | * +* ---------------------------------------------------------------------------------- * +* | 0x140 | 0x144 | 0x148 | 0x14c | 0x150 | 0x154 | 0x158 | 0x15c | * +* ---------------------------------------------------------------------------------- * +* | FCTX | DATA | | * +* ---------------------------------------------------------------------------------- * +**************************************************************************************/ + +.file "make_x86_64_ms_pe_gas.asm" +.text +.p2align 4,,15 +.globl make_fcontext +.def make_fcontext; .scl 2; .type 32; .endef +.seh_proc make_fcontext +make_fcontext: +.seh_endprologue + + /* first arg of make_fcontext() == top of context-stack */ + movq %rcx, %rax + + /* shift address in RAX to lower 16 byte boundary */ + /* == pointer to fcontext_t and address of context stack */ + andq $-16, %rax + + /* reserve space for context-data on context-stack */ + /* on context-function entry: (RSP -0x8) % 16 == 0 */ + leaq -0x150(%rax), %rax + + /* third arg of make_fcontext() == address of context-function */ + movq %r8, 0x100(%rax) + + /* first arg of make_fcontext() == top of context-stack */ + /* save top address of context stack as 'base' */ + movq %rcx, 0xc8(%rax) + /* second arg of make_fcontext() == size of context-stack */ + /* negate stack size for LEA instruction (== substraction) */ + negq %rdx + /* compute bottom address of context stack (limit) */ + leaq (%rcx,%rdx), %rcx + /* save bottom address of context stack as 'limit' */ + movq %rcx, 0xc0(%rax) + /* save address of context stack limit as 'dealloction stack' */ + movq %rcx, 0xb8(%rax) + /* set fiber-storage to zero */ + xorq %rcx, %rcx + movq %rcx, 0xb0(%rax) + + /* save MMX control- and status-word */ + stmxcsr 0xa0(%rax) + /* save x87 control-word */ + fnstcw 0xa4(%rax) + + /* compute address of transport_t */ + leaq 0x140(%rax), %rcx + /* store address of transport_t in hidden field */ + movq %rcx, 0x110(%rax) + + /* compute abs address of label trampoline */ + leaq trampoline(%rip), %rcx + /* save address of finish as return-address for context-function */ + /* will be entered after jump_fcontext() first time */ + movq %rcx, 0x118(%rax) + + /* compute abs address of label finish */ + leaq finish(%rip), %rcx + /* save address of finish as return-address for context-function */ + /* will be entered after context-function returns */ + movq %rcx, 0x108(%rax) + + ret /* return pointer to context-data */ + +trampoline: + /* store return address on stack */ + /* fix stack alignment */ + pushq %rbp + /* jump to context-function */ + jmp *%rbx + +finish: + /* 32byte shadow-space for _exit() */ + andq $-32, %rsp + /* 32byte shadow-space for _exit() are */ + /* already reserved by make_fcontext() */ + /* exit code is zero */ + xorq %rcx, %rcx + /* exit application */ + call _exit + hlt +.seh_endproc + +.def _exit; .scl 2; .type 32; .endef /* standard C library function */ + +.section .drectve +.ascii " -export:\"make_fcontext\"" diff --git a/third_party/context/src/asm/make_x86_64_ms_pe_masm.asm b/third_party/context/src/asm/make_x86_64_ms_pe_masm.asm new file mode 100644 index 0000000..8f6c959 --- /dev/null +++ b/third_party/context/src/asm/make_x86_64_ms_pe_masm.asm @@ -0,0 +1,163 @@ + +; Copyright Oliver Kowalke 2009. +; Distributed under the Boost Software License, Version 1.0. +; (See accompanying file LICENSE_1_0.txt or copy at +; http://www.boost.org/LICENSE_1_0.txt) + +; ---------------------------------------------------------------------------------- +; | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | +; ---------------------------------------------------------------------------------- +; | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | +; ---------------------------------------------------------------------------------- +; | SEE registers (XMM6-XMM15) | +; ---------------------------------------------------------------------------------- +; ---------------------------------------------------------------------------------- +; | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | +; ---------------------------------------------------------------------------------- +; | 0x20 | 0x24 | 0x28 | 0x2c | 0x30 | 0x34 | 0x38 | 0x3c | +; ---------------------------------------------------------------------------------- +; | SEE registers (XMM6-XMM15) | +; ---------------------------------------------------------------------------------- +; ---------------------------------------------------------------------------------- +; | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | +; ---------------------------------------------------------------------------------- +; | 0xe40 | 0x44 | 0x48 | 0x4c | 0x50 | 0x54 | 0x58 | 0x5c | +; ---------------------------------------------------------------------------------- +; | SEE registers (XMM6-XMM15) | +; ---------------------------------------------------------------------------------- +; ---------------------------------------------------------------------------------- +; | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | +; ---------------------------------------------------------------------------------- +; | 0x60 | 0x64 | 0x68 | 0x6c | 0x70 | 0x74 | 0x78 | 0x7c | +; ---------------------------------------------------------------------------------- +; | SEE registers (XMM6-XMM15) | +; ---------------------------------------------------------------------------------- +; ---------------------------------------------------------------------------------- +; | 32 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | +; ---------------------------------------------------------------------------------- +; | 0x80 | 0x84 | 0x88 | 0x8c | 0x90 | 0x94 | 0x98 | 0x9c | +; ---------------------------------------------------------------------------------- +; | SEE registers (XMM6-XMM15) | +; ---------------------------------------------------------------------------------- +; ---------------------------------------------------------------------------------- +; | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | +; ---------------------------------------------------------------------------------- +; | 0xa0 | 0xa4 | 0xa8 | 0xac | 0xb0 | 0xb4 | 0xb8 | 0xbc | +; ---------------------------------------------------------------------------------- +; | fc_mxcsr|fc_x87_cw| | fbr_strg | fc_dealloc | +; ---------------------------------------------------------------------------------- +; ---------------------------------------------------------------------------------- +; | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | +; ---------------------------------------------------------------------------------- +; | 0xc0 | 0xc4 | 0xc8 | 0xcc | 0xd0 | 0xd4 | 0xd8 | 0xdc | +; ---------------------------------------------------------------------------------- +; | limit | base | R12 | R13 | +; ---------------------------------------------------------------------------------- +; ---------------------------------------------------------------------------------- +; | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | +; ---------------------------------------------------------------------------------- +; | 0xe0 | 0xe4 | 0xe8 | 0xec | 0xf0 | 0xf4 | 0xf8 | 0xfc | +; ---------------------------------------------------------------------------------- +; | R14 | R15 | RDI | RSI | +; ---------------------------------------------------------------------------------- +; ---------------------------------------------------------------------------------- +; | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | +; ---------------------------------------------------------------------------------- +; | 0x100 | 0x104 | 0x108 | 0x10c | 0x110 | 0x114 | 0x118 | 0x11c | +; ---------------------------------------------------------------------------------- +; | RBX | RBP | hidden | RIP | +; ---------------------------------------------------------------------------------- +; ---------------------------------------------------------------------------------- +; | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | +; ---------------------------------------------------------------------------------- +; | 0x120 | 0x124 | 0x128 | 0x12c | 0x130 | 0x134 | 0x138 | 0x13c | +; ---------------------------------------------------------------------------------- +; | parameter area | +; ---------------------------------------------------------------------------------- +; ---------------------------------------------------------------------------------- +; | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | +; ---------------------------------------------------------------------------------- +; | 0x140 | 0x144 | 0x148 | 0x14c | 0x150 | 0x154 | 0x158 | 0x15c | +; ---------------------------------------------------------------------------------- +; | FCTX | DATA | | +; ---------------------------------------------------------------------------------- + +; standard C library function +EXTERN _exit:PROC +.code + +; generate function table entry in .pdata and unwind information in +make_fcontext PROC BOOST_CONTEXT_EXPORT FRAME + ; .xdata for a function's structured exception handling unwind behavior + .endprolog + + ; first arg of make_fcontext() == top of context-stack + mov rax, rcx + + ; shift address in RAX to lower 16 byte boundary + ; == pointer to fcontext_t and address of context stack + and rax, -16 + + ; reserve space for context-data on context-stack + ; on context-function entry: (RSP -0x8) % 16 == 0 + sub rax, 0150h + + ; third arg of make_fcontext() == address of context-function + ; stored in RBX + mov [rax+0100h], r8 + + ; first arg of make_fcontext() == top of context-stack + ; save top address of context stack as 'base' + mov [rax+0c8h], rcx + ; second arg of make_fcontext() == size of context-stack + ; negate stack size for LEA instruction (== substraction) + neg rdx + ; compute bottom address of context stack (limit) + lea rcx, [rcx+rdx] + ; save bottom address of context stack as 'limit' + mov [rax+0c0h], rcx + ; save address of context stack limit as 'dealloction stack' + mov [rax+0b8h], rcx + ; set fiber-storage to zero + xor rcx, rcx + mov [rax+0b0h], rcx + + ; save MMX control- and status-word + stmxcsr [rax+0a0h] + ; save x87 control-word + fnstcw [rax+0a4h] + + ; compute address of transport_t + lea rcx, [rax+0140h] + ; store address of transport_t in hidden field + mov [rax+0110h], rcx + + ; compute abs address of label trampoline + lea rcx, trampoline + ; save address of trampoline as return-address for context-function + ; will be entered after calling jump_fcontext() first time + mov [rax+0118h], rcx + + ; compute abs address of label finish + lea rcx, finish + ; save address of finish as return-address for context-function in RBP + ; will be entered after context-function returns + mov [rax+0108h], rcx + + ret ; return pointer to context-data + +trampoline: + ; store return address on stack + ; fix stack alignment + push rbp + ; jump to context-function + jmp rbx + +finish: + ; exit code is zero + xor rcx, rcx + ; exit application + call _exit + hlt +make_fcontext ENDP +END diff --git a/third_party/context/src/asm/make_x86_64_sysv_elf_gas.S b/third_party/context/src/asm/make_x86_64_sysv_elf_gas.S new file mode 100644 index 0000000..4294398 --- /dev/null +++ b/third_party/context/src/asm/make_x86_64_sysv_elf_gas.S @@ -0,0 +1,147 @@ +/* + Copyright Oliver Kowalke 2009. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/**************************************************************************************** + * * + * ---------------------------------------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ---------------------------------------------------------------------------------- * + * | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | * + * ---------------------------------------------------------------------------------- * + * | fc_mxcsr|fc_x87_cw| guard | R12 | R13 | * + * ---------------------------------------------------------------------------------- * + * ---------------------------------------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ---------------------------------------------------------------------------------- * + * | 0x20 | 0x24 | 0x28 | 0x2c | 0x30 | 0x34 | 0x38 | 0x3c | * + * ---------------------------------------------------------------------------------- * + * | R14 | R15 | RBX | RBP | * + * ---------------------------------------------------------------------------------- * + * ---------------------------------------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * + * ---------------------------------------------------------------------------------- * + * | 0x40 | 0x44 | | * + * ---------------------------------------------------------------------------------- * + * | RIP | | * + * ---------------------------------------------------------------------------------- * + * * + ****************************************************************************************/ + +# if defined __CET__ +# include +# define SHSTK_ENABLED (__CET__ & 0x2) +# define BOOST_CONTEXT_SHADOW_STACK (SHSTK_ENABLED && SHADOW_STACK_SYSCALL) +# else +# define _CET_ENDBR +# endif +.file "make_x86_64_sysv_elf_gas.S" +.text +.globl make_fcontext +.type make_fcontext,@function +.align 16 +make_fcontext: + _CET_ENDBR +#if BOOST_CONTEXT_SHADOW_STACK + /* the new shadow stack pointer (SSP) */ + movq -0x8(%rdi), %r9 +#endif + + /* first arg of make_fcontext() == top of context-stack */ + movq %rdi, %rax + + /* shift address in RAX to lower 16 byte boundary */ + andq $-16, %rax + + /* reserve space for context-data on context-stack */ + /* on context-function entry: (RSP -0x8) % 16 == 0 */ + leaq -0x48(%rax), %rax + + /* third arg of make_fcontext() == address of context-function */ + /* stored in RBX */ + movq %rdx, 0x30(%rax) + + /* save MMX control- and status-word */ + stmxcsr (%rax) + /* save x87 control-word */ + fnstcw 0x4(%rax) + +#if defined(BOOST_CONTEXT_TLS_STACK_PROTECTOR) + /* save stack guard */ + movq %fs:0x28, %rcx /* read stack guard from TLS record */ + movq %rcx, 0x8(%rsp) /* save stack guard */ +#endif + + /* compute abs address of label trampoline */ + leaq trampoline(%rip), %rcx + /* save address of trampoline as return-address for context-function */ + /* will be entered after calling jump_fcontext() first time */ + movq %rcx, 0x40(%rax) + + /* compute abs address of label finish */ + leaq finish(%rip), %rcx + /* save address of finish as return-address for context-function */ + /* will be entered after context-function returns */ + movq %rcx, 0x38(%rax) + +#if BOOST_CONTEXT_SHADOW_STACK + /* Populate the shadow stack and normal stack */ + /* get original SSP */ + rdsspq %r8 + /* restore new shadow stack */ + rstorssp -0x8(%r9) + /* save the restore token on the original shadow stack */ + saveprevssp + /* push the address of "jmp trampoline" to the new shadow stack */ + /* as well as the stack */ + call 1f + jmp trampoline +1: + /* save address of "jmp trampoline" as return-address */ + /* for context-function */ + pop 0x38(%rax) + /* Get the new SSP. */ + rdsspq %r9 + /* restore original shadow stack */ + rstorssp -0x8(%r8) + /* save the restore token on the new shadow stack. */ + saveprevssp + + /* reserve space for the new SSP */ + leaq -0x8(%rax), %rax + /* save the new SSP to this fcontext */ + movq %r9, (%rax) +#endif + + ret /* return pointer to context-data */ + +trampoline: + _CET_ENDBR + /* store return address on stack */ + /* fix stack alignment */ +#if BOOST_CONTEXT_SHADOW_STACK + /* save address of "jmp *%rbp" as return-address */ + /* on stack and shadow stack */ + call 2f + jmp *%rbp +2: +#else + push %rbp +#endif + /* jump to context-function */ + jmp *%rbx + +finish: + _CET_ENDBR + /* exit code is zero */ + xorq %rdi, %rdi + /* exit application */ + call _exit@PLT + hlt +.size make_fcontext,.-make_fcontext + +/* Mark that we don't need executable stack. */ +.section .note.GNU-stack,"",%progbits diff --git a/third_party/context/src/asm/make_x86_64_sysv_macho_gas.S b/third_party/context/src/asm/make_x86_64_sysv_macho_gas.S new file mode 100644 index 0000000..5d6c543 --- /dev/null +++ b/third_party/context/src/asm/make_x86_64_sysv_macho_gas.S @@ -0,0 +1,76 @@ +/* + Copyright Oliver Kowalke 2009. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/**************************************************************************************** + * * + * ---------------------------------------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ---------------------------------------------------------------------------------- * + * | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | * + * ---------------------------------------------------------------------------------- * + * | fc_mxcsr|fc_x87_cw| R12 | R13 | R14 | * + * ---------------------------------------------------------------------------------- * + * ---------------------------------------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ---------------------------------------------------------------------------------- * + * | 0x20 | 0x24 | 0x28 | 0x2c | 0x30 | 0x34 | 0x38 | 0x3c | * + * ---------------------------------------------------------------------------------- * + * | R15 | RBX | RBP | RIP | * + * ---------------------------------------------------------------------------------- * + * * + ****************************************************************************************/ + +.text +.globl _make_fcontext +.align 8 +_make_fcontext: + /* first arg of make_fcontext() == top of context-stack */ + movq %rdi, %rax + + /* shift address in RAX to lower 16 byte boundary */ + andq $-16, %rax + + /* reserve space for context-data on context-stack */ + /* on context-function entry: (RSP -0x8) % 16 == 0 */ + leaq -0x40(%rax), %rax + + /* third arg of make_fcontext() == address of context-function */ + /* stored in RBX */ + movq %rdx, 0x28(%rax) + + /* save MMX control- and status-word */ + stmxcsr (%rax) + /* save x87 control-word */ + fnstcw 0x4(%rax) + + /* compute abs address of label trampoline */ + leaq trampoline(%rip), %rcx + /* save address of trampoline as return-address for context-function */ + /* will be entered after calling jump_fcontext() first time */ + movq %rcx, 0x38(%rax) + + /* compute abs address of label finish */ + leaq finish(%rip), %rcx + /* save address of finish as return-address for context-function */ + /* will be entered after context-function returns */ + movq %rcx, 0x30(%rax) + + ret /* return pointer to context-data */ + +trampoline: + /* store return address on stack */ + /* fix stack alignment */ + push %rbp + /* jump to context-function */ + jmp *%rbx + +finish: + /* exit code is zero */ + xorq %rdi, %rdi + /* exit application */ + call __exit + hlt diff --git a/third_party/context/src/asm/ontop_arm64_aapcs_elf_gas.S b/third_party/context/src/asm/ontop_arm64_aapcs_elf_gas.S new file mode 100644 index 0000000..665ca5a --- /dev/null +++ b/third_party/context/src/asm/ontop_arm64_aapcs_elf_gas.S @@ -0,0 +1,113 @@ +/* + Copyright Edward Nevill + Oliver Kowalke 2015 + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ +/******************************************************* + * * + * ------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ------------------------------------------------- * + * | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| * + * ------------------------------------------------- * + * | d8 | d9 | d10 | d11 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ------------------------------------------------- * + * | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| * + * ------------------------------------------------- * + * | d12 | d13 | d14 | d15 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * + * ------------------------------------------------- * + * | 0x40| 0x44| 0x48| 0x4c| 0x50| 0x54| 0x58| 0x5c| * + * ------------------------------------------------- * + * | x19 | x20 | x21 | x22 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * + * ------------------------------------------------- * + * | 0x60| 0x64| 0x68| 0x6c| 0x70| 0x74| 0x78| 0x7c| * + * ------------------------------------------------- * + * | x23 | x24 | x25 | x26 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * + * ------------------------------------------------- * + * | 0x80| 0x84| 0x88| 0x8c| 0x90| 0x94| 0x98| 0x9c| * + * ------------------------------------------------- * + * | x27 | x28 | FP | LR | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 40 | 41 | 42 | 43 | | | * + * ------------------------------------------------- * + * | 0xa0| 0xa4| 0xa8| 0xac| | | * + * ------------------------------------------------- * + * | PC | align | | | * + * ------------------------------------------------- * + * * + *******************************************************/ + +.file "ontop_arm64_aapcs_elf_gas.S" +.text +.align 2 +.global ontop_fcontext +.type ontop_fcontext, %function +ontop_fcontext: + # prepare stack for GP + FPU + sub sp, sp, #0xb0 + + # save d8 - d15 + stp d8, d9, [sp, #0x00] + stp d10, d11, [sp, #0x10] + stp d12, d13, [sp, #0x20] + stp d14, d15, [sp, #0x30] + + # save x19-x30 + stp x19, x20, [sp, #0x40] + stp x21, x22, [sp, #0x50] + stp x23, x24, [sp, #0x60] + stp x25, x26, [sp, #0x70] + stp x27, x28, [sp, #0x80] + stp x29, x30, [sp, #0x90] + + # save LR as PC + str x30, [sp, #0xa0] + + # store RSP (pointing to context-data) in X5 + mov x4, sp + + # restore RSP (pointing to context-data) from X1 + mov sp, x0 + + # load d8 - d15 + ldp d8, d9, [sp, #0x00] + ldp d10, d11, [sp, #0x10] + ldp d12, d13, [sp, #0x20] + ldp d14, d15, [sp, #0x30] + + # load x19-x30 + ldp x19, x20, [sp, #0x40] + ldp x21, x22, [sp, #0x50] + ldp x23, x24, [sp, #0x60] + ldp x25, x26, [sp, #0x70] + ldp x27, x28, [sp, #0x80] + ldp x29, x30, [sp, #0x90] + + # return transfer_t from jump + # pass transfer_t as first arg in context function + # X0 == FCTX, X1 == DATA + mov x0, x4 + + # skip pc + # restore stack from GP + FPU + add sp, sp, #0xb0 + + # jump to ontop-function + ret x2 +.size ontop_fcontext,.-ontop_fcontext +# Mark that we don't need executable stack. +.section .note.GNU-stack,"",%progbits diff --git a/third_party/context/src/asm/ontop_arm64_aapcs_macho_gas.S b/third_party/context/src/asm/ontop_arm64_aapcs_macho_gas.S new file mode 100644 index 0000000..a387d06 --- /dev/null +++ b/third_party/context/src/asm/ontop_arm64_aapcs_macho_gas.S @@ -0,0 +1,108 @@ +/* + Copyright Edward Nevill + Oliver Kowalke 2015 + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ +/******************************************************* + * * + * ------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ------------------------------------------------- * + * | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| * + * ------------------------------------------------- * + * | d8 | d9 | d10 | d11 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ------------------------------------------------- * + * | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| * + * ------------------------------------------------- * + * | d12 | d13 | d14 | d15 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * + * ------------------------------------------------- * + * | 0x40| 0x44| 0x48| 0x4c| 0x50| 0x54| 0x58| 0x5c| * + * ------------------------------------------------- * + * | x19 | x20 | x21 | x22 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * + * ------------------------------------------------- * + * | 0x60| 0x64| 0x68| 0x6c| 0x70| 0x74| 0x78| 0x7c| * + * ------------------------------------------------- * + * | x23 | x24 | x25 | x26 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * + * ------------------------------------------------- * + * | 0x80| 0x84| 0x88| 0x8c| 0x90| 0x94| 0x98| 0x9c| * + * ------------------------------------------------- * + * | x27 | x28 | FP | LR | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 40 | 41 | 42 | 43 | | | * + * ------------------------------------------------- * + * | 0xa0| 0xa4| 0xa8| 0xac| | | * + * ------------------------------------------------- * + * | PC | align | | | * + * ------------------------------------------------- * + * * + *******************************************************/ + +.text +.global _ontop_fcontext +.balign 16 +_ontop_fcontext: + ; prepare stack for GP + FPU + sub sp, sp, #0xb0 + + ; save d8 - d15 + stp d8, d9, [sp, #0x00] + stp d10, d11, [sp, #0x10] + stp d12, d13, [sp, #0x20] + stp d14, d15, [sp, #0x30] + + ; save x19-x30 + stp x19, x20, [sp, #0x40] + stp x21, x22, [sp, #0x50] + stp x23, x24, [sp, #0x60] + stp x25, x26, [sp, #0x70] + stp x27, x28, [sp, #0x80] + stp x29, x30, [sp, #0x90] + + ; save LR as PC + str x30, [sp, #0xa0] + + ; store RSP (pointing to context-data) in X5 + mov x4, sp + + ; restore RSP (pointing to context-data) from X1 + mov sp, x0 + + ; load d8 - d15 + ldp d8, d9, [sp, #0x00] + ldp d10, d11, [sp, #0x10] + ldp d12, d13, [sp, #0x20] + ldp d14, d15, [sp, #0x30] + + ; load x19-x30 + ldp x19, x20, [sp, #0x40] + ldp x21, x22, [sp, #0x50] + ldp x23, x24, [sp, #0x60] + ldp x25, x26, [sp, #0x70] + ldp x27, x28, [sp, #0x80] + ldp x29, x30, [sp, #0x90] + + ; return transfer_t from jump + ; pass transfer_t as first arg in context function + ; X0 == FCTX, X1 == DATA + mov x0, x4 + + ; skip pc + ; restore stack from GP + FPU + add sp, sp, #0xb0 + + ; jump to ontop-function + ret x2 diff --git a/third_party/context/src/asm/ontop_arm64_aapcs_pe_armasm.asm b/third_party/context/src/asm/ontop_arm64_aapcs_pe_armasm.asm new file mode 100644 index 0000000..dc522c0 --- /dev/null +++ b/third_party/context/src/asm/ontop_arm64_aapcs_pe_armasm.asm @@ -0,0 +1,132 @@ +; Copyright Edward Nevill + Oliver Kowalke 2015 +; Distributed under the Boost Software License, Version 1.0. +; (See accompanying file LICENSE_1_0.txt or copy at +; http://www.boost.org/LICENSE_1_0.txt) + +;******************************************************* +;* * +;* ------------------------------------------------- * +;* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * +;* ------------------------------------------------- * +;* | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| * +;* ------------------------------------------------- * +;* | d8 | d9 | d10 | d11 | * +;* ------------------------------------------------- * +;* ------------------------------------------------- * +;* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * +;* ------------------------------------------------- * +;* | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| * +;* ------------------------------------------------- * +;* | d12 | d13 | d14 | d15 | * +;* ------------------------------------------------- * +;* ------------------------------------------------- * +;* | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * +;* ------------------------------------------------- * +;* | 0x40| 0x44| 0x48| 0x4c| 0x50| 0x54| 0x58| 0x5c| * +;* ------------------------------------------------- * +;* | x19 | x20 | x21 | x22 | * +;* ------------------------------------------------- * +;* ------------------------------------------------- * +;* | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * +;* ------------------------------------------------- * +;* | 0x60| 0x64| 0x68| 0x6c| 0x70| 0x74| 0x78| 0x7c| * +;* ------------------------------------------------- * +;* | x23 | x24 | x25 | x26 | * +;* ------------------------------------------------- * +;* ------------------------------------------------- * +;* | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * +;* ------------------------------------------------- * +;* | 0x80| 0x84| 0x88| 0x8c| 0x90| 0x94| 0x98| 0x9c| * +;* ------------------------------------------------- * +;* | x27 | x28 | FP | LR | * +;* ------------------------------------------------- * +;* ------------------------------------------------- * +;* | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | * +;* ------------------------------------------------- * +;* | 0xa0| 0xa4| 0xa8| 0xac| 0xb0| 0xb4| 0xb8| 0xbc| * +;* ------------------------------------------------- * +;* | fiber data| base | limit | dealloc | * +;* ------------------------------------------------- * +;* ------------------------------------------------- * +;* | 48 | 49 | 50 | 51 | | | * +;* ------------------------------------------------- * +;* | 0xc0| 0xc4| 0xc8| 0xcc| | | * +;* ------------------------------------------------- * +;* | PC | align | | | * +;* ------------------------------------------------- * +;* * +;******************************************************* + + AREA |.text|, CODE, READONLY, ALIGN=4, CODEALIGN + EXPORT ontop_fcontext + +ontop_fcontext proc BOOST_CONTEXT_EXPORT + ; prepare stack for GP + FPU + sub sp, sp, #0xd0 + + ; save d8 - d15 + stp d8, d9, [sp, #0x00] + stp d10, d11, [sp, #0x10] + stp d12, d13, [sp, #0x20] + stp d14, d15, [sp, #0x30] + + ; save x19-x30 + stp x19, x20, [sp, #0x40] + stp x21, x22, [sp, #0x50] + stp x23, x24, [sp, #0x60] + stp x25, x26, [sp, #0x70] + stp x27, x28, [sp, #0x80] + stp x29, x30, [sp, #0x90] + + ; save LR as PC + str x30, [sp, #0xc0] + + ; save current stack base and limit + ldp x5, x6, [x18, #0x08] ; TeStackBase and TeStackLimit at ksarm64.h + stp x5, x6, [sp, #0xa0] + ; save current fiber data and deallocation stack + ldr x5, [x18, #0x1478] ; TeDeallocationStack at ksarm64.h + ldr x6, [x18, #0x20] ; TeFiberData at ksarm64.h + stp x5, x6, [sp, #0xb0] + + ; store RSP (pointing to context-data) in X5 + mov x4, sp + + ; restore RSP (pointing to context-data) from X1 + mov sp, x0 + + ; restore stack base and limit + ldp x5, x6, [sp, #0xa0] + stp x5, x6, [x18, #0x08] ; TeStackBase and TeStackLimit at ksarm64.h + ; restore fiber data and deallocation stack + ldp x5, x6, [sp, #0xb0] + str x5, [x18, #0x1478] ; TeDeallocationStack at ksarm64.h + str x6, [x18, #0x20] ; TeFiberData at ksarm64.h + + ; load d8 - d15 + ldp d8, d9, [sp, #0x00] + ldp d10, d11, [sp, #0x10] + ldp d12, d13, [sp, #0x20] + ldp d14, d15, [sp, #0x30] + + ; load x19-x30 + ldp x19, x20, [sp, #0x40] + ldp x21, x22, [sp, #0x50] + ldp x23, x24, [sp, #0x60] + ldp x25, x26, [sp, #0x70] + ldp x27, x28, [sp, #0x80] + ldp x29, x30, [sp, #0x90] + + ; return transfer_t from jump + ; pass transfer_t as first arg in context function + ; X0 == FCTX, X1 == DATA + mov x0, x4 + + ; skip pc + ; restore stack from GP + FPU + add sp, sp, #0xc0 + + ; jump to ontop-function + ret x2 + ENDP + END diff --git a/third_party/context/src/asm/ontop_arm_aapcs_elf_gas.S b/third_party/context/src/asm/ontop_arm_aapcs_elf_gas.S new file mode 100644 index 0000000..59ad5ca --- /dev/null +++ b/third_party/context/src/asm/ontop_arm_aapcs_elf_gas.S @@ -0,0 +1,93 @@ +/* + Copyright Oliver Kowalke 2009. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/******************************************************* + * * + * ------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ------------------------------------------------- * + * | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| * + * ------------------------------------------------- * + * | s16 | s17 | s18 | s19 | s20 | s21 | s22 | s23 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ------------------------------------------------- * + * | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| * + * ------------------------------------------------- * + * | s24 | s25 | s26 | s27 | s28 | s29 | s30 | s31 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * + * ------------------------------------------------- * + * | 0x40| 0x44| 0x48| 0x4c| 0x50| 0x54| 0x58| 0x5c| * + * ------------------------------------------------- * + * |hiddn| v1 | v2 | v3 | v4 | v5 | v6 | v7 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * + * ------------------------------------------------- * + * | 0x60| 0x64| 0x68| 0x6c| 0x70| 0x74| 0x78| 0x7c| * + * ------------------------------------------------- * + * | v8 | lr | pc | FCTX| DATA| | * + * ------------------------------------------------- * + * * + *******************************************************/ + +.file "ontop_arm_aapcs_elf_gas.S" +.text +.globl ontop_fcontext +.align 2 +.type ontop_fcontext,%function +.syntax unified +ontop_fcontext: + @ save LR as PC + push {lr} + @ save hidden,V1-V8,LR + push {a1,v1-v8,lr} + + @ prepare stack for FPU + sub sp, sp, #64 +#if (defined(__VFP_FP__) && !defined(__SOFTFP__)) + @ save S16-S31 + vstmia sp, {d8-d15} +#endif + + @ store RSP (pointing to context-data) in A1 + mov a1, sp + + @ restore RSP (pointing to context-data) from A2 + mov sp, a2 + + @ store parent context in A2 + mov a2, a1 + +#if (defined(__VFP_FP__) && !defined(__SOFTFP__)) + @ restore S16-S31 + vldmia sp, {d8-d15} +#endif + @ prepare stack for FPU + add sp, sp, #64 + + @ restore hidden,V1-V8,LR + pop {a1,v1-v8,lr} + + @ return transfer_t from jump + str a2, [a1, #0] + str a3, [a1, #4] + @ pass transfer_t as first arg in context function + @ A1 == hidden, A2 == FCTX, A3 == DATA + + @ skip PC + add sp, sp, #4 + + @ jump to ontop-function + bx a4 +.size ontop_fcontext,.-ontop_fcontext + +@ Mark that we don't need executable stack. +.section .note.GNU-stack,"",%progbits diff --git a/third_party/context/src/asm/ontop_arm_aapcs_macho_gas.S b/third_party/context/src/asm/ontop_arm_aapcs_macho_gas.S new file mode 100644 index 0000000..3633aca --- /dev/null +++ b/third_party/context/src/asm/ontop_arm_aapcs_macho_gas.S @@ -0,0 +1,100 @@ +/* + Copyright Oliver Kowalke 2009. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/******************************************************* + * * + * ------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ------------------------------------------------- * + * | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| * + * ------------------------------------------------- * + * | s16 | s17 | s18 | s19 | s20 | s21 | s22 | s23 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ------------------------------------------------- * + * | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| * + * ------------------------------------------------- * + * | s24 | s25 | s26 | s27 | s28 | s29 | s30 | s31 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * + * ------------------------------------------------- * + * | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| * + * ------------------------------------------------- * + * | sjlj|hiddn| v1 | v2 | v3 | v4 | v5 | v6 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * + * ------------------------------------------------- * + * | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| * + * ------------------------------------------------- * + * | v7 | v8 | lr | pc | FCTX| DATA| | * + * ------------------------------------------------- * + * * + *******************************************************/ + +.text +.globl _ontop_fcontext +.align 2 +_ontop_fcontext: + @ save LR as PC + push {lr} + @ save hidden,V1-V8,LR + push {a1,v1-v8,lr} + + @ locate TLS to save/restore SjLj handler + mrc p15, 0, v2, c13, c0, #3 + bic v2, v2, #3 + + @ load TLS[__PTK_LIBC_DYLD_Unwind_SjLj_Key] + ldr v1, [v2, #72] + @ save SjLj handler + push {v1} + + @ prepare stack for FPU + sub sp, sp, #64 +#if (defined(__VFP_FP__) && !defined(__SOFTFP__)) + @ save S16-S31 + vstmia sp, {d8-d15} +#endif + + @ store RSP (pointing to context-data) in A1 + mov a1, sp + + @ restore RSP (pointing to context-data) from A2 + mov sp, a2 + +#if (defined(__VFP_FP__) && !defined(__SOFTFP__)) + @ restore S16-S31 + vldmia sp, {d8-d15} +#endif + @ prepare stack for FPU + add sp, sp, #64 + + @ restore SjLj handler + pop {v1} + @ store SjLj handler in TLS + str v1, [v2, #72] + + @ store parent context in A2 + mov a2, a1 + + @ restore hidden,V1-V8,LR + pop {a1,v1-v8,lr} + + @ return transfer_t from jump + str a2, [a1, #0] + str a3, [a1, #4] + @ pass transfer_t as first arg in context function + @ A1 == hidden, A2 == FCTX, A3 == DATA + + @ skip PC + add sp, sp, #4 + + @ jump to ontop-function + bx a4 diff --git a/third_party/context/src/asm/ontop_arm_aapcs_pe_armasm.asm b/third_party/context/src/asm/ontop_arm_aapcs_pe_armasm.asm new file mode 100644 index 0000000..f360a8f --- /dev/null +++ b/third_party/context/src/asm/ontop_arm_aapcs_pe_armasm.asm @@ -0,0 +1,86 @@ +;/* +; Copyright Oliver Kowalke 2009. +; Distributed under the Boost Software License, Version 1.0. +; (See accompanying file LICENSE_1_0.txt or copy at +; http://www.boost.org/LICENSE_1_0.txt) +;*/ + +; ******************************************************* +; * * +; * ------------------------------------------------- * +; * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * +; * ------------------------------------------------- * +; * | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| * +; * ------------------------------------------------- * +; * |deall|limit| base|hiddn| v1 | v2 | v3 | v4 | * +; * ------------------------------------------------- * +; * ------------------------------------------------- * +; * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * +; * ------------------------------------------------- * +; * | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| * +; * ------------------------------------------------- * +; * | v5 | v6 | v7 | v8 | lr | pc | FCTX| DATA| * +; * ------------------------------------------------- * +; * * +; ******************************************************* + + AREA |.text|, CODE + ALIGN 4 + EXPORT ontop_fcontext + +ontop_fcontext PROC + ; save LR as PC + push {lr} + ; save hidden,V1-V8,LR + push {a1,v1-v8,lr} + + ; load TIB to save/restore thread size and limit. + ; we do not need preserve CPU flag and can use it's arg register + mrc p15, #0, v1, c13, c0, #2 + + ; save current stack base + ldr a1, [v1, #0x04] + push {a1} + ; save current stack limit + ldr a1, [v1, #0x08] + push {a1} + ; save current deallocation stack + ldr a1, [v1, #0xe0c] + push {a1} + + ; store RSP (pointing to context-data) in A1 + mov a1, sp + + ; restore RSP (pointing to context-data) from A2 + mov sp, a2 + + ; restore stack base + pop {a1} + str a1, [v1, #0x04] + ; restore stack limit + pop {a1} + str a1, [v1, #0x08] + ; restore deallocation stack + pop {a1} + str a1, [v1, #0xe0c] + + ; store parent context in A2 + mov a2, a1 + + ; restore hidden,V1-V8,LR + pop {a1,v1-v8,lr} + + ; return transfer_t from jump + str a2, [a1, #0] + str a3, [a1, #4] + ; pass transfer_t as first arg in context function + ; A1 == hidden, A2 == FCTX, A3 == DATA + + ; skip PC + add sp, sp, #4 + + ; jump to ontop-function + bx a4 + + ENDP + END diff --git a/third_party/context/src/asm/ontop_combined_sysv_macho_gas.S b/third_party/context/src/asm/ontop_combined_sysv_macho_gas.S new file mode 100644 index 0000000..7d254de --- /dev/null +++ b/third_party/context/src/asm/ontop_combined_sysv_macho_gas.S @@ -0,0 +1,24 @@ +/* + Copyright Sergue E. Leontiev 2013. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +// Stub file for universal binary + +#if defined(__i386__) + #include "ontop_i386_sysv_macho_gas.S" +#elif defined(__x86_64__) + #include "ontop_x86_64_sysv_macho_gas.S" +#elif defined(__ppc__) + #include "ontop_ppc32_sysv_macho_gas.S" +#elif defined(__ppc64__) + #include "ontop_ppc64_sysv_macho_gas.S" +#elif defined(__arm__) + #include "ontop_arm_aapcs_macho_gas.S" +#elif defined(__arm64__) + #include "ontop_arm64_aapcs_macho_gas.S" +#else + #error "No arch's" +#endif diff --git a/third_party/context/src/asm/ontop_i386_ms_pe_clang_gas.S b/third_party/context/src/asm/ontop_i386_ms_pe_clang_gas.S new file mode 100644 index 0000000..16eb33e --- /dev/null +++ b/third_party/context/src/asm/ontop_i386_ms_pe_clang_gas.S @@ -0,0 +1,131 @@ +/* + Copyright Oliver Kowalke 2009. + Copyright Thomas Sailer 2013. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/************************************************************************************* +* --------------------------------------------------------------------------------- * +* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * +* --------------------------------------------------------------------------------- * +* | 0h | 04h | 08h | 0ch | 010h | 014h | 018h | 01ch | * +* --------------------------------------------------------------------------------- * +* | fc_mxcsr|fc_x87_cw| fc_strg |fc_deallo| limit | base | fc_seh | EDI | * +* --------------------------------------------------------------------------------- * +* --------------------------------------------------------------------------------- * +* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * +* --------------------------------------------------------------------------------- * +* | 020h | 024h | 028h | 02ch | 030h | 034h | 038h | 03ch | * +* --------------------------------------------------------------------------------- * +* | ESI | EBX | EBP | EIP | to | data | EH NXT |SEH HNDLR| * +* --------------------------------------------------------------------------------- * +**************************************************************************************/ + +.file "ontop_i386_ms_pe_clang_gas.S" +.text +.p2align 4,,15 + +/* mark as using no unregistered SEH handlers */ +.globl @feat.00 +.def @feat.00; .scl 3; .type 0; .endef +.set @feat.00, 1 + +.globl _ontop_fcontext +.def _ontop_fcontext; .scl 2; .type 32; .endef +_ontop_fcontext: + /* prepare stack */ + leal -0x2c(%esp), %esp + +#if !defined(BOOST_USE_TSX) + /* save MMX control- and status-word */ + stmxcsr (%esp) + /* save x87 control-word */ + fnstcw 0x4(%esp) +#endif + + /* load NT_TIB */ + movl %fs:(0x18), %edx + /* load fiber local storage */ + movl 0x10(%edx), %eax + movl %eax, 0x8(%esp) + /* load current dealloction stack */ + movl 0xe0c(%edx), %eax + movl %eax, 0xc(%esp) + /* load current stack limit */ + movl 0x8(%edx), %eax + movl %eax, 0x10(%esp) + /* load current stack base */ + movl 0x4(%edx), %eax + movl %eax, 0x14(%esp) + /* load current SEH exception list */ + movl (%edx), %eax + movl %eax, 0x18(%esp) + + movl %edi, 0x1c(%esp) /* save EDI */ + movl %esi, 0x20(%esp) /* save ESI */ + movl %ebx, 0x24(%esp) /* save EBX */ + movl %ebp, 0x28(%esp) /* save EBP */ + + /* store ESP (pointing to context-data) in ECX */ + movl %esp, %ecx + + /* first arg of ontop_fcontext() == fcontext to jump to */ + movl 0x30(%esp), %eax + + /* pass parent fcontext_t */ + movl %ecx, 0x30(%eax) + + /* second arg of ontop_fcontext() == data to be transferred */ + movl 0x34(%esp), %ecx + + /* pass data */ + movl %ecx, 0x34(%eax) + + /* third arg of ontop_fcontext() == ontop-function */ + movl 0x38(%esp), %ecx + + /* restore ESP (pointing to context-data) from EDX */ + movl %eax, %esp + +#if !defined(BOOST_USE_TSX) + /* restore MMX control- and status-word */ + ldmxcsr (%esp) + /* restore x87 control-word */ + fldcw 0x4(%esp) +#endif + + /* restore NT_TIB into EDX */ + movl %fs:(0x18), %edx + /* restore fiber local storage */ + movl 0x8(%esp), %eax + movl %eax, 0x10(%edx) + /* restore current deallocation stack */ + movl 0xc(%esp), %eax + movl %eax, 0xe0c(%edx) + /* restore current stack limit */ + movl 0x10(%esp), %eax + movl %eax, 0x08(%edx) + /* restore current stack base */ + movl 0x14(%esp), %eax + movl %eax, 0x04(%edx) + /* restore current SEH exception list */ + movl 0x18(%esp), %eax + movl %eax, (%edx) + + movl 0x1c(%esp), %edi /* restore EDI */ + movl 0x20(%esp), %esi /* restore ESI */ + movl 0x24(%esp), %ebx /* restore EBX */ + movl 0x28(%esp), %ebp /* restore EBP */ + + /* prepare stack */ + leal 0x2c(%esp), %esp + + /* keep return-address on stack */ + + /* jump to context */ + jmp *%ecx + +.section .drectve +.ascii " -export:\"_ontop_fcontext\"" diff --git a/third_party/context/src/asm/ontop_i386_ms_pe_gas.asm b/third_party/context/src/asm/ontop_i386_ms_pe_gas.asm new file mode 100644 index 0000000..abe9002 --- /dev/null +++ b/third_party/context/src/asm/ontop_i386_ms_pe_gas.asm @@ -0,0 +1,131 @@ +/* + Copyright Oliver Kowalke 2009. + Copyright Thomas Sailer 2013. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/************************************************************************************* +* --------------------------------------------------------------------------------- * +* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * +* --------------------------------------------------------------------------------- * +* | 0h | 04h | 08h | 0ch | 010h | 014h | 018h | 01ch | * +* --------------------------------------------------------------------------------- * +* | fc_mxcsr|fc_x87_cw| fc_strg |fc_deallo| limit | base | fc_seh | EDI | * +* --------------------------------------------------------------------------------- * +* --------------------------------------------------------------------------------- * +* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * +* --------------------------------------------------------------------------------- * +* | 020h | 024h | 028h | 02ch | 030h | 034h | 038h | 03ch | * +* --------------------------------------------------------------------------------- * +* | ESI | EBX | EBP | EIP | to | data | EH NXT |SEH HNDLR| * +* --------------------------------------------------------------------------------- * +**************************************************************************************/ + +.file "ontop_i386_ms_pe_gas.asm" +.text +.p2align 4,,15 + +/* mark as using no unregistered SEH handlers */ +.globl @feat.00 +.def @feat.00; .scl 3; .type 0; .endef +.set @feat.00, 1 + +.globl _ontop_fcontext +.def _ontop_fcontext; .scl 2; .type 32; .endef +_ontop_fcontext: + /* prepare stack */ + leal -0x2c(%esp), %esp + +#if !defined(BOOST_USE_TSX) + /* save MMX control- and status-word */ + stmxcsr (%esp) + /* save x87 control-word */ + fnstcw 0x4(%esp) +#endif + + /* load NT_TIB */ + movl %fs:(0x18), %edx + /* load fiber local storage */ + movl 0x10(%edx), %eax + movl %eax, 0x8(%esp) + /* load current dealloction stack */ + movl 0xe0c(%edx), %eax + movl %eax, 0xc(%esp) + /* load current stack limit */ + movl 0x8(%edx), %eax + movl %eax, 0x10(%esp) + /* load current stack base */ + movl 0x4(%edx), %eax + movl %eax, 0x14(%esp) + /* load current SEH exception list */ + movl (%edx), %eax + movl %eax, 0x18(%esp) + + movl %edi, 0x1c(%esp) /* save EDI */ + movl %esi, 0x20(%esp) /* save ESI */ + movl %ebx, 0x24(%esp) /* save EBX */ + movl %ebp, 0x28(%esp) /* save EBP */ + + /* store ESP (pointing to context-data) in ECX */ + movl %esp, %ecx + + /* first arg of ontop_fcontext() == fcontext to jump to */ + movl 0x30(%esp), %eax + + /* pass parent fcontext_t */ + movl %ecx, 0x30(%eax) + + /* second arg of ontop_fcontext() == data to be transferred */ + movl 0x34(%esp), %ecx + + /* pass data */ + movl %ecx, 0x34(%eax) + + /* third arg of ontop_fcontext() == ontop-function */ + movl 0x38(%esp), %ecx + + /* restore ESP (pointing to context-data) from EDX */ + movl %eax, %esp + +#if !defined(BOOST_USE_TSX) + /* restore MMX control- and status-word */ + ldmxcsr (%esp) + /* restore x87 control-word */ + fldcw 0x4(%esp) +#endif + + /* restore NT_TIB into EDX */ + movl %fs:(0x18), %edx + /* restore fiber local storage */ + movl 0x8(%esp), %eax + movl %eax, 0x10(%edx) + /* restore current deallocation stack */ + movl 0xc(%esp), %eax + movl %eax, 0xe0c(%edx) + /* restore current stack limit */ + movl 0x10(%esp), %eax + movl %eax, 0x08(%edx) + /* restore current stack base */ + movl 0x14(%esp), %eax + movl %eax, 0x04(%edx) + /* restore current SEH exception list */ + movl 0x18(%esp), %eax + movl %eax, (%edx) + + movl 0x1c(%esp), %edi /* restore EDI */ + movl 0x20(%esp), %esi /* restore ESI */ + movl 0x24(%esp), %ebx /* restore EBX */ + movl 0x28(%esp), %ebp /* restore EBP */ + + /* prepare stack */ + leal 0x2c(%esp), %esp + + /* keep return-address on stack */ + + /* jump to context */ + jmp *%ecx + +.section .drectve +.ascii " -export:\"ontop_fcontext\"" diff --git a/third_party/context/src/asm/ontop_i386_ms_pe_masm.asm b/third_party/context/src/asm/ontop_i386_ms_pe_masm.asm new file mode 100644 index 0000000..82246a4 --- /dev/null +++ b/third_party/context/src/asm/ontop_i386_ms_pe_masm.asm @@ -0,0 +1,124 @@ + +; Copyright Oliver Kowalke 2009. +; Distributed under the Boost Software License, Version 1.0. +; (See accompanying file LICENSE_1_0.txt or copy at +; http://www.boost.org/LICENSE_1_0.txt) + +; --------------------------------------------------------------------------------- +; | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | +; --------------------------------------------------------------------------------- +; | 0h | 04h | 08h | 0ch | 010h | 014h | 018h | 01ch | +; --------------------------------------------------------------------------------- +; | fc_mxcsr|fc_x87_cw| fc_strg |fc_deallo| limit | base | fc_seh | EDI | +; --------------------------------------------------------------------------------- +; --------------------------------------------------------------------------------- +; | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | +; --------------------------------------------------------------------------------- +; | 020h | 024h | 028h | 02ch | 030h | 034h | 038h | 03ch | +; --------------------------------------------------------------------------------- +; | ESI | EBX | EBP | EIP | to | data | EH NXT |SEH HNDLR| +; --------------------------------------------------------------------------------- + +.386 +.XMM +.model flat, c +.code + +ontop_fcontext PROC BOOST_CONTEXT_EXPORT + ; prepare stack + lea esp, [esp-02ch] + +IFNDEF BOOST_USE_TSX + ; save MMX control- and status-word + stmxcsr [esp] + ; save x87 control-word + fnstcw [esp+04h] +ENDIF + + assume fs:nothing + ; load NT_TIB into ECX + mov edx, fs:[018h] + assume fs:error + ; load fiber local storage + mov eax, [edx+010h] + mov [esp+08h], eax + ; load current deallocation stack + mov eax, [edx+0e0ch] + mov [esp+0ch], eax + ; load current stack limit + mov eax, [edx+08h] + mov [esp+010h], eax + ; load current stack base + mov eax, [edx+04h] + mov [esp+014h], eax + ; load current SEH exception list + mov eax, [edx] + mov [esp+018h], eax + + mov [esp+01ch], edi ; save EDI + mov [esp+020h], esi ; save ESI + mov [esp+024h], ebx ; save EBX + mov [esp+028h], ebp ; save EBP + + ; store ESP (pointing to context-data) in ECX + mov ecx, esp + + ; first arg of ontop_fcontext() == fcontext to jump to + mov eax, [esp+030h] + + ; pass parent fcontext_t + mov [eax+030h], ecx + + ; second arg of ontop_fcontext() == data to be transferred + mov ecx, [esp+034h] + + ; pass data + mov [eax+034h], ecx + + ; third arg of ontop_fcontext() == ontop-function + mov ecx, [esp+038h] + + ; restore ESP (pointing to context-data) from EAX + mov esp, eax + +IFNDEF BOOST_USE_TSX + ; restore MMX control- and status-word + ldmxcsr [esp] + ; restore x87 control-word + fldcw [esp+04h] +ENDIF + + assume fs:nothing + ; load NT_TIB into EDX + mov edx, fs:[018h] + assume fs:error + ; restore fiber local storage + mov eax, [esp+08h] + mov [edx+010h], eax + ; restore current deallocation stack + mov eax, [esp+0ch] + mov [edx+0e0ch], eax + ; restore current stack limit + mov eax, [esp+010h] + mov [edx+08h], eax + ; restore current stack base + mov eax, [esp+014h] + mov [edx+04h], eax + ; restore current SEH exception list + mov eax, [esp+018h] + mov [edx], eax + + mov edi, [esp+01ch] ; restore EDI + mov esi, [esp+020h] ; restore ESI + mov ebx, [esp+024h] ; restore EBX + mov ebp, [esp+028h] ; restore EBP + + ; prepare stack + lea esp, [esp+02ch] + + ; keep return-address on stack + + ; jump to context + jmp ecx +ontop_fcontext ENDP +END diff --git a/third_party/context/src/asm/ontop_i386_sysv_elf_gas.S b/third_party/context/src/asm/ontop_i386_sysv_elf_gas.S new file mode 100644 index 0000000..0cb6168 --- /dev/null +++ b/third_party/context/src/asm/ontop_i386_sysv_elf_gas.S @@ -0,0 +1,100 @@ +/* + Copyright Oliver Kowalke 2009. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/**************************************************************************************** + * * + * ---------------------------------------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ---------------------------------------------------------------------------------- * + * | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | * + * ---------------------------------------------------------------------------------- * + * | fc_mxcsr|fc_x87_cw| guard | EDI | ESI | EBX | EBP | EIP | * + * ---------------------------------------------------------------------------------- * + * ---------------------------------------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ---------------------------------------------------------------------------------- * + * | 0x20 | 0x24 | 0x28 | | * + * ---------------------------------------------------------------------------------- * + * | hidden | to | data | | * + * ---------------------------------------------------------------------------------- * + * * + ****************************************************************************************/ + +.file "ontop_i386_sysv_elf_gas.S" +.text +.globl ontop_fcontext +.align 2 +.type ontop_fcontext,@function +ontop_fcontext: + leal -0x1c(%esp), %esp /* prepare stack */ + +#if !defined(BOOST_USE_TSX) + stmxcsr (%esp) /* save MMX control- and status-word */ + fnstcw 0x4(%esp) /* save x87 control-word */ +#endif + +#if defined(BOOST_CONTEXT_TLS_STACK_PROTECTOR) + movl %gs:0x14, %ecx /* read stack guard from TLS record */ + movl %ecx, 0x8(%esp) /* save stack guard */ +#endif + + movl %edi, 0xc(%esp) /* save EDI */ + movl %esi, 0x10(%esp) /* save ESI */ + movl %ebx, 0x14(%esp) /* save EBX */ + movl %ebp, 0x18(%esp) /* save EBP */ + + /* store ESP (pointing to context-data) in ECX */ + movl %esp, %ecx + + /* first arg of ontop_fcontext() == fcontext to jump to */ + movl 0x24(%esp), %eax + + /* pass parent fcontext_t */ + movl %ecx, 0x24(%eax) + + /* second arg of ontop_fcontext() == data to be transferred */ + movl 0x28(%esp), %ecx + + /* pass data */ + movl %ecx, 0x28(%eax) + + /* third arg of ontop_fcontext() == ontop-function */ + movl 0x2c(%esp), %ecx + + /* restore ESP (pointing to context-data) from EAX */ + movl %eax, %esp + + /* address of returned transport_t */ + movl 0x20(%esp), %eax + /* return parent fcontext_t */ + movl %ecx, (%eax) + /* return data */ + movl %edx, 0x4(%eax) + +#if !defined(BOOST_USE_TSX) + ldmxcsr (%esp) /* restore MMX control- and status-word */ + fldcw 0x4(%esp) /* restore x87 control-word */ +#endif + +#if defined(BOOST_CONTEXT_TLS_STACK_PROTECTOR) + movl 0x8(%esp), %edx /* load stack guard */ + movl %edx, %gs:0x14 /* restore stack guard to TLS record */ +#endif + + movl 0xc(%esp), %edi /* restore EDI */ + movl 0x10(%esp), %esi /* restore ESI */ + movl 0x14(%esp), %ebx /* restore EBX */ + movl 0x18(%esp), %ebp /* restore EBP */ + + leal 0x1c(%esp), %esp /* prepare stack */ + + /* jump to context */ + jmp *%ecx +.size ontop_fcontext,.-ontop_fcontext + +/* Mark that we don't need executable stack. */ +.section .note.GNU-stack,"",%progbits diff --git a/third_party/context/src/asm/ontop_i386_sysv_macho_gas.S b/third_party/context/src/asm/ontop_i386_sysv_macho_gas.S new file mode 100644 index 0000000..3a88372 --- /dev/null +++ b/third_party/context/src/asm/ontop_i386_sysv_macho_gas.S @@ -0,0 +1,81 @@ +/* + Copyright Oliver Kowalke 2009. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/**************************************************************************************** + * * + * ---------------------------------------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ---------------------------------------------------------------------------------- * + * | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | * + * ---------------------------------------------------------------------------------- * + * | fc_mxcsr|fc_x87_cw| EDI | ESI | EBX | EBP | EIP | to | * + * ---------------------------------------------------------------------------------- * + * ---------------------------------------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ---------------------------------------------------------------------------------- * + * | 0x20 | | * + * ---------------------------------------------------------------------------------- * + * | data | | * + * ---------------------------------------------------------------------------------- * + * * + ****************************************************************************************/ + +.text +.globl _ontop_fcontext +.align 2 +_ontop_fcontext: + leal -0x18(%esp), %esp /* prepare stack */ + +#if !defined(BOOST_USE_TSX) + stmxcsr (%esp) /* save MMX control- and status-word */ + fnstcw 0x4(%esp) /* save x87 control-word */ +#endif + + movl %edi, 0x8(%esp) /* save EDI */ + movl %esi, 0xc(%esp) /* save ESI */ + movl %ebx, 0x10(%esp) /* save EBX */ + movl %ebp, 0x14(%esp) /* save EBP */ + + /* store ESP (pointing to context-data) in ECX */ + movl %esp, %ecx + + /* first arg of ontop_fcontext() == fcontext to jump to */ + movl 0x1c(%esp), %eax + + /* pass parent fcontext_t */ + movl %ecx, 0x1c(%eax) + + /* second arg of ontop_fcontext() == data to be transferred */ + movl 0x20(%esp), %ecx + + /* pass data */ + movl %ecx, 0x20(%eax) + + /* third arg of ontop_fcontext() == ontop-function */ + movl 0x24(%esp), %ecx + + /* restore ESP (pointing to context-data) from EAX */ + movl %eax, %esp + + /* return parent fcontext_t */ + movl %ecx, %eax + /* returned data is stored in EDX */ + +#if !defined(BOOST_USE_TSX) + ldmxcsr (%esp) /* restore MMX control- and status-word */ + fldcw 0x4(%esp) /* restore x87 control-word */ +#endif + + movl 0x8(%esp), %edi /* restore EDI */ + movl 0xc(%esp), %esi /* restore ESI */ + movl 0x10(%esp), %ebx /* restore EBX */ + movl 0x14(%esp), %ebp /* restore EBP */ + + leal 0x18(%esp), %esp /* prepare stack */ + + /* jump to context */ + jmp *%ecx diff --git a/third_party/context/src/asm/ontop_i386_x86_64_sysv_macho_gas.S b/third_party/context/src/asm/ontop_i386_x86_64_sysv_macho_gas.S new file mode 100644 index 0000000..393c5fe --- /dev/null +++ b/third_party/context/src/asm/ontop_i386_x86_64_sysv_macho_gas.S @@ -0,0 +1,16 @@ +/* + Copyright Sergue E. Leontiev 2013. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +// Stub file for universal binary + +#if defined(__i386__) + #include "ontop_i386_sysv_macho_gas.S" +#elif defined(__x86_64__) + #include "ontop_x86_64_sysv_macho_gas.S" +#else + #error "No arch's" +#endif diff --git a/third_party/context/src/asm/ontop_loongarch64_sysv_elf_gas.S b/third_party/context/src/asm/ontop_loongarch64_sysv_elf_gas.S new file mode 100644 index 0000000..c6ea044 --- /dev/null +++ b/third_party/context/src/asm/ontop_loongarch64_sysv_elf_gas.S @@ -0,0 +1,118 @@ +/******************************************************* + * * + * ------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ------------------------------------------------- * + * | 0 | 8 | 16 | 24 | * + * ------------------------------------------------- * + * | FS0 | FS1 | FS2 | FS3 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ------------------------------------------------- * + * | 32 | 40 | 48 | 56 | * + * ------------------------------------------------- * + * | FS4 | FS5 | FS6 | FS7 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * + * ------------------------------------------------- * + * | 64 | 72 | 80 | 88 | * + * ------------------------------------------------- * + * | S0 | S1 | S2 | S3 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * + * ------------------------------------------------- * + * | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | * + * ------------------------------------------------- * + * | S4 | S5 | S6 | S7 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * + * ------------------------------------------------- * + * | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | * + * ------------------------------------------------- * + * | S8 | FP | RA | PC | * + * ------------------------------------------------- * + * * + * *****************************************************/ + +.file "ontop_loongarch64_sysv_elf_gas.S" +.text +.globl ontop_fcontext +.align 2 +.type ontop_fcontext,@function +ontop_fcontext: + # reserve space on stack + addi.d $sp, $sp, -160 + + # save fs0 - fs7 + fst.d $fs0, $sp, 0 + fst.d $fs1, $sp, 8 + fst.d $fs2, $sp, 16 + fst.d $fs3, $sp, 24 + fst.d $fs4, $sp, 32 + fst.d $fs5, $sp, 40 + fst.d $fs6, $sp, 48 + fst.d $fs7, $sp, 56 + + # save s0 - s8, fp, ra + st.d $s0, $sp, 64 + st.d $s1, $sp, 72 + st.d $s2, $sp, 80 + st.d $s3, $sp, 88 + st.d $s4, $sp, 96 + st.d $s5, $sp, 104 + st.d $s6, $sp, 112 + st.d $s7, $sp, 120 + st.d $s8, $sp, 128 + st.d $fp, $sp, 136 + st.d $ra, $sp, 144 + + # save RA as PC + st.d $ra, $sp, 152 + + # store SP (pointing to context-data) in A3 + move $a3, $sp + + # restore SP (pointing to context-data) from A0 + move $sp, $a0 + + # load fs0 - fs11 + fld.d $fs0, $sp, 0 + fld.d $fs1, $sp, 8 + fld.d $fs2, $sp, 16 + fld.d $fs3, $sp, 24 + fld.d $fs4, $sp, 32 + fld.d $fs5, $sp, 40 + fld.d $fs6, $sp, 48 + fld.d $fs7, $sp, 56 + + #load s0 - s11, fp, ra + ld.d $s0, $sp, 64 + ld.d $s1, $sp, 72 + ld.d $s2, $sp, 80 + ld.d $s3, $sp, 88 + ld.d $s4, $sp, 96 + ld.d $s5, $sp, 104 + ld.d $s6, $sp, 112 + ld.d $s7, $sp, 120 + ld.d $s8, $sp, 128 + ld.d $fp, $sp, 136 + ld.d $ra, $sp, 144 + + # return transfer_t from jump + # pass transfer_t as first arg in context function + # a0 == FCTX, a1 == DATA + move $a0, $a3 + + # adjust stack + addi.d $sp, $sp, 160 + + # jump to context + jr $a2 +.size ontop_fcontext, .-ontop_fcontext + +/* Mark that we don't need executable stack. */ +.section .note.GNU-stack,"",%progbits diff --git a/third_party/context/src/asm/ontop_mips32_o32_elf_gas.S b/third_party/context/src/asm/ontop_mips32_o32_elf_gas.S new file mode 100644 index 0000000..c69203c --- /dev/null +++ b/third_party/context/src/asm/ontop_mips32_o32_elf_gas.S @@ -0,0 +1,120 @@ +/* + Copyright Oliver Kowalke 2009. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/******************************************************* + * * + * ------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ------------------------------------------------- * + * | 0 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | * + * ------------------------------------------------- * + * | F20 | F22 | F24 | F26 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ------------------------------------------------- * + * | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | * + * ------------------------------------------------- * + * | F28 | F30 | S0 | S1 | S2 | S3 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * + * ------------------------------------------------- * + * | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | * + * ------------------------------------------------- * + * | S4 | S5 | S6 | S7 | FP |hiddn| RA | PC | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * + * ------------------------------------------------- * + * | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | * + * ------------------------------------------------- * + * | ABI ARGS | GP | FCTX| DATA| | * + * ------------------------------------------------- * + * * + * *****************************************************/ + +.file "ontop_mips32_o32_elf_gas.S" +.text +.globl ontop_fcontext +.align 2 +.type ontop_fcontext,@function +.ent ontop_fcontext +ontop_fcontext: + # reserve space on stack + addiu $sp, $sp, -96 + + sw $s0, 48($sp) # save S0 + sw $s1, 52($sp) # save S1 + sw $s2, 56($sp) # save S2 + sw $s3, 60($sp) # save S3 + sw $s4, 64($sp) # save S4 + sw $s5, 68($sp) # save S5 + sw $s6, 72($sp) # save S6 + sw $s7, 76($sp) # save S7 + sw $fp, 80($sp) # save FP + sw $a0, 84($sp) # save hidden, address of returned transfer_t + sw $ra, 88($sp) # save RA + sw $ra, 92($sp) # save RA as PC + +#if defined(__mips_hard_float) + s.d $f20, ($sp) # save F20 + s.d $f22, 8($sp) # save F22 + s.d $f24, 16($sp) # save F24 + s.d $f26, 24($sp) # save F26 + s.d $f28, 32($sp) # save F28 + s.d $f30, 40($sp) # save F30 +#endif + + # store SP (pointing to context-data) in A0 + move $a0, $sp + + # restore SP (pointing to context-data) from A1 + move $sp, $a1 + +#if defined(__mips_hard_float) + l.d $f20, ($sp) # restore F20 + l.d $f22, 8($sp) # restore F22 + l.d $f24, 16($sp) # restore F24 + l.d $f26, 24($sp) # restore F26 + l.d $f28, 32($sp) # restore F28 + l.d $f30, 40($sp) # restore F30 +#endif + + lw $s0, 48($sp) # restore S0 + lw $s1, 52($sp) # restore S1 + lw $s2, 56($sp) # restore S2 + lw $s3, 60($sp) # restore S3 + lw $s4, 64($sp) # restore S4 + lw $s5, 68($sp) # restore S5 + lw $s6, 72($sp) # restore S6 + lw $s7, 76($sp) # restore S7 + lw $fp, 80($sp) # restore FP + lw $v0, 84($sp) # restore hidden, address of returned transfer_t + lw $ra, 88($sp) # restore RA + + # load PC + move $t9, $a3 + + # adjust stack + addiu $sp, $sp, 96 + + # return transfer_t from jump + sw $a0, ($v0) # fctx of transfer_t + sw $a2, 4($v0) # data of transfer_t + # pass transfer_t as first arg in context function + # A0 == hidden, A1 == fctx, A2 == data + move $a1, $a0 + move $a0, $v0 + + # jump to context + jr $t9 +.end ontop_fcontext +.size ontop_fcontext, .-ontop_fcontext + +/* Mark that we don't need executable stack. */ +.section .note.GNU-stack,"",%progbits diff --git a/third_party/context/src/asm/ontop_mips64_n64_elf_gas.S b/third_party/context/src/asm/ontop_mips64_n64_elf_gas.S new file mode 100644 index 0000000..68087b0 --- /dev/null +++ b/third_party/context/src/asm/ontop_mips64_n64_elf_gas.S @@ -0,0 +1,123 @@ +/* + Copyright Jiaxun Yang 2018. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE +*/ + +/******************************************************* + * * + * ------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ------------------------------------------------- * + * | 0 | 8 | 16 | 24 | * + * ------------------------------------------------- * + * | F24 | F25 | F26 | F27 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ------------------------------------------------- * + * | 32 | 40 | 48 | 56 | * + * ------------------------------------------------- * + * | F28 | F29 | F30 | F31 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * + * ------------------------------------------------- * + * | 64 | 72 | 80 | 88 | * + * ------------------------------------------------- * + * | S0 | S1 | S2 | S3 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * + * ------------------------------------------------- * + * | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | * + * ------------------------------------------------- * + * | S4 | S5 | S6 | S7 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * + * ------------------------------------------------- * + * | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | * + * ------------------------------------------------- * + * | FP | GP | RA | PC | * + * ------------------------------------------------- * + * * + * *****************************************************/ + +.file "ontop_mips64_n64_elf_gas.S" +.text +.globl ontop_fcontext +.align 3 +.type ontop_fcontext,@function +.ent ontop_fcontext +ontop_fcontext: + # reserve space on stack + daddiu $sp, $sp, -160 + + sd $s0, 64($sp) # save S0 + sd $s1, 72($sp) # save S1 + sd $s2, 80($sp) # save S2 + sd $s3, 88($sp) # save S3 + sd $s4, 96($sp) # save S4 + sd $s5, 104($sp) # save S5 + sd $s6, 112($sp) # save S6 + sd $s7, 120($sp) # save S7 + sd $fp, 128($sp) # save FP + sd $ra, 144($sp) # save RA + sd $ra, 152($sp) # save RA as PC + +#if defined(__mips_hard_float) + s.d $f24, 0($sp) # save F24 + s.d $f25, 8($sp) # save F25 + s.d $f26, 16($sp) # save F26 + s.d $f27, 24($sp) # save F27 + s.d $f28, 32($sp) # save F28 + s.d $f29, 40($sp) # save F29 + s.d $f30, 48($sp) # save F30 + s.d $f31, 56($sp) # save F31 +#endif + + # store SP (pointing to context-data) in t0 + move $t0, $sp + + # restore SP (pointing to context-data) from a0 + move $sp, $a0 + +#if defined(__mips_hard_float) + l.d $f24, 0($sp) # restore F24 + l.d $f25, 8($sp) # restore F25 + l.d $f26, 16($sp) # restore F26 + l.d $f27, 24($sp) # restore F27 + l.d $f28, 32($sp) # restore F28 + l.d $f29, 40($sp) # restore F29 + l.d $f30, 48($sp) # restore F30 + l.d $f31, 56($sp) # restore F31 +#endif + + ld $s0, 64($sp) # restore S0 + ld $s1, 72($sp) # restore S1 + ld $s2, 80($sp) # restore S2 + ld $s3, 88($sp) # restore S3 + ld $s4, 96($sp) # restore S4 + ld $s5, 104($sp) # restore S5 + ld $s6, 112($sp) # restore S6 + ld $s7, 120($sp) # restore S7 + ld $fp, 128($sp) # restore FP + ld $ra, 144($sp) # restore RA + + # load PC + move $t9, $a2 + + # adjust stack + daddiu $sp, $sp, 160 + + move $a0, $t0 # move param from t0 to a0 as param + + # jump to context + jr $t9 +.end ontop_fcontext +.size ontop_fcontext, .-ontop_fcontext + +/* Mark that we don't need executable stack. */ +.section .note.GNU-stack,"",%progbits diff --git a/third_party/context/src/asm/ontop_ppc32_ppc64_sysv_macho_gas.S b/third_party/context/src/asm/ontop_ppc32_ppc64_sysv_macho_gas.S new file mode 100644 index 0000000..4632f4c --- /dev/null +++ b/third_party/context/src/asm/ontop_ppc32_ppc64_sysv_macho_gas.S @@ -0,0 +1,16 @@ +/* + Copyright Sergue E. Leontiev 2013. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +// Stub file for universal binary + +#if defined(__ppc__) + #include "ontop_ppc32_sysv_macho_gas.S" +#elif defined(__ppc64__) + #include "ontop_ppc64_sysv_macho_gas.S" +#else + #error "No arch's" +#endif diff --git a/third_party/context/src/asm/ontop_ppc32_sysv_elf_gas.S b/third_party/context/src/asm/ontop_ppc32_sysv_elf_gas.S new file mode 100644 index 0000000..464d99d --- /dev/null +++ b/third_party/context/src/asm/ontop_ppc32_sysv_elf_gas.S @@ -0,0 +1,193 @@ +/* + Copyright Oliver Kowalke 2009. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/******************************************************* + * * + * ------------------------------------------------- * + * | 0 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | * + * ------------------------------------------------- * + * |bchai|hiddn| fpscr | PC | CR | R14 | R15 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | * + * ------------------------------------------------- * + * | R16 | R17 | R18 | R19 | R20 | R21 | R22 | R23 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | * + * ------------------------------------------------- * + * | R24 | R25 | R26 | R27 | R28 | R29 | R30 | R31 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | * + * ------------------------------------------------- * + * | F14 | F15 | F16 | F17 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | * + * ------------------------------------------------- * + * | F18 | F19 | F20 | F21 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 160 | 164 | 168 | 172 | 176 | 180 | 184 | 188 | * + * ------------------------------------------------- * + * | F22 | F23 | F24 | F25 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 192 | 196 | 200 | 204 | 208 | 212 | 216 | 220 | * + * ------------------------------------------------- * + * | F26 | F27 | F28 | F29 | * + * ------------------------------------------------- * + * ------------------------|------------ * + * | 224 | 228 | 232 | 236 | 240 | 244 | * + * ------------------------|------------ * + * | F30 | F31 |bchai| LR | * + * ------------------------|------------ * + * * + *******************************************************/ + +.file "ontop_ppc32_sysv_elf_gas.S" +.text +.globl ontop_fcontext +.align 2 +.type ontop_fcontext,@function +ontop_fcontext: + # Linux: ontop_fcontext( hidden transfer_t * R3, R4, R5, R6) + # Other: transfer_t R3:R4 = jump_fcontext( R3, R4, R5) + + mflr %r0 # return address from LR + mffs %f0 # FPSCR + mfcr %r8 # condition register + + stwu %r1, -240(%r1) # allocate stack space, R1 % 16 == 0 + stw %r0, 244(%r1) # save LR in caller's frame + +#ifdef __linux__ + stw %r3, 4(%r1) # hidden pointer +#endif + + stfd %f0, 8(%r1) # FPSCR + stw %r0, 16(%r1) # LR as PC + stw %r8, 20(%r1) # CR + + # Save registers R14 to R31. + # Don't change R2, the thread-local storage pointer. + # Don't change R13, the small data pointer. + stw %r14, 24(%r1) + stw %r15, 28(%r1) + stw %r16, 32(%r1) + stw %r17, 36(%r1) + stw %r18, 40(%r1) + stw %r19, 44(%r1) + stw %r20, 48(%r1) + stw %r21, 52(%r1) + stw %r22, 56(%r1) + stw %r23, 60(%r1) + stw %r24, 64(%r1) + stw %r25, 68(%r1) + stw %r26, 72(%r1) + stw %r27, 76(%r1) + stw %r28, 80(%r1) + stw %r29, 84(%r1) + stw %r30, 88(%r1) + stw %r31, 92(%r1) + + # Save registers F14 to F31 in slots with 8-byte alignment. + # 4-byte alignment may stall the pipeline of some processors. + # Less than 4 may cause alignment traps. + stfd %f14, 96(%r1) + stfd %f15, 104(%r1) + stfd %f16, 112(%r1) + stfd %f17, 120(%r1) + stfd %f18, 128(%r1) + stfd %f19, 136(%r1) + stfd %f20, 144(%r1) + stfd %f21, 152(%r1) + stfd %f22, 160(%r1) + stfd %f23, 168(%r1) + stfd %f24, 176(%r1) + stfd %f25, 184(%r1) + stfd %f26, 192(%r1) + stfd %f27, 200(%r1) + stfd %f28, 208(%r1) + stfd %f29, 216(%r1) + stfd %f30, 224(%r1) + stfd %f31, 232(%r1) + + # store RSP (pointing to context-data) in R7/R6 + # restore RSP (pointing to context-data) from R4/R3 +#ifdef __linux__ + mr %r7, %r1 + mr %r1, %r4 + lwz %r3, 4(%r1) # hidden pointer +#else + mr %r6, %r1 + mr %r1, %r3 +#endif + + # ignore PC at 16(%r1) + lfd %f0, 8(%r1) # FPSCR + lwz %r8, 20(%r1) # CR + + mtfsf 0xff, %f0 # restore FPSCR + mtcr %r8 # restore CR + + # restore R14 to R31 + lwz %r14, 24(%r1) + lwz %r15, 28(%r1) + lwz %r16, 32(%r1) + lwz %r17, 36(%r1) + lwz %r18, 40(%r1) + lwz %r19, 44(%r1) + lwz %r20, 48(%r1) + lwz %r21, 52(%r1) + lwz %r22, 56(%r1) + lwz %r23, 60(%r1) + lwz %r24, 64(%r1) + lwz %r25, 68(%r1) + lwz %r26, 72(%r1) + lwz %r27, 76(%r1) + lwz %r28, 80(%r1) + lwz %r29, 84(%r1) + lwz %r30, 88(%r1) + lwz %r31, 92(%r1) + + # restore F14 to F31 + lfd %f14, 96(%r1) + lfd %f15, 104(%r1) + lfd %f16, 112(%r1) + lfd %f17, 120(%r1) + lfd %f18, 128(%r1) + lfd %f19, 136(%r1) + lfd %f20, 144(%r1) + lfd %f21, 152(%r1) + lfd %f22, 160(%r1) + lfd %f23, 168(%r1) + lfd %f24, 176(%r1) + lfd %f25, 184(%r1) + lfd %f26, 192(%r1) + lfd %f27, 200(%r1) + lfd %f28, 208(%r1) + lfd %f29, 216(%r1) + lfd %f30, 224(%r1) + lfd %f31, 232(%r1) + + # restore LR from caller's frame + lwz %r0, 244(%r1) + mtlr %r0 + + # adjust stack + addi %r1, %r1, 240 + + # see tail_ppc32_sysv_elf_gas.cpp + # Linux: fcontext_ontop_tail( hidden transfer_t * R3, R4, R5, R6, R7) + # Other: transfer_t R3:R4 = fcontext_ontop_tail( R3, R4, R5, R6) + b ontop_fcontext_tail +.size ontop_fcontext, .-ontop_fcontext + +/* Mark that we don't need executable stack. */ +.section .note.GNU-stack,"",%progbits diff --git a/third_party/context/src/asm/ontop_ppc32_sysv_macho_gas.S b/third_party/context/src/asm/ontop_ppc32_sysv_macho_gas.S new file mode 100644 index 0000000..a746171 --- /dev/null +++ b/third_party/context/src/asm/ontop_ppc32_sysv_macho_gas.S @@ -0,0 +1,201 @@ +/* + Copyright Oliver Kowalke 2009. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/****************************************************** + * * + * ------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ------------------------------------------------- * + * | 0 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | * + * ------------------------------------------------- * + * | F14 | F15 | F16 | F17 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ------------------------------------------------- * + * | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | * + * ------------------------------------------------- * + * | F18 | F19 | F20 | F21 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * + * ------------------------------------------------- * + * | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | * + * ------------------------------------------------- * + * | F22 | F23 | F24 | F25 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * + * ------------------------------------------------- * + * | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | * + * ------------------------------------------------- * + * | F26 | F27 | F28 | F29 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * + * ------------------------------------------------- * + * | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | * + * ------------------------------------------------- * + * | F30 | F31 | fpscr | R13 | R14 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | * + * ------------------------------------------------- * + * | 160 | 164 | 168 | 172 | 176 | 180 | 184 | 188 | * + * ------------------------------------------------- * + * | R15 | R16 | R17 | R18 | R19 | R20 | R21 | R22 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | * + * ------------------------------------------------- * + * | 192 | 196 | 200 | 204 | 208 | 212 | 216 | 220 | * + * ------------------------------------------------- * + * | R23 | R24 | R25 | R26 | R27 | R28 | R29 | R30 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | * + * ------------------------------------------------- * + * | 224 | 228 | 232 | 236 | 240 | 244 | 248 | 252 | * + * ------------------------------------------------- * + * | R31 |hiddn| CR | LR | PC |bchai|linkr| FCTX| * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 64 | | * + * ------------------------------------------------- * + * | 256 | | * + * ------------------------------------------------- * + * | DATA| | * + * ------------------------------------------------- * + * * + *******************************************************/ + +.text +.globl _ontop_fcontext +.align 2 +_ontop_fcontext: + ; reserve space on stack + subi r1, r1, 244 + + stfd f14, 0(r1) ; save F14 + stfd f15, 8(r1) ; save F15 + stfd f16, 16(r1) ; save F16 + stfd f17, 24(r1) ; save F17 + stfd f18, 32(r1) ; save F18 + stfd f19, 40(r1) ; save F19 + stfd f20, 48(r1) ; save F20 + stfd f21, 56(r1) ; save F21 + stfd f22, 64(r1) ; save F22 + stfd f23, 72(r1) ; save F23 + stfd f24, 80(r1) ; save F24 + stfd f25, 88(r1) ; save F25 + stfd f26, 96(r1) ; save F26 + stfd f27, 104(r1) ; save F27 + stfd f28, 112(r1) ; save F28 + stfd f29, 120(r1) ; save F29 + stfd f30, 128(r1) ; save F30 + stfd f31, 136(r1) ; save F31 + mffs f0 ; load FPSCR + stfd f0, 144(r1) ; save FPSCR + + stw r13, 152(r1) ; save R13 + stw r14, 156(r1) ; save R14 + stw r15, 160(r1) ; save R15 + stw r16, 164(r1) ; save R16 + stw r17, 168(r1) ; save R17 + stw r18, 172(r1) ; save R18 + stw r19, 176(r1) ; save R19 + stw r20, 180(r1) ; save R20 + stw r21, 184(r1) ; save R21 + stw r22, 188(r1) ; save R22 + stw r23, 192(r1) ; save R23 + stw r24, 196(r1) ; save R24 + stw r25, 200(r1) ; save R25 + stw r26, 204(r1) ; save R26 + stw r27, 208(r1) ; save R27 + stw r28, 212(r1) ; save R28 + stw r29, 216(r1) ; save R29 + stw r30, 220(r1) ; save R30 + stw r31, 224(r1) ; save R31 + stw r3, 228(r1) ; save hidden + + ; save CR + mfcr r0 + stw r0, 232(r1) + ; save LR + mflr r0 + stw r0, 236(r1) + ; save LR as PC + stw r0, 240(r1) + + ; store RSP (pointing to context-data) in R7 + mr r7, r1 + + ; restore RSP (pointing to context-data) from R4 + mr r1, r4 + + lfd f14, 0(r1) ; restore F14 + lfd f15, 8(r1) ; restore F15 + lfd f16, 16(r1) ; restore F16 + lfd f17, 24(r1) ; restore F17 + lfd f18, 32(r1) ; restore F18 + lfd f19, 40(r1) ; restore F19 + lfd f20, 48(r1) ; restore F20 + lfd f21, 56(r1) ; restore F21 + lfd f22, 64(r1) ; restore F22 + lfd f23, 72(r1) ; restore F23 + lfd f24, 80(r1) ; restore F24 + lfd f25, 88(r1) ; restore F25 + lfd f26, 96(r1) ; restore F26 + lfd f27, 104(r1) ; restore F27 + lfd f28, 112(r1) ; restore F28 + lfd f29, 120(r1) ; restore F29 + lfd f30, 128(r1) ; restore F30 + lfd f31, 136(r1) ; restore F31 + lfd f0, 144(r1) ; load FPSCR + mtfsf 0xff, f0 ; restore FPSCR + + lwz r13, 152(r1) ; restore R13 + lwz r14, 156(r1) ; restore R14 + lwz r15, 160(r1) ; restore R15 + lwz r16, 164(r1) ; restore R16 + lwz r17, 168(r1) ; restore R17 + lwz r18, 172(r1) ; restore R18 + lwz r19, 176(r1) ; restore R19 + lwz r20, 180(r1) ; restore R20 + lwz r21, 184(r1) ; restore R21 + lwz r22, 188(r1) ; restore R22 + lwz r23, 192(r1) ; restore R23 + lwz r24, 196(r1) ; restore R24 + lwz r25, 200(r1) ; restore R25 + lwz r26, 204(r1) ; restore R26 + lwz r27, 208(r1) ; restore R27 + lwz r28, 212(r1) ; restore R28 + lwz r29, 216(r1) ; restore R29 + lwz r30, 220(r1) ; restore R30 + lwz r31, 224(r1) ; restore R31 + lwz r3, 228(r1) ; restore hidden + + ; restore CR + lwz r0, 232(r1) + mtcr r0 + ; restore LR + lwz r0, 236(r1) + mtlr r0 + ; ignore PC + + ; adjust stack + addi r1, r1, 244 + + ; Need to pass ontop_fcontext_tail( + ; hidden R3, + ; R4 = ignore, + ; R5 = data, + ; R6 = ontop-function, + ; R7 = fcontext_t + ; ) + ; All of these registers are correctly set at this point + b _ontop_fcontext_tail diff --git a/third_party/context/src/asm/ontop_ppc32_sysv_xcoff_gas.S b/third_party/context/src/asm/ontop_ppc32_sysv_xcoff_gas.S new file mode 100644 index 0000000..9dfb492 --- /dev/null +++ b/third_party/context/src/asm/ontop_ppc32_sysv_xcoff_gas.S @@ -0,0 +1,230 @@ +/* + Copyright Oliver Kowalke 2009. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/******************************************************* + * * + * ------------------------------------------------- * + * | 0 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | * + * ------------------------------------------------- * + * |bchai| CR | LR |compl| link| TOC | R14 | R15 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | * + * ------------------------------------------------- * + * | R16 | R17 | R18 | R19 | R20 | R21 | R22 | R23 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | * + * ------------------------------------------------- * + * | R24 | R25 | R26 | R27 | R28 | R29 | R30 | R31 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | * + * ------------------------------------------------- * + * | F14 | F15 | F16 | F17 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | * + * ------------------------------------------------- * + * | F18 | F19 | F20 | F21 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 160 | 164 | 168 | 172 | 176 | 180 | 184 | 188 | * + * ------------------------------------------------- * + * | F22 | F23 | F24 | F25 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 192 | 196 | 200 | 204 | 208 | 212 | 216 | 220 | * + * ------------------------------------------------- * + * | F26 | F27 | F28 | F29 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 224 | 228 | 232 | 236 | 240 | 244 | 248 | 252 | * + * ------------------------------------------------- * + * | F30 | F31 | PC |hiddn| fpscr | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 256 | 260 | 264 | 268 | 272 | 276 | 280 | 284 | * + * ------------------------------------------------- * + * |bchai|savLR|savLR|compl| link|svTOC| FCTX| DATA| * + * ------------------------------------------------- * + * * + *******************************************************/ + + .file "ontop_ppc32_sysv_xcoff_xas.S" + .toc + .csect .text[PR] + .align 2 + .globl ontop_fcontext[DS] + .globl .ontop_fcontext + .csect ontop_fcontext[DS] +ontop_fcontext: + .long .ontop_fcontext[PR], TOC[tc0], 0 + .csect .text[PR], 5 +.ontop_fcontext: + # reserve space on stack + subi 1, 1, 256 + + # save CR + mfcr 0 + stw 0, 4(1) + # save LR + mflr 0 + stw 0, 8(1) + # save LR as PC + stw 0, 240(1) + # save TOC + stw 2, 20(1) + + # Save registers R14 to R31. + stw 14, 24(1) + stw 15, 28(1) + stw 16, 32(1) + stw 17, 36(1) + stw 18, 40(1) + stw 19, 44(1) + stw 20, 48(1) + stw 21, 52(1) + stw 22, 56(1) + stw 23, 60(1) + stw 24, 64(1) + stw 25, 68(1) + stw 26, 72(1) + stw 27, 76(1) + stw 28, 80(1) + stw 29, 84(1) + stw 30, 88(1) + stw 31, 92(1) + + # Save registers F14 to F31 in slots with 8-byte alignment. + # 4-byte alignment may stall the pipeline of some processors. + # Less than 4 may cause alignment traps. + stfd 14, 96(1) + stfd 15, 104(1) + stfd 16, 112(1) + stfd 17, 120(1) + stfd 18, 128(1) + stfd 19, 136(1) + stfd 20, 144(1) + stfd 21, 152(1) + stfd 22, 160(1) + stfd 23, 168(1) + stfd 24, 176(1) + stfd 25, 184(1) + stfd 26, 192(1) + stfd 27, 200(1) + stfd 28, 208(1) + stfd 29, 216(1) + stfd 30, 224(1) + stfd 31, 232(1) + + # hidden pointer + stw 3, 244(1) + + mffs 0 # load FPSCR + stfd 0, 248(1) # save FPSCR + + # store RSP (pointing to context-data) in R7 + mr 7, 1 + + # restore RSP (pointing to context-data) from R4 + mr 1, 4 + + # restore CR + lwz 0, 4(1) + mtcr 0 + + # restore R14 to R31 + lwz 14, 24(1) + lwz 15, 28(1) + lwz 16, 32(1) + lwz 17, 36(1) + lwz 18, 40(1) + lwz 19, 44(1) + lwz 20, 48(1) + lwz 21, 52(1) + lwz 22, 56(1) + lwz 23, 60(1) + lwz 24, 64(1) + lwz 25, 68(1) + lwz 26, 72(1) + lwz 27, 76(1) + lwz 28, 80(1) + lwz 29, 84(1) + lwz 30, 88(1) + lwz 31, 92(1) + + # restore F14 to F31 + lfd 14, 96(1) + lfd 15, 104(1) + lfd 16, 112(1) + lfd 17, 120(1) + lfd 18, 128(1) + lfd 19, 136(1) + lfd 20, 144(1) + lfd 21, 152(1) + lfd 22, 160(1) + lfd 23, 168(1) + lfd 24, 176(1) + lfd 25, 184(1) + lfd 26, 192(1) + lfd 27, 200(1) + lfd 28, 208(1) + lfd 29, 216(1) + lfd 30, 224(1) + lfd 31, 232(1) + + lwz 3, 244(1) # restore hidden + + lfd 0, 248(1) # load FPSCR + mtfsf 0xff, 0 # restore FPSCR + + # copy transfer_t into ontop_fn arg registers + mr 4, 7 + # arg pointer already in r5 + # hidden arg already in r3 + + # restore CTR + lwz 7, 0(6) + mtctr 7 + # restore TOC + lwz 2, 4(6) + + # zero in r3 indicates first jump to context-function + cmpdi 3, 0 + beq use_entry_arg + +return_to_ctx: + # restore LR + lwz 0, 8(1) + mtlr 0 + + # adjust stack + addi 1, 1, 256 + + # jump to context + bctr + +use_entry_arg: + # compute return-value struct address + # (passed has hidden arg to ontop_fn) + addi 3, 1, 8 + + # jump to context and update LR + bctrl + + # restore CTR + lwz 7, 4(1) + mtctr 7 + # restore TOC + lwz 2, 20(1) + + # copy returned transfer_t into entry_fn arg registers + lwz 3, 8(1) + lwz 4, 12(1) + + b return_to_ctx diff --git a/third_party/context/src/asm/ontop_ppc64_sysv_elf_gas.S b/third_party/context/src/asm/ontop_ppc64_sysv_elf_gas.S new file mode 100644 index 0000000..cd97f45 --- /dev/null +++ b/third_party/context/src/asm/ontop_ppc64_sysv_elf_gas.S @@ -0,0 +1,244 @@ +/* + Copyright Oliver Kowalke 2009. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/******************************************************* + * * + * ------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ------------------------------------------------- * + * | 0 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | * + * ------------------------------------------------- * + * | TOC | R14 | R15 | R16 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ------------------------------------------------- * + * | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | * + * ------------------------------------------------- * + * | R17 | R18 | R19 | R20 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * + * ------------------------------------------------- * + * | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | * + * ------------------------------------------------- * + * | R21 | R22 | R23 | R24 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * + * ------------------------------------------------- * + * | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | * + * ------------------------------------------------- * + * | R25 | R26 | R27 | R28 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * + * ------------------------------------------------- * + * | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | * + * ------------------------------------------------- * + * | R29 | R30 | R31 | hidden | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | * + * ------------------------------------------------- * + * | 160 | 164 | 168 | 172 | 176 | 180 | 184 | 188 | * + * ------------------------------------------------- * + * | CR | LR | PC | back-chain| * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | * + * ------------------------------------------------- * + * | 192 | 196 | 200 | 204 | 208 | 212 | 216 | 220 | * + * ------------------------------------------------- * + * | cr saved | lr saved | compiler | linker | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | * + * ------------------------------------------------- * + * | 224 | 228 | 232 | 236 | 240 | 244 | 248 | 252 | * + * ------------------------------------------------- * + * | TOC saved | FCTX | DATA | | * + * ------------------------------------------------- * + * * + *******************************************************/ + +.file "ontop_ppc64_sysv_elf_gas.S" +.globl ontop_fcontext +#if _CALL_ELF == 2 + .text + .align 2 +ontop_fcontext: + addis %r2, %r12, .TOC.-ontop_fcontext@ha + addi %r2, %r2, .TOC.-ontop_fcontext@l + .localentry ontop_fcontext, . - ontop_fcontext +#else + .section ".opd","aw" + .align 3 +ontop_fcontext: +# ifdef _CALL_LINUX + .quad .L.ontop_fcontext,.TOC.@tocbase,0 + .type ontop_fcontext,@function + .text + .align 2 +.L.ontop_fcontext: +# else + .hidden .ontop_fcontext + .globl .ontop_fcontext + .quad .ontop_fcontext,.TOC.@tocbase,0 + .size ontop_fcontext,24 + .type .ontop_fcontext,@function + .text + .align 2 +.ontop_fcontext: +# endif +#endif + # reserve space on stack + subi %r1, %r1, 184 + +#if _CALL_ELF != 2 + std %r2, 0(%r1) # save TOC +#endif + std %r14, 8(%r1) # save R14 + std %r15, 16(%r1) # save R15 + std %r16, 24(%r1) # save R16 + std %r17, 32(%r1) # save R17 + std %r18, 40(%r1) # save R18 + std %r19, 48(%r1) # save R19 + std %r20, 56(%r1) # save R20 + std %r21, 64(%r1) # save R21 + std %r22, 72(%r1) # save R22 + std %r23, 80(%r1) # save R23 + std %r24, 88(%r1) # save R24 + std %r25, 96(%r1) # save R25 + std %r26, 104(%r1) # save R26 + std %r27, 112(%r1) # save R27 + std %r28, 120(%r1) # save R28 + std %r29, 128(%r1) # save R29 + std %r30, 136(%r1) # save R30 + std %r31, 144(%r1) # save R31 +#if _CALL_ELF != 2 + std %r3, 152(%r1) # save hidden +#endif + + # save CR + mfcr %r0 + std %r0, 160(%r1) + # save LR + mflr %r0 + std %r0, 168(%r1) + # save LR as PC + std %r0, 176(%r1) + + # store RSP (pointing to context-data) in R7 + mr %r7, %r1 + +#if _CALL_ELF == 2 + # restore RSP (pointing to context-data) from R3 + mr %r1, %r3 +#else + # restore RSP (pointing to context-data) from R4 + mr %r1, %r4 +#endif + + ld %r14, 8(%r1) # restore R14 + ld %r15, 16(%r1) # restore R15 + ld %r16, 24(%r1) # restore R16 + ld %r17, 32(%r1) # restore R17 + ld %r18, 40(%r1) # restore R18 + ld %r19, 48(%r1) # restore R19 + ld %r20, 56(%r1) # restore R20 + ld %r21, 64(%r1) # restore R21 + ld %r22, 72(%r1) # restore R22 + ld %r23, 80(%r1) # restore R23 + ld %r24, 88(%r1) # restore R24 + ld %r25, 96(%r1) # restore R25 + ld %r26, 104(%r1) # restore R26 + ld %r27, 112(%r1) # restore R27 + ld %r28, 120(%r1) # restore R28 + ld %r29, 128(%r1) # restore R29 + ld %r30, 136(%r1) # restore R30 + ld %r31, 144(%r1) # restore R31 +#if _CALL_ELF != 2 + ld %r3, 152(%r1) # restore hidden +#endif + + # restore CR + ld %r0, 160(%r1) + mtcr %r0 + +#if _CALL_ELF == 2 + # restore CTR + mtctr %r5 + + # store cb entrypoint in %r12, used for TOC calculation + mr %r12, %r5 + + # copy transfer_t into ontop_fn arg registers + mr %r3, %r7 + # arg pointer already in %r4 +#else + # copy transfer_t into ontop_fn arg registers + mr %r4, %r7 + # arg pointer already in %r5 + # hidden arg already in %r3 + + # restore CTR + ld %r7, 0(%r6) + mtctr %r7 + # restore TOC + ld %r2, 8(%r6) + + # zero in r3 indicates first jump to context-function + cmpdi %r3, 0 + beq use_entry_arg +#endif + +return_to_ctx: + # restore LR + ld %r0, 168(%r1) + mtlr %r0 + + # adjust stack + addi %r1, %r1, 184 + + # jump to context + bctr + +#if _CALL_ELF == 2 + .size ontop_fcontext, .-ontop_fcontext +#else +use_entry_arg: + # compute return-value struct address + # (passed has hidden arg to ontop_fn) + addi %r3, %r1, 8 + + # jump to context and update LR + bctrl + + # restore CTR + ld %r7, 176(%r1) + mtctr %r7 +#if _CALL_ELF != 2 + # restore TOC + ld %r2, 0(%r1) +#endif + + # copy returned transfer_t into entry_fn arg registers + ld %r3, 8(%r1) + ld %r4, 16(%r1) + + b return_to_ctx +# ifdef _CALL_LINUX + .size .ontop_fcontext, .-.L.ontop_fcontext +# else + .size .ontop_fcontext, .-.ontop_fcontext +# endif +#endif + + +/* Mark that we don't need executable stack. */ +.section .note.GNU-stack,"",%progbits diff --git a/third_party/context/src/asm/ontop_ppc64_sysv_macho_gas.S b/third_party/context/src/asm/ontop_ppc64_sysv_macho_gas.S new file mode 100644 index 0000000..a9fe8cf --- /dev/null +++ b/third_party/context/src/asm/ontop_ppc64_sysv_macho_gas.S @@ -0,0 +1,151 @@ +/* + Copyright Oliver Kowalke 2009. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/******************************************************* + * * + * ------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ------------------------------------------------- * + * | 0 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | * + * ------------------------------------------------- * + * | R13 | R14 | R15 | R16 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ------------------------------------------------- * + * | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | * + * ------------------------------------------------- * + * | R17 | R18 | R19 | R20 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * + * ------------------------------------------------- * + * | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | * + * ------------------------------------------------- * + * | R21 | R22 | R23 | R24 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * + * ------------------------------------------------- * + * | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | * + * ------------------------------------------------- * + * | R25 | R26 | R27 | R28 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * + * ------------------------------------------------- * + * | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | * + * ------------------------------------------------- * + * | R29 | R30 | R31 | hidden | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | * + * ------------------------------------------------- * + * | 160 | 164 | 168 | 172 | 176 | 180 | 184 | 188 | * + * ------------------------------------------------- * + * | CR | LR | PC | back-chain| * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | * + * ------------------------------------------------- * + * | 192 | 196 | 200 | 204 | 208 | 212 | 216 | 220 | * + * ------------------------------------------------- * + * | cr saved | lr saved | compiler | linker | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | * + * ------------------------------------------------- * + * | 224 | 228 | 232 | 236 | 240 | 244 | 248 | 252 | * + * ------------------------------------------------- * + * | FCTX | DATA | | | * + * ------------------------------------------------- * + * * + *******************************************************/ + +.text +.align 2 +.globl _ontop_fcontext + +_ontop_fcontext: + ; reserve space on stack + subi r1, r1, 184 + + std r14, 8(r1) ; save R14 + std r15, 16(r1) ; save R15 + std r16, 24(r1) ; save R16 + std r17, 32(r1) ; save R17 + std r18, 40(r1) ; save R18 + std r19, 48(r1) ; save R19 + std r20, 56(r1) ; save R20 + std r21, 64(r1) ; save R21 + std r22, 72(r1) ; save R22 + std r23, 80(r1) ; save R23 + std r24, 88(r1) ; save R24 + std r25, 96(r1) ; save R25 + std r26, 104(r1) ; save R26 + std r27, 112(r1) ; save R27 + std r28, 120(r1) ; save R28 + std r29, 128(r1) ; save R29 + std r30, 136(r1) ; save R30 + std r31, 144(r1) ; save R31 + std r3, 152(r1) ; save hidden + + ; save CR + mfcr r0 + std r0, 160(r1) + ; save LR + mflr r0 + std r0, 168(r1) + ; save LR as PC + std r0, 176(r1) + + ; store RSP (pointing to context-data) in R7 + mr r7, r1 + + ; restore RSP (pointing to context-data) from R4 + mr r1, r4 + + ld r14, 8(r1) ; restore R14 + ld r15, 16(r1) ; restore R15 + ld r16, 24(r1) ; restore R16 + ld r17, 32(r1) ; restore R17 + ld r18, 40(r1) ; restore R18 + ld r19, 48(r1) ; restore R19 + ld r20, 56(r1) ; restore R20 + ld r21, 64(r1) ; restore R21 + ld r22, 72(r1) ; restore R22 + ld r23, 80(r1) ; restore R23 + ld r24, 88(r1) ; restore R24 + ld r25, 96(r1) ; restore R25 + ld r26, 104(r1) ; restore R26 + ld r27, 112(r1) ; restore R27 + ld r28, 120(r1) ; restore R28 + ld r29, 128(r1) ; restore R29 + ld r30, 136(r1) ; restore R30 + ld r31, 144(r1) ; restore R31 + ld r4, 152(r1) ; restore hidden + + ; restore CR + ld r0, 160(r1) + mtcr r0 + ; restore LR + ld r0, 168(r1) + mtlr r0 + ; ignore PC + + ; adjust stack + addi r1, r1, 184 + + ; return transfer_t + std r7, 0(r4) + std r5, 8(r4) + + ; restore CTR + mtctr r6 + + ; jump to context + bctr diff --git a/third_party/context/src/asm/ontop_ppc64_sysv_xcoff_gas.S b/third_party/context/src/asm/ontop_ppc64_sysv_xcoff_gas.S new file mode 100644 index 0000000..546b1b2 --- /dev/null +++ b/third_party/context/src/asm/ontop_ppc64_sysv_xcoff_gas.S @@ -0,0 +1,187 @@ +/* + Copyright Oliver Kowalke 2009. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/******************************************************* + * * + * ------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ------------------------------------------------- * + * | 0 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | * + * ------------------------------------------------- * + * | TOC | R14 | R15 | R16 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ------------------------------------------------- * + * | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | * + * ------------------------------------------------- * + * | R17 | R18 | R19 | R20 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * + * ------------------------------------------------- * + * | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | * + * ------------------------------------------------- * + * | R21 | R22 | R23 | R24 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * + * ------------------------------------------------- * + * | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | * + * ------------------------------------------------- * + * | R25 | R26 | R27 | R28 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * + * ------------------------------------------------- * + * | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | * + * ------------------------------------------------- * + * | R29 | R30 | R31 | hidden | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | * + * ------------------------------------------------- * + * | 160 | 164 | 168 | 172 | 176 | 180 | 184 | 188 | * + * ------------------------------------------------- * + * | CR | LR | PC | back-chain| * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | * + * ------------------------------------------------- * + * | 192 | 196 | 200 | 204 | 208 | 212 | 216 | 220 | * + * ------------------------------------------------- * + * | cr saved | lr saved | compiler | linker | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | * + * ------------------------------------------------- * + * | 224 | 228 | 232 | 236 | 240 | 244 | 248 | 252 | * + * ------------------------------------------------- * + * | TOC saved | FCTX | DATA | | * + * ------------------------------------------------- * + * * + *******************************************************/ + + .file "ontop_ppc64_sysv_xcoff_gas.S" + .toc + .csect .text[PR], 5 + .align 2 + .globl ontop_fcontext[DS] + .globl .ontop_fcontext + .csect ontop_fcontext[DS], 3 +ontop_fcontext: + .llong .ontop_fcontext[PR], TOC[tc0], 0 + .csect .text[PR], 5 +.ontop_fcontext: + # reserve space on stack + subi 1, 1, 184 + + std 2, 0(1) # save TOC + std 14, 8(1) # save R14 + std 15, 16(1) # save R15 + std 16, 24(1) # save R16 + std 17, 32(1) # save R17 + std 18, 40(1) # save R18 + std 19, 48(1) # save R19 + std 20, 56(1) # save R20 + std 21, 64(1) # save R21 + std 22, 72(1) # save R22 + std 23, 80(1) # save R23 + std 24, 88(1) # save R24 + std 25, 96(1) # save R25 + std 26, 104(1) # save R26 + std 27, 112(1) # save R27 + std 28, 120(1) # save R28 + std 29, 128(1) # save R29 + std 30, 136(1) # save R30 + std 31, 144(1) # save R31 + std 3, 152(1) # save hidden + + # save CR + mfcr 0 + std 0, 160(1) + # save LR + mflr 0 + std 0, 168(1) + # save LR as PC + std 0, 176(1) + + # store RSP (pointing to context-data) in R7 + mr 7, 1 + + # restore RSP (pointing to context-data) from R4 + mr 1, 4 + + ld 14, 8(1) # restore R14 + ld 15, 16(1) # restore R15 + ld 16, 24(1) # restore R16 + ld 17, 32(1) # restore R17 + ld 18, 40(1) # restore R18 + ld 19, 48(1) # restore R19 + ld 20, 56(1) # restore R20 + ld 21, 64(1) # restore R21 + ld 22, 72(1) # restore R22 + ld 23, 80(1) # restore R23 + ld 24, 88(1) # restore R24 + ld 25, 96(1) # restore R25 + ld 26, 104(1) # restore R26 + ld 27, 112(1) # restore R27 + ld 28, 120(1) # restore R28 + ld 29, 128(1) # restore R29 + ld 30, 136(1) # restore R30 + ld 31, 144(1) # restore R31 + ld 3, 152(1) # restore hidden + + # restore CR + ld 0, 160(1) + mtcr 0 + + # copy transfer_t into ontop_fn arg registers + mr 4, 7 + # arg pointer already in r5 + # hidden arg already in r3 + + # restore CTR + ld 7, 0(6) + mtctr 7 + # restore TOC + ld 2, 8(6) + + # zero in r3 indicates first jump to context-function + cmpdi 3, 0 + beq use_entry_arg + +return_to_ctx: + # restore LR + ld 0, 168(1) + mtlr 0 + + # adjust stack + addi 1, 1, 184 + + # jump to context + bctr + +use_entry_arg: + # compute return-value struct address + # (passed has hidden arg to ontop_fn) + addi 3, 1, 8 + + # jump to context and update LR + bctrl + + # restore CTR + ld 7, 176(1) + mtctr 7 + # restore TOC + ld 2, 0(1) + + # copy returned transfer_t into entry_fn arg registers + ld 3, 8(1) + ld 4, 16(1) + + b return_to_ctx diff --git a/third_party/context/src/asm/ontop_riscv64_sysv_elf_gas.S b/third_party/context/src/asm/ontop_riscv64_sysv_elf_gas.S new file mode 100644 index 0000000..61ab46b --- /dev/null +++ b/third_party/context/src/asm/ontop_riscv64_sysv_elf_gas.S @@ -0,0 +1,149 @@ +/* + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ +/******************************************************* + * * + * ------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ------------------------------------------------- * + * | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| * + * ------------------------------------------------- * + * | fs0 | fs1 | fs2 | fs3 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ------------------------------------------------- * + * | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| * + * ------------------------------------------------- * + * | fs4 | fs5 | fs6 | fs7 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * + * ------------------------------------------------- * + * | 0x40| 0x44| 0x48| 0x4c| 0x50| 0x54| 0x58| 0x5c| * + * ------------------------------------------------- * + * | fs8 | fs9 | fs10 | fs11 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * + * ------------------------------------------------- * + * | 0x60| 0x64| 0x68| 0x6c| 0x70| 0x74| 0x78| 0x7c| * + * ------------------------------------------------- * + * | s0 | s1 | s2 | s3 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * + * ------------------------------------------------- * + * | 0x80| 0x84| 0x88| 0x8c| 0x90| 0x94| 0x98| 0x9c| * + * ------------------------------------------------- * + * | s4 | s5 | s6 | s7 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | * + * ------------------------------------------------- * + * | 0xa0| 0xa4| 0xa8| 0xac| 0xb0| 0xb4| 0xb8| 0xbc| * + * ------------------------------------------------- * + * | s8 | s9 | s10 | s11 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 48 | 49 | 50 | 51 | | | | | * + * ------------------------------------------------- * + * | 0xc0| 0xc4| 0xc8| 0xcc| | | | | * + * ------------------------------------------------- * + * | ra | pc | | | * + * ------------------------------------------------- * + * * + *******************************************************/ + +.file "ontop_riscv64_sysv_elf_gas.S" +.text +.align 1 +.global ontop_fcontext +.type ontop_fcontext, %function +ontop_fcontext: + # prepare stack for GP + FPU + addi sp, sp, -0xd0 + + # save fs0 - fs11 + fsd fs0, 0x00(sp) + fsd fs1, 0x08(sp) + fsd fs2, 0x10(sp) + fsd fs3, 0x18(sp) + fsd fs4, 0x20(sp) + fsd fs5, 0x28(sp) + fsd fs6, 0x30(sp) + fsd fs7, 0x38(sp) + fsd fs8, 0x40(sp) + fsd fs9, 0x48(sp) + fsd fs10, 0x50(sp) + fsd fs11, 0x58(sp) + + # save s0-s11, ra + sd s0, 0x60(sp) + sd s1, 0x68(sp) + sd s2, 0x70(sp) + sd s3, 0x78(sp) + sd s4, 0x80(sp) + sd s5, 0x88(sp) + sd s6, 0x90(sp) + sd s7, 0x98(sp) + sd s8, 0xa0(sp) + sd s9, 0xa8(sp) + sd s10, 0xb0(sp) + sd s11, 0xb8(sp) + sd ra, 0xc0(sp) + + # save RA as PC + sd ra, 0xc8(sp) + + # store SP (pointing to context-data) in A3 + mv a3, sp + + # restore SP (pointing to context-data) from A0 + mv sp, a0 + + # load fs0 - fs11 + fld fs0, 0x00(sp) + fld fs1, 0x08(sp) + fld fs2, 0x10(sp) + fld fs3, 0x18(sp) + fld fs4, 0x20(sp) + fld fs5, 0x28(sp) + fld fs6, 0x30(sp) + fld fs7, 0x38(sp) + fld fs8, 0x40(sp) + fld fs9, 0x48(sp) + fld fs10, 0x50(sp) + fld fs11, 0x58(sp) + + # load s0-s11,ra + ld s0, 0x60(sp) + ld s1, 0x68(sp) + ld s2, 0x70(sp) + ld s3, 0x78(sp) + ld s4, 0x80(sp) + ld s5, 0x88(sp) + ld s6, 0x90(sp) + ld s7, 0x98(sp) + ld s8, 0xa0(sp) + ld s9, 0xa8(sp) + ld s10, 0xb0(sp) + ld s11, 0xb8(sp) + ld ra, 0xc0(sp) + + # return transfer_t from jump + # pass transfer_t as first arg in context function + # a0 == FCTX, a1 == DATA + mv a0, a3 + + # skip pc + # restore stack from GP + FPU + addi sp, sp, 0xd0 + + # jump to ontop-function + jr a2 +.size ontop_fcontext,.-ontop_fcontext +# Mark that we don't need executable stack. +.section .note.GNU-stack,"",%progbits diff --git a/third_party/context/src/asm/ontop_s390x_sysv_elf_gas.S b/third_party/context/src/asm/ontop_s390x_sysv_elf_gas.S new file mode 100644 index 0000000..709b3d6 --- /dev/null +++ b/third_party/context/src/asm/ontop_s390x_sysv_elf_gas.S @@ -0,0 +1,146 @@ +/******************************************************* + * ------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ------------------------------------------------- * + * | 0 | 8 | 16 | 24 | * + * ------------------------------------------------- * + * | t.fctx | t.data | r2 | r6 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ------------------------------------------------- * + * | 32 | 40 | 48 | 56 | * + * ------------------------------------------------- * + * | r7 | r8 | r9 | r10 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * + * ------------------------------------------------- * + * | 64 | 72 | 80 | 88 | * + * ------------------------------------------------- * + * | r11 | r12 | r13 | r14 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * + * ------------------------------------------------- * + * | 96 | 104 | 112 | 120 | * + * ------------------------------------------------- * + * | f8 | f9 | f10 | f11 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * + * ------------------------------------------------- * + * | 128 | 136 | 144 | 152 | * + * ------------------------------------------------- * + * | f12 | f13 | f14 | f15 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | * + * ------------------------------------------------- * + * | 160 | 168 | 176 | | * + * ------------------------------------------------- * + * | fpc | pc | | | * + * ------------------------------------------------- * + *******************************************************/ + +.text +.align 8 +.global ontop_fcontext +.type ontop_fcontext, @function + +#define ARG_OFFSET 0 +#define GR_OFFSET 16 +#define R14_OFFSET 88 +#define FP_OFFSET 96 +#define FPC_OFFSET 160 +#define PC_OFFSET 168 +#define CONTEXT_SIZE 176 + + +/* + +typedef void* fcontext_t; + +struct transfer_t { + fcontext_t fctx; + void * data; +}; + +transfer_t ontop_fcontext( fcontext_t const to, + void * vp, + transfer_t (* fn)( transfer_t) ); + +Incoming args +r2 - Hidden argument to the location where the return transfer_t needs to be returned +r3 - Target context +r4 - Data pointer +r5 - Function to be executed + +This implementation assumes that ontop_fcontext will never be called with target contexts +created via make_fcontext. + +*/ + +ontop_fcontext: + /* Reserve stack space to store the current context. */ + aghi %r15,-CONTEXT_SIZE + + /* Save the argument register holding the location of the return value. */ + stg %r2,GR_OFFSET(%r15) + + /* Save the call-saved general purpose registers. */ + stmg %r6,%r14,GR_OFFSET+8(%r15) + + /* Save call-saved floating point registers. */ + std %f8,FP_OFFSET(%r15) + std %f9,FP_OFFSET+8(%r15) + std %f10,FP_OFFSET+16(%r15) + std %f11,FP_OFFSET+24(%r15) + std %f12,FP_OFFSET+32(%r15) + std %f13,FP_OFFSET+40(%r15) + std %f14,FP_OFFSET+48(%r15) + std %f15,FP_OFFSET+56(%r15) + + /* Save the return address as current pc. */ + stg %r14,PC_OFFSET(%r15) + + /* Save the floating point control register. */ + stfpc FPC_OFFSET(%r15) + + /* Backup the stack pointer pointing to the old context-data into r1. */ + lgr %r1,%r15 + + /* Load the new context pointer as stack pointer. */ + lgr %r15,%r3 + + /* Restore the call-saved GPRs from the new context. */ + lmg %r6,%r14,GR_OFFSET+8(%r15) + + /* Restore call-saved floating point registers. */ + ld %f8,FP_OFFSET(%r15) + ld %f9,FP_OFFSET+8(%r15) + ld %f10,FP_OFFSET+16(%r15) + ld %f11,FP_OFFSET+24(%r15) + ld %f12,FP_OFFSET+32(%r15) + ld %f13,FP_OFFSET+40(%r15) + ld %f14,FP_OFFSET+48(%r15) + ld %f15,FP_OFFSET+56(%r15) + + /* Load the floating point control register. */ + lfpc FPC_OFFSET(%r15) + + /* Store the transfer_t values located in the saved context. */ + stg %r1,0(%r1) /* transfer_t.fctx = old context */ + stg %r4,8(%r1) /* transfer_t.data = data */ + + /* Set up the arguments for the target function. */ + lg %r2,GR_OFFSET(%r15) + lgr %r3,%r1 + + /* Deallocate the context. */ + aghi %r15,CONTEXT_SIZE + + br %r5 + +.size ontop_fcontext,.-ontop_fcontext +.section .note.GNU-stack,"",%progbits diff --git a/third_party/context/src/asm/ontop_x86_64_ms_pe_clang_gas.S b/third_party/context/src/asm/ontop_x86_64_ms_pe_clang_gas.S new file mode 100644 index 0000000..162c1f4 --- /dev/null +++ b/third_party/context/src/asm/ontop_x86_64_ms_pe_clang_gas.S @@ -0,0 +1,211 @@ +/* + Copyright Oliver Kowalke 2009. + Copyright Thomas Sailer 2013. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/************************************************************************************* +* ---------------------------------------------------------------------------------- * +* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * +* ---------------------------------------------------------------------------------- * +* | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | * +* ---------------------------------------------------------------------------------- * +* | SEE registers (XMM6-XMM15) | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * +* ---------------------------------------------------------------------------------- * +* | 0x20 | 0x24 | 0x28 | 0x2c | 0x30 | 0x34 | 0x38 | 0x3c | * +* ---------------------------------------------------------------------------------- * +* | SEE registers (XMM6-XMM15) | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * +* ---------------------------------------------------------------------------------- * +* | 0xe40 | 0x44 | 0x48 | 0x4c | 0x50 | 0x54 | 0x58 | 0x5c | * +* ---------------------------------------------------------------------------------- * +* | SEE registers (XMM6-XMM15) | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * +* ---------------------------------------------------------------------------------- * +* | 0x60 | 0x64 | 0x68 | 0x6c | 0x70 | 0x74 | 0x78 | 0x7c | * +* ---------------------------------------------------------------------------------- * +* | SEE registers (XMM6-XMM15) | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 32 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | * +* ---------------------------------------------------------------------------------- * +* | 0x80 | 0x84 | 0x88 | 0x8c | 0x90 | 0x94 | 0x98 | 0x9c | * +* ---------------------------------------------------------------------------------- * +* | SEE registers (XMM6-XMM15) | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | * +* ---------------------------------------------------------------------------------- * +* | 0xa0 | 0xa4 | 0xa8 | 0xac | 0xb0 | 0xb4 | 0xb8 | 0xbc | * +* ---------------------------------------------------------------------------------- * +* | fc_mxcsr|fc_x87_cw| | fbr_strg | fc_dealloc | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | * +* ---------------------------------------------------------------------------------- * +* | 0xc0 | 0xc4 | 0xc8 | 0xcc | 0xd0 | 0xd4 | 0xd8 | 0xdc | * +* ---------------------------------------------------------------------------------- * +* | limit | base | R12 | R13 | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | * +* ---------------------------------------------------------------------------------- * +* | 0xe0 | 0xe4 | 0xe8 | 0xec | 0xf0 | 0xf4 | 0xf8 | 0xfc | * +* ---------------------------------------------------------------------------------- * +* | R14 | R15 | RDI | RSI | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | * +* ---------------------------------------------------------------------------------- * +* | 0x100 | 0x104 | 0x108 | 0x10c | 0x110 | 0x114 | 0x118 | 0x11c | * +* ---------------------------------------------------------------------------------- * +* | RBX | RBP | hidden | RIP | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | * +* ---------------------------------------------------------------------------------- * +* | 0x120 | 0x124 | 0x128 | 0x12c | 0x130 | 0x134 | 0x138 | 0x13c | * +* ---------------------------------------------------------------------------------- * +* | parameter area | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | * +* ---------------------------------------------------------------------------------- * +* | 0x140 | 0x144 | 0x148 | 0x14c | 0x150 | 0x154 | 0x158 | 0x15c | * +* ---------------------------------------------------------------------------------- * +* | FCTX | DATA | | * +* ---------------------------------------------------------------------------------- * +**************************************************************************************/ + +.file "ontop_x86_64_ms_pe_clang_gas.S" +.text +.p2align 4,,15 +.globl ontop_fcontext +.def ontop_fcontext; .scl 2; .type 32; .endef +.seh_proc ontop_fcontext +ontop_fcontext: +.seh_endprologue + + leaq -0x118(%rsp), %rsp /* prepare stack */ + +#if !defined(BOOST_USE_TSX) + /* save XMM storage */ + movaps %xmm6, 0x0(%rsp) + movaps %xmm7, 0x10(%rsp) + movaps %xmm8, 0x20(%rsp) + movaps %xmm9, 0x30(%rsp) + movaps %xmm10, 0x40(%rsp) + movaps %xmm11, 0x50(%rsp) + movaps %xmm12, 0x60(%rsp) + movaps %xmm13, 0x70(%rsp) + movaps %xmm14, 0x80(%rsp) + movaps %xmm15, 0x90(%rsp) + stmxcsr 0xa0(%rsp) /* save MMX control- and status-word */ + fnstcw 0xa4(%rsp) /* save x87 control-word */ +#endif + + /* load NT_TIB */ + movq %gs:(0x30), %r10 + /* save fiber local storage */ + movq 0x20(%r10), %rax + movq %rax, 0xb0(%rsp) + /* save current deallocation stack */ + movq 0x1478(%r10), %rax + movq %rax, 0xb8(%rsp) + /* save current stack limit */ + movq 0x10(%r10), %rax + movq %rax, 0xc0(%rsp) + /* save current stack base */ + movq 0x08(%r10), %rax + movq %rax, 0xc8(%rsp) + + movq %r12, 0xd0(%rsp) /* save R12 */ + movq %r13, 0xd8(%rsp) /* save R13 */ + movq %r14, 0xe0(%rsp) /* save R14 */ + movq %r15, 0xe8(%rsp) /* save R15 */ + movq %rdi, 0xf0(%rsp) /* save RDI */ + movq %rsi, 0xf8(%rsp) /* save RSI */ + movq %rbx, 0x100(%rsp) /* save RBX */ + movq %rbp, 0x108(%rsp) /* save RBP */ + + movq %rcx, 0x110(%rsp) /* save hidden address of transport_t */ + + /* preserve RSP (pointing to context-data) in RCX */ + movq %rsp, %rcx + + /* restore RSP (pointing to context-data) from RDX */ + movq %rdx, %rsp + +#if !defined(BOOST_USE_TSX) + /* restore XMM storage */ + movaps 0x0(%rsp), %xmm6 + movaps 0x10(%rsp), %xmm7 + movaps 0x20(%rsp), %xmm8 + movaps 0x30(%rsp), %xmm9 + movaps 0x40(%rsp), %xmm10 + movaps 0x50(%rsp), %xmm11 + movaps 0x60(%rsp), %xmm12 + movaps 0x70(%rsp), %xmm13 + movaps 0x80(%rsp), %xmm14 + movaps 0x90(%rsp), %xmm15 + ldmxcsr 0xa0(%rsp) /* restore MMX control- and status-word */ + fldcw 0xa4(%rsp) /* restore x87 control-word */ +#endif + + /* load NT_TIB */ + movq %gs:(0x30), %r10 + /* restore fiber local storage */ + movq 0xb0(%rsp), %rax + movq %rax, 0x20(%r10) + /* restore current deallocation stack */ + movq 0xb8(%rsp), %rax + movq %rax, 0x1478(%r10) + /* restore current stack limit */ + movq 0xc0(%rsp), %rax + movq %rax, 0x10(%r10) + /* restore current stack base */ + movq 0xc8(%rsp), %rax + movq %rax, 0x08(%r10) + + movq 0xd0(%rsp), %r12 /* restore R12 */ + movq 0xd8(%rsp), %r13 /* restore R13 */ + movq 0xe0(%rsp), %r14 /* restore R14 */ + movq 0xe8(%rsp), %r15 /* restore R15 */ + movq 0xf0(%rsp), %rdi /* restore RDI */ + movq 0xf8(%rsp), %rsi /* restore RSI */ + movq 0x100(%rsp), %rbx /* restore RBX */ + movq 0x108(%rsp), %rbp /* restore RBP */ + + movq 0x110(%rsp), %rax /* restore hidden address of transport_t */ + + leaq 0x118(%rsp), %rsp /* prepare stack */ + + /* keep return-address on stack */ + + /* transport_t returned in RAX */ + /* return parent fcontext_t */ + movq %rcx, 0x0(%rax) + /* return data */ + movq %r8, 0x8(%rax) + + /* transport_t as 1.arg of context-function */ + /* RCX contains address of returned (hidden) transfer_t */ + movq %rax, %rcx + /* RDX contains address of passed transfer_t */ + movq %rax, %rdx + + /* indirect jump to context */ + jmp *%r9 +.seh_endproc + +.section .drectve +.ascii " -export:\"ontop_fcontext\"" diff --git a/third_party/context/src/asm/ontop_x86_64_ms_pe_gas.asm b/third_party/context/src/asm/ontop_x86_64_ms_pe_gas.asm new file mode 100644 index 0000000..02e040c --- /dev/null +++ b/third_party/context/src/asm/ontop_x86_64_ms_pe_gas.asm @@ -0,0 +1,211 @@ +/* + Copyright Oliver Kowalke 2009. + Copyright Thomas Sailer 2013. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/************************************************************************************* +* ---------------------------------------------------------------------------------- * +* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * +* ---------------------------------------------------------------------------------- * +* | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | * +* ---------------------------------------------------------------------------------- * +* | SEE registers (XMM6-XMM15) | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * +* ---------------------------------------------------------------------------------- * +* | 0x20 | 0x24 | 0x28 | 0x2c | 0x30 | 0x34 | 0x38 | 0x3c | * +* ---------------------------------------------------------------------------------- * +* | SEE registers (XMM6-XMM15) | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * +* ---------------------------------------------------------------------------------- * +* | 0xe40 | 0x44 | 0x48 | 0x4c | 0x50 | 0x54 | 0x58 | 0x5c | * +* ---------------------------------------------------------------------------------- * +* | SEE registers (XMM6-XMM15) | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * +* ---------------------------------------------------------------------------------- * +* | 0x60 | 0x64 | 0x68 | 0x6c | 0x70 | 0x74 | 0x78 | 0x7c | * +* ---------------------------------------------------------------------------------- * +* | SEE registers (XMM6-XMM15) | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 32 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | * +* ---------------------------------------------------------------------------------- * +* | 0x80 | 0x84 | 0x88 | 0x8c | 0x90 | 0x94 | 0x98 | 0x9c | * +* ---------------------------------------------------------------------------------- * +* | SEE registers (XMM6-XMM15) | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | * +* ---------------------------------------------------------------------------------- * +* | 0xa0 | 0xa4 | 0xa8 | 0xac | 0xb0 | 0xb4 | 0xb8 | 0xbc | * +* ---------------------------------------------------------------------------------- * +* | fc_mxcsr|fc_x87_cw| | fbr_strg | fc_dealloc | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | * +* ---------------------------------------------------------------------------------- * +* | 0xc0 | 0xc4 | 0xc8 | 0xcc | 0xd0 | 0xd4 | 0xd8 | 0xdc | * +* ---------------------------------------------------------------------------------- * +* | limit | base | R12 | R13 | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | * +* ---------------------------------------------------------------------------------- * +* | 0xe0 | 0xe4 | 0xe8 | 0xec | 0xf0 | 0xf4 | 0xf8 | 0xfc | * +* ---------------------------------------------------------------------------------- * +* | R14 | R15 | RDI | RSI | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | * +* ---------------------------------------------------------------------------------- * +* | 0x100 | 0x104 | 0x108 | 0x10c | 0x110 | 0x114 | 0x118 | 0x11c | * +* ---------------------------------------------------------------------------------- * +* | RBX | RBP | hidden | RIP | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | * +* ---------------------------------------------------------------------------------- * +* | 0x120 | 0x124 | 0x128 | 0x12c | 0x130 | 0x134 | 0x138 | 0x13c | * +* ---------------------------------------------------------------------------------- * +* | parameter area | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | * +* ---------------------------------------------------------------------------------- * +* | 0x140 | 0x144 | 0x148 | 0x14c | 0x150 | 0x154 | 0x158 | 0x15c | * +* ---------------------------------------------------------------------------------- * +* | FCTX | DATA | | * +* ---------------------------------------------------------------------------------- * +**************************************************************************************/ + +.file "ontop_x86_64_ms_pe_gas.asm" +.text +.p2align 4,,15 +.globl ontop_fcontext +.def ontop_fcontext; .scl 2; .type 32; .endef +.seh_proc ontop_fcontext +ontop_fcontext: +.seh_endprologue + + leaq -0x118(%rsp), %rsp /* prepare stack */ + +#if !defined(BOOST_USE_TSX) + /* save XMM storage */ + movaps %xmm6, 0x0(%rsp) + movaps %xmm7, 0x10(%rsp) + movaps %xmm8, 0x20(%rsp) + movaps %xmm9, 0x30(%rsp) + movaps %xmm10, 0x40(%rsp) + movaps %xmm11, 0x50(%rsp) + movaps %xmm12, 0x60(%rsp) + movaps %xmm13, 0x70(%rsp) + movaps %xmm14, 0x80(%rsp) + movaps %xmm15, 0x90(%rsp) + stmxcsr 0xa0(%rsp) /* save MMX control- and status-word */ + fnstcw 0xa4(%rsp) /* save x87 control-word */ +#endif + + /* load NT_TIB */ + movq %gs:(0x30), %r10 + /* save fiber local storage */ + movq 0x20(%r10), %rax + movq %rax, 0xb0(%rsp) + /* save current deallocation stack */ + movq 0x1478(%r10), %rax + movq %rax, 0xb8(%rsp) + /* save current stack limit */ + movq 0x10(%r10), %rax + movq %rax, 0xc0(%rsp) + /* save current stack base */ + movq 0x08(%r10), %rax + movq %rax, 0xc8(%rsp) + + movq %r12, 0xd0(%rsp) /* save R12 */ + movq %r13, 0xd8(%rsp) /* save R13 */ + movq %r14, 0xe0(%rsp) /* save R14 */ + movq %r15, 0xe8(%rsp) /* save R15 */ + movq %rdi, 0xf0(%rsp) /* save RDI */ + movq %rsi, 0xf8(%rsp) /* save RSI */ + movq %rbx, 0x100(%rsp) /* save RBX */ + movq %rbp, 0x108(%rsp) /* save RBP */ + + movq %rcx, 0x110(%rsp) /* save hidden address of transport_t */ + + /* preserve RSP (pointing to context-data) in RCX */ + movq %rsp, %rcx + + /* restore RSP (pointing to context-data) from RDX */ + movq %rdx, %rsp + +#if !defined(BOOST_USE_TSX) + /* restore XMM storage */ + movaps 0x0(%rsp), %xmm6 + movaps 0x10(%rsp), %xmm7 + movaps 0x20(%rsp), %xmm8 + movaps 0x30(%rsp), %xmm9 + movaps 0x40(%rsp), %xmm10 + movaps 0x50(%rsp), %xmm11 + movaps 0x60(%rsp), %xmm12 + movaps 0x70(%rsp), %xmm13 + movaps 0x80(%rsp), %xmm14 + movaps 0x90(%rsp), %xmm15 + ldmxcsr 0xa0(%rsp) /* restore MMX control- and status-word */ + fldcw 0xa4(%rsp) /* restore x87 control-word */ +#endif + + /* load NT_TIB */ + movq %gs:(0x30), %r10 + /* restore fiber local storage */ + movq 0xb0(%rsp), %rax + movq %rax, 0x20(%r10) + /* restore current deallocation stack */ + movq 0xb8(%rsp), %rax + movq %rax, 0x1478(%r10) + /* restore current stack limit */ + movq 0xc0(%rsp), %rax + movq %rax, 0x10(%r10) + /* restore current stack base */ + movq 0xc8(%rsp), %rax + movq %rax, 0x08(%r10) + + movq 0xd0(%rsp), %r12 /* restore R12 */ + movq 0xd8(%rsp), %r13 /* restore R13 */ + movq 0xe0(%rsp), %r14 /* restore R14 */ + movq 0xe8(%rsp), %r15 /* restore R15 */ + movq 0xf0(%rsp), %rdi /* restore RDI */ + movq 0xf8(%rsp), %rsi /* restore RSI */ + movq 0x100(%rsp), %rbx /* restore RBX */ + movq 0x108(%rsp), %rbp /* restore RBP */ + + movq 0x110(%rsp), %rax /* restore hidden address of transport_t */ + + leaq 0x118(%rsp), %rsp /* prepare stack */ + + /* keep return-address on stack */ + + /* transport_t returned in RAX */ + /* return parent fcontext_t */ + movq %rcx, 0x0(%rax) + /* return data */ + movq %r8, 0x8(%rax) + + /* transport_t as 1.arg of context-function */ + /* RCX contains address of returned (hidden) transfer_t */ + movq %rax, %rcx + /* RDX contains address of passed transfer_t */ + movq %rax, %rdx + + /* indirect jump to context */ + jmp *%r9 +.seh_endproc + +.section .drectve +.ascii " -export:\"ontop_fcontext\"" diff --git a/third_party/context/src/asm/ontop_x86_64_ms_pe_masm.asm b/third_party/context/src/asm/ontop_x86_64_ms_pe_masm.asm new file mode 100644 index 0000000..b57dd15 --- /dev/null +++ b/third_party/context/src/asm/ontop_x86_64_ms_pe_masm.asm @@ -0,0 +1,207 @@ + +; Copyright Oliver Kowalke 2009. +; Distributed under the Boost Software License, Version 1.0. +; (See accompanying file LICENSE_1_0.txt or copy at +; http://www.boost.org/LICENSE_1_0.txt) + +; ---------------------------------------------------------------------------------- +; | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | +; ---------------------------------------------------------------------------------- +; | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | +; ---------------------------------------------------------------------------------- +; | SEE registers (XMM6-XMM15) | +; ---------------------------------------------------------------------------------- +; ---------------------------------------------------------------------------------- +; | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | +; ---------------------------------------------------------------------------------- +; | 0x20 | 0x24 | 0x28 | 0x2c | 0x30 | 0x34 | 0x38 | 0x3c | +; ---------------------------------------------------------------------------------- +; | SEE registers (XMM6-XMM15) | +; ---------------------------------------------------------------------------------- +; ---------------------------------------------------------------------------------- +; | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | +; ---------------------------------------------------------------------------------- +; | 0xe40 | 0x44 | 0x48 | 0x4c | 0x50 | 0x54 | 0x58 | 0x5c | +; ---------------------------------------------------------------------------------- +; | SEE registers (XMM6-XMM15) | +; ---------------------------------------------------------------------------------- +; ---------------------------------------------------------------------------------- +; | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | +; ---------------------------------------------------------------------------------- +; | 0x60 | 0x64 | 0x68 | 0x6c | 0x70 | 0x74 | 0x78 | 0x7c | +; ---------------------------------------------------------------------------------- +; | SEE registers (XMM6-XMM15) | +; ---------------------------------------------------------------------------------- +; ---------------------------------------------------------------------------------- +; | 32 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | +; ---------------------------------------------------------------------------------- +; | 0x80 | 0x84 | 0x88 | 0x8c | 0x90 | 0x94 | 0x98 | 0x9c | +; ---------------------------------------------------------------------------------- +; | SEE registers (XMM6-XMM15) | +; ---------------------------------------------------------------------------------- +; ---------------------------------------------------------------------------------- +; | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | +; ---------------------------------------------------------------------------------- +; | 0xa0 | 0xa4 | 0xa8 | 0xac | 0xb0 | 0xb4 | 0xb8 | 0xbc | +; ---------------------------------------------------------------------------------- +; | fc_mxcsr|fc_x87_cw| | fbr_strg | fc_dealloc | +; ---------------------------------------------------------------------------------- +; ---------------------------------------------------------------------------------- +; | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | +; ---------------------------------------------------------------------------------- +; | 0xc0 | 0xc4 | 0xc8 | 0xcc | 0xd0 | 0xd4 | 0xd8 | 0xdc | +; ---------------------------------------------------------------------------------- +; | limit | base | R12 | R13 | +; ---------------------------------------------------------------------------------- +; ---------------------------------------------------------------------------------- +; | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | +; ---------------------------------------------------------------------------------- +; | 0xe0 | 0xe4 | 0xe8 | 0xec | 0xf0 | 0xf4 | 0xf8 | 0xfc | +; ---------------------------------------------------------------------------------- +; | R14 | R15 | RDI | RSI | +; ---------------------------------------------------------------------------------- +; ---------------------------------------------------------------------------------- +; | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | +; ---------------------------------------------------------------------------------- +; | 0x100 | 0x104 | 0x108 | 0x10c | 0x110 | 0x114 | 0x118 | 0x11c | +; ---------------------------------------------------------------------------------- +; | RBX | RBP | hidden | RIP | +; ---------------------------------------------------------------------------------- +; ---------------------------------------------------------------------------------- +; | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | +; ---------------------------------------------------------------------------------- +; | 0x120 | 0x124 | 0x128 | 0x12c | 0x130 | 0x134 | 0x138 | 0x13c | +; ---------------------------------------------------------------------------------- +; | parameter area | +; ---------------------------------------------------------------------------------- +; ---------------------------------------------------------------------------------- +; | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | +; ---------------------------------------------------------------------------------- +; | 0x140 | 0x144 | 0x148 | 0x14c | 0x150 | 0x154 | 0x158 | 0x15c | +; ---------------------------------------------------------------------------------- +; | FCTX | DATA | | +; ---------------------------------------------------------------------------------- + +.code + +ontop_fcontext PROC BOOST_CONTEXT_EXPORT FRAME + .endprolog + + ; prepare stack + lea rsp, [rsp-0118h] + +IFNDEF BOOST_USE_TSX + ; save XMM storage + movaps [rsp], xmm6 + movaps [rsp+010h], xmm7 + movaps [rsp+020h], xmm8 + movaps [rsp+030h], xmm9 + movaps [rsp+040h], xmm10 + movaps [rsp+050h], xmm11 + movaps [rsp+060h], xmm12 + movaps [rsp+070h], xmm13 + movaps [rsp+080h], xmm14 + movaps [rsp+090h], xmm15 + ; save MMX control- and status-word + stmxcsr [rsp+0a0h] + ; save x87 control-word + fnstcw [rsp+0a4h] +ENDIF + + ; load NT_TIB + mov r10, gs:[030h] + ; save fiber local storage + mov rax, [r10+020h] + mov [rsp+0b0h], rax + ; save current deallocation stack + mov rax, [r10+01478h] + mov [rsp+0b8h], rax + ; save current stack limit + mov rax, [r10+010h] + mov [rsp+0c0h], rax + ; save current stack base + mov rax, [r10+08h] + mov [rsp+0c8h], rax + + mov [rsp+0d0h], r12 ; save R12 + mov [rsp+0d8h], r13 ; save R13 + mov [rsp+0e0h], r14 ; save R14 + mov [rsp+0e8h], r15 ; save R15 + mov [rsp+0f0h], rdi ; save RDI + mov [rsp+0f8h], rsi ; save RSI + mov [rsp+0100h], rbx ; save RBX + mov [rsp+0108h], rbp ; save RBP + + mov [rsp+0110h], rcx ; save hidden address of transport_t + + ; preserve RSP (pointing to context-data) in RCX + mov rcx, rsp + + ; restore RSP (pointing to context-data) from RDX + mov rsp, rdx + +IFNDEF BOOST_USE_TSX + ; restore XMM storage + movaps xmm6, [rsp] + movaps xmm7, [rsp+010h] + movaps xmm8, [rsp+020h] + movaps xmm9, [rsp+030h] + movaps xmm10, [rsp+040h] + movaps xmm11, [rsp+050h] + movaps xmm12, [rsp+060h] + movaps xmm13, [rsp+070h] + movaps xmm14, [rsp+080h] + movaps xmm15, [rsp+090h] + ; restore MMX control- and status-word + ldmxcsr [rsp+0a0h] + ; save x87 control-word + fldcw [rsp+0a4h] +ENDIF + + ; load NT_TIB + mov r10, gs:[030h] + ; restore fiber local storage + mov rax, [rsp+0b0h] + mov [r10+020h], rax + ; restore current deallocation stack + mov rax, [rsp+0b8h] + mov [r10+01478h], rax + ; restore current stack limit + mov rax, [rsp+0c0h] + mov [r10+010h], rax + ; restore current stack base + mov rax, [rsp+0c8h] + mov [r10+08h], rax + + mov r12, [rsp+0d0h] ; restore R12 + mov r13, [rsp+0d8h] ; restore R13 + mov r14, [rsp+0e0h] ; restore R14 + mov r15, [rsp+0e8h] ; restore R15 + mov rdi, [rsp+0f0h] ; restore RDI + mov rsi, [rsp+0f8h] ; restore RSI + mov rbx, [rsp+0100h] ; restore RBX + mov rbp, [rsp+0108h] ; restore RBP + + mov rax, [rsp+0110h] ; restore hidden address of transport_t + + ; prepare stack + lea rsp, [rsp+0118h] + + ; keep return-address on stack + + ; transport_t returned in RAX + ; return parent fcontext_t + mov [rax], rcx + ; return data + mov [rax+08h], r8 + + ; transport_t as 1.arg of context-function + ; RCX contains address of returned (hidden) transfer_t + mov rcx, rax + ; RDX contains address of passed transfer_t + mov rdx, rax + + ; indirect jump to context + jmp r9 +ontop_fcontext ENDP +END diff --git a/third_party/context/src/asm/ontop_x86_64_sysv_elf_gas.S b/third_party/context/src/asm/ontop_x86_64_sysv_elf_gas.S new file mode 100644 index 0000000..c3892b8 --- /dev/null +++ b/third_party/context/src/asm/ontop_x86_64_sysv_elf_gas.S @@ -0,0 +1,138 @@ +/* + Copyright Oliver Kowalke 2009. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/**************************************************************************************** + * * + * ---------------------------------------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ---------------------------------------------------------------------------------- * + * | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | * + * ---------------------------------------------------------------------------------- * + * | fc_mxcsr|fc_x87_cw| guard | R12 | R13 | * + * ---------------------------------------------------------------------------------- * + * ---------------------------------------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ---------------------------------------------------------------------------------- * + * | 0x20 | 0x24 | 0x28 | 0x2c | 0x30 | 0x34 | 0x38 | 0x3c | * + * ---------------------------------------------------------------------------------- * + * | R14 | R15 | RBX | RBP | * + * ---------------------------------------------------------------------------------- * + * ---------------------------------------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * + * ---------------------------------------------------------------------------------- * + * | 0x40 | 0x44 | | * + * ---------------------------------------------------------------------------------- * + * | RIP | | * + * ---------------------------------------------------------------------------------- * + * * + ****************************************************************************************/ +# if defined __CET__ +# include +# define SHSTK_ENABLED (__CET__ & 0x2) +# define BOOST_CONTEXT_SHADOW_STACK (SHSTK_ENABLED && SHADOW_STACK_SYSCALL) +# else +# define _CET_ENDBR +# endif +.file "ontop_x86_64_sysv_elf_gas.S" +.text +.globl ontop_fcontext +.type ontop_fcontext,@function +.align 16 +ontop_fcontext: + _CET_ENDBR + /* preserve ontop-function in R8 */ + movq %rdx, %r8 + + leaq -0x40(%rsp), %rsp /* prepare stack */ + +#if !defined(BOOST_USE_TSX) + stmxcsr (%rsp) /* save MMX control- and status-word */ + fnstcw 0x4(%rsp) /* save x87 control-word */ +#endif + +#if defined(BOOST_CONTEXT_TLS_STACK_PROTECTOR) + movq %fs:0x28, %rcx /* read stack guard from TLS record */ + movq %rcx, 0x8(%rsp) /* save stack guard */ +#endif + + movq %r12, 0x10(%rsp) /* save R12 */ + movq %r13, 0x18(%rsp) /* save R13 */ + movq %r14, 0x20(%rsp) /* save R14 */ + movq %r15, 0x28(%rsp) /* save R15 */ + movq %rbx, 0x30(%rsp) /* save RBX */ + movq %rbp, 0x38(%rsp) /* save RBP */ + +#if BOOST_CONTEXT_SHADOW_STACK + /* grow the stack to reserve space for shadow stack pointer(SSP) */ + leaq -0x8(%rsp), %rsp + /* read the current SSP and store it */ + rdsspq %rcx + movq %rcx, (%rsp) +#endif + + /* store RSP (pointing to context-data) in RAX */ + movq %rsp, %rax + + /* restore RSP (pointing to context-data) from RDI */ + movq %rdi, %rsp + +#if BOOST_CONTEXT_SHADOW_STACK + /* first 8 bytes are SSP */ + movq (%rsp), %rcx + leaq 0x8(%rsp), %rsp + + /* Restore target(new) shadow stack */ + rstorssp -8(%rcx) + /* restore token for previous shadow stack is pushed */ + /* on previous shadow stack after saveprevssp */ + saveprevssp +#endif + +#if !defined(BOOST_USE_TSX) + ldmxcsr (%rsp) /* restore MMX control- and status-word */ + fldcw 0x4(%rsp) /* restore x87 control-word */ +#endif + +#if defined(BOOST_CONTEXT_TLS_STACK_PROTECTOR) + movq 0x8(%rsp), %rdx /* load stack guard */ + movq %rdx, %fs:0x28 /* restore stack guard to TLS record */ +#endif + + movq 0x10(%rsp), %r12 /* restore R12 */ + movq 0x18(%rsp), %r13 /* restore R13 */ + movq 0x20(%rsp), %r14 /* restore R14 */ + movq 0x28(%rsp), %r15 /* restore R15 */ + movq 0x30(%rsp), %rbx /* restore RBX */ + movq 0x38(%rsp), %rbp /* restore RBP */ + + leaq 0x40(%rsp), %rsp /* prepare stack */ + + /* return transfer_t from jump */ +#if !defined(_ILP32) + /* RAX == fctx, RDX == data */ + movq %rsi, %rdx +#else + /* RAX == data:fctx */ + salq $32, %rsi + orq %rsi, %rax +#endif + /* pass transfer_t as first arg in context function */ +#if !defined(_ILP32) + /* RDI == fctx, RSI == data */ +#else + /* RDI == data:fctx */ +#endif + movq %rax, %rdi + + /* keep return-address on stack */ + + /* indirect jump to context */ + jmp *%r8 +.size ontop_fcontext,.-ontop_fcontext + +/* Mark that we don't need executable stack. */ +.section .note.GNU-stack,"",%progbits diff --git a/third_party/context/src/asm/ontop_x86_64_sysv_macho_gas.S b/third_party/context/src/asm/ontop_x86_64_sysv_macho_gas.S new file mode 100644 index 0000000..49755c6 --- /dev/null +++ b/third_party/context/src/asm/ontop_x86_64_sysv_macho_gas.S @@ -0,0 +1,78 @@ +/* + Copyright Oliver Kowalke 2009. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/**************************************************************************************** + * * + * ---------------------------------------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ---------------------------------------------------------------------------------- * + * | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | * + * ---------------------------------------------------------------------------------- * + * | fc_mxcsr|fc_x87_cw| R12 | R13 | R14 | * + * ---------------------------------------------------------------------------------- * + * ---------------------------------------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ---------------------------------------------------------------------------------- * + * | 0x20 | 0x24 | 0x28 | 0x2c | 0x30 | 0x34 | 0x38 | 0x3c | * + * ---------------------------------------------------------------------------------- * + * | R15 | RBX | RBP | RIP | * + * ---------------------------------------------------------------------------------- * + * * + ****************************************************************************************/ + +.text +.globl _ontop_fcontext +.align 8 +_ontop_fcontext: + /* preserve ontop-function in R8 */ + movq %rdx, %r8 + + leaq -0x38(%rsp), %rsp /* prepare stack */ + +#if !defined(BOOST_USE_TSX) + stmxcsr (%rsp) /* save MMX control- and status-word */ + fnstcw 0x4(%rsp) /* save x87 control-word */ +#endif + + movq %r12, 0x8(%rsp) /* save R12 */ + movq %r13, 0x10(%rsp) /* save R13 */ + movq %r14, 0x18(%rsp) /* save R14 */ + movq %r15, 0x20(%rsp) /* save R15 */ + movq %rbx, 0x28(%rsp) /* save RBX */ + movq %rbp, 0x30(%rsp) /* save RBP */ + + /* store RSP (pointing to context-data) in RAX */ + movq %rsp, %rax + + /* restore RSP (pointing to context-data) from RDI */ + movq %rdi, %rsp + +#if !defined(BOOST_USE_TSX) + ldmxcsr (%rsp) /* restore MMX control- and status-word */ + fldcw 0x4(%rsp) /* restore x87 control-word */ +#endif + + movq 0x8(%rsp), %r12 /* restore R12 */ + movq 0x10(%rsp), %r13 /* restore R13 */ + movq 0x18(%rsp), %r14 /* restore R14 */ + movq 0x20(%rsp), %r15 /* restore R15 */ + movq 0x28(%rsp), %rbx /* restore RBX */ + movq 0x30(%rsp), %rbp /* restore RBP */ + + leaq 0x38(%rsp), %rsp /* prepare stack */ + + /* return transfer_t from jump */ + /* RAX == fctx, RDX == data */ + movq %rsi, %rdx + /* pass transfer_t as first arg in context function */ + /* RDI == fctx, RSI == data */ + movq %rax, %rdi + + /* keep return-address on stack */ + + /* indirect jump to context */ + jmp *%r8 diff --git a/third_party/context/src/asm/tail_ontop_ppc32_sysv.cpp b/third_party/context/src/asm/tail_ontop_ppc32_sysv.cpp new file mode 100644 index 0000000..a3c5875 --- /dev/null +++ b/third_party/context/src/asm/tail_ontop_ppc32_sysv.cpp @@ -0,0 +1,16 @@ + +// Copyright Oliver Kowalke 2009. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// Modified to match the Nova-Context project structure +#include "include/nova/context/fcontext.h" + +// This C++ tail of ontop_fcontext() allocates fcontext_transfer_t{ from, vp } on the stack. If fn() throws a +// C++ exception, then the C++ runtime must remove this tail's stack frame. +extern "C" fcontext_transfer_t +ontop_fcontext_tail(int ignore, void *vp, fcontext_transfer_t (*fn)(fcontext_transfer_t), fcontext_t const from) +{ + return fn(fcontext_transfer_t{ from, vp }); +} diff --git a/tile/fiber/detail/fiber.cc b/tile/fiber/detail/fiber.cc index c633fd1..7fa89b2 100644 --- a/tile/fiber/detail/fiber.cc +++ b/tile/fiber/detail/fiber.cc @@ -7,6 +7,8 @@ #include "tile/base/object_pool.h" #include "tile/fiber/detail/ucontext.h" +#include "nova/context/fcontext.h" + namespace tile { namespace fiber { namespace detail { @@ -25,8 +27,20 @@ void RunProc(void *arg) { Fiber::MasterFiber()->Resume(); } +void RunProc1(fcontext_transfer_t ft) { + auto t = jump_fcontext(ft.fctx, nullptr); + + auto proc = static_cast *>(ft.data); + TILE_LOG_INFO("proc: {}", fmt::ptr(proc)); + if (proc) { + (*proc)(); + } + Fiber::MasterFiber()->Resume(); +} + struct alignas(hardware_destructive_interference_size) Fiber::FiberContext { - tile_ucontext_t uctx; + fcontext_t fctx; + // tile_ucontext_t uctx; std::aligned_storage::type stack; }; @@ -47,8 +61,7 @@ Fiber::Fiber(std::function proc) // memset(&ctx_->uctx, 0, sizeof(tile_ucontext_t)); // memset(&ctx_->stack, 0, kStackSize); if (proc_) { - tile_ucontext_set_target(&ctx_->uctx, &ctx_->stack, kStackSize, RunProc, - &proc_); + make_fcontext(&ctx_->stack, kStackSize, RunProc1); } } @@ -62,7 +75,9 @@ void Fiber::Resume() { auto caller = Current(); TILE_CHECK_NE(caller, this, "Can't `Resume()` self"); SetCurrent(this); - tile_ucontext_swap(&caller->ctx_->uctx, &ctx_->uctx); + // tile_ucontext_swap(&caller->ctx_->uctx, &ctx_->uctx); + TILE_LOG_INFO("proc: {}", fmt::ptr(&proc_)); + jump_fcontext(ctx_->fctx, nullptr); SetCurrent(caller); } diff --git a/tile/fiber/detail/fiber.h b/tile/fiber/detail/fiber.h index 0536f24..6c903f7 100644 --- a/tile/fiber/detail/fiber.h +++ b/tile/fiber/detail/fiber.h @@ -10,11 +10,13 @@ #include struct tile_ucontext_t; +struct fcontext_transfer; namespace tile { namespace fiber { namespace detail { void RunProc(void *arg); +void RunProc1(struct fcontext_transfer); class Scheduler; @@ -44,6 +46,7 @@ public: private: TILE_FRIEND_TEST(Fiber, Base); friend void RunProc(void *); + friend void RunProc1(struct fcontext_transfer); friend Scheduler; struct FiberContext; friend class ::tile::PoolTraits; From ab8c2bf2cc80bba023f4eaa5a8f77861d7300c94 Mon Sep 17 00:00:00 2001 From: tqcq <99722391+tqcq@users.noreply.github.com> Date: Wed, 12 Jun 2024 11:11:43 +0800 Subject: [PATCH 07/56] fix fiber crash --- CMakeLists.txt | 2 +- third_party/context/CMakeLists.txt | 7 ++-- tile/base/internal/format.h | 20 +++++++++++ tile/fiber/detail/fiber.cc | 57 +++++++++++++++++------------- tile/fiber/detail/fiber.h | 9 +++-- tile/fiber/detail/fiber_test.cc | 26 +++++--------- 6 files changed, 71 insertions(+), 50 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 59a083b..ab75262 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -204,7 +204,7 @@ if((NOT TILE_HAVE_GETIFADDRS) OR (NOT TILE_HAVE_FREEIFADDRS)) list(APPEND TILE_SRCS "tile/base/net/detail/android/ifaddrs.c") endif() -add_library(tile OBJECT ${TILE_SRCS} ${ASM_SRCS}) +add_library(tile OBJECT ${TILE_SRCS}) set_target_properties(tile PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION "${tile_VERSION_MAJRO}") # target_sources(tile PRIVATE ${TILE_SRCS}) diff --git a/third_party/context/CMakeLists.txt b/third_party/context/CMakeLists.txt index 5174108..cf8db97 100644 --- a/third_party/context/CMakeLists.txt +++ b/third_party/context/CMakeLists.txt @@ -10,7 +10,7 @@ cmake_minimum_required(VERSION 3.5...3.16) project( nova_context VERSION 0.1.0 - LANGUAGES C) + LANGUAGES C ASM) list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) @@ -197,6 +197,7 @@ set(ASM_SRC unset(_asm_suffix) +set_source_files_properties(${ASM_SRC} PROPERTIES LINKER_LANGUAGE C) # POWERPC_32/SYSV Special case: https://github.com/boostorg/context/issues/120 if((NOVA_CONTEXT_ARCHITECTURE STREQUAL ppc32) AND (NOVA_CONTEXT_ABI STREQUAL sysv)) @@ -210,8 +211,8 @@ if(NOVA_CONTEXT_ASSEMBLER STREQUAL masm AND NOVA_CONTEXT_ARCHITECTURE STREQUAL endif() if(CMAKE_CXX_COMPILER_ID STREQUAL GNU) - set_source_files_properties(${ASM_SRC} PROPERTIES COMPILE_OPTIONS - "-x assembler-with-cpp") + # set_source_files_properties(${ASM_SRC} PROPERTIES COMPILE_OPTIONS + # "-x assembler-with-cpp") endif() # Boost specific definitions diff --git a/tile/base/internal/format.h b/tile/base/internal/format.h index 70027e4..80a5e6d 100644 --- a/tile/base/internal/format.h +++ b/tile/base/internal/format.h @@ -57,6 +57,13 @@ auto format_as(const T &val) return val.ToString(); } +template +auto format_as(T *ptr) + -> tile::enable_if_t>::value, + void *> { + return reinterpret_cast(ptr); +} + #define TILE_INSTANCE_CHRONO_FORMAT_AS(type, suffix) \ inline std::string format_as(const type &val) { \ return tile::detail::format_as_impl(val, suffix); \ @@ -80,4 +87,17 @@ TILE_INSTANCE_CHRONO_FORMAT_AS(std::chrono::years, "y") #include "fmt/format.h" #include "fmt/ostream.h" +inline std::ostream &operator<<(std::ostream &os, std::nullptr_t) { + return os << "nullptr"; +} + +// template ::value && +// !std::is_same, +// std::nullptr_t>::value>> +// std::ostream &operator<<(std::ostream &os, T *ptr) { +// return os << fmt::format("{}", fmt::ptr(ptr)); +// } + #endif // TILE_BASE_INTERNAL_FORMAT_H diff --git a/tile/fiber/detail/fiber.cc b/tile/fiber/detail/fiber.cc index 7fa89b2..3aa3a06 100644 --- a/tile/fiber/detail/fiber.cc +++ b/tile/fiber/detail/fiber.cc @@ -16,32 +16,38 @@ namespace detail { static thread_local Fiber *tls_current_fiber = nullptr; static thread_local Fiber *tls_master_fiber = nullptr; -constexpr auto kStackSize = 8192; -constexpr auto kAlignSize = 16; +constexpr std::size_t kStackSize = 8192; +constexpr std::size_t kAlignSize = 16; -void RunProc(void *arg) { - auto proc = static_cast *>(arg); - if (proc) { - (*proc)(); +void FiberEntry(fcontext_transfer_t t) { + // TILE_LOG_INFO("FiberEntry creater {}, proc {}", t.fctx, t.data); + std::function *fn = static_cast *>(t.data); + TILE_CHECK_NE(t.data, nullptr); + TILE_CHECK_NE(t.fctx, nullptr); + try { + t = jump_fcontext(t.fctx, nullptr); + (*fn)(); + } catch (const std::exception &e) { + // TILE_LOG_ERROR("Exception caught in fiber: {}", e.what()); } - Fiber::MasterFiber()->Resume(); + TILE_CHECK_NE(t.fctx, nullptr); + // TILE_LOG_INFO("FiberEntry End. Resume to {}", t.fctx); + jump_fcontext(t.fctx, nullptr); } -void RunProc1(fcontext_transfer_t ft) { - auto t = jump_fcontext(ft.fctx, nullptr); +fcontext_t CreateFiber(void *stack, std::size_t stack_size, + std::function *fn) { + void *stack_top = static_cast(stack) + stack_size; + const fcontext_t fctx = make_fcontext(stack_top, stack_size, FiberEntry); + TILE_CHECK_NE(fctx, nullptr); - auto proc = static_cast *>(ft.data); - TILE_LOG_INFO("proc: {}", fmt::ptr(proc)); - if (proc) { - (*proc)(); - } - Fiber::MasterFiber()->Resume(); + return jump_fcontext(fctx, fn).fctx; } struct alignas(hardware_destructive_interference_size) Fiber::FiberContext { fcontext_t fctx; - // tile_ucontext_t uctx; std::aligned_storage::type stack; + std::function proc; }; Fiber *Fiber::Current() noexcept { return tls_current_fiber; } @@ -56,12 +62,13 @@ std::unique_ptr Fiber::Create(std::function proc) noexcept { } Fiber::Fiber(std::function proc) - : ctx_(object_pool::Get().Leak()), proc_(std::move(proc)) { + : ctx_(object_pool::Get().Leak()) { - // memset(&ctx_->uctx, 0, sizeof(tile_ucontext_t)); - // memset(&ctx_->stack, 0, kStackSize); - if (proc_) { - make_fcontext(&ctx_->stack, kStackSize, RunProc1); + ctx_->proc = std::move(proc); + if (ctx_->proc) { + ctx_->fctx = CreateFiber(&ctx_->stack, kStackSize, &ctx_->proc); + } else { + ctx_->fctx = nullptr; } } @@ -75,12 +82,14 @@ void Fiber::Resume() { auto caller = Current(); TILE_CHECK_NE(caller, this, "Can't `Resume()` self"); SetCurrent(this); - // tile_ucontext_swap(&caller->ctx_->uctx, &ctx_->uctx); - TILE_LOG_INFO("proc: {}", fmt::ptr(&proc_)); - jump_fcontext(ctx_->fctx, nullptr); + // TILE_LOG_INFO("Resume before proc: {}", fmt::ptr(&proc_)); + ctx_->fctx = jump_fcontext(ctx_->fctx, nullptr).fctx; + // TILE_LOG_INFO("Resume after proc: {}", fmt::ptr(&proc_)); SetCurrent(caller); } +void Fiber::Yield() {} + } // namespace detail } // namespace fiber diff --git a/tile/fiber/detail/fiber.h b/tile/fiber/detail/fiber.h index 6c903f7..8d83756 100644 --- a/tile/fiber/detail/fiber.h +++ b/tile/fiber/detail/fiber.h @@ -43,21 +43,20 @@ public: Fiber(Fiber &&other) noexcept = default; Fiber &operator=(Fiber &&other) noexcept = default; + // for `Scheduler` + void Resume(); + void Yield(); + private: TILE_FRIEND_TEST(Fiber, Base); - friend void RunProc(void *); - friend void RunProc1(struct fcontext_transfer); friend Scheduler; struct FiberContext; friend class ::tile::PoolTraits; Fiber(std::function proc = nullptr); - void Resume(); - private: std::unique_ptr ctx_; - std::function proc_; FiberState state_{Ready}; }; diff --git a/tile/fiber/detail/fiber_test.cc b/tile/fiber/detail/fiber_test.cc index 497b3c1..d431a9e 100644 --- a/tile/fiber/detail/fiber_test.cc +++ b/tile/fiber/detail/fiber_test.cc @@ -13,27 +13,19 @@ TEST(Fiber, Base) { // 0 -> master fiber // [1, 9] -> worker fibers - std::vector> fibers; - fibers.emplace_back(Fiber::Create()); - Fiber::SetMasterFiber(fibers[0].get()); - Fiber::SetCurrent(fibers[0].get()); - - for (int i = 1; i != 10; ++i) { - fibers.emplace_back(Fiber::Create([&, i] { - while (cnt < kMaxCnt) { - ASSERT_EQ(Fiber::Current(), fibers[i].get()); - ++cnt; - Fiber::MasterFiber()->Resume(); - } - })); - } + auto master_fiber = Fiber::Create(); + Fiber::SetMasterFiber(master_fiber.get()); + Fiber::SetCurrent(master_fiber.get()); while (cnt < kMaxCnt) { - int old = cnt; - auto next_fiber = fibers[Random(1, 9)].get(); + std::unique_ptr worker_fiber = Fiber::Create([&] { + ASSERT_EQ(Fiber::Current(), worker_fiber.get()); + ++cnt; + }); - next_fiber->Resume(); + int old = cnt; + worker_fiber->Resume(); ++resume_cnt; ASSERT_EQ(old + 1, cnt); ASSERT_EQ(Fiber::Current(), Fiber::MasterFiber()); From 7c7f73b508000b03a2b90ecbcb98388a75eb1a7e Mon Sep 17 00:00:00 2001 From: tqcq <99722391+tqcq@users.noreply.github.com> Date: Wed, 12 Jun 2024 11:26:09 +0800 Subject: [PATCH 08/56] feat use system_clock --- tile/base/chrono.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tile/base/chrono.cc b/tile/base/chrono.cc index 1b70e0b..f0c6a45 100644 --- a/tile/base/chrono.cc +++ b/tile/base/chrono.cc @@ -118,8 +118,8 @@ std::chrono::steady_clock::time_point ReadSteadyClock() { return std::chrono::steady_clock::now(); } std::chrono::system_clock::time_point ReadSystemClock() { - return ReadClock(CLOCK_REALTIME); - // return std::chrono::system_clock::now(); + // return ReadClock(CLOCK_REALTIME); + return std::chrono::system_clock::now(); } std::chrono::steady_clock::time_point ReadCoarseSteadyClock() { From 8d1b951a25a5180f329680df5b4eb88273950e03 Mon Sep 17 00:00:00 2001 From: tqcq <99722391+tqcq@users.noreply.github.com> Date: Wed, 12 Jun 2024 11:30:39 +0800 Subject: [PATCH 09/56] fix chrono test --- tile/base/chrono_test.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tile/base/chrono_test.cc b/tile/base/chrono_test.cc index 3dbbb68..be71bf0 100644 --- a/tile/base/chrono_test.cc +++ b/tile/base/chrono_test.cc @@ -6,10 +6,11 @@ namespace tile { static constexpr auto one = detail::chrono::CoarseClockInitializer::kAccuracy; -long AvageTime(std::function f, std::size_t n = 1000) { +long AvageTime(std::function f, std::size_t n = 100) { long double total = 0; for (std::size_t i = 0; i != n; ++i) { total += 1.0f / n * f(); + std::this_thread::sleep_for(std::chrono::milliseconds(1)); } return static_cast(total); } From 7248d70d38be31452053f608af63041785d0e144 Mon Sep 17 00:00:00 2001 From: tqcq <99722391+tqcq@users.noreply.github.com> Date: Wed, 12 Jun 2024 21:48:07 +0800 Subject: [PATCH 10/56] feat add benchmark --- CMakeLists.txt | 2 ++ tile/fiber/detail/fiber.cc | 4 ++- tile/fiber/detail/fiber_benchmark.cc | 37 +++++++++++++++++++++++ tile/fiber/detail/fiber_test.cc | 44 +++++++++++++++++----------- 4 files changed, 69 insertions(+), 18 deletions(-) create mode 100644 tile/fiber/detail/fiber_benchmark.cc diff --git a/CMakeLists.txt b/CMakeLists.txt index ab75262..d1caa83 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -362,6 +362,8 @@ if(TILE_BUILD_BENCHMARKS) target_sources(tile_bm_all PRIVATE ${benchmark_file}) endmacro() + tile_add_bm(fiber_detail_fiber_benchmark + "tile/fiber/detail/fiber_benchmark.cc") tile_add_bm(base_casting_benchmark "tile/base/casting_benchmark.cc") tile_add_bm(base_thread_mutex_benchmark "tile/base/thread/mutex_benchmark.cc") tile_add_bm(base_encoding_benchmark "tile/base/encoding_benchmark.cc") diff --git a/tile/fiber/detail/fiber.cc b/tile/fiber/detail/fiber.cc index 3aa3a06..b49ef22 100644 --- a/tile/fiber/detail/fiber.cc +++ b/tile/fiber/detail/fiber.cc @@ -79,11 +79,13 @@ Fiber::~Fiber() { } void Fiber::Resume() { + TILE_CHECK_NE(ctx_->fctx, nullptr); auto caller = Current(); TILE_CHECK_NE(caller, this, "Can't `Resume()` self"); SetCurrent(this); // TILE_LOG_INFO("Resume before proc: {}", fmt::ptr(&proc_)); - ctx_->fctx = jump_fcontext(ctx_->fctx, nullptr).fctx; + ctx_->fctx = + jump_fcontext(internal::Exchange(ctx_->fctx, nullptr), nullptr).fctx; // TILE_LOG_INFO("Resume after proc: {}", fmt::ptr(&proc_)); SetCurrent(caller); } diff --git a/tile/fiber/detail/fiber_benchmark.cc b/tile/fiber/detail/fiber_benchmark.cc new file mode 100644 index 0000000..14f3fd4 --- /dev/null +++ b/tile/fiber/detail/fiber_benchmark.cc @@ -0,0 +1,37 @@ +#include "tile/fiber/detail/fiber.h" + +#include "tile/base/random.h" +#include "tile/base/string.h" + +#include "benchmark/benchmark.h" + +namespace tile { +namespace fiber { +namespace detail { +void Benchmark_FiberSwitch(benchmark::State &state) { + std::unique_ptr master_fiber; + + int switch_cnt = 0; + master_fiber = Fiber::Create([&] { + while (state.KeepRunning()) { + std::unique_ptr worker_fiber1 = + Fiber::Create([&] { ++switch_cnt; }); + + auto start = std::chrono::steady_clock::now(); + worker_fiber1->Resume(); + auto end = std::chrono::steady_clock::now(); + auto elapsed = std::chrono::duration_cast>( + end - start); + state.SetIterationTime(elapsed.count()); + } + }); + + master_fiber->Resume(); + state.counters["switch_cnt"] = switch_cnt; +} + +} // namespace detail +} // namespace fiber +} // namespace tile + +BENCHMARK(tile::fiber::detail::Benchmark_FiberSwitch)->UseManualTime(); diff --git a/tile/fiber/detail/fiber_test.cc b/tile/fiber/detail/fiber_test.cc index d431a9e..bffb03a 100644 --- a/tile/fiber/detail/fiber_test.cc +++ b/tile/fiber/detail/fiber_test.cc @@ -7,30 +7,40 @@ namespace fiber { namespace detail { TEST(Fiber, Base) { - constexpr auto kMaxCnt = 5000000; + constexpr auto kMaxCnt = 100 * 1000; int cnt = 0; int resume_cnt = 0; // 0 -> master fiber // [1, 9] -> worker fibers + std::unique_ptr master_fiber; + + master_fiber = Fiber::Create([&] { + TILE_LOG_INFO("master fiber"); + // ASSERT_EQ(cnt, 0); + ASSERT_EQ(Fiber::MasterFiber(), master_fiber.get()); + ASSERT_EQ(Fiber::Current(), master_fiber.get()); + + ASSERT_EQ(cnt, 0); + while (cnt < kMaxCnt) { + std::unique_ptr worker_fiber = Fiber::Create([&] { + ASSERT_EQ(Fiber::Current(), worker_fiber.get()); + ++cnt; + }); + + int old = cnt; + worker_fiber->Resume(); + ASSERT_EQ(old + 1, cnt); + ASSERT_EQ(Fiber::Current(), master_fiber.get()); + } + + ASSERT_EQ(cnt, kMaxCnt); + }); - auto master_fiber = Fiber::Create(); Fiber::SetMasterFiber(master_fiber.get()); - Fiber::SetCurrent(master_fiber.get()); - - while (cnt < kMaxCnt) { - std::unique_ptr worker_fiber = Fiber::Create([&] { - ASSERT_EQ(Fiber::Current(), worker_fiber.get()); - ++cnt; - }); - - int old = cnt; - worker_fiber->Resume(); - ++resume_cnt; - ASSERT_EQ(old + 1, cnt); - ASSERT_EQ(Fiber::Current(), Fiber::MasterFiber()); - } - ASSERT_EQ(resume_cnt, kMaxCnt); + // Fiber::SetCurrent(master_fiber.get()); + // master_fiber->Resume(); + master_fiber->Resume(); } } // namespace detail From f6dea4fa2dac3b31afd1211d57e43a7ad3783fa9 Mon Sep 17 00:00:00 2001 From: tqcq <99722391+tqcq@users.noreply.github.com> Date: Wed, 12 Jun 2024 22:48:24 +0800 Subject: [PATCH 11/56] feat delete asm --- CMakeLists.txt | 15 --- tile/fiber/detail/asm/ucontext_aarch64.S | 153 ----------------------- tile/fiber/detail/asm/ucontext_aarch64.h | 143 --------------------- tile/fiber/detail/asm/ucontext_arm.S | 75 ----------- tile/fiber/detail/asm/ucontext_arm.h | 110 ---------------- tile/fiber/detail/asm/ucontext_mips32.S | 97 -------------- tile/fiber/detail/asm/ucontext_mips32.h | 123 ------------------ tile/fiber/detail/asm/ucontext_mips64.S | 95 -------------- tile/fiber/detail/asm/ucontext_mips64.h | 123 ------------------ tile/fiber/detail/asm/ucontext_riscv64.S | 100 --------------- tile/fiber/detail/asm/ucontext_riscv64.h | 141 --------------------- tile/fiber/detail/asm/ucontext_x64.S | 65 ---------- tile/fiber/detail/asm/ucontext_x64.h | 75 ----------- tile/fiber/detail/asm/ucontext_x86.S | 43 ------- tile/fiber/detail/asm/ucontext_x86.h | 52 -------- tile/fiber/detail/fiber.cc | 1 - tile/fiber/detail/mutex.cc | 50 -------- tile/fiber/detail/mutex.h | 31 ----- tile/fiber/detail/ucontext.c | 58 --------- tile/fiber/detail/ucontext.h | 43 ------- 20 files changed, 1593 deletions(-) delete mode 100644 tile/fiber/detail/asm/ucontext_aarch64.S delete mode 100644 tile/fiber/detail/asm/ucontext_aarch64.h delete mode 100644 tile/fiber/detail/asm/ucontext_arm.S delete mode 100644 tile/fiber/detail/asm/ucontext_arm.h delete mode 100644 tile/fiber/detail/asm/ucontext_mips32.S delete mode 100644 tile/fiber/detail/asm/ucontext_mips32.h delete mode 100644 tile/fiber/detail/asm/ucontext_mips64.S delete mode 100644 tile/fiber/detail/asm/ucontext_mips64.h delete mode 100644 tile/fiber/detail/asm/ucontext_riscv64.S delete mode 100644 tile/fiber/detail/asm/ucontext_riscv64.h delete mode 100644 tile/fiber/detail/asm/ucontext_x64.S delete mode 100644 tile/fiber/detail/asm/ucontext_x64.h delete mode 100644 tile/fiber/detail/asm/ucontext_x86.S delete mode 100644 tile/fiber/detail/asm/ucontext_x86.h delete mode 100644 tile/fiber/detail/mutex.cc delete mode 100644 tile/fiber/detail/mutex.h delete mode 100644 tile/fiber/detail/ucontext.c delete mode 100644 tile/fiber/detail/ucontext.h diff --git a/CMakeLists.txt b/CMakeLists.txt index d1caa83..6dca3a7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -164,9 +164,6 @@ set(TILE_SRCS "tile/base/thread/scoped_lock.cc" "tile/base/thread/spinlock.cc" "tile/fiber/detail/fiber.cc" - # "tile/fiber/detail/os_fiber.cc" "tile/fiber/detail/posix_os_fiber.cc" - # "tile/fiber/detail/mutex.cc" - "tile/fiber/detail/ucontext.c" "tile/io/detail/eintr_safe.cc" "tile/io/native/acceptor.cc" "tile/io/descriptor.cc" @@ -188,18 +185,6 @@ set(TILE_SRCS # "tile/rpc/server.cc" ) -list( - APPEND - ASM_SRCS - "tile/fiber/detail/asm/ucontext_aarch64.S" - "tile/fiber/detail/asm/ucontext_arm.S" - "tile/fiber/detail/asm/ucontext_riscv64.S" - "tile/fiber/detail/asm/ucontext_mips64.S" - "tile/fiber/detail/asm/ucontext_mips32.S" - "tile/fiber/detail/asm/ucontext_x64.S" - "tile/fiber/detail/asm/ucontext_x86.S") -set_source_files_properties(${ASM_SRCS} PROPERTIES LANGUAGE C) - if((NOT TILE_HAVE_GETIFADDRS) OR (NOT TILE_HAVE_FREEIFADDRS)) list(APPEND TILE_SRCS "tile/base/net/detail/android/ifaddrs.c") endif() diff --git a/tile/fiber/detail/asm/ucontext_aarch64.S b/tile/fiber/detail/asm/ucontext_aarch64.S deleted file mode 100644 index 8c682e7..0000000 --- a/tile/fiber/detail/asm/ucontext_aarch64.S +++ /dev/null @@ -1,153 +0,0 @@ -#if defined(__aarch64__) - -#define TILE_BUILD_ASM 1 -#include "tile/fiber/detail/asm/ucontext_aarch64.h" - - -#if defined(__ARM_FEATURE_PAC_DEFAULT) && __ARM_FEATURE_PAC_DEFAULT -// ENABLE_PAUTH must be defined to 1 since this value will be used in -// bitwise-shift later! -#define ENABLE_PAUTH 1 - -#if ((__ARM_FEATURE_PAC_DEFAULT & ((1 << 0) | (1 << 1))) == 0) -#error Pointer authentication defines no valid key! -#endif -#else -#define ENABLE_PAUTH 0 -#endif - -#if defined(__ARM_FEATURE_BTI_DEFAULT) && (__ARM_FEATURE_BTI_DEFAULT == 1) -// ENABLE_BTI must be defined to 1 since this value will be used in -// bitwise-shift later! -#define ENABLE_BTI 1 -#else -#define ENABLE_BTI 0 -#endif - -// Although Pointer Authentication and Branch Target Instructions are -// technically seperate features they work together, i.e. the paciasp and -// pacibsp instructions serve as BTI landing pads. Therefore PA-instructions are -// enabled when PA _or_ BTI is enabled! -#if ENABLE_PAUTH || ENABLE_BTI -// See section "Pointer Authentication" of -// https://developer.arm.com/documentation/101028/0012/5--Feature-test-macros -// for details how to interpret __ARM_FEATURE_PAC_DEFAULT -#if (__ARM_FEATURE_PAC_DEFAULT & (1 << 0)) -#define PAUTH_SIGN_SP paciasp -#define PAUTH_AUTH_SP autiasp -#else -#define PAUTH_SIGN_SP pacibsp -#define PAUTH_AUTH_SP autibsp -#endif -#else -#define PAUTH_SIGN_SP -#define PAUTH_AUTH_SP -#endif - - -// void tile_ucontext_swap(tile_ucontext_t* from, const tile_ucontext_t* to) -// x0: from -// x1: to -.text -.global TILE_ASM_SYMBOL(tile_ucontext_swap) -// .balign 16 -.align 8 -TILE_ASM_SYMBOL(tile_ucontext_swap): - - // Save context 'from' - // TODO: pairs of str can be combined with stp. - - PAUTH_SIGN_SP - - // Store special purpose registers - str x16, [x0, #TILE_REG_r16] - str x17, [x0, #TILE_REG_r17] - str x18, [x0, #TILE_REG_r18] - - // Store callee-preserved registers - str x19, [x0, #TILE_REG_r19] - str x20, [x0, #TILE_REG_r20] - str x21, [x0, #TILE_REG_r21] - str x22, [x0, #TILE_REG_r22] - str x23, [x0, #TILE_REG_r23] - str x24, [x0, #TILE_REG_r24] - str x25, [x0, #TILE_REG_r25] - str x26, [x0, #TILE_REG_r26] - str x27, [x0, #TILE_REG_r27] - str x28, [x0, #TILE_REG_r28] - str x29, [x0, #TILE_REG_r29] - - str d8, [x0, #TILE_REG_v8] - str d9, [x0, #TILE_REG_v9] - str d10, [x0, #TILE_REG_v10] - str d11, [x0, #TILE_REG_v11] - str d12, [x0, #TILE_REG_v12] - str d13, [x0, #TILE_REG_v13] - str d14, [x0, #TILE_REG_v14] - str d15, [x0, #TILE_REG_v15] - - // Store sp and lr - mov x2, sp - str x2, [x0, #TILE_REG_SP] - str x30, [x0, #TILE_REG_LR] - - // Load context 'to' - mov x7, x1 - - // Load special purpose registers - ldr x16, [x7, #TILE_REG_r16] - ldr x17, [x7, #TILE_REG_r17] - ldr x18, [x7, #TILE_REG_r18] - - // Load callee-preserved registers - ldr x19, [x7, #TILE_REG_r19] - ldr x20, [x7, #TILE_REG_r20] - ldr x21, [x7, #TILE_REG_r21] - ldr x22, [x7, #TILE_REG_r22] - ldr x23, [x7, #TILE_REG_r23] - ldr x24, [x7, #TILE_REG_r24] - ldr x25, [x7, #TILE_REG_r25] - ldr x26, [x7, #TILE_REG_r26] - ldr x27, [x7, #TILE_REG_r27] - ldr x28, [x7, #TILE_REG_r28] - ldr x29, [x7, #TILE_REG_r29] - - ldr d8, [x7, #TILE_REG_v8] - ldr d9, [x7, #TILE_REG_v9] - ldr d10, [x7, #TILE_REG_v10] - ldr d11, [x7, #TILE_REG_v11] - ldr d12, [x7, #TILE_REG_v12] - ldr d13, [x7, #TILE_REG_v13] - ldr d14, [x7, #TILE_REG_v14] - ldr d15, [x7, #TILE_REG_v15] - - // Load parameter registers - ldr x0, [x7, #TILE_REG_r0] - ldr x1, [x7, #TILE_REG_r1] - - // Load sp and lr - ldr x30, [x7, #TILE_REG_LR] - ldr x2, [x7, #TILE_REG_SP] - mov sp, x2 - - PAUTH_AUTH_SP - - ret - -#if ENABLE_PAUTH || ENABLE_BTI -// see -// https://github.com/ARM-software/abi-aa/blob/main/aaelf64/aaelf64.rst#program-property -.pushsection .note.gnu.property, "a"; - .balign 8 - .long 4 - .long 0x10 - .long 0x5 - .asciz "GNU" - .long 0xc0000000 /* GNU_PROPERTY_AARCH64_FEATURE_1_AND */ - .long 4 - .long ((ENABLE_PAUTH)<<1) | ((ENABLE_BTI)<<0) /* PAuth and BTI */ - .long 0 -.popsection -#endif - -#endif // defined(__aarch64__) diff --git a/tile/fiber/detail/asm/ucontext_aarch64.h b/tile/fiber/detail/asm/ucontext_aarch64.h deleted file mode 100644 index b40d639..0000000 --- a/tile/fiber/detail/asm/ucontext_aarch64.h +++ /dev/null @@ -1,143 +0,0 @@ -#ifndef TILE_FIBER_DETAIL_ASM_UCONTEXT_AARCH64_H -#define TILE_FIBER_DETAIL_ASM_UCONTEXT_AARCH64_H - -#pragma once -#define TILE_REG_r0 0x00 -#define TILE_REG_r1 0x08 -#define TILE_REG_r16 0x10 -#define TILE_REG_r17 0x18 -#define TILE_REG_r18 0x20 -#define TILE_REG_r19 0x28 -#define TILE_REG_r20 0x30 -#define TILE_REG_r21 0x38 -#define TILE_REG_r22 0x40 -#define TILE_REG_r23 0x48 -#define TILE_REG_r24 0x50 -#define TILE_REG_r25 0x58 -#define TILE_REG_r26 0x60 -#define TILE_REG_r27 0x68 -#define TILE_REG_r28 0x70 -#define TILE_REG_r29 0x78 -#define TILE_REG_v8 0x80 -#define TILE_REG_v9 0x88 -#define TILE_REG_v10 0x90 -#define TILE_REG_v11 0x98 -#define TILE_REG_v12 0xa0 -#define TILE_REG_v13 0xa8 -#define TILE_REG_v14 0xb0 -#define TILE_REG_v15 0xb8 -#define TILE_REG_SP 0xc0 -#define TILE_REG_LR 0xc8 - -#if defined(__APPLE__) -#define TILE_ASM_SYMBOL(x) _##x -#else -#define TILE_ASM_SYMBOL(x) x -#endif - -#ifndef TILE_BUILD_ASM - -#include - -// Procedure Call Standard for the ARM 64-bit Architecture -// http://infocenter.arm.com/help/topic/com.arm.doc.ihi0055b/IHI0055B_aapcs64.pdf -struct tile_ucontext_t { - // parameter registers - uintptr_t r0; - uintptr_t r1; - - // special purpose registers - uintptr_t r16; - uintptr_t r17; - uintptr_t r18; // platform specific (maybe inter-procedural state) - - // callee-saved registers - uintptr_t r19; - uintptr_t r20; - uintptr_t r21; - uintptr_t r22; - uintptr_t r23; - uintptr_t r24; - uintptr_t r25; - uintptr_t r26; - uintptr_t r27; - uintptr_t r28; - uintptr_t r29; - - uintptr_t v8; - uintptr_t v9; - uintptr_t v10; - uintptr_t v11; - uintptr_t v12; - uintptr_t v13; - uintptr_t v14; - uintptr_t v15; - - uintptr_t SP; // stack pointer - uintptr_t LR; // link register (R30) -}; - -#define TILE_UCONTEXT_ARG0(ctx, stack_top) (ctx)->LR -#define TILE_UCONTEXT_ARG1(ctx, stack_top) (ctx)->r0 -#define TILE_UCONTEXT_ARG2(ctx, stack_top) (ctx)->r1 -#define TILE_UCONTEXT_ARG3(ctx, stack_top) (ctx)->SP - -#ifdef __cplusplus -#include -static_assert(offsetof(tile_ucontext_t, r0) == TILE_REG_r0, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, r1) == TILE_REG_r1, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, r16) == TILE_REG_r16, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, r17) == TILE_REG_r17, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, r18) == TILE_REG_r18, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, r19) == TILE_REG_r19, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, r20) == TILE_REG_r20, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, r21) == TILE_REG_r21, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, r22) == TILE_REG_r22, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, r23) == TILE_REG_r23, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, r24) == TILE_REG_r24, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, r25) == TILE_REG_r25, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, r26) == TILE_REG_r26, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, r27) == TILE_REG_r27, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, r28) == TILE_REG_r28, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, r29) == TILE_REG_r29, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, v8) == TILE_REG_v8, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, v9) == TILE_REG_v9, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, v10) == TILE_REG_v10, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, v11) == TILE_REG_v11, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, v12) == TILE_REG_v12, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, v13) == TILE_REG_v13, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, v14) == TILE_REG_v14, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, v15) == TILE_REG_v15, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, SP) == TILE_REG_SP, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, LR) == TILE_REG_LR, - "Bad register offset"); -#endif // __cplusplus - -#endif // TILE_BUILD_ASM - -#endif // TILE_FIBER_DETAIL_ASM_UCONTEXT_AARCH64_H diff --git a/tile/fiber/detail/asm/ucontext_arm.S b/tile/fiber/detail/asm/ucontext_arm.S deleted file mode 100644 index 0111ae6..0000000 --- a/tile/fiber/detail/asm/ucontext_arm.S +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright 2019 The Marl Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#if defined(__arm__) - -#define TILE_BUILD_ASM 1 -#include "tile/fiber/detail/asm/ucontext_arm.h" - -// void tile_ucontext_swap(tile_ucontext_t* from, const tile_ucontext_t* to) -// x0: from -// x1: to -.text -.global tile_ucontext_swap -.align 4 -.type tile_ucontext_swap, %function -tile_ucontext_swap: - - // Save context 'from' - // TODO: multiple registers can be stored in a single instruction with: stm rA, {rB-rC} - - // Store special purpose registers - str r12, [r0, #TILE_REG_r12] - - // Store callee-preserved registers - str r4, [r0, #TILE_REG_r4] - str r5, [r0, #TILE_REG_r5] - str r6, [r0, #TILE_REG_r6] - str r7, [r0, #TILE_REG_r7] - str r8, [r0, #TILE_REG_r8] - str r9, [r0, #TILE_REG_r9] - str r10, [r0, #TILE_REG_r10] - str r11, [r0, #TILE_REG_r11] - - // Store sp, lr and pc - str sp, [r0, #TILE_REG_SP] - str lr, [r0, #TILE_REG_LR] - - // Load context 'to' - // TODO: multiple registers can be loaded in a single instruction with: ldm rA, {rB-rC} - mov r3, r1 - - // Load special purpose registers - ldr r12, [r3, #TILE_REG_r12] - - // Load callee-preserved registers - ldr r4, [r3, #TILE_REG_r4] - ldr r5, [r3, #TILE_REG_r5] - ldr r6, [r3, #TILE_REG_r6] - ldr r7, [r3, #TILE_REG_r7] - ldr r8, [r3, #TILE_REG_r8] - ldr r9, [r3, #TILE_REG_r9] - ldr r10, [r3, #TILE_REG_r10] - ldr r11, [r3, #TILE_REG_r11] - - // Load parameter registers - ldr r0, [r3, #TILE_REG_r0] - ldr r1, [r3, #TILE_REG_r1] - - // Load sp, lr and pc - ldr sp, [r3, #TILE_REG_SP] - ldr lr, [r3, #TILE_REG_LR] - mov pc, lr - -#endif // defined(__arm__) diff --git a/tile/fiber/detail/asm/ucontext_arm.h b/tile/fiber/detail/asm/ucontext_arm.h deleted file mode 100644 index 3bbb3b6..0000000 --- a/tile/fiber/detail/asm/ucontext_arm.h +++ /dev/null @@ -1,110 +0,0 @@ -#define TILE_REG_r0 0x00 -#define TILE_REG_r1 0x04 -#define TILE_REG_r12 0x08 -#define TILE_REG_r4 0x0c -#define TILE_REG_r5 0x10 -#define TILE_REG_r6 0x14 -#define TILE_REG_r7 0x18 -#define TILE_REG_r8 0x1c -#define TILE_REG_r9 0x20 -#define TILE_REG_r10 0x24 -#define TILE_REG_r11 0x28 -#define TILE_REG_v8 0x2c -#define TILE_REG_v9 0x30 -#define TILE_REG_v10 0x34 -#define TILE_REG_v11 0x38 -#define TILE_REG_v12 0x3c -#define TILE_REG_v13 0x40 -#define TILE_REG_v14 0x44 -#define TILE_REG_v15 0x48 -#define TILE_REG_SP 0x4c -#define TILE_REG_LR 0x50 - -#ifndef TILE_BUILD_ASM -#include - -// Procedure Call Standard for the ARM 64-bit Architecture -// http://infocenter.arm.com/help/topic/com.arm.doc.ihi0055b/IHI0055B_aapcs64.pdf -struct tile_ucontext_t { - // parameter registers - uintptr_t r0; - uintptr_t r1; - - // special purpose registers - uintptr_t r12; // Intra-Procedure-call - - // callee-saved registers - uintptr_t r4; - uintptr_t r5; - uintptr_t r6; - uintptr_t r7; - uintptr_t r8; - uintptr_t r9; - uintptr_t r10; - uintptr_t r11; - - uintptr_t v8; - uintptr_t v9; - uintptr_t v10; - uintptr_t v11; - uintptr_t v12; - uintptr_t v13; - uintptr_t v14; - uintptr_t v15; - - uintptr_t SP; // stack pointer (r13) - uintptr_t LR; // link register (r14) -}; - -#define TILE_UCONTEXT_ARG0(ctx, stack_top) (ctx)->LR -#define TILE_UCONTEXT_ARG1(ctx, stack_top) (ctx)->r0 -#define TILE_UCONTEXT_ARG2(ctx, stack_top) (ctx)->r1 -#define TILE_UCONTEXT_ARG3(ctx, stack_top) (ctx)->SP - -#ifdef __cplusplus -#include -static_assert(offsetof(tile_ucontext_t, r0) == TILE_REG_r0, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, r1) == TILE_REG_r1, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, r12) == TILE_REG_r12, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, r4) == TILE_REG_r4, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, r5) == TILE_REG_r5, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, r6) == TILE_REG_r6, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, r7) == TILE_REG_r7, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, r8) == TILE_REG_r8, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, r9) == TILE_REG_r9, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, r10) == TILE_REG_r10, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, r11) == TILE_REG_r11, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, v8) == TILE_REG_v8, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, v9) == TILE_REG_v9, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, v10) == TILE_REG_v10, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, v11) == TILE_REG_v11, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, v12) == TILE_REG_v12, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, v13) == TILE_REG_v13, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, v14) == TILE_REG_v14, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, v15) == TILE_REG_v15, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, SP) == TILE_REG_SP, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, LR) == TILE_REG_LR, - "Bad register offset"); -#endif // __cplusplus - -#endif // TILE_BUILD_ASM diff --git a/tile/fiber/detail/asm/ucontext_mips32.S b/tile/fiber/detail/asm/ucontext_mips32.S deleted file mode 100644 index f896445..0000000 --- a/tile/fiber/detail/asm/ucontext_mips32.S +++ /dev/null @@ -1,97 +0,0 @@ -// Copyright 2020 The Marl Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#if defined(__mips__) && _MIPS_SIM == _ABIO32 - -#define TILE_BUILD_ASM 1 -#include "tile/fiber/detail/asm/ucontext_mips32.h" - -// void tile_ucontext_swap(tile_ucontext_t* from, const tile_ucontext_t* to) -// a0: from -// a1: to -.text -.global TILE_ASM_SYMBOL(tile_ucontext_swap) -.align 2 -.type TILE_ASM_SYMBOL(tile_ucontext_swap),@function -.ent TILE_ASM_SYMBOL(tile_ucontext_swap) -TILE_ASM_SYMBOL(tile_ucontext_swap): - - // Save context 'from' - - // sw $v0, TILE_REG_v0($a0) - - // Store callee-preserved registers - sw $s0, TILE_REG_s0($a0) - sw $s1, TILE_REG_s1($a0) - sw $s2, TILE_REG_s2($a0) - sw $s3, TILE_REG_s3($a0) - sw $s4, TILE_REG_s4($a0) - sw $s5, TILE_REG_s5($a0) - sw $s6, TILE_REG_s6($a0) - sw $s7, TILE_REG_s7($a0) - -#ifdef __mips_hard_float - s.d $f20, TILE_REG_f20($a0) - s.d $f22, TILE_REG_f22($a0) - s.d $f24, TILE_REG_f24($a0) - s.d $f26, TILE_REG_f26($a0) - s.d $f28, TILE_REG_f28($a0) - s.d $f30, TILE_REG_f30($a0) -#endif // __mips_hard_float - - sw $gp, TILE_REG_gp($a0) - sw $sp, TILE_REG_sp($a0) - sw $fp, TILE_REG_fp($a0) - sw $ra, TILE_REG_ra($a0) - - move $v0, $a1 // Function have no return, so safe to touch v0 - - // Recover callee-preserved registers - lw $s0, TILE_REG_s0($v0) - lw $s1, TILE_REG_s1($v0) - lw $s2, TILE_REG_s2($v0) - lw $s3, TILE_REG_s3($v0) - lw $s4, TILE_REG_s4($v0) - lw $s5, TILE_REG_s5($v0) - lw $s6, TILE_REG_s6($v0) - lw $s7, TILE_REG_s7($v0) - -#ifdef __mips_hard_float - l.d $f20, TILE_REG_f20($v0) - l.d $f22, TILE_REG_f22($v0) - l.d $f24, TILE_REG_f24($v0) - l.d $f26, TILE_REG_f26($v0) - l.d $f28, TILE_REG_f28($v0) - l.d $f30, TILE_REG_f30($v0) -#endif // __mips_hard_float - - lw $gp, TILE_REG_gp($v0) - lw $sp, TILE_REG_sp($v0) - lw $fp, TILE_REG_fp($v0) - lw $ra, TILE_REG_ra($v0) - - // Recover arguments - lw $a0, TILE_REG_a0($v0) - lw $a1, TILE_REG_a1($v0) - lw $a2, TILE_REG_a2($v0) - lw $a3, TILE_REG_a3($v0) - - // lw $v0, TILE_REG_v0($v0) - - jr $ra -.end TILE_ASM_SYMBOL(tile_ucontext_swap) -.size TILE_ASM_SYMBOL(tile_ucontext_swap), .-TILE_ASM_SYMBOL(tile_ucontext_swap) -.section .note.GNU_stack,"",%progbits - -#endif // defined(__mips__) && _MIPS_SIM == _ABIO32 diff --git a/tile/fiber/detail/asm/ucontext_mips32.h b/tile/fiber/detail/asm/ucontext_mips32.h deleted file mode 100644 index 510b7d7..0000000 --- a/tile/fiber/detail/asm/ucontext_mips32.h +++ /dev/null @@ -1,123 +0,0 @@ -#ifndef TILE_FIBER_DETAIL_ASM_UCONTEXT_MIPS32_H -#define TILE_FIBER_DETAIL_ASM_UCONTEXT_MIPS32_H - -#pragma once -#define TILE_REG_f20 0x00 -#define TILE_REG_f22 0x08 -#define TILE_REG_f24 0x10 -#define TILE_REG_f26 0x18 -#define TILE_REG_f28 0x20 -#define TILE_REG_f30 0x28 -#define TILE_REG_a0 0x30 -#define TILE_REG_a1 0x34 -#define TILE_REG_a2 0x38 -#define TILE_REG_a3 0x3C -#define TILE_REG_s0 0x40 -#define TILE_REG_s1 0x44 -#define TILE_REG_s2 0x48 -#define TILE_REG_s3 0x4C -#define TILE_REG_s4 0x50 -#define TILE_REG_s5 0x54 -#define TILE_REG_s6 0x58 -#define TILE_REG_s7 0x5C -#define TILE_REG_gp 0x60 -#define TILE_REG_sp 0x64 -#define TILE_REG_fp 0x68 -#define TILE_REG_ra 0x6C - -#if defined(__APPLE__) -#define TILE_ASM_SYMBOL(x) _##x -#else -#define TILE_ASM_SYMBOL(x) x -#endif - -#ifndef TILE_BUILD_ASM - -#include - -struct tile_ucontext_t { - double f20; - double f22; - double f24; - double f26; - double f28; - double f30; - - // parameter registers (First two) - uintptr_t a0; - uintptr_t a1; - uintptr_t a2; - uintptr_t a3; - - // callee-saved registers - uintptr_t s0; - uintptr_t s1; - uintptr_t s2; - uintptr_t s3; - uintptr_t s4; - uintptr_t s5; - uintptr_t s6; - uintptr_t s7; - - uintptr_t gp; - uintptr_t sp; - uintptr_t fp; - uintptr_t ra; -}; - -#define TILE_UCONTEXT_ARG0(ctx, stack_top) (ctx)->ra -#define TILE_UCONTEXT_ARG1(ctx, stack_top) (ctx)->a0 -#define TILE_UCONTEXT_ARG2(ctx, stack_top) (ctx)->a1 -#define TILE_UCONTEXT_ARG3(ctx, stack_top) (ctx)->sp - -#ifdef __cplusplus -#include -static_assert(offsetof(tile_ucontext_t, f20) == TILE_REG_f20, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, f22) == TILE_REG_f22, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, f24) == TILE_REG_f24, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, f26) == TILE_REG_f26, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, f28) == TILE_REG_f28, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, f30) == TILE_REG_f30, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, a0) == TILE_REG_a0, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, a1) == TILE_REG_a1, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, a2) == TILE_REG_a2, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, a3) == TILE_REG_a3, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, s0) == TILE_REG_s0, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, s1) == TILE_REG_s1, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, s2) == TILE_REG_s2, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, s3) == TILE_REG_s3, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, s4) == TILE_REG_s4, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, s5) == TILE_REG_s5, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, s6) == TILE_REG_s6, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, s7) == TILE_REG_s7, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, gp) == TILE_REG_gp, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, sp) == TILE_REG_sp, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, fp) == TILE_REG_fp, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, ra) == TILE_REG_ra, - "Bad register offset"); -#endif // __cplusplus - -#endif // TILE_BUILD_ASM - -#endif // TILE_FIBER_DETAIL_ASM_UCONTEXT_MIPS32_H diff --git a/tile/fiber/detail/asm/ucontext_mips64.S b/tile/fiber/detail/asm/ucontext_mips64.S deleted file mode 100644 index 28fbaea..0000000 --- a/tile/fiber/detail/asm/ucontext_mips64.S +++ /dev/null @@ -1,95 +0,0 @@ -// Copyright 2020 The Marl Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#if defined(__mips__) && _MIPS_SIM == _ABI64 - -#define TILE_BUILD_ASM 1 -#include "tile/fiber/detail/asm/ucontext_mips64.h" - -// void tile_ucontext_swap(tile_ucontext_t* from, const tile_ucontext_t* to) -// a0: from -// a1: to -.text -.global TILE_ASM_SYMBOL(tile_ucontext_swap) -.align 4 -.type TILE_ASM_SYMBOL(tile_ucontext_swap), @function -.ent TILE_ASM_SYMBOL(tile_ucontext_swap) -TILE_ASM_SYMBOL(tile_ucontext_swap): - - // Save context 'from' - - // Store callee-preserved registers - sd $s0, TILE_REG_s0($a0) - sd $s1, TILE_REG_s1($a0) - sd $s2, TILE_REG_s2($a0) - sd $s3, TILE_REG_s3($a0) - sd $s4, TILE_REG_s4($a0) - sd $s5, TILE_REG_s5($a0) - sd $s6, TILE_REG_s6($a0) - sd $s7, TILE_REG_s7($a0) - -#ifdef __mips_hard_float - s.d $f24, TILE_REG_f24($a0) - s.d $f25, TILE_REG_f25($a0) - s.d $f26, TILE_REG_f26($a0) - s.d $f27, TILE_REG_f27($a0) - s.d $f28, TILE_REG_f28($a0) - s.d $f29, TILE_REG_f29($a0) - s.d $f31, TILE_REG_f30($a0) - s.d $f31, TILE_REG_f31($a0) -#endif // __mips_hard_float - - sd $gp, TILE_REG_gp($a0) - sd $sp, TILE_REG_sp($a0) - sd $fp, TILE_REG_fp($a0) - sd $ra, TILE_REG_ra($a0) - - move $v0, $a1 // Function have no return, so safe to touch v0 - - // Recover callee-preserved registers - ld $s0, TILE_REG_s0($v0) - ld $s1, TILE_REG_s1($v0) - ld $s2, TILE_REG_s2($v0) - ld $s3, TILE_REG_s3($v0) - ld $s4, TILE_REG_s4($v0) - ld $s5, TILE_REG_s5($v0) - ld $s6, TILE_REG_s6($v0) - ld $s7, TILE_REG_s7($v0) - -#ifdef __mips_hard_float - l.d $f24, TILE_REG_f24($v0) - l.d $f25, TILE_REG_f25($v0) - l.d $f26, TILE_REG_f26($v0) - l.d $f27, TILE_REG_f27($v0) - l.d $f28, TILE_REG_f28($v0) - l.d $f29, TILE_REG_f29($v0) - l.d $f31, TILE_REG_f30($v0) - l.d $f31, TILE_REG_f31($v0) -#endif // __mips_hard_float - - ld $gp, TILE_REG_gp($v0) - ld $sp, TILE_REG_sp($v0) - ld $fp, TILE_REG_fp($v0) - ld $ra, TILE_REG_ra($v0) - - // Recover arguments - ld $a0, TILE_REG_a0($v0) - ld $a1, TILE_REG_a1($v0) - - jr $ra -.end TILE_ASM_SYMBOL(tile_ucontext_swap) -.size TILE_ASM_SYMBOL(tile_ucontext_swap), .-TILE_ASM_SYMBOL(tile_ucontext_swap) -.section .note.GNU-stack,"",%progbits - -#endif // defined(__mips__) && _MIPS_SIM == _ABI64 diff --git a/tile/fiber/detail/asm/ucontext_mips64.h b/tile/fiber/detail/asm/ucontext_mips64.h deleted file mode 100644 index 5573ce1..0000000 --- a/tile/fiber/detail/asm/ucontext_mips64.h +++ /dev/null @@ -1,123 +0,0 @@ -#ifndef TILE_FIBER_DETAIL_ASM_UCONTEXT_MIPS64_H -#define TILE_FIBER_DETAIL_ASM_UCONTEXT_MIPS64_H - -#pragma once -#define TILE_REG_a0 0x00 -#define TILE_REG_a1 0x08 -#define TILE_REG_s0 0x10 -#define TILE_REG_s1 0x18 -#define TILE_REG_s2 0x20 -#define TILE_REG_s3 0x28 -#define TILE_REG_s4 0x30 -#define TILE_REG_s5 0x38 -#define TILE_REG_s6 0x40 -#define TILE_REG_s7 0x48 -#define TILE_REG_f24 0x50 -#define TILE_REG_f25 0x58 -#define TILE_REG_f26 0x60 -#define TILE_REG_f27 0x68 -#define TILE_REG_f28 0x70 -#define TILE_REG_f29 0x78 -#define TILE_REG_f30 0x80 -#define TILE_REG_f31 0x88 -#define TILE_REG_gp 0x90 -#define TILE_REG_sp 0x98 -#define TILE_REG_fp 0xa0 -#define TILE_REG_ra 0xa8 - -#if defined(__APPLE__) -#define TILE_ASM_SYMBOL(x) _##x -#else -#define TILE_ASM_SYMBOL(x) x -#endif - -#ifndef TILE_BUILD_ASM - -#include - -struct tile_ucontext_t { - // parameter registers (First two) - uintptr_t a0; - uintptr_t a1; - - // callee-saved registers - uintptr_t s0; - uintptr_t s1; - uintptr_t s2; - uintptr_t s3; - uintptr_t s4; - uintptr_t s5; - uintptr_t s6; - uintptr_t s7; - - uintptr_t f24; - uintptr_t f25; - uintptr_t f26; - uintptr_t f27; - uintptr_t f28; - uintptr_t f29; - uintptr_t f30; - uintptr_t f31; - - uintptr_t gp; - uintptr_t sp; - uintptr_t fp; - uintptr_t ra; -}; - -#define TILE_UCONTEXT_ARG0(ctx, stack_top) (ctx)->ra -#define TILE_UCONTEXT_ARG1(ctx, stack_top) (ctx)->a0 -#define TILE_UCONTEXT_ARG2(ctx, stack_top) (ctx)->a1 -#define TILE_UCONTEXT_ARG3(ctx, stack_top) (ctx)->sp - -#ifdef __cplusplus -#include -static_assert(offsetof(tile_ucontext_t, a0) == TILE_REG_a0, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, a1) == TILE_REG_a1, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, s0) == TILE_REG_s0, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, s1) == TILE_REG_s1, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, s2) == TILE_REG_s2, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, s3) == TILE_REG_s3, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, s4) == TILE_REG_s4, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, s5) == TILE_REG_s5, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, s6) == TILE_REG_s6, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, s7) == TILE_REG_s7, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, f24) == TILE_REG_f24, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, f25) == TILE_REG_f25, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, f26) == TILE_REG_f26, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, f27) == TILE_REG_f27, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, f28) == TILE_REG_f28, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, f29) == TILE_REG_f29, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, f30) == TILE_REG_f30, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, f31) == TILE_REG_f31, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, gp) == TILE_REG_gp, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, sp) == TILE_REG_sp, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, fp) == TILE_REG_fp, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, ra) == TILE_REG_ra, - "Bad register offset"); -#endif // __cplusplus - -#endif // TILE_BUILD_ASM - -#endif // TILE_FIBER_DETAIL_ASM_UCONTEXT_MIPS64_H diff --git a/tile/fiber/detail/asm/ucontext_riscv64.S b/tile/fiber/detail/asm/ucontext_riscv64.S deleted file mode 100644 index b5298ec..0000000 --- a/tile/fiber/detail/asm/ucontext_riscv64.S +++ /dev/null @@ -1,100 +0,0 @@ -// Copyright 2021 The Marl Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#if defined(__riscv) && __riscv_xlen == 64 - -#define TILE_BUILD_ASM 1 -#include "tile/fiber/detail/asm/ucontext_riscv64.h" - -// void tile_ucontext_swap(tile_ucontext_t* from, const tile_ucontext_t* to) -// a0: from -// a1: to -.text -.global tile_ucontext_swap -.align 4 -tile_ucontext_swap: - - // Save context 'from' - - // Store callee-preserved registers - sd s0, TILE_REG_s0(a0) - sd s1, TILE_REG_s1(a0) - sd s2, TILE_REG_s2(a0) - sd s3, TILE_REG_s3(a0) - sd s4, TILE_REG_s4(a0) - sd s5, TILE_REG_s5(a0) - sd s6, TILE_REG_s6(a0) - sd s7, TILE_REG_s7(a0) - sd s8, TILE_REG_s8(a0) - sd s9, TILE_REG_s9(a0) - sd s10, TILE_REG_s10(a0) - sd s11, TILE_REG_s11(a0) - - fsd fs0, TILE_REG_fs0(a0) - fsd fs1, TILE_REG_fs1(a0) - fsd fs2, TILE_REG_fs2(a0) - fsd fs3, TILE_REG_fs3(a0) - fsd fs4, TILE_REG_fs4(a0) - fsd fs5, TILE_REG_fs5(a0) - fsd fs6, TILE_REG_fs6(a0) - fsd fs7, TILE_REG_fs7(a0) - fsd fs8, TILE_REG_fs8(a0) - fsd fs9, TILE_REG_fs9(a0) - fsd fs10, TILE_REG_fs10(a0) - fsd fs11, TILE_REG_fs11(a0) - - sd sp, TILE_REG_sp(a0) - // On RISC-V ra is caller-saved - // but we need ra to jump to the trampoline - sd ra, TILE_REG_ra(a0) - - move t0, a1 // Store a1 in temporary register - - // Recover callee-preserved registers - ld s0, TILE_REG_s0(t0) - ld s1, TILE_REG_s1(t0) - ld s2, TILE_REG_s2(t0) - ld s3, TILE_REG_s3(t0) - ld s4, TILE_REG_s4(t0) - ld s5, TILE_REG_s5(t0) - ld s6, TILE_REG_s6(t0) - ld s7, TILE_REG_s7(t0) - ld s8, TILE_REG_s8(t0) - ld s9, TILE_REG_s9(t0) - ld s10, TILE_REG_s10(t0) - ld s11, TILE_REG_s11(t0) - - fld fs0, TILE_REG_fs0(t0) - fld fs1, TILE_REG_fs1(t0) - fld fs2, TILE_REG_fs2(t0) - fld fs3, TILE_REG_fs3(t0) - fld fs4, TILE_REG_fs4(t0) - fld fs5, TILE_REG_fs5(t0) - fld fs6, TILE_REG_fs6(t0) - fld fs7, TILE_REG_fs7(t0) - fld fs8, TILE_REG_fs8(t0) - fld fs9, TILE_REG_fs9(t0) - fld fs10, TILE_REG_fs10(t0) - fld fs11, TILE_REG_fs11(t0) - - ld sp, TILE_REG_sp(t0) - ld ra, TILE_REG_ra(t0) - - // Recover arguments - ld a0, TILE_REG_a0(t0) - ld a1, TILE_REG_a1(t0) - - jr ra // Jump to the trampoline - -#endif // defined(__riscv) && __riscv_xlen == 64 diff --git a/tile/fiber/detail/asm/ucontext_riscv64.h b/tile/fiber/detail/asm/ucontext_riscv64.h deleted file mode 100644 index 5a058ef..0000000 --- a/tile/fiber/detail/asm/ucontext_riscv64.h +++ /dev/null @@ -1,141 +0,0 @@ -#ifndef TILE_FIBER_DETAIL_ASM_UCONTEXT_RISCV64_H -#define TILE_FIBER_DETAIL_ASM_UCONTEXT_RISCV64_H - -#pragma once -#define TILE_REG_a0 0x00 -#define TILE_REG_a1 0x08 -#define TILE_REG_s0 0x10 -#define TILE_REG_s1 0x18 -#define TILE_REG_s2 0x20 -#define TILE_REG_s3 0x28 -#define TILE_REG_s4 0x30 -#define TILE_REG_s5 0x38 -#define TILE_REG_s6 0x40 -#define TILE_REG_s7 0x48 -#define TILE_REG_s8 0x50 -#define TILE_REG_s9 0x58 -#define TILE_REG_s10 0x60 -#define TILE_REG_s11 0x68 -#define TILE_REG_fs0 0x70 -#define TILE_REG_fs1 0x78 -#define TILE_REG_fs2 0x80 -#define TILE_REG_fs3 0x88 -#define TILE_REG_fs4 0x90 -#define TILE_REG_fs5 0x98 -#define TILE_REG_fs6 0xa0 -#define TILE_REG_fs7 0xa8 -#define TILE_REG_fs8 0xb0 -#define TILE_REG_fs9 0xb8 -#define TILE_REG_fs10 0xc0 -#define TILE_REG_fs11 0xc8 -#define TILE_REG_sp 0xd0 -#define TILE_REG_ra 0xd8 - -#ifndef TILE_BUILD_ASM - -#include - -struct tile_ucontext_t { - // parameter registers (First two) - uintptr_t a0; - uintptr_t a1; - - // callee-saved registers - uintptr_t s0; - uintptr_t s1; - uintptr_t s2; - uintptr_t s3; - uintptr_t s4; - uintptr_t s5; - uintptr_t s6; - uintptr_t s7; - uintptr_t s8; - uintptr_t s9; - uintptr_t s10; - uintptr_t s11; - - uintptr_t fs0; - uintptr_t fs1; - uintptr_t fs2; - uintptr_t fs3; - uintptr_t fs4; - uintptr_t fs5; - uintptr_t fs6; - uintptr_t fs7; - uintptr_t fs8; - uintptr_t fs9; - uintptr_t fs10; - uintptr_t fs11; - - uintptr_t sp; - uintptr_t ra; -}; - -#define TILE_UCONTEXT_ARG0(ctx, stack_top) (ctx)->ra -#define TILE_UCONTEXT_ARG1(ctx, stack_top) (ctx)->a0 -#define TILE_UCONTEXT_ARG2(ctx, stack_top) (ctx)->a1 -#define TILE_UCONTEXT_ARG3(ctx, stack_top) (ctx)->sp - -#ifdef __cplusplus -#include -static_assert(offsetof(tile_ucontext_t, a0) == TILE_REG_a0, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, a1) == TILE_REG_a1, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, s0) == TILE_REG_s0, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, s1) == TILE_REG_s1, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, s2) == TILE_REG_s2, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, s3) == TILE_REG_s3, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, s4) == TILE_REG_s4, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, s5) == TILE_REG_s5, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, s6) == TILE_REG_s6, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, s7) == TILE_REG_s7, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, s8) == TILE_REG_s8, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, s9) == TILE_REG_s9, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, s10) == TILE_REG_s10, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, s11) == TILE_REG_s11, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, fs0) == TILE_REG_fs0, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, fs1) == TILE_REG_fs1, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, fs2) == TILE_REG_fs2, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, fs3) == TILE_REG_fs3, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, fs4) == TILE_REG_fs4, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, fs5) == TILE_REG_fs5, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, fs6) == TILE_REG_fs6, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, fs7) == TILE_REG_fs7, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, fs8) == TILE_REG_fs8, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, fs9) == TILE_REG_fs9, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, fs10) == TILE_REG_fs10, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, fs11) == TILE_REG_fs11, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, sp) == TILE_REG_sp, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, ra) == TILE_REG_ra, - "Bad register offset"); -#endif // __cplusplus - -#endif // TILE_BUILD_ASM - -#endif // TILE_FIBER_DETAIL_ASM_UCONTEXT_RISCV64_H diff --git a/tile/fiber/detail/asm/ucontext_x64.S b/tile/fiber/detail/asm/ucontext_x64.S deleted file mode 100644 index 3c1e4f0..0000000 --- a/tile/fiber/detail/asm/ucontext_x64.S +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright 2019 The Marl Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#if defined(__x86_64__) - -#define TILE_BUILD_ASM 1 -#include "tile/fiber/detail/asm/ucontext_x64.h" - -// void tile_ucontext_swap(tile_ucontext_t* from, const tile_ucontext_t* to) -// rdi: from -// rsi: to -.text -.global TILE_ASM_SYMBOL(tile_ucontext_swap) -.align 4 -TILE_ASM_SYMBOL(tile_ucontext_swap): - - // Save context 'from' - - // Store callee-preserved registers - movq %rbx, TILE_REG_RBX(%rdi) - movq %rbp, TILE_REG_RBP(%rdi) - movq %r12, TILE_REG_R12(%rdi) - movq %r13, TILE_REG_R13(%rdi) - movq %r14, TILE_REG_R14(%rdi) - movq %r15, TILE_REG_R15(%rdi) - - movq (%rsp), %rcx /* call stores the return address on the stack before jumping */ - movq %rcx, TILE_REG_RIP(%rdi) - leaq 8(%rsp), %rcx /* skip the pushed return address */ - movq %rcx, TILE_REG_RSP(%rdi) - - // Load context 'to' - movq %rsi, %r8 - - // Load callee-preserved registers - movq TILE_REG_RBX(%r8), %rbx - movq TILE_REG_RBP(%r8), %rbp - movq TILE_REG_R12(%r8), %r12 - movq TILE_REG_R13(%r8), %r13 - movq TILE_REG_R14(%r8), %r14 - movq TILE_REG_R15(%r8), %r15 - - // Load first two call parameters - movq TILE_REG_RDI(%r8), %rdi - movq TILE_REG_RSI(%r8), %rsi - - // Load stack pointer - movq TILE_REG_RSP(%r8), %rsp - - // Load instruction pointer, and jump - movq TILE_REG_RIP(%r8), %rcx - jmp *%rcx - -#endif // defined(__x86_64__) diff --git a/tile/fiber/detail/asm/ucontext_x64.h b/tile/fiber/detail/asm/ucontext_x64.h deleted file mode 100644 index 369a246..0000000 --- a/tile/fiber/detail/asm/ucontext_x64.h +++ /dev/null @@ -1,75 +0,0 @@ -#ifndef TILE_FIBER_DETAIL_ASM_UCONTEXT_X64_H -#define TILE_FIBER_DETAIL_ASM_UCONTEXT_X64_H - -#pragma once -#define TILE_REG_RBX 0x00 -#define TILE_REG_RBP 0x08 -#define TILE_REG_R12 0x10 -#define TILE_REG_R13 0x18 -#define TILE_REG_R14 0x20 -#define TILE_REG_R15 0x28 -#define TILE_REG_RDI 0x30 -#define TILE_REG_RSI 0x38 -#define TILE_REG_RSP 0x40 -#define TILE_REG_RIP 0x48 - -#if defined(__APPLE__) -#define TILE_ASM_SYMBOL(x) _##x -#else -#define TILE_ASM_SYMBOL(x) x -#endif - -#ifndef TILE_BUILD_ASM - -#include - -struct tile_ucontext_t { - // callee-saved registers - uintptr_t RBX; - uintptr_t RBP; - uintptr_t R12; - uintptr_t R13; - uintptr_t R14; - uintptr_t R15; - - // parameter registers - uintptr_t RDI; - uintptr_t RSI; - - // stack and instruction registers - uintptr_t RSP; - uintptr_t RIP; -}; - -#define TILE_UCONTEXT_ARG0(ctx, stack_top) (ctx)->RIP -#define TILE_UCONTEXT_ARG1(ctx, stack_top) (ctx)->RDI -#define TILE_UCONTEXT_ARG2(ctx, stack_top) (ctx)->RSI -#define TILE_UCONTEXT_ARG3(ctx, stack_top) (ctx)->RSP - -#ifdef __cplusplus -#include -static_assert(offsetof(tile_ucontext_t, RBX) == TILE_REG_RBX, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, RBP) == TILE_REG_RBP, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, R12) == TILE_REG_R12, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, R13) == TILE_REG_R13, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, R14) == TILE_REG_R14, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, R15) == TILE_REG_R15, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, RDI) == TILE_REG_RDI, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, RSI) == TILE_REG_RSI, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, RSP) == TILE_REG_RSP, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, RIP) == TILE_REG_RIP, - "Bad register offset"); -#endif // __cplusplus - -#endif // TILE_BUILD_ASM - -#endif // TILE_FIBER_DETAIL_ASM_UCONTEXT_X64_H diff --git a/tile/fiber/detail/asm/ucontext_x86.S b/tile/fiber/detail/asm/ucontext_x86.S deleted file mode 100644 index 5260f85..0000000 --- a/tile/fiber/detail/asm/ucontext_x86.S +++ /dev/null @@ -1,43 +0,0 @@ -#if defined(__i386__) - -#define TILE_BUILD_ASM 1 -#include "tile/fiber/detail/asm/ucontext_x86.h" - -// void tile_ucontext_swap(tile_ucontext_context* from, const tile_ucontext_context* to) -// esp+4: from -// esp+8: to -.text -.global tile_ucontext_swap -.align 4 -tile_ucontext_swap: - // Save context 'from' - movl 4(%esp), %eax - - // Store callee-preserved registers - movl %ebx, TILE_REG_EBX(%eax) - movl %ebp, TILE_REG_EBP(%eax) - movl %esi, TILE_REG_ESI(%eax) - movl %edi, TILE_REG_EDI(%eax) - - movl (%esp), %ecx /* call stores the return address on the stack before jumping */ - movl %ecx, TILE_REG_EIP(%eax) - lea 4(%esp), %ecx /* skip the pushed return address */ - movl %ecx, TILE_REG_ESP(%eax) - - // Load context 'to' - movl 8(%esp), %ecx - - // Load callee-preserved registers - movl TILE_REG_EBX(%ecx), %ebx - movl TILE_REG_EBP(%ecx), %ebp - movl TILE_REG_ESI(%ecx), %esi - movl TILE_REG_EDI(%ecx), %edi - - // Load stack pointer - movl TILE_REG_ESP(%ecx), %esp - - // Load instruction pointer, and jump - movl TILE_REG_EIP(%ecx), %ecx - jmp *%ecx - -#endif // defined(__i386__) diff --git a/tile/fiber/detail/asm/ucontext_x86.h b/tile/fiber/detail/asm/ucontext_x86.h deleted file mode 100644 index 3d4e9d6..0000000 --- a/tile/fiber/detail/asm/ucontext_x86.h +++ /dev/null @@ -1,52 +0,0 @@ -#ifndef TILE_FIBER_DETAIL_ASM_UCONTEXT_X86_H -#define TILE_FIBER_DETAIL_ASM_UCONTEXT_X86_H - -#pragma once -#define TILE_REG_EBX 0x00 -#define TILE_REG_EBP 0x04 -#define TILE_REG_ESI 0x08 -#define TILE_REG_EDI 0x0c -#define TILE_REG_ESP 0x10 -#define TILE_REG_EIP 0x14 - -#ifndef TILE_BUILD_ASM -#include - -// Assumes cdecl calling convention. -// Registers EAX, ECX, and EDX are caller-saved, and the rest are callee-saved. -struct tile_ucontext_t { - // callee-saved registers - uintptr_t EBX; - uintptr_t EBP; - uintptr_t ESI; - uintptr_t EDI; - - // stack and instruction registers - uintptr_t ESP; - uintptr_t EIP; -}; - -#define TILE_UCONTEXT_ARG0(ctx, stack_top) (ctx)->EIP -#define TILE_UCONTEXT_ARG1(ctx, stack_top) (ctx)->ESP -#define TILE_UCONTEXT_ARG2(ctx, stack_top) (stack_top)[-3] -#define TILE_UCONTEXT_ARG3(ctx, stack_top) (stack_top)[-4] - -#ifdef __cplusplus -#include -static_assert(offsetof(tile_ucontext_t, EBX) == TILE_REG_EBX, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, EBP) == TILE_REG_EBP, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, ESI) == TILE_REG_ESI, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, EDI) == TILE_REG_EDI, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, ESP) == TILE_REG_ESP, - "Bad register offset"); -static_assert(offsetof(tile_ucontext_t, EIP) == TILE_REG_EIP, - "Bad register offset"); -#endif // __cplusplus - -#endif // TILE_BUILD_ASM - -#endif // TILE_FIBER_DETAIL_ASM_UCONTEXT_X86_H diff --git a/tile/fiber/detail/fiber.cc b/tile/fiber/detail/fiber.cc index b49ef22..6757326 100644 --- a/tile/fiber/detail/fiber.cc +++ b/tile/fiber/detail/fiber.cc @@ -5,7 +5,6 @@ #include "tile/base/logging.h" #include "tile/base/make_unique.h" #include "tile/base/object_pool.h" -#include "tile/fiber/detail/ucontext.h" #include "nova/context/fcontext.h" diff --git a/tile/fiber/detail/mutex.cc b/tile/fiber/detail/mutex.cc deleted file mode 100644 index 14ad60b..0000000 --- a/tile/fiber/detail/mutex.cc +++ /dev/null @@ -1,50 +0,0 @@ -#include "tile/fiber/detail/mutex.h" -#include "tile/base/thread/unique_lock.h" -#include "tile/fiber/detail/os_fiber.h" - -namespace tile { -namespace fiber { -namespace detail { -void Mutex::Lock() { - TILE_DCHECK(detail::IsFiberEnv()); - if (TILE_LIKELY(TryLock())) { - return; - } - LockSlow(); -} -bool Mutex::TryLock() { - TILE_DCHECK(detail::IsFiberEnv()); - std::uint32_t expected = 0; - return count_.compare_exchange_strong(expected, 1, std::memory_order_acquire); -} -void Mutex::Unlock() { - TILE_CHECK(detail::IsFiberEnv()); - auto was = count_.fetch_sub(1, std::memory_order_release); - if (was == 1) { - // lock success. - } else { - TILE_CHECK_GT(was, 1); - - UniqueLock splk(slow_path_lock_); - splk.Unlock(); - } -} -void Mutex::LockSlow() { - TILE_DCHECK(detail::IsFiberEnv()); - if (TryLock()) { - // lock success. - return; - } - - UniqueLock splk(slow_path_lock_); - if (count_.fetch_add(1, std::memory_order_acquire) == 0) { - // lock success. - return; - } - - auto current = detail::OSFiber::Current(); -} - -} // namespace detail -} // namespace fiber -} // namespace tile diff --git a/tile/fiber/detail/mutex.h b/tile/fiber/detail/mutex.h deleted file mode 100644 index 923e060..0000000 --- a/tile/fiber/detail/mutex.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef TILE_FIBER_MUTEX_H -#define TILE_FIBER_MUTEX_H - -#pragma once -#include "tile/base/logging.h" -#include "tile/base/thread/spinlock.h" -#include - -namespace tile { -namespace fiber { -namespace detail { - -class Mutex { -public: - void Lock(); - bool TryLock(); - void Unlock(); - -private: - void LockSlow(); - -private: - Spinlock slow_path_lock_; - std::atomic count_{0}; -}; - -} // namespace detail -} // namespace fiber -} // namespace tile - -#endif // TILE_FIBER_MUTEX_H diff --git a/tile/fiber/detail/ucontext.c b/tile/fiber/detail/ucontext.c deleted file mode 100644 index f512513..0000000 --- a/tile/fiber/detail/ucontext.c +++ /dev/null @@ -1,58 +0,0 @@ -#include "tile/fiber/detail/ucontext.h" -#include -#include - -#if defined(linux) || defined(__linux) || defined(__linux__) -#if defined(__aaarch64__) -#define TILE_USE_HWASAN 1 -#endif -#endif -#ifndef TILE_USE_HWASAN -#define TILE_USE_HWASAN 0 -#endif - -// __attribute__((weak)) doesn't work on MacOS. -#if TILE_USE_HWASAN -// This is needed for HWSAan runtimes that don't have this commit: -// https://reviews.llvm.org/D149228. -__attribute__((weak)) void __hwasan_tag_memory(const volatile void *p, - unsigned char tag, size_t size); -__attribute((weak)) void *__hwasan_tag_pointer(const volatile void *p, - unsigned char tag); -#endif - -void tile_ucontext_trampoline(void (*target)(void *), void *arg) { - target(arg); -} - -void tile_ucontext_set_target(struct tile_ucontext_t *ctx, void *stack, - uint32_t stack_size, void (*target)(void *), - void *arg) { -#if TILE_USE_HWASAN - if (__hwasan_tag_memory && __hwasan_tag_pointer) { - stack = __hwasan_tag_pointer(stack, 0); - __hwasan_tag_memory(stack, 0, stack_size); - } -#endif - uintptr_t *stack_top = (uintptr_t *)((uint8_t *)(stack) + stack_size); - assert(((uintptr_t)stack_top & 15) == 0); - -#if defined(__x86_64__) - TILE_UCONTEXT_ARG0(ctx, stack_top) = (uintptr_t)&tile_ucontext_trampoline; - TILE_UCONTEXT_ARG1(ctx, stack_top) = (uintptr_t)target; - TILE_UCONTEXT_ARG2(ctx, stack_top) = (uintptr_t)arg; - TILE_UCONTEXT_ARG3(ctx, stack_top) = (uintptr_t)&stack_top[-3]; - stack_top[-2] = 0; // no return -#elif defined(__i386__) - TILE_UCONTEXT_ARG0(ctx, stack_top) = (uintptr_t)&tile_ucontext_trampoline; - TILE_UCONTEXT_ARG1(ctx, stack_top) = (uintptr_t)&stack_top[-5]; - TILE_UCONTEXT_ARG2(ctx, stack_top) = (uintptr_t)arg; - TILE_UCONTEXT_ARG3(ctx, stack_top) = (uintptr_t)target; - stack_top[-5] = 0; // no return -#else - TILE_UCONTEXT_ARG0(ctx, stack_top) = (uintptr_t)&tile_ucontext_trampoline; - TILE_UCONTEXT_ARG1(ctx, stack_top) = (uintptr_t)target; - TILE_UCONTEXT_ARG2(ctx, stack_top) = (uintptr_t)arg; - TILE_UCONTEXT_ARG3(ctx, stack_top) = (uintptr_t)&stack_top; -#endif -} diff --git a/tile/fiber/detail/ucontext.h b/tile/fiber/detail/ucontext.h deleted file mode 100644 index 34369ff..0000000 --- a/tile/fiber/detail/ucontext.h +++ /dev/null @@ -1,43 +0,0 @@ -#ifndef TILE_FIBER_DETAIL_UCONTEXT_H -#define TILE_FIBER_DETAIL_UCONTEXT_H - -#pragma once - -#include "tile/base/internal/macro.h" -#include - -#define HAVE_TILE_UCONTEXT 1 -#if defined(__x86_64__) -#include "tile/fiber/detail/asm/ucontext_x64.h" -#elif defined(__i386__) -#include "tile/fiber/detail/asm/ucontext_x86.h" -#elif defined(__aarch64__) -#include "tile/fiber/detail/asm/ucontext_aarch64.h" -#elif defined(__arm__) -#include "tile/fiber/detail/asm/ucontext_arm.h" -#elif defined(__mips__) && _MIPS_SIM == _ABI64 -#include "tile/fiber/detail/asm/ucontext_mips64.h" -#elif defined(__mips__) && _MIPS_SIM == _ABIO32 -#include "tile/fiber/detail/asm/ucontext_mips32.h" -#elif defined(__riscv) && __riscv_xlen == 64 -#include "tile/fiber/detail/asm/ucontext_riscv64.h" -#else -#undef HAVE_TILE_UCONTEXT -#define HAVE_TILE_UCONTEXT 0 -#Error "Unsupported architecture" -#endif - -#if defined(__cplusplus) -extern "C" { -#endif - -void tile_ucontext_set_target(struct tile_ucontext_t *, void *stack_ptr, - uint32_t stack_szie, void (*target)(void *), - void *arg); -void tile_ucontext_swap(struct tile_ucontext_t *from, - struct tile_ucontext_t *to); -#if defined(__cplusplus) -} -#endif - -#endif // TILE_FIBER_DETAIL_UCONTEXT_H From 6229d0db144bf977a899c3366078800aaeeac43d Mon Sep 17 00:00:00 2001 From: tqcq <99722391+tqcq@users.noreply.github.com> Date: Wed, 12 Jun 2024 22:52:23 +0800 Subject: [PATCH 12/56] feat adjust stack_size = 128k --- tile/fiber/detail/fiber.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tile/fiber/detail/fiber.cc b/tile/fiber/detail/fiber.cc index 6757326..49be635 100644 --- a/tile/fiber/detail/fiber.cc +++ b/tile/fiber/detail/fiber.cc @@ -15,7 +15,7 @@ namespace detail { static thread_local Fiber *tls_current_fiber = nullptr; static thread_local Fiber *tls_master_fiber = nullptr; -constexpr std::size_t kStackSize = 8192; +constexpr std::size_t kStackSize = 128 * 1024; // 128k constexpr std::size_t kAlignSize = 16; void FiberEntry(fcontext_transfer_t t) { From 10a4e047e6d6219a4074058099c0d60de6203b6a Mon Sep 17 00:00:00 2001 From: tqcq <99722391+tqcq@users.noreply.github.com> Date: Thu, 13 Jun 2024 11:07:14 +0800 Subject: [PATCH 13/56] fix boxed use monostate --- tile/base/future/boxed.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tile/base/future/boxed.h b/tile/base/future/boxed.h index 2a0dcfc..fb2c70c 100644 --- a/tile/base/future/boxed.h +++ b/tile/base/future/boxed.h @@ -86,7 +86,7 @@ private: } private: - std::variant holding_; + std::variant holding_; }; static_assert(std::is_void>().Get())>::value, ""); From 27d8c675b6d82c714af8eb8cc86202931faac1d0 Mon Sep 17 00:00:00 2001 From: tqcq <99722391+tqcq@users.noreply.github.com> Date: Thu, 13 Jun 2024 13:17:08 +0800 Subject: [PATCH 14/56] feat use C11 --- CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6dca3a7..7b2f669 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,6 +13,9 @@ set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) +set(CMAKE_C_STANDARD 11) +set(CMAKE_C_STANDARD_REQUIRED ON) + set(CMAKE_POSITION_INDEPENDENT_CODE ON) option(TILE_BUILD_TESTS "Build tests" OFF) From 79eea2680e163ee13e887c05e52147fd42fa4a43 Mon Sep 17 00:00:00 2001 From: tqcq <99722391+tqcq@users.noreply.github.com> Date: Thu, 13 Jun 2024 13:19:24 +0800 Subject: [PATCH 15/56] feat use C99 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7b2f669..9859564 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,7 +13,7 @@ set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) -set(CMAKE_C_STANDARD 11) +set(CMAKE_C_STANDARD 99) set(CMAKE_C_STANDARD_REQUIRED ON) set(CMAKE_POSITION_INDEPENDENT_CODE ON) From 25c5bcbef9f2751520800150ac7d12d8c8188b45 Mon Sep 17 00:00:00 2001 From: tqcq <99722391+tqcq@users.noreply.github.com> Date: Thu, 13 Jun 2024 13:25:34 +0800 Subject: [PATCH 16/56] remove uint32 --- third_party/gflags/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/third_party/gflags/CMakeLists.txt b/third_party/gflags/CMakeLists.txt index 5a7ebb5..bee810d 100644 --- a/third_party/gflags/CMakeLists.txt +++ b/third_party/gflags/CMakeLists.txt @@ -297,7 +297,7 @@ gflags_define( "Format of integer types: \"C99\" (uint32_t), \"BSD\" (u_int32_t), \"VC7\" (__int32)" "") gflags_property(INTTYPES_FORMAT STRINGS "C99;BSD;VC7") -gflags_property(INTTYPES_FORMAT ADVANCED TRUE) +gflags_property(INTTYPES_FORMAT ADVANCED FALSE) if(NOT INTTYPES_FORMAT) set(TYPES uint32_t u_int32_t) if(MSVC) From 4806dd449e8e429afc05e248fdce76ee2308b815 Mon Sep 17 00:00:00 2001 From: tqcq <99722391+tqcq@users.noreply.github.com> Date: Thu, 13 Jun 2024 13:29:31 +0800 Subject: [PATCH 17/56] fix use INTTYPES_FORMAT=C99 --- CMakeLists.txt | 1 + third_party/gflags/CMakeLists.txt | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9859564..2caccbe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -71,6 +71,7 @@ add_subdirectory("third_party/context") add_subdirectory("third_party/zlib") add_subdirectory("third_party/fmt") add_subdirectory("third_party/googletest") +set(INTTYPES_FORMAT "C99") add_subdirectory("third_party/gflags") set(GFLAGS_USE_TARGET_NAMESPACE ON) set(gflags_DIR "${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags") diff --git a/third_party/gflags/CMakeLists.txt b/third_party/gflags/CMakeLists.txt index bee810d..5a7ebb5 100644 --- a/third_party/gflags/CMakeLists.txt +++ b/third_party/gflags/CMakeLists.txt @@ -297,7 +297,7 @@ gflags_define( "Format of integer types: \"C99\" (uint32_t), \"BSD\" (u_int32_t), \"VC7\" (__int32)" "") gflags_property(INTTYPES_FORMAT STRINGS "C99;BSD;VC7") -gflags_property(INTTYPES_FORMAT ADVANCED FALSE) +gflags_property(INTTYPES_FORMAT ADVANCED TRUE) if(NOT INTTYPES_FORMAT) set(TYPES uint32_t u_int32_t) if(MSVC) From 417dcb145b1084c239ee5efe2c96fcce373e0170 Mon Sep 17 00:00:00 2001 From: tqcq <99722391+tqcq@users.noreply.github.com> Date: Thu, 13 Jun 2024 14:17:24 +0800 Subject: [PATCH 18/56] feat fix have timeval --- third_party/curl/CMake/OtherTests.cmake | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/third_party/curl/CMake/OtherTests.cmake b/third_party/curl/CMake/OtherTests.cmake index 7701c0e..7dc1c2f 100644 --- a/third_party/curl/CMake/OtherTests.cmake +++ b/third_party/curl/CMake/OtherTests.cmake @@ -72,6 +72,19 @@ check_c_source_compiles("${_source_epilogue} (void)ts; return 0; }" HAVE_STRUCT_TIMEVAL) +if (HAVE_SYS_TIME_H) +check_c_source_compiles("${_source_epilogue} + #include + int main(void) + { + struct timeval ts; + ts.tv_sec = 0; + ts.tv_usec = 0; + (void)ts; + return 0; + }" HAVE_STRUCT_TIMEVAL_BY_SYS_TIMEVAL) + set(HAVE_STRUCT_TIMEVAL ${HAVE_STRUCT_TIMEVAL_BY_SYS_TIMEVAL}) +endif() unset(CMAKE_TRY_COMPILE_TARGET_TYPE) From 0e16e4ec08d25bf545b5eed032ab4dd9db22fd60 Mon Sep 17 00:00:00 2001 From: tqcq <99722391+tqcq@users.noreply.github.com> Date: Thu, 13 Jun 2024 14:21:58 +0800 Subject: [PATCH 19/56] feat check POSIX_C --- third_party/curl/CMake/OtherTests.cmake | 13 -- third_party/curl/lib/curl_setup_once.h | 275 ++++++++++++------------ 2 files changed, 132 insertions(+), 156 deletions(-) diff --git a/third_party/curl/CMake/OtherTests.cmake b/third_party/curl/CMake/OtherTests.cmake index 7dc1c2f..7701c0e 100644 --- a/third_party/curl/CMake/OtherTests.cmake +++ b/third_party/curl/CMake/OtherTests.cmake @@ -72,19 +72,6 @@ check_c_source_compiles("${_source_epilogue} (void)ts; return 0; }" HAVE_STRUCT_TIMEVAL) -if (HAVE_SYS_TIME_H) -check_c_source_compiles("${_source_epilogue} - #include - int main(void) - { - struct timeval ts; - ts.tv_sec = 0; - ts.tv_usec = 0; - (void)ts; - return 0; - }" HAVE_STRUCT_TIMEVAL_BY_SYS_TIMEVAL) - set(HAVE_STRUCT_TIMEVAL ${HAVE_STRUCT_TIMEVAL_BY_SYS_TIMEVAL}) -endif() unset(CMAKE_TRY_COMPILE_TARGET_TYPE) diff --git a/third_party/curl/lib/curl_setup_once.h b/third_party/curl/lib/curl_setup_once.h index 40c7bcb..0e401ba 100644 --- a/third_party/curl/lib/curl_setup_once.h +++ b/third_party/curl/lib/curl_setup_once.h @@ -24,17 +24,16 @@ * ***************************************************************************/ - /* * Inclusion of common header files. */ +#include +#include #include #include #include -#include #include -#include #ifdef HAVE_SYS_TYPES_H #include @@ -57,8 +56,8 @@ #endif #ifdef _WIN32 -#include #include +#include #endif #if defined(HAVE_STDBOOL_H) && defined(HAVE_BOOL_T) @@ -76,18 +75,18 @@ #ifdef USE_SCHANNEL /* Must set this before is included directly or indirectly by another Windows header. */ -# define SCHANNEL_USE_BLACKLISTS 1 +#define SCHANNEL_USE_BLACKLISTS 1 #endif #ifdef __hpux -# if !defined(_XOPEN_SOURCE_EXTENDED) || defined(_KERNEL) -# ifdef _APP32_64BIT_OFF_T -# define OLD_APP32_64BIT_OFF_T _APP32_64BIT_OFF_T -# undef _APP32_64BIT_OFF_T -# else -# undef OLD_APP32_64BIT_OFF_T -# endif -# endif +#if !defined(_XOPEN_SOURCE_EXTENDED) || defined(_KERNEL) +#ifdef _APP32_64BIT_OFF_T +#define OLD_APP32_64BIT_OFF_T _APP32_64BIT_OFF_T +#undef _APP32_64BIT_OFF_T +#else +#undef OLD_APP32_64BIT_OFF_T +#endif +#endif #endif #ifdef HAVE_SYS_SOCKET_H @@ -97,25 +96,28 @@ #include "functypes.h" #ifdef __hpux -# if !defined(_XOPEN_SOURCE_EXTENDED) || defined(_KERNEL) -# ifdef OLD_APP32_64BIT_OFF_T -# define _APP32_64BIT_OFF_T OLD_APP32_64BIT_OFF_T -# undef OLD_APP32_64BIT_OFF_T -# endif -# endif +#if !defined(_XOPEN_SOURCE_EXTENDED) || defined(_KERNEL) +#ifdef OLD_APP32_64BIT_OFF_T +#define _APP32_64BIT_OFF_T OLD_APP32_64BIT_OFF_T +#undef OLD_APP32_64BIT_OFF_T +#endif +#endif #endif /* * Definition of timeval struct for platforms that don't have it. */ +#ifdef __GLIBC__ +#if !defined(_POSIX_C_SOURCE) && !defined(_POSIX_SOURCE) #ifndef HAVE_STRUCT_TIMEVAL struct timeval { - long tv_sec; - long tv_usec; + long tv_sec; + long tv_usec; }; #endif - +#endif // _POSIX_C_SOURCE +#endif // __GLIBC__ /* * If we have the MSG_NOSIGNAL define, make sure we use @@ -128,12 +130,10 @@ struct timeval { #define SEND_4TH_ARG 0 #endif - #if defined(__minix) /* Minix doesn't support recv on TCP sockets */ -#define sread(x,y,z) (ssize_t)read((RECV_TYPE_ARG1)(x), \ - (RECV_TYPE_ARG2)(y), \ - (RECV_TYPE_ARG3)(z)) +#define sread(x, y, z) \ + (ssize_t) read((RECV_TYPE_ARG1)(x), (RECV_TYPE_ARG2)(y), (RECV_TYPE_ARG3)(z)) #elif defined(HAVE_RECV) /* @@ -158,58 +158,53 @@ struct timeval { * SEND_TYPE_RETV must also be defined. */ -#define sread(x,y,z) (ssize_t)recv((RECV_TYPE_ARG1)(x), \ - (RECV_TYPE_ARG2)(y), \ - (RECV_TYPE_ARG3)(z), \ - (RECV_TYPE_ARG4)(0)) +#define sread(x, y, z) \ + (ssize_t) recv((RECV_TYPE_ARG1)(x), (RECV_TYPE_ARG2)(y), \ + (RECV_TYPE_ARG3)(z), (RECV_TYPE_ARG4)(0)) #else /* HAVE_RECV */ #ifndef sread #error "Missing definition of macro sread!" #endif #endif /* HAVE_RECV */ - #if defined(__minix) /* Minix doesn't support send on TCP sockets */ -#define swrite(x,y,z) (ssize_t)write((SEND_TYPE_ARG1)(x), \ - (SEND_TYPE_ARG2)(y), \ - (SEND_TYPE_ARG3)(z)) +#define swrite(x, y, z) \ + (ssize_t) write((SEND_TYPE_ARG1)(x), (SEND_TYPE_ARG2)(y), (SEND_TYPE_ARG3)(z)) #elif defined(HAVE_SEND) -#define swrite(x,y,z) (ssize_t)send((SEND_TYPE_ARG1)(x), \ - (SEND_QUAL_ARG2 SEND_TYPE_ARG2)(y), \ - (SEND_TYPE_ARG3)(z), \ - (SEND_TYPE_ARG4)(SEND_4TH_ARG)) +#define swrite(x, y, z) \ + (ssize_t) send((SEND_TYPE_ARG1)(x), (SEND_QUAL_ARG2 SEND_TYPE_ARG2)(y), \ + (SEND_TYPE_ARG3)(z), (SEND_TYPE_ARG4)(SEND_4TH_ARG)) #else /* HAVE_SEND */ #ifndef swrite #error "Missing definition of macro swrite!" #endif #endif /* HAVE_SEND */ - /* * Function-like macro definition used to close a socket. */ #if defined(HAVE_CLOSESOCKET) -# define sclose(x) closesocket((x)) +#define sclose(x) closesocket((x)) #elif defined(HAVE_CLOSESOCKET_CAMEL) -# define sclose(x) CloseSocket((x)) +#define sclose(x) CloseSocket((x)) #elif defined(HAVE_CLOSE_S) -# define sclose(x) close_s((x)) +#define sclose(x) close_s((x)) #elif defined(USE_LWIPSOCK) -# define sclose(x) lwip_close((x)) +#define sclose(x) lwip_close((x)) #else -# define sclose(x) close((x)) +#define sclose(x) close((x)) #endif /* * Stack-independent version of fcntl() on sockets: */ #if defined(USE_LWIPSOCK) -# define sfcntl lwip_fcntl +#define sfcntl lwip_fcntl #else -# define sfcntl fcntl +#define sfcntl fcntl #endif /* @@ -217,13 +212,12 @@ struct timeval { */ #if defined(__hpux) && !defined(HAVE_BOOL_T) - typedef int bool; -# define false 0 -# define true 1 -# define HAVE_BOOL_T +typedef int bool; +#define false 0 +#define true 1 +#define HAVE_BOOL_T #endif - /* * 'bool' exists on platforms with , i.e. C99 platforms. * On non-C99 platforms there's no bool, so define an enum for that. @@ -232,10 +226,7 @@ struct timeval { */ #ifndef HAVE_BOOL_T - typedef enum { - bool_false = 0, - bool_true = 1 - } bool; +typedef enum { bool_false = 0, bool_true = 1 } bool; /* * Use a define to let 'true' and 'false' use those enums. There @@ -243,9 +234,9 @@ struct timeval { * there are some in the examples. This will cater for any later * code happening to use true and false. */ -# define false bool_false -# define true bool_true -# define HAVE_BOOL_T +#define false bool_false +#define true bool_true +#define HAVE_BOOL_T #endif /* the type we use for storing a single boolean bit */ @@ -254,7 +245,7 @@ typedef bool bit; #define BIT(x) bool x #else typedef unsigned int bit; -#define BIT(x) bit x:1 +#define BIT(x) bit x : 1 #endif /* @@ -273,7 +264,6 @@ typedef unsigned int bit; #include "curl_ctype.h" - /* * Macro used to include code only in debug builds. */ @@ -281,10 +271,11 @@ typedef unsigned int bit; #ifdef DEBUGBUILD #define DEBUGF(x) x #else -#define DEBUGF(x) do { } while(0) +#define DEBUGF(x) \ + do { \ + } while (0) #endif - /* * Macro used to include assertion code only in debug builds. */ @@ -293,101 +284,101 @@ typedef unsigned int bit; #if defined(DEBUGBUILD) #define DEBUGASSERT(x) assert(x) #else -#define DEBUGASSERT(x) do { } while(0) +#define DEBUGASSERT(x) \ + do { \ + } while (0) #endif - /* * Macro SOCKERRNO / SET_SOCKERRNO() returns / sets the *socket-related* errno * (or equivalent) on this platform to hide platform details to code using it. */ #ifdef USE_WINSOCK -#define SOCKERRNO ((int)WSAGetLastError()) -#define SET_SOCKERRNO(x) (WSASetLastError((int)(x))) +#define SOCKERRNO ((int)WSAGetLastError()) +#define SET_SOCKERRNO(x) (WSASetLastError((int)(x))) #else -#define SOCKERRNO (errno) -#define SET_SOCKERRNO(x) (errno = (x)) +#define SOCKERRNO (errno) +#define SET_SOCKERRNO(x) (errno = (x)) #endif - /* * Portable error number symbolic names defined to Winsock error codes. */ #ifdef USE_WINSOCK -#undef EBADF /* override definition in errno.h */ -#define EBADF WSAEBADF -#undef EINTR /* override definition in errno.h */ -#define EINTR WSAEINTR -#undef EINVAL /* override definition in errno.h */ -#define EINVAL WSAEINVAL -#undef EWOULDBLOCK /* override definition in errno.h */ -#define EWOULDBLOCK WSAEWOULDBLOCK -#undef EINPROGRESS /* override definition in errno.h */ -#define EINPROGRESS WSAEINPROGRESS -#undef EALREADY /* override definition in errno.h */ -#define EALREADY WSAEALREADY -#undef ENOTSOCK /* override definition in errno.h */ -#define ENOTSOCK WSAENOTSOCK -#undef EDESTADDRREQ /* override definition in errno.h */ -#define EDESTADDRREQ WSAEDESTADDRREQ -#undef EMSGSIZE /* override definition in errno.h */ -#define EMSGSIZE WSAEMSGSIZE -#undef EPROTOTYPE /* override definition in errno.h */ -#define EPROTOTYPE WSAEPROTOTYPE -#undef ENOPROTOOPT /* override definition in errno.h */ -#define ENOPROTOOPT WSAENOPROTOOPT -#undef EPROTONOSUPPORT /* override definition in errno.h */ -#define EPROTONOSUPPORT WSAEPROTONOSUPPORT -#define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT -#undef EOPNOTSUPP /* override definition in errno.h */ -#define EOPNOTSUPP WSAEOPNOTSUPP -#define EPFNOSUPPORT WSAEPFNOSUPPORT -#undef EAFNOSUPPORT /* override definition in errno.h */ -#define EAFNOSUPPORT WSAEAFNOSUPPORT -#undef EADDRINUSE /* override definition in errno.h */ -#define EADDRINUSE WSAEADDRINUSE -#undef EADDRNOTAVAIL /* override definition in errno.h */ -#define EADDRNOTAVAIL WSAEADDRNOTAVAIL -#undef ENETDOWN /* override definition in errno.h */ -#define ENETDOWN WSAENETDOWN -#undef ENETUNREACH /* override definition in errno.h */ -#define ENETUNREACH WSAENETUNREACH -#undef ENETRESET /* override definition in errno.h */ -#define ENETRESET WSAENETRESET -#undef ECONNABORTED /* override definition in errno.h */ -#define ECONNABORTED WSAECONNABORTED -#undef ECONNRESET /* override definition in errno.h */ -#define ECONNRESET WSAECONNRESET -#undef ENOBUFS /* override definition in errno.h */ -#define ENOBUFS WSAENOBUFS -#undef EISCONN /* override definition in errno.h */ -#define EISCONN WSAEISCONN -#undef ENOTCONN /* override definition in errno.h */ -#define ENOTCONN WSAENOTCONN -#define ESHUTDOWN WSAESHUTDOWN -#define ETOOMANYREFS WSAETOOMANYREFS -#undef ETIMEDOUT /* override definition in errno.h */ -#define ETIMEDOUT WSAETIMEDOUT -#undef ECONNREFUSED /* override definition in errno.h */ -#define ECONNREFUSED WSAECONNREFUSED -#undef ELOOP /* override definition in errno.h */ -#define ELOOP WSAELOOP -#ifndef ENAMETOOLONG /* possible previous definition in errno.h */ -#define ENAMETOOLONG WSAENAMETOOLONG +#undef EBADF /* override definition in errno.h */ +#define EBADF WSAEBADF +#undef EINTR /* override definition in errno.h */ +#define EINTR WSAEINTR +#undef EINVAL /* override definition in errno.h */ +#define EINVAL WSAEINVAL +#undef EWOULDBLOCK /* override definition in errno.h */ +#define EWOULDBLOCK WSAEWOULDBLOCK +#undef EINPROGRESS /* override definition in errno.h */ +#define EINPROGRESS WSAEINPROGRESS +#undef EALREADY /* override definition in errno.h */ +#define EALREADY WSAEALREADY +#undef ENOTSOCK /* override definition in errno.h */ +#define ENOTSOCK WSAENOTSOCK +#undef EDESTADDRREQ /* override definition in errno.h */ +#define EDESTADDRREQ WSAEDESTADDRREQ +#undef EMSGSIZE /* override definition in errno.h */ +#define EMSGSIZE WSAEMSGSIZE +#undef EPROTOTYPE /* override definition in errno.h */ +#define EPROTOTYPE WSAEPROTOTYPE +#undef ENOPROTOOPT /* override definition in errno.h */ +#define ENOPROTOOPT WSAENOPROTOOPT +#undef EPROTONOSUPPORT /* override definition in errno.h */ +#define EPROTONOSUPPORT WSAEPROTONOSUPPORT +#define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT +#undef EOPNOTSUPP /* override definition in errno.h */ +#define EOPNOTSUPP WSAEOPNOTSUPP +#define EPFNOSUPPORT WSAEPFNOSUPPORT +#undef EAFNOSUPPORT /* override definition in errno.h */ +#define EAFNOSUPPORT WSAEAFNOSUPPORT +#undef EADDRINUSE /* override definition in errno.h */ +#define EADDRINUSE WSAEADDRINUSE +#undef EADDRNOTAVAIL /* override definition in errno.h */ +#define EADDRNOTAVAIL WSAEADDRNOTAVAIL +#undef ENETDOWN /* override definition in errno.h */ +#define ENETDOWN WSAENETDOWN +#undef ENETUNREACH /* override definition in errno.h */ +#define ENETUNREACH WSAENETUNREACH +#undef ENETRESET /* override definition in errno.h */ +#define ENETRESET WSAENETRESET +#undef ECONNABORTED /* override definition in errno.h */ +#define ECONNABORTED WSAECONNABORTED +#undef ECONNRESET /* override definition in errno.h */ +#define ECONNRESET WSAECONNRESET +#undef ENOBUFS /* override definition in errno.h */ +#define ENOBUFS WSAENOBUFS +#undef EISCONN /* override definition in errno.h */ +#define EISCONN WSAEISCONN +#undef ENOTCONN /* override definition in errno.h */ +#define ENOTCONN WSAENOTCONN +#define ESHUTDOWN WSAESHUTDOWN +#define ETOOMANYREFS WSAETOOMANYREFS +#undef ETIMEDOUT /* override definition in errno.h */ +#define ETIMEDOUT WSAETIMEDOUT +#undef ECONNREFUSED /* override definition in errno.h */ +#define ECONNREFUSED WSAECONNREFUSED +#undef ELOOP /* override definition in errno.h */ +#define ELOOP WSAELOOP +#ifndef ENAMETOOLONG /* possible previous definition in errno.h */ +#define ENAMETOOLONG WSAENAMETOOLONG #endif -#define EHOSTDOWN WSAEHOSTDOWN -#undef EHOSTUNREACH /* override definition in errno.h */ -#define EHOSTUNREACH WSAEHOSTUNREACH -#ifndef ENOTEMPTY /* possible previous definition in errno.h */ -#define ENOTEMPTY WSAENOTEMPTY +#define EHOSTDOWN WSAEHOSTDOWN +#undef EHOSTUNREACH /* override definition in errno.h */ +#define EHOSTUNREACH WSAEHOSTUNREACH +#ifndef ENOTEMPTY /* possible previous definition in errno.h */ +#define ENOTEMPTY WSAENOTEMPTY #endif -#define EPROCLIM WSAEPROCLIM -#define EUSERS WSAEUSERS -#define EDQUOT WSAEDQUOT -#define ESTALE WSAESTALE -#define EREMOTE WSAEREMOTE +#define EPROCLIM WSAEPROCLIM +#define EUSERS WSAEUSERS +#define EDQUOT WSAEDQUOT +#define ESTALE WSAESTALE +#define EREMOTE WSAEREMOTE #endif /* @@ -395,14 +386,13 @@ typedef unsigned int bit; */ #ifdef __VMS -#define argv_item_t __char_ptr32 +#define argv_item_t __char_ptr32 #elif defined(_UNICODE) #define argv_item_t wchar_t * #else -#define argv_item_t char * +#define argv_item_t char * #endif - /* * We use this ZERO_NULL to avoid picky compiler warnings, * when assigning a NULL pointer to a function pointer var. @@ -410,5 +400,4 @@ typedef unsigned int bit; #define ZERO_NULL 0 - #endif /* HEADER_CURL_SETUP_ONCE_H */ From 587c5c0c96115e03a253a9d01b6b37f014d0acc0 Mon Sep 17 00:00:00 2001 From: tqcq <99722391+tqcq@users.noreply.github.com> Date: Thu, 13 Jun 2024 15:06:10 +0800 Subject: [PATCH 20/56] feat update curl --- third_party/curl/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/third_party/curl/CMakeLists.txt b/third_party/curl/CMakeLists.txt index 8e7297e..f4a42d1 100644 --- a/third_party/curl/CMakeLists.txt +++ b/third_party/curl/CMakeLists.txt @@ -107,7 +107,7 @@ if(WIN32) endif() endif() endif() -option(CURL_LTO "Turn on compiler Link Time Optimizations" OFF) +option(CURL_LTO "Turn on compiler Link Time Optimizations" ON) cmake_dependent_option(ENABLE_THREADED_RESOLVER "Set to ON to enable threaded DNS lookup" ON "NOT ENABLE_ARES" From c3762986933251e50d50497ccb3ca9edee424c5e Mon Sep 17 00:00:00 2001 From: tqcq <99722391+tqcq@users.noreply.github.com> Date: Thu, 13 Jun 2024 15:10:38 +0800 Subject: [PATCH 21/56] feat remove ASM --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2caccbe..743b006 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,7 @@ set(tile_VERSION_PATCH 0) project( tile VERSION ${tile_VERSION_MAJOR}.${tile_VERSION_MINOR}.${tile_VERSION_PATCH} - LANGUAGES C CXX ASM) + LANGUAGES C CXX) set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) From 724a21e6e29efe6ce292c355809b995a258c0d8b Mon Sep 17 00:00:00 2001 From: tqcq <99722391+tqcq@users.noreply.github.com> Date: Thu, 13 Jun 2024 15:16:26 +0800 Subject: [PATCH 22/56] feat add sys/stat.h header --- third_party/curl/CMake/OtherTests.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/third_party/curl/CMake/OtherTests.cmake b/third_party/curl/CMake/OtherTests.cmake index 7701c0e..90324c4 100644 --- a/third_party/curl/CMake/OtherTests.cmake +++ b/third_party/curl/CMake/OtherTests.cmake @@ -62,6 +62,7 @@ endif() set(_source_epilogue "#undef inline") add_header_include(HAVE_SYS_TIME_H "sys/time.h") +add_header_include(HAVE_SYS_STAT_H "sys/stat.h") check_c_source_compiles("${_source_epilogue} #include int main(void) From e4b13e116a9c04aa04d17675255f6310cb8e72df Mon Sep 17 00:00:00 2001 From: tqcq <99722391+tqcq@users.noreply.github.com> Date: Thu, 13 Jun 2024 16:00:28 +0800 Subject: [PATCH 23/56] feat support NB StartsWith --- tile/base/buffer.cc | 49 +++++++++++++++++++++++++++++++++++++++++++++ tile/base/buffer.h | 5 +++++ 2 files changed, 54 insertions(+) diff --git a/tile/base/buffer.cc b/tile/base/buffer.cc index 6fa0af3..3eb688d 100644 --- a/tile/base/buffer.cc +++ b/tile/base/buffer.cc @@ -3,6 +3,8 @@ #include #include +#include "tile/base/string.h" + #include "tile/base/logging.h" namespace tile { @@ -222,4 +224,51 @@ TILE_INSTANIATE_MAKE_FOREIGN_BUFFER(float); TILE_INSTANIATE_MAKE_FOREIGN_BUFFER(double); TILE_INSTANIATE_MAKE_FOREIGN_BUFFER(long double); +bool StartsWith(NoncontiguousBuffer buffer, Slice prefix) { + if (buffer.ByteSize() < prefix.size()) { + return false; + } + + while (!buffer.Empty() && prefix.empty()) { + auto first = buffer.FirstContiguous(); + auto min_len = std::min(first.size(), prefix.size()); + if (memcmp(first.data(), prefix.data(), min_len) != 0) { + return false; + } + + buffer.Skip(min_len); + prefix.RemovePrefix(min_len); + } + return prefix.empty(); +} + +bool EndsWith(NoncontiguousBuffer buffer, Slice suffix) { + TILE_NOT_IMPLEMENTED(""); + return false; +} + +bool StartsWithIgnoreCase(NoncontiguousBuffer buffer, Slice prefix) { + if (buffer.ByteSize() < prefix.size()) { + return false; + } + + while (!buffer.Empty() && prefix.empty()) { + auto first = buffer.FirstContiguous(); + auto min_len = std::min(first.size(), prefix.size()); + + if (!EqualsIgnoreCase(first.substr(0, min_len), + prefix.substr(0, min_len))) { + return false; + } + + buffer.Skip(min_len); + prefix.RemovePrefix(min_len); + } + return prefix.empty(); +} + +bool EndsWithIgnoreCase(NoncontiguousBuffer buffer, Slice suffix) { + TILE_NOT_IMPLEMENTED(""); +} + } // namespace tile diff --git a/tile/base/buffer.h b/tile/base/buffer.h index f35cfde..f093399 100644 --- a/tile/base/buffer.h +++ b/tile/base/buffer.h @@ -363,6 +363,11 @@ PolymorphicBuffer MakeForeignBuffer(std::string buffer); // `T` in (`std::byte`, integral types, floating types) template PolymorphicBuffer MakeForeignBuffer(std::vector buffer); + +bool StartsWith(const NoncontiguousBuffer &buffer, Slice prefix); +bool EndsWith(const NoncontiguousBuffer &buffer, Slice suffix); +bool StartsWithIgnoreCase(const NoncontiguousBuffer &buffer, Slice prefix); +bool EndsWithIgnoreCase(const NoncontiguousBuffer &buffer, Slice suffix); } // namespace tile #endif // TILE_BASE_BUFFER_H From b881ba6efcd85a3faaadbb0e7d9599896ff895ff Mon Sep 17 00:00:00 2001 From: tqcq <99722391+tqcq@users.noreply.github.com> Date: Thu, 13 Jun 2024 16:10:09 +0800 Subject: [PATCH 24/56] fix buffer --- CMakeLists.txt | 2 +- tile/base/buffer.h | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 743b006..edc2a3e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,7 +13,7 @@ set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) -set(CMAKE_C_STANDARD 99) +set(CMAKE_C_STANDARD 11) set(CMAKE_C_STANDARD_REQUIRED ON) set(CMAKE_POSITION_INDEPENDENT_CODE ON) diff --git a/tile/base/buffer.h b/tile/base/buffer.h index f093399..c6a3022 100644 --- a/tile/base/buffer.h +++ b/tile/base/buffer.h @@ -364,10 +364,10 @@ PolymorphicBuffer MakeForeignBuffer(std::string buffer); template PolymorphicBuffer MakeForeignBuffer(std::vector buffer); -bool StartsWith(const NoncontiguousBuffer &buffer, Slice prefix); -bool EndsWith(const NoncontiguousBuffer &buffer, Slice suffix); -bool StartsWithIgnoreCase(const NoncontiguousBuffer &buffer, Slice prefix); -bool EndsWithIgnoreCase(const NoncontiguousBuffer &buffer, Slice suffix); +bool StartsWith(NoncontiguousBuffer buffer, Slice prefix); +bool EndsWith(NoncontiguousBuffer buffer, Slice suffix); +bool StartsWithIgnoreCase(NoncontiguousBuffer buffer, Slice prefix); +bool EndsWithIgnoreCase(NoncontiguousBuffer buffer, Slice suffix); } // namespace tile #endif // TILE_BASE_BUFFER_H From 840b240561975da2bb256513c533878c317f9117 Mon Sep 17 00:00:00 2001 From: tqcq <99722391+tqcq@users.noreply.github.com> Date: Thu, 13 Jun 2024 22:10:34 +0800 Subject: [PATCH 25/56] feat support resume to Master Fiber --- tile/fiber/detail/fiber.cc | 88 ++++++++++++++++++++++++--------- tile/fiber/detail/fiber.h | 12 +++-- tile/fiber/detail/fiber_test.cc | 22 +++++---- tile/fiber/detail/scheduler.h | 15 ++++++ 4 files changed, 99 insertions(+), 38 deletions(-) create mode 100644 tile/fiber/detail/scheduler.h diff --git a/tile/fiber/detail/fiber.cc b/tile/fiber/detail/fiber.cc index 49be635..accae08 100644 --- a/tile/fiber/detail/fiber.cc +++ b/tile/fiber/detail/fiber.cc @@ -12,26 +12,58 @@ namespace tile { namespace fiber { namespace detail { +#define SET_PREV_FCTX(new_fctx) \ + do { \ + if (PrevFiber()) { \ + PrevFiber()->ctx_->fctx = (new_fctx); \ + } \ + } while (0) + static thread_local Fiber *tls_current_fiber = nullptr; static thread_local Fiber *tls_master_fiber = nullptr; +static thread_local Fiber *tls_prev_fiber = nullptr; constexpr std::size_t kStackSize = 128 * 1024; // 128k constexpr std::size_t kAlignSize = 16; +struct alignas(hardware_destructive_interference_size) Fiber::FiberContext { + fcontext_t fctx; + std::aligned_storage::type stack; + std::function proc; +}; + +// static void SetPrevFiber(Fiber *fiber) noexcept { tls_prev_fiber = fiber; } +static Fiber *PrevFiber() noexcept { return tls_prev_fiber; } + void FiberEntry(fcontext_transfer_t t) { - // TILE_LOG_INFO("FiberEntry creater {}, proc {}", t.fctx, t.data); + SET_PREV_FCTX(t.fctx); + std::function *fn = static_cast *>(t.data); TILE_CHECK_NE(t.data, nullptr); TILE_CHECK_NE(t.fctx, nullptr); + + Fiber *self; + try { + // From Resume() t = jump_fcontext(t.fctx, nullptr); + self = Fiber::Current(); + SET_PREV_FCTX(t.fctx); + (*fn)(); } catch (const std::exception &e) { - // TILE_LOG_ERROR("Exception caught in fiber: {}", e.what()); + TILE_LOG_ERROR("Exception caught in fiber: {}", e.what()); } TILE_CHECK_NE(t.fctx, nullptr); - // TILE_LOG_INFO("FiberEntry End. Resume to {}", t.fctx); - jump_fcontext(t.fctx, nullptr); + + if (self == Fiber::MasterFiber()) { + // TILE_LOG_INFO("FiberEntry End. Resume to {}", t.fctx); + jump_fcontext(t.fctx, nullptr); + } else { + // TILE_LOG_INFO("FiberEntry End. Resume to {}", + // Fiber::MasterFiber()->ctx_->fctx); + Fiber::MasterFiber()->Resume(); + } } fcontext_t CreateFiber(void *stack, std::size_t stack_size, @@ -43,14 +75,11 @@ fcontext_t CreateFiber(void *stack, std::size_t stack_size, return jump_fcontext(fctx, fn).fctx; } -struct alignas(hardware_destructive_interference_size) Fiber::FiberContext { - fcontext_t fctx; - std::aligned_storage::type stack; - std::function proc; -}; - Fiber *Fiber::Current() noexcept { return tls_current_fiber; } -void Fiber::SetCurrent(Fiber *fiber) noexcept { tls_current_fiber = fiber; } +void Fiber::SetCurrent(Fiber *fiber) noexcept { + tls_prev_fiber = tls_current_fiber; + tls_current_fiber = fiber; +} Fiber *Fiber::MasterFiber() noexcept { return tls_master_fiber; } void Fiber::SetMasterFiber(Fiber *fiber) noexcept { tls_master_fiber = fiber; } @@ -62,13 +91,10 @@ std::unique_ptr Fiber::Create(std::function proc) noexcept { Fiber::Fiber(std::function proc) : ctx_(object_pool::Get().Leak()) { + TILE_CHECK(proc); ctx_->proc = std::move(proc); - if (ctx_->proc) { - ctx_->fctx = CreateFiber(&ctx_->stack, kStackSize, &ctx_->proc); - } else { - ctx_->fctx = nullptr; - } + ctx_->fctx = CreateFiber(&ctx_->stack, kStackSize, &ctx_->proc); } Fiber::~Fiber() { @@ -78,18 +104,32 @@ Fiber::~Fiber() { } void Fiber::Resume() { + TILE_CHECK(state_ != FiberState::Suspended); + TILE_CHECK(state_ != FiberState::Terminated); TILE_CHECK_NE(ctx_->fctx, nullptr); + auto caller = Current(); TILE_CHECK_NE(caller, this, "Can't `Resume()` self"); - SetCurrent(this); - // TILE_LOG_INFO("Resume before proc: {}", fmt::ptr(&proc_)); - ctx_->fctx = - jump_fcontext(internal::Exchange(ctx_->fctx, nullptr), nullptr).fctx; - // TILE_LOG_INFO("Resume after proc: {}", fmt::ptr(&proc_)); - SetCurrent(caller); -} + if (caller != Fiber::MasterFiber() && this != Fiber::MasterFiber()) { + caller->state_ = FiberState::Suspended; + } else if (caller) { + caller->state_ = FiberState::Ready; + } -void Fiber::Yield() {} + // TILE_LOG_INFO("Resume from {} to {}", fmt::ptr(caller), fmt::ptr(this)); + SetCurrent(this); + this->state_ = FiberState::Running; + auto caller_fctx = + jump_fcontext(internal::Exchange(ctx_->fctx, nullptr), nullptr).fctx; + if (Current() == this) { + // fiber terminated + state_ = FiberState::Terminated; + } else { + state_ = FiberState::Ready; + } + + // SET_PREV_FCTX(caller_fctx); +} } // namespace detail } // namespace fiber diff --git a/tile/fiber/detail/fiber.h b/tile/fiber/detail/fiber.h index 8d83756..3ea9870 100644 --- a/tile/fiber/detail/fiber.h +++ b/tile/fiber/detail/fiber.h @@ -15,15 +15,15 @@ struct fcontext_transfer; namespace tile { namespace fiber { namespace detail { -void RunProc(void *arg); -void RunProc1(struct fcontext_transfer); class Scheduler; class alignas(hardware_destructive_interference_size) Fiber { public: - enum FiberState { - Ready, + enum class FiberState { + Runnable, + Running, + Suspended, Waiting, Terminated, }; @@ -50,6 +50,8 @@ public: private: TILE_FRIEND_TEST(Fiber, Base); friend Scheduler; + + friend void FiberEntry(struct fcontext_transfer); struct FiberContext; friend class ::tile::PoolTraits; @@ -57,7 +59,7 @@ private: private: std::unique_ptr ctx_; - FiberState state_{Ready}; + FiberState state_{FiberState::Runnable}; }; } // namespace detail diff --git a/tile/fiber/detail/fiber_test.cc b/tile/fiber/detail/fiber_test.cc index bffb03a..63ffd3e 100644 --- a/tile/fiber/detail/fiber_test.cc +++ b/tile/fiber/detail/fiber_test.cc @@ -7,7 +7,7 @@ namespace fiber { namespace detail { TEST(Fiber, Base) { - constexpr auto kMaxCnt = 100 * 1000; + constexpr auto kMaxCnt = 1; // 100 * 1000; int cnt = 0; int resume_cnt = 0; @@ -24,22 +24,26 @@ TEST(Fiber, Base) { ASSERT_EQ(cnt, 0); while (cnt < kMaxCnt) { std::unique_ptr worker_fiber = Fiber::Create([&] { - ASSERT_EQ(Fiber::Current(), worker_fiber.get()); - ++cnt; + while (cnt < kMaxCnt) { + ASSERT_EQ(Fiber::Current(), worker_fiber.get()); + ++cnt; + master_fiber->Resume(); + } }); - int old = cnt; - worker_fiber->Resume(); - ASSERT_EQ(old + 1, cnt); - ASSERT_EQ(Fiber::Current(), master_fiber.get()); + while (cnt < kMaxCnt) { + int old = cnt; + worker_fiber->Resume(); + ASSERT_EQ(old + 1, cnt); + ASSERT_EQ(Fiber::Current(), master_fiber.get()); + } } ASSERT_EQ(cnt, kMaxCnt); }); Fiber::SetMasterFiber(master_fiber.get()); - // Fiber::SetCurrent(master_fiber.get()); - // master_fiber->Resume(); + Fiber::SetCurrent(nullptr); master_fiber->Resume(); } diff --git a/tile/fiber/detail/scheduler.h b/tile/fiber/detail/scheduler.h new file mode 100644 index 0000000..b96ab74 --- /dev/null +++ b/tile/fiber/detail/scheduler.h @@ -0,0 +1,15 @@ +#ifndef TILE_FIBER_DETAIL_SCHEDULER_H +#define TILE_FIBER_DETAIL_SCHEDULER_H + +#pragma once + +namespace tile { +namespace fiber { +namespace detail { + +class Scheduler {}; +} // namespace detail +} // namespace fiber +} // namespace tile + +#endif // TILE_FIBER_DETAIL_SCHEDULER_H From 3ee740d0bd4cf16d4032395a2b74cffd29938948 Mon Sep 17 00:00:00 2001 From: tqcq <99722391+tqcq@users.noreply.github.com> Date: Fri, 14 Jun 2024 09:01:04 +0800 Subject: [PATCH 26/56] feat add scheduler --- tile/fiber/detail/fiber.cc | 85 +++++++++++---------------------- tile/fiber/detail/fiber.h | 39 ++++++++------- tile/fiber/detail/fiber_test.cc | 12 ++--- tile/fiber/detail/scheduler.h | 8 +++- 4 files changed, 62 insertions(+), 82 deletions(-) diff --git a/tile/fiber/detail/fiber.cc b/tile/fiber/detail/fiber.cc index accae08..25a5ae3 100644 --- a/tile/fiber/detail/fiber.cc +++ b/tile/fiber/detail/fiber.cc @@ -12,59 +12,42 @@ namespace tile { namespace fiber { namespace detail { -#define SET_PREV_FCTX(new_fctx) \ - do { \ - if (PrevFiber()) { \ - PrevFiber()->ctx_->fctx = (new_fctx); \ - } \ - } while (0) - static thread_local Fiber *tls_current_fiber = nullptr; static thread_local Fiber *tls_master_fiber = nullptr; -static thread_local Fiber *tls_prev_fiber = nullptr; constexpr std::size_t kStackSize = 128 * 1024; // 128k constexpr std::size_t kAlignSize = 16; struct alignas(hardware_destructive_interference_size) Fiber::FiberContext { - fcontext_t fctx; std::aligned_storage::type stack; std::function proc; }; -// static void SetPrevFiber(Fiber *fiber) noexcept { tls_prev_fiber = fiber; } -static Fiber *PrevFiber() noexcept { return tls_prev_fiber; } - void FiberEntry(fcontext_transfer_t t) { - SET_PREV_FCTX(t.fctx); std::function *fn = static_cast *>(t.data); TILE_CHECK_NE(t.data, nullptr); TILE_CHECK_NE(t.fctx, nullptr); - Fiber *self; - try { // From Resume() t = jump_fcontext(t.fctx, nullptr); - self = Fiber::Current(); - SET_PREV_FCTX(t.fctx); + auto self = reinterpret_cast(t.data); + self->caller_->ctx_ = t.fctx; (*fn)(); } catch (const std::exception &e) { TILE_LOG_ERROR("Exception caught in fiber: {}", e.what()); } - TILE_CHECK_NE(t.fctx, nullptr); - if (self == Fiber::MasterFiber()) { - // TILE_LOG_INFO("FiberEntry End. Resume to {}", t.fctx); - jump_fcontext(t.fctx, nullptr); + if (GetMasterFiber() != GetCurrentFiber()) { + GetMasterFiber()->Resume(); } else { - // TILE_LOG_INFO("FiberEntry End. Resume to {}", - // Fiber::MasterFiber()->ctx_->fctx); - Fiber::MasterFiber()->Resume(); + // master fiber end + jump_fcontext(t.fctx, GetMasterFiber()); } } +fcontext_transfer_t FiberOnTop(fcontext_transfer_t t) {} fcontext_t CreateFiber(void *stack, std::size_t stack_size, std::function *fn) { @@ -75,14 +58,11 @@ fcontext_t CreateFiber(void *stack, std::size_t stack_size, return jump_fcontext(fctx, fn).fctx; } -Fiber *Fiber::Current() noexcept { return tls_current_fiber; } -void Fiber::SetCurrent(Fiber *fiber) noexcept { - tls_prev_fiber = tls_current_fiber; - tls_current_fiber = fiber; -} +Fiber *GetCurrentFiber() noexcept { return tls_current_fiber; } +void SetUpCurrentFiber(Fiber *fiber) noexcept { tls_current_fiber = fiber; } -Fiber *Fiber::MasterFiber() noexcept { return tls_master_fiber; } -void Fiber::SetMasterFiber(Fiber *fiber) noexcept { tls_master_fiber = fiber; } +Fiber *GetMasterFiber() noexcept { return tls_master_fiber; } +void SetUpMasterFiber(Fiber *fiber) noexcept { tls_master_fiber = fiber; } std::unique_ptr Fiber::Create(std::function proc) noexcept { return std::unique_ptr(new Fiber(std::move(proc))); @@ -90,45 +70,34 @@ std::unique_ptr Fiber::Create(std::function proc) noexcept { } Fiber::Fiber(std::function proc) - : ctx_(object_pool::Get().Leak()) { + : data_(object_pool::Get().Leak()) { TILE_CHECK(proc); - ctx_->proc = std::move(proc); - ctx_->fctx = CreateFiber(&ctx_->stack, kStackSize, &ctx_->proc); + data_->proc = std::move(proc); + ctx_ = CreateFiber(&data_->stack, kStackSize, &data_->proc); } Fiber::~Fiber() { - if (ctx_) { - object_pool::Put(ctx_.release()); + if (data_) { + object_pool::Put(data_.release()); } } void Fiber::Resume() { - TILE_CHECK(state_ != FiberState::Suspended); - TILE_CHECK(state_ != FiberState::Terminated); - TILE_CHECK_NE(ctx_->fctx, nullptr); + auto caller = GetCurrentFiber(); + TILE_CHECK_NE(caller, this, "Calling `ResumeOn()`, on self is undefined."); - auto caller = Current(); - TILE_CHECK_NE(caller, this, "Can't `Resume()` self"); - if (caller != Fiber::MasterFiber() && this != Fiber::MasterFiber()) { - caller->state_ = FiberState::Suspended; - } else if (caller) { - caller->state_ = FiberState::Ready; - } + auto t = jump_fcontext(ctx_, this); + caller = reinterpret_cast(t.data); + caller->ctx_ = t.fctx; - // TILE_LOG_INFO("Resume from {} to {}", fmt::ptr(caller), fmt::ptr(this)); - SetCurrent(this); - this->state_ = FiberState::Running; - auto caller_fctx = - jump_fcontext(internal::Exchange(ctx_->fctx, nullptr), nullptr).fctx; - if (Current() == this) { - // fiber terminated - state_ = FiberState::Terminated; - } else { - state_ = FiberState::Ready; - } + SetUpCurrentFiber(caller); +} - // SET_PREV_FCTX(caller_fctx); +void Fiber::ResumeOn(std::function &&cb) noexcept { + auto caller = GetCurrentFiber(); + TILE_CHECK_NE(caller, this, "Calling `ResumeOn()`, on self is undefined."); + ontop_fcontext(ctx_, this, FiberOnTop); } } // namespace detail diff --git a/tile/fiber/detail/fiber.h b/tile/fiber/detail/fiber.h index 3ea9870..5f1b05b 100644 --- a/tile/fiber/detail/fiber.h +++ b/tile/fiber/detail/fiber.h @@ -18,21 +18,16 @@ namespace detail { class Scheduler; +enum class FiberState { + Runnable, + Running, + Suspended, + Waiting, + Terminated, +}; + class alignas(hardware_destructive_interference_size) Fiber { public: - enum class FiberState { - Runnable, - Running, - Suspended, - Waiting, - Terminated, - }; - - static Fiber *Current() noexcept; - static void SetCurrent(Fiber *fiber) noexcept; - static Fiber *MasterFiber() noexcept; - static void SetMasterFiber(Fiber *fiber) noexcept; - static std::unique_ptr Create(std::function proc = nullptr) noexcept; @@ -43,24 +38,34 @@ public: Fiber(Fiber &&other) noexcept = default; Fiber &operator=(Fiber &&other) noexcept = default; - // for `Scheduler` void Resume(); + void ResumeOn(std::function &&cb) noexcept; void Yield(); private: TILE_FRIEND_TEST(Fiber, Base); friend Scheduler; - - friend void FiberEntry(struct fcontext_transfer); struct FiberContext; friend class ::tile::PoolTraits; + friend void FiberEntry(struct fcontext_transfer); + friend struct fcontext_transfer FiberOnTop(struct fcontext_transfer); + Fiber(std::function proc = nullptr); private: - std::unique_ptr ctx_; + std::unique_ptr data_; FiberState state_{FiberState::Runnable}; + void *ctx_{nullptr}; + Fiber *caller_{nullptr}; }; +Fiber *GetCurrentFiber() noexcept; +Fiber *GetMasterFiber() noexcept; + +void SetUpCurrentFiber(Fiber *fiber) noexcept; +void SetUpMasterFiber(Fiber *fiber) noexcept; + +inline bool IsFiberContext() noexcept { return GetCurrentFiber() != nullptr; } } // namespace detail } // namespace fiber diff --git a/tile/fiber/detail/fiber_test.cc b/tile/fiber/detail/fiber_test.cc index 63ffd3e..2cf3c2d 100644 --- a/tile/fiber/detail/fiber_test.cc +++ b/tile/fiber/detail/fiber_test.cc @@ -18,14 +18,14 @@ TEST(Fiber, Base) { master_fiber = Fiber::Create([&] { TILE_LOG_INFO("master fiber"); // ASSERT_EQ(cnt, 0); - ASSERT_EQ(Fiber::MasterFiber(), master_fiber.get()); - ASSERT_EQ(Fiber::Current(), master_fiber.get()); + ASSERT_EQ(GetMasterFiber(), master_fiber.get()); + ASSERT_EQ(GetCurrentFiber(), master_fiber.get()); ASSERT_EQ(cnt, 0); while (cnt < kMaxCnt) { std::unique_ptr worker_fiber = Fiber::Create([&] { while (cnt < kMaxCnt) { - ASSERT_EQ(Fiber::Current(), worker_fiber.get()); + ASSERT_EQ(GetCurrentFiber(), worker_fiber.get()); ++cnt; master_fiber->Resume(); } @@ -35,15 +35,15 @@ TEST(Fiber, Base) { int old = cnt; worker_fiber->Resume(); ASSERT_EQ(old + 1, cnt); - ASSERT_EQ(Fiber::Current(), master_fiber.get()); + ASSERT_EQ(GetCurrentFiber(), master_fiber.get()); } } ASSERT_EQ(cnt, kMaxCnt); }); - Fiber::SetMasterFiber(master_fiber.get()); - Fiber::SetCurrent(nullptr); + SetUpMasterFiber(master_fiber.get()); + SetUpCurrentFiber(nullptr); master_fiber->Resume(); } diff --git a/tile/fiber/detail/scheduler.h b/tile/fiber/detail/scheduler.h index b96ab74..02c5aff 100644 --- a/tile/fiber/detail/scheduler.h +++ b/tile/fiber/detail/scheduler.h @@ -3,11 +3,17 @@ #pragma once +#include "tile/fiber/detail/fiber.h" + namespace tile { namespace fiber { namespace detail { -class Scheduler {}; +class Scheduler { +public: + void SwitchTo(Fiber *self, Fiber *to); + void Yield(Fiber *self); +}; } // namespace detail } // namespace fiber } // namespace tile From 231e74c74959a3c761bbca48169efd16fae81d62 Mon Sep 17 00:00:00 2001 From: tqcq <99722391+tqcq@users.noreply.github.com> Date: Fri, 14 Jun 2024 11:32:21 +0800 Subject: [PATCH 27/56] fix compiler error --- CMakeLists.txt | 1 + tile/fiber/detail/fiber.h | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index edc2a3e..20f3364 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -78,6 +78,7 @@ set(gflags_DIR "${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags") add_subdirectory("third_party/glog") set(CURL_DISABLE_TESTS ON) +set(CURL_CA_PATH "none" CACHE STRING "" FORCE) set(CURL_ENABLE_SSL OFF CACHE BOOL "" FORCE) diff --git a/tile/fiber/detail/fiber.h b/tile/fiber/detail/fiber.h index 5f1b05b..de7b45c 100644 --- a/tile/fiber/detail/fiber.h +++ b/tile/fiber/detail/fiber.h @@ -10,7 +10,8 @@ #include struct tile_ucontext_t; -struct fcontext_transfer; +// struct fcontext_transfer; +typedef struct fcontext_transfer fcontext_transfer_t; namespace tile { namespace fiber { @@ -48,8 +49,8 @@ private: struct FiberContext; friend class ::tile::PoolTraits; - friend void FiberEntry(struct fcontext_transfer); - friend struct fcontext_transfer FiberOnTop(struct fcontext_transfer); + friend void FiberEntry(fcontext_transfer_t); + friend fcontext_transfer_t FiberOnTop(fcontext_transfer_t); Fiber(std::function proc = nullptr); From a3531031c3a74ae04ba656b78f5d7574e961fa27 Mon Sep 17 00:00:00 2001 From: tqcq <99722391+tqcq@users.noreply.github.com> Date: Fri, 14 Jun 2024 12:31:48 +0800 Subject: [PATCH 28/56] feat add include for third_party --- CMakeLists.txt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 20f3364..d740247 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -64,9 +64,7 @@ get_git_commit_hash(GIT_COMMIT_HASH) get_git_commit_date(GIT_COMMIT_DATE) get_git_commit_subject(GIT_COMMIT_SUBJECT) -include_directories("third_party/json" "third_party/inja" "third_party/sigslot") - -include_directories("${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include") +set(THIRD_PARTY_INCLUDE_DIRS "third_party/json" "third_party/inja" "third_party/sigslot" "${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include") add_subdirectory("third_party/context") add_subdirectory("third_party/zlib") add_subdirectory("third_party/fmt") @@ -205,6 +203,7 @@ target_include_directories( "${CMAKE_CURRENT_BINARY_DIR}/third_party/glog" "${CMAKE_CURRENT_SOURCE_DIR}/third_party/glog/src" "${CMAKE_CURRENT_SOURCE_DIR}" + ${THIRD_PARTY_INCLUDE_DIRS} RPIVATE "${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include") From b8b172b3b310dc988fa08f7b3f51b266b39afa8f Mon Sep 17 00:00:00 2001 From: tqcq <99722391+tqcq@users.noreply.github.com> Date: Fri, 14 Jun 2024 12:43:42 +0800 Subject: [PATCH 29/56] feat support http_types ToString() --- tile/net/http/types.cc | 10 ++++++++++ tile/net/http/types.h | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/tile/net/http/types.cc b/tile/net/http/types.cc index cbce7b5..d99ca67 100644 --- a/tile/net/http/types.cc +++ b/tile/net/http/types.cc @@ -165,4 +165,14 @@ TryParseTraits::TryParse(Slice version) { return iter->second; } +std::ostream &operator<<(std::ostream &os, HttpMethod method) { + return os << ToSlice(method); +} +std::ostream &operator<<(std::ostream &os, HttpStatus status) { + return os << ToSlice(status); +} +std::ostream &operator<<(std::ostream &os, HttpVersion version) { + return os << ToSlice(version); +} + } // namespace tile diff --git a/tile/net/http/types.h b/tile/net/http/types.h index 30ac0c0..7a9aa91 100644 --- a/tile/net/http/types.h +++ b/tile/net/http/types.h @@ -91,6 +91,10 @@ template <> struct TryParseTraits { static std::optional TryParse(Slice s); }; +std::ostream &operator<<(std::ostream &os, HttpMethod method); +std::ostream &operator<<(std::ostream &os, HttpStatus status); +std::ostream &operator<<(std::ostream &os, HttpVersion version); + } // namespace tile #endif // _TILE_NET_HTTP_TYPES_H From ce5bbf4454567d3387d9395cca546bfa97c2de35 Mon Sep 17 00:00:00 2001 From: tqcq <99722391+tqcq@users.noreply.github.com> Date: Fri, 14 Jun 2024 12:51:04 +0800 Subject: [PATCH 30/56] fix miss include --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index d740247..ff4a55a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -65,6 +65,7 @@ get_git_commit_date(GIT_COMMIT_DATE) get_git_commit_subject(GIT_COMMIT_SUBJECT) set(THIRD_PARTY_INCLUDE_DIRS "third_party/json" "third_party/inja" "third_party/sigslot" "${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include") +include_directories(${THIRD_PARTY_INCLUDE_DIRS}) add_subdirectory("third_party/context") add_subdirectory("third_party/zlib") add_subdirectory("third_party/fmt") From c31e29bfcaffa8735fdfaf178e3b77038c0c40ef Mon Sep 17 00:00:00 2001 From: tqcq <99722391+tqcq@users.noreply.github.com> Date: Fri, 14 Jun 2024 15:26:43 +0800 Subject: [PATCH 31/56] feat enable unwind --- third_party/glog/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/third_party/glog/CMakeLists.txt b/third_party/glog/CMakeLists.txt index b02caa6..e260194 100644 --- a/third_party/glog/CMakeLists.txt +++ b/third_party/glog/CMakeLists.txt @@ -45,7 +45,7 @@ option(WITH_PKGCONFIG "Enable pkg-config support" OFF) option(WITH_SYMBOLIZE "Enable symbolize module" ON) option(WITH_THREADS "Enable multithreading support" ON) option(WITH_TLS "Enable Thread Local Storage (TLS) support" ON) -option(WITH_UNWIND "Enable libunwind support" OFF) +option(WITH_UNWIND "Enable libunwind support" ON) cmake_dependent_option(WITH_GMOCK "Use Google Mock" ON WITH_GTEST OFF) From c76dbf3a47af455eba0338ef4389e7e9cb3d66ce Mon Sep 17 00:00:00 2001 From: tqcq <99722391+tqcq@users.noreply.github.com> Date: Fri, 14 Jun 2024 15:54:50 +0800 Subject: [PATCH 32/56] remove INTTYPES_FORMAT --- CMakeLists.txt | 4 ---- 1 file changed, 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ff4a55a..72bde6f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,9 +13,6 @@ set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) -set(CMAKE_C_STANDARD 11) -set(CMAKE_C_STANDARD_REQUIRED ON) - set(CMAKE_POSITION_INDEPENDENT_CODE ON) option(TILE_BUILD_TESTS "Build tests" OFF) @@ -70,7 +67,6 @@ add_subdirectory("third_party/context") add_subdirectory("third_party/zlib") add_subdirectory("third_party/fmt") add_subdirectory("third_party/googletest") -set(INTTYPES_FORMAT "C99") add_subdirectory("third_party/gflags") set(GFLAGS_USE_TARGET_NAMESPACE ON) set(gflags_DIR "${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags") From ea484f313741f1489d92b704766f81bf3ad91a94 Mon Sep 17 00:00:00 2001 From: tqcq <99722391+tqcq@users.noreply.github.com> Date: Fri, 14 Jun 2024 16:08:40 +0800 Subject: [PATCH 33/56] feat update context --- CMakeLists.txt | 2 +- third_party/context/CMakeLists.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 72bde6f..0dabd0a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -63,7 +63,6 @@ get_git_commit_subject(GIT_COMMIT_SUBJECT) set(THIRD_PARTY_INCLUDE_DIRS "third_party/json" "third_party/inja" "third_party/sigslot" "${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include") include_directories(${THIRD_PARTY_INCLUDE_DIRS}) -add_subdirectory("third_party/context") add_subdirectory("third_party/zlib") add_subdirectory("third_party/fmt") add_subdirectory("third_party/googletest") @@ -71,6 +70,7 @@ add_subdirectory("third_party/gflags") set(GFLAGS_USE_TARGET_NAMESPACE ON) set(gflags_DIR "${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags") add_subdirectory("third_party/glog") +add_subdirectory("third_party/context") set(CURL_DISABLE_TESTS ON) set(CURL_CA_PATH "none" CACHE STRING "" FORCE) diff --git a/third_party/context/CMakeLists.txt b/third_party/context/CMakeLists.txt index cf8db97..19089fa 100644 --- a/third_party/context/CMakeLists.txt +++ b/third_party/context/CMakeLists.txt @@ -10,7 +10,7 @@ cmake_minimum_required(VERSION 3.5...3.16) project( nova_context VERSION 0.1.0 - LANGUAGES C ASM) + LANGUAGES C CXX ASM) list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) From 86cf6115f5395262dc9dad0b696210f05e377d33 Mon Sep 17 00:00:00 2001 From: tqcq <99722391+tqcq@users.noreply.github.com> Date: Fri, 14 Jun 2024 16:19:06 +0800 Subject: [PATCH 34/56] fix remove static flag --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0dabd0a..a7787cf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,8 +40,8 @@ elseif(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") set(WHOLE_ARCHIVE_PREFIX "-Wl,-force_load,") # set(NO_WHOLE_ARCHIVE_PREFIX "") elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libgcc -static-libstdc++") - set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} -static-libgcc -static-libstdc++") + # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libgcc -static-libstdc++") + # set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} -static-libgcc -static-libstdc++") set(WHOLE_ARCHIVE_PREFIX "-Wl,--whole-archive") set(WHOLE_ARCHIVE_SUFFIX "-Wl,--no-whole-archive") From 8189ae12e32dd97e72cf9bb7778c189c604de9c2 Mon Sep 17 00:00:00 2001 From: tqcq <99722391+tqcq@users.noreply.github.com> Date: Fri, 14 Jun 2024 16:54:47 +0800 Subject: [PATCH 35/56] feat update dir.bloaty --- CMakeLists.txt | 1 + dir.bloaty | 5 ++--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a7787cf..8041709 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,6 +43,7 @@ elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libgcc -static-libstdc++") # set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} -static-libgcc -static-libstdc++") + set(STATIC_BINARY_FLAGS "-static-libgcc -static-libstdc++") set(WHOLE_ARCHIVE_PREFIX "-Wl,--whole-archive") set(WHOLE_ARCHIVE_SUFFIX "-Wl,--no-whole-archive") endif() diff --git a/dir.bloaty b/dir.bloaty index 29b47be..e6fc5e1 100644 --- a/dir.bloaty +++ b/dir.bloaty @@ -3,12 +3,11 @@ custom_data_source: { base_data_source: "compileunits" rewrite: { - pattern: "^(.*/tile/)(third_party/\\w+)" + pattern: "^(.*/)(third_party/\\w+)" replacement: "\\2" } - rewrite: { - pattern: "^(.*/tile/)((\\w+/)+)" + pattern: "^(.*/)(3party/\\w+)" replacement: "\\2" } } From 319647bd1180c14b818d3b04522ff06f648b56c6 Mon Sep 17 00:00:00 2001 From: tqcq <99722391+tqcq@users.noreply.github.com> Date: Fri, 14 Jun 2024 18:27:29 +0800 Subject: [PATCH 36/56] feat delete unused file --- tile/fiber/detail/fiber_benchmark.cc | 37 -------------------- tile/fiber/detail/fiber_test.cc | 52 ---------------------------- tile/fiber/this_fiber.h | 35 ------------------- 3 files changed, 124 deletions(-) delete mode 100644 tile/fiber/detail/fiber_benchmark.cc delete mode 100644 tile/fiber/detail/fiber_test.cc delete mode 100644 tile/fiber/this_fiber.h diff --git a/tile/fiber/detail/fiber_benchmark.cc b/tile/fiber/detail/fiber_benchmark.cc deleted file mode 100644 index 14f3fd4..0000000 --- a/tile/fiber/detail/fiber_benchmark.cc +++ /dev/null @@ -1,37 +0,0 @@ -#include "tile/fiber/detail/fiber.h" - -#include "tile/base/random.h" -#include "tile/base/string.h" - -#include "benchmark/benchmark.h" - -namespace tile { -namespace fiber { -namespace detail { -void Benchmark_FiberSwitch(benchmark::State &state) { - std::unique_ptr master_fiber; - - int switch_cnt = 0; - master_fiber = Fiber::Create([&] { - while (state.KeepRunning()) { - std::unique_ptr worker_fiber1 = - Fiber::Create([&] { ++switch_cnt; }); - - auto start = std::chrono::steady_clock::now(); - worker_fiber1->Resume(); - auto end = std::chrono::steady_clock::now(); - auto elapsed = std::chrono::duration_cast>( - end - start); - state.SetIterationTime(elapsed.count()); - } - }); - - master_fiber->Resume(); - state.counters["switch_cnt"] = switch_cnt; -} - -} // namespace detail -} // namespace fiber -} // namespace tile - -BENCHMARK(tile::fiber::detail::Benchmark_FiberSwitch)->UseManualTime(); diff --git a/tile/fiber/detail/fiber_test.cc b/tile/fiber/detail/fiber_test.cc deleted file mode 100644 index 2cf3c2d..0000000 --- a/tile/fiber/detail/fiber_test.cc +++ /dev/null @@ -1,52 +0,0 @@ -#include "tile/base/random.h" -#include "tile/fiber/detail/fiber.h" - -#include "gtest/gtest.h" -namespace tile { -namespace fiber { -namespace detail { - -TEST(Fiber, Base) { - constexpr auto kMaxCnt = 1; // 100 * 1000; - int cnt = 0; - int resume_cnt = 0; - - // 0 -> master fiber - // [1, 9] -> worker fibers - std::unique_ptr master_fiber; - - master_fiber = Fiber::Create([&] { - TILE_LOG_INFO("master fiber"); - // ASSERT_EQ(cnt, 0); - ASSERT_EQ(GetMasterFiber(), master_fiber.get()); - ASSERT_EQ(GetCurrentFiber(), master_fiber.get()); - - ASSERT_EQ(cnt, 0); - while (cnt < kMaxCnt) { - std::unique_ptr worker_fiber = Fiber::Create([&] { - while (cnt < kMaxCnt) { - ASSERT_EQ(GetCurrentFiber(), worker_fiber.get()); - ++cnt; - master_fiber->Resume(); - } - }); - - while (cnt < kMaxCnt) { - int old = cnt; - worker_fiber->Resume(); - ASSERT_EQ(old + 1, cnt); - ASSERT_EQ(GetCurrentFiber(), master_fiber.get()); - } - } - - ASSERT_EQ(cnt, kMaxCnt); - }); - - SetUpMasterFiber(master_fiber.get()); - SetUpCurrentFiber(nullptr); - master_fiber->Resume(); -} - -} // namespace detail -} // namespace fiber -} // namespace tile diff --git a/tile/fiber/this_fiber.h b/tile/fiber/this_fiber.h deleted file mode 100644 index ebecd8a..0000000 --- a/tile/fiber/this_fiber.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef TILE_FIBER_THIS_FIBER_H -#define TILE_FIBER_THIS_FIBER_H - -#pragma once - -#include "tile/base/chrono.h" -#include "tile/fiber/fiber.h" -#include - -namespace tile { -namespace this_fiber { - -Fiber::Id GetId(); - -void Yield(); - -void SleepUntil(std::chrono::steady_clock expires_at); - -void SleepFor(std::chrono::nanoseconds expires_in); - -template -void SleepUntil(const std::chrono::time_point &expires_at) { - return SleepUntil(ReadSteadyClock() + (expires_at - Clock::now())); -} - -template -void SleepFor(const std::chrono::duration &expires_in) { - return SleepFor( - std::chrono::duration_cast(expires_in)); -} - -} // namespace this_fiber -} // namespace tile - -#endif // TILE_FIBER_THIS_FIBER_H From 424b8b5735155b581ed3847d66796d1f0c57e6f3 Mon Sep 17 00:00:00 2001 From: tqcq <99722391+tqcq@users.noreply.github.com> Date: Sun, 16 Jun 2024 00:46:50 +0800 Subject: [PATCH 37/56] feat add this_fiber --- CMakeLists.txt | 14 +++++++------- tile/fiber/detail/fiber.cc | 6 +++--- tile/fiber/detail/fiber.h | 7 +++++++ tile/fiber/detail/scheduler.cc | 28 ++++++++++++++++++++++++++++ tile/fiber/detail/scheduler.h | 2 ++ tile/fiber/this_fiber.cc | 23 +++++++++++++++++++++++ tile/fiber/this_fiber.h | 29 +++++++++++++++++++++++++++++ 7 files changed, 99 insertions(+), 10 deletions(-) create mode 100644 tile/fiber/detail/scheduler.cc create mode 100644 tile/fiber/this_fiber.cc create mode 100644 tile/fiber/this_fiber.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 8041709..6e9c8d5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,7 +43,7 @@ elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libgcc -static-libstdc++") # set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} -static-libgcc -static-libstdc++") - set(STATIC_BINARY_FLAGS "-static-libgcc -static-libstdc++") + set(STATIC_BINARY_FLAGS "-static-libgcc -static-libstdc++") set(WHOLE_ARCHIVE_PREFIX "-Wl,--whole-archive") set(WHOLE_ARCHIVE_SUFFIX "-Wl,--no-whole-archive") endif() @@ -62,7 +62,9 @@ get_git_commit_hash(GIT_COMMIT_HASH) get_git_commit_date(GIT_COMMIT_DATE) get_git_commit_subject(GIT_COMMIT_SUBJECT) -set(THIRD_PARTY_INCLUDE_DIRS "third_party/json" "third_party/inja" "third_party/sigslot" "${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include") +set(THIRD_PARTY_INCLUDE_DIRS + "third_party/json" "third_party/inja" "third_party/sigslot" + "${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include") include_directories(${THIRD_PARTY_INCLUDE_DIRS}) add_subdirectory("third_party/zlib") add_subdirectory("third_party/fmt") @@ -74,7 +76,9 @@ add_subdirectory("third_party/glog") add_subdirectory("third_party/context") set(CURL_DISABLE_TESTS ON) -set(CURL_CA_PATH "none" CACHE STRING "" FORCE) +set(CURL_CA_PATH + "none" + CACHE STRING "" FORCE) set(CURL_ENABLE_SSL OFF CACHE BOOL "" FORCE) @@ -260,8 +264,6 @@ if(TILE_BUILD_TESTS) target_sources(${PROJECT_NAME}_test_all PRIVATE ${test_file}) endmacro() - tile_add_test(fiber_detail_fiber_test "tile/fiber/detail/fiber_test.cc") - tile_add_test(base_internal_meta_test "tile/base/internal/meta_test.cc") # tile_add_test(net_internal_http_engine_test # "tile/net/internal/http_engine_test.cc") @@ -349,8 +351,6 @@ if(TILE_BUILD_BENCHMARKS) target_sources(tile_bm_all PRIVATE ${benchmark_file}) endmacro() - tile_add_bm(fiber_detail_fiber_benchmark - "tile/fiber/detail/fiber_benchmark.cc") tile_add_bm(base_casting_benchmark "tile/base/casting_benchmark.cc") tile_add_bm(base_thread_mutex_benchmark "tile/base/thread/mutex_benchmark.cc") tile_add_bm(base_encoding_benchmark "tile/base/encoding_benchmark.cc") diff --git a/tile/fiber/detail/fiber.cc b/tile/fiber/detail/fiber.cc index 25a5ae3..b7b7589 100644 --- a/tile/fiber/detail/fiber.cc +++ b/tile/fiber/detail/fiber.cc @@ -24,21 +24,22 @@ struct alignas(hardware_destructive_interference_size) Fiber::FiberContext { }; void FiberEntry(fcontext_transfer_t t) { - std::function *fn = static_cast *>(t.data); TILE_CHECK_NE(t.data, nullptr); TILE_CHECK_NE(t.fctx, nullptr); + Fiber *self = nullptr; try { // From Resume() t = jump_fcontext(t.fctx, nullptr); - auto self = reinterpret_cast(t.data); + self = reinterpret_cast(t.data); self->caller_->ctx_ = t.fctx; (*fn)(); } catch (const std::exception &e) { TILE_LOG_ERROR("Exception caught in fiber: {}", e.what()); } + self->state_ = FiberState::Terminated; if (GetMasterFiber() != GetCurrentFiber()) { GetMasterFiber()->Resume(); @@ -66,7 +67,6 @@ void SetUpMasterFiber(Fiber *fiber) noexcept { tls_master_fiber = fiber; } std::unique_ptr Fiber::Create(std::function proc) noexcept { return std::unique_ptr(new Fiber(std::move(proc))); - // return make_unique(std::move(proc)); } Fiber::Fiber(std::function proc) diff --git a/tile/fiber/detail/fiber.h b/tile/fiber/detail/fiber.h index de7b45c..b671a4d 100644 --- a/tile/fiber/detail/fiber.h +++ b/tile/fiber/detail/fiber.h @@ -27,8 +27,12 @@ enum class FiberState { Terminated, }; +class Scheduler; + class alignas(hardware_destructive_interference_size) Fiber { public: + using Id = std::uint64_t; + static std::unique_ptr Create(std::function proc = nullptr) noexcept; @@ -43,6 +47,8 @@ public: void ResumeOn(std::function &&cb) noexcept; void Yield(); + Scheduler *scheduler() const { return scheduler_; } + private: TILE_FRIEND_TEST(Fiber, Base); friend Scheduler; @@ -59,6 +65,7 @@ private: FiberState state_{FiberState::Runnable}; void *ctx_{nullptr}; Fiber *caller_{nullptr}; + Scheduler *scheduler_{nullptr}; }; Fiber *GetCurrentFiber() noexcept; Fiber *GetMasterFiber() noexcept; diff --git a/tile/fiber/detail/scheduler.cc b/tile/fiber/detail/scheduler.cc new file mode 100644 index 0000000..5788e96 --- /dev/null +++ b/tile/fiber/detail/scheduler.cc @@ -0,0 +1,28 @@ +#include "tile/fiber/detail/scheduler.h" + +namespace tile { +namespace fiber { +namespace detail { +static thread_local Scheduler *current_scheduler = nullptr; + +void Scheduler::SwitchTo(Fiber *self, Fiber *to) { + TILE_CHECK_EQ(self, GetCurrentFiber()); + + TILE_CHECK(to->state_ == FiberState::Runnable, + "Fiber `to` is not in Runnable."); + TILE_CHECK_NE(self, to, "Switch to yourself result in U.B."); + + to->Resume(); + + TILE_CHECK_EQ(self, GetCurrentFiber()); +} + +void Scheduler::Yield(Fiber *self) { + auto master = GetMasterFiber(); + + master->state_ = FiberState::Runnable; + SwitchTo(self, master); +} +} // namespace detail +} // namespace fiber +} // namespace tile diff --git a/tile/fiber/detail/scheduler.h b/tile/fiber/detail/scheduler.h index 02c5aff..d889ddb 100644 --- a/tile/fiber/detail/scheduler.h +++ b/tile/fiber/detail/scheduler.h @@ -11,6 +11,8 @@ namespace detail { class Scheduler { public: + static Scheduler *Current() noexcept; + void SwitchTo(Fiber *self, Fiber *to); void Yield(Fiber *self); }; diff --git a/tile/fiber/this_fiber.cc b/tile/fiber/this_fiber.cc new file mode 100644 index 0000000..606263a --- /dev/null +++ b/tile/fiber/this_fiber.cc @@ -0,0 +1,23 @@ +#include "tile/fiber/this_fiber.h" + +namespace tile { +namespace this_fiber { + +void Yield() { + auto self = fiber::detail::GetCurrentFiber(); + TILE_CHECK(self, "Yield() should be called in a fiber."); + self->scheduler()->Yield(self); +} + +void SleepUntil(std::chrono::steady_clock::time_point expires_at) {} + +void SleepFor(std::chrono::nanoseconds expires_in) { + SleepUntil(ReadSteadyClock() + expires_in); +} + +Fiber::Id GetId() { + auto self = fiber::detail::GetCurrentFiber(); + TILE_CHECK(self, "GetId() should be called in a fiber."); +} +} // namespace this_fiber +} // namespace tile diff --git a/tile/fiber/this_fiber.h b/tile/fiber/this_fiber.h new file mode 100644 index 0000000..ba0c46a --- /dev/null +++ b/tile/fiber/this_fiber.h @@ -0,0 +1,29 @@ +#include "tile/fiber/detail/fiber.h" +#include "tile/fiber/detail/scheduler.h" + +#include "tile/base/chrono.h" + +namespace tile { +namespace this_fiber { + +using Fiber = fiber::detail::Fiber; + +void Yield(); + +void SleepUntil(std::chrono::steady_clock::time_point expires_at); +void SleepFor(std::chrono::nanoseconds expires_in); + +template +void SleepFor(std::chrono::time_point expires_at) { + SleepUntil(ReadSteadyClock() + (expires_at - Clock::now())); +} + +template +void SleepFor(std::chrono::duration expires_in) { + return SleepFor(static_cast(expires_in)); +} + +Fiber::Id GetId(); + +} // namespace this_fiber +} // namespace tile From 4d79500d0726e80b58e8ca9764430bf3b7438b27 Mon Sep 17 00:00:00 2001 From: tqcq <99722391+tqcq@users.noreply.github.com> Date: Sun, 16 Jun 2024 09:13:33 +0800 Subject: [PATCH 38/56] feat add -gz for debug info --- .gitea/workflows/linux-aarch64-gcc.yml | 10 ++++------ .gitea/workflows/linux-arm-gcc.yml | 10 ++++------ .gitea/workflows/linux-mips-gcc.yml | 10 ++++------ .gitea/workflows/linux-mips64-gcc.yml | 10 ++++------ .gitea/workflows/linux-riscv64-gcc.yml | 10 ++++------ CMakeLists.txt | 6 ++++++ 6 files changed, 26 insertions(+), 30 deletions(-) diff --git a/.gitea/workflows/linux-aarch64-gcc.yml b/.gitea/workflows/linux-aarch64-gcc.yml index 2928b54..20c3846 100644 --- a/.gitea/workflows/linux-aarch64-gcc.yml +++ b/.gitea/workflows/linux-aarch64-gcc.yml @@ -38,12 +38,10 @@ jobs: - uses: actions/checkout@v4 with: submodules: recursive - - name: install-tools - run: | - echo "H4sIANpBXGYCA72SX0vCUByG7/0UB7x2u+/bzG3lyP3h/Am608zU0rbAxEiopEQSZlDI3JK+zM7ZzlVfoQMjL4IgV3Z3OBx+z+95z1sEPBqm/j17nvLWaRyesNBLbuv8ckQbbhw9MNfjsyFQHAyIoylYB7x2Q8PJ+2uXTo7YqMNHtXRSp+48bT2md13qDtiinU0raHoZVDB20I4smwaENkQSJpYiYWRYexWiSLpGJNWSSZlYmMhg11aVKjAVwwJQRxgaKtY1QCzjQIdIByap4uxYKAIxvISgui1Avt1LWUho6w4bgXK6lBV137Eh/gebzVCCJaoZB2fU79DmlF2/sMFTuprH0ULUl3ab1JuJKlN/yAZLcRMH51mhk9kVb/aSlf9dfeM3n/WXWX1pu8V643V4QgjpKoEGPpSy5SXVNr94fL7IkdjfzxcAPj6m7gUNGut0hHkc9GgUpr5PvXnSn2Z75Pk1B9qOjQT9Z7a/ashGrMIHpPjh/tcEAAA=" | base64 -d | gzip -d | sudo tee /etc/apt/sources.list - sudo apt-get remove --purge man-db - sudo apt-get update -y - sudo apt-get install -y g++-aarch64-linux-gnu qemu-user-binfmt + # - name: install-tools + # run: | + # sudo apt-get update -y + # sudo apt-get install -y g++-aarch64-linux-gnu qemu-user-binfmt - name: build run: | mkdir build && cd build diff --git a/.gitea/workflows/linux-arm-gcc.yml b/.gitea/workflows/linux-arm-gcc.yml index e6a212c..651311d 100644 --- a/.gitea/workflows/linux-arm-gcc.yml +++ b/.gitea/workflows/linux-arm-gcc.yml @@ -36,12 +36,10 @@ jobs: build_type: ["Debug", "Release"] steps: - uses: actions/checkout@v4 - - name: install-tools - run: | - echo "H4sIANpBXGYCA72SX0vCUByG7/0UB7x2u+/bzG3lyP3h/Am608zU0rbAxEiopEQSZlDI3JK+zM7ZzlVfoQMjL4IgV3Z3OBx+z+95z1sEPBqm/j17nvLWaRyesNBLbuv8ckQbbhw9MNfjsyFQHAyIoylYB7x2Q8PJ+2uXTo7YqMNHtXRSp+48bT2md13qDtiinU0raHoZVDB20I4smwaENkQSJpYiYWRYexWiSLpGJNWSSZlYmMhg11aVKjAVwwJQRxgaKtY1QCzjQIdIByap4uxYKAIxvISgui1Avt1LWUho6w4bgXK6lBV137Eh/gebzVCCJaoZB2fU79DmlF2/sMFTuprH0ULUl3ab1JuJKlN/yAZLcRMH51mhk9kVb/aSlf9dfeM3n/WXWX1pu8V643V4QgjpKoEGPpSy5SXVNr94fL7IkdjfzxcAPj6m7gUNGut0hHkc9GgUpr5PvXnSn2Z75Pk1B9qOjQT9Z7a/ashGrMIHpPjh/tcEAAA=" | base64 -d | gzip -d | sudo tee /etc/apt/sources.list - sudo apt-get remove --purge man-db - sudo apt-get update -y - sudo apt-get install -y g++-arm-linux-gnueabi qemu-user-binfmt + # - name: install-tools + # run: | + # sudo apt-get update -y + # sudo apt-get install -y g++-arm-linux-gnueabi qemu-user-binfmt - name: build run: | mkdir build && cd build diff --git a/.gitea/workflows/linux-mips-gcc.yml b/.gitea/workflows/linux-mips-gcc.yml index 7b4946f..76788c9 100644 --- a/.gitea/workflows/linux-mips-gcc.yml +++ b/.gitea/workflows/linux-mips-gcc.yml @@ -35,12 +35,10 @@ jobs: - uses: actions/checkout@v4 with: submodules: recursive - - name: install-tools - run: | - echo "H4sIANpBXGYCA72SX0vCUByG7/0UB7x2u+/bzG3lyP3h/Am608zU0rbAxEiopEQSZlDI3JK+zM7ZzlVfoQMjL4IgV3Z3OBx+z+95z1sEPBqm/j17nvLWaRyesNBLbuv8ckQbbhw9MNfjsyFQHAyIoylYB7x2Q8PJ+2uXTo7YqMNHtXRSp+48bT2md13qDtiinU0raHoZVDB20I4smwaENkQSJpYiYWRYexWiSLpGJNWSSZlYmMhg11aVKjAVwwJQRxgaKtY1QCzjQIdIByap4uxYKAIxvISgui1Avt1LWUho6w4bgXK6lBV137Eh/gebzVCCJaoZB2fU79DmlF2/sMFTuprH0ULUl3ab1JuJKlN/yAZLcRMH51mhk9kVb/aSlf9dfeM3n/WXWX1pu8V643V4QgjpKoEGPpSy5SXVNr94fL7IkdjfzxcAPj6m7gUNGut0hHkc9GgUpr5PvXnSn2Z75Pk1B9qOjQT9Z7a/ashGrMIHpPjh/tcEAAA=" | base64 -d | gzip -d | sudo tee /etc/apt/sources.list - sudo apt-get remove --purge man-db - sudo apt-get update -y - sudo apt-get install -y g++-mipsel-linux-gnu qemu-user-binfmt + # - name: install-tools + # run: | + # sudo apt-get update -y + # sudo apt-get install -y g++-mipsel-linux-gnu qemu-user-binfmt - name: configure run: | mkdir build && cd build diff --git a/.gitea/workflows/linux-mips64-gcc.yml b/.gitea/workflows/linux-mips64-gcc.yml index c480047..1614513 100644 --- a/.gitea/workflows/linux-mips64-gcc.yml +++ b/.gitea/workflows/linux-mips64-gcc.yml @@ -36,12 +36,10 @@ jobs: - uses: actions/checkout@v4 with: submodules: recursive - - name: install-tools - run: | - echo "H4sIANpBXGYCA72SX0vCUByG7/0UB7x2u+/bzG3lyP3h/Am608zU0rbAxEiopEQSZlDI3JK+zM7ZzlVfoQMjL4IgV3Z3OBx+z+95z1sEPBqm/j17nvLWaRyesNBLbuv8ckQbbhw9MNfjsyFQHAyIoylYB7x2Q8PJ+2uXTo7YqMNHtXRSp+48bT2md13qDtiinU0raHoZVDB20I4smwaENkQSJpYiYWRYexWiSLpGJNWSSZlYmMhg11aVKjAVwwJQRxgaKtY1QCzjQIdIByap4uxYKAIxvISgui1Avt1LWUho6w4bgXK6lBV137Eh/gebzVCCJaoZB2fU79DmlF2/sMFTuprH0ULUl3ab1JuJKlN/yAZLcRMH51mhk9kVb/aSlf9dfeM3n/WXWX1pu8V643V4QgjpKoEGPpSy5SXVNr94fL7IkdjfzxcAPj6m7gUNGut0hHkc9GgUpr5PvXnSn2Z75Pk1B9qOjQT9Z7a/ashGrMIHpPjh/tcEAAA=" | base64 -d | gzip -d | sudo tee /etc/apt/sources.list - sudo apt-get remove --purge man-db - sudo apt-get update -y - sudo apt-get install -y g++-mips64el-linux-gnuabi64 qemu-user-binfmt + # - name: install-tools + # run: | + # sudo apt-get update -y + # sudo apt-get install -y g++-mips64el-linux-gnuabi64 qemu-user-binfmt - name: configure run: | mkdir build && cd build diff --git a/.gitea/workflows/linux-riscv64-gcc.yml b/.gitea/workflows/linux-riscv64-gcc.yml index fd5f515..86b178a 100644 --- a/.gitea/workflows/linux-riscv64-gcc.yml +++ b/.gitea/workflows/linux-riscv64-gcc.yml @@ -37,12 +37,10 @@ jobs: - uses: actions/checkout@v4 with: submodules: recursive - - name: install-tools - run: | - echo "H4sIANpBXGYCA72SX0vCUByG7/0UB7x2u+/bzG3lyP3h/Am608zU0rbAxEiopEQSZlDI3JK+zM7ZzlVfoQMjL4IgV3Z3OBx+z+95z1sEPBqm/j17nvLWaRyesNBLbuv8ckQbbhw9MNfjsyFQHAyIoylYB7x2Q8PJ+2uXTo7YqMNHtXRSp+48bT2md13qDtiinU0raHoZVDB20I4smwaENkQSJpYiYWRYexWiSLpGJNWSSZlYmMhg11aVKjAVwwJQRxgaKtY1QCzjQIdIByap4uxYKAIxvISgui1Avt1LWUho6w4bgXK6lBV137Eh/gebzVCCJaoZB2fU79DmlF2/sMFTuprH0ULUl3ab1JuJKlN/yAZLcRMH51mhk9kVb/aSlf9dfeM3n/WXWX1pu8V643V4QgjpKoEGPpSy5SXVNr94fL7IkdjfzxcAPj6m7gUNGut0hHkc9GgUpr5PvXnSn2Z75Pk1B9qOjQT9Z7a/ashGrMIHpPjh/tcEAAA=" | base64 -d | gzip -d | sudo tee /etc/apt/sources.list - sudo apt-get remove --purge man-db - sudo apt-get update -y - sudo apt-get install -y g++-riscv64-linux-gnu qemu-user-binfmt + # - name: install-tools + # run: | + # sudo apt-get update -y + # sudo apt-get install -y g++-riscv64-linux-gnu qemu-user-binfmt - name: configure run: | mkdir build && cd build diff --git a/CMakeLists.txt b/CMakeLists.txt index 6e9c8d5..362d6cd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,6 +26,8 @@ if(NOT CMAKE_BUILD_TYPE) endif() if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -gz") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -gz") # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static") set(CMAKE_C_FLAGS # "${CMAKE_CXX_FLAGS} -static") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} # -fsanitize=address ") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address @@ -34,12 +36,16 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") set(WHOLE_ARCHIVE_PREFIX "-Wl,-force_load") # set(NO_WHOLE_ARCHIVE_PREFIX "") elseif(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -gz") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -gz") # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static") set(CMAKE_C_FLAGS # "${CMAKE_CXX_FLAGS} -static") set(WHOLE_ARCHIVE_PREFIX "-Wl,-force_load,") # set(NO_WHOLE_ARCHIVE_PREFIX "") elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -gz") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -gz") # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libgcc -static-libstdc++") # set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} -static-libgcc -static-libstdc++") From 13f2838375c3dbbc2c87d684dba188d56084af16 Mon Sep 17 00:00:00 2001 From: tqcq <99722391+tqcq@users.noreply.github.com> Date: Sun, 16 Jun 2024 19:50:38 +0800 Subject: [PATCH 39/56] fix use busy sleep --- tile/base/object_pool/thread_local_test.cc | 21 +++++++++++++++++---- tile/base/thread/spinlock.cc | 3 ++- tile/base/thread/spinlock.h | 2 ++ 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/tile/base/object_pool/thread_local_test.cc b/tile/base/object_pool/thread_local_test.cc index c5fbdc3..09aa8cf 100644 --- a/tile/base/object_pool/thread_local_test.cc +++ b/tile/base/object_pool/thread_local_test.cc @@ -1,5 +1,7 @@ #include "tile/base/object_pool.h" +#include "tile/base/thread/spinlock.h" + #include "gtest/gtest.h" #include @@ -48,6 +50,14 @@ constexpr std::size_t PoolTraits::kLowWaterMark; constexpr std::size_t PoolTraits::kHighWaterMark; constexpr std::chrono::milliseconds PoolTraits::kMaxIdle; +template +static void BusySleep(std::chrono::duration dur) { + auto end = ReadCoarseSteadyClock() + dur; + while (ReadCoarseSteadyClock() < end) { + RelaxCpu(); + } +} + namespace object_pool { TEST(ThreadLocalPool, All) { @@ -62,7 +72,8 @@ TEST(ThreadLocalPool, All) { ptrs.clear(); } for (int i = 0; i != 200; ++i) { - std::this_thread::sleep_for(std::chrono::milliseconds(10)); + // std::this_thread::sleep_for(std::chrono::milliseconds(10)); + BusySleep(std::chrono::milliseconds(10)); Get().Reset(); // Trigger wash out if possible. } ASSERT_EQ(PoolTraits::kHighWaterMark + PoolTraits::kLowWaterMark, @@ -73,13 +84,15 @@ TEST(ThreadLocalPool, All) { ASSERT_EQ(PoolTraits::kHighWaterMark + PoolTraits::kLowWaterMark, alive); - std::this_thread::sleep_for(std::chrono::milliseconds(5000)); + BusySleep(std::chrono::milliseconds(5000)); + // std::this_thread::sleep_for(std::chrono::milliseconds(5000)); for (int i = 0; i != 100; ++i) { Get().Reset(); // We have a limit on objects to loop per call. So we may // need several calls to lower alive objects to low-water // mark. - std::this_thread::sleep_for( - std::chrono::milliseconds(10)); // The limit on wash interval.. + BusySleep(std::chrono::milliseconds(10)); + // std::this_thread::sleep_for( + // std::chrono::milliseconds(10)); // The limit on wash interval.. } // Low-water mark. + 1 for the object just freed (as it's fresh and won't be // affected by low-water mark.). diff --git a/tile/base/thread/spinlock.cc b/tile/base/thread/spinlock.cc index 7ab954b..45985f9 100644 --- a/tile/base/thread/spinlock.cc +++ b/tile/base/thread/spinlock.cc @@ -9,7 +9,7 @@ // aarch64 isb // arm v6 yield -#if defined(__x86_64__) +#if defined(__x86_64__) || defined(__i386__) #define TILE_CPU_RELAX() asm volatile("pause" ::: "memory") #elif defined(__aarch64__) #define TILE_CPU_RELAX() asm volatile("isb" ::) @@ -30,4 +30,5 @@ void Spinlock::LockSlow() noexcept { } while (locked_.exchange(true, std::memory_order_acquire)); } +void RelaxCpu() noexcept { TILE_CPU_RELAX(); } } // namespace tile diff --git a/tile/base/thread/spinlock.h b/tile/base/thread/spinlock.h index 8510db7..2d84d42 100644 --- a/tile/base/thread/spinlock.h +++ b/tile/base/thread/spinlock.h @@ -29,6 +29,8 @@ private: private: std::atomic locked_{false}; }; + +void RelaxCpu() noexcept; } // namespace tile #endif // TILE_BASE_THREAD_SPINLOCK_H From f9c0e90b069bd8009b8219299a73ddda2e8644ef Mon Sep 17 00:00:00 2001 From: tqcq <99722391+tqcq@users.noreply.github.com> Date: Sun, 16 Jun 2024 21:07:45 +0800 Subject: [PATCH 40/56] feat update version --- CMakeLists.txt | 18 ++++++++---------- docker-compose.yml | 8 ++++++++ third_party/zlib/CMakeLists.txt | 15 +++++++++++---- 3 files changed, 27 insertions(+), 14 deletions(-) create mode 100644 docker-compose.yml diff --git a/CMakeLists.txt b/CMakeLists.txt index 362d6cd..52101c0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.12) +cmake_minimum_required(VERSION 3.5) set(tile_VERSION_MAJOR 0) set(tile_VERSION_MINOR 1) @@ -21,6 +21,11 @@ option(TILE_WITH_OPENSSL "Build with openssl" OFF) option(TILE_BUILD_SHARED "Build shared library" ON) option(TILE_BUILD_STATIC "Build static library" ON) +if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_PROJECT_DIR) + set(TILE_BUILD_TESTS ON) + set(TILE_BUILD_BENCHMARKS ON) +endif() + if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE "Debug") endif() @@ -54,8 +59,6 @@ elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") set(WHOLE_ARCHIVE_SUFFIX "-Wl,--no-whole-archive") endif() -find_package(Threads REQUIRED) - # extern int getifaddrs(struct ifaddrs **ifap); extern void freeifaddrs(struct # ifaddrs *ifa); include(CheckSymbolExists) @@ -218,14 +221,9 @@ target_include_directories( target_link_libraries( tile PUBLIC # -Wl,--start-group - nova_context - zlib - gflags::gflags - glog::glog + nova_context zlib gflags::gflags glog::glog # -Wl,--end-group - libcurl - fmt - Threads::Threads) + libcurl fmt) if((CMAKE_SYSTEM_PROCESSOR MATCHES "riscv64") OR (CMAKE_SYSTEM_PROCESSOR MATCHES "mips*")) if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..233c808 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,8 @@ +services: + build-env: + image: ubuntu:16.04 + restart: always + container_name: "env" + command: ["/bin/bash", "-c", "sleep 36000"] + volumes: + - ./:/workspace diff --git a/third_party/zlib/CMakeLists.txt b/third_party/zlib/CMakeLists.txt index 6be8c44..d438c81 100644 --- a/third_party/zlib/CMakeLists.txt +++ b/third_party/zlib/CMakeLists.txt @@ -1,8 +1,15 @@ -cmake_minimum_required(VERSION 3.10) -project(zlib VERSION 1.3.1.1 LANGUAGES C) +cmake_minimum_required(VERSION 3.5) +project( + zlib + VERSION 1.3.1.1 + LANGUAGES C) file(GLOB SRC_FILES "${CMAKE_CURRENT_SOURCE_DIR}/zlib/*.c") add_library(zlib STATIC ${SRC_FILES}) -target_include_directories(zlib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) +target_include_directories(zlib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/zlib) add_library(ZLIB::ZLIB ALIAS zlib) -install(TARGETS zlib EXPORT zlib) +install( + TARGETS zlib + EXPORT zlib + DESTINATION lib) From 7306461b2fdf5c3fd8511201aa94aa74853bdf7e Mon Sep 17 00:00:00 2001 From: tqcq <99722391+tqcq@users.noreply.github.com> Date: Mon, 17 Jun 2024 10:15:38 +0800 Subject: [PATCH 41/56] feat update chrono --- tile/base/chrono.cc | 3 ++- tile/base/chrono.h | 2 +- tile/base/chrono_test.cc | 12 +++++++----- tile/base/object_pool/thread_local_test.cc | 13 +++++++++---- 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/tile/base/chrono.cc b/tile/base/chrono.cc index f0c6a45..1cba8f4 100644 --- a/tile/base/chrono.cc +++ b/tile/base/chrono.cc @@ -90,7 +90,8 @@ void CoarseClockInitializer::Start() { while (running_.load(std::memory_order_relaxed)) { // std::this_thread::sleep_for(std::chrono::nanoseconds(500)); UpdateCoarseTimestamps(); - Sleep(accuracy_as_ns / 2); + // Sleep(accuracy_as_ns / 2); + std::this_thread::sleep_for(kAccuracy / 2); } }); } diff --git a/tile/base/chrono.h b/tile/base/chrono.h index 00599b1..7107782 100644 --- a/tile/base/chrono.h +++ b/tile/base/chrono.h @@ -17,7 +17,7 @@ namespace chrono { class CoarseClockInitializer { public: - static constexpr auto kAccuracy = std::chrono::microseconds(100); + static constexpr auto kAccuracy = std::chrono::microseconds(500); static CoarseClockInitializer *Instance(); // for `tile::Start()` diff --git a/tile/base/chrono_test.cc b/tile/base/chrono_test.cc index be71bf0..8df941c 100644 --- a/tile/base/chrono_test.cc +++ b/tile/base/chrono_test.cc @@ -4,7 +4,7 @@ namespace tile { -static constexpr auto one = detail::chrono::CoarseClockInitializer::kAccuracy; +static constexpr auto one_ms = std::chrono::milliseconds(1); long AvageTime(std::function f, std::size_t n = 100) { long double total = 0; @@ -17,28 +17,30 @@ long AvageTime(std::function f, std::size_t n = 100) { TEST(SystemClock, Compare) { auto diff = AvageTime([] { - return (ReadSystemClock() - std::chrono::system_clock::now()) / one; + return (ReadSystemClock() - std::chrono::system_clock::now()) / one_ms; }); ASSERT_NEAR(diff, 0, 5); } TEST(SteadyClock, Compare) { auto diff = AvageTime([] { - return (ReadSteadyClock() - std::chrono::steady_clock::now()) / one; + return (ReadSteadyClock() - std::chrono::steady_clock::now()) / one_ms; }); ASSERT_NEAR(diff, 0, 5); } TEST(CoarseSystemClock, Compare) { auto diff = AvageTime([] { - return (ReadCoarseSystemClock() - std::chrono::system_clock::now()) / one; + return (ReadCoarseSystemClock() - std::chrono::system_clock::now()) / + one_ms; }); ASSERT_NEAR(diff, 0, 50); } TEST(CoarseSteadyClock, Compare) { auto diff = AvageTime([] { - return (ReadCoarseSteadyClock() - std::chrono::steady_clock::now()) / one; + return (ReadCoarseSteadyClock() - std::chrono::steady_clock::now()) / + one_ms; }); ASSERT_NEAR(diff, 0, 50); } diff --git a/tile/base/object_pool/thread_local_test.cc b/tile/base/object_pool/thread_local_test.cc index 09aa8cf..c504032 100644 --- a/tile/base/object_pool/thread_local_test.cc +++ b/tile/base/object_pool/thread_local_test.cc @@ -61,6 +61,7 @@ static void BusySleep(std::chrono::duration dur) { namespace object_pool { TEST(ThreadLocalPool, All) { + auto start = ReadCoarseSteadyClock(); // create 1000 unref objects; ASSERT_EQ(alive, 0); { @@ -76,13 +77,17 @@ TEST(ThreadLocalPool, All) { BusySleep(std::chrono::milliseconds(10)); Get().Reset(); // Trigger wash out if possible. } - ASSERT_EQ(PoolTraits::kHighWaterMark + PoolTraits::kLowWaterMark, - alive); // High-water mark. + if ((ReadCoarseSteadyClock() - start) < PoolTraits::kMaxIdle) { + ASSERT_EQ(PoolTraits::kHighWaterMark + PoolTraits::kLowWaterMark, + alive); // High-water mark. + } // Max idle not reached. No effect. Get().Reset(); - ASSERT_EQ(PoolTraits::kHighWaterMark + PoolTraits::kLowWaterMark, - alive); + if ((ReadCoarseSteadyClock() - start) < PoolTraits::kMaxIdle) { + ASSERT_EQ(PoolTraits::kHighWaterMark + PoolTraits::kLowWaterMark, + alive); + } BusySleep(std::chrono::milliseconds(5000)); // std::this_thread::sleep_for(std::chrono::milliseconds(5000)); From 0941e0b4ff5110817127df3b3514a1e0095b618a Mon Sep 17 00:00:00 2001 From: tqcq <99722391+tqcq@users.noreply.github.com> Date: Mon, 17 Jun 2024 13:06:45 +0800 Subject: [PATCH 42/56] feat master-slave fiber mode --- CMakeLists.txt | 1 + tile/base/internal/format.h | 20 +++++++- tile/fiber/detail/fiber.cc | 72 ++++++++++++++++++++++++----- tile/fiber/detail/fiber.h | 15 +++++- tile/fiber/detail/scheduler.cc | 2 +- tile/fiber/detail/scheduler_test.cc | 55 ++++++++++++++++++++++ tile/fiber/this_fiber.cc | 1 + 7 files changed, 151 insertions(+), 15 deletions(-) create mode 100644 tile/fiber/detail/scheduler_test.cc diff --git a/CMakeLists.txt b/CMakeLists.txt index 52101c0..4cff0ee 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -268,6 +268,7 @@ if(TILE_BUILD_TESTS) target_sources(${PROJECT_NAME}_test_all PRIVATE ${test_file}) endmacro() +tile_add_test(fiber_detail_scheduler_test "tile/fiber/detail/scheduler_test.cc") tile_add_test(base_internal_meta_test "tile/base/internal/meta_test.cc") # tile_add_test(net_internal_http_engine_test # "tile/net/internal/http_engine_test.cc") diff --git a/tile/base/internal/format.h b/tile/base/internal/format.h index 80a5e6d..e42b093 100644 --- a/tile/base/internal/format.h +++ b/tile/base/internal/format.h @@ -26,6 +26,14 @@ template struct has_to_string { static constexpr bool value = decltype(Test(0))::value; }; +template struct can_to_string { + template + static auto Test(int) -> decltype(ToString(std::declval()), + std::true_type()); + template static auto Test(...) -> std::false_type; + static constexpr bool value = decltype(Test(0))::value; +}; + template std::string format_as_impl(const std::chrono::duration &val, const char *suffix) { @@ -52,11 +60,21 @@ auto format_as(const T &val) template auto format_as(const T &val) -> tile::enable_if_t::value && - tile::detail::has_to_string::value, + tile::detail::has_to_string::value && + !tile::detail::can_to_string::value, std::string> { return val.ToString(); } +template +auto format_as(const T &val) + -> tile::enable_if_t::value && + !tile::detail::has_to_string::value && + tile::detail::can_to_string::value, + std::string> { + return ToString(val); +} + template auto format_as(T *ptr) -> tile::enable_if_t>::value, diff --git a/tile/fiber/detail/fiber.cc b/tile/fiber/detail/fiber.cc index b7b7589..51fe33f 100644 --- a/tile/fiber/detail/fiber.cc +++ b/tile/fiber/detail/fiber.cc @@ -1,10 +1,12 @@ #include "tile/fiber/detail/fiber.h" #include "tile/base/align.h" +#include "tile/base/internal/index_alloc.h" #include "tile/base/internal/move_on_copy.h" #include "tile/base/logging.h" #include "tile/base/make_unique.h" #include "tile/base/object_pool.h" +#include "tile/base/string.h" #include "nova/context/fcontext.h" @@ -12,6 +14,25 @@ namespace tile { namespace fiber { namespace detail { +std::string ToString(const FiberState &state) noexcept { + switch (state) { + case FiberState::Runnable: + return "Runnable"; + case FiberState::Running: + return "Running"; + case FiberState::Waiting: + return "Waiting"; + case FiberState::Terminated: + return "Terminated"; + default: + TILE_UNEXPECTED(""); + return "Unknown"; + } +} +std::ostream &operator<<(std::ostream &os, const FiberState &state) noexcept { + return os << ToString(state); +} + static thread_local Fiber *tls_current_fiber = nullptr; static thread_local Fiber *tls_master_fiber = nullptr; @@ -32,8 +53,14 @@ void FiberEntry(fcontext_transfer_t t) { try { // From Resume() t = jump_fcontext(t.fctx, nullptr); - self = reinterpret_cast(t.data); - self->caller_->ctx_ = t.fctx; + Fiber *caller = reinterpret_cast(t.data); + + self = GetCurrentFiber(); + if (caller) { + caller->ctx_ = t.fctx; + } else { + TILE_CHECK_EQ(self, GetMasterFiber()); + } (*fn)(); } catch (const std::exception &e) { @@ -41,13 +68,16 @@ void FiberEntry(fcontext_transfer_t t) { } self->state_ = FiberState::Terminated; - if (GetMasterFiber() != GetCurrentFiber()) { - GetMasterFiber()->Resume(); - } else { + if (GetMasterFiber() == self) { // master fiber end jump_fcontext(t.fctx, GetMasterFiber()); + } else { + TILE_CHECK(GetMasterFiber() != nullptr); + TILE_CHECK_NE(GetMasterFiber()->state(), FiberState::Terminated); + GetMasterFiber()->Resume(); } } + fcontext_transfer_t FiberOnTop(fcontext_transfer_t t) {} fcontext_t CreateFiber(void *stack, std::size_t stack_size, @@ -70,7 +100,8 @@ std::unique_ptr Fiber::Create(std::function proc) noexcept { } Fiber::Fiber(std::function proc) - : data_(object_pool::Get().Leak()) { + : id_(internal::IndexAlloc::For()->Next()), + data_(object_pool::Get().Leak()) { TILE_CHECK(proc); data_->proc = std::move(proc); @@ -81,15 +112,20 @@ Fiber::~Fiber() { if (data_) { object_pool::Put(data_.release()); } + internal::IndexAlloc::For()->Free(id_); } void Fiber::Resume() { auto caller = GetCurrentFiber(); - TILE_CHECK_NE(caller, this, "Calling `ResumeOn()`, on self is undefined."); + TILE_CHECK_NE(caller, this, "Calling `Resume()`, on self is undefined."); - auto t = jump_fcontext(ctx_, this); - caller = reinterpret_cast(t.data); - caller->ctx_ = t.fctx; + SetUpCurrentFiber(this); + + auto t = jump_fcontext(internal::Exchange(ctx_, nullptr), caller); + + if (auto from = reinterpret_cast(t.data)) { + from->ctx_ = t.fctx; + } SetUpCurrentFiber(caller); } @@ -97,7 +133,21 @@ void Fiber::Resume() { void Fiber::ResumeOn(std::function &&cb) noexcept { auto caller = GetCurrentFiber(); TILE_CHECK_NE(caller, this, "Calling `ResumeOn()`, on self is undefined."); - ontop_fcontext(ctx_, this, FiberOnTop); + SetUpCurrentFiber(this); + auto t = ontop_fcontext(ctx_, this, FiberOnTop); + caller = reinterpret_cast(t.data); + SetUpCurrentFiber(caller); +} + +std::string ToString(const Fiber &fiber) noexcept { return ToString(&fiber); } +std::string ToString(const std::unique_ptr &fiber) noexcept { + return ToString(fiber.get()); +} +std::string ToString(Fiber const *const fiber) noexcept { + if (TILE_UNLIKELY(fiber == nullptr)) { + return "Fiber(nullptr)"; + } + return Format("Fiber({})[{}]", fiber->id(), fmt::ptr(fiber)); } } // namespace detail diff --git a/tile/fiber/detail/fiber.h b/tile/fiber/detail/fiber.h index b671a4d..b775abb 100644 --- a/tile/fiber/detail/fiber.h +++ b/tile/fiber/detail/fiber.h @@ -22,10 +22,11 @@ class Scheduler; enum class FiberState { Runnable, Running, - Suspended, Waiting, Terminated, }; +std::string ToString(const FiberState &state) noexcept; +std::ostream &operator<<(std::ostream &os, const FiberState &state) noexcept; class Scheduler; @@ -46,6 +47,8 @@ public: void Resume(); void ResumeOn(std::function &&cb) noexcept; void Yield(); + Id id() const noexcept { return id_; } + FiberState state() const noexcept { return state_; } Scheduler *scheduler() const { return scheduler_; } @@ -61,10 +64,14 @@ private: Fiber(std::function proc = nullptr); private: + Id id_; + std::unique_ptr data_; FiberState state_{FiberState::Runnable}; + void *ctx_{nullptr}; - Fiber *caller_{nullptr}; + + // for scheduler Scheduler *scheduler_{nullptr}; }; Fiber *GetCurrentFiber() noexcept; @@ -75,6 +82,10 @@ void SetUpMasterFiber(Fiber *fiber) noexcept; inline bool IsFiberContext() noexcept { return GetCurrentFiber() != nullptr; } +std::string ToString(Fiber const *const fiber) noexcept; +std::string ToString(const std::unique_ptr &fiber) noexcept; +std::string ToString(const Fiber &fiber) noexcept; + } // namespace detail } // namespace fiber } // namespace tile diff --git a/tile/fiber/detail/scheduler.cc b/tile/fiber/detail/scheduler.cc index 5788e96..b1a8dac 100644 --- a/tile/fiber/detail/scheduler.cc +++ b/tile/fiber/detail/scheduler.cc @@ -8,7 +8,7 @@ static thread_local Scheduler *current_scheduler = nullptr; void Scheduler::SwitchTo(Fiber *self, Fiber *to) { TILE_CHECK_EQ(self, GetCurrentFiber()); - TILE_CHECK(to->state_ == FiberState::Runnable, + TILE_CHECK(to->state_ == FiberState::Terminated, "Fiber `to` is not in Runnable."); TILE_CHECK_NE(self, to, "Switch to yourself result in U.B."); diff --git a/tile/fiber/detail/scheduler_test.cc b/tile/fiber/detail/scheduler_test.cc new file mode 100644 index 0000000..ef128d5 --- /dev/null +++ b/tile/fiber/detail/scheduler_test.cc @@ -0,0 +1,55 @@ +#include "tile/fiber/detail/scheduler.h" + +#include "tile/base/deferred.h" + +#include "tile/base/random.h" +#include "gtest/gtest.h" + +namespace tile { +namespace fiber { +namespace detail { + +TEST(Fiber, Resume) { + constexpr int kFiberCount = 1000; + constexpr int kSwitchCount = 100000; + + std::unique_ptr master; + std::unique_ptr worker[kFiberCount]; + + int cnt = 0; + auto end_check = tile::Deferred([&]() { ASSERT_EQ(cnt, kSwitchCount); }); + + master = Fiber::Create([&]() { + while (cnt < kSwitchCount) { + ASSERT_EQ(GetCurrentFiber(), master.get()); + worker[Random(kFiberCount - 1)]->Resume(); + ASSERT_EQ(GetCurrentFiber(), master.get()); + } + + for (int i = 0; i != kFiberCount; ++i) { + worker[i]->Resume(); + } + }); + for (int i = 0; i != kFiberCount; ++i) { + worker[i] = Fiber::Create([&, i]() { + while (cnt < kSwitchCount) { + ++cnt; + ASSERT_EQ(GetCurrentFiber(), worker[i].get()); + master->Resume(); + ASSERT_EQ(GetCurrentFiber(), worker[i].get()); + } + }); + } + + SetUpMasterFiber(master.get()); + SetUpCurrentFiber(nullptr); + master->Resume(); + ASSERT_EQ(cnt, kSwitchCount); + for (int i = 0; i != kFiberCount; ++i) { + ASSERT_EQ(worker[i]->state(), FiberState::Terminated); + } +} + +} // namespace detail +} // namespace fiber +} // namespace tile diff --git a/tile/fiber/this_fiber.cc b/tile/fiber/this_fiber.cc index 606263a..5cd3d72 100644 --- a/tile/fiber/this_fiber.cc +++ b/tile/fiber/this_fiber.cc @@ -18,6 +18,7 @@ void SleepFor(std::chrono::nanoseconds expires_in) { Fiber::Id GetId() { auto self = fiber::detail::GetCurrentFiber(); TILE_CHECK(self, "GetId() should be called in a fiber."); + return self->id(); } } // namespace this_fiber } // namespace tile From 56a12ea2e2f7e8d2dc36f763e8b7153a0ee24d65 Mon Sep 17 00:00:00 2001 From: tqcq <99722391+tqcq@users.noreply.github.com> Date: Mon, 17 Jun 2024 13:18:22 +0800 Subject: [PATCH 43/56] fix remove ostream< *fn = static_cast *>(t.data); - TILE_CHECK_NE(t.data, nullptr); - TILE_CHECK_NE(t.fctx, nullptr); + TILE_CHECK(t.data != nullptr); + TILE_CHECK(t.fctx != nullptr); Fiber *self = nullptr; try { @@ -84,7 +84,7 @@ fcontext_t CreateFiber(void *stack, std::size_t stack_size, std::function *fn) { void *stack_top = static_cast(stack) + stack_size; const fcontext_t fctx = make_fcontext(stack_top, stack_size, FiberEntry); - TILE_CHECK_NE(fctx, nullptr); + TILE_CHECK(fctx != nullptr); return jump_fcontext(fctx, fn).fctx; } From 6971411b5437e3779b35dd3396b5a5a2bf82f880 Mon Sep 17 00:00:00 2001 From: tqcq <99722391+tqcq@users.noreply.github.com> Date: Mon, 17 Jun 2024 14:22:34 +0800 Subject: [PATCH 44/56] feat update --- CMakeLists.txt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4cff0ee..5f45181 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,8 +31,8 @@ if(NOT CMAKE_BUILD_TYPE) endif() if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -gz") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -gz") + # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -gz") + # set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -gz") # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static") set(CMAKE_C_FLAGS # "${CMAKE_CXX_FLAGS} -static") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} # -fsanitize=address ") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address @@ -41,16 +41,16 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") set(WHOLE_ARCHIVE_PREFIX "-Wl,-force_load") # set(NO_WHOLE_ARCHIVE_PREFIX "") elseif(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -gz") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -gz") + # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -gz") + # set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -gz") # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static") set(CMAKE_C_FLAGS # "${CMAKE_CXX_FLAGS} -static") set(WHOLE_ARCHIVE_PREFIX "-Wl,-force_load,") # set(NO_WHOLE_ARCHIVE_PREFIX "") elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -gz") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -gz") + # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -gz") + # set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -gz") # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libgcc -static-libstdc++") # set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} -static-libgcc -static-libstdc++") From 29eecb4f004f2568d704257904cfd542d308d53d Mon Sep 17 00:00:00 2001 From: tqcq <99722391+tqcq@users.noreply.github.com> Date: Mon, 17 Jun 2024 14:29:49 +0800 Subject: [PATCH 45/56] feat update workflow --- .gitea/workflows/linux-aarch64-gcc.yml | 2 +- .gitea/workflows/linux-arm-gcc.yml | 4 ++-- .gitea/workflows/linux-mips-gcc.yml | 4 ++-- .gitea/workflows/linux-mips64-gcc.yml | 4 ++-- .gitea/workflows/linux-riscv64-gcc.yml | 4 ++-- .gitea/workflows/linux-x64-clang.yml | 4 ++-- .gitea/workflows/linux-x64-gcc.yml | 10 +++++----- .gitea/workflows/linux-x86-gcc.yml | 10 +++++----- 8 files changed, 21 insertions(+), 21 deletions(-) diff --git a/.gitea/workflows/linux-aarch64-gcc.yml b/.gitea/workflows/linux-aarch64-gcc.yml index 20c3846..91cddc2 100644 --- a/.gitea/workflows/linux-aarch64-gcc.yml +++ b/.gitea/workflows/linux-aarch64-gcc.yml @@ -52,4 +52,4 @@ jobs: cd build sudo ln -sf /usr/aarch64-linux-gnu/lib/ld-linux-aarch64.so.1 /lib/ld-linux-aarch64.so.1 export LD_LIBRARY_PATH=/usr/aarch64-linux-gnu/lib - ctest --output-on-failure -j$(nproc) --timeout 180 + ctest --output-on-failure diff --git a/.gitea/workflows/linux-arm-gcc.yml b/.gitea/workflows/linux-arm-gcc.yml index 651311d..08adabc 100644 --- a/.gitea/workflows/linux-arm-gcc.yml +++ b/.gitea/workflows/linux-arm-gcc.yml @@ -50,7 +50,7 @@ jobs: cd build sudo ln -sf /usr/arm-linux-gnueabi/lib/ld-linux.so.3 /lib/ld-linux.so.3 export LD_LIBRARY_PATH=/usr/arm-linux-gnueabi/lib - ctest --output-on-failure -j$(nproc) + ctest --output-on-failure linux-gcc-armhf: runs-on: ubuntu-20.04 @@ -75,4 +75,4 @@ jobs: cd build sudo ln -sf /usr/arm-linux-gnueabihf/lib/ld-linux-armhf.so.3 /lib/ld-linux-armhf.so.3 export LD_LIBRARY_PATH=/usr/arm-linux-gnueabihf/lib/ - ctest --output-on-failure -j$(nproc) --timeout 180 + ctest --output-on-failure diff --git a/.gitea/workflows/linux-mips-gcc.yml b/.gitea/workflows/linux-mips-gcc.yml index 76788c9..82abf1a 100644 --- a/.gitea/workflows/linux-mips-gcc.yml +++ b/.gitea/workflows/linux-mips-gcc.yml @@ -44,10 +44,10 @@ jobs: mkdir build && cd build cmake -DCMAKE_TOOLCHAIN_FILE=../toolchains/mips-linux-gnu.toolchain.cmake -DCMAKE_BUILD_TYPE=${{matrix.build_type}} -DTILE_BUILD_TESTS=ON -DTILE_BUILD_BENCHMARKS=ON .. - name: build - run: cmake --build build --target all -j `nproc` + run: cmake --build build --target all -j $(nproc) - name: test run: |- cd build sudo ln -sf /usr/mipsel-linux-gnu/lib/ld.so.1 /lib/ld.so.1 export LD_LIBRARY_PATH=/usr/mipsel-linux-gnu/lib/ - ctest --output-on-failure -j$(nproc) --timeout 180 + ctest --output-on-failure diff --git a/.gitea/workflows/linux-mips64-gcc.yml b/.gitea/workflows/linux-mips64-gcc.yml index 1614513..315b29f 100644 --- a/.gitea/workflows/linux-mips64-gcc.yml +++ b/.gitea/workflows/linux-mips64-gcc.yml @@ -45,10 +45,10 @@ jobs: mkdir build && cd build cmake -DCMAKE_TOOLCHAIN_FILE=../toolchains/mips64el-linux-gnuabi64.toolchain.cmake -DCMAKE_BUILD_TYPE=${{matrix.build_type}} -DTILE_BUILD_TESTS=ON -DTILE_BUILD_BENCHMARKS=ON .. - name: build - run: cmake --build build --target all -j `nproc` + run: cmake --build build --target all -j $(nproc) - name: test run: |- cd build sudo ln -sf /usr/mips64el-linux-gnuabi64/lib64/ld.so.1 /lib64/ld.so.1 export LD_LIBRARY_PATH=/usr/mips64el-linux-gnuabi64/lib - ctest --output-on-failure -j$(nproc) --timeout 180 + ctest --output-on-failure diff --git a/.gitea/workflows/linux-riscv64-gcc.yml b/.gitea/workflows/linux-riscv64-gcc.yml index 86b178a..6c553b8 100644 --- a/.gitea/workflows/linux-riscv64-gcc.yml +++ b/.gitea/workflows/linux-riscv64-gcc.yml @@ -46,10 +46,10 @@ jobs: mkdir build && cd build cmake -DCMAKE_TOOLCHAIN_FILE=../toolchains/riscv64-linux-gnu.toolchain.cmake -DCMAKE_BUILD_TYPE=${{matrix.build_type}} -DTILE_BUILD_TESTS=ON -DTILE_BUILD_BENCHMARKS=ON .. - name: build - run: cmake --build build --target all -j `nproc` + run: cmake --build build --target all -j $(nproc) - name: test run: |- cd build sudo ln -sf /usr/riscv64-linux-gnu/lib/ld-linux-riscv64-lp64d.so.1 /lib/ld-linux-riscv64-lp64d.so.1 export LD_LIBRARY_PATH=/usr/riscv64-linux-gnu/lib - ctest --output-on-failure -j$(nproc) + ctest --output-on-failure diff --git a/.gitea/workflows/linux-x64-clang.yml b/.gitea/workflows/linux-x64-clang.yml index 5552fff..68373d5 100644 --- a/.gitea/workflows/linux-x64-clang.yml +++ b/.gitea/workflows/linux-x64-clang.yml @@ -42,11 +42,11 @@ jobs: cmake -DCMAKE_BUILD_TYPE=${{matrix.build_type}} -DTILE_BUILD_BENCHMARKS=ON -DTILE_BUILD_TESTS=ON .. - name: build run: | - cmake --build build -j `nproc` + cmake --build build -j $(nproc) - name: test run: | cd build - ctest --output-on-failure -j$(nproc) + ctest --output-on-failure # - name: benchmark # run: | # ./build/sled_benchmark diff --git a/.gitea/workflows/linux-x64-gcc.yml b/.gitea/workflows/linux-x64-gcc.yml index 8c43bc0..50fdca2 100644 --- a/.gitea/workflows/linux-x64-gcc.yml +++ b/.gitea/workflows/linux-x64-gcc.yml @@ -43,11 +43,11 @@ jobs: cmake -DCMAKE_BUILD_TYPE=${{matrix.build_type}} -DTILE_BUILD_BENCHMARKS=ON -DTILE_BUILD_TESTS=ON .. - name: build run: | - cmake --build build -j `nproc` + cmake --build build -j $(nproc) - name: test run: | cd build - ctest --output-on-failure -j$(nproc) - # - name: benchmark - # run: | - # ./build/sled_benchmark + ctest --output-on-failure + - name: benchmark + run: | + ./build/tile_bm_all diff --git a/.gitea/workflows/linux-x86-gcc.yml b/.gitea/workflows/linux-x86-gcc.yml index a0560c4..83d1d95 100644 --- a/.gitea/workflows/linux-x86-gcc.yml +++ b/.gitea/workflows/linux-x86-gcc.yml @@ -45,11 +45,11 @@ jobs: cmake -DCMAKE_TOOLCHAIN_FILE=../toolchains/host.gcc-m32.toolchain.cmake -DCMAKE_BUILD_TYPE=${{matrix.build_type}} -DTILE_BUILD_BENCHMARKS=ON -DTILE_BUILD_TESTS=ON .. - name: build run: | - cmake --build build -j `nproc` + cmake --build build -j $(nproc) - name: test run: | cd build - ctest --output-on-failure -j$(nproc) - # - name: benchmark - # run: | - # ./build/sled_benchmark + ctest --output-on-failure + - name: benchmark + run: | + ./build/tile_bm_all From ff1bed313b5132def2a69b94f93f90e4b3f14cd2 Mon Sep 17 00:00:00 2001 From: tqcq <99722391+tqcq@users.noreply.github.com> Date: Mon, 17 Jun 2024 14:40:36 +0800 Subject: [PATCH 46/56] feat move find_package(Git REQUIRED) --- CMakeLists.txt | 2 ++ cmake/BuildInfo.cmake | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5f45181..50901ee 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -67,6 +67,8 @@ include(cmake/BuildInfo.cmake) check_symbol_exists("getifaddrs" "ifaddrs.h" TILE_HAVE_GETIFADDRS) check_symbol_exists("freeifaddrs" "ifaddrs.h" TILE_HAVE_FREEIFADDRS) +find_package(Git REQUIRED) + get_git_commit_hash(GIT_COMMIT_HASH) get_git_commit_date(GIT_COMMIT_DATE) get_git_commit_subject(GIT_COMMIT_SUBJECT) diff --git a/cmake/BuildInfo.cmake b/cmake/BuildInfo.cmake index e2c19a6..33c60ac 100644 --- a/cmake/BuildInfo.cmake +++ b/cmake/BuildInfo.cmake @@ -1,5 +1,3 @@ -find_package(Git REQUIRED) - macro(get_git_commit_hash output) # full commit hash execute_process( From 80e184af0712de89e9b314c939d04a1cd7276a1f Mon Sep 17 00:00:00 2001 From: tqcq <99722391+tqcq@users.noreply.github.com> Date: Mon, 17 Jun 2024 14:52:25 +0800 Subject: [PATCH 47/56] feat test use multi thread --- .gitea/workflows/linux-aarch64-gcc.yml | 2 +- .gitea/workflows/linux-arm-gcc.yml | 4 ++-- .gitea/workflows/linux-mips-gcc.yml | 2 +- .gitea/workflows/linux-mips64-gcc.yml | 2 +- .gitea/workflows/linux-riscv64-gcc.yml | 2 +- .gitea/workflows/linux-x64-gcc.yml | 2 +- .gitea/workflows/linux-x86-gcc.yml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.gitea/workflows/linux-aarch64-gcc.yml b/.gitea/workflows/linux-aarch64-gcc.yml index 91cddc2..7ebe318 100644 --- a/.gitea/workflows/linux-aarch64-gcc.yml +++ b/.gitea/workflows/linux-aarch64-gcc.yml @@ -52,4 +52,4 @@ jobs: cd build sudo ln -sf /usr/aarch64-linux-gnu/lib/ld-linux-aarch64.so.1 /lib/ld-linux-aarch64.so.1 export LD_LIBRARY_PATH=/usr/aarch64-linux-gnu/lib - ctest --output-on-failure + ctest --output-on-failure -j $(nproc) diff --git a/.gitea/workflows/linux-arm-gcc.yml b/.gitea/workflows/linux-arm-gcc.yml index 08adabc..608eedc 100644 --- a/.gitea/workflows/linux-arm-gcc.yml +++ b/.gitea/workflows/linux-arm-gcc.yml @@ -50,7 +50,7 @@ jobs: cd build sudo ln -sf /usr/arm-linux-gnueabi/lib/ld-linux.so.3 /lib/ld-linux.so.3 export LD_LIBRARY_PATH=/usr/arm-linux-gnueabi/lib - ctest --output-on-failure + ctest --output-on-failure -j $(nproc) linux-gcc-armhf: runs-on: ubuntu-20.04 @@ -75,4 +75,4 @@ jobs: cd build sudo ln -sf /usr/arm-linux-gnueabihf/lib/ld-linux-armhf.so.3 /lib/ld-linux-armhf.so.3 export LD_LIBRARY_PATH=/usr/arm-linux-gnueabihf/lib/ - ctest --output-on-failure + ctest --output-on-failure -j $(nproc) diff --git a/.gitea/workflows/linux-mips-gcc.yml b/.gitea/workflows/linux-mips-gcc.yml index 82abf1a..e1ee3a0 100644 --- a/.gitea/workflows/linux-mips-gcc.yml +++ b/.gitea/workflows/linux-mips-gcc.yml @@ -50,4 +50,4 @@ jobs: cd build sudo ln -sf /usr/mipsel-linux-gnu/lib/ld.so.1 /lib/ld.so.1 export LD_LIBRARY_PATH=/usr/mipsel-linux-gnu/lib/ - ctest --output-on-failure + ctest --output-on-failure -j $(nproc) diff --git a/.gitea/workflows/linux-mips64-gcc.yml b/.gitea/workflows/linux-mips64-gcc.yml index 315b29f..23a500f 100644 --- a/.gitea/workflows/linux-mips64-gcc.yml +++ b/.gitea/workflows/linux-mips64-gcc.yml @@ -51,4 +51,4 @@ jobs: cd build sudo ln -sf /usr/mips64el-linux-gnuabi64/lib64/ld.so.1 /lib64/ld.so.1 export LD_LIBRARY_PATH=/usr/mips64el-linux-gnuabi64/lib - ctest --output-on-failure + ctest --output-on-failure -j $(nproc) diff --git a/.gitea/workflows/linux-riscv64-gcc.yml b/.gitea/workflows/linux-riscv64-gcc.yml index 6c553b8..1c6566a 100644 --- a/.gitea/workflows/linux-riscv64-gcc.yml +++ b/.gitea/workflows/linux-riscv64-gcc.yml @@ -52,4 +52,4 @@ jobs: cd build sudo ln -sf /usr/riscv64-linux-gnu/lib/ld-linux-riscv64-lp64d.so.1 /lib/ld-linux-riscv64-lp64d.so.1 export LD_LIBRARY_PATH=/usr/riscv64-linux-gnu/lib - ctest --output-on-failure + ctest --output-on-failure -j $(nproc) diff --git a/.gitea/workflows/linux-x64-gcc.yml b/.gitea/workflows/linux-x64-gcc.yml index 50fdca2..dd09d6f 100644 --- a/.gitea/workflows/linux-x64-gcc.yml +++ b/.gitea/workflows/linux-x64-gcc.yml @@ -47,7 +47,7 @@ jobs: - name: test run: | cd build - ctest --output-on-failure + ctest --output-on-failure -j $(nproc) - name: benchmark run: | ./build/tile_bm_all diff --git a/.gitea/workflows/linux-x86-gcc.yml b/.gitea/workflows/linux-x86-gcc.yml index 83d1d95..c72322b 100644 --- a/.gitea/workflows/linux-x86-gcc.yml +++ b/.gitea/workflows/linux-x86-gcc.yml @@ -49,7 +49,7 @@ jobs: - name: test run: | cd build - ctest --output-on-failure + ctest --output-on-failure -j $(nproc) - name: benchmark run: | ./build/tile_bm_all From 3fe1b1bf4c2f003efccd70097408e73035e7e051 Mon Sep 17 00:00:00 2001 From: tqcq <99722391+tqcq@users.noreply.github.com> Date: Mon, 17 Jun 2024 15:12:02 +0800 Subject: [PATCH 48/56] feat add mxgot for misp --- toolchains/mips64el-linux-gnuabi64.toolchain.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/toolchains/mips64el-linux-gnuabi64.toolchain.cmake b/toolchains/mips64el-linux-gnuabi64.toolchain.cmake index b6a8c09..20248ff 100644 --- a/toolchains/mips64el-linux-gnuabi64.toolchain.cmake +++ b/toolchains/mips64el-linux-gnuabi64.toolchain.cmake @@ -18,8 +18,8 @@ if(NOT CMAKE_FIND_ROOT_PATH_MODE_PACKAGE) set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) endif() -set(CMAKE_C_FLAGS "-march=mips64 -mno-xgot") -set(CMAKE_CXX_FLAGS "-march=mips64 -mno-xgot") +set(CMAKE_C_FLAGS "-march=mips64 -mxgot") +set(CMAKE_CXX_FLAGS "-march=mips64 -mxgot") # cache flags set(CMAKE_C_FLAGS From d3d60da45accd662798e04916d237d7d8f8a86fb Mon Sep 17 00:00:00 2001 From: tqcq <99722391+tqcq@users.noreply.github.com> Date: Mon, 17 Jun 2024 15:28:32 +0800 Subject: [PATCH 49/56] fix i386 fiber asm --- CMakeLists.txt | 2 +- toolchains/host.gcc-m32.toolchain.cmake | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 50901ee..8c79940 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,7 +21,7 @@ option(TILE_WITH_OPENSSL "Build with openssl" OFF) option(TILE_BUILD_SHARED "Build shared library" ON) option(TILE_BUILD_STATIC "Build static library" ON) -if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_PROJECT_DIR) +if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) set(TILE_BUILD_TESTS ON) set(TILE_BUILD_BENCHMARKS ON) endif() diff --git a/toolchains/host.gcc-m32.toolchain.cmake b/toolchains/host.gcc-m32.toolchain.cmake index 5b2abd1..d646167 100644 --- a/toolchains/host.gcc-m32.toolchain.cmake +++ b/toolchains/host.gcc-m32.toolchain.cmake @@ -10,7 +10,9 @@ set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) set(CMAKE_C_FLAGS "-m32") set(CMAKE_CXX_FLAGS "-m32") +set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -m32") # cache flags set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "c flags") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" CACHE STRING "c++ flags") +set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS}" CACHE STRING "asm flags") From 6e7d46c259948bcf2289d8f829d8b3a0814b7d65 Mon Sep 17 00:00:00 2001 From: tqcq <99722391+tqcq@users.noreply.github.com> Date: Mon, 17 Jun 2024 15:33:07 +0800 Subject: [PATCH 50/56] feat update split configure,build --- .gitea/workflows/linux-aarch64-gcc.yml | 5 ++++- .gitea/workflows/linux-arm-gcc.yml | 10 ++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/.gitea/workflows/linux-aarch64-gcc.yml b/.gitea/workflows/linux-aarch64-gcc.yml index 7ebe318..3676172 100644 --- a/.gitea/workflows/linux-aarch64-gcc.yml +++ b/.gitea/workflows/linux-aarch64-gcc.yml @@ -42,10 +42,13 @@ jobs: # run: | # sudo apt-get update -y # sudo apt-get install -y g++-aarch64-linux-gnu qemu-user-binfmt - - name: build + - name: configure run: | mkdir build && cd build cmake -DCMAKE_TOOLCHAIN_FILE=../toolchains/aarch64-linux-gnu.toolchain.cmake -DCMAKE_BUILD_TYPE=${{matrix.build_type}} -DTILE_BUILD_TESTS=ON -DTILE_BUILD_BENCHMARKS=ON .. + - name: build + run: | + cd build cmake --build . -j $(nproc) - name: test run: |- diff --git a/.gitea/workflows/linux-arm-gcc.yml b/.gitea/workflows/linux-arm-gcc.yml index 608eedc..28ace26 100644 --- a/.gitea/workflows/linux-arm-gcc.yml +++ b/.gitea/workflows/linux-arm-gcc.yml @@ -40,10 +40,13 @@ jobs: # run: | # sudo apt-get update -y # sudo apt-get install -y g++-arm-linux-gnueabi qemu-user-binfmt - - name: build + - name: configure run: | mkdir build && cd build cmake -DCMAKE_TOOLCHAIN_FILE=../toolchains/arm-linux-gnueabi.toolchain.cmake -DCMAKE_BUILD_TYPE=${{matrix.build_type}} -DTILE_BUILD_TESTS=ON -DTILE_BUILD_TESTS=ON .. + - name: build + run: | + cd build cmake --build . -j $(nproc) - name: test run: | @@ -65,10 +68,13 @@ jobs: run: | sudo apt-get update -y sudo apt-get install -y cmake make g++-arm-linux-gnueabihf qemu-user-binfmt - - name: build + - name: configure run: | mkdir build && cd build cmake -DCMAKE_TOOLCHAIN_FILE=../toolchains/arm-linux-gnueabihf.toolchain.cmake -DCMAKE_BUILD_TYPE=${{matrix.build_type}} -DTILE_BUILD_TESTS=ON -DTILE_BUILD_BENCHMARKS=ON .. + - name: build + run: | + cd build cmake --build . -j $(nproc) - name: test run: |- From 4fc64d5028ee7c8edaa76165d214e2564e1bd90b Mon Sep 17 00:00:00 2001 From: tqcq <99722391+tqcq@users.noreply.github.com> Date: Mon, 17 Jun 2024 20:08:36 +0800 Subject: [PATCH 51/56] fix chrono_test --- tile/base/chrono_test.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tile/base/chrono_test.cc b/tile/base/chrono_test.cc index 8df941c..524fbce 100644 --- a/tile/base/chrono_test.cc +++ b/tile/base/chrono_test.cc @@ -5,8 +5,9 @@ namespace tile { static constexpr auto one_ms = std::chrono::milliseconds(1); +static constexpr auto kTestN = 1000; -long AvageTime(std::function f, std::size_t n = 100) { +long AvageTime(std::function f, std::size_t n = kTestN) { long double total = 0; for (std::size_t i = 0; i != n; ++i) { total += 1.0f / n * f(); @@ -34,7 +35,7 @@ TEST(CoarseSystemClock, Compare) { return (ReadCoarseSystemClock() - std::chrono::system_clock::now()) / one_ms; }); - ASSERT_NEAR(diff, 0, 50); + ASSERT_NEAR(diff, 0, kTestN); } TEST(CoarseSteadyClock, Compare) { @@ -42,6 +43,6 @@ TEST(CoarseSteadyClock, Compare) { return (ReadCoarseSteadyClock() - std::chrono::steady_clock::now()) / one_ms; }); - ASSERT_NEAR(diff, 0, 50); + ASSERT_NEAR(diff, 0, kTestN); } } // namespace tile From 31ca7c9f6b4bca727d0a1d599cb7cc2c1a399433 Mon Sep 17 00:00:00 2001 From: tqcq <99722391+tqcq@users.noreply.github.com> Date: Mon, 17 Jun 2024 22:46:00 +0800 Subject: [PATCH 52/56] feat add fiber switch benchmark --- CMakeLists.txt | 7 ++++ tile/fiber/detail/fiber_benchmark.cc | 45 ++++++++++++++++++++++++++ tile/fiber/detail/scheduler.cc | 16 ++++++++++ tile/fiber/detail/scheduler.h | 1 + tile/fiber/detail/scheduler_test.cc | 2 +- tile/fiber/detail/waitable.cc | 42 ++++++++++++++++++++++++ tile/fiber/detail/waitable.h | 48 ++++++++++++++++++++++++++++ 7 files changed, 160 insertions(+), 1 deletion(-) create mode 100644 tile/fiber/detail/fiber_benchmark.cc create mode 100644 tile/fiber/detail/waitable.cc create mode 100644 tile/fiber/detail/waitable.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 8c79940..3ab08e6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,6 +21,9 @@ option(TILE_WITH_OPENSSL "Build with openssl" OFF) option(TILE_BUILD_SHARED "Build shared library" ON) option(TILE_BUILD_STATIC "Build static library" ON) +# set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "time") +# set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK "time") + if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) set(TILE_BUILD_TESTS ON) set(TILE_BUILD_BENCHMARKS ON) @@ -207,6 +210,9 @@ endif() add_library(tile OBJECT ${TILE_SRCS}) set_target_properties(tile PROPERTIES VERSION ${PROJECT_VERSION} +target_precompile_headers(tile PUBLIC inja/inja.h) +target_precompile_headers(tile PUBLIC inja/string_view.h) +target_precompile_headers(tile PUBLIC json/nlohann/json.hpp) SOVERSION "${tile_VERSION_MAJRO}") # target_sources(tile PRIVATE ${TILE_SRCS}) target_include_directories( @@ -358,6 +364,7 @@ if(TILE_BUILD_BENCHMARKS) target_sources(tile_bm_all PRIVATE ${benchmark_file}) endmacro() +tile_add_bm(fiber_detail_fiber_benchmark "tile/fiber/detail/fiber_benchmark.cc") tile_add_bm(base_casting_benchmark "tile/base/casting_benchmark.cc") tile_add_bm(base_thread_mutex_benchmark "tile/base/thread/mutex_benchmark.cc") tile_add_bm(base_encoding_benchmark "tile/base/encoding_benchmark.cc") diff --git a/tile/fiber/detail/fiber_benchmark.cc b/tile/fiber/detail/fiber_benchmark.cc new file mode 100644 index 0000000..1b053a2 --- /dev/null +++ b/tile/fiber/detail/fiber_benchmark.cc @@ -0,0 +1,45 @@ +#include "tile/base/random.h" +#include "tile/fiber/detail/fiber.h" + +#include "benchmark/benchmark.h" +namespace tile { +namespace fiber { +namespace detail { + +void Benchmark_FiberSwitch(benchmark::State &state) { + constexpr int kFiberCount = 10000; + std::unique_ptr master; + std::unique_ptr worker[kFiberCount]; + + int cnt = 0; + + master = Fiber::Create([&]() { + while (state.KeepRunning()) { + ++cnt; + worker[Random(kFiberCount - 1)]->Resume(); + } + + cnt = -1; + for (int i = 0; i != kFiberCount; ++i) { + worker[i]->Resume(); + } + }); + + for (int i = 0; i != kFiberCount; ++i) { + worker[i] = Fiber::Create([&, i]() { + while (cnt != -1) { + master->Resume(); + } + }); + } + + SetUpMasterFiber(master.get()); + SetUpCurrentFiber(nullptr); + + master->Resume(); +} + +BENCHMARK(Benchmark_FiberSwitch); +} // namespace detail +} // namespace fiber +} // namespace tile diff --git a/tile/fiber/detail/scheduler.cc b/tile/fiber/detail/scheduler.cc index b1a8dac..7d4c719 100644 --- a/tile/fiber/detail/scheduler.cc +++ b/tile/fiber/detail/scheduler.cc @@ -20,9 +20,25 @@ void Scheduler::SwitchTo(Fiber *self, Fiber *to) { void Scheduler::Yield(Fiber *self) { auto master = GetMasterFiber(); + TILE_CHECK(self, "self fiber is nullptr."); + TILE_CHECK(master, "Master fiber is not set."); master->state_ = FiberState::Runnable; + self->state_ = FiberState::Running; SwitchTo(self, master); } + +void Scheduler::Halt(Fiber *self) { + TILE_CHECK_EQ(self, GetCurrentFiber(), "Fiber is not current fiber."); + TILE_CHECK(self->state() == FiberState::Running, "Fiber is not running."); + + auto master = GetMasterFiber(); + self->state_ = FiberState::Waiting; + + master->Resume(); + + TILE_CHECK_EQ(self, GetCurrentFiber()); +} + } // namespace detail } // namespace fiber } // namespace tile diff --git a/tile/fiber/detail/scheduler.h b/tile/fiber/detail/scheduler.h index d889ddb..594c695 100644 --- a/tile/fiber/detail/scheduler.h +++ b/tile/fiber/detail/scheduler.h @@ -15,6 +15,7 @@ public: void SwitchTo(Fiber *self, Fiber *to); void Yield(Fiber *self); + void Halt(Fiber *self); }; } // namespace detail } // namespace fiber diff --git a/tile/fiber/detail/scheduler_test.cc b/tile/fiber/detail/scheduler_test.cc index ef128d5..84a0a1f 100644 --- a/tile/fiber/detail/scheduler_test.cc +++ b/tile/fiber/detail/scheduler_test.cc @@ -11,7 +11,7 @@ namespace detail { TEST(Fiber, Resume) { constexpr int kFiberCount = 1000; - constexpr int kSwitchCount = 100000; + constexpr int kSwitchCount = 1000 * 1000; std::unique_ptr master; std::unique_ptr worker[kFiberCount]; diff --git a/tile/fiber/detail/waitable.cc b/tile/fiber/detail/waitable.cc new file mode 100644 index 0000000..eba155e --- /dev/null +++ b/tile/fiber/detail/waitable.cc @@ -0,0 +1,42 @@ +#include "tile/fiber/detail/waitable.h" +#include "tile/base/thread/scoped_lock.h" + +namespace tile { +namespace fiber { +namespace detail { +WaitList::WaitList() {} +WaitList::~WaitList() {} + +bool WaitList::AddWaiter(WaitListNode *node) { + ScopedLock _(lock_); + TILE_CHECK(node->waiter); + + waiters_.push_back(node); + return true; +} + +Fiber *WaitList::WakeOne() { + ScopedLock _(lock_); + while (true) { + if (waiters_.empty()) { + return nullptr; + } + + WaitListNode *waiter = waiters_.front(); + waiters_.pop_front(); + if (!waiter) { + return nullptr; + } + + if (waiter->satisfied.exchange(true, std::memory_order_relaxed)) { + continue; + ; + } + + return waiter->waiter; + } +} + +} // namespace detail +} // namespace fiber +} // namespace tile diff --git a/tile/fiber/detail/waitable.h b/tile/fiber/detail/waitable.h new file mode 100644 index 0000000..2bb04cd --- /dev/null +++ b/tile/fiber/detail/waitable.h @@ -0,0 +1,48 @@ +#ifndef TILE_FIBER_DETAIL_WAITABLE_H +#define TILE_FIBER_DETAIL_WAITABLE_H + +#pragma once + +#include "tile/base/internal/singly_linked_list.h" +#include "tile/base/thread/spinlock.h" + +#include + +namespace tile { +namespace fiber { +namespace detail { + +class Fiber; +class Scheduler; + +struct WaitListNode { + Fiber *waiter = nullptr; + tile::internal::SinglyLinkedListEntry chain; + std::atomic satisfied{false}; +}; + +class WaitList { +public: + WaitList(); + ~WaitList(); + + bool AddWaiter(WaitListNode *node); + // Remove the waiter from the list. + // return true if the waiter is removed, otherwise return nullptr. + Fiber *WakeOne(); + + WaitList(const WaitList &) = delete; + WaitList &operator=(const WaitList &) = delete; + +private: + Spinlock lock_; + std::list waiters_; + // tile::internal::SinglyLinkedList + // waiters_; +}; + +} // namespace detail +} // namespace fiber +} // namespace tile + +#endif // TILE_FIBER_DETAIL_WAITABLE_H From ed0dfc9c6f1f61452c3973fda0241a1838a1a305 Mon Sep 17 00:00:00 2001 From: tqcq <99722391+tqcq@users.noreply.github.com> Date: Thu, 20 Jun 2024 21:17:12 +0800 Subject: [PATCH 53/56] feat use jsoncpp --- CMakeLists.txt | 5 +- third_party/jsoncpp/.clang-format | 4 + third_party/jsoncpp/.clang-tidy | 11 + third_party/jsoncpp/.gitattributes | 11 + .../.github/ISSUE_TEMPLATE/bug_report.md | 26 + .../.github/ISSUE_TEMPLATE/feature_request.md | 20 + third_party/jsoncpp/.gitignore | 57 + third_party/jsoncpp/.travis.yml | 71 + .../jsoncpp/.travis_scripts/cmake_builder.sh | 130 + .../jsoncpp/.travis_scripts/meson_builder.sh | 83 + .../.travis_scripts/run-clang-format.py | 356 ++ .../.travis_scripts/run-clang-format.sh | 4 + .../travis.before_install.linux.sh | 8 + .../travis.before_install.osx.sh | 0 .../.travis_scripts/travis.install.linux.sh | 5 + .../.travis_scripts/travis.install.osx.sh | 1 + third_party/jsoncpp/AUTHORS | 115 + third_party/jsoncpp/BUILD.bazel | 37 + third_party/jsoncpp/CMakeLists.txt | 245 + third_party/jsoncpp/CONTRIBUTING.md | 152 + third_party/jsoncpp/CTestConfig.cmake | 15 + third_party/jsoncpp/LICENSE | 55 + third_party/jsoncpp/README.md | 67 + third_party/jsoncpp/amalgamate.py | 161 + third_party/jsoncpp/appveyor.yml | 37 + third_party/jsoncpp/cmake/JoinPaths.cmake | 23 + third_party/jsoncpp/dev.makefile | 37 + third_party/jsoncpp/devtools/__init__.py | 6 + third_party/jsoncpp/devtools/agent_vmw7.json | 33 + third_party/jsoncpp/devtools/agent_vmxp.json | 26 + third_party/jsoncpp/devtools/antglob.py | 205 + third_party/jsoncpp/devtools/batchbuild.py | 278 ++ third_party/jsoncpp/devtools/fixeol.py | 70 + .../jsoncpp/devtools/licenseupdater.py | 94 + third_party/jsoncpp/devtools/tarball.py | 52 + third_party/jsoncpp/doc/doxyfile.in | 2302 ++++++++++ third_party/jsoncpp/doc/footer.html | 21 + third_party/jsoncpp/doc/header.html | 64 + third_party/jsoncpp/doc/jsoncpp.dox | 164 + third_party/jsoncpp/doc/readme.txt | 1 + third_party/jsoncpp/doc/roadmap.dox | 3 + third_party/jsoncpp/doc/web_doxyfile.in | 2290 ++++++++++ third_party/jsoncpp/doxybuild.py | 189 + third_party/jsoncpp/example/CMakeLists.txt | 27 + third_party/jsoncpp/example/README.md | 13 + .../example/readFromStream/errorFormat.json | 3 + .../example/readFromStream/readFromStream.cpp | 30 + .../example/readFromStream/withComment.json | 6 + .../example/readFromString/readFromString.cpp | 38 + .../example/streamWrite/streamWrite.cpp | 23 + .../example/stringWrite/stringWrite.cpp | 33 + third_party/jsoncpp/get_version.pl | 5 + third_party/jsoncpp/include/CMakeLists.txt | 5 + .../include/PreventInBuildInstalls.cmake | 9 + .../include/PreventInSourceBuilds.cmake | 45 + third_party/jsoncpp/include/json/allocator.h | 88 + third_party/jsoncpp/include/json/assertions.h | 61 + third_party/jsoncpp/include/json/config.h | 150 + third_party/jsoncpp/include/json/forwards.h | 43 + third_party/jsoncpp/include/json/json.h | 15 + .../jsoncpp/include/json/json_features.h | 61 + third_party/jsoncpp/include/json/reader.h | 405 ++ third_party/jsoncpp/include/json/value.h | 935 ++++ third_party/jsoncpp/include/json/version.h | 28 + third_party/jsoncpp/include/json/writer.h | 369 ++ .../jsoncpp/jsoncpp-namespaced-targets.cmake | 7 + third_party/jsoncpp/jsoncppConfig.cmake.in | 11 + third_party/jsoncpp/meson.build | 119 + third_party/jsoncpp/meson_options.txt | 5 + third_party/jsoncpp/pkg-config/jsoncpp.pc.in | 11 + third_party/jsoncpp/reformat.sh | 1 + third_party/jsoncpp/src/CMakeLists.txt | 5 + .../jsoncpp/src/jsontestrunner/CMakeLists.txt | 51 + .../jsoncpp/src/jsontestrunner/main.cpp | 343 ++ .../jsoncpp/src/lib_json/CMakeLists.txt | 223 + .../jsoncpp/src/lib_json/json_reader.cpp | 1992 +++++++++ third_party/jsoncpp/src/lib_json/json_tool.h | 138 + .../jsoncpp/src/lib_json/json_value.cpp | 1634 +++++++ .../src/lib_json/json_valueiterator.inl | 156 + .../jsoncpp/src/lib_json/json_writer.cpp | 1259 ++++++ .../jsoncpp/src/test_lib_json/CMakeLists.txt | 39 + .../jsoncpp/src/test_lib_json/fuzz.cpp | 54 + .../jsoncpp/src/test_lib_json/fuzz.dict | 54 + third_party/jsoncpp/src/test_lib_json/fuzz.h | 14 + .../jsoncpp/src/test_lib_json/jsontest.cpp | 430 ++ .../jsoncpp/src/test_lib_json/jsontest.h | 288 ++ .../jsoncpp/src/test_lib_json/main.cpp | 3971 +++++++++++++++++ third_party/jsoncpp/version.in | 1 + tile/base/data/json.h | 13 +- tile/base/option.cc | 2 +- tile/base/option.h | 2 +- tile/base/option/json_parser.cc | 11 +- tile/base/option/json_parser.h | 4 +- tile/base/option/json_parser_test.cc | 3 +- tile/base/option/option_service.cc | 8 +- tile/base/option/option_service.h | 8 +- tile/base/option/option_service_test.cc | 8 +- 97 files changed, 20761 insertions(+), 30 deletions(-) create mode 100644 third_party/jsoncpp/.clang-format create mode 100644 third_party/jsoncpp/.clang-tidy create mode 100644 third_party/jsoncpp/.gitattributes create mode 100644 third_party/jsoncpp/.github/ISSUE_TEMPLATE/bug_report.md create mode 100644 third_party/jsoncpp/.github/ISSUE_TEMPLATE/feature_request.md create mode 100644 third_party/jsoncpp/.gitignore create mode 100644 third_party/jsoncpp/.travis.yml create mode 100755 third_party/jsoncpp/.travis_scripts/cmake_builder.sh create mode 100755 third_party/jsoncpp/.travis_scripts/meson_builder.sh create mode 100755 third_party/jsoncpp/.travis_scripts/run-clang-format.py create mode 100755 third_party/jsoncpp/.travis_scripts/run-clang-format.sh create mode 100644 third_party/jsoncpp/.travis_scripts/travis.before_install.linux.sh create mode 100644 third_party/jsoncpp/.travis_scripts/travis.before_install.osx.sh create mode 100644 third_party/jsoncpp/.travis_scripts/travis.install.linux.sh create mode 100644 third_party/jsoncpp/.travis_scripts/travis.install.osx.sh create mode 100644 third_party/jsoncpp/AUTHORS create mode 100644 third_party/jsoncpp/BUILD.bazel create mode 100644 third_party/jsoncpp/CMakeLists.txt create mode 100644 third_party/jsoncpp/CONTRIBUTING.md create mode 100644 third_party/jsoncpp/CTestConfig.cmake create mode 100644 third_party/jsoncpp/LICENSE create mode 100644 third_party/jsoncpp/README.md create mode 100755 third_party/jsoncpp/amalgamate.py create mode 100644 third_party/jsoncpp/appveyor.yml create mode 100644 third_party/jsoncpp/cmake/JoinPaths.cmake create mode 100644 third_party/jsoncpp/dev.makefile create mode 100644 third_party/jsoncpp/devtools/__init__.py create mode 100644 third_party/jsoncpp/devtools/agent_vmw7.json create mode 100644 third_party/jsoncpp/devtools/agent_vmxp.json create mode 100644 third_party/jsoncpp/devtools/antglob.py create mode 100644 third_party/jsoncpp/devtools/batchbuild.py create mode 100644 third_party/jsoncpp/devtools/fixeol.py create mode 100644 third_party/jsoncpp/devtools/licenseupdater.py create mode 100644 third_party/jsoncpp/devtools/tarball.py create mode 100644 third_party/jsoncpp/doc/doxyfile.in create mode 100644 third_party/jsoncpp/doc/footer.html create mode 100644 third_party/jsoncpp/doc/header.html create mode 100644 third_party/jsoncpp/doc/jsoncpp.dox create mode 100644 third_party/jsoncpp/doc/readme.txt create mode 100644 third_party/jsoncpp/doc/roadmap.dox create mode 100644 third_party/jsoncpp/doc/web_doxyfile.in create mode 100644 third_party/jsoncpp/doxybuild.py create mode 100644 third_party/jsoncpp/example/CMakeLists.txt create mode 100644 third_party/jsoncpp/example/README.md create mode 100644 third_party/jsoncpp/example/readFromStream/errorFormat.json create mode 100644 third_party/jsoncpp/example/readFromStream/readFromStream.cpp create mode 100644 third_party/jsoncpp/example/readFromStream/withComment.json create mode 100644 third_party/jsoncpp/example/readFromString/readFromString.cpp create mode 100644 third_party/jsoncpp/example/streamWrite/streamWrite.cpp create mode 100644 third_party/jsoncpp/example/stringWrite/stringWrite.cpp create mode 100644 third_party/jsoncpp/get_version.pl create mode 100644 third_party/jsoncpp/include/CMakeLists.txt create mode 100644 third_party/jsoncpp/include/PreventInBuildInstalls.cmake create mode 100644 third_party/jsoncpp/include/PreventInSourceBuilds.cmake create mode 100644 third_party/jsoncpp/include/json/allocator.h create mode 100644 third_party/jsoncpp/include/json/assertions.h create mode 100644 third_party/jsoncpp/include/json/config.h create mode 100644 third_party/jsoncpp/include/json/forwards.h create mode 100644 third_party/jsoncpp/include/json/json.h create mode 100644 third_party/jsoncpp/include/json/json_features.h create mode 100644 third_party/jsoncpp/include/json/reader.h create mode 100644 third_party/jsoncpp/include/json/value.h create mode 100644 third_party/jsoncpp/include/json/version.h create mode 100644 third_party/jsoncpp/include/json/writer.h create mode 100644 third_party/jsoncpp/jsoncpp-namespaced-targets.cmake create mode 100644 third_party/jsoncpp/jsoncppConfig.cmake.in create mode 100644 third_party/jsoncpp/meson.build create mode 100644 third_party/jsoncpp/meson_options.txt create mode 100644 third_party/jsoncpp/pkg-config/jsoncpp.pc.in create mode 100755 third_party/jsoncpp/reformat.sh create mode 100644 third_party/jsoncpp/src/CMakeLists.txt create mode 100644 third_party/jsoncpp/src/jsontestrunner/CMakeLists.txt create mode 100644 third_party/jsoncpp/src/jsontestrunner/main.cpp create mode 100644 third_party/jsoncpp/src/lib_json/CMakeLists.txt create mode 100644 third_party/jsoncpp/src/lib_json/json_reader.cpp create mode 100644 third_party/jsoncpp/src/lib_json/json_tool.h create mode 100644 third_party/jsoncpp/src/lib_json/json_value.cpp create mode 100644 third_party/jsoncpp/src/lib_json/json_valueiterator.inl create mode 100644 third_party/jsoncpp/src/lib_json/json_writer.cpp create mode 100644 third_party/jsoncpp/src/test_lib_json/CMakeLists.txt create mode 100644 third_party/jsoncpp/src/test_lib_json/fuzz.cpp create mode 100644 third_party/jsoncpp/src/test_lib_json/fuzz.dict create mode 100644 third_party/jsoncpp/src/test_lib_json/fuzz.h create mode 100644 third_party/jsoncpp/src/test_lib_json/jsontest.cpp create mode 100644 third_party/jsoncpp/src/test_lib_json/jsontest.h create mode 100644 third_party/jsoncpp/src/test_lib_json/main.cpp create mode 100644 third_party/jsoncpp/version.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 3ab08e6..6a83176 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -77,10 +77,12 @@ get_git_commit_date(GIT_COMMIT_DATE) get_git_commit_subject(GIT_COMMIT_SUBJECT) set(THIRD_PARTY_INCLUDE_DIRS - "third_party/json" "third_party/inja" "third_party/sigslot" + # "third_party/json" "third_party/inja" + "third_party/sigslot" "${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include") include_directories(${THIRD_PARTY_INCLUDE_DIRS}) add_subdirectory("third_party/zlib") +add_subdirectory("third_party/jsoncpp") add_subdirectory("third_party/fmt") add_subdirectory("third_party/googletest") add_subdirectory("third_party/gflags") @@ -230,6 +232,7 @@ target_link_libraries( tile PUBLIC # -Wl,--start-group nova_context zlib gflags::gflags glog::glog + jsoncpp_static # -Wl,--end-group libcurl fmt) if((CMAKE_SYSTEM_PROCESSOR MATCHES "riscv64") OR (CMAKE_SYSTEM_PROCESSOR MATCHES diff --git a/third_party/jsoncpp/.clang-format b/third_party/jsoncpp/.clang-format new file mode 100644 index 0000000..2a80669 --- /dev/null +++ b/third_party/jsoncpp/.clang-format @@ -0,0 +1,4 @@ +BasedOnStyle: LLVM +DerivePointerAlignment: false +PointerAlignment: Left + diff --git a/third_party/jsoncpp/.clang-tidy b/third_party/jsoncpp/.clang-tidy new file mode 100644 index 0000000..99e914d --- /dev/null +++ b/third_party/jsoncpp/.clang-tidy @@ -0,0 +1,11 @@ +--- +Checks: 'google-readability-casting,modernize-deprecated-headers,modernize-loop-convert,modernize-use-auto,modernize-use-default-member-init,modernize-use-using,readability-else-after-return,readability-redundant-member-init,readability-redundant-string-cstr' +WarningsAsErrors: '' +HeaderFilterRegex: '' +AnalyzeTemporaryDtors: false +FormatStyle: none +CheckOptions: + - key: modernize-use-using.IgnoreMacros + value: '0' +... + diff --git a/third_party/jsoncpp/.gitattributes b/third_party/jsoncpp/.gitattributes new file mode 100644 index 0000000..22d2b7a --- /dev/null +++ b/third_party/jsoncpp/.gitattributes @@ -0,0 +1,11 @@ +* text=auto +*.h text +*.cpp text +*.json text +*.in text +*.sh eol=lf +*.bat eol=crlf +*.vcproj eol=crlf +*.vcxproj eol=crlf +*.sln eol=crlf +devtools/agent_vm* eol=crlf diff --git a/third_party/jsoncpp/.github/ISSUE_TEMPLATE/bug_report.md b/third_party/jsoncpp/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..3547709 --- /dev/null +++ b/third_party/jsoncpp/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,26 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: '' +assignees: '' + +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** +Steps to reproduce the behavior: +1. + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Desktop (please complete the following information):** + - OS: [e.g. iOS] + - Meson version + - Ninja version + +**Additional context** +Add any other context about the problem here. diff --git a/third_party/jsoncpp/.github/ISSUE_TEMPLATE/feature_request.md b/third_party/jsoncpp/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..bbcbbe7 --- /dev/null +++ b/third_party/jsoncpp/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,20 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: '' +labels: '' +assignees: '' + +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. diff --git a/third_party/jsoncpp/.gitignore b/third_party/jsoncpp/.gitignore new file mode 100644 index 0000000..9682782 --- /dev/null +++ b/third_party/jsoncpp/.gitignore @@ -0,0 +1,57 @@ +/build/ +/build-*/ +*.pyc +*.swp +*.actual +*.actual-rewrite +*.process-output +*.rewrite +/bin/ +/libs/ +/doc/doxyfile +/dist/ +/.cache/ + +# MSVC project files: +*.sln +*.vcxproj +*.filters +*.user +*.sdf +*.opensdf +*.suo + +# MSVC build files: +*.lib +*.obj +*.tlog/ +*.pdb + +# CMake-generated files: +CMakeFiles/ +/pkg-config/jsoncpp.pc +jsoncpp_lib_static.dir/ +compile_commands.json + +# In case someone runs cmake in the root-dir: +/CMakeCache.txt +/Makefile +/include/Makefile +/src/Makefile +/src/jsontestrunner/Makefile +/src/jsontestrunner/jsontestrunner_exe +/src/lib_json/Makefile +/src/test_lib_json/Makefile +/src/test_lib_json/jsoncpp_test +*.a + +# eclipse project files +.project +.cproject +/.settings/ + +# DS_Store +.DS_Store + +# temps +/version diff --git a/third_party/jsoncpp/.travis.yml b/third_party/jsoncpp/.travis.yml new file mode 100644 index 0000000..23acd4e --- /dev/null +++ b/third_party/jsoncpp/.travis.yml @@ -0,0 +1,71 @@ +# Build matrix / environment variables are explained on: +# http://about.travis-ci.com/docs/user/build-configuration/ +# This file can be validated on: http://www.yamllint.com/ +# Or using the Ruby based travel command line tool: +# gem install travis --no-rdoc --no-ri +# travis lint .travis.yml +language: cpp +sudo: false +addons: + homebrew: + packages: + - clang-format + - meson + - ninja + update: false # do not update homebrew by default + apt: + sources: + - ubuntu-toolchain-r-test + - llvm-toolchain-xenial-8 + packages: + - clang-format-8 + - clang-8 + - valgrind +matrix: + include: + - name: Mac clang meson static release testing + os: osx + osx_image: xcode11 + compiler: clang + env: + CXX="clang++" + CC="clang" + LIB_TYPE=static + BUILD_TYPE=release + script: ./.travis_scripts/meson_builder.sh + - name: Linux xenial clang meson static release testing + os: linux + dist: xenial + compiler: clang + env: + CXX="clang++" + CC="clang" + LIB_TYPE=static + BUILD_TYPE=release + PYTHONUSERBASE="$(pwd)/LOCAL" + PATH="$PYTHONUSERBASE/bin:$PATH" + # before_install and install steps only needed for linux meson builds + before_install: + - source ./.travis_scripts/travis.before_install.${TRAVIS_OS_NAME}.sh + install: + - source ./.travis_scripts/travis.install.${TRAVIS_OS_NAME}.sh + script: ./.travis_scripts/meson_builder.sh + - name: Linux xenial gcc cmake coverage + os: linux + dist: xenial + compiler: gcc + env: + CXX=g++ + CC=gcc + DO_Coverage=ON + BUILD_TOOL="Unix Makefiles" + BUILD_TYPE=Debug + LIB_TYPE=shared + DESTDIR=/tmp/cmake_json_cpp + before_install: + - pip install --user cpp-coveralls + script: ./.travis_scripts/cmake_builder.sh + after_success: + - coveralls --include src/lib_json --include include +notifications: + email: false diff --git a/third_party/jsoncpp/.travis_scripts/cmake_builder.sh b/third_party/jsoncpp/.travis_scripts/cmake_builder.sh new file mode 100755 index 0000000..f3d4e46 --- /dev/null +++ b/third_party/jsoncpp/.travis_scripts/cmake_builder.sh @@ -0,0 +1,130 @@ +#!/usr/bin/env sh +# This script can be used on the command line directly to configure several +# different build environments. +# This is called by `.travis.yml` via Travis CI. +# Travis supplies $TRAVIS_OS_NAME. +# http://docs.travis-ci.com/user/multi-os/ +# Our .travis.yml also defines: + +# - BUILD_TYPE=Release/Debug +# - LIB_TYPE=static/shared +# +# Optional environmental variables +# - DESTDIR <- used for setting the install prefix +# - BUILD_TOOL=["Unix Makefile"|"Ninja"] +# - BUILDNAME <- how to identify this build on the dashboard +# - DO_MemCheck <- if set, try to use valgrind +# - DO_Coverage <- if set, try to do dashboard coverage testing +# + +env_set=1 +if ${BUILD_TYPE+false}; then + echo "BUILD_TYPE not set in environment." + env_set=0 +fi +if ${LIB_TYPE+false}; then + echo "LIB_TYPE not set in environment." + env_set=0 +fi +if ${CXX+false}; then + echo "CXX not set in environment." + env_set=0 +fi + + +if [ ${env_set} -eq 0 ]; then + echo "USAGE: CXX=$(which clang++) BUILD_TYPE=[Release|Debug] LIB_TYPE=[static|shared] $0" + echo "" + echo "Examples:" + echo " CXX=$(which clang++) BUILD_TYPE=Release LIB_TYPE=shared DESTDIR=/tmp/cmake_json_cpp $0" + echo " CXX=$(which clang++) BUILD_TYPE=Debug LIB_TYPE=shared DESTDIR=/tmp/cmake_json_cpp $0" + echo " CXX=$(which clang++) BUILD_TYPE=Release LIB_TYPE=static DESTDIR=/tmp/cmake_json_cpp $0" + echo " CXX=$(which clang++) BUILD_TYPE=Debug LIB_TYPE=static DESTDIR=/tmp/cmake_json_cpp $0" + + echo " CXX=$(which g++) BUILD_TYPE=Release LIB_TYPE=shared DESTDIR=/tmp/cmake_json_cpp $0" + echo " CXX=$(which g++) BUILD_TYPE=Debug LIB_TYPE=shared DESTDIR=/tmp/cmake_json_cpp $0" + echo " CXX=$(which g++) BUILD_TYPE=Release LIB_TYPE=static DESTDIR=/tmp/cmake_json_cpp $0" + echo " CXX=$(which g++) BUILD_TYPE=Debug LIB_TYPE=static DESTDIR=/tmp/cmake_json_cpp $0" + + exit -1 +fi + +if ${DESTDIR+false}; then + DESTDIR="/usr/local" +fi + +# -e: fail on error +# -v: show commands +# -x: show expanded commands +set -vex + +env | sort + +which cmake +cmake --version + +echo ${CXX} +${CXX} --version +_COMPILER_NAME=`basename ${CXX}` +if [ "${LIB_TYPE}" = "shared" ]; then + _CMAKE_BUILD_SHARED_LIBS=ON +else + _CMAKE_BUILD_SHARED_LIBS=OFF +fi + +CTEST_TESTING_OPTION="-D ExperimentalTest" +# - DO_MemCheck <- if set, try to use valgrind +if ! ${DO_MemCheck+false}; then + valgrind --version + CTEST_TESTING_OPTION="-D ExperimentalMemCheck" +else +# - DO_Coverage <- if set, try to do dashboard coverage testing + if ! ${DO_Coverage+false}; then + export CXXFLAGS="-fprofile-arcs -ftest-coverage" + export LDFLAGS="-fprofile-arcs -ftest-coverage" + CTEST_TESTING_OPTION="-D ExperimentalTest -D ExperimentalCoverage" + #gcov --version + fi +fi + +# Ninja = Generates build.ninja files. +if ${BUILD_TOOL+false}; then + BUILD_TOOL="Ninja" + export _BUILD_EXE=ninja + which ninja + ninja --version +else +# Unix Makefiles = Generates standard UNIX makefiles. + export _BUILD_EXE=make +fi + +_BUILD_DIR_NAME="build-cmake_${BUILD_TYPE}_${LIB_TYPE}_${_COMPILER_NAME}_${_BUILD_EXE}" +mkdir -p ${_BUILD_DIR_NAME} +cd "${_BUILD_DIR_NAME}" + if ${BUILDNAME+false}; then + _HOSTNAME=`hostname -s` + BUILDNAME="${_HOSTNAME}_${BUILD_TYPE}_${LIB_TYPE}_${_COMPILER_NAME}_${_BUILD_EXE}" + fi + cmake \ + -G "${BUILD_TOOL}" \ + -DBUILDNAME:STRING="${BUILDNAME}" \ + -DCMAKE_CXX_COMPILER:PATH=${CXX} \ + -DCMAKE_BUILD_TYPE:STRING=${BUILD_TYPE} \ + -DBUILD_SHARED_LIBS:BOOL=${_CMAKE_BUILD_SHARED_LIBS} \ + -DCMAKE_INSTALL_PREFIX:PATH=${DESTDIR} \ + ../ + + ctest -C ${BUILD_TYPE} -D ExperimentalStart -D ExperimentalConfigure -D ExperimentalBuild ${CTEST_TESTING_OPTION} -D ExperimentalSubmit + # Final step is to verify that installation succeeds + cmake --build . --config ${BUILD_TYPE} --target install + + if [ "${DESTDIR}" != "/usr/local" ]; then + ${_BUILD_EXE} install + fi +cd - + +if ${CLEANUP+false}; then + echo "Skipping cleanup: build directory will persist." +else + rm -r "${_BUILD_DIR_NAME}" +fi diff --git a/third_party/jsoncpp/.travis_scripts/meson_builder.sh b/third_party/jsoncpp/.travis_scripts/meson_builder.sh new file mode 100755 index 0000000..bc74732 --- /dev/null +++ b/third_party/jsoncpp/.travis_scripts/meson_builder.sh @@ -0,0 +1,83 @@ +#!/usr/bin/env sh +# This script can be used on the command line directly to configure several +# different build environments. +# This is called by `.travis.yml` via Travis CI. +# Travis supplies $TRAVIS_OS_NAME. +# http://docs.travis-ci.com/user/multi-os/ +# Our .travis.yml also defines: + +# - BUILD_TYPE=release/debug +# - LIB_TYPE=static/shared + +env_set=1 +if ${BUILD_TYPE+false}; then + echo "BUILD_TYPE not set in environment." + env_set=0 +fi +if ${LIB_TYPE+false}; then + echo "LIB_TYPE not set in environment." + env_set=0 +fi +if ${CXX+false}; then + echo "CXX not set in environment." + env_set=0 +fi + + +if [ ${env_set} -eq 0 ]; then + echo "USAGE: CXX=$(which clang++) BUILD_TYPE=[release|debug] LIB_TYPE=[static|shared] $0" + echo "" + echo "Examples:" + echo " CXX=$(which clang++) BUILD_TYPE=release LIB_TYPE=shared DESTDIR=/tmp/meson_json_cpp $0" + echo " CXX=$(which clang++) BUILD_TYPE=debug LIB_TYPE=shared DESTDIR=/tmp/meson_json_cpp $0" + echo " CXX=$(which clang++) BUILD_TYPE=release LIB_TYPE=static DESTDIR=/tmp/meson_json_cpp $0" + echo " CXX=$(which clang++) BUILD_TYPE=debug LIB_TYPE=static DESTDIR=/tmp/meson_json_cpp $0" + + echo " CXX=$(which g++) BUILD_TYPE=release LIB_TYPE=shared DESTDIR=/tmp/meson_json_cpp $0" + echo " CXX=$(which g++) BUILD_TYPE=debug LIB_TYPE=shared DESTDIR=/tmp/meson_json_cpp $0" + echo " CXX=$(which g++) BUILD_TYPE=release LIB_TYPE=static DESTDIR=/tmp/meson_json_cpp $0" + echo " CXX=$(which g++) BUILD_TYPE=debug LIB_TYPE=static DESTDIR=/tmp/meson_json_cpp $0" + + exit -1 +fi + +if ${DESTDIR+false}; then + DESTDIR="/usr/local" +fi + +# -e: fail on error +# -v: show commands +# -x: show expanded commands +set -vex + + +env | sort + +which python3 +which meson +which ninja +echo ${CXX} +${CXX} --version +python3 --version +meson --version +ninja --version +_COMPILER_NAME=`basename ${CXX}` +_BUILD_DIR_NAME="build-${BUILD_TYPE}_${LIB_TYPE}_${_COMPILER_NAME}" + +#./.travis_scripts/run-clang-format.sh +meson --fatal-meson-warnings --werror --buildtype ${BUILD_TYPE} --default-library ${LIB_TYPE} . "${_BUILD_DIR_NAME}" +ninja -v -j 2 -C "${_BUILD_DIR_NAME}" + +cd "${_BUILD_DIR_NAME}" + meson test --no-rebuild --print-errorlogs + + if [ "${DESTDIR}" != "/usr/local" ]; then + ninja install + fi +cd - + +if ${CLEANUP+false}; then + echo "Skipping cleanup: build directory will persist." +else + rm -r "${_BUILD_DIR_NAME}" +fi diff --git a/third_party/jsoncpp/.travis_scripts/run-clang-format.py b/third_party/jsoncpp/.travis_scripts/run-clang-format.py new file mode 100755 index 0000000..605b5aa --- /dev/null +++ b/third_party/jsoncpp/.travis_scripts/run-clang-format.py @@ -0,0 +1,356 @@ +#!/usr/bin/env python +"""A wrapper script around clang-format, suitable for linting multiple files +and to use for continuous integration. +This is an alternative API for the clang-format command line. +It runs over multiple files and directories in parallel. +A diff output is produced and a sensible exit code is returned. + +NOTE: pulled from https://github.com/Sarcasm/run-clang-format, which is +licensed under the MIT license. +""" + +from __future__ import print_function, unicode_literals + +import argparse +import codecs +import difflib +import fnmatch +import io +import multiprocessing +import os +import signal +import subprocess +import sys +import traceback + +from functools import partial + +try: + from subprocess import DEVNULL # py3k +except ImportError: + DEVNULL = open(os.devnull, "wb") + + +DEFAULT_EXTENSIONS = 'c,h,C,H,cpp,hpp,cc,hh,c++,h++,cxx,hxx' + + +class ExitStatus: + SUCCESS = 0 + DIFF = 1 + TROUBLE = 2 + + +def list_files(files, recursive=False, extensions=None, exclude=None): + if extensions is None: + extensions = [] + if exclude is None: + exclude = [] + + out = [] + for file in files: + if recursive and os.path.isdir(file): + for dirpath, dnames, fnames in os.walk(file): + fpaths = [os.path.join(dirpath, fname) for fname in fnames] + for pattern in exclude: + # os.walk() supports trimming down the dnames list + # by modifying it in-place, + # to avoid unnecessary directory listings. + dnames[:] = [ + x for x in dnames + if + not fnmatch.fnmatch(os.path.join(dirpath, x), pattern) + ] + fpaths = [ + x for x in fpaths if not fnmatch.fnmatch(x, pattern) + ] + for f in fpaths: + ext = os.path.splitext(f)[1][1:] + if ext in extensions: + out.append(f) + else: + out.append(file) + return out + + +def make_diff(file, original, reformatted): + return list( + difflib.unified_diff( + original, + reformatted, + fromfile='{}\t(original)'.format(file), + tofile='{}\t(reformatted)'.format(file), + n=3)) + + +class DiffError(Exception): + def __init__(self, message, errs=None): + super(DiffError, self).__init__(message) + self.errs = errs or [] + + +class UnexpectedError(Exception): + def __init__(self, message, exc=None): + super(UnexpectedError, self).__init__(message) + self.formatted_traceback = traceback.format_exc() + self.exc = exc + + +def run_clang_format_diff_wrapper(args, file): + try: + ret = run_clang_format_diff(args, file) + return ret + except DiffError: + raise + except Exception as e: + raise UnexpectedError('{}: {}: {}'.format(file, e.__class__.__name__, + e), e) + + +def run_clang_format_diff(args, file): + try: + with io.open(file, 'r', encoding='utf-8') as f: + original = f.readlines() + except IOError as exc: + raise DiffError(str(exc)) + invocation = [args.clang_format_executable, file] + + # Use of utf-8 to decode the process output. + # + # Hopefully, this is the correct thing to do. + # + # It's done due to the following assumptions (which may be incorrect): + # - clang-format will returns the bytes read from the files as-is, + # without conversion, and it is already assumed that the files use utf-8. + # - if the diagnostics were internationalized, they would use utf-8: + # > Adding Translations to Clang + # > + # > Not possible yet! + # > Diagnostic strings should be written in UTF-8, + # > the client can translate to the relevant code page if needed. + # > Each translation completely replaces the format string + # > for the diagnostic. + # > -- http://clang.llvm.org/docs/InternalsManual.html#internals-diag-translation + # + # It's not pretty, due to Python 2 & 3 compatibility. + encoding_py3 = {} + if sys.version_info[0] >= 3: + encoding_py3['encoding'] = 'utf-8' + + try: + proc = subprocess.Popen( + invocation, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + universal_newlines=True, + **encoding_py3) + except OSError as exc: + raise DiffError( + "Command '{}' failed to start: {}".format( + subprocess.list2cmdline(invocation), exc + ) + ) + proc_stdout = proc.stdout + proc_stderr = proc.stderr + if sys.version_info[0] < 3: + # make the pipes compatible with Python 3, + # reading lines should output unicode + encoding = 'utf-8' + proc_stdout = codecs.getreader(encoding)(proc_stdout) + proc_stderr = codecs.getreader(encoding)(proc_stderr) + # hopefully the stderr pipe won't get full and block the process + outs = list(proc_stdout.readlines()) + errs = list(proc_stderr.readlines()) + proc.wait() + if proc.returncode: + raise DiffError( + "Command '{}' returned non-zero exit status {}".format( + subprocess.list2cmdline(invocation), proc.returncode + ), + errs, + ) + return make_diff(file, original, outs), errs + + +def bold_red(s): + return '\x1b[1m\x1b[31m' + s + '\x1b[0m' + + +def colorize(diff_lines): + def bold(s): + return '\x1b[1m' + s + '\x1b[0m' + + def cyan(s): + return '\x1b[36m' + s + '\x1b[0m' + + def green(s): + return '\x1b[32m' + s + '\x1b[0m' + + def red(s): + return '\x1b[31m' + s + '\x1b[0m' + + for line in diff_lines: + if line[:4] in ['--- ', '+++ ']: + yield bold(line) + elif line.startswith('@@ '): + yield cyan(line) + elif line.startswith('+'): + yield green(line) + elif line.startswith('-'): + yield red(line) + else: + yield line + + +def print_diff(diff_lines, use_color): + if use_color: + diff_lines = colorize(diff_lines) + if sys.version_info[0] < 3: + sys.stdout.writelines((l.encode('utf-8') for l in diff_lines)) + else: + sys.stdout.writelines(diff_lines) + + +def print_trouble(prog, message, use_colors): + error_text = 'error:' + if use_colors: + error_text = bold_red(error_text) + print("{}: {} {}".format(prog, error_text, message), file=sys.stderr) + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument( + '--clang-format-executable', + metavar='EXECUTABLE', + help='path to the clang-format executable', + default='clang-format') + parser.add_argument( + '--extensions', + help='comma separated list of file extensions (default: {})'.format( + DEFAULT_EXTENSIONS), + default=DEFAULT_EXTENSIONS) + parser.add_argument( + '-r', + '--recursive', + action='store_true', + help='run recursively over directories') + parser.add_argument('files', metavar='file', nargs='+') + parser.add_argument( + '-q', + '--quiet', + action='store_true') + parser.add_argument( + '-j', + metavar='N', + type=int, + default=0, + help='run N clang-format jobs in parallel' + ' (default number of cpus + 1)') + parser.add_argument( + '--color', + default='auto', + choices=['auto', 'always', 'never'], + help='show colored diff (default: auto)') + parser.add_argument( + '-e', + '--exclude', + metavar='PATTERN', + action='append', + default=[], + help='exclude paths matching the given glob-like pattern(s)' + ' from recursive search') + + args = parser.parse_args() + + # use default signal handling, like diff return SIGINT value on ^C + # https://bugs.python.org/issue14229#msg156446 + signal.signal(signal.SIGINT, signal.SIG_DFL) + try: + signal.SIGPIPE + except AttributeError: + # compatibility, SIGPIPE does not exist on Windows + pass + else: + signal.signal(signal.SIGPIPE, signal.SIG_DFL) + + colored_stdout = False + colored_stderr = False + if args.color == 'always': + colored_stdout = True + colored_stderr = True + elif args.color == 'auto': + colored_stdout = sys.stdout.isatty() + colored_stderr = sys.stderr.isatty() + + version_invocation = [args.clang_format_executable, str("--version")] + try: + subprocess.check_call(version_invocation, stdout=DEVNULL) + except subprocess.CalledProcessError as e: + print_trouble(parser.prog, str(e), use_colors=colored_stderr) + return ExitStatus.TROUBLE + except OSError as e: + print_trouble( + parser.prog, + "Command '{}' failed to start: {}".format( + subprocess.list2cmdline(version_invocation), e + ), + use_colors=colored_stderr, + ) + return ExitStatus.TROUBLE + + retcode = ExitStatus.SUCCESS + files = list_files( + args.files, + recursive=args.recursive, + exclude=args.exclude, + extensions=args.extensions.split(',')) + + if not files: + return + + njobs = args.j + if njobs == 0: + njobs = multiprocessing.cpu_count() + 1 + njobs = min(len(files), njobs) + + if njobs == 1: + # execute directly instead of in a pool, + # less overhead, simpler stacktraces + it = (run_clang_format_diff_wrapper(args, file) for file in files) + pool = None + else: + pool = multiprocessing.Pool(njobs) + it = pool.imap_unordered( + partial(run_clang_format_diff_wrapper, args), files) + while True: + try: + outs, errs = next(it) + except StopIteration: + break + except DiffError as e: + print_trouble(parser.prog, str(e), use_colors=colored_stderr) + retcode = ExitStatus.TROUBLE + sys.stderr.writelines(e.errs) + except UnexpectedError as e: + print_trouble(parser.prog, str(e), use_colors=colored_stderr) + sys.stderr.write(e.formatted_traceback) + retcode = ExitStatus.TROUBLE + # stop at the first unexpected error, + # something could be very wrong, + # don't process all files unnecessarily + if pool: + pool.terminate() + break + else: + sys.stderr.writelines(errs) + if outs == []: + continue + if not args.quiet: + print_diff(outs, use_color=colored_stdout) + if retcode == ExitStatus.SUCCESS: + retcode = ExitStatus.DIFF + return retcode + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/third_party/jsoncpp/.travis_scripts/run-clang-format.sh b/third_party/jsoncpp/.travis_scripts/run-clang-format.sh new file mode 100755 index 0000000..ded76aa --- /dev/null +++ b/third_party/jsoncpp/.travis_scripts/run-clang-format.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" +python $DIR/run-clang-format.py -r $DIR/../src/**/ $DIR/../include/**/ diff --git a/third_party/jsoncpp/.travis_scripts/travis.before_install.linux.sh b/third_party/jsoncpp/.travis_scripts/travis.before_install.linux.sh new file mode 100644 index 0000000..9b556de --- /dev/null +++ b/third_party/jsoncpp/.travis_scripts/travis.before_install.linux.sh @@ -0,0 +1,8 @@ +set -vex + +# Preinstalled versions of python are dependent on which Ubuntu distribution +# you are running. The below version needs to be updated whenever we roll +# the Ubuntu version used in Travis. +# https://docs.travis-ci.com/user/languages/python/ + +pyenv global 3.7.1 diff --git a/third_party/jsoncpp/.travis_scripts/travis.before_install.osx.sh b/third_party/jsoncpp/.travis_scripts/travis.before_install.osx.sh new file mode 100644 index 0000000..e69de29 diff --git a/third_party/jsoncpp/.travis_scripts/travis.install.linux.sh b/third_party/jsoncpp/.travis_scripts/travis.install.linux.sh new file mode 100644 index 0000000..6495fef --- /dev/null +++ b/third_party/jsoncpp/.travis_scripts/travis.install.linux.sh @@ -0,0 +1,5 @@ +set -vex + +pip3 install --user meson ninja +which meson +which ninja diff --git a/third_party/jsoncpp/.travis_scripts/travis.install.osx.sh b/third_party/jsoncpp/.travis_scripts/travis.install.osx.sh new file mode 100644 index 0000000..5d83c0c --- /dev/null +++ b/third_party/jsoncpp/.travis_scripts/travis.install.osx.sh @@ -0,0 +1 @@ +# NOTHING TO DO HERE diff --git a/third_party/jsoncpp/AUTHORS b/third_party/jsoncpp/AUTHORS new file mode 100644 index 0000000..e1fa0fc --- /dev/null +++ b/third_party/jsoncpp/AUTHORS @@ -0,0 +1,115 @@ +Baptiste Lepilleur + +Aaron Jacobs +Aaron Jacobs +Adam Boseley +Adam Boseley +Aleksandr Derbenev <13alexac@gmail.com> +Alexander Gazarov +Alexander V. Brezgin +Alexandr Brezgin +Alexey Kruchinin +Anton Indrawan +Baptiste Jonglez +Baptiste Lepilleur +Baruch Siach +Ben Boeckel +Benjamin Knecht +Bernd Kuhls +Billy Donahue +Braden McDorman +Brandon Myers +Brendan Drew +chason +chenguoping +Chris Gilling +Christopher Dawes +Christopher Dunn +Chuck Atkins +Cody P Schafer +Connor Manning +Cory Quammen +Cristóvão B da Cruz e Silva +Daniel Krügler +Dani-Hub +Dan Liu +datadiode +datadiode +David Seifert +David West +dawesc +Devin Jeanpierre +Dmitry Marakasov +dominicpezzuto +Don Milham +drgler +ds283 +Egor Tensin +eightnoteight +Evince +filipjs +findblar +Florian Meier +Gaëtan Lehmann +Gaurav +Gergely Nagy +Gida Pataki +I3ck +Iñaki Baz Castillo +Jacco +Jean-Christophe Fillion-Robin +Jonas Platte +Jordan Bayles +Jörg Krause +Keith Lea +Kevin Grant +Kirill V. Lyadvinsky +Kirill V. Lyadvinsky +Kobi Gurkan +Magnus Bjerke Vik +Malay Shah +Mara Kim +Marek Kotewicz +Mark Lakata +Mark Zeren +Martin Buck +Martyn Gigg +Mattes D +Matthias Loy +Merlyn Morgan-Graham +Michael Shields +Michał Górny +Mike Naberezny +mloy +Motti +nnkur +Omkar Wagh +paulo +pavel.pimenov +Paweł Bylica +Péricles Lopes Machado +Peter Spiess-Knafl +pffang +Rémi Verschelde +renu555 +Robert Dailey +Sam Clegg +selaselah +Sergiy80 +sergzub +Stefan Schweter +Stefano Fiorentino +Steffen Kieß +Steven Hahn +Stuart Eichert +SuperManitu +Techwolf +Tengiz Sharafiev +Tomasz Maciejewski +Vicente Olivert Riera +xiaoyur347 +ycqiu <429148848@qq.com> +yiqiju +Yu Xiaolei + +Google Inc. diff --git a/third_party/jsoncpp/BUILD.bazel b/third_party/jsoncpp/BUILD.bazel new file mode 100644 index 0000000..6d7ac3d --- /dev/null +++ b/third_party/jsoncpp/BUILD.bazel @@ -0,0 +1,37 @@ +licenses(["unencumbered"]) # Public Domain or MIT + +exports_files(["LICENSE"]) + +cc_library( + name = "jsoncpp", + srcs = [ + "src/lib_json/json_reader.cpp", + "src/lib_json/json_tool.h", + "src/lib_json/json_value.cpp", + "src/lib_json/json_writer.cpp", + ], + hdrs = [ + "include/json/allocator.h", + "include/json/assertions.h", + "include/json/config.h", + "include/json/json_features.h", + "include/json/forwards.h", + "include/json/json.h", + "include/json/reader.h", + "include/json/value.h", + "include/json/version.h", + "include/json/writer.h", + ], + copts = [ + "-DJSON_USE_EXCEPTION=0", + "-DJSON_HAS_INT64", + ], + includes = ["include"], + visibility = ["//visibility:public"], + deps = [":private"], +) + +cc_library( + name = "private", + textual_hdrs = ["src/lib_json/json_valueiterator.inl"], +) diff --git a/third_party/jsoncpp/CMakeLists.txt b/third_party/jsoncpp/CMakeLists.txt new file mode 100644 index 0000000..be55f39 --- /dev/null +++ b/third_party/jsoncpp/CMakeLists.txt @@ -0,0 +1,245 @@ +# vim: et ts=4 sts=4 sw=4 tw=0 + +# ==== Define cmake build policies that affect compilation and linkage default +# behaviors +# +# Set the JSONCPP_NEWEST_VALIDATED_POLICIES_VERSION string to the newest cmake +# version policies that provide successful builds. By setting +# JSONCPP_NEWEST_VALIDATED_POLICIES_VERSION to a value greater than the oldest +# policies, all policies between JSONCPP_OLDEST_VALIDATED_POLICIES_VERSION and +# CMAKE_VERSION (used for this build) are set to their NEW behaivor, thereby +# suppressing policy warnings related to policies between the +# JSONCPP_OLDEST_VALIDATED_POLICIES_VERSION and CMAKE_VERSION. +# +# CMake versions greater than the JSONCPP_NEWEST_VALIDATED_POLICIES_VERSION +# policies will continue to generate policy warnings "CMake Warning +# (dev)...Policy CMP0XXX is not set:" +# +set(JSONCPP_OLDEST_VALIDATED_POLICIES_VERSION "3.8.0") +set(JSONCPP_NEWEST_VALIDATED_POLICIES_VERSION "3.13.2") +cmake_minimum_required(VERSION ${JSONCPP_OLDEST_VALIDATED_POLICIES_VERSION}) +if("${CMAKE_VERSION}" VERSION_LESS + "${JSONCPP_NEWEST_VALIDATED_POLICIES_VERSION}") + # Set and use the newest available cmake policies that are validated to work + set(JSONCPP_CMAKE_POLICY_VERSION "${CMAKE_VERSION}") +else() + set(JSONCPP_CMAKE_POLICY_VERSION + "${JSONCPP_NEWEST_VALIDATED_POLICIES_VERSION}") +endif() +cmake_policy(VERSION ${JSONCPP_CMAKE_POLICY_VERSION}) +if(POLICY CMP0091) + cmake_policy(SET CMP0091 NEW) +endif() +# +# Now enumerate specific policies newer than +# JSONCPP_NEWEST_VALIDATED_POLICIES_VERSION that may need to be individually set +# to NEW/OLD +# +foreach(pnew "") # Currently Empty + if(POLICY ${pnew}) + cmake_policy(SET ${pnew} NEW) + endif() +endforeach() +foreach(pold "") # Currently Empty + if(POLICY ${pold}) + cmake_policy(SET ${pold} OLD) + endif() +endforeach() + +# Build the library with C++11 standard support, independent from other +# including software which may use a different CXX_STANDARD or +# CMAKE_CXX_STANDARD. +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_EXTENSIONS OFF) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +# Ensure that CMAKE_BUILD_TYPE has a value specified for single configuration +# generators. +if(NOT DEFINED CMAKE_BUILD_TYPE AND NOT DEFINED CMAKE_CONFIGURATION_TYPES) + set(CMAKE_BUILD_TYPE + Release + CACHE + STRING + "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel Coverage." + ) +endif() + +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake") + +# --------------------------------------------------------------------------- +# use ccache if found, has to be done before project() +# --------------------------------------------------------------------------- +find_program(CCACHE_EXECUTABLE "ccache" HINTS /usr/local/bin /opt/local/bin) +if(CCACHE_EXECUTABLE) + message(STATUS "use ccache") + set(CMAKE_CXX_COMPILER_LAUNCHER + "${CCACHE_EXECUTABLE}" + CACHE PATH "ccache" FORCE) + set(CMAKE_C_COMPILER_LAUNCHER + "${CCACHE_EXECUTABLE}" + CACHE PATH "ccache" FORCE) +endif() + +project( + jsoncpp + # Note: version must be updated in three places when doing a release. This + # annoying process ensures that amalgamate, CMake, and meson all report the + # correct version. 1. ./meson.build 2. ./include/json/version.h 3. + # ./CMakeLists.txt IMPORTANT: also update the PROJECT_SOVERSION!! + VERSION 1.9.5 # [.[.[.]]] + LANGUAGES CXX) + +message( + STATUS + "JsonCpp Version: ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}" +) +set(PROJECT_SOVERSION 25) + +include(${CMAKE_CURRENT_SOURCE_DIR}/include/PreventInSourceBuilds.cmake) +include(${CMAKE_CURRENT_SOURCE_DIR}/include/PreventInBuildInstalls.cmake) + +option(JSONCPP_WITH_TESTS + "Compile and (for jsoncpp_check) run JsonCpp test executables" OFF) +option(JSONCPP_WITH_POST_BUILD_UNITTEST + "Automatically run unit-tests as a post build step" OFF) +option(JSONCPP_WITH_WARNING_AS_ERROR + "Force compilation to fail if a warning occurs" OFF) +option(JSONCPP_WITH_STRICT_ISO + "Issue all the warnings demanded by strict ISO C and ISO C++" ON) +option(JSONCPP_WITH_PKGCONFIG_SUPPORT "Generate and install .pc files" OFF) +option(JSONCPP_WITH_CMAKE_PACKAGE "Generate and install cmake package files" + OFF) +option(JSONCPP_WITH_EXAMPLE "Compile JsonCpp example" OFF) +option(JSONCPP_STATIC_WINDOWS_RUNTIME "Use static (MT/MTd) Windows runtime" OFF) +option(BUILD_SHARED_LIBS "Build jsoncpp_lib as a shared library." OFF) +option(BUILD_STATIC_LIBS "Build jsoncpp_lib as a static library." ON) +option(BUILD_OBJECT_LIBS "Build jsoncpp_lib as a object library." OFF) + +# Adhere to GNU filesystem layout conventions +include(GNUInstallDirs) + +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY + "${CMAKE_BINARY_DIR}/lib" + CACHE PATH "Archive output dir.") +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY + "${CMAKE_BINARY_DIR}/lib" + CACHE PATH "Library output dir.") +set(CMAKE_PDB_OUTPUT_DIRECTORY + "${CMAKE_BINARY_DIR}/bin" + CACHE PATH "PDB (MSVC debug symbol)output dir.") +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY + "${CMAKE_BINARY_DIR}/bin" + CACHE PATH "Executable/dll output dir.") + +set(JSONCPP_USE_SECURE_MEMORY + "0" + CACHE STRING "-D...=1 to use memory-wiping allocator for STL") + +configure_file("${PROJECT_SOURCE_DIR}/version.in" + "${PROJECT_BINARY_DIR}/version" NEWLINE_STYLE UNIX) + +macro(use_compilation_warning_as_error) + if(MSVC) + # Only enabled in debug because some old versions of VS STL generate + # warnings when compiled in release configuration. + add_compile_options($<$:/WX>) + elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + add_compile_options(-Werror) + if(JSONCPP_WITH_STRICT_ISO) + add_compile_options(-pedantic-errors) + endif() + endif() +endmacro() + +# Include our configuration header +include_directories(${jsoncpp_SOURCE_DIR}/include) + +if(MSVC) + # Only enabled in debug because some old versions of VS STL generate + # unreachable code warning when compiled in release configuration. + add_compile_options($<$:/W4>) + if(JSONCPP_STATIC_WINDOWS_RUNTIME) + set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") + endif() +endif() + +if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") + # using regular Clang or AppleClang + add_compile_options(-Wall -Wconversion -Wshadow) + + if(JSONCPP_WITH_WARNING_AS_ERROR) + add_compile_options(-Werror=conversion -Werror=sign-compare) + endif() +elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + # using GCC + add_compile_options(-Wall -Wconversion -Wshadow -Wextra) + # not yet ready for -Wsign-conversion + + if(JSONCPP_WITH_STRICT_ISO) + add_compile_options(-Wpedantic) + endif() + if(JSONCPP_WITH_WARNING_AS_ERROR) + add_compile_options(-Werror=conversion) + endif() +elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Intel") + # using Intel compiler + add_compile_options(-Wall -Wconversion -Wshadow -Wextra) + + if(JSONCPP_WITH_WARNING_AS_ERROR) + add_compile_options(-Werror=conversion) + elseif(JSONCPP_WITH_STRICT_ISO) + add_compile_options(-Wpedantic) + endif() +endif() + +if(JSONCPP_WITH_WARNING_AS_ERROR) + use_compilation_warning_as_error() +endif() + +if(JSONCPP_WITH_PKGCONFIG_SUPPORT) + include(JoinPaths) + + join_paths(libdir_for_pc_file "\${exec_prefix}" "${CMAKE_INSTALL_LIBDIR}") + join_paths(includedir_for_pc_file "\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}") + + configure_file("pkg-config/jsoncpp.pc.in" "pkg-config/jsoncpp.pc" @ONLY) + install(FILES "${CMAKE_CURRENT_BINARY_DIR}/pkg-config/jsoncpp.pc" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") +endif() + +if(JSONCPP_WITH_CMAKE_PACKAGE) + include(CMakePackageConfigHelpers) + install( + EXPORT jsoncpp + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/jsoncpp + FILE jsoncpp-targets.cmake) + configure_package_config_file( + jsoncppConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/jsoncppConfig.cmake + INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/jsoncpp) + + write_basic_package_version_file( + "${CMAKE_CURRENT_BINARY_DIR}/jsoncppConfigVersion.cmake" + VERSION ${PROJECT_VERSION} + COMPATIBILITY SameMajorVersion) + install( + FILES ${CMAKE_CURRENT_BINARY_DIR}/jsoncppConfigVersion.cmake + ${CMAKE_CURRENT_BINARY_DIR}/jsoncppConfig.cmake + ${CMAKE_CURRENT_SOURCE_DIR}/jsoncpp-namespaced-targets.cmake + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/jsoncpp) +endif() + +if(JSONCPP_WITH_TESTS) + enable_testing() + include(CTest) +endif() + +# Build the different applications +add_subdirectory(src) + +# install the includes +add_subdirectory(include) + +# install the example +if(JSONCPP_WITH_EXAMPLE) + add_subdirectory(example) +endif() diff --git a/third_party/jsoncpp/CONTRIBUTING.md b/third_party/jsoncpp/CONTRIBUTING.md new file mode 100644 index 0000000..8d992be --- /dev/null +++ b/third_party/jsoncpp/CONTRIBUTING.md @@ -0,0 +1,152 @@ +# Contributing to JsonCpp + +## Building + +Both CMake and Meson tools are capable of generating a variety of build environments for you preferred development environment. +Using cmake or meson you can generate an XCode, Visual Studio, Unix Makefile, Ninja, or other environment that fits your needs. + +An example of a common Meson/Ninja environment is described next. + +## Building and testing with Meson/Ninja +Thanks to David Seifert (@SoapGentoo), we (the maintainers) now use +[meson](http://mesonbuild.com/) and [ninja](https://ninja-build.org/) to build +for debugging, as well as for continuous integration (see +[`./.travis_scripts/meson_builder.sh`](./.travis_scripts/meson_builder.sh) ). Other systems may work, but minor +things like version strings might break. + +First, install both meson (which requires Python3) and ninja. +If you wish to install to a directory other than /usr/local, set an environment variable called DESTDIR with the desired path: + DESTDIR=/path/to/install/dir + +Then, +```sh + cd jsoncpp/ + BUILD_TYPE=debug + #BUILD_TYPE=release + LIB_TYPE=shared + #LIB_TYPE=static + meson --buildtype ${BUILD_TYPE} --default-library ${LIB_TYPE} . build-${LIB_TYPE} + ninja -v -C build-${LIB_TYPE} + + ninja -C build-static/ test + + # Or + #cd build-${LIB_TYPE} + #meson test --no-rebuild --print-errorlogs + + sudo ninja install +``` + +## Building and testing with other build systems +See https://github.com/open-source-parsers/jsoncpp/wiki/Building + +## Running the tests manually + +You need to run tests manually only if you are troubleshooting an issue. + +In the instructions below, replace `path/to/jsontest` with the path of the +`jsontest` executable that was compiled on your platform. + + cd test + # This will run the Reader/Writer tests + python runjsontests.py path/to/jsontest + + # This will run the Reader/Writer tests, using JSONChecker test suite + # (http://www.json.org/JSON_checker/). + # Notes: not all tests pass: JsonCpp is too lenient (for example, + # it allows an integer to start with '0'). The goal is to improve + # strict mode parsing to get all tests to pass. + python runjsontests.py --with-json-checker path/to/jsontest + + # This will run the unit tests (mostly Value) + python rununittests.py path/to/test_lib_json + + # You can run the tests using valgrind: + python rununittests.py --valgrind path/to/test_lib_json + +## Building the documentation + +Run the Python script `doxybuild.py` from the top directory: + + python doxybuild.py --doxygen=$(which doxygen) --open --with-dot + +See `doxybuild.py --help` for options. + +## Adding a reader/writer test + +To add a test, you need to create two files in test/data: + +* a `TESTNAME.json` file, that contains the input document in JSON format. +* a `TESTNAME.expected` file, that contains a flatened representation of the + input document. + +The `TESTNAME.expected` file format is as follows: + +* Each line represents a JSON element of the element tree represented by the + input document. +* Each line has two parts: the path to access the element separated from the + element value by `=`. Array and object values are always empty (i.e. + represented by either `[]` or `{}`). +* Element path `.` represents the root element, and is used to separate object + members. `[N]` is used to specify the value of an array element at index `N`. + +See the examples `test_complex_01.json` and `test_complex_01.expected` to better understand element paths. + +## Understanding reader/writer test output + +When a test is run, output files are generated beside the input test files. Below is a short description of the content of each file: + +* `test_complex_01.json`: input JSON document. +* `test_complex_01.expected`: flattened JSON element tree used to check if + parsing was corrected. +* `test_complex_01.actual`: flattened JSON element tree produced by `jsontest` + from reading `test_complex_01.json`. +* `test_complex_01.rewrite`: JSON document written by `jsontest` using the + `Json::Value` parsed from `test_complex_01.json` and serialized using + `Json::StyledWritter`. +* `test_complex_01.actual-rewrite`: flattened JSON element tree produced by + `jsontest` from reading `test_complex_01.rewrite`. +* `test_complex_01.process-output`: `jsontest` output, typically useful for + understanding parsing errors. + +## Versioning rules + +Consumers of this library require a strict approach to incrementing versioning of the JsonCpp library. Currently, we follow the below set of rules: + +* Any new public symbols require a minor version bump. +* Any alteration or removal of public symbols requires a major version bump, including changing the size of a class. This is necessary for +consumers to do dependency injection properly. + +## Preparing code for submission + +Generally, JsonCpp's style guide has been pretty relaxed, with the following common themes: + +* Variables and function names use lower camel case (E.g. parseValue or collectComments). +* Class use camel case (e.g. OurReader) +* Member variables have a trailing underscore +* Prefer `nullptr` over `NULL`. +* Passing by non-const reference is allowed. +* Single statement if blocks may omit brackets. +* Generally prefer less space over more space. + +For an example: + +```c++ +bool Reader::decodeNumber(Token& token) { + Value decoded; + if (!decodeNumber(token, decoded)) + return false; + currentValue().swapPayload(decoded); + currentValue().setOffsetStart(token.start_ - begin_); + currentValue().setOffsetLimit(token.end_ - begin_); + return true; +} +``` + +Before submitting your code, ensure that you meet the versioning requirements above, follow the style guide of the file you are modifying (or the above rules for new files), and run clang format. Meson exposes clang format with the following command: +``` +ninja -v -C build-${LIB_TYPE}/ clang-format +``` + +For convenience, you can also run the `reformat.sh` script located in the root directory. + diff --git a/third_party/jsoncpp/CTestConfig.cmake b/third_party/jsoncpp/CTestConfig.cmake new file mode 100644 index 0000000..b8fc6d5 --- /dev/null +++ b/third_party/jsoncpp/CTestConfig.cmake @@ -0,0 +1,15 @@ +## This file should be placed in the root directory of your project. +## Then modify the CMakeLists.txt file in the root directory of your +## project to incorporate the testing dashboard. +## +## # The following are required to submit to the CDash dashboard: +## ENABLE_TESTING() +## INCLUDE(CTest) + +set(CTEST_PROJECT_NAME "jsoncpp") +set(CTEST_NIGHTLY_START_TIME "01:23:45 UTC") + +set(CTEST_DROP_METHOD "https") +set(CTEST_DROP_SITE "my.cdash.org") +set(CTEST_DROP_LOCATION "/submit.php?project=jsoncpp") +set(CTEST_DROP_SITE_CDASH TRUE) diff --git a/third_party/jsoncpp/LICENSE b/third_party/jsoncpp/LICENSE new file mode 100644 index 0000000..c41a1d1 --- /dev/null +++ b/third_party/jsoncpp/LICENSE @@ -0,0 +1,55 @@ +The JsonCpp library's source code, including accompanying documentation, +tests and demonstration applications, are licensed under the following +conditions... + +Baptiste Lepilleur and The JsonCpp Authors explicitly disclaim copyright in all +jurisdictions which recognize such a disclaimer. In such jurisdictions, +this software is released into the Public Domain. + +In jurisdictions which do not recognize Public Domain property (e.g. Germany as of +2010), this software is Copyright (c) 2007-2010 by Baptiste Lepilleur and +The JsonCpp Authors, and is released under the terms of the MIT License (see below). + +In jurisdictions which recognize Public Domain property, the user of this +software may choose to accept it either as 1) Public Domain, 2) under the +conditions of the MIT License (see below), or 3) under the terms of dual +Public Domain/MIT License conditions described here, as they choose. + +The MIT License is about as close to Public Domain as a license can get, and is +described in clear, concise terms at: + + http://en.wikipedia.org/wiki/MIT_License + +The full text of the MIT License follows: + +======================================================================== +Copyright (c) 2007-2010 Baptiste Lepilleur and The JsonCpp Authors + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the "Software"), to deal in the Software without +restriction, including without limitation the rights to use, copy, +modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS +BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +======================================================================== +(END LICENSE TEXT) + +The MIT license is compatible with both the GPL and commercial +software, affording one all of the rights of Public Domain with the +minor nuisance of being required to keep the above copyright notice +and license text in the source code. Note also that by accepting the +Public Domain "license" you can re-license your copy using whatever +license you like. diff --git a/third_party/jsoncpp/README.md b/third_party/jsoncpp/README.md new file mode 100644 index 0000000..5bff8dc --- /dev/null +++ b/third_party/jsoncpp/README.md @@ -0,0 +1,67 @@ +# JsonCpp + +[![badge](https://img.shields.io/badge/conan.io-jsoncpp%2F1.8.0-green.svg?logo=data:image/png;base64%2CiVBORw0KGgoAAAANSUhEUgAAAA4AAAAOCAMAAAAolt3jAAAA1VBMVEUAAABhlctjlstkl8tlmMtlmMxlmcxmmcxnmsxpnMxpnM1qnc1sn85voM91oM11oc1xotB2oc56pNF6pNJ2ptJ8ptJ8ptN9ptN8p9N5qNJ9p9N9p9R8qtOBqdSAqtOAqtR%2BrNSCrNJ/rdWDrNWCsNWCsNaJs9eLs9iRvNuVvdyVv9yXwd2Zwt6axN6dxt%2Bfx%2BChyeGiyuGjyuCjyuGly%2BGlzOKmzOGozuKoz%2BKqz%2BOq0OOv1OWw1OWw1eWx1eWy1uay1%2Baz1%2Baz1%2Bez2Oe02Oe12ee22ujUGwH3AAAAAXRSTlMAQObYZgAAAAFiS0dEAIgFHUgAAAAJcEhZcwAACxMAAAsTAQCanBgAAAAHdElNRQfgBQkREyOxFIh/AAAAiklEQVQI12NgAAMbOwY4sLZ2NtQ1coVKWNvoc/Eq8XDr2wB5Ig62ekza9vaOqpK2TpoMzOxaFtwqZua2Bm4makIM7OzMAjoaCqYuxooSUqJALjs7o4yVpbowvzSUy87KqSwmxQfnsrPISyFzWeWAXCkpMaBVIC4bmCsOdgiUKwh3JojLgAQ4ZCE0AMm2D29tZwe6AAAAAElFTkSuQmCC)](https://bintray.com/theirix/conan-repo/jsoncpp%3Atheirix) +[![badge](https://img.shields.io/badge/license-MIT-blue)](https://github.com/open-source-parsers/jsoncpp/blob/master/LICENSE) +[![badge](https://img.shields.io/badge/document-doxygen-brightgreen)](http://open-source-parsers.github.io/jsoncpp-docs/doxygen/index.html) +[![Coverage Status](https://coveralls.io/repos/github/open-source-parsers/jsoncpp/badge.svg?branch=master)](https://coveralls.io/github/open-source-parsers/jsoncpp?branch=master) + + +[JSON][json-org] is a lightweight data-interchange format. It can represent +numbers, strings, ordered sequences of values, and collections of name/value +pairs. + +[json-org]: http://json.org/ + +JsonCpp is a C++ library that allows manipulating JSON values, including +serialization and deserialization to and from strings. It can also preserve +existing comment in unserialization/serialization steps, making it a convenient +format to store user input files. + + +## Documentation + +[JsonCpp documentation][JsonCpp-documentation] is generated using [Doxygen][]. + +[JsonCpp-documentation]: http://open-source-parsers.github.io/jsoncpp-docs/doxygen/index.html +[Doxygen]: http://www.doxygen.org + + +## A note on backward-compatibility + +* `1.y.z` is built with C++11. +* `0.y.z` can be used with older compilers. +* `00.11.z` can be used both in old and new compilers. +* Major versions maintain binary-compatibility. + +### Special note +The branch `00.11.z`is a new branch, its major version number `00` is to show that it is +different from `0.y.z` and `1.y.z`, the main purpose of this branch is to make a balance +between the other two branches. Thus, users can use some new features in this new branch +that introduced in 1.y.z, but can hardly applied into 0.y.z. + +## Using JsonCpp in your project + +### The vcpkg dependency manager +You can download and install JsonCpp using the [vcpkg](https://github.com/Microsoft/vcpkg/) dependency manager: + + git clone https://github.com/Microsoft/vcpkg.git + cd vcpkg + ./bootstrap-vcpkg.sh + ./vcpkg integrate install + ./vcpkg install jsoncpp + +The JsonCpp port in vcpkg is kept up to date by Microsoft team members and community contributors. If the version is out of date, please [create an issue or pull request](https://github.com/Microsoft/vcpkg) on the vcpkg repository. + +### Amalgamated source +https://github.com/open-source-parsers/jsoncpp/wiki/Amalgamated-(Possibly-outdated) + +### The Meson Build System +If you are using the [Meson Build System](http://mesonbuild.com), then you can get a wrap file by downloading it from [Meson WrapDB](https://wrapdb.mesonbuild.com/jsoncpp), or simply use `meson wrap install jsoncpp`. + +### Other ways +If you have trouble, see the [Wiki](https://github.com/open-source-parsers/jsoncpp/wiki), or post a question as an Issue. + +## License + +See the `LICENSE` file for details. In summary, JsonCpp is licensed under the +MIT license, or public domain if desired and recognized in your jurisdiction. diff --git a/third_party/jsoncpp/amalgamate.py b/third_party/jsoncpp/amalgamate.py new file mode 100755 index 0000000..4a328ab --- /dev/null +++ b/third_party/jsoncpp/amalgamate.py @@ -0,0 +1,161 @@ +#!/usr/bin/env python + +"""Amalgamate json-cpp library sources into a single source and header file. + +Works with python2.6+ and python3.4+. + +Example of invocation (must be invoked from json-cpp top directory): +python amalgamate.py +""" +import os +import os.path +import sys + +INCLUDE_PATH = "include/json" +SRC_PATH = "src/lib_json" + +class AmalgamationFile: + def __init__(self, top_dir): + self.top_dir = top_dir + self.blocks = [] + + def add_text(self, text): + if not text.endswith("\n"): + text += "\n" + self.blocks.append(text) + + def add_file(self, relative_input_path, wrap_in_comment=False): + def add_marker(prefix): + self.add_text("") + self.add_text("// " + "/"*70) + self.add_text("// %s of content of file: %s" % (prefix, relative_input_path.replace("\\","/"))) + self.add_text("// " + "/"*70) + self.add_text("") + add_marker("Beginning") + f = open(os.path.join(self.top_dir, relative_input_path), "rt") + content = f.read() + if wrap_in_comment: + content = "/*\n" + content + "\n*/" + self.add_text(content) + f.close() + add_marker("End") + self.add_text("\n\n\n\n") + + def get_value(self): + return "".join(self.blocks).replace("\r\n","\n") + + def write_to(self, output_path): + output_dir = os.path.dirname(output_path) + if output_dir and not os.path.isdir(output_dir): + os.makedirs(output_dir) + f = open(output_path, "wb") + f.write(str.encode(self.get_value(), 'UTF-8')) + f.close() + +def amalgamate_source(source_top_dir=None, + target_source_path=None, + header_include_path=None): + """Produces amalgamated source. + Parameters: + source_top_dir: top-directory + target_source_path: output .cpp path + header_include_path: generated header path relative to target_source_path. + """ + print("Amalgamating header...") + header = AmalgamationFile(source_top_dir) + header.add_text("/// Json-cpp amalgamated header (http://jsoncpp.sourceforge.net/).") + header.add_text('/// It is intended to be used with #include "%s"' % header_include_path) + header.add_file("LICENSE", wrap_in_comment=True) + header.add_text("#ifndef JSON_AMALGAMATED_H_INCLUDED") + header.add_text("# define JSON_AMALGAMATED_H_INCLUDED") + header.add_text("/// If defined, indicates that the source file is amalgamated") + header.add_text("/// to prevent private header inclusion.") + header.add_text("#define JSON_IS_AMALGAMATION") + header.add_file(os.path.join(INCLUDE_PATH, "version.h")) + header.add_file(os.path.join(INCLUDE_PATH, "allocator.h")) + header.add_file(os.path.join(INCLUDE_PATH, "config.h")) + header.add_file(os.path.join(INCLUDE_PATH, "forwards.h")) + header.add_file(os.path.join(INCLUDE_PATH, "json_features.h")) + header.add_file(os.path.join(INCLUDE_PATH, "value.h")) + header.add_file(os.path.join(INCLUDE_PATH, "reader.h")) + header.add_file(os.path.join(INCLUDE_PATH, "writer.h")) + header.add_file(os.path.join(INCLUDE_PATH, "assertions.h")) + header.add_text("#endif //ifndef JSON_AMALGAMATED_H_INCLUDED") + + target_header_path = os.path.join(os.path.dirname(target_source_path), header_include_path) + print("Writing amalgamated header to %r" % target_header_path) + header.write_to(target_header_path) + + base, ext = os.path.splitext(header_include_path) + forward_header_include_path = base + "-forwards" + ext + print("Amalgamating forward header...") + header = AmalgamationFile(source_top_dir) + header.add_text("/// Json-cpp amalgamated forward header (http://jsoncpp.sourceforge.net/).") + header.add_text('/// It is intended to be used with #include "%s"' % forward_header_include_path) + header.add_text("/// This header provides forward declaration for all JsonCpp types.") + header.add_file("LICENSE", wrap_in_comment=True) + header.add_text("#ifndef JSON_FORWARD_AMALGAMATED_H_INCLUDED") + header.add_text("# define JSON_FORWARD_AMALGAMATED_H_INCLUDED") + header.add_text("/// If defined, indicates that the source file is amalgamated") + header.add_text("/// to prevent private header inclusion.") + header.add_text("#define JSON_IS_AMALGAMATION") + header.add_file(os.path.join(INCLUDE_PATH, "version.h")) + header.add_file(os.path.join(INCLUDE_PATH, "allocator.h")) + header.add_file(os.path.join(INCLUDE_PATH, "config.h")) + header.add_file(os.path.join(INCLUDE_PATH, "forwards.h")) + header.add_text("#endif //ifndef JSON_FORWARD_AMALGAMATED_H_INCLUDED") + + target_forward_header_path = os.path.join(os.path.dirname(target_source_path), + forward_header_include_path) + print("Writing amalgamated forward header to %r" % target_forward_header_path) + header.write_to(target_forward_header_path) + + print("Amalgamating source...") + source = AmalgamationFile(source_top_dir) + source.add_text("/// Json-cpp amalgamated source (http://jsoncpp.sourceforge.net/).") + source.add_text('/// It is intended to be used with #include "%s"' % header_include_path) + source.add_file("LICENSE", wrap_in_comment=True) + source.add_text("") + source.add_text('#include "%s"' % header_include_path) + source.add_text(""" +#ifndef JSON_IS_AMALGAMATION +#error "Compile with -I PATH_TO_JSON_DIRECTORY" +#endif +""") + source.add_text("") + source.add_file(os.path.join(SRC_PATH, "json_tool.h")) + source.add_file(os.path.join(SRC_PATH, "json_reader.cpp")) + source.add_file(os.path.join(SRC_PATH, "json_valueiterator.inl")) + source.add_file(os.path.join(SRC_PATH, "json_value.cpp")) + source.add_file(os.path.join(SRC_PATH, "json_writer.cpp")) + + print("Writing amalgamated source to %r" % target_source_path) + source.write_to(target_source_path) + +def main(): + usage = """%prog [options] +Generate a single amalgamated source and header file from the sources. +""" + from optparse import OptionParser + parser = OptionParser(usage=usage) + parser.allow_interspersed_args = False + parser.add_option("-s", "--source", dest="target_source_path", action="store", default="dist/jsoncpp.cpp", + help="""Output .cpp source path. [Default: %default]""") + parser.add_option("-i", "--include", dest="header_include_path", action="store", default="json/json.h", + help="""Header include path. Used to include the header from the amalgamated source file. [Default: %default]""") + parser.add_option("-t", "--top-dir", dest="top_dir", action="store", default=os.getcwd(), + help="""Source top-directory. [Default: %default]""") + parser.enable_interspersed_args() + options, args = parser.parse_args() + + msg = amalgamate_source(source_top_dir=options.top_dir, + target_source_path=options.target_source_path, + header_include_path=options.header_include_path) + if msg: + sys.stderr.write(msg + "\n") + sys.exit(1) + else: + print("Source successfully amalgamated") + +if __name__ == "__main__": + main() diff --git a/third_party/jsoncpp/appveyor.yml b/third_party/jsoncpp/appveyor.yml new file mode 100644 index 0000000..cccce42 --- /dev/null +++ b/third_party/jsoncpp/appveyor.yml @@ -0,0 +1,37 @@ +clone_folder: c:\projects\jsoncpp + +environment: + + matrix: + - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 + CMAKE_GENERATOR: Visual Studio 14 2015 + - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 + CMAKE_GENERATOR: Visual Studio 14 2015 Win64 + - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 + CMAKE_GENERATOR: Visual Studio 15 2017 + - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 + CMAKE_GENERATOR: Visual Studio 15 2017 Win64 + +build_script: + - cmake --version + # The build script starts in root. + - set JSONCPP_FOLDER=%cd% + - set JSONCPP_BUILD_FOLDER=%JSONCPP_FOLDER%\build\release + - mkdir -p %JSONCPP_BUILD_FOLDER% + - cd %JSONCPP_BUILD_FOLDER% + - cmake -G "%CMAKE_GENERATOR%" -DCMAKE_INSTALL_PREFIX:PATH=%CD:\=/%/install -DBUILD_SHARED_LIBS:BOOL=ON %JSONCPP_FOLDER% + # Use ctest to make a dashboard build: + # - ctest -D Experimental(Start|Update|Configure|Build|Test|Coverage|MemCheck|Submit) + # NOTE: Testing on windows is not yet finished: + # - ctest -C Release -D ExperimentalStart -D ExperimentalConfigure -D ExperimentalBuild -D ExperimentalTest -D ExperimentalSubmit + - ctest -C Release -D ExperimentalStart -D ExperimentalConfigure -D ExperimentalBuild -D ExperimentalSubmit + # Final step is to verify that installation succeeds + - cmake --build . --config Release --target install + +deploy: + provider: GitHub + auth_token: + secure: K2Tp1q8pIZ7rs0Ot24ZMWuwr12Ev6Tc6QkhMjGQxoQG3ng1pXtgPasiJ45IDXGdg + on: + branch: master + appveyor_repo_tag: true diff --git a/third_party/jsoncpp/cmake/JoinPaths.cmake b/third_party/jsoncpp/cmake/JoinPaths.cmake new file mode 100644 index 0000000..2b376b7 --- /dev/null +++ b/third_party/jsoncpp/cmake/JoinPaths.cmake @@ -0,0 +1,23 @@ +# This module provides a function for joining paths +# known from most languages +# +# SPDX-License-Identifier: (MIT OR CC0-1.0) +# Copyright 2020 Jan Tojnar +# https://github.com/jtojnar/cmake-snips +# +# Modelled after Python’s os.path.join +# https://docs.python.org/3.7/library/os.path.html#os.path.join +# Windows not supported +function(join_paths joined_path first_path_segment) + set(temp_path "${first_path_segment}") + foreach(current_segment IN LISTS ARGN) + if(NOT ("${current_segment}" STREQUAL "")) + if(IS_ABSOLUTE "${current_segment}") + set(temp_path "${current_segment}") + else() + set(temp_path "${temp_path}/${current_segment}") + endif() + endif() + endforeach() + set(${joined_path} "${temp_path}" PARENT_SCOPE) +endfunction() diff --git a/third_party/jsoncpp/dev.makefile b/third_party/jsoncpp/dev.makefile new file mode 100644 index 0000000..545ff27 --- /dev/null +++ b/third_party/jsoncpp/dev.makefile @@ -0,0 +1,37 @@ +# This is only for jsoncpp developers/contributors. +# We use this to sign releases, generate documentation, etc. +VER?=$(shell cat version) + +default: + @echo "VER=${VER}" +update-version: + perl get_version.pl meson.build >| version +sign: jsoncpp-${VER}.tar.gz + gpg --armor --detach-sign $< + gpg --verify $<.asc + # Then upload .asc to the release. +jsoncpp-%.tar.gz: + curl https://github.com/open-source-parsers/jsoncpp/archive/$*.tar.gz -o $@ +dox: + python doxybuild.py --doxygen=$$(which doxygen) --in doc/web_doxyfile.in + rsync -va -c --delete dist/doxygen/jsoncpp-api-html-${VER}/ ../jsoncpp-docs/doxygen/ + # Then 'git add -A' and 'git push' in jsoncpp-docs. +build: + mkdir -p build/debug + cd build/debug; cmake -DCMAKE_BUILD_TYPE=debug -DBUILD_SHARED_LIBS=ON -G "Unix Makefiles" ../.. + make -C build/debug + +# Currently, this depends on include/json/version.h generated +# by cmake. +test-amalgamate: + python2.7 amalgamate.py + python3.4 amalgamate.py + cd dist; gcc -I. -c jsoncpp.cpp + +valgrind: + valgrind --error-exitcode=42 --leak-check=full ./build/debug/src/test_lib_json/jsoncpp_test + +clean: + \rm -rf *.gz *.asc dist/ + +.PHONY: build diff --git a/third_party/jsoncpp/devtools/__init__.py b/third_party/jsoncpp/devtools/__init__.py new file mode 100644 index 0000000..4a51e65 --- /dev/null +++ b/third_party/jsoncpp/devtools/__init__.py @@ -0,0 +1,6 @@ +# Copyright 2010 Baptiste Lepilleur and The JsonCpp Authors +# Distributed under MIT license, or public domain if desired and +# recognized in your jurisdiction. +# See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE + +# module diff --git a/third_party/jsoncpp/devtools/agent_vmw7.json b/third_party/jsoncpp/devtools/agent_vmw7.json new file mode 100644 index 0000000..cd7b777 --- /dev/null +++ b/third_party/jsoncpp/devtools/agent_vmw7.json @@ -0,0 +1,33 @@ +{ + "cmake_variants" : [ + {"name": "generator", + "generators": [ + {"generator": [ + "Visual Studio 7 .NET 2003", + "Visual Studio 9 2008", + "Visual Studio 9 2008 Win64", + "Visual Studio 10", + "Visual Studio 10 Win64", + "Visual Studio 11", + "Visual Studio 11 Win64" + ] + }, + {"generator": ["MinGW Makefiles"], + "env_prepend": [{"path": "c:/wut/prg/MinGW/bin"}] + } + ] + }, + {"name": "shared_dll", + "variables": [ + ["BUILD_SHARED_LIBS=true"], + ["BUILD_SHARED_LIBS=false"] + ] + }, + {"name": "build_type", + "build_types": [ + "debug", + "release" + ] + } + ] +} diff --git a/third_party/jsoncpp/devtools/agent_vmxp.json b/third_party/jsoncpp/devtools/agent_vmxp.json new file mode 100644 index 0000000..f82a077 --- /dev/null +++ b/third_party/jsoncpp/devtools/agent_vmxp.json @@ -0,0 +1,26 @@ +{ + "cmake_variants" : [ + {"name": "generator", + "generators": [ + {"generator": [ + "Visual Studio 6", + "Visual Studio 7", + "Visual Studio 8 2005" + ] + } + ] + }, + {"name": "shared_dll", + "variables": [ + ["BUILD_SHARED_LIBS=true"], + ["BUILD_SHARED_LIBS=false"] + ] + }, + {"name": "build_type", + "build_types": [ + "debug", + "release" + ] + } + ] +} diff --git a/third_party/jsoncpp/devtools/antglob.py b/third_party/jsoncpp/devtools/antglob.py new file mode 100644 index 0000000..bd2d7ae --- /dev/null +++ b/third_party/jsoncpp/devtools/antglob.py @@ -0,0 +1,205 @@ +#!/usr/bin/env python +# encoding: utf-8 +# Copyright 2009 Baptiste Lepilleur and The JsonCpp Authors +# Distributed under MIT license, or public domain if desired and +# recognized in your jurisdiction. +# See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE + +from __future__ import print_function +from dircache import listdir +import re +import fnmatch +import os.path + + +# These fnmatch expressions are used by default to prune the directory tree +# while doing the recursive traversal in the glob_impl method of glob function. +prune_dirs = '.git .bzr .hg .svn _MTN _darcs CVS SCCS ' + +# These fnmatch expressions are used by default to exclude files and dirs +# while doing the recursive traversal in the glob_impl method of glob function. +##exclude_pats = prune_pats + '*~ #*# .#* %*% ._* .gitignore .cvsignore vssver.scc .DS_Store'.split() + +# These ant_glob expressions are used by default to exclude files and dirs and also prune the directory tree +# while doing the recursive traversal in the glob_impl method of glob function. +default_excludes = ''' +**/*~ +**/#*# +**/.#* +**/%*% +**/._* +**/CVS +**/CVS/** +**/.cvsignore +**/SCCS +**/SCCS/** +**/vssver.scc +**/.svn +**/.svn/** +**/.git +**/.git/** +**/.gitignore +**/.bzr +**/.bzr/** +**/.hg +**/.hg/** +**/_MTN +**/_MTN/** +**/_darcs +**/_darcs/** +**/.DS_Store ''' + +DIR = 1 +FILE = 2 +DIR_LINK = 4 +FILE_LINK = 8 +LINKS = DIR_LINK | FILE_LINK +ALL_NO_LINK = DIR | FILE +ALL = DIR | FILE | LINKS + +_ANT_RE = re.compile(r'(/\*\*/)|(\*\*/)|(/\*\*)|(\*)|(/)|([^\*/]*)') + +def ant_pattern_to_re(ant_pattern): + """Generates a regular expression from the ant pattern. + Matching convention: + **/a: match 'a', 'dir/a', 'dir1/dir2/a' + a/**/b: match 'a/b', 'a/c/b', 'a/d/c/b' + *.py: match 'script.py' but not 'a/script.py' + """ + rex = ['^'] + next_pos = 0 + sep_rex = r'(?:/|%s)' % re.escape(os.path.sep) +## print 'Converting', ant_pattern + for match in _ANT_RE.finditer(ant_pattern): +## print 'Matched', match.group() +## print match.start(0), next_pos + if match.start(0) != next_pos: + raise ValueError("Invalid ant pattern") + if match.group(1): # /**/ + rex.append(sep_rex + '(?:.*%s)?' % sep_rex) + elif match.group(2): # **/ + rex.append('(?:.*%s)?' % sep_rex) + elif match.group(3): # /** + rex.append(sep_rex + '.*') + elif match.group(4): # * + rex.append('[^/%s]*' % re.escape(os.path.sep)) + elif match.group(5): # / + rex.append(sep_rex) + else: # somepath + rex.append(re.escape(match.group(6))) + next_pos = match.end() + rex.append('$') + return re.compile(''.join(rex)) + +def _as_list(l): + if isinstance(l, basestring): + return l.split() + return l + +def glob(dir_path, + includes = '**/*', + excludes = default_excludes, + entry_type = FILE, + prune_dirs = prune_dirs, + max_depth = 25): + include_filter = [ant_pattern_to_re(p) for p in _as_list(includes)] + exclude_filter = [ant_pattern_to_re(p) for p in _as_list(excludes)] + prune_dirs = [p.replace('/',os.path.sep) for p in _as_list(prune_dirs)] + dir_path = dir_path.replace('/',os.path.sep) + entry_type_filter = entry_type + + def is_pruned_dir(dir_name): + for pattern in prune_dirs: + if fnmatch.fnmatch(dir_name, pattern): + return True + return False + + def apply_filter(full_path, filter_rexs): + """Return True if at least one of the filter regular expression match full_path.""" + for rex in filter_rexs: + if rex.match(full_path): + return True + return False + + def glob_impl(root_dir_path): + child_dirs = [root_dir_path] + while child_dirs: + dir_path = child_dirs.pop() + for entry in listdir(dir_path): + full_path = os.path.join(dir_path, entry) +## print 'Testing:', full_path, + is_dir = os.path.isdir(full_path) + if is_dir and not is_pruned_dir(entry): # explore child directory ? +## print '===> marked for recursion', + child_dirs.append(full_path) + included = apply_filter(full_path, include_filter) + rejected = apply_filter(full_path, exclude_filter) + if not included or rejected: # do not include entry ? +## print '=> not included or rejected' + continue + link = os.path.islink(full_path) + is_file = os.path.isfile(full_path) + if not is_file and not is_dir: +## print '=> unknown entry type' + continue + if link: + entry_type = is_file and FILE_LINK or DIR_LINK + else: + entry_type = is_file and FILE or DIR +## print '=> type: %d' % entry_type, + if (entry_type & entry_type_filter) != 0: +## print ' => KEEP' + yield os.path.join(dir_path, entry) +## else: +## print ' => TYPE REJECTED' + return list(glob_impl(dir_path)) + + +if __name__ == "__main__": + import unittest + + class AntPatternToRETest(unittest.TestCase): +## def test_conversion(self): +## self.assertEqual('^somepath$', ant_pattern_to_re('somepath').pattern) + + def test_matching(self): + test_cases = [ ('path', + ['path'], + ['somepath', 'pathsuffix', '/path', '/path']), + ('*.py', + ['source.py', 'source.ext.py', '.py'], + ['path/source.py', '/.py', 'dir.py/z', 'z.pyc', 'z.c']), + ('**/path', + ['path', '/path', '/a/path', 'c:/a/path', '/a/b/path', '//a/path', '/a/path/b/path'], + ['path/', 'a/path/b', 'dir.py/z', 'somepath', 'pathsuffix', 'a/somepath']), + ('path/**', + ['path/a', 'path/path/a', 'path//'], + ['path', 'somepath/a', 'a/path', 'a/path/a', 'pathsuffix/a']), + ('/**/path', + ['/path', '/a/path', '/a/b/path/path', '/path/path'], + ['path', 'path/', 'a/path', '/pathsuffix', '/somepath']), + ('a/b', + ['a/b'], + ['somea/b', 'a/bsuffix', 'a/b/c']), + ('**/*.py', + ['script.py', 'src/script.py', 'a/b/script.py', '/a/b/script.py'], + ['script.pyc', 'script.pyo', 'a.py/b']), + ('src/**/*.py', + ['src/a.py', 'src/dir/a.py'], + ['a/src/a.py', '/src/a.py']), + ] + for ant_pattern, accepted_matches, rejected_matches in list(test_cases): + def local_path(paths): + return [ p.replace('/',os.path.sep) for p in paths ] + test_cases.append((ant_pattern, local_path(accepted_matches), local_path(rejected_matches))) + for ant_pattern, accepted_matches, rejected_matches in test_cases: + rex = ant_pattern_to_re(ant_pattern) + print('ant_pattern:', ant_pattern, ' => ', rex.pattern) + for accepted_match in accepted_matches: + print('Accepted?:', accepted_match) + self.assertTrue(rex.match(accepted_match) is not None) + for rejected_match in rejected_matches: + print('Rejected?:', rejected_match) + self.assertTrue(rex.match(rejected_match) is None) + + unittest.main() diff --git a/third_party/jsoncpp/devtools/batchbuild.py b/third_party/jsoncpp/devtools/batchbuild.py new file mode 100644 index 0000000..0eb0690 --- /dev/null +++ b/third_party/jsoncpp/devtools/batchbuild.py @@ -0,0 +1,278 @@ +from __future__ import print_function +import collections +import itertools +import json +import os +import os.path +import re +import shutil +import string +import subprocess +import sys +import cgi + +class BuildDesc: + def __init__(self, prepend_envs=None, variables=None, build_type=None, generator=None): + self.prepend_envs = prepend_envs or [] # [ { "var": "value" } ] + self.variables = variables or [] + self.build_type = build_type + self.generator = generator + + def merged_with(self, build_desc): + """Returns a new BuildDesc by merging field content. + Prefer build_desc fields to self fields for single valued field. + """ + return BuildDesc(self.prepend_envs + build_desc.prepend_envs, + self.variables + build_desc.variables, + build_desc.build_type or self.build_type, + build_desc.generator or self.generator) + + def env(self): + environ = os.environ.copy() + for values_by_name in self.prepend_envs: + for var, value in list(values_by_name.items()): + var = var.upper() + if type(value) is unicode: + value = value.encode(sys.getdefaultencoding()) + if var in environ: + environ[var] = value + os.pathsep + environ[var] + else: + environ[var] = value + return environ + + def cmake_args(self): + args = ["-D%s" % var for var in self.variables] + # skip build type for Visual Studio solution as it cause warning + if self.build_type and 'Visual' not in self.generator: + args.append("-DCMAKE_BUILD_TYPE=%s" % self.build_type) + if self.generator: + args.extend(['-G', self.generator]) + return args + + def __repr__(self): + return "BuildDesc(%s, build_type=%s)" % (" ".join(self.cmake_args()), self.build_type) + +class BuildData: + def __init__(self, desc, work_dir, source_dir): + self.desc = desc + self.work_dir = work_dir + self.source_dir = source_dir + self.cmake_log_path = os.path.join(work_dir, 'batchbuild_cmake.log') + self.build_log_path = os.path.join(work_dir, 'batchbuild_build.log') + self.cmake_succeeded = False + self.build_succeeded = False + + def execute_build(self): + print('Build %s' % self.desc) + self._make_new_work_dir() + self.cmake_succeeded = self._generate_makefiles() + if self.cmake_succeeded: + self.build_succeeded = self._build_using_makefiles() + return self.build_succeeded + + def _generate_makefiles(self): + print(' Generating makefiles: ', end=' ') + cmd = ['cmake'] + self.desc.cmake_args() + [os.path.abspath(self.source_dir)] + succeeded = self._execute_build_subprocess(cmd, self.desc.env(), self.cmake_log_path) + print('done' if succeeded else 'FAILED') + return succeeded + + def _build_using_makefiles(self): + print(' Building:', end=' ') + cmd = ['cmake', '--build', self.work_dir] + if self.desc.build_type: + cmd += ['--config', self.desc.build_type] + succeeded = self._execute_build_subprocess(cmd, self.desc.env(), self.build_log_path) + print('done' if succeeded else 'FAILED') + return succeeded + + def _execute_build_subprocess(self, cmd, env, log_path): + process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, cwd=self.work_dir, + env=env) + stdout, _ = process.communicate() + succeeded = (process.returncode == 0) + with open(log_path, 'wb') as flog: + log = ' '.join(cmd) + '\n' + stdout + '\nExit code: %r\n' % process.returncode + flog.write(fix_eol(log)) + return succeeded + + def _make_new_work_dir(self): + if os.path.isdir(self.work_dir): + print(' Removing work directory', self.work_dir) + shutil.rmtree(self.work_dir, ignore_errors=True) + if not os.path.isdir(self.work_dir): + os.makedirs(self.work_dir) + +def fix_eol(stdout): + """Fixes wrong EOL produced by cmake --build on Windows (\r\r\n instead of \r\n). + """ + return re.sub('\r*\n', os.linesep, stdout) + +def load_build_variants_from_config(config_path): + with open(config_path, 'rb') as fconfig: + data = json.load(fconfig) + variants = data[ 'cmake_variants' ] + build_descs_by_axis = collections.defaultdict(list) + for axis in variants: + axis_name = axis["name"] + build_descs = [] + if "generators" in axis: + for generator_data in axis["generators"]: + for generator in generator_data["generator"]: + build_desc = BuildDesc(generator=generator, + prepend_envs=generator_data.get("env_prepend")) + build_descs.append(build_desc) + elif "variables" in axis: + for variables in axis["variables"]: + build_desc = BuildDesc(variables=variables) + build_descs.append(build_desc) + elif "build_types" in axis: + for build_type in axis["build_types"]: + build_desc = BuildDesc(build_type=build_type) + build_descs.append(build_desc) + build_descs_by_axis[axis_name].extend(build_descs) + return build_descs_by_axis + +def generate_build_variants(build_descs_by_axis): + """Returns a list of BuildDesc generated for the partial BuildDesc for each axis.""" + axis_names = list(build_descs_by_axis.keys()) + build_descs = [] + for axis_name, axis_build_descs in list(build_descs_by_axis.items()): + if len(build_descs): + # for each existing build_desc and each axis build desc, create a new build_desc + new_build_descs = [] + for prototype_build_desc, axis_build_desc in itertools.product(build_descs, axis_build_descs): + new_build_descs.append(prototype_build_desc.merged_with(axis_build_desc)) + build_descs = new_build_descs + else: + build_descs = axis_build_descs + return build_descs + +HTML_TEMPLATE = string.Template(''' + + $title + + + + + + + + $th_vars + + + + $th_build_types + + + +$tr_builds + +
Variables
Build type
+''') + +def generate_html_report(html_report_path, builds): + report_dir = os.path.dirname(html_report_path) + # Vertical axis: generator + # Horizontal: variables, then build_type + builds_by_generator = collections.defaultdict(list) + variables = set() + build_types_by_variable = collections.defaultdict(set) + build_by_pos_key = {} # { (generator, var_key, build_type): build } + for build in builds: + builds_by_generator[build.desc.generator].append(build) + var_key = tuple(sorted(build.desc.variables)) + variables.add(var_key) + build_types_by_variable[var_key].add(build.desc.build_type) + pos_key = (build.desc.generator, var_key, build.desc.build_type) + build_by_pos_key[pos_key] = build + variables = sorted(variables) + th_vars = [] + th_build_types = [] + for variable in variables: + build_types = sorted(build_types_by_variable[variable]) + nb_build_type = len(build_types_by_variable[variable]) + th_vars.append('%s' % (nb_build_type, cgi.escape(' '.join(variable)))) + for build_type in build_types: + th_build_types.append('%s' % cgi.escape(build_type)) + tr_builds = [] + for generator in sorted(builds_by_generator): + tds = [ '%s\n' % cgi.escape(generator) ] + for variable in variables: + build_types = sorted(build_types_by_variable[variable]) + for build_type in build_types: + pos_key = (generator, variable, build_type) + build = build_by_pos_key.get(pos_key) + if build: + cmake_status = 'ok' if build.cmake_succeeded else 'FAILED' + build_status = 'ok' if build.build_succeeded else 'FAILED' + cmake_log_url = os.path.relpath(build.cmake_log_path, report_dir) + build_log_url = os.path.relpath(build.build_log_path, report_dir) + td = 'CMake: %s' % ( build_status.lower(), cmake_log_url, cmake_status.lower(), cmake_status) + if build.cmake_succeeded: + td += '
Build: %s' % ( build_log_url, build_status.lower(), build_status) + td += '' + else: + td = '' + tds.append(td) + tr_builds.append('%s' % '\n'.join(tds)) + html = HTML_TEMPLATE.substitute( title='Batch build report', + th_vars=' '.join(th_vars), + th_build_types=' '.join(th_build_types), + tr_builds='\n'.join(tr_builds)) + with open(html_report_path, 'wt') as fhtml: + fhtml.write(html) + print('HTML report generated in:', html_report_path) + +def main(): + usage = r"""%prog WORK_DIR SOURCE_DIR CONFIG_JSON_PATH [CONFIG2_JSON_PATH...] +Build a given CMake based project located in SOURCE_DIR with multiple generators/options.dry_run +as described in CONFIG_JSON_PATH building in WORK_DIR. + +Example of call: +python devtools\batchbuild.py e:\buildbots\jsoncpp\build . devtools\agent_vmw7.json +""" + from optparse import OptionParser + parser = OptionParser(usage=usage) + parser.allow_interspersed_args = True +# parser.add_option('-v', '--verbose', dest="verbose", action='store_true', +# help="""Be verbose.""") + parser.enable_interspersed_args() + options, args = parser.parse_args() + if len(args) < 3: + parser.error("Missing one of WORK_DIR SOURCE_DIR CONFIG_JSON_PATH.") + work_dir = args[0] + source_dir = args[1].rstrip('/\\') + config_paths = args[2:] + for config_path in config_paths: + if not os.path.isfile(config_path): + parser.error("Can not read: %r" % config_path) + + # generate build variants + build_descs = [] + for config_path in config_paths: + build_descs_by_axis = load_build_variants_from_config(config_path) + build_descs.extend(generate_build_variants(build_descs_by_axis)) + print('Build variants (%d):' % len(build_descs)) + # assign build directory for each variant + if not os.path.isdir(work_dir): + os.makedirs(work_dir) + builds = [] + with open(os.path.join(work_dir, 'matrix-dir-map.txt'), 'wt') as fmatrixmap: + for index, build_desc in enumerate(build_descs): + build_desc_work_dir = os.path.join(work_dir, '%03d' % (index+1)) + builds.append(BuildData(build_desc, build_desc_work_dir, source_dir)) + fmatrixmap.write('%s: %s\n' % (build_desc_work_dir, build_desc)) + for build in builds: + build.execute_build() + html_report_path = os.path.join(work_dir, 'batchbuild-report.html') + generate_html_report(html_report_path, builds) + print('Done') + + +if __name__ == '__main__': + main() + diff --git a/third_party/jsoncpp/devtools/fixeol.py b/third_party/jsoncpp/devtools/fixeol.py new file mode 100644 index 0000000..11e1ce2 --- /dev/null +++ b/third_party/jsoncpp/devtools/fixeol.py @@ -0,0 +1,70 @@ +# Copyright 2010 Baptiste Lepilleur and The JsonCpp Authors +# Distributed under MIT license, or public domain if desired and +# recognized in your jurisdiction. +# See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE + +from __future__ import print_function +import os.path +import sys + +def fix_source_eol(path, is_dry_run = True, verbose = True, eol = '\n'): + """Makes sure that all sources have the specified eol sequence (default: unix).""" + if not os.path.isfile(path): + raise ValueError('Path "%s" is not a file' % path) + try: + f = open(path, 'rb') + except IOError as msg: + print("%s: I/O Error: %s" % (file, str(msg)), file=sys.stderr) + return False + try: + raw_lines = f.readlines() + finally: + f.close() + fixed_lines = [line.rstrip('\r\n') + eol for line in raw_lines] + if raw_lines != fixed_lines: + print('%s =>' % path, end=' ') + if not is_dry_run: + f = open(path, "wb") + try: + f.writelines(fixed_lines) + finally: + f.close() + if verbose: + print(is_dry_run and ' NEED FIX' or ' FIXED') + return True +## +## +## +##def _do_fix(is_dry_run = True): +## from waftools import antglob +## python_sources = antglob.glob('.', +## includes = '**/*.py **/wscript **/wscript_build', +## excludes = antglob.default_excludes + './waf.py', +## prune_dirs = antglob.prune_dirs + 'waf-* ./build') +## for path in python_sources: +## _fix_python_source(path, is_dry_run) +## +## cpp_sources = antglob.glob('.', +## includes = '**/*.cpp **/*.h **/*.inl', +## prune_dirs = antglob.prune_dirs + 'waf-* ./build') +## for path in cpp_sources: +## _fix_source_eol(path, is_dry_run) +## +## +##def dry_fix(context): +## _do_fix(is_dry_run = True) +## +##def fix(context): +## _do_fix(is_dry_run = False) +## +##def shutdown(): +## pass +## +##def check(context): +## # Unit tests are run when "check" target is used +## ut = UnitTest.unit_test() +## ut.change_to_testfile_dir = True +## ut.want_to_see_test_output = True +## ut.want_to_see_test_error = True +## ut.run() +## ut.print_results() diff --git a/third_party/jsoncpp/devtools/licenseupdater.py b/third_party/jsoncpp/devtools/licenseupdater.py new file mode 100644 index 0000000..d9b662e --- /dev/null +++ b/third_party/jsoncpp/devtools/licenseupdater.py @@ -0,0 +1,94 @@ +"""Updates the license text in source file. +""" +from __future__ import print_function + +# An existing license is found if the file starts with the string below, +# and ends with the first blank line. +LICENSE_BEGIN = "// Copyright " + +BRIEF_LICENSE = LICENSE_BEGIN + """2007-2010 Baptiste Lepilleur and The JsonCpp Authors +// Distributed under MIT license, or public domain if desired and +// recognized in your jurisdiction. +// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE + +""".replace('\r\n','\n') + +def update_license(path, dry_run, show_diff): + """Update the license statement in the specified file. + Parameters: + path: path of the C++ source file to update. + dry_run: if True, just print the path of the file that would be updated, + but don't change it. + show_diff: if True, print the path of the file that would be modified, + as well as the change made to the file. + """ + with open(path, 'rt') as fin: + original_text = fin.read().replace('\r\n','\n') + newline = fin.newlines and fin.newlines[0] or '\n' + if not original_text.startswith(LICENSE_BEGIN): + # No existing license found => prepend it + new_text = BRIEF_LICENSE + original_text + else: + license_end_index = original_text.index('\n\n') # search first blank line + new_text = BRIEF_LICENSE + original_text[license_end_index+2:] + if original_text != new_text: + if not dry_run: + with open(path, 'wb') as fout: + fout.write(new_text.replace('\n', newline)) + print('Updated', path) + if show_diff: + import difflib + print('\n'.join(difflib.unified_diff(original_text.split('\n'), + new_text.split('\n')))) + return True + return False + +def update_license_in_source_directories(source_dirs, dry_run, show_diff): + """Updates license text in C++ source files found in directory source_dirs. + Parameters: + source_dirs: list of directory to scan for C++ sources. Directories are + scanned recursively. + dry_run: if True, just print the path of the file that would be updated, + but don't change it. + show_diff: if True, print the path of the file that would be modified, + as well as the change made to the file. + """ + from devtools import antglob + prune_dirs = antglob.prune_dirs + 'scons-local* ./build* ./libs ./dist' + for source_dir in source_dirs: + cpp_sources = antglob.glob(source_dir, + includes = '''**/*.h **/*.cpp **/*.inl''', + prune_dirs = prune_dirs) + for source in cpp_sources: + update_license(source, dry_run, show_diff) + +def main(): + usage = """%prog DIR [DIR2...] +Updates license text in sources of the project in source files found +in the directory specified on the command-line. + +Example of call: +python devtools\licenseupdater.py include src -n --diff +=> Show change that would be made to the sources. + +python devtools\licenseupdater.py include src +=> Update license statement on all sources in directories include/ and src/. +""" + from optparse import OptionParser + parser = OptionParser(usage=usage) + parser.allow_interspersed_args = False + parser.add_option('-n', '--dry-run', dest="dry_run", action='store_true', default=False, + help="""Only show what files are updated, do not update the files""") + parser.add_option('--diff', dest="show_diff", action='store_true', default=False, + help="""On update, show change made to the file.""") + parser.enable_interspersed_args() + options, args = parser.parse_args() + update_license_in_source_directories(args, options.dry_run, options.show_diff) + print('Done') + +if __name__ == '__main__': + import sys + import os.path + sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) + main() + diff --git a/third_party/jsoncpp/devtools/tarball.py b/third_party/jsoncpp/devtools/tarball.py new file mode 100644 index 0000000..3c0ba65 --- /dev/null +++ b/third_party/jsoncpp/devtools/tarball.py @@ -0,0 +1,52 @@ +# Copyright 2010 Baptiste Lepilleur and The JsonCpp Authors +# Distributed under MIT license, or public domain if desired and +# recognized in your jurisdiction. +# See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE + +from contextlib import closing +import os +import tarfile + +TARGZ_DEFAULT_COMPRESSION_LEVEL = 9 + +def make_tarball(tarball_path, sources, base_dir, prefix_dir=''): + """Parameters: + tarball_path: output path of the .tar.gz file + sources: list of sources to include in the tarball, relative to the current directory + base_dir: if a source file is in a sub-directory of base_dir, then base_dir is stripped + from path in the tarball. + prefix_dir: all files stored in the tarball be sub-directory of prefix_dir. Set to '' + to make them child of root. + """ + base_dir = os.path.normpath(os.path.abspath(base_dir)) + def archive_name(path): + """Makes path relative to base_dir.""" + path = os.path.normpath(os.path.abspath(path)) + common_path = os.path.commonprefix((base_dir, path)) + archive_name = path[len(common_path):] + if os.path.isabs(archive_name): + archive_name = archive_name[1:] + return os.path.join(prefix_dir, archive_name) + def visit(tar, dirname, names): + for name in names: + path = os.path.join(dirname, name) + if os.path.isfile(path): + path_in_tar = archive_name(path) + tar.add(path, path_in_tar) + compression = TARGZ_DEFAULT_COMPRESSION_LEVEL + with closing(tarfile.TarFile.open(tarball_path, 'w:gz', + compresslevel=compression)) as tar: + for source in sources: + source_path = source + if os.path.isdir(source): + for dirpath, dirnames, filenames in os.walk(source_path): + visit(tar, dirpath, filenames) + else: + path_in_tar = archive_name(source_path) + tar.add(source_path, path_in_tar) # filename, arcname + +def decompress(tarball_path, base_dir): + """Decompress the gzipped tarball into directory base_dir. + """ + with closing(tarfile.TarFile.open(tarball_path)) as tar: + tar.extractall(base_dir) diff --git a/third_party/jsoncpp/doc/doxyfile.in b/third_party/jsoncpp/doc/doxyfile.in new file mode 100644 index 0000000..dcf514e --- /dev/null +++ b/third_party/jsoncpp/doc/doxyfile.in @@ -0,0 +1,2302 @@ +# Doxyfile 1.8.5 + +# This file describes the settings to be used by the documentation system +# doxygen (www.doxygen.org) for a project. +# +# All text after a double hash (##) is considered a comment and is placed in +# front of the TAG it is preceding. +# +# All text after a single hash (#) is considered a comment and will be ignored. +# The format is: +# TAG = value [value, ...] +# For lists, items can also be appended using: +# TAG += value [value, ...] +# Values that contain spaces should be placed between quotes (\" \"). + +#--------------------------------------------------------------------------- +# Project related configuration options +#--------------------------------------------------------------------------- + +# This tag specifies the encoding used for all characters in the config file +# that follow. The default is UTF-8 which is also the encoding used for all text +# before the first occurrence of this tag. Doxygen uses libiconv (or the iconv +# built into libc) for the transcoding. See http://www.gnu.org/software/libiconv +# for the list of possible encodings. +# The default value is: UTF-8. + +DOXYFILE_ENCODING = UTF-8 + +# The PROJECT_NAME tag is a single word (or a sequence of words surrounded by +# double-quotes, unless you are using Doxywizard) that should identify the +# project for which the documentation is generated. This name is used in the +# title of most generated pages and in a few other places. +# The default value is: My Project. + +PROJECT_NAME = "JsonCpp" + +# The PROJECT_NUMBER tag can be used to enter a project or revision number. This +# could be handy for archiving the generated documentation or if some version +# control system is used. + +PROJECT_NUMBER = %JSONCPP_VERSION% + +# Using the PROJECT_BRIEF tag one can provide an optional one line description +# for a project that appears at the top of each page and should give viewer a +# quick idea about the purpose of the project. Keep the description short. + +PROJECT_BRIEF = + +# With the PROJECT_LOGO tag one can specify an logo or icon that is included in +# the documentation. The maximum height of the logo should not exceed 55 pixels +# and the maximum width should not exceed 200 pixels. Doxygen will copy the logo +# to the output directory. + +PROJECT_LOGO = + +# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) path +# into which the generated documentation will be written. If a relative path is +# entered, it will be relative to the location where doxygen was started. If +# left blank the current directory will be used. + +OUTPUT_DIRECTORY = %DOC_TOPDIR% + +# If the CREATE_SUBDIRS tag is set to YES, then doxygen will create 4096 sub- +# directories (in 2 levels) under the output directory of each output format and +# will distribute the generated files over these directories. Enabling this +# option can be useful when feeding doxygen a huge amount of source files, where +# putting all generated files in the same directory would otherwise causes +# performance problems for the file system. +# The default value is: NO. + +CREATE_SUBDIRS = NO + +# The OUTPUT_LANGUAGE tag is used to specify the language in which all +# documentation generated by doxygen is written. Doxygen will use this +# information to generate all constant output in the proper language. +# Possible values are: Afrikaans, Arabic, Brazilian, Catalan, Chinese, Chinese- +# Traditional, Croatian, Czech, Danish, Dutch, English, Esperanto, Farsi, +# Finnish, French, German, Greek, Hungarian, Italian, Japanese, Japanese-en, +# Korean, Korean-en, Latvian, Norwegian, Macedonian, Persian, Polish, +# Portuguese, Romanian, Russian, Serbian, Slovak, Slovene, Spanish, Swedish, +# Turkish, Ukrainian and Vietnamese. +# The default value is: English. + +OUTPUT_LANGUAGE = English + +# If the BRIEF_MEMBER_DESC tag is set to YES doxygen will include brief member +# descriptions after the members that are listed in the file and class +# documentation (similar to Javadoc). Set to NO to disable this. +# The default value is: YES. + +BRIEF_MEMBER_DESC = YES + +# If the REPEAT_BRIEF tag is set to YES doxygen will prepend the brief +# description of a member or function before the detailed description +# +# Note: If both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the +# brief descriptions will be completely suppressed. +# The default value is: YES. + +REPEAT_BRIEF = YES + +# This tag implements a quasi-intelligent brief description abbreviator that is +# used to form the text in various listings. Each string in this list, if found +# as the leading text of the brief description, will be stripped from the text +# and the result, after processing the whole list, is used as the annotated +# text. Otherwise, the brief description is used as-is. If left blank, the +# following values are used ($name is automatically replaced with the name of +# the entity):The $name class, The $name widget, The $name file, is, provides, +# specifies, contains, represents, a, an and the. + +ABBREVIATE_BRIEF = "The $name class" \ + "The $name widget" \ + "The $name file" \ + is \ + provides \ + specifies \ + contains \ + represents \ + a \ + an \ + the + +# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then +# doxygen will generate a detailed section even if there is only a brief +# description. +# The default value is: NO. + +ALWAYS_DETAILED_SEC = NO + +# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all +# inherited members of a class in the documentation of that class as if those +# members were ordinary class members. Constructors, destructors and assignment +# operators of the base classes will not be shown. +# The default value is: NO. + +INLINE_INHERITED_MEMB = NO + +# If the FULL_PATH_NAMES tag is set to YES doxygen will prepend the full path +# before files name in the file list and in the header files. If set to NO the +# shortest path that makes the file name unique will be used +# The default value is: YES. + +FULL_PATH_NAMES = YES + +# The STRIP_FROM_PATH tag can be used to strip a user-defined part of the path. +# Stripping is only done if one of the specified strings matches the left-hand +# part of the path. The tag can be used to show relative paths in the file list. +# If left blank the directory from which doxygen is run is used as the path to +# strip. +# +# Note that you can specify absolute paths here, but also relative paths, which +# will be relative from the directory where doxygen is started. +# This tag requires that the tag FULL_PATH_NAMES is set to YES. + +STRIP_FROM_PATH = %TOPDIR% + +# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of the +# path mentioned in the documentation of a class, which tells the reader which +# header file to include in order to use a class. If left blank only the name of +# the header file containing the class definition is used. Otherwise one should +# specify the list of include paths that are normally passed to the compiler +# using the -I flag. + +STRIP_FROM_INC_PATH = %TOPDIR%/include + +# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter (but +# less readable) file names. This can be useful is your file systems doesn't +# support long names like on DOS, Mac, or CD-ROM. +# The default value is: NO. + +SHORT_NAMES = NO + +# If the JAVADOC_AUTOBRIEF tag is set to YES then doxygen will interpret the +# first line (until the first dot) of a Javadoc-style comment as the brief +# description. If set to NO, the Javadoc-style will behave just like regular Qt- +# style comments (thus requiring an explicit @brief command for a brief +# description.) +# The default value is: NO. + +JAVADOC_AUTOBRIEF = YES + +# If the QT_AUTOBRIEF tag is set to YES then doxygen will interpret the first +# line (until the first dot) of a Qt-style comment as the brief description. If +# set to NO, the Qt-style will behave just like regular Qt-style comments (thus +# requiring an explicit \brief command for a brief description.) +# The default value is: NO. + +QT_AUTOBRIEF = NO + +# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make doxygen treat a +# multi-line C++ special comment block (i.e. a block of //! or /// comments) as +# a brief description. This used to be the default behavior. The new default is +# to treat a multi-line C++ comment block as a detailed description. Set this +# tag to YES if you prefer the old behavior instead. +# +# Note that setting this tag to YES also means that rational rose comments are +# not recognized any more. +# The default value is: NO. + +MULTILINE_CPP_IS_BRIEF = NO + +# If the INHERIT_DOCS tag is set to YES then an undocumented member inherits the +# documentation from any documented member that it re-implements. +# The default value is: YES. + +INHERIT_DOCS = YES + +# If the SEPARATE_MEMBER_PAGES tag is set to YES, then doxygen will produce a +# new page for each member. If set to NO, the documentation of a member will be +# part of the file/class/namespace that contains it. +# The default value is: NO. + +SEPARATE_MEMBER_PAGES = NO + +# The TAB_SIZE tag can be used to set the number of spaces in a tab. Doxygen +# uses this value to replace tabs by spaces in code fragments. +# Minimum value: 1, maximum value: 16, default value: 4. + +TAB_SIZE = 3 + +# This tag can be used to specify a number of aliases that act as commands in +# the documentation. An alias has the form: +# name=value +# For example adding +# "sideeffect=@par Side Effects:\n" +# will allow you to put the command \sideeffect (or @sideeffect) in the +# documentation, which will result in a user-defined paragraph with heading +# "Side Effects:". You can put \n's in the value part of an alias to insert +# newlines. + +ALIASES = "testCaseSetup=\link CppUT::TestCase::setUp() setUp()\endlink" \ + "testCaseRun=\link CppUT::TestCase::run() run()\endlink" \ + "testCaseTearDown=\link CppUT::TestCase::tearDown() tearDown()\endlink" \ + "json_ref=JSON (JavaScript Object Notation)" + +# This tag can be used to specify a number of word-keyword mappings (TCL only). +# A mapping has the form "name=value". For example adding "class=itcl::class" +# will allow you to use the command class in the itcl::class meaning. + +TCL_SUBST = + +# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C sources +# only. Doxygen will then generate output that is more tailored for C. For +# instance, some of the names that are used will be different. The list of all +# members will be omitted, etc. +# The default value is: NO. + +OPTIMIZE_OUTPUT_FOR_C = NO + +# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java or +# Python sources only. Doxygen will then generate output that is more tailored +# for that language. For instance, namespaces will be presented as packages, +# qualified scopes will look different, etc. +# The default value is: NO. + +OPTIMIZE_OUTPUT_JAVA = NO + +# Set the OPTIMIZE_FOR_FORTRAN tag to YES if your project consists of Fortran +# sources. Doxygen will then generate output that is tailored for Fortran. +# The default value is: NO. + +OPTIMIZE_FOR_FORTRAN = NO + +# Set the OPTIMIZE_OUTPUT_VHDL tag to YES if your project consists of VHDL +# sources. Doxygen will then generate output that is tailored for VHDL. +# The default value is: NO. + +OPTIMIZE_OUTPUT_VHDL = NO + +# Doxygen selects the parser to use depending on the extension of the files it +# parses. With this tag you can assign which parser to use for a given +# extension. Doxygen has a built-in mapping, but you can override or extend it +# using this tag. The format is ext=language, where ext is a file extension, and +# language is one of the parsers supported by doxygen: IDL, Java, JavaScript, +# C#, C, C++, D, PHP, Objective-C, Python, Fortran, VHDL. For instance to make +# doxygen treat .inc files as Fortran files (default is PHP), and .f files as C +# (default is Fortran), use: inc=Fortran f=C. +# +# Note For files without extension you can use no_extension as a placeholder. +# +# Note that for custom extensions you also need to set FILE_PATTERNS otherwise +# the files are not read by doxygen. + +EXTENSION_MAPPING = + +# If the MARKDOWN_SUPPORT tag is enabled then doxygen pre-processes all comments +# according to the Markdown format, which allows for more readable +# documentation. See http://daringfireball.net/projects/markdown/ for details. +# The output of markdown processing is further processed by doxygen, so you can +# mix doxygen, HTML, and XML commands with Markdown formatting. Disable only in +# case of backward compatibilities issues. +# The default value is: YES. + +MARKDOWN_SUPPORT = YES + +# When enabled doxygen tries to link words that correspond to documented +# classes, or namespaces to their corresponding documentation. Such a link can +# be prevented in individual cases by by putting a % sign in front of the word +# or globally by setting AUTOLINK_SUPPORT to NO. +# The default value is: YES. + +AUTOLINK_SUPPORT = YES + +# If you use STL classes (i.e. std::string, std::vector, etc.) but do not want +# to include (a tag file for) the STL sources as input, then you should set this +# tag to YES in order to let doxygen match functions declarations and +# definitions whose arguments contain STL classes (e.g. func(std::string); +# versus func(std::string) {}). This also make the inheritance and collaboration +# diagrams that involve STL classes more complete and accurate. +# The default value is: NO. + +BUILTIN_STL_SUPPORT = YES + +# If you use Microsoft's C++/CLI language, you should set this option to YES to +# enable parsing support. +# The default value is: NO. + +CPP_CLI_SUPPORT = NO + +# Set the SIP_SUPPORT tag to YES if your project consists of sip (see: +# http://www.riverbankcomputing.co.uk/software/sip/intro) sources only. Doxygen +# will parse them like normal C++ but will assume all classes use public instead +# of private inheritance when no explicit protection keyword is present. +# The default value is: NO. + +SIP_SUPPORT = NO + +# For Microsoft's IDL there are propget and propput attributes to indicate +# getter and setter methods for a property. Setting this option to YES will make +# doxygen to replace the get and set methods by a property in the documentation. +# This will only work if the methods are indeed getting or setting a simple +# type. If this is not the case, or you want to show the methods anyway, you +# should set this option to NO. +# The default value is: YES. + +IDL_PROPERTY_SUPPORT = YES + +# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC +# tag is set to YES, then doxygen will reuse the documentation of the first +# member in the group (if any) for the other members of the group. By default +# all members of a group must be documented explicitly. +# The default value is: NO. + +DISTRIBUTE_GROUP_DOC = NO + +# Set the SUBGROUPING tag to YES to allow class member groups of the same type +# (for instance a group of public functions) to be put as a subgroup of that +# type (e.g. under the Public Functions section). Set it to NO to prevent +# subgrouping. Alternatively, this can be done per class using the +# \nosubgrouping command. +# The default value is: YES. + +SUBGROUPING = YES + +# When the INLINE_GROUPED_CLASSES tag is set to YES, classes, structs and unions +# are shown inside the group in which they are included (e.g. using \ingroup) +# instead of on a separate page (for HTML and Man pages) or section (for LaTeX +# and RTF). +# +# Note that this feature does not work in combination with +# SEPARATE_MEMBER_PAGES. +# The default value is: NO. + +INLINE_GROUPED_CLASSES = NO + +# When the INLINE_SIMPLE_STRUCTS tag is set to YES, structs, classes, and unions +# with only public data fields or simple typedef fields will be shown inline in +# the documentation of the scope in which they are defined (i.e. file, +# namespace, or group documentation), provided this scope is documented. If set +# to NO, structs, classes, and unions are shown on a separate page (for HTML and +# Man pages) or section (for LaTeX and RTF). +# The default value is: NO. + +INLINE_SIMPLE_STRUCTS = NO + +# When TYPEDEF_HIDES_STRUCT tag is enabled, a typedef of a struct, union, or +# enum is documented as struct, union, or enum with the name of the typedef. So +# typedef struct TypeS {} TypeT, will appear in the documentation as a struct +# with name TypeT. When disabled the typedef will appear as a member of a file, +# namespace, or class. And the struct will be named TypeS. This can typically be +# useful for C code in case the coding convention dictates that all compound +# types are typedef'ed and only the typedef is referenced, never the tag name. +# The default value is: NO. + +TYPEDEF_HIDES_STRUCT = NO + +# The size of the symbol lookup cache can be set using LOOKUP_CACHE_SIZE. This +# cache is used to resolve symbols given their name and scope. Since this can be +# an expensive process and often the same symbol appears multiple times in the +# code, doxygen keeps a cache of pre-resolved symbols. If the cache is too small +# doxygen will become slower. If the cache is too large, memory is wasted. The +# cache size is given by this formula: 2^(16+LOOKUP_CACHE_SIZE). The valid range +# is 0..9, the default is 0, corresponding to a cache size of 2^16=65536 +# symbols. At the end of a run doxygen will report the cache usage and suggest +# the optimal cache size from a speed point of view. +# Minimum value: 0, maximum value: 9, default value: 0. + +LOOKUP_CACHE_SIZE = 0 + +#--------------------------------------------------------------------------- +# Build related configuration options +#--------------------------------------------------------------------------- + +# If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in +# documentation are documented, even if no documentation was available. Private +# class members and static file members will be hidden unless the +# EXTRACT_PRIVATE respectively EXTRACT_STATIC tags are set to YES. +# Note: This will also disable the warnings about undocumented members that are +# normally produced when WARNINGS is set to YES. +# The default value is: NO. + +EXTRACT_ALL = YES + +# If the EXTRACT_PRIVATE tag is set to YES all private members of a class will +# be included in the documentation. +# The default value is: NO. + +EXTRACT_PRIVATE = NO + +# If the EXTRACT_PACKAGE tag is set to YES all members with package or internal +# scope will be included in the documentation. +# The default value is: NO. + +EXTRACT_PACKAGE = NO + +# If the EXTRACT_STATIC tag is set to YES all static members of a file will be +# included in the documentation. +# The default value is: NO. + +EXTRACT_STATIC = YES + +# If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs) defined +# locally in source files will be included in the documentation. If set to NO +# only classes defined in header files are included. Does not have any effect +# for Java sources. +# The default value is: YES. + +EXTRACT_LOCAL_CLASSES = NO + +# This flag is only useful for Objective-C code. When set to YES local methods, +# which are defined in the implementation section but not in the interface are +# included in the documentation. If set to NO only methods in the interface are +# included. +# The default value is: NO. + +EXTRACT_LOCAL_METHODS = NO + +# If this flag is set to YES, the members of anonymous namespaces will be +# extracted and appear in the documentation as a namespace called +# 'anonymous_namespace{file}', where file will be replaced with the base name of +# the file that contains the anonymous namespace. By default anonymous namespace +# are hidden. +# The default value is: NO. + +EXTRACT_ANON_NSPACES = NO + +# If the HIDE_UNDOC_MEMBERS tag is set to YES, doxygen will hide all +# undocumented members inside documented classes or files. If set to NO these +# members will be included in the various overviews, but no documentation +# section is generated. This option has no effect if EXTRACT_ALL is enabled. +# The default value is: NO. + +HIDE_UNDOC_MEMBERS = NO + +# If the HIDE_UNDOC_CLASSES tag is set to YES, doxygen will hide all +# undocumented classes that are normally visible in the class hierarchy. If set +# to NO these classes will be included in the various overviews. This option has +# no effect if EXTRACT_ALL is enabled. +# The default value is: NO. + +HIDE_UNDOC_CLASSES = NO + +# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, doxygen will hide all friend +# (class|struct|union) declarations. If set to NO these declarations will be +# included in the documentation. +# The default value is: NO. + +HIDE_FRIEND_COMPOUNDS = NO + +# If the HIDE_IN_BODY_DOCS tag is set to YES, doxygen will hide any +# documentation blocks found inside the body of a function. If set to NO these +# blocks will be appended to the function's detailed documentation block. +# The default value is: NO. + +HIDE_IN_BODY_DOCS = NO + +# The INTERNAL_DOCS tag determines if documentation that is typed after a +# \internal command is included. If the tag is set to NO then the documentation +# will be excluded. Set it to YES to include the internal documentation. +# The default value is: NO. + +INTERNAL_DOCS = YES + +# If the CASE_SENSE_NAMES tag is set to NO then doxygen will only generate file +# names in lower-case letters. If set to YES upper-case letters are also +# allowed. This is useful if you have classes or files whose names only differ +# in case and if your file system supports case sensitive file names. Windows +# and Mac users are advised to set this option to NO. +# The default value is: system dependent. + +CASE_SENSE_NAMES = NO + +# If the HIDE_SCOPE_NAMES tag is set to NO then doxygen will show members with +# their full class and namespace scopes in the documentation. If set to YES the +# scope will be hidden. +# The default value is: NO. + +HIDE_SCOPE_NAMES = NO + +# If the SHOW_INCLUDE_FILES tag is set to YES then doxygen will put a list of +# the files that are included by a file in the documentation of that file. +# The default value is: YES. + +SHOW_INCLUDE_FILES = YES + +# If the FORCE_LOCAL_INCLUDES tag is set to YES then doxygen will list include +# files with double quotes in the documentation rather than with sharp brackets. +# The default value is: NO. + +FORCE_LOCAL_INCLUDES = NO + +# If the INLINE_INFO tag is set to YES then a tag [inline] is inserted in the +# documentation for inline members. +# The default value is: YES. + +INLINE_INFO = YES + +# If the SORT_MEMBER_DOCS tag is set to YES then doxygen will sort the +# (detailed) documentation of file and class members alphabetically by member +# name. If set to NO the members will appear in declaration order. +# The default value is: YES. + +SORT_MEMBER_DOCS = YES + +# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the brief +# descriptions of file, namespace and class members alphabetically by member +# name. If set to NO the members will appear in declaration order. +# The default value is: NO. + +SORT_BRIEF_DOCS = NO + +# If the SORT_MEMBERS_CTORS_1ST tag is set to YES then doxygen will sort the +# (brief and detailed) documentation of class members so that constructors and +# destructors are listed first. If set to NO the constructors will appear in the +# respective orders defined by SORT_BRIEF_DOCS and SORT_MEMBER_DOCS. +# Note: If SORT_BRIEF_DOCS is set to NO this option is ignored for sorting brief +# member documentation. +# Note: If SORT_MEMBER_DOCS is set to NO this option is ignored for sorting +# detailed member documentation. +# The default value is: NO. + +SORT_MEMBERS_CTORS_1ST = NO + +# If the SORT_GROUP_NAMES tag is set to YES then doxygen will sort the hierarchy +# of group names into alphabetical order. If set to NO the group names will +# appear in their defined order. +# The default value is: NO. + +SORT_GROUP_NAMES = NO + +# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be sorted by +# fully-qualified names, including namespaces. If set to NO, the class list will +# be sorted only by class name, not including the namespace part. +# Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES. +# Note: This option applies only to the class list, not to the alphabetical +# list. +# The default value is: NO. + +SORT_BY_SCOPE_NAME = YES + +# If the STRICT_PROTO_MATCHING option is enabled and doxygen fails to do proper +# type resolution of all parameters of a function it will reject a match between +# the prototype and the implementation of a member function even if there is +# only one candidate or it is obvious which candidate to choose by doing a +# simple string match. By disabling STRICT_PROTO_MATCHING doxygen will still +# accept a match between prototype and implementation in such cases. +# The default value is: NO. + +STRICT_PROTO_MATCHING = NO + +# The GENERATE_TODOLIST tag can be used to enable ( YES) or disable ( NO) the +# todo list. This list is created by putting \todo commands in the +# documentation. +# The default value is: YES. + +GENERATE_TODOLIST = YES + +# The GENERATE_TESTLIST tag can be used to enable ( YES) or disable ( NO) the +# test list. This list is created by putting \test commands in the +# documentation. +# The default value is: YES. + +GENERATE_TESTLIST = NO + +# The GENERATE_BUGLIST tag can be used to enable ( YES) or disable ( NO) the bug +# list. This list is created by putting \bug commands in the documentation. +# The default value is: YES. + +GENERATE_BUGLIST = NO + +# The GENERATE_DEPRECATEDLIST tag can be used to enable ( YES) or disable ( NO) +# the deprecated list. This list is created by putting \deprecated commands in +# the documentation. +# The default value is: YES. + +GENERATE_DEPRECATEDLIST= YES + +# The ENABLED_SECTIONS tag can be used to enable conditional documentation +# sections, marked by \if ... \endif and \cond +# ... \endcond blocks. + +ENABLED_SECTIONS = + +# The MAX_INITIALIZER_LINES tag determines the maximum number of lines that the +# initial value of a variable or macro / define can have for it to appear in the +# documentation. If the initializer consists of more lines than specified here +# it will be hidden. Use a value of 0 to hide initializers completely. The +# appearance of the value of individual variables and macros / defines can be +# controlled using \showinitializer or \hideinitializer command in the +# documentation regardless of this setting. +# Minimum value: 0, maximum value: 10000, default value: 30. + +MAX_INITIALIZER_LINES = 30 + +# Set the SHOW_USED_FILES tag to NO to disable the list of files generated at +# the bottom of the documentation of classes and structs. If set to YES the list +# will mention the files that were used to generate the documentation. +# The default value is: YES. + +SHOW_USED_FILES = YES + +# Set the SHOW_FILES tag to NO to disable the generation of the Files page. This +# will remove the Files entry from the Quick Index and from the Folder Tree View +# (if specified). +# The default value is: YES. + +SHOW_FILES = YES + +# Set the SHOW_NAMESPACES tag to NO to disable the generation of the Namespaces +# page. This will remove the Namespaces entry from the Quick Index and from the +# Folder Tree View (if specified). +# The default value is: YES. + +SHOW_NAMESPACES = YES + +# The FILE_VERSION_FILTER tag can be used to specify a program or script that +# doxygen should invoke to get the current version for each file (typically from +# the version control system). Doxygen will invoke the program by executing (via +# popen()) the command command input-file, where command is the value of the +# FILE_VERSION_FILTER tag, and input-file is the name of an input file provided +# by doxygen. Whatever the program writes to standard output is used as the file +# version. For an example see the documentation. + +FILE_VERSION_FILTER = + +# The LAYOUT_FILE tag can be used to specify a layout file which will be parsed +# by doxygen. The layout file controls the global structure of the generated +# output files in an output format independent way. To create the layout file +# that represents doxygen's defaults, run doxygen with the -l option. You can +# optionally specify a file name after the option, if omitted DoxygenLayout.xml +# will be used as the name of the layout file. +# +# Note that if you run doxygen from a directory containing a file called +# DoxygenLayout.xml, doxygen will parse it automatically even if the LAYOUT_FILE +# tag is left empty. + +LAYOUT_FILE = + +# The CITE_BIB_FILES tag can be used to specify one or more bib files containing +# the reference definitions. This must be a list of .bib files. The .bib +# extension is automatically appended if omitted. This requires the bibtex tool +# to be installed. See also http://en.wikipedia.org/wiki/BibTeX for more info. +# For LaTeX the style of the bibliography can be controlled using +# LATEX_BIB_STYLE. To use this feature you need bibtex and perl available in the +# search path. Do not use file names with spaces, bibtex cannot handle them. See +# also \cite for info how to create references. + +CITE_BIB_FILES = + +#--------------------------------------------------------------------------- +# Configuration options related to warning and progress messages +#--------------------------------------------------------------------------- + +# The QUIET tag can be used to turn on/off the messages that are generated to +# standard output by doxygen. If QUIET is set to YES this implies that the +# messages are off. +# The default value is: NO. + +QUIET = NO + +# The WARNINGS tag can be used to turn on/off the warning messages that are +# generated to standard error ( stderr) by doxygen. If WARNINGS is set to YES +# this implies that the warnings are on. +# +# Tip: Turn warnings on while writing the documentation. +# The default value is: YES. + +WARNINGS = YES + +# If the WARN_IF_UNDOCUMENTED tag is set to YES, then doxygen will generate +# warnings for undocumented members. If EXTRACT_ALL is set to YES then this flag +# will automatically be disabled. +# The default value is: YES. + +WARN_IF_UNDOCUMENTED = YES + +# If the WARN_IF_DOC_ERROR tag is set to YES, doxygen will generate warnings for +# potential errors in the documentation, such as not documenting some parameters +# in a documented function, or documenting parameters that don't exist or using +# markup commands wrongly. +# The default value is: YES. + +WARN_IF_DOC_ERROR = YES + +# This WARN_NO_PARAMDOC option can be enabled to get warnings for functions that +# are documented, but have no documentation for their parameters or return +# value. If set to NO doxygen will only warn about wrong or incomplete parameter +# documentation, but not about the absence of documentation. +# The default value is: NO. + +WARN_NO_PARAMDOC = NO + +# The WARN_FORMAT tag determines the format of the warning messages that doxygen +# can produce. The string should contain the $file, $line, and $text tags, which +# will be replaced by the file and line number from which the warning originated +# and the warning text. Optionally the format may contain $version, which will +# be replaced by the version of the file (if it could be obtained via +# FILE_VERSION_FILTER) +# The default value is: $file:$line: $text. + +WARN_FORMAT = "$file:$line: $text" + +# The WARN_LOGFILE tag can be used to specify a file to which warning and error +# messages should be written. If left blank the output is written to standard +# error (stderr). + +WARN_LOGFILE = %WARNING_LOG_PATH% + +#--------------------------------------------------------------------------- +# Configuration options related to the input files +#--------------------------------------------------------------------------- + +# The INPUT tag is used to specify the files and/or directories that contain +# documented source files. You may enter file names like myfile.cpp or +# directories like /usr/src/myproject. Separate the files or directories with +# spaces. +# Note: If this tag is empty the current directory is searched. + +INPUT = ../include \ + ../src/lib_json \ + . + +# This tag can be used to specify the character encoding of the source files +# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses +# libiconv (or the iconv built into libc) for the transcoding. See the libiconv +# documentation (see: http://www.gnu.org/software/libiconv) for the list of +# possible encodings. +# The default value is: UTF-8. + +INPUT_ENCODING = UTF-8 + +# If the value of the INPUT tag contains directories, you can use the +# FILE_PATTERNS tag to specify one or more wildcard patterns (like *.cpp and +# *.h) to filter out the source-files in the directories. If left blank the +# following patterns are tested:*.c, *.cc, *.cxx, *.cpp, *.c++, *.java, *.ii, +# *.ixx, *.ipp, *.i++, *.inl, *.idl, *.ddl, *.odl, *.h, *.hh, *.hxx, *.hpp, +# *.h++, *.cs, *.d, *.php, *.php4, *.php5, *.phtml, *.inc, *.m, *.markdown, +# *.md, *.mm, *.dox, *.py, *.f90, *.f, *.for, *.tcl, *.vhd, *.vhdl, *.ucf, +# *.qsf, *.as and *.js. + +FILE_PATTERNS = *.h \ + *.cpp \ + *.inl \ + *.dox + +# The RECURSIVE tag can be used to specify whether or not subdirectories should +# be searched for input files as well. +# The default value is: NO. + +RECURSIVE = YES + +# The EXCLUDE tag can be used to specify files and/or directories that should be +# excluded from the INPUT source files. This way you can easily exclude a +# subdirectory from a directory tree whose root is specified with the INPUT tag. +# +# Note that relative paths are relative to the directory from which doxygen is +# run. + +EXCLUDE = + +# The EXCLUDE_SYMLINKS tag can be used to select whether or not files or +# directories that are symbolic links (a Unix file system feature) are excluded +# from the input. +# The default value is: NO. + +EXCLUDE_SYMLINKS = NO + +# If the value of the INPUT tag contains directories, you can use the +# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude +# certain files from those directories. +# +# Note that the wildcards are matched against the file with absolute path, so to +# exclude all test directories for example use the pattern */test/* + +EXCLUDE_PATTERNS = + +# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names +# (namespaces, classes, functions, etc.) that should be excluded from the +# output. The symbol name can be a fully qualified name, a word, or if the +# wildcard * is used, a substring. Examples: ANamespace, AClass, +# AClass::ANamespace, ANamespace::*Test +# +# Note that the wildcards are matched against the file with absolute path, so to +# exclude all test directories use the pattern */test/* + +EXCLUDE_SYMBOLS = + +# The EXAMPLE_PATH tag can be used to specify one or more files or directories +# that contain example code fragments that are included (see the \include +# command). + +EXAMPLE_PATH = .. + +# If the value of the EXAMPLE_PATH tag contains directories, you can use the +# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp and +# *.h) to filter out the source-files in the directories. If left blank all +# files are included. + +EXAMPLE_PATTERNS = * + +# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be +# searched for input files to be used with the \include or \dontinclude commands +# irrespective of the value of the RECURSIVE tag. +# The default value is: NO. + +EXAMPLE_RECURSIVE = NO + +# The IMAGE_PATH tag can be used to specify one or more files or directories +# that contain images that are to be included in the documentation (see the +# \image command). + +IMAGE_PATH = + +# The INPUT_FILTER tag can be used to specify a program that doxygen should +# invoke to filter for each input file. Doxygen will invoke the filter program +# by executing (via popen()) the command: +# +# +# +# where is the value of the INPUT_FILTER tag, and is the +# name of an input file. Doxygen will then use the output that the filter +# program writes to standard output. If FILTER_PATTERNS is specified, this tag +# will be ignored. +# +# Note that the filter must not add or remove lines; it is applied before the +# code is scanned, but not when the output code is generated. If lines are added +# or removed, the anchors will not be placed correctly. + +INPUT_FILTER = + +# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern +# basis. Doxygen will compare the file name with each pattern and apply the +# filter if there is a match. The filters are a list of the form: pattern=filter +# (like *.cpp=my_cpp_filter). See INPUT_FILTER for further information on how +# filters are used. If the FILTER_PATTERNS tag is empty or if none of the +# patterns match the file name, INPUT_FILTER is applied. + +FILTER_PATTERNS = + +# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using +# INPUT_FILTER ) will also be used to filter the input files that are used for +# producing the source files to browse (i.e. when SOURCE_BROWSER is set to YES). +# The default value is: NO. + +FILTER_SOURCE_FILES = NO + +# The FILTER_SOURCE_PATTERNS tag can be used to specify source filters per file +# pattern. A pattern will override the setting for FILTER_PATTERN (if any) and +# it is also possible to disable source filtering for a specific pattern using +# *.ext= (so without naming a filter). +# This tag requires that the tag FILTER_SOURCE_FILES is set to YES. + +FILTER_SOURCE_PATTERNS = + +# If the USE_MDFILE_AS_MAINPAGE tag refers to the name of a markdown file that +# is part of the input, its contents will be placed on the main page +# (index.html). This can be useful if you have a project on for instance GitHub +# and want to reuse the introduction page also for the doxygen output. + +USE_MDFILE_AS_MAINPAGE = + +#--------------------------------------------------------------------------- +# Configuration options related to source browsing +#--------------------------------------------------------------------------- + +# If the SOURCE_BROWSER tag is set to YES then a list of source files will be +# generated. Documented entities will be cross-referenced with these sources. +# +# Note: To get rid of all source code in the generated output, make sure that +# also VERBATIM_HEADERS is set to NO. +# The default value is: NO. + +SOURCE_BROWSER = YES + +# Setting the INLINE_SOURCES tag to YES will include the body of functions, +# classes and enums directly into the documentation. +# The default value is: NO. + +INLINE_SOURCES = NO + +# Setting the STRIP_CODE_COMMENTS tag to YES will instruct doxygen to hide any +# special comment blocks from generated source code fragments. Normal C, C++ and +# Fortran comments will always remain visible. +# The default value is: YES. + +STRIP_CODE_COMMENTS = YES + +# If the REFERENCED_BY_RELATION tag is set to YES then for each documented +# function all documented functions referencing it will be listed. +# The default value is: NO. + +REFERENCED_BY_RELATION = YES + +# If the REFERENCES_RELATION tag is set to YES then for each documented function +# all documented entities called/used by that function will be listed. +# The default value is: NO. + +REFERENCES_RELATION = YES + +# If the REFERENCES_LINK_SOURCE tag is set to YES and SOURCE_BROWSER tag is set +# to YES, then the hyperlinks from functions in REFERENCES_RELATION and +# REFERENCED_BY_RELATION lists will link to the source code. Otherwise they will +# link to the documentation. +# The default value is: YES. + +REFERENCES_LINK_SOURCE = YES + +# If SOURCE_TOOLTIPS is enabled (the default) then hovering a hyperlink in the +# source code will show a tooltip with additional information such as prototype, +# brief description and links to the definition and documentation. Since this +# will make the HTML file larger and loading of large files a bit slower, you +# can opt to disable this feature. +# The default value is: YES. +# This tag requires that the tag SOURCE_BROWSER is set to YES. + +SOURCE_TOOLTIPS = YES + +# If the USE_HTAGS tag is set to YES then the references to source code will +# point to the HTML generated by the htags(1) tool instead of doxygen built-in +# source browser. The htags tool is part of GNU's global source tagging system +# (see http://www.gnu.org/software/global/global.html). You will need version +# 4.8.6 or higher. +# +# To use it do the following: +# - Install the latest version of global +# - Enable SOURCE_BROWSER and USE_HTAGS in the config file +# - Make sure the INPUT points to the root of the source tree +# - Run doxygen as normal +# +# Doxygen will invoke htags (and that will in turn invoke gtags), so these +# tools must be available from the command line (i.e. in the search path). +# +# The result: instead of the source browser generated by doxygen, the links to +# source code will now point to the output of htags. +# The default value is: NO. +# This tag requires that the tag SOURCE_BROWSER is set to YES. + +USE_HTAGS = NO + +# If the VERBATIM_HEADERS tag is set the YES then doxygen will generate a +# verbatim copy of the header file for each class for which an include is +# specified. Set to NO to disable this. +# See also: Section \class. +# The default value is: YES. + +VERBATIM_HEADERS = YES + +#--------------------------------------------------------------------------- +# Configuration options related to the alphabetical class index +#--------------------------------------------------------------------------- + +# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index of all +# compounds will be generated. Enable this if the project contains a lot of +# classes, structs, unions or interfaces. +# The default value is: YES. + +ALPHABETICAL_INDEX = YES +TOC_INCLUDE_HEADINGS = 2 + +# The COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns in +# which the alphabetical index list will be split. +# Minimum value: 1, maximum value: 20, default value: 5. +# This tag requires that the tag ALPHABETICAL_INDEX is set to YES. + +COLS_IN_ALPHA_INDEX = 5 + +# In case all classes in a project start with a common prefix, all classes will +# be put under the same header in the alphabetical index. The IGNORE_PREFIX tag +# can be used to specify a prefix (or a list of prefixes) that should be ignored +# while generating the index headers. +# This tag requires that the tag ALPHABETICAL_INDEX is set to YES. + +IGNORE_PREFIX = + +#--------------------------------------------------------------------------- +# Configuration options related to the HTML output +#--------------------------------------------------------------------------- + +# If the GENERATE_HTML tag is set to YES doxygen will generate HTML output +# The default value is: YES. + +GENERATE_HTML = YES + +# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. If a +# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of +# it. +# The default directory is: html. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_OUTPUT = %HTML_OUTPUT% + +# The HTML_FILE_EXTENSION tag can be used to specify the file extension for each +# generated HTML page (for example: .htm, .php, .asp). +# The default value is: .html. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_FILE_EXTENSION = .html + +# The HTML_HEADER tag can be used to specify a user-defined HTML header file for +# each generated HTML page. If the tag is left blank doxygen will generate a +# standard header. +# +# To get valid HTML the header file that includes any scripts and style sheets +# that doxygen needs, which is dependent on the configuration options used (e.g. +# the setting GENERATE_TREEVIEW). It is highly recommended to start with a +# default header using +# doxygen -w html new_header.html new_footer.html new_stylesheet.css +# YourConfigFile +# and then modify the file new_header.html. See also section "Doxygen usage" +# for information on how to generate the default header that doxygen normally +# uses. +# Note: The header is subject to change so you typically have to regenerate the +# default header when upgrading to a newer version of doxygen. For a description +# of the possible markers and block names see the documentation. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_HEADER = header.html + +# The HTML_FOOTER tag can be used to specify a user-defined HTML footer for each +# generated HTML page. If the tag is left blank doxygen will generate a standard +# footer. See HTML_HEADER for more information on how to generate a default +# footer and what special commands can be used inside the footer. See also +# section "Doxygen usage" for information on how to generate the default footer +# that doxygen normally uses. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_FOOTER = footer.html + +# The HTML_STYLESHEET tag can be used to specify a user-defined cascading style +# sheet that is used by each HTML page. It can be used to fine-tune the look of +# the HTML output. If left blank doxygen will generate a default style sheet. +# See also section "Doxygen usage" for information on how to generate the style +# sheet that doxygen normally uses. +# Note: It is recommended to use HTML_EXTRA_STYLESHEET instead of this tag, as +# it is more robust and this tag (HTML_STYLESHEET) will in the future become +# obsolete. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_STYLESHEET = + +# The HTML_EXTRA_STYLESHEET tag can be used to specify an additional user- +# defined cascading style sheet that is included after the standard style sheets +# created by doxygen. Using this option one can overrule certain style aspects. +# This is preferred over using HTML_STYLESHEET since it does not replace the +# standard style sheet and is therefore more robust against future updates. +# Doxygen will copy the style sheet file to the output directory. For an example +# see the documentation. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_EXTRA_STYLESHEET = + +# The HTML_EXTRA_FILES tag can be used to specify one or more extra images or +# other source files which should be copied to the HTML output directory. Note +# that these files will be copied to the base HTML output directory. Use the +# $relpath^ marker in the HTML_HEADER and/or HTML_FOOTER files to load these +# files. In the HTML_STYLESHEET file, use the file name only. Also note that the +# files will be copied as-is; there are no commands or markers available. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_EXTRA_FILES = + +# The HTML_COLORSTYLE_HUE tag controls the color of the HTML output. Doxygen +# will adjust the colors in the stylesheet and background images according to +# this color. Hue is specified as an angle on a colorwheel, see +# http://en.wikipedia.org/wiki/Hue for more information. For instance the value +# 0 represents red, 60 is yellow, 120 is green, 180 is cyan, 240 is blue, 300 +# purple, and 360 is red again. +# Minimum value: 0, maximum value: 359, default value: 220. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_COLORSTYLE_HUE = 220 + +# The HTML_COLORSTYLE_SAT tag controls the purity (or saturation) of the colors +# in the HTML output. For a value of 0 the output will use grayscales only. A +# value of 255 will produce the most vivid colors. +# Minimum value: 0, maximum value: 255, default value: 100. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_COLORSTYLE_SAT = 100 + +# The HTML_COLORSTYLE_GAMMA tag controls the gamma correction applied to the +# luminance component of the colors in the HTML output. Values below 100 +# gradually make the output lighter, whereas values above 100 make the output +# darker. The value divided by 100 is the actual gamma applied, so 80 represents +# a gamma of 0.8, The value 220 represents a gamma of 2.2, and 100 does not +# change the gamma. +# Minimum value: 40, maximum value: 240, default value: 80. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_COLORSTYLE_GAMMA = 80 + +# If the HTML_TIMESTAMP tag is set to YES then the footer of each generated HTML +# page will contain the date and time when the page was generated. Setting this +# to NO can help when comparing the output of multiple runs. +# The default value is: YES. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_TIMESTAMP = YES + +# If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML +# documentation will contain sections that can be hidden and shown after the +# page has loaded. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_DYNAMIC_SECTIONS = YES + +# With HTML_INDEX_NUM_ENTRIES one can control the preferred number of entries +# shown in the various tree structured indices initially; the user can expand +# and collapse entries dynamically later on. Doxygen will expand the tree to +# such a level that at most the specified number of entries are visible (unless +# a fully collapsed tree already exceeds this amount). So setting the number of +# entries 1 will produce a full collapsed tree by default. 0 is a special value +# representing an infinite number of entries and will result in a full expanded +# tree by default. +# Minimum value: 0, maximum value: 9999, default value: 100. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_INDEX_NUM_ENTRIES = 100 + +# If the GENERATE_DOCSET tag is set to YES, additional index files will be +# generated that can be used as input for Apple's Xcode 3 integrated development +# environment (see: http://developer.apple.com/tools/xcode/), introduced with +# OSX 10.5 (Leopard). To create a documentation set, doxygen will generate a +# Makefile in the HTML output directory. Running make will produce the docset in +# that directory and running make install will install the docset in +# ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find it at +# startup. See http://developer.apple.com/tools/creatingdocsetswithdoxygen.html +# for more information. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +GENERATE_DOCSET = NO + +# This tag determines the name of the docset feed. A documentation feed provides +# an umbrella under which multiple documentation sets from a single provider +# (such as a company or product suite) can be grouped. +# The default value is: Doxygen generated docs. +# This tag requires that the tag GENERATE_DOCSET is set to YES. + +DOCSET_FEEDNAME = "Doxygen generated docs" + +# This tag specifies a string that should uniquely identify the documentation +# set bundle. This should be a reverse domain-name style string, e.g. +# com.mycompany.MyDocSet. Doxygen will append .docset to the name. +# The default value is: org.doxygen.Project. +# This tag requires that the tag GENERATE_DOCSET is set to YES. + +DOCSET_BUNDLE_ID = org.doxygen.Project + +# The DOCSET_PUBLISHER_ID tag specifies a string that should uniquely identify +# the documentation publisher. This should be a reverse domain-name style +# string, e.g. com.mycompany.MyDocSet.documentation. +# The default value is: org.doxygen.Publisher. +# This tag requires that the tag GENERATE_DOCSET is set to YES. + +DOCSET_PUBLISHER_ID = org.doxygen.Publisher + +# The DOCSET_PUBLISHER_NAME tag identifies the documentation publisher. +# The default value is: Publisher. +# This tag requires that the tag GENERATE_DOCSET is set to YES. + +DOCSET_PUBLISHER_NAME = Publisher + +# If the GENERATE_HTMLHELP tag is set to YES then doxygen generates three +# additional HTML index files: index.hhp, index.hhc, and index.hhk. The +# index.hhp is a project file that can be read by Microsoft's HTML Help Workshop +# (see: http://www.microsoft.com/en-us/download/details.aspx?id=21138) on +# Windows. +# +# The HTML Help Workshop contains a compiler that can convert all HTML output +# generated by doxygen into a single compiled HTML file (.chm). Compiled HTML +# files are now used as the Windows 98 help format, and will replace the old +# Windows help format (.hlp) on all Windows platforms in the future. Compressed +# HTML files also contain an index, a table of contents, and you can search for +# words in the documentation. The HTML workshop also contains a viewer for +# compressed HTML files. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +GENERATE_HTMLHELP = %HTML_HELP% + +# The CHM_FILE tag can be used to specify the file name of the resulting .chm +# file. You can add a path in front of the file if the result should not be +# written to the html output directory. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. + +CHM_FILE = jsoncpp-%JSONCPP_VERSION%.chm + +# The HHC_LOCATION tag can be used to specify the location (absolute path +# including file name) of the HTML help compiler ( hhc.exe). If non-empty +# doxygen will try to run the HTML help compiler on the generated index.hhp. +# The file has to be specified with full path. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. + +HHC_LOCATION = "c:\Program Files\HTML Help Workshop\hhc.exe" + +# The GENERATE_CHI flag controls if a separate .chi index file is generated ( +# YES) or that it should be included in the master .chm file ( NO). +# The default value is: NO. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. + +GENERATE_CHI = YES + +# The CHM_INDEX_ENCODING is used to encode HtmlHelp index ( hhk), content ( hhc) +# and project file content. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. + +CHM_INDEX_ENCODING = + +# The BINARY_TOC flag controls whether a binary table of contents is generated ( +# YES) or a normal table of contents ( NO) in the .chm file. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. + +BINARY_TOC = YES + +# The TOC_EXPAND flag can be set to YES to add extra items for group members to +# the table of contents of the HTML help documentation and to the tree view. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. + +TOC_EXPAND = YES + +# If the GENERATE_QHP tag is set to YES and both QHP_NAMESPACE and +# QHP_VIRTUAL_FOLDER are set, an additional index file will be generated that +# can be used as input for Qt's qhelpgenerator to generate a Qt Compressed Help +# (.qch) of the generated HTML documentation. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +GENERATE_QHP = NO + +# If the QHG_LOCATION tag is specified, the QCH_FILE tag can be used to specify +# the file name of the resulting .qch file. The path specified is relative to +# the HTML output folder. +# This tag requires that the tag GENERATE_QHP is set to YES. + +QCH_FILE = + +# The QHP_NAMESPACE tag specifies the namespace to use when generating Qt Help +# Project output. For more information please see Qt Help Project / Namespace +# (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#namespace). +# The default value is: org.doxygen.Project. +# This tag requires that the tag GENERATE_QHP is set to YES. + +QHP_NAMESPACE = + +# The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating Qt +# Help Project output. For more information please see Qt Help Project / Virtual +# Folders (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#virtual- +# folders). +# The default value is: doc. +# This tag requires that the tag GENERATE_QHP is set to YES. + +QHP_VIRTUAL_FOLDER = doc + +# If the QHP_CUST_FILTER_NAME tag is set, it specifies the name of a custom +# filter to add. For more information please see Qt Help Project / Custom +# Filters (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#custom- +# filters). +# This tag requires that the tag GENERATE_QHP is set to YES. + +QHP_CUST_FILTER_NAME = + +# The QHP_CUST_FILTER_ATTRS tag specifies the list of the attributes of the +# custom filter to add. For more information please see Qt Help Project / Custom +# Filters (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#custom- +# filters). +# This tag requires that the tag GENERATE_QHP is set to YES. + +QHP_CUST_FILTER_ATTRS = + +# The QHP_SECT_FILTER_ATTRS tag specifies the list of the attributes this +# project's filter section matches. Qt Help Project / Filter Attributes (see: +# http://qt-project.org/doc/qt-4.8/qthelpproject.html#filter-attributes). +# This tag requires that the tag GENERATE_QHP is set to YES. + +QHP_SECT_FILTER_ATTRS = + +# The QHG_LOCATION tag can be used to specify the location of Qt's +# qhelpgenerator. If non-empty doxygen will try to run qhelpgenerator on the +# generated .qhp file. +# This tag requires that the tag GENERATE_QHP is set to YES. + +QHG_LOCATION = + +# If the GENERATE_ECLIPSEHELP tag is set to YES, additional index files will be +# generated, together with the HTML files, they form an Eclipse help plugin. To +# install this plugin and make it available under the help contents menu in +# Eclipse, the contents of the directory containing the HTML and XML files needs +# to be copied into the plugins directory of eclipse. The name of the directory +# within the plugins directory should be the same as the ECLIPSE_DOC_ID value. +# After copying Eclipse needs to be restarted before the help appears. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +GENERATE_ECLIPSEHELP = NO + +# A unique identifier for the Eclipse help plugin. When installing the plugin +# the directory name containing the HTML and XML files should also have this +# name. Each documentation set should have its own identifier. +# The default value is: org.doxygen.Project. +# This tag requires that the tag GENERATE_ECLIPSEHELP is set to YES. + +ECLIPSE_DOC_ID = org.doxygen.Project + +# If you want full control over the layout of the generated HTML pages it might +# be necessary to disable the index and replace it with your own. The +# DISABLE_INDEX tag can be used to turn on/off the condensed index (tabs) at top +# of each HTML page. A value of NO enables the index and the value YES disables +# it. Since the tabs in the index contain the same information as the navigation +# tree, you can set this option to YES if you also set GENERATE_TREEVIEW to YES. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +DISABLE_INDEX = NO + +# The GENERATE_TREEVIEW tag is used to specify whether a tree-like index +# structure should be generated to display hierarchical information. If the tag +# value is set to YES, a side panel will be generated containing a tree-like +# index structure (just like the one that is generated for HTML Help). For this +# to work a browser that supports JavaScript, DHTML, CSS and frames is required +# (i.e. any modern browser). Windows users are probably better off using the +# HTML help feature. Via custom stylesheets (see HTML_EXTRA_STYLESHEET) one can +# further fine-tune the look of the index. As an example, the default style +# sheet generated by doxygen has an example that shows how to put an image at +# the root of the tree instead of the PROJECT_NAME. Since the tree basically has +# the same information as the tab index, you could consider setting +# DISABLE_INDEX to YES when enabling this option. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +GENERATE_TREEVIEW = NO + +# The ENUM_VALUES_PER_LINE tag can be used to set the number of enum values that +# doxygen will group on one line in the generated HTML documentation. +# +# Note that a value of 0 will completely suppress the enum values from appearing +# in the overview section. +# Minimum value: 0, maximum value: 20, default value: 4. +# This tag requires that the tag GENERATE_HTML is set to YES. + +ENUM_VALUES_PER_LINE = 4 + +# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be used +# to set the initial width (in pixels) of the frame in which the tree is shown. +# Minimum value: 0, maximum value: 1500, default value: 250. +# This tag requires that the tag GENERATE_HTML is set to YES. + +TREEVIEW_WIDTH = 250 + +# When the EXT_LINKS_IN_WINDOW option is set to YES doxygen will open links to +# external symbols imported via tag files in a separate window. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +EXT_LINKS_IN_WINDOW = NO + +# Use this tag to change the font size of LaTeX formulas included as images in +# the HTML documentation. When you change the font size after a successful +# doxygen run you need to manually remove any form_*.png images from the HTML +# output directory to force them to be regenerated. +# Minimum value: 8, maximum value: 50, default value: 10. +# This tag requires that the tag GENERATE_HTML is set to YES. + +FORMULA_FONTSIZE = 10 + +# Use the FORMULA_TRANPARENT tag to determine whether or not the images +# generated for formulas are transparent PNGs. Transparent PNGs are not +# supported properly for IE 6.0, but are supported on all modern browsers. +# +# Note that when changing this option you need to delete any form_*.png files in +# the HTML output directory before the changes have effect. +# The default value is: YES. +# This tag requires that the tag GENERATE_HTML is set to YES. + +FORMULA_TRANSPARENT = YES + +# Enable the USE_MATHJAX option to render LaTeX formulas using MathJax (see +# http://www.mathjax.org) which uses client side JavaScript for the rendering +# instead of using prerendered bitmaps. Use this if you do not have LaTeX +# installed or if you want to formulas look prettier in the HTML output. When +# enabled you may also need to install MathJax separately and configure the path +# to it using the MATHJAX_RELPATH option. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +USE_MATHJAX = NO + +# When MathJax is enabled you can set the default output format to be used for +# the MathJax output. See the MathJax site (see: +# http://docs.mathjax.org/en/latest/output.html) for more details. +# Possible values are: HTML-CSS (which is slower, but has the best +# compatibility), NativeMML (i.e. MathML) and SVG. +# The default value is: HTML-CSS. +# This tag requires that the tag USE_MATHJAX is set to YES. + +MATHJAX_FORMAT = HTML-CSS + +# When MathJax is enabled you need to specify the location relative to the HTML +# output directory using the MATHJAX_RELPATH option. The destination directory +# should contain the MathJax.js script. For instance, if the mathjax directory +# is located at the same level as the HTML output directory, then +# MATHJAX_RELPATH should be ../mathjax. The default value points to the MathJax +# Content Delivery Network so you can quickly see the result without installing +# MathJax. However, it is strongly recommended to install a local copy of +# MathJax from http://www.mathjax.org before deployment. +# The default value is: http://cdn.mathjax.org/mathjax/latest. +# This tag requires that the tag USE_MATHJAX is set to YES. + +MATHJAX_RELPATH = http://cdn.mathjax.org/mathjax/latest + +# The MATHJAX_EXTENSIONS tag can be used to specify one or more MathJax +# extension names that should be enabled during MathJax rendering. For example +# MATHJAX_EXTENSIONS = TeX/AMSmath TeX/AMSsymbols +# This tag requires that the tag USE_MATHJAX is set to YES. + +MATHJAX_EXTENSIONS = + +# The MATHJAX_CODEFILE tag can be used to specify a file with javascript pieces +# of code that will be used on startup of the MathJax code. See the MathJax site +# (see: http://docs.mathjax.org/en/latest/output.html) for more details. For an +# example see the documentation. +# This tag requires that the tag USE_MATHJAX is set to YES. + +MATHJAX_CODEFILE = + +# When the SEARCHENGINE tag is enabled doxygen will generate a search box for +# the HTML output. The underlying search engine uses javascript and DHTML and +# should work on any modern browser. Note that when using HTML help +# (GENERATE_HTMLHELP), Qt help (GENERATE_QHP), or docsets (GENERATE_DOCSET) +# there is already a search function so this one should typically be disabled. +# For large projects the javascript based search engine can be slow, then +# enabling SERVER_BASED_SEARCH may provide a better solution. It is possible to +# search using the keyboard; to jump to the search box use + S +# (what the is depends on the OS and browser, but it is typically +# , /