system.pp 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. unit system;
  2. interface
  3. {$define FPC_IS_SYSTEM}
  4. {$I systemh.inc}
  5. const
  6. LineEnding = #10;
  7. LFNSupport = true;
  8. DirectorySeparator = '/';
  9. DriveSeparator = '';
  10. ExtensionSeparator = '.';
  11. PathSeparator = ':';
  12. AllowDirectorySeparators : set of char = ['\','/'];
  13. AllowDriveSeparators : set of char = [];
  14. { FileNameCaseSensitive and FileNameCasePreserving are defined below! }
  15. maxExitCode = 65535;
  16. MaxPathLen = 4096;
  17. AllFilesMask = '*';
  18. const
  19. UnusedHandle = -1;
  20. StdInputHandle = 0;
  21. StdOutputHandle = 1;
  22. StdErrorHandle = 2;
  23. FileNameCaseSensitive : boolean = true;
  24. FileNameCasePreserving: boolean = true;
  25. CtrlZMarksEOF: boolean = false; (* #26 not considered as end of file *)
  26. sLineBreak = LineEnding;
  27. DefaultTextLineBreakStyle : TTextLineBreakStyle = tlbsLF;
  28. procedure DebugWrite(const P: PChar);
  29. procedure DebugWriteLn(const P: PChar);
  30. procedure DebugWriteChar(Ch: Char);
  31. procedure DebugWriteHexDigit(d: Byte);
  32. procedure DebugWriteHexByte(b: Byte);
  33. procedure DebugWriteHexWord(w: Word);
  34. procedure DebugWriteHexLongWord(lw: Word);
  35. implementation
  36. type
  37. P__wasi_size_t = ^__wasi_size_t;
  38. __wasi_size_t = longint;
  39. __wasi_fd_t = longint;
  40. size_t = longint;
  41. __wasi_errno_t = longint;
  42. const
  43. __WASI_ERRNO_SUCCESS = 0;
  44. __WASI_ERRNO_2BIG = 1;
  45. __WASI_ERRNO_ACCES = 2;
  46. __WASI_ERRNO_ADDRINUSE = 3;
  47. __WASI_ERRNO_ADDRNOTAVAIL = 4;
  48. __WASI_ERRNO_AFNOSUPPORT = 5;
  49. __WASI_ERRNO_AGAIN = 6;
  50. __WASI_ERRNO_ALREADY = 7;
  51. __WASI_ERRNO_BADF = 8;
  52. __WASI_ERRNO_BADMSG = 9;
  53. __WASI_ERRNO_BUSY = 10;
  54. __WASI_ERRNO_CANCELED = 11;
  55. __WASI_ERRNO_CHILD = 12;
  56. __WASI_ERRNO_CONNABORTED = 13;
  57. __WASI_ERRNO_CONNREFUSED = 14;
  58. __WASI_ERRNO_CONNRESET = 15;
  59. __WASI_ERRNO_DEADLK = 16;
  60. __WASI_ERRNO_DESTADDRREQ = 17;
  61. __WASI_ERRNO_DOM = 18;
  62. __WASI_ERRNO_DQUOT = 19;
  63. __WASI_ERRNO_EXIST = 20;
  64. __WASI_ERRNO_FAULT = 21;
  65. __WASI_ERRNO_FBIG = 22;
  66. __WASI_ERRNO_HOSTUNREACH = 23;
  67. __WASI_ERRNO_IDRM = 24;
  68. __WASI_ERRNO_ILSEQ = 25;
  69. __WASI_ERRNO_INPROGRESS = 26;
  70. __WASI_ERRNO_INTR = 27;
  71. __WASI_ERRNO_INVAL = 28;
  72. __WASI_ERRNO_IO = 29;
  73. __WASI_ERRNO_ISCONN = 30;
  74. __WASI_ERRNO_ISDIR = 31;
  75. __WASI_ERRNO_LOOP = 32;
  76. __WASI_ERRNO_MFILE = 33;
  77. __WASI_ERRNO_MLINK = 34;
  78. __WASI_ERRNO_MSGSIZE = 35;
  79. __WASI_ERRNO_MULTIHOP = 36;
  80. __WASI_ERRNO_NAMETOOLONG = 37;
  81. __WASI_ERRNO_NETDOWN = 38;
  82. __WASI_ERRNO_NETRESET = 39;
  83. __WASI_ERRNO_NETUNREACH = 40;
  84. __WASI_ERRNO_NFILE = 41;
  85. __WASI_ERRNO_NOBUFS = 42;
  86. __WASI_ERRNO_NODEV = 43;
  87. __WASI_ERRNO_NOENT = 44;
  88. __WASI_ERRNO_NOEXEC = 45;
  89. __WASI_ERRNO_NOLCK = 46;
  90. __WASI_ERRNO_NOLINK = 47;
  91. __WASI_ERRNO_NOMEM = 48;
  92. __WASI_ERRNO_NOMSG = 49;
  93. __WASI_ERRNO_NOPROTOOPT = 50;
  94. __WASI_ERRNO_NOSPC = 51;
  95. __WASI_ERRNO_NOSYS = 52;
  96. __WASI_ERRNO_NOTCONN = 53;
  97. __WASI_ERRNO_NOTDIR = 54;
  98. __WASI_ERRNO_NOTEMPTY = 55;
  99. __WASI_ERRNO_NOTRECOVERABLE = 56;
  100. __WASI_ERRNO_NOTSOCK = 57;
  101. __WASI_ERRNO_NOTSUP = 58;
  102. __WASI_ERRNO_NOTTY = 59;
  103. __WASI_ERRNO_NXIO = 60;
  104. __WASI_ERRNO_OVERFLOW = 61;
  105. __WASI_ERRNO_OWNERDEAD = 62;
  106. __WASI_ERRNO_PERM = 63;
  107. __WASI_ERRNO_PIPE = 64;
  108. __WASI_ERRNO_PROTO = 65;
  109. __WASI_ERRNO_PROTONOSUPPORT = 66;
  110. __WASI_ERRNO_PROTOTYPE = 67;
  111. __WASI_ERRNO_RANGE = 68;
  112. __WASI_ERRNO_ROFS = 69;
  113. __WASI_ERRNO_SPIPE = 70;
  114. __WASI_ERRNO_SRCH = 71;
  115. __WASI_ERRNO_STALE = 72;
  116. __WASI_ERRNO_TIMEDOUT = 73;
  117. __WASI_ERRNO_TXTBSY = 74;
  118. __WASI_ERRNO_XDEV = 75;
  119. __WASI_ERRNO_NOTCAPABLE = 76;
  120. type
  121. P__wasi_iovec_t = ^__wasi_iovec_t;
  122. __wasi_iovec_t = record
  123. buf: PUInt8;
  124. buf_len: __wasi_size_t;
  125. end;
  126. P__wasi_ciovec_t = ^__wasi_ciovec_t;
  127. __wasi_ciovec_t = record
  128. buf: pointer;
  129. buf_len: __wasi_size_t;
  130. end;
  131. __wasi_exitcode_t = UInt32;
  132. __wasi_filetype_t = UInt8;
  133. const
  134. __WASI_FILETYPE_UNKNOWN = 0;
  135. __WASI_FILETYPE_BLOCK_DEVICE = 1;
  136. __WASI_FILETYPE_CHARACTER_DEVICE = 2;
  137. __WASI_FILETYPE_DIRECTORY = 3;
  138. __WASI_FILETYPE_REGULAR_FILE = 4;
  139. __WASI_FILETYPE_SOCKET_DGRAM = 5;
  140. __WASI_FILETYPE_SOCKET_STREAM = 6;
  141. __WASI_FILETYPE_SYMBOLIC_LINK = 7;
  142. type
  143. __wasi_fdflags_t = UInt16;
  144. const
  145. __WASI_FDFLAGS_APPEND = 1;
  146. __WASI_FDFLAGS_DSYNC = 2;
  147. __WASI_FDFLAGS_NONBLOCK = 4;
  148. __WASI_FDFLAGS_RSYNC = 8;
  149. __WASI_FDFLAGS_SYNC = 16;
  150. type
  151. __wasi_rights_t = UInt64;
  152. const
  153. __WASI_RIGHTS_FD_DATASYNC = 1;
  154. __WASI_RIGHTS_FD_READ = 2;
  155. __WASI_RIGHTS_FD_SEEK = 4;
  156. __WASI_RIGHTS_FD_FDSTAT_SET_FLAGS = 8;
  157. __WASI_RIGHTS_FD_SYNC = 16;
  158. __WASI_RIGHTS_FD_TELL = 32;
  159. __WASI_RIGHTS_FD_WRITE = 64;
  160. __WASI_RIGHTS_FD_ADVISE = 128;
  161. __WASI_RIGHTS_FD_ALLOCATE = 256;
  162. __WASI_RIGHTS_PATH_CREATE_DIRECTORY = 512;
  163. __WASI_RIGHTS_PATH_CREATE_FILE = 1024;
  164. __WASI_RIGHTS_PATH_LINK_SOURCE = 2048;
  165. __WASI_RIGHTS_PATH_LINK_TARGET = 4096;
  166. __WASI_RIGHTS_PATH_OPEN = 8192;
  167. __WASI_RIGHTS_FD_READDIR = 16384;
  168. __WASI_RIGHTS_PATH_READLINK = 32768;
  169. __WASI_RIGHTS_PATH_RENAME_SOURCE = 65536;
  170. __WASI_RIGHTS_PATH_RENAME_TARGET = 131072;
  171. __WASI_RIGHTS_PATH_FILESTAT_GET = 262144;
  172. __WASI_RIGHTS_PATH_FILESTAT_SET_SIZE = 524288;
  173. __WASI_RIGHTS_PATH_FILESTAT_SET_TIMES = 1048576;
  174. __WASI_RIGHTS_FD_FILESTAT_GET = 2097152;
  175. __WASI_RIGHTS_FD_FILESTAT_SET_SIZE = 4194304;
  176. __WASI_RIGHTS_FD_FILESTAT_SET_TIMES = 8388608;
  177. __WASI_RIGHTS_PATH_SYMLINK = 16777216;
  178. __WASI_RIGHTS_PATH_REMOVE_DIRECTORY = 33554432;
  179. __WASI_RIGHTS_PATH_UNLINK_FILE = 67108864;
  180. __WASI_RIGHTS_POLL_FD_READWRITE = 134217728;
  181. __WASI_RIGHTS_SOCK_SHUTDOWN = 268435456;
  182. type
  183. P__wasi_fdstat_t = ^__wasi_fdstat_t;
  184. __wasi_fdstat_t = record
  185. fs_filetype: __wasi_filetype_t;
  186. fs_flags: __wasi_fdflags_t;
  187. fs_rights_base: __wasi_rights_t;
  188. fs_rights_inheriting: __wasi_rights_t;
  189. end;
  190. function fd_write(fd: __wasi_fd_t;
  191. iovs: P__wasi_ciovec_t;
  192. iovs_len: size_t;
  193. nwritten: P__wasi_size_t): __wasi_errno_t; external 'wasi_snapshot_preview1';
  194. function fd_read(fd: __wasi_fd_t;
  195. iovs: P__wasi_iovec_t;
  196. iovs_len: size_t;
  197. nread: P__wasi_size_t): __wasi_errno_t; external 'wasi_snapshot_preview1';
  198. procedure proc_exit(rval: __wasi_exitcode_t); noreturn; external 'wasi_snapshot_preview1';
  199. function fd_fdstat_get(fd: __wasi_fd_t;
  200. stat: P__wasi_fdstat_t): __wasi_errno_t; external 'wasi_snapshot_preview1';
  201. {$I system.inc}
  202. function GetProcessID: SizeUInt;
  203. begin
  204. end;
  205. Procedure Randomize;
  206. Begin
  207. End;
  208. procedure System_exit;
  209. begin
  210. proc_exit(ExitCode);
  211. End;
  212. Function ParamCount: Longint;
  213. Begin
  214. End;
  215. function paramstr(l: longint) : string;
  216. begin
  217. end;
  218. procedure SysInitStdIO;
  219. begin
  220. OpenStdIO(Input,fmInput,StdInputHandle);
  221. OpenStdIO(Output,fmOutput,StdOutputHandle);
  222. OpenStdIO(ErrOutput,fmOutput,StdErrorHandle);
  223. OpenStdIO(StdOut,fmOutput,StdOutputHandle);
  224. OpenStdIO(StdErr,fmOutput,StdErrorHandle);
  225. end;
  226. function CheckInitialStkLen(stklen : SizeUInt) : SizeUInt;
  227. begin
  228. end;
  229. procedure DebugWrite(const P: PChar);
  230. var
  231. our_iov: __wasi_ciovec_t;
  232. our_nwritten: longint;
  233. begin
  234. our_iov.buf := P;
  235. our_iov.buf_len := StrLen(P);
  236. fd_write(1, @our_iov, 1, @our_nwritten);
  237. end;
  238. procedure DebugWriteLn(const P: PChar);
  239. begin
  240. DebugWrite(P);
  241. DebugWriteChar(#10);
  242. end;
  243. procedure DebugWriteChar(Ch: Char);
  244. var
  245. CharArr: array [0..1] of Char;
  246. begin
  247. CharArr[0] := Ch;
  248. CharArr[1] := #0;
  249. DebugWrite(@CharArr);
  250. end;
  251. procedure DebugWriteHexDigit(d: Byte);
  252. const
  253. HexDigits: array [0..15] of Char = '0123456789ABCDEF';
  254. begin
  255. DebugWriteChar(HexDigits[d]);
  256. end;
  257. procedure DebugWriteHexByte(b: Byte);
  258. begin
  259. DebugWriteHexDigit(b shr 4);
  260. DebugWriteHexDigit(b and 15);
  261. end;
  262. procedure DebugWriteHexWord(w: Word);
  263. begin
  264. DebugWriteHexByte(w shr 8);
  265. DebugWriteHexByte(Byte(w));
  266. end;
  267. procedure DebugWriteHexLongWord(lw: Word);
  268. begin
  269. DebugWriteHexWord(lw shr 16);
  270. DebugWriteHexWord(Word(lw));
  271. end;
  272. begin
  273. { To be set if this is a GUI or console application }
  274. IsConsole := TRUE;
  275. {$ifdef FPC_HAS_FEATURE_DYNLIBS}
  276. { If dynlibs feature is disabled,
  277. IsLibrary is a constant, which can thus not be set to a value }
  278. { To be set if this is a library and not a program }
  279. IsLibrary := FALSE;
  280. {$endif def FPC_HAS_FEATURE_DYNLIBS}
  281. { Setup heap }
  282. InitHeap;
  283. SysInitExceptions;
  284. initunicodestringmanager;
  285. { Setup stdin, stdout and stderr }
  286. SysInitStdIO;
  287. { Reset IO Error }
  288. InOutRes:=0;
  289. end.