qemu/linux-user/hppa
Mikulas Patocka 2529497cb6 linux-user/hppa: clear the PSW 'N' bit when delivering signals
qemu-hppa may crash when delivering a signal. It can be demonstrated with
this program. Compile the program with "hppa-linux-gnu-gcc -O2 signal.c"
and run it with "qemu-hppa -one-insn-per-tb a.out". It reports that the
address of the flag is 0xb4 and it crashes when attempting to touch it.

#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <signal.h>

sig_atomic_t flag;

void sig(int n)
{
	printf("&flag: %p\n", &flag);
	flag = 1;
}

int main(void)
{
	struct sigaction sa;
	struct itimerval it;

	sa.sa_handler = sig;
	sigemptyset(&sa.sa_mask);
	sa.sa_flags = SA_RESTART;
	if (sigaction(SIGALRM, &sa, NULL)) perror("sigaction"), exit(1);

	it.it_interval.tv_sec = 0;
	it.it_interval.tv_usec = 100;
	it.it_value.tv_sec = it.it_interval.tv_sec;
	it.it_value.tv_usec = it.it_interval.tv_usec;

	if (setitimer(ITIMER_REAL, &it, NULL)) perror("setitimer"), exit(1);

	while (1) {
	}
}

The reason for the crash is that the signal handling routine doesn't clear
the 'N' flag in the PSW. If the signal interrupts a thread when the 'N'
flag is set, the flag remains set at the beginning of the signal handler
and the first instruction of the signal handler is skipped.

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Acked-by: Helge Deller <deller@gmx.de>
Cc: qemu-stable@nongnu.org
Signed-off-by: Helge Deller <deller@gmx.de>
2023-09-19 21:12:18 +02:00
..
cpu_loop.c linux-user/hppa: Detect glibc ABORT_INSTRUCTION and EXCP_BREAK handler 2022-11-02 17:14:02 +01:00
meson.build meson: linux-user 2020-08-21 06:30:38 -04:00
signal.c linux-user/hppa: clear the PSW 'N' bit when delivering signals 2023-09-19 21:12:18 +02:00
sockbits.h Supply missing header guards 2019-06-12 13:20:21 +02:00
syscall.tbl linux-user: update syscall.tbl to Linux v5.13 2021-07-13 13:59:59 +02:00
syscallhdr.sh linux-user, hppa: add syscall table generation support 2020-03-20 16:02:00 +01:00
target_cpu.h linux user: Fix Lesser GPL version number 2020-11-15 16:41:26 +01:00
target_elf.h linux-user: Move CPU type name selection to a function 2018-02-25 17:27:41 +01:00
target_errno_defs.h linux-user/hppa: Move errno definitions to 'target_errno_defs.h' 2021-07-12 21:53:35 +02:00
target_fcntl.h linux-user: fix O_NONBLOCK in signalfd4() and eventfd2() syscalls 2021-02-13 22:50:49 +01:00
target_mman.h linux-user: Define ELF_ET_DYN_BASE in $guest/target_mman.h 2023-08-08 13:27:15 -07:00
target_prctl.h target/hppa: Implement prctl_unalign_sigbus 2022-01-06 11:40:52 +01:00
target_proc.h linux-user: Split out cpu/target_proc.h 2023-09-01 13:33:09 -07:00
target_resource.h linux-user: Move generic TARGET_RLIMIT* definitions to generic/target_resource.h 2022-02-01 08:01:38 +01:00
target_signal.h linux-user/hppa: Add signal trampoline for hppa target 2022-09-27 09:33:19 +02:00
target_structs.h linux user: Fix Lesser GPL version number 2020-11-15 16:41:26 +01:00
target_syscall.h linux-user/hppa: Increase guest stack size to 80MB for hppa target 2022-09-27 09:33:56 +02:00
termbits.h linux-user: Add missing termbits types and values definitions 2020-08-27 12:29:50 +02:00