Andrew Geissler | d583833 | 2022-05-27 11:33:10 -0500 | [diff] [blame] | 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 | |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 7 | When using qemu-i386 to build qemux86 webkitgtk on musl, it sits in an |
| 8 | infinite loop of mremap calls of ever decreasing/increasing addresses. |
| 9 | |
| 10 | I suspect something in the musl memory allocation code loops indefinitely |
| 11 | if it only sees ENOMEM and only exits when it hits EFAULT. |
| 12 | |
| 13 | According to the docs, trying to mremap outside the address space |
| 14 | can/should return EFAULT and changing this allows the build to succeed. |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 15 | |
Andrew Geissler | 9b4d8b0 | 2021-02-19 12:26:16 -0600 | [diff] [blame] | 16 | A better return value for the other cases of invalid addresses is EINVAL |
| 17 | rather than ENOMEM so adjust the other part of the test to this. |
| 18 | |
| 19 | 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] | 20 | Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org |
| 21 | |
Andrew Geissler | d583833 | 2022-05-27 11:33:10 -0500 | [diff] [blame] | 22 | --- |
| 23 | linux-user/mmap.c | 10 +++++++--- |
| 24 | 1 file changed, 7 insertions(+), 3 deletions(-) |
| 25 | |
| 26 | diff --git a/linux-user/mmap.c b/linux-user/mmap.c |
| 27 | index c125031b9..e651834a5 100644 |
| 28 | --- a/linux-user/mmap.c |
| 29 | +++ b/linux-user/mmap.c |
| 30 | @@ -749,12 +749,16 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size, |
Andrew Geissler | 9b4d8b0 | 2021-02-19 12:26:16 -0600 | [diff] [blame] | 31 | int prot; |
| 32 | void *host_addr; |
| 33 | |
William A. Kennington III | ac69b48 | 2021-06-02 12:28:27 -0700 | [diff] [blame] | 34 | - if (!guest_range_valid_untagged(old_addr, old_size) || |
Andrew Geissler | 9b4d8b0 | 2021-02-19 12:26:16 -0600 | [diff] [blame] | 35 | - ((flags & MREMAP_FIXED) && |
William A. Kennington III | ac69b48 | 2021-06-02 12:28:27 -0700 | [diff] [blame] | 36 | + if (!guest_range_valid_untagged(old_addr, old_size)) { |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 37 | + errno = EFAULT; |
Andrew Geissler | 9b4d8b0 | 2021-02-19 12:26:16 -0600 | [diff] [blame] | 38 | + return -1; |
| 39 | + } |
William A. Kennington III | ac69b48 | 2021-06-02 12:28:27 -0700 | [diff] [blame] | 40 | + |
| 41 | + if (((flags & MREMAP_FIXED) && |
| 42 | !guest_range_valid_untagged(new_addr, new_size)) || |
| 43 | ((flags & MREMAP_MAYMOVE) == 0 && |
| 44 | !guest_range_valid_untagged(old_addr, new_size))) { |
| 45 | - errno = ENOMEM; |
Andrew Geissler | 9b4d8b0 | 2021-02-19 12:26:16 -0600 | [diff] [blame] | 46 | + errno = EINVAL; |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 47 | return -1; |
| 48 | } |
| 49 | |
Andrew Geissler | d583833 | 2022-05-27 11:33:10 -0500 | [diff] [blame] | 50 | -- |
| 51 | 2.30.2 |
| 52 | |