libcommunism
Userspace cooperative threading library
Common.h
Go to the documentation of this file.
1 #ifndef ARCH_AARCH64_COMMON_H
2 #define ARCH_AARCH64_COMMON_H
3 
4 #include "CothreadPrivate.h"
5 #include "CothreadImpl.h"
6 
7 #include <array>
8 #include <cstddef>
9 #include <cstdint>
10 
18 class Aarch64 final: public CothreadImpl {
20 
24  struct CallInfo {
26  Cothread::Entry entry;
27  };
28 
29  public:
30  Aarch64(const Entry &entry, const size_t stackSize = 0);
31  Aarch64(const Entry &entry, std::span<uintptr_t> stack);
32  Aarch64(std::span<uintptr_t> stack);
33  ~Aarch64();
34 
35  void switchTo(CothreadImpl *from) override;
36 
37  private:
38  static void AllocMainCothread();
39  static void ValidateStackSize(const size_t size);
40  static void *AllocStack(const size_t bytes);
41  static void DeallocStack(void* stack);
42  static void CothreadReturned();
43  static void DereferenceCallInfo(CallInfo *info);
44 
52  static void Prepare(Aarch64 *thread, const Entry &entry);
53 
62  static void Switch(Aarch64 *from, Aarch64 *to);
63 
64  public:
69  static constexpr const size_t kContextSaveAreaSize{0x100};
70 
75  static constexpr const size_t kMainStackSize{(kContextSaveAreaSize * 2) / sizeof(uintptr_t)};
76 
80  static constexpr const size_t kStackAlignment{64};
81 
86  static constexpr const size_t kDefaultStackSize{0x80000};
87 
88  private:
97  static thread_local std::array<uintptr_t, kMainStackSize> gMainStack;
98 
99  private:
101  bool ownsStack{false};
102 
104  void *stackTop{nullptr};
105 };
106 }
107 
108 #endif
std::function< void()> Entry
Type alias for an entry point of a cothread.
Definition: Cothread.h:27
Architecture specific methods for working with cothreads on 64 bit ARM machines.
Definition: Common.h:18
static constexpr const size_t kMainStackSize
Definition: Common.h:75
static constexpr const size_t kDefaultStackSize
Definition: Common.h:86
static constexpr const size_t kStackAlignment
Definition: Common.h:80
static constexpr const size_t kContextSaveAreaSize
Definition: Common.h:69
Aarch64(const Entry &entry, const size_t stackSize=0)
Definition: Common.cpp:33
void switchTo(CothreadImpl *from) override
Definition: Common.cpp:85
Implementation details (including architecture/platform specific code) for the library.
Definition: Common.h:11
CothreadImpl * AllocKernelThreadWrapper()
Definition: Common.cpp:134
Abstract interface for a platform implementation of cothreads.
Definition: CothreadImpl.h:18
std::span< uintptr_t > stack
Stack used by this cothread, if any.
Definition: CothreadImpl.h:88