linsysca.inc 23 KB

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