2
0

sysos.inc 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2001 by Free Pascal development team
  4. This file implements all the base types and limits required
  5. for a minimal POSIX compliant subset required to port the compiler
  6. to a new OS.
  7. See the file COPYING.FPC, included in this distribution,
  8. for details about the copyright.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. **********************************************************************}
  13. type
  14. TByteArray = array [0..$FFFF] of byte;
  15. PByteArray = ^TByteArray;
  16. TSysThreadIB = record
  17. TID,
  18. Priority,
  19. Version: cardinal;
  20. MCCount,
  21. MCForceFlag: word;
  22. end;
  23. PSysThreadIB = ^TSysThreadIB;
  24. TThreadInfoBlock = record
  25. PExChain,
  26. Stack,
  27. StackLimit: pointer;
  28. TIB2: PSysThreadIB;
  29. Version,
  30. Ordinal: cardinal;
  31. end;
  32. PThreadInfoBlock = ^TThreadInfoBlock;
  33. PPThreadInfoBlock = ^PThreadInfoBlock;
  34. TProcessInfoBlock = record
  35. PID,
  36. ParentPid,
  37. Handle: cardinal;
  38. Cmd,
  39. Env: PByteArray;
  40. Status,
  41. ProcType: cardinal;
  42. end;
  43. PProcessInfoBlock = ^TProcessInfoBlock;
  44. PPProcessInfoBlock = ^PProcessInfoBlock;
  45. var
  46. ProcessID: SizeUInt;
  47. function GetProcessID:SizeUInt;
  48. begin
  49. GetProcessID := ProcessID;
  50. end;
  51. type
  52. TSysDateTime=packed record
  53. Hour,
  54. Minute,
  55. Second,
  56. Sec100,
  57. Day,
  58. Month: byte;
  59. Year: word;
  60. TimeZone: smallint;
  61. WeekDay: byte;
  62. end;
  63. procedure DosGetInfoBlocks (PATIB: PPThreadInfoBlock;
  64. PAPIB: PPProcessInfoBlock); cdecl;
  65. external 'DOSCALLS' index 312;
  66. function DosLoadModule (ObjName: PChar; ObjLen: cardinal; DLLName: PChar;
  67. var Handle: cardinal): cardinal; cdecl;
  68. external 'DOSCALLS' index 318;
  69. function DosQueryModuleHandle (DLLName: PChar; var Handle: THandle): cardinal;
  70. cdecl;
  71. external 'DOSCALLS' index 319;
  72. function DosQueryProcAddr (Handle, Ordinal: cardinal; ProcName: PChar;
  73. var Address: pointer): cardinal; cdecl;
  74. external 'DOSCALLS' index 321;
  75. function DosSetRelMaxFH (var ReqCount: longint; var CurMaxFH: cardinal):
  76. cardinal; cdecl;
  77. external 'DOSCALLS' index 382;
  78. function DosSetCurrentDir (Name:PChar): cardinal; cdecl;
  79. external 'DOSCALLS' index 255;
  80. procedure DosQueryCurrentDisk(var DiskNum:cardinal;var Logical:cardinal); cdecl;
  81. external 'DOSCALLS' index 275;
  82. function DosSetDefaultDisk (DiskNum:cardinal): cardinal; cdecl;
  83. external 'DOSCALLS' index 220;
  84. { This is not real prototype, but is close enough }
  85. { for us (the 2nd parameter is actually a pointer }
  86. { to a structure). }
  87. function DosCreateDir (Name: PChar; P: pointer): cardinal; cdecl;
  88. external 'DOSCALLS' index 270;
  89. function DosDeleteDir (Name: PChar): cardinal; cdecl;
  90. external 'DOSCALLS' index 226;
  91. function DosQueryCurrentDir(DiskNum:cardinal;var Buffer;
  92. var BufLen:cardinal): cardinal; cdecl;
  93. external 'DOSCALLS' index 274;
  94. function DosMove(OldFile,NewFile:PChar):cardinal; cdecl;
  95. external 'DOSCALLS' index 271;
  96. function DosDelete(FileName:PChar):cardinal; cdecl;
  97. external 'DOSCALLS' index 259;
  98. procedure DosExit(Action, Result: cardinal); cdecl;
  99. external 'DOSCALLS' index 234;
  100. // EAs not used in System unit
  101. function DosOpen(FileName:PChar;var Handle: THandle;var Action:cardinal;
  102. InitSize,Attrib,OpenFlags,FileMode:cardinal;
  103. EA:Pointer): cardinal; cdecl;
  104. external 'DOSCALLS' index 273;
  105. function DosClose(Handle: THandle): cardinal; cdecl;
  106. external 'DOSCALLS' index 257;
  107. function DosRead(Handle: THandle; Buffer: Pointer; Count: cardinal;
  108. var ActCount: cardinal): cardinal; cdecl;
  109. external 'DOSCALLS' index 281;
  110. function DosWrite(Handle: THandle; Buffer: Pointer;Count: cardinal;
  111. var ActCount: cardinal): cardinal; cdecl;
  112. external 'DOSCALLS' index 282;
  113. function DosSetFilePtr(Handle: THandle; Pos:longint; Method:cardinal;
  114. var PosActual: cardinal): cardinal; cdecl;
  115. external 'DOSCALLS' index 256;
  116. function DosSetFileSize(Handle: THandle; Size: cardinal): cardinal; cdecl;
  117. external 'DOSCALLS' index 272;
  118. function DosQueryHType(Handle: THandle; var HandType: cardinal;
  119. var Attr: cardinal): cardinal; cdecl;
  120. external 'DOSCALLS' index 224;
  121. function DosQueryModuleName (Handle: THandle; NameLen: cardinal; Name: PChar):
  122. cardinal; cdecl;
  123. external 'DOSCALLS' index 320;
  124. function DosGetDateTime(var Buf:TSysDateTime): cardinal; cdecl;
  125. external 'DOSCALLS' index 230;
  126. {
  127. Already declared in interface part:
  128. type
  129. TDosOpenL = function (FileName: PChar; var Handle: THandle;
  130. var Action: cardinal; InitSize: int64;
  131. Attrib, OpenFlags, FileMode: cardinal;
  132. EA: pointer): cardinal; cdecl;
  133. TDosSetFilePtrL = function (Handle: THandle; Pos: int64; Method: cardinal;
  134. var PosActual: int64): cardinal; cdecl;
  135. TDosSetFileSizeL = function (Handle: THandle; Size: int64): cardinal; cdecl;
  136. }
  137. function DummyDosOpenL (FileName: PChar; var Handle: THandle;
  138. var Action: cardinal; InitSize: int64;
  139. Attrib, OpenFlags, FileMode: cardinal;
  140. EA: pointer): cardinal; cdecl;
  141. begin
  142. DummyDosOpenL := DosOpen (FileName, Handle, Action, InitSize, Attrib,
  143. OpenFlags, FileMode, EA);
  144. end;
  145. function DummyDosSetFilePtrL (Handle: THandle; Pos: int64; Method: cardinal;
  146. var PosActual: int64): cardinal; cdecl;
  147. var
  148. PosAct0: cardinal;
  149. begin
  150. DummyDosSetFilePtrL := DosSetFilePtr (Handle, Pos, Method, PosAct0);
  151. PosActual := PosAct0;
  152. end;
  153. function DummyDosSetFileSizeL (Handle: THandle; Size: int64): cardinal; cdecl;
  154. begin
  155. DummyDosSetFileSizeL := DosSetFileSize (Handle, Size);
  156. end;
  157. const
  158. OrdDosOpenL = 981;
  159. OrdDosSetFilePtrL = 988;
  160. OrdDosSetFileSizeL = 989;
  161. { converts an OS/2 error code to a TP compatible error }
  162. { code. Same thing exists under most other supported }
  163. { systems. }
  164. { Only call for OS/2 DLL imported routines }
  165. Procedure Errno2InOutRes;
  166. Begin
  167. { errors 1..18 are the same as in DOS }
  168. case InOutRes of
  169. { simple offset to convert these error codes }
  170. { exactly like the error codes in Win32 }
  171. 19..31 : InOutRes := InOutRes + 131;
  172. { gets a bit more complicated ... }
  173. 32..33 : InOutRes := 5;
  174. 38 : InOutRes := 100;
  175. 39 : InOutRes := 101;
  176. 112 : InOutRes := 101;
  177. 110 : InOutRes := 5;
  178. 114 : InOutRes := 6;
  179. 290 : InOutRes := 290;
  180. end;
  181. { all other cases ... we keep the same error code }
  182. end;
  183. (* Types and constants for exception handler support *)
  184. const
  185. deHardErr = 1; {Pop-ups for hard errors are enabled, to disable
  186. do not give this switch.}
  187. deDisableExceptions = 2; {Pop-ups for exceptions are disabled, to enable
  188. do not give this switch.}
  189. MaxExceptionParameters = 4; {Enough for all system exceptions.}
  190. Xcpt_Continue_Search = $00000000;
  191. Xcpt_Continue_Execution = $ffffffff;
  192. Xcpt_Continue_Stop = $00716668;
  193. Xcpt_Signal_Intr = 1;
  194. Xcpt_Signal_KillProc = 3;
  195. Xcpt_Signal_Break = 4;
  196. Xcpt_Fatal_Exception = $c0000000;
  197. Xcpt_Severity_Code = $c0000000;
  198. Xcpt_Customer_Code = $20000000;
  199. Xcpt_Facility_Code = $1fff0000;
  200. Xcpt_Exception_Code = $0000ffff;
  201. Xcpt_Unknown_Access = $00000000;
  202. Xcpt_Read_Access = $00000001;
  203. Xcpt_Write_Access = $00000002;
  204. Xcpt_Execute_Access = $00000004;
  205. Xcpt_Space_Access = $00000008;
  206. Xcpt_Limit_Access = $00000010;
  207. Xcpt_Data_Unknown = $ffffffff;
  208. Xcpt_Guard_Page_Violation = $80000001;
  209. Xcpt_Unable_To_Grow_Stack = $80010001;
  210. Xcpt_Access_Violation = $c0000005;
  211. Xcpt_In_Page_Error = $c0000006;
  212. Xcpt_Illegal_Instruction = $c000001c;
  213. Xcpt_Invalid_Lock_Sequence = $c000001d;
  214. Xcpt_Noncontinuable_Exception = $c0000024;
  215. Xcpt_Invalid_Disposition = $c0000025;
  216. Xcpt_Unwind = $c0000026;
  217. Xcpt_Bad_Stack = $c0000027;
  218. Xcpt_Invalid_Unwind_Target = $c0000028;
  219. Xcpt_Array_Bounds_Exceeded = $c0000093;
  220. Xcpt_Float_Denormal_Operand = $c0000094;
  221. Xcpt_Float_Divide_By_Zero = $c0000095;
  222. Xcpt_Float_Inexact_Result = $c0000096;
  223. Xcpt_Float_Invalid_Operation = $c0000097;
  224. Xcpt_Float_Overflow = $c0000098;
  225. Xcpt_Float_Stack_Check = $c0000099;
  226. Xcpt_Float_Underflow = $c000009a;
  227. Xcpt_Integer_Divide_By_Zero = $c000009b;
  228. Xcpt_Integer_Overflow = $c000009c;
  229. Xcpt_Privileged_Instruction = $c000009d;
  230. Xcpt_Datatype_Misalignment = $c000009e;
  231. Xcpt_Breakpoint = $c000009f;
  232. Xcpt_Single_Step = $c00000a0;
  233. Xcpt_Process_Terminate = $c0010001;
  234. Xcpt_Async_Process_Terminate = $c0010002;
  235. Xcpt_Signal = $c0010003;
  236. Context_Control = $00000001; { SS:ESP, CS:EIP, EFLAGS and EBP set }
  237. Context_Integer = $00000002; { EAX, EBX, ECX, EDX, ESI and EDI set }
  238. Context_Segments = $00000004; { DS, ES, FS, and GS set }
  239. Context_Floating_Point = $00000008; { numeric coprocessor state set }
  240. Context_Full = Context_Control or
  241. Context_Integer or
  242. Context_Segments or
  243. Context_Floating_Point;
  244. type
  245. PExceptionRegistrationRecord = ^TExceptionRegistrationRecord;
  246. PExceptionReportRecord = ^TExceptionReportRecord;
  247. PContextRecord = ^TContextRecord;
  248. TExceptionHandler = function (Report: PExceptionReportRecord;
  249. RegRec: PExceptionRegistrationRecord;
  250. Context: PContextRecord;
  251. DispContext: pointer): cardinal; cdecl;
  252. TExceptionRegistrationRecord = record
  253. Prev_Structure: PExceptionRegistrationRecord;
  254. ExceptionHandler: TExceptionHandler;
  255. end;
  256. TExceptionReportRecord = record
  257. Exception_Num,
  258. HandlerFlags: cardinal;
  259. Nested_RepRec: PExceptionReportRecord;
  260. Address: pointer;
  261. ParamCount: cardinal;
  262. Parameters: array [0..MaxExceptionParameters] of cardinal;
  263. end;
  264. TContextRecord = packed record
  265. ContextFlags: cardinal;
  266. Env: array [1..7] of cardinal;
  267. FPUStack: array [0..7] of extended;
  268. Reg_GS,
  269. Reg_FS,
  270. Reg_ES,
  271. Reg_DS,
  272. Reg_EDI,
  273. Reg_ESI,
  274. Reg_EAX,
  275. Reg_EBX,
  276. Reg_ECX,
  277. Reg_EDX,
  278. Reg_EBP,
  279. Reg_EIP,
  280. Reg_CS,
  281. Flags,
  282. Reg_ESP,
  283. Reg_SS: cardinal;
  284. end;
  285. function DosSetExceptionHandler (var RegRec: TExceptionRegistrationRecord):
  286. cardinal; cdecl;
  287. external 'DOSCALLS' index 354;
  288. function DosUnsetExceptionHandler (var RegRec: TExceptionRegistrationRecord):
  289. cardinal; cdecl;
  290. external 'DOSCALLS' index 355;
  291. {Full screen applications can get Ctrl-C and Ctrl-Break focus. For all
  292. processes sharing one screen, only one can have Ctrl-C focus.
  293. Enable = 0 = Release focus, 1 = Get focus.
  294. Times = Number of times focus has been get minus number of times it
  295. has been released.}
  296. function DosSetSignalExceptionFocus (Enable: cardinal;
  297. var Times: cardinal): cardinal; cdecl;
  298. external 'DOSCALLS' index 378;
  299. {Tell we want further signal exceptions.
  300. SignalNum = Signal number to acknowlegde.}
  301. function DosAcknowledgeSignalException (SignalNum: cardinal): cardinal; cdecl;
  302. external 'DOSCALLS' index 418;
  303. function DosError (Error: cardinal): cardinal; cdecl;
  304. external 'DOSCALLS' index 212;
  305. type
  306. TWinMessageBox = function (Parent, Owner: cardinal;
  307. BoxText, BoxTitle: PChar; Identity, Style: cardinal): cardinal; cdecl;
  308. TWinInitialize = function (Options: cardinal): cardinal; cdecl;
  309. TWinCreateMsgQueue = function (Handle: cardinal; cmsg: longint): cardinal;
  310. cdecl;
  311. const
  312. ErrorBufferLength = 1024;
  313. mb_OK = $0000;
  314. mb_Error = $0040;
  315. mb_Moveable = $4000;
  316. MBStyle = mb_OK or mb_Error or mb_Moveable;
  317. mfPag_Read = $00001; {Give read access to memory.}
  318. mfPag_Write = $00002; {Give write access to memory.}
  319. mfPag_Execute = $00004; {Allow code execution in memory.}
  320. mfPag_Guard = $00008; {Used for dynamic memory growing. Create
  321. uncommitted memory and make the first
  322. page guarded. Once it is accessed it
  323. will be made committed, and the next
  324. uncommitted page will be made guarded.}
  325. mfPag_Commit = $00010; {Make the memory committed.}
  326. mfPag_Decommit = $00020; {Decommit the page.}
  327. mfObj_Tile = $00040; {Also allocate 16-bit segments of 64k
  328. which map the memory. (Makes 16<>32 bit
  329. pointer conversion possible.}
  330. mfObj_Protected = $00080;
  331. mfObj_Gettable = $00100;
  332. mfObj_Giveable = $00200;
  333. mfObj_Any = $00400; {Allow using high memory (> 512 MB).}
  334. mfPag_Default = $00400;
  335. mfPag_Shared = $02000;
  336. mfPag_Free = $04000;
  337. mfPag_Base = $10000;
  338. mfSub_Init = $00001; {Use base, if not set, choose a base
  339. address yourself.}
  340. mfSub_Grow = $00002; {Grow the specified heap, instead of
  341. allocating it. Ignore mfSub_Init.}
  342. mfSub_Sparse = $00004;
  343. mfSub_Serialize = $00008;
  344. function DosQueryMem (P: pointer; var Size, Flag: cardinal): cardinal; cdecl;
  345. external 'DOSCALLS' index 306;