MMAP fails in attempt to double buffer framebufer

2019-09-13 02:30发布

问题:

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?

回答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?



标签: linux mmap