From c12b76a0eb9445ae36db371bd3c763c884d4869f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=BCrgen=20Buchm=C3=BCller?= <pullmoll@t-online.de>
Date: Sun, 30 Jun 2019 17:53:10 +0200
Subject: [PATCH 1/3] qemu: fix mremap(2) errno codes

[ci skip]
---
 srcpkgs/qemu/patches/mmap-mremap-efault.patch | 41 +++++++++++++++++++
 srcpkgs/qemu/template                         |  2 +-
 2 files changed, 42 insertions(+), 1 deletion(-)
 create mode 100644 srcpkgs/qemu/patches/mmap-mremap-efault.patch

diff --git a/srcpkgs/qemu/patches/mmap-mremap-efault.patch b/srcpkgs/qemu/patches/mmap-mremap-efault.patch
new file mode 100644
index 00000000000..a5eaa7906c8
--- /dev/null
+++ b/srcpkgs/qemu/patches/mmap-mremap-efault.patch
@@ -0,0 +1,41 @@
+Source: @pullmoll
+Upstream: no
+Reason: errno=EFAULT when the address passed to mremap(2) is not valid
+
+See Rich Felker's comment at https://www.openwall.com/lists/musl/2017/06/21/2 for
+why we need to return errno as described in man mremap(2) from qemu-user-static.
+Also speed up the loop when checking for increasing the mappings size to go
+in steps of TARGET_PAGE_SIZE and OR-in a check for the very last byte of the range.
+
+--- linux-user/mmap.c	2019-04-23 20:14:46.000000000 +0200
++++ linux-user/mmap.c	2019-06-30 16:31:26.545637450 +0200
+@@ -692,7 +692,7 @@
+     if (!guest_range_valid(old_addr, old_size) ||
+         ((flags & MREMAP_FIXED) &&
+          !guest_range_valid(new_addr, new_size))) {
+-        errno = ENOMEM;
++        errno = EFAULT;
+         return -1;
+     }
+ 
+@@ -728,9 +728,10 @@
+             abi_ulong addr;
+             for (addr = old_addr + old_size;
+                  addr < old_addr + new_size;
+-                 addr++) {
++                 addr += TARGET_PAGE_SIZE) {
+                 prot |= page_get_flags(addr);
+             }
++            prot |= page_get_flags(old_addr + new_size - 1);
+         }
+         if (prot == 0) {
+             host_addr = mremap(g2h(old_addr), old_size, new_size, flags);
+@@ -738,7 +739,7 @@
+                 mmap_reserve(old_addr + old_size, new_size - old_size);
+             }
+         } else {
+-            errno = ENOMEM;
++            errno = EFAULT;
+             host_addr = MAP_FAILED;
+         }
+         /* Check if address fits target address space */
diff --git a/srcpkgs/qemu/template b/srcpkgs/qemu/template
index 0b2ab2ee7da..3dc198185ad 100644
--- a/srcpkgs/qemu/template
+++ b/srcpkgs/qemu/template
@@ -1,7 +1,7 @@
 # Template file for 'qemu'
 pkgname=qemu
 version=4.0.0
-revision=3
+revision=4
 short_desc="Open Source Processor Emulator"
 maintainer="Juan RP <xtraeme@voidlinux.org>"
 license="GPL-2.0-or-later, LGPL-2.1-or-later"

From ccebb850319950ab5b8d8491ffa7ba56d107fa2e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=BCrgen=20Buchm=C3=BCller?= <pullmoll@t-online.de>
Date: Sun, 30 Jun 2019 17:19:18 +0200
Subject: [PATCH 2/3] qemu-user-static: fix mremap(2) errno codes

This fixes #11426

[ci skip]
---
 srcpkgs/qemu-user-static/template | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/srcpkgs/qemu-user-static/template b/srcpkgs/qemu-user-static/template
index 6abbb10875b..9b587f1f71e 100644
--- a/srcpkgs/qemu-user-static/template
+++ b/srcpkgs/qemu-user-static/template
@@ -1,7 +1,7 @@
 # Template file for 'qemu-user-static'
 pkgname=qemu-user-static
 version=4.0.0
-revision=1
+revision=2
 wrksrc="qemu-${version}"
 hostmakedepends="pkg-config automake python"
 makedepends="dtc-devel libglib-static pixman-devel libuuid-devel"

From acf65971b5c4b6005bc4925a07576253ce47de76 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=BCrgen=20Buchm=C3=BCller?= <pullmoll@t-online.de>
Date: Sun, 30 Jun 2019 17:21:32 +0200
Subject: [PATCH 3/3] webkit2gtk: enable gir for all targets

[ci skip]
---
 srcpkgs/webkit2gtk/template | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)

diff --git a/srcpkgs/webkit2gtk/template b/srcpkgs/webkit2gtk/template
index eb6d61e8c29..9918fd28639 100644
--- a/srcpkgs/webkit2gtk/template
+++ b/srcpkgs/webkit2gtk/template
@@ -36,14 +36,7 @@ CXXFLAGS="-Wno-expansion-to-defined"
 
 # Package build options
 build_options="gir wayland x11 jit sampling_profiler"
-build_options_default="wayland x11"
-
-case "$XBPS_TARGET_MACHINE" in
-	arm*-musl) # cross building hangs for hours in g-ir-scanner-qemuwrapper
-		broken="cross compiling from x86_64 to arm*-musl stalls the builders"
-		;;
-	*) build_options_default+=" gir"
-esac
+build_options_default="gir wayland x11"
 
 desc_option_jit="Enable JustInTime JS support"
 desc_option_sampling_profiler="Toggle sampling profiler support (disabled on musl)"
