0006-qemu-Add-some-user-space-mmap-tweaks-to-address-musl.patch 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. From 375cae3dd6151ef33cae8f243f6a2c2da6c0c356 Mon Sep 17 00:00:00 2001
  2. From: Richard Purdie <richard.purdie@linuxfoundation.org>
  3. Date: Fri, 8 Jan 2021 17:27:06 +0000
  4. Subject: [PATCH 06/12] qemu: Add some user space mmap tweaks to address musl
  5. 32 bit
  6. When using qemu-i386 to build qemux86 webkitgtk on musl, it sits in an
  7. infinite loop of mremap calls of ever decreasing/increasing addresses.
  8. I suspect something in the musl memory allocation code loops indefinitely
  9. if it only sees ENOMEM and only exits when it hits EFAULT.
  10. According to the docs, trying to mremap outside the address space
  11. can/should return EFAULT and changing this allows the build to succeed.
  12. A better return value for the other cases of invalid addresses is EINVAL
  13. rather than ENOMEM so adjust the other part of the test to this.
  14. Upstream-Status: Submitted [https://lists.gnu.org/archive/html/qemu-devel/2021-01/msg01355.html]
  15. Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org
  16. ---
  17. linux-user/mmap.c | 10 +++++++---
  18. 1 file changed, 7 insertions(+), 3 deletions(-)
  19. diff --git a/linux-user/mmap.c b/linux-user/mmap.c
  20. index c125031b9..e651834a5 100644
  21. --- a/linux-user/mmap.c
  22. +++ b/linux-user/mmap.c
  23. @@ -749,12 +749,16 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size,
  24. int prot;
  25. void *host_addr;
  26. - if (!guest_range_valid_untagged(old_addr, old_size) ||
  27. - ((flags & MREMAP_FIXED) &&
  28. + if (!guest_range_valid_untagged(old_addr, old_size)) {
  29. + errno = EFAULT;
  30. + return -1;
  31. + }
  32. +
  33. + if (((flags & MREMAP_FIXED) &&
  34. !guest_range_valid_untagged(new_addr, new_size)) ||
  35. ((flags & MREMAP_MAYMOVE) == 0 &&
  36. !guest_range_valid_untagged(old_addr, new_size))) {
  37. - errno = ENOMEM;
  38. + errno = EINVAL;
  39. return -1;
  40. }
  41. --
  42. 2.30.2