diff options
author | njn <njn@a5019735-40e9-0310-863c-91ae7b9d1cf9> | 2009-06-10 06:13:34 +0000 |
---|---|---|
committer | njn <njn@a5019735-40e9-0310-863c-91ae7b9d1cf9> | 2009-06-10 06:13:34 +0000 |
commit | 143377eab2ef89c9806a16580c6bf0ae3f8b0834 (patch) | |
tree | c327271a5b0ec20010c05b80fb3d3163f275df09 | |
parent | c19072441d4a7649a007a0651a95d1cc0fa8462c (diff) | |
download | valgrind-143377eab2ef89c9806a16580c6bf0ae3f8b0834.tar.gz |
Implement and test wrappers for lstat_extended, stat64_extended,
lstat64_extended, and improve the existing wrapper for stat_extended.
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@10291 a5019735-40e9-0310-863c-91ae7b9d1cf9
-rw-r--r-- | coregrind/m_syswrap/priv_syswrap-darwin.h | 6 | ||||
-rw-r--r-- | coregrind/m_syswrap/syswrap-darwin.c | 88 | ||||
-rw-r--r-- | coregrind/m_syswrap/syswrap-generic.c | 2 | ||||
-rw-r--r-- | memcheck/tests/darwin/scalar.c | 32 | ||||
-rw-r--r-- | memcheck/tests/darwin/scalar.stderr.exp | 124 |
5 files changed, 238 insertions, 14 deletions
diff --git a/coregrind/m_syswrap/priv_syswrap-darwin.h b/coregrind/m_syswrap/priv_syswrap-darwin.h index c72eb5a29..6e822523a 100644 --- a/coregrind/m_syswrap/priv_syswrap-darwin.h +++ b/coregrind/m_syswrap/priv_syswrap-darwin.h @@ -335,7 +335,7 @@ DECL_TEMPLATE(darwin, sem_destroy); // 276 // NYI open_extended 277 // NYI umask_extended 278 DECL_TEMPLATE(darwin, stat_extended); // 279 -// NYI lstat_extended 280 +DECL_TEMPLATE(darwin, lstat_extended); // 280 // NYI fstat_extended 281 DECL_TEMPLATE(darwin, chmod_extended); // 282 DECL_TEMPLATE(darwin, fchmod_extended); // 283 @@ -396,8 +396,8 @@ DECL_TEMPLATE(darwin, sendfile); // 337 DECL_TEMPLATE(darwin, stat64); // 338 DECL_TEMPLATE(darwin, fstat64); // 339 DECL_TEMPLATE(darwin, lstat64); // 340 -// NYI stat64_extended 341 -// NYI lstat64_extended 342 +DECL_TEMPLATE(darwin, stat64_extended); // 341 +DECL_TEMPLATE(darwin, lstat64_extended); // 342 // NYI fstat64_extended 343 DECL_TEMPLATE(darwin, getdirentries64); // 344 DECL_TEMPLATE(darwin, statfs64); // 345 diff --git a/coregrind/m_syswrap/syswrap-darwin.c b/coregrind/m_syswrap/syswrap-darwin.c index d670ee1cd..20238def2 100644 --- a/coregrind/m_syswrap/syswrap-darwin.c +++ b/coregrind/m_syswrap/syswrap-darwin.c @@ -1828,22 +1828,90 @@ PRE(stat_extended) PRE_REG_READ4(int, "stat_extended", char *, file_name, struct stat *, buf, void *, fsacl, vki_size_t *, fsacl_size); PRE_MEM_RASCIIZ( "stat_extended(file_name)", ARG1 ); - PRE_MEM_READ( "stat_extended(fsacl_size)", ARG4, sizeof(vki_size_t) ); PRE_MEM_WRITE( "stat_extended(buf)", ARG2, sizeof(struct vki_stat) ); + if (ML_(safe_to_deref)( (void*)ARG4, sizeof(vki_size_t) )) + PRE_MEM_WRITE("stat_extended(fsacl)", ARG3, *(vki_size_t *)ARG4 ); + PRE_MEM_READ( "stat_extended(fsacl_size)", ARG4, sizeof(vki_size_t) ); PRE_MEM_WRITE( "stat_extended(fsacl_size)", ARG4, sizeof(vki_size_t) ); - PRE_MEM_WRITE( "stat_extended(fsacl)", ARG3, *(vki_size_t *)ARG4 ); } POST(stat_extended) { POST_MEM_WRITE( ARG2, sizeof(struct vki_stat) ); + if (ML_(safe_to_deref)( (void*)ARG4, sizeof(vki_size_t) )) + POST_MEM_WRITE( ARG3, *(vki_size_t *)ARG4 ); + POST_MEM_WRITE( ARG4, sizeof(vki_size_t) ); +} + + +PRE(lstat_extended) +{ + PRINT("lstat_extended( %#lx(%s), %#lx, %#lx, %#lx )", + ARG1, (char *)ARG1, ARG2, ARG3, ARG4); + PRE_REG_READ4(int, "lstat_extended", char *, file_name, struct stat *, buf, + void *, fsacl, vki_size_t *, fsacl_size); + PRE_MEM_RASCIIZ( "lstat_extended(file_name)", ARG1 ); + PRE_MEM_WRITE( "lstat_extended(buf)", ARG2, sizeof(struct vki_stat) ); + if (ML_(safe_to_deref)( (void*)ARG4, sizeof(vki_size_t) )) + PRE_MEM_WRITE("lstat_extended(fsacl)", ARG3, *(vki_size_t *)ARG4 ); + PRE_MEM_READ( "lstat_extended(fsacl_size)", ARG4, sizeof(vki_size_t) ); + PRE_MEM_WRITE( "lstat_extended(fsacl_size)", ARG4, sizeof(vki_size_t) ); +} +POST(lstat_extended) +{ + POST_MEM_WRITE( ARG2, sizeof(struct vki_stat) ); + if (ML_(safe_to_deref)( (void*)ARG4, sizeof(vki_size_t) )) + POST_MEM_WRITE( ARG3, *(vki_size_t *)ARG4 ); + POST_MEM_WRITE( ARG4, sizeof(vki_size_t) ); +} + + +PRE(stat64_extended) +{ + PRINT("stat64_extended( %#lx(%s), %#lx, %#lx, %#lx )", + ARG1, (char *)ARG1, ARG2, ARG3, ARG4); + PRE_REG_READ4(int, "stat64_extended", char *, file_name, struct stat64 *, buf, + void *, fsacl, vki_size_t *, fsacl_size); + PRE_MEM_RASCIIZ( "stat64_extended(file_name)", ARG1 ); + PRE_MEM_WRITE( "stat64_extended(buf)", ARG2, sizeof(struct vki_stat64) ); + if (ML_(safe_to_deref)( (void*)ARG4, sizeof(vki_size_t) )) + PRE_MEM_WRITE("stat64_extended(fsacl)", ARG3, *(vki_size_t *)ARG4 ); + PRE_MEM_READ( "stat64_extended(fsacl_size)", ARG4, sizeof(vki_size_t) ); + PRE_MEM_WRITE( "stat64_extended(fsacl_size)", ARG4, sizeof(vki_size_t) ); +} +POST(stat64_extended) +{ + POST_MEM_WRITE( ARG2, sizeof(struct vki_stat64) ); + if (ML_(safe_to_deref)( (void*)ARG4, sizeof(vki_size_t) )) + POST_MEM_WRITE( ARG3, *(vki_size_t *)ARG4 ); + POST_MEM_WRITE( ARG4, sizeof(vki_size_t) ); +} + + +PRE(lstat64_extended) +{ + PRINT("lstat64_extended( %#lx(%s), %#lx, %#lx, %#lx )", + ARG1, (char *)ARG1, ARG2, ARG3, ARG4); + PRE_REG_READ4(int, "lstat64_extended", char *, file_name, struct stat64 *, buf, + void *, fsacl, vki_size_t *, fsacl_size); + PRE_MEM_RASCIIZ( "lstat64_extended(file_name)", ARG1 ); + PRE_MEM_WRITE( "lstat64_extended(buf)", ARG2, sizeof(struct vki_stat64) ); + if (ML_(safe_to_deref)( (void*)ARG4, sizeof(vki_size_t) )) + PRE_MEM_WRITE( "lstat64_extended(fsacl)", ARG3, *(vki_size_t *)ARG4 ); + PRE_MEM_READ( "lstat64_extended(fsacl_size)", ARG4, sizeof(vki_size_t) ); + PRE_MEM_WRITE( "lstat64_extended(fsacl_size)", ARG4, sizeof(vki_size_t) ); +} +POST(lstat64_extended) +{ + POST_MEM_WRITE( ARG2, sizeof(struct vki_stat64) ); + if (ML_(safe_to_deref)( (void*)ARG4, sizeof(vki_size_t) )) + POST_MEM_WRITE( ARG3, *(vki_size_t *)ARG4 ); POST_MEM_WRITE( ARG4, sizeof(vki_size_t) ); - POST_MEM_WRITE( ARG3, *(vki_size_t *)ARG4 ); } PRE(fchmod_extended) { - /* Note: this is not really correct. Handling of + /* DDD: Note: this is not really correct. Handling of chmod_extended is broken in the same way. */ PRINT("fchmod_extended ( %ld, %ld, %ld, %ld, %#lx )", ARG1, ARG2, ARG3, ARG4, ARG5); @@ -1853,7 +1921,7 @@ PRE(fchmod_extended) gid_t, gid, vki_mode_t, mode, void* /*really,user_addr_t*/, xsecurity); - /* relative to the xnu sources (kauth_copyinfilesec), this + /* DDD: relative to the xnu sources (kauth_copyinfilesec), this is just way wrong. */ PRE_MEM_READ( "fchmod_extended(xsecurity)", ARG5, sizeof(struct kauth_filesec) ); @@ -1861,7 +1929,7 @@ PRE(fchmod_extended) PRE(chmod_extended) { - /* Note: this is not really correct. Handling of + /* DDD: Note: this is not really correct. Handling of fchmod_extended is broken in the same way. */ PRINT("chmod_extended ( %#lx(%s), %ld, %ld, %ld, %#lx )", ARG1, ARG1 ? (HChar*)ARG1 : "(null)", ARG2, ARG3, ARG4, ARG5); @@ -1872,7 +1940,7 @@ PRE(chmod_extended) vki_mode_t, mode, void* /*really,user_addr_t*/, xsecurity); PRE_MEM_RASCIIZ("chmod_extended(path)", ARG1); - /* relative to the xnu sources (kauth_copyinfilesec), this + /* DDD: relative to the xnu sources (kauth_copyinfilesec), this is just way wrong. */ PRE_MEM_READ( "chmod_extended(xsecurity)", ARG5, sizeof(struct kauth_filesec) ); @@ -7157,7 +7225,7 @@ const SyscallTableEntry ML_(syscall_table)[] = { // _____(__NR_open_extended), // _____(__NR_umask_extended), MACXY(__NR_stat_extended, stat_extended), -// _____(__NR_lstat_extended), // 280 + MACXY(__NR_lstat_extended, lstat_extended), // 280 // _____(__NR_fstat_extended), MACX_(__NR_chmod_extended, chmod_extended), MACX_(__NR_fchmod_extended, fchmod_extended), @@ -7218,8 +7286,8 @@ const SyscallTableEntry ML_(syscall_table)[] = { MACXY(__NR_stat64, stat64), MACXY(__NR_fstat64, fstat64), MACXY(__NR_lstat64, lstat64), // 340 -// _____(__NR_stat64_extended), -// _____(__NR_lstat64_extended), + MACXY(__NR_stat64_extended, stat64_extended), + MACXY(__NR_lstat64_extended, lstat64_extended), // _____(__NR_fstat64_extended), MACXY(__NR_getdirentries64, getdirentries64), MACXY(__NR_statfs64, statfs64), diff --git a/coregrind/m_syswrap/syswrap-generic.c b/coregrind/m_syswrap/syswrap-generic.c index 354c48527..1aedb6a15 100644 --- a/coregrind/m_syswrap/syswrap-generic.c +++ b/coregrind/m_syswrap/syswrap-generic.c @@ -109,7 +109,7 @@ Bool ML_(client_signal_OK)(Int sigNo) Bool ML_(safe_to_deref) ( void* start, SizeT size ) { - return VG_(am_is_valid_for_client)( (Addr)start, size, VKI_PROT_NONE ); + return VG_(am_is_valid_for_client)( (Addr)start, size, VKI_PROT_READ ); } diff --git a/memcheck/tests/darwin/scalar.c b/memcheck/tests/darwin/scalar.c index bfd8397a3..fef31b803 100644 --- a/memcheck/tests/darwin/scalar.c +++ b/memcheck/tests/darwin/scalar.c @@ -364,8 +364,24 @@ int main(void) // __NR_open_extended 277 // __NR_umask_extended 278 + // __NR_stat_extended 279 + { + size_t one = 1; + GO(__NR_stat_extended, "4s 4m"); + SY(__NR_stat_extended, x0, x0, x0, x0); FAIL; + // Go again to get a complaint about where the 3rd arg points; it + // requires the 4th arg to point to a valid value. + SY(__NR_stat_extended, 0, 0, 0, &one); FAIL; + // __NR_lstat_extended 280 + GO(__NR_lstat_extended, "4s 4m"); + SY(__NR_lstat_extended, x0, x0, x0, x0); FAIL; + // Go again to get a complaint about where the 3rd arg points; it + // requires the 4th arg to point to a valid value. + SY(__NR_lstat_extended, 0, 0, 0, &one); FAIL; + } + // __NR_fstat_extended 281 // __NR_chmod_extended 282 // __NR_fchmod_extended 283 @@ -428,8 +444,24 @@ int main(void) // __NR_fstat64 339 // __NR_lstat64 340 // __NR_stat64_extended 341 + // __NR_lstat64_extended 342 + { + size_t one = 1; + GO(__NR_stat64_extended, "4s 4m"); + SY(__NR_stat64_extended, x0, x0, x0, x0); FAIL; + // Go again to get a complaint about where the 3rd arg points; it + // requires the 4th arg to point to a valid value. + SY(__NR_stat64_extended, 0, 0, 0, &one); FAIL; + // __NR_fstat64_extended 343 + GO(__NR_lstat64_extended, "4s 4m"); + SY(__NR_lstat64_extended, x0, x0, x0, x0); FAIL; + // Go again to get a complaint about where the 3rd arg points; it + // requires the 4th arg to point to a valid value. + SY(__NR_lstat64_extended, 0, 0, 0, &one); FAIL; + } + // __NR_getdirentries64 344 // __NR_statfs64 345 // __NR_fstatfs64 346 diff --git a/memcheck/tests/darwin/scalar.stderr.exp b/memcheck/tests/darwin/scalar.stderr.exp index d0541e1e1..fbd0014aa 100644 --- a/memcheck/tests/darwin/scalar.stderr.exp +++ b/memcheck/tests/darwin/scalar.stderr.exp @@ -214,6 +214,130 @@ Syscall param sem_destroy(sem) points to unaddressable byte(s) ... Address 0x........ is not stack'd, malloc'd or (recently) free'd ----------------------------------------------------- +x2000117(279): __NR_stat_extended 4s 4m +----------------------------------------------------- + +Syscall param stat_extended(file_name) contains uninitialised byte(s) + ... + +Syscall param stat_extended(buf) contains uninitialised byte(s) + ... + +Syscall param stat_extended(fsacl) contains uninitialised byte(s) + ... + +Syscall param stat_extended(fsacl_size) contains uninitialised byte(s) + ... + +Syscall param stat_extended(file_name) points to unaddressable byte(s) + ... + Address 0x........ is not stack'd, malloc'd or (recently) free'd + +Syscall param stat_extended(buf) points to unaddressable byte(s) + ... + Address 0x........ is not stack'd, malloc'd or (recently) free'd + +Syscall param stat_extended(fsacl_size) points to unaddressable byte(s) + ... + Address 0x........ is not stack'd, malloc'd or (recently) free'd + +Syscall param stat_extended(fsacl) points to unaddressable byte(s) + ... + Address 0x........ is not stack'd, malloc'd or (recently) free'd +----------------------------------------------------- +x2000118(280): __NR_lstat_extended 4s 4m +----------------------------------------------------- + +Syscall param lstat_extended(file_name) contains uninitialised byte(s) + ... + +Syscall param lstat_extended(buf) contains uninitialised byte(s) + ... + +Syscall param lstat_extended(fsacl) contains uninitialised byte(s) + ... + +Syscall param lstat_extended(fsacl_size) contains uninitialised byte(s) + ... + +Syscall param lstat_extended(file_name) points to unaddressable byte(s) + ... + Address 0x........ is not stack'd, malloc'd or (recently) free'd + +Syscall param lstat_extended(buf) points to unaddressable byte(s) + ... + Address 0x........ is not stack'd, malloc'd or (recently) free'd + +Syscall param lstat_extended(fsacl_size) points to unaddressable byte(s) + ... + Address 0x........ is not stack'd, malloc'd or (recently) free'd + +Syscall param lstat_extended(fsacl) points to unaddressable byte(s) + ... + Address 0x........ is not stack'd, malloc'd or (recently) free'd +----------------------------------------------------- +x2000155(341):__NR_stat64_extended 4s 4m +----------------------------------------------------- + +Syscall param stat64_extended(file_name) contains uninitialised byte(s) + ... + +Syscall param stat64_extended(buf) contains uninitialised byte(s) + ... + +Syscall param stat64_extended(fsacl) contains uninitialised byte(s) + ... + +Syscall param stat64_extended(fsacl_size) contains uninitialised byte(s) + ... + +Syscall param stat64_extended(file_name) points to unaddressable byte(s) + ... + Address 0x........ is not stack'd, malloc'd or (recently) free'd + +Syscall param stat64_extended(buf) points to unaddressable byte(s) + ... + Address 0x........ is not stack'd, malloc'd or (recently) free'd + +Syscall param stat64_extended(fsacl_size) points to unaddressable byte(s) + ... + Address 0x........ is not stack'd, malloc'd or (recently) free'd + +Syscall param stat64_extended(fsacl) points to unaddressable byte(s) + ... + Address 0x........ is not stack'd, malloc'd or (recently) free'd +----------------------------------------------------- +x2000156(342):__NR_lstat64_extended 4s 4m +----------------------------------------------------- + +Syscall param lstat64_extended(file_name) contains uninitialised byte(s) + ... + +Syscall param lstat64_extended(buf) contains uninitialised byte(s) + ... + +Syscall param lstat64_extended(fsacl) contains uninitialised byte(s) + ... + +Syscall param lstat64_extended(fsacl_size) contains uninitialised byte(s) + ... + +Syscall param lstat64_extended(file_name) points to unaddressable byte(s) + ... + Address 0x........ is not stack'd, malloc'd or (recently) free'd + +Syscall param lstat64_extended(buf) points to unaddressable byte(s) + ... + Address 0x........ is not stack'd, malloc'd or (recently) free'd + +Syscall param lstat64_extended(fsacl_size) points to unaddressable byte(s) + ... + Address 0x........ is not stack'd, malloc'd or (recently) free'd + +Syscall param lstat64_extended(fsacl) points to unaddressable byte(s) + ... + Address 0x........ is not stack'd, malloc'd or (recently) free'd +----------------------------------------------------- x20001a4(420):__NR_sem_wait_nocancel 0s* 0m ----------------------------------------------------- ----------------------------------------------------- |