Changeset 96370 in vbox
- Timestamp:
- Aug 20, 2022 2:28:31 AM (2 years ago)
- Location:
- trunk/src/VBox/Runtime/common/compiler/vcc
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/compiler/vcc/stack-vcc.asm
r96368 r96370 30 30 ;* Header Files * 31 31 ;********************************************************************************************************************************* 32 %if 0 ; YASM's builtin SEH64 support doesn't cope well with code alignment, so use our own. 33 %define RT_ASM_WITH_SEH64 34 %else 35 %define RT_ASM_WITH_SEH64_ALT 36 %endif 32 37 %include "iprt/asmdefs.mac" 33 38 %include "iprt/x86.mac" … … 99 104 extern NAME(_RTC_StackVarCorrupted) 100 105 extern NAME(_RTC_SecurityCookieMismatch) 106 %ifdef RT_ARCH_X86 107 extern NAME(_RTC_CheckEspFailed) 108 %endif 101 109 102 110 103 111 BEGINPROC __GSHandlerCheck 112 SEH64_END_PROLOGUE 104 113 int3 105 114 ENDPROC __GSHandlerCheck 106 115 107 116 ;; 108 ; Probe stack to trigger guard faults. 109 ; 110 ; @param eax Frame size. 111 ; @uses Nothing (because we don't quite now the convention). 112 ; 113 ALIGNCODE(32) 114 BEGINPROC __chkstk 117 ; Probe stack to trigger guard faults, and for x86 to allocate stack space. 118 ; 119 ; @param xAX Frame size. 120 ; @uses AMD64: Nothing (because we don't quite now the convention). 121 ; x86: ESP = ESP - EAX; nothing else 122 ; 123 ALIGNCODE(64) 124 GLOBALNAME_RAW __alloca_probe, __alloca_probe, function 125 BEGINPROC_RAW __chkstk 115 126 push xBP 127 SEH64_PUSH_xBP 116 128 mov xBP, xSP 117 pushf129 SEH64_SET_FRAME_xBP 0 118 130 push xAX 131 SEH64_PUSH_GREG xAX 119 132 push xBX 120 121 xor ebx, ebx 122 .again: 133 SEH64_PUSH_GREG xBX 134 SEH64_END_PROLOGUE 135 136 ; 137 ; Adjust eax so we can use xBP for stack addressing. 138 ; 139 sub xAX, xCB*2 140 jle .touch_loop_done 141 142 ; 143 ; Subtract what's left of the current page from eax and only engage 144 ; the touch loop if (int)xAX > 0. 145 ; 146 mov ebx, PAGE_SIZE - 1 147 and ebx, ebp 148 sub xAX, xBX 149 jnl .touch_loop 150 151 .touch_loop_done: 152 pop xBX 153 pop xAX 154 leave 155 %ifndef RT_ARCH_X86 156 ret 157 %else 158 ; 159 ; Do the stack space allocation and jump to the return location. 160 ; 161 sub esp, eax 162 add esp, 4 163 jmp dword [esp + eax - 4] 164 %endif 165 166 ; 167 ; The touch loop. 168 ; 169 .touch_loop: 123 170 sub xBX, PAGE_SIZE 124 171 mov [xBP + xBX], bl 125 sub eax, PAGE_SIZE 126 jnl .again 127 128 pop xBX 129 pop xAX 130 popf 131 leave 132 ret 133 ENDPROC __chkstk 172 sub xAX, PAGE_SIZE 173 jnl .touch_loop 174 jmp .touch_loop_done 175 ENDPROC_RAW __chkstk 176 177 178 %ifdef RT_ARCH_X86 179 ;; 180 ; 8 and 16 byte aligned alloca w/ probing. 181 ; 182 ; This routine adjusts the allocation size so __chkstk will return a 183 ; correctly aligned allocation. 184 ; 185 ; @param xAX Unaligned allocation size. 186 ; 187 %macro __alloc_probe_xxx 1 188 ALIGNCODE(16) 189 BEGINPROC_RAW __alloca_probe_ %+ %1 190 push ecx 191 192 ; 193 ; Calc the ESP address after the allocation and adjust EAX so that it 194 ; will be aligned as desired. 195 ; 196 lea ecx, [esp + 8] 197 sub ecx, eax 198 and ecx, %1 - 1 199 add eax, ecx 200 jc .bad_alloc_size 201 .continue: 202 203 pop ecx 204 jmp __alloca_probe 205 206 .bad_alloc_size: 207 %ifdef RT_STRICT 208 int3 209 %endif 210 or eax, 0xfffffff0 211 jmp .continue 212 ENDPROC_RAW __alloca_probe_ %+ %1 213 %endmacro 214 215 __alloc_probe_xxx 16 216 __alloc_probe_xxx 8 217 %endif ; RT_ARCH_X86 134 218 135 219 … … 138 222 ; since we don't have either of those we have nothing to do here. 139 223 BEGINPROC _RTC_InitBase 224 SEH64_END_PROLOGUE 140 225 ret 141 226 ENDPROC _RTC_InitBase … … 145 230 ; Nothing to do here. 146 231 BEGINPROC _RTC_Shutdown 232 SEH64_END_PROLOGUE 147 233 ret 148 234 ENDPROC _RTC_Shutdown … … 166 252 BEGINPROC_RAW FASTCALL_NAME(_RTC_CheckStackVars, 8) 167 253 push xBP 254 SEH64_PUSH_xBP 255 SEH64_END_PROLOGUE 168 256 169 257 ; … … 249 337 250 338 339 %ifdef RT_ARCH_X86 340 ;; 341 ; Called to follow up on a 'CMP ESP, EBP' kind of instruction, 342 ; expected to report failure if the compare failed. 343 ; 344 ALIGNCODE(16) 345 BEGINPROC _RTC_CheckEsp 346 jne .unexpected_esp 347 ret 348 349 .unexpected_esp: 350 push ebp 351 mov ebp, esp 352 push eax 353 push ecx 354 push edx 355 356 ; DECLASM(void) _RTC_CheckEspFailed(uintptr_t uEip, uintptr_t uEsp, uintptr_t uEbp) 357 push dword [ebp] 358 lea edx, [ebp + 8] 359 push edx 360 mov ecx, [ebp + 8] 361 push ecx 362 call NAME(_RTC_CheckEspFailed) 363 364 pop edx 365 pop ecx 366 pop eax 367 leave 368 ret 369 ENDPROC _RTC_CheckEsp 370 %endif ; RT_ARCH_X86 371 372 373 251 374 ;; 252 375 ; Initialize an alloca allocation list entry and add it to it. … … 260 383 ALIGNCODE(64) 261 384 BEGINPROC_RAW FASTCALL_NAME(_RTC_AllocaHelper, 12) 385 SEH64_END_PROLOGUE 386 262 387 ; 263 388 ; Check that input isn't NULL or the size isn't zero. … … 328 453 ALIGNCODE(16) 329 454 BEGINPROC_RAW FASTCALL_NAME(__security_check_cookie, 4) 455 SEH64_END_PROLOGUE 330 456 cmp xCX, [NAME(__security_cookie) xWrtRIP] 331 457 jne .corrupted … … 351 477 ; Not stack related stubs. 352 478 BEGINPROC __C_specific_handler 479 SEH64_END_PROLOGUE 353 480 int3 354 481 ENDPROC __C_specific_handler … … 356 483 357 484 BEGINPROC __report_rangecheckfailure 485 SEH64_END_PROLOGUE 358 486 int3 359 487 ENDPROC __report_rangecheckfailure -
trunk/src/VBox/Runtime/common/compiler/vcc/stacksup-vcc.cpp
r95870 r96370 123 123 124 124 125 #ifdef RT_ARCH_X86 126 DECLASM(void) _RTC_CheckEspFailed(uintptr_t uEip, uintptr_t uEsp, uintptr_t uEbp) 127 { 128 RTAssertMsg2("\n\n!!ESP check failed!!\n\n" 129 "eip=%p esp=%p ebp=%p\n", 130 uEip, uEsp, uEbp); 131 RT_BREAKPOINT(); 132 } 133 #endif 134 135 125 136 extern "C" void __cdecl _RTC_UninitUse(const char *pszVar) 126 137 {
Note:
See TracChangeset
for help on using the changeset viewer.