sysos.inc 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2001-2015 by Free Pascal development team
  4. This file contains a subset of OS/2 base types and imported OS/2 API
  5. functions necessary for implementation of unit system.
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. type
  13. TByteArray = array [0..$FFFF] of byte;
  14. PByteArray = ^TByteArray;
  15. TSysThreadIB = record
  16. TID,
  17. Priority,
  18. Version: cardinal;
  19. MCCount,
  20. MCForceFlag: word;
  21. end;
  22. PSysThreadIB = ^TSysThreadIB;
  23. TThreadInfoBlock = record
  24. PExChain,
  25. Stack,
  26. StackLimit: pointer;
  27. TIB2: PSysThreadIB;
  28. Version,
  29. Ordinal: cardinal;
  30. end;
  31. PThreadInfoBlock = ^TThreadInfoBlock;
  32. PPThreadInfoBlock = ^PThreadInfoBlock;
  33. TProcessInfoBlock = record
  34. PID,
  35. ParentPid,
  36. Handle: cardinal;
  37. Cmd,
  38. Env: PByteArray;
  39. Status,
  40. ProcType: cardinal;
  41. end;
  42. PProcessInfoBlock = ^TProcessInfoBlock;
  43. PPProcessInfoBlock = ^PProcessInfoBlock;
  44. var
  45. ProcessID: SizeUInt;
  46. function GetProcessID: SizeUInt;
  47. begin
  48. GetProcessID := ProcessID;
  49. end;
  50. type
  51. TSysDateTime=packed record
  52. Hour,
  53. Minute,
  54. Second,
  55. Sec100,
  56. Day,
  57. Month: byte;
  58. Year: word;
  59. TimeZone: smallint;
  60. WeekDay: byte;
  61. end;
  62. procedure DosGetInfoBlocks (PATIB: PPThreadInfoBlock;
  63. PAPIB: PPProcessInfoBlock); cdecl;
  64. external 'DOSCALLS' index 312;
  65. function DosLoadModule (ObjName: PChar; ObjLen: cardinal; DLLName: PChar;
  66. var Handle: THandle): cardinal; cdecl;
  67. external 'DOSCALLS' index 318;
  68. function DosQueryModuleHandle (DLLName: PChar; var Handle: THandle): cardinal;
  69. cdecl;
  70. external 'DOSCALLS' index 319;
  71. function DosQueryProcAddr (Handle, Ordinal: cardinal; ProcName: PChar;
  72. var Address: pointer): cardinal; cdecl;
  73. external 'DOSCALLS' index 321;
  74. function DosSetRelMaxFH (var ReqCount: longint; var CurMaxFH: cardinal):
  75. cardinal; cdecl;
  76. external 'DOSCALLS' index 382;
  77. function DosSetCurrentDir (Name:PChar): cardinal; cdecl;
  78. external 'DOSCALLS' index 255;
  79. procedure DosQueryCurrentDisk(var DiskNum:cardinal;var Logical:cardinal); cdecl;
  80. external 'DOSCALLS' index 275;
  81. function DosSetDefaultDisk (DiskNum:cardinal): cardinal; cdecl;
  82. external 'DOSCALLS' index 220;
  83. { This is not real prototype, but is close enough }
  84. { for us (the 2nd parameter is actually a pointer }
  85. { to a structure). }
  86. function DosCreateDir (Name: PChar; P: pointer): cardinal; cdecl;
  87. external 'DOSCALLS' index 270;
  88. function DosDeleteDir (Name: PChar): cardinal; cdecl;
  89. external 'DOSCALLS' index 226;
  90. function DosQueryCurrentDir(DiskNum:cardinal;var Buffer;
  91. var BufLen:cardinal): cardinal; cdecl;
  92. external 'DOSCALLS' index 274;
  93. function DosMove(OldFile,NewFile:PChar):cardinal; cdecl;
  94. external 'DOSCALLS' index 271;
  95. function DosDelete(FileName:PChar):cardinal; cdecl;
  96. external 'DOSCALLS' index 259;
  97. procedure DosExit(Action, Result: cardinal); cdecl;
  98. external 'DOSCALLS' index 234;
  99. // EAs not used in System unit
  100. function DosOpen(FileName:PChar;var Handle: THandle;var Action:cardinal;
  101. InitSize,Attrib,OpenFlags,FileMode:cardinal;
  102. EA:Pointer): cardinal; cdecl;
  103. external 'DOSCALLS' index 273;
  104. function DosClose(Handle: THandle): cardinal; cdecl;
  105. external 'DOSCALLS' index 257;
  106. function DosRead(Handle: THandle; Buffer: Pointer; Count: cardinal;
  107. var ActCount: cardinal): cardinal; cdecl;
  108. external 'DOSCALLS' index 281;
  109. function DosWrite(Handle: THandle; Buffer: Pointer;Count: cardinal;
  110. var ActCount: cardinal): cardinal; cdecl;
  111. external 'DOSCALLS' index 282;
  112. function DosSetFilePtr(Handle: THandle; Pos:longint; Method:cardinal;
  113. var PosActual: cardinal): cardinal; cdecl;
  114. external 'DOSCALLS' index 256;
  115. function DosSetFileSize(Handle: THandle; Size: cardinal): cardinal; cdecl;
  116. external 'DOSCALLS' index 272;
  117. function DosQueryHType(Handle: THandle; var HandType: cardinal;
  118. var Attr: cardinal): cardinal; cdecl;
  119. external 'DOSCALLS' index 224;
  120. function DosQueryModuleName (Handle: THandle; NameLen: cardinal; Name: PChar):
  121. cardinal; cdecl;
  122. external 'DOSCALLS' index 320;
  123. function DosGetDateTime(var Buf:TSysDateTime): cardinal; cdecl;
  124. external 'DOSCALLS' index 230;
  125. {
  126. Already declared in interface part:
  127. type
  128. TDosOpenL = function (FileName: PChar; var Handle: THandle;
  129. var Action: cardinal; InitSize: int64;
  130. Attrib, OpenFlags, FileMode: cardinal;
  131. EA: pointer): cardinal; cdecl;
  132. TDosSetFilePtrL = function (Handle: THandle; Pos: int64; Method: cardinal;
  133. var PosActual: int64): cardinal; cdecl;
  134. TDosSetFileSizeL = function (Handle: THandle; Size: int64): cardinal; cdecl;
  135. }
  136. function DummyDosOpenL (FileName: PChar; var Handle: THandle;
  137. var Action: cardinal; InitSize: int64;
  138. Attrib, OpenFlags, FileMode: cardinal;
  139. EA: pointer): cardinal; cdecl;
  140. begin
  141. DummyDosOpenL := DosOpen (FileName, Handle, Action, InitSize, Attrib,
  142. OpenFlags, FileMode, EA);
  143. end;
  144. function DummyDosSetFilePtrL (Handle: THandle; Pos: int64; Method: cardinal;
  145. var PosActual: int64): cardinal; cdecl;
  146. var
  147. PosAct0: cardinal;
  148. begin
  149. DummyDosSetFilePtrL := DosSetFilePtr (Handle, Pos, Method, PosAct0);
  150. PosActual := PosAct0;
  151. end;
  152. function DummyDosSetFileSizeL (Handle: THandle; Size: int64): cardinal; cdecl;
  153. begin
  154. DummyDosSetFileSizeL := DosSetFileSize (Handle, Size);
  155. end;
  156. const
  157. OrdDosOpenL = 981;
  158. OrdDosSetFilePtrL = 988;
  159. OrdDosSetFileSizeL = 989;
  160. { converts an OS/2 error code to a TP compatible error }
  161. { code. Same thing exists under most other supported }
  162. { systems. }
  163. { Only call for OS/2 DLL imported routines }
  164. Procedure Errno2InOutRes;
  165. Begin
  166. { errors 1..18 are the same as in DOS }
  167. case InOutRes of
  168. { simple offset to convert these error codes }
  169. { exactly like the error codes in Win32 }
  170. 19..31 : InOutRes := InOutRes + 131;
  171. { gets a bit more complicated ... }
  172. 32..33 : InOutRes := 5;
  173. 38 : InOutRes := 100;
  174. 39 : InOutRes := 101;
  175. 112 : InOutRes := 101;
  176. 110 : InOutRes := 5;
  177. 114 : InOutRes := 6;
  178. 206 : InOutRes := 3; (* TH: Path too long *)
  179. 290 : InOutRes := 4;
  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..Pred (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;
  346. function DosQuerySysInfo (First, Last: cardinal; var Buf; BufSize: cardinal):
  347. cardinal; cdecl;
  348. external 'DOSCALLS' index 348;
  349. type
  350. TCPArray = array [0..2] of cardinal;
  351. PCPArray = ^TCPArray;
  352. function DosQueryCP (Size: cardinal; CodePages: PCPArray;
  353. var ActSize: cardinal): cardinal; cdecl;
  354. external 'DOSCALLS' index 291;
  355. function DosSetProcessCP (CP: cardinal): cardinal; cdecl;
  356. external 'DOSCALLS' index 289;
  357. type
  358. TCountryCode = record
  359. Country, {Country to query info about (0=current).}
  360. CodePage: cardinal; {Code page to query info about (0=current).}
  361. end;
  362. function DosMapCase (Size: cardinal; var Country: TCountryCode;
  363. AString: PChar): cardinal; cdecl;
  364. external 'NLS' index 7;
  365. function DosQueryDBCSEnv (Size: cardinal; var Country: TCountryCode;
  366. Buf: PChar): cardinal; cdecl;
  367. external 'NLS' index 6;
  368. function DosQueryCollate (Size: cardinal; var Country: TCountryCode;
  369. Buf: PByteArray; var TableLen: cardinal): cardinal; cdecl;
  370. external 'NLS' index 8;
  371. type
  372. TTimeFmt = (Clock12, Clock24);
  373. TCountryInfo = record
  374. Country, CodePage: cardinal; {Country and codepage requested.}
  375. DateFormat: cardinal; {1=ddmmyy 2=yymmdd 3=mmddyy}
  376. CurrencyUnit: array [0..4] of char;
  377. ThousandSeparator: char; {Thousands separator.}
  378. Zero1: byte; {Always zero.}
  379. DecimalSeparator: char; {Decimals separator,}
  380. Zero2: byte;
  381. DateSeparator: char; {Date separator.}
  382. Zero3: byte;
  383. TimeSeparator: char; {Time separator.}
  384. Zero4: byte;
  385. CurrencyFormat, {Bit field:
  386. Bit 0: 0=indicator before value
  387. 1=indicator after value
  388. Bit 1: 1=insert space after indicator.
  389. Bit 2: 1=Ignore bit 0&1, replace
  390. decimal separator with
  391. indicator.}
  392. DecimalPlace: byte; {Number of decimal places used in
  393. currency indication.}
  394. TimeFormat: TTimeFmt; {12/24 hour.}
  395. Reserve1: array [0..1] of word;
  396. DataSeparator: char; {Data list separator}
  397. Zero5: byte;
  398. Reserve2: array [0..4] of word;
  399. end;
  400. const
  401. CurrentCountry: TCountryCode = (Country: 0; CodePage: 0);
  402. function DosQueryCtryInfo (Size: cardinal; var Country: TCountryCode;
  403. var Res: TCountryInfo; var ActualSize: cardinal): cardinal; cdecl;
  404. external 'NLS' index 5;