I am trying to copy a current running process esp value to another processes esp, running on another terminal.
I am getting a segmentation fault.
But I can't figure out the reason correctly as I am using inline assembly.
p1.c
int main()
{
int a=5;
int b =8;
unsigned int esp =0;
asm("mov %%esp,%0":"=r"(esp)::);
printf("esp:[%x] \n",esp);
while(1);
}
P2.c
int main()
{
int a=5;
int espoth=0;
asm("mov 0xbfda8008,%%esp"::);
}
First I ran p1.c which gave me 0xbfda8008 current stack pointer.
Then I used it in p2.c which gave me Segmentation fault.
I am just writing a value into esp. Why am I getting this fault ? Need a little hint... ;-(
This will not work as expected. The memory for each process is isolated from the other processes, and the memory-map each process sees is virtual. So even if two processes both might have memory available at the same address, it does not mean that the actual physical memory is the same.
This is what separates "modern" operating systems and hardware from the "old" ones. You can search about "mmu", "memory protection unit" and "virtual memory" on your favorite search engine.
Your idea would work if playing in good old MS-DOS for instance that did not use the MMU (unless playing with protected mode programs using for instance DOS4GW, GO32-V2)