| ... | ... | @@ -5,9 +5,6 @@ const arch = builtin.cpu.arch; |
| 5 | 5 | const abi = builtin.abi; |
| 6 | 6 | const is_test = builtin.is_test; |
| 7 | 7 | |
| 8 | | const is_gnu = abi.isGnu(); |
| 9 | | const is_mingw = os_tag == .windows and is_gnu; |
| 10 | | |
| 11 | 8 | const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .internal else .weak; |
| 12 | 9 | const strong_linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .internal else .strong; |
| 13 | 10 | pub const panic = @import("common.zig").panic; |
| ... | ... | @@ -15,11 +12,11 @@ pub const panic = @import("common.zig").panic; |
| 15 | 12 | comptime { |
| 16 | 13 | if (builtin.os.tag == .windows) { |
| 17 | 14 | // Default stack-probe functions emitted by LLVM |
| 18 | | if (is_mingw) { |
| 15 | if (builtin.target.isMinGW()) { |
| 19 | 16 | @export(&_chkstk, .{ .name = "_alloca", .linkage = linkage }); |
| 20 | 17 | @export(&___chkstk_ms, .{ .name = "___chkstk_ms", .linkage = linkage }); |
| 21 | 18 | |
| 22 | | if (arch.isAARCH64()) { |
| 19 | if (arch == .thumb or arch == .aarch64) { |
| 23 | 20 | @export(&__chkstk, .{ .name = "__chkstk", .linkage = linkage }); |
| 24 | 21 | } |
| 25 | 22 | } else if (!builtin.link_libc) { |
| ... | ... | @@ -100,6 +97,35 @@ fn win_probe_stack_only() void { |
| 100 | 97 | @setRuntimeSafety(false); |
| 101 | 98 | |
| 102 | 99 | switch (arch) { |
| 100 | .thumb => { |
| 101 | asm volatile ( |
| 102 | \\ lsl r4, r4, #2 |
| 103 | \\ mov r12, sp |
| 104 | \\ push {r5, r6} |
| 105 | \\ mov r5, r4 |
| 106 | \\1: |
| 107 | \\ sub r12, r12, #4096 |
| 108 | \\ subs r5, r5, #4096 |
| 109 | \\ ldr r6, [r12] |
| 110 | \\ bgt 1b |
| 111 | \\ pop {r5, r6} |
| 112 | \\ bx lr |
| 113 | ); |
| 114 | }, |
| 115 | .aarch64 => { |
| 116 | asm volatile ( |
| 117 | \\ lsl x16, x15, #4 |
| 118 | \\ mov x17, sp |
| 119 | \\1: |
| 120 | \\ |
| 121 | \\ sub x17, x17, 4096 |
| 122 | \\ subs x16, x16, 4096 |
| 123 | \\ ldr xzr, [x17] |
| 124 | \\ b.gt 1b |
| 125 | \\ |
| 126 | \\ ret |
| 127 | ); |
| 128 | }, |
| 103 | 129 | .x86_64 => { |
| 104 | 130 | asm volatile ( |
| 105 | 131 | \\ push %%rcx |
| ... | ... | @@ -144,21 +170,6 @@ fn win_probe_stack_only() void { |
| 144 | 170 | }, |
| 145 | 171 | else => {}, |
| 146 | 172 | } |
| 147 | | if (comptime arch.isAARCH64()) { |
| 148 | | // NOTE: page size hardcoded to 4096 for now |
| 149 | | asm volatile ( |
| 150 | | \\ lsl x16, x15, #4 |
| 151 | | \\ mov x17, sp |
| 152 | | \\1: |
| 153 | | \\ |
| 154 | | \\ sub x17, x17, 4096 |
| 155 | | \\ subs x16, x16, 4096 |
| 156 | | \\ ldr xzr, [x17] |
| 157 | | \\ b.gt 1b |
| 158 | | \\ |
| 159 | | \\ ret |
| 160 | | ); |
| 161 | | } |
| 162 | 173 | |
| 163 | 174 | unreachable; |
| 164 | 175 | } |
| ... | ... | @@ -240,7 +251,7 @@ pub fn _chkstk() callconv(.Naked) void { |
| 240 | 251 | } |
| 241 | 252 | pub fn __chkstk() callconv(.Naked) void { |
| 242 | 253 | @setRuntimeSafety(false); |
| 243 | | if (comptime arch.isAARCH64()) { |
| 254 | if (arch == .thumb or arch == .aarch64) { |
| 244 | 255 | @call(.always_inline, win_probe_stack_only, .{}); |
| 245 | 256 | } else switch (arch) { |
| 246 | 257 | .x86 => @call(.always_inline, win_probe_stack_adjust_sp, .{}), |