Patched fbcon to compile on newer Linux kernels that don't #define PAGE_SIZE, SDL-1.2
authorRyan C. Gordon <icculus@icculus.org>
Thu, 15 Feb 2007 23:50:45 +0000
branchSDL-1.2
changeset 39178a3a0f1179f3
parent 3916 16f7767f9580
child 3918 f16c15f3bc2b
Patched fbcon to compile on newer Linux kernels that don't #define PAGE_SIZE,
since a memory page's size may vary on various architectures and kernel
configurations.

Will use getpagesize() if it exists, the PAGE_SIZE #define from older kernels
if that doesn't, and #error out if that's not there either...but it's
probably 4096 in that case. We may revisit this.

Fixes Bugzilla #392.
configure.in
include/SDL_config.h.in
src/video/fbcon/SDL_fbvideo.c
     1.1 --- a/configure.in	Thu Feb 15 11:06:22 2007 +0000
     1.2 +++ b/configure.in	Thu Feb 15 23:50:45 2007 +0000
     1.3 @@ -1125,6 +1125,7 @@
     1.4          ])
     1.5          AC_MSG_RESULT($video_fbcon)
     1.6          if test x$video_fbcon = xyes; then
     1.7 +            AC_CHECK_FUNCS(getpagesize)
     1.8              AC_DEFINE(SDL_VIDEO_DRIVER_FBCON)
     1.9              SOURCES="$SOURCES $srcdir/src/video/fbcon/*.c"
    1.10              have_video=yes
     2.1 --- a/include/SDL_config.h.in	Thu Feb 15 11:06:22 2007 +0000
     2.2 +++ b/include/SDL_config.h.in	Thu Feb 15 23:50:45 2007 +0000
     2.3 @@ -130,6 +130,7 @@
     2.4  #undef HAVE_NANOSLEEP
     2.5  #undef HAVE_CLOCK_GETTIME
     2.6  #undef HAVE_DLVSYM
     2.7 +#undef HAVE_GETPAGESIZE
     2.8  
     2.9  #else
    2.10  /* We may need some replacement for stdarg.h here */
     3.1 --- a/src/video/fbcon/SDL_fbvideo.c	Thu Feb 15 11:06:22 2007 +0000
     3.2 +++ b/src/video/fbcon/SDL_fbvideo.c	Thu Feb 15 23:50:45 2007 +0000
     3.3 @@ -149,6 +149,19 @@
     3.4                                    struct fb_var_screeninfo *vinfo);
     3.5  static void FB_RestorePalette(_THIS);
     3.6  
     3.7 +static int SDL_getpagesize(void)
     3.8 +{
     3.9 +#ifdef HAVE_GETPAGESIZE
    3.10 +	return getpagesize();
    3.11 +#elif defined(PAGE_SIZE)
    3.12 +	return PAGE_SIZE;
    3.13 +#else
    3.14 +#error Can not determine system page size.
    3.15 +	return 4096;  /* this is what it USED to be in Linux... */
    3.16 +#endif
    3.17 +}
    3.18 +
    3.19 +
    3.20  /* Small wrapper for mmap() so we can play nicely with no-mmu hosts
    3.21   * (non-mmu hosts disallow the MAP_SHARED flag) */
    3.22  
    3.23 @@ -466,6 +479,7 @@
    3.24  
    3.25  static int FB_VideoInit(_THIS, SDL_PixelFormat *vformat)
    3.26  {
    3.27 +	const int pagesize = SDL_getpagesize();
    3.28  	struct fb_fix_screeninfo finfo;
    3.29  	struct fb_var_screeninfo vinfo;
    3.30  	int i, j;
    3.31 @@ -547,7 +561,7 @@
    3.32  
    3.33  	/* Memory map the device, compensating for buggy PPC mmap() */
    3.34  	mapped_offset = (((long)finfo.smem_start) -
    3.35 -	                (((long)finfo.smem_start)&~(PAGE_SIZE-1)));
    3.36 +	                (((long)finfo.smem_start)&~(pagesize-1)));
    3.37  	mapped_memlen = finfo.smem_len+mapped_offset;
    3.38  	mapped_mem = do_mmap(NULL, mapped_memlen,
    3.39  	                  PROT_READ|PROT_WRITE, MAP_SHARED, console_fd, 0);