a technique whereby computer peripherals may be addressed as though they formed part of the main memory of the computer
Questions tagged [memory-mapping]
272 questions
49
votes
2 answers
How to access physical addresses from user space in Linux?
On a ARM based system running Linux, I have a device that's memory mapped to a physical address. From a user space program where all addresses are virtual, how can I read content from this address?

lang2
- 11,433
- 18
- 83
- 133
33
votes
8 answers
Binary search in a sorted (memory-mapped ?) file in Java
I am struggling to port a Perl program to Java, and learning Java as I go. A central component of the original program is a Perl module that does string prefix lookups in a +500 GB sorted text file using binary search
(essentially, "seek" to a byte…

sds
- 373
- 1
- 4
- 7
29
votes
4 answers
Is it legal for a pointer to point to a C++ register?
Let's say a C++ compiler compiled code for an architecture where CPU registers are not memory-mapped. And also let's say that same compiler reserved some pointer values for CPU registers.
For example, if the compiler, for whatever reason…

wolfofuniverse
- 441
- 4
- 8
24
votes
4 answers
How does copy_from_user from the Linux kernel work internally?
How exactly does the copy_from_user() function work internally? Does it use any buffers or is there any memory mapping done, considering the fact that kernel does have the privilege to access the user memory space?

Santi1986
- 463
- 1
- 4
- 10
22
votes
1 answer
Why data and stack segments are executable?
I have just noticed that my simple program has its data and stack segments executable.
I saw it in /proc/[pid]/maps, and simple code confirmed it.
For example:
; prog.asm
section .data
code: db 0xCC ;int3
section .text
global…

witosx
- 614
- 4
- 15
22
votes
1 answer
munmap() failure with ENOMEM with private anonymous mapping
I have recently discovered that Linux does not guarantee that memory allocated with mmap can be freed with munmap if this leads to situation when number of VMA (Virtual Memory Area) structures exceed vm.max_map_count. Manpage states this (almost)…
user1143634
15
votes
5 answers
"live C++ objects that live in memory mapped files"?
So I read this interview with John Carmack in Gamasutra, in which he talks about what he calls "live C++ objects that live in memory mapped files". Here are some quotes:
JC: Yeah. And I actually get multiple benefits out of it in that... The last…

Mart
- 1,278
- 12
- 12
14
votes
3 answers
What do the "---p" permissions in /proc/self/maps mean?
I understand the meaning of rwxps bits. r-xp is for .text. rw-p is for .data/.bss/heap/stack. What is the use of just ---p pages?
For example see this output of cat /proc/self/maps
00400000-0040b000 r-xp 00000000 08:03 827490 …

user209051
- 309
- 2
- 8
13
votes
5 answers
Why 16-bit address with 12-bit offset results in 4KB page size?
I'm reading the "Modern Operating System" book. And I'm confused about the "Page Size".
In the book, the author says,
The incoming 16-bit virtual address is
split into a 4-bit page number and
12-bit offset. With 4 bits for the
page number, we…

Mouhong Lin
- 4,402
- 4
- 33
- 48
13
votes
1 answer
How would I design and implement a non-blocking memory mapping module for node.js
There exists the mmap module for node.js: https://github.com/bnoordhuis/node-mmap/
As the author Ben Noordhuis notes, accesing mapped memory can block, which is why he does not recommend it anymore and discontinued it.
So I wonder how would I…

citykid
- 9,916
- 10
- 55
- 91
12
votes
1 answer
Who loads the BIOS and the memory map during boot-up
For the BIOS, Wikipedia states:
The address of the BIOS's memory is located such that it will be executed when the computer is first started up. A jump instruction then directs the processor to start executing code in the BIOS.
I know that BIOS…

Cygnus
- 3,222
- 9
- 35
- 65
11
votes
1 answer
Using memory maps with a service
I built an application that can also be ran as a service (using a -service) switch. This works perfectly with no issues when I'm running the service from a command prompt (I have something set up that lets me debug it from a console when not being…

Arvo Bowen
- 4,524
- 6
- 51
- 109
11
votes
1 answer
Mapping files bigger than 2GB with Java
It could be generally stated: how do you implement a method byte[] get(offset, length) for a memory-mapped file that is bigger than 2GB in Java.
With context:
I'm trying to read efficiently files that are bigger than 2GB with random i/o. Of course…

marcorossi
- 1,941
- 2
- 21
- 34
11
votes
2 answers
segments within a executable C program
I was reading about sections and segments. Seems you could list the mapping between sections and segments as below.
$ readelf -l test
Elf file type is EXEC (Executable file)
Entry point 0x8048330
There are 9 program headers, starting at offset…

John Eipe
- 10,922
- 24
- 72
- 114
10
votes
2 answers
Is mmap atomic?
Are mmap calls atomic in their effect?
That is, does a mapping change made by mmap appear atomically to other threads accessing the affected region?
As a litmus test, consider the case you do a mmap in a file of all zeros (from thread T1 which is…

BeeOnRope
- 60,350
- 16
- 207
- 386