Commit 53aa72b58a

Andrew Kelley <superjoe30@gmail.com>
2017-09-30 19:39:18
add ___chkstk_ms compiler-rt function
1 parent 09369b6
Changed files (1)
std
special
compiler_rt
std/special/compiler_rt/index.zig
@@ -98,7 +98,7 @@ export nakedcc fn __aeabi_uidivmod() {
     @setGlobalLinkage(__aeabi_uidivmod, builtin.GlobalLinkage.Internal);
 }
 
-export nakedcc fn __chkstk() {
+export nakedcc fn __chkstk() align 4 {
     @setDebugSafety(this, false);
 
     if (comptime builtin.os == builtin.Os.windows) {
@@ -132,6 +132,37 @@ export nakedcc fn __chkstk() {
     @setGlobalLinkage(__chkstk, builtin.GlobalLinkage.Internal);
 }
 
+export nakedcc fn ___chkstk_ms() align 4 {
+    @setDebugSafety(this, false);
+
+    if (comptime builtin.os == builtin.Os.windows) {
+        if (comptime builtin.arch == builtin.Arch.x86_64) {
+            asm volatile (
+                \\        push   %%rcx
+                \\        push   %%rax
+                \\        cmp    $0x1000,%%rax
+                \\        lea    24(%%rsp),%%rcx
+                \\        jb     1f
+                \\2:
+                \\        sub    $0x1000,%%rcx
+                \\        test   %%rcx,(%%rcx)
+                \\        sub    $0x1000,%%rax
+                \\        cmp    $0x1000,%%rax
+                \\        ja     2b
+                \\1:
+                \\        sub    %%rax,%%rcx
+                \\        test   %%rcx,(%%rcx)
+                \\        pop    %%rax
+                \\        pop    %%rcx
+                \\        ret
+            );
+            unreachable;
+        }
+    }
+
+    @setGlobalLinkage(__chkstk, builtin.GlobalLinkage.Internal);
+}
+
 export fn __udivmodsi4(a: u32, b: u32, rem: &u32) -> u32 {
     @setDebugSafety(this, is_test);
     @setGlobalLinkage(__udivmodsi4, builtin.GlobalLinkage.LinkOnce);