Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 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 | |
| 4 | I suspect something in the musl memory allocation code loops indefinitely |
| 5 | if it only sees ENOMEM and only exits when it hits EFAULT. |
| 6 | |
| 7 | According to the docs, trying to mremap outside the address space |
| 8 | can/should return EFAULT and changing this allows the build to succeed. |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 9 | |
Andrew Geissler | 9b4d8b0 | 2021-02-19 12:26:16 -0600 | [diff] [blame] | 10 | A better return value for the other cases of invalid addresses is EINVAL |
| 11 | rather than ENOMEM so adjust the other part of the test to this. |
| 12 | |
| 13 | Upstream-Status: Submitted [https://lists.gnu.org/archive/html/qemu-devel/2021-01/msg01355.html] |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 14 | Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org |
| 15 | |
| 16 | Index: qemu-5.2.0/linux-user/mmap.c |
| 17 | =================================================================== |
| 18 | --- qemu-5.2.0.orig/linux-user/mmap.c |
| 19 | +++ qemu-5.2.0/linux-user/mmap.c |
Andrew Geissler | 9b4d8b0 | 2021-02-19 12:26:16 -0600 | [diff] [blame] | 20 | @@ -722,12 +722,14 @@ abi_long target_mremap(abi_ulong old_add |
| 21 | int prot; |
| 22 | void *host_addr; |
| 23 | |
| 24 | - if (!guest_range_valid(old_addr, old_size) || |
| 25 | - ((flags & MREMAP_FIXED) && |
| 26 | - !guest_range_valid(new_addr, new_size)) || |
| 27 | - ((flags & MREMAP_MAYMOVE) == 0 && |
| 28 | - !guest_range_valid(old_addr, new_size))) { |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 29 | - errno = ENOMEM; |
Andrew Geissler | 9b4d8b0 | 2021-02-19 12:26:16 -0600 | [diff] [blame] | 30 | + if (!guest_range_valid(old_addr, old_size)) { |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 31 | + errno = EFAULT; |
Andrew Geissler | 9b4d8b0 | 2021-02-19 12:26:16 -0600 | [diff] [blame] | 32 | + return -1; |
| 33 | + } |
| 34 | + |
| 35 | + if (((flags & MREMAP_FIXED) && !guest_range_valid(new_addr, new_size)) || |
| 36 | + ((flags & MREMAP_MAYMOVE) == 0 && !guest_range_valid(old_addr, new_size))) { |
| 37 | + errno = EINVAL; |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 38 | return -1; |
| 39 | } |
| 40 | |