0

I am trying to implement a double buffer using ioctl(fd, FBIOPAN_DISPLAY... my single buffer code works fine

screensize = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8;

fbp = (char*)mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, fbfd, 0);

when I try to increase the "length parameter" by using screensize*2, the mmap fails with EINVAL. I think it doesn't like my length parameter.

The screen size for a single buffer is 6,220,800 and for the double buffer is 12,441600. This is an embedded system but it has 1 Gig of RAM.

The length parameter is size_t which on this system is only 4 bytes which would make me think that the max size I could use would be 4 Meg, yet 6 Meg works fine so I think I am missing something really simple. Is there a way to mmap a buffer larger than size_t?

RTC
  • 1
  • 2
  • what do you mean 'increase'. are you saying remapping? – DAG Oct 11 '16 at 03:19
  • by increase, I mean that I recompile and run with that second param (length) = screensize*2. It fails with the EINVAL errno – RTC Oct 11 '16 at 19:56
  • have you tried just create a const var as double_screensize = screensize*2 and then pass it to mmap? – DAG Oct 12 '16 at 04:41

1 Answers1

1

The man page says that length (the 2nd parameter) is of type size_t, so I don't think you are safe to pass a larger type.

I would suggest you to just map the first part, and then remap the second part as shown in this SO Q&A.

Regarding the EINVAL: Following is stated in the man page:

EINVAL We don't like addr, length, or offset (e.g., they are too large, or not aligned on a page boundary).

EINVAL (since Linux 2.6.12) length was 0.

EINVAL flags contained neither MAP_PRIVATE or MAP_SHARED, or contained both of these values.

Are you sure you are page alligned?

Community
  • 1
  • 1
Markus Weninger
  • 11,931
  • 7
  • 64
  • 137
  • Which param needs to be page-aligned? Since the first and last params are 0, I figured I was but do I need to modify my length value to be cleanly divisible by a page size? – RTC Oct 11 '16 at 19:58
  • if using screensize is successful and therefore page-aligned. I would think that screensize*2 would also be page-aligned if needed – RTC Oct 11 '16 at 20:02
  • Okay, that's correct. But what comes to my mind: If `screensize * 2` is larger than `size_t`, then an arithmetic overflow occurs, which may result in undefined behaviour. But I also don't think that this is the problem, because 12,441,600 is far more smaller than 4,294,967,295 (assuming size_t is uint). – Markus Weninger Oct 12 '16 at 07:33