Domanda

MinGW uses this code as start for every program

static void  __attribute__((noreturn)) __mingw_CRTStartup (void)    
{
  int nRet;
  SetUnhandledExceptionFilter (_gnu_exception_handler);
  _fpreset ();  
  _mingw32_init_mainargs ();
  _mingw32_init_fmode ();
  _pei386_runtime_relocator ();
  asm  __volatile__  ("andl $-16, %%esp" : : : "%esp");
  nRet = main (_argc, _argv, environ);
  _cexit ();
  ExitProcess (nRet);
}

What is the alternative for Linux for the line ExitProcess(nRet); which terminates all threads and handles return value? Where can I find source code for Linux/OS X gcc runtime? Does Linux-GCC/XCode runtime terminates all threads? If not, how does it handle return values of main?

È stato utile?

Soluzione

The corresponding code, which is a fair bit more complex in "glibc" than the above MingW code (because it has a lot of options that has both compile tile and runtime choices associated with them):

http://sourceware.org/git/?p=glibc.git;a=blob;f=csu/libc-start.c;h=a14ed71616a3f63f092837e9c30780f8344b4fbe;hb=cvs/glibc-2_9-branch

However, the simple view is that it does:

result = main (argc, argv, __environ MAIN_AUXVEC_PARAM);
exit (result);

And yes, exit will kill all threads (if nothing else, the OS will when the system call to exit is called in _exit().

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top