Add VG_(gettimeofday) such that callgrind can use it without
a bloody hack.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@14857 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/callgrind/main.c b/callgrind/main.c
index 30a0cce..ad61d45 100644
--- a/callgrind/main.c
+++ b/callgrind/main.c
@@ -1706,10 +1706,6 @@
 
 /* struct timeval syscalltime[VG_N_THREADS]; */
 #if CLG_MICROSYSTIME
-#include <sys/time.h>
-#include <sys/syscall.h>
-extern Int VG_(do_syscall) ( UInt, ... );
-
 ULong syscalltime[VG_N_THREADS];
 #else
 UInt syscalltime[VG_N_THREADS];
@@ -1722,7 +1718,7 @@
   if (CLG_(clo).collect_systime) {
 #if CLG_MICROSYSTIME
     struct vki_timeval tv_now;
-    VG_(do_syscall)(__NR_gettimeofday, (UInt)&tv_now, (UInt)NULL);
+    VG_(gettimeofday)(&tv_now, NULL);
     syscalltime[tid] = tv_now.tv_sec * 1000000ULL + tv_now.tv_usec;
 #else
     syscalltime[tid] = VG_(read_millisecond_timer)();
@@ -1741,7 +1737,7 @@
     struct vki_timeval tv_now;
     ULong diff;
     
-    VG_(do_syscall)(__NR_gettimeofday, (UInt)&tv_now, (UInt)NULL);
+    VG_(gettimeofday)(&tv_now, NULL);
     diff = (tv_now.tv_sec * 1000000ULL + tv_now.tv_usec) - syscalltime[tid];
 #else
     UInt diff = VG_(read_millisecond_timer)() - syscalltime[tid];
@@ -1750,7 +1746,8 @@
     /* offset o is for "SysCount", o+1 for "SysTime" */
     o = fullOffset(EG_SYS);
     CLG_ASSERT(o>=0);
-    CLG_DEBUG(0,"   Time (Off %d) for Syscall %d: %ull\n", o, syscallno, diff);
+    CLG_DEBUG(0,"   Time (Off %d) for Syscall %u: %llu\n", o, syscallno,
+              (ULong)diff);
     
     CLG_(current_state).cost[o] ++;
     CLG_(current_state).cost[o+1] += diff;
diff --git a/coregrind/m_libcproc.c b/coregrind/m_libcproc.c
index a371ce3..ec6b0c8 100644
--- a/coregrind/m_libcproc.c
+++ b/coregrind/m_libcproc.c
@@ -666,6 +666,20 @@
    return (now - base) / 1000;
 }
 
+Int VG_(gettimeofday)(struct vki_timeval *tv, struct vki_timezone *tz)
+{
+   SysRes res;
+   res = VG_(do_syscall2)(__NR_gettimeofday, (UWord)tv, (UWord)tz);
+
+   if (! sr_isError(res)) return 0;
+
+   /* Make sure, argument values are determinstic upon failure */
+   if (tv) *tv = (struct vki_timeval){ .tv_sec = 0, .tv_usec = 0 };
+   if (tz) *tz = (struct vki_timezone){ .tz_minuteswest = 0, .tz_dsttime = 0 };
+
+   return -1;
+}
+
 
 /* ---------------------------------------------------------------------
    atfork()
diff --git a/include/pub_tool_libcproc.h b/include/pub_tool_libcproc.h
index 585cbd7..cbd159f 100644
--- a/include/pub_tool_libcproc.h
+++ b/include/pub_tool_libcproc.h
@@ -88,6 +88,7 @@
 // (roughly;  it gets initialised partway through Valgrind's initialisation
 // steps).
 extern UInt VG_(read_millisecond_timer) ( void );
+extern Int  VG_(gettimeofday)(struct vki_timeval *tv, struct vki_timezone *tz);
 
 /* ---------------------------------------------------------------------
    atfork