unixsysc.inc 21 KB

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