1 =============================
2 NO-MMU MEMORY MAPPING SUPPORT
3 =============================
5 The kernel has limited support for memory mapping under no-MMU conditions, such
6 as are used in uClinux environments. From the userspace point of view, memory
7 mapping is made use of in conjunction with the mmap() system call, the shmat()
8 call and the execve() system call. From the kernel's point of view, execve()
9 mapping is actually performed by the binfmt drivers, which call back into the
10 mmap() routines to do the actual work.
12 Memory mapping behaviour also involves the way fork(), vfork(), clone() and
13 ptrace() work. Under uClinux there is no fork(), and clone() must be supplied
16 The behaviour is similar between the MMU and no-MMU cases, but not identical;
17 and it's also much more restricted in the latter case:
19 (*) Anonymous mapping, MAP_PRIVATE
21 In the MMU case: VM regions backed by arbitrary pages; copy-on-write
24 In the no-MMU case: VM regions backed by arbitrary contiguous runs of
27 (*) Anonymous mapping, MAP_SHARED
29 These behave very much like private mappings, except that they're
30 shared across fork() or clone() without CLONE_VM in the MMU case. Since
31 the no-MMU case doesn't support these, behaviour is identical to
34 (*) File, MAP_PRIVATE, PROT_READ / PROT_EXEC, !PROT_WRITE
36 In the MMU case: VM regions backed by pages read from file; changes to
37 the underlying file are reflected in the mapping; copied across fork.
39 In the no-MMU case: VM regions backed by arbitrary contiguous runs of
40 pages into which the appropriate bit of the file is read; any remaining
41 bit of the mapping is cleared; such mappings are shared if possible;
42 writes to the file do not affect the mapping; writes to the mapping are
43 visible in other processes (no MMU protection), but should not happen.
45 (*) File, MAP_PRIVATE, PROT_READ / PROT_EXEC, PROT_WRITE
47 In the MMU case: like the non-PROT_WRITE case, except that the pages in
48 question get copied before the write actually happens. From that point
49 on writes to that page in the file no longer get reflected into the
50 mapping's backing pages.
52 In the no-MMU case: works exactly as for the non-PROT_WRITE case.
54 (*) Regular file / blockdev, MAP_SHARED, PROT_READ / PROT_EXEC / PROT_WRITE
56 In the MMU case: VM regions backed by pages read from file; changes to
57 pages written back to file; writes to file reflected into pages backing
58 mapping; shared across fork.
60 In the no-MMU case: not supported.
62 (*) Memory backed regular file, MAP_SHARED, PROT_READ / PROT_EXEC / PROT_WRITE
64 In the MMU case: As for ordinary regular files.
66 In the no-MMU case: The filesystem providing the memory-backed file
67 (such as ramfs or tmpfs) may choose to honour an open, truncate, mmap
68 sequence by providing a contiguous sequence of pages to map. In that
69 case, a shared-writable memory mapping will be possible. It will work
70 as for the MMU case. If the filesystem does not provide any such
71 support, then the mapping request will be denied.
73 (*) Memory backed chardev, MAP_SHARED, PROT_READ / PROT_EXEC / PROT_WRITE
75 In the MMU case: As for ordinary regular files.
77 In the no-MMU case: The character device driver may choose to honour
78 the mmap() by providing direct access to the underlying device if it
79 provides memory or quasi-memory that can be accessed directly. Examples
80 of such are frame buffers and flash devices. If the driver does not
81 provide any such support, then the mapping request will be denied.
84 ============================
85 FURTHER NOTES ON NO-MMU MMAP
86 ============================
88 (*) A request for a private mapping of less than a page in size may not return
89 a page-aligned buffer. This is because the kernel calls kmalloc() to
90 allocate the buffer, not get_free_page().
92 (*) A list of all the mappings on the system is visible through /proc/maps in
95 (*) Supplying MAP_FIXED or a requesting a particular mapping address will
98 (*) Files mapped privately must have a read method provided by the driver or
99 filesystem so that the contents can be read into the memory allocated. An
100 error will result if they don't. This is most likely to be encountered
101 with character device files, pipes, fifos and sockets.
104 ============================================
105 PROVIDING SHAREABLE CHARACTER DEVICE SUPPORT
106 ============================================
108 To provide shareable character device support, a driver must provide a
109 file->f_op->get_unmapped_area() operation. The mmap() routines will call this
110 to get a proposed address for the mapping. This may return an error if it
111 doesn't wish to honour the mapping because it's too long, at a weird offset,
112 under some unsupported combination of flags or whatever.
114 The vm_ops->close() routine will be invoked when the last mapping on a chardev
115 is removed. An existing mapping will be shared, partially or not, if possible
116 without notifying the driver.
118 It is permitted also for the file->f_op->get_unmapped_area() operation to
119 return -ENOSYS. This will be taken to mean that this operation just doesn't
120 want to handle it, despite the fact it's got an operation. For instance, it
121 might try directing the call to a secondary driver which turns out not to
122 implement it. Such is the case for the framebuffer driver which attempts to
123 direct the call to the device-specific driver.
126 ==============================================
127 PROVIDING SHAREABLE MEMORY-BACKED FILE SUPPORT
128 ==============================================
130 Provision of shared mappings on memory backed files is similar to the provision
131 of support for shared mapped character devices. The main difference is that the
132 filesystem providing the service will probably allocate a contiguous collection
133 of pages and permit mappings to be made on that.
135 It is recommended that a truncate operation applied to such a file that
136 increases the file size, if that file is empty, be taken as a request to gather
137 enough pages to honour a mapping. This is required to support POSIX shared
140 Memory backed devices are indicated by the mapping's backing device info having
141 the memory_backed flag set.