[PATCH 17/30] bsd-user/signal.c: Implement rewind_if_in_safe_syscall

Warner Losh posted 30 patches 4 years ago
There is a newer version of this series
[PATCH 17/30] bsd-user/signal.c: Implement rewind_if_in_safe_syscall
Posted by Warner Losh 4 years ago
Signed-off-by: Kyle Evans <kevans@freebsd.org>
Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/qemu.h   |  2 ++
 bsd-user/signal.c | 12 ++++++++++++
 2 files changed, 14 insertions(+)

diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h
index 0e0b8db708b..e5e97632c82 100644
--- a/bsd-user/qemu.h
+++ b/bsd-user/qemu.h
@@ -454,4 +454,6 @@ static inline void *lock_user_string(abi_ulong guest_addr)
 
 #include <pthread.h>
 
+#include "user/safe-syscall.h"
+
 #endif /* QEMU_H */
diff --git a/bsd-user/signal.c b/bsd-user/signal.c
index 3fe8b2d9898..b1331f63d61 100644
--- a/bsd-user/signal.c
+++ b/bsd-user/signal.c
@@ -43,6 +43,18 @@ int target_to_host_signal(int sig)
     return sig;
 }
 
+/* Adjust the signal context to rewind out of safe-syscall if we're in it */
+static inline void rewind_if_in_safe_syscall(void *puc)
+{
+    ucontext_t *uc = (ucontext_t *)puc;
+    uintptr_t pcreg = host_signal_pc(uc);
+
+    if (pcreg > (uintptr_t)safe_syscall_start
+        && pcreg < (uintptr_t)safe_syscall_end) {
+        host_signal_set_pc(uc, (uintptr_t)safe_syscall_start);
+    }
+}
+
 /* Siginfo conversion. */
 static inline void host_to_target_siginfo_noswap(target_siginfo_t *tinfo,
         const siginfo_t *info)
-- 
2.33.1


Re: [PATCH 17/30] bsd-user/signal.c: Implement rewind_if_in_safe_syscall
Posted by Peter Maydell 4 years ago
On Sun, 9 Jan 2022 at 16:32, Warner Losh <imp@bsdimp.com> wrote:
>
> Signed-off-by: Kyle Evans <kevans@freebsd.org>
> Signed-off-by: Warner Losh <imp@bsdimp.com>
> ---
>  bsd-user/qemu.h   |  2 ++
>  bsd-user/signal.c | 12 ++++++++++++
>  2 files changed, 14 insertions(+)

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

thanks
-- PMM

Re: [PATCH 17/30] bsd-user/signal.c: Implement rewind_if_in_safe_syscall
Posted by Richard Henderson 4 years ago
On 1/10/22 3:19 AM, Warner Losh wrote:
> Signed-off-by: Kyle Evans<kevans@freebsd.org>
> Signed-off-by: Warner Losh<imp@bsdimp.com>
> ---
>   bsd-user/qemu.h   |  2 ++
>   bsd-user/signal.c | 12 ++++++++++++
>   2 files changed, 14 insertions(+)

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

r~