]> git.proxmox.com Git - mirror_qemu.git/blob - linux-user/mmap.c
linux-user: log page table changes under -d page
[mirror_qemu.git] / linux-user / mmap.c
1 /*
2 * mmap support for qemu
3 *
4 * Copyright (c) 2003 Fabrice Bellard
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
18 */
19 #include "qemu/osdep.h"
20 #include "trace.h"
21 #include "exec/log.h"
22 #include "qemu.h"
23
24 //#define DEBUG_MMAP
25
26 static pthread_mutex_t mmap_mutex = PTHREAD_MUTEX_INITIALIZER;
27 static __thread int mmap_lock_count;
28
29 void mmap_lock(void)
30 {
31 if (mmap_lock_count++ == 0) {
32 pthread_mutex_lock(&mmap_mutex);
33 }
34 }
35
36 void mmap_unlock(void)
37 {
38 if (--mmap_lock_count == 0) {
39 pthread_mutex_unlock(&mmap_mutex);
40 }
41 }
42
43 bool have_mmap_lock(void)
44 {
45 return mmap_lock_count > 0 ? true : false;
46 }
47
48 /* Grab lock to make sure things are in a consistent state after fork(). */
49 void mmap_fork_start(void)
50 {
51 if (mmap_lock_count)
52 abort();
53 pthread_mutex_lock(&mmap_mutex);
54 }
55
56 void mmap_fork_end(int child)
57 {
58 if (child)
59 pthread_mutex_init(&mmap_mutex, NULL);
60 else
61 pthread_mutex_unlock(&mmap_mutex);
62 }
63
64 /* NOTE: all the constants are the HOST ones, but addresses are target. */
65 int target_mprotect(abi_ulong start, abi_ulong len, int prot)
66 {
67 abi_ulong end, host_start, host_end, addr;
68 int prot1, ret;
69
70 trace_target_mprotect(start, len, prot);
71
72 if ((start & ~TARGET_PAGE_MASK) != 0)
73 return -TARGET_EINVAL;
74 len = TARGET_PAGE_ALIGN(len);
75 end = start + len;
76 if (!guest_range_valid(start, len)) {
77 return -TARGET_ENOMEM;
78 }
79 prot &= PROT_READ | PROT_WRITE | PROT_EXEC;
80 if (len == 0)
81 return 0;
82
83 mmap_lock();
84 host_start = start & qemu_host_page_mask;
85 host_end = HOST_PAGE_ALIGN(end);
86 if (start > host_start) {
87 /* handle host page containing start */
88 prot1 = prot;
89 for(addr = host_start; addr < start; addr += TARGET_PAGE_SIZE) {
90 prot1 |= page_get_flags(addr);
91 }
92 if (host_end == host_start + qemu_host_page_size) {
93 for(addr = end; addr < host_end; addr += TARGET_PAGE_SIZE) {
94 prot1 |= page_get_flags(addr);
95 }
96 end = host_end;
97 }
98 ret = mprotect(g2h(host_start), qemu_host_page_size, prot1 & PAGE_BITS);
99 if (ret != 0)
100 goto error;
101 host_start += qemu_host_page_size;
102 }
103 if (end < host_end) {
104 prot1 = prot;
105 for(addr = end; addr < host_end; addr += TARGET_PAGE_SIZE) {
106 prot1 |= page_get_flags(addr);
107 }
108 ret = mprotect(g2h(host_end - qemu_host_page_size), qemu_host_page_size,
109 prot1 & PAGE_BITS);
110 if (ret != 0)
111 goto error;
112 host_end -= qemu_host_page_size;
113 }
114
115 /* handle the pages in the middle */
116 if (host_start < host_end) {
117 ret = mprotect(g2h(host_start), host_end - host_start, prot);
118 if (ret != 0)
119 goto error;
120 }
121 page_set_flags(start, start + len, prot | PAGE_VALID);
122 mmap_unlock();
123 return 0;
124 error:
125 mmap_unlock();
126 return ret;
127 }
128
129 /* map an incomplete host page */
130 static int mmap_frag(abi_ulong real_start,
131 abi_ulong start, abi_ulong end,
132 int prot, int flags, int fd, abi_ulong offset)
133 {
134 abi_ulong real_end, addr;
135 void *host_start;
136 int prot1, prot_new;
137
138 real_end = real_start + qemu_host_page_size;
139 host_start = g2h(real_start);
140
141 /* get the protection of the target pages outside the mapping */
142 prot1 = 0;
143 for(addr = real_start; addr < real_end; addr++) {
144 if (addr < start || addr >= end)
145 prot1 |= page_get_flags(addr);
146 }
147
148 if (prot1 == 0) {
149 /* no page was there, so we allocate one */
150 void *p = mmap(host_start, qemu_host_page_size, prot,
151 flags | MAP_ANONYMOUS, -1, 0);
152 if (p == MAP_FAILED)
153 return -1;
154 prot1 = prot;
155 }
156 prot1 &= PAGE_BITS;
157
158 prot_new = prot | prot1;
159 if (!(flags & MAP_ANONYMOUS)) {
160 /* msync() won't work here, so we return an error if write is
161 possible while it is a shared mapping */
162 if ((flags & MAP_TYPE) == MAP_SHARED &&
163 (prot & PROT_WRITE))
164 return -1;
165
166 /* adjust protection to be able to read */
167 if (!(prot1 & PROT_WRITE))
168 mprotect(host_start, qemu_host_page_size, prot1 | PROT_WRITE);
169
170 /* read the corresponding file data */
171 if (pread(fd, g2h(start), end - start, offset) == -1)
172 return -1;
173
174 /* put final protection */
175 if (prot_new != (prot1 | PROT_WRITE))
176 mprotect(host_start, qemu_host_page_size, prot_new);
177 } else {
178 if (prot_new != prot1) {
179 mprotect(host_start, qemu_host_page_size, prot_new);
180 }
181 if (prot_new & PROT_WRITE) {
182 memset(g2h(start), 0, end - start);
183 }
184 }
185 return 0;
186 }
187
188 #if HOST_LONG_BITS == 64 && TARGET_ABI_BITS == 64
189 # define TASK_UNMAPPED_BASE (1ul << 38)
190 #else
191 # define TASK_UNMAPPED_BASE 0x40000000
192 #endif
193 abi_ulong mmap_next_start = TASK_UNMAPPED_BASE;
194
195 unsigned long last_brk;
196
197 /* Subroutine of mmap_find_vma, used when we have pre-allocated a chunk
198 of guest address space. */
199 static abi_ulong mmap_find_vma_reserved(abi_ulong start, abi_ulong size,
200 abi_ulong align)
201 {
202 abi_ulong addr, end_addr, incr = qemu_host_page_size;
203 int prot;
204 bool looped = false;
205
206 if (size > reserved_va) {
207 return (abi_ulong)-1;
208 }
209
210 /* Note that start and size have already been aligned by mmap_find_vma. */
211
212 end_addr = start + size;
213 if (start > reserved_va - size) {
214 /* Start at the top of the address space. */
215 end_addr = ((reserved_va - size) & -align) + size;
216 looped = true;
217 }
218
219 /* Search downward from END_ADDR, checking to see if a page is in use. */
220 addr = end_addr;
221 while (1) {
222 addr -= incr;
223 if (addr > end_addr) {
224 if (looped) {
225 /* Failure. The entire address space has been searched. */
226 return (abi_ulong)-1;
227 }
228 /* Re-start at the top of the address space. */
229 addr = end_addr = ((reserved_va - size) & -align) + size;
230 looped = true;
231 } else {
232 prot = page_get_flags(addr);
233 if (prot) {
234 /* Page in use. Restart below this page. */
235 addr = end_addr = ((addr - size) & -align) + size;
236 } else if (addr && addr + size == end_addr) {
237 /* Success! All pages between ADDR and END_ADDR are free. */
238 if (start == mmap_next_start) {
239 mmap_next_start = addr;
240 }
241 return addr;
242 }
243 }
244 }
245 }
246
247 /*
248 * Find and reserve a free memory area of size 'size'. The search
249 * starts at 'start'.
250 * It must be called with mmap_lock() held.
251 * Return -1 if error.
252 */
253 abi_ulong mmap_find_vma(abi_ulong start, abi_ulong size, abi_ulong align)
254 {
255 void *ptr, *prev;
256 abi_ulong addr;
257 int wrapped, repeat;
258
259 align = MAX(align, qemu_host_page_size);
260
261 /* If 'start' == 0, then a default start address is used. */
262 if (start == 0) {
263 start = mmap_next_start;
264 } else {
265 start &= qemu_host_page_mask;
266 }
267 start = ROUND_UP(start, align);
268
269 size = HOST_PAGE_ALIGN(size);
270
271 if (reserved_va) {
272 return mmap_find_vma_reserved(start, size, align);
273 }
274
275 addr = start;
276 wrapped = repeat = 0;
277 prev = 0;
278
279 for (;; prev = ptr) {
280 /*
281 * Reserve needed memory area to avoid a race.
282 * It should be discarded using:
283 * - mmap() with MAP_FIXED flag
284 * - mremap() with MREMAP_FIXED flag
285 * - shmat() with SHM_REMAP flag
286 */
287 ptr = mmap(g2h(addr), size, PROT_NONE,
288 MAP_ANONYMOUS|MAP_PRIVATE|MAP_NORESERVE, -1, 0);
289
290 /* ENOMEM, if host address space has no memory */
291 if (ptr == MAP_FAILED) {
292 return (abi_ulong)-1;
293 }
294
295 /* Count the number of sequential returns of the same address.
296 This is used to modify the search algorithm below. */
297 repeat = (ptr == prev ? repeat + 1 : 0);
298
299 if (h2g_valid(ptr + size - 1)) {
300 addr = h2g(ptr);
301
302 if ((addr & (align - 1)) == 0) {
303 /* Success. */
304 if (start == mmap_next_start && addr >= TASK_UNMAPPED_BASE) {
305 mmap_next_start = addr + size;
306 }
307 return addr;
308 }
309
310 /* The address is not properly aligned for the target. */
311 switch (repeat) {
312 case 0:
313 /* Assume the result that the kernel gave us is the
314 first with enough free space, so start again at the
315 next higher target page. */
316 addr = ROUND_UP(addr, align);
317 break;
318 case 1:
319 /* Sometimes the kernel decides to perform the allocation
320 at the top end of memory instead. */
321 addr &= -align;
322 break;
323 case 2:
324 /* Start over at low memory. */
325 addr = 0;
326 break;
327 default:
328 /* Fail. This unaligned block must the last. */
329 addr = -1;
330 break;
331 }
332 } else {
333 /* Since the result the kernel gave didn't fit, start
334 again at low memory. If any repetition, fail. */
335 addr = (repeat ? -1 : 0);
336 }
337
338 /* Unmap and try again. */
339 munmap(ptr, size);
340
341 /* ENOMEM if we checked the whole of the target address space. */
342 if (addr == (abi_ulong)-1) {
343 return (abi_ulong)-1;
344 } else if (addr == 0) {
345 if (wrapped) {
346 return (abi_ulong)-1;
347 }
348 wrapped = 1;
349 /* Don't actually use 0 when wrapping, instead indicate
350 that we'd truly like an allocation in low memory. */
351 addr = (mmap_min_addr > TARGET_PAGE_SIZE
352 ? TARGET_PAGE_ALIGN(mmap_min_addr)
353 : TARGET_PAGE_SIZE);
354 } else if (wrapped && addr >= start) {
355 return (abi_ulong)-1;
356 }
357 }
358 }
359
360 /* NOTE: all the constants are the HOST ones */
361 abi_long target_mmap(abi_ulong start, abi_ulong len, int prot,
362 int flags, int fd, abi_ulong offset)
363 {
364 abi_ulong ret, end, real_start, real_end, retaddr, host_offset, host_len;
365
366 mmap_lock();
367 trace_target_mmap(start, len, prot, flags, fd, offset);
368
369 if (!len) {
370 errno = EINVAL;
371 goto fail;
372 }
373
374 /* Also check for overflows... */
375 len = TARGET_PAGE_ALIGN(len);
376 if (!len) {
377 errno = ENOMEM;
378 goto fail;
379 }
380
381 if (offset & ~TARGET_PAGE_MASK) {
382 errno = EINVAL;
383 goto fail;
384 }
385
386 real_start = start & qemu_host_page_mask;
387 host_offset = offset & qemu_host_page_mask;
388
389 /* If the user is asking for the kernel to find a location, do that
390 before we truncate the length for mapping files below. */
391 if (!(flags & MAP_FIXED)) {
392 host_len = len + offset - host_offset;
393 host_len = HOST_PAGE_ALIGN(host_len);
394 start = mmap_find_vma(real_start, host_len, TARGET_PAGE_SIZE);
395 if (start == (abi_ulong)-1) {
396 errno = ENOMEM;
397 goto fail;
398 }
399 }
400
401 /* When mapping files into a memory area larger than the file, accesses
402 to pages beyond the file size will cause a SIGBUS.
403
404 For example, if mmaping a file of 100 bytes on a host with 4K pages
405 emulating a target with 8K pages, the target expects to be able to
406 access the first 8K. But the host will trap us on any access beyond
407 4K.
408
409 When emulating a target with a larger page-size than the hosts, we
410 may need to truncate file maps at EOF and add extra anonymous pages
411 up to the targets page boundary. */
412
413 if ((qemu_real_host_page_size < qemu_host_page_size) &&
414 !(flags & MAP_ANONYMOUS)) {
415 struct stat sb;
416
417 if (fstat (fd, &sb) == -1)
418 goto fail;
419
420 /* Are we trying to create a map beyond EOF?. */
421 if (offset + len > sb.st_size) {
422 /* If so, truncate the file map at eof aligned with
423 the hosts real pagesize. Additional anonymous maps
424 will be created beyond EOF. */
425 len = REAL_HOST_PAGE_ALIGN(sb.st_size - offset);
426 }
427 }
428
429 if (!(flags & MAP_FIXED)) {
430 unsigned long host_start;
431 void *p;
432
433 host_len = len + offset - host_offset;
434 host_len = HOST_PAGE_ALIGN(host_len);
435
436 /* Note: we prefer to control the mapping address. It is
437 especially important if qemu_host_page_size >
438 qemu_real_host_page_size */
439 p = mmap(g2h(start), host_len, prot,
440 flags | MAP_FIXED | MAP_ANONYMOUS, -1, 0);
441 if (p == MAP_FAILED)
442 goto fail;
443 /* update start so that it points to the file position at 'offset' */
444 host_start = (unsigned long)p;
445 if (!(flags & MAP_ANONYMOUS)) {
446 p = mmap(g2h(start), len, prot,
447 flags | MAP_FIXED, fd, host_offset);
448 if (p == MAP_FAILED) {
449 munmap(g2h(start), host_len);
450 goto fail;
451 }
452 host_start += offset - host_offset;
453 }
454 start = h2g(host_start);
455 } else {
456 if (start & ~TARGET_PAGE_MASK) {
457 errno = EINVAL;
458 goto fail;
459 }
460 end = start + len;
461 real_end = HOST_PAGE_ALIGN(end);
462
463 /*
464 * Test if requested memory area fits target address space
465 * It can fail only on 64-bit host with 32-bit target.
466 * On any other target/host host mmap() handles this error correctly.
467 */
468 if (!guest_range_valid(start, len)) {
469 errno = ENOMEM;
470 goto fail;
471 }
472
473 /* worst case: we cannot map the file because the offset is not
474 aligned, so we read it */
475 if (!(flags & MAP_ANONYMOUS) &&
476 (offset & ~qemu_host_page_mask) != (start & ~qemu_host_page_mask)) {
477 /* msync() won't work here, so we return an error if write is
478 possible while it is a shared mapping */
479 if ((flags & MAP_TYPE) == MAP_SHARED &&
480 (prot & PROT_WRITE)) {
481 errno = EINVAL;
482 goto fail;
483 }
484 retaddr = target_mmap(start, len, prot | PROT_WRITE,
485 MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS,
486 -1, 0);
487 if (retaddr == -1)
488 goto fail;
489 if (pread(fd, g2h(start), len, offset) == -1)
490 goto fail;
491 if (!(prot & PROT_WRITE)) {
492 ret = target_mprotect(start, len, prot);
493 assert(ret == 0);
494 }
495 goto the_end;
496 }
497
498 /* handle the start of the mapping */
499 if (start > real_start) {
500 if (real_end == real_start + qemu_host_page_size) {
501 /* one single host page */
502 ret = mmap_frag(real_start, start, end,
503 prot, flags, fd, offset);
504 if (ret == -1)
505 goto fail;
506 goto the_end1;
507 }
508 ret = mmap_frag(real_start, start, real_start + qemu_host_page_size,
509 prot, flags, fd, offset);
510 if (ret == -1)
511 goto fail;
512 real_start += qemu_host_page_size;
513 }
514 /* handle the end of the mapping */
515 if (end < real_end) {
516 ret = mmap_frag(real_end - qemu_host_page_size,
517 real_end - qemu_host_page_size, end,
518 prot, flags, fd,
519 offset + real_end - qemu_host_page_size - start);
520 if (ret == -1)
521 goto fail;
522 real_end -= qemu_host_page_size;
523 }
524
525 /* map the middle (easier) */
526 if (real_start < real_end) {
527 void *p;
528 unsigned long offset1;
529 if (flags & MAP_ANONYMOUS)
530 offset1 = 0;
531 else
532 offset1 = offset + real_start - start;
533 p = mmap(g2h(real_start), real_end - real_start,
534 prot, flags, fd, offset1);
535 if (p == MAP_FAILED)
536 goto fail;
537 }
538 }
539 the_end1:
540 page_set_flags(start, start + len, prot | PAGE_VALID);
541 the_end:
542 trace_target_mmap_complete(start);
543 if (qemu_loglevel_mask(CPU_LOG_PAGE)) {
544 log_page_dump(__func__);
545 }
546 tb_invalidate_phys_range(start, start + len);
547 mmap_unlock();
548 return start;
549 fail:
550 mmap_unlock();
551 return -1;
552 }
553
554 static void mmap_reserve(abi_ulong start, abi_ulong size)
555 {
556 abi_ulong real_start;
557 abi_ulong real_end;
558 abi_ulong addr;
559 abi_ulong end;
560 int prot;
561
562 real_start = start & qemu_host_page_mask;
563 real_end = HOST_PAGE_ALIGN(start + size);
564 end = start + size;
565 if (start > real_start) {
566 /* handle host page containing start */
567 prot = 0;
568 for (addr = real_start; addr < start; addr += TARGET_PAGE_SIZE) {
569 prot |= page_get_flags(addr);
570 }
571 if (real_end == real_start + qemu_host_page_size) {
572 for (addr = end; addr < real_end; addr += TARGET_PAGE_SIZE) {
573 prot |= page_get_flags(addr);
574 }
575 end = real_end;
576 }
577 if (prot != 0)
578 real_start += qemu_host_page_size;
579 }
580 if (end < real_end) {
581 prot = 0;
582 for (addr = end; addr < real_end; addr += TARGET_PAGE_SIZE) {
583 prot |= page_get_flags(addr);
584 }
585 if (prot != 0)
586 real_end -= qemu_host_page_size;
587 }
588 if (real_start != real_end) {
589 mmap(g2h(real_start), real_end - real_start, PROT_NONE,
590 MAP_FIXED | MAP_ANONYMOUS | MAP_PRIVATE | MAP_NORESERVE,
591 -1, 0);
592 }
593 }
594
595 int target_munmap(abi_ulong start, abi_ulong len)
596 {
597 abi_ulong end, real_start, real_end, addr;
598 int prot, ret;
599
600 #ifdef DEBUG_MMAP
601 printf("munmap: start=0x" TARGET_ABI_FMT_lx " len=0x"
602 TARGET_ABI_FMT_lx "\n",
603 start, len);
604 #endif
605 if (start & ~TARGET_PAGE_MASK)
606 return -TARGET_EINVAL;
607 len = TARGET_PAGE_ALIGN(len);
608 if (len == 0 || !guest_range_valid(start, len)) {
609 return -TARGET_EINVAL;
610 }
611
612 mmap_lock();
613 end = start + len;
614 real_start = start & qemu_host_page_mask;
615 real_end = HOST_PAGE_ALIGN(end);
616
617 if (start > real_start) {
618 /* handle host page containing start */
619 prot = 0;
620 for(addr = real_start; addr < start; addr += TARGET_PAGE_SIZE) {
621 prot |= page_get_flags(addr);
622 }
623 if (real_end == real_start + qemu_host_page_size) {
624 for(addr = end; addr < real_end; addr += TARGET_PAGE_SIZE) {
625 prot |= page_get_flags(addr);
626 }
627 end = real_end;
628 }
629 if (prot != 0)
630 real_start += qemu_host_page_size;
631 }
632 if (end < real_end) {
633 prot = 0;
634 for(addr = end; addr < real_end; addr += TARGET_PAGE_SIZE) {
635 prot |= page_get_flags(addr);
636 }
637 if (prot != 0)
638 real_end -= qemu_host_page_size;
639 }
640
641 ret = 0;
642 /* unmap what we can */
643 if (real_start < real_end) {
644 if (reserved_va) {
645 mmap_reserve(real_start, real_end - real_start);
646 } else {
647 ret = munmap(g2h(real_start), real_end - real_start);
648 }
649 }
650
651 if (ret == 0) {
652 page_set_flags(start, start + len, 0);
653 tb_invalidate_phys_range(start, start + len);
654 }
655 mmap_unlock();
656 return ret;
657 }
658
659 abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size,
660 abi_ulong new_size, unsigned long flags,
661 abi_ulong new_addr)
662 {
663 int prot;
664 void *host_addr;
665
666 if (!guest_range_valid(old_addr, old_size) ||
667 ((flags & MREMAP_FIXED) &&
668 !guest_range_valid(new_addr, new_size))) {
669 errno = ENOMEM;
670 return -1;
671 }
672
673 mmap_lock();
674
675 if (flags & MREMAP_FIXED) {
676 host_addr = mremap(g2h(old_addr), old_size, new_size,
677 flags, g2h(new_addr));
678
679 if (reserved_va && host_addr != MAP_FAILED) {
680 /* If new and old addresses overlap then the above mremap will
681 already have failed with EINVAL. */
682 mmap_reserve(old_addr, old_size);
683 }
684 } else if (flags & MREMAP_MAYMOVE) {
685 abi_ulong mmap_start;
686
687 mmap_start = mmap_find_vma(0, new_size, TARGET_PAGE_SIZE);
688
689 if (mmap_start == -1) {
690 errno = ENOMEM;
691 host_addr = MAP_FAILED;
692 } else {
693 host_addr = mremap(g2h(old_addr), old_size, new_size,
694 flags | MREMAP_FIXED, g2h(mmap_start));
695 if (reserved_va) {
696 mmap_reserve(old_addr, old_size);
697 }
698 }
699 } else {
700 int prot = 0;
701 if (reserved_va && old_size < new_size) {
702 abi_ulong addr;
703 for (addr = old_addr + old_size;
704 addr < old_addr + new_size;
705 addr++) {
706 prot |= page_get_flags(addr);
707 }
708 }
709 if (prot == 0) {
710 host_addr = mremap(g2h(old_addr), old_size, new_size, flags);
711 if (host_addr != MAP_FAILED && reserved_va && old_size > new_size) {
712 mmap_reserve(old_addr + old_size, new_size - old_size);
713 }
714 } else {
715 errno = ENOMEM;
716 host_addr = MAP_FAILED;
717 }
718 /* Check if address fits target address space */
719 if ((unsigned long)host_addr + new_size > (abi_ulong)-1) {
720 /* Revert mremap() changes */
721 host_addr = mremap(g2h(old_addr), new_size, old_size, flags);
722 errno = ENOMEM;
723 host_addr = MAP_FAILED;
724 }
725 }
726
727 if (host_addr == MAP_FAILED) {
728 new_addr = -1;
729 } else {
730 new_addr = h2g(host_addr);
731 prot = page_get_flags(old_addr);
732 page_set_flags(old_addr, old_addr + old_size, 0);
733 page_set_flags(new_addr, new_addr + new_size, prot | PAGE_VALID);
734 }
735 tb_invalidate_phys_range(new_addr, new_addr + new_size);
736 mmap_unlock();
737 return new_addr;
738 }