From owner-p4-projects@FreeBSD.ORG Fri Oct 24 21:28:21 2008 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 4BE09106567D; Fri, 24 Oct 2008 21:28:21 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 0FE5C1065672 for ; Fri, 24 Oct 2008 21:28:21 +0000 (UTC) (envelope-from peter-gmail@wemm.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id F1CE88FC12 for ; Fri, 24 Oct 2008 21:28:20 +0000 (UTC) (envelope-from peter-gmail@wemm.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id m9OLSKxk010963 for ; Fri, 24 Oct 2008 21:28:20 GMT (envelope-from peter-gmail@wemm.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id m9OLSKmj010961 for perforce@freebsd.org; Fri, 24 Oct 2008 21:28:20 GMT (envelope-from peter-gmail@wemm.org) Date: Fri, 24 Oct 2008 21:28:20 GMT Message-Id: <200810242128.m9OLSKmj010961@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to peter-gmail@wemm.org using -f From: Peter Wemm To: Perforce Change Reviews Cc: Subject: PERFORCE change 151881 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 24 Oct 2008 21:28:21 -0000 http://perforce.freebsd.org/chv.cgi?CH=151881 Change 151881 by peter@peter_cheese on 2008/10/24 21:27:59 add handlers for *at syscalls, duplicated from linux code. Affected files ... .. //depot/projects/valgrind/coregrind/m_syswrap/priv_syswrap-freebsd.h#7 edit .. //depot/projects/valgrind/coregrind/m_syswrap/syswrap-freebsd.c#14 edit .. //depot/projects/valgrind/include/vki/vki-freebsd.h#4 edit Differences ... ==== //depot/projects/valgrind/coregrind/m_syswrap/priv_syswrap-freebsd.h#7 (text+ko) ==== ==== //depot/projects/valgrind/coregrind/m_syswrap/syswrap-freebsd.c#14 (text+ko) ==== @@ -2301,6 +2301,213 @@ ML_(generic_POST_sys_semctl)(tid, RES,ARG1,ARG2,ARG3,ARG4); } +/* --------------------------------------------------------------------- + *at wrappers + ------------------------------------------------------------------ */ + +PRE(sys_openat) +{ + HChar name[30]; + SysRes sres; + + if (ARG3 & VKI_O_CREAT) { + // 4-arg version + PRINT("sys_openat ( %ld, %#lx(%s), %ld, %ld )",ARG1,ARG2,(char*)ARG2,ARG3,ARG4); + PRE_REG_READ4(long, "openat", + int, dfd, const char *, filename, int, flags, int, mode); + } else { + // 3-arg version + PRINT("sys_openat ( %ld, %#lx(%s), %ld )",ARG1,ARG2,(char*)ARG2,ARG3); + PRE_REG_READ3(long, "openat", + int, dfd, const char *, filename, int, flags); + } + + if (ARG1 != VKI_AT_FDCWD && !ML_(fd_allowed)(ARG1, "openat", tid, False)) + SET_STATUS_Failure( VKI_EBADF ); + else + PRE_MEM_RASCIIZ( "openat(filename)", ARG2 ); + + /* Handle the case where the open is of /proc/curproc/cmdline or + /proc//cmdline, and just give it a copy of the fd for the + fake file we cooked up at startup (in m_main). Also, seek the + cloned fd back to the start. */ + + VG_(sprintf)(name, "/proc/%d/cmdline", VG_(getpid)()); + if (ML_(safe_to_deref)( (void*)ARG2, 1 ) + && (VG_(strcmp)((Char *)ARG2, name) == 0 + || VG_(strcmp)((Char *)ARG2, "/proc/curproc/cmdline") == 0)) { + sres = VG_(dup)( VG_(cl_cmdline_fd) ); + SET_STATUS_from_SysRes( sres ); + if (!sres.isError) { + OffT off = VG_(lseek)( sres.res, 0, VKI_SEEK_SET ); + if (off < 0) + SET_STATUS_Failure( VKI_EMFILE ); + } + return; + } + + /* Otherwise handle normally */ + *flags |= SfMayBlock; +} + +POST(sys_openat) +{ + vg_assert(SUCCESS); + if (!ML_(fd_allowed)(RES, "openat", tid, True)) { + VG_(close)(RES); + SET_STATUS_Failure( VKI_EMFILE ); + } else { + if (VG_(clo_track_fds)) + ML_(record_fd_open_with_given_name)(tid, RES, (Char*)ARG2); + } +} + +PRE(sys_mkdirat) +{ + *flags |= SfMayBlock; + PRINT("sys_mkdirat ( %ld, %#lx(%s), %ld )", ARG1,ARG2,(char*)ARG2,ARG3); + PRE_REG_READ3(long, "mkdirat", + int, dfd, const char *, pathname, int, mode); + PRE_MEM_RASCIIZ( "mkdirat(pathname)", ARG2 ); +} + +PRE(sys_mkfifoat) +{ + PRINT("sys_mkfifoat ( %ld, %#lx(%s), 0x%lx )", ARG1,ARG2,(char*)ARG2,ARG3 ); + PRE_REG_READ3(long, "mkfifoat", + int, dfd, const char *, pathname, int, mode); + PRE_MEM_RASCIIZ( "mkfifoat(pathname)", ARG2 ); +} + +PRE(sys_mknodat) +{ + PRINT("sys_mknodat ( %ld, %#lx(%s), 0x%lx, 0x%lx )", ARG1,ARG2,(char*)ARG2,ARG3,ARG4 ); + PRE_REG_READ4(long, "mknodat", + int, dfd, const char *, pathname, int, mode, unsigned, dev); + PRE_MEM_RASCIIZ( "mknodat(pathname)", ARG2 ); +} + +PRE(sys_fchownat) +{ + PRINT("sys_fchownat ( %ld, %#lx(%s), 0x%lx, 0x%lx )", ARG1,ARG2,(char*)ARG2,ARG3,ARG4); + PRE_REG_READ4(long, "fchownat", + int, dfd, const char *, path, + vki_uid_t, owner, vki_gid_t, group); + PRE_MEM_RASCIIZ( "fchownat(path)", ARG2 ); +} + +PRE(sys_futimesat) +{ + PRINT("sys_futimesat ( %ld, %#lx(%s), %#lx )", ARG1,ARG2,(char*)ARG2,ARG3); + PRE_REG_READ3(long, "futimesat", + int, dfd, char *, filename, struct timeval *, tvp); + if (ARG2 != 0) + PRE_MEM_RASCIIZ( "futimesat(filename)", ARG2 ); + if (ARG3 != 0) + PRE_MEM_READ( "futimesat(tvp)", ARG3, 2 * sizeof(struct vki_timeval) ); +} + +PRE(sys_fstatat) +{ + PRINT("sys_fstatat ( %ld, %#lx(%s), %#lx )", ARG1,ARG2,(char*)ARG2,ARG3); + PRE_REG_READ3(long, "fstatat", + int, dfd, char *, file_name, struct stat *, buf); + PRE_MEM_RASCIIZ( "fstatat(file_name)", ARG2 ); + PRE_MEM_WRITE( "fstatat(buf)", ARG3, sizeof(struct vki_stat) ); +} + +POST(sys_fstatat) +{ + POST_MEM_WRITE( ARG3, sizeof(struct vki_stat) ); +} + +PRE(sys_unlinkat) +{ + *flags |= SfMayBlock; + PRINT("sys_unlinkat ( %ld, %#lx(%s) )", ARG1,ARG2,(char*)ARG2); + PRE_REG_READ2(long, "unlinkat", int, dfd, const char *, pathname); + PRE_MEM_RASCIIZ( "unlinkat(pathname)", ARG2 ); +} + +PRE(sys_renameat) +{ + PRINT("sys_renameat ( %ld, %#lx(%s), %ld, %#lx(%s) )", ARG1,ARG2,(char*)ARG2,ARG3,ARG4,(char*)ARG4); + PRE_REG_READ4(long, "renameat", + int, olddfd, const char *, oldpath, + int, newdfd, const char *, newpath); + PRE_MEM_RASCIIZ( "renameat(oldpath)", ARG2 ); + PRE_MEM_RASCIIZ( "renameat(newpath)", ARG4 ); +} + +PRE(sys_linkat) +{ + *flags |= SfMayBlock; + PRINT("sys_linkat ( %ld, %#lx(%s), %ld, %#lx(%s), %ld )",ARG1,ARG2,(char*)ARG2,ARG3,ARG4,(char*)ARG4,ARG5); + PRE_REG_READ5(long, "linkat", + int, olddfd, const char *, oldpath, + int, newdfd, const char *, newpath, + int, flags); + PRE_MEM_RASCIIZ( "linkat(oldpath)", ARG2); + PRE_MEM_RASCIIZ( "linkat(newpath)", ARG4); +} + +PRE(sys_symlinkat) +{ + *flags |= SfMayBlock; + PRINT("sys_symlinkat ( %#lx(%s), %ld, %#lx(%s) )",ARG1,(char*)ARG1,ARG2,ARG3,(char*)ARG3); + PRE_REG_READ3(long, "symlinkat", + const char *, oldpath, int, newdfd, const char *, newpath); + PRE_MEM_RASCIIZ( "symlinkat(oldpath)", ARG1 ); + PRE_MEM_RASCIIZ( "symlinkat(newpath)", ARG3 ); +} + +PRE(sys_readlinkat) +{ + HChar name[25]; + Word saved = SYSNO; + + PRINT("sys_readlinkat ( %ld, %#lx(%s), %#lx, %llu )", ARG1,ARG2,(char*)ARG2,ARG3,(ULong)ARG4); + PRE_REG_READ4(long, "readlinkat", + int, dfd, const char *, path, char *, buf, int, bufsiz); + PRE_MEM_RASCIIZ( "readlinkat(path)", ARG2 ); + PRE_MEM_WRITE( "readlinkat(buf)", ARG3,ARG4 ); + + /* + * Handle the case where readlinkat is looking at /proc/curproc/file or + * /proc//file. + */ + VG_(sprintf)(name, "/proc/%d/file", VG_(getpid)()); + if (ML_(safe_to_deref)((void*)ARG2, 1) + && (VG_(strcmp)((Char *)ARG2, name) == 0 + || VG_(strcmp)((Char *)ARG2, "/proc/curproc/file") == 0)) { + VG_(sprintf)(name, "/proc/self/fd/%d", VG_(cl_exec_fd)); + SET_STATUS_from_SysRes( VG_(do_syscall4)(saved, ARG1, (UWord)name, + ARG3, ARG4)); + } else { + /* Normal case */ + SET_STATUS_from_SysRes( VG_(do_syscall4)(saved, ARG1, ARG2, ARG3, ARG4)); + } + + if (SUCCESS && RES > 0) + POST_MEM_WRITE( ARG3, RES ); +} + +PRE(sys_fchmodat) +{ + PRINT("sys_fchmodat ( %ld, %#lx(%s), %ld )", ARG1,ARG2,(char*)ARG2,ARG3); + PRE_REG_READ3(long, "fchmodat", + int, dfd, const char *, path, vki_mode_t, mode); + PRE_MEM_RASCIIZ( "fchmodat(path)", ARG2 ); +} + +PRE(sys_faccessat) +{ + PRINT("sys_faccessat ( %ld, %#lx(%s), %ld )", ARG1,ARG2,(char*)ARG2,ARG3); + PRE_REG_READ3(long, "faccessat", + int, dfd, const char *, pathname, int, mode); + PRE_MEM_RASCIIZ( "faccessat(pathname)", ARG2 ); +} + #undef PRE #undef POST @@ -2916,24 +3123,24 @@ // cpuset_getaffinity 487 // cpuset_setaffinity 488 - // faccessat 489 - // fchmodat 490 - // fchownat 491 + BSDX_(__NR_faccessat, sys_faccessat), // 489 + BSDX_(__NR_fchmodat, sys_fchmodat), // 490 + BSDX_(__NR_fchownat, sys_fchownat), // 491 // fexecve 492 - // fstatat 493 - // futimesat 494 - // linkat 495 + BSDXY(__NR_fstatat, sys_fstatat), // 493 + BSDX_(__NR_futimesat, sys_futimesat), // 494 + BSDX_(__NR_linkat, sys_linkat), // 495 - // mkdirat 496 - // mkfifoat 497 - // mknodat 498 - // openat 499 + BSDX_(__NR_mkdirat, sys_mkdirat), // 496 + BSDX_(__NR_mkfifoat, sys_mkfifoat), // 497 + BSDX_(__NR_mknodat, sys_mknodat), // 498 + BSDXY(__NR_openat, sys_openat), // 499 - // readlinkat 500 - // renameat 501 - // symlinkat 502 - // unlinkat 503 + BSDX_(__NR_readlinkat, sys_readlinkat), // 500 + BSDX_(__NR_renameat, sys_renameat), // 501 + BSDX_(__NR_symlinkat, sys_symlinkat), // 502 + BSDX_(__NR_unlinkat, sys_unlinkat), // 503 // posix_openpt 504 ==== //depot/projects/valgrind/include/vki/vki-freebsd.h#4 (text+ko) ==== @@ -1326,6 +1326,8 @@ #define VKI_O_TRUNC 0x0400 /* not fcntl */ #define VKI_O_EXCL 0x0800 /* not fcntl */ +#define VKI_AT_FDCWD -100 + #define VKI_F_DUPFD 0 /* dup */ #define VKI_F_GETFD 1 /* get close_on_exec */ #define VKI_F_SETFD 2 /* set/clear close_on_exec */