diff mbox series

[v5,10/67] linux-user/host/sparc: Populate host_signal.h

Message ID 20211015041053.2769193-11-richard.henderson@linaro.org
State Superseded
Headers show
Series user-only: Cleanup SIGSEGV and SIGBUS handling | expand

Commit Message

Richard Henderson Oct. 15, 2021, 4:09 a.m. UTC
Split host_signal_pc and host_signal_write out of user-exec.c.
Drop the *BSD code, to be re-created under bsd-user/ later.
Drop the Solaris code as completely unused.

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

---
 linux-user/host/sparc/host-signal.h   | 54 ++++++++++++++++++++++-
 linux-user/host/sparc64/host-signal.h |  2 +-
 accel/tcg/user-exec.c                 | 62 +--------------------------
 3 files changed, 55 insertions(+), 63 deletions(-)

-- 
2.25.1

Comments

Warner Losh Oct. 15, 2021, 6:30 p.m. UTC | #1
On Thu, Oct 14, 2021 at 10:11 PM Richard Henderson <
richard.henderson@linaro.org> wrote:

> Split host_signal_pc and host_signal_write out of user-exec.c.

> Drop the *BSD code, to be re-created under bsd-user/ later.

> Drop the Solaris code as completely unused.

>

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

> ---

>  linux-user/host/sparc/host-signal.h   | 54 ++++++++++++++++++++++-

>  linux-user/host/sparc64/host-signal.h |  2 +-

>  accel/tcg/user-exec.c                 | 62 +--------------------------

>  3 files changed, 55 insertions(+), 63 deletions(-)

>


Reviewed-by: Warner Losh <imp@bsdimp.com>


FreeBSD has dropped sparc64, but NetBSD/OpenBSD have not. There's
a number of issues with bsd-user on {Net,Open}BSD which this does
exacerbate,
but just noting it should suffice since those issues are much bigger deals.

Warner


> diff --git a/linux-user/host/sparc/host-signal.h

> b/linux-user/host/sparc/host-signal.h

> index f4b4d65031..232943a1db 100644

> --- a/linux-user/host/sparc/host-signal.h

> +++ b/linux-user/host/sparc/host-signal.h

> @@ -1 +1,53 @@

> -#define HOST_SIGNAL_PLACEHOLDER

> +/*

> + * host-signal.h: signal info dependent on the host architecture

> + *

> + * Copyright (C) 2021 Linaro Limited

> + *

> + * This work is licensed under the terms of the GNU GPL, version 2 or

> later.

> + * See the COPYING file in the top-level directory.

> + */

> +

> +#ifndef SPARC_HOST_SIGNAL_H

> +#define SPARC_HOST_SIGNAL_H

> +

> +static inline uintptr_t host_signal_pc(ucontext_t *uc)

> +{

> +#ifdef __arch64__

> +    return uc->uc_mcontext.mc_gregs[MC_PC];

> +#else

> +    return uc->uc_mcontext.gregs[REG_PC];

> +#endif

> +}

> +

> +static inline bool host_signal_write(siginfo_t *info, ucontext_t *uc)

> +{

> +    uint32_t insn = *(uint32_t *)host_signal_pc(uc);

> +

> +    if ((insn >> 30) == 3) {

> +        switch ((insn >> 19) & 0x3f) {

> +        case 0x05: /* stb */

> +        case 0x15: /* stba */

> +        case 0x06: /* sth */

> +        case 0x16: /* stha */

> +        case 0x04: /* st */

> +        case 0x14: /* sta */

> +        case 0x07: /* std */

> +        case 0x17: /* stda */

> +        case 0x0e: /* stx */

> +        case 0x1e: /* stxa */

> +        case 0x24: /* stf */

> +        case 0x34: /* stfa */

> +        case 0x27: /* stdf */

> +        case 0x37: /* stdfa */

> +        case 0x26: /* stqf */

> +        case 0x36: /* stqfa */

> +        case 0x25: /* stfsr */

> +        case 0x3c: /* casa */

> +        case 0x3e: /* casxa */

> +            return true;

> +        }

> +    }

> +    return false;

> +}

> +

> +#endif

