2010-11-07 14:42:29 +01:00
|
|
|
|
|
|
|
.global ___chkstk
|
2012-06-27 14:31:46 +02:00
|
|
|
.global ___chkstk_ms
|
2010-11-07 14:42:29 +01:00
|
|
|
.global __alloca
|
|
|
|
|
|
|
|
.section .text
|
|
|
|
|
2012-06-27 14:31:46 +02:00
|
|
|
#.def ___chkstk; .scl 2; .type 32; .endef
|
|
|
|
#.def ___chkstk_ms; .scl 2; .type 32; .endef
|
|
|
|
#.def __alloca; .scl 2; .type 32; .endef
|
|
|
|
|
2010-11-07 14:42:29 +01:00
|
|
|
___chkstk:
|
|
|
|
__alloca:
|
|
|
|
pushl %ecx /* save temp */
|
|
|
|
leal 8(%esp), %ecx /* point past return addr */
|
|
|
|
subl %eax, %ecx
|
2013-07-10 21:26:24 +02:00
|
|
|
cmpl %fs:8, %ecx # check low stack limit
|
2010-11-07 14:42:29 +01:00
|
|
|
jb 1f
|
|
|
|
|
|
|
|
movl %esp, %eax /* save old stack pointer */
|
|
|
|
movl %ecx, %esp /* decrement stack */
|
|
|
|
movl (%eax), %ecx /* recover saved temp */
|
|
|
|
movl 4(%eax), %eax /* recover return address */
|
|
|
|
|
|
|
|
/* Push the return value back. Doing this instead of just
|
|
|
|
jumping to %eax preserves the cached call-return stack
|
|
|
|
used by most modern processors. */
|
|
|
|
pushl %eax
|
|
|
|
ret
|
|
|
|
1:
|
|
|
|
int3 #trap to debugger
|
|
|
|
.ascii "Stack overflow"
|
|
|
|
|
2011-03-11 19:52:24 +01:00
|
|
|
|
2012-06-27 14:31:46 +02:00
|
|
|
___chkstk_ms:
|
|
|
|
pushl %ecx /* save temp */
|
|
|
|
pushl %eax
|
|
|
|
cmpl $0x1000, %eax /* > 4k ?*/
|
|
|
|
leal 12(%esp), %ecx /* point past return addr */
|
|
|
|
jb 2f
|
|
|
|
|
|
|
|
1:
|
|
|
|
subl $0x1000, %ecx /* yes, move pointer down 4k*/
|
2013-07-10 21:26:24 +02:00
|
|
|
cmpl %fs:8, %ecx /* check low stack limit */
|
2012-06-27 14:31:46 +02:00
|
|
|
jb 3f
|
|
|
|
|
|
|
|
orl $0x0, (%ecx) /* probe there */
|
|
|
|
subl $0x1000, %eax /* decrement count */
|
|
|
|
cmpl $0x1000, %eax
|
|
|
|
ja 1b /* and do it again */
|
|
|
|
|
|
|
|
2:
|
|
|
|
subl %eax, %ecx
|
|
|
|
orl $0x0, (%ecx) /* less than 4k, just peek here */
|
|
|
|
|
|
|
|
popl %eax
|
|
|
|
popl %ecx
|
|
|
|
ret
|
|
|
|
3:
|
|
|
|
int3 #trap to debugger
|
|
|
|
.ascii "Stack overflow"
|