1 // SPDX-License-Identifier: GPL-2.0-or-later 2 3 #include <linux/compat.h> 4 #include <linux/context_tracking.h> 5 #include <linux/randomize_kstack.h> 6 #include <linux/entry-common.h> 7 8 #include <asm/interrupt.h> 9 #include <asm/kup.h> 10 #include <asm/syscall.h> 11 #include <asm/time.h> 12 #include <asm/tm.h> 13 #include <asm/unistd.h> 14 15 16 /* Has to run notrace because it is entered not completely "reconciled" */ 17 notrace long system_call_exception(struct pt_regs *regs, unsigned long r0) 18 { 19 long ret; 20 syscall_fn f; 21 22 add_random_kstack_offset(); 23 r0 = syscall_enter_from_user_mode(regs, r0); 24 25 if (unlikely(test_and_clear_thread_flag(TIF_SYSCALL_RET))) 26 return syscall_get_error(current, regs); 27 28 if (unlikely(r0 >= NR_syscalls)) { 29 if (unlikely(trap_is_unsupported_scv(regs))) { 30 /* Unsupported scv vector */ 31 _exception(SIGILL, regs, ILL_ILLOPC, regs->nip); 32 return regs->gpr[3]; 33 } 34 return -ENOSYS; 35 } 36 37 /* May be faster to do array_index_nospec? */ 38 barrier_nospec(); 39 40 #ifdef CONFIG_ARCH_HAS_SYSCALL_WRAPPER 41 // No COMPAT if we have SYSCALL_WRAPPER, see Kconfig 42 f = (void *)sys_call_table[r0]; 43 ret = f(regs); 44 #else 45 if (unlikely(is_compat_task())) { 46 unsigned long r3, r4, r5, r6, r7, r8; 47 48 f = (void *)compat_sys_call_table[r0]; 49 50 r3 = regs->gpr[3] & 0x00000000ffffffffULL; 51 r4 = regs->gpr[4] & 0x00000000ffffffffULL; 52 r5 = regs->gpr[5] & 0x00000000ffffffffULL; 53 r6 = regs->gpr[6] & 0x00000000ffffffffULL; 54 r7 = regs->gpr[7] & 0x00000000ffffffffULL; 55 r8 = regs->gpr[8] & 0x00000000ffffffffULL; 56 57 ret = f(r3, r4, r5, r6, r7, r8); 58 } else { 59 f = (void *)sys_call_table[r0]; 60 61 ret = f(regs->gpr[3], regs->gpr[4], regs->gpr[5], 62 regs->gpr[6], regs->gpr[7], regs->gpr[8]); 63 } 64 #endif 65 66 return ret; 67 } 68