Browse Source

* Only "difficult" functions + execvp + termios + rewinddir left to do

marco 23 years ago
parent
commit
21fb7bbb50

+ 56 - 6
rtl/bsd/bsdfuncs.inc

@@ -16,9 +16,10 @@
 
 
  **********************************************************************}
  **********************************************************************}
 
 
-{$i syscallh.inc}
-{$i sysnr.inc}
-{$i bsdsysch.inc}
+{$i syscallh.inc}	// do_syscall declarations themselves
+{$i sysnr.inc}		// syscall numbers.
+{$i bsdsysch.inc}	// external interface to syscalls in system unit.
+{$i posixunx.inc}	// generic calls. (like getenv)
 
 
 Function sys_Kill(Pid:pid_t;Sig:cint):cint;
 Function sys_Kill(Pid:pid_t;Sig:cint):cint;
 {
 {
@@ -455,16 +456,65 @@ begin
  sys_fcntl:=do_syscall(syscall_nr_fcntl,fildes,cmd);
  sys_fcntl:=do_syscall(syscall_nr_fcntl,fildes,cmd);
 end;
 end;
 
 
-function sys_execve(path:pchar;argv:ppchar;envp:ppchar):cint
+function sys_execve(path:pchar;argv:ppchar;envp:ppchar):cint;
 
 
 Begin
 Begin
- sys_execve:=do_syscall(syscall_nr_Execve,longint(path),longint(argv),longint(envp));
+  sys_execve:=do_syscall(syscall_nr_Execve,longint(path),longint(argv),longint(envp));
 End;
 End;
 
 
+function sys_execv(path:pchar;argv:ppchar):cint;
+
+Begin
+  sys_execv:=do_syscall(syscall_nr_Execve,longint(path),longint(argv),longint(envp));
+End;
+
+CONST RUSAGE_SELF	= 0;
+      RUSAGE_CHILDREN   = -1;
+
+function sys_getrusage(who:cint;var ru : rusage):cint;
+
+begin
+ sys_getrusage:=do_syscall(syscall_nr_getrusage,longint(who),longint(@ru));
+end;
+
+function sys_times(var buffer : tms):clock_t;
+
+var ru : rusage;
+    t  : timeval;
+
+CONST CLK_TCK=128;
+
+function CONVTCK(r:timeval):clock_t;	
+{
+ * Convert usec to clock ticks; could do (usec * CLK_TCK) / 1000000,
+ * but this would overflow if we switch to nanosec.
+ }
+begin
+ CONVTCK:=(r.tv_sec * CLK_TCK + r.tv_usec DIV (1000000 DIV CLK_TCK));
+end;
+
+begin
+
+	if (sys_getrusage(RUSAGE_SELF, ru) < 0) Then
+	    exit(clock_t(-1));
+	buffer.tms_utime := CONVTCK(ru.ru_utime);
+	buffer.tms_stime := CONVTCK(ru.ru_stime);
+	if (sys_getrusage(RUSAGE_CHILDREN, ru) < 0) Then
+ 	    exit(clock_t(-1));
+	buffer.tms_cutime := CONVTCK(ru.ru_utime);
+	buffer.tms_cstime := CONVTCK(ru.ru_stime);
+	if do_syscall(syscall_nr_gettimeofday,longint(@t),0)<>0 Then
+		    exit(clock_t(-1));
+	sys_times:=clock_t(CONVTCK(t));
+end;
+
 
 
 {
 {
  $Log$
  $Log$
- Revision 1.7  2002-10-27 11:58:29  marco
+ Revision 1.8  2002-10-27 17:21:29  marco
+  * Only "difficult" functions + execvp + termios + rewinddir left to do
+
+ Revision 1.7  2002/10/27 11:58:29  marco
   * Modifications from Saturday.
   * Modifications from Saturday.
 
 
  Revision 1.6  2002/10/26 18:27:51  marco
  Revision 1.6  2002/10/26 18:27:51  marco

+ 8 - 4
rtl/bsd/bsdsysc.inc

@@ -369,18 +369,19 @@ Begin
   do_syscall(syscall_nr_Execve,longint(@path[1]),longint(Argv),longint(envp));
   do_syscall(syscall_nr_Execve,longint(@path[1]),longint(Argv),longint(envp));
 End;
 End;
 }
 }
-
+{
 function sys_execve(const path : pchar; const argv : ppchar; const envp: ppchar): cint;  [public, alias : 'FPC_SYSC_EXECVE'];
 function sys_execve(const path : pchar; const argv : ppchar; const envp: ppchar): cint;  [public, alias : 'FPC_SYSC_EXECVE'];
+}
 {
 {
   Replaces the current program by the program specified in path,
   Replaces the current program by the program specified in path,
   arguments in args are passed to Execve.
   arguments in args are passed to Execve.
   environment specified in ep is passed on.
   environment specified in ep is passed on.
 }
 }
-
+{
 Begin
 Begin
   do_syscall(syscall_nr_Execve,longint(path),longint(Argv),longint(envp));
   do_syscall(syscall_nr_Execve,longint(path),longint(Argv),longint(envp));
 End;
 End;
-
+}
 function sys_waitpid(pid : pid_t; var stat_loc : cint; options: cint): pid_t; [public, alias : 'FPC_SYSC_WAITPID'];
 function sys_waitpid(pid : pid_t; var stat_loc : cint; options: cint): pid_t; [public, alias : 'FPC_SYSC_WAITPID'];
 {
 {
   Waits until a child with PID Pid exits, or returns if it is exited already.
   Waits until a child with PID Pid exits, or returns if it is exited already.
@@ -573,7 +574,10 @@ end;
 
 
 {
 {
  $Log$
  $Log$
- Revision 1.7  2002-10-27 11:58:29  marco
+ Revision 1.8  2002-10-27 17:21:29  marco
+  * Only "difficult" functions + execvp + termios + rewinddir left to do
+
+ Revision 1.7  2002/10/27 11:58:29  marco
   * Modifications from Saturday.
   * Modifications from Saturday.
 
 
  Revision 1.6  2002/10/26 18:27:51  marco
  Revision 1.6  2002/10/26 18:27:51  marco

+ 25 - 1
rtl/bsd/bsdtypes.inc

@@ -40,9 +40,33 @@ Type
   ptimezone =^timezone;
   ptimezone =^timezone;
   TTimeZone = timezone;
   TTimeZone = timezone;
 
 
+  rusage = packed record
+	ru_utime    : timeval;		{ user time used }
+	ru_stime    : timeval;		{ system time used }
+	ru_maxrss   : clong;		{ max resident set size }
+	ru_ixrss    : clong;		{ integral shared memory size }
+	ru_idrss    : clong;		{ integral unshared data " }
+	ru_isrss    : clong;		{ integral unshared stack " }
+	ru_minflt   : clong;		{ page reclaims }
+	ru_majflt   : clong;		{ page faults }
+	ru_nswap    : clong;		{ swaps }
+	ru_inblock  : clong;		{ block input operations }
+	ru_oublock  : clong;		{ block output operations }
+	ru_msgsnd   : clong;		{ messages sent }
+	ru_msgrcv   : clong;		{ messages received }
+	ru_nsignals : clong;		{ signals received }
+	ru_nvcsw    : clong;		{ voluntary context switches }
+	ru_nivcsw   : clong;		{ involuntary " }
+	end;
+// #define	ru_last		ru_nivcsw
+// #define	ru_first	ru_ixrss
+
 {
 {
  $Log$
  $Log$
- Revision 1.3  2002-10-27 11:58:30  marco
+ Revision 1.4  2002-10-27 17:21:29  marco
+  * Only "difficult" functions + execvp + termios + rewinddir left to do
+
+ Revision 1.3  2002/10/27 11:58:30  marco
   * Modifications from Saturday.
   * Modifications from Saturday.
 
 
  Revision 1.2  2002/09/07 16:01:17  peter
  Revision 1.2  2002/09/07 16:01:17  peter

+ 6 - 3
rtl/bsd/osposix.inc

@@ -51,7 +51,7 @@ Uses Sysctl;
     function sys_rename(const old : pchar; const newpath: pchar): cint; cdecl;external name 'rename';
     function sys_rename(const old : pchar; const newpath: pchar): cint; cdecl;external name 'rename';
     function sys_fstat(fd : cint; var sb : stat): cint; cdecl; external name 'fstat';
     function sys_fstat(fd : cint; var sb : stat): cint; cdecl; external name 'fstat';
     function sys_fork : pid_t; cdecl; external name 'fork';
     function sys_fork : pid_t; cdecl; external name 'fork';
-    function sys_execve(const path : pchar; const argv : ppchar; const envp: ppchar): cint; cdecl; external name 'execve';
+    function sys_execve(path : pchar; argv : ppchar; envp: ppchar): cint; cdecl; external name 'execve';
     function sys_waitpid(pid : pid_t; var stat_loc : cint; options: cint): pid_t; cdecl; external name 'waitpid';
     function sys_waitpid(pid : pid_t; var stat_loc : cint; options: cint): pid_t; cdecl; external name 'waitpid';
     function sys_access(const pathname : pchar; amode : cint): cint; cdecl; external name 'access';
     function sys_access(const pathname : pchar; amode : cint): cint; cdecl; external name 'access';
     function sys_uname(var name: utsname): cint; cdecl; external name 'uname';
     function sys_uname(var name: utsname): cint; cdecl; external name 'uname';
@@ -82,7 +82,7 @@ function sys_sigaction(sig: cint; var act : sigactionrec; var oact : sigactionre
 function sys_ftruncate(fd : cint; flength : off_t): cint; external name 'FPC_SYSC_FTRUNCATE';
 function sys_ftruncate(fd : cint; flength : off_t): cint; external name 'FPC_SYSC_FTRUNCATE';
 function sys_fstat(fd : cint; var sb : stat): cint; external name 'FPC_SYSC_FSTAT';
 function sys_fstat(fd : cint; var sb : stat): cint; external name 'FPC_SYSC_FSTAT';
 function sys_fork : pid_t; external name 'FPC_SYSC_FORK';
 function sys_fork : pid_t; external name 'FPC_SYSC_FORK';
-function sys_execve(const path : pchar; const argv : ppchar; const envp: ppchar): cint; external name 'FPC_SYSC_EXECVE';
+// function sys_execve(path : pchar; argv : ppchar;envp: ppchar): cint; external name 'FPC_SYSC_EXECVE';
 function sys_waitpid(pid : pid_t; var stat_loc : cint; options: cint): pid_t; external name 'FPC_SYSC_WAITPID';
 function sys_waitpid(pid : pid_t; var stat_loc : cint; options: cint): pid_t; external name 'FPC_SYSC_WAITPID';
 function sys_access(const pathname : pchar; amode : cint): cint;external name 'FPC_SYSC_ACCESS';
 function sys_access(const pathname : pchar; amode : cint): cint;external name 'FPC_SYSC_ACCESS';
 function sys_Dup(fildes:cint):cint;  external name 'FPC_SYSC_DUP';
 function sys_Dup(fildes:cint):cint;  external name 'FPC_SYSC_DUP';
@@ -96,7 +96,10 @@ procedure seterrno (i:cint); external name  'FPC_SYS_SETERRNO';
 
 
 {
 {
  $Log$
  $Log$
- Revision 1.7  2002-10-27 11:58:30  marco
+ Revision 1.8  2002-10-27 17:21:29  marco
+  * Only "difficult" functions + execvp + termios + rewinddir left to do
+
+ Revision 1.7  2002/10/27 11:58:30  marco
   * Modifications from Saturday.
   * Modifications from Saturday.
 
 
  Revision 1.6  2002/10/26 18:27:51  marco
  Revision 1.6  2002/10/26 18:27:51  marco

+ 13 - 1
rtl/bsd/osposixh.inc

@@ -101,6 +101,15 @@ TYPE
 		l_whence: cshort;	{ type of l_start }
 		l_whence: cshort;	{ type of l_start }
                 end;
                 end;
 
 
+
+ tms = packed record
+	 tms_utime  : clock_t;	{ User CPU time }
+	 tms_stime  : clock_t;	{ System CPU time }
+	 tms_cutime : clock_t;	{ User CPU time of terminated child procs }
+	 tms_cstime : clock_t;	{ System CPU time of terminated child procs }
+	 end;
+
+
 {***********************************************************************}
 {***********************************************************************}
 {                  POSIX CONSTANT ROUTINE DEFINITIONS                   }
 {                  POSIX CONSTANT ROUTINE DEFINITIONS                   }
 {***********************************************************************}
 {***********************************************************************}
@@ -155,7 +164,10 @@ CONST
 
 
 {
 {
   $Log$
   $Log$
-  Revision 1.5  2002-10-27 11:58:30  marco
+  Revision 1.6  2002-10-27 17:21:29  marco
+   * Only "difficult" functions + execvp + termios + rewinddir left to do
+
+  Revision 1.5  2002/10/27 11:58:30  marco
    * Modifications from Saturday.
    * Modifications from Saturday.
 
 
   Revision 1.4  2002/09/07 16:01:17  peter
   Revision 1.4  2002/09/07 16:01:17  peter

+ 3 - 0
rtl/freebsd/ptypes.inc

@@ -39,6 +39,8 @@ type
     cuint  = Cardinal;          { minimum range is : 32-bit    }
     cuint  = Cardinal;          { minimum range is : 32-bit    }
     clong  = longint;
     clong  = longint;
     culong = Cardinal;
     culong = Cardinal;
+    cshort = integer;
+    cushort= word;
 
 
     dev_t    = cuint32;         { used for device numbers      }
     dev_t    = cuint32;         { used for device numbers      }
     gid_t    = cuint32;         { used for group IDs           }
     gid_t    = cuint32;         { used for group IDs           }
@@ -50,6 +52,7 @@ type
     size_t   = cuint32;         { as definied in the C standard}
     size_t   = cuint32;         { as definied in the C standard}
     ssize_t  = cint32;          { used by function for returning number of bytes }
     ssize_t  = cint32;          { used by function for returning number of bytes }
     uid_t    = cuint32;         { used for user ID type        }
     uid_t    = cuint32;         { used for user ID type        }
+    clock_t  = culong;
 
 
     time_t   = clong;           { used for returning the time  }
     time_t   = clong;           { used for returning the time  }
     socklen_t= cuint32;
     socklen_t= cuint32;

+ 6 - 3
rtl/freebsd/sysnr.inc

@@ -89,7 +89,6 @@ const
  syscall_nr_getpriority                 =100;
  syscall_nr_getpriority                 =100;
  syscall_nr_setsockopt                  =105;
  syscall_nr_setsockopt                  =105;
  syscall_nr_gettimeofday                =116;
  syscall_nr_gettimeofday                =116;
- syscall_nr_getrusage                   =117;
  syscall_nr_readv                       =120;
  syscall_nr_readv                       =120;
  syscall_nr_writev                      =121;
  syscall_nr_writev                      =121;
  syscall_nr_settimeofday                =122;
  syscall_nr_settimeofday                =122;
@@ -99,7 +98,6 @@ const
  syscall_nr_setregid                    =127;
  syscall_nr_setregid                    =127;
  syscall_nr_rename                      =128;
  syscall_nr_rename                      =128;
  syscall_nr_flock                       =131;
  syscall_nr_flock                       =131;
- syscall_nr_mkfifo                      =132;
  syscall_nr_mkdir                       =136;
  syscall_nr_mkdir                       =136;
  syscall_nr_rmdir                       =137;
  syscall_nr_rmdir                       =137;
  syscall_nr_utimes                      =138;
  syscall_nr_utimes                      =138;
@@ -235,6 +233,7 @@ syscall_nr_getdirentries                =196;
 }
 }
 
 
 {More or less checked BSD syscalls}
 {More or less checked BSD syscalls}
+ syscall_nr_mkfifo                      =132;
  syscall_nr___getcwd                    =326;
  syscall_nr___getcwd                    =326;
  syscall_nr_getitimer                   = 86;
  syscall_nr_getitimer                   = 86;
  syscall_nr_setitimer                   = 83;
  syscall_nr_setitimer                   = 83;
@@ -314,11 +313,15 @@ syscall_nr_getdirentries                =196;
  syscall_nr_getsockopt                  = 118;
  syscall_nr_getsockopt                  = 118;
  syscall_nr_rfork                       = 251;
  syscall_nr_rfork                       = 251;
  syscall_nr_nanosleep                   = 240;
  syscall_nr_nanosleep                   = 240;
+ syscall_nr_getrusage                   =117;
 
 
 
 
 {
 {
   $Log$
   $Log$
-  Revision 1.8  2002-10-26 18:27:52  marco
+  Revision 1.9  2002-10-27 17:21:29  marco
+   * Only "difficult" functions + execvp + termios + rewinddir left to do
+
+  Revision 1.8  2002/10/26 18:27:52  marco
    * First series POSIX calls commits. Including getcwd.
    * First series POSIX calls commits. Including getcwd.
 
 
   Revision 1.7  2002/09/07 16:01:18  peter
   Revision 1.7  2002/09/07 16:01:18  peter

+ 5 - 2
rtl/posix/sysposix.inc

@@ -434,7 +434,7 @@ Begin
    InOutRes:=3;
    InOutRes:=3;
 End;
 End;
 
 
-{$define usegetcwd}
+{ // $define usegetcwd}
 
 
 procedure getdir(drivenr : byte;var dir : shortstring);
 procedure getdir(drivenr : byte;var dir : shortstring);
 var
 var
@@ -657,7 +657,10 @@ End.
 *)
 *)
 {
 {
  $Log$
  $Log$
- Revision 1.5  2002-10-26 18:27:52  marco
+ Revision 1.6  2002-10-27 17:21:29  marco
+  * Only "difficult" functions + execvp + termios + rewinddir left to do
+
+ Revision 1.5  2002/10/26 18:27:52  marco
   * First series POSIX calls commits. Including getcwd.
   * First series POSIX calls commits. Including getcwd.
 
 
  Revision 1.4  2002/09/07 16:01:26  peter
  Revision 1.4  2002/09/07 16:01:26  peter

+ 51 - 1
rtl/unix/posixunx.inc

@@ -15,6 +15,53 @@
 
 
  **********************************************************************}
  **********************************************************************}
 
 
+function InternalCreateShellArgV(cmd:pChar; len:longint):ppchar;
+{
+  Create an argv which executes a command in a shell using /bin/sh -c
+}
+const   Shell   = '/bin/sh'#0'-c'#0;
+var
+  pp,p : ppchar;
+//  temp : string; !! Never pass a local var back!!
+begin
+  getmem(pp,4*4);
+  p:=pp;
+  p^:=@Shell[1];
+  inc(p);
+  p^:=@Shell[9];
+  inc(p);
+  getmem(p^,len+1);
+  move(cmd^,p^^,len);
+  pchar(p^)[len]:=#0;
+  inc(p);
+  p^:=Nil;
+  InternalCreateShellArgV:=pp;
+end;
+
+function CreateShellArgV(const prog:string):ppchar;
+begin
+  CreateShellArgV:=InternalCreateShellArgV(@prog[1],length(prog));
+end;
+
+function CreateShellArgV(const prog:Ansistring):ppchar;
+{
+  Create an argv which executes a command in a shell using /bin/sh -c
+  using a AnsiString;
+}
+begin
+  CreateShellArgV:=InternalCreateShellArgV(@prog[1],length(prog)); // if ppc works like delphi this also work when @prog[1] is invalid (len=0)
+end;
+
+
+procedure FreeShellArgV(p:ppchar);
+begin
+  if (p<>nil) then begin
+    freemem(p[2]);
+    freemem(p);
+   end;
+end;
+
+
 Function sys_getenv(const name:pchar):pchar;
 Function sys_getenv(const name:pchar):pchar;
 
 
 var
 var
@@ -66,7 +113,10 @@ end;
 
 
 {
 {
   $Log$
   $Log$
-  Revision 1.1  2002-10-27 13:16:54  marco
+  Revision 1.2  2002-10-27 17:21:30  marco
+   * Only "difficult" functions + execvp + termios + rewinddir left to do
+
+  Revision 1.1  2002/10/27 13:16:54  marco
    * Routines that certainly will be shared between Linux and *BSD
    * Routines that certainly will be shared between Linux and *BSD