> diff --git a/linux-user/host/sparc64/host-signal.h

> b/linux-user/host/sparc64/host-signal.h

> index f4b4d65031..1191fe2d40 100644

> --- a/linux-user/host/sparc64/host-signal.h

> +++ b/linux-user/host/sparc64/host-signal.h

> @@ -1 +1 @@

> -#define HOST_SIGNAL_PLACEHOLDER

> +#include "../sparc/host-signal.h"

> diff --git a/accel/tcg/user-exec.c b/accel/tcg/user-exec.c

> index 0db3c5cf3c..17fe867aeb 100644

> --- a/accel/tcg/user-exec.c

> +++ b/accel/tcg/user-exec.c

> @@ -255,67 +255,7 @@ void *probe_access(CPUArchState *env, target_ulong

> addr, int size,

>      return size ? g2h(env_cpu(env), addr) : NULL;

>  }

>

> -#if defined(__sparc__)

> -

> -int cpu_signal_handler(int host_signum, void *pinfo,

> -                       void *puc)

> -{

> -    siginfo_t *info = pinfo;

> -    int is_write;

> -    uint32_t insn;

> -#if !defined(__arch64__) || defined(CONFIG_SOLARIS)

> -    uint32_t *regs = (uint32_t *)(info + 1);

> -    void *sigmask = (regs + 20);

> -    /* XXX: is there a standard glibc define ? */

> -    unsigned long pc = regs[1];

> -#else

> -#ifdef __linux__

> -    struct sigcontext *sc = puc;

> -    unsigned long pc = sc->sigc_regs.tpc;

> -    void *sigmask = (void *)sc->sigc_mask;

> -#elif defined(__OpenBSD__)

> -    struct sigcontext *uc = puc;

> -    unsigned long pc = uc->sc_pc;

> -    void *sigmask = (void *)(long)uc->sc_mask;

> -#elif defined(__NetBSD__)

> -    ucontext_t *uc = puc;

> -    unsigned long pc = _UC_MACHINE_PC(uc);

> -    void *sigmask = (void *)&uc->uc_sigmask;

> -#endif

> -#endif

> -

> -    /* XXX: need kernel patch to get write flag faster */

> -    is_write = 0;

> -    insn = *(uint32_t *)pc;

> -    if ((insn >> 30) == 3) {

> -        switch ((insn >> 19) & 0x3f) {

> -        case 0x05: /* stb */

> -        case 0x15: /* stba */

> -        case 0x06: /* sth */

> -        case 0x16: /* stha */

> -        case 0x04: /* st */

> -        case 0x14: /* sta */

> -        case 0x07: /* std */

> -        case 0x17: /* stda */

> -        case 0x0e: /* stx */

> -        case 0x1e: /* stxa */

> -        case 0x24: /* stf */

> -        case 0x34: /* stfa */

> -        case 0x27: /* stdf */

> -        case 0x37: /* stdfa */

> -        case 0x26: /* stqf */

> -        case 0x36: /* stqfa */

> -        case 0x25: /* stfsr */

> -        case 0x3c: /* casa */

> -        case 0x3e: /* casxa */

> -            is_write = 1;

> -            break;

> -        }

> -    }

> -    return handle_cpu_signal(pc, info, is_write, sigmask);

> -}

> -

> -#elif defined(__arm__)

> +#if defined(__arm__)

>

>  #if defined(__NetBSD__)

>  #include <ucontext.h>

> --

> 2.25.1

>

>
<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Oct 14, 2021 at 10:11 PM Richard Henderson &lt;<a href="mailto:richard.henderson@linaro.org">richard.henderson@linaro.org</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Split host_signal_pc and host_signal_write out of user-exec.c.<br>
Drop the *BSD code, to be re-created under bsd-user/ later.<br>
Drop the Solaris code as completely unused.<br>
<br>
Signed-off-by: Richard Henderson &lt;<a href="mailto:richard.henderson@linaro.org" target="_blank">richard.henderson@linaro.org</a>&gt;<br>

