linsysca.inc 24 KB

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