From: Tom Hughes Date: Thu, 26 Jun 2014 11:29:05 +0000 (+0000) Subject: Add support for the SG_IO ioctl. X-Git-Tag: svn/VALGRIND_3_10_0~330 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5f4dbbeb75d1cd33268d0d8329d8a24f2bdf9941;p=thirdparty%2Fvalgrind.git Add support for the SG_IO ioctl. Patch from Daniel Kamil Kozar via BZ#333817. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@14107 --- diff --git a/NEWS b/NEWS index 08b4de26f5..bdf4fb22db 100644 --- 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 diff --git a/coregrind/m_syswrap/syswrap-linux.c b/coregrind/m_syswrap/syswrap-linux.c index ea9f9841df..8ea032e6b8 100644 --- a/coregrind/m_syswrap/syswrap-linux.c +++ b/coregrind/m_syswrap/syswrap-linux.c @@ -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)); diff --git a/docs/internals/3_9_BUGSTATUS.txt b/docs/internals/3_9_BUGSTATUS.txt index 449865d438..a0a4878b49 100644 --- a/docs/internals/3_9_BUGSTATUS.txt +++ b/docs/internals/3_9_BUGSTATUS.txt @@ -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 =================================================== diff --git a/include/vki/vki-linux.h b/include/vki/vki-linux.h index c5d60e34b6..225da00ae8 100644 --- a/include/vki/vki-linux.h +++ b/include/vki/vki-linux.h @@ -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" where 'n' is one of 0, 1, 2 etc */ int channel;