blob: 1652131757bc3718dc375a59864a733ef6c72ede [file] [log] [blame]
Andrew Geisslerd1e89492021-02-12 15:35:20 -06001When using qemu-i386 to build qemux86 webkitgtk on musl, it sits in an
2infinite loop of mremap calls of ever decreasing/increasing addresses.
3
4I suspect something in the musl memory allocation code loops indefinitely
5if it only sees ENOMEM and only exits when it hits EFAULT.
6
7According to the docs, trying to mremap outside the address space
8can/should return EFAULT and changing this allows the build to succeed.
Andrew Geisslerd1e89492021-02-12 15:35:20 -06009
Andrew Geissler9b4d8b02021-02-19 12:26:16 -060010A better return value for the other cases of invalid addresses is EINVAL
11rather than ENOMEM so adjust the other part of the test to this.
12
13Upstream-Status: Submitted [https://lists.gnu.org/archive/html/qemu-devel/2021-01/msg01355.html]
Andrew Geisslerd1e89492021-02-12 15:35:20 -060014Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org
15
16Index: 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 Geissler9b4d8b02021-02-19 12:26:16 -060020@@ -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 Geisslerd1e89492021-02-12 15:35:20 -060029- errno = ENOMEM;
Andrew Geissler9b4d8b02021-02-19 12:26:16 -060030+ if (!guest_range_valid(old_addr, old_size)) {
Andrew Geisslerd1e89492021-02-12 15:35:20 -060031+ errno = EFAULT;
Andrew Geissler9b4d8b02021-02-19 12:26:16 -060032+ 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 Geisslerd1e89492021-02-12 15:35:20 -060038 return -1;
39 }
40