| .. | .. |
|---|
| 1 | +/* SPDX-License-Identifier: GPL-2.0-only */ |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Copyright (C) 2012 ARM Ltd. |
|---|
| 3 | | - * |
|---|
| 4 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 5 | | - * it under the terms of the GNU General Public License version 2 as |
|---|
| 6 | | - * published by the Free Software Foundation. |
|---|
| 7 | | - * |
|---|
| 8 | | - * This program is distributed in the hope that it will be useful, |
|---|
| 9 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 10 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 11 | | - * GNU General Public License for more details. |
|---|
| 12 | | - * |
|---|
| 13 | | - * You should have received a copy of the GNU General Public License |
|---|
| 14 | | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
|---|
| 15 | 4 | */ |
|---|
| 16 | 5 | #ifndef __ASM_SYSCALL_H |
|---|
| 17 | 6 | #define __ASM_SYSCALL_H |
|---|
| .. | .. |
|---|
| 40 | 29 | regs->regs[0] = regs->orig_x0; |
|---|
| 41 | 30 | } |
|---|
| 42 | 31 | |
|---|
| 32 | +static inline long syscall_get_return_value(struct task_struct *task, |
|---|
| 33 | + struct pt_regs *regs) |
|---|
| 34 | +{ |
|---|
| 35 | + unsigned long val = regs->regs[0]; |
|---|
| 36 | + |
|---|
| 37 | + if (is_compat_thread(task_thread_info(task))) |
|---|
| 38 | + val = sign_extend64(val, 31); |
|---|
| 39 | + |
|---|
| 40 | + return val; |
|---|
| 41 | +} |
|---|
| 43 | 42 | |
|---|
| 44 | 43 | static inline long syscall_get_error(struct task_struct *task, |
|---|
| 45 | 44 | struct pt_regs *regs) |
|---|
| 46 | 45 | { |
|---|
| 47 | | - unsigned long error = regs->regs[0]; |
|---|
| 48 | | - |
|---|
| 49 | | - if (is_compat_thread(task_thread_info(task))) |
|---|
| 50 | | - error = sign_extend64(error, 31); |
|---|
| 46 | + unsigned long error = syscall_get_return_value(task, regs); |
|---|
| 51 | 47 | |
|---|
| 52 | 48 | return IS_ERR_VALUE(error) ? error : 0; |
|---|
| 53 | | -} |
|---|
| 54 | | - |
|---|
| 55 | | -static inline long syscall_get_return_value(struct task_struct *task, |
|---|
| 56 | | - struct pt_regs *regs) |
|---|
| 57 | | -{ |
|---|
| 58 | | - return regs->regs[0]; |
|---|
| 59 | 49 | } |
|---|
| 60 | 50 | |
|---|
| 61 | 51 | static inline void syscall_set_return_value(struct task_struct *task, |
|---|
| .. | .. |
|---|
| 75 | 65 | |
|---|
| 76 | 66 | static inline void syscall_get_arguments(struct task_struct *task, |
|---|
| 77 | 67 | struct pt_regs *regs, |
|---|
| 78 | | - unsigned int i, unsigned int n, |
|---|
| 79 | 68 | unsigned long *args) |
|---|
| 80 | 69 | { |
|---|
| 81 | | - if (n == 0) |
|---|
| 82 | | - return; |
|---|
| 70 | + args[0] = regs->orig_x0; |
|---|
| 71 | + args++; |
|---|
| 83 | 72 | |
|---|
| 84 | | - if (i + n > SYSCALL_MAX_ARGS) { |
|---|
| 85 | | - unsigned long *args_bad = args + SYSCALL_MAX_ARGS - i; |
|---|
| 86 | | - unsigned int n_bad = n + i - SYSCALL_MAX_ARGS; |
|---|
| 87 | | - pr_warning("%s called with max args %d, handling only %d\n", |
|---|
| 88 | | - __func__, i + n, SYSCALL_MAX_ARGS); |
|---|
| 89 | | - memset(args_bad, 0, n_bad * sizeof(args[0])); |
|---|
| 90 | | - } |
|---|
| 91 | | - |
|---|
| 92 | | - if (i == 0) { |
|---|
| 93 | | - args[0] = regs->orig_x0; |
|---|
| 94 | | - args++; |
|---|
| 95 | | - i++; |
|---|
| 96 | | - n--; |
|---|
| 97 | | - } |
|---|
| 98 | | - |
|---|
| 99 | | - memcpy(args, ®s->regs[i], n * sizeof(args[0])); |
|---|
| 73 | + memcpy(args, ®s->regs[1], 5 * sizeof(args[0])); |
|---|
| 100 | 74 | } |
|---|
| 101 | 75 | |
|---|
| 102 | 76 | static inline void syscall_set_arguments(struct task_struct *task, |
|---|
| 103 | 77 | struct pt_regs *regs, |
|---|
| 104 | | - unsigned int i, unsigned int n, |
|---|
| 105 | 78 | const unsigned long *args) |
|---|
| 106 | 79 | { |
|---|
| 107 | | - if (n == 0) |
|---|
| 108 | | - return; |
|---|
| 80 | + regs->orig_x0 = args[0]; |
|---|
| 81 | + args++; |
|---|
| 109 | 82 | |
|---|
| 110 | | - if (i + n > SYSCALL_MAX_ARGS) { |
|---|
| 111 | | - pr_warning("%s called with max args %d, handling only %d\n", |
|---|
| 112 | | - __func__, i + n, SYSCALL_MAX_ARGS); |
|---|
| 113 | | - n = SYSCALL_MAX_ARGS - i; |
|---|
| 114 | | - } |
|---|
| 115 | | - |
|---|
| 116 | | - if (i == 0) { |
|---|
| 117 | | - regs->orig_x0 = args[0]; |
|---|
| 118 | | - args++; |
|---|
| 119 | | - i++; |
|---|
| 120 | | - n--; |
|---|
| 121 | | - } |
|---|
| 122 | | - |
|---|
| 123 | | - memcpy(®s->regs[i], args, n * sizeof(args[0])); |
|---|
| 83 | + memcpy(®s->regs[1], args, 5 * sizeof(args[0])); |
|---|
| 124 | 84 | } |
|---|
| 125 | 85 | |
|---|
| 126 | 86 | /* |
|---|
| 127 | 87 | * We don't care about endianness (__AUDIT_ARCH_LE bit) here because |
|---|
| 128 | 88 | * AArch64 has the same system calls both on little- and big- endian. |
|---|
| 129 | 89 | */ |
|---|
| 130 | | -static inline int syscall_get_arch(void) |
|---|
| 90 | +static inline int syscall_get_arch(struct task_struct *task) |
|---|
| 131 | 91 | { |
|---|
| 132 | | - if (is_compat_task()) |
|---|
| 92 | + if (is_compat_thread(task_thread_info(task))) |
|---|
| 133 | 93 | return AUDIT_ARCH_ARM; |
|---|
| 134 | 94 | |
|---|
| 135 | 95 | return AUDIT_ARCH_AARCH64; |
|---|