简体   繁体   中英

Unix alternative to this mingw runtime code

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?

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() .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM