From: Mark Wielaard Date: Wed, 9 Mar 2016 16:18:34 +0000 (+0000) Subject: Use correct syscall numbers on arm64. Fix rename, dup2 and getpgrp. X-Git-Tag: svn/VALGRIND_3_12_0~199 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=eba2cff4801cd7f4be4c1a467c3435e86c9c020b;p=thirdparty%2Fvalgrind.git Use correct syscall numbers on arm64. Fix rename, dup2 and getpgrp. We were using some wrong syscall numbers in vki-scnums-arm64-linux.h arm64 doesn't implement a couple of old deprecated system calls like rename, dup2, getpgrp and fork. Adjust m_libcfile.c rename and dup2 functions to use renameat (also on tilegx) and dup3 (with fcntl fallback for bad oldfd). And in m_libcproc.c implement getpgrp as getpgid(0). Also don't compile the fork syswrap on arm64 (it only supports clone). In practice this only affected callgrind which was unable to rename dump files in some cases and ELF core dumps might have contained some bogus prstatus fields. Related to bug #359503 - Add missing syscalls for aarch64 (arm64) Reported by Marcin Juszkiewicz who also posted a nice overview of system calls on different linux architectures: https://marcin.juszkiewicz.com.pl/2016/03/05/from-a-diary-of-aarch64-porter-system-calls/ git-svn-id: svn://svn.valgrind.org/valgrind/trunk@15824 --- diff --git a/coregrind/m_libcfile.c b/coregrind/m_libcfile.c index 7e94ce36c9..c413db1282 100644 --- a/coregrind/m_libcfile.c +++ b/coregrind/m_libcfile.c @@ -480,7 +480,18 @@ SysRes VG_(dup) ( Int oldfd ) SysRes VG_(dup2) ( Int oldfd, Int newfd ) { -# if defined(VGO_linux) || defined(VGO_darwin) +# if defined(VGP_arm64_linux) + /* We only have dup3, that means we have to mimic dup2. + The only real difference is when oldfd == newfd. + dup3 always returns an error, but dup2 returns only an + error if the fd is invalid, otherwise it returns newfd. */ + if (oldfd == newfd) { + if (VG_(fcntl)(oldfd, VKI_F_GETFL, 0) == -1) + return VG_(mk_SysRes_Error)(VKI_EBADF); + return VG_(mk_SysRes_Success)(newfd); + } + return VG_(do_syscall3)(__NR_dup3, oldfd, newfd, 0); +# elif defined(VGO_linux) || defined(VGO_darwin) return VG_(do_syscall2)(__NR_dup2, oldfd, newfd); # elif defined(VGO_solaris) return VG_(do_syscall3)(__NR_fcntl, oldfd, F_DUP2FD, newfd); @@ -504,14 +515,12 @@ Int VG_(fcntl) ( Int fd, Int cmd, Addr arg ) Int VG_(rename) ( const HChar* old_name, const HChar* new_name ) { -# if defined(VGP_tilegx_linux) - SysRes res = VG_(do_syscall3)(__NR_renameat, VKI_AT_FDCWD, - (UWord)old_name, (UWord)new_name); -# elif defined(VGO_linux) || defined(VGO_darwin) - SysRes res = VG_(do_syscall2)(__NR_rename, (UWord)old_name, (UWord)new_name); -# elif defined(VGO_solaris) +# if defined(VGO_solaris) \ + || defined(VGP_arm64_linux) || defined(VGP_tilegx_linux) SysRes res = VG_(do_syscall4)(__NR_renameat, VKI_AT_FDCWD, (UWord)old_name, VKI_AT_FDCWD, (UWord)new_name); +# elif defined(VGO_linux) || defined(VGO_darwin) + SysRes res = VG_(do_syscall2)(__NR_rename, (UWord)old_name, (UWord)new_name); # else # error "Unknown OS" # endif diff --git a/coregrind/m_libcproc.c b/coregrind/m_libcproc.c index a30f7dc8f0..eb911beba3 100644 --- a/coregrind/m_libcproc.c +++ b/coregrind/m_libcproc.c @@ -708,7 +708,9 @@ Int VG_(getpid) ( void ) Int VG_(getpgrp) ( void ) { /* ASSUMES SYSCALL ALWAYS SUCCEEDS */ -# if defined(VGO_linux) || defined(VGO_darwin) +# if defined(VGP_arm64_linux) + return sr_Res( VG_(do_syscall1)(__NR_getpgid, 0) ); +# elif defined(VGO_linux) || defined(VGO_darwin) return sr_Res( VG_(do_syscall0)(__NR_getpgrp) ); # elif defined(VGO_solaris) /* Uses the shared pgrpsys syscall, 0 for the getpgrp variant. */ diff --git a/coregrind/m_syswrap/syswrap-generic.c b/coregrind/m_syswrap/syswrap-generic.c index 2eaf505db2..dd1da9c3f0 100644 --- a/coregrind/m_syswrap/syswrap-generic.c +++ b/coregrind/m_syswrap/syswrap-generic.c @@ -3264,7 +3264,7 @@ POST(sys_newfstat) POST_MEM_WRITE( ARG2, sizeof(struct vki_stat) ); } -#if !defined(VGO_solaris) +#if !defined(VGO_solaris) && !defined(VGP_arm64_linux) static vki_sigset_t fork_saved_mask; // In Linux, the sys_fork() function varies across architectures, but we @@ -3327,7 +3327,7 @@ PRE(sys_fork) VG_(sigprocmask)(VKI_SIG_SETMASK, &fork_saved_mask, NULL); } } -#endif // !defined(VGO_solaris) +#endif // !defined(VGO_solaris) && !defined(VGP_arm64_linux) PRE(sys_ftruncate) { diff --git a/include/vki/vki-scnums-arm64-linux.h b/include/vki/vki-scnums-arm64-linux.h index f70a2edb87..e963c45214 100644 --- a/include/vki/vki-scnums-arm64-linux.h +++ b/include/vki/vki-scnums-arm64-linux.h @@ -331,7 +331,7 @@ //#define __NR_link 1025 //__SYSCALL(__NR_link, sys_link) //#define __NR_unlink 1026 -#define __NR_mknod 1027 +//#define __NR_mknod 1027 //#define __NR_chmod 1028 //__SYSCALL(__NR_chmod, sys_chmod) //#define __NR_chown 1029 @@ -342,8 +342,8 @@ //__SYSCALL(__NR_rmdir, sys_rmdir) //#define __NR_lchown 1032 //__SYSCALL(__NR_lchown, sys_lchown) -#define __NR_access 1033 -#define __NR_rename 1034 +//#define __NR_access 1033 +//#define __NR_rename 1034 //#define __NR_readlink 1035 //#define __NR_symlink 1036 //__SYSCALL(__NR_symlink, sys_symlink) @@ -359,8 +359,8 @@ //#endif /* __ARCH_WANT_SYSCALL_NO_AT */ // //#ifdef __ARCH_WANT_SYSCALL_NO_FLAGS -#define __NR_pipe 1040 -#define __NR_dup2 1041 +//#define __NR_pipe 1040 +//#define __NR_dup2 1041 //#define __NR_epoll_create 1042 //__SYSCALL(__NR_epoll_create, sys_epoll_create) //#define __NR_inotify_init 1043 @@ -383,7 +383,7 @@ //__SYSCALL(__NR_ftruncate, sys_ftruncate) //#define __NR_truncate 1048 //__SYSCALL(__NR_truncate, sys_truncate) -#define __NR_stat 1049 +//#define __NR_stat 1049 //#define __NR_lstat 1050 //__SYSCALL(__NR_lstat, sys_newlstat) //ZZ#define __NR_fstat 1051 @@ -399,7 +399,7 @@ //#define __NR_statfs 1056 //__SYSCALL(__NR_statfs, sys_statfs) //#define __NR_lseek 1057 -#define __NR_mmap 1058 +//#define __NR_mmap 1058 // //#undef __NR_syscalls //#define __NR_syscalls (__NR_mmap+1) @@ -409,7 +409,7 @@ //#define __NR_alarm 1059 //#define __ARCH_WANT_SYS_ALARM //__SYSCALL(__NR_alarm, sys_alarm) -#define __NR_getpgrp 1060 +//#define __NR_getpgrp 1060 //#define __ARCH_WANT_SYS_GETPGRP //__SYSCALL(__NR_getpgrp, sys_getpgrp) //#define __NR_pause 1061 @@ -425,13 +425,13 @@ // //#define __NR_creat 1064 //__SYSCALL(__NR_creat, sys_creat) -#define __NR_getdents 1065 +//#define __NR_getdents 1065 //#define __NR_futimesat 1066 //__SYSCALL(__NR_futimesat, sys_futimesat) //#define __NR_select 1067 //#define __ARCH_WANT_SYS_SELECT //__SYSCALL(__NR_select, sys_select) -#define __NR_poll 1068 +//#define __NR_poll 1068 //#define __NR_epoll_wait 1069 //__SYSCALL(__NR_epoll_wait, sys_epoll_wait) //#define __NR_ustat 1070 @@ -454,7 +454,7 @@ //#define __NR__sysctl 1078 //__SYSCALL(__NR__sysctl, sys_sysctl) // -#define __NR_fork 1079 +//#define __NR_fork 1079 //#ifdef CONFIG_MMU //__SYSCALL(__NR_fork, sys_fork) //#else @@ -478,16 +478,16 @@ // */ //#if __BITS_PER_LONG == 64 && !defined(__SYSCALL_COMPAT) #define __NR_fcntl __NR3264_fcntl -//#define __NR_statfs __NR3264_statfs -//#define __NR_fstatfs __NR3264_fstatfs -//#define __NR_truncate __NR3264_truncate -//#define __NR_ftruncate __NR3264_ftruncate +#define __NR_statfs __NR3264_statfs +#define __NR_fstatfs __NR3264_fstatfs +#define __NR_truncate __NR3264_truncate +#define __NR_ftruncate __NR3264_ftruncate #define __NR_lseek __NR3264_lseek -//#define __NR_sendfile __NR3264_sendfile -//#define __NR_newfstatat __NR3264_fstatat +#define __NR_sendfile __NR3264_sendfile +#define __NR_newfstatat __NR3264_fstatat #define __NR_fstat __NR3264_fstat -//#define __NR_mmap __NR3264_mmap -//#define __NR_fadvise64 __NR3264_fadvise64 +#define __NR_mmap __NR3264_mmap +#define __NR_fadvise64 __NR3264_fadvise64 //#ifdef __NR3264_stat //#define __NR_stat __NR3264_stat //#define __NR_lstat __NR3264_lstat