Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
We've got a 64-bit arm kernel and pretty much all of our userspace is 32-bit. The problem is that I'm getting a 64-bit address when I create a DRM DUMB framebuffer, so when I pass that to mmap (mmap2 system call to be specific) it gets truncated to 32 bits and I get an "invalid argument (22)" error. Some solutions that came to my mind:
1. Modify the DRM driver to only allocate buffers below the 4GB boundary
2. Create a new kernel interface to call the 64-bit version of mmap, there's many ways to do this (i.e. new system call, a character driver, a sys/proc file, an ioctl....and many more I'm sure).
But my gut tell me that there's probably already a solution to this that I'm not aware of. Having to mmap a 64-bit address/offset in a 32-bit process seems like it would happen somewhat often. Is anyone able to shed some light on this? Thanks.
@lazydog...I'm not sure you completely grokked the question. I'm running a 32-bit userspace process on a 64-bit system with a 64-bit kernel. The problem is that the DRM framebuffer I get back from the kernel is above 4 GB (requires more than 32-bits) and that value is supposed to be passed as the "pgoffset" to mmap, but since the userspace process is only 32-bits, the value I get back from DRM is truncated. The question is, how do you perform the mmap of a 64-bit address/offset in a 32-bit process.
I answered my own question today. TLDR; I added "-D_FILE_OFFSET_BITS=64" to my compiler command line.
By defining this value, glibc redirected all calls to mmap to another function, mmap64, which ends up being able to support up to 44 bit offsets. It shifts the value by 12 bits and passes it to the "mmap2" system call which is actualy a page index rather than a full offset.
I was able to discover this because I noticed the Weston compositor was not having the same problem with its pixman backend which was using DRM the same way I was by mapping in a "dumb" framebuffer with mmap. I debugged the assembly on an embedded arm device and realized it was calling `mmap64` rather than `mmap`, and was passing the value of the pgoffset in a 64-bit register, D16 instead of the normal `r6` register. I looked through all it's command line parameters (I'm building it in yocto) and also noticed it was including a special header file, "config.h" before any other header file, and that's where I found:
#define _FILE_OFFSET_BITS 64
I added this define to my program and now off_t is 64 bits instead of 32 bits, and a call to mmap is redirected to mmap64 which solved the problem.
Also note that just calling mmap64 expclitily did not work. You need to define _FILE_OFFSET_BITS to be 64, probably before you include the "sys/mman.h" header file.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.