[alsa-devel] Assertion failure in alsa-lib crashing applications (snd_pcm_area_copy: Assertion `dst < src || dst >= src + bytes' failed)

Takashi Iwai tiwai at suse.de
Fri Jul 1 12:26:11 CEST 2016


On Fri, 01 Jul 2016 12:19:08 +0200,
Baptiste Jonglez wrote:
> 
> On Wed, Jun 29, 2016 at 06:02:58PM +0200, Takashi Iwai wrote:
> > Now I reread the code again, and I guess it's really the racy
> > accesses.  Basically you can't call alsa-lib functions concurrently.
> > For example, calling snd_pcm_avail_update() from multiple threads
> > concurrently may lead to such an error.  Internally it copies /
> > converts the content (e.g. for softvol plugin), and this would
> > conflict when called in parallel.
> > 
> > You can try a hackish patch below to see whether it emits any
> > messages.  It has no mutex, so the code itself is racy, but it should
> > be enough just as a check.
> > 
> > Meanwhile, the crash itself might be avoided by disabling
> > "pcm->mmap_shadow = 1" line in pcm_softvol.c.  Then it'll be copied to
> > the external buffer.
> 
> Thank you Takashi, I will give it a try!

To be noted: clearing mmap_show won't "fix" but merely avoid the
crash.  You may still get garbled sounds when such a race happens.

The best would be to fix the race.  But it's often difficult to fix
due to the design of apps.

I created an experimental version of alsa-lib to make PCM thread-safe
by forcibly applying pthread mutex.  The code is found in
thread-safety branch in the git tree below:
  https://github.com/tiwai/alsa-lib

You need to build with --enable-thread-safety configure option with
this code.  I haven't tested whether it really avoids the race yet.
I'd need to write a test case.  So, take it as a proof-of-concept, so
far.


Takashi


More information about the Alsa-devel mailing list