From 9633a4c11d48e3347d3e6dc2e43b11ef966b4c51 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 22 May 2009 08:12:46 +0000 Subject: [PATCH] DARWIN sync: all the timeval stuff git-svn-id: svn://svn.valgrind.org/valgrind/trunk@10106 --- coregrind/m_syswrap/priv_syswrap-generic.h | 20 +++++++++ coregrind/m_syswrap/priv_types_n_macros.h | 10 +++++ coregrind/m_syswrap/syswrap-generic.c | 49 ++++++++++++++++------ memcheck/tests/x86-linux/scalar.c | 4 +- memcheck/tests/x86-linux/scalar.stderr.exp | 24 +++++++++-- 5 files changed, 88 insertions(+), 19 deletions(-) diff --git a/coregrind/m_syswrap/priv_syswrap-generic.h b/coregrind/m_syswrap/priv_syswrap-generic.h index 376c2b507c..1d66d64021 100644 --- a/coregrind/m_syswrap/priv_syswrap-generic.h +++ b/coregrind/m_syswrap/priv_syswrap-generic.h @@ -252,6 +252,26 @@ extern void ML_(generic_POST_sys_shmctl) ( TId, UW, UW, UW, UW ); extern SysRes ML_(generic_PRE_sys_mmap) ( TId, UW, UW, UW, UW, UW, Off64T ); +#define PRE_timeval_READ(zzname, zzarg) \ + do { \ + struct vki_timeval *zztv = (struct vki_timeval *)zzarg; \ + PRE_FIELD_READ(zzname, zztv->tv_sec); \ + PRE_FIELD_READ(zzname, zztv->tv_usec); \ + } while (0) +#define PRE_timeval_WRITE(zzname, zzarg) \ + do { \ + struct vki_timeval *zztv = (struct vki_timeval *)zzarg; \ + PRE_FIELD_WRITE(zzname, zztv->tv_sec); \ + PRE_FIELD_WRITE(zzname, zztv->tv_usec); \ + } while (0) +#define POST_timeval_WRITE(zzarg) \ + do { \ + struct vki_timeval *zztv = (struct vki_timeval *)zzarg; \ + POST_FIELD_WRITE(zztv->tv_sec); \ + POST_FIELD_WRITE(zztv->tv_usec); \ + } while (0) + + #undef TId #undef UW #undef SR diff --git a/coregrind/m_syswrap/priv_types_n_macros.h b/coregrind/m_syswrap/priv_types_n_macros.h index 407fdb0c6a..45536b8968 100644 --- a/coregrind/m_syswrap/priv_types_n_macros.h +++ b/coregrind/m_syswrap/priv_types_n_macros.h @@ -453,6 +453,16 @@ static inline UWord getERR ( SyscallStatus* st ) { VG_TRACK( post_mem_write, Vg_CoreSysCall, tid, zzaddr, zzlen) +#define PRE_FIELD_READ(zzname, zzfield) \ + PRE_MEM_READ(zzname, (UWord)&zzfield, sizeof(zzfield)) + +#define PRE_FIELD_WRITE(zzname, zzfield) \ + PRE_MEM_WRITE(zzname, (UWord)&zzfield, sizeof(zzfield)) + +#define POST_FIELD_WRITE(zzfield) \ + POST_MEM_WRITE((UWord)&zzfield, sizeof(zzfield)) + + #endif // __PRIV_TYPES_N_MACROS_H /*--------------------------------------------------------------------*/ diff --git a/coregrind/m_syswrap/syswrap-generic.c b/coregrind/m_syswrap/syswrap-generic.c index ffce2923c8..6a90fd1692 100644 --- a/coregrind/m_syswrap/syswrap-generic.c +++ b/coregrind/m_syswrap/syswrap-generic.c @@ -2129,14 +2129,19 @@ PRE(sys_putpmsg) PRE(sys_getitimer) { + struct vki_itimerval *value = (struct vki_itimerval*)ARG2; PRINT("sys_getitimer ( %ld, %#lx )", ARG1, ARG2); PRE_REG_READ2(long, "getitimer", int, which, struct itimerval *, value); - PRE_MEM_WRITE( "getitimer(value)", ARG2, sizeof(struct vki_itimerval) ); + + PRE_timeval_WRITE( "getitimer(&value->it_interval)", &(value->it_interval)); + PRE_timeval_WRITE( "getitimer(&value->it_value)", &(value->it_value)); } POST(sys_getitimer) { if (ARG2 != (Addr)NULL) { - POST_MEM_WRITE(ARG2, sizeof(struct vki_itimerval)); + struct vki_itimerval *value = (struct vki_itimerval*)ARG2; + POST_timeval_WRITE( &(value->it_interval) ); + POST_timeval_WRITE( &(value->it_value) ); } } @@ -2146,16 +2151,28 @@ PRE(sys_setitimer) PRE_REG_READ3(long, "setitimer", int, which, struct itimerval *, value, struct itimerval *, ovalue); - if (ARG2 != (Addr)NULL) - PRE_MEM_READ( "setitimer(value)", ARG2, sizeof(struct vki_itimerval) ); - if (ARG3 != (Addr)NULL) - PRE_MEM_WRITE( "setitimer(ovalue)", ARG3, sizeof(struct vki_itimerval)); + if (ARG2 != (Addr)NULL) { + struct vki_itimerval *value = (struct vki_itimerval*)ARG2; + PRE_timeval_READ( "setitimer(&value->it_interval)", + &(value->it_interval)); + PRE_timeval_READ( "setitimer(&value->it_value)", + &(value->it_value)); + } + if (ARG3 != (Addr)NULL) { + struct vki_itimerval *ovalue = (struct vki_itimerval*)ARG3; + PRE_timeval_WRITE( "setitimer(&ovalue->it_interval)", + &(ovalue->it_interval)); + PRE_timeval_WRITE( "setitimer(&ovalue->it_value)", + &(ovalue->it_value)); + } } POST(sys_setitimer) { if (ARG3 != (Addr)NULL) { - POST_MEM_WRITE(ARG3, sizeof(struct vki_itimerval)); + struct vki_itimerval *ovalue = (struct vki_itimerval*)ARG3; + POST_timeval_WRITE( &(ovalue->it_interval) ); + POST_timeval_WRITE( &(ovalue->it_value) ); } } @@ -3046,7 +3063,8 @@ PRE(sys_gettimeofday) PRINT("sys_gettimeofday ( %#lx, %#lx )", ARG1,ARG2); PRE_REG_READ2(long, "gettimeofday", struct timeval *, tv, struct timezone *, tz); - PRE_MEM_WRITE( "gettimeofday(tv)", ARG1, sizeof(struct vki_timeval) ); + if (ARG1 != 0) + PRE_timeval_WRITE( "gettimeofday(tv)", ARG1 ); if (ARG2 != 0) PRE_MEM_WRITE( "gettimeofday(tz)", ARG2, sizeof(struct vki_timezone) ); } @@ -3055,7 +3073,8 @@ POST(sys_gettimeofday) { vg_assert(SUCCESS); if (RES == 0) { - POST_MEM_WRITE( ARG1, sizeof(struct vki_timeval) ); + if (ARG1 != 0) + POST_timeval_WRITE( ARG1 ); if (ARG2 != 0) POST_MEM_WRITE( ARG2, sizeof(struct vki_timezone) ); } @@ -3066,7 +3085,8 @@ PRE(sys_settimeofday) PRINT("sys_settimeofday ( %#lx, %#lx )", ARG1,ARG2); PRE_REG_READ2(long, "settimeofday", struct timeval *, tv, struct timezone *, tz); - PRE_MEM_READ( "settimeofday(tv)", ARG1, sizeof(struct vki_timeval) ); + if (ARG1 != 0) + PRE_MEM_READ( "settimeofday(tv)", ARG1, sizeof(struct vki_timeval) ); if (ARG2 != 0) { PRE_MEM_READ( "settimeofday(tz)", ARG2, sizeof(struct vki_timezone) ); /* maybe should warn if tz->tz_dsttime is non-zero? */ @@ -3632,7 +3652,7 @@ PRE(sys_select) PRE_MEM_READ( "select(exceptfds)", ARG4, ARG1/8 /* __FD_SETSIZE/8 */ ); if (ARG5 != 0) - PRE_MEM_READ( "select(timeout)", ARG5, sizeof(struct vki_timeval) ); + PRE_timeval_READ( "select(timeout)", ARG5 ); } PRE(sys_setgid) @@ -3895,8 +3915,11 @@ PRE(sys_utimes) PRINT("sys_utimes ( %#lx(%s), %#lx )", ARG1,(char*)ARG1,ARG2); PRE_REG_READ2(long, "utimes", char *, filename, struct timeval *, tvp); PRE_MEM_RASCIIZ( "utimes(filename)", ARG1 ); - if (ARG2 != 0) - PRE_MEM_READ( "utimes(tvp)", ARG2, 2 * sizeof(struct vki_timeval) ); + if (ARG2 != 0) { + PRE_timeval_READ( "utimes(tvp[0])", ARG2 ); + PRE_timeval_READ( "utimes(tvp[1])", ARG2+sizeof(struct vki_timeval) ); + } + } PRE(sys_acct) diff --git a/memcheck/tests/x86-linux/scalar.c b/memcheck/tests/x86-linux/scalar.c index b853c03457..d6d5a3a3e6 100644 --- a/memcheck/tests/x86-linux/scalar.c +++ b/memcheck/tests/x86-linux/scalar.c @@ -371,11 +371,11 @@ int main(void) // __NR_gettimeofday 78 GO(__NR_gettimeofday, "2s 2m"); - SY(__NR_gettimeofday, x0, x0+1); FAIL; + SY(__NR_gettimeofday, x0+1, x0+1); FAIL; // __NR_settimeofday 79 GO(__NR_settimeofday, "2s 2m"); - SY(__NR_settimeofday, x0, x0+1); FAIL; + SY(__NR_settimeofday, x0+1, x0+1); FAIL; // __NR_getgroups 80 GO(__NR_getgroups, "2s 1m"); diff --git a/memcheck/tests/x86-linux/scalar.stderr.exp b/memcheck/tests/x86-linux/scalar.stderr.exp index 96a97cf26f..e1c3f6fb7b 100644 --- a/memcheck/tests/x86-linux/scalar.stderr.exp +++ b/memcheck/tests/x86-linux/scalar.stderr.exp @@ -978,11 +978,19 @@ Syscall param setitimer(value) contains uninitialised byte(s) Syscall param setitimer(ovalue) contains uninitialised byte(s) ... -Syscall param setitimer(value) points to unaddressable byte(s) +Syscall param setitimer(&value->it_interval) points to unaddressable byte(s) ... Address 0x........ is not stack'd, malloc'd or (recently) free'd -Syscall param setitimer(ovalue) points to unaddressable byte(s) +Syscall param setitimer(&value->it_value) points to unaddressable byte(s) + ... + Address 0x........ is not stack'd, malloc'd or (recently) free'd + +Syscall param setitimer(&ovalue->it_interval) points to unaddressable byte(s) + ... + Address 0x........ is not stack'd, malloc'd or (recently) free'd + +Syscall param setitimer(&ovalue->it_value) points to unaddressable byte(s) ... Address 0x........ is not stack'd, malloc'd or (recently) free'd ----------------------------------------------------- @@ -995,7 +1003,11 @@ Syscall param getitimer(which) contains uninitialised byte(s) Syscall param getitimer(value) contains uninitialised byte(s) ... -Syscall param getitimer(value) points to unaddressable byte(s) +Syscall param getitimer(&value->it_interval) points to unaddressable byte(s) + ... + Address 0x........ is not stack'd, malloc'd or (recently) free'd + +Syscall param getitimer(&value->it_value) points to unaddressable byte(s) ... Address 0x........ is not stack'd, malloc'd or (recently) free'd ----------------------------------------------------- @@ -3085,7 +3097,11 @@ Syscall param utimes(filename) points to unaddressable byte(s) ... Address 0x........ is not stack'd, malloc'd or (recently) free'd -Syscall param utimes(tvp) points to unaddressable byte(s) +Syscall param utimes(tvp[0]) points to unaddressable byte(s) + ... + Address 0x........ is not stack'd, malloc'd or (recently) free'd + +Syscall param utimes(tvp[1]) points to unaddressable byte(s) ... Address 0x........ is not stack'd, malloc'd or (recently) free'd ----------------------------------------------------- -- 2.47.3