Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

When I try to study some piece of code that deals with FPGA, I came across with munmap, mmap.

I go through the manual provided here. I am still not understanding the purpose of this function. What exactly this does?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
917 views
Welcome To Ask or Share your Answers For Others

1 Answer

mmap() is a system call, which helps in memory-mapped I/O operations. It allocates a memory region and maps that into the calling process virtual address space so as to enable the application to access the memory.

mmap() returns a pointer to the mapped area which can be used to access the memory.

Similarly, munmap() removes the mapping so no further access to the allocated memory remains legal.

These are lower level calls, behaviourally similar to what is offered by memory allocator functions like malloc() / free() on a higher level. However, this system call allow one to have fine grained control over the allocated region behaviour, like,

  • memory protection of the mapping (read, write, execute permission)
  • (approximate) location of the mapping (see MAP_FIXED flag)
  • the initial content of the mapped area (see MAP_UNINITIALIZED flag)

etc.

You can also refer to the wikipedia article if you think alternate wordings can help you.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...