]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Add support for the SG_IO ioctl.
authorTom Hughes <tom@compton.nu>
Thu, 26 Jun 2014 11:29:05 +0000 (11:29 +0000)
committerTom Hughes <tom@compton.nu>
Thu, 26 Jun 2014 11:29:05 +0000 (11:29 +0000)
Patch from Daniel Kamil Kozar via BZ#333817.

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

NEWS
coregrind/m_syswrap/syswrap-linux.c
docs/internals/3_9_BUGSTATUS.txt
include/vki/vki-linux.h

diff --git a/NEWS b/NEWS
index 08b4de26f5f924292aa40477b08fa373bf05408f..bdf4fb22dbea58f68ab44d2616a8093b4a58759b 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -154,6 +154,8 @@ where XXXXXX is the bug number as listed below.
 333428  ldr.w pc [rD, #imm] instruction leads to assertion
 333666  Recognize MPX instructions and bnd prefix.
 333788  Valgrind does not support the CDROM_DISC_STATUS ioctl (has patch)
+333817  Valgrind reports the memory areas written to by the SG_IO
+        ioctl as untouched
 334049  lzcnt fails silently (x86_32)
 334705  sendmsg and recvmsg should guard against bogus msghdr fields.
 334727  Build fails with -Werror=format-security
index ea9f9841dff11e67081b844488d9045d47012a7b..8ea032e6b8c184894e5206bc49a65a870646d43e 100644 (file)
@@ -5761,7 +5761,15 @@ PRE(sys_ioctl)
       PRE_MEM_READ( "ioctl(SG_SET_COMMAND_Q)", ARG3, sizeof(int) );
       break;
    case VKI_SG_IO:
-      PRE_MEM_WRITE( "ioctl(SG_IO)", ARG3, sizeof(vki_sg_io_hdr_t) );
+      PRE_MEM_READ( "ioctl(SG_IO)", ARG3, sizeof(vki_sg_io_hdr_t) );
+      {
+         vki_sg_io_hdr_t *sgio = (vki_sg_io_hdr_t*)ARG3;
+         PRE_MEM_READ( "ioctl(SG_IO)", (Addr)sgio->cmdp, sgio->cmd_len );
+         if ( sgio->dxfer_direction == VKI_SG_DXFER_TO_DEV ||
+              sgio->dxfer_direction == VKI_SG_DXFER_TO_FROM_DEV ) {
+            PRE_MEM_READ( "ioctl(SG_IO)", (Addr)sgio->dxferp, sgio->dxfer_len );
+         }
+      }
       break;
    case VKI_SG_GET_SCSI_ID:
       PRE_MEM_WRITE( "ioctl(SG_GET_SCSI_ID)", ARG3, sizeof(vki_sg_scsi_id_t) );
@@ -7189,7 +7197,17 @@ POST(sys_ioctl)
    case VKI_SG_SET_COMMAND_Q:
       break;
    case VKI_SG_IO:
-      POST_MEM_WRITE(ARG3, sizeof(vki_sg_io_hdr_t));
+      {
+         vki_sg_io_hdr_t *sgio = (vki_sg_io_hdr_t*)ARG3;
+         if ( sgio->sbp ) {
+            POST_MEM_WRITE( (Addr)sgio->sbp, sgio->sb_len_wr );
+         }
+         if ( sgio->dxfer_direction == VKI_SG_DXFER_FROM_DEV ||
+              sgio->dxfer_direction == VKI_SG_DXFER_TO_FROM_DEV ) {
+            int transferred = sgio->dxfer_len - sgio->resid;
+            POST_MEM_WRITE( (Addr)sgio->dxferp, transferred );
+         }
+      }
       break;
    case VKI_SG_GET_SCSI_ID:
       POST_MEM_WRITE(ARG3, sizeof(vki_sg_scsi_id_t));
index 449865d43852952717bfacc9724b97eba00c44c8..a0a4878b494fc20656aae4e1a452b36c6dd01e00 100644 (file)
@@ -57,8 +57,6 @@ For bugs reported before this time, see 3_8_BUGSTATUS.txt
 333434  In some weird corner case Valgrind cannot execute
         executable files symlinked by /proc/self/fd (related to 331311?)
 333051  handling hugepages (is largely broken)
-333817  Valgrind reports the memory areas written to by the SG_IO
-        ioctl as untouched
 334585  recvmmsg unhandled (+patch) (arm)
 
 === Debuginfo reader ===================================================
index c5d60e34b6b8c52fae776862964a46b4204e5eff..225da00ae8766eda84a51a5382677aaf52f00246 100644 (file)
@@ -1769,6 +1769,14 @@ typedef struct vki_sg_io_hdr
     unsigned int info;          /* [o] auxiliary information */
 } vki_sg_io_hdr_t;  /* 64 bytes long (on i386) */
 
+#define VKI_SG_DXFER_NONE -1        /* e.g. a SCSI Test Unit Ready command */
+#define VKI_SG_DXFER_TO_DEV -2      /* e.g. a SCSI WRITE command */
+#define VKI_SG_DXFER_FROM_DEV -3    /* e.g. a SCSI READ command */
+#define VKI_SG_DXFER_TO_FROM_DEV -4 /* treated like SG_DXFER_FROM_DEV with the
+                                  additional property than during indirect
+                                  IO the user buffer is copied into the
+                                  kernel buffers before the transfer */
+
 typedef struct vki_sg_scsi_id { /* used by SG_GET_SCSI_ID ioctl() */
     int host_no;        /* as in "scsi<n>" where 'n' is one of 0, 1, 2 etc */
     int channel;