qemu-e2k/linux-user
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
..
aarch64 linux-user: Emulate /proc/cpuinfo on aarch64 and arm 2023-09-01 13:33:36 -07:00
alpha linux-user: Emulate /proc/cpuinfo for Alpha 2023-09-01 13:33:47 -07:00
arm linux-user: Emulate /proc/cpuinfo on aarch64 and arm 2023-09-01 13:33:36 -07:00
cris linux-user: Split out cpu/target_proc.h 2023-09-01 13:33:09 -07:00
generic linux-user: Split TARGET_PROT_* out of syscall_defs.h 2023-07-15 08:02:32 +01:00
hexagon linux-user: Split out cpu/target_proc.h 2023-09-01 13:33:09 -07:00
hppa linux-user/hppa: clear the PSW 'N' bit when delivering signals 2023-09-19 21:12:18 +02:00
i386 linux-user: Split out cpu/target_proc.h 2023-09-01 13:33:09 -07:00
include linux-user: cleanup unused linux-user/include/host directories 2023-08-08 20:44:08 +02:00
loongarch64 linux-user: Split out cpu/target_proc.h 2023-09-01 13:33:09 -07:00
m68k linux-user: Split out cpu/target_proc.h 2023-09-01 13:33:09 -07:00
microblaze linux-user: Split out cpu/target_proc.h 2023-09-01 13:33:09 -07:00
mips linux-user: Split out cpu/target_proc.h 2023-09-01 13:33:09 -07:00
mips64 linux-user: Split out cpu/target_proc.h 2023-09-01 13:33:09 -07:00
nios2 linux-user: Split out cpu/target_proc.h 2023-09-01 13:33:09 -07:00
openrisc linux-user: Split out cpu/target_proc.h 2023-09-01 13:33:09 -07:00
ppc linux-user: Split out cpu/target_proc.h 2023-09-01 13:33:09 -07:00
riscv linux-user/riscv: Use abi type for target_ucontext 2023-09-11 11:45:55 +10:00
s390x linux-user: Split out cpu/target_proc.h 2023-09-01 13:33:09 -07:00
sh4 linux-user: Split out cpu/target_proc.h 2023-09-01 13:33:09 -07:00
sparc linux-user: Split out cpu/target_proc.h 2023-09-01 13:33:09 -07:00
x86_64 linux-user: Split out cpu/target_proc.h 2023-09-01 13:33:09 -07:00
xtensa linux-user: Split out cpu/target_proc.h 2023-09-01 13:33:09 -07:00
cpu_loop-common.h
elfload.c linux-user: Remove ELF_START_MMAP and image_info.start_mmap 2023-09-01 13:34:50 -07:00
errnos.c.inc
exit.c
fd-trans.c
fd-trans.h
flat.h
flatload.c accel/tcg: spelling fixes 2023-08-31 19:47:43 +02:00
ioctls.h
linux_loop.h
linuxload.c
loader.h linux-user: Emulate /proc/cpuinfo on aarch64 and arm 2023-09-01 13:33:36 -07:00
main.c linux-user: Define ELF_ET_DYN_BASE in $guest/target_mman.h 2023-08-08 13:27:15 -07:00
meson.build
mmap.c linux-user: Track shm regions with an interval tree 2023-09-01 13:35:57 -07:00
qemu.h linux-user: Remove ELF_START_MMAP and image_info.start_mmap 2023-09-01 13:34:50 -07:00
semihost.c
signal-common.h
signal.c
socket.h
strace.c linux-user: Fix strace output for old_mmap 2023-07-18 20:42:05 +02:00
strace.h
strace.list linux-user: Improve strace output of pread64() and pwrite64() 2023-07-08 16:55:08 +02:00
syscall_defs.h linux-user: Split TARGET_PROT_* out of syscall_defs.h 2023-07-15 08:02:32 +01:00
syscall_types.h
syscall.c linux-user/riscv: Add new extensions to hwprobe 2023-09-11 11:45:55 +10:00
thunk.c linux-user: Use ARRAY_SIZE with bitmask_transtbl 2023-08-09 07:17:42 -07:00
trace-events
trace.h
uaccess.c
uname.c
uname.h
user-internals.h
user-mmap.h linux-user: Move shmat and shmdt implementations to mmap.c 2023-09-01 13:35:02 -07:00
vm86.c