From 2a8d225a89cbf9dbc157e559b5af3e5a8cd64eb2 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Wed, 10 May 2006 04:05:46 +0000 Subject: [PATCH] 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 --- src/video/fbcon/SDL_fbvideo.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/video/fbcon/SDL_fbvideo.c b/src/video/fbcon/SDL_fbvideo.c index bdbcfbd5d..2f2aac493 100644 --- a/src/video/fbcon/SDL_fbvideo.c +++ b/src/video/fbcon/SDL_fbvideo.c @@ -149,6 +149,19 @@ static void FB_SavePalette(_THIS, struct fb_fix_screeninfo *finfo, 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 @@ static int FB_VideoInit(_THIS, SDL_PixelFormat *vformat) 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 @@ static int FB_VideoInit(_THIS, SDL_PixelFormat *vformat) 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 */