2 .\" Copyright (c) 2011 Advanced Computing Technologies LLC
3 .\" Written by: John H. Baldwin <jhb@FreeBSD.org>
4 .\" All rights reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\" notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\" notice, this list of conditions and the following disclaimer in the
13 .\" documentation and/or other materials provided with the distribution.
15 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 .Nm shm_map , shm_unmap
34 .Nd "map shared memory objects into the kernel's address space"
39 .Fn shm_map "struct file *fp" "size_t size" "off_t offset" "void **memp"
41 .Fn shm_unmap "struct file *fp" "void *mem" "size_t size"
47 functions provide an API for mapping shared memory objects into the kernel.
48 Shared memory objects are created by
50 These objects can then be passed into the kernel via file descriptors.
52 A shared memory object cannot be shrunk while it is mapped into the kernel.
53 This is to avoid invalidating any pages that may be wired into the kernel's
55 Shared memory objects can still be grown while mapped into the kernel.
57 To simplify the accounting needed to enforce the above requirement,
58 callers of this API are required to unmap the entire region mapped by
62 Unmapping only a portion of the region is not permitted.
66 function locates the shared memory object associated with the open file
68 It maps the region of that object described by
72 into the kernel's address space.
75 will be set to the start of the mapping.
76 All pages for the range will be wired into memory upon successful return.
80 function unmaps a region previously mapped by
84 argument should match the value previously returned in
88 argument should match the value passed to
93 will not hold an extra reference on the open file
95 for the lifetime of the mapping.
97 the calling code is required to do this if it wishes to use
99 on the region in the future.
105 functions return zero on success or an error on failure.
107 The following function accepts a file descriptor for a shared memory
109 It maps the first sixteen kilobytes of the object into the kernel,
110 performs some work on that address,
111 and then unmaps the address before returning.
112 .Bd -literal -offset indent
120 error = fget(curthread, fd, CAP_MMAP, &fp);
123 error = shm_map(fp, 16384, 0, &mem);
125 fdrop(fp, curthread);
129 /* Do something with 'mem'. */
131 error = shm_unmap(fp, mem, 16384);
132 fdrop(fp, curthread);
139 function returns the following errors on failure:
144 is not a shared memory object.
146 The requested region described by
150 extends beyond the end of the shared memory object.
152 Insufficient address space was available.
154 The shared memory object could not be mapped due to a protection error.
156 The shared memory object could not be mapped due to some other VM error.
161 function returns the following errors on failure:
166 is not a shared memory object.
168 The address range described by
172 is not a valid address range.
174 The address range described by
178 is not backed by the shared memory object associated with the open file
180 or the address range does not cover the entire mapping of the object.
185 This API was first introduced in