]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
mips32: fix fadvise64 system call
authorPetar Jovanovic <mips32r2@gmail.com>
Tue, 29 Nov 2016 14:27:25 +0000 (14:27 +0000)
committerPetar Jovanovic <mips32r2@gmail.com>
Tue, 29 Nov 2016 14:27:25 +0000 (14:27 +0000)
For fadvise64 system call, 7th 32-bit argument slot (third on the stack)
will also be used due to MIPS O32 calling convention in passing 64-bit
values.

sys_fadvise64(int fd, loff_t offset, loff_t len, int advice);

NR_fadvise64 -> v0               (sysno)
fd           -> a0               (ARG1)
offset       -> a2, a3           (ARG3, ARG4)
len          -> SP + 16, SP + 20 (ARG5, ARG6)
advise       -> SP + 24          (ARG7)

Change the code according to it.

Patch by Aleksandar Rikalo.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@16162

coregrind/m_syswrap/priv_types_n_macros.h
coregrind/m_syswrap/syswrap-generic.c
coregrind/m_syswrap/syswrap-linux.c
coregrind/m_syswrap/syswrap-main.c
coregrind/m_syswrap/syswrap-mips32-linux.c

index 0eacfc758d9891af171eb49f86c17336c5d0cdd8..2a689475dbebcd5aa40f502e12a0959a2e60b86a 100644 (file)
@@ -110,7 +110,7 @@ typedef
       Int o_arg4;
       Int s_arg5;
       Int s_arg6;
-      Int uu_arg7;
+      Int s_arg7;
       Int uu_arg8;
 #     elif defined(VGP_x86_darwin) || defined(VGP_x86_solaris)
       Int s_arg1;
@@ -181,16 +181,7 @@ typedef
    fixed sized table exposed to the caller, but that's too inflexible;
    hence now use a function which can do arbitrary messing around to
    find the required entry. */
-#if defined(VGP_mips32_linux)
-   /* Up to 6 parameters, 4 in registers 2 on stack. */
-#  define PRA1(s,t,a) PRRAn(1,s,t,a)
-#  define PRA2(s,t,a) PRRAn(2,s,t,a)
-#  define PRA3(s,t,a) PRRAn(3,s,t,a)
-#  define PRA4(s,t,a) PRRAn(4,s,t,a)
-#  define PRA5(s,t,a) PSRAn(5,s,t,a)
-#  define PRA6(s,t,a) PSRAn(6,s,t,a)
 
-#endif
 #if defined(VGO_linux)
 extern
 SyscallTableEntry* ML_(get_linux_syscall_entry)( UInt sysno );
