diff options
Diffstat (limited to 'man2/mmap.2')
-rw-r--r-- | man2/mmap.2 | 146 |
1 files changed, 73 insertions, 73 deletions
diff --git a/man2/mmap.2 b/man2/mmap.2 index c847a77ac..3d9a887e2 100644 --- a/man2/mmap.2 +++ b/man2/mmap.2 @@ -18,7 +18,7 @@ .\" 2007-07-10, mtk, Added an example program. .\" 2008-11-18, mtk, document MAP_STACK .\" -.TH mmap 2 2023-02-05 "Linux man-pages 6.03" +.TH mmap 2 2023-07-20 "Linux man-pages 6.05.01" .SH NAME mmap, munmap \- map or unmap files or devices into memory .SH LIBRARY @@ -650,56 +650,20 @@ of the page size, see NOTES. .SH ATTRIBUTES For an explanation of the terms used in this section, see .BR attributes (7). -.ad l -.nh .TS allbox; lbx lb lb l l l. Interface Attribute Value T{ +.na +.nh .BR mmap (), .BR munmap () T} Thread safety MT-Safe .TE -.hy -.ad .sp 1 -.SH STANDARDS -POSIX.1-2001, POSIX.1-2008, SVr4, 4.4BSD. -.\" SVr4 documents additional error codes ENXIO and ENODEV. -.\" SUSv2 documents additional error codes EMFILE and EOVERFLOW. -.PP -On POSIX systems on which -.BR mmap (), -.BR msync (2), -and -.BR munmap () -are available, -.B _POSIX_MAPPED_FILES -is defined in \fI<unistd.h>\fP to a value greater than 0. -(See also -.BR sysconf (3).) -.\" POSIX.1-2001: It shall be defined to -1 or 0 or 200112L. -.\" -1: unavailable, 0: ask using sysconf(). -.\" glibc defines it to 1. -.SH NOTES -Memory mapped by -.BR mmap () -is preserved across -.BR fork (2), -with the same attributes. -.PP -A file is mapped in multiples of the page size. -For a file that is not -a multiple of the page size, -the remaining bytes in the partial page at the end of the mapping -are zeroed when mapped, -and modifications to that region are not written out to the file. -The effect of -changing the size of the underlying file of a mapping on the pages that -correspond to added or removed regions of the file is unspecified. -.PP +.SH VERSIONS On some hardware architectures (e.g., i386), .B PROT_WRITE implies @@ -760,6 +724,57 @@ The relevant flags are: .BR MAP_POPULATE , and .BR MAP_STACK . +.SS C library/kernel differences +This page describes the interface provided by the glibc +.BR mmap () +wrapper function. +Originally, this function invoked a system call of the same name. +Since Linux 2.4, that system call has been superseded by +.BR mmap2 (2), +and nowadays +.\" Since around glibc 2.1/2.2, depending on the platform. +the glibc +.BR mmap () +wrapper function invokes +.BR mmap2 (2) +with a suitably adjusted value for +.IR offset . +.SH STANDARDS +POSIX.1-2008. +.SH HISTORY +POSIX.1-2001, SVr4, 4.4BSD. +.\" SVr4 documents additional error codes ENXIO and ENODEV. +.\" SUSv2 documents additional error codes EMFILE and EOVERFLOW. +.PP +On POSIX systems on which +.BR mmap (), +.BR msync (2), +and +.BR munmap () +are available, +.B _POSIX_MAPPED_FILES +is defined in \fI<unistd.h>\fP to a value greater than 0. +(See also +.BR sysconf (3).) +.\" POSIX.1-2001: It shall be defined to -1 or 0 or 200112L. +.\" -1: unavailable, 0: ask using sysconf(). +.\" glibc defines it to 1. +.SH NOTES +Memory mapped by +.BR mmap () +is preserved across +.BR fork (2), +with the same attributes. +.PP +A file is mapped in multiples of the page size. +For a file that is not +a multiple of the page size, +the remaining bytes in the partial page at the end of the mapping +are zeroed when mapped, +and modifications to that region are not written out to the file. +The effect of +changing the size of the underlying file of a mapping on the pages that +correspond to added or removed regions of the file is unspecified. .PP An application can determine which pages of a mapping are currently resident in the buffer/page cache using @@ -779,7 +794,7 @@ is hazardous because it forcibly removes preexisting mappings, making it easy for a multithreaded process to corrupt its own address space. .PP For example, suppose that thread A looks through -.I /proc/<pid>/maps +.IR /proc/ pid /maps in order to locate an unused address range that it can map using .BR MAP_FIXED , while thread B simultaneously acquires part or all of that same @@ -860,21 +875,6 @@ and .I length must both be a multiple of the underlying huge page size. .\" -.SS C library/kernel differences -This page describes the interface provided by the glibc -.BR mmap () -wrapper function. -Originally, this function invoked a system call of the same name. -Since Linux 2.4, that system call has been superseded by -.BR mmap2 (2), -and nowadays -.\" Since around glibc 2.1/2.2, depending on the platform. -the glibc -.BR mmap () -wrapper function invokes -.BR mmap2 (2) -with a suitably adjusted value for -.IR offset . .SH BUGS On Linux, there are no guarantees like those suggested above under .BR MAP_NORESERVE . @@ -939,10 +939,10 @@ to output the desired bytes. #include <sys/mman.h> #include <sys/stat.h> #include <unistd.h> - +\& #define handle_error(msg) \e do { perror(msg); exit(EXIT_FAILURE); } while (0) - +\& int main(int argc, char *argv[]) { @@ -952,55 +952,55 @@ main(int argc, char *argv[]) size_t length; ssize_t s; struct stat sb; - +\& if (argc < 3 || argc > 4) { fprintf(stderr, "%s file offset [length]\en", argv[0]); exit(EXIT_FAILURE); } - +\& fd = open(argv[1], O_RDONLY); if (fd == \-1) handle_error("open"); - +\& if (fstat(fd, &sb) == \-1) /* To obtain file size */ handle_error("fstat"); - +\& offset = atoi(argv[2]); pa_offset = offset & \[ti](sysconf(_SC_PAGE_SIZE) \- 1); /* offset for mmap() must be page aligned */ - +\& if (offset >= sb.st_size) { fprintf(stderr, "offset is past end of file\en"); exit(EXIT_FAILURE); } - +\& if (argc == 4) { length = atoi(argv[3]); if (offset + length > sb.st_size) length = sb.st_size \- offset; /* Can\[aq]t display bytes past end of file */ - +\& } else { /* No length arg ==> display to end of file */ length = sb.st_size \- offset; } - +\& addr = mmap(NULL, length + offset \- pa_offset, PROT_READ, MAP_PRIVATE, fd, pa_offset); if (addr == MAP_FAILED) handle_error("mmap"); - +\& s = write(STDOUT_FILENO, addr + offset \- pa_offset, length); if (s != length) { if (s == \-1) handle_error("write"); - +\& fprintf(stderr, "partial write"); exit(EXIT_FAILURE); } - +\& munmap(addr, length + offset \- pa_offset); close(fd); - +\& exit(EXIT_SUCCESS); } .EE @@ -1024,10 +1024,10 @@ main(int argc, char *argv[]) .PP The descriptions of the following files in .BR proc (5): -.IR /proc/[pid]/maps , -.IR /proc/[pid]/map_files , +.IR /proc/ pid /maps , +.IR /proc/ pid /map_files , and -.IR /proc/[pid]/smaps . +.IR /proc/ pid /smaps . .PP B.O. Gallmeister, POSIX.4, O'Reilly, pp. 128\[en]129 and 389\[en]391. .\" |