changeset 1798:49b4b8413734

Date: Tue, 9 May 2006 23:01:49 -0400 From: Mike Frysinger Subject: [SDL] [patch] fall back to using MAP_PRIVATE with mmap() in fbcon dri trying to use MAP_SHARED with mmap() on uClinux (aka non-mmu) hosts nowadays will simply fail since the kernel disallows it ... falling back to using MAP_PRIVATE on these hosts is acceptable ... as such, ive attached a patch for the fbcon driver that will fall back to using MAP_PRIVATE if mmap() with MAP_SHARED failed going by a grep of MAP_SHARED, the only other drivers that utilize this flag are video/wscons, video/ps2gs, and sound/dmaaudio ... i dont think these would appear on a non-mmu host so the patch i wrote is restricted to just SDL_fbvideo.c ... -mike
author Sam Lantinga <slouken@libsdl.org>
date Wed, 10 May 2006 04:05:46 +0000
parents 783b9409baa0
children 50e9cca3fe7b
files src/video/fbcon/SDL_fbvideo.c
diffstat 1 files changed, 15 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/video/fbcon/SDL_fbvideo.c	Tue May 09 16:10:04 2006 +0000
+++ b/src/video/fbcon/SDL_fbvideo.c	Wed May 10 04:05:46 2006 +0000
@@ -149,6 +149,19 @@
                                   struct fb_var_screeninfo *vinfo);
 static void FB_RestorePalette(_THIS);
 
+/* Small wrapper for mmap() so we can play nicely with no-mmu hosts
+ * (non-mmu hosts disallow the MAP_SHARED flag) */
+
+static void *do_mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset)
+{
+	void *ret;
+	ret = mmap(start, length, prot, flags, fd, offset);
+	if ( ret == (char *)-1 && (flags & MAP_SHARED) ) {
+		ret = mmap(start, length, prot,
+		           (flags & ~MAP_SHARED) | MAP_PRIVATE, fd, offset);
+	}
+}
+
 /* FB driver bootstrap functions */
 
 static int FB_Available(void)
@@ -535,7 +548,7 @@
 	mapped_offset = (((long)finfo.smem_start) -
 	                (((long)finfo.smem_start)&~(PAGE_SIZE-1)));
 	mapped_memlen = finfo.smem_len+mapped_offset;
-	mapped_mem = mmap(NULL, mapped_memlen,
+	mapped_mem = do_mmap(NULL, mapped_memlen,
 	                  PROT_READ|PROT_WRITE, MAP_SHARED, console_fd, 0);
 	if ( mapped_mem == (char *)-1 ) {
 		SDL_SetError("Unable to memory map the video hardware");
@@ -579,7 +592,7 @@
 	ioctl(console_fd, FBIOPUT_VSCREENINFO, &vinfo);
 	if ( finfo.accel && finfo.mmio_len ) {
 		mapped_iolen = finfo.mmio_len;
-		mapped_io = mmap(NULL, mapped_iolen, PROT_READ|PROT_WRITE,
+		mapped_io = do_mmap(NULL, mapped_iolen, PROT_READ|PROT_WRITE,
 		                 MAP_SHARED, console_fd, mapped_memlen);
 		if ( mapped_io == (char *)-1 ) {
 			/* Hmm, failed to memory map I/O registers */