Mmap /Dev/Fb0 Fails with "Invalid Argument"

android mmap failed: invalid argument (errno 22)

prmatta,

Error code 22 is EINVAL.

From the mmap() documentation that tells you...

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

Perhaps you didn't page align your memory?

Linux DRM ( DRI ) Cannot Screen Scrape /dev/fb0 as before with FBDEV

finfo.line_length gives the size of the actual physical scan line in bytes. It is not necessarily the same as screen width multiplied by pixel size, as scan lines may be padded.

However the QImage constructor you are using assumes no padding.

If xoffset is zero, it should be possible to construct a QImage directly from the framebuffer data using a constructor with the bytesPerLine argument. Otherwise there are two options:

  • allocate a separate buffer and copy only the visible portion of each scanline to it
  • create an image from the entire buffer (including the padding) and then crop it

Calling mmap on dumbbuffer with Linux’ Direct Rendering Manager in Rust fails while working in C

So I used strace as recommended by Shepmaster, and found the problem: the offset field of the CMapDumb structure should have been a u64 instead of an u32 (I have been too quick copying from the C original). The actual offset returned by the DRM_IOCTL_MODE_MAP_DUMB IOCTL is 33 bits long, and I was losing the most significant one. It now works fine.



Related Topics



Leave a reply



Submit