Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
| 2 | /* |
| 3 | * Access to user system call parameters and results |
| 4 | * |
| 5 | * Copyright IBM Corp. 2008 |
| 6 | * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com) |
| 7 | */ |
| 8 | |
| 9 | #ifndef _ASM_SYSCALL_H |
| 10 | #define _ASM_SYSCALL_H 1 |
| 11 | |
| 12 | #include <uapi/linux/audit.h> |
| 13 | #include <linux/sched.h> |
| 14 | #include <linux/err.h> |
| 15 | #include <asm/ptrace.h> |
| 16 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 17 | extern const unsigned long sys_call_table[]; |
| 18 | extern const unsigned long sys_call_table_emu[]; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 19 | |
| 20 | static inline long syscall_get_nr(struct task_struct *task, |
| 21 | struct pt_regs *regs) |
| 22 | { |
| 23 | return test_pt_regs_flag(regs, PIF_SYSCALL) ? |
| 24 | (regs->int_code & 0xffff) : -1; |
| 25 | } |
| 26 | |
| 27 | static inline void syscall_rollback(struct task_struct *task, |
| 28 | struct pt_regs *regs) |
| 29 | { |
| 30 | regs->gprs[2] = regs->orig_gpr2; |
| 31 | } |
| 32 | |
| 33 | static inline long syscall_get_error(struct task_struct *task, |
| 34 | struct pt_regs *regs) |
| 35 | { |
| 36 | return IS_ERR_VALUE(regs->gprs[2]) ? regs->gprs[2] : 0; |
| 37 | } |
| 38 | |
| 39 | static inline long syscall_get_return_value(struct task_struct *task, |
| 40 | struct pt_regs *regs) |
| 41 | { |
| 42 | return regs->gprs[2]; |
| 43 | } |
| 44 | |
| 45 | static inline void syscall_set_return_value(struct task_struct *task, |
| 46 | struct pt_regs *regs, |
| 47 | int error, long val) |
| 48 | { |
| 49 | regs->gprs[2] = error ? error : val; |
| 50 | } |
| 51 | |
| 52 | static inline void syscall_get_arguments(struct task_struct *task, |
| 53 | struct pt_regs *regs, |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 54 | unsigned long *args) |
| 55 | { |
| 56 | unsigned long mask = -1UL; |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 57 | unsigned int n = 6; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 58 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 59 | #ifdef CONFIG_COMPAT |
| 60 | if (test_tsk_thread_flag(task, TIF_31BIT)) |
| 61 | mask = 0xffffffff; |
| 62 | #endif |
| 63 | while (n-- > 0) |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 64 | if (n > 0) |
| 65 | args[n] = regs->gprs[2 + n] & mask; |
| 66 | |
| 67 | args[0] = regs->orig_gpr2 & mask; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | static inline void syscall_set_arguments(struct task_struct *task, |
| 71 | struct pt_regs *regs, |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 72 | const unsigned long *args) |
| 73 | { |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 74 | unsigned int n = 6; |
| 75 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 76 | while (n-- > 0) |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 77 | if (n > 0) |
| 78 | regs->gprs[2 + n] = args[n]; |
| 79 | regs->orig_gpr2 = args[0]; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 80 | } |
| 81 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 82 | static inline int syscall_get_arch(struct task_struct *task) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 83 | { |
| 84 | #ifdef CONFIG_COMPAT |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 85 | if (test_tsk_thread_flag(task, TIF_31BIT)) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 86 | return AUDIT_ARCH_S390; |
| 87 | #endif |
| 88 | return AUDIT_ARCH_S390X; |
| 89 | } |
| 90 | #endif /* _ASM_SYSCALL_H */ |