unixsysc.inc 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 2000 by Marco van de Voort
  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. {
  13. function clone(func:TCloneFunc;sp:pointer;flags:longint;args:pointer):longint;
  14. {NOT IMPLEMENTED YET UNDER BSD}
  15. begin // perhaps it is better to implement the hack from solaris then this msg
  16. HALT;
  17. END;
  18. if (pointer(func)=nil) or (sp=nil) then
  19. begin
  20. Lfpseterrno(EsysEInval);
  21. exit(-1);
  22. end;
  23. asm
  24. { Insert the argument onto the new stack. }
  25. movl sp,%ecx
  26. subl $8,%ecx
  27. movl args,%eax
  28. movl %eax,4(%ecx)
  29. { Save the function pointer as the zeroth argument.
  30. It will be popped off in the child in the ebx frobbing below. }
  31. movl func,%eax
  32. movl %eax,0(%ecx)
  33. { Do the system call }
  34. pushl %ebx
  35. pushl %ebx
  36. // movl flags,%ebx
  37. movl $251,%eax
  38. int $0x80
  39. popl %ebx
  40. popl %ebx
  41. test %eax,%eax
  42. jnz .Lclone_end
  43. { We're in the new thread }
  44. subl %ebp,%ebp { terminate the stack frame }
  45. call *%ebx
  46. { exit process }
  47. movl %eax,%ebx
  48. movl $1,%eax
  49. int $0x80
  50. .Lclone_end:
  51. movl %eax,__RESULT
  52. end;
  53. end;
  54. }
  55. {
  56. Procedure GetTimeOfDay(var tv:timeval);
  57. {
  58. Get the number of seconds since 00:00, January 1 1970, GMT
  59. the time NOT corrected any way
  60. }
  61. var tz : timezone;
  62. begin
  63. do_syscall(syscall_nr_gettimeofday,longint(@tv),longint(@tz));
  64. end;
  65. }
  66. Function fsync (fd : cint) : cint;
  67. begin
  68. fsync:=do_syscall(syscall_nr_fsync,fd);
  69. end;
  70. Function Flock (fd,mode : longint) : cint;
  71. begin
  72. Flock:=do_syscall(syscall_nr_flock,fd,mode);
  73. end;
  74. Function StatFS(Path:Pathstr;Var Info:Tstatfs):cint;
  75. {
  76. Get all information on a fileSystem, and return it in Info.
  77. Path is the name of a file/directory on the fileSystem you wish to
  78. investigate.
  79. }
  80. begin
  81. path:=path+#0;
  82. StatFS:=Do_Syscall(syscall_nr_statfs,longint(@path[1]),longint(@info));
  83. end;
  84. Function fStatFS(Fd:Longint;Var Info:tstatfs):cint;
  85. {
  86. Get all information on a fileSystem, and return it in Info.
  87. Fd is the file descriptor of a file/directory on the fileSystem
  88. you wish to investigate.
  89. }
  90. begin
  91. fStatFS:=do_syscall(syscall_nr_fstatfs,fd,longint(@info));
  92. end;
  93. // needs oldfpccall;
  94. Function intAssignPipe(var pipe_in,pipe_out:longint;var errn:cint):cint; {$ifndef ver1_0} oldfpccall;{$endif}
  95. {
  96. Sets up a pair of file variables, which act as a pipe. The first one can
  97. be read from, the second one can be written to.
  98. If the operation was unsuccesful, linuxerror is set.
  99. }
  100. begin
  101. asm
  102. mov $42,%eax
  103. int $0x80
  104. jb .Lerror
  105. mov pipe_in,%ebx
  106. mov %eax,(%ebx)
  107. mov pipe_out,%ebx
  108. mov $0,%eax
  109. mov %edx,(%ebx)
  110. mov %eax,%ebx
  111. jmp .Lexit
  112. .Lerror:
  113. mov %eax,%ebx
  114. mov $-1,%eax
  115. .Lexit:
  116. mov Errn,%edx
  117. mov %ebx,(%edx)
  118. end;
  119. end;
  120. // can't have oldfpccall here, linux doesn't need it.
  121. Function AssignPipe(var pipe_in,pipe_out:cint):cint; [public, alias : 'FPC_SYSC_ASSIGNPIPE'];
  122. {
  123. Sets up a pair of file variables, which act as a pipe. The first one can
  124. be read from, the second one can be written to.
  125. If the operation was unsuccesful, linuxerror is set.
  126. }
  127. var
  128. ret : longint;
  129. errn : cint;
  130. begin
  131. ret:=intAssignPipe(pipe_in,pipe_out,errn);
  132. if ret=-1 Then
  133. fpseterrno(errn);
  134. AssignPipe:=ret;
  135. end;
  136. Function PClose(Var F:text) :longint;
  137. var
  138. pl : ^longint;
  139. res : longint;
  140. begin
  141. do_syscall(syscall_nr_close,Textrec(F).Handle);
  142. { closed our side, Now wait for the other - this appears to be needed ?? }
  143. pl:=@(textrec(f).userdata[2]);
  144. fpwaitpid(pl^,@res,0);
  145. pclose:=res shr 8;
  146. end;
  147. Function PClose(Var F:file) : cint;
  148. var
  149. pl : ^cint;
  150. res : cint;
  151. begin
  152. do_syscall(syscall_nr_close,filerec(F).Handle);
  153. { closed our side, Now wait for the other - this appears to be needed ?? }
  154. pl:=@(filerec(f).userdata[2]);
  155. fpwaitpid(pl^,@res,0);
  156. pclose:=res shr 8;
  157. end;
  158. function MUnMap (P : Pointer; Size : Longint) : Boolean;
  159. begin
  160. MUnMap:=do_syscall(syscall_nr_munmap,longint(P),Size)=0;
  161. end;
  162. {
  163. function intClone(func:TCloneFunc;sp:pointer;flags:longint;args:pointer):longint; {$ifndef ver1_0} oldfpccall; {$endif}
  164. var lerrno : Longint;
  165. errset : Boolean;
  166. Res : Longint;
  167. begin
  168. errset:=false;
  169. Res:=0;
  170. asm
  171. pushl %esi
  172. movl 12(%ebp), %esi // get stack addr
  173. subl $4, %esi
  174. movl 20(%ebp), %eax // get __arg
  175. movl %eax, (%esi)
  176. subl $4, %esi
  177. movl 8(%ebp), %eax // get __fn
  178. movl %eax, (%esi)
  179. pushl 16(%ebp)
  180. pushl %esi
  181. mov syscall_nr_rfork, %eax
  182. int $0x80 // call actualsyscall
  183. jb .L2
  184. test %edx, %edx
  185. jz .L1
  186. movl %esi,%esp
  187. popl %eax
  188. call %eax
  189. addl $8, %esp
  190. call halt // Does not return
  191. .L2:
  192. mov %eax,LErrNo
  193. mov $true,Errset
  194. mov $-1,%eax
  195. // jmp .L1
  196. .L1:
  197. addl $8, %esp
  198. popl %esi
  199. mov %eax,Res
  200. end;
  201. If ErrSet Then
  202. fpSetErrno(LErrno);
  203. intClone:=Res;
  204. end;
  205. function Clone(func:TCloneFunc;sp:pointer;flags:longint;args:pointer):longint;
  206. begin
  207. Clone:=
  208. intclone(tclonefunc(func),sp,flags,args);
  209. end;
  210. }
  211. {
  212. $Log$
  213. Revision 1.16 2003-11-19 17:11:40 marco
  214. * termio unit
  215. Revision 1.15 2003/11/19 10:12:02 marco
  216. * more cleanups
  217. Revision 1.14 2003/11/17 10:05:51 marco
  218. * threads for FreeBSD. Not working tho
  219. Revision 1.13 2003/11/14 16:21:59 marco
  220. * linuxerror elimination
  221. Revision 1.12 2003/11/09 12:00:16 marco
  222. * pipe fix
  223. Revision 1.11 2003/09/20 12:38:29 marco
  224. * FCL now compiles for FreeBSD with new 1.1. Now Linux.
  225. Revision 1.10 2003/09/15 20:08:49 marco
  226. * small fixes. FreeBSD now cycles
  227. Revision 1.9 2003/09/15 07:09:58 marco
  228. * small fixes, round 1
  229. Revision 1.8 2003/09/14 20:15:01 marco
  230. * Unix reform stage two. Remove all calls from Unix that exist in Baseunix.
  231. Revision 1.7 2003/01/05 19:02:29 marco
  232. * Should now work with baseunx. (gmake all works)
  233. Revision 1.6 2002/10/18 12:19:59 marco
  234. * Fixes to get the generic *BSD RTL compiling again + fixes for thread
  235. support. Still problems left in fexpand. (inoutres?) Therefore fixed
  236. sysposix not yet commited
  237. Revision 1.5 2002/09/07 16:01:18 peter
  238. * old logs removed and tabs fixed
  239. Revision 1.4 2002/05/06 09:35:09 marco
  240. * Some stuff from 1.0.x ported
  241. }