|
From: Haakon R. <haa...@fy...> - 2007-05-17 11:33:44
|
When calling ioctl() with only two arguments (perfectly legal
according to the function prototype and the semantics of many
ioctl functions), valgrind complains about uninitialized bytes
in the third argument. E.g.,
/* --------- ioctl-test.c --------- */
#include <linux/fs.h>
#include <sys/ioctl.h>
int main(void)
{
return ioctl(1, BLKFLSBUF);
}
/* -------------------------------- */
$ gcc ioctl-test.c
$ valgrind ./a.out 2>&1 | grep -C1 ': ioctl'
==31617== Syscall param ioctl(arg) contains uninitialised byte(s)
==31617== at 0x40EF3A4: ioctl (in /lib/tls/libc-2.3.6.so)
==31617== by 0x4042E13: (below main) (in /lib/tls/libc-2.3.6.so)
This is particularly annoying when debugging applications that use
ALSA's libasound, since it is littered with two-argument ioctls.
I looked at valgrind's sys_ioctl in coregrind/m_syswrap/syswrap-generic.c,
and the easiest solution seems to be to make the two-argument ioctls
a special case. Here is a patch for the latest revision in svn that
includes support for the BLKFLSBUF ioctl, and moves the appropriate
ALSA ioctls into the two-argument section:
--- valgrind/coregrind/m_syswrap/syswrap-generic.c.orig 2007-05-17 13:26:00.000000000 +0200
+++ valgrind/coregrind/m_syswrap/syswrap-generic.c 2007-05-17 13:26:51.000000000 +0200
@@ -3160,6 +3160,26 @@
PRE(sys_ioctl)
{
*flags |= SfMayBlock;
+
+ /* Special case for ioctls that only uses the first two arguments. */
+ switch (ARG2 /* request */) {
+ case VKI_BLKFLSBUF:
+ /* linux/soundcard interface (ALSA) */
+ case VKI_SNDRV_PCM_IOCTL_HW_FREE:
+ case VKI_SNDRV_PCM_IOCTL_HWSYNC:
+ case VKI_SNDRV_PCM_IOCTL_PREPARE:
+ case VKI_SNDRV_PCM_IOCTL_RESET:
+ case VKI_SNDRV_PCM_IOCTL_START:
+ case VKI_SNDRV_PCM_IOCTL_DROP:
+ case VKI_SNDRV_PCM_IOCTL_DRAIN:
+ case VKI_SNDRV_PCM_IOCTL_RESUME:
+ case VKI_SNDRV_PCM_IOCTL_XRUN:
+ case VKI_SNDRV_PCM_IOCTL_UNLINK:
+ PRINT("sys_ioctl ( %d, 0x%x )",ARG1,ARG2);
+ PRE_REG_READ2(long, "ioctl", unsigned int, fd, unsigned int, request);
+ return;
+ }
+
PRINT("sys_ioctl ( %d, 0x%x, %p )",ARG1,ARG2,ARG3);
PRE_REG_READ3(long, "ioctl",
unsigned int, fd, unsigned int, request, unsigned long, arg);
@@ -3555,16 +3575,6 @@
break;
/* linux/soundcard interface (ALSA) */
- case VKI_SNDRV_PCM_IOCTL_HW_FREE:
- case VKI_SNDRV_PCM_IOCTL_HWSYNC:
- case VKI_SNDRV_PCM_IOCTL_PREPARE:
- case VKI_SNDRV_PCM_IOCTL_RESET:
- case VKI_SNDRV_PCM_IOCTL_START:
- case VKI_SNDRV_PCM_IOCTL_DROP:
- case VKI_SNDRV_PCM_IOCTL_DRAIN:
- case VKI_SNDRV_PCM_IOCTL_RESUME:
- case VKI_SNDRV_PCM_IOCTL_XRUN:
- case VKI_SNDRV_PCM_IOCTL_UNLINK:
case VKI_SNDRV_TIMER_IOCTL_START:
case VKI_SNDRV_TIMER_IOCTL_STOP:
case VKI_SNDRV_TIMER_IOCTL_CONTINUE:
@@ -4483,6 +4493,8 @@
case VKI_BLKGETSIZE:
POST_MEM_WRITE(ARG3, sizeof(unsigned long));
break;
+ case VKI_BLKFLSBUF:
+ break;
case VKI_BLKRASET:
break;
case VKI_BLKRAGET:
--- valgrind/include/vki/vki-linux.h.orig 2007-05-17 12:57:17.000000000 +0200
+++ valgrind/include/vki/vki-linux.h 2007-05-17 13:26:51.000000000 +0200
@@ -1582,6 +1582,7 @@
#define VKI_BLKROSET _VKI_IO(0x12,93) /* set device read-only (0 = read-write) */
#define VKI_BLKROGET _VKI_IO(0x12,94) /* get read-only status (0 = read_write) */
#define VKI_BLKGETSIZE _VKI_IO(0x12,96) /* return device size /512 (long *arg) */
+#define VKI_BLKFLSBUF _VKI_IO(0x12,97) /* flush buffer cache */
#define VKI_BLKRASET _VKI_IO(0x12,98) /* set read ahead for block device */
#define VKI_BLKRAGET _VKI_IO(0x12,99) /* get current read ahead setting */
#define VKI_BLKFRASET _VKI_IO(0x12,100)/* set filesystem (mm/filemap.c) read-ahead */
Please let me know if there are problems. I'd really like to push a
solution for this annoying problem upstream.
--
Haakon
|