diff mbox series

[v5,44/67] linux-user: Add cpu_loop_exit_sigbus

Message ID 20211015041053.2769193-45-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:10 a.m. UTC
This is a new interface to be provided by the os emulator for
raising SIGBUS on fault.  Use the new record_sigbus target hook.

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

---
 include/exec/exec-all.h | 14 ++++++++++++++
 linux-user/signal.c     | 14 ++++++++++++++
 2 files changed, 28 insertions(+)

-- 
2.25.1

Comments

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

> This is a new interface to be provided by the os emulator for

> raising SIGBUS on fault.  Use the new record_sigbus target hook.

>

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

> ---

>  include/exec/exec-all.h | 14 ++++++++++++++

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

>  2 files changed, 28 insertions(+)

>


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



> diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h

> index f74578500c..6bb2a0f7ec 100644

> --- a/include/exec/exec-all.h

> +++ b/include/exec/exec-all.h

> @@ -700,6 +700,20 @@ void QEMU_NORETURN cpu_loop_exit_sigsegv(CPUState

> *cpu, target_ulong addr,

>                                           MMUAccessType access_type,

>                                           bool maperr, uintptr_t ra);

>

> +/**

> + * cpu_loop_exit_sigbus:

> + * @cpu: the cpu context

> + * @addr: the guest address of the alignment fault

> + * @access_type: access was read/write/execute

> + * @ra: host pc for unwinding

> + *

> + * Use the TCGCPUOps hook to record cpu state, do guest operating system

> + * specific things to raise SIGBUS, and jump to the main cpu loop.

> + */

> +void QEMU_NORETURN cpu_loop_exit_sigbus(CPUState *cpu, target_ulong addr,

> +                                        MMUAccessType access_type,

> +                                        uintptr_t ra);

> +

>  #else

>  static inline void mmap_lock(void) {}

>  static inline void mmap_unlock(void) {}

> diff --git a/linux-user/signal.c b/linux-user/signal.c

> index 9d60abc038..df2c8678d0 100644

> --- a/linux-user/signal.c

> +++ b/linux-user/signal.c

> @@ -706,6 +706,20 @@ void cpu_loop_exit_sigsegv(CPUState *cpu,

> target_ulong addr,

>      cpu_loop_exit_restore(cpu, ra);

>  }

>

> +void cpu_loop_exit_sigbus(CPUState *cpu, target_ulong addr,

> +                          MMUAccessType access_type, uintptr_t ra)

> +{

> +    const struct TCGCPUOps *tcg_ops = CPU_GET_CLASS(cpu)->tcg_ops;

> +

> +    if (tcg_ops->record_sigbus) {

> +        tcg_ops->record_sigbus(cpu, addr, access_type, ra);

> +    }

> +

> +    force_sig_fault(TARGET_SIGBUS, TARGET_BUS_ADRALN, addr);

> +    cpu->exception_index = EXCP_INTERRUPT;

> +    cpu_loop_exit_restore(cpu, ra);

> +}

> +

>  /* abort execution with signal */

>  static void QEMU_NORETURN dump_core_and_abort(int target_sig)

