initial import
[patches.git] / libsdl-fbcon-no-mmu-mmap.patch
CommitLineData
5e993f12 1Index: src/video/fbcon/SDL_fbvideo.c
2===================================================================
3--- src/video/fbcon/SDL_fbvideo.c (revision 2363)
4+++ src/video/fbcon/SDL_fbvideo.c (working copy)
5@@ -149,6 +149,19 @@ static void FB_SavePalette(_THIS, struct
6 struct fb_var_screeninfo *vinfo);
7 static void FB_RestorePalette(_THIS);
8
9+/* Small wrapper for mmap() so we can play nicely with no-mmu hosts
10+ * (non-mmu hosts disallow the MAP_SHARED flag) */
11+
12+static void *do_mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset)
13+{
14+ void *ret;
15+ ret = mmap(start, length, prot, flags, fd, offset);
16+ if ( ret == (char *)-1 && flags != (flags & ~MAP_SHARED) ) {
17+ ret = mmap(start, length, prot,
18+ (flags & ~MAP_SHARED) | MAP_PRIVATE, fd, offset);
19+ }
20+}
21+
22 /* FB driver bootstrap functions */
23
24 static int FB_Available(void)
25@@ -535,7 +548,7 @@ static int FB_VideoInit(_THIS, SDL_Pixel
26 mapped_offset = (((long)finfo.smem_start) -
27 (((long)finfo.smem_start)&~(PAGE_SIZE-1)));
28 mapped_memlen = finfo.smem_len+mapped_offset;
29- mapped_mem = mmap(NULL, mapped_memlen,
30+ mapped_mem = do_mmap(NULL, mapped_memlen,
31 PROT_READ|PROT_WRITE, MAP_SHARED, console_fd, 0);
32 if ( mapped_mem == (char *)-1 ) {
33 SDL_SetError("Unable to memory map the video hardware");
34@@ -579,7 +592,7 @@ static int FB_VideoInit(_THIS, SDL_Pixel
35 ioctl(console_fd, FBIOPUT_VSCREENINFO, &vinfo);
36 if ( finfo.accel && finfo.mmio_len ) {
37 mapped_iolen = finfo.mmio_len;
38- mapped_io = mmap(NULL, mapped_iolen, PROT_READ|PROT_WRITE,
39+ mapped_io = do_mmap(NULL, mapped_iolen, PROT_READ|PROT_WRITE,
40 MAP_SHARED, console_fd, mapped_memlen);
41 if ( mapped_io == (char *)-1 ) {
42 /* Hmm, failed to memory map I/O registers */