Hi,
pcmattman wrote:Unfortunately, whenever a process tries to return it crashes with an "Invalid Opcode" error. I'm assuming this means that the process stack isn't setup right.
You can't "return" unless there's something to return to....
Normally for C there's a run time library, with something like this:
Code: Select all
void STARTUP_ENTRY_POINT(char *commandLineString) {
int argc;
char *argv[];
int status;
parseCommandLine(&argc, &argv);
status = main(argc, argv);
exit(status);
}
This means when "main()" returns it returns to the C library, and the C library calls some function to terminate the task (which never returns, as the task is terminated).
Of course the code above is just an example - someone who is more familiar with C would have a better idea of what is actually in the C library's startup code. I can imagine a collection of OS dependant things, like setting up STDIN, STDOUT and STDERR, initialising the heap, installing default signal handlers, etc.
Cheers,
Brendan