unixsysc.inc 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999-2000 by Michael Van Canneyt,
  5. member of the Free Pascal development team.
  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. Function Fork:longint;
  13. {
  14. This function issues the 'fork' System call. the program is duplicated in memory
  15. and Execution continues in parent and child process.
  16. In the parent process, fork returns the PID of the child. In the child process,
  17. zero is returned.
  18. A negative value indicates that an error has occurred, the error is returned in
  19. LinuxError.
  20. }
  21. var
  22. regs:SysCallregs;
  23. begin
  24. Fork:=SysCall(SysCall_nr_fork,regs);
  25. LinuxError:=fpgetErrno;
  26. End;
  27. Procedure Execve(path:pathstr;args:ppchar;ep:ppchar);
  28. {
  29. Replaces the current program by the program specified in path,
  30. arguments in args are passed to Execve.
  31. environment specified in ep is passed on.
  32. }
  33. var
  34. regs:SysCallregs;
  35. begin
  36. path:=path+#0;
  37. regs.reg2:=longint(@path[1]);
  38. regs.reg3:=longint(args);
  39. regs.reg4:=longint(ep);
  40. SysCall(SysCall_nr_Execve,regs);
  41. { This only gets set when the call fails, otherwise we don't get here ! }
  42. Linuxerror:=fpgeterrno;
  43. end;
  44. Procedure Execve(path:pchar;args:ppchar;ep:ppchar);
  45. {
  46. Replaces the current program by the program specified in path,
  47. arguments in args are passed to Execve.
  48. environment specified in ep is passed on.
  49. }
  50. var
  51. regs:SysCallregs;
  52. begin
  53. regs.reg2:=longint(path);
  54. regs.reg3:=longint(args);
  55. regs.reg4:=longint(ep);
  56. SysCall(SysCall_nr_Execve,regs);
  57. { This only gets set when the call fails, otherwise we don't get here ! }
  58. Linuxerror:=fpgeterrno;
  59. end;
  60. Procedure ExitProcess(val:longint);
  61. var
  62. regs : SysCallregs;
  63. begin
  64. regs.reg2:=val;
  65. SysCall(SysCall_nr_exit,regs);
  66. end;
  67. Function WaitPid(Pid:longint;Status:pointer;Options:Longint):Longint;
  68. {
  69. Waits until a child with PID Pid exits, or returns if it is exited already.
  70. Any resources used by the child are freed.
  71. The exit status is reported in the adress referred to by Status. It should
  72. be a longint.
  73. }
  74. var
  75. regs : SysCallregs;
  76. begin
  77. regs.reg2:=pid;
  78. regs.reg3:=longint(status);
  79. regs.reg4:=options;
  80. WaitPid:=SysCall(SysCall_nr_waitpid,regs);
  81. LinuxError:=fpgeterrno;
  82. end;
  83. Procedure GetTimeOfDay(var tv:timeval);
  84. {
  85. Get the number of seconds since 00:00, January 1 1970, GMT
  86. the time NOT corrected any way
  87. }
  88. var
  89. regs : SysCallregs;
  90. begin
  91. regs.reg2:=longint(@tv);
  92. regs.reg3:=0;
  93. SysCall(SysCall_nr_gettimeofday,regs);
  94. LinuxError:=fpgetErrno;
  95. end;
  96. Function GetPriority(Which,Who:Integer):integer;
  97. {
  98. Get Priority of process, process group, or user.
  99. Which : selects what kind of priority is used.
  100. can be one of the following predefined Constants :
  101. Prio_User.
  102. Prio_PGrp.
  103. Prio_Process.
  104. Who : depending on which, this is , respectively :
  105. Uid
  106. Pid
  107. Process Group id
  108. Errors are reported in linuxerror _only_. (priority can be negative)
  109. }
  110. var
  111. sr : Syscallregs;
  112. begin
  113. fpseterrno(0);
  114. if (which<prio_process) or (which>prio_user) then
  115. begin
  116. { We can save an interrupt here }
  117. getpriority:=0;
  118. linuxerror:=ESyseinval;
  119. end
  120. else
  121. begin
  122. sr.reg2:=which;
  123. sr.reg3:=who;
  124. getpriority:=SysCall(Syscall_nr_getpriority,sr);
  125. linuxerror:=fpgeterrno;
  126. end;
  127. end;
  128. Procedure SetPriority(Which:Integer;Who:Integer;What:Integer);
  129. {
  130. Set Priority of process, process group, or user.
  131. Which : selects what kind of priority is used.
  132. can be one of the following predefined Constants :
  133. Prio_User.
  134. Prio_PGrp.
  135. Prio_Process.
  136. Who : depending on value of which, this is, respectively :
  137. Uid
  138. Pid
  139. Process Group id
  140. what : A number between -20 and 20. -20 is most favorable, 20 least.
  141. 0 is the default.
  142. }
  143. var
  144. sr : Syscallregs;
  145. begin
  146. fpseterrno(0);
  147. if ((which<prio_process) or (which>prio_user)) or ((what<-20) or (what>20)) then
  148. linuxerror:=ESyseinval { We can save an interrupt here }
  149. else
  150. begin
  151. sr.reg2:=which;
  152. sr.reg3:=who;
  153. sr.reg4:=what;
  154. SysCall(Syscall_nr_setpriority,sr);
  155. linuxerror:=fpgeterrno;
  156. end;
  157. end;
  158. Procedure Nice(N:integer);
  159. {
  160. Set process priority. A positive N means a lower priority.
  161. A negative N decreases priority.
  162. }
  163. var
  164. sr : Syscallregs;
  165. begin
  166. sr.reg2:=n;
  167. SysCall(Syscall_nr_nice,sr);
  168. linuxerror:=fpgeterrno;
  169. end;
  170. Function GetPid:LongInt;
  171. {
  172. Get Process ID.
  173. }
  174. var
  175. regs : SysCallregs;
  176. begin
  177. GetPid:=SysCall(SysCall_nr_getpid,regs);
  178. linuxerror:=fpgeterrno;
  179. end;
  180. Function GetPPid:LongInt;
  181. {
  182. Get Process ID of parent process.
  183. }
  184. var
  185. regs : SysCallregs;
  186. begin
  187. GetPpid:=SysCall(SysCall_nr_getppid,regs);
  188. linuxerror:=fpgeterrno;
  189. end;
  190. Function GetUid:Longint;
  191. {
  192. Get User ID.
  193. }
  194. var
  195. regs : SysCallregs;
  196. begin
  197. GetUid:=SysCall(SysCall_nr_getuid,regs);
  198. Linuxerror:=fpgeterrno;
  199. end;
  200. Function GetEUid:Longint;
  201. {
  202. Get _effective_ User ID.
  203. }
  204. var
  205. regs : SysCallregs;
  206. begin
  207. GetEuid:=SysCall(SysCall_nr_geteuid,regs);
  208. Linuxerror:=fpgeterrno;
  209. end;
  210. Function GetGid:Longint;
  211. {
  212. Get Group ID.
  213. }
  214. var
  215. regs : SysCallregs;
  216. begin
  217. Getgid:=SysCall(SysCall_nr_getgid,regs);
  218. Linuxerror:=fpgeterrno;
  219. end;
  220. Function GetEGid:Longint;
  221. {
  222. Get _effective_ Group ID.
  223. }
  224. var
  225. regs : SysCallregs;
  226. begin
  227. GetEgid:=SysCall(SysCall_nr_getegid,regs);
  228. Linuxerror:=fpgeterrno;
  229. end;
  230. Function GetTimeOfDay: longint;
  231. {
  232. Get the number of seconds since 00:00, January 1 1970, GMT
  233. the time NOT corrected any way
  234. }
  235. var
  236. regs : SysCallregs;
  237. tv : timeval;
  238. begin
  239. regs.reg2:=longint(@tv);
  240. regs.reg3:=0;
  241. SysCall(SysCall_nr_gettimeofday,regs);
  242. LinuxError:=fpgetErrno;
  243. GetTimeOfDay:=tv.tv_sec;
  244. end;
  245. Function fdTruncate(fd,size:longint):boolean;
  246. var
  247. Regs : SysCallRegs;
  248. begin
  249. Regs.reg2:=fd;
  250. Regs.reg3:=size;
  251. fdTruncate:=(SysCall(Syscall_nr_ftruncate,regs)=0);
  252. LinuxError:=fpgetErrno;
  253. end;
  254. Function fdFlush (fd : Longint) : Boolean;
  255. var
  256. SR: SysCallRegs;
  257. begin
  258. SR.reg2 := fd;
  259. fdFlush := (SysCall(syscall_nr_fsync, SR)=0);
  260. LinuxError:=fpgetErrno;
  261. end;
  262. Function Fcntl(Fd:longint;Cmd:longint):longint;
  263. {
  264. Read or manipulate a file.(See also fcntl (2) )
  265. Possible values for Cmd are :
  266. F_GetFd,F_GetFl,F_GetOwn
  267. Errors are reported in Linuxerror;
  268. If Cmd is different from the allowed values, linuxerror=ESyseninval.
  269. }
  270. var
  271. sr : Syscallregs;
  272. begin
  273. if (cmd in [F_GetFd,F_GetFl,F_GetOwn]) then
  274. begin
  275. sr.reg2:=Fd;
  276. sr.reg3:=cmd;
  277. Linuxerror:=SysCall(Syscall_nr_fcntl,sr);
  278. if linuxerror=-1 then
  279. begin
  280. linuxerror:=fpgeterrno;
  281. fcntl:=0;
  282. end
  283. else
  284. begin
  285. fcntl:=linuxerror;
  286. linuxerror:=0;
  287. end;
  288. end
  289. else
  290. begin
  291. linuxerror:=ESyseinval;
  292. Fcntl:=0;
  293. end;
  294. end;
  295. Procedure Fcntl(Fd:longint;Cmd : longint;Arg:Longint);
  296. {
  297. Read or manipulate a file. (See also fcntl (2) )
  298. Possible values for Cmd are :
  299. F_setFd,F_SetFl,F_GetLk,F_SetLk,F_SetLkW,F_SetOwn;
  300. Errors are reported in Linuxerror;
  301. If Cmd is different from the allowed values, linuxerror=ESyseninval.
  302. F_DupFD is not allowed, due to the structure of Files in Pascal.
  303. }
  304. var
  305. sr : Syscallregs;
  306. begin
  307. if (cmd in [F_SetFd,F_SetFl,F_GetLk,F_SetLk,F_SetLkw,F_SetOwn]) then
  308. begin
  309. sr.reg2:=Fd;
  310. sr.reg3:=cmd;
  311. sr.reg4:=arg;
  312. SysCall(Syscall_nr_fcntl,sr);
  313. linuxerror:=fpgeterrno;
  314. end
  315. else
  316. linuxerror:=ESyseinval;
  317. end;
  318. Function Chmod(path:pathstr;Newmode:longint):Boolean;
  319. {
  320. Changes the permissions of a file.
  321. }
  322. var
  323. sr : Syscallregs;
  324. begin
  325. path:=path+#0;
  326. sr.reg2:=longint(@(path[1]));
  327. sr.reg3:=newmode;
  328. Chmod:=(SysCall(Syscall_nr_chmod,sr)=0);
  329. linuxerror:=fpgeterrno;
  330. end;
  331. Function Chown(path:pathstr;NewUid,NewGid:longint):boolean;
  332. {
  333. Change the owner and group of a file.
  334. A user can only change the group to a group of which he is a member.
  335. The super-user can change uid and gid of any file.
  336. }
  337. var
  338. sr : Syscallregs;
  339. begin
  340. path:=path+#0;
  341. sr.reg2:=longint(@(path[1]));
  342. sr.reg3:=newuid;
  343. sr.reg4:=newgid;
  344. ChOwn:=(Syscall(Syscall_nr_chown,sr)=0);
  345. linuxerror:=fpgeterrno;
  346. end;
  347. Function Utime(path:pathstr;utim:utimbuf):boolean;
  348. var
  349. sr : Syscallregs;
  350. begin
  351. path:=path+#0;
  352. sr.reg2:=longint(@(path[1]));
  353. sr.reg3:=longint(@utim);
  354. Utime:=SysCall(Syscall_nr_utime,sr)=0;
  355. linuxerror:=fpgeterrno;
  356. end;
  357. Function Flock (fd,mode : longint) : boolean;
  358. var
  359. sr : Syscallregs;
  360. begin
  361. sr.reg2:=fd;
  362. sr.reg3:=mode;
  363. flock:=Syscall(Syscall_nr_flock,sr)=0;
  364. LinuxError:=fpgeterrno;
  365. end;
  366. Function Fstat(Fd:Longint;var Info:stat):Boolean;
  367. {
  368. Get all information on a file descriptor, and return it in info.
  369. }
  370. var
  371. regs : SysCallregs;
  372. begin
  373. regs.reg2:=Fd;
  374. regs.reg3:=longint(@Info);
  375. FStat:=(SysCall(SysCall_nr_fstat,regs)=0);
  376. LinuxError:=fpgetErrno;
  377. end;
  378. Function Lstat(Filename: PathStr;var Info:stat):Boolean;
  379. {
  380. Get all information on a link (the link itself), and return it in info.
  381. }
  382. var
  383. regs : SysCallregs;
  384. begin
  385. FileName:=FileName+#0;
  386. regs.reg2:=longint(@filename[1]);
  387. regs.reg3:=longint(@Info);
  388. LStat:=(SysCall(SysCall_nr_lstat,regs)=0);
  389. LinuxError:=fpgetErrno;
  390. end;
  391. Function StatFS(Path:Pathstr;Var Info:tstatfs):Boolean;
  392. {
  393. Get all information on a fileSystem, and return it in Info.
  394. Path is the name of a file/directory on the fileSystem you wish to
  395. investigate.
  396. }
  397. var
  398. regs : SysCallregs;
  399. begin
  400. path:=path+#0;
  401. regs.reg2:=longint(@path[1]);
  402. regs.reg3:=longint(@Info);
  403. StatFS:=(SysCall(SysCall_nr_statfs,regs)=0);
  404. LinuxError:=fpgeterrno;
  405. end;
  406. Function StatFS(Fd:Longint;Var Info:tstatfs):Boolean;
  407. {
  408. Get all information on a fileSystem, and return it in Info.
  409. Fd is the file descriptor of a file/directory on the fileSystem
  410. you wish to investigate.
  411. }
  412. var
  413. regs : SysCallregs;
  414. begin
  415. regs.reg2:=Fd;
  416. regs.reg3:=longint(@Info);
  417. StatFS:=(SysCall(SysCall_nr_fstatfs,regs)=0);
  418. LinuxError:=fpgeterrno;
  419. end;
  420. Function Link(OldPath,NewPath:pathstr):boolean;
  421. {
  422. Proceduces a hard link from new to old.
  423. In effect, new will be the same file as old.
  424. }
  425. var
  426. regs : SysCallregs;
  427. begin
  428. oldpath:=oldpath+#0;
  429. newpath:=newpath+#0;
  430. regs.reg2:=longint(@oldpath[1]);
  431. regs.reg3:=longint(@newpath[1]);
  432. Link:=SysCall(SysCall_nr_link,regs)=0;
  433. linuxerror:=fpgeterrno;
  434. end;
  435. Function Umask(Mask:Integer):integer;
  436. {
  437. Sets file creation mask to (Mask and 0777 (octal) ), and returns the
  438. previous value.
  439. }
  440. var
  441. sr : Syscallregs;
  442. begin
  443. sr.reg2:=mask;
  444. Umask:=SysCall(Syscall_nr_umask,sr);
  445. linuxerror:=0;
  446. end;
  447. Function Access(Path:Pathstr ;mode:integer):boolean;
  448. {
  449. Test users access rights on the specified file.
  450. Mode is a mask xosisting of one or more of R_OK, W_OK, X_OK, F_OK.
  451. R,W,X stand for read,write and Execute access, simultaneously.
  452. F_OK checks whether the test would be allowed on the file.
  453. i.e. It checks the search permissions in all directory components
  454. of the path.
  455. The test is done with the real user-ID, instead of the effective.
  456. If access is denied, or an error occurred, false is returned.
  457. If access is granted, true is returned.
  458. Errors other than no access,are reported in linuxerror.
  459. }
  460. var
  461. sr : Syscallregs;
  462. begin
  463. path:=path+#0;
  464. sr.reg2:=longint(@(path[1]));
  465. sr.reg3:=mode;
  466. access:=(SysCall(Syscall_nr_access,sr)=0);
  467. linuxerror:=fpgeterrno;
  468. end;
  469. Function Dup(oldfile:longint;var newfile:longint):Boolean;
  470. {
  471. Copies the filedescriptor oldfile to newfile
  472. }
  473. var
  474. sr : Syscallregs;
  475. begin
  476. sr.reg2:=oldfile;
  477. newfile:=Syscall(Syscall_nr_dup,sr);
  478. linuxerror:=fpgeterrno;
  479. Dup:=(LinuxError=0);
  480. end;
  481. Function Dup2(oldfile,newfile:longint):Boolean;
  482. {
  483. Copies the filedescriptor oldfile to newfile
  484. }
  485. var
  486. sr : Syscallregs;
  487. begin
  488. sr.reg2:=oldfile;
  489. sr.reg3:=newfile;
  490. SysCall(Syscall_nr_dup2,sr);
  491. linuxerror:=fpgeterrno;
  492. Dup2:=(LinuxError=0);
  493. end;
  494. Function AssignPipe(var pipe_in,pipe_out:longint):boolean; [public, alias : 'FPC_SYSC_ASSIGNPIPE'];
  495. {
  496. Sets up a pair of file variables, which act as a pipe. The first one can
  497. be read from, the second one can be written to.
  498. If the operation was unsuccesful, linuxerror is set.
  499. }
  500. var
  501. pip : tpipe;
  502. regs : SysCallregs;
  503. begin
  504. regs.reg2:=longint(@pip);
  505. SysCall(SysCall_nr_pipe,regs);
  506. pipe_in:=pip[1];
  507. pipe_out:=pip[2];
  508. linuxerror:=fpgeterrno;
  509. AssignPipe:=(LinuxError=0);
  510. end;
  511. Function PClose(Var F:text) :longint;
  512. var
  513. sr : syscallregs;
  514. pl : ^longint;
  515. res : longint;
  516. begin
  517. sr.reg2:=Textrec(F).Handle;
  518. SysCall (syscall_nr_close,sr);
  519. { closed our side, Now wait for the other - this appears to be needed ?? }
  520. pl:=@(textrec(f).userdata[2]);
  521. waitpid(pl^,@res,0);
  522. pclose:=res shr 8;
  523. end;
  524. Function PClose(Var F:file) : longint;
  525. var
  526. sr : syscallregs;
  527. pl : ^longint;
  528. res : longint;
  529. begin
  530. sr.reg2:=FileRec(F).Handle;
  531. SysCall (Syscall_nr_close,sr);
  532. { closed our side, Now wait for the other - this appears to be needed ?? }
  533. pl:=@(filerec(f).userdata[2]);
  534. waitpid(pl^,@res,0);
  535. pclose:=res shr 8;
  536. end;
  537. Function Sysinfo(var Info:TSysinfo):Boolean;
  538. {
  539. Get system info
  540. }
  541. var
  542. regs : SysCallregs;
  543. Begin
  544. regs.reg2:=longint(@info);
  545. Sysinfo:=SysCall(SysCall_nr_Sysinfo,regs)=0;
  546. End;
  547. Function mkFifo(pathname:string;mode:longint):boolean;
  548. var
  549. regs : SysCallRegs;
  550. begin
  551. pathname:=pathname+#0;
  552. regs.reg2:=longint(@pathname[1]);
  553. regs.reg3:=mode or STAT_IFIFO;
  554. regs.reg4:=0;
  555. mkFifo:=(SysCall(syscall_nr_mknod,regs)=0);
  556. end;
  557. Function Uname(var unamerec:utsname):Boolean;
  558. {
  559. Get machine's names
  560. }
  561. var
  562. regs : SysCallregs;
  563. Begin
  564. regs.reg2:=longint(@unamerec);
  565. Uname:=SysCall(SysCall_nr_uname,regs)=0;
  566. LinuxError:=fpgetErrno;
  567. End;
  568. Function Kill(Pid:longint;Sig:longint):integer;
  569. {
  570. Send signal 'sig' to a process, or a group of processes.
  571. If Pid > 0 then the signal is sent to pid
  572. pid=-1 to all processes except process 1
  573. pid < -1 to process group -pid
  574. Return value is zero, except for case three, where the return value
  575. is the number of processes to which the signal was sent.
  576. }
  577. var
  578. regs : Syscallregs;
  579. begin
  580. regs.reg2:=Pid;
  581. regs.reg3:=Sig;
  582. kill:=SysCall(Syscall_nr_kill,regs);
  583. if kill<0 then
  584. Kill:=0;
  585. linuxerror:=fpgeterrno;
  586. end;
  587. Procedure SigProcMask(How:longint;SSet,OldSSet:PSigSet);
  588. {
  589. Change the list of currently blocked signals.
  590. How determines which signals will be blocked :
  591. SigBlock : Add SSet to the current list of blocked signals
  592. SigUnBlock : Remove the signals in SSet from the list of blocked signals.
  593. SigSetMask : Set the list of blocked signals to SSet
  594. if OldSSet is non-null, the old set will be saved there.
  595. }
  596. Var
  597. sr : SyscallRegs;
  598. begin
  599. sr.reg2:=how;
  600. sr.reg3:=longint(SSet);
  601. sr.reg4:=longint(OldSSet);
  602. SysCall(Syscall_nr_sigprocmask,sr);
  603. linuxerror:=fpgeterrno;
  604. end;
  605. Function SigPending:SigSet;
  606. {
  607. Allows examination of pending signals. The signal mask of pending
  608. signals is set in SSet
  609. }
  610. Var
  611. sr : SyscallRegs;
  612. dummy : Sigset;
  613. begin
  614. sr.reg2:=longint(@dummy);
  615. SysCall(Syscall_nr_sigpending,sr);
  616. linuxerror:=fpgeterrno;
  617. Sigpending:=dummy;
  618. end;
  619. Procedure SigSuspend(Mask:Sigset);
  620. {
  621. Set the signal mask with Mask, and suspend the program until a signal
  622. is received.
  623. }
  624. Var
  625. sr : SyscallRegs;
  626. begin
  627. sr.reg2:=mask[0];
  628. SysCall(Syscall_nr_sigsuspend,sr);
  629. linuxerror:=fpgeterrno;
  630. end;
  631. Function Signal(Signum:longint;Handler:SignalHandler):SignalHandler;
  632. {
  633. Install a new handler for signal Signum.
  634. The old signal handler is returned.
  635. This call does, in fact, the same as SigAction.
  636. }
  637. var
  638. sr : Syscallregs;
  639. begin
  640. sr.reg2:=signum;
  641. sr.reg3:=longint(handler);
  642. Linuxerror:=SysCall(Syscall_nr_signal,sr);
  643. If linuxerror=Sig_Err then
  644. begin
  645. Signal:=nil;
  646. Linuxerror:=fpgeterrno;
  647. end
  648. else
  649. begin
  650. Signal:=signalhandler(Linuxerror);
  651. linuxerror:=0;
  652. end;
  653. end;
  654. Function Alarm(Sec : Longint) : longint;
  655. Var Sr : Syscallregs;
  656. begin
  657. sr.reg2:=Sec;
  658. Alarm:=Syscall(syscall_nr_alarm,sr);
  659. end;
  660. Procedure Pause;
  661. Var Sr : Syscallregs;
  662. begin
  663. syscall(syscall_nr_pause,sr);
  664. end;
  665. {
  666. Function NanoSleep(const req : timespec;var rem : timespec) : longint;
  667. var Sr : Syscallregs;
  668. begin
  669. sr.reg2:=longint(@req);
  670. sr.reg3:=longint(@rem);
  671. NanoSleep:=Syscall(syscall_nr_nanosleep,sr);
  672. LinuxError:=Errno;
  673. end;
  674. }
  675. Function IOCtl(Handle,Ndx: Longint;Data: Pointer):boolean;
  676. {
  677. Interface to Unix ioctl call.
  678. Performs various operations on the filedescriptor Handle.
  679. Ndx describes the operation to perform.
  680. Data points to data needed for the Ndx function. The structure of this
  681. data is function-dependent.
  682. }
  683. var
  684. sr: SysCallRegs;
  685. begin
  686. sr.reg2:=Handle;
  687. sr.reg3:=Ndx;
  688. sr.reg4:=Longint(Data);
  689. IOCtl:=(SysCall(Syscall_nr_ioctl,sr)=0);
  690. LinuxError:=fpgetErrno;
  691. end;
  692. function MMap(const m:tmmapargs):longint;
  693. Var
  694. Sr : Syscallregs;
  695. begin
  696. Sr.reg2:=longint(@m);
  697. MMap:=syscall(syscall_nr_mmap,sr);
  698. LinuxError:=fpgetErrno;
  699. end;
  700. function MUnMap (P : Pointer; Size : Longint) : Boolean;
  701. Var
  702. Sr : Syscallregs;
  703. begin
  704. Sr.reg2:=longint(P);
  705. sr.reg3:=Size;
  706. MUnMap:=syscall(syscall_nr_munmap,sr)=0;
  707. LinuxError:=fpgetErrno;
  708. end;
  709. {--------------------------------
  710. Port IO functions
  711. --------------------------------}
  712. {$ifdef i386}
  713. Function IOperm (From,Num : Cardinal; Value : Longint) : boolean;
  714. {
  715. Set permissions on NUM ports starting with port FROM to VALUE
  716. this works ONLY as root.
  717. }
  718. Var
  719. Sr : Syscallregs;
  720. begin
  721. Sr.Reg2:=From;
  722. Sr.Reg3:=Num;
  723. Sr.Reg4:=Value;
  724. IOPerm:=Syscall(Syscall_nr_ioperm,sr)=0;
  725. LinuxError:=fpgetErrno;
  726. end;
  727. Function IoPL(Level : longint) : Boolean;
  728. Var
  729. Sr : Syscallregs;
  730. begin
  731. Sr.Reg2:=Level;
  732. IOPL:=Syscall(Syscall_nr_iopl,sr)=0;
  733. LinuxError:=fpgetErrno;
  734. end;
  735. {$endif i386}
  736. {
  737. $Log$
  738. Revision 1.11 2003-09-15 21:07:32 marco
  739. * second round of linux fixes. oldlinux now works
  740. Revision 1.10 2003/09/14 20:15:01 marco
  741. * Unix reform stage two. Remove all calls from Unix that exist in Baseunix.
  742. Revision 1.9 2003/07/08 21:23:24 peter
  743. * sparc fixes
  744. Revision 1.8 2002/12/18 16:43:26 marco
  745. * new unix rtl, linux part.....
  746. Revision 1.7 2002/09/07 16:01:20 peter
  747. * old logs removed and tabs fixed
  748. Revision 1.6 2002/03/05 20:04:25 michael
  749. + Patch from Sebastian for FCNTL call
  750. }