blob: 7e273eecede976aa4dd0a7ee2dc023f8c080eba1 [file] [log] [blame]
Andrew Geissler82c905d2020-04-13 13:39:40 -05001From 613166007e3b852c99caf2cd34a972e2c8460737 Mon Sep 17 00:00:00 2001
Brad Bishopc68388fc2019-08-26 01:33:31 -04002From: Martin Jansa <martin.jansa@lge.com>
3Date: Fri, 1 Jun 2018 08:41:07 +0000
4Subject: [PATCH] Fix webkitgtk builds
5
6This is a partial revert of "linux-user: fix mmap/munmap/mprotect/mremap/shmat".
7
8This patch fixes qemu-i386 hangs during gobject-introspection in webkitgtk build
9when musl is used on qemux86. This is the same issue that
100008-linux-user-Fix-webkitgtk-hangs-on-32-bit-x86-target.patch was
11fixing in the 2.11 release.
12
13This patch also fixes a build failure when building webkitgtk for
14qemumips. A QEMU assert is seen while building webkitgtk:
15page_check_range: Assertion `start < ((target_ulong)1 << L1_MAP_ADDR_SPACE_BITS)' failed.
16
17This reverts commit ebf9a3630c911d0cfc9c20f7cafe9ba4f88cf583.
18
19Upstream-Status: Pending
20Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
Andrew Geissler82c905d2020-04-13 13:39:40 -050021
Brad Bishopc68388fc2019-08-26 01:33:31 -040022---
23 include/exec/cpu-all.h | 6 +-----
24 include/exec/cpu_ldst.h | 5 ++++-
25 linux-user/mmap.c | 17 ++++-------------
26 linux-user/syscall.c | 5 +----
27 4 files changed, 10 insertions(+), 23 deletions(-)
28
29diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h
Andrew Geissler82c905d2020-04-13 13:39:40 -050030index e96781a4..a369f81a 100644
Brad Bishopc68388fc2019-08-26 01:33:31 -040031--- a/include/exec/cpu-all.h
32+++ b/include/exec/cpu-all.h
33@@ -162,12 +162,8 @@ extern unsigned long guest_base;
34 extern int have_guest_base;
35 extern unsigned long reserved_va;
36
37-#if HOST_LONG_BITS <= TARGET_VIRT_ADDR_SPACE_BITS
38-#define GUEST_ADDR_MAX (~0ul)
39-#else
40-#define GUEST_ADDR_MAX (reserved_va ? reserved_va - 1 : \
41+#define GUEST_ADDR_MAX (reserved_va ? reserved_va : \
42 (1ul << TARGET_VIRT_ADDR_SPACE_BITS) - 1)
43-#endif
44 #else
45
46 #include "exec/hwaddr.h"
47diff --git a/include/exec/cpu_ldst.h b/include/exec/cpu_ldst.h
Andrew Geissler82c905d2020-04-13 13:39:40 -050048index fd499f7e..30575f60 100644
Brad Bishopc68388fc2019-08-26 01:33:31 -040049--- a/include/exec/cpu_ldst.h
50+++ b/include/exec/cpu_ldst.h
51@@ -65,7 +65,10 @@ typedef uint64_t abi_ptr;
52 #if HOST_LONG_BITS <= TARGET_VIRT_ADDR_SPACE_BITS
53 #define guest_addr_valid(x) (1)
54 #else
55-#define guest_addr_valid(x) ((x) <= GUEST_ADDR_MAX)
56+#define guest_addr_valid(x) ({ \
57+ ((x) < (1ul << TARGET_VIRT_ADDR_SPACE_BITS)) && \
58+ (!reserved_va || ((x) < reserved_va)); \
59+})
60 #endif
61 #define h2g_valid(x) guest_addr_valid((unsigned long)(x) - guest_base)
62
63diff --git a/linux-user/mmap.c b/linux-user/mmap.c
Andrew Geissler82c905d2020-04-13 13:39:40 -050064index 46a6e3a7..77354654 100644
Brad Bishopc68388fc2019-08-26 01:33:31 -040065--- a/linux-user/mmap.c
66+++ b/linux-user/mmap.c
67@@ -78,7 +78,7 @@ int target_mprotect(abi_ulong start, abi_ulong len, int prot)
68 return -TARGET_EINVAL;
69 len = TARGET_PAGE_ALIGN(len);
70 end = start + len;
71- if (!guest_range_valid(start, len)) {
72+ if (end < start) {
73 return -TARGET_ENOMEM;
74 }
75 prot &= PROT_READ | PROT_WRITE | PROT_EXEC;
76@@ -495,8 +495,8 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot,
77 * It can fail only on 64-bit host with 32-bit target.
78 * On any other target/host host mmap() handles this error correctly.
79 */
80- if (!guest_range_valid(start, len)) {
81- errno = ENOMEM;
82+ if ((unsigned long)start + len - 1 > (abi_ulong) -1) {
83+ errno = EINVAL;
84 goto fail;
85 }
86
87@@ -636,10 +636,8 @@ int target_munmap(abi_ulong start, abi_ulong len)
88 if (start & ~TARGET_PAGE_MASK)
89 return -TARGET_EINVAL;
90 len = TARGET_PAGE_ALIGN(len);
91- if (len == 0 || !guest_range_valid(start, len)) {
92+ if (len == 0)
93 return -TARGET_EINVAL;
94- }
95-
96 mmap_lock();
97 end = start + len;
98 real_start = start & qemu_host_page_mask;
99@@ -694,13 +692,6 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size,
100 int prot;
101 void *host_addr;
102
103- if (!guest_range_valid(old_addr, old_size) ||
104- ((flags & MREMAP_FIXED) &&
105- !guest_range_valid(new_addr, new_size))) {
106- errno = ENOMEM;
107- return -1;
108- }
109-
110 mmap_lock();
111
112 if (flags & MREMAP_FIXED) {
113diff --git a/linux-user/syscall.c b/linux-user/syscall.c
Andrew Geissler82c905d2020-04-13 13:39:40 -0500114index 171c0cae..fc18f244 100644
Brad Bishopc68388fc2019-08-26 01:33:31 -0400115--- a/linux-user/syscall.c
116+++ b/linux-user/syscall.c
Andrew Geissler82c905d2020-04-13 13:39:40 -0500117@@ -4138,9 +4138,6 @@ static inline abi_ulong do_shmat(CPUArchState *cpu_env,
Brad Bishopc68388fc2019-08-26 01:33:31 -0400118 return -TARGET_EINVAL;
119 }
120 }
121- if (!guest_range_valid(shmaddr, shm_info.shm_segsz)) {
122- return -TARGET_EINVAL;
123- }
124
125 mmap_lock();
126
Andrew Geissler82c905d2020-04-13 13:39:40 -0500127@@ -6990,7 +6987,7 @@ static int open_self_maps(void *cpu_env, int fd)
Brad Bishopc68388fc2019-08-26 01:33:31 -0400128 }
129 if (h2g_valid(min)) {
130 int flags = page_get_flags(h2g(min));
131- max = h2g_valid(max - 1) ? max : (uintptr_t)g2h(GUEST_ADDR_MAX) + 1;
132+ max = h2g_valid(max - 1) ? max : (uintptr_t)g2h(GUEST_ADDR_MAX);
133 if (page_check_range(h2g(min), max - min, flags) == -1) {
134 continue;
135 }