Created
September 16, 2015 17:07
-
-
Save astarasikov/bf0601f1cdcc7c86e769 to your computer and use it in GitHub Desktop.
assembly stub to clear caller's stack frame on i386 linux/gcc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.globl mcount | |
mcount: | |
push %eax | |
push %ebx | |
push %ecx | |
mov %esp,%eax | |
add $0x10,%eax //retval + rax + rbx + rcx | |
mov %ebp,%ebx | |
sub %eax,%ebx //caller thread stack frame size = ebp - prev.sp | |
mov $0,%ecx //stack filler value | |
sub $4,%ebx //subtract stored sp offset | |
//first iteration of the loop also decrements the %ebx | |
//thus preventing overwriting the return address | |
loop: | |
sub $4,%ebx | |
cmp $0,%ebx | |
jle done | |
mov %ecx,(%eax,%ebx,1) | |
jmp loop | |
done: | |
pop %ecx | |
pop %ebx | |
pop %eax | |
ret |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment