27 void Amd64::ValidateStackSize(
const size_t size) {
28 if(!size)
throw std::runtime_error(
"Size may not be nil");
29 if(size %
kStackAlignment)
throw std::runtime_error(
"Stack is misaligned");
42 void* Amd64::AllocStack(
const size_t bytes) {
48 throw std::runtime_error(
"posix_memalign() failed");
61 void Amd64::DeallocStack(
void* stack) {
80 void Amd64::Prepare(
Amd64 *wrap,
const Entry &entry) {
81 static_assert(offsetof(
Amd64, stackTop) == COTHREAD_OFF_CONTEXT_TOP,
"cothread stack top is invalid");
84 auto info =
new CallInfo{entry};
85 if(!info)
throw std::runtime_error(
"Failed to allocate call info");
89 auto &stackBuf = wrap->
stack;
90 auto stackFrame =
reinterpret_cast<std::byte *
>(stackBuf.data());
91 stackFrame += ((stackBuf.size()*
sizeof(typeof(*stackBuf.data()))) & ~(0x10-1))
93 auto stack =
reinterpret_cast<uintptr_t *
>(stackFrame);
96 *--
stack =
reinterpret_cast<uintptr_t
>(&Amd64::EntryReturnedStub);
99 *--
stack =
reinterpret_cast<uintptr_t
>(info);
100 *--
stack =
reinterpret_cast<uintptr_t
>(&Amd64::DereferenceCallInfo);
101 *--
stack =
reinterpret_cast<uintptr_t
>(&Amd64::JumpToEntry);
110 wrap->stackTop =
stack;
Architecture specific methods for working with cothreads on amd64 based systems.
static const size_t kNumSavedRegisters
static constexpr const size_t kStackAlignment
Implementation details (including architecture/platform specific code) for the library.
Main namespace for the libcommunism library.
std::span< uintptr_t > stack
Stack used by this cothread, if any.