root / linux-user / mmap.c @ facc68be
History | View | Annotate | Download (12.4 kB)
1 | 54936004 | bellard | /*
|
---|---|---|---|
2 | 54936004 | bellard | * mmap support for qemu
|
3 | 54936004 | bellard | *
|
4 | 54936004 | bellard | * Copyright (c) 2003 Fabrice Bellard
|
5 | 54936004 | bellard | *
|
6 | 54936004 | bellard | * This program is free software; you can redistribute it and/or modify
|
7 | 54936004 | bellard | * it under the terms of the GNU General Public License as published by
|
8 | 54936004 | bellard | * the Free Software Foundation; either version 2 of the License, or
|
9 | 54936004 | bellard | * (at your option) any later version.
|
10 | 54936004 | bellard | *
|
11 | 54936004 | bellard | * This program is distributed in the hope that it will be useful,
|
12 | 54936004 | bellard | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | 54936004 | bellard | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 | 54936004 | bellard | * GNU General Public License for more details.
|
15 | 54936004 | bellard | *
|
16 | 54936004 | bellard | * You should have received a copy of the GNU General Public License
|
17 | 54936004 | bellard | * along with this program; if not, write to the Free Software
|
18 | 54936004 | bellard | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
19 | 54936004 | bellard | */
|
20 | 54936004 | bellard | #include <stdlib.h> |
21 | 54936004 | bellard | #include <stdio.h> |
22 | 54936004 | bellard | #include <stdarg.h> |
23 | 54936004 | bellard | #include <string.h> |
24 | 54936004 | bellard | #include <unistd.h> |
25 | 54936004 | bellard | #include <errno.h> |
26 | 54936004 | bellard | #include <sys/mman.h> |
27 | 54936004 | bellard | |
28 | 54936004 | bellard | #include "qemu.h" |
29 | 54936004 | bellard | |
30 | 54936004 | bellard | //#define DEBUG_MMAP
|
31 | 54936004 | bellard | |
32 | 54936004 | bellard | /* NOTE: all the constants are the HOST ones */
|
33 | 54936004 | bellard | int target_mprotect(unsigned long start, unsigned long len, int prot) |
34 | 54936004 | bellard | { |
35 | 54936004 | bellard | unsigned long end, host_start, host_end, addr; |
36 | 54936004 | bellard | int prot1, ret;
|
37 | 54936004 | bellard | |
38 | 54936004 | bellard | #ifdef DEBUG_MMAP
|
39 | 54936004 | bellard | printf("mprotect: start=0x%lx len=0x%lx prot=%c%c%c\n", start, len,
|
40 | 54936004 | bellard | prot & PROT_READ ? 'r' : '-', |
41 | 54936004 | bellard | prot & PROT_WRITE ? 'w' : '-', |
42 | 54936004 | bellard | prot & PROT_EXEC ? 'x' : '-'); |
43 | 54936004 | bellard | #endif
|
44 | 54936004 | bellard | |
45 | 54936004 | bellard | if ((start & ~TARGET_PAGE_MASK) != 0) |
46 | 54936004 | bellard | return -EINVAL;
|
47 | 54936004 | bellard | len = TARGET_PAGE_ALIGN(len); |
48 | 54936004 | bellard | end = start + len; |
49 | 54936004 | bellard | if (end < start)
|
50 | 54936004 | bellard | return -EINVAL;
|
51 | 54936004 | bellard | if (prot & ~(PROT_READ | PROT_WRITE | PROT_EXEC))
|
52 | 54936004 | bellard | return -EINVAL;
|
53 | 54936004 | bellard | if (len == 0) |
54 | 54936004 | bellard | return 0; |
55 | 54936004 | bellard | |
56 | 54936004 | bellard | host_start = start & host_page_mask; |
57 | 54936004 | bellard | host_end = HOST_PAGE_ALIGN(end); |
58 | 54936004 | bellard | if (start > host_start) {
|
59 | 54936004 | bellard | /* handle host page containing start */
|
60 | 54936004 | bellard | prot1 = prot; |
61 | 54936004 | bellard | for(addr = host_start; addr < start; addr += TARGET_PAGE_SIZE) {
|
62 | 54936004 | bellard | prot1 |= page_get_flags(addr); |
63 | 54936004 | bellard | } |
64 | d418c81e | bellard | if (host_end == host_start + host_page_size) {
|
65 | d418c81e | bellard | for(addr = end; addr < host_end; addr += TARGET_PAGE_SIZE) {
|
66 | d418c81e | bellard | prot1 |= page_get_flags(addr); |
67 | d418c81e | bellard | } |
68 | d418c81e | bellard | end = host_end; |
69 | d418c81e | bellard | } |
70 | 54936004 | bellard | ret = mprotect((void *)host_start, host_page_size, prot1 & PAGE_BITS);
|
71 | 54936004 | bellard | if (ret != 0) |
72 | 54936004 | bellard | return ret;
|
73 | 54936004 | bellard | host_start += host_page_size; |
74 | 54936004 | bellard | } |
75 | 54936004 | bellard | if (end < host_end) {
|
76 | 54936004 | bellard | prot1 = prot; |
77 | 54936004 | bellard | for(addr = end; addr < host_end; addr += TARGET_PAGE_SIZE) {
|
78 | 54936004 | bellard | prot1 |= page_get_flags(addr); |
79 | 54936004 | bellard | } |
80 | 54936004 | bellard | ret = mprotect((void *)(host_end - host_page_size), host_page_size,
|
81 | 54936004 | bellard | prot1 & PAGE_BITS); |
82 | 54936004 | bellard | if (ret != 0) |
83 | 54936004 | bellard | return ret;
|
84 | 54936004 | bellard | host_end -= host_page_size; |
85 | 54936004 | bellard | } |
86 | 54936004 | bellard | |
87 | 54936004 | bellard | /* handle the pages in the middle */
|
88 | 54936004 | bellard | if (host_start < host_end) {
|
89 | 54936004 | bellard | ret = mprotect((void *)host_start, host_end - host_start, prot);
|
90 | 54936004 | bellard | if (ret != 0) |
91 | 54936004 | bellard | return ret;
|
92 | 54936004 | bellard | } |
93 | 54936004 | bellard | page_set_flags(start, start + len, prot | PAGE_VALID); |
94 | 54936004 | bellard | return 0; |
95 | 54936004 | bellard | } |
96 | 54936004 | bellard | |
97 | 54936004 | bellard | /* map an incomplete host page */
|
98 | 54936004 | bellard | int mmap_frag(unsigned long host_start, |
99 | 54936004 | bellard | unsigned long start, unsigned long end, |
100 | 54936004 | bellard | int prot, int flags, int fd, unsigned long offset) |
101 | 54936004 | bellard | { |
102 | 54936004 | bellard | unsigned long host_end, ret, addr; |
103 | 54936004 | bellard | int prot1, prot_new;
|
104 | 54936004 | bellard | |
105 | 54936004 | bellard | host_end = host_start + host_page_size; |
106 | 54936004 | bellard | |
107 | 54936004 | bellard | /* get the protection of the target pages outside the mapping */
|
108 | 54936004 | bellard | prot1 = 0;
|
109 | 54936004 | bellard | for(addr = host_start; addr < host_end; addr++) {
|
110 | 54936004 | bellard | if (addr < start || addr >= end)
|
111 | 54936004 | bellard | prot1 |= page_get_flags(addr); |
112 | 54936004 | bellard | } |
113 | 54936004 | bellard | |
114 | 54936004 | bellard | if (prot1 == 0) { |
115 | 54936004 | bellard | /* no page was there, so we allocate one */
|
116 | 54936004 | bellard | ret = (long)mmap((void *)host_start, host_page_size, prot, |
117 | 54936004 | bellard | flags | MAP_ANONYMOUS, -1, 0); |
118 | 54936004 | bellard | if (ret == -1) |
119 | 54936004 | bellard | return ret;
|
120 | 54936004 | bellard | } |
121 | 54936004 | bellard | prot1 &= PAGE_BITS; |
122 | 54936004 | bellard | |
123 | 54936004 | bellard | prot_new = prot | prot1; |
124 | 54936004 | bellard | if (!(flags & MAP_ANONYMOUS)) {
|
125 | 54936004 | bellard | /* msync() won't work here, so we return an error if write is
|
126 | 54936004 | bellard | possible while it is a shared mapping */
|
127 | 54936004 | bellard | if ((flags & MAP_TYPE) == MAP_SHARED &&
|
128 | 54936004 | bellard | (prot & PROT_WRITE)) |
129 | 54936004 | bellard | return -EINVAL;
|
130 | 54936004 | bellard | |
131 | 54936004 | bellard | /* adjust protection to be able to read */
|
132 | 54936004 | bellard | if (!(prot1 & PROT_WRITE))
|
133 | 54936004 | bellard | mprotect((void *)host_start, host_page_size, prot1 | PROT_WRITE);
|
134 | 54936004 | bellard | |
135 | 54936004 | bellard | /* read the corresponding file data */
|
136 | 54936004 | bellard | pread(fd, (void *)start, end - start, offset);
|
137 | 54936004 | bellard | |
138 | 54936004 | bellard | /* put final protection */
|
139 | 54936004 | bellard | if (prot_new != (prot1 | PROT_WRITE))
|
140 | 54936004 | bellard | mprotect((void *)host_start, host_page_size, prot_new);
|
141 | 54936004 | bellard | } else {
|
142 | 54936004 | bellard | /* just update the protection */
|
143 | 54936004 | bellard | if (prot_new != prot1) {
|
144 | 54936004 | bellard | mprotect((void *)host_start, host_page_size, prot_new);
|
145 | 54936004 | bellard | } |
146 | 54936004 | bellard | } |
147 | 54936004 | bellard | return 0; |
148 | 54936004 | bellard | } |
149 | 54936004 | bellard | |
150 | 54936004 | bellard | /* NOTE: all the constants are the HOST ones */
|
151 | 54936004 | bellard | long target_mmap(unsigned long start, unsigned long len, int prot, |
152 | 54936004 | bellard | int flags, int fd, unsigned long offset) |
153 | 54936004 | bellard | { |
154 | 54936004 | bellard | unsigned long ret, end, host_start, host_end, retaddr, host_offset, host_len; |
155 | 54936004 | bellard | |
156 | 54936004 | bellard | #ifdef DEBUG_MMAP
|
157 | 54936004 | bellard | { |
158 | 54936004 | bellard | printf("mmap: start=0x%lx len=0x%lx prot=%c%c%c flags=",
|
159 | 54936004 | bellard | start, len, |
160 | 54936004 | bellard | prot & PROT_READ ? 'r' : '-', |
161 | 54936004 | bellard | prot & PROT_WRITE ? 'w' : '-', |
162 | 54936004 | bellard | prot & PROT_EXEC ? 'x' : '-'); |
163 | 54936004 | bellard | if (flags & MAP_FIXED)
|
164 | 54936004 | bellard | printf("MAP_FIXED ");
|
165 | 54936004 | bellard | if (flags & MAP_ANONYMOUS)
|
166 | 54936004 | bellard | printf("MAP_ANON ");
|
167 | 54936004 | bellard | switch(flags & MAP_TYPE) {
|
168 | 54936004 | bellard | case MAP_PRIVATE:
|
169 | 54936004 | bellard | printf("MAP_PRIVATE ");
|
170 | 54936004 | bellard | break;
|
171 | 54936004 | bellard | case MAP_SHARED:
|
172 | 54936004 | bellard | printf("MAP_SHARED ");
|
173 | 54936004 | bellard | break;
|
174 | 54936004 | bellard | default:
|
175 | 54936004 | bellard | printf("[MAP_TYPE=0x%x] ", flags & MAP_TYPE);
|
176 | 54936004 | bellard | break;
|
177 | 54936004 | bellard | } |
178 | 54936004 | bellard | printf("fd=%d offset=%lx\n", fd, offset);
|
179 | 54936004 | bellard | } |
180 | 54936004 | bellard | #endif
|
181 | 54936004 | bellard | |
182 | 54936004 | bellard | if (offset & ~TARGET_PAGE_MASK)
|
183 | 54936004 | bellard | return -EINVAL;
|
184 | 54936004 | bellard | |
185 | 54936004 | bellard | len = TARGET_PAGE_ALIGN(len); |
186 | 54936004 | bellard | if (len == 0) |
187 | 54936004 | bellard | return start;
|
188 | 54936004 | bellard | host_start = start & host_page_mask; |
189 | 54936004 | bellard | |
190 | 54936004 | bellard | if (!(flags & MAP_FIXED)) {
|
191 | 4a585ccb | bellard | #if defined(__alpha__) || defined(__sparc__)
|
192 | 917f95fd | bellard | /* tell the kenel to search at the same place as i386 */
|
193 | 917f95fd | bellard | if (host_start == 0) |
194 | 917f95fd | bellard | host_start = 0x40000000;
|
195 | 917f95fd | bellard | #endif
|
196 | 54936004 | bellard | if (host_page_size != real_host_page_size) {
|
197 | 54936004 | bellard | /* NOTE: this code is only for debugging with '-p' option */
|
198 | 54936004 | bellard | /* reserve a memory area */
|
199 | 54936004 | bellard | host_len = HOST_PAGE_ALIGN(len) + host_page_size - TARGET_PAGE_SIZE; |
200 | 54936004 | bellard | host_start = (long)mmap((void *)host_start, host_len, PROT_NONE, |
201 | 54936004 | bellard | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); |
202 | 54936004 | bellard | if (host_start == -1) |
203 | 54936004 | bellard | return host_start;
|
204 | 54936004 | bellard | host_end = host_start + host_len; |
205 | 54936004 | bellard | start = HOST_PAGE_ALIGN(host_start); |
206 | 54936004 | bellard | end = start + HOST_PAGE_ALIGN(len); |
207 | 54936004 | bellard | if (start > host_start)
|
208 | 54936004 | bellard | munmap((void *)host_start, start - host_start);
|
209 | 54936004 | bellard | if (end < host_end)
|
210 | 54936004 | bellard | munmap((void *)end, host_end - end);
|
211 | 54936004 | bellard | /* use it as a fixed mapping */
|
212 | 54936004 | bellard | flags |= MAP_FIXED; |
213 | 54936004 | bellard | } else {
|
214 | 54936004 | bellard | /* if not fixed, no need to do anything */
|
215 | 54936004 | bellard | host_offset = offset & host_page_mask; |
216 | 54936004 | bellard | host_len = len + offset - host_offset; |
217 | 54936004 | bellard | start = (long)mmap((void *)host_start, host_len, |
218 | 54936004 | bellard | prot, flags, fd, host_offset); |
219 | 54936004 | bellard | if (start == -1) |
220 | 54936004 | bellard | return start;
|
221 | 54936004 | bellard | /* update start so that it points to the file position at 'offset' */
|
222 | 54936004 | bellard | if (!(flags & MAP_ANONYMOUS))
|
223 | 54936004 | bellard | start += offset - host_offset; |
224 | 54936004 | bellard | goto the_end1;
|
225 | 54936004 | bellard | } |
226 | 54936004 | bellard | } |
227 | 54936004 | bellard | |
228 | 54936004 | bellard | if (start & ~TARGET_PAGE_MASK)
|
229 | 54936004 | bellard | return -EINVAL;
|
230 | 54936004 | bellard | end = start + len; |
231 | 54936004 | bellard | host_end = HOST_PAGE_ALIGN(end); |
232 | 54936004 | bellard | |
233 | 54936004 | bellard | /* worst case: we cannot map the file because the offset is not
|
234 | 54936004 | bellard | aligned, so we read it */
|
235 | 54936004 | bellard | if (!(flags & MAP_ANONYMOUS) &&
|
236 | 54936004 | bellard | (offset & ~host_page_mask) != (start & ~host_page_mask)) { |
237 | 54936004 | bellard | /* msync() won't work here, so we return an error if write is
|
238 | 54936004 | bellard | possible while it is a shared mapping */
|
239 | 54936004 | bellard | if ((flags & MAP_TYPE) == MAP_SHARED &&
|
240 | 54936004 | bellard | (prot & PROT_WRITE)) |
241 | 54936004 | bellard | return -EINVAL;
|
242 | 54936004 | bellard | retaddr = target_mmap(start, len, prot | PROT_WRITE, |
243 | 54936004 | bellard | MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS, |
244 | 54936004 | bellard | -1, 0); |
245 | 54936004 | bellard | if (retaddr == -1) |
246 | 54936004 | bellard | return retaddr;
|
247 | 54936004 | bellard | pread(fd, (void *)start, len, offset);
|
248 | 54936004 | bellard | if (!(prot & PROT_WRITE)) {
|
249 | 54936004 | bellard | ret = target_mprotect(start, len, prot); |
250 | 54936004 | bellard | if (ret != 0) |
251 | 54936004 | bellard | return ret;
|
252 | 54936004 | bellard | } |
253 | 54936004 | bellard | goto the_end;
|
254 | 54936004 | bellard | } |
255 | 54936004 | bellard | |
256 | 54936004 | bellard | /* handle the start of the mapping */
|
257 | 54936004 | bellard | if (start > host_start) {
|
258 | 54936004 | bellard | if (host_end == host_start + host_page_size) {
|
259 | 54936004 | bellard | /* one single host page */
|
260 | 54936004 | bellard | ret = mmap_frag(host_start, start, end, |
261 | 54936004 | bellard | prot, flags, fd, offset); |
262 | 54936004 | bellard | if (ret == -1) |
263 | 54936004 | bellard | return ret;
|
264 | 54936004 | bellard | goto the_end1;
|
265 | 54936004 | bellard | } |
266 | 54936004 | bellard | ret = mmap_frag(host_start, start, host_start + host_page_size, |
267 | 54936004 | bellard | prot, flags, fd, offset); |
268 | 54936004 | bellard | if (ret == -1) |
269 | 54936004 | bellard | return ret;
|
270 | 54936004 | bellard | host_start += host_page_size; |
271 | 54936004 | bellard | } |
272 | 54936004 | bellard | /* handle the end of the mapping */
|
273 | 54936004 | bellard | if (end < host_end) {
|
274 | 54936004 | bellard | ret = mmap_frag(host_end - host_page_size, |
275 | 54936004 | bellard | host_end - host_page_size, host_end, |
276 | 54936004 | bellard | prot, flags, fd, |
277 | 54936004 | bellard | offset + host_end - host_page_size - start); |
278 | 54936004 | bellard | if (ret == -1) |
279 | 54936004 | bellard | return ret;
|
280 | 54936004 | bellard | host_end -= host_page_size; |
281 | 54936004 | bellard | } |
282 | 54936004 | bellard | |
283 | 54936004 | bellard | /* map the middle (easier) */
|
284 | 54936004 | bellard | if (host_start < host_end) {
|
285 | 4a585ccb | bellard | unsigned long offset1; |
286 | 4a585ccb | bellard | if (flags & MAP_ANONYMOUS)
|
287 | 4a585ccb | bellard | offset1 = 0;
|
288 | 4a585ccb | bellard | else
|
289 | 4a585ccb | bellard | offset1 = offset + host_start - start; |
290 | 54936004 | bellard | ret = (long)mmap((void *)host_start, host_end - host_start, |
291 | 4a585ccb | bellard | prot, flags, fd, offset1); |
292 | 54936004 | bellard | if (ret == -1) |
293 | 54936004 | bellard | return ret;
|
294 | 54936004 | bellard | } |
295 | 54936004 | bellard | the_end1:
|
296 | 54936004 | bellard | page_set_flags(start, start + len, prot | PAGE_VALID); |
297 | 54936004 | bellard | the_end:
|
298 | 54936004 | bellard | #ifdef DEBUG_MMAP
|
299 | 917f95fd | bellard | printf("ret=0x%lx\n", (long)start); |
300 | 54936004 | bellard | page_dump(stdout); |
301 | 54936004 | bellard | printf("\n");
|
302 | 54936004 | bellard | #endif
|
303 | 54936004 | bellard | return start;
|
304 | 54936004 | bellard | } |
305 | 54936004 | bellard | |
306 | 54936004 | bellard | int target_munmap(unsigned long start, unsigned long len) |
307 | 54936004 | bellard | { |
308 | 54936004 | bellard | unsigned long end, host_start, host_end, addr; |
309 | 54936004 | bellard | int prot, ret;
|
310 | 54936004 | bellard | |
311 | 54936004 | bellard | #ifdef DEBUG_MMAP
|
312 | 54936004 | bellard | printf("munmap: start=0x%lx len=0x%lx\n", start, len);
|
313 | 54936004 | bellard | #endif
|
314 | 54936004 | bellard | if (start & ~TARGET_PAGE_MASK)
|
315 | 54936004 | bellard | return -EINVAL;
|
316 | 54936004 | bellard | len = TARGET_PAGE_ALIGN(len); |
317 | 54936004 | bellard | if (len == 0) |
318 | 54936004 | bellard | return -EINVAL;
|
319 | 54936004 | bellard | end = start + len; |
320 | 54936004 | bellard | host_start = start & host_page_mask; |
321 | 54936004 | bellard | host_end = HOST_PAGE_ALIGN(end); |
322 | 54936004 | bellard | |
323 | 54936004 | bellard | if (start > host_start) {
|
324 | 54936004 | bellard | /* handle host page containing start */
|
325 | 54936004 | bellard | prot = 0;
|
326 | 54936004 | bellard | for(addr = host_start; addr < start; addr += TARGET_PAGE_SIZE) {
|
327 | 54936004 | bellard | prot |= page_get_flags(addr); |
328 | 54936004 | bellard | } |
329 | d418c81e | bellard | if (host_end == host_start + host_page_size) {
|
330 | d418c81e | bellard | for(addr = end; addr < host_end; addr += TARGET_PAGE_SIZE) {
|
331 | d418c81e | bellard | prot |= page_get_flags(addr); |
332 | d418c81e | bellard | } |
333 | d418c81e | bellard | end = host_end; |
334 | d418c81e | bellard | } |
335 | 54936004 | bellard | if (prot != 0) |
336 | 54936004 | bellard | host_start += host_page_size; |
337 | 54936004 | bellard | } |
338 | 54936004 | bellard | if (end < host_end) {
|
339 | 54936004 | bellard | prot = 0;
|
340 | 54936004 | bellard | for(addr = end; addr < host_end; addr += TARGET_PAGE_SIZE) {
|
341 | 54936004 | bellard | prot |= page_get_flags(addr); |
342 | 54936004 | bellard | } |
343 | 54936004 | bellard | if (prot != 0) |
344 | 54936004 | bellard | host_end -= host_page_size; |
345 | 54936004 | bellard | } |
346 | 54936004 | bellard | |
347 | 54936004 | bellard | /* unmap what we can */
|
348 | 54936004 | bellard | if (host_start < host_end) {
|
349 | 54936004 | bellard | ret = munmap((void *)host_start, host_end - host_start);
|
350 | 54936004 | bellard | if (ret != 0) |
351 | 54936004 | bellard | return ret;
|
352 | 54936004 | bellard | } |
353 | 54936004 | bellard | |
354 | 54936004 | bellard | page_set_flags(start, start + len, 0);
|
355 | 54936004 | bellard | return 0; |
356 | 54936004 | bellard | } |
357 | 54936004 | bellard | |
358 | 54936004 | bellard | /* XXX: currently, we only handle MAP_ANONYMOUS and not MAP_FIXED
|
359 | 54936004 | bellard | blocks which have been allocated starting on a host page */
|
360 | 54936004 | bellard | long target_mremap(unsigned long old_addr, unsigned long old_size, |
361 | 54936004 | bellard | unsigned long new_size, unsigned long flags, |
362 | 54936004 | bellard | unsigned long new_addr) |
363 | 54936004 | bellard | { |
364 | 54936004 | bellard | int prot;
|
365 | 54936004 | bellard | |
366 | 54936004 | bellard | /* XXX: use 5 args syscall */
|
367 | 54936004 | bellard | new_addr = (long)mremap((void *)old_addr, old_size, new_size, flags); |
368 | 54936004 | bellard | if (new_addr == -1) |
369 | 54936004 | bellard | return new_addr;
|
370 | 54936004 | bellard | prot = page_get_flags(old_addr); |
371 | 54936004 | bellard | page_set_flags(old_addr, old_addr + old_size, 0);
|
372 | 54936004 | bellard | page_set_flags(new_addr, new_addr + new_size, prot | PAGE_VALID); |
373 | 54936004 | bellard | return new_addr;
|
374 | 54936004 | bellard | } |
375 | 54936004 | bellard | |
376 | 54936004 | bellard | int target_msync(unsigned long start, unsigned long len, int flags) |
377 | 54936004 | bellard | { |
378 | 54936004 | bellard | unsigned long end; |
379 | 54936004 | bellard | |
380 | 54936004 | bellard | if (start & ~TARGET_PAGE_MASK)
|
381 | 54936004 | bellard | return -EINVAL;
|
382 | 54936004 | bellard | len = TARGET_PAGE_ALIGN(len); |
383 | 54936004 | bellard | end = start + len; |
384 | d418c81e | bellard | if (end < start)
|
385 | d418c81e | bellard | return -EINVAL;
|
386 | d418c81e | bellard | if (end == start)
|
387 | d418c81e | bellard | return 0; |
388 | 54936004 | bellard | |
389 | 54936004 | bellard | start &= host_page_mask; |
390 | d418c81e | bellard | return msync((void *)start, end - start, flags); |
391 | 54936004 | bellard | } |