why we can mmap to a file but exceed the file size?
问题 For example. fd = ::open ("/test.txt", O_RDONLY, 0); struct stat buf; fstat(fd, &buf); char* addr = (char*)::mmap(NULL, buf.st_size + 10, PROT_READ, MAP_PRIVATE | MAP_POPULATE, fd, 0); Notice that I mapped + 10 here. But it still works? Why system does NOT apply any check? Is it dangerous? Thanks 回答1: Signature of mmap is: void *mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset); To quote Michael Kerrisk: The length argument specifies the size of the mapping in bytes.