diff options
author | Warner Losh <imp@bsdimp.com> | 2022-01-08 23:48:12 -0700 |
---|---|---|
committer | Warner Losh <imp@bsdimp.com> | 2022-01-30 17:13:30 -0700 |
commit | c885ae0e4ebf207c861bf651dcf9282677281c06 (patch) | |
tree | c096183897788085ae60b3f3c33c5b78e3b6f27e /bsd-user/signal.c | |
parent | d7acd31780bea1c192854a8617255ad992b19c4d (diff) |
bsd-user/signal.c: implement do_sigreturn
Implements the meat of a sigreturn(2) system call via do_sigreturn, and
helper reset_signal_mask. Fix the prototype of do_sigreturn in qemu.h
and remove do_rt_sigreturn since it's linux only.
Signed-off-by: Stacey Son <sson@FreeBSD.org>
Signed-off-by: Kyle Evans <kevans@freebsd.org>
Signed-off-by: Warner Losh <imp@bsdimp.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Diffstat (limited to 'bsd-user/signal.c')
-rw-r--r-- | bsd-user/signal.c | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/bsd-user/signal.c b/bsd-user/signal.c index 4b398745f4..150262a87e 100644 --- a/bsd-user/signal.c +++ b/bsd-user/signal.c @@ -627,6 +627,62 @@ static void setup_frame(int sig, int code, struct target_sigaction *ka, unlock_user_struct(frame, frame_addr, 1); } +static int reset_signal_mask(target_ucontext_t *ucontext) +{ + int i; + sigset_t blocked; + target_sigset_t target_set; + TaskState *ts = (TaskState *)thread_cpu->opaque; + + for (i = 0; i < TARGET_NSIG_WORDS; i++) { + if (__get_user(target_set.__bits[i], + &ucontext->uc_sigmask.__bits[i])) { + return -TARGET_EFAULT; + } + } + target_to_host_sigset_internal(&blocked, &target_set); + ts->signal_mask = blocked; + + return 0; +} + +/* See sys/$M/$M/exec_machdep.c sigreturn() */ +long do_sigreturn(CPUArchState *env, abi_ulong addr) +{ + long ret; + abi_ulong target_ucontext; + target_ucontext_t *ucontext = NULL; + + /* Get the target ucontext address from the stack frame */ + ret = get_ucontext_sigreturn(env, addr, &target_ucontext); + if (is_error(ret)) { + return ret; + } + trace_user_do_sigreturn(env, addr); + if (!lock_user_struct(VERIFY_READ, ucontext, target_ucontext, 0)) { + goto badframe; + } + + /* Set the register state back to before the signal. */ + if (set_mcontext(env, &ucontext->uc_mcontext, 1)) { + goto badframe; + } + + /* And reset the signal mask. */ + if (reset_signal_mask(ucontext)) { + goto badframe; + } + + unlock_user_struct(ucontext, target_ucontext, 0); + return -TARGET_EJUSTRETURN; + +badframe: + if (ucontext != NULL) { + unlock_user_struct(ucontext, target_ucontext, 0); + } + return -TARGET_EFAULT; +} + void signal_init(void) { TaskState *ts = (TaskState *)thread_cpu->opaque; |