unixsysc.inc 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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. LinuxError:=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. LinuxError:=Errno;
  65. end;
  66. }
  67. Function fdFlush (fd : Longint) : Boolean;
  68. begin
  69. fdflush:=do_syscall(syscall_nr_fsync,fd)=0;
  70. LinuxError:=Errno;
  71. end;
  72. Function Flock (fd,mode : longint) : boolean;
  73. begin
  74. Flock:=do_syscall(syscall_nr_flock,fd,mode)=0;
  75. LinuxError:=Errno;
  76. end;
  77. Function StatFS(Path:Pathstr;Var Info:Tstatfs):Boolean;
  78. {
  79. Get all information on a fileSystem, and return it in Info.
  80. Path is the name of a file/directory on the fileSystem you wish to
  81. investigate.
  82. }
  83. begin
  84. path:=path+#0;
  85. StatFS:=Do_Syscall(syscall_nr_statfs,longint(@path[1]),longint(@info))=0;
  86. LinuxError:=Errno;
  87. end;
  88. Function StatFS(Fd:Longint;Var Info:tstatfs):Boolean;
  89. {
  90. Get all information on a fileSystem, and return it in Info.
  91. Fd is the file descriptor of a file/directory on the fileSystem
  92. you wish to investigate.
  93. }
  94. begin
  95. StatFS:=do_syscall(syscall_nr_fstatfs,fd,longint(@info))=0;
  96. LinuxError:=Errno;
  97. end;
  98. Function AssignPipe(var pipe_in,pipe_out:longint):boolean;
  99. {
  100. Sets up a pair of file variables, which act as a pipe. The first one can
  101. be read from, the second one can be written to.
  102. If the operation was unsuccesful, linuxerror is set.
  103. }
  104. var
  105. pip : tpipe;
  106. begin
  107. do_syscall(syscall_nr_pipe,longint(@pip));
  108. LinuxError:=Errno;
  109. pipe_in:=pip[1];
  110. pipe_out:=pip[2];
  111. AssignPipe:=(LinuxError=0);
  112. end;
  113. Function PClose(Var F:text) :longint;
  114. var
  115. pl : ^longint;
  116. res : longint;
  117. begin
  118. do_syscall(syscall_nr_close,Textrec(F).Handle);
  119. { closed our side, Now wait for the other - this appears to be needed ?? }
  120. pl:=@(textrec(f).userdata[2]);
  121. fpwaitpid(pl^,res,0);
  122. pclose:=res shr 8;
  123. end;
  124. Function PClose(Var F:file) : longint;
  125. var
  126. pl : ^longint;
  127. res : longint;
  128. begin
  129. do_syscall(syscall_nr_close,filerec(F).Handle);
  130. { closed our side, Now wait for the other - this appears to be needed ?? }
  131. pl:=@(filerec(f).userdata[2]);
  132. fpwaitpid(pl^,res,0);
  133. pclose:=res shr 8;
  134. end;
  135. function MUnMap (P : Pointer; Size : Longint) : Boolean;
  136. begin
  137. MUnMap:=do_syscall(syscall_nr_munmap,longint(P),Size)=0;
  138. LinuxError:=Errno;
  139. end;
  140. function Clone(func:TCloneFunc;sp:pointer;flags:longint;args:pointer):longint; assembler;
  141. asm
  142. pushl %esi
  143. movl 12(%ebp), %esi // get stack addr
  144. subl $4, %esi
  145. movl 20(%ebp), %eax // get __arg
  146. movl %eax, (%esi)
  147. subl $4, %esi
  148. movl 8(%ebp), %eax // get __fn
  149. movl %eax, (%esi)
  150. pushl 16(%ebp)
  151. pushl %esi
  152. mov syscall_nr_rfork, %eax
  153. int $0x80 // call actualsyscall
  154. jb .L2
  155. test %edx, %edx
  156. jz .L1
  157. movl %esi,%esp
  158. popl %eax
  159. call %eax
  160. addl $8, %esp
  161. call halt // Does not return
  162. .L2:
  163. mov %eax,ErrNo
  164. mov $-1,%eax
  165. jmp .L1
  166. // jmp PIC_PLT(HIDENAME(cerror))
  167. .L1:
  168. addl $8, %esp
  169. popl %esi
  170. end;
  171. {
  172. $Log$
  173. Revision 1.8 2003-09-14 20:15:01 marco
  174. * Unix reform stage two. Remove all calls from Unix that exist in Baseunix.
  175. Revision 1.7 2003/01/05 19:02:29 marco
  176. * Should now work with baseunx. (gmake all works)
  177. Revision 1.6 2002/10/18 12:19:59 marco
  178. * Fixes to get the generic *BSD RTL compiling again + fixes for thread
  179. support. Still problems left in fexpand. (inoutres?) Therefore fixed
  180. sysposix not yet commited
  181. Revision 1.5 2002/09/07 16:01:18 peter
  182. * old logs removed and tabs fixed
  183. Revision 1.4 2002/05/06 09:35:09 marco
  184. * Some stuff from 1.0.x ported
  185. }