blob: eef3f3f97f985b2b1a81ab2f59a7077e70c63d69 [file] [log] [blame]
Andrew Geisslerd25ed322020-06-27 00:28:28 -05001From 815c97ba0de02da9dace3fcfcbdf9b20e029f0d7 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
Andrew Geisslerd25ed322020-06-27 00:28:28 -050022[update patch context]
23Signed-off-by: Sakib Sajal <sakib.sajal@windriver.com>
Brad Bishopc68388fc2019-08-26 01:33:31 -040024---
25 include/exec/cpu-all.h | 6 +-----
26 include/exec/cpu_ldst.h | 5 ++++-
27 linux-user/mmap.c | 17 ++++-------------
28 linux-user/syscall.c | 5 +----
29 4 files changed, 10 insertions(+), 23 deletions(-)
30
31diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h
Andrew Geisslerd25ed322020-06-27 00:28:28 -050032index 49384bb6..93b12519 100644
Brad Bishopc68388fc2019-08-26 01:33:31 -040033--- a/include/exec/cpu-all.h
34+++ b/include/exec/cpu-all.h
35@@ -162,12 +162,8 @@ extern unsigned long guest_base;
36 extern int have_guest_base;
37 extern unsigned long reserved_va;
38
39-#if HOST_LONG_BITS <= TARGET_VIRT_ADDR_SPACE_BITS
40-#define GUEST_ADDR_MAX (~0ul)
41-#else
42-#define GUEST_ADDR_MAX (reserved_va ? reserved_va - 1 : \
43+#define GUEST_ADDR_MAX (reserved_va ? reserved_va : \
44 (1ul << TARGET_VIRT_ADDR_SPACE_BITS) - 1)
45-#endif
46 #else
47
48 #include "exec/hwaddr.h"
49diff --git a/include/exec/cpu_ldst.h b/include/exec/cpu_ldst.h
Andrew Geisslerd25ed322020-06-27 00:28:28 -050050index 53de1975..cf19ed2e 100644
Brad Bishopc68388fc2019-08-26 01:33:31 -040051--- a/include/exec/cpu_ldst.h
52+++ b/include/exec/cpu_ldst.h
Andrew Geisslerd25ed322020-06-27 00:28:28 -050053@@ -70,7 +70,10 @@ typedef uint64_t abi_ptr;
Brad Bishopc68388fc2019-08-26 01:33:31 -040054 #if HOST_LONG_BITS <= TARGET_VIRT_ADDR_SPACE_BITS
55 #define guest_addr_valid(x) (1)
56 #else
57-#define guest_addr_valid(x) ((x) <= GUEST_ADDR_MAX)
58+#define guest_addr_valid(x) ({ \
59+ ((x) < (1ul << TARGET_VIRT_ADDR_SPACE_BITS)) && \
60+ (!reserved_va || ((x) < reserved_va)); \
61+})
62 #endif
63 #define h2g_valid(x) guest_addr_valid((unsigned long)(x) - guest_base)
64
65diff --git a/linux-user/mmap.c b/linux-user/mmap.c
Andrew Geisslerd25ed322020-06-27 00:28:28 -050066index e3780337..1d4aba95 100644
Brad Bishopc68388fc2019-08-26 01:33:31 -040067--- a/linux-user/mmap.c
68+++ b/linux-user/mmap.c
Andrew Geisslerd25ed322020-06-27 00:28:28 -050069@@ -71,7 +71,7 @@ int target_mprotect(abi_ulong start, abi_ulong len, int prot)
Brad Bishopc68388fc2019-08-26 01:33:31 -040070 return -TARGET_EINVAL;
71 len = TARGET_PAGE_ALIGN(len);
72 end = start + len;
73- if (!guest_range_valid(start, len)) {
74+ if (end < start) {
75 return -TARGET_ENOMEM;
76 }
77 prot &= PROT_READ | PROT_WRITE | PROT_EXEC;
Andrew Geisslerd25ed322020-06-27 00:28:28 -050078@@ -467,8 +467,8 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot,
Brad Bishopc68388fc2019-08-26 01:33:31 -040079 * It can fail only on 64-bit host with 32-bit target.
80 * On any other target/host host mmap() handles this error correctly.
81 */
82- if (!guest_range_valid(start, len)) {
83- errno = ENOMEM;
84+ if ((unsigned long)start + len - 1 > (abi_ulong) -1) {
85+ errno = EINVAL;
86 goto fail;
87 }
88
Andrew Geisslerd25ed322020-06-27 00:28:28 -050089@@ -604,10 +604,8 @@ int target_munmap(abi_ulong start, abi_ulong len)
Brad Bishopc68388fc2019-08-26 01:33:31 -040090 if (start & ~TARGET_PAGE_MASK)
91 return -TARGET_EINVAL;
92 len = TARGET_PAGE_ALIGN(len);
93- if (len == 0 || !guest_range_valid(start, len)) {
94+ if (len == 0)
95 return -TARGET_EINVAL;
96- }
97-
98 mmap_lock();
99 end = start + len;
100 real_start = start & qemu_host_page_mask;
Andrew Geisslerd25ed322020-06-27 00:28:28 -0500101@@ -662,13 +660,6 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size,
Brad Bishopc68388fc2019-08-26 01:33:31 -0400102 int prot;
103 void *host_addr;
104
105- if (!guest_range_valid(old_addr, old_size) ||
106- ((flags & MREMAP_FIXED) &&
107- !guest_range_valid(new_addr, new_size))) {
108- errno = ENOMEM;
109- return -1;
110- }
111-
112 mmap_lock();
113
114 if (flags & MREMAP_FIXED) {
115diff --git a/linux-user/syscall.c b/linux-user/syscall.c
Andrew Geisslerd25ed322020-06-27 00:28:28 -0500116index 05f03919..d6f8cc97 100644
Brad Bishopc68388fc2019-08-26 01:33:31 -0400117--- a/linux-user/syscall.c
118+++ b/linux-user/syscall.c
Andrew Geisslerd25ed322020-06-27 00:28:28 -0500119@@ -4287,9 +4287,6 @@ static inline abi_ulong do_shmat(CPUArchState *cpu_env,
Brad Bishopc68388fc2019-08-26 01:33:31 -0400120 return -TARGET_EINVAL;
121 }
122 }
123- if (!guest_range_valid(shmaddr, shm_info.shm_segsz)) {
124- return -TARGET_EINVAL;
125- }
126
127 mmap_lock();
128
Andrew Geisslerd25ed322020-06-27 00:28:28 -0500129@@ -7247,7 +7244,7 @@ static int open_self_maps(void *cpu_env, int fd)
130 const char *path;
131
132 max = h2g_valid(max - 1) ?
133- max : (uintptr_t) g2h(GUEST_ADDR_MAX) + 1;
134+ max : (uintptr_t) g2h(GUEST_ADDR_MAX);
135
Brad Bishopc68388fc2019-08-26 01:33:31 -0400136 if (page_check_range(h2g(min), max - min, flags) == -1) {
137 continue;
Andrew Geisslerd25ed322020-06-27 00:28:28 -0500138--
1392.24.0
140