libcommunism
Userspace cooperative threading library
|
Architecture specific methods for working with cothreads on amd64 based systems. More...
#include <Common.h>
Public Member Functions | |
Amd64 (const Entry &entry, const size_t stackSize=0) | |
Amd64 (const Entry &entry, std::span< uintptr_t > stack) | |
Amd64 (std::span< uintptr_t > stack) | |
~Amd64 () | |
void | switchTo (CothreadImpl *from) override |
Public Member Functions inherited from libcommunism::CothreadImpl | |
CothreadImpl (const Cothread::Entry &entry, const size_t stackSize=0) | |
CothreadImpl (const Cothread::Entry &entry, std::span< uintptr_t > stack) | |
CothreadImpl (std::span< uintptr_t > stack) | |
virtual | ~CothreadImpl ()=default |
virtual size_t | getStackSize () const |
virtual void * | getStack () const |
Static Public Attributes | |
static const size_t | kNumSavedRegisters {6} |
static constexpr const size_t | kMainStackSize {64} |
static constexpr const size_t | kStackAlignment {64} |
static constexpr const size_t | kDefaultStackSize {0x80000} |
Friends | |
CothreadImpl * | libcommunism::AllocKernelThreadWrapper () |
Additional Inherited Members | |
Public Types inherited from libcommunism::CothreadImpl | |
using | Entry = Cothread::Entry |
Protected Attributes inherited from libcommunism::CothreadImpl | |
std::span< uintptr_t > | stack |
Stack used by this cothread, if any. More... | |
Architecture specific methods for working with cothreads on amd64 based systems.
Amd64::Amd64 | ( | const Entry & | entry, |
const size_t | stackSize = 0 |
||
) |
Allocates an amd64 thread, allocating its stack.
entry | Method to execute on entry to this cothread |
stackSize | Size of the stack to be allocated, in bytes. it should be a multiple of the machine word size, or specify zero to use the platform default. |
std::runtime_error | If the memory for the cothread could not be allocated. |
std::runtime_error | If the provided stack size is invalid |
Definition at line 32 of file Common.cpp.
Amd64::Amd64 | ( | const Entry & | entry, |
std::span< uintptr_t > | _stack | ||
) |
Allocates and amd64 cothread with an already provided stack.
entry | Method to execute on entry to this cothread |
stack | Buffer to use as the stack of the cothread |
std::runtime_error | If the provided stack is invalid |
Definition at line 56 of file Common.cpp.
|
inline |
Amd64::~Amd64 | ( | ) |
Release the stack if we allocated it.
Definition at line 64 of file Common.cpp.
|
overridevirtual |
Performs a context switch to the provided cothread.
The state of the caller is stored on the stack of the currently active thread.
Implements libcommunism::CothreadImpl.
Definition at line 75 of file Common.cpp.
|
friend |
|
staticconstexpr |
|
staticconstexpr |
Size of the stack buffer for the "fake" initial cothread, in machine words. This only needs to be large enough to fit the register stack frame. This must be a power of two.
It must be sufficiently large to store the callee-saved general purpose registers, as well as all of the SSE registers on Windows.
|
static |
Number of registers saved by the cothread swap code. This is used to correctly build the stack frames during initialization.
For System V ABI, the only saved registers are rbp, rbx, and r12-r15.
On Windows, we have to save integer registers RBX, RBP, RDI, RSI, and R12-R15. In addition, XMM6-XMM15 must be saved. Since the SSE registers are 128 bits vs. 64 bits for an integer register, we just count them twice.
|
staticconstexpr |