---<br>
 linux-user/host/sparc/host-signal.h   | 54 ++++++++++++++++++++++-<br>
 linux-user/host/sparc64/host-signal.h |  2 +-<br>
 accel/tcg/user-exec.c                 | 62 +--------------------------<br>
 3 files changed, 55 insertions(+), 63 deletions(-)<br></blockquote><div><br></div><div><div>Reviewed-by: Warner Losh &lt;<a href="mailto:imp@bsdimp.com">imp@bsdimp.com</a>&gt;</div><br class="gmail-Apple-interchange-newline"></div><div>FreeBSD has dropped sparc64, but NetBSD/OpenBSD have not. There&#39;s</div><div>a number of issues with bsd-user on {Net,Open}BSD which this does exacerbate,</div><div>but just noting it should suffice since those issues are much bigger deals.</div><div><br></div><div>Warner</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
diff --git a/linux-user/host/sparc/host-signal.h b/linux-user/host/sparc/host-signal.h<br>
index f4b4d65031..232943a1db 100644<br>
--- a/linux-user/host/sparc/host-signal.h<br>
+++ b/linux-user/host/sparc/host-signal.h<br>
@@ -1 +1,53 @@<br>
-#define HOST_SIGNAL_PLACEHOLDER<br>
+/*<br>
+ * host-signal.h: signal info dependent on the host architecture<br>
+ *<br>
+ * Copyright (C) 2021 Linaro Limited<br>
+ *<br>
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.<br>
+ * See the COPYING file in the top-level directory.<br>
+ */<br>
+<br>
+#ifndef SPARC_HOST_SIGNAL_H<br>
+#define SPARC_HOST_SIGNAL_H<br>
+<br>
+static inline uintptr_t host_signal_pc(ucontext_t *uc)<br>
+{<br>
+#ifdef __arch64__<br>
+    return uc-&gt;uc_mcontext.mc_gregs[MC_PC];<br>
+#else<br>
+    return uc-&gt;uc_mcontext.gregs[REG_PC];<br>
+#endif<br>
+}<br>
+<br>
+static inline bool host_signal_write(siginfo_t *info, ucontext_t *uc)<br>
+{<br>
+    uint32_t insn = *(uint32_t *)host_signal_pc(uc);<br>
+<br>
+    if ((insn &gt;&gt; 30) == 3) {<br>
+        switch ((insn &gt;&gt; 19) &amp; 0x3f) {<br>
+        case 0x05: /* stb */<br>
+        case 0x15: /* stba */<br>
+        case 0x06: /* sth */<br>
+        case 0x16: /* stha */<br>
+        case 0x04: /* st */<br>
+        case 0x14: /* sta */<br>
+        case 0x07: /* std */<br>
+        case 0x17: /* stda */<br>
+        case 0x0e: /* stx */<br>
+        case 0x1e: /* stxa */<br>
+        case 0x24: /* stf */<br>
+        case 0x34: /* stfa */<br>
+        case 0x27: /* stdf */<br>
+        case 0x37: /* stdfa */<br>
+        case 0x26: /* stqf */<br>
+        case 0x36: /* stqfa */<br>
+        case 0x25: /* stfsr */<br>
+        case 0x3c: /* casa */<br>
+        case 0x3e: /* casxa */<br>
+            return true;<br>
+        }<br>
+    }<br>
+    return false;<br>
+}<br>
+<br>
+#endif<br>
diff --git a/linux-user/host/sparc64/host-signal.h b/linux-user/host/sparc64/host-signal.h<br>
index f4b4d65031..1191fe2d40 100644<br>
--- a/linux-user/host/sparc64/host-signal.h<br>
+++ b/linux-user/host/sparc64/host-signal.h<br>
@@ -1 +1 @@<br>
-#define HOST_SIGNAL_PLACEHOLDER<br>
+#include &quot;../sparc/host-signal.h&quot;<br>
diff --git a/accel/tcg/user-exec.c b/accel/tcg/user-exec.c<br>
index 0db3c5cf3c..17fe867aeb 100644<br>
--- a/accel/tcg/user-exec.c<br>
+++ b/accel/tcg/user-exec.c<br>
@@ -255,67 +255,7 @@ void *probe_access(CPUArchState *env, target_ulong addr, int size,<br>
     return size ? g2h(env_cpu(env), addr) : NULL;<br>
 }<br>
