linux-user/s390x: Implement setup_sigtramp
Create and record the two signal trampolines.
Use them when the guest does not use SA_RESTORER.
Cc: qemu-s390x@nongnu.org
Tested-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20210929130553.121567-22-richard.henderson@linaro.org>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
diff --git a/linux-user/s390x/signal.c b/linux-user/s390x/signal.c
index 80f3408..676b948 100644
--- a/linux-user/s390x/signal.c
+++ b/linux-user/s390x/signal.c
@@ -68,7 +68,6 @@
target_sigregs sregs;
int signo;
target_sigregs_ext sregs_ext;
- uint16_t retcode;
} sigframe;
#define TARGET_UC_VXRS 2
@@ -85,7 +84,6 @@
typedef struct {
uint8_t callee_used_stack[__SIGNAL_FRAMESIZE];
- uint16_t retcode;
struct target_siginfo info;
struct target_ucontext uc;
} rt_sigframe;
@@ -209,9 +207,7 @@
if (ka->sa_flags & TARGET_SA_RESTORER) {
restorer = ka->sa_restorer;
} else {
- restorer = frame_addr + offsetof(sigframe, retcode);
- __put_user(S390_SYSCALL_OPCODE | TARGET_NR_sigreturn,
- &frame->retcode);
+ restorer = default_sigreturn;
}
/* Set up registers for signal handler */
@@ -262,9 +258,7 @@
if (ka->sa_flags & TARGET_SA_RESTORER) {
restorer = ka->sa_restorer;
} else {
- restorer = frame_addr + offsetof(typeof(*frame), retcode);
- __put_user(S390_SYSCALL_OPCODE | TARGET_NR_rt_sigreturn,
- &frame->retcode);
+ restorer = default_rt_sigreturn;
}
/* Create siginfo on the signal stack. */
@@ -405,3 +399,17 @@
unlock_user_struct(frame, frame_addr, 0);
return -TARGET_QEMU_ESIGRETURN;
}
+
+void setup_sigtramp(abi_ulong sigtramp_page)
+{
+ uint16_t *tramp = lock_user(VERIFY_WRITE, sigtramp_page, 2 + 2, 0);
+ assert(tramp != NULL);
+
+ default_sigreturn = sigtramp_page;
+ __put_user(S390_SYSCALL_OPCODE | TARGET_NR_sigreturn, &tramp[0]);
+
+ default_rt_sigreturn = sigtramp_page + 2;
+ __put_user(S390_SYSCALL_OPCODE | TARGET_NR_rt_sigreturn, &tramp[1]);
+
+ unlock_user(tramp, sigtramp_page, 2 + 2);
+}
diff --git a/linux-user/s390x/target_signal.h b/linux-user/s390x/target_signal.h
index bbfc464..64f5f42 100644
--- a/linux-user/s390x/target_signal.h
+++ b/linux-user/s390x/target_signal.h
@@ -19,4 +19,6 @@
#include "../generic/signal.h"
#define TARGET_ARCH_HAS_SETUP_FRAME
+#define TARGET_ARCH_HAS_SIGTRAMP_PAGE 1
+
#endif /* S390X_TARGET_SIGNAL_H */