Hi everyone,

Here is my implementation of the 'time' system call which uses getElapsedTime() to calculate the current time. As before, comments welcome.

Cheers
Tim

--
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.

diff --git a/src/kern/linux/linux.hh b/src/kern/linux/linux.hh
--- a/src/kern/linux/linux.hh
+++ b/src/kern/linux/linux.hh
@@ -62,6 +62,7 @@
     typedef uint64_t size_t;
     typedef uint64_t off_t;
     typedef int64_t time_t;
+    typedef int64_t clock_t;
     typedef uint32_t uid_t;
     typedef uint32_t gid_t;
     //@}
diff --git a/src/sim/syscall_emul.hh b/src/sim/syscall_emul.hh
--- a/src/sim/syscall_emul.hh
+++ b/src/sim/syscall_emul.hh
@@ -1132,6 +1132,25 @@
     return curTick;
 }
 
+/// Target time() function.
+template <class OS>
+SyscallReturn
+timeFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
+           ThreadContext *tc)
+{
+    typename OS::time_t sec, usec;
+    getElapsedTime(sec, usec);
+    sec += seconds_since_epoch;
+
+    Addr taddr = (Addr)process->getSyscallArg(tc, 0);
+    if(taddr != 0) {
+        typename OS::time_t t = sec;
+        t = htog(t);
+        TranslatingPort *p = tc->getMemPort();
+        p->writeBlob(taddr, (uint8_t*)&t, (int)sizeof(typename OS::time_t));
+    }
+    return sec;
+}
 
 
 #endif // __SIM_SYSCALL_EMUL_HH__
_______________________________________________
m5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/m5-dev

Reply via email to