linux-user: Clean up siginfo_t handling
v2 cover linux-user: Clean up siginfo_t handling
Supercedes: [email protected] ("linux-user: Clean up siginfo_t handling for arm, aarch64")
Changes from Peter's v1:
* Introduce force_sigsegv_for_addr().
* Convert the rest of the targets, except nios2 (nios2 looks very wrong, and I can't test it).
* Other misc cleanups to signal handling, while I was nearby and looking at kernel code.
r~
Peter Maydell (7):
linux-user/aarch64: Set siginfo_t addr field for SIGTRAP signals linux-user/arm: Set siginfo_t addr field for SIGTRAP signals linux-user/arm: Use force_sig() to deliver fpa11 emulation SIGFPE
linux-user: Zero out target_siginfo_t in force_sig()
linux-user: Provide new force_sig_fault() function linux-user/arm: Use force_sig_fault() linux-user/aarch64: Use force_sig_fault()
Richard Henderson (23):
linux-user: Provide new force_sigsegv_for_addr() function linux-user/alpha: Set TRAP_UNK for bugchk and unknown gentrap linux-user/alpha: Set FPE_FLTUNK for gentrap ROPRAND linux-user/alpha: Use force_sig_fault, force_sigsegv_code linux-user/cris: Use force_sig_fault, force_sigsegv_code linux-user/hexagon: Use force_sigsegv_code linux-user/hppa: Use force_sig_fault, force_sigsegv_for_addr linux-user/hppa: Use the proper si_code for PRIV_OPR, PRIV_REG,
OVERFLOW
linux-user/hppa: Set FPE_CONDTRAP for COND linux-user/i386: Split out maybe_handle_vm86_trap linux-user/i386: Use force_sig, force_sig_fault,
force_sigsegv_for_addr
linux-user/m68k: Use force_sig_fault, force_sigsegv_for_addr linux-user/microblaze: Use force_sig_fault, force_sigsegv_for_addr linux-user/microblaze: Fix SIGFPE si_codes linux-user/mips: Improve do_break
linux-user/mips: Use force_sig_fault, force_sigsegv_for_addr linux-user/openrisc: Use force_sig_fault, force_sigsegv_for_addr linux-user/ppc: Use force_sig_fault, force_sigsegv_for_addr linux-user/riscv: Use force_sig_fault, force_sigsegv_for_addr linux-user/s390x: Use force_sig_fault, force_sigsegv_for_addr linux-user/sh4: Use force_sig_fault, force_sigsegv_for_addr linux-user/sparc: Use force_sig_fault, force_sigsegv_for_addr linux-user/xtensa: Use force_sig_fault, force_sigsegv_for_addr
linux-user/signal-common.h | 2 + linux-user/syscall_defs.h | 2 + linux-user/aarch64/cpu_loop.c | 33 ++----- linux-user/alpha/cpu_loop.c | 76 +++++------------ linux-user/arm/cpu_loop.c | 64 +++++--------- linux-user/cris/cpu_loop.c | 22 ++--- linux-user/hexagon/cpu_loop.c | 22 +---- linux-user/hppa/cpu_loop.c | 40 ++++----- linux-user/i386/cpu_loop.c | 77 +++++++---------- linux-user/m68k/cpu_loop.c | 35 ++------ linux-user/microblaze/cpu_loop.c | 83 +++++++++--------- linux-user/mips/cpu_loop.c | 92 +++++++++----------- linux-user/openrisc/cpu_loop.c | 37 +++----- linux-user/ppc/cpu_loop.c | 142 +++++++------------------------ linux-user/riscv/cpu_loop.c | 36 ++------ linux-user/s390x/cpu_loop.c | 16 ++-- linux-user/sh4/cpu_loop.c | 14 +-- linux-user/signal.c | 37 +++++++- linux-user/sparc/cpu_loop.c | 38 ++------- linux-user/xtensa/cpu_loop.c | 34 +++----- 20 files changed, 310 insertions(+), 592 deletions(-)
Signature · 1 line
2.25.1
PATCH v2 1/30 linux-user/aarch64: Set siginfo_t addr field for SIGTRAP signals
From: Peter Maydell <[email protected]>
When generating a TRAP_BRKPT SIGTRAP, set the siginfo_t addr field to the PC where the breakpoint/singlestep trap occurred; this is what the kernel does for this signal for this architecture.
Message-Id: <[email protected]>
--- linux-user/aarch64/cpu_loop.c | 1 + 1 file changed, 1 insertion(+)
linux-user/aarch64/cpu_loop.c +1 -0
@@ -148,6 +148,7 @@ void cpu_loop(CPUARMState *env) info.si_signo =TARGET_SIGTRAP ; info.si_errno =0 ; info.si_code =TARGET_TRAP_BRKPT ; + info._sifields._sigfault._addr = env->pc;queue_signal (env, info.si_signo,QEMU_SI_FAULT , &info);break ;case EXCP_SEMIHOST :
Signature · 1 line
2.25.1
PATCH v2 2/30 linux-user/arm: Set siginfo_t addr field for SIGTRAP signals
In reply to Richard HendersonFrom: Peter Maydell <[email protected]>
When generating a TRAP_BRKPT SIGTRAP, set the siginfo_t addr field to the PC where the breakpoint/singlestep trap occurred; this is what the kernel does for this signal for this architecture.
Message-Id: <[email protected]>
--- linux-user/arm/cpu_loop.c | 1 + 1 file changed, 1 insertion(+)
linux-user/arm/cpu_loop.c +1 -0
@@ -453,6 +453,7 @@ void cpu_loop(CPUARMState *env) info.si_signo =TARGET_SIGTRAP ; info.si_errno =0 ; info.si_code =TARGET_TRAP_BRKPT ; + info._sifields._sigfault._addr = env->regs[15 ];queue_signal (env, info.si_signo,QEMU_SI_FAULT , &info);break ;case EXCP_KERNEL_TRAP :
Signature · 1 line
2.25.1
PATCH v2 3/30 linux-user/arm: Use force_sig() to deliver fpa11 emulation SIGFPE
In reply to Richard HendersonFrom: Peter Maydell <[email protected]>
In the Arm target code, when the fpa11 emulation code tells us we need to send the guest a SIGFPE, we do this with queue_signal(), but we are using the wrong si_type, and we aren't setting the _sifields union members corresponding to either the si_type we are using or the si_type we should be using.
As the existing comment notes, the kernel code for this calls the old send_sig() function to deliver the signal. This eventually results in the kernel's signal handling code fabricating a siginfo_t with a SI_KERNEL code and a zero pid and uid. For QEMU this means we need to use QEMU_SI_KILL. We already have a function for that:force_sig() sets up the whole target_siginfo_t the way we need it.
Message-Id: <[email protected]>
--- linux-user/arm/cpu_loop.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
linux-user/arm/cpu_loop.c +5 -7
@@ -22,6 +22,7 @@#include "qemu.h" #include "elf.h" #include "cpu_loop-common.h" +#include "signal-common.h" #include "semihosting/common-semi.h" #define get_user_code_u32 (x, gaddr, env) \
@@ -266,16 +267,13 @@ static bool emulate_arm_fpa11(CPUARMState *env, uint32_t opcode) ts->fpa.fpsr |= raise & ~enabled;if (raise & enabled) { -target_siginfo_t info = { }; -/* * The kernel's nwfpe emulator does not pass a real si_code. -* It merely uses send_sig(SIGFPE, current, 1). +* It merely uses send_sig(SIGFPE, current, 1), which results in +* __send_signal() filling out SI_KERNEL with pid and uid 0 (under +* the "SEND_SIG_PRIV" case). That's what our force_sig() does. */ - info.si_signo =TARGET_SIGFPE ; - info.si_code =TARGET_SI_KERNEL ; - -queue_signal (env, info.si_signo,QEMU_SI_FAULT , &info); +force_sig (TARGET_SIGFPE ); }else { env->regs[15 ] +=4 ; }
Signature · 1 line
2.25.1
PATCH v2 4/30 linux-user: Zero out target_siginfo_t in force_sig()
In reply to Richard HendersonFrom: Peter Maydell <[email protected]>
The target_siginfo_t we populate in force_sig() will eventually get copied onto the target's stack. Zero it out so that any extra padding in the sifields union is consistently zero when the guest sees it.
Message-Id: <[email protected]>
--- linux-user/signal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
linux-user/signal.c +1 -1
@@ -636,7 +636,7 @@ void force_sig(int sig) {CPUState *cpu = thread_cpu;CPUArchState *env = cpu->env_ptr; -target_siginfo_t info; +target_siginfo_t info = {}; info.si_signo = sig; info.si_errno =0 ;
Signature · 1 line
2.25.1
Re: [PATCH v2 04/30] linux-user: Zero out target_siginfo_t in force_sig()
Quoted 7 lines · Richard Henderson
From: Peter Maydell <[email protected]>
The
target_siginfo_twe populate inforce_sig()will eventually get copied onto the target's stack. Zero it out so that any extra padding in the sifields union is consistently zero when the guest sees it.
Quoted 6 lines
Signed-off-by Peter Maydell <[email protected]>Message-Id: <[email protected]>
Signed-off-by Richard Henderson <[email protected]>--- linux-user/signal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
PATCH v2 5/30 linux-user: Provide new force_sig_fault() function
In reply to Richard HendersonFrom: Peter Maydell <[email protected]>
In many places in the linux-user code we need to queue a signal for the guest using the QEMU_SI_FAULT si_type. This requires that the caller sets up and passes us a target_siginfo, including setting the appropriate part of the _sifields union for the si_type. In a number of places the code forgets to set the _sifields union field.
Provide a new force_sig_fault() function, which does the same thing as the Linux kernel function of that name -- it takes the signal number, the si_code value and the address to use in _sifields._sigfault, and assembles the target_siginfo itself. This makes the callsites simpler and means it's harder to forget to pass in an address value.
We follow force_sig() and the kernel's force_sig_fault() in not requiring the caller to pass in the CPU pointer but always acting on the CPU of the current thread.
Message-Id: <[email protected]>
--- linux-user/signal-common.h | 1 + linux-user/signal.c | 17 +++++++++++++++++ 2 files changed, 18 insertions(+)
linux-user/signal-common.h +1 -0
@@ -40,6 +40,7 @@ void tswap_siginfo(target_siginfo_t *tinfo,void set_sigmask (const sigset_t *set);void force_sig (int sig);void force_sigsegv (int oldsig); +void force_sig_fault (int sig,int code,abi_ulong addr);#if defined(TARGET_ARCH_HAS_SETUP_FRAME )void setup_frame (int sig,struct target_sigaction *ka,target_sigset_t *set,CPUArchState *env);
linux-user/signal.c +17 -0
@@ -646,6 +646,23 @@ void force_sig(int sig)queue_signal (env, info.si_signo,QEMU_SI_KILL , &info); } +/* +* Force a synchronously taken QEMU_SI_FAULT signal. For QEMU the +* 'force' part is handled in process_pending_signals(). +*/ +void force_sig_fault (int sig,int code,abi_ulong addr) +{ +CPUState *cpu = thread_cpu; +CPUArchState *env = cpu->env_ptr; +target_siginfo_t info = {}; + + info.si_signo = sig; + info.si_errno =0 ; + info.si_code = code; + info._sifields._sigfault._addr = addr; +queue_signal (env, sig,QEMU_SI_FAULT , &info); +} +/* Force a SIGSEGV if we couldn't write to memory trying to set * up the signal frame. oldsig is the signal we were trying to handle * at the point of failure.
Signature · 1 line
2.25.1
Re: [PATCH v2 05/30] linux-user: Provide new force_sig_fault() function
Quoted 51 lines · Richard Henderson
From: Peter Maydell <[email protected]>
In many places in the linux-user code we need to queue a signal for the guest using the
QEMU_SI_FAULTsi_type. This requires that the caller sets up and passes us atarget_siginfo, including setting the appropriate part of the_sifieldsunion for thesi_type. In a number of places the code forgets to set the_sifieldsunion field.Provide a new
force_sig_fault()function, which does the same thing as the Linux kernel function of that name -- it takes the signal number, thesi_codevalue and the address to use in _sifields._sigfault, and assembles thetarget_siginfoitself. This makes the callsites simpler and means it's harder to forget to pass in an address value.We follow
force_sig()and the kernel'sforce_sig_fault()in not requiring the caller to pass in the CPU pointer but always acting on the CPU of the current thread.Signed-off-by Peter Maydell <[email protected]>Message-Id: <[email protected]>
Signed-off-by Richard Henderson <[email protected]>--- linux-user/signal-common.h | 1 + linux-user/signal.c | 17 +++++++++++++++++ 2 files changed, 18 insertions(+)linux-user/signal-common.h +1
-0@@ -40,6 +40,7 @@ void tswap_siginfo(target_siginfo_t *tinfo,void set_sigmask (const sigset_t *set);void force_sig (int sig);void force_sigsegv (int oldsig); +void force_sig_fault (int sig,int code,abi_ulong addr);#if defined(TARGET_ARCH_HAS_SETUP_FRAME )void setup_frame (int sig,struct target_sigaction *ka,target_sigset_t *set,CPUArchState *env);linux-user/signal.c +4
-0@@ -646,6 +646,23 @@ void force_sig(int sig)queue_signal (env, info.si_signo,QEMU_SI_KILL , &info); } +/* +* Force a synchronously taken QEMU_SI_FAULT signal. For QEMU the +* 'force' part is handled in process_pending_signals(). +*/
linux-user/signal.c void force_sig(int sig) · line 662
Quoted 10 lines
linux-user/signal.c +10
-0+void force_sig_fault (int sig,int code,abi_ulong addr) +{ +CPUState *cpu = thread_cpu; +CPUArchState *env = cpu->env_ptr; +target_siginfo_t info = {}; + + info.si_signo = sig; + info.si_errno =0 ; + info.si_code = code; + info._sifields._sigfault._addr = addr;
Maybe assign the members directly upon declaration? (to ease readability...)
Quoted 7 lines
linux-user/signal.c +3
-0+queue_signal (env, sig,QEMU_SI_FAULT , &info); +} +/* Force a SIGSEGV if we couldn't write to memory trying to set * up the signal frame. oldsig is the signal we were trying to handle * at the point of failure.
PATCH v2 6/30 linux-user: Provide new force_sigsegv_for_addr() function
In reply to Richard HendersonMost linux-user targets so far do not distinguish between SEGV_MAPERR and SEGV_ACCERR. This function will be used to fix that.
--- linux-user/signal-common.h | 1 + linux-user/signal.c | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+)
linux-user/signal-common.h +1 -0
@@ -40,6 +40,7 @@ void tswap_siginfo(target_siginfo_t *tinfo,void set_sigmask (const sigset_t *set);void force_sig (int sig);void force_sigsegv (int oldsig); +void force_sigsegv_for_addr (abi_ulong addr);void force_sig_fault (int sig,int code,abi_ulong addr);#if defined(TARGET_ARCH_HAS_SETUP_FRAME ) void setup_frame(int sig, struct target_sigaction *ka,
linux-user/signal.c +18 -0
@@ -663,6 +663,24 @@ void force_sig_fault(int sig, int code, abi_ulong addr)queue_signal (env, sig,QEMU_SI_FAULT , &info); } +/* +* Force a synchronously taken SIGSEGV signal for @addr. +* Distinguish between SEGV_MAPERR and SEGV_ACCERR here, +* in preference to doing that for each target. +*/ +void force_sigsegv_for_addr (abi_ulong addr) +{ +/* +* MAPERR indicates the page is not present at all. +* Otherwise, it must have been a permission problem. +*/ +int si_code =TARGET_SEGV_MAPERR ; +if (page_get_flags (addr) &PAGE_VALID ) { + si_code =TARGET_SEGV_ACCERR ; + } +force_sig_fault (TARGET_SIGSEGV , si_code, addr); +} +/* Force a SIGSEGV if we couldn't write to memory trying to set * up the signal frame. oldsig is the signal we were trying to handle * at the point of failure.
Signature · 1 line
2.25.1
Re: [PATCH v2 06/30] linux-user: Provide new force_sigsegv_for_addr() function
Quoted 9 lines · Richard Henderson
Most linux-user targets so far do not distinguish between
SEGV_MAPERRandSEGV_ACCERR. This function will be used to fix that.Signed-off-by Richard Henderson <[email protected]>--- linux-user/signal-common.h | 1 + linux-user/signal.c | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+)
thanks
-- PMM
PATCH v2 7/30 linux-user/arm: Use force_sig_fault()
In reply to Richard HendersonFrom: Peter Maydell <[email protected]>
Use the new force_sig_fault() function instead of setting up a target_siginfo_t and calling queue_signal().
Message-Id: <[email protected]>
--- linux-user/arm/cpu_loop.c | 53 +++++++++++---------------------------- 1 file changed, 15 insertions(+), 38 deletions(-)
linux-user/arm/cpu_loop.c +15 -38
@@ -93,7 +93,6 @@ static void arm_kernel_cmpxchg64_helper(CPUARMState *env) {uint64_t oldval, newval, val;uint32_t addr, cpsr; -target_siginfo_t info;/* Based on the 32 bit code in do_kernel_trap */
@@ -142,12 +141,9 @@ segv:end_exclusive ();/* We get the PC of the entry address - which is as good as anything, on a real kernel what you get depends on which mode it uses. */ - info.si_signo =TARGET_SIGSEGV ; - info.si_errno =0 ;/* XXX: check env->error_code */ - info.si_code =TARGET_SEGV_MAPERR ; - info._sifields._sigfault._addr = env->exception.vaddress; -queue_signal (env, info.si_signo,QEMU_SI_FAULT , &info); +force_sig_fault (TARGET_SIGSEGV ,TARGET_SEGV_MAPERR , + env->exception.vaddress); }/* Handle a jump to the kernel code page. */
@@ -285,8 +281,6 @@ void cpu_loop(CPUARMState *env)CPUState *cs =env_cpu (env);int trapnr;unsigned int n, insn; -target_siginfo_t info; -uint32_t addr;abi_ulong ret;for (;;) {
@@ -321,11 +315,8 @@ void cpu_loop(CPUARMState *env)break ; } - info.si_signo =TARGET_SIGILL ; - info.si_errno =0 ; - info.si_code =TARGET_ILL_ILLOPN ; - info._sifields._sigfault._addr = env->regs[15 ]; -queue_signal (env, info.si_signo,QEMU_SI_FAULT , &info); +force_sig_fault (TARGET_SIGILL ,TARGET_ILL_ILLOPN , + env->regs[15 ]); }break ;case EXCP_SWI :
@@ -393,18 +384,14 @@ void cpu_loop(CPUARMState *env)* Otherwise SIGILL. This includes any SWI with * immediate not originally 0x9fxxxx, because * of the earlier XOR. +* Like the real kernel, we report the addr of the +* SWI in the siginfo si_addr but leave the PC +* pointing at the insn after the SWI. */ - info.si_signo =TARGET_SIGILL ; - info.si_errno =0 ; - info.si_code =TARGET_ILL_ILLTRP ; - info._sifields._sigfault._addr = env->regs[15 ]; -if (env->thumb) { - info._sifields._sigfault._addr -=2 ; - }else { - info._sifields._sigfault._addr -=4 ; - } -queue_signal (env, info.si_signo, -QEMU_SI_FAULT , &info); +abi_ulong faultaddr = env->regs[15 ]; + faultaddr -= env->thumb ?2 :4 ; +force_sig_fault (TARGET_SIGILL ,TARGET_ILL_ILLTRP , + faultaddr); }break ; }
@@ -435,24 +422,14 @@ void cpu_loop(CPUARMState *env)break ;case EXCP_PREFETCH_ABORT :case EXCP_DATA_ABORT : - addr = env->exception.vaddress; - { - info.si_signo =TARGET_SIGSEGV ; - info.si_errno =0 ; -/* XXX: check env->error_code */ - info.si_code =TARGET_SEGV_MAPERR ; - info._sifields._sigfault._addr = addr; -queue_signal (env, info.si_signo,QEMU_SI_FAULT , &info); - } +/* XXX: check env->error_code */ +force_sig_fault (TARGET_SIGSEGV ,TARGET_SEGV_MAPERR , + env->exception.vaddress);break ;case EXCP_DEBUG :case EXCP_BKPT : excp_debug: - info.si_signo =TARGET_SIGTRAP ; - info.si_errno =0 ; - info.si_code =TARGET_TRAP_BRKPT ; - info._sifields._sigfault._addr = env->regs[15 ]; -queue_signal (env, info.si_signo,QEMU_SI_FAULT , &info); +force_sig_fault (TARGET_SIGTRAP ,TARGET_TRAP_BRKPT , env->regs[15 ]);break ;case EXCP_KERNEL_TRAP :if (do_kernel_trap (env))
Signature · 1 line
2.25.1
Re: [PATCH v2 07/30] linux-user/arm: Use force_sig_fault()
Quoted 11 lines · Richard Henderson
From: Peter Maydell <[email protected]>
Use the new
force_sig_fault()function instead of setting up atarget_siginfo_tand callingqueue_signal().Signed-off-by Peter Maydell <[email protected]>Message-Id: <[email protected]>
Signed-off-by Richard Henderson <[email protected]>--- linux-user/arm/cpu_loop.c | 53 +++++++++++---------------------------- 1 file changed, 15 insertions(+), 38 deletions(-)
PATCH v2 8/30 linux-user/aarch64: Use force_sig_fault()
In reply to Richard HendersonFrom: Peter Maydell <[email protected]>
Use the new force_sig_fault() function instead of setting up a target_siginfo_t and calling queue_signal().
Message-Id: <[email protected]>
--- linux-user/aarch64/cpu_loop.c | 34 +++++++++------------------------- 1 file changed, 9 insertions(+), 25 deletions(-)
linux-user/aarch64/cpu_loop.c +9 -25
@@ -21,6 +21,7 @@#include "qemu-common.h" #include "qemu.h" #include "cpu_loop-common.h" +#include "signal-common.h" #include "qemu/guest-random.h" #include "semihosting/common-semi.h" #include "target/arm/syndrome.h"
@@ -77,9 +78,8 @@void cpu_loop (CPUARMState *env) {CPUState *cs =env_cpu (env); -int trapnr, ec, fsc; +int trapnr, ec, fsc, si_code;abi_long ret; -target_siginfo_t info;for (;;) {cpu_exec_start (cs);
@@ -108,18 +108,10 @@ void cpu_loop(CPUARMState *env)/* just indicate that signals should be handled asap */ break ;case EXCP_UDEF : - info.si_signo =TARGET_SIGILL ; - info.si_errno =0 ; - info.si_code =TARGET_ILL_ILLOPN ; - info._sifields._sigfault._addr = env->pc; -queue_signal (env, info.si_signo,QEMU_SI_FAULT , &info); +force_sig_fault (TARGET_SIGILL ,TARGET_ILL_ILLOPN , env->pc);break ;case EXCP_PREFETCH_ABORT :case EXCP_DATA_ABORT : - info.si_signo =TARGET_SIGSEGV ; - info.si_errno =0 ; - info._sifields._sigfault._addr = env->exception.vaddress; -/* We should only arrive here with EC in {DATAABORT, INSNABORT}. */ ec =syn_get_ec (env->exception.syndrome);assert (ec ==EC_DATAABORT || ec ==EC_INSNABORT );
@@ -128,28 +120,24 @@ void cpu_loop(CPUARMState *env) fsc =extract32 (env->exception.syndrome,0 ,6 );switch (fsc) { case 0x04 ... 0x07: /* Translation fault, level {0-3} */ - info.si_code =TARGET_SEGV_MAPERR ; + si_code =TARGET_SEGV_MAPERR ;break ; case 0x09 ... 0x0b: /* Access flag fault, level {1-3} */ case 0x0d ... 0x0f: /* Permission fault, level {1-3} */ - info.si_code =TARGET_SEGV_ACCERR ; + si_code =TARGET_SEGV_ACCERR ;break ;case 0x11 :/* Synchronous Tag Check Fault */ - info.si_code =TARGET_SEGV_MTESERR ; + si_code =TARGET_SEGV_MTESERR ;break ;default :g_assert_not_reached (); } -queue_signal (env, info.si_signo,QEMU_SI_FAULT , &info); +force_sig_fault (TARGET_SIGSEGV , si_code, env->exception.vaddress);break ;case EXCP_DEBUG :case EXCP_BKPT : - info.si_signo =TARGET_SIGTRAP ; - info.si_errno =0 ; - info.si_code =TARGET_TRAP_BRKPT ; - info._sifields._sigfault._addr = env->pc; -queue_signal (env, info.si_signo,QEMU_SI_FAULT , &info); +force_sig_fault (TARGET_SIGTRAP ,TARGET_TRAP_BRKPT , env->pc);break ;case EXCP_SEMIHOST : env->xregs[0 ] =do_common_semihosting (cs);
@@ -169,11 +157,7 @@ void cpu_loop(CPUARMState *env)/* Check for MTE asynchronous faults */ if (unlikely (env->cp15.tfsr_el[0 ])) { env->cp15.tfsr_el[0 ] =0 ; - info.si_signo =TARGET_SIGSEGV ; - info.si_errno =0 ; - info._sifields._sigfault._addr =0 ; - info.si_code =TARGET_SEGV_MTEAERR ; -queue_signal (env, info.si_signo,QEMU_SI_FAULT , &info); +force_sig_fault (TARGET_SIGSEGV ,TARGET_SEGV_MTEAERR ,0 ); }process_pending_signals (env);
Signature · 1 line
2.25.1
Re: [PATCH v2 08/30] linux-user/aarch64: Use force_sig_fault()
Quoted 11 lines · Richard Henderson
From: Peter Maydell <[email protected]>
Use the new
force_sig_fault()function instead of setting up atarget_siginfo_tand callingqueue_signal().Signed-off-by Peter Maydell <[email protected]>Message-Id: <[email protected]>
Signed-off-by Richard Henderson <[email protected]>--- linux-user/aarch64/cpu_loop.c | 34 +++++++++------------------------- 1 file changed, 9 insertions(+), 25 deletions(-)
PATCH v2 9/30 linux-user/alpha: Set TRAP_UNK for bugchk and unknown gentrap
In reply to Richard HendersonThese si_codes were changed in 535906c684fca, for linux 4.17.
--- linux-user/syscall_defs.h | 1 + linux-user/alpha/cpu_loop.c | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-)
linux-user/syscall_defs.h +1 -0
@@ -715,6 +715,7 @@ typedef struct target_siginfo {#define TARGET_TRAP_TRACE (2)/* process trace trap */ #define TARGET_TRAP_BRANCH (3)/* process taken branch trap */ #define TARGET_TRAP_HWBKPT (4)/* hardware breakpoint/watchpoint */ +#define TARGET_TRAP_UNK (5)/* undiagnosed trap */ struct target_rlimit {abi_ulong rlim_cur;
linux-user/alpha/cpu_loop.c +2 -2
@@ -99,7 +99,7 @@ void cpu_loop(CPUAlphaState *env)/* BUGCHK */ info.si_signo =TARGET_SIGTRAP ; info.si_errno =0 ; - info.si_code =0 ; + info.si_code =TARGET_TRAP_UNK ; info._sifields._sigfault._addr = env->pc;queue_signal (env, info.si_signo,QEMU_SI_FAULT , &info);break ;
@@ -168,7 +168,7 @@ void cpu_loop(CPUAlphaState *env)break ;default : info.si_signo =TARGET_SIGTRAP ; - info.si_code =0 ; + info.si_code =TARGET_TRAP_UNK ;break ; } info.si_errno =0 ;
Signature · 1 line
2.25.1
Re: [PATCH v2 09/30] linux-user/alpha: Set TRAP_UNK for bugchk and unknown gentrap
Quoted 8 lines · Richard Henderson
These
si_codeswere changed in535906c684fca, for linux 4.17.Signed-off-by Richard Henderson <[email protected]>--- linux-user/syscall_defs.h | 1 + linux-user/alpha/cpu_loop.c | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-)
thanks
-- PMM
PATCH v2 10/30 linux-user/alpha: Set FPE_FLTUNK for gentrap ROPRAND
In reply to Richard HendersonThis si_code was changed in 4cc13e4f6d441, for linux 4.17.
--- linux-user/alpha/cpu_loop.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
linux-user/alpha/cpu_loop.c +1 -1
@@ -164,7 +164,7 @@ void cpu_loop(CPUAlphaState *env) info.si_code =TARGET_FPE_FLTRES ;break ;case TARGET_GEN_ROPRAND : - info.si_code =0 ; + info.si_code =TARGET_FPE_FLTUNK ;break ;default : info.si_signo =TARGET_SIGTRAP ;
Signature · 1 line
2.25.1
Re: [PATCH v2 10/30] linux-user/alpha: Set FPE_FLTUNK for gentrap ROPRAND
Quoted 5 lines · Richard Henderson
This
si_codewas changed in4cc13e4f6d441, for linux 4.17.Signed-off-by Richard Henderson <[email protected]>---
thanks
-- PMM
PATCH v2 11/30 linux-user/alpha: Use force_sig_fault, force_sigsegv_code
In reply to Richard HendersonUse the new functions instead of setting up a target_siginfo_t and calling queue_signal.
--- linux-user/alpha/cpu_loop.c | 76 +++++++++++-------------------------- 1 file changed, 23 insertions(+), 53 deletions(-)
linux-user/alpha/cpu_loop.c +23 -53
@@ -21,12 +21,13 @@#include "qemu-common.h" #include "qemu.h" #include "cpu_loop-common.h" +#include "signal-common.h" +void cpu_loop (CPUAlphaState *env) {CPUState *cs =env_cpu (env); -int trapnr; -target_siginfo_t info; +int trapnr, si_code;abi_long sysret;while (1 ) {
@@ -53,34 +54,17 @@ void cpu_loop(CPUAlphaState *env)exit (EXIT_FAILURE );break ;case EXCP_MMFAULT : - info.si_signo =TARGET_SIGSEGV ; - info.si_errno =0 ; - info.si_code = (page_get_flags (env->trap_arg0) &PAGE_VALID - ?TARGET_SEGV_ACCERR :TARGET_SEGV_MAPERR ); - info._sifields._sigfault._addr = env->trap_arg0; -queue_signal (env, info.si_signo,QEMU_SI_FAULT , &info); +force_sigsegv_for_addr (env->trap_arg0);break ;case EXCP_UNALIGN : - info.si_signo =TARGET_SIGBUS ; - info.si_errno =0 ; - info.si_code =TARGET_BUS_ADRALN ; - info._sifields._sigfault._addr = env->trap_arg0; -queue_signal (env, info.si_signo,QEMU_SI_FAULT , &info); +force_sig_fault (TARGET_SIGBUS ,TARGET_BUS_ADRALN , env->trap_arg0);break ;case EXCP_OPCDEC : do_sigill: - info.si_signo =TARGET_SIGILL ; - info.si_errno =0 ; - info.si_code =TARGET_ILL_ILLOPC ; - info._sifields._sigfault._addr = env->pc; -queue_signal (env, info.si_signo,QEMU_SI_FAULT , &info); +force_sig_fault (TARGET_SIGILL ,TARGET_ILL_ILLOPC , env->pc);break ;case EXCP_ARITH : - info.si_signo =TARGET_SIGFPE ; - info.si_errno =0 ; - info.si_code =TARGET_FPE_FLTINV ; - info._sifields._sigfault._addr = env->pc; -queue_signal (env, info.si_signo,QEMU_SI_FAULT , &info); +force_sig_fault (TARGET_SIGFPE ,TARGET_FPE_FLTINV , env->pc);break ;case EXCP_FEN :/* No-op. Linux simply re-enables the FPU. */
@@ -89,20 +73,10 @@ void cpu_loop(CPUAlphaState *env)switch (env->error_code) {case 0x80 :/* BPT */ - info.si_signo =TARGET_SIGTRAP ; - info.si_errno =0 ; - info.si_code =TARGET_TRAP_BRKPT ; - info._sifields._sigfault._addr = env->pc; -queue_signal (env, info.si_signo,QEMU_SI_FAULT , &info); -break ; + goto do_sigtrap_brkpt;case 0x81 :/* BUGCHK */ - info.si_signo =TARGET_SIGTRAP ; - info.si_errno =0 ; - info.si_code =TARGET_TRAP_UNK ; - info._sifields._sigfault._addr = env->pc; -queue_signal (env, info.si_signo,QEMU_SI_FAULT , &info); -break ; + goto do_sigtrap_unk;case 0x83 :/* CALLSYS */ trapnr = env->ir[IR_V0 ];
@@ -143,47 +117,43 @@ void cpu_loop(CPUAlphaState *env)abort ();case 0xAA :/* GENTRAP */ - info.si_signo =TARGET_SIGFPE ;switch (env->ir[IR_A0 ]) {case TARGET_GEN_INTOVF : - info.si_code =TARGET_FPE_INTOVF ; + si_code =TARGET_FPE_INTOVF ;break ;case TARGET_GEN_INTDIV : - info.si_code =TARGET_FPE_INTDIV ; + si_code =TARGET_FPE_INTDIV ;break ;case TARGET_GEN_FLTOVF : - info.si_code =TARGET_FPE_FLTOVF ; + si_code =TARGET_FPE_FLTOVF ;break ;case TARGET_GEN_FLTUND : - info.si_code =TARGET_FPE_FLTUND ; + si_code =TARGET_FPE_FLTUND ;break ;case TARGET_GEN_FLTINV : - info.si_code =TARGET_FPE_FLTINV ; + si_code =TARGET_FPE_FLTINV ;break ;case TARGET_GEN_FLTINE : - info.si_code =TARGET_FPE_FLTRES ; + si_code =TARGET_FPE_FLTRES ;break ;case TARGET_GEN_ROPRAND : - info.si_code =TARGET_FPE_FLTUNK ; + si_code =TARGET_FPE_FLTUNK ;break ;default : - info.si_signo =TARGET_SIGTRAP ; - info.si_code =TARGET_TRAP_UNK ; -break ; + goto do_sigtrap_unk; } - info.si_errno =0 ; - info._sifields._sigfault._addr = env->pc; -queue_signal (env, info.si_signo,QEMU_SI_FAULT , &info); +force_sig_fault (TARGET_SIGFPE , si_code, env->pc);break ;default : goto do_sigill; }break ;case EXCP_DEBUG : - info.si_signo =TARGET_SIGTRAP ; - info.si_errno =0 ; - info.si_code =TARGET_TRAP_BRKPT ; -queue_signal (env, info.si_signo,QEMU_SI_FAULT , &info); + do_sigtrap_brkpt: +force_sig_fault (TARGET_SIGTRAP ,TARGET_TRAP_BRKPT , env->pc); +break ; + do_sigtrap_unk: +force_sig_fault (TARGET_SIGTRAP ,TARGET_TRAP_UNK , env->pc);break ;case EXCP_INTERRUPT :/* Just indicate that signals should be handled asap. */
Signature · 1 line
2.25.1
Re: [PATCH v2 11/30] linux-user/alpha: Use force_sig_fault, force_sigsegv_code
Quoted 6 lines · Richard Henderson
Use the new functions instead of setting up a
target_siginfo_tand callingqueue_signal.Signed-off-by Richard Henderson <[email protected]>---
thanks
-- PMM
PATCH v2 12/30 linux-user/cris: Use force_sig_fault, force_sigsegv_code
In reply to Richard HendersonUse the new functions instead of setting up a target_siginfo_t and calling queue_signal.
--- linux-user/cris/cpu_loop.c | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-)
linux-user/cris/cpu_loop.c +6 -16
@@ -21,13 +21,13 @@#include "qemu-common.h" #include "qemu.h" #include "cpu_loop-common.h" +#include "signal-common.h" void cpu_loop (CPUCRISState *env) {CPUState *cs =env_cpu (env);int trapnr, ret; -target_siginfo_t info; - +while (1 ) {cpu_exec_start (cs); trapnr =cpu_exec (cs);
@@ -36,18 +36,11 @@ void cpu_loop(CPUCRISState *env)switch (trapnr) {case 0xaa : - { - info.si_signo =TARGET_SIGSEGV ; - info.si_errno =0 ; -/* XXX: check env->error_code */ - info.si_code =TARGET_SEGV_MAPERR ; - info._sifields._sigfault._addr = env->pregs[PR_EDA ]; -queue_signal (env, info.si_signo,QEMU_SI_FAULT , &info); - } +force_sigsegv_for_addr (env->pregs[PR_EDA ]);break ;case EXCP_INTERRUPT : -/* just indicate that signals should be handled asap */ -break ; +/* just indicate that signals should be handled asap */ +break ;case EXCP_BREAK : ret = do_syscall(env, env->regs[9],
@@ -65,10 +58,7 @@ void cpu_loop(CPUCRISState *env) }break ;case EXCP_DEBUG : - info.si_signo =TARGET_SIGTRAP ; - info.si_errno =0 ; - info.si_code =TARGET_TRAP_BRKPT ; -queue_signal (env, info.si_signo,QEMU_SI_FAULT , &info); +force_sig_fault (TARGET_SIGTRAP ,TARGET_TRAP_BRKPT , env->pc);break ;case EXCP_ATOMIC :cpu_exec_step_atomic (cs);
Signature · 1 line
2.25.1
Re: [PATCH v2 12/30] linux-user/cris: Use force_sig_fault, force_sigsegv_code
Quoted 3 lines · Richard Henderson
Use the new functions instead of setting up a
target_siginfo_tand callingqueue_signal.
You should mention in the commit message that this fixes two bugs:
* SIGSEGV not distinguishing MAPERR from ACCERR
* SIGTRAP on breakpoint not setting the address
Otherwise
thanks
-- PMM
PATCH v2 13/30 linux-user/hexagon: Use force_sigsegv_code
In reply to Richard HendersonUse the new function instead of setting up a target_siginfo_t and calling queue_signal. Note that we were incorrectly using QEMU_SI_KILL instead of QEMU_SI_FAULT for raising SIGSEGV.
--- linux-user/hexagon/cpu_loop.c | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-)
linux-user/hexagon/cpu_loop.c +4 -18
@@ -21,13 +21,13 @@#include "qemu/osdep.h" #include "qemu.h" #include "cpu_loop-common.h" +#include "signal-common.h" #include "internal.h" void cpu_loop (CPUHexagonState *env) {CPUState *cs =env_cpu (env); -int trapnr, signum, sigcode; -target_ulong sigaddr; +int trapnr;target_ulong syscallnum;target_ulong ret;
@@ -37,10 +37,6 @@ void cpu_loop(CPUHexagonState *env)cpu_exec_end (cs);process_queued_cpu_work (cs); - signum =0 ; - sigcode =0 ; - sigaddr =0 ; -switch (trapnr) {case EXCP_INTERRUPT :/* just indicate that signals should be handled asap */
@@ -66,8 +62,8 @@ void cpu_loop(CPUHexagonState *env)case HEX_EXCP_FETCH_NO_UPAGE :case HEX_EXCP_PRIV_NO_UREAD :case HEX_EXCP_PRIV_NO_UWRITE : - signum =TARGET_SIGSEGV ; - sigcode =TARGET_SEGV_MAPERR ; +/* FIXME: need to store vaddr in hexagon_tlb_fill */ +force_sigsegv_for_addr (0 );break ;case EXCP_ATOMIC :cpu_exec_step_atomic (cs);
@@ -78,16 +74,6 @@ void cpu_loop(CPUHexagonState *env)exit (EXIT_FAILURE ); } -if (signum) { -target_siginfo_t info = { - .si_signo = signum, - .si_errno =0 , - .si_code = sigcode, - ._sifields._sigfault._addr = sigaddr - }; -queue_signal (env, info.si_signo,QEMU_SI_KILL , &info); - } -process_pending_signals (env); } }
Signature · 1 line
2.25.1
Re: [PATCH v2 13/30] linux-user/hexagon: Use force_sigsegv_code
Quoted 9 lines · Richard Henderson
Use the new function instead of setting up a
target_siginfo_tand callingqueue_signal. Note that we were incorrectly usingQEMU_SI_KILLinstead ofQEMU_SI_FAULTfor raising SIGSEGV.Signed-off-by Richard Henderson <[email protected]>--- linux-user/hexagon/cpu_loop.c | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-)
thanks
-- PMM
PATCH v2 14/30 linux-user/hppa: Use force_sig_fault, force_sigsegv_for_addr
In reply to Richard HendersonUse the new functions instead of setting up a target_siginfo_t and calling queue_signal.
--- linux-user/hppa/cpu_loop.c | 32 +++++++------------------------- 1 file changed, 7 insertions(+), 25 deletions(-)
linux-user/hppa/cpu_loop.c +7 -25
@@ -20,6 +20,8 @@#include "qemu/osdep.h" #include "qemu.h" #include "cpu_loop-common.h" +#include "signal-common.h" +static abi_ulong hppa_lws (CPUHPPAState *env) {
@@ -108,7 +110,6 @@ static abi_ulong hppa_lws(CPUHPPAState *env)void cpu_loop (CPUHPPAState *env) {CPUState *cs =env_cpu (env); -target_siginfo_t info;abi_ulong ret;int trapnr;
@@ -152,42 +153,23 @@ void cpu_loop(CPUHPPAState *env)case EXCP_PAGE_REF :case EXCP_DMAR :case EXCP_DMPI : - info.si_signo =TARGET_SIGSEGV ; - info.si_errno =0 ; - info.si_code =TARGET_SEGV_ACCERR ; - info._sifields._sigfault._addr = env->cr[CR_IOR ]; -queue_signal (env, info.si_signo,QEMU_SI_FAULT , &info); +force_sigsegv_for_addr (env->cr[CR_IOR ]);break ;case EXCP_UNALIGN : - info.si_signo =TARGET_SIGBUS ; - info.si_errno =0 ; - info.si_code =0 ; - info._sifields._sigfault._addr = env->cr[CR_IOR ]; -queue_signal (env, info.si_signo,QEMU_SI_FAULT , &info); +force_sig_fault (TARGET_SIGBUS ,TARGET_BUS_ADRALN , env->cr[CR_IOR ]);break ;case EXCP_ILL :case EXCP_PRIV_OPR :case EXCP_PRIV_REG : - info.si_signo =TARGET_SIGILL ; - info.si_errno =0 ; - info.si_code =TARGET_ILL_ILLOPN ; - info._sifields._sigfault._addr = env->iaoq_f; -queue_signal (env, info.si_signo,QEMU_SI_FAULT , &info); +force_sig_fault (TARGET_SIGILL ,TARGET_ILL_ILLOPN , env->iaoq_f);break ;case EXCP_OVERFLOW :case EXCP_COND :case EXCP_ASSIST : - info.si_signo =TARGET_SIGFPE ; - info.si_errno =0 ; - info.si_code =0 ; - info._sifields._sigfault._addr = env->iaoq_f; -queue_signal (env, info.si_signo,QEMU_SI_FAULT , &info); +force_sig_fault (TARGET_SIGFPE ,0 , env->iaoq_f);break ;case EXCP_DEBUG : - info.si_signo =TARGET_SIGTRAP ; - info.si_errno =0 ; - info.si_code =TARGET_TRAP_BRKPT ; -queue_signal (env, info.si_signo,QEMU_SI_FAULT , &info); +force_sig_fault (TARGET_SIGTRAP ,TARGET_TRAP_BRKPT , env->iaoq_f);break ;case EXCP_INTERRUPT :/* just indicate that signals should be handled asap */
Signature · 1 line
2.25.1
Re: [PATCH v2 14/30] linux-user/hppa: Use force_sig_fault, force_sigsegv_for_addr
Quoted 3 lines · Richard Henderson
Use the new functions instead of setting up a
target_siginfo_tand callingqueue_signal.
Where this is changing behaviour to fix bugs you should mention it in the commit message:
* address field for breakpoint trap
* si_code for alignment traps
Otherwise
thanks
-- PMM
PATCH v2 15/30 linux-user/hppa: Use the proper si_code for PRIV_OPR, PRIV_REG, OVERFLOW
In reply to Richard HendersonThese si_codes have been properly set by the kernel since the beginning.
--- linux-user/hppa/cpu_loop.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
linux-user/hppa/cpu_loop.c +8 -2
@@ -159,11 +159,17 @@ void cpu_loop(CPUHPPAState *env)force_sig_fault (TARGET_SIGBUS ,TARGET_BUS_ADRALN , env->cr[CR_IOR ]);break ;case EXCP_ILL : -case EXCP_PRIV_OPR : -case EXCP_PRIV_REG :force_sig_fault (TARGET_SIGILL ,TARGET_ILL_ILLOPN , env->iaoq_f);break ; +case EXCP_PRIV_OPR : +force_sig_fault (TARGET_SIGILL ,TARGET_ILL_PRVOPC , env->iaoq_f); +break ; +case EXCP_PRIV_REG : +force_sig_fault (TARGET_SIGILL ,TARGET_ILL_PRVREG , env->iaoq_f); +break ;case EXCP_OVERFLOW : +force_sig_fault (TARGET_SIGFPE ,TARGET_FPE_INTOVF , env->iaoq_f); +break ;case EXCP_COND :case EXCP_ASSIST :force_sig_fault (TARGET_SIGFPE ,0 , env->iaoq_f);
Signature · 1 line
2.25.1
Re: [PATCH v2 15/30] linux-user/hppa: Use the proper si_code for PRIV_OPR, PRIV_REG, OVERFLOW
Quoted 4 lines · Richard Henderson
These
si_codeshave been properly set by the kernel since the beginning.Signed-off-by Richard Henderson <[email protected]>
thanks
-- PMM
PATCH v2 16/30 linux-user/hppa: Set FPE_CONDTRAP for COND
In reply to Richard HendersonThis si_code was changed in 75abf64287cab, for linux 4.17.
--- linux-user/syscall_defs.h | 1 + linux-user/hppa/cpu_loop.c | 2 ++ 2 files changed, 3 insertions(+)
linux-user/syscall_defs.h +1 -0
@@ -688,6 +688,7 @@ typedef struct target_siginfo {#define TARGET_FPE_FLTINV (7)/* floating point invalid operation */ #define TARGET_FPE_FLTSUB (8)/* subscript out of range */ #define TARGET_FPE_FLTUNK (14)/* undiagnosed fp exception */ +#define TARGET_FPE_CONDTRAP (15)/* trap on condition */ #define TARGET_NSIGFPE 15/*
linux-user/hppa/cpu_loop.c +2 -0
@@ -171,6 +171,8 @@ void cpu_loop(CPUHPPAState *env)force_sig_fault (TARGET_SIGFPE ,TARGET_FPE_INTOVF , env->iaoq_f);break ;case EXCP_COND : +force_sig_fault (TARGET_SIGFPE ,TARGET_FPE_CONDTRAP , env->iaoq_f); +break ;case EXCP_ASSIST :force_sig_fault (TARGET_SIGFPE ,0 , env->iaoq_f);break ;
Signature · 1 line
2.25.1
Re: [PATCH v2 16/30] linux-user/hppa: Set FPE_CONDTRAP for COND
Quoted 14 lines · Richard Henderson
This
si_codewas changed in75abf64287cab, for linux 4.17.Signed-off-by Richard Henderson <[email protected]>--- linux-user/syscall_defs.h | 1 + linux-user/hppa/cpu_loop.c | 2 ++ 2 files changed, 3 insertions(+)linux-user/syscall_defs.h +0
-0
linux-user/syscall_defs.h typedef struct target_siginfo { · line 692
Quoted 5 lines
linux-user/syscall_defs.h +1
-0@@ -688,6 +688,7 @@ typedef struct target_siginfo {#define TARGET_FPE_FLTINV (7)/* floating point invalid operation */ #define TARGET_FPE_FLTSUB (8)/* subscript out of range */ #define TARGET_FPE_FLTUNK (14)/* undiagnosed fp exception */ +#define TARGET_FPE_CONDTRAP (15)/* trap on condition */ #define TARGET_NSIGFPE 15
We don't use TARGET_NSIGFPE, but we should either update it as the kernel did in 75abf64287cab, or just delete it. (We don't have the equivalent NSIGTRAP, NSIGBUS, etc for the other si_codes, so maybe deleting is the simplest option. If you want to put a preceding patch that just deletes our TARGET_NSIGFPE definition, you can have my r-by for that.)
Otherwise
thanks
-- PMM
PATCH v2 17/30 linux-user/i386: Split out maybe_handle_vm86_trap
In reply to Richard HendersonReduce the number of ifdefs within cpu_loop().
--- linux-user/i386/cpu_loop.c | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-)
linux-user/i386/cpu_loop.c +15 -16
@@ -195,6 +195,17 @@ static void emulate_vsyscall(CPUX86State *env) }#endif +static bool maybe_handle_vm86_trap (CPUX86State *env,int trapnr) +{ +#ifndef TARGET_X86_64 +if (env->eflags &VM_MASK ) { +handle_vm86_trap (env, trapnr); +return true; + } +#endif +return false; +} +void cpu_loop (CPUX86State *env) {CPUState *cs =env_cpu (env);
@@ -256,12 +267,9 @@ void cpu_loop(CPUX86State *env)break ;case EXCP0D_GPF :/* XXX: potential problem if ABI32 */ -#ifndef TARGET_X86_64 -if (env->eflags &VM_MASK ) { -handle_vm86_fault (env); +if (maybe_handle_vm86_trap (env, trapnr)) {break ; } -#endif gen_signal (env,TARGET_SIGSEGV ,TARGET_SI_KERNEL ,0 );break ;case EXCP0E_PAGE :
@@ -271,22 +279,16 @@ void cpu_loop(CPUX86State *env) env->cr[2]);break ;case EXCP00_DIVZ : -#ifndef TARGET_X86_64 -if (env->eflags &VM_MASK ) { -handle_vm86_trap (env, trapnr); +if (maybe_handle_vm86_trap (env, trapnr)) {break ; } -#endif gen_signal (env,TARGET_SIGFPE ,TARGET_FPE_INTDIV , env->eip);break ;case EXCP01_DB :case EXCP03_INT3 : -#ifndef TARGET_X86_64 -if (env->eflags &VM_MASK ) { -handle_vm86_trap (env, trapnr); +if (maybe_handle_vm86_trap (env, trapnr)) {break ; } -#endif if (trapnr ==EXCP01_DB ) {gen_signal (env,TARGET_SIGTRAP ,TARGET_TRAP_BRKPT , env->eip); }else {
@@ -295,12 +297,9 @@ void cpu_loop(CPUX86State *env)break ;case EXCP04_INTO :case EXCP05_BOUND : -#ifndef TARGET_X86_64 -if (env->eflags &VM_MASK ) { -handle_vm86_trap (env, trapnr); +if (maybe_handle_vm86_trap (env, trapnr)) {break ; } -#endif gen_signal (env,TARGET_SIGSEGV ,TARGET_SI_KERNEL ,0 );break ;case EXCP06_ILLOP :
Signature · 1 line
2.25.1
Re: [PATCH v2 17/30] linux-user/i386: Split out maybe_handle_vm86_trap
Quoted 5 lines · Richard Henderson
Reduce the number of ifdefs within
cpu_loop().Signed-off-by Richard Henderson <[email protected]>---
thanks
-- PMM
PATCH v2 18/30 linux-user/i386: Use force_sig, force_sig_fault, force_sigsegv_for_addr
In reply to Richard HendersonReplace the local gen_signal with the generic functions that match how the kernel raises signals.
--- linux-user/i386/cpu_loop.c | 46 +++++++++++++------------------------- 1 file changed, 16 insertions(+), 30 deletions(-)
linux-user/i386/cpu_loop.c +16 -30
@@ -21,6 +21,7 @@#include "qemu-common.h" #include "qemu.h" #include "cpu_loop-common.h" +#include "signal-common.h" /***********************************************************/ /* CPUX86 core interface */
@@ -81,17 +82,6 @@ static void set_idt(int n, unsigned int dpl) }#endif -static void gen_signal (CPUX86State *env,int sig,int code,abi_ptr addr) -{ -target_siginfo_t info = { - .si_signo = sig, - .si_code = code, - ._sifields._sigfault._addr = addr - }; - -queue_signal (env, info.si_signo,QEMU_SI_FAULT , &info); -} -#ifdef TARGET_X86_64 static bool write_ok_or_segv (CPUX86State *env,abi_ptr addr,size_t len) {
@@ -103,8 +93,7 @@ static bool write_ok_or_segv(CPUX86State *env, abi_ptr addr, size_t len)return true; } - env->error_code =PG_ERROR_W_MASK |PG_ERROR_U_MASK ; -gen_signal (env,TARGET_SIGSEGV ,TARGET_SEGV_MAPERR , addr); +force_sigsegv_for_addr (addr);return false; }
@@ -190,8 +179,7 @@ static void emulate_vsyscall(CPUX86State *env)return ; sigsegv: -/* Like force_sig(SIGSEGV). */ - gen_signal(env, TARGET_SIGSEGV, TARGET_SI_KERNEL, 0); + force_sig(TARGET_SIGSEGV); }#endif
@@ -263,53 +251,51 @@ void cpu_loop(CPUX86State *env)#endif case EXCP0B_NOSEG :case EXCP0C_STACK : -gen_signal (env,TARGET_SIGBUS ,TARGET_SI_KERNEL ,0 ); +force_sig (TARGET_SIGBUS );break ;case EXCP0D_GPF :/* XXX: potential problem if ABI32 */ if (maybe_handle_vm86_trap (env, trapnr)) {break ; } -gen_signal (env,TARGET_SIGSEGV ,TARGET_SI_KERNEL ,0 ); +force_sig (TARGET_SIGSEGV );break ;case EXCP0E_PAGE : -gen_signal (env,TARGET_SIGSEGV , - (env->error_code &1 ? -TARGET_SEGV_ACCERR :TARGET_SEGV_MAPERR ), - env->cr[2 ]); +force_sigsegv_for_addr (env->cr[2 ]);break ;case EXCP00_DIVZ :if (maybe_handle_vm86_trap (env, trapnr)) {break ; } -gen_signal (env,TARGET_SIGFPE ,TARGET_FPE_INTDIV , env->eip); +force_sig_fault (TARGET_SIGFPE ,TARGET_FPE_INTDIV , env->eip);break ;case EXCP01_DB : +if (maybe_handle_vm86_trap (env, trapnr)) { +break ; + } +force_sig_fault (TARGET_SIGTRAP ,TARGET_TRAP_BRKPT , env->eip); +break ;case EXCP03_INT3 :if (maybe_handle_vm86_trap (env, trapnr)) {break ; } -if (trapnr ==EXCP01_DB ) { -gen_signal (env,TARGET_SIGTRAP ,TARGET_TRAP_BRKPT , env->eip); - }else { -gen_signal (env,TARGET_SIGTRAP ,TARGET_SI_KERNEL ,0 ); - } +force_sig (TARGET_SIGTRAP );break ;case EXCP04_INTO :case EXCP05_BOUND :if (maybe_handle_vm86_trap (env, trapnr)) {break ; } -gen_signal (env,TARGET_SIGSEGV ,TARGET_SI_KERNEL ,0 ); +force_sig (TARGET_SIGSEGV );break ;case EXCP06_ILLOP : -gen_signal (env,TARGET_SIGILL ,TARGET_ILL_ILLOPN , env->eip); +force_sig_fault (TARGET_SIGILL ,TARGET_ILL_ILLOPN , env->eip);break ;case EXCP_INTERRUPT :/* just indicate that signals should be handled asap */ break ;case EXCP_DEBUG : -gen_signal (env,TARGET_SIGTRAP ,TARGET_TRAP_BRKPT ,0 ); +force_sig_fault (TARGET_SIGTRAP ,TARGET_TRAP_BRKPT , env->eip);break ;case EXCP_ATOMIC :cpu_exec_step_atomic (cs);
Signature · 1 line
2.25.1
Re: [PATCH v2 18/30] linux-user/i386: Use force_sig, force_sig_fault, force_sigsegv_for_addr
Quoted 5 lines · Richard Henderson
Replace the local
gen_signalwith the generic functions that match how the kernel raises signals.Signed-off-by Richard Henderson <[email protected]>
Mention behaviour changes in the commit message. Otherwise
thanks
-- PMM
PATCH v2 19/30 linux-user/m68k: Use force_sig_fault, force_sigsegv_for_addr
In reply to Richard HendersonUse the new functions instead of setting up a target_siginfo_t and calling queue_signal.
--- linux-user/m68k/cpu_loop.c | 35 +++++++---------------------------- 1 file changed, 7 insertions(+), 28 deletions(-)
linux-user/m68k/cpu_loop.c +7 -28
@@ -21,13 +21,14 @@#include "qemu-common.h" #include "qemu.h" #include "cpu_loop-common.h" +#include "signal-common.h" +void cpu_loop (CPUM68KState *env) {CPUState *cs =env_cpu (env);int trapnr;unsigned int n; -target_siginfo_t info;for (;;) {cpu_exec_start (cs);
@@ -44,25 +45,13 @@ void cpu_loop(CPUM68KState *env)case EXCP_ILLEGAL :case EXCP_LINEA :case EXCP_LINEF : - info.si_signo =TARGET_SIGILL ; - info.si_errno =0 ; - info.si_code =TARGET_ILL_ILLOPN ; - info._sifields._sigfault._addr = env->pc; -queue_signal (env, info.si_signo,QEMU_SI_FAULT , &info); +force_sig_fault (TARGET_SIGILL ,TARGET_ILL_ILLOPN , env->pc);break ;case EXCP_CHK : - info.si_signo =TARGET_SIGFPE ; - info.si_errno =0 ; - info.si_code =TARGET_FPE_INTOVF ; - info._sifields._sigfault._addr = env->pc; -queue_signal (env, info.si_signo,QEMU_SI_FAULT , &info); +force_sig_fault (TARGET_SIGFPE ,TARGET_FPE_INTOVF , env->pc);break ;case EXCP_DIV0 : - info.si_signo =TARGET_SIGFPE ; - info.si_errno =0 ; - info.si_code =TARGET_FPE_INTDIV ; - info._sifields._sigfault._addr = env->pc; -queue_signal (env, info.si_signo,QEMU_SI_FAULT , &info); +force_sig_fault (TARGET_SIGFPE ,TARGET_FPE_INTDIV , env->pc);break ;case EXCP_TRAP0 : {
@@ -89,20 +78,10 @@ void cpu_loop(CPUM68KState *env)/* just indicate that signals should be handled asap */ break ;case EXCP_ACCESS : - { - info.si_signo =TARGET_SIGSEGV ; - info.si_errno =0 ; -/* XXX: check env->error_code */ - info.si_code =TARGET_SEGV_MAPERR ; - info._sifields._sigfault._addr = env->mmu.ar; -queue_signal (env, info.si_signo,QEMU_SI_FAULT , &info); - } +force_sigsegv_for_addr (env->mmu.ar);break ;case EXCP_DEBUG : - info.si_signo =TARGET_SIGTRAP ; - info.si_errno =0 ; - info.si_code =TARGET_TRAP_BRKPT ; -queue_signal (env, info.si_signo,QEMU_SI_FAULT , &info); +force_sig_fault (TARGET_SIGTRAP ,TARGET_TRAP_BRKPT , env->pc);break ;case EXCP_ATOMIC :cpu_exec_step_atomic (cs);
Signature · 1 line
2.25.1
Re: [PATCH v2 19/30] linux-user/m68k: Use force_sig_fault, force_sigsegv_for_addr
Quoted 5 lines · Richard Henderson
Use the new functions instead of setting up a
target_siginfo_tand callingqueue_signal.Signed-off-by Richard Henderson <[email protected]>
Commit message should mention behaviour changes.
Otherwise
thanks
-- PMM
PATCH v2 20/30 linux-user/microblaze: Use force_sig_fault, force_sigsegv_for_addr
In reply to Richard HendersonUse the new functions instead of setting up a target_siginfo_t and calling queue_signal.
--- linux-user/microblaze/cpu_loop.c | 73 +++++++++++++------------------- 1 file changed, 29 insertions(+), 44 deletions(-)
linux-user/microblaze/cpu_loop.c +29 -44
@@ -21,13 +21,14 @@#include "qemu-common.h" #include "qemu.h" #include "cpu_loop-common.h" +#include "signal-common.h" +void cpu_loop (CPUMBState *env) {CPUState *cs =env_cpu (env); -int trapnr, ret; -target_siginfo_t info; - +int trapnr, ret, si_code; +while (1 ) {cpu_exec_start (cs); trapnr =cpu_exec (cs);
@@ -36,18 +37,12 @@ void cpu_loop(CPUMBState *env)switch (trapnr) {case 0xaa : - { - info.si_signo =TARGET_SIGSEGV ; - info.si_errno =0 ; -/* XXX: check env->error_code */ - info.si_code =TARGET_SEGV_MAPERR ; - info._sifields._sigfault._addr =0 ; -queue_signal (env, info.si_signo,QEMU_SI_FAULT , &info); - } +/* FIXME: save vaddr in tlb_fill */ +force_sigsegv_for_addr (0 );break ;case EXCP_INTERRUPT : -/* just indicate that signals should be handled asap */ -break ; +/* just indicate that signals should be handled asap */ +break ;case EXCP_SYSCALL :/* Return address is 4 bytes after the call. */ env->regs[14 ] +=4 ;
@@ -75,6 +70,7 @@ void cpu_loop(CPUMBState *env)*/ env->regs[14 ] = env->pc;break ; +case EXCP_HW_EXCP : env->regs[17 ] = env->pc +4 ;if (env->iflags &D_FLAG ) {
@@ -82,42 +78,31 @@ void cpu_loop(CPUMBState *env) env->pc -=4 ;/* FIXME: if branch was immed, replay the imm as well. */ } - env->iflags &= ~(IMM_FLAG |D_FLAG ); -switch (env->esr &31 ) { -case ESR_EC_DIVZERO : - info.si_signo =TARGET_SIGFPE ; - info.si_errno =0 ; - info.si_code =TARGET_FPE_FLTDIV ; - info._sifields._sigfault._addr =0 ; -queue_signal (env, info.si_signo,QEMU_SI_FAULT , &info); -break ; -case ESR_EC_FPU : - info.si_signo =TARGET_SIGFPE ; - info.si_errno =0 ; -if (env->fsr &FSR_IO ) { - info.si_code =TARGET_FPE_FLTINV ; - } -if (env->fsr &FSR_DZ ) { - info.si_code =TARGET_FPE_FLTDIV ; - } - info._sifields._sigfault._addr =0 ; -queue_signal (env, info.si_signo,QEMU_SI_FAULT , &info); -break ; -default : -fprintf (stderr,"Unhandled hw-exception: 0x%x\n" , - env->esr &ESR_EC_MASK ); -cpu_dump_state (cs, stderr,0 ); -exit (EXIT_FAILURE ); -break ; +case ESR_EC_DIVZERO : + si_code =TARGET_FPE_FLTDIV ; +break ; +case ESR_EC_FPU : + si_code =0 ; +if (env->fsr &FSR_IO ) { + si_code =TARGET_FPE_FLTINV ; + } +if (env->fsr &FSR_DZ ) { + si_code =TARGET_FPE_FLTDIV ; + } +break ; +default : +fprintf (stderr,"Unhandled hw-exception: 0x%x\n" , + env->esr &ESR_EC_MASK ); +cpu_dump_state (cs, stderr,0 ); +exit (EXIT_FAILURE ); } +force_sig_fault (TARGET_SIGFPE , si_code, env->pc);break ; +case EXCP_DEBUG : - info.si_signo =TARGET_SIGTRAP ; - info.si_errno =0 ; - info.si_code =TARGET_TRAP_BRKPT ; -queue_signal (env, info.si_signo,QEMU_SI_FAULT , &info); +force_sig_fault (TARGET_SIGTRAP ,TARGET_TRAP_BRKPT , env->pc);break ;case EXCP_ATOMIC :cpu_exec_step_atomic (cs);
Signature · 1 line
2.25.1
Re: [PATCH v2 20/30] linux-user/microblaze: Use force_sig_fault, force_sigsegv_for_addr
Quoted 5 lines · Richard Henderson
Use the new functions instead of setting up a
target_siginfo_tand callingqueue_signal.Signed-off-by Richard Henderson <[email protected]>
thanks
-- PMM
PATCH v2 21/30 linux-user/microblaze: Fix SIGFPE si_codes
In reply to Richard HendersonFix a typo for ESR_EC_DIVZERO, which is integral not floating-point. Fix the if ladder for decoding floating-point exceptions.
--- linux-user/microblaze/cpu_loop.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-)
linux-user/microblaze/cpu_loop.c +15 -5
@@ -81,15 +81,25 @@ void cpu_loop(CPUMBState *env) env->iflags &= ~(IMM_FLAG |D_FLAG );switch (env->esr &31 ) {case ESR_EC_DIVZERO : - si_code =TARGET_FPE_FLTDIV ; + si_code =TARGET_FPE_INTDIV ;break ;case ESR_EC_FPU : - si_code =0 ; -if (env->fsr &FSR_IO ) { +/* +* Note that the kernel passes along fsr as si_code +* if there's no recognized bit set. Possibly this +* implies that si_code is 0, but follow the structure. +*/ + si_code = env->fsr; +if (si_code &FSR_IO ) { si_code =TARGET_FPE_FLTINV ; - } -if (env->fsr &FSR_DZ ) { + }else if (si_code &FSR_OF ) { + si_code =TARGET_FPE_FLTOVF ; + }else if (si_code &FSR_UF ) { + si_code =TARGET_FPE_FLTUND ; + }else if (si_code &FSR_DZ ) { si_code =TARGET_FPE_FLTDIV ; + }else if (si_code &FSR_DO ) { + si_code =TARGET_FPE_FLTRES ; }break ;default :
Signature · 1 line
2.25.1
Re: [PATCH v2 21/30] linux-user/microblaze: Fix SIGFPE si_codes
Quoted 18 lines · Richard Henderson
Fix a typo for
ESR_EC_DIVZERO, which is integral not floating-point. Fix the if ladder for decoding floating-point exceptions.Signed-off-by Richard Henderson <[email protected]>--- linux-user/microblaze/cpu_loop.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-)linux-user/microblaze/cpu_loop.c +0
-1@@ -81,15 +81,25 @@ void cpu_loop(CPUMBState *env) env->iflags &= ~(IMM_FLAG |D_FLAG );switch (env->esr &31 ) {case ESR_EC_DIVZERO : - si_code =TARGET_FPE_FLTDIV ;
linux-user/microblaze/cpu_loop.c void cpu_loop(CPUMBState *env) · line 91
Quoted 10 lines
linux-user/microblaze/cpu_loop.c +6
-2+ si_code =TARGET_FPE_INTDIV ;break ;case ESR_EC_FPU : - si_code =0 ; -if (env->fsr &FSR_IO ) { +/* +* Note that the kernel passes along fsr as si_code +* if there's no recognized bit set. Possibly this +* implies that si_code is 0, but follow the structure. +*/
In theory it should: the Microblaze processor reference guide
https://www.xilinx.com/support/documentation/sw_manuals/mb_ref_guide.pdf
defines only 5 bits in the FSR, all of which we look at here. However our implementation provides two loopholes by which a high bit might get set:
* our implementation of MTS rfsr, rX doesn't prevent high bits being set by the guest
* our implementation of gdbstub writes to fsr doesn't prevent high bits being set by the guest
I don't know whether the real h/w makes the reserved FSR high bits RAZ/WI or not; the spec doesn't say either way.
Quoted 6 lines
linux-user/microblaze/cpu_loop.c +3
-2+ si_code = env->fsr; +if (si_code &FSR_IO ) { si_code =TARGET_FPE_FLTINV ; - } -if (env->fsr &FSR_DZ ) { + }else if (si_code &FSR_OF ) {
linux-user/microblaze/cpu_loop.c void cpu_loop(CPUMBState *env) · line 105
Quoted 10 lines
linux-user/microblaze/cpu_loop.c +6
-0+ si_code =TARGET_FPE_FLTOVF ; + }else if (si_code &FSR_UF ) { + si_code =TARGET_FPE_FLTUND ; + }else if (si_code &FSR_DZ ) { si_code =TARGET_FPE_FLTDIV ; + }else if (si_code &FSR_DO ) { + si_code =TARGET_FPE_FLTRES ; }break ;default :
Side note: our implementation will never set FSR_DO; we don't implement the denormal number handling the FPU does, where:
* operations on input denormals return a QNaN and set FSR.DO
* output denormals are flushed to + or - zero, setting FSR.UF
Anyway,
thanks
-- PMM
PATCH v2 22/30 linux-user/mips: Improve do_break
In reply to Richard HendersonRename to do_tr_or_bp, as per the kernel function.
Add a 'trap' argument, akin to the kernel's si_code, but clearer. The return value is always 0, so change the return value to void. Use force_sig and force_sig_fault.
--- linux-user/mips/cpu_loop.c | 47 ++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 20 deletions(-)
linux-user/mips/cpu_loop.c +27 -20
@@ -21,6 +21,7 @@#include "qemu-common.h" #include "qemu.h" #include "cpu_loop-common.h" +#include "signal-common.h" #include "elf.h" #include "internal.h" #include "fpu_helper.h"
@@ -38,29 +39,25 @@ enum { BRK_DIVZERO = 7 }; -static int do_break (CPUMIPSState *env,target_siginfo_t *info, -unsigned int code) +static void do_tr_or_bp (CPUMIPSState *env,unsigned int code,bool trap) { -int ret =-1 ; +target_ulong pc = env->active_tc.PC;switch (code) {case BRK_OVERFLOW : +force_sig_fault (TARGET_SIGFPE ,TARGET_FPE_INTOVF , pc); +break ;case BRK_DIVZERO : - info->si_signo =TARGET_SIGFPE ; - info->si_errno =0 ; - info->si_code = (code ==BRK_OVERFLOW ) ?FPE_INTOVF :FPE_INTDIV ; -queue_signal (env, info->si_signo,QEMU_SI_FAULT , &*info); - ret =0 ; +force_sig_fault (TARGET_SIGFPE ,TARGET_FPE_INTDIV , pc);break ;default : - info->si_signo =TARGET_SIGTRAP ; - info->si_errno =0 ; -queue_signal (env, info->si_signo,QEMU_SI_FAULT , &*info); - ret =0 ; +if (trap) { +force_sig (TARGET_SIGTRAP ); + }else { +force_sig_fault (TARGET_SIGTRAP ,TARGET_TRAP_BRKPT , pc); + }break ; } - -return ret; }void cpu_loop (CPUMIPSState *env)
@@ -214,6 +211,13 @@ done_syscall:abi_ulong trap_instr;unsigned int code; +/* +* FIXME: It would be better to decode the trap number +* during translate, and store it in error_code while +* raising the exception. We should not be re-reading +* the opcode here. +*/ +if (env->hflags &MIPS_HFLAG_M16 ) {if (env->insn_flags &ASE_MICROMIPS ) {/* microMIPS mode */
@@ -266,9 +270,7 @@ done_syscall: } } -if (do_break (env, &info, code) !=0 ) { - goto error; - } +do_tr_or_bp (env, code, false); }break ;case EXCP_TRAP :
@@ -276,6 +278,13 @@ done_syscall:abi_ulong trap_instr;unsigned int code =0 ; +/* +* FIXME: It would be better to decode the trap number +* during translate, and store it in error_code while +* raising the exception. We should not be re-reading +* the opcode here. +*/ +if (env->hflags &MIPS_HFLAG_M16 ) {/* microMIPS mode */ abi_ulong instr[2 ];
@@ -302,9 +311,7 @@ done_syscall: } } -if (do_break (env, &info, code) !=0 ) { - goto error; - } +do_tr_or_bp (env, code, true); }break ;case EXCP_ATOMIC :
Signature · 1 line
2.25.1
Re: [PATCH v2 22/30] linux-user/mips: Improve do_break
Quoted 11 lines · Richard Henderson
Rename to
do_tr_or_bp, as per the kernel function.
Add a 'trap' argument, akin to the kernel'ssi_code, but clearer. The return value is always 0, so change the return value to void. Useforce_sigandforce_sig_fault.Signed-off-by Richard Henderson <[email protected]>--- linux-user/mips/cpu_loop.c | 47 ++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 20 deletions(-)default:
linux-user/mips/cpu_loop.c enum { · line 58
Quoted 3 lines
linux-user/mips/cpu_loop.c +0
-3- info->si_signo =TARGET_SIGTRAP ; - info->si_errno =0 ; -queue_signal (env, info->si_signo,QEMU_SI_FAULT , &*info);
PATCH v2 23/30 linux-user/mips: Use force_sig_fault, force_sigsegv_for_addr
In reply to Richard HendersonUse the new functions instead of setting up a target_siginfo_t and calling queue_signal.
--- linux-user/mips/cpu_loop.c | 45 ++++++++++++-------------------------- 1 file changed, 14 insertions(+), 31 deletions(-)
linux-user/mips/cpu_loop.c +14 -31
@@ -63,8 +63,7 @@ static void do_tr_or_bp(CPUMIPSState *env, unsigned int code, bool trap)void cpu_loop (CPUMIPSState *env) {CPUState *cs =env_cpu (env); -target_siginfo_t info; -int trapnr; +int trapnr, si_code;abi_long ret;# ifdef TARGET_ABI_MIPSO32 unsigned int syscall_num;
@@ -157,52 +156,36 @@ done_syscall:case EXCP_TLBS :case EXCP_AdEL:case EXCP_AdES: - info.si_signo =TARGET_SIGSEGV ; - info.si_errno =0 ; -/* XXX: check env->error_code */ - info.si_code =TARGET_SEGV_MAPERR ; - info._sifields._sigfault._addr = env->CP0_BadVAddr; -queue_signal (env, info.si_signo,QEMU_SI_FAULT , &info); +force_sigsegv_for_addr (env->CP0_BadVAddr);break ;case EXCP_CpU:case EXCP_RI : - info.si_signo =TARGET_SIGILL ; - info.si_errno =0 ; - info.si_code =0 ; -queue_signal (env, info.si_signo,QEMU_SI_FAULT , &info); +case EXCP_DSPDIS : +force_sig (TARGET_SIGILL );break ;case EXCP_INTERRUPT :/* just indicate that signals should be handled asap */ break ;case EXCP_DEBUG : - info.si_signo =TARGET_SIGTRAP ; - info.si_errno =0 ; - info.si_code =TARGET_TRAP_BRKPT ; -queue_signal (env, info.si_signo,QEMU_SI_FAULT , &info); -break ; -case EXCP_DSPDIS : - info.si_signo =TARGET_SIGILL ; - info.si_errno =0 ; - info.si_code =TARGET_ILL_ILLOPC ; -queue_signal (env, info.si_signo,QEMU_SI_FAULT , &info); +force_sig_fault (TARGET_SIGTRAP ,TARGET_TRAP_BRKPT , + env->active_tc.PC);break ;case EXCP_FPE : - info.si_signo =TARGET_SIGFPE ; - info.si_errno =0 ; - info.si_code =TARGET_FPE_FLTUNK ; + si_code =TARGET_FPE_FLTUNK ;if (GET_FP_CAUSE (env->active_fpu.fcr31) &FP_INVALID ) { - info.si_code =TARGET_FPE_FLTINV ; + si_code =TARGET_FPE_FLTINV ; }else if (GET_FP_CAUSE (env->active_fpu.fcr31) &FP_DIV0 ) { - info.si_code =TARGET_FPE_FLTDIV ; + si_code =TARGET_FPE_FLTDIV ; }else if (GET_FP_CAUSE (env->active_fpu.fcr31) &FP_OVERFLOW ) { - info.si_code =TARGET_FPE_FLTOVF ; + si_code =TARGET_FPE_FLTOVF ; }else if (GET_FP_CAUSE (env->active_fpu.fcr31) &FP_UNDERFLOW ) { - info.si_code =TARGET_FPE_FLTUND ; + si_code =TARGET_FPE_FLTUND ; }else if (GET_FP_CAUSE (env->active_fpu.fcr31) &FP_INEXACT ) { - info.si_code =TARGET_FPE_FLTRES ; + si_code =TARGET_FPE_FLTRES ; } -queue_signal (env, info.si_signo,QEMU_SI_FAULT , &info); +force_sig_fault (TARGET_SIGFPE , si_code, env->active_tc.PC);break ; +/* The code below was inspired by the MIPS Linux kernel trap * handling code in arch/mips/kernel/traps.c. */
Signature · 1 line
2.25.1
Re: [PATCH v2 23/30] linux-user/mips: Use force_sig_fault, force_sigsegv_for_addr
Quoted 8 lines · Richard Henderson
Use the new functions instead of setting up a
target_siginfo_tand callingqueue_signal.Signed-off-by Richard Henderson <[email protected]>--- linux-user/mips/cpu_loop.c | 45 ++++++++++++-------------------------- 1 file changed, 14 insertions(+), 31 deletions(-)
with the usual caveat about documenting behaviour changes in the commit message.
thanks
-- PMM
PATCH v2 24/30 linux-user/openrisc: Use force_sig_fault, force_sigsegv_for_addr
In reply to Richard HendersonUse the new functions instead of setting up a target_siginfo_t and calling queue_signal.
--- linux-user/openrisc/cpu_loop.c | 37 +++++++++------------------------- 1 file changed, 10 insertions(+), 27 deletions(-)
linux-user/openrisc/cpu_loop.c +10 -27
@@ -21,13 +21,14 @@#include "qemu-common.h" #include "qemu.h" #include "cpu_loop-common.h" +#include "signal-common.h" +void cpu_loop (CPUOpenRISCState *env) {CPUState *cs =env_cpu (env);int trapnr;abi_long ret; -target_siginfo_t info;for (;;) {cpu_exec_start (cs);
@@ -54,42 +55,24 @@ void cpu_loop(CPUOpenRISCState *env)break ;case EXCP_DPF :case EXCP_IPF : +force_sigsegv_for_addr (env->eear); +break ;case EXCP_RANGE : - info.si_signo =TARGET_SIGSEGV ; - info.si_errno =0 ; - info.si_code =TARGET_SEGV_MAPERR ; - info._sifields._sigfault._addr = env->pc; -queue_signal (env, info.si_signo,QEMU_SI_FAULT , &info); +case EXCP_FPE : +/* ??? The kernel vectors both of these to unhandled_exception. */ +force_sig (TARGET_SIGSEGV );break ;case EXCP_ALIGN : - info.si_signo =TARGET_SIGBUS ; - info.si_errno =0 ; - info.si_code =TARGET_BUS_ADRALN ; - info._sifields._sigfault._addr = env->pc; -queue_signal (env, info.si_signo,QEMU_SI_FAULT , &info); +force_sig_fault (TARGET_SIGBUS ,TARGET_BUS_ADRALN , env->eear);break ;case EXCP_ILLEGAL : - info.si_signo =TARGET_SIGILL ; - info.si_errno =0 ; - info.si_code =TARGET_ILL_ILLOPC ; - info._sifields._sigfault._addr = env->pc; -queue_signal (env, info.si_signo,QEMU_SI_FAULT , &info); -break ; -case EXCP_FPE : - info.si_signo =TARGET_SIGFPE ; - info.si_errno =0 ; - info.si_code =0 ; - info._sifields._sigfault._addr = env->pc; -queue_signal (env, info.si_signo,QEMU_SI_FAULT , &info); +force_sig_fault (TARGET_SIGILL ,TARGET_ILL_ILLOPC , env->pc);break ;case EXCP_INTERRUPT :/* We processed the pending cpu work above. */ break ;case EXCP_DEBUG : - info.si_signo =TARGET_SIGTRAP ; - info.si_errno =0 ; - info.si_code =TARGET_TRAP_BRKPT ; -queue_signal (env, info.si_signo,QEMU_SI_FAULT , &info); +force_sig_fault (TARGET_SIGTRAP ,TARGET_TRAP_BRKPT , env->pc);break ;case EXCP_ATOMIC :cpu_exec_step_atomic (cs);
Signature · 1 line
2.25.1
Re: [PATCH v2 24/30] linux-user/openrisc: Use force_sig_fault, force_sigsegv_for_addr
Quoted 33 lines · Richard Henderson
Use the new functions instead of setting up a
target_siginfo_tand callingqueue_signal.Signed-off-by Richard Henderson <[email protected]>--- linux-user/openrisc/cpu_loop.c | 37 +++++++++------------------------- 1 file changed, 10 insertions(+), 27 deletions(-)linux-user/openrisc/cpu_loop.c +2
-1@@ -21,13 +21,14 @@#include "qemu-common.h" #include "qemu.h" #include "cpu_loop-common.h" +#include "signal-common.h" +void cpu_loop (CPUOpenRISCState *env) {CPUState *cs =env_cpu (env);int trapnr;abi_long ret; -target_siginfo_t info;for (;;) {cpu_exec_start (cs);@@ -54,42 +55,24 @@ void cpu_loop(CPUOpenRISCState *env)break ;case EXCP_DPF :case EXCP_IPF :
linux-user/openrisc/cpu_loop.c void cpu_loop(CPUOpenRISCState *env) · line 62
Quoted 10 lines
linux-user/openrisc/cpu_loop.c +4
-5+force_sigsegv_for_addr (env->eear); +break ;case EXCP_RANGE : - info.si_signo =TARGET_SIGSEGV ; - info.si_errno =0 ; - info.si_code =TARGET_SEGV_MAPERR ; - info._sifields._sigfault._addr = env->pc; -queue_signal (env, info.si_signo,QEMU_SI_FAULT , &info); +case EXCP_FPE : +/* ??? The kernel vectors both of these to unhandled_exception. */
I think that EXCP_RANGE should for us be unreachable in user-only mode (because it can only happen if the relevant bits in SR are set, and SR is writeable only in supervisor mode, and its starting value doesn't set these bits). So we could just delete the EXCP_RANGE handling and let it hit the default g_assert_not_reached() case.
EXCP_FPE is more tricky -- this happens for FP exceptions, where the enabling bit is in the FPCSR, which does appear to be writeable from user mode. So either:
* our mtspr is wrong and should either be not allowing writes to FPCSR in usermode (or at least sanitizing them)
* the Linux kernel for openrisc is wrong, because a userspace program that sets FPCSR.FPEE can make it run into unhandled_exception() and die(), and it should be doing something else, like delivering a suitable SIGFPE
linux-user/openrisc/cpu_loop.c void cpu_loop(CPUOpenRISCState *env) · line 66
Quoted 9 lines
linux-user/openrisc/cpu_loop.c +2
-5+force_sig (TARGET_SIGSEGV );break ;case EXCP_ALIGN : - info.si_signo =TARGET_SIGBUS ; - info.si_errno =0 ; - info.si_code =TARGET_BUS_ADRALN ; - info._sifields._sigfault._addr = env->pc; -queue_signal (env, info.si_signo,QEMU_SI_FAULT , &info); +force_sig_fault (TARGET_SIGBUS ,TARGET_BUS_ADRALN , env->eear);
So we were reporting completely the wrong address previously ?
Quoted 29 lines
linux-user/openrisc/cpu_loop.c +2
-17break ;case EXCP_ILLEGAL : - info.si_signo =TARGET_SIGILL ; - info.si_errno =0 ; - info.si_code =TARGET_ILL_ILLOPC ; - info._sifields._sigfault._addr = env->pc; -queue_signal (env, info.si_signo,QEMU_SI_FAULT , &info); -break ; -case EXCP_FPE : - info.si_signo =TARGET_SIGFPE ; - info.si_errno =0 ; - info.si_code =0 ; - info._sifields._sigfault._addr = env->pc; -queue_signal (env, info.si_signo,QEMU_SI_FAULT , &info); +force_sig_fault (TARGET_SIGILL ,TARGET_ILL_ILLOPC , env->pc);break ;case EXCP_INTERRUPT :/* We processed the pending cpu work above. */ break ;case EXCP_DEBUG : - info.si_signo =TARGET_SIGTRAP ; - info.si_errno =0 ; - info.si_code =TARGET_TRAP_BRKPT ; -queue_signal (env, info.si_signo,QEMU_SI_FAULT , &info); +force_sig_fault (TARGET_SIGTRAP ,TARGET_TRAP_BRKPT , env->pc);break ;case EXCP_ATOMIC :cpu_exec_step_atomic (cs); --
Quoted 1 line
2.25.1
thanks
-- PMM
Re: [PATCH v2 24/30] linux-user/openrisc: Use force_sig_fault, force_sigsegv_for_addr
Quoted 5 lines · Peter Maydell
I think that
EXCP_RANGEshould for us be unreachable in user-only mode (because it can only happen if the relevant bits in SR are set, and SR is writeable only in supervisor mode, and its starting value doesn't set these bits). So we could just delete theEXCP_RANGEhandling and let it hit the defaultg_assert_not_reached()case.
If I also disable the SR case from gdbstub.
Quoted 9 lines
EXCP_FPEis more tricky -- this happens for FP exceptions, where the enabling bit is in the FPCSR, which does appear to be writeable from user mode. So either:
* our mtspr is wrong and should either be not allowing writes to FPCSR in usermode (or at least sanitizing them)
* the Linux kernel for openrisc is wrong, because a userspace program that sets FPCSR.FPEE can make it run intounhandled_exception()anddie(), and it should be doing something else, like delivering a suitable SIGFPE
I believe the kernel to be buggy. But it also point to the fact that no one has written fenv.h for or1k for musl, so no one has tried to use those bits.
r~
Re: [PATCH v2 24/30] linux-user/openrisc: Use force_sig_fault, force_sigsegv_for_addr
Quoted 19 lines · Richard Henderson
Quoted 5 lines · Peter Maydell
I think that
EXCP_RANGEshould for us be unreachable in user-only mode (because it can only happen if the relevant bits in SR are set, and SR is writeable only in supervisor mode, and its starting value doesn't set these bits). So we could just delete theEXCP_RANGEhandling and let it hit the defaultg_assert_not_reached()case.If I also disable the SR case from gdbstub.
Quoted 9 lines
EXCP_FPEis more tricky -- this happens for FP exceptions, where the enabling bit is in the FPCSR, which does appear to be writeable from user mode. So either:
* our mtspr is wrong and should either be not allowing writes to FPCSR in usermode (or at least sanitizing them)
* the Linux kernel for openrisc is wrong, because a userspace program that sets FPCSR.FPEE can make it run intounhandled_exception()anddie(), and it should be doing something else, like delivering a suitable SIGFPE
Quoted 2 lines
I believe the kernel to be buggy. But it also point to the fact that no one has written
fenv.hfor or1k for musl, so no one has tried to use those bits.
Hi,
*On User Accessible FPCSR*
As per the spec FPCSR should not be accessible in user space. But...
I am currently working on the OpenRISC port for glibc, and at first I was planning for FPU support but this was one thing that slowed me down.
For that reason I proposed an architecture change to allow setting fpcsr in user space, it seems that is allowed by almost all other architectures:
https://openrisc.io/proposals/p17-user-mode-fpcsr
I think I could also simulate it in the kernel by catching the mtspr failure and then performing it on behalf of the user if its for MTSPR.
At the moment I am going with softfpu until I can spend time on sorting out the FPCSR issue.
*On QEMU*
When I started to develop the glibc FPU code, I put a patch into qemu to allow for using mtspr and mfspr in user space:
branch:
https://github.com/stffrdhrn/qemu/commits/or1k-glibc
commit:
https://github.com/stffrdhrn/qemu/commit/dfa5331bf43f71535847c585a6b3f5779a422b13
User space access it not allowed as per trans_l_mfspr, trans_l_mfspr. I did not post this upstream as it's not as per spec.
I hope it helps a bit.
-Stafford
PATCH v2 25/30 linux-user/ppc: Use force_sig_fault, force_sigsegv_for_addr
In reply to Richard HendersonUse the new functions instead of setting up a target_siginfo_t and calling queue_signal.
The user-only version of ppc_cpu_tlb_fill does not distinguish between the various hw codes. Drop all of that and just use the new force_sigsegv_for_addr function. The fault address for POWERPC_EXCP_ISI is nip exactly, not nip - 4.
--- linux-user/ppc/cpu_loop.c | 142 ++++++++------------------------------ 1 file changed, 30 insertions(+), 112 deletions(-)
linux-user/ppc/cpu_loop.c +30 -112
@@ -21,6 +21,8 @@#include "qemu-common.h" #include "qemu.h" #include "cpu_loop-common.h" +#include "signal-common.h" +static inline uint64_t cpu_ppc_get_tb (CPUPPCState *env) {
@@ -74,8 +76,7 @@ int ppc_dcr_write (ppc_dcr_t *dcr_env, int dcrn, uint32_t val)void cpu_loop (CPUPPCState *env) {CPUState *cs =env_cpu (env); -target_siginfo_t info; -int trapnr; +int trapnr, si_signo, si_code;target_ulong ret;for (;;) {
@@ -100,61 +101,10 @@ void cpu_loop(CPUPPCState *env) "Aborting\n");break ;case POWERPC_EXCP_DSI :/* Data storage exception */ -/* XXX: check this. Seems bugged */ -switch (env->error_code &0xFF000000 ) { -case 0x40000000 : -case 0x42000000 : - info.si_signo =TARGET_SIGSEGV ; - info.si_errno =0 ; - info.si_code =TARGET_SEGV_MAPERR ; -break ; -case 0x04000000 : - info.si_signo =TARGET_SIGILL ; - info.si_errno =0 ; - info.si_code =TARGET_ILL_ILLADR ; -break ; -case 0x08000000 : - info.si_signo =TARGET_SIGSEGV ; - info.si_errno =0 ; - info.si_code =TARGET_SEGV_ACCERR ; -break ; -default : -/* Let's send a regular segfault... */ -EXCP_DUMP (env,"Invalid segfault errno (%02x)\n" , - env->error_code); - info.si_signo =TARGET_SIGSEGV ; - info.si_errno =0 ; - info.si_code =TARGET_SEGV_MAPERR ; -break ; - } - info._sifields._sigfault._addr = env->spr[SPR_DAR ]; -queue_signal (env, info.si_signo,QEMU_SI_FAULT , &info); +force_sigsegv_for_addr (env->spr[SPR_DAR ]);break ;case POWERPC_EXCP_ISI :/* Instruction storage exception */ -/* XXX: check this */ -switch (env->error_code &0xFF000000 ) { -case 0x40000000 : - info.si_signo =TARGET_SIGSEGV ; - info.si_errno =0 ; - info.si_code =TARGET_SEGV_MAPERR ; -break ; -case 0x10000000 : -case 0x08000000 : - info.si_signo =TARGET_SIGSEGV ; - info.si_errno =0 ; - info.si_code =TARGET_SEGV_ACCERR ; -break ; -default : -/* Let's send a regular segfault... */ -EXCP_DUMP (env,"Invalid segfault errno (%02x)\n" , - env->error_code); - info.si_signo =TARGET_SIGSEGV ; - info.si_errno =0 ; - info.si_code =TARGET_SEGV_MAPERR ; -break ; - } - info._sifields._sigfault._addr = env->nip -4 ; -queue_signal (env, info.si_signo,QEMU_SI_FAULT , &info); +force_sigsegv_for_addr (env->nip);break ;case POWERPC_EXCP_EXTERNAL :/* External input */ cpu_abort(cs, "External interrupt while in user mode. "
@@ -162,35 +112,30 @@ void cpu_loop(CPUPPCState *env)break ;case POWERPC_EXCP_ALIGN :/* Alignment exception */ /* XXX: check this */ - info.si_signo =TARGET_SIGBUS ; - info.si_errno =0 ; - info.si_code =TARGET_BUS_ADRALN ; - info._sifields._sigfault._addr = env->nip; -queue_signal (env, info.si_signo,QEMU_SI_FAULT , &info); +force_sig_fault (TARGET_SIGBUS ,TARGET_BUS_ADRALN , env->nip);break ;case POWERPC_EXCP_PROGRAM :/* Program exception */ case POWERPC_EXCP_HV_EMU :/* HV emulation */ /* XXX: check this */ switch (env->error_code & ~0xF ) {case POWERPC_EXCP_FP : - info.si_signo =TARGET_SIGFPE ; - info.si_errno =0 ; + si_signo =TARGET_SIGFPE ;switch (env->error_code &0xF ) {case POWERPC_EXCP_FP_OX : - info.si_code =TARGET_FPE_FLTOVF ; + si_code =TARGET_FPE_FLTOVF ;break ;case POWERPC_EXCP_FP_UX : - info.si_code =TARGET_FPE_FLTUND ; + si_code =TARGET_FPE_FLTUND ;break ;case POWERPC_EXCP_FP_ZX :case POWERPC_EXCP_FP_VXZDZ : - info.si_code =TARGET_FPE_FLTDIV ; + si_code =TARGET_FPE_FLTDIV ;break ;case POWERPC_EXCP_FP_XX : - info.si_code =TARGET_FPE_FLTRES ; + si_code =TARGET_FPE_FLTRES ;break ;case POWERPC_EXCP_FP_VXSOFT : - info.si_code =TARGET_FPE_FLTINV ; + si_code =TARGET_FPE_FLTINV ;break ;case POWERPC_EXCP_FP_VXSNAN :case POWERPC_EXCP_FP_VXISI :
@@ -199,51 +144,50 @@ void cpu_loop(CPUPPCState *env)case POWERPC_EXCP_FP_VXVC :case POWERPC_EXCP_FP_VXSQRT :case POWERPC_EXCP_FP_VXCVI : - info.si_code =TARGET_FPE_FLTSUB ; + si_code =TARGET_FPE_FLTSUB ;break ;default :EXCP_DUMP (env,"Unknown floating point exception (%02x)\n" , env->error_code); + si_code =0 ;break ; }break ;case POWERPC_EXCP_INVAL : - info.si_signo =TARGET_SIGILL ; - info.si_errno =0 ; + si_signo =TARGET_SIGILL ;switch (env->error_code &0xF ) {case POWERPC_EXCP_INVAL_INVAL : - info.si_code =TARGET_ILL_ILLOPC ; + si_code =TARGET_ILL_ILLOPC ;break ;case POWERPC_EXCP_INVAL_LSWX : - info.si_code =TARGET_ILL_ILLOPN ; + si_code =TARGET_ILL_ILLOPN ;break ;case POWERPC_EXCP_INVAL_SPR : - info.si_code =TARGET_ILL_PRVREG ; + si_code =TARGET_ILL_PRVREG ;break ;case POWERPC_EXCP_INVAL_FP : - info.si_code =TARGET_ILL_COPROC ; + si_code =TARGET_ILL_COPROC ;break ;default :EXCP_DUMP (env,"Unknown invalid operation (%02x)\n" , env->error_code &0xF ); - info.si_code =TARGET_ILL_ILLADR ; + si_code =TARGET_ILL_ILLADR ;break ; }break ;case POWERPC_EXCP_PRIV : - info.si_signo =TARGET_SIGILL ; - info.si_errno =0 ; + si_signo =TARGET_SIGILL ;switch (env->error_code &0xF ) {case POWERPC_EXCP_PRIV_OPC : - info.si_code =TARGET_ILL_PRVOPC ; + si_code =TARGET_ILL_PRVOPC ;break ;case POWERPC_EXCP_PRIV_REG : - info.si_code =TARGET_ILL_PRVREG ; + si_code =TARGET_ILL_PRVREG ;break ;default :EXCP_DUMP (env,"Unknown privilege violation (%02x)\n" , env->error_code &0xF ); - info.si_code =TARGET_ILL_PRVOPC ; + si_code =TARGET_ILL_PRVOPC ;break ; }break ;
@@ -256,28 +200,19 @@ void cpu_loop(CPUPPCState *env) env->error_code);break ; } - info._sifields._sigfault._addr = env->nip; -queue_signal (env, info.si_signo,QEMU_SI_FAULT , &info); +force_sig_fault (si_signo, si_code, env->nip);break ;case POWERPC_EXCP_FPU :/* Floating-point unavailable exception */ - info.si_signo =TARGET_SIGILL ; - info.si_errno =0 ; - info.si_code =TARGET_ILL_COPROC ; - info._sifields._sigfault._addr = env->nip; -queue_signal (env, info.si_signo,QEMU_SI_FAULT , &info); +case POWERPC_EXCP_APU :/* Auxiliary processor unavailable */ +case POWERPC_EXCP_SPEU :/* SPE/embedded floating-point unavail. */ +case POWERPC_EXCP_VPU :/* Vector unavailable exception */ +force_sig_fault (TARGET_SIGILL ,TARGET_ILL_COPROC , env->nip);break ;case POWERPC_EXCP_SYSCALL :/* System call exception */ case POWERPC_EXCP_SYSCALL_VECTORED :cpu_abort (cs,"Syscall exception while in user mode. " "Aborting\n" );break ; -case POWERPC_EXCP_APU :/* Auxiliary processor unavailable */ - info.si_signo =TARGET_SIGILL ; - info.si_errno =0 ; - info.si_code =TARGET_ILL_COPROC ; - info._sifields._sigfault._addr = env->nip; -queue_signal (env, info.si_signo,QEMU_SI_FAULT , &info); -break ;case POWERPC_EXCP_DECR :/* Decrementer exception */ cpu_abort (cs,"Decrementer interrupt while in user mode. " "Aborting\n" );
@@ -298,13 +233,6 @@ void cpu_loop(CPUPPCState *env)cpu_abort (cs,"Instruction TLB exception while in user mode. " "Aborting\n" );break ; -case POWERPC_EXCP_SPEU :/* SPE/embedded floating-point unavail. */ - info.si_signo =TARGET_SIGILL ; - info.si_errno =0 ; - info.si_code =TARGET_ILL_COPROC ; - info._sifields._sigfault._addr = env->nip; -queue_signal (env, info.si_signo,QEMU_SI_FAULT , &info); -break ;case POWERPC_EXCP_EFPDI :/* Embedded floating-point data IRQ */ cpu_abort (cs,"Embedded floating-point data IRQ not handled\n" );break ;
@@ -361,13 +289,6 @@ void cpu_loop(CPUPPCState *env)cpu_abort (cs,"Hypervisor instruction segment exception " "while in user mode. Aborting\n" );break ; -case POWERPC_EXCP_VPU :/* Vector unavailable exception */ - info.si_signo =TARGET_SIGILL ; - info.si_errno =0 ; - info.si_code =TARGET_ILL_COPROC ; - info._sifields._sigfault._addr = env->nip; -queue_signal (env, info.si_signo,QEMU_SI_FAULT , &info); -break ;case POWERPC_EXCP_PIT :/* Programmable interval timer IRQ */ cpu_abort (cs,"Programmable interval timer interrupt " "while in user mode. Aborting\n" );
@@ -450,10 +371,7 @@ void cpu_loop(CPUPPCState *env) env->gpr[3 ] = ret;break ;case EXCP_DEBUG : - info.si_signo =TARGET_SIGTRAP ; - info.si_errno =0 ; - info.si_code =TARGET_TRAP_BRKPT ; -queue_signal (env, info.si_signo,QEMU_SI_FAULT , &info); +force_sig_fault (TARGET_SIGTRAP ,TARGET_TRAP_BRKPT , env->nip);break ;case EXCP_INTERRUPT :/* just indicate that signals should be handled asap */
Signature · 1 line
2.25.1
Re: [PATCH v2 25/30] linux-user/ppc: Use force_sig_fault, force_sigsegv_for_addr
Quoted 10 lines · Richard Henderson
Use the new functions instead of setting up a
target_siginfo_tand callingqueue_signal.The user-only version of
ppc_cpu_tlb_filldoes not distinguish between the various hw codes. Drop all of that and just use the newforce_sigsegv_for_addrfunction. The fault address forPOWERPC_EXCP_ISIis nip exactly, not nip - 4.Signed-off-by Richard Henderson <[email protected]>
thanks
-- PMM
PATCH v2 26/30 linux-user/riscv: Use force_sig_fault, force_sigsegv_for_addr
In reply to Richard HendersonUse the new functions instead of setting up a target_siginfo_t and calling queue_signal.
--- linux-user/riscv/cpu_loop.c | 36 +++++++----------------------------- 1 file changed, 7 insertions(+), 29 deletions(-)
linux-user/riscv/cpu_loop.c +7 -29
@@ -22,14 +22,14 @@#include "qemu/error-report.h" #include "qemu.h" #include "cpu_loop-common.h" +#include "signal-common.h" #include "elf.h" #include "semihosting/common-semi.h" void cpu_loop (CPURISCVState *env) {CPUState *cs =env_cpu (env); -int trapnr, signum, sigcode; -target_ulong sigaddr; +int trapnr;target_ulong ret;for (;;) {
@@ -38,10 +38,6 @@ void cpu_loop(CPURISCVState *env)cpu_exec_end (cs);process_queued_cpu_work (cs); - signum =0 ; - sigcode =0 ; - sigaddr =0 ; -switch (trapnr) {case EXCP_INTERRUPT :/* just indicate that signals should be handled asap */
@@ -77,46 +73,28 @@ void cpu_loop(CPURISCVState *env) }break ;case RISCV_EXCP_ILLEGAL_INST : - signum =TARGET_SIGILL ; - sigcode =TARGET_ILL_ILLOPC ; +force_sig_fault (TARGET_SIGILL ,TARGET_ILL_ILLOPC , env->pc);break ;case RISCV_EXCP_BREAKPOINT : - signum =TARGET_SIGTRAP ; - sigcode =TARGET_TRAP_BRKPT ; - sigaddr = env->pc; +case EXCP_DEBUG : + gdbstep: +force_sig_fault (TARGET_SIGTRAP ,TARGET_TRAP_BRKPT , env->pc);break ;case RISCV_EXCP_INST_PAGE_FAULT :case RISCV_EXCP_LOAD_PAGE_FAULT :case RISCV_EXCP_STORE_PAGE_FAULT : - signum =TARGET_SIGSEGV ; - sigcode =TARGET_SEGV_MAPERR ; - sigaddr = env->badaddr; +force_sigsegv_for_addr (env->badaddr);break ;case RISCV_EXCP_SEMIHOST : env->gpr[xA0] =do_common_semihosting (cs); env->pc +=4 ;break ; -case EXCP_DEBUG : - gdbstep: - signum =TARGET_SIGTRAP ; - sigcode =TARGET_TRAP_BRKPT ; -break ;default :EXCP_DUMP (env,"\nqemu: unhandled CPU exception %#x - aborting\n" , trapnr);exit (EXIT_FAILURE ); } -if (signum) { -target_siginfo_t info = { - .si_signo = signum, - .si_errno =0 , - .si_code = sigcode, - ._sifields._sigfault._addr = sigaddr - }; -queue_signal (env, info.si_signo,QEMU_SI_FAULT , &info); - } -process_pending_signals (env); } }
Signature · 1 line
2.25.1
Re: [PATCH v2 26/30] linux-user/riscv: Use force_sig_fault, force_sigsegv_for_addr
Quoted 8 lines · Richard Henderson
Use the new functions instead of setting up a
target_siginfo_tand callingqueue_signal.Signed-off-by Richard Henderson <[email protected]>--- linux-user/riscv/cpu_loop.c | 36 +++++++----------------------------- 1 file changed, 7 insertions(+), 29 deletions(-)
usual commit message nit, otherwise
thanks
-- PMM
PATCH v2 27/30 linux-user/s390x: Use force_sig_fault, force_sigsegv_for_addr
In reply to Richard HendersonUse the new functions instead of setting up a target_siginfo_t and calling queue_signal.
--- linux-user/s390x/cpu_loop.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-)
linux-user/s390x/cpu_loop.c +5 -11
@@ -21,6 +21,8 @@#include "qemu-common.h" #include "qemu.h" #include "cpu_loop-common.h" +#include "signal-common.h" +/* s390x masks the fault address it reports in si_addr for SIGSEGV and SIGBUS */ #define S390X_FAIL_ADDR_MASK -4096LL
@@ -58,7 +60,6 @@ void cpu_loop(CPUS390XState *env) {CPUState *cs =env_cpu (env);int trapnr, n, sig; -target_siginfo_t info;target_ulong addr;abi_long ret;
@@ -110,11 +111,8 @@ void cpu_loop(CPUS390XState *env) goto do_signal_pc;case PGM_PROTECTION :case PGM_ADDRESSING : - sig =TARGET_SIGSEGV ; -/* XXX: check env->error_code */ - n =TARGET_SEGV_MAPERR ; - addr = env->__excp_addr &S390X_FAIL_ADDR_MASK ; - goto do_signal; +force_sigsegv_for_addr (env->__excp_addr &S390X_FAIL_ADDR_MASK ); +break ;case PGM_EXECUTE :case PGM_SPECIFICATION :case PGM_SPECIAL_OP :
@@ -157,11 +155,7 @@ void cpu_loop(CPUS390XState *env)*/ env->psw.addr += env->int_pgm_ilen; do_signal: - info.si_signo = sig; - info.si_errno =0 ; - info.si_code = n; - info._sifields._sigfault._addr = addr; -queue_signal (env, info.si_signo,QEMU_SI_FAULT , &info); +force_sig_fault (sig, n, addr);break ;case EXCP_ATOMIC :
Signature · 1 line
2.25.1
Re: [PATCH v2 27/30] linux-user/s390x: Use force_sig_fault, force_sigsegv_for_addr
Quoted 7 lines · Richard Henderson
Use the new functions instead of setting up a
target_siginfo_tand callingqueue_signal.Signed-off-by Richard Henderson <[email protected]>--- linux-user/s390x/cpu_loop.c | 16 +++++-----------
thanks
-- PMM
PATCH v2 28/30 linux-user/sh4: Use force_sig_fault, force_sigsegv_for_addr
In reply to Richard HendersonUse the new functions instead of setting up a target_siginfo_t and calling queue_signal.
--- linux-user/sh4/cpu_loop.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-)
linux-user/sh4/cpu_loop.c +4 -10
@@ -21,12 +21,13 @@#include "qemu-common.h" #include "qemu.h" #include "cpu_loop-common.h" +#include "signal-common.h" +void cpu_loop (CPUSH4State *env) {CPUState *cs =env_cpu (env);int trapnr, ret; -target_siginfo_t info;while (1 ) {bool arch_interrupt = true;
@@ -58,18 +59,11 @@ void cpu_loop(CPUSH4State *env)/* just indicate that signals should be handled asap */ break ;case EXCP_DEBUG : - info.si_signo =TARGET_SIGTRAP ; - info.si_errno =0 ; - info.si_code =TARGET_TRAP_BRKPT ; -queue_signal (env, info.si_signo,QEMU_SI_FAULT , &info); +force_sig_fault (TARGET_SIGTRAP ,TARGET_TRAP_BRKPT , env->pc);break ;case 0xa0 :case 0xc0 : - info.si_signo =TARGET_SIGSEGV ; - info.si_errno =0 ; - info.si_code =TARGET_SEGV_MAPERR ; - info._sifields._sigfault._addr = env->tea; -queue_signal (env, info.si_signo,QEMU_SI_FAULT , &info); +force_sigsegv_for_addr (env->tea);break ;case EXCP_ATOMIC :cpu_exec_step_atomic (cs);
Signature · 1 line
2.25.1
Re: [PATCH v2 28/30] linux-user/sh4: Use force_sig_fault, force_sigsegv_for_addr
Quoted 8 lines · Richard Henderson
Use the new functions instead of setting up a
target_siginfo_tand callingqueue_signal.Signed-off-by Richard Henderson <[email protected]>--- linux-user/sh4/cpu_loop.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-)
thanks
-- PMM
PATCH v2 29/30 linux-user/sparc: Use force_sig_fault, force_sigsegv_for_addr
In reply to Richard HendersonUse the new functions instead of setting up a target_siginfo_t and calling queue_signal.
--- linux-user/sparc/cpu_loop.c | 38 +++++++------------------------------ 1 file changed, 7 insertions(+), 31 deletions(-)
linux-user/sparc/cpu_loop.c +7 -31
@@ -21,6 +21,7 @@#include "qemu-common.h" #include "qemu.h" #include "cpu_loop-common.h" +#include "signal-common.h" #define SPARC64_STACK_BIAS 2047
@@ -153,7 +154,6 @@ void cpu_loop (CPUSPARCState *env)CPUState *cs =env_cpu (env);int trapnr;abi_long ret; -target_siginfo_t info;while (1 ) {cpu_exec_start (cs);
@@ -219,14 +219,7 @@ void cpu_loop (CPUSPARCState *env)break ;case TT_TFAULT :case TT_DFAULT : - { - info.si_signo =TARGET_SIGSEGV ; - info.si_errno =0 ; -/* XXX: check env->error_code */ - info.si_code =TARGET_SEGV_MAPERR ; - info._sifields._sigfault._addr = env->mmuregs[4 ]; -queue_signal (env, info.si_signo,QEMU_SI_FAULT , &info); - } +force_sigsegv_for_addr (env->mmuregs[4 ]);break ;#else case TT_SPILL :/* window overflow */
@@ -236,18 +229,10 @@ void cpu_loop (CPUSPARCState *env)restore_window (env);break ;case TT_TFAULT : +force_sigsegv_for_addr (cpu_tsptr (env)->tpc); +break ;case TT_DFAULT : - { - info.si_signo =TARGET_SIGSEGV ; - info.si_errno =0 ; -/* XXX: check env->error_code */ - info.si_code =TARGET_SEGV_MAPERR ; -if (trapnr ==TT_DFAULT ) - info._sifields._sigfault._addr = env->dmmu.mmuregs[4 ]; -else - info._sifields._sigfault._addr =cpu_tsptr (env)->tpc; -queue_signal (env, info.si_signo,QEMU_SI_FAULT , &info); - } +force_sigsegv_for_addr (env->dmmu.mmuregs[4 ]);break ;#ifndef TARGET_ABI32 case 0x16e :
@@ -264,19 +249,10 @@ void cpu_loop (CPUSPARCState *env)/* just indicate that signals should be handled asap */ break ;case TT_ILL_INSN : - { - info.si_signo =TARGET_SIGILL ; - info.si_errno =0 ; - info.si_code =TARGET_ILL_ILLOPC ; - info._sifields._sigfault._addr = env->pc; -queue_signal (env, info.si_signo,QEMU_SI_FAULT , &info); - } +force_sig_fault (TARGET_SIGILL ,TARGET_ILL_ILLOPC , env->pc);break ;case EXCP_DEBUG : - info.si_signo =TARGET_SIGTRAP ; - info.si_errno =0 ; - info.si_code =TARGET_TRAP_BRKPT ; -queue_signal (env, info.si_signo,QEMU_SI_FAULT , &info); +force_sig_fault (TARGET_SIGTRAP ,TARGET_TRAP_BRKPT , env->pc);break ;case EXCP_ATOMIC :cpu_exec_step_atomic (cs);
Signature · 1 line
2.25.1
Re: [PATCH v2 29/30] linux-user/sparc: Use force_sig_fault, force_sigsegv_for_addr
Quoted 6 lines · Richard Henderson
Use the new functions instead of setting up a
target_siginfo_tand callingqueue_signal.Signed-off-by Richard Henderson <[email protected]>---
thanks
-- PMM
PATCH v2 30/30 linux-user/xtensa: Use force_sig_fault, force_sigsegv_for_addr
In reply to Richard HendersonUse the new functions instead of setting up a target_siginfo_t and calling queue_signal.
--- linux-user/xtensa/cpu_loop.c | 34 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 22 deletions(-)
linux-user/xtensa/cpu_loop.c +12 -22
@@ -20,6 +20,8 @@#include "qemu/osdep.h" #include "qemu.h" #include "cpu_loop-common.h" +#include "signal-common.h" +static void xtensa_rfw (CPUXtensaState *env) {
@@ -124,7 +126,6 @@ static void xtensa_underflow12(CPUXtensaState *env)void cpu_loop (CPUXtensaState *env) {CPUState *cs =env_cpu (env); -target_siginfo_t info;abi_ulong ret;int trapnr;
@@ -161,14 +162,12 @@ void cpu_loop(CPUXtensaState *env)case EXC_USER :switch (env->sregs[EXCCAUSE ]) {case ILLEGAL_INSTRUCTION_CAUSE : +force_sig_fault (TARGET_SIGILL ,TARGET_ILL_ILLOPC , + env->sregs[EPC1 ]); +break ;case PRIVILEGED_CAUSE : - info.si_signo =TARGET_SIGILL ; - info.si_errno =0 ; - info.si_code = - env->sregs[EXCCAUSE ] ==ILLEGAL_INSTRUCTION_CAUSE ? -TARGET_ILL_ILLOPC :TARGET_ILL_PRVOPC ; - info._sifields._sigfault._addr = env->sregs[EPC1 ]; -queue_signal (env, info.si_signo,QEMU_SI_FAULT , &info); +force_sig_fault (TARGET_SIGILL ,TARGET_ILL_PRVOPC , + env->sregs[EPC1 ]);break ;case SYSCALL_CAUSE :
@@ -217,20 +216,13 @@ void cpu_loop(CPUXtensaState *env)break ;case INTEGER_DIVIDE_BY_ZERO_CAUSE : - info.si_signo =TARGET_SIGFPE ; - info.si_errno =0 ; - info.si_code =TARGET_FPE_INTDIV ; - info._sifields._sigfault._addr = env->sregs[EPC1 ]; -queue_signal (env, info.si_signo,QEMU_SI_FAULT , &info); +force_sig_fault (TARGET_SIGFPE ,TARGET_FPE_INTDIV , + env->sregs[EPC1 ]);break ;case LOAD_PROHIBITED_CAUSE :case STORE_PROHIBITED_CAUSE : - info.si_signo =TARGET_SIGSEGV ; - info.si_errno =0 ; - info.si_code =TARGET_SEGV_ACCERR ; - info._sifields._sigfault._addr = env->sregs[EXCVADDR ]; -queue_signal (env, info.si_signo,QEMU_SI_FAULT , &info); +force_sigsegv_for_addr (env->sregs[EXCVADDR ]);break ;default :
@@ -239,10 +231,8 @@ void cpu_loop(CPUXtensaState *env) }break ;case EXCP_DEBUG : - info.si_signo =TARGET_SIGTRAP ; - info.si_errno =0 ; - info.si_code =TARGET_TRAP_BRKPT ; -queue_signal (env, info.si_signo,QEMU_SI_FAULT , &info); +force_sig_fault (TARGET_SIGTRAP ,TARGET_TRAP_BRKPT , + env->sregs[EPC1 ]);break ;case EXC_DEBUG :default :
Signature · 1 line
2.25.1
Re: [PATCH v2 30/30] linux-user/xtensa: Use force_sig_fault, force_sigsegv_for_addr
Quoted 9 lines · Richard Henderson
Use the new functions instead of setting up a
target_siginfo_tand callingqueue_signal.Signed-off-by Richard Henderson <[email protected]>--- linux-user/xtensa/cpu_loop.c | 34 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 22 deletions(-)
thanks
-- PMM