| ... | @@ -129,8 +129,9 @@ export nakedcc fn _chkstk() align(4) { | ... | @@ -129,8 +129,9 @@ export nakedcc fn _chkstk() align(4) { |
| 129 | @setGlobalLinkage(_chkstk, strong_linkage); | 129 | @setGlobalLinkage(_chkstk, strong_linkage); |
| 130 | asm volatile ( | 130 | asm volatile ( |
| 131 | \\ push %%ecx | 131 | \\ push %%ecx |
| | 132 | \\ push %%eax |
| 132 | \\ cmp $0x1000,%%eax | 133 | \\ cmp $0x1000,%%eax |
| 133 | \\ lea 8(%%esp),%%ecx // esp before calling this routine -> ecx | 134 | \\ lea 12(%%esp),%%ecx |
| 134 | \\ jb 1f | 135 | \\ jb 1f |
| 135 | \\ 2: | 136 | \\ 2: |
| 136 | \\ sub $0x1000,%%ecx | 137 | \\ sub $0x1000,%%ecx |
| ... | @@ -141,12 +142,8 @@ export nakedcc fn _chkstk() align(4) { | ... | @@ -141,12 +142,8 @@ export nakedcc fn _chkstk() align(4) { |
| 141 | \\ 1: | 142 | \\ 1: |
| 142 | \\ sub %%eax,%%ecx | 143 | \\ sub %%eax,%%ecx |
| 143 | \\ test %%ecx,(%%ecx) | 144 | \\ test %%ecx,(%%ecx) |
| 144 | \\ | 145 | \\ pop %%eax |
| 145 | \\ lea 4(%%esp),%%eax // load pointer to the return address into eax | 146 | \\ pop %%ecx |
| 146 | \\ mov %%ecx,%%esp // install the new top of stack pointer into esp | | |
| 147 | \\ mov -4(%%eax),%%ecx // restore ecx | | |
| 148 | \\ push (%%eax) // push return address onto the stack | | |
| 149 | \\ sub %%esp,%%eax // restore the original value in eax | | |
| 150 | \\ ret | 147 | \\ ret |
| 151 | ); | 148 | ); |
| 152 | unreachable; | 149 | unreachable; |
| ... | @@ -159,13 +156,29 @@ export nakedcc fn _chkstk() align(4) { | ... | @@ -159,13 +156,29 @@ export nakedcc fn _chkstk() align(4) { |
| 159 | // the implementation from disassembled ntdll seems to depend on | 156 | // the implementation from disassembled ntdll seems to depend on |
| 160 | // thread local storage. So we have given up this safety check | 157 | // thread local storage. So we have given up this safety check |
| 161 | // and simply have `ret`. | 158 | // and simply have `ret`. |
| 162 | export nakedcc fn __chkstk() align(8) { | 159 | export nakedcc fn __chkstk() align(4) { |
| 163 | @setDebugSafety(this, false); | 160 | @setDebugSafety(this, false); |
| 164 | | 161 | |
| 165 | if (win64_nocrt) { | 162 | if (win64_nocrt) { |
| 166 | @setGlobalLinkage(__chkstk, strong_linkage); | 163 | @setGlobalLinkage(__chkstk, strong_linkage); |
| 167 | asm volatile ( | 164 | asm volatile ( |
| 168 | \\ ret | 165 | \\ push %%rcx |
| | 166 | \\ push %%rax |
| | 167 | \\ cmp $0x1000,%%rax |
| | 168 | \\ lea 24(%%rsp),%%rcx |
| | 169 | \\ jb 1f |
| | 170 | \\2: |
| | 171 | \\ sub $0x1000,%%rcx |
| | 172 | \\ test %%rcx,(%%rcx) |
| | 173 | \\ sub $0x1000,%%rax |
| | 174 | \\ cmp $0x1000,%%rax |
| | 175 | \\ ja 2b |
| | 176 | \\1: |
| | 177 | \\ sub %%rax,%%rcx |
| | 178 | \\ test %%rcx,(%%rcx) |
| | 179 | \\ pop %%rax |
| | 180 | \\ pop %%rcx |
| | 181 | \\ ret |
| 169 | ); | 182 | ); |
| 170 | unreachable; | 183 | unreachable; |
| 171 | } | 184 | } |