VirtualBox

Ignore:
Timestamp:
Jan 20, 2023 9:16:34 AM (2 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
155324
Message:

IPRT/vcc: Split out the stack probing code (_chkstk) from stack-vcc.asm. bugref:10348 bugref:10261

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/compiler/vcc/stack-vcc.asm

    r98103 r98151  
    124124%endif
    125125
    126 
    127 
    128 ;;
    129 ; Probe stack to trigger guard faults, and for x86 to allocate stack space.
    130 ;
    131 ; @param    xAX     Frame size.
    132 ; @uses     AMD64:  Probably nothing. EAX is certainly not supposed to change.
    133 ;           x86:    ESP = ESP - EAX; EFLAGS, nothing else
    134 ;
    135 ALIGNCODE(64)
    136 GLOBALNAME_RAW  __alloca_probe, __alloca_probe, function
    137 BEGINPROC_RAW   __chkstk
    138         push    xBP
    139         SEH64_PUSH_xBP
    140         mov     xBP, xSP
    141         SEH64_SET_FRAME_xBP 0
    142         push    xAX
    143         SEH64_PUSH_GREG xAX
    144         push    xBX
    145         SEH64_PUSH_GREG xBX
    146         SEH64_END_PROLOGUE
    147 
    148         ;
    149         ; Adjust eax so we're relative to [xBP - xCB*2].
    150         ;
    151         sub     xAX, xCB * 4
    152         jle     .touch_loop_done            ; jump if rax < xCB*4, very unlikely
    153 
    154         ;
    155         ; Subtract what's left of the current page from eax and only engage
    156         ; the touch loop if (int)xAX > 0.
    157         ;
    158         lea     ebx, [ebp - xCB * 2]
    159         and     ebx, PAGE_SIZE - 1
    160         sub     xAX, xBX
    161         jnl     .touch_loop                 ; jump if pages to touch.
    162 
    163 .touch_loop_done:
    164         pop     xBX
    165         pop     xAX
    166         leave
    167 %ifndef RT_ARCH_X86
    168         ret
    169 %else
    170         ;
    171         ; Do the stack space allocation and jump to the return location.
    172         ;
    173         sub     esp, eax
    174         add     esp, 4
    175         jmp     dword [esp + eax - 4]
    176 %endif
    177 
    178         ;
    179         ; The touch loop.
    180         ;
    181 .touch_loop:
    182         sub     xBX, PAGE_SIZE
    183 %if 1
    184         mov     [xBP + xBX - xCB * 2], bl
    185 %else
    186         or      byte [xBP + xBX - xCB * 2], 0   ; non-destructive variant...
    187 %endif
    188         sub     xAX, PAGE_SIZE
    189         jnl     .touch_loop
    190         jmp     .touch_loop_done
    191 ENDPROC_RAW     __chkstk
    192 
    193 
    194 %ifdef RT_ARCH_X86
    195 ;;
    196 ; 8 and 16 byte aligned alloca w/ probing.
    197 ;
    198 ; This routine adjusts the allocation size so __chkstk will return a
    199 ; correctly aligned allocation.
    200 ;
    201 ; @param    xAX     Unaligned allocation size.
    202 ;
    203 %macro __alloc_probe_xxx 1
    204 ALIGNCODE(16)
    205 BEGINPROC_RAW   __alloca_probe_ %+ %1
    206         push    ecx
    207 
    208         ;
    209         ; Calc the ESP address after the allocation and adjust EAX so that it
    210         ; will be aligned as desired.
    211         ;
    212         lea     ecx, [esp + 8]
    213         sub     ecx, eax
    214         and     ecx, %1 - 1
    215         add     eax, ecx
    216         jc      .bad_alloc_size
    217 .continue:
    218 
    219         pop     ecx
    220         jmp     __alloca_probe
    221 
    222 .bad_alloc_size:
    223   %ifdef RT_STRICT
    224         int3
    225   %endif
    226         or      eax, 0xfffffff0
    227         jmp     .continue
    228 ENDPROC_RAW     __alloca_probe_ %+ %1
    229 %endmacro
    230 
    231 __alloc_probe_xxx 16
    232 __alloc_probe_xxx 8
    233 %endif ; RT_ARCH_X86
    234126
    235127
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette