From: Nicholas Nethercote Date: Sun, 14 Nov 2004 19:11:56 +0000 (+0000) Subject: Converted a few more syscalls. X-Git-Tag: svn/VALGRIND_3_0_0~1316 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=117e80b375f63449ba09cec85109e0ad042b1751;p=thirdparty%2Fvalgrind.git Converted a few more syscalls. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@2996 --- diff --git a/coregrind/vg_syscalls.c b/coregrind/vg_syscalls.c index b0a61898af..952002e085 100644 --- a/coregrind/vg_syscalls.c +++ b/coregrind/vg_syscalls.c @@ -1475,10 +1475,11 @@ PRE(fdatasync) PRINT("fdatasync ( %d )", arg1); } -PRE(msync) +PREx(sys_msync, MayBlock) { - /* int msync(const void *start, size_t length, int flags); */ - PRINT("msync ( %p, %llu, %d )", arg1,(ULong)arg2,arg3); + PRINT("sys_msync ( %p, %llu, %d )", arg1,(ULong)arg2,arg3); + PRE_REG_READ3(long, "msync", + unsigned long, start, vki_size_t, length, int, flags); PRE_MEM_READ( "msync(start)", arg1, arg2 ); } @@ -1600,15 +1601,16 @@ PRE(madvise) PRINT("madvise ( %p, %llu, %d )", arg1,(ULong)arg2,arg3); } -PRE(mremap) +PREx(sys_mremap, Special) { // Nb: this is different to the glibc version described in the man pages, // which lacks the fifth 'new_address' argument. - /* void* mremap(void * old_address, size_t old_size, - size_t new_size, unsigned long flags, void * new_address); */ - PRINT("mremap ( %p, %llu, %d, 0x%x, %p )", - arg1, (ULong)arg2, arg3, arg4, arg5); - + PRINT("sys_mremap ( %p, %llu, %d, 0x%x, %p )", + arg1, (ULong)arg2, arg3, arg4, arg5); + PRE_REG_READ5(unsigned long, "mremap", + unsigned long, old_addr, unsigned long, old_size, + unsigned long, new_size, unsigned long, flags, + unsigned long, new_addr); set_result( mremap_segment((Addr)arg1, arg2, (Addr)arg5, arg3, arg4, tid) ); } @@ -1653,22 +1655,22 @@ PRE(sched_setscheduler) arg3, sizeof(struct vki_sched_param)); } -PRE(mlock) +PREx(sys_mlock, MayBlock) { - /* int mlock(const void * addr, size_t len) */ - PRINT("mlock ( %p, %llu )", arg1, (ULong)arg2); + PRINT("sys_mlock ( %p, %llu )", arg1, (ULong)arg2); + PRE_REG_READ2(long, "mlock", unsigned long, addr, vki_size_t, len); } -PRE(munlock) +PREx(sys_munlock, MayBlock) { - /* int munlock(const void * addr, size_t len) */ - PRINT("munlock ( %p, %llu )", arg1, (ULong)arg2); + PRINT("sys_munlock ( %p, %llu )", arg1, (ULong)arg2); + PRE_REG_READ2(long, "munlock", unsigned long, addr, vki_size_t, len); } -PRE(mlockall) +PREx(sys_mlockall, MayBlock) { - /* int mlockall(int flags); */ - PRINT("mlockall ( %x )", arg1); + PRINT("sys_mlockall ( %x )", arg1); + PRE_REG_READ1(long, "mlockall", int, flags); } PREx(sys_munlockall, MayBlock) @@ -1830,10 +1832,10 @@ PREx(sys_mknod, 0) PRE_MEM_RASCIIZ( "mknod(pathname)", arg1 ); } -PRE(flock) +PREx(sys_flock, MayBlock) { - /* int flock(int fd, int operation); */ - PRINT("flock ( %d, %d )", arg1, arg2 ); + PRINT("sys_flock ( %d, %d )", arg1, arg2 ); + PRE_REG_READ2(long, "flock", unsigned int, fd, unsigned int, operation); } PRE(init_module) @@ -2185,15 +2187,17 @@ PRE(fchmod) PRINT("fchmod ( %d, %d )", arg1,arg2); } -PRE(fcntl64) +// XXX: wrapper only suitable for 32-bit systems +PREx(sys_fcntl64, 0) { - /* int fcntl64(int fd, int cmd, int arg); */ - PRINT("fcntl64 ( %d, %d, %d )", arg1,arg2,arg3); + PRINT("sys_fcntl64 ( %d, %d, %d )", arg1,arg2,arg3); + PRE_REG_READ3(long, "fcntl64", + unsigned int, fd, unsigned int, cmd, unsigned long, arg); if (arg2 == VKI_F_SETLKW || arg2 == VKI_F_SETLKW64) tst->sys_flags |= MayBlock; } -POST(fcntl64) +POSTx(sys_fcntl64) { if (arg2 == VKI_F_DUPFD) { if (!fd_allowed(res, "fcntl64(DUPFD)", tid, True)) { @@ -2323,29 +2327,31 @@ PREx(sys_truncate64, MayBlock) } -PRE(getdents) +PREx(sys_getdents, MayBlock) { - /* int getdents(unsigned int fd, struct dirent *dirp, - unsigned int count); */ - PRINT("getdents ( %d, %p, %d )",arg1,arg2,arg3); + PRINT("sys_getdents ( %d, %p, %d )", arg1,arg2,arg3); + PRE_REG_READ3(long, "getdents", + unsigned int, fd, struct linux_dirent *, dirp, + unsigned int, count); PRE_MEM_WRITE( "getdents(dirp)", arg2, arg3 ); } -POST(getdents) +POSTx(sys_getdents) { if (res > 0) POST_MEM_WRITE( arg2, res ); } -PRE(getdents64) +PREx(sys_getdents64, MayBlock) { - /* int getdents(unsigned int fd, struct dirent64 *dirp, - unsigned int count); */ PRINT("getdents64 ( %d, %p, %d )",arg1,arg2,arg3); + PRE_REG_READ3(long, "getdents64", + unsigned int, fd, struct linux_dirent64 *, dirp, + unsigned int, count); PRE_MEM_WRITE( "getdents64(dirp)", arg2, arg3 ); } -POST(getdents64) +POSTx(sys_getdents64) { if (res > 0) POST_MEM_WRITE( arg2, res ); @@ -4507,17 +4513,17 @@ PRE(mmap) } } -PRE(mprotect) +PREx(sys_mprotect, 0) { - /* int mprotect(const void *addr, size_t len, int prot); */ - /* should addr .. addr+len-1 be checked before the call? */ - PRINT("mprotect ( %p, %llu, %d )", arg1,(ULong)arg2,arg3); + PRINT("sys_mprotect ( %p, %llu, %d )", arg1,(ULong)arg2,arg3); + PRE_REG_READ3(long, "mprotect", + unsigned long, addr, vki_size_t, len, unsigned long, prot); if (!valid_client_addr(arg1, arg2, tid, "mprotect")) set_result( -VKI_ENOMEM ); } -POST(mprotect) +POSTx(sys_mprotect) { Addr a = arg1; SizeT len = arg2; @@ -4531,17 +4537,16 @@ POST(mprotect) VG_TRACK( change_mem_mprotect, a, len, rr, ww, xx ); } -PRE(munmap) +PREx(sys_munmap, 0) { - /* int munmap(void *start, size_t length); */ - /* should start .. start+length-1 be checked before the call? */ - PRINT("munmap ( %p, %llu )", arg1,(ULong)arg2); + PRINT("sys_munmap ( %p, %llu )", arg1,(ULong)arg2); + PRE_REG_READ2(long, "munmap", unsigned long, start, vki_size_t, length); if (!valid_client_addr(arg1, arg2, tid, "munmap")) set_result( -VKI_EINVAL ); } -POST(munmap) +POSTx(sys_munmap) { Addr a = arg1; SizeT len = arg2; @@ -6392,7 +6397,7 @@ static const struct sys_info sys_info[] = { // (__NR_readdir, old_readdir), // 89 () L -- superseded SYSB_(__NR_mmap, old_mmap, Special), // 90 old_mmap - SYSBA(__NR_munmap, sys_munmap, 0), // 91 * + SYSXY(__NR_munmap, sys_munmap), // 91 * P SYSX_(__NR_truncate, sys_truncate), // 92 * P SYSX_(__NR_ftruncate, sys_ftruncate), // 93 * P SYSB_(__NR_fchmod, sys_fchmod, 0), // 94 * @@ -6433,7 +6438,7 @@ static const struct sys_info sys_info[] = { SYSB_(__NR_modify_ldt, sys_modify_ldt, Special), // 123 (x86,amd64) L SYSBA(__NR_adjtimex, sys_adjtimex, 0), // 124 * - SYSBA(__NR_mprotect, sys_mprotect, 0), // 125 * + SYSXY(__NR_mprotect, sys_mprotect), // 125 * P SYSBA(__NR_sigprocmask, sys_sigprocmask, SIG_SIM), // 126 * // Nb: create_module() was removed 2.4-->2.6 SYSX_(__NR_create_module, sys_ni_syscall), // 127 * P -- unimplemented @@ -6454,10 +6459,10 @@ static const struct sys_info sys_info[] = { SYSX_(__NR_setfsgid, sys_setfsgid16), // 139 ## L SYSBA(__NR__llseek, sys_llseek, 0), // 140 * - SYSBA(__NR_getdents, sys_getdents, MayBlock), // 141 * + SYSXY(__NR_getdents, sys_getdents), // 141 * (SVr4,SVID) SYSX_(__NR__newselect, sys_select), // 142 * (4.4BSD...) - SYSB_(__NR_flock, sys_flock, MayBlock), // 143 * - SYSB_(__NR_msync, sys_msync, MayBlock), // 144 * + SYSX_(__NR_flock, sys_flock), // 143 * (4.4BSD...) + SYSX_(__NR_msync, sys_msync), // 144 * P SYSBA(__NR_readv, sys_readv, MayBlock), // 145 * SYSB_(__NR_writev, sys_writev, MayBlock), // 146 * @@ -6465,9 +6470,9 @@ static const struct sys_info sys_info[] = { SYSB_(__NR_fdatasync, sys_fdatasync, MayBlock), // 148 * SYSBA(__NR__sysctl, sys_sysctl, 0), // 149 * - SYSB_(__NR_mlock, sys_mlock, MayBlock), // 150 * - SYSB_(__NR_munlock, sys_unlock, MayBlock), // 151 * - SYSB_(__NR_mlockall, sys_mlockall, MayBlock), // 152 * + SYSX_(__NR_mlock, sys_mlock), // 150 * P + SYSX_(__NR_munlock, sys_munlock), // 151 * P + SYSX_(__NR_mlockall, sys_mlockall), // 152 * P SYSX_(__NR_munlockall, sys_munlockall), // 153 * P SYSBA(__NR_sched_setparam, sys_sched_setparam, 0/*???*/), // 154 * @@ -6480,7 +6485,7 @@ static const struct sys_info sys_info[] = { SYSB_(__NR_sched_get_priority_min,sys_sched_get_priority_min, 0/*???*/), // 160 * // (__NR_sched_rr_get_interval, sys_sched_rr_get_interval), // 161 * SYSBA(__NR_nanosleep, sys_nanosleep, MayBlock|PostOnFail), // 162 * - SYSB_(__NR_mremap, sys_mremap, Special), // 163 * + SYSX_(__NR_mremap, sys_mremap), // 163 * P SYSX_(__NR_setresuid, sys_setresuid16), // 164 ## (non-standard) SYSXY(__NR_getresuid, sys_getresuid16), // 165 ## L @@ -6550,10 +6555,10 @@ static const struct sys_info sys_info[] = { SYSBA(__NR_mincore, sys_mincore, 0), // 218 * SYSB_(__NR_madvise, sys_madvise, MayBlock), // 219 * - SYSBA(__NR_getdents64, sys_getdents64, MayBlock), // 220 * + SYSXY(__NR_getdents64, sys_getdents64), // 220 * (SVr4,SVID?) // XXX: This wrapped in a "#if BITS_PER_LONG == 32" in // include/linux/syscalls.h... - SYSBA(__NR_fcntl64, sys_fcntl64, 0), // 221 * + SYSXY(__NR_fcntl64, sys_fcntl64), // 221 * P? // Nb: 222 is reserved for TUX (whatever that means --njn) SYSX_(222, sys_ni_syscall), // 222 * P -- reserved SYSX_(223, sys_ni_syscall), // 223 * P -- unused diff --git a/memcheck/tests/scalar.c b/memcheck/tests/scalar.c index 4816b825a2..8aa488ddb5 100644 --- a/memcheck/tests/scalar.c +++ b/memcheck/tests/scalar.c @@ -366,9 +366,9 @@ int main(void) //GO(__NR_mmap, ".s .m"); //SY(__NR_mmap); - // __NR_munmap 91 - //GO(__NR_munmap, ".s .m"); - //SY(__NR_munmap); + // __NR_munmap 91 --> sys_munmap() + GO(__NR_munmap, "2s 0m"); + SY(__NR_munmap, x0, x0); // __NR_truncate 92 --> sys_truncate() GO(__NR_truncate, "2s 1m"); @@ -501,9 +501,9 @@ int main(void) //GO(__NR_adjtimex, ".s .m"); //SY(__NR_adjtimex); - // __NR_mprotect 125 - //GO(__NR_mprotect, ".s .m"); - //SY(__NR_mprotect); + // __NR_mprotect 125 --> sys_mprotect() + GO(__NR_mprotect, "3s 0m"); + SY(__NR_mprotect, x0, x0, x0); // __NR_sigprocmask 126 //GO(__NR_sigprocmask, ".s .m"); @@ -565,21 +565,21 @@ int main(void) //GO(__NR__llseek, ".s .m"); //SY(__NR__llseek); - // __NR_getdents 141 - //GO(__NR_getdents, ".s .m"); - //SY(__NR_getdents); + // __NR_getdents 141 --> sys_getdents() + GO(__NR_getdents, "3s 1m"); + SY(__NR_getdents, x0, x0, x0+1); // __NR__newselect 142 --> sys_select() GO(__NR__newselect, "5s 4m"); SY(__NR__newselect, x0+8, x0+0xffffffff, x0+1, x0+1, x0+1); // __NR_flock 143 - //GO(__NR_flock, ".s .m"); - //SY(__NR_flock); + GO(__NR_flock, "2s 0m"); + SY(__NR_flock, x0, x0); - // __NR_msync 144 - //GO(__NR_msync, ".s .m"); - //SY(__NR_msync); + // __NR_msync 144 --> sys_msync() + GO(__NR_msync, "3s 0m"); + SY(__NR_msync, x0, x0, x0); // __NR_readv 145 //GO(__NR_readv, ".s .m"); @@ -601,17 +601,17 @@ int main(void) //GO(__NR__sysctl, ".s .m"); //SY(__NR__sysctl); - // __NR_mlock 150 - //GO(__NR_mlock, ".s .m"); - //SY(__NR_mlock); + // __NR_mlock 150 --> sys_mlock() + GO(__NR_mlock, "2s 0m"); + SY(__NR_mlock, x0, x0); - // __NR_munlock 151 - //GO(__NR_munlock, ".s .m"); - //SY(__NR_munlock); + // __NR_munlock 151 --> sys_munlock() + GO(__NR_munlock, "2s 0m"); + SY(__NR_munlock, x0, x0); - // __NR_mlockall 152 - //GO(__NR_mlockall, ".s .m"); - //SY(__NR_mlockall); + // __NR_mlockall 152 --> sys_mlockall() + GO(__NR_mlockall, "2s 0m"); + SY(__NR_mlockall); // __NR_munlockall 153 --> sys_munlockall() GO(__NR_munlockall, "0e"); @@ -881,9 +881,9 @@ int main(void) //GO(__NR_madvise, ".s .m"); //SY(__NR_madvise); - // __NR_getdents64 220 - //GO(__NR_getdents64, ".s .m"); - //SY(__NR_getdents64); + // __NR_getdents64 220 --> sys_getdents64 + GO(__NR_getdents64, "3s 1m"); + SY(__NR_getdents64, x0, x0, x0+1); // __NR_fcntl64 221 //GO(__NR_fcntl64, ".s .m"); diff --git a/memcheck/tests/scalar.stderr.exp b/memcheck/tests/scalar.stderr.exp index a27b71a16c..f4fc109f90 100644 --- a/memcheck/tests/scalar.stderr.exp +++ b/memcheck/tests/scalar.stderr.exp @@ -1040,6 +1040,19 @@ Syscall param readlink(buf) points to unaddressable byte(s) by 0x........: __libc_start_main (...libc...) by 0x........: ... Address 0x........ is not stack'd, malloc'd or (recently) free'd +----------------------------------------------------- + 91: __NR_munmap 2s 0m +----------------------------------------------------- + +Syscall param munmap(start) contains uninitialised byte(s) + at 0x........: syscall (in /...libc...) + by 0x........: __libc_start_main (...libc...) + by 0x........: ... + +Syscall param munmap(length) contains uninitialised byte(s) + at 0x........: syscall (in /...libc...) + by 0x........: __libc_start_main (...libc...) + by 0x........: ... ----------------------------------------------------- 92: __NR_truncate 2s 1m ----------------------------------------------------- @@ -1180,6 +1193,24 @@ Syscall param uname(buf) points to unaddressable byte(s) by 0x........: ... Address 0x........ is not stack'd, malloc'd or (recently) free'd ----------------------------------------------------- +125: __NR_mprotect 3s 0m +----------------------------------------------------- + +Syscall param mprotect(addr) contains uninitialised byte(s) + at 0x........: syscall (in /...libc...) + by 0x........: __libc_start_main (...libc...) + by 0x........: ... + +Syscall param mprotect(len) contains uninitialised byte(s) + at 0x........: syscall (in /...libc...) + by 0x........: __libc_start_main (...libc...) + by 0x........: ... + +Syscall param mprotect(prot) contains uninitialised byte(s) + at 0x........: syscall (in /...libc...) + by 0x........: __libc_start_main (...libc...) + by 0x........: ... +----------------------------------------------------- 127: __NR_create_module 0e ----------------------------------------------------- ----------------------------------------------------- @@ -1205,6 +1236,30 @@ Syscall param setfsgid16(gid) contains uninitialised byte(s) by 0x........: __libc_start_main (...libc...) by 0x........: ... ----------------------------------------------------- +141: __NR_getdents 3s 1m +----------------------------------------------------- + +Syscall param getdents(fd) contains uninitialised byte(s) + at 0x........: syscall (in /...libc...) + by 0x........: __libc_start_main (...libc...) + by 0x........: ... + +Syscall param getdents(dirp) contains uninitialised byte(s) + at 0x........: syscall (in /...libc...) + by 0x........: __libc_start_main (...libc...) + by 0x........: ... + +Syscall param getdents(count) contains uninitialised byte(s) + at 0x........: syscall (in /...libc...) + by 0x........: __libc_start_main (...libc...) + by 0x........: ... + +Syscall param getdents(dirp) points to unaddressable byte(s) + at 0x........: syscall (in /...libc...) + by 0x........: __libc_start_main (...libc...) + by 0x........: ... + Address 0x........ is not stack'd, malloc'd or (recently) free'd +----------------------------------------------------- 142: __NR__newselect 5s 4m ----------------------------------------------------- @@ -1257,6 +1312,71 @@ Syscall param select(timeout) points to unaddressable byte(s) by 0x........: ... Address 0x........ is not stack'd, malloc'd or (recently) free'd ----------------------------------------------------- +143: __NR_flock 2s 0m +----------------------------------------------------- + +Syscall param flock(fd) contains uninitialised byte(s) + at 0x........: syscall (in /...libc...) + by 0x........: __libc_start_main (...libc...) + by 0x........: ... + +Syscall param flock(operation) contains uninitialised byte(s) + at 0x........: syscall (in /...libc...) + by 0x........: __libc_start_main (...libc...) + by 0x........: ... +----------------------------------------------------- +144: __NR_msync 3s 0m +----------------------------------------------------- + +Syscall param msync(start) contains uninitialised byte(s) + at 0x........: syscall (in /...libc...) + by 0x........: __libc_start_main (...libc...) + by 0x........: ... + +Syscall param msync(length) contains uninitialised byte(s) + at 0x........: syscall (in /...libc...) + by 0x........: __libc_start_main (...libc...) + by 0x........: ... + +Syscall param msync(flags) contains uninitialised byte(s) + at 0x........: syscall (in /...libc...) + by 0x........: __libc_start_main (...libc...) + by 0x........: ... +----------------------------------------------------- +150: __NR_mlock 2s 0m +----------------------------------------------------- + +Syscall param mlock(addr) contains uninitialised byte(s) + at 0x........: syscall (in /...libc...) + by 0x........: __libc_start_main (...libc...) + by 0x........: ... + +Syscall param mlock(len) contains uninitialised byte(s) + at 0x........: syscall (in /...libc...) + by 0x........: __libc_start_main (...libc...) + by 0x........: ... +----------------------------------------------------- +151: __NR_munlock 2s 0m +----------------------------------------------------- + +Syscall param munlock(addr) contains uninitialised byte(s) + at 0x........: syscall (in /...libc...) + by 0x........: __libc_start_main (...libc...) + by 0x........: ... + +Syscall param munlock(len) contains uninitialised byte(s) + at 0x........: syscall (in /...libc...) + by 0x........: __libc_start_main (...libc...) + by 0x........: ... +----------------------------------------------------- +152: __NR_mlockall 2s 0m +----------------------------------------------------- + +Syscall param mlockall(flags) contains uninitialised byte(s) + at 0x........: syscall (in /...libc...) + by 0x........: __libc_start_main (...libc...) + by 0x........: ... +----------------------------------------------------- 153: __NR_munlockall 0e ----------------------------------------------------- ----------------------------------------------------- @@ -1842,6 +1962,30 @@ Syscall param setfsgid(gid) contains uninitialised byte(s) by 0x........: __libc_start_main (...libc...) by 0x........: ... ----------------------------------------------------- +220: __NR_getdents64 3s 1m +----------------------------------------------------- + +Syscall param getdents64(fd) contains uninitialised byte(s) + at 0x........: syscall (in /...libc...) + by 0x........: __libc_start_main (...libc...) + by 0x........: ... + +Syscall param getdents64(dirp) contains uninitialised byte(s) + at 0x........: syscall (in /...libc...) + by 0x........: __libc_start_main (...libc...) + by 0x........: ... + +Syscall param getdents64(count) contains uninitialised byte(s) + at 0x........: syscall (in /...libc...) + by 0x........: __libc_start_main (...libc...) + by 0x........: ... + +Syscall param getdents64(dirp) points to unaddressable byte(s) + at 0x........: syscall (in /...libc...) + by 0x........: __libc_start_main (...libc...) + by 0x........: ... + Address 0x........ is not stack'd, malloc'd or (recently) free'd +----------------------------------------------------- 222: 222 0e ----------------------------------------------------- -----------------------------------------------------