aboutsummaryrefslogtreecommitdiff
path: root/user-exec.c
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2016-05-17 15:18:03 +0100
committerPeter Maydell <peter.maydell@linaro.org>2016-06-09 15:55:02 +0100
commitf213e72f2356b77768b9cb73814a3b26ad5a0099 (patch)
treef49afba3203cac181be2cc1b5db37ac4fc584ab9 /user-exec.c
parent75809229bbf28b371afce14921ff5be98ddc5faa (diff)
downloadqemu-f213e72f2356b77768b9cb73814a3b26ad5a0099.zip
qemu-f213e72f2356b77768b9cb73814a3b26ad5a0099.tar.gz
qemu-f213e72f2356b77768b9cb73814a3b26ad5a0099.tar.bz2
user-exec: Push resume-from-signal code out to handle_cpu_signal()
Since the only caller of page_unprotect() which might cause it to need to call cpu_resume_from_signal() is handle_cpu_signal() in the user-mode code, push the longjump handling out to that function. Since this is the only caller of cpu_resume_from_signal() which passes a non-NULL puc argument, split the non-NULL handling into a new cpu_exit_tb_from_sighandler() function. This allows us to merge the softmmu and usermode implementations of the cpu_resume_from_signal() function, which are now identical. Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Reviewed-by: Sergey Fedorov <sergey.fedorov@linaro.org> Acked-by: Eduardo Habkost <ehabkost@redhat.com> Acked-by: Riku Voipio <riku.voipio@linaro.org> Message-id: 1463494687-25947-3-git-send-email-peter.maydell@linaro.org
Diffstat (limited to 'user-exec.c')
-rw-r--r--user-exec.c41
1 files changed, 29 insertions, 12 deletions
diff --git a/user-exec.c b/user-exec.c
index c809daa..efd34a6 100644
--- a/user-exec.c
+++ b/user-exec.c
@@ -55,7 +55,7 @@ static void exception_action(CPUState *cpu)
/* exit the current TB from a signal handler. The host registers are
restored in a state compatible with the CPU emulator
*/
-void cpu_resume_from_signal(CPUState *cpu, void *puc)
+static void cpu_exit_tb_from_sighandler(CPUState *cpu, void *puc)
{
#ifdef __linux__
struct ucontext *uc = puc;
@@ -63,20 +63,18 @@ void cpu_resume_from_signal(CPUState *cpu, void *puc)
struct sigcontext *uc = puc;
#endif
- if (puc) {
- /* XXX: use siglongjmp ? */
+ /* XXX: use siglongjmp ? */
#ifdef __linux__
#ifdef __ia64
- sigprocmask(SIG_SETMASK, (sigset_t *)&uc->uc_sigmask, NULL);
+ sigprocmask(SIG_SETMASK, (sigset_t *)&uc->uc_sigmask, NULL);
#else
- sigprocmask(SIG_SETMASK, &uc->uc_sigmask, NULL);
+ sigprocmask(SIG_SETMASK, &uc->uc_sigmask, NULL);
#endif
#elif defined(__OpenBSD__)
- sigprocmask(SIG_SETMASK, &uc->sc_mask, NULL);
+ sigprocmask(SIG_SETMASK, &uc->sc_mask, NULL);
#endif
- }
- cpu->exception_index = -1;
- siglongjmp(cpu->jmp_env, 1);
+
+ cpu_resume_from_signal(cpu, NULL);
}
/* 'pc' is the host PC at which the exception was raised. 'address' is
@@ -96,9 +94,28 @@ static inline int handle_cpu_signal(uintptr_t pc, unsigned long address,
pc, address, is_write, *(unsigned long *)old_set);
#endif
/* XXX: locking issue */
- if (is_write && h2g_valid(address)
- && page_unprotect(h2g(address), pc, puc)) {
- return 1;
+ if (is_write && h2g_valid(address)) {
+ switch (page_unprotect(h2g(address), pc)) {
+ case 0:
+ /* Fault not caused by a page marked unwritable to protect
+ * cached translations, must be the guest binary's problem
+ */
+ break;
+ case 1:
+ /* Fault caused by protection of cached translation; TBs
+ * invalidated, so resume execution
+ */
+ return 1;
+ case 2:
+ /* Fault caused by protection of cached translation, and the
+ * currently executing TB was modified and must be exited
+ * immediately.
+ */
+ cpu_exit_tb_from_sighandler(current_cpu, puc);
+ g_assert_not_reached();
+ default:
+ g_assert_not_reached();
+ }
}
/* Convert forcefully to guest address space, invalid addresses