Unix替代此mingw运行时代码

Unix alternative to this mingw runtime code

本文关键字:运行时 代码 mingw Unix      更新时间:2023-10-16

MinGW使用此代码作为每个程序的启动

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);
}

对于终止所有线程并处理返回值的行ExitProcess(nRet);,Linux有什么替代方案?在哪里可以找到Linux/OSX gcc运行时的源代码?Linux GCC/XCode运行时是否终止所有线程?如果没有,它如何处理main的返回值?

对应的代码,在"glibc"中比上面的MingW代码复杂一点(因为它有很多选项,其中既有编译瓦片,也有运行时选项):

http://sourceware.org/git/?p=glibc.git;a=斑点;f=csu/libc start.c;h=a14ed71616a3f63f092837e9c30780f8344b4be;hb=cvs/glibc-2_9分支

然而,简单的观点是:

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

是的,exit将杀死所有线程(如果没有其他操作,则当在_exit()中调用退出的系统调用时,操作系统将杀死。