unxsysc.inc 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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. begin
  79. {$ifdef cpui386}
  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. {$endif}
  99. end;
  100. {
  101. Function PClose(Var F:text) :cint;
  102. var
  103. pl : ^longint;
  104. res : longint;
  105. begin
  106. do_syscall(syscall_nr_close,Textrec(F).Handle);
  107. { closed our side, Now wait for the other - this appears to be needed ?? }
  108. pl:=@(textrec(f).userdata[2]);
  109. fpwaitpid(pl^,@res,0);
  110. pclose:=res shr 8;
  111. end;
  112. Function PClose(Var F:file) : cint;
  113. var
  114. pl : ^cint;
  115. res : cint;
  116. begin
  117. do_syscall(syscall_nr_close,filerec(F).Handle);
  118. { closed our side, Now wait for the other - this appears to be needed ?? }
  119. pl:=@(filerec(f).userdata[2]);
  120. fpwaitpid(pl^,@res,0);
  121. pclose:=res shr 8;
  122. end;
  123. }
  124. function MUnMap (P : Pointer; Size : size_t) : cint;
  125. begin
  126. MUnMap:=do_syscall(syscall_nr_munmap,longint(P),Size);
  127. end;
  128. {$else}
  129. {
  130. }
  131. {$endif}
  132. {
  133. function intClone(func:TCloneFunc;sp:pointer;flags:longint;args:pointer):longint; oldfpccall;
  134. var lerrno : Longint;
  135. errset : Boolean;
  136. Res : Longint;
  137. begin
  138. errset:=false;
  139. Res:=0;
  140. asm
  141. pushl %esi
  142. movl 12(%ebp), %esi // get stack addr
  143. subl $4, %esi
  144. movl 20(%ebp), %eax // get __arg
  145. movl %eax, (%esi)
  146. subl $4, %esi
  147. movl 8(%ebp), %eax // get __fn
  148. movl %eax, (%esi)
  149. pushl 16(%ebp)
  150. pushl %esi
  151. mov syscall_nr_rfork, %eax
  152. int $0x80 // call actualsyscall
  153. jb .L2
  154. test %edx, %edx
  155. jz .L1
  156. movl %esi,%esp
  157. popl %eax
  158. call %eax
  159. addl $8, %esp
  160. call halt // Does not return
  161. .L2:
  162. mov %eax,LErrNo
  163. mov $true,Errset
  164. mov $-1,%eax
  165. // jmp .L1
  166. .L1:
  167. addl $8, %esp
  168. popl %esi
  169. mov %eax,Res
  170. end;
  171. If ErrSet Then
  172. fpSetErrno(LErrno);
  173. intClone:=Res;
  174. end;
  175. function Clone(func:TCloneFunc;sp:pointer;flags:longint;args:pointer):longint;
  176. begin
  177. Clone:=
  178. intclone(tclonefunc(func),sp,flags,args);
  179. end;
  180. }