Subversion Repositories Kolibri OS

Rev

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

  1. // =============================================
  2. // crt1.c
  3.  
  4. // For ExitProcess
  5. // windows.h header file should be included before any other library include
  6. #include <windows.h>
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9.  
  10. #define _UNKNOWN_APP    0
  11. #define _CONSOLE_APP    1
  12. #define _GUI_APP        2
  13.  
  14. #define _MCW_PC         0x00030000 // Precision Control
  15. #define _PC_24          0x00020000 // 24 bits
  16. #define _PC_53          0x00010000 // 53 bits
  17. #define _PC_64          0x00000000 // 64 bits
  18.  
  19. #ifndef __TRY__
  20.     #ifdef _WIN64
  21.         #define __TRY__
  22.     #else
  23.         #define __TRY__ void __try__(void**), *_sehrec[6]; __try__(_sehrec);
  24.     #endif
  25. #endif
  26.  
  27. typedef struct
  28. {
  29.     int newmode;
  30. } _startupinfo;
  31.  
  32. // Prototype of __getmainargs:
  33. // in msvcrt v6.x : returns void (windows 98, 2000)
  34. // in msvcrt v7.x : returns int  (windows xp and above)
  35. // Using the last for check the result. A negative value means no success.
  36. // These are the test results of call to __getmainargs with the heap fully:
  37. // win 98, 2000 :
  38. //     program termination with error code 255 after call _amsg_exit(8)
  39. //     prints: "runtime error R6008\r\n- not enough space for arguments\r\n"
  40. // win xp :
  41. //     returns -1
  42. // win 7, 8 :
  43. //     program termination with error code -1 after call ExitProcess(-1)
  44. //
  45. // Checking the return of this function also works on windows 98 and 2000
  46. // because internally it sets to eax the value of the third parameter.
  47. // In this case is &env and at that point it is not a negative value.
  48.  
  49. int __cdecl __getmainargs(int *pargc, char ***pargv, char ***penv, int globb, _startupinfo*);
  50. void __cdecl __set_app_type(int apptype);
  51. unsigned int __cdecl _controlfp(unsigned int new_value, unsigned int mask);
  52.  
  53. void _start(void);
  54. int main(int argc, char * argv[], char * env[]);
  55.  
  56. void _start(void)
  57. {
  58.     __TRY__
  59.     int argc;
  60.     char **argv;
  61.     char **env;
  62.     _startupinfo start_info;
  63.  
  64.     // Sets the current application type
  65.     __set_app_type(_CONSOLE_APP);
  66.  
  67.     // Set default FP precision to 53 bits (8-byte double)
  68.     // _MCW_PC (Precision control) is not supported on
  69.     // the ARM and x64 architectures
  70. #if defined(_X86_) && !defined(__x86_64)
  71.     _controlfp(_PC_53, _MCW_PC);
  72. #endif
  73.  
  74.     start_info.newmode = 0;
  75.     if ( __getmainargs( &argc, &argv, &env, 0, &start_info ) < 0 )
  76.     {
  77.         ExitProcess(-1);
  78.     }
  79.     else
  80.     {
  81.         exit( main(argc, argv, env) );
  82.     }
  83.  
  84. }
  85.  
  86. // =============================================
  87.