@@ -407,6 +398,7 @@ static inline UWord getERR ( SyscallStatus* st ) {
 #  define PRA4(s,t,a) PRRAn(4,s,t,a)
 #  define PRA5(s,t,a) PSRAn(5,s,t,a)
 #  define PRA6(s,t,a) PSRAn(6,s,t,a)
+#  define PRA7(s,t,a) PSRAn(7,s,t,a)
 
 #elif defined(VGO_linux) && !defined(VGP_mips32_linux)
    /* Up to 6 parameters, all in registers. */
@@ -637,6 +629,19 @@ static inline UWord getERR ( SyscallStatus* st ) {
 #define POST_FIELD_WRITE(zzfield) \
     POST_MEM_WRITE((UWord)&zzfield, sizeof(zzfield))
 
+// Macros to support 64-bit syscall args split into two 32 bit values
+#define LOHI64(lo,hi)   ( ((ULong)(lo)) | (((ULong)(hi)) << 32) )
+#if defined(VG_LITTLEENDIAN)
+#define MERGE64(lo,hi)   ( ((ULong)(lo)) | (((ULong)(hi)) << 32) )
+#define MERGE64_FIRST(name) name##_low
+#define MERGE64_SECOND(name) name##_high
+#elif defined(VG_BIGENDIAN)
+#define MERGE64(hi,lo)   ( ((ULong)(lo)) | (((ULong)(hi)) << 32) )
+#define MERGE64_FIRST(name) name##_high
+#define MERGE64_SECOND(name) name##_low
+#else
+#error Unknown endianness
+#endif
 
 #endif   // __PRIV_TYPES_N_MACROS_H
 
index 28972ae4553a63eba489d124fdf1cfc99de76771..31eca3df775d6fd2a90b5c912a7b5c5f1e93a3a9 100644 (file)
@@ -2429,19 +2429,6 @@ ML_(generic_PRE_sys_mmap) ( ThreadId tid,
 #define PRE(name)      DEFN_PRE_TEMPLATE(generic, name)
 #define POST(name)     DEFN_POST_TEMPLATE(generic, name)
 
-// Macros to support 64-bit syscall args split into two 32 bit values
-#if defined(VG_LITTLEENDIAN)
-#define MERGE64(lo,hi)   ( ((ULong)(lo)) | (((ULong)(hi)) << 32) )
-#define MERGE64_FIRST(name) name##_low
-#define MERGE64_SECOND(name) name##_high
-#elif defined(VG_BIGENDIAN)
-#define MERGE64(hi,lo)   ( ((ULong)(lo)) | (((ULong)(hi)) << 32) )
-#define MERGE64_FIRST(name) name##_high
-#define MERGE64_SECOND(name) name##_low
-#else
-#error Unknown endianness
-#endif
-
 PRE(sys_exit)
 {
    ThreadState* tst;
index 725ad782e9ea3af52a876eca00a6a0eaa9e6c41c..b3ffdb1cbfaab3eb683b6620bc092d289ec6d3ce 100644 (file)
@@ -519,20 +519,6 @@ SysRes ML_(do_fork_clone) ( ThreadId tid, UInt flags,
 #define PRE(name)       DEFN_PRE_TEMPLATE(linux, name)
 #define POST(name)      DEFN_POST_TEMPLATE(linux, name)
 
-// Macros to support 64-bit syscall args split into two 32 bit values
-#define LOHI64(lo,hi)   ( ((ULong)(lo)) | (((ULong)(hi)) << 32) )
-#if defined(VG_LITTLEENDIAN)
-#define MERGE64(lo,hi)   ( ((ULong)(lo)) | (((ULong)(hi)) << 32) )
-#define MERGE64_FIRST(name) name##_low
-#define MERGE64_SECOND(name) name##_high
-#elif defined(VG_BIGENDIAN)
-#define MERGE64(hi,lo)   ( ((ULong)(lo)) | (((ULong)(hi)) << 32) )
-#define MERGE64_FIRST(name) name##_high
-#define MERGE64_SECOND(name) name##_low
-#else
-#error Unknown endianness
-#endif
-
 /* ---------------------------------------------------------------------
    *mount wrappers
    ------------------------------------------------------------------ */
index d85419473efc91856802523c07c6fab69754086e..7a9664e9242375b3d34af220c077b118bf09eb0d 100644 (file)
@@ -549,8 +549,9 @@ void getSyscallArgsFromGuestState ( /*OUT*/SyscallArgs*       canonical,
       canonical->arg2  = gst->guest_r5;    // a1
       canonical->arg3  = gst->guest_r6;    // a2
       canonical->arg4  = gst->guest_r7;    // a3
-      canonical->arg5  = *((UInt*) (gst->guest_r29 + 16));    // 16(guest_SP/sp)
-      canonical->arg6  = *((UInt*) (gst->guest_r29 + 20));    // 20(sp)
+      canonical->arg5  = *((UInt*) (gst->guest_r29 + 16));    // 16(guest_SP)
+      canonical->arg6  = *((UInt*) (gst->guest_r29 + 20));    // 20(guest_SP)
+      canonical->arg7  = *((UInt*) (gst->guest_r29 + 24));    // 24(guest_SP)
       canonical->arg8 = 0;
    } else {
       // Fixme hack handle syscall()
@@ -1490,7 +1491,7 @@ void getSyscallArgLayout ( /*OUT*/SyscallArgLayout* layout )
    layout->o_arg4   = OFFSET_mips32_r7;
    layout->s_arg5   = sizeof(UWord) * 4;
    layout->s_arg6   = sizeof(UWord) * 5;
-   layout->uu_arg7  = -1; /* impossible value */
+   layout->s_arg7   = sizeof(UWord) * 6;
    layout->uu_arg8  = -1; /* impossible value */
 
 #elif defined(VGP_mips64_linux)
index 371578f3a597309e15b9f4203e5965d9b0df1836..c85236c14682513584da8cb9c07d636855860357 100644 (file)
@@ -518,6 +518,7 @@ DECL_TEMPLATE (mips_linux, sys_mmap);
 DECL_TEMPLATE (mips_linux, sys_mmap2);
 DECL_TEMPLATE (mips_linux, sys_stat64);
 DECL_TEMPLATE (mips_linux, sys_lstat64);
+DECL_TEMPLATE (mips_linux, sys_fadvise64);
 DECL_TEMPLATE (mips_linux, sys_fstatat64);
 DECL_TEMPLATE (mips_linux, sys_fstat64);
 DECL_TEMPLATE (mips_linux, sys_clone);
@@ -590,6 +591,22 @@ POST(sys_stat64)
   POST_MEM_WRITE (ARG2, sizeof (struct vki_stat64));
 }
 
+PRE(sys_fadvise64)
+{
+    PRINT("sys_fadvise64 ( %ld, %llu, %llu, %ld )",
+          SARG1, MERGE64(ARG3,ARG4), MERGE64(ARG5, ARG6), SARG7);
+
+   if (VG_(tdict).track_pre_reg_read) {
+      PRRSN;
+      PRA1("fadvise64", int, fd);
+      PRA3("fadvise64", vki_u32, MERGE64_FIRST(offset));
+      PRA4("fadvise64", vki_u32, MERGE64_SECOND(offset));
+      PRA5("fadvise64", vki_u32, MERGE64_FIRST(len));
+      PRA6("fadvise64", vki_u32, MERGE64_SECOND(len));
+      PRA7("fadvise64", int, advice);
+   }
+}
+
 PRE(sys_fstatat64)
 {
   // ARG4 =  int flags;  Flags are or'ed together, therefore writing them
@@ -1101,7 +1118,7 @@ static SyscallTableEntry syscall_main_table[] = {
    LINXY (__NR_epoll_wait,             sys_epoll_wait),              // 250
    //..
    LINX_ (__NR_set_tid_address,        sys_set_tid_address),         // 252
-   LINX_ (__NR_fadvise64,              sys_fadvise64),               // 254
+   PLAX_ (__NR_fadvise64,              sys_fadvise64),               // 254
    GENXY (__NR_statfs64,               sys_statfs64),                // 255
    GENXY (__NR_fstatfs64,              sys_fstatfs64),               // 256
    //..