>  {

> --

> 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:14 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">This is a new interface to be provided by the os emulator for<br>
raising SIGBUS on fault.  Use the new record_sigbus target hook.<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>
 include/exec/exec-all.h | 14 ++++++++++++++<br>
 linux-user/signal.c     | 14 ++++++++++++++<br>
 2 files changed, 28 insertions(+)<br></blockquote><div><br></div><div><div>Reviewed-by: Warner Losh &lt;<a href="mailto:imp@bsdimp.com">imp@bsdimp.com</a>&gt;</div></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/include/exec/exec-all.h b/include/exec/exec-all.h<br>
index f74578500c..6bb2a0f7ec 100644<br>
--- a/include/exec/exec-all.h<br>
+++ b/include/exec/exec-all.h<br>
@@ -700,6 +700,20 @@ void QEMU_NORETURN cpu_loop_exit_sigsegv(CPUState *cpu, target_ulong addr,<br>
                                          MMUAccessType access_type,<br>
                                          bool maperr, uintptr_t ra);<br>
<br>
+/**<br>
+ * cpu_loop_exit_sigbus:<br>
+ * @cpu: the cpu context<br>
+ * @addr: the guest address of the alignment fault<br>
+ * @access_type: access was read/write/execute<br>
+ * @ra: host pc for unwinding<br>
+ *<br>
+ * Use the TCGCPUOps hook to record cpu state, do guest operating system<br>
+ * specific things to raise SIGBUS, and jump to the main cpu loop.<br>
+ */<br>
+void QEMU_NORETURN cpu_loop_exit_sigbus(CPUState *cpu, target_ulong addr,<br>
+                                        MMUAccessType access_type,<br>
+                                        uintptr_t ra);<br>
+<br>
 #else<br>
 static inline void mmap_lock(void) {}<br>
 static inline void mmap_unlock(void) {}<br>
diff --git a/linux-user/signal.c b/linux-user/signal.c<br>
index 9d60abc038..df2c8678d0 100644<br>
--- a/linux-user/signal.c<br>
+++ b/linux-user/signal.c<br>
@@ -706,6 +706,20 @@ void cpu_loop_exit_sigsegv(CPUState *cpu, target_ulong addr,<br>
     cpu_loop_exit_restore(cpu, ra);<br>
 }<br>
<br>
+void cpu_loop_exit_sigbus(CPUState *cpu, target_ulong addr,<br>
+                          MMUAccessType access_type, uintptr_t ra)<br>
+{<br>
+    const struct TCGCPUOps *tcg_ops = CPU_GET_CLASS(cpu)-&gt;tcg_ops;<br>
+<br>
+    if (tcg_ops-&gt;record_sigbus) {<br>
+        tcg_ops-&gt;record_sigbus(cpu, addr, access_type, ra);<br>
+    }<br>
+<br>
+    force_sig_fault(TARGET_SIGBUS, TARGET_BUS_ADRALN, addr);<br>
+    cpu-&gt;exception_index = EXCP_INTERRUPT;<br>
+    cpu_loop_exit_restore(cpu, ra);<br>
+}<br>
+<br>
 /* abort execution with signal */<br>
 static void QEMU_NORETURN dump_core_and_abort(int target_sig)<br>
 {<br>
-- <br>
2.25.1<br>
<br>
</blockquote></div></div>
Philippe Mathieu-Daudé Oct. 29, 2021, 11:35 p.m. UTC | #2
On 10/15/21 06:10, Richard Henderson wrote:
> This is a new interface to be provided by the os emulator for

> raising SIGBUS on fault.  Use the new record_sigbus target hook.

> 

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

> ---

>  include/exec/exec-all.h | 14 ++++++++++++++


This header deserves a system/user split.

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

>  2 files changed, 28 insertions(+)


Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
diff mbox series

Patch

diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h
index f74578500c..6bb2a0f7ec 100644
--- a/include/exec/exec-all.h
+++ b/include/exec/exec-all.h
@@ -700,6 +700,20 @@  void QEMU_NORETURN cpu_loop_exit_sigsegv(CPUState *cpu, target_ulong addr,
                                          MMUAccessType access_type,
                                          bool maperr, uintptr_t ra);
 
+/**
+ * cpu_loop_exit_sigbus:
+ * @cpu: the cpu context
+ * @addr: the guest address of the alignment fault
+ * @access_type: access was read/write/execute
+ * @ra: host pc for unwinding
+ *
+ * Use the TCGCPUOps hook to record cpu state, do guest operating system
+ * specific things to raise SIGBUS, and jump to the main cpu loop.
+ */
+void QEMU_NORETURN cpu_loop_exit_sigbus(CPUState *cpu, target_ulong addr,
+                                        MMUAccessType access_type,
+                                        uintptr_t ra);
+
 #else
 static inline void mmap_lock(void) {}
 static inline void mmap_unlock(void) {}
diff --git a/linux-user/signal.c b/linux-user/signal.c
index 9d60abc038..df2c8678d0 100644
--- a/linux-user/signal.c
+++ b/linux-user/signal.c
@@ -706,6 +706,20 @@  void cpu_loop_exit_sigsegv(CPUState *cpu, target_ulong addr,
     cpu_loop_exit_restore(cpu, ra);
 }
 
+void cpu_loop_exit_sigbus(CPUState *cpu, target_ulong addr,
+                          MMUAccessType access_type, uintptr_t ra)
+{
+    const struct TCGCPUOps *tcg_ops = CPU_GET_CLASS(cpu)->tcg_ops;
+
+    if (tcg_ops->record_sigbus) {
+        tcg_ops->record_sigbus(cpu, addr, access_type, ra);
+    }
+
+    force_sig_fault(TARGET_SIGBUS, TARGET_BUS_ADRALN, addr);
+    cpu->exception_index = EXCP_INTERRUPT;
+    cpu_loop_exit_restore(cpu, ra);
+}
+
 /* abort execution with signal */
 static void QEMU_NORETURN dump_core_and_abort(int target_sig)
 {