Subversion Repositories Kolibri OS

Rev

Rev 205 | Blame | Last modification | View Log | Download | RSS feed

  1. #include "crt.h"
  2.  
  3. #define atexitBufferSize        32
  4.  
  5. char pureCallMessage[] = "PURE function call!";
  6.  
  7. char *__argv[2];
  8. int __argc;
  9.  
  10. void (__cdecl *atExitList[atexitBufferSize])();
  11. int atExitFnNum = 0;
  12. int main(int argc, char *argv[]);
  13.  
  14. void exit()
  15. {       int i;
  16.  
  17.         for ( i = atExitFnNum - 1; i >= 0; i-- )
  18.                 atExitList[i]();
  19.        
  20.         __asm
  21.         {
  22.                 mov eax, -1
  23.                 int 0x40
  24.   };
  25. };
  26.  
  27. int __cdecl atexit( void (__cdecl *func )( void ))
  28. {
  29.         //
  30.         if ( atExitFnNum < atexitBufferSize )
  31.         {
  32.                 //
  33.                 atExitList[atExitFnNum++] = func;
  34.                 return 0;
  35.         }
  36.         else
  37.         {
  38.                 return 1;
  39.         }
  40. }
  41.  
  42. int __cdecl _purecall()
  43. {
  44.         exit();
  45.         return 0;
  46. }
  47.  
  48. #pragma section(".CRT$XCA",long,read,write)
  49. #pragma section(".CRT$XCZ",long,read,write)
  50. typedef void (__cdecl *_PVFV)(void);
  51. __declspec(allocate(".CRT$XCA"))  _PVFV __xc_a[1] = { 0 };
  52. __declspec(allocate(".CRT$XCZ"))  _PVFV __xc_z[1] = { 0 };
  53. //
  54. #pragma comment(linker, "/merge:.CRT=.rdata")
  55. //
  56. void crtStartUp()
  57. {_PVFV *pbegin;
  58.  
  59.         _asm {fninit};
  60.  
  61.         for ( pbegin = __xc_a; pbegin < __xc_z; pbegin++ )
  62.         {
  63.                 //
  64.                 if ( *pbegin != 0 )
  65.                         (**pbegin)();
  66.         }
  67.         __argc = 2;
  68.         __argv[0] = *((char **)0x20);
  69.         __argv[1] = *((char **)0x1C);
  70.         main(__argc, __argv);
  71.         exit();
  72. }
  73.  
  74.  
  75.