1mmapobj(2) System Calls mmapobj(2)
2
3
4
6 mmapobj - map a file object in the appropriate manner
7
9 #include <sys/mman.h>
10
11 int mmapobj(int fd, uint_t flags, mmapobj_result_t *storage,
12 uint_t *elements, void *arg);
13
14
16 fd The open file descriptor for the file to be mapped.
17
18
19 flags Indicates that the default behavior of mmapobj() should be
20 modified accordingly. Available flags are:
21
22 MMOBJ_INTERPRET
23
24 Interpret the contents of the file descriptor instead
25 of just mapping it as a single image. This flag can be
26 used only with ELF and AOUT files.
27
28
29 MMOBJ_PADDING
30
31 When mapping in the file descriptor, add an additional
32 mapping before the lowest mapping and after the highest
33 mapping. The size of this padding is at least as large
34 as the amount pointed to by arg. These mappings will be
35 private to the process, will not reserve any swap space
36 and will have no protections. To use this address
37 space, the protections for it will need to be changed.
38 This padding request will be ignored for the AOUT for‐
39 mat.
40
41
42
43 storage A pointer to the mmapobj_result_t array where the mapping
44 data will be copied out after a successful mapping of fd.
45
46
47 elements A pointer to the number of mmapobj_result_t elements
48 pointed to by storage. On return, elements contains the
49 number of mappings required to fully map the requested
50 object. If the original value of elements is too small,
51 E2BIG is returned and elements is modified to contain the
52 number of mappings necessary.
53
54
55 arg A pointer to additional information that might be associ‐
56 ated with the specific request. Only the MMOBJ_PADDING
57 request uses this argument. If MMOBJ_PADDING is not speci‐
58 fied, arg must be NULL.
59
60
62 The mmapobj() function establishes a set of mappings between a
63 process's address space and a file. By default, mmapobj() maps the
64 whole file as a single, private, read-only mapping. The MMOBJ_INTER‐
65 PRET flag instructs mmapobj() to attempt to interpret the file and map
66 the file according to the rules for that file format. The following
67 ELF and AOUT formats are supported:
68
69 ET_EXEC and AOUT executables
70
71 This format results in one or more mappings whose size, alignment
72 and protections are as described by the file's program header
73 information. The address of each mapping is explicitly defined by
74 the file's program headers.
75
76
77 ET_DYN and AOUT shared objects
78
79 This format results in one or more mappings whose size, alignment
80 and protections are as described by the file's program header
81 information. The base address of the initial mapping is chosen by
82 mmapobj(). The addresses of adjacent mappings are based off of this
83 base address as defined by the file's program headers.
84
85
86 ET_REL and ET_CORE
87
88 This format results in a single, read-only mapping that covers the
89 whole file. The base address of this mapping is chosen by
90 mmapobj().
91
92
93
94 The mmapobj() function will not map over any currently used mappings
95 within the process, except for the case of an ELF ET_EXEC file for
96 which a previous reservation has been made via /dev/null. The most com‐
97 mon way to make such a reservation would be with an mmap() of
98 /dev/null.
99
100
101 Mappings created with mmapobj() can be processed individually by other
102 system calls such as munmap(2).
103
104
105 The mmapobj_result structure contains the following members:
106
107 typedef struct mmapobj_result {
108 caddr_t mr_addr; /* mapping address */
109 size_t mr_msize; /* mapping size */
110 size_t mr_fsize; /* file size */
111 size_t mr_offset; /* offset into file */
112 uint_t mr_prot; /* the protections provided */
113 uint_t mr_flags; /* info on the mapping */
114 } mmapobj_result_t;
115
116
117
118 The macro MR_GET_TYPE(mr_flags) must be used when looking for the above
119 flags in the value of mr_flags.
120
121
122 Values for mr_flags include:
123
124 MR_PADDING 0x1 /* this mapping represents requested padding */
125 MR_HDR_ELF 0x2 /* the ELF header is mapped at mr_addr */
126 MR_HDR_AOU 0x3 /* the AOUT header is mapped at mr_addr */
127
128
129
130 When MR_PADDING is set, mr_fsize and mr_offset will both be 0.
131
132
133 The mr_fsize member represents the amount of the file that is mapped
134 into memory with this mapping.
135
136
137 The mr_offset member is the offset into the mapping where valid data
138 begins.
139
140
141 The mr_msize member represents the size of the memory mapping starting
142 at mr_addr. This size may include unused data prior to mr_offset that
143 exists to satisfy the alignment requirements of this segment. This size
144 may also include any non-file data that are required to provide NOBITS
145 data (typically .bss). The system reserves the right to map more than
146 mr_msize bytes of memory but only mr_msize bytes will be available to
147 the caller of mmapobj().
148
150 Upon successful completion, 0 is returned and elements contains the
151 number of program headers that are mapped for fd. The data describing
152 these elements are copied to storage such that the first elements mem‐
153 bers of the storage array contain valid mapping data.
154
155
156 On failure, -1 is returned and errno is set to indicate the error. No
157 data is copied to storage.
158
160 The mmapobj() function will fail if:
161
162 E2BIG The elements argument was not large enough to hold the
163 number of loadable segments in fd. The elements argument
164 will be modified to contain the number of segments
165 required.
166
167
168 EACCES The file system containing the fd to be mapped does not
169 allow execute access, or the file descriptor pointed to
170 by fd is not open for reading.
171
172
173 EADDRINUSE The mapping requirements overlap an object that is
174 already used by the process.
175
176
177 EAGAIN There is insufficient room to reserve swap space for the
178 mapping.
179
180 The file to be mapped is already locked using advisory or
181 mandatory record locking. See fcntl(2).
182
183
184 EBADF The fd argument is not a valid open file descriptor.
185
186
187 EFAULT The storage, arg, or elements argument points to an
188 invalid address.
189
190
191 EINVAL The flags argument contains an invalid flag.
192
193 MMOBJ_PADDING was not specified in flagsand arg was non-
194 null.
195
196
197 ENODEV The fd argument refers to an object for which mmapobj()
198 is meaningless, such as a terminal.
199
200
201 ENOMEM Insufficient memory is available to hold the program
202 headers.
203
204 Insufficient memory is available in the address space to
205 create the mapping.
206
207
208 ENOTSUP The current user data model does not match the fd to be
209 interpreted; thus, a 32-bit process that tried to use
210 mmapobj() to interpret a 64-bit object would return ENOT‐
211 SUP.
212
213 The fd argument is a file whose type can not be inter‐
214 preted and MMOBJ_INTERPRET was specified in flags.
215
216 The ELF header contains an unaligned e_phentsize value.
217
218
219 ENOSYS An unsupported filesystem operation was attempted while
220 trying to map in the object.
221
222
224 See attributes(5) for descriptions of the following attributes:
225
226
227
228
229 ┌─────────────────────────────┬─────────────────────────────┐
230 │ ATTRIBUTE TYPE │ ATTRIBUTE VALUE │
231 ├─────────────────────────────┼─────────────────────────────┤
232 │Interface Stability │Private │
233 ├─────────────────────────────┼─────────────────────────────┤
234 │MT-Level │Async-Signal-Safe │
235 └─────────────────────────────┴─────────────────────────────┘
236
238 ld.so.1(1), fcntl(2), memcntl(2), mmap(2), mprotect(2), munmap(2),
239 elf(3ELF), madvise(3C), mlockall(3C), msync(3C), a.out(4),
240 attributes(5)
241
242
243 Linker and Libraries Guide
244
245
246
247SunOS 5.11 1 Dec 2008 mmapobj(2)