Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Copyright (C) 2009 Sunplus Core Technology Co., Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *  Chen Liqin <liqin.chen@sunplusct.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *  Lennox Wu <lennox.wu@sunplusct.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Copyright (C) 2012 Regents of the University of California
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/signal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/syscalls.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/tracehook.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/linkage.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <asm/ucontext.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <asm/vdso.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <asm/switch_to.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <asm/csr.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) extern u32 __user_rt_sigreturn[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #define DEBUG_SIG 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) struct rt_sigframe {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	struct siginfo info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	struct ucontext uc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #ifndef CONFIG_MMU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	u32 sigreturn_code[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #ifdef CONFIG_FPU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) static long restore_fp_state(struct pt_regs *regs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 			     union __riscv_fp_state __user *sc_fpregs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	long err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	struct __riscv_d_ext_state __user *state = &sc_fpregs->d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	size_t i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	err = __copy_from_user(&current->thread.fstate, state, sizeof(*state));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	if (unlikely(err))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	fstate_restore(current, regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	/* We support no other extension state at this time. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	for (i = 0; i < ARRAY_SIZE(sc_fpregs->q.reserved); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 		u32 value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 		err = __get_user(value, &sc_fpregs->q.reserved[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 		if (unlikely(err))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 		if (value != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) static long save_fp_state(struct pt_regs *regs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 			  union __riscv_fp_state __user *sc_fpregs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	long err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	struct __riscv_d_ext_state __user *state = &sc_fpregs->d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	size_t i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	fstate_save(current, regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	err = __copy_to_user(state, &current->thread.fstate, sizeof(*state));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	if (unlikely(err))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	/* We support no other extension state at this time. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	for (i = 0; i < ARRAY_SIZE(sc_fpregs->q.reserved); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		err = __put_user(0, &sc_fpregs->q.reserved[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 		if (unlikely(err))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) #define save_fp_state(task, regs) (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) #define restore_fp_state(task, regs) (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) static long restore_sigcontext(struct pt_regs *regs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	struct sigcontext __user *sc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	long err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	/* sc_regs is structured the same as the start of pt_regs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	err = __copy_from_user(regs, &sc->sc_regs, sizeof(sc->sc_regs));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	/* Restore the floating-point state. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	if (has_fpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		err |= restore_fp_state(regs, &sc->sc_fpregs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) SYSCALL_DEFINE0(rt_sigreturn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	struct pt_regs *regs = current_pt_regs();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	struct rt_sigframe __user *frame;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	struct task_struct *task;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	sigset_t set;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	/* Always make any pending restarted system calls return -EINTR */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	current->restart_block.fn = do_no_restart_syscall;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	frame = (struct rt_sigframe __user *)regs->sp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	if (!access_ok(frame, sizeof(*frame)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		goto badframe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		goto badframe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	set_current_blocked(&set);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	if (restore_sigcontext(regs, &frame->uc.uc_mcontext))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		goto badframe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	if (restore_altstack(&frame->uc.uc_stack))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		goto badframe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	return regs->a0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) badframe:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	task = current;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	if (show_unhandled_signals) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		pr_info_ratelimited(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 			"%s[%d]: bad frame in %s: frame=%p pc=%p sp=%p\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 			task->comm, task_pid_nr(task), __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 			frame, (void *)regs->epc, (void *)regs->sp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	force_sig(SIGSEGV);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) static long setup_sigcontext(struct rt_sigframe __user *frame,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	struct pt_regs *regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	struct sigcontext __user *sc = &frame->uc.uc_mcontext;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	long err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	/* sc_regs is structured the same as the start of pt_regs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	err = __copy_to_user(&sc->sc_regs, regs, sizeof(sc->sc_regs));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	/* Save the floating-point state. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	if (has_fpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		err |= save_fp_state(regs, &sc->sc_fpregs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) static inline void __user *get_sigframe(struct ksignal *ksig,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	struct pt_regs *regs, size_t framesize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	unsigned long sp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	/* Default to using normal stack */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	sp = regs->sp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	 * If we are on the alternate signal stack and would overflow it, don't.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	 * Return an always-bogus address instead so we will die with SIGSEGV.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	if (on_sig_stack(sp) && !likely(on_sig_stack(sp - framesize)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		return (void __user __force *)(-1UL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	/* This is the X/Open sanctioned signal stack switching. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	sp = sigsp(sp, ksig) - framesize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	/* Align the stack frame. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	sp &= ~0xfUL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	return (void __user *)sp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) static int setup_rt_frame(struct ksignal *ksig, sigset_t *set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	struct pt_regs *regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	struct rt_sigframe __user *frame;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	long err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	frame = get_sigframe(ksig, regs, sizeof(*frame));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	if (!access_ok(frame, sizeof(*frame)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	err |= copy_siginfo_to_user(&frame->info, &ksig->info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	/* Create the ucontext. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	err |= __put_user(0, &frame->uc.uc_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	err |= __put_user(NULL, &frame->uc.uc_link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	err |= __save_altstack(&frame->uc.uc_stack, regs->sp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	err |= setup_sigcontext(frame, regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	/* Set up to return from userspace. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) #ifdef CONFIG_MMU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	regs->ra = (unsigned long)VDSO_SYMBOL(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		current->mm->context.vdso, rt_sigreturn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	 * For the nommu case we don't have a VDSO.  Instead we push two
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	 * instructions to call the rt_sigreturn syscall onto the user stack.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	if (copy_to_user(&frame->sigreturn_code, __user_rt_sigreturn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 			 sizeof(frame->sigreturn_code)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	regs->ra = (unsigned long)&frame->sigreturn_code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) #endif /* CONFIG_MMU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	 * Set up registers for signal handler.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	 * Registers that we don't modify keep the value they had from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	 * user-space at the time we took the signal.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	 * We always pass siginfo and mcontext, regardless of SA_SIGINFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	 * since some things rely on this (e.g. glibc's debug/segfault.c).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	regs->epc = (unsigned long)ksig->ka.sa.sa_handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	regs->sp = (unsigned long)frame;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	regs->a0 = ksig->sig;                     /* a0: signal number */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	regs->a1 = (unsigned long)(&frame->info); /* a1: siginfo pointer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	regs->a2 = (unsigned long)(&frame->uc);   /* a2: ucontext pointer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) #if DEBUG_SIG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	pr_info("SIG deliver (%s:%d): sig=%d pc=%p ra=%p sp=%p\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 		current->comm, task_pid_nr(current), ksig->sig,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		(void *)regs->epc, (void *)regs->ra, frame);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) static void handle_signal(struct ksignal *ksig, struct pt_regs *regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	sigset_t *oldset = sigmask_to_save();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	/* Are we from a system call? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	if (regs->cause == EXC_SYSCALL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 		/* Avoid additional syscall restarting via ret_from_exception */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 		regs->cause = -1UL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 		/* If so, check system call restarting.. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 		switch (regs->a0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 		case -ERESTART_RESTARTBLOCK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 		case -ERESTARTNOHAND:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 			regs->a0 = -EINTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 		case -ERESTARTSYS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 			if (!(ksig->ka.sa.sa_flags & SA_RESTART)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 				regs->a0 = -EINTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 			fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 		case -ERESTARTNOINTR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)                         regs->a0 = regs->orig_a0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 			regs->epc -= 0x4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	/* Set up the stack frame */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	ret = setup_rt_frame(ksig, oldset, regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	signal_setup_done(ret, ksig, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) static void do_signal(struct pt_regs *regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	struct ksignal ksig;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	if (get_signal(&ksig)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 		/* Actually deliver the signal */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 		handle_signal(&ksig, regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	/* Did we come from a system call? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	if (regs->cause == EXC_SYSCALL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 		/* Avoid additional syscall restarting via ret_from_exception */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 		regs->cause = -1UL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 		/* Restart the system call - no handlers present */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 		switch (regs->a0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 		case -ERESTARTNOHAND:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 		case -ERESTARTSYS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 		case -ERESTARTNOINTR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287)                         regs->a0 = regs->orig_a0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 			regs->epc -= 0x4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 		case -ERESTART_RESTARTBLOCK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)                         regs->a0 = regs->orig_a0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 			regs->a7 = __NR_restart_syscall;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 			regs->epc -= 0x4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	 * If there is no signal to deliver, we just put the saved
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	 * sigmask back.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	restore_saved_sigmask();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306)  * notification of userspace execution resumption
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)  * - triggered by the _TIF_WORK_MASK flags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) asmlinkage __visible void do_notify_resume(struct pt_regs *regs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 					   unsigned long thread_info_flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	/* Handle pending signal delivery */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	if (thread_info_flags & _TIF_SIGPENDING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 		do_signal(regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	if (thread_info_flags & _TIF_NOTIFY_RESUME)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 		tracehook_notify_resume(regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) }