LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This 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


Reply
  Search this Thread
Old 10-09-2018, 09:13 PM   #1
marler8997
LQ Newbie
 
Registered: Sep 2018
Posts: 5

Rep: Reputation: Disabled
64-bit mmap in 32-bit userspace


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.
 
Old 10-10-2018, 08:27 AM   #2
lazydog
Senior Member
 
Registered: Dec 2003
Location: The Key Stone State
Distribution: CentOS Sabayon and now Gentoo
Posts: 1,249
Blog Entries: 3

Rep: Reputation: 194Reputation: 194
While 32 bit can run in a 64 bit environment the opposite does not work.
 
Old 10-10-2018, 10:59 AM   #3
marler8997
LQ Newbie
 
Registered: Sep 2018
Posts: 5

Original Poster
Rep: Reputation: Disabled
@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.
 
Old 10-11-2018, 05:51 PM   #4
marler8997
LQ Newbie
 
Registered: Sep 2018
Posts: 5

Original Poster
Rep: Reputation: Disabled
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.
 
2 members found this post helpful.
  


Reply

Tags
32bit, 64bit, drm, mmap



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
•Red Hat Enterprise Linux 5 (UL6+) (32-bit. 64 bit supported in 32-bit mode) download oylf1985 Linux - Newbie 13 04-08-2019 12:55 PM
VirtualBox starting as 32 bit on a 64 bit device which doesn't acknowledge the existence of a 32 bit vbox (installed 64bit) QuantumChaos Linux - Virtualization and Cloud 3 02-23-2017 06:49 AM
64 bit Wine and 64 bit Windows applications. SketchUp 2015/16 64 bit install fails. bamunds Slackware 2 03-23-2016 08:42 PM
Can't find 32 bit libs to run 32 bit prog on 64 bit CentOS homer_3 Linux - Distributions 2 09-30-2013 08:45 PM
64-bit kernel, 32-bit userspace? piete Slackware 21 06-18-2009 04:54 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 06:41 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration