system.pp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2020,2021 by the Free Pascal development team.
  4. System unit for The WebAssembly System Interface (WASI).
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. unit system;
  12. interface
  13. {$define FPC_IS_SYSTEM}
  14. {$ifdef FPC_WASM_THREADS}
  15. {$define DISABLE_NO_THREAD_MANAGER}
  16. {$else FPC_WASM_THREADS}
  17. {$define USE_NOTHREADMANAGER}
  18. {$endif FPC_WASM_THREADS}
  19. {$I systemh.inc}
  20. const
  21. LineEnding = #10;
  22. LFNSupport = true;
  23. DirectorySeparator = '/';
  24. DriveSeparator = '';
  25. ExtensionSeparator = '.';
  26. PathSeparator = ':';
  27. AllowDirectorySeparators : set of AnsiChar = ['\','/'];
  28. AllowDriveSeparators : set of AnsiChar = [];
  29. { FileNameCaseSensitive and FileNameCasePreserving are defined below! }
  30. maxExitCode = 65535;
  31. MaxPathLen = 4096;
  32. AllFilesMask = '*';
  33. const
  34. UnusedHandle = -1;
  35. StdInputHandle = 0;
  36. StdOutputHandle = 1;
  37. StdErrorHandle = 2;
  38. FileNameCaseSensitive : boolean = true;
  39. FileNameCasePreserving: boolean = true;
  40. CtrlZMarksEOF: boolean = false; (* #26 not considered as end of file *)
  41. sLineBreak = LineEnding;
  42. DefaultTextLineBreakStyle : TTextLineBreakStyle = tlbsLF;
  43. var
  44. argc: longint;
  45. argv: PPAnsiChar;
  46. { envp: PPAnsiChar;}
  47. implementation
  48. var
  49. StkLen: SizeUInt; external name '__stklen';
  50. {$I system.inc}
  51. {var
  52. argv_size,
  53. argv_buf_size: __wasi_size_t;
  54. argv_buf: Pointer;
  55. environc,environ_buf_size,envp_size: __wasi_size_t;
  56. environ_buf: Pointer;}
  57. function GetProcessID: SizeUInt;
  58. begin
  59. end;
  60. Procedure Randomize;
  61. Begin
  62. End;
  63. procedure System_exit;
  64. begin
  65. End;
  66. procedure Setup_Environment;
  67. begin
  68. end;
  69. procedure setup_arguments;
  70. begin
  71. end;
  72. Function ParamCount: Longint;
  73. Begin
  74. paramcount := 0;
  75. End;
  76. function paramstr(l: longint) : shortstring;
  77. begin
  78. paramstr:='';
  79. end;
  80. procedure SysInitStdIO;
  81. begin
  82. OpenStdIO(Input,fmInput,StdInputHandle);
  83. OpenStdIO(Output,fmOutput,StdOutputHandle);
  84. OpenStdIO(ErrOutput,fmOutput,StdErrorHandle);
  85. OpenStdIO(StdOut,fmOutput,StdOutputHandle);
  86. OpenStdIO(StdErr,fmOutput,StdErrorHandle);
  87. end;
  88. function CheckInitialStkLen(stklen : SizeUInt) : SizeUInt;
  89. begin
  90. result := stklen;
  91. end;
  92. begin
  93. StackLength:=CheckInitialStkLen(stklen);
  94. StackBottom:=Pointer(PtrUInt(InitialHeapBlockStart)-PtrUInt(StackLength));
  95. { To be set if this is a GUI or console application }
  96. IsConsole := TRUE;
  97. {$ifdef FPC_HAS_FEATURE_DYNLIBS}
  98. { If dynlibs feature is disabled,
  99. IsLibrary is a constant, which can thus not be set to a value }
  100. { To be set if this is a library and not a program }
  101. IsLibrary := FALSE;
  102. {$endif def FPC_HAS_FEATURE_DYNLIBS}
  103. { Setup heap }
  104. InitInitialHeapBlock;
  105. InitHeap;
  106. SysInitExceptions;
  107. initunicodestringmanager;
  108. { Reset IO Error }
  109. InOutRes:=0;
  110. {$ifdef FPC_HAS_FEATURE_THREADING}
  111. InitSystemThreads;
  112. {$ifdef FPC_WASM_THREADS}
  113. InitThreadVars(@WasiRelocateThreadVar);
  114. {$endif}
  115. {$endif}
  116. { Setup stdin, stdout and stderr }
  117. SysInitStdIO;
  118. Setup_Environment;
  119. // Setup_PreopenedDirs;
  120. {$ifdef FPC_WASM_THREADS}
  121. TLSInfoBlock:=Nil;
  122. {$endif}
  123. end.