<br>
-#if defined(__sparc__)<br>
-<br>
-int cpu_signal_handler(int host_signum, void *pinfo,<br>
-                       void *puc)<br>
-{<br>
-    siginfo_t *info = pinfo;<br>
-    int is_write;<br>
-    uint32_t insn;<br>
-#if !defined(__arch64__) || defined(CONFIG_SOLARIS)<br>
-    uint32_t *regs = (uint32_t *)(info + 1);<br>
-    void *sigmask = (regs + 20);<br>
-    /* XXX: is there a standard glibc define ? */<br>
-    unsigned long pc = regs[1];<br>
-#else<br>
-#ifdef __linux__<br>
-    struct sigcontext *sc = puc;<br>
-    unsigned long pc = sc-&gt;sigc_regs.tpc;<br>
-    void *sigmask = (void *)sc-&gt;sigc_mask;<br>
-#elif defined(__OpenBSD__)<br>
-    struct sigcontext *uc = puc;<br>
-    unsigned long pc = uc-&gt;sc_pc;<br>
-    void *sigmask = (void *)(long)uc-&gt;sc_mask;<br>
-#elif defined(__NetBSD__)<br>
-    ucontext_t *uc = puc;<br>
-    unsigned long pc = _UC_MACHINE_PC(uc);<br>
-    void *sigmask = (void *)&amp;uc-&gt;uc_sigmask;<br>
-#endif<br>
-#endif<br>
-<br>
-    /* XXX: need kernel patch to get write flag faster */<br>
-    is_write = 0;<br>
-    insn = *(uint32_t *)pc;<br>
-    if ((insn &gt;&gt; 30) == 3) {<br>
-        switch ((insn &gt;&gt; 19) &amp; 0x3f) {<br>
-        case 0x05: /* stb */<br>
-        case 0x15: /* stba */<br>
-        case 0x06: /* sth */<br>
-        case 0x16: /* stha */<br>
-        case 0x04: /* st */<br>
-        case 0x14: /* sta */<br>
-        case 0x07: /* std */<br>
-        case 0x17: /* stda */<br>
-        case 0x0e: /* stx */<br>
-        case 0x1e: /* stxa */<br>
-        case 0x24: /* stf */<br>
-        case 0x34: /* stfa */<br>
-        case 0x27: /* stdf */<br>
-        case 0x37: /* stdfa */<br>
-        case 0x26: /* stqf */<br>
-        case 0x36: /* stqfa */<br>
-        case 0x25: /* stfsr */<br>
-        case 0x3c: /* casa */<br>
-        case 0x3e: /* casxa */<br>
-            is_write = 1;<br>
-            break;<br>
-        }<br>
-    }<br>
-    return handle_cpu_signal(pc, info, is_write, sigmask);<br>
-}<br>
-<br>
-#elif defined(__arm__)<br>
+#if defined(__arm__)<br>
<br>
 #if defined(__NetBSD__)<br>
 #include &lt;ucontext.h&gt;<br>
-- <br>
2.25.1<br>
<br>
</blockquote></div></div>
diff mbox series

Patch

diff --git a/linux-user/host/sparc/host-signal.h b/linux-user/host/sparc/host-signal.h
index f4b4d65031..232943a1db 100644
--- a/linux-user/host/sparc/host-signal.h
+++ b/linux-user/host/sparc/host-signal.h
@@ -1 +1,53 @@ 
-#define HOST_SIGNAL_PLACEHOLDER
+/*
+ * host-signal.h: signal info dependent on the host architecture
+ *
+ * Copyright (C) 2021 Linaro Limited
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#ifndef SPARC_HOST_SIGNAL_H
+#define SPARC_HOST_SIGNAL_H
+
+static inline uintptr_t host_signal_pc(ucontext_t *uc)
+{
+#ifdef __arch64__
+    return uc->uc_mcontext.mc_gregs[MC_PC];
+#else
+    return uc->uc_mcontext.gregs[REG_PC];
+#endif
+}
+
+static inline bool host_signal_write(siginfo_t *info, ucontext_t *uc)
+{
+    uint32_t insn = *(uint32_t *)host_signal_pc(uc);
+
+    if ((insn >> 30) == 3) {
+        switch ((insn >> 19) & 0x3f) {
+        case 0x05: /* stb */
+        case 0x15: /* stba */
+        case 0x06: /* sth */
+        case 0x16: /* stha */
+        case 0x04: /* st */
+        case 0x14: /* sta */
+        case 0x07: /* std */
+        case 0x17: /* stda */
+        case 0x0e: /* stx */
+        case 0x1e: /* stxa */
+        case 0x24: /* stf */
+        case 0x34: /* stfa */
+        case 0x27: /* stdf */
+        case 0x37: /* stdfa */
+        case 0x26: /* stqf */
+        case 0x36: /* stqfa */
+        case 0x25: /* stfsr */
+        case 0x3c: /* casa */
+        case 0x3e: /* casxa */
+            return true;
+        }
+    }
+    return false;
+}
+
+#endif
diff --git a/linux-user/host/sparc64/host-signal.h b/linux-user/host/sparc64/host-signal.h
index f4b4d65031..1191fe2d40 100644
--- a/linux-user/host/sparc64/host-signal.h
+++ b/linux-user/host/sparc64/host-signal.h
@@ -1 +1 @@ 
-#define HOST_SIGNAL_PLACEHOLDER
+#include "../sparc/host-signal.h"
diff --git a/accel/tcg/user-exec.c b/accel/tcg/user-exec.c
index 0db3c5cf3c..17fe867aeb 100644
--- a/accel/tcg/user-exec.c
+++ b/accel/tcg/user-exec.c
@@ -255,67 +255,7 @@  void *probe_access(CPUArchState *env, target_ulong addr, int size,
     return size ? g2h(env_cpu(env), addr) : NULL;
 }
 
-#if defined(__sparc__)
-
-int cpu_signal_handler(int host_signum, void *pinfo,
-                       void *puc)
-{
-    siginfo_t *info = pinfo;
-    int is_write;
-    uint32_t insn;
-#if !defined(__arch64__) || defined(CONFIG_SOLARIS)
-    uint32_t *regs = (uint32_t *)(info + 1);
-    void *sigmask = (regs + 20);
-    /* XXX: is there a standard glibc define ? */
-    unsigned long pc = regs[1];
-#else
-#ifdef __linux__
-    struct sigcontext *sc = puc;
-    unsigned long pc = sc->sigc_regs.tpc;
-    void *sigmask = (void *)sc->sigc_mask;
-#elif defined(__OpenBSD__)
-    struct sigcontext *uc = puc;
-    unsigned long pc = uc->sc_pc;
-    void *sigmask = (void *)(long)uc->sc_mask;
-#elif defined(__NetBSD__)
-    ucontext_t *uc = puc;
-    unsigned long pc = _UC_MACHINE_PC(uc);
-    void *sigmask = (void *)&uc->uc_sigmask;
-#endif
-#endif
-
-    /* XXX: need kernel patch to get write flag faster */
-    is_write = 0;
-    insn = *(uint32_t *)pc;
-    if ((insn >> 30) == 3) {
-        switch ((insn >> 19) & 0x3f) {
-        case 0x05: /* stb */
-        case 0x15: /* stba */
-        case 0x06: /* sth */
-        case 0x16: /* stha */
-        case 0x04: /* st */
-        case 0x14: /* sta */
-        case 0x07: /* std */
-        case 0x17: /* stda */
-        case 0x0e: /* stx */
-        case 0x1e: /* stxa */
-        case 0x24: /* stf */
-        case 0x34: /* stfa */
-        case 0x27: /* stdf */
-        case 0x37: /* stdfa */
-        case 0x26: /* stqf */
-        case 0x36: /* stqfa */
-        case 0x25: /* stfsr */
-        case 0x3c: /* casa */
-        case 0x3e: /* casxa */
-            is_write = 1;
-            break;
-        }
-    }
-    return handle_cpu_signal(pc, info, is_write, sigmask);
-}
-
-#elif defined(__arm__)
+#if defined(__arm__)
 
 #if defined(__NetBSD__)
 #include <ucontext.h>