Skip to contentSkip to conversation

Alsa timer: ioctl problem/bug

DISCUSSION Jonathan Woithe 2 participants 2 messages Jun 14, 2005 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

Hi all

I think I have discovered a problem with the alsa timer - in particular, the alsalib snd_timer_stop() call. In short, it doesn't work - a running timer isn't stopped and the call often (but not always) returns an error of -14 (-EFAULT).

The reason for this turns out to be the definition of the SNDRV_TIMER_IOCTL_STOP ioctl request in asound.h from alsa-driver. This is currently defined as

  #define SNDRV_TIMER_IOCTL_STOP _IO('T',0x21)

which resolves to 0x5421. The problem is that this is exactly the same as the FIONBIO request used by the vfs kernel layer to control non-blocking behaviour. When a program calls alsalib's snd_timer_stop(), the SNDRV_TIMER_IOCTL_STOP ioctl is invoked. However, the alsa-driver never sees this because the vfs layer sees it as a FIONBIO request first and tries to set the file's non-blocking behaviour according to the parameter FIONBIO expects. Of course in the case of a SNDRV_TIMER_IOCTL_STOP request we don't pass any parameter, so the vfs FIONBIO handler accesses whatever happens to be on the stack at the time. Sometimes it's a valid address and sometimes it's not. When it is, the non-blocking behaviour of the alsa timer handler is set to whatever the random stack data happens to indicate; when it's not we get the EFAULT return from snd_timer_stop(). In both cases the alsa timer is not stopped.

The fix is conceptually simple: just change the magic 'T' in the SNDRV_TIMER_IOCTL_STOP define in alsa-driver's asound.h to something else to avoid the clash (and note that the SNDRV_TIMER_IOCTL_STOP_OLD define in alsa-lib's timer/timer_hw.c also needs to be updated to match). As a proof concept I tried 'U' and I was then able to stop the timer successfully.

However, I don't know what the ALSA developers want to do here. Do we just change the SNDRV_TIMER_IOCTL_STOP define, or should all SNDRV_TIMER_IOCTL_* defines be changed to keep them consistent? My own thought is to change all SNDRV_TIMER_IOCTL_* defines to avoid clashes with the "standard" ioctl requests defined in asm/ioctls.h to remove the chances of this kind of thing cropping up again in future.

Regards
jonathan

-------------------------------------------------------
This SF.Net email is sponsored by: NEC IT Guy Games. How far can you shotput a projector? How fast can you ride your desk chair down the office luge track? If you want to score the big prize, get to know the little guy. Play to win an NEC 61" plasma display: http://www.necitguy.com/?r=20

#2 lore raw

At Tue, 14 Jun 2005 10:50:05 +0930 (CST),

Quoted 34 lines · Jonathan Woithe

Hi all

I think I have discovered a problem with the alsa timer - in particular, the alsalib snd_timer_stop() call. In short, it doesn't work - a running timer isn't stopped and the call often (but not always) returns an error of -14 (-EFAULT).

The reason for this turns out to be the definition of the SNDRV_TIMER_IOCTL_STOP ioctl request in asound.h from alsa-driver. This is currently defined as

  #define SNDRV_TIMER_IOCTL_STOP _IO('T',0x21)

which resolves to 0x5421. The problem is that this is exactly the same as the FIONBIO request used by the vfs kernel layer to control non-blocking behaviour. When a program calls alsalib's snd_timer_stop(), the SNDRV_TIMER_IOCTL_STOP ioctl is invoked. However, the alsa-driver never sees this because the vfs layer sees it as a FIONBIO request first and tries to set the file's non-blocking behaviour according to the parameter FIONBIO expects. Of course in the case of a SNDRV_TIMER_IOCTL_STOP request we don't pass any parameter, so the vfs FIONBIO handler accesses whatever happens to be on the stack at the time. Sometimes it's a valid address and sometimes it's not. When it is, the non-blocking behaviour of the alsa timer handler is set to whatever the random stack data happens to indicate; when it's not we get the EFAULT return from snd_timer_stop(). In both cases the alsa timer is not stopped.

The fix is conceptually simple: just change the magic 'T' in the SNDRV_TIMER_IOCTL_STOP define in alsa-driver's asound.h to something else to avoid the clash (and note that the SNDRV_TIMER_IOCTL_STOP_OLD define in alsa-lib's timer/timer_hw.c also needs to be updated to match). As a proof concept I tried 'U' and I was then able to stop the timer successfully.

Quoted 6 lines

However, I don't know what the ALSA developers want to do here. Do we just change the SNDRV_TIMER_IOCTL_STOP define, or should all SNDRV_TIMER_IOCTL_* defines be changed to keep them consistent? My own thought is to change all SNDRV_TIMER_IOCTL_* defines to avoid clashes with the "standard" ioctl requests defined in asm/ioctls.h to remove the chances of this kind of thing cropping up again in future.

It's already fixed in ALSA 1.0.9 release.
The releveant ioctl numbers were changed.

Takashi

-------------------------------------------------------
This SF.Net email is sponsored by: NEC IT Guy Games. How far can you shotput a projector? How fast can you ride your desk chair down the office luge track? If you want to score the big prize, get to know the little guy. Play to win an NEC 61" plasma display: http://www.necitguy.com/?r=20