diff mbox series

[v2,06/30] linux-user: Provide new force_sigsegv_for_addr() function

Message ID 20210822035537.283193-7-richard.henderson@linaro.org
State New
Headers show
Series linux-user: Clean up siginfo_t handling | expand

Commit Message

Richard Henderson Aug. 22, 2021, 3:55 a.m. UTC
Most linux-user targets so far do not distinguish between SEGV_MAPERR
and SEGV_ACCERR.  This function will be used to fix that.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>

---
 linux-user/signal-common.h |  1 +
 linux-user/signal.c        | 18 ++++++++++++++++++
 2 files changed, 19 insertions(+)

-- 
2.25.1

Comments

Peter Maydell Aug. 24, 2021, 4:20 p.m. UTC | #1
On Sun, 22 Aug 2021 at 04:55, Richard Henderson
<richard.henderson@linaro.org> wrote:
>

> Most linux-user targets so far do not distinguish between SEGV_MAPERR

> and SEGV_ACCERR.  This function will be used to fix that.

>

> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>

> ---

>  linux-user/signal-common.h |  1 +

>  linux-user/signal.c        | 18 ++++++++++++++++++

>  2 files changed, 19 insertions(+)


Reviewed-by: Peter Maydell <peter.maydell@linaro.org>


thanks
-- PMM
diff mbox series

Patch

diff --git a/linux-user/signal-common.h b/linux-user/signal-common.h
index 536c7ac2c2..9090bbb315 100644
--- a/linux-user/signal-common.h
+++ b/linux-user/signal-common.h
@@ -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,
diff --git a/linux-user/signal.c b/linux-user/signal.c
index 5ea8e4584a..0bb369c888 100644
--- a/linux-user/signal.c
+++ b/linux-user/signal.c
@@ -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.