]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Use correct syscall numbers on arm64. Fix rename, dup2 and getpgrp.
authorMark Wielaard <mark@klomp.org>
Wed, 9 Mar 2016 16:18:34 +0000 (16:18 +0000)
committerMark Wielaard <mark@klomp.org>
Wed, 9 Mar 2016 16:18:34 +0000 (16:18 +0000)
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

coregrind/m_libcfile.c
coregrind/m_libcproc.c
coregrind/m_syswrap/syswrap-generic.c
include/vki/vki-scnums-arm64-linux.h

index 7e94ce36c972a99867165d53bab715772a4cbb10..c413db1282a9e632010ab5530249962d3f5c147b 100644 (file)
@@ -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
index a30f7dc8f0c5071d6ba30a319bca3e7eac61dbef..eb911beba3d634d46cfaf2ad0f2b6b18c891ea79 100644 (file)
@@ -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. */
index 2eaf505db2700e28f61cf37e76223b84af523446..dd1da9c3f00185ca69d18be0b8f4d1f2101bc916 100644 (file)
@@ -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)
 {
index f70a2edb87adc2a7d0bde68e9eb48d18c563a7d0..e963c45214772c461439698c06da1da38c895312 100644 (file)
 //#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
 //__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)
 //#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
 //__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
 //#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)
 //#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
 //
 //#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
 //#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
 // */
 //#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