unixsysc.inc 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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. {$ifndef FPC_USE_LIBC}
  56. Function fsync (fd : cint) : cint;
  57. begin
  58. fsync:=do_syscall(syscall_nr_fsync,fd);
  59. end;
  60. Function Flock (fd,mode : longint) : cint;
  61. begin
  62. Flock:=do_syscall(syscall_nr_flock,fd,mode);
  63. end;
  64. Function fStatFS(Fd:Longint;Var Info:tstatfs):cint;
  65. {
  66. Get all information on a fileSystem, and return it in Info.
  67. Fd is the file descriptor of a file/directory on the fileSystem
  68. you wish to investigate.
  69. }
  70. begin
  71. fStatFS:=do_syscall(syscall_nr_fstatfs,fd,longint(@info));
  72. end;
  73. // needs oldfpccall;
  74. Function intAssignPipe(var pipe_in,pipe_out:longint;var errn:cint):cint; {$ifndef ver1_0} oldfpccall;{$endif}
  75. {
  76. Sets up a pair of file variables, which act as a pipe. The first one can
  77. be read from, the second one can be written to.
  78. If the operation was unsuccesful, linuxerror is set.
  79. }
  80. begin
  81. asm
  82. mov $42,%eax
  83. int $0x80
  84. jb .Lerror
  85. mov pipe_in,%ebx
  86. mov %eax,(%ebx)
  87. mov pipe_out,%ebx
  88. mov $0,%eax
  89. mov %edx,(%ebx)
  90. mov %eax,%ebx
  91. jmp .Lexit
  92. .Lerror:
  93. mov %eax,%ebx
  94. mov $-1,%eax
  95. .Lexit:
  96. mov Errn,%edx
  97. mov %ebx,(%edx)
  98. end;
  99. end;
  100. Function PClose(Var F:text) :cint;
  101. var
  102. pl : ^longint;
  103. res : longint;
  104. begin
  105. do_syscall(syscall_nr_close,Textrec(F).Handle);
  106. { closed our side, Now wait for the other - this appears to be needed ?? }
  107. pl:=@(textrec(f).userdata[2]);
  108. fpwaitpid(pl^,@res,0);
  109. pclose:=res shr 8;
  110. end;
  111. Function PClose(Var F:file) : cint;
  112. var
  113. pl : ^cint;
  114. res : cint;
  115. begin
  116. do_syscall(syscall_nr_close,filerec(F).Handle);
  117. { closed our side, Now wait for the other - this appears to be needed ?? }
  118. pl:=@(filerec(f).userdata[2]);
  119. fpwaitpid(pl^,@res,0);
  120. pclose:=res shr 8;
  121. end;
  122. function MUnMap (P : Pointer; Size : size_t) : cint;
  123. begin
  124. MUnMap:=do_syscall(syscall_nr_munmap,longint(P),Size);
  125. end;
  126. {$else}
  127. Function PClose(Var F:file) : cint;
  128. var
  129. pl : ^cint;
  130. res : cint;
  131. begin
  132. fpclose(filerec(F).Handle);
  133. { closed our side, Now wait for the other - this appears to be needed ?? }
  134. pl:=@(filerec(f).userdata[2]);
  135. fpwaitpid(pl^,@res,0);
  136. pclose:=res shr 8;
  137. end;
  138. Function PClose(Var F:text) :cint;
  139. var
  140. pl : ^longint;
  141. res : longint;
  142. begin
  143. fpclose(Textrec(F).Handle);
  144. { closed our side, Now wait for the other - this appears to be needed ?? }
  145. pl:=@(textrec(f).userdata[2]);
  146. fpwaitpid(pl^,@res,0);
  147. pclose:=res shr 8;
  148. end;
  149. {$endif}
  150. // can't have oldfpccall here, linux doesn't need it.
  151. Function AssignPipe(var pipe_in,pipe_out:cint):cint; [public, alias : 'FPC_SYSC_ASSIGNPIPE'];
  152. {
  153. Sets up a pair of file variables, which act as a pipe. The first one can
  154. be read from, the second one can be written to.
  155. If the operation was unsuccesful, linuxerror is set.
  156. }
  157. var
  158. ret : longint;
  159. errn : cint;
  160. {$ifdef FPC_USE_LIBC}
  161. fdis : array[0..1] of cint;
  162. {$endif}
  163. begin
  164. {$ifndef FPC_USE_LIBC}
  165. ret:=intAssignPipe(pipe_in,pipe_out,errn);
  166. if ret=-1 Then
  167. fpseterrno(errn);
  168. {$ELSE}
  169. fdis[0]:=pipe_in;
  170. fdis[1]:=pipe_out;
  171. ret:=pipe(fdis);
  172. pipe_in:=fdis[0];
  173. pipe_out:=fdis[1];
  174. {$ENDIF}
  175. AssignPipe:=ret;
  176. end;
  177. {
  178. function intClone(func:TCloneFunc;sp:pointer;flags:longint;args:pointer):longint; {$ifndef ver1_0} oldfpccall; {$endif}
  179. var lerrno : Longint;
  180. errset : Boolean;
  181. Res : Longint;
  182. begin
  183. errset:=false;
  184. Res:=0;
  185. asm
  186. pushl %esi
  187. movl 12(%ebp), %esi // get stack addr
  188. subl $4, %esi
  189. movl 20(%ebp), %eax // get __arg
  190. movl %eax, (%esi)
  191. subl $4, %esi
  192. movl 8(%ebp), %eax // get __fn
  193. movl %eax, (%esi)
  194. pushl 16(%ebp)
  195. pushl %esi
  196. mov syscall_nr_rfork, %eax
  197. int $0x80 // call actualsyscall
  198. jb .L2
  199. test %edx, %edx
  200. jz .L1
  201. movl %esi,%esp
  202. popl %eax
  203. call %eax
  204. addl $8, %esp
  205. call halt // Does not return
  206. .L2:
  207. mov %eax,LErrNo
  208. mov $true,Errset
  209. mov $-1,%eax
  210. // jmp .L1
  211. .L1:
  212. addl $8, %esp
  213. popl %esi
  214. mov %eax,Res
  215. end;
  216. If ErrSet Then
  217. fpSetErrno(LErrno);
  218. intClone:=Res;
  219. end;
  220. function Clone(func:TCloneFunc;sp:pointer;flags:longint;args:pointer):longint;
  221. begin
  222. Clone:=
  223. intclone(tclonefunc(func),sp,flags,args);
  224. end;
  225. }
  226. {
  227. $Log$
  228. Revision 1.17 2003-12-30 12:32:30 marco
  229. *** empty log message ***
  230. Revision 1.16 2003/11/19 17:11:40 marco
  231. * termio unit
  232. Revision 1.15 2003/11/19 10:12:02 marco
  233. * more cleanups
  234. Revision 1.14 2003/11/17 10:05:51 marco
  235. * threads for FreeBSD. Not working tho
  236. Revision 1.13 2003/11/14 16:21:59 marco
  237. * linuxerror elimination
  238. Revision 1.12 2003/11/09 12:00:16 marco
  239. * pipe fix
  240. Revision 1.11 2003/09/20 12:38:29 marco
  241. * FCL now compiles for FreeBSD with new 1.1. Now Linux.
  242. Revision 1.10 2003/09/15 20:08:49 marco
  243. * small fixes. FreeBSD now cycles
  244. Revision 1.9 2003/09/15 07:09:58 marco
  245. * small fixes, round 1
  246. Revision 1.8 2003/09/14 20:15:01 marco
  247. * Unix reform stage two. Remove all calls from Unix that exist in Baseunix.
  248. Revision 1.7 2003/01/05 19:02:29 marco
  249. * Should now work with baseunx. (gmake all works)
  250. Revision 1.6 2002/10/18 12:19:59 marco
  251. * Fixes to get the generic *BSD RTL compiling again + fixes for thread
  252. support. Still problems left in fexpand. (inoutres?) Therefore fixed
  253. sysposix not yet commited
  254. Revision 1.5 2002/09/07 16:01:18 peter
  255. * old logs removed and tabs fixed
  256. Revision 1.4 2002/05/06 09:35:09 marco
  257. * Some stuff from 1.0.x ported
  258. }