unxsysc.inc 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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 fsync (fd : cint) : cint;
  56. begin
  57. fsync:=do_syscall(syscall_nr_fsync,fd);
  58. end;
  59. Function fpFlock (fd,mode : longint) : cint;
  60. begin
  61. fpFlock:=do_syscall(syscall_nr_flock,fd,mode);
  62. end;
  63. Function fStatFS(Fd:Longint;Var Info:tstatfs):cint;
  64. {
  65. Get all information on a fileSystem, and return it in Info.
  66. Fd is the file descriptor of a file/directory on the fileSystem
  67. you wish to investigate.
  68. }
  69. begin
  70. fStatFS:=do_syscall(syscall_nr_fstatfs,fd,longint(@info));
  71. end;
  72. Function StatFS(path:pchar;Var Info:tstatfs):cint;
  73. {
  74. Get all information on a fileSystem, and return it in Info.
  75. Fd is the file descriptor of a file/directory on the fileSystem
  76. you wish to investigate.
  77. }
  78. begin
  79. StatFS:=do_syscall(syscall_nr_statfs,longint(path),longint(@info));
  80. end;
  81. // needs oldfpccall;
  82. Function intAssignPipe(var pipe_in,pipe_out:longint;var errn:cint):cint; oldfpccall;
  83. {
  84. Sets up a pair of file variables, which act as a pipe. The first one can
  85. be read from, the second one can be written to.
  86. If the operation was unsuccesful, linuxerror is set.
  87. }
  88. begin
  89. {$ifdef cpui386}
  90. asm
  91. mov $42,%eax
  92. int $0x80
  93. jb .Lerror
  94. mov pipe_in,%ebx
  95. mov %eax,(%ebx)
  96. mov pipe_out,%ebx
  97. mov $0,%eax
  98. mov %edx,(%ebx)
  99. mov %eax,%ebx
  100. jmp .Lexit
  101. .Lerror:
  102. mov %eax,%ebx
  103. mov $-1,%eax
  104. .Lexit:
  105. mov Errn,%edx
  106. mov %ebx,(%edx)
  107. end;
  108. {$endif}
  109. end;
  110. {
  111. Function PClose(Var F:text) :cint;
  112. var
  113. pl : ^longint;
  114. res : longint;
  115. begin
  116. do_syscall(syscall_nr_close,Textrec(F).Handle);
  117. { closed our side, Now wait for the other - this appears to be needed ?? }
  118. pl:=@(textrec(f).userdata[2]);
  119. fpwaitpid(pl^,@res,0);
  120. pclose:=res shr 8;
  121. end;
  122. Function PClose(Var F:file) : cint;
  123. var
  124. pl : ^cint;
  125. res : cint;
  126. begin
  127. do_syscall(syscall_nr_close,filerec(F).Handle);
  128. { closed our side, Now wait for the other - this appears to be needed ?? }
  129. pl:=@(filerec(f).userdata[2]);
  130. fpwaitpid(pl^,@res,0);
  131. pclose:=res shr 8;
  132. end;
  133. }
  134. function MUnMap (P : Pointer; Size : size_t) : cint;
  135. begin
  136. MUnMap:=do_syscall(syscall_nr_munmap,longint(P),Size);
  137. end;
  138. {$else}
  139. {
  140. }
  141. {$endif}
  142. {
  143. function intClone(func:TCloneFunc;sp:pointer;flags:longint;args:pointer):longint; oldfpccall;
  144. var lerrno : Longint;
  145. errset : Boolean;
  146. Res : Longint;
  147. begin
  148. errset:=false;
  149. Res:=0;
  150. asm
  151. pushl %esi
  152. movl 12(%ebp), %esi // get stack addr
  153. subl $4, %esi
  154. movl 20(%ebp), %eax // get __arg
  155. movl %eax, (%esi)
  156. subl $4, %esi
  157. movl 8(%ebp), %eax // get __fn
  158. movl %eax, (%esi)
  159. pushl 16(%ebp)
  160. pushl %esi
  161. mov syscall_nr_rfork, %eax
  162. int $0x80 // call actualsyscall
  163. jb .L2
  164. test %edx, %edx
  165. jz .L1
  166. movl %esi,%esp
  167. popl %eax
  168. call %eax
  169. addl $8, %esp
  170. call halt // Does not return
  171. .L2:
  172. mov %eax,LErrNo
  173. mov $true,Errset
  174. mov $-1,%eax
  175. // jmp .L1
  176. .L1:
  177. addl $8, %esp
  178. popl %esi
  179. mov %eax,Res
  180. end;
  181. If ErrSet Then
  182. fpSetErrno(LErrno);
  183. intClone:=Res;
  184. end;
  185. function Clone(func:TCloneFunc;sp:pointer;flags:longint;args:pointer):longint;
  186. begin
  187. Clone:=
  188. intclone(tclonefunc(func),sp,flags,args);
  189. end;
  190. }