Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

49. Memory Mappings > Creating a Mapping: mmap()

Creating a Mapping: mmap()

The mmap() system call creates a new mapping in the calling process’s virtual address space.

#include <sys/mman.h>

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

Note

Returns starting address of mapping on success, or MAP_FAILED on error

The addr argument indicates the virtual address at which the mapping is to be located. If we specify addr as NULL, the kernel chooses a suitable address for the mapping. This is the preferred way of creating a mapping. Alternatively, we can specify a non-NULL value in addr, which the kernel takes as a hint about the address at which the mapping should be placed. In practice, the kernel will at the very least round the address to a nearby page boundary. In either case, the kernel will choose an address that doesn’t conflict with any existing mapping. (If the value MAP_FIXED is included in flags, then addr must be page-aligned. We describe this flag in The MAP_FIXED Flag.)


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint