libcommunism
Userspace cooperative threading library
|
Architecture specific methods for working with cothreads on x86 systems. More...
#include <Common.h>
Public Member Functions | |
x86 (const Entry &entry, const size_t stackSize=0) | |
x86 (const Entry &entry, std::span< uintptr_t > stack) | |
x86 (std::span< uintptr_t > stack) | |
~x86 () | |
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 {4} |
static constexpr const size_t | kMainStackSize {64} |
static constexpr const size_t | kStackAlignment {16} |
static constexpr const size_t | kDefaultStackSize {0x40000} |
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 x86 systems.
This implementation exploits the fact that clang and GCC both support Microsoft's fastcall calling convention, so we can get away with one implementation for both System V and Windows platforms, albeit with differing assembly syntaxes.
In operation, this is identical to the Amd64 implementation; thread state is stored on the stack and the cothread's stackTop
pointer actually points to the stack pointer of the cothread when it is switched out.
x86::x86 | ( | const Entry & | entry, |
const size_t | stackSize = 0 |
||
) |
Allocate an x86 cothread instance, allocating the stack as part of this.
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 40 of file Common.cpp.
x86::x86 | ( | const Entry & | entry, |
std::span< uintptr_t > | stack | ||
) |
Allocates an x86 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 64 of file Common.cpp.
|
inline |
x86::~x86 | ( | ) |
Deallocate the stack.
Definition at line 72 of file Common.cpp.
|
overridevirtual |
Perform a context switch to this cothread.
The currently executing cothread's state is saved to its buffer, then this cothread's state is restored.
Implements libcommunism::CothreadImpl.
Definition at line 78 of file Common.cpp.
|
friend |
|
staticconstexpr |
|
staticconstexpr |
|
static |
|
staticconstexpr |