sysos.inc 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531
  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. 290 : InOutRes := 290;
  181. end;
  182. { all other cases ... we keep the same error code }
  183. end;
  184. (* Types and constants for exception handler support *)
  185. const
  186. deHardErr = 1; {Pop-ups for hard errors are enabled, to disable
  187. do not give this switch.}
  188. deDisableExceptions = 2; {Pop-ups for exceptions are disabled, to enable
  189. do not give this switch.}
  190. MaxExceptionParameters = 4; {Enough for all system exceptions.}
  191. Xcpt_Continue_Search = $00000000;
  192. Xcpt_Continue_Execution = $ffffffff;
  193. Xcpt_Continue_Stop = $00716668;
  194. Xcpt_Signal_Intr = 1;
  195. Xcpt_Signal_KillProc = 3;
  196. Xcpt_Signal_Break = 4;
  197. Xcpt_Fatal_Exception = $c0000000;
  198. Xcpt_Severity_Code = $c0000000;
  199. Xcpt_Customer_Code = $20000000;
  200. Xcpt_Facility_Code = $1fff0000;
  201. Xcpt_Exception_Code = $0000ffff;
  202. Xcpt_Unknown_Access = $00000000;
  203. Xcpt_Read_Access = $00000001;
  204. Xcpt_Write_Access = $00000002;
  205. Xcpt_Execute_Access = $00000004;
  206. Xcpt_Space_Access = $00000008;
  207. Xcpt_Limit_Access = $00000010;
  208. Xcpt_Data_Unknown = $ffffffff;
  209. Xcpt_Guard_Page_Violation = $80000001;
  210. Xcpt_Unable_To_Grow_Stack = $80010001;
  211. Xcpt_Access_Violation = $c0000005;
  212. Xcpt_In_Page_Error = $c0000006;
  213. Xcpt_Illegal_Instruction = $c000001c;
  214. Xcpt_Invalid_Lock_Sequence = $c000001d;
  215. Xcpt_Noncontinuable_Exception = $c0000024;
  216. Xcpt_Invalid_Disposition = $c0000025;
  217. Xcpt_Unwind = $c0000026;
  218. Xcpt_Bad_Stack = $c0000027;
  219. Xcpt_Invalid_Unwind_Target = $c0000028;
  220. Xcpt_Array_Bounds_Exceeded = $c0000093;
  221. Xcpt_Float_Denormal_Operand = $c0000094;
  222. Xcpt_Float_Divide_By_Zero = $c0000095;
  223. Xcpt_Float_Inexact_Result = $c0000096;
  224. Xcpt_Float_Invalid_Operation = $c0000097;
  225. Xcpt_Float_Overflow = $c0000098;
  226. Xcpt_Float_Stack_Check = $c0000099;
  227. Xcpt_Float_Underflow = $c000009a;
  228. Xcpt_Integer_Divide_By_Zero = $c000009b;
  229. Xcpt_Integer_Overflow = $c000009c;
  230. Xcpt_Privileged_Instruction = $c000009d;
  231. Xcpt_Datatype_Misalignment = $c000009e;
  232. Xcpt_Breakpoint = $c000009f;
  233. Xcpt_Single_Step = $c00000a0;
  234. Xcpt_Process_Terminate = $c0010001;
  235. Xcpt_Async_Process_Terminate = $c0010002;
  236. Xcpt_Signal = $c0010003;
  237. Context_Control = $00000001; { SS:ESP, CS:EIP, EFLAGS and EBP set }
  238. Context_Integer = $00000002; { EAX, EBX, ECX, EDX, ESI and EDI set }
  239. Context_Segments = $00000004; { DS, ES, FS, and GS set }
  240. Context_Floating_Point = $00000008; { numeric coprocessor state set }
  241. Context_Full = Context_Control or
  242. Context_Integer or
  243. Context_Segments or
  244. Context_Floating_Point;
  245. type
  246. PExceptionRegistrationRecord = ^TExceptionRegistrationRecord;
  247. PExceptionReportRecord = ^TExceptionReportRecord;
  248. PContextRecord = ^TContextRecord;
  249. TExceptionHandler = function (Report: PExceptionReportRecord;
  250. RegRec: PExceptionRegistrationRecord;
  251. Context: PContextRecord;
  252. DispContext: pointer): cardinal; cdecl;
  253. TExceptionRegistrationRecord = record
  254. Prev_Structure: PExceptionRegistrationRecord;
  255. ExceptionHandler: TExceptionHandler;
  256. end;
  257. TExceptionReportRecord = record
  258. Exception_Num,
  259. HandlerFlags: cardinal;
  260. Nested_RepRec: PExceptionReportRecord;
  261. Address: pointer;
  262. ParamCount: cardinal;
  263. Parameters: array [0..MaxExceptionParameters] of cardinal;
  264. end;
  265. TContextRecord = packed record
  266. ContextFlags: cardinal;
  267. Env: array [1..7] of cardinal;
  268. FPUStack: array [0..7] of extended;
  269. Reg_GS,
  270. Reg_FS,
  271. Reg_ES,
  272. Reg_DS,
  273. Reg_EDI,
  274. Reg_ESI,
  275. Reg_EAX,
  276. Reg_EBX,
  277. Reg_ECX,
  278. Reg_EDX,
  279. Reg_EBP,
  280. Reg_EIP,
  281. Reg_CS,
  282. Flags,
  283. Reg_ESP,
  284. Reg_SS: cardinal;
  285. end;
  286. function DosSetExceptionHandler (var RegRec: TExceptionRegistrationRecord):
  287. cardinal; cdecl;
  288. external 'DOSCALLS' index 354;
  289. function DosUnsetExceptionHandler (var RegRec: TExceptionRegistrationRecord):
  290. cardinal; cdecl;
  291. external 'DOSCALLS' index 355;
  292. {Full screen applications can get Ctrl-C and Ctrl-Break focus. For all
  293. processes sharing one screen, only one can have Ctrl-C focus.
  294. Enable = 0 = Release focus, 1 = Get focus.
  295. Times = Number of times focus has been get minus number of times it
  296. has been released.}
  297. function DosSetSignalExceptionFocus (Enable: cardinal;
  298. var Times: cardinal): cardinal; cdecl;
  299. external 'DOSCALLS' index 378;
  300. {Tell we want further signal exceptions.
  301. SignalNum = Signal number to acknowlegde.}
  302. function DosAcknowledgeSignalException (SignalNum: cardinal): cardinal; cdecl;
  303. external 'DOSCALLS' index 418;
  304. function DosError (Error: cardinal): cardinal; cdecl;
  305. external 'DOSCALLS' index 212;
  306. type
  307. TWinMessageBox = function (Parent, Owner: cardinal;
  308. BoxText, BoxTitle: PChar; Identity, Style: cardinal): cardinal; cdecl;
  309. TWinInitialize = function (Options: cardinal): cardinal; cdecl;
  310. TWinCreateMsgQueue = function (Handle: cardinal; cmsg: longint): cardinal;
  311. cdecl;
  312. const
  313. ErrorBufferLength = 1024;
  314. mb_OK = $0000;
  315. mb_Error = $0040;
  316. mb_Moveable = $4000;
  317. MBStyle = mb_OK or mb_Error or mb_Moveable;
  318. mfPag_Read = $00001; {Give read access to memory.}
  319. mfPag_Write = $00002; {Give write access to memory.}
  320. mfPag_Execute = $00004; {Allow code execution in memory.}
  321. mfPag_Guard = $00008; {Used for dynamic memory growing. Create
  322. uncommitted memory and make the first
  323. page guarded. Once it is accessed it
  324. will be made committed, and the next
  325. uncommitted page will be made guarded.}
  326. mfPag_Commit = $00010; {Make the memory committed.}
  327. mfPag_Decommit = $00020; {Decommit the page.}
  328. mfObj_Tile = $00040; {Also allocate 16-bit segments of 64k
  329. which map the memory. (Makes 16<>32 bit
  330. pointer conversion possible.}
  331. mfObj_Protected = $00080;
  332. mfObj_Gettable = $00100;
  333. mfObj_Giveable = $00200;
  334. mfObj_Any = $00400; {Allow using high memory (> 512 MB).}
  335. mfPag_Default = $00400;
  336. mfPag_Shared = $02000;
  337. mfPag_Free = $04000;
  338. mfPag_Base = $10000;
  339. mfSub_Init = $00001; {Use base, if not set, choose a base
  340. address yourself.}
  341. mfSub_Grow = $00002; {Grow the specified heap, instead of
  342. allocating it. Ignore mfSub_Init.}
  343. mfSub_Sparse = $00004;
  344. mfSub_Serialize = $00008;
  345. function DosQueryMem (P: pointer; var Size, Flag: cardinal): cardinal; cdecl;
  346. external 'DOSCALLS' index 306;
  347. function DosQuerySysInfo (First, Last: cardinal; var Buf; BufSize: cardinal):
  348. cardinal; cdecl;
  349. external 'DOSCALLS' index 348;
  350. type
  351. TCPArray = array [0..2] of cardinal;
  352. PCPArray = ^TCPArray;
  353. function DosQueryCP (Size: cardinal; CodePages: PCPArray;
  354. var ActSize: cardinal): cardinal; cdecl;
  355. external 'DOSCALLS' index 291;
  356. function DosSetProcessCP (CP: cardinal): cardinal; cdecl;
  357. external 'DOSCALLS' index 289;
  358. type
  359. TCountryCode = record
  360. Country, {Country to query info about (0=current).}
  361. CodePage: cardinal; {Code page to query info about (0=current).}
  362. end;
  363. function DosMapCase (Size: cardinal; var Country: TCountryCode;
  364. AString: PChar): cardinal; cdecl;
  365. external 'NLS' index 7;
  366. function DosQueryDBCSEnv (Size: cardinal; var Country: TCountryCode;
  367. Buf: PChar): cardinal; cdecl;
  368. external 'NLS' index 6;
  369. function DosQueryCollate (Size: cardinal; var Country: TCountryCode;
  370. Buf: PByteArray; var TableLen: cardinal): cardinal; cdecl;
  371. external 'NLS' index 8;
  372. type
  373. TTimeFmt = (Clock12, Clock24);
  374. TCountryInfo = record
  375. Country, CodePage: cardinal; {Country and codepage requested.}
  376. DateFormat: cardinal; {1=ddmmyy 2=yymmdd 3=mmddyy}
  377. CurrencyUnit: array [0..4] of char;
  378. ThousandSeparator: char; {Thousands separator.}
  379. Zero1: byte; {Always zero.}
  380. DecimalSeparator: char; {Decimals separator,}
  381. Zero2: byte;
  382. DateSeparator: char; {Date separator.}
  383. Zero3: byte;
  384. TimeSeparator: char; {Time separator.}
  385. Zero4: byte;
  386. CurrencyFormat, {Bit field:
  387. Bit 0: 0=indicator before value
  388. 1=indicator after value
  389. Bit 1: 1=insert space after indicator.
  390. Bit 2: 1=Ignore bit 0&1, replace
  391. decimal separator with
  392. indicator.}
  393. DecimalPlace: byte; {Number of decimal places used in
  394. currency indication.}
  395. TimeFormat: TTimeFmt; {12/24 hour.}
  396. Reserve1: array [0..1] of word;
  397. DataSeparator: char; {Data list separator}
  398. Zero5: byte;
  399. Reserve2: array [0..4] of word;
  400. end;
  401. const
  402. CurrentCountry: TCountryCode = (Country: 0; CodePage: 0);
  403. function DosQueryCtryInfo (Size: cardinal; var Country: TCountryCode;
  404. var Res: TCountryInfo; var ActualSize: cardinal): cardinal; cdecl;
  405. external 'NLS' index 5;
  406. type
  407. PInsertTable = ^TInsertTable;
  408. TInsertTable = array [1..9] of PChar;
  409. function DosTrueGetMessage (MsgSeg: pointer; Table: PInsertTable;
  410. TableSize: cardinal; Buf: PChar;
  411. BufSize, MsgNumber: cardinal; FileName: PChar;
  412. var MsgSize: cardinal): cardinal; cdecl;
  413. external 'MSG' index 6;
  414. procedure MagicHeaderEnd; assembler; forward;
  415. {$ASMMODE INTEL}
  416. {start of _MSGSEG32 segment}
  417. procedure MagicHeaderStart; assembler;
  418. asm
  419. db $0FF
  420. db $4D,$53,$47,$53,$45,$47,$33,$32, 0 //'MSGSEG32'
  421. dd $8001
  422. dd MagicHeaderEnd
  423. end;
  424. function DosGetMessage (Table: PInsertTable; TableSize: cardinal; Buf: PChar;
  425. BufSize, MsgNumber: cardinal; FileName: PChar;
  426. var MsgSize: cardinal): cardinal; cdecl; assembler;
  427. nostackframe;
  428. asm
  429. pop eax
  430. push offset MagicHeaderStart
  431. push eax
  432. jmp DosTrueGetMessage
  433. end;
  434. procedure MagicHeaderEnd; assembler;
  435. asm
  436. dd $0FFFF0000
  437. end;
  438. {$ASMMODE DEFAULT}