Using the following code to print the ESP register:
#include <stdio.h>
#include <stdlib.h>
unsigned long get_sp() {
__asm__("movl %esp, %eax");
}
int main() {
sleep(5);
printf("Stack pointer (ESP): 0x%x\n", get_sp());
return 0;
}
Disable ASLR
echo "0" > /proc/sys/kernel/randomize_va_space
Build:
gcc get_sp.c -o get_sp
Run two processes:
./get_sp & ./get_sp
I get:
Stack pointer (ESP): 0xbffff158
Stack pointer (ESP): 0xbffff158
I was expecting different addresses though. Can anyone shed some light on this? Is it because these are virtual memory addresses and under the hood Linux tracks memory per process and maps correctly to main memory?
Thanks
Yes.