Date: Tue, 9 May 2006 23:01:49 -0400
authorSam Lantinga <slouken@libsdl.org>
Wed, 10 May 2006 04:05:46 +0000
changeset 179849b4b8413734
parent 1797 783b9409baa0
child 1799 50e9cca3fe7b
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
     1.1 --- a/src/video/fbcon/SDL_fbvideo.c	Tue May 09 16:10:04 2006 +0000
     1.2 +++ b/src/video/fbcon/SDL_fbvideo.c	Wed May 10 04:05:46 2006 +0000
     1.3 @@ -149,6 +149,19 @@
     1.4                                    struct fb_var_screeninfo *vinfo);
     1.5  static void FB_RestorePalette(_THIS);
     1.6  
     1.7 +/* Small wrapper for mmap() so we can play nicely with no-mmu hosts
     1.8 + * (non-mmu hosts disallow the MAP_SHARED flag) */
     1.9 +
    1.10 +static void *do_mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset)
    1.11 +{
    1.12 +	void *ret;
    1.13 +	ret = mmap(start, length, prot, flags, fd, offset);
    1.14 +	if ( ret == (char *)-1 && (flags & MAP_SHARED) ) {
    1.15 +		ret = mmap(start, length, prot,
    1.16 +		           (flags & ~MAP_SHARED) | MAP_PRIVATE, fd, offset);
    1.17 +	}
    1.18 +}
    1.19 +
    1.20  /* FB driver bootstrap functions */
    1.21  
    1.22  static int FB_Available(void)
    1.23 @@ -535,7 +548,7 @@
    1.24  	mapped_offset = (((long)finfo.smem_start) -
    1.25  	                (((long)finfo.smem_start)&~(PAGE_SIZE-1)));
    1.26  	mapped_memlen = finfo.smem_len+mapped_offset;
    1.27 -	mapped_mem = mmap(NULL, mapped_memlen,
    1.28 +	mapped_mem = do_mmap(NULL, mapped_memlen,
    1.29  	                  PROT_READ|PROT_WRITE, MAP_SHARED, console_fd, 0);
    1.30  	if ( mapped_mem == (char *)-1 ) {
    1.31  		SDL_SetError("Unable to memory map the video hardware");
    1.32 @@ -579,7 +592,7 @@
    1.33  	ioctl(console_fd, FBIOPUT_VSCREENINFO, &vinfo);
    1.34  	if ( finfo.accel && finfo.mmio_len ) {
    1.35  		mapped_iolen = finfo.mmio_len;
    1.36 -		mapped_io = mmap(NULL, mapped_iolen, PROT_READ|PROT_WRITE,
    1.37 +		mapped_io = do_mmap(NULL, mapped_iolen, PROT_READ|PROT_WRITE,
    1.38  		                 MAP_SHARED, console_fd, mapped_memlen);
    1.39  		if ( mapped_io == (char *)-1 ) {
    1.40  			/* Hmm, failed to memory map I/O registers */