-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathalloca16.asm
71 lines (59 loc) · 2.19 KB
/
alloca16.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
page ,132
title alloca16 - aligned C stack checking routine
;***
;chkstk.asm - aligned C stack checking routine
;
; Copyright (c) Microsoft Corporation. All rights reserved.
;
;Purpose:
; Provides 16 and 8 bit aligned alloca routines.
;
;*******************************************************************************
.xlist
include vcruntime.inc
.list
extern _chkstk:near
; size of a page of memory
CODESEG
page
;***
; _alloca_probe_16, _alloca_probe_8 - align allocation to 16/8 byte boundary
;
;Purpose:
; Adjust allocation size so the ESP returned from chkstk will be aligned
; to 16/8 bit boundary. Call chkstk to do the real allocation.
;
;Entry:
; EAX = size of local frame
;
;Exit:
; Adjusted EAX.
;
;Uses:
; EAX
;
;*******************************************************************************
public _alloca_probe_8
_alloca_probe_16 proc ; 16 byte aligned alloca
push ecx
lea ecx, [esp] + 8 ; TOS before entering this function
sub ecx, eax ; New TOS
and ecx, (16 - 1) ; Distance from 16 bit align (align down)
add eax, ecx ; Increase allocation size
sbb ecx, ecx ; ecx = 0xFFFFFFFF if size wrapped around
or eax, ecx ; cap allocation size on wraparound
pop ecx ; Restore ecx
jmp _chkstk
alloca_8: ; 8 byte aligned alloca
_alloca_probe_8 = alloca_8
push ecx
lea ecx, [esp] + 8 ; TOS before entering this function
sub ecx, eax ; New TOS
and ecx, (8 - 1) ; Distance from 8 bit align (align down)
add eax, ecx ; Increase allocation Size
sbb ecx, ecx ; ecx = 0xFFFFFFFF if size wrapped around
or eax, ecx ; cap allocation size on wraparound
pop ecx ; Restore ecx
jmp _chkstk
_alloca_probe_16 endp
end