sysos.inc 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  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 DosFreeModule (Handle: THandle): cardinal; cdecl;
  69. external 'DOSCALLS' index 322;
  70. function DosQueryModuleHandle (DLLName: PChar; var Handle: THandle): cardinal;
  71. cdecl;
  72. external 'DOSCALLS' index 319;
  73. function DosQueryProcAddr (Handle, Ordinal: cardinal; ProcName: PChar;
  74. var Address: pointer): cardinal; cdecl;
  75. external 'DOSCALLS' index 321;
  76. function DosSetRelMaxFH (var ReqCount: longint; var CurMaxFH: cardinal):
  77. cardinal; cdecl;
  78. external 'DOSCALLS' index 382;
  79. function DosSetCurrentDir (Name:PChar): cardinal; cdecl;
  80. external 'DOSCALLS' index 255;
  81. procedure DosQueryCurrentDisk(var DiskNum:cardinal;var Logical:cardinal); cdecl;
  82. external 'DOSCALLS' index 275;
  83. function DosSetDefaultDisk (DiskNum:cardinal): cardinal; cdecl;
  84. external 'DOSCALLS' index 220;
  85. { This is not real prototype, but is close enough }
  86. { for us (the 2nd parameter is actually a pointer }
  87. { to a structure). }
  88. function DosCreateDir (Name: PChar; P: pointer): cardinal; cdecl;
  89. external 'DOSCALLS' index 270;
  90. function DosDeleteDir (Name: PChar): cardinal; cdecl;
  91. external 'DOSCALLS' index 226;
  92. function DosQueryCurrentDir(DiskNum:cardinal;var Buffer;
  93. var BufLen:cardinal): cardinal; cdecl;
  94. external 'DOSCALLS' index 274;
  95. function DosMove(OldFile,NewFile:PChar):cardinal; cdecl;
  96. external 'DOSCALLS' index 271;
  97. function DosDelete(FileName:PChar):cardinal; cdecl;
  98. external 'DOSCALLS' index 259;
  99. procedure DosExit(Action, Result: cardinal); cdecl;
  100. external 'DOSCALLS' index 234;
  101. // EAs not used in System unit
  102. function DosOpen(FileName:PChar;var Handle: THandle;var Action:cardinal;
  103. InitSize,Attrib,OpenFlags,FileMode:cardinal;
  104. EA:Pointer): cardinal; cdecl;
  105. external 'DOSCALLS' index 273;
  106. function DosClose(Handle: THandle): cardinal; cdecl;
  107. external 'DOSCALLS' index 257;
  108. function DosRead(Handle: THandle; Buffer: Pointer; Count: cardinal;
  109. var ActCount: cardinal): cardinal; cdecl;
  110. external 'DOSCALLS' index 281;
  111. function DosWrite(Handle: THandle; Buffer: Pointer;Count: cardinal;
  112. var ActCount: cardinal): cardinal; cdecl;
  113. external 'DOSCALLS' index 282;
  114. function DosSetFilePtr(Handle: THandle; Pos:longint; Method:cardinal;
  115. var PosActual: cardinal): cardinal; cdecl;
  116. external 'DOSCALLS' index 256;
  117. function DosSetFileSize(Handle: THandle; Size: cardinal): cardinal; cdecl;
  118. external 'DOSCALLS' index 272;
  119. function DosQueryHType(Handle: THandle; var HandType: cardinal;
  120. var Attr: cardinal): cardinal; cdecl;
  121. external 'DOSCALLS' index 224;
  122. function DosQueryModuleName (Handle: THandle; NameLen: cardinal; Name: PChar):
  123. cardinal; cdecl;
  124. external 'DOSCALLS' index 320;
  125. function DosGetDateTime(var Buf:TSysDateTime): cardinal; cdecl;
  126. external 'DOSCALLS' index 230;
  127. {
  128. Already declared in interface part:
  129. type
  130. TDosOpenL = function (FileName: PChar; var Handle: THandle;
  131. var Action: cardinal; InitSize: int64;
  132. Attrib, OpenFlags, FileMode: cardinal;
  133. EA: pointer): cardinal; cdecl;
  134. TDosSetFilePtrL = function (Handle: THandle; Pos: int64; Method: cardinal;
  135. var PosActual: int64): cardinal; cdecl;
  136. TDosSetFileSizeL = function (Handle: THandle; Size: int64): cardinal; cdecl;
  137. }
  138. function DummyDosOpenL (FileName: PChar; var Handle: THandle;
  139. var Action: cardinal; InitSize: int64;
  140. Attrib, OpenFlags, FileMode: cardinal;
  141. EA: pointer): cardinal; cdecl;
  142. begin
  143. DummyDosOpenL := DosOpen (FileName, Handle, Action, InitSize, Attrib,
  144. OpenFlags, FileMode, EA);
  145. end;
  146. function DummyDosSetFilePtrL (Handle: THandle; Pos: int64; Method: cardinal;
  147. var PosActual: int64): cardinal; cdecl;
  148. var
  149. PosAct0: cardinal;
  150. begin
  151. DummyDosSetFilePtrL := DosSetFilePtr (Handle, Pos, Method, PosAct0);
  152. PosActual := PosAct0;
  153. end;
  154. function DummyDosSetFileSizeL (Handle: THandle; Size: int64): cardinal; cdecl;
  155. begin
  156. DummyDosSetFileSizeL := DosSetFileSize (Handle, Size);
  157. end;
  158. const
  159. OrdDosOpenL = 981;
  160. OrdDosSetFilePtrL = 988;
  161. OrdDosSetFileSizeL = 989;
  162. { converts an OS/2 error code to a TP compatible error }
  163. { code. Same thing exists under most other supported }
  164. { systems. }
  165. { Only call for OS/2 DLL imported routines }
  166. Procedure Errno2InOutRes;
  167. Begin
  168. { errors 1..18 are the same as in DOS }
  169. case InOutRes of
  170. { simple offset to convert these error codes }
  171. { exactly like the error codes in Win32 }
  172. 19..31 : InOutRes := InOutRes + 131;
  173. { gets a bit more complicated ... }
  174. 32..33 : InOutRes := 5;
  175. 38 : InOutRes := 100;
  176. 39 : InOutRes := 101;
  177. 112 : InOutRes := 101;
  178. 110 : InOutRes := 5;
  179. 114 : InOutRes := 6;
  180. 206 : InOutRes := 3; (* TH: Path too long *)
  181. 290 : InOutRes := 4;
  182. end;
  183. { all other cases ... we keep the same error code }
  184. end;
  185. (* Types and constants for exception handler support *)
  186. const
  187. deHardErr = 1; {Pop-ups for hard errors are enabled, to disable
  188. do not give this switch.}
  189. deDisableExceptions = 2; {Pop-ups for exceptions are disabled, to enable
  190. do not give this switch.}
  191. MaxExceptionParameters = 4; {Enough for all system exceptions.}
  192. Xcpt_Continue_Search = $00000000;
  193. Xcpt_Continue_Execution = $ffffffff;
  194. Xcpt_Continue_Stop = $00716668;
  195. Xcpt_Signal_Intr = 1;
  196. Xcpt_Signal_KillProc = 3;
  197. Xcpt_Signal_Break = 4;
  198. Xcpt_Fatal_Exception = $c0000000;
  199. Xcpt_Severity_Code = $c0000000;
  200. Xcpt_Customer_Code = $20000000;
  201. Xcpt_Facility_Code = $1fff0000;
  202. Xcpt_Exception_Code = $0000ffff;
  203. Xcpt_Unknown_Access = $00000000;
  204. Xcpt_Read_Access = $00000001;
  205. Xcpt_Write_Access = $00000002;
  206. Xcpt_Execute_Access = $00000004;
  207. Xcpt_Space_Access = $00000008;
  208. Xcpt_Limit_Access = $00000010;
  209. Xcpt_Data_Unknown = $ffffffff;
  210. Xcpt_Guard_Page_Violation = $80000001;
  211. Xcpt_Unable_To_Grow_Stack = $80010001;
  212. Xcpt_Access_Violation = $c0000005;
  213. Xcpt_In_Page_Error = $c0000006;
  214. Xcpt_Illegal_Instruction = $c000001c;
  215. Xcpt_Invalid_Lock_Sequence = $c000001d;
  216. Xcpt_Noncontinuable_Exception = $c0000024;
  217. Xcpt_Invalid_Disposition = $c0000025;
  218. Xcpt_Unwind = $c0000026;
  219. Xcpt_Bad_Stack = $c0000027;
  220. Xcpt_Invalid_Unwind_Target = $c0000028;
  221. Xcpt_Array_Bounds_Exceeded = $c0000093;
  222. Xcpt_Float_Denormal_Operand = $c0000094;
  223. Xcpt_Float_Divide_By_Zero = $c0000095;
  224. Xcpt_Float_Inexact_Result = $c0000096;
  225. Xcpt_Float_Invalid_Operation = $c0000097;
  226. Xcpt_Float_Overflow = $c0000098;
  227. Xcpt_Float_Stack_Check = $c0000099;
  228. Xcpt_Float_Underflow = $c000009a;
  229. Xcpt_Integer_Divide_By_Zero = $c000009b;
  230. Xcpt_Integer_Overflow = $c000009c;
  231. Xcpt_Privileged_Instruction = $c000009d;
  232. Xcpt_Datatype_Misalignment = $c000009e;
  233. Xcpt_Breakpoint = $c000009f;
  234. Xcpt_Single_Step = $c00000a0;
  235. Xcpt_Process_Terminate = $c0010001;
  236. Xcpt_Async_Process_Terminate = $c0010002;
  237. Xcpt_Signal = $c0010003;
  238. Context_Control = $00000001; { SS:ESP, CS:EIP, EFLAGS and EBP set }
  239. Context_Integer = $00000002; { EAX, EBX, ECX, EDX, ESI and EDI set }
  240. Context_Segments = $00000004; { DS, ES, FS, and GS set }
  241. Context_Floating_Point = $00000008; { numeric coprocessor state set }
  242. Context_Full = Context_Control or
  243. Context_Integer or
  244. Context_Segments or
  245. Context_Floating_Point;
  246. type
  247. PExceptionRegistrationRecord = ^TExceptionRegistrationRecord;
  248. PExceptionReportRecord = ^TExceptionReportRecord;
  249. PContextRecord = ^TContextRecord;
  250. TExceptionHandler = function (Report: PExceptionReportRecord;
  251. RegRec: PExceptionRegistrationRecord;
  252. Context: PContextRecord;
  253. DispContext: pointer): cardinal; cdecl;
  254. TExceptionRegistrationRecord = record
  255. Prev_Structure: PExceptionRegistrationRecord;
  256. ExceptionHandler: TExceptionHandler;
  257. end;
  258. TExceptionReportRecord = record
  259. Exception_Num,
  260. HandlerFlags: cardinal;
  261. Nested_RepRec: PExceptionReportRecord;
  262. Address: pointer;
  263. ParamCount: cardinal;
  264. Parameters: array [0..Pred (MaxExceptionParameters)] of cardinal;
  265. end;
  266. TContextRecord = packed record
  267. ContextFlags: cardinal;
  268. Env: array [1..7] of cardinal;
  269. FPUStack: array [0..7] of extended;
  270. Reg_GS,
  271. Reg_FS,
  272. Reg_ES,
  273. Reg_DS,
  274. Reg_EDI,
  275. Reg_ESI,
  276. Reg_EAX,
  277. Reg_EBX,
  278. Reg_ECX,
  279. Reg_EDX,
  280. Reg_EBP,
  281. Reg_EIP,
  282. Reg_CS,
  283. Flags,
  284. Reg_ESP,
  285. Reg_SS: cardinal;
  286. end;
  287. function DosSetExceptionHandler (var RegRec: TExceptionRegistrationRecord):
  288. cardinal; cdecl;
  289. external 'DOSCALLS' index 354;
  290. function DosUnsetExceptionHandler (var RegRec: TExceptionRegistrationRecord):
  291. cardinal; cdecl;
  292. external 'DOSCALLS' index 355;
  293. {Full screen applications can get Ctrl-C and Ctrl-Break focus. For all
  294. processes sharing one screen, only one can have Ctrl-C focus.
  295. Enable = 0 = Release focus, 1 = Get focus.
  296. Times = Number of times focus has been get minus number of times it
  297. has been released.}
  298. function DosSetSignalExceptionFocus (Enable: cardinal;
  299. var Times: cardinal): cardinal; cdecl;
  300. external 'DOSCALLS' index 378;
  301. {Tell we want further signal exceptions.
  302. SignalNum = Signal number to acknowlegde.}
  303. function DosAcknowledgeSignalException (SignalNum: cardinal): cardinal; cdecl;
  304. external 'DOSCALLS' index 418;
  305. function DosError (Error: cardinal): cardinal; cdecl;
  306. external 'DOSCALLS' index 212;
  307. type
  308. TWinMessageBox = function (Parent, Owner: cardinal;
  309. BoxText, BoxTitle: PChar; Identity, Style: cardinal): cardinal; cdecl;
  310. TWinInitialize = function (Options: cardinal): cardinal; cdecl;
  311. TWinCreateMsgQueue = function (Handle: cardinal; cmsg: longint): cardinal;
  312. cdecl;
  313. const
  314. ErrorBufferLength = 1024;
  315. mb_OK = $0000;
  316. mb_Error = $0040;
  317. mb_Moveable = $4000;
  318. MBStyle = mb_OK or mb_Error or mb_Moveable;
  319. mfPag_Read = $00001; {Give read access to memory.}
  320. mfPag_Write = $00002; {Give write access to memory.}
  321. mfPag_Execute = $00004; {Allow code execution in memory.}
  322. mfPag_Guard = $00008; {Used for dynamic memory growing. Create
  323. uncommitted memory and make the first
  324. page guarded. Once it is accessed it
  325. will be made committed, and the next
  326. uncommitted page will be made guarded.}
  327. mfPag_Commit = $00010; {Make the memory committed.}
  328. mfPag_Decommit = $00020; {Decommit the page.}
  329. mfObj_Tile = $00040; {Also allocate 16-bit segments of 64k
  330. which map the memory. (Makes 16<>32 bit
  331. pointer conversion possible.}
  332. mfObj_Protected = $00080;
  333. mfObj_Gettable = $00100;
  334. mfObj_Giveable = $00200;
  335. mfObj_Any = $00400; {Allow using high memory (> 512 MB).}
  336. mfPag_Default = $00400;
  337. mfPag_Shared = $02000;
  338. mfPag_Free = $04000;
  339. mfPag_Base = $10000;
  340. mfSub_Init = $00001; {Use base, if not set, choose a base
  341. address yourself.}
  342. mfSub_Grow = $00002; {Grow the specified heap, instead of
  343. allocating it. Ignore mfSub_Init.}
  344. mfSub_Sparse = $00004;
  345. mfSub_Serialize = $00008;
  346. function DosQueryMem (P: pointer; var Size, Flag: cardinal): cardinal; cdecl;
  347. external 'DOSCALLS' index 306;
  348. function DosQuerySysInfo (First, Last: cardinal; var Buf; BufSize: cardinal):
  349. cardinal; cdecl;
  350. external 'DOSCALLS' index 348;
  351. type
  352. TCPArray = array [0..2] of cardinal;
  353. PCPArray = ^TCPArray;
  354. function DosQueryCP (Size: cardinal; CodePages: PCPArray;
  355. var ActSize: cardinal): cardinal; cdecl;
  356. external 'DOSCALLS' index 291;
  357. function DosSetProcessCP (CP: cardinal): cardinal; cdecl;
  358. external 'DOSCALLS' index 289;
  359. type
  360. TCountryCode = record
  361. Country, {Country to query info about (0=current).}
  362. CodePage: cardinal; {Code page to query info about (0=current).}
  363. end;
  364. function DosMapCase (Size: cardinal; var Country: TCountryCode;
  365. AString: PChar): cardinal; cdecl;
  366. external 'NLS' index 7;
  367. function DosQueryDBCSEnv (Size: cardinal; var Country: TCountryCode;
  368. Buf: PChar): cardinal; cdecl;
  369. external 'NLS' index 6;
  370. function DosQueryCollate (Size: cardinal; var Country: TCountryCode;
  371. Buf: PByteArray; var TableLen: cardinal): cardinal; cdecl;
  372. external 'NLS' index 8;
  373. type
  374. TTimeFmt = (Clock12, Clock24);
  375. TCountryInfo = record
  376. Country, CodePage: cardinal; {Country and codepage requested.}
  377. DateFormat: cardinal; {1=ddmmyy 2=yymmdd 3=mmddyy}
  378. CurrencyUnit: array [0..4] of char;
  379. ThousandSeparator: char; {Thousands separator.}
  380. Zero1: byte; {Always zero.}
  381. DecimalSeparator: char; {Decimals separator,}
  382. Zero2: byte;
  383. DateSeparator: char; {Date separator.}
  384. Zero3: byte;
  385. TimeSeparator: char; {Time separator.}
  386. Zero4: byte;
  387. CurrencyFormat, {Bit field:
  388. Bit 0: 0=indicator before value
  389. 1=indicator after value
  390. Bit 1: 1=insert space after indicator.
  391. Bit 2: 1=Ignore bit 0&1, replace
  392. decimal separator with
  393. indicator.}
  394. DecimalPlace: byte; {Number of decimal places used in
  395. currency indication.}
  396. TimeFormat: TTimeFmt; {12/24 hour.}
  397. Reserve1: array [0..1] of word;
  398. DataSeparator: char; {Data list separator}
  399. Zero5: byte;
  400. Reserve2: array [0..4] of word;
  401. end;
  402. const
  403. CurrentCountry: TCountryCode = (Country: 0; CodePage: 0);
  404. function DosQueryCtryInfo (Size: cardinal; var Country: TCountryCode;
  405. var Res: TCountryInfo; var ActualSize: cardinal): cardinal; cdecl;
  406. external 'NLS' index 5;
  407. type
  408. PInsertTable = ^TInsertTable;
  409. TInsertTable = array [1..9] of PChar;
  410. function DosTrueGetMessage (MsgSeg: pointer; Table: PInsertTable;
  411. TableSize: cardinal; Buf: PChar;
  412. BufSize, MsgNumber: cardinal; FileName: PChar;
  413. var MsgSize: cardinal): cardinal; cdecl;
  414. external 'MSG' index 6;
  415. procedure MagicHeaderEnd; assembler; forward;
  416. {$ASMMODE INTEL}
  417. {start of _MSGSEG32 segment}
  418. procedure MagicHeaderStart; assembler;
  419. asm
  420. db $0FF
  421. db $4D,$53,$47,$53,$45,$47,$33,$32, 0 //'MSGSEG32'
  422. dd $8001
  423. dd MagicHeaderEnd
  424. end;
  425. function DosGetMessage (Table: PInsertTable; TableSize: cardinal; Buf: PChar;
  426. BufSize, MsgNumber: cardinal; FileName: PChar;
  427. var MsgSize: cardinal): cardinal; cdecl; assembler;
  428. nostackframe;
  429. asm
  430. pop eax
  431. push offset MagicHeaderStart
  432. push eax
  433. jmp DosTrueGetMessage
  434. end;
  435. procedure MagicHeaderEnd; assembler;
  436. asm
  437. dd $0FFFF0000
  438. end;
  439. {$ASMMODE DEFAULT}