1 #ifndef COROUTINE_AMD64_CONTEXT_H
2 #define COROUTINE_AMD64_CONTEXT_H 1
18 #define COROUTINE __attribute__((noreturn)) void
20 enum {COROUTINE_REGISTERS = 6};
22 #if defined(__SANITIZE_ADDRESS__)
23 #define COROUTINE_SANITIZE_ADDRESS
24 #elif defined(__has_feature)
25 #if __has_feature(address_sanitizer)
26 #define COROUTINE_SANITIZE_ADDRESS
30 #if defined(COROUTINE_SANITIZE_ADDRESS)
31 #include <sanitizer/common_interface_defs.h>
32 #include <sanitizer/asan_interface.h>
40 #if defined(COROUTINE_SANITIZE_ADDRESS)
49 static inline void coroutine_initialize_main(
struct coroutine_context * context) {
50 context->stack_pointer = NULL;
53 static inline void coroutine_initialize(
55 coroutine_start start,
59 assert(start && stack && size >= 1024);
61 #if defined(COROUTINE_SANITIZE_ADDRESS)
62 context->fake_stack = NULL;
63 context->stack_base = stack;
64 context->stack_size = size;
68 char * top = (
char*)stack + size;
69 context->stack_pointer = (
void**)((uintptr_t)top & ~0xF);
71 *--context->stack_pointer = NULL;
72 *--context->stack_pointer = (
void*)(uintptr_t)start;
74 context->stack_pointer -= COROUTINE_REGISTERS;
75 memset(context->stack_pointer, 0,
sizeof(
void*) * COROUTINE_REGISTERS);
82 context->stack_pointer = NULL;