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