2
0

unxsysc.inc 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2000 by Marco van de Voort
  4. member of the Free Pascal development team.
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY;without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. {
  12. function clone(func:TCloneFunc;sp:pointer;flags:longint;args:pointer):longint;
  13. {NOT IMPLEMENTED YET UNDER BSD}
  14. begin // perhaps it is better to implement the hack from solaris then this msg
  15. HALT;
  16. END;
  17. if (pointer(func)=nil) or (sp=nil) then
  18. begin
  19. Lfpseterrno(EsysEInval);
  20. exit(-1);
  21. end;
  22. asm
  23. { Insert the argument onto the new stack. }
  24. movl sp,%ecx
  25. subl $8,%ecx
  26. movl args,%eax
  27. movl %eax,4(%ecx)
  28. { Save the function pointer as the zeroth argument.
  29. It will be popped off in the child in the ebx frobbing below. }
  30. movl func,%eax
  31. movl %eax,0(%ecx)
  32. { Do the system call }
  33. pushl %ebx
  34. pushl %ebx
  35. // movl flags,%ebx
  36. movl $251,%eax
  37. int $0x80
  38. popl %ebx
  39. popl %ebx
  40. test %eax,%eax
  41. jnz .Lclone_end
  42. { We're in the new thread }
  43. subl %ebp,%ebp { terminate the stack frame }
  44. call *%ebx
  45. { exit process }
  46. movl %eax,%ebx
  47. movl $1,%eax
  48. int $0x80
  49. .Lclone_end:
  50. movl %eax,__RESULT
  51. end;
  52. end;
  53. }
  54. {$ifndef FPC_USE_LIBC}
  55. Function fpFlock (fd,mode : longint) : cint;
  56. begin
  57. fpFlock:=do_syscall(syscall_nr_flock,fd,mode);
  58. end;
  59. Function fpfStatFS (Fd: cint; Info:pstatfs):cint;
  60. begin
  61. fpfstatfs:=do_SysCall(SysCall_nr_fstatfs,fd,TSysParam(info))
  62. end;
  63. Function fpStatFS (Path:pchar; Info:pstatfs):cint;
  64. begin
  65. fpstatfs:=do_SysCall(SysCall_nr_statfs,TSysParam(path),TSysParam(Info))
  66. end;
  67. Function fpfsync (fd : cint) : cint;
  68. begin
  69. fpfsync:=do_SysCall(syscall_nr_fsync, fd);
  70. end;
  71. // needs oldfpccall;
  72. Function intAssignPipe(var pipe_in,pipe_out:longint;var errn:cint):cint; oldfpccall;
  73. {
  74. Sets up a pair of file variables, which act as a pipe. The first one can
  75. be read from, the second one can be written to.
  76. If the operation was unsuccesful, linuxerror is set.
  77. }
  78. {$ifdef cpui386}
  79. begin
  80. asm
  81. mov $42,%eax
  82. int $0x80
  83. jb .Lerror
  84. mov pipe_in,%ebx
  85. mov %eax,(%ebx)
  86. mov pipe_out,%ebx
  87. mov $0,%eax
  88. mov %edx,(%ebx)
  89. mov %eax,%ebx
  90. jmp .Lexit
  91. .Lerror:
  92. mov %eax,%ebx
  93. mov $-1,%eax
  94. .Lexit:
  95. mov Errn,%edx
  96. mov %ebx,(%edx)
  97. end;
  98. end;
  99. {$else}
  100. {$ifdef cpux86_64}
  101. begin
  102. asm
  103. mov $42,%eax
  104. syscall
  105. jb .Lerror
  106. mov pipe_in,%rbx
  107. mov %eax,(%rbx)
  108. mov pipe_out,%rbx
  109. mov $0,%rax
  110. mov %edx,(%rbx)
  111. mov %rax,%rbx
  112. jmp .Lexit
  113. .Lerror:
  114. mov %eax,%ebx
  115. mov $-1,%eax
  116. .Lexit:
  117. mov Errn,%rdx
  118. mov %ebx,(%rdx)
  119. end;
  120. end;
  121. {$else}
  122. var fildes : tfildes;
  123. begin
  124. fildes[0]:=pipe_in;
  125. fildes[1]:=pipe_out;
  126. errn:=do_syscall(syscall_nr_pipe,TSysParam(@fildes));
  127. pipe_in:=fildes[0];
  128. pipe_out:=fildes[1];
  129. intAssignPipe:=errn;
  130. end;
  131. {$endif}
  132. {$endif}
  133. {
  134. Function PClose(Var F:text) :cint;
  135. var
  136. pl : ^longint;
  137. res : longint;
  138. begin
  139. do_syscall(syscall_nr_close,Textrec(F).Handle);
  140. { closed our side, Now wait for the other - this appears to be needed ?? }
  141. pl:=@(textrec(f).userdata[2]);
  142. fpwaitpid(pl^,@res,0);
  143. pclose:=res shr 8;
  144. end;
  145. Function PClose(Var F:file) : cint;
  146. var
  147. pl : ^cint;
  148. res : cint;
  149. begin
  150. do_syscall(syscall_nr_close,filerec(F).Handle);
  151. { closed our side, Now wait for the other - this appears to be needed ?? }
  152. pl:=@(filerec(f).userdata[2]);
  153. fpwaitpid(pl^,@res,0);
  154. pclose:=res shr 8;
  155. end;
  156. }
  157. function MUnMap (P : Pointer; Size : size_t) : cint;
  158. begin
  159. MUnMap:=do_syscall(syscall_nr_munmap,longint(P),Size);
  160. end;
  161. {$else}
  162. {
  163. }
  164. {$endif}
  165. {
  166. function intClone(func:TCloneFunc;sp:pointer;flags:longint;args:pointer):longint; oldfpccall;
  167. var lerrno : Longint;
  168. errset : Boolean;
  169. Res : Longint;
  170. begin
  171. errset:=false;
  172. Res:=0;
  173. asm
  174. pushl %esi
  175. movl 12(%ebp), %esi // get stack addr
  176. subl $4, %esi
  177. movl 20(%ebp), %eax // get __arg
  178. movl %eax, (%esi)
  179. subl $4, %esi
  180. movl 8(%ebp), %eax // get __fn
  181. movl %eax, (%esi)
  182. pushl 16(%ebp)
  183. pushl %esi
  184. mov syscall_nr_rfork, %eax
  185. int $0x80 // call actualsyscall
  186. jb .L2
  187. test %edx, %edx
  188. jz .L1
  189. movl %esi,%esp
  190. popl %eax
  191. call %eax
  192. addl $8, %esp
  193. call halt // Does not return
  194. .L2:
  195. mov %eax,LErrNo
  196. mov $true,Errset
  197. mov $-1,%eax
  198. // jmp .L1
  199. .L1:
  200. addl $8, %esp
  201. popl %esi
  202. mov %eax,Res
  203. end;
  204. If ErrSet Then
  205. fpSetErrno(LErrno);
  206. intClone:=Res;
  207. end;
  208. function Clone(func:TCloneFunc;sp:pointer;flags:longint;args:pointer):longint;
  209. begin
  210. Clone:=
  211. intclone(tclonefunc(func),sp,flags,args);
  212. end;
  213. }