-#if defined(__alpha__) || defined(__sparc__)
- /* tell the kenel to search at the same place as i386 */
- if (host_start == 0)
- host_start = 0x40000000;
-#endif
- if (host_page_size != real_host_page_size) {
- /* NOTE: this code is only for debugging with '-p' option */
- /* reserve a memory area */
- host_len = HOST_PAGE_ALIGN(len) + host_page_size - TARGET_PAGE_SIZE;
- host_start = (long)mmap((void *)host_start, host_len, PROT_NONE,
- MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
- if (host_start == -1)
- return host_start;
- host_end = host_start + host_len;
- start = HOST_PAGE_ALIGN(host_start);
- end = start + HOST_PAGE_ALIGN(len);
- if (start > host_start)
- munmap((void *)host_start, start - host_start);
- if (end < host_end)
- munmap((void *)end, host_end - end);
- /* use it as a fixed mapping */
- flags |= MAP_FIXED;
- } else {
- /* if not fixed, no need to do anything */
- host_offset = offset & host_page_mask;
- host_len = len + offset - host_offset;
- start = (long)mmap((void *)host_start, host_len,
- prot, flags, fd, host_offset);
- if (start == -1)
- return start;
- /* update start so that it points to the file position at 'offset' */
- if (!(flags & MAP_ANONYMOUS))
- start += offset - host_offset;
- goto the_end1;
+ abi_ulong mmap_start;
+ void *p;
+ host_offset = offset & qemu_host_page_mask;
+ host_len = len + offset - host_offset;
+ host_len = HOST_PAGE_ALIGN(host_len);
+ mmap_start = mmap_find_vma(real_start, host_len);
+ if (mmap_start == (abi_ulong)-1) {
+ errno = ENOMEM;
+ return -1;