Revision 3b46e624 linux-user/mmap.c
b/linux-user/mmap.c | ||
---|---|---|
52 | 52 |
return -EINVAL; |
53 | 53 |
if (len == 0) |
54 | 54 |
return 0; |
55 |
|
|
55 |
|
|
56 | 56 |
host_start = start & qemu_host_page_mask; |
57 | 57 |
host_end = HOST_PAGE_ALIGN(end); |
58 | 58 |
if (start > host_start) { |
... | ... | |
83 | 83 |
return ret; |
84 | 84 |
host_end -= qemu_host_page_size; |
85 | 85 |
} |
86 |
|
|
86 |
|
|
87 | 87 |
/* handle the pages in the middle */ |
88 | 88 |
if (host_start < host_end) { |
89 | 89 |
ret = mprotect(g2h(host_start), host_end - host_start, prot); |
... | ... | |
112 | 112 |
if (addr < start || addr >= end) |
113 | 113 |
prot1 |= page_get_flags(addr); |
114 | 114 |
} |
115 |
|
|
115 |
|
|
116 | 116 |
if (prot1 == 0) { |
117 | 117 |
/* no page was there, so we allocate one */ |
118 | 118 |
ret = (long)mmap(host_start, qemu_host_page_size, prot, |
... | ... | |
134 | 134 |
/* adjust protection to be able to read */ |
135 | 135 |
if (!(prot1 & PROT_WRITE)) |
136 | 136 |
mprotect(host_start, qemu_host_page_size, prot1 | PROT_WRITE); |
137 |
|
|
137 |
|
|
138 | 138 |
/* read the corresponding file data */ |
139 | 139 |
pread(fd, g2h(start), end - start, offset); |
140 |
|
|
140 |
|
|
141 | 141 |
/* put final protection */ |
142 | 142 |
if (prot_new != (prot1 | PROT_WRITE)) |
143 | 143 |
mprotect(host_start, qemu_host_page_size, prot_new); |
... | ... | |
244 | 244 |
goto the_end1; |
245 | 245 |
} |
246 | 246 |
} |
247 |
|
|
247 |
|
|
248 | 248 |
if (start & ~TARGET_PAGE_MASK) { |
249 | 249 |
errno = EINVAL; |
250 | 250 |
return -1; |
... | ... | |
303 | 303 |
return ret; |
304 | 304 |
real_end -= qemu_host_page_size; |
305 | 305 |
} |
306 |
|
|
306 |
|
|
307 | 307 |
/* map the middle (easier) */ |
308 | 308 |
if (real_start < real_end) { |
309 | 309 |
unsigned long offset1; |
... | ... | |
367 | 367 |
if (prot != 0) |
368 | 368 |
real_end -= qemu_host_page_size; |
369 | 369 |
} |
370 |
|
|
370 |
|
|
371 | 371 |
/* unmap what we can */ |
372 | 372 |
if (real_start < real_end) { |
373 | 373 |
ret = munmap((void *)real_start, real_end - real_start); |
... | ... | |
410 | 410 |
return -EINVAL; |
411 | 411 |
if (end == start) |
412 | 412 |
return 0; |
413 |
|
|
413 |
|
|
414 | 414 |
start &= qemu_host_page_mask; |
415 | 415 |
return msync(g2h(start), end - start, flags); |
416 | 416 |
} |
Also available in: Unified diff