ossysc.inc 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677
  1. {
  2. Copyright (c) 2002 by Marco van de Voort
  3. The base *BSD syscalls required to implement the system unit. These
  4. are aliased for use in other units (to avoid poluting the system units
  5. interface)
  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. }
  13. function Fptime( tloc:ptime): time_t; [public, alias : 'FPC_SYSC_TIME'];
  14. VAR tv : timeval;
  15. tz : timezone;
  16. retval : longint;
  17. begin
  18. Retval:=do_syscall(syscall_nr_gettimeofday,TSysParam(@tv),TSysParam(@tz));
  19. If retval=-1 then
  20. Fptime:=-1
  21. else
  22. Begin
  23. If Assigned(tloc) Then
  24. TLoc^:=tv.tv_sec;
  25. Fptime:=tv.tv_sec;
  26. End;
  27. End;
  28. {*****************************************************************************
  29. --- File:File handling related calls ---
  30. *****************************************************************************}
  31. function Fpopen(path: pchar; flags : cint; mode: mode_t):cint; [public, alias : 'FPC_SYSC_OPEN'];
  32. Begin
  33. Fpopen:=do_syscall(syscall_nr_open,TSysParam(path),TSysParam(flags),TSysParam(mode));
  34. End;
  35. function Fpclose(fd : cint): cint; [public, alias : 'FPC_SYSC_CLOSE'];
  36. begin
  37. Fpclose:=do_syscall(syscall_nr_close,fd);
  38. end;
  39. {$ifdef netbsd}
  40. {$ifdef cpupowerpc}
  41. {$define netbsdmacppc}
  42. {$endif}
  43. {$endif}
  44. {$ifdef netbsdmacppc}
  45. {$i sysofft.inc} // odd ball calling convention.
  46. {$else}
  47. // generic versions.
  48. function Fplseek(fd : cint; offset : off_t; whence : cint): off_t; [public, alias : 'FPC_SYSC_LSEEK'];
  49. {$ifdef cpum68k}
  50. begin
  51. Fplseek:=do_syscall64(syscall_nr_lseek,TSysParam(fd),0,hi(offset),lo(offset),whence);
  52. end;
  53. {$else}
  54. {
  55. this one is special for the return value being 64-bit..
  56. hi/lo offset not yet tested.
  57. NetBSD: ok, but implicit return value in edx:eax
  58. FreeBSD: same implementation as NetBSD.
  59. }
  60. begin
  61. {$ifdef CPU64}
  62. {$ifdef freebsd}
  63. // newer style, no align zeroes in _syscall
  64. Fplseek:=do_syscall(syscall_nr___syscall,syscall_nr_lseek,TSysParam(fd),Offset,whence);
  65. {$else}
  66. Fplseek:=do_syscall(syscall_nr___syscall,syscall_nr_lseek,TSysParam(fd),0,Offset,whence);
  67. {$endif}
  68. {$else}
  69. {$ifdef freebsd}
  70. Fplseek:=do_syscall(syscall_nr___syscall,syscall_nr_lseek,0,TSysParam(fd),
  71. {$else}
  72. Fplseek:=do_syscall(syscall_nr___syscall,syscall_nr_lseek,0,TSysParam(fd),0,
  73. {$endif}
  74. {$ifdef ENDIAN_BIG}hi(offset),lo(offset){$endif}
  75. {$ifdef ENDIAN_LITTLE}lo(Offset),hi(offset){$endif},
  76. Whence);
  77. {$endif}
  78. end;
  79. {$endif}
  80. function Fpftruncate(fd : cint; flength : off_t): cint; [public, alias : 'FPC_SYSC_FTRUNCATE'];
  81. begin
  82. {$ifdef CPU64}
  83. {$ifdef freebsd}
  84. // newer style, no align zeroes in _syscall
  85. Fpftruncate:=Do_syscall(syscall_nr___syscall,syscall_nr_ftruncate, fd ,flength);
  86. {$else}
  87. Fpftruncate:=Do_syscall(syscall_nr___syscall,syscall_nr_ftruncate, fd ,0 ,flength);
  88. {$endif}
  89. {$else}
  90. {$ifdef freebsd}
  91. // newer style, no align zeroes in _syscall
  92. Fpftruncate:=Do_syscall(syscall_nr___syscall,syscall_nr_ftruncate,0,fd,lo(flength),hi(flength));
  93. {$else}
  94. Fpftruncate:=Do_syscall(syscall_nr___syscall,syscall_nr_ftruncate,0,fd,0,lo(flength),hi(flength));
  95. {$endif}
  96. {$endif}
  97. end;
  98. Function Fpmmap(start:pointer;len:size_t;prot:cint;flags:cint;fd:cint;offst:off_t):pointer; [public, alias: 'FPC_SYSC_MMAP'];
  99. begin
  100. {$ifdef CPU64}
  101. {$ifdef freebsd}
  102. Fpmmap:=pointer(ptruint(do_syscall(TSysParam(syscall_nr_mmap),TSysParam(Start),TSysParam(Len),TSysParam(Prot),TSysParam(Flags),TSysParam(fd),TSysParam(offst))));
  103. {$else}
  104. Fpmmap:=pointer(ptruint(do_syscall(TSysParam(syscall_nr_mmap),TSysParam(Start),TSysParam(Len),TSysParam(Prot),TSysParam(Flags),TSysParam(fd),0,TSysParam(offst))));
  105. {$endif}
  106. {$else}
  107. {$ifdef freebsd}
  108. Fpmmap:=pointer(ptruint(do_syscall(syscall_nr_mmap,TSysParam(Start),Len,Prot,Flags,fd,
  109. {$else}
  110. Fpmmap:=pointer(ptruint(do_syscall(syscall_nr_mmap,TSysParam(Start),Len,Prot,Flags,fd,0,
  111. {$endif}
  112. {$ifdef FPC_BIG_ENDIAN} hi(offst),lo(offst){$endif}
  113. {$ifdef FPC_LITTLE_ENDIAN} lo(offst),hi(offst){$endif}
  114. )));
  115. {$endif}
  116. end;
  117. {$endif}
  118. function Fpread(fd: cint; buf: pchar; nbytes : size_t): ssize_t; [public, alias : 'FPC_SYSC_READ'];
  119. begin
  120. Fpread:=do_syscall(syscall_nr_read,Fd,TSysParam(buf),nbytes);
  121. end;
  122. function Fpwrite(fd: cint;buf:pchar; nbytes : size_t): ssize_t; [public, alias : 'FPC_SYSC_WRITE'];
  123. begin
  124. Fpwrite:=do_syscall(syscall_nr_write,Fd,TSysParam(buf),nbytes);
  125. end;
  126. function Fpunlink(const path: pchar): cint; [public, alias : 'FPC_SYSC_UNLINK'];
  127. begin
  128. Fpunlink:=do_syscall(syscall_nr_unlink,TSysParam(path));
  129. end;
  130. function Fprename(old : pchar; newpath: pchar): cint; [public, alias : 'FPC_SYSC_RENAME'];
  131. begin
  132. Fprename:=do_syscall(syscall_nr_rename,TSysParam(old),TSysParam(newpath));
  133. end;
  134. {$ifdef freebsd}
  135. Function fpFstatat(fd: cint; path: pchar; var sb: stat; flag: cint):cint;
  136. begin
  137. fpFStatat:=do_syscall(syscall_nr_fstatat,fd,TSysParam(path),TSysParam(@sb),flag);
  138. end;
  139. {$endif}
  140. function Fpstat(const path: pchar; var buf : stat):cint; [public, alias : 'FPC_SYSC_STAT'];
  141. const
  142. AT_FDCWD=-100;
  143. begin
  144. {$ifdef freebsd}
  145. Fpstat:=FpFstatat(AT_FDCWD, path, buf, 0);
  146. {$else}
  147. Fpstat:=do_syscall(syscall_nr_stat,TSysParam(path),TSysParam(@buf));
  148. {$endif}
  149. end;
  150. {*****************************************************************************
  151. --- Directory:Directory related calls ---
  152. *****************************************************************************}
  153. function Fpchdir(path : pchar): cint; [public, alias : 'FPC_SYSC_CHDIR'];
  154. begin
  155. Fpchdir:=do_syscall(syscall_nr_chdir,TSysParam(path));
  156. end;
  157. function Fpmkdir(path : pchar; mode: mode_t):cint; [public, alias : 'FPC_SYSC_MKDIR'];
  158. begin {Mode is 16-bit on F-BSD 4!}
  159. Fpmkdir:=do_syscall(syscall_nr_mkdir,TSysParam(path),mode);
  160. end;
  161. function Fprmdir(path : pchar): cint; [public, alias : 'FPC_SYSC_RMDIR'];
  162. begin
  163. Fprmdir:=do_syscall(syscall_nr_rmdir,TSysParam(path));
  164. end;
  165. {$ifndef NewReaddir}
  166. const DIRBLKSIZ=1024;
  167. {$ifdef freebsd}
  168. function FpGetdirentries(fd : cint; buf : pchar; nbytes : clong) : cint;
  169. begin
  170. FpGetdirentries:=do_syscall(syscall_nr_getdirentries,fd,TSysParam(buf),nbytes,TSysParam(0));
  171. end;
  172. {$endif}
  173. function Fpfstat(fd : cint; var sb : stat): cint; forward;
  174. function Fpopendir(dirname : pchar): pdir; [public, alias : 'FPC_SYSC_OPENDIR'];
  175. var
  176. fd:longint;
  177. st:stat;
  178. ptr:pdir;
  179. save_errno:cint;
  180. begin
  181. Fpopendir:=nil;
  182. { Open it}
  183. fd:=Fpopen(dirname,O_RDONLY,438);
  184. if fd<0 then
  185. Begin
  186. Errno:=-1;
  187. exit;
  188. End;
  189. if FpFStat(fd,st)<0 then
  190. begin
  191. save_errno:=errno;
  192. FpClose(fd);
  193. errno:=save_errno;
  194. exit;
  195. end;
  196. { Is it a dir ? }
  197. if not((st.st_mode and $f000)=$4000)then
  198. begin
  199. FpClose(fd);
  200. errno:=ESysENOTDIR;
  201. exit
  202. end;
  203. new(ptr);
  204. if ptr=nil then
  205. Begin
  206. FpClose(fd);
  207. Errno:=1;
  208. exit;
  209. End;
  210. Getmem(ptr^.dd_buf,2*DIRBLKSIZ);
  211. if ptr^.dd_buf=nil then
  212. begin
  213. dispose(ptr);
  214. FpClose(fd);
  215. Errno:=1;
  216. exit;
  217. end;
  218. ptr^.dd_fd:=fd;
  219. ptr^.dd_loc:=-1;
  220. ptr^.dd_rewind:=ptrint(ptr^.dd_buf);
  221. ptr^.dd_size:=0;
  222. // ptr^.dd_max:=sizeof(ptr^.dd_buf^);
  223. Fpopendir:=ptr;
  224. end;
  225. function Fpclosedir(dirp : pdir): cint; [public, alias : 'FPC_SYSC_CLOSEDIR'];
  226. begin
  227. Fpclosedir:=Fpclose(dirp^.dd_fd);
  228. Freemem(dirp^.dd_buf);
  229. dispose(dirp);
  230. end;
  231. function Fpreaddir(dirp : pdir) : pdirent; [public, alias : 'FPC_SYSC_READDIR'];
  232. {Different from Linux, Readdir on BSD is based on Getdents, due to the
  233. missing of the readdir syscall.
  234. Getdents requires the buffer to be larger than the blocksize.
  235. This usually the sectorsize =512 bytes, but maybe tapedrives and harddisks
  236. with blockmode have this higher?}
  237. function readbuffer:longint;
  238. var retval :longint;
  239. begin
  240. {$ifdef freebsd}
  241. Retval:=FpGetdirentries(dirp^.dd_fd, @dirp^.dd_buf^, DIRBLKSIZ {sizeof(getdentsbuffer)});
  242. {$else}
  243. Retval:=do_syscall(syscall_nr_getdents,TSysParam(dirp^.dd_fd),TSysParam(@dirp^.dd_buf^),DIRBLKSIZ {sizeof(getdentsbuffer)});
  244. {$endif}
  245. dirp^.dd_rewind:=TSysParam(dirp^.dd_buf);
  246. if retval=0 then
  247. begin
  248. dirp^.dd_rewind:=0;
  249. dirp^.dd_loc:=0;
  250. end
  251. else
  252. dirP^.dd_loc:=retval;
  253. dirP^.dd_size:=retval;
  254. readbuffer:=retval;
  255. end;
  256. var
  257. FinalEntry : pdirent;
  258. novalid : boolean;
  259. Reclen : Longint;
  260. CurEntry : PDirent;
  261. begin
  262. if (dirp^.dd_buf=nil) or (dirp^.dd_loc=0) THEN
  263. exit(nil);
  264. if (dirp^.dd_loc=-1) OR {First readdir on this pdir. Initial fill of buffer}
  265. (dirp^.dd_rewind>=(ptrint(dirp^.dd_buf)+dirp^.dd_size)) then {no more entries left?}
  266. Begin
  267. if readbuffer=0 then {succesful read?}
  268. Exit(NIL); {No more data}
  269. End;
  270. FinalEntry:=NIL;
  271. CurEntry:=nil;
  272. repeat
  273. novalid:=false;
  274. CurEntry:=pdirent(dirp^.dd_rewind);
  275. {$ifdef dragonfly}
  276. RecLen:=(CurEntry^.d_namlen + 24) and $FFFFFFF8;
  277. {$else}
  278. RecLen:=CurEntry^.d_reclen;
  279. {$endif}
  280. if RecLen<>0 Then
  281. begin {valid direntry?}
  282. if CurEntry^.d_fileno<>0 then
  283. FinalEntry:=CurEntry;
  284. inc(dirp^.dd_rewind,Reclen);
  285. end
  286. else
  287. begin {block entirely searched or reclen=0}
  288. Novalid:=True;
  289. if dirp^.dd_loc<>0 THEN {blocks left?}
  290. if readbuffer()<>0 then {succesful read?}
  291. novalid:=false;
  292. end;
  293. until (FinalEntry<>nil) or novalid;
  294. If novalid then
  295. FinalEntry:=nil;
  296. FpReadDir:=FinalEntry;
  297. end;
  298. {$endif}
  299. {*****************************************************************************
  300. --- Process:Process & program handling - related calls ---
  301. *****************************************************************************}
  302. procedure Fpexit(status : cint); [public, alias : 'FPC_SYSC_EXIT'];
  303. begin
  304. do_syscall(syscall_nr_exit,status);
  305. end;
  306. {
  307. Change action of process upon receipt of a signal.
  308. Signum specifies the signal (all except SigKill and SigStop).
  309. If Act is non-nil, it is used to specify the new action.
  310. If OldAct is non-nil the previous action is saved there.
  311. }
  312. {$ifdef USE_SIGACTION_SIGTRAMP}
  313. procedure signal_trampoline; cdecl; forward;
  314. {$endif def USE_SIGACTION_SIGTRAMP}
  315. function Fpsigaction(sig: cint; act, oact: psigactionrec): cint; [public, alias : 'FPC_SYSC_SIGACTION'];
  316. {
  317. Change action of process upon receipt of a signal.
  318. Signum specifies the signal (all except SigKill and SigStop).
  319. If Act is non-nil, it is used to specify the new action.
  320. If OldAct is non-nil the previous action is saved there.
  321. }
  322. begin
  323. {$ifdef USE_SIGACTION_SIGTRAMP}
  324. fpsigaction:=do_syscall(syscall_nr___sigaction_sigtramp,TSysParam(sig),TSysParam(act),TSysParam(oact),
  325. TSysParam(@signal_trampoline),2);
  326. {$else not USE_SIGACTION_SIGTRAMP}
  327. fpsigaction:=do_syscall(syscall_nr_sigaction,TSysParam(sig),TSysParam(act),TSysParam(oact));
  328. {$endif not USE_SIGACTION_SIGTRAMP}
  329. end;
  330. (*=================== MOVED from sysunix.inc ========================*)
  331. function Fpfstat(fd : cint; var sb : stat): cint; [public, alias : 'FPC_SYSC_FSTAT'];
  332. begin
  333. fpFStat:=do_SysCall(syscall_nr_fstat,fd,TSysParam(@sb));
  334. end;
  335. {$ifdef NewReaddir}
  336. {$I readdir.inc}
  337. {$endif}
  338. function Fpfork : pid_t; [public, alias : 'FPC_SYSC_FORK'];
  339. {
  340. This function issues the 'fork' System call. the program is duplicated in memory
  341. and Execution continues in parent and child process.
  342. In the parent process, fork returns the PID of the child. In the child process,
  343. zero is returned.
  344. A negative value indicates that an error has occurred, the error is returned in
  345. LinuxError.
  346. }
  347. Begin
  348. Fpfork:=Do_syscall(SysCall_nr_fork);
  349. End;
  350. {
  351. function Fpexecve(const path : pathstr; const argv : ppchar; const envp: ppchar): cint;
  352. }
  353. {
  354. Replaces the current program by the program specified in path,
  355. arguments in args are passed to Execve.
  356. environment specified in ep is passed on.
  357. }
  358. {
  359. Begin
  360. path:=path+#0;
  361. do_syscall(syscall_nr_Execve,TSysParam(@path[1]),TSysParam(Argv),TSysParam(envp));
  362. End;
  363. }
  364. {
  365. function Fpexecve(const path : pchar; const argv : ppchar; const envp: ppchar): cint; [public, alias : 'FPC_SYSC_EXECVE'];
  366. }
  367. {
  368. Replaces the current program by the program specified in path,
  369. arguments in args are passed to Execve.
  370. environment specified in ep is passed on.
  371. }
  372. {
  373. Begin
  374. do_syscall(syscall_nr_Execve,TSysParam(path),TSysParam(Argv),TSysParam(envp));
  375. End;
  376. }
  377. function Fpwaitpid(pid : pid_t; stat_loc : pcint; options: cint): pid_t; [public, alias : 'FPC_SYSC_WAITPID'];
  378. {
  379. Waits until a child with PID Pid exits, or returns if it is exited already.
  380. Any resources used by the child are freed.
  381. The exit status is reported in the adress referred to by Status. It should
  382. be a longint.
  383. }
  384. begin // actually a wait4() call with 4th arg 0.
  385. FpWaitPID:=do_syscall(syscall_nr_WaitPID,PID,TSysParam(Stat_loc),options,0);
  386. end;
  387. function Fpaccess(const pathname : pchar; amode : cint): cint; [public, alias : 'FPC_SYSC_ACCESS'];
  388. {
  389. Test users access rights on the specified file.
  390. Mode is a mask xosisting of one or more of R_OK, W_OK, X_OK, F_OK.
  391. R,W,X stand for read,write and Execute access, simultaneously.
  392. F_OK checks whether the test would be allowed on the file.
  393. i.e. It checks the search permissions in all directory components
  394. of the path.
  395. The test is done with the real user-ID, instead of the effective.
  396. If access is denied, or an error occurred, false is returned.
  397. If access is granted, true is returned.
  398. Errors other than no access,are reported in unixerror.
  399. }
  400. begin
  401. FpAccess:=do_syscall(syscall_nr_access,TSysParam(pathname),amode);
  402. end;
  403. (*
  404. function Fpaccess(const pathname : pathstr; amode : cint): cint;
  405. {
  406. Test users access rights on the specified file.
  407. Mode is a mask xosisting of one or more of R_OK, W_OK, X_OK, F_OK.
  408. R,W,X stand for read,write and Execute access, simultaneously.
  409. F_OK checks whether the test would be allowed on the file.
  410. i.e. It checks the search permissions in all directory components
  411. of the path.
  412. The test is done with the real user-ID, instead of the effective.
  413. If access is denied, or an error occurred, false is returned.
  414. If access is granted, true is returned.
  415. Errors other than no access,are reported in unixerror.
  416. }
  417. begin
  418. pathname:=pathname+#0;
  419. Access:=do_syscall(syscall_nr_access, TSysParam(@pathname[1]),mode)=0;
  420. end;
  421. *)
  422. Function FpDup(fildes:cint):cint; [public, alias : 'FPC_SYSC_DUP'];
  423. begin
  424. Fpdup:=Do_syscall(syscall_nr_dup,TSysParam(fildes));
  425. end;
  426. Function FpDup2(fildes,fildes2:cint):cint; [public, alias : 'FPC_SYSC_DUP2'];
  427. begin
  428. Fpdup2:=do_syscall(syscall_nr_dup2,TSysParam(fildes),TSysParam(fildes2));
  429. end;
  430. Function Fpmunmap(start:pointer;len:size_t):cint; [public, alias :'FPC_SYSC_MUNMAP'];
  431. begin
  432. Fpmunmap:=do_syscall(syscall_nr_munmap,TSysParam(start),Len);
  433. end;
  434. Function Fpmprotect(start:pointer;len:size_t;prot:cint):cint; [public, alias : 'FPC_SYSC_MPROTECT'];
  435. begin
  436. Fpmprotect:=do_syscall(syscall_nr_mprotect,TSysParam(start),TSysParam(len),TSysParam(prot));
  437. end;
  438. {
  439. Interface to Unix ioctl call.
  440. Performs various operations on the filedescriptor Handle.
  441. Ndx describes the operation to perform.
  442. Data points to data needed for the Ndx function. The structure of this
  443. data is function-dependent.
  444. }
  445. Function FpIOCtl(Handle:cint;Ndx: TIOCtlRequest;Data: Pointer):cint; [public, alias : 'FPC_SYSC_IOCTL'];
  446. // This was missing here, instead hardcoded in Do_IsDevice
  447. begin
  448. FpIOCtl:=do_SysCall(syscall_nr_ioctl,handle,Ndx,TSysParam(data));
  449. end;
  450. Function FpGetPid:LongInt; [public, alias : 'FPC_SYSC_GETPID'];
  451. {
  452. Get Process ID.
  453. }
  454. begin
  455. FpGetPID:=do_syscall(syscall_nr_getpid);
  456. end;
  457. function fpgettimeofday(tp: ptimeval;tzp:ptimezone):cint; [public, alias: 'FPC_SYSC_GETTIMEOFDAY'];
  458. begin
  459. fpgettimeofday:=do_syscall(syscall_nr_gettimeofday,TSysParam(tp),TSysParam(tzp));
  460. end;
  461. function FPSigProcMask(how:cint;nset : psigset;oset : psigset):cint; [public, alias : 'FPC_SYSC_SIGPROCMASK'];
  462. {
  463. Change the list of currently blocked signals.
  464. How determines which signals will be blocked :
  465. SigBlock : Add SSet to the current list of blocked signals
  466. SigUnBlock : Remove the signals in SSet from the list of blocked signals.
  467. SigSetMask : Set the list of blocked signals to SSet
  468. if OldSSet is non-null, the old set will be saved there.
  469. }
  470. {$ifdef OpenBSD}
  471. { OpenBSD sigprocmask signal uses
  472. sigset_t that are cint type
  473. the value of nset^[0] must be passed as second parameter
  474. the old mask value is in return value }
  475. { How do we know if the call failed... PM }
  476. {$define OS_SIGPROCMASK_RETURNS_OVAL}
  477. {$endif}
  478. {$ifdef OS_SIGPROCMASK_RETURNS_OVAL}
  479. var
  480. res : cint;
  481. {$endif OS_SIGPROCMASK_RETURNS_OVAL}
  482. begin
  483. {$ifdef OS_SIGPROCMASK_RETURNS_OVAL}
  484. res:=do_syscall(syscall_nr_sigprocmask,tsysparam(how),TSysParam(nset^[0]));
  485. if assigned(oset) then
  486. oset^[0]:=res;
  487. FPsigprocmask:=0;
  488. {$else OS_SIGPROCMASK_RETURNS_OVAL}
  489. FPsigprocmask:=do_syscall(syscall_nr_sigprocmask,tsysparam(how),TSysParam(nset),TSysParam(oset));
  490. {$endif OS_SIGPROCMASK_RETURNS_OVAL}
  491. end;
  492. {$warning user BLA!}
  493. Function FpNanoSleep(req : ptimespec;rem : ptimespec) : cint; [public, alias : 'FPC_SYSC_NANOSLEEP'];
  494. begin
  495. FpNanoSleep:=Do_SysCall(syscall_nr_nanosleep,TSysParam(req),TSysParam(rem));
  496. end;
  497. function Fpgetcwd(pt:pchar; _size:size_t):pchar;[public, alias :'FPC_SYSC_GETCWD'];
  498. const intpathmax = 1024-4; // didn't use POSIX data in libc
  499. // implementation.
  500. var ept,bpt : pchar;
  501. c : char;
  502. ret : cint;
  503. begin
  504. if pt=NIL Then
  505. begin
  506. // POSIX: undefined. (exit(nil) ?)
  507. // BSD : allocate mem for path.
  508. getmem(pt,intpathmax);
  509. if pt=nil Then
  510. exit(nil);
  511. ept:=pt+intpathmax;
  512. end
  513. else
  514. Begin
  515. if (_size=0) Then
  516. Begin
  517. seterrno(ESysEINVAL);
  518. exit(nil);
  519. End;
  520. if (_size=1) Then
  521. Begin
  522. seterrno(ESysERANGE);
  523. exit(nil);
  524. End;
  525. ept:=pt+_size;
  526. end;
  527. ret := do_syscall(syscall_nr___getcwd,TSysParam(pt),TSysParam( ept - pt));
  528. If (ret = 0) Then
  529. begin
  530. If (pt[0] <> '/') Then
  531. Begin
  532. bpt := pt;
  533. ept := pt + strlen(pt) - 1;
  534. While (bpt < ept) Do
  535. Begin
  536. c := bpt^;
  537. bpt^:=ept^;
  538. inc(bpt);
  539. ept^:=c;
  540. dec(ept);
  541. End;
  542. End
  543. end
  544. {$if defined(openbsd) or defined (netbsd)}
  545. { At least for openbsd, a positive return value is
  546. the length of the returned pchar }
  547. else if (ret<0) then
  548. {$else not opensd}
  549. else
  550. {$endif openbsd}
  551. begin
  552. seterrno(-ret);
  553. pt:=nil;
  554. end;
  555. Fpgetcwd:=pt;
  556. end;
  557. Function fpReadLink(name,linkname:pchar;maxlen:size_t):cint; [public, alias : 'FPC_SYSC_READLINK'];
  558. begin
  559. fpreadlink:=do_syscall(syscall_nr_readlink, TSysParam(name),TSysParam(linkname),maxlen);
  560. end;
  561. function FpGetRLimit(resource:cint;rlim:PRLimit):cint; [public, alias : 'FPC_SYSC_GETRLIMIT'];
  562. begin
  563. fpgetrlimit:=do_syscall(syscall_nr_getrlimit,TSysParam(Resource),TSysParam(rlim));
  564. end;
  565. function FpSetRLimit(Resource:cint;rlim:PRLimit):cint; [public, alias : 'FPC_SYSC_SETRLIMIT'];
  566. begin
  567. fpsetrlimit:=do_syscall(syscall_nr_setrlimit,TSysParam(Resource),TSysParam(rlim));
  568. end;