I was wondering if it was possible to restart a program (ignoring previously mapped files) with different argument by either calling
main() or a glibc entry point function.
Well, while it's definitely possible to jump to the entrypoint of the program to try restarting it, there may be various consequences preventing correct execution, e.g.:
- library initialization has been run already, and running it a second time is not something most libraries expect
- various resources may have been allocated and variables initialized, so doing it again may not work.
So what you can do is to cause the program to simulate termination without actually exiting and then jump to the entry point. Microsoft CRT provides functions
_cexit for such cpurpose, but it seems glibc does not have anything similar. So you may have to simulate calling of the
atexit handlers manually to perform cleanup.