Skip to content

Latest commit

 

History

History
22 lines (14 loc) · 1.67 KB

mmap.md

File metadata and controls

22 lines (14 loc) · 1.67 KB

mmap`

mmap is a system call in Unix and Unix-like systems used to map a range of virtual addresses to a file, device, or shared memory area. The term "mmap" stands for "memory map." Essentially, this system call allows a process to access a file as if it were memory.

Here are some of the main uses of mmap:

  1. Mapping Files to Memory:

    • mmap can be used to map a file to the process's memory. This allows the process to access the contents of the file directly in memory, without the need to read from or write to the file itself.
  2. Shared Memory:

    • mmap can also be used to create a shared memory area between processes. This allows multiple processes to share data in memory, facilitating communication between them.
  3. Anonymous Memory:

    • In addition to files, mmap can be used to create an anonymous memory area, which is not associated with any particular file. This is useful for allocating large blocks of memory on the process's heap.
  4. Direct Device Access:

    • mmap can also be used to map hardware devices to the process's memory, allowing direct access to these devices as if they were memory regions.
  5. Implementation of Protected Memory Regions:

    • mmap is often used to implement memory regions with specific access permissions, such as read-only memory regions or memory regions that can be executed as code.

In summary, mmap is a versatile system call that provides various functionalities related to memory mapping in Unix and Unix-like systems. It is widely used in low-level programming and operating systems for a variety of purposes, including efficient file I/O, inter-process communication, and access to hardware devices.