| ... | ... | @@ -129,8 +129,9 @@ export nakedcc fn _chkstk() align(4) { |
| 129 | 129 | @setGlobalLinkage(_chkstk, strong_linkage); |
| 130 | 130 | asm volatile ( |
| 131 | 131 | \\ push %%ecx |
| 132 | \\ push %%eax |
| 132 | 133 | \\ cmp $0x1000,%%eax |
| 133 | | \\ lea 8(%%esp),%%ecx // esp before calling this routine -> ecx |
| 134 | \\ lea 12(%%esp),%%ecx |
| 134 | 135 | \\ jb 1f |
| 135 | 136 | \\ 2: |
| 136 | 137 | \\ sub $0x1000,%%ecx |
| ... | ... | @@ -141,12 +142,8 @@ export nakedcc fn _chkstk() align(4) { |
| 141 | 142 | \\ 1: |
| 142 | 143 | \\ sub %%eax,%%ecx |
| 143 | 144 | \\ test %%ecx,(%%ecx) |
| 144 | | \\ |
| 145 | | \\ lea 4(%%esp),%%eax // load pointer to the return address into eax |
| 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 |
| 145 | \\ pop %%eax |
| 146 | \\ pop %%ecx |
| 150 | 147 | \\ ret |
| 151 | 148 | ); |
| 152 | 149 | unreachable; |
| ... | ... | @@ -159,13 +156,29 @@ export nakedcc fn _chkstk() align(4) { |
| 159 | 156 | // the implementation from disassembled ntdll seems to depend on |
| 160 | 157 | // thread local storage. So we have given up this safety check |
| 161 | 158 | // and simply have `ret`. |
| 162 | | export nakedcc fn __chkstk() align(8) { |
| 159 | export nakedcc fn __chkstk() align(4) { |
| 163 | 160 | @setDebugSafety(this, false); |
| 164 | 161 | |
| 165 | 162 | if (win64_nocrt) { |
| 166 | 163 | @setGlobalLinkage(__chkstk, strong_linkage); |
| 167 | 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 | 183 | unreachable; |
| 171 | 184 | } |