Re: exiting programs
Posted: Fri Jan 30, 2009 1:28 am
Hi,
For my OS's you'd get a page fault when the CPU tries to get the return EIP from the stack, and the kernel would handle this just like any other page fault. For other OS's it depends on the OS and where the stack is - for example, maybe there's dynamically allocated data above the stack and the CPU pops garbage into EIP, or maybe the kernel pushes data onto the stack (like command line arguments and environment strings) when starting the process and the CPU pops part of that into EIP.
Cheers,
Brendan
If the program itself doesn't use a proper library or anything and just does "ret", then the simple answer would be: usually the program crashes.yemista wrote:How do you guys handle finished programs. I know how to do it with the system call exit, but lets say someone builds a program and the main function never calls exit, just returns, how do you detect that?
For my OS's you'd get a page fault when the CPU tries to get the return EIP from the stack, and the kernel would handle this just like any other page fault. For other OS's it depends on the OS and where the stack is - for example, maybe there's dynamically allocated data above the stack and the CPU pops garbage into EIP, or maybe the kernel pushes data onto the stack (like command line arguments and environment strings) when starting the process and the CPU pops part of that into EIP.
Cheers,
Brendan