summaryrefslogtreecommitdiffstats
path: root/library/fibers/initializestack_64_linux_mac.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'library/fibers/initializestack_64_linux_mac.cpp')
-rw-r--r--library/fibers/initializestack_64_linux_mac.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/library/fibers/initializestack_64_linux_mac.cpp b/library/fibers/initializestack_64_linux_mac.cpp
new file mode 100644
index 0000000..5465dfb
--- /dev/null
+++ b/library/fibers/initializestack_64_linux_mac.cpp
@@ -0,0 +1,22 @@
+#include <stdlib.h>
+
+void initializeStack(void *data, int size, void (*entry)(), void **stackPointer)
+{
+ void* stackBottom = (char*)data + size;
+ // align to 16 byte
+ stackBottom = (void*)((size_t)stackBottom & ~0xF);
+
+ void **p = (void**)stackBottom;
+
+ *(--p) = 0; // align
+ *(--p) = (void*)entry; // rip
+ *(--p) = stackBottom; // rbp
+ *(--p) = 0; // rbx
+ *(--p) = 0; // r12
+ *(--p) = 0; // r13
+ *(--p) = 0; // r14
+ *(--p) = 0; // r15
+ *(--p) = (void*)0x00001f800000033f; // SIMD and regular floating point control defaults
+
+ *stackPointer = p;
+}