Subversion Repositories Kolibri OS

Rev

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