Please enable Javascript to view the contents

mmap

 ·  ☕ 1 分钟
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
NAME
       mmap, munmap - map or unmap files or devices into memory 将文件或设备映射或取消映射到内存中

SYNOPSIS 概要
       #include <sys/mman.h>

       void *mmap(void *addr, size_t length, int prot, int flags,
                  int fd, off_t offset);
       int munmap(void *addr, size_t length);

       See NOTES for information on feature test macro requirements.

DESCRIPTION
       mmap()  creates  a  new mapping in the virtual address space of the calling process. 
       mmap()在调用进程的虚拟地址空间中创建一个新的映射
       The starting address for the new mapping is specified in addr.  
       The length argument specifies the length of the mapping.
       
       If addr is NULL, then the kernel chooses the address at which to create the mapping;
       this is the most portable method of creating a new mapping. 
       If addr  is  not  NULL,
       then  the kernel takes it as a hint about where to place the mapping; 
       on Linux, the mapping will be created at a nearby page boundary.
        The address of the new mapping is
       returned as the result of the call.

       The contents of a file mapping (as opposed to an anonymous mapping; 
       see MAP_ANONYMOUS below), are initialized using length bytes starting at offset offset  in  the  file
       (or other object) referred to by the file descriptor fd.
       offset must be a multiple of the page size as returned by sysconf(_SC_PAGE_SIZE).

       The  prot  argument describes the desired memory protection of the mapping (and must not conflict with the open mode of the file). 
        It is either PROT_NONE or the bitwise
       OR of one or more of the following flags:

SEE ALSO
       getpagesize(2),  memfd_create(2),  mincore(2),  mlock(2), mmap2(2), mprotect(2), mremap(2), msync(2), remap_file_pages(2), setrlimit(2), shmat(2), shm_open(3), shm_over‐
       view(7)

       The descriptions of the following files in proc(5): /proc/[pid]/maps, /proc/[pid]/map_files, and /proc/[pid]/smaps.