mirror of
https://github.com/izzy2lost/xemu.git
synced 2026-07-06 00:20:22 -07:00
Merge tag 'pull-lu-20231018' of https://gitlab.com/rth7680/qemu into staging
linux-user/mips: fix abort on integer overflow linux-user/sh4: Fix crashes on signal delivery linux-user/loongarch: Enable LSX/LASX in HWCAP linux-user: Fixes for zero_bss linux-user: Propagate failure in mmap_reserve_or_unmap back to target_munmap linux-user: Detect and report host crashes linux-user: Remap guest SIGABRT # -----BEGIN PGP SIGNATURE----- # # iQFRBAABCgA7FiEEekgeeIaLTbaoWgXAZN846K9+IV8FAmUwapYdHHJpY2hhcmQu # aGVuZGVyc29uQGxpbmFyby5vcmcACgkQZN846K9+IV92UAf/RSsFWwCBAqt1WKIK # 7/7F8AF7WW1Hhjy3bHLjNnzgsDeWYfdIVxMGfF9IYKrYMeEqFeBeQ+vcOe9LTAvW # fEZkA//V+LosiYCwtVGBXyCbeXYxoONMp/taRv6lVHoqVU7aSlbXsYqwePcUtPWq # r/V+Ru5vssqMueBdE9+E53JPewGPVw8xQE+xGgd1TZIeHWgegZHBzKWVap/3noey # dKjTig3yxXXg1gQJLCRw+a6bl8oCl4vEluGsLzh5P8aV1imjvFPXkR2w1vQOC3ws # 8DmyMcPEcsY4D2WLeTAGMheURLRzs5141nT0fQCOB4yzO/I8zYFIG12xCxgWoQkg # kW9XZw== # =5oFh # -----END PGP SIGNATURE----- # gpg: Signature made Wed 18 Oct 2023 16:30:30 PDT # gpg: using RSA key 7A481E78868B4DB6A85A05C064DF38E8AF7E215F # gpg: issuer "richard.henderson@linaro.org" # gpg: Good signature from "Richard Henderson <richard.henderson@linaro.org>" [full] # Primary key fingerprint: 7A48 1E78 868B 4DB6 A85A 05C0 64DF 38E8 AF7E 215F * tag 'pull-lu-20231018' of https://gitlab.com/rth7680/qemu: linux-user: Remap guest SIGABRT linux-user: Detect and report host SIGILL, SIGFPE, SIGTRAP linux-user: Split out host_sig{segv,bus}_handler linux-user: Simplify signal_init linux-user: Map unsupported signals to an out-of-bounds value linux-user: Only register handlers for core_dump_signal by default linux-user: Detect and report host crashes linux-user: Exit not abort in die_with_backtrace linux-user: Split out die_with_signal linux-user: Propagate failure in mmap_reserve_or_unmap back to target_munmap linux-user/elfload: Enable LSX/LASX in HWCAP for LoongArch linux-user/sh4: Fix crashes on signal delivery linux-user/mips: fix abort on integer overflow linux-user: Fixes for zero_bss Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
This commit is contained in:
+48
-13
@@ -1237,6 +1237,14 @@ static uint32_t get_elf_hwcap(void)
|
||||
hwcaps |= HWCAP_LOONGARCH_LAM;
|
||||
}
|
||||
|
||||
if (FIELD_EX32(cpu->env.cpucfg[2], CPUCFG2, LSX)) {
|
||||
hwcaps |= HWCAP_LOONGARCH_LSX;
|
||||
}
|
||||
|
||||
if (FIELD_EX32(cpu->env.cpucfg[2], CPUCFG2, LASX)) {
|
||||
hwcaps |= HWCAP_LOONGARCH_LASX;
|
||||
}
|
||||
|
||||
return hwcaps;
|
||||
}
|
||||
|
||||
@@ -2362,31 +2370,58 @@ static abi_ulong setup_arg_pages(struct linux_binprm *bprm,
|
||||
* Map and zero the bss. We need to explicitly zero any fractional pages
|
||||
* after the data section (i.e. bss). Return false on mapping failure.
|
||||
*/
|
||||
static bool zero_bss(abi_ulong start_bss, abi_ulong end_bss, int prot)
|
||||
static bool zero_bss(abi_ulong start_bss, abi_ulong end_bss,
|
||||
int prot, Error **errp)
|
||||
{
|
||||
abi_ulong align_bss;
|
||||
|
||||
/* We only expect writable bss; the code segment shouldn't need this. */
|
||||
if (!(prot & PROT_WRITE)) {
|
||||
error_setg(errp, "PT_LOAD with non-writable bss");
|
||||
return false;
|
||||
}
|
||||
|
||||
align_bss = TARGET_PAGE_ALIGN(start_bss);
|
||||
end_bss = TARGET_PAGE_ALIGN(end_bss);
|
||||
|
||||
if (start_bss < align_bss) {
|
||||
int flags = page_get_flags(start_bss);
|
||||
|
||||
if (!(flags & PAGE_VALID)) {
|
||||
/* Map the start of the bss. */
|
||||
if (!(flags & PAGE_BITS)) {
|
||||
/*
|
||||
* The whole address space of the executable was reserved
|
||||
* at the start, therefore all pages will be VALID.
|
||||
* But assuming there are no PROT_NONE PT_LOAD segments,
|
||||
* a PROT_NONE page means no data all bss, and we can
|
||||
* simply extend the new anon mapping back to the start
|
||||
* of the page of bss.
|
||||
*/
|
||||
align_bss -= TARGET_PAGE_SIZE;
|
||||
} else if (flags & PAGE_WRITE) {
|
||||
/* The page is already mapped writable. */
|
||||
memset(g2h_untagged(start_bss), 0, align_bss - start_bss);
|
||||
} else {
|
||||
/* Read-only zeros? */
|
||||
g_assert_not_reached();
|
||||
/*
|
||||
* The start of the bss shares a page with something.
|
||||
* The only thing that we expect is the data section,
|
||||
* which would already be marked writable.
|
||||
* Overlapping the RX code segment seems malformed.
|
||||
*/
|
||||
if (!(flags & PAGE_WRITE)) {
|
||||
error_setg(errp, "PT_LOAD with bss overlapping "
|
||||
"non-writable page");
|
||||
return false;
|
||||
}
|
||||
|
||||
/* The page is already mapped and writable. */
|
||||
memset(g2h_untagged(start_bss), 0, align_bss - start_bss);
|
||||
}
|
||||
}
|
||||
|
||||
return align_bss >= end_bss ||
|
||||
target_mmap(align_bss, end_bss - align_bss, prot,
|
||||
MAP_FIXED | MAP_PRIVATE | MAP_ANON, -1, 0) != -1;
|
||||
if (align_bss < end_bss &&
|
||||
target_mmap(align_bss, end_bss - align_bss, prot,
|
||||
MAP_FIXED | MAP_PRIVATE | MAP_ANON, -1, 0) == -1) {
|
||||
error_setg_errno(errp, errno, "Error mapping bss");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
#if defined(TARGET_ARM)
|
||||
@@ -3410,8 +3445,8 @@ static void load_elf_image(const char *image_name, int image_fd,
|
||||
|
||||
/* If the load segment requests extra zeros (e.g. bss), map it. */
|
||||
if (vaddr_ef < vaddr_em &&
|
||||
!zero_bss(vaddr_ef, vaddr_em, elf_prot)) {
|
||||
goto exit_mmap;
|
||||
!zero_bss(vaddr_ef, vaddr_em, elf_prot, &err)) {
|
||||
goto exit_errmsg;
|
||||
}
|
||||
|
||||
/* Find the full program boundaries. */
|
||||
|
||||
@@ -180,7 +180,9 @@ done_syscall:
|
||||
}
|
||||
force_sig_fault(TARGET_SIGFPE, si_code, env->active_tc.PC);
|
||||
break;
|
||||
|
||||
case EXCP_OVERFLOW:
|
||||
force_sig_fault(TARGET_SIGFPE, TARGET_FPE_INTOVF, env->active_tc.PC);
|
||||
break;
|
||||
/* The code below was inspired by the MIPS Linux kernel trap
|
||||
* handling code in arch/mips/kernel/traps.c.
|
||||
*/
|
||||
|
||||
+17
-13
@@ -778,7 +778,7 @@ fail:
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void mmap_reserve_or_unmap(abi_ulong start, abi_ulong len)
|
||||
static int mmap_reserve_or_unmap(abi_ulong start, abi_ulong len)
|
||||
{
|
||||
abi_ulong real_start;
|
||||
abi_ulong real_last;
|
||||
@@ -807,7 +807,7 @@ static void mmap_reserve_or_unmap(abi_ulong start, abi_ulong len)
|
||||
prot |= page_get_flags(a + 1);
|
||||
}
|
||||
if (prot != 0) {
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
for (prot = 0, a = real_start; a < start; a += TARGET_PAGE_SIZE) {
|
||||
@@ -825,7 +825,7 @@ static void mmap_reserve_or_unmap(abi_ulong start, abi_ulong len)
|
||||
}
|
||||
|
||||
if (real_last < real_start) {
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -836,32 +836,36 @@ static void mmap_reserve_or_unmap(abi_ulong start, abi_ulong len)
|
||||
void *ptr = mmap(host_start, real_len, PROT_NONE,
|
||||
MAP_FIXED | MAP_ANONYMOUS
|
||||
| MAP_PRIVATE | MAP_NORESERVE, -1, 0);
|
||||
assert(ptr == host_start);
|
||||
} else {
|
||||
int ret = munmap(host_start, real_len);
|
||||
assert(ret == 0);
|
||||
return ptr == host_start ? 0 : -1;
|
||||
}
|
||||
return munmap(host_start, real_len);
|
||||
}
|
||||
|
||||
int target_munmap(abi_ulong start, abi_ulong len)
|
||||
{
|
||||
int ret;
|
||||
|
||||
trace_target_munmap(start, len);
|
||||
|
||||
if (start & ~TARGET_PAGE_MASK) {
|
||||
return -TARGET_EINVAL;
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
len = TARGET_PAGE_ALIGN(len);
|
||||
if (len == 0 || !guest_range_valid_untagged(start, len)) {
|
||||
return -TARGET_EINVAL;
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
mmap_lock();
|
||||
mmap_reserve_or_unmap(start, len);
|
||||
page_set_flags(start, start + len - 1, 0);
|
||||
shm_region_rm_complete(start, start + len - 1);
|
||||
ret = mmap_reserve_or_unmap(start, len);
|
||||
if (likely(ret == 0)) {
|
||||
page_set_flags(start, start + len - 1, 0);
|
||||
shm_region_rm_complete(start, start + len - 1);
|
||||
}
|
||||
mmap_unlock();
|
||||
|
||||
return 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size,
|
||||
|
||||
@@ -104,6 +104,14 @@ static void unwind_gusa(CPUSH4State *regs)
|
||||
|
||||
/* Reset the SP to the saved version in R1. */
|
||||
regs->gregs[15] = regs->gregs[1];
|
||||
} else if (regs->gregs[15] >= -128u && regs->pc == regs->gregs[0]) {
|
||||
/* If we are on the last instruction of a gUSA region, we must reset
|
||||
the SP, otherwise we would be pushing the signal context to
|
||||
invalid memory. */
|
||||
regs->gregs[15] = regs->gregs[1];
|
||||
} else if (regs->flags & TB_FLAG_DELAY_SLOT) {
|
||||
/* If we are in a delay slot, push the previous instruction. */
|
||||
regs->pc -= 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+303
-156
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user