linsysca.inc 23 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202
  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:longint):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. { Moved to syscalls.inc, because it is needed for initialising the runerror/
  642. exceptions system
  643. Procedure SigAction(Signum:longint;Var Act,OldAct:PSigActionRec );
  644. {
  645. Change action of process upon receipt of a signal.
  646. Signum specifies the signal (all except SigKill and SigStop).
  647. If Act is non-nil, it is used to specify the new action.
  648. If OldAct is non-nil the previous action is saved there.
  649. }
  650. Var
  651. sr : Syscallregs;
  652. begin
  653. sr.reg2:=Signum;
  654. sr.reg3:=Longint(act);
  655. sr.reg4:=Longint(oldact);
  656. SysCall(Syscall_nr_sigaction,sr);
  657. linuxerror:=errno;
  658. end;
  659. }
  660. Procedure SigProcMask(How:longint;SSet,OldSSet:PSigSet);
  661. {
  662. Change the list of currently blocked signals.
  663. How determines which signals will be blocked :
  664. SigBlock : Add SSet to the current list of blocked signals
  665. SigUnBlock : Remove the signals in SSet from the list of blocked signals.
  666. SigSetMask : Set the list of blocked signals to SSet
  667. if OldSSet is non-null, the old set will be saved there.
  668. }
  669. Var
  670. sr : SyscallRegs;
  671. begin
  672. sr.reg2:=how;
  673. sr.reg3:=longint(SSet);
  674. sr.reg4:=longint(OldSSet);
  675. SysCall(Syscall_nr_sigprocmask,sr);
  676. linuxerror:=errno;
  677. end;
  678. Function SigPending:SigSet;
  679. {
  680. Allows examination of pending signals. The signal mask of pending
  681. signals is set in SSet
  682. }
  683. Var
  684. sr : SyscallRegs;
  685. dummy : Sigset;
  686. begin
  687. sr.reg2:=longint(@dummy);
  688. SysCall(Syscall_nr_sigpending,sr);
  689. linuxerror:=errno;
  690. Sigpending:=dummy;
  691. end;
  692. Procedure SigSuspend(Mask:Sigset);
  693. {
  694. Set the signal mask with Mask, and suspend the program until a signal
  695. is received.
  696. }
  697. Var
  698. sr : SyscallRegs;
  699. begin
  700. sr.reg2:=mask;
  701. SysCall(Syscall_nr_sigsuspend,sr);
  702. linuxerror:=errno;
  703. end;
  704. Function Signal(Signum:longint;Handler:SignalHandler):SignalHandler;
  705. {
  706. Install a new handler for signal Signum.
  707. The old signal handler is returned.
  708. This call does, in fact, the same as SigAction.
  709. }
  710. var
  711. sr : Syscallregs;
  712. begin
  713. sr.reg2:=signum;
  714. sr.reg3:=longint(handler);
  715. Linuxerror:=SysCall(Syscall_nr_signal,sr);
  716. If linuxerror=Sig_Err then
  717. begin
  718. Signal:=nil;
  719. Linuxerror:=errno;
  720. end
  721. else
  722. begin
  723. Signal:=signalhandler(Linuxerror);
  724. linuxerror:=0;
  725. end;
  726. end;
  727. Function Alarm(Sec : Longint) : longint;
  728. Var Sr : Syscallregs;
  729. begin
  730. sr.reg2:=Sec;
  731. Alarm:=Syscall(syscall_nr_alarm,sr);
  732. end;
  733. Procedure Pause;
  734. Var Sr : Syscallregs;
  735. begin
  736. syscall(syscall_nr_pause,sr);
  737. end;
  738. Function IOCtl(Handle,Ndx: Longint;Data: Pointer):boolean;
  739. {
  740. Interface to Unix ioctl call.
  741. Performs various operations on the filedescriptor Handle.
  742. Ndx describes the operation to perform.
  743. Data points to data needed for the Ndx function. The structure of this
  744. data is function-dependent.
  745. }
  746. var
  747. sr: SysCallRegs;
  748. begin
  749. sr.reg2:=Handle;
  750. sr.reg3:=Ndx;
  751. sr.reg4:=Longint(Data);
  752. IOCtl:=(SysCall(Syscall_nr_ioctl,sr)=0);
  753. LinuxError:=Errno;
  754. end;
  755. function MMap(const m:tmmapargs):longint;
  756. Var
  757. Sr : Syscallregs;
  758. begin
  759. Sr.reg2:=longint(@m);
  760. MMap:=syscall(syscall_nr_mmap,sr);
  761. LinuxError:=Errno;
  762. end;
  763. function MUnMap (P : Pointer; Size : Longint) : Boolean;
  764. Var
  765. Sr : Syscallregs;
  766. begin
  767. Sr.reg2:=longint(P);
  768. sr.reg3:=Size;
  769. MUnMap:=syscall(syscall_nr_munmap,sr)=0;
  770. LinuxError:=Errno;
  771. end;
  772. {--------------------------------
  773. Port IO functions
  774. --------------------------------}
  775. Function IOperm (From,Num : Cardinal; Value : Longint) : boolean;
  776. {
  777. Set permissions on NUM ports starting with port FROM to VALUE
  778. this works ONLY as root.
  779. }
  780. Var
  781. Sr : Syscallregs;
  782. begin
  783. Sr.Reg2:=From;
  784. Sr.Reg3:=Num;
  785. Sr.Reg4:=Value;
  786. IOPerm:=Syscall(Syscall_nr_ioperm,sr)=0;
  787. LinuxError:=Errno;
  788. end;
  789. {$IFDEF I386}
  790. Procedure WritePort (Port : Longint; Value : Byte);
  791. {
  792. Writes 'Value' to port 'Port'
  793. }
  794. begin
  795. asm
  796. movl port,%edx
  797. movb value,%al
  798. outb %al,%dx
  799. end ['EAX','EDX'];
  800. end;
  801. Procedure WritePort (Port : Longint; Value : Word);
  802. {
  803. Writes 'Value' to port 'Port'
  804. }
  805. begin
  806. asm
  807. movl port,%edx
  808. movw value,%ax
  809. outw %ax,%dx
  810. end ['EAX','EDX'];
  811. end;
  812. Procedure WritePort (Port : Longint; Value : Longint);
  813. {
  814. Writes 'Value' to port 'Port'
  815. }
  816. begin
  817. asm
  818. movl port,%edx
  819. movl value,%eax
  820. outl %eax,%dx
  821. end ['EAX','EDX'];
  822. end;
  823. Procedure WritePortB (Port : Longint; Value : Byte);
  824. {
  825. Writes 'Value' to port 'Port'
  826. }
  827. begin
  828. asm
  829. movl port,%edx
  830. movb value,%al
  831. outb %al,%dx
  832. end ['EAX','EDX'];
  833. end;
  834. Procedure WritePortW (Port : Longint; Value : Word);
  835. {
  836. Writes 'Value' to port 'Port'
  837. }
  838. begin
  839. asm
  840. movl port,%edx
  841. movw value,%ax
  842. outw %ax,%dx
  843. end ['EAX','EDX'];
  844. end;
  845. Procedure WritePortL (Port : Longint; Value : Longint);
  846. {
  847. Writes 'Value' to port 'Port'
  848. }
  849. begin
  850. asm
  851. movl port,%edx
  852. movl value,%eax
  853. outl %eax,%dx
  854. end ['EAX','EDX'];
  855. end;
  856. Procedure WritePortl (Port : Longint; Var Buf; Count: longint);
  857. {
  858. Writes 'Count' longints from 'Buf' to Port
  859. }
  860. begin
  861. asm
  862. movl count,%ecx
  863. movl buf,%esi
  864. movl port,%edx
  865. cld
  866. rep
  867. outsl
  868. end ['ECX','ESI','EDX'];
  869. end;
  870. Procedure WritePortW (Port : Longint; Var Buf; Count: longint);
  871. {
  872. Writes 'Count' words from 'Buf' to Port
  873. }
  874. begin
  875. asm
  876. movl count,%ecx
  877. movl buf,%esi
  878. movl port,%edx
  879. cld
  880. rep
  881. outsw
  882. end ['ECX','ESI','EDX'];
  883. end;
  884. Procedure WritePortB (Port : Longint; Var Buf; Count: longint);
  885. {
  886. Writes 'Count' bytes from 'Buf' to Port
  887. }
  888. begin
  889. asm
  890. movl count,%ecx
  891. movl buf,%esi
  892. movl port,%edx
  893. cld
  894. rep
  895. outsb
  896. end ['ECX','ESI','EDX'];
  897. end;
  898. Procedure ReadPort (Port : Longint; Var Value : Byte);
  899. {
  900. Reads 'Value' from port 'Port'
  901. }
  902. begin
  903. asm
  904. movl port,%edx
  905. inb %dx,%al
  906. movl value,%edx
  907. movb %al,(%edx)
  908. end ['EAX','EDX'];
  909. end;
  910. Procedure ReadPort (Port : Longint; Var Value : Word);
  911. {
  912. Reads 'Value' from port 'Port'
  913. }
  914. begin
  915. asm
  916. movl port,%edx
  917. inw %dx,%ax
  918. movl value,%edx
  919. movw %ax,(%edx)
  920. end ['EAX','EDX'];
  921. end;
  922. Procedure ReadPort (Port : Longint; Var Value : Longint);
  923. {
  924. Reads 'Value' from port 'Port'
  925. }
  926. begin
  927. asm
  928. movl port,%edx
  929. inl %dx,%eax
  930. movl value,%edx
  931. movl %eax,(%edx)
  932. end ['EAX','EDX'];
  933. end;
  934. function ReadPortB (Port : Longint): Byte; assembler;
  935. {
  936. Reads a byte from port 'Port'
  937. }
  938. asm
  939. xorl %eax,%eax
  940. movl port,%edx
  941. inb %dx,%al
  942. end ['EAX','EDX'];
  943. function ReadPortW (Port : Longint): Word; assembler;
  944. {
  945. Reads a word from port 'Port'
  946. }
  947. asm
  948. xorl %eax,%eax
  949. movl port,%edx
  950. inw %dx,%ax
  951. end ['EAX','EDX'];
  952. function ReadPortL (Port : Longint): LongInt; assembler;
  953. {
  954. Reads a LongInt from port 'Port'
  955. }
  956. asm
  957. movl port,%edx
  958. inl %dx,%eax
  959. end ['EAX','EDX'];
  960. Procedure ReadPortL (Port : Longint; Var Buf; Count: longint);
  961. {
  962. Reads 'Count' longints from port 'Port' to 'Buf'.
  963. }
  964. begin
  965. asm
  966. movl count,%ecx
  967. movl buf,%edi
  968. movl port,%edx
  969. cld
  970. rep
  971. insl
  972. end ['ECX','EDI','EDX'];
  973. end;
  974. Procedure ReadPortW (Port : Longint; Var Buf; Count: longint);
  975. {
  976. Reads 'Count' words from port 'Port' to 'Buf'.
  977. }
  978. begin
  979. asm
  980. movl count,%ecx
  981. movl buf,%edi
  982. movl port,%edx
  983. cld
  984. rep
  985. insw
  986. end ['ECX','EDI','EDX'];
  987. end;
  988. Procedure ReadPortB (Port : Longint; Var Buf; Count: longint);
  989. {
  990. Reads 'Count' bytes from port 'Port' to 'Buf'.
  991. }
  992. begin
  993. asm
  994. movl count,%ecx
  995. movl buf,%edi
  996. movl port,%edx
  997. cld
  998. rep
  999. insb
  1000. end ['ECX','EDI','EDX'];
  1001. end;
  1002. {$ENDIF}
  1003. {
  1004. $Log$
  1005. Revision 1.3 2000-09-11 14:05:31 marco
  1006. * FreeBSD support and removed old signalhandling
  1007. Revision 1.2 2000/07/13 11:33:48 michael
  1008. + removed logs
  1009. }