mmap2.patch 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. When using qemu-i386 to build qemux86 webkitgtk on musl, it sits in an
  2. infinite loop of mremap calls of ever decreasing/increasing addresses.
  3. I suspect something in the musl memory allocation code loops indefinitely
  4. if it only sees ENOMEM and only exits when it hits EFAULT.
  5. According to the docs, trying to mremap outside the address space
  6. can/should return EFAULT and changing this allows the build to succeed.
  7. A better return value for the other cases of invalid addresses is EINVAL
  8. rather than ENOMEM so adjust the other part of the test to this.
  9. Upstream-Status: Submitted [https://lists.gnu.org/archive/html/qemu-devel/2021-01/msg01355.html]
  10. Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org
  11. Index: qemu-6.0.0/linux-user/mmap.c
  12. ===================================================================
  13. --- qemu-6.0.0.orig/linux-user/mmap.c
  14. +++ qemu-6.0.0/linux-user/mmap.c
  15. @@ -733,12 +733,16 @@ abi_long target_mremap(abi_ulong old_add
  16. int prot;
  17. void *host_addr;
  18. - if (!guest_range_valid_untagged(old_addr, old_size) ||
  19. - ((flags & MREMAP_FIXED) &&
  20. + if (!guest_range_valid_untagged(old_addr, old_size)) {
  21. + errno = EFAULT;
  22. + return -1;
  23. + }
  24. +
  25. + if (((flags & MREMAP_FIXED) &&
  26. !guest_range_valid_untagged(new_addr, new_size)) ||
  27. ((flags & MREMAP_MAYMOVE) == 0 &&
  28. !guest_range_valid_untagged(old_addr, new_size))) {
  29. - errno = ENOMEM;
  30. + errno = EINVAL;
  31. return -1;
  32. }