system.pp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. {$IFNDEF FPC_DISABLE_MONITOR}
  14. {$DEFINE SYSTEM_HAS_FEATURE_MONITOR}
  15. {$ENDIF}
  16. {$define FPC_IS_SYSTEM}
  17. {$ifdef FPC_WASM_THREADS}
  18. {$define DISABLE_NO_THREAD_MANAGER}
  19. {$else FPC_WASM_THREADS}
  20. {$define USE_NOTHREADMANAGER}
  21. {$endif FPC_WASM_THREADS}
  22. {$I systemh.inc}
  23. const
  24. LineEnding = #10;
  25. LFNSupport = true;
  26. DirectorySeparator = '/';
  27. DriveSeparator = '';
  28. ExtensionSeparator = '.';
  29. PathSeparator = ':';
  30. AllowDirectorySeparators : set of AnsiChar = ['\','/'];
  31. AllowDriveSeparators : set of AnsiChar = [];
  32. { FileNameCaseSensitive and FileNameCasePreserving are defined below! }
  33. maxExitCode = 65535;
  34. MaxPathLen = 4096;
  35. AllFilesMask = '*';
  36. const
  37. UnusedHandle = -1;
  38. StdInputHandle = 0;
  39. StdOutputHandle = 1;
  40. StdErrorHandle = 2;
  41. FileNameCaseSensitive : boolean = true;
  42. FileNameCasePreserving: boolean = true;
  43. CtrlZMarksEOF: boolean = false; (* #26 not considered as end of file *)
  44. sLineBreak = LineEnding;
  45. DefaultTextLineBreakStyle : TTextLineBreakStyle = tlbsLF;
  46. var
  47. argc: longint;
  48. argv: PPAnsiChar;
  49. { envp: PPAnsiChar;}
  50. implementation
  51. var
  52. StkLen: SizeUInt; external name '__stklen';
  53. {$I system.inc}
  54. {var
  55. argv_size,
  56. argv_buf_size: __wasi_size_t;
  57. argv_buf: Pointer;
  58. environc,environ_buf_size,envp_size: __wasi_size_t;
  59. environ_buf: Pointer;}
  60. function GetProcessID: SizeUInt;
  61. begin
  62. end;
  63. Procedure Randomize;
  64. Begin
  65. End;
  66. procedure System_exit;
  67. begin
  68. End;
  69. procedure Setup_Environment;
  70. begin
  71. end;
  72. procedure setup_arguments;
  73. begin
  74. end;
  75. Function ParamCount: Longint;
  76. Begin
  77. paramcount := 0;
  78. End;
  79. function paramstr(l: longint) : shortstring;
  80. begin
  81. paramstr:='';
  82. end;
  83. procedure SysInitStdIO;
  84. begin
  85. OpenStdIO(Input,fmInput,StdInputHandle);
  86. OpenStdIO(Output,fmOutput,StdOutputHandle);
  87. OpenStdIO(ErrOutput,fmOutput,StdErrorHandle);
  88. OpenStdIO(StdOut,fmOutput,StdOutputHandle);
  89. OpenStdIO(StdErr,fmOutput,StdErrorHandle);
  90. end;
  91. function CheckInitialStkLen(stklen : SizeUInt) : SizeUInt;
  92. begin
  93. result := stklen;
  94. end;
  95. begin
  96. StackLength:=CheckInitialStkLen(stklen);
  97. StackBottom:=Pointer(PtrUInt(InitialHeapBlockStart)-PtrUInt(StackLength));
  98. { To be set if this is a GUI or console application }
  99. IsConsole := TRUE;
  100. {$ifdef FPC_HAS_FEATURE_DYNLIBS}
  101. { If dynlibs feature is disabled,
  102. IsLibrary is a constant, which can thus not be set to a value }
  103. { To be set if this is a library and not a program }
  104. IsLibrary := FALSE;
  105. {$endif def FPC_HAS_FEATURE_DYNLIBS}
  106. { Setup heap }
  107. InitInitialHeapBlock;
  108. InitHeap;
  109. SysInitExceptions;
  110. initunicodestringmanager;
  111. { Reset IO Error }
  112. InOutRes:=0;
  113. {$ifdef FPC_HAS_FEATURE_THREADING}
  114. InitSystemThreads;
  115. {$ifdef FPC_WASM_THREADS}
  116. InitThreadVars(@WasiRelocateThreadVar);
  117. {$endif}
  118. {$endif}
  119. { Setup stdin, stdout and stderr }
  120. SysInitStdIO;
  121. Setup_Environment;
  122. // Setup_PreopenedDirs;
  123. {$ifdef FPC_WASM_THREADS}
  124. TLSInfoBlock:=Nil;
  125. {$endif}
  126. end.