Skip to content

Commit 930dcd2

Browse files
committed
get mmap.c to compile
1 parent 19069e7 commit 930dcd2

File tree

2 files changed

+85
-69
lines changed

2 files changed

+85
-69
lines changed

darwin-user/Makefile.objs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
obj-y = main.o syscall.o strace.o mmap.o signal.o \
22
elfload.o linuxload.o uaccess.o uname.o \
3-
safe-syscall.o
3+
safe-syscall.o \
4+
shim_fallocate.o shim_gettid.o shim_timers.o
45

56
obj-$(TARGET_HAS_BFLT) += flatload.o
67
obj-$(TARGET_I386) += vm86.o

darwin-user/mmap.c

Lines changed: 83 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@
2424

2525
//#define DEBUG_MMAP
2626

27+
/** macOS does not define this mask for the sharing type and options
28+
* this both matches the flag in linux, and works with macOS
29+
*/
30+
#define MAP_TYPE 0x000f
31+
2732
static pthread_mutex_t mmap_mutex = PTHREAD_MUTEX_INITIALIZER;
2833
static __thread int mmap_lock_count;
2934

@@ -671,79 +676,89 @@ int target_munmap(abi_ulong start, abi_ulong len)
671676
return ret;
672677
}
673678

679+
/** macOS/darwin does not have mremap. It is possible that (parts?) of
680+
* of this syscall could be emualted, but it is not necessary for Irix
681+
* https://ipads.se.sjtu.edu.cn:1312/opensource/powerlyra/commit/e226dc04639692b57fcaf666cf4006498c48f516
682+
*/
674683
abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size,
675684
abi_ulong new_size, unsigned long flags,
676685
abi_ulong new_addr)
677686
{
678-
int prot;
679-
void *host_addr;
680-
681-
mmap_lock();
682-
683-
if (flags & MREMAP_FIXED) {
684-
host_addr = mremap(g2h(old_addr), old_size, new_size,
685-
flags, g2h(new_addr));
686-
687-
if (reserved_va && host_addr != MAP_FAILED) {
688-
/* If new and old addresses overlap then the above mremap will
689-
already have failed with EINVAL. */
690-
mmap_reserve(old_addr, old_size);
691-
}
692-
} else if (flags & MREMAP_MAYMOVE) {
693-
abi_ulong mmap_start;
694-
695-
mmap_start = mmap_find_vma(0, new_size);
696-
697-
if (mmap_start == -1) {
698-
errno = ENOMEM;
699-
host_addr = MAP_FAILED;
700-
} else {
701-
host_addr = mremap(g2h(old_addr), old_size, new_size,
702-
flags | MREMAP_FIXED, g2h(mmap_start));
703-
if (reserved_va) {
704-
mmap_reserve(old_addr, old_size);
705-
}
706-
}
707-
} else {
708-
int prot = 0;
709-
if (reserved_va && old_size < new_size) {
710-
abi_ulong addr;
711-
for (addr = old_addr + old_size;
712-
addr < old_addr + new_size;
713-
addr++) {
714-
prot |= page_get_flags(addr);
715-
}
716-
}
717-
if (prot == 0) {
718-
host_addr = mremap(g2h(old_addr), old_size, new_size, flags);
719-
if (host_addr != MAP_FAILED && reserved_va && old_size > new_size) {
720-
mmap_reserve(old_addr + old_size, new_size - old_size);
721-
}
722-
} else {
723-
errno = ENOMEM;
724-
host_addr = MAP_FAILED;
725-
}
726-
/* Check if address fits target address space */
727-
if ((unsigned long)host_addr + new_size > (abi_ulong)-1) {
728-
/* Revert mremap() changes */
729-
host_addr = mremap(g2h(old_addr), new_size, old_size, flags);
730-
errno = ENOMEM;
731-
host_addr = MAP_FAILED;
732-
}
733-
}
734-
735-
if (host_addr == MAP_FAILED) {
736-
new_addr = -1;
737-
} else {
738-
new_addr = h2g(host_addr);
739-
prot = page_get_flags(old_addr);
740-
page_set_flags(old_addr, old_addr + old_size, 0);
741-
page_set_flags(new_addr, new_addr + new_size, prot | PAGE_VALID);
742-
}
743-
tb_invalidate_phys_range(new_addr, new_addr + new_size);
744-
mmap_unlock();
745-
return new_addr;
687+
return -1;
746688
}
689+
// abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size,
690+
// abi_ulong new_size, unsigned long flags,
691+
// abi_ulong new_addr)
692+
// {
693+
// int prot;
694+
// void *host_addr;
695+
//
696+
// mmap_lock();
697+
//
698+
// if (flags & MREMAP_FIXED) {
699+
// host_addr = mremap(g2h(old_addr), old_size, new_size,
700+
// flags, g2h(new_addr));
701+
//
702+
// if (reserved_va && host_addr != MAP_FAILED) {
703+
// /* If new and old addresses overlap then the above mremap will
704+
// already have failed with EINVAL. */
705+
// mmap_reserve(old_addr, old_size);
706+
// }
707+
// } else if (flags & MREMAP_MAYMOVE) {
708+
// abi_ulong mmap_start;
709+
//
710+
// mmap_start = mmap_find_vma(0, new_size);
711+
//
712+
// if (mmap_start == -1) {
713+
// errno = ENOMEM;
714+
// host_addr = MAP_FAILED;
715+
// } else {
716+
// host_addr = mremap(g2h(old_addr), old_size, new_size,
717+
// flags | MREMAP_FIXED, g2h(mmap_start));
718+
// if (reserved_va) {
719+
// mmap_reserve(old_addr, old_size);
720+
// }
721+
// }
722+
// } else {
723+
// int prot = 0;
724+
// if (reserved_va && old_size < new_size) {
725+
// abi_ulong addr;
726+
// for (addr = old_addr + old_size;
727+
// addr < old_addr + new_size;
728+
// addr++) {
729+
// prot |= page_get_flags(addr);
730+
// }
731+
// }
732+
// if (prot == 0) {
733+
// host_addr = mremap(g2h(old_addr), old_size, new_size, flags);
734+
// if (host_addr != MAP_FAILED && reserved_va && old_size > new_size) {
735+
// mmap_reserve(old_addr + old_size, new_size - old_size);
736+
// }
737+
// } else {
738+
// errno = ENOMEM;
739+
// host_addr = MAP_FAILED;
740+
// }
741+
// /* Check if address fits target address space */
742+
// if ((unsigned long)host_addr + new_size > (abi_ulong)-1) {
743+
// /* Revert mremap() changes */
744+
// host_addr = mremap(g2h(old_addr), new_size, old_size, flags);
745+
// errno = ENOMEM;
746+
// host_addr = MAP_FAILED;
747+
// }
748+
// }
749+
//
750+
// if (host_addr == MAP_FAILED) {
751+
// new_addr = -1;
752+
// } else {
753+
// new_addr = h2g(host_addr);
754+
// prot = page_get_flags(old_addr);
755+
// page_set_flags(old_addr, old_addr + old_size, 0);
756+
// page_set_flags(new_addr, new_addr + new_size, prot | PAGE_VALID);
757+
// }
758+
// tb_invalidate_phys_range(new_addr, new_addr + new_size);
759+
// mmap_unlock();
760+
// return new_addr;
761+
// }
747762

748763
int target_msync(abi_ulong start, abi_ulong len, int flags)
749764
{

0 commit comments

Comments
 (0)