[Cbe-oss-dev] [PATCH] libspe2: prevent segfault when SPE memory is not available

D. Herrendoerfer d.herrendoerfer at herrendoerfer.name
Sat Nov 17 02:33:48 EST 2007


This patch prevents libspe2 to memcpy to a
non-mapped SPE.
The use of memcpy is a fallback when DMA over the
kernel interface is not possible. Although the DMA-ing
to a non-existing SPE is an error in itself it will
provoke a segfault in libspe2 instead of an error response.

Signed-off-by: D.Herrendoerfer <herrend at de.ibm.com>

Index: libspe2/spebase/dma.c
===================================================================
--- libspe2/spebase/dma.c	(revision 95)
+++ libspe2/spebase/dma.c	(working copy)
@@ -24,6 +24,7 @@
 #include <string.h>
 #include <unistd.h>
 
+#include <sys/mman.h>
 #include <sys/poll.h>
 
 #include "create.h"
@@ -102,6 +103,10 @@ static int spe_do_mfc_put(spe_context_pt
 	}
 	else {
 		/* the kernel does not support DMA, so just copy directly */
+		if (spectx->base_private->mem_mmap_base == MAP_FAILED) {
+			errno = EINVAL;
+			return -1;
+		}
 		memcpy(dst, spectx->base_private->mem_mmap_base + src, size);
 		return 0;
 	}
@@ -118,6 +123,10 @@ static int spe_do_mfc_get(spe_context_pt
 	}
 	else {
 		/* the kernel does not support DMA, so just copy directly */
+		if (spectx->base_private->mem_mmap_base == MAP_FAILED) {
+			errno = EINVAL;
+			return -1;
+		}
 		memcpy(spectx->base_private->mem_mmap_base + dst, src, size);
 		return 0;
 	}





More information about the cbe-oss-dev mailing list