| .. | .. |
|---|
| 1 | | -// SPDX-License-Identifier: GPL-2.0 |
|---|
| 1 | +/* SPDX-License-Identifier: GPL-2.0 */ |
|---|
| 2 | 2 | // Copyright (C) 2008-2009 Red Hat, Inc. All rights reserved. |
|---|
| 3 | 3 | // Copyright (C) 2005-2017 Andes Technology Corporation |
|---|
| 4 | 4 | |
|---|
| 5 | 5 | #ifndef _ASM_NDS32_SYSCALL_H |
|---|
| 6 | 6 | #define _ASM_NDS32_SYSCALL_H 1 |
|---|
| 7 | 7 | |
|---|
| 8 | +#include <uapi/linux/audit.h> |
|---|
| 8 | 9 | #include <linux/err.h> |
|---|
| 9 | 10 | struct task_struct; |
|---|
| 10 | 11 | struct pt_regs; |
|---|
| .. | .. |
|---|
| 25 | 26 | * |
|---|
| 26 | 27 | * It's only valid to call this when @task is known to be blocked. |
|---|
| 27 | 28 | */ |
|---|
| 28 | | -int syscall_get_nr(struct task_struct *task, struct pt_regs *regs) |
|---|
| 29 | +static inline int |
|---|
| 30 | +syscall_get_nr(struct task_struct *task, struct pt_regs *regs) |
|---|
| 29 | 31 | { |
|---|
| 30 | 32 | return regs->syscallno; |
|---|
| 31 | 33 | } |
|---|
| .. | .. |
|---|
| 46 | 48 | * system call instruction. This may not be the same as what the |
|---|
| 47 | 49 | * register state looked like at system call entry tracing. |
|---|
| 48 | 50 | */ |
|---|
| 49 | | -void syscall_rollback(struct task_struct *task, struct pt_regs *regs) |
|---|
| 51 | +static inline void |
|---|
| 52 | +syscall_rollback(struct task_struct *task, struct pt_regs *regs) |
|---|
| 50 | 53 | { |
|---|
| 51 | 54 | regs->uregs[0] = regs->orig_r0; |
|---|
| 52 | 55 | } |
|---|
| .. | .. |
|---|
| 61 | 64 | * It's only valid to call this when @task is stopped for tracing on exit |
|---|
| 62 | 65 | * from a system call, due to %TIF_SYSCALL_TRACE or %TIF_SYSCALL_AUDIT. |
|---|
| 63 | 66 | */ |
|---|
| 64 | | -long syscall_get_error(struct task_struct *task, struct pt_regs *regs) |
|---|
| 67 | +static inline long |
|---|
| 68 | +syscall_get_error(struct task_struct *task, struct pt_regs *regs) |
|---|
| 65 | 69 | { |
|---|
| 66 | 70 | unsigned long error = regs->uregs[0]; |
|---|
| 67 | 71 | return IS_ERR_VALUE(error) ? error : 0; |
|---|
| .. | .. |
|---|
| 78 | 82 | * It's only valid to call this when @task is stopped for tracing on exit |
|---|
| 79 | 83 | * from a system call, due to %TIF_SYSCALL_TRACE or %TIF_SYSCALL_AUDIT. |
|---|
| 80 | 84 | */ |
|---|
| 81 | | -long syscall_get_return_value(struct task_struct *task, struct pt_regs *regs) |
|---|
| 85 | +static inline long |
|---|
| 86 | +syscall_get_return_value(struct task_struct *task, struct pt_regs *regs) |
|---|
| 82 | 87 | { |
|---|
| 83 | 88 | return regs->uregs[0]; |
|---|
| 84 | 89 | } |
|---|
| .. | .. |
|---|
| 98 | 103 | * It's only valid to call this when @task is stopped for tracing on exit |
|---|
| 99 | 104 | * from a system call, due to %TIF_SYSCALL_TRACE or %TIF_SYSCALL_AUDIT. |
|---|
| 100 | 105 | */ |
|---|
| 101 | | -void syscall_set_return_value(struct task_struct *task, struct pt_regs *regs, |
|---|
| 102 | | - int error, long val) |
|---|
| 106 | +static inline void |
|---|
| 107 | +syscall_set_return_value(struct task_struct *task, struct pt_regs *regs, |
|---|
| 108 | + int error, long val) |
|---|
| 103 | 109 | { |
|---|
| 104 | 110 | regs->uregs[0] = (long)error ? error : val; |
|---|
| 105 | 111 | } |
|---|
| .. | .. |
|---|
| 108 | 114 | * syscall_get_arguments - extract system call parameter values |
|---|
| 109 | 115 | * @task: task of interest, must be blocked |
|---|
| 110 | 116 | * @regs: task_pt_regs() of @task |
|---|
| 111 | | - * @i: argument index [0,5] |
|---|
| 112 | | - * @n: number of arguments; n+i must be [1,6]. |
|---|
| 113 | 117 | * @args: array filled with argument values |
|---|
| 114 | 118 | * |
|---|
| 115 | | - * Fetches @n arguments to the system call starting with the @i'th argument |
|---|
| 116 | | - * (from 0 through 5). Argument @i is stored in @args[0], and so on. |
|---|
| 117 | | - * An arch inline version is probably optimal when @i and @n are constants. |
|---|
| 119 | + * Fetches 6 arguments to the system call (from 0 through 5). The first |
|---|
| 120 | + * argument is stored in @args[0], and so on. |
|---|
| 118 | 121 | * |
|---|
| 119 | 122 | * It's only valid to call this when @task is stopped for tracing on |
|---|
| 120 | 123 | * entry to a system call, due to %TIF_SYSCALL_TRACE or %TIF_SYSCALL_AUDIT. |
|---|
| 121 | | - * It's invalid to call this with @i + @n > 6; we only support system calls |
|---|
| 122 | | - * taking up to 6 arguments. |
|---|
| 123 | 124 | */ |
|---|
| 124 | 125 | #define SYSCALL_MAX_ARGS 6 |
|---|
| 125 | | -void syscall_get_arguments(struct task_struct *task, struct pt_regs *regs, |
|---|
| 126 | | - unsigned int i, unsigned int n, unsigned long *args) |
|---|
| 126 | +static inline void |
|---|
| 127 | +syscall_get_arguments(struct task_struct *task, struct pt_regs *regs, |
|---|
| 128 | + unsigned long *args) |
|---|
| 127 | 129 | { |
|---|
| 128 | | - if (n == 0) |
|---|
| 129 | | - return; |
|---|
| 130 | | - if (i + n > SYSCALL_MAX_ARGS) { |
|---|
| 131 | | - unsigned long *args_bad = args + SYSCALL_MAX_ARGS - i; |
|---|
| 132 | | - unsigned int n_bad = n + i - SYSCALL_MAX_ARGS; |
|---|
| 133 | | - pr_warning("%s called with max args %d, handling only %d\n", |
|---|
| 134 | | - __func__, i + n, SYSCALL_MAX_ARGS); |
|---|
| 135 | | - memset(args_bad, 0, n_bad * sizeof(args[0])); |
|---|
| 136 | | - memset(args_bad, 0, n_bad * sizeof(args[0])); |
|---|
| 137 | | - } |
|---|
| 138 | | - |
|---|
| 139 | | - if (i == 0) { |
|---|
| 140 | | - args[0] = regs->orig_r0; |
|---|
| 141 | | - args++; |
|---|
| 142 | | - i++; |
|---|
| 143 | | - n--; |
|---|
| 144 | | - } |
|---|
| 145 | | - |
|---|
| 146 | | - memcpy(args, ®s->uregs[0] + i, n * sizeof(args[0])); |
|---|
| 130 | + args[0] = regs->orig_r0; |
|---|
| 131 | + args++; |
|---|
| 132 | + memcpy(args, ®s->uregs[0] + 1, 5 * sizeof(args[0])); |
|---|
| 147 | 133 | } |
|---|
| 148 | 134 | |
|---|
| 149 | 135 | /** |
|---|
| 150 | 136 | * syscall_set_arguments - change system call parameter value |
|---|
| 151 | 137 | * @task: task of interest, must be in system call entry tracing |
|---|
| 152 | 138 | * @regs: task_pt_regs() of @task |
|---|
| 153 | | - * @i: argument index [0,5] |
|---|
| 154 | | - * @n: number of arguments; n+i must be [1,6]. |
|---|
| 155 | 139 | * @args: array of argument values to store |
|---|
| 156 | 140 | * |
|---|
| 157 | | - * Changes @n arguments to the system call starting with the @i'th argument. |
|---|
| 158 | | - * Argument @i gets value @args[0], and so on. |
|---|
| 159 | | - * An arch inline version is probably optimal when @i and @n are constants. |
|---|
| 141 | + * Changes 6 arguments to the system call. The first argument gets value |
|---|
| 142 | + * @args[0], and so on. |
|---|
| 160 | 143 | * |
|---|
| 161 | 144 | * It's only valid to call this when @task is stopped for tracing on |
|---|
| 162 | 145 | * entry to a system call, due to %TIF_SYSCALL_TRACE or %TIF_SYSCALL_AUDIT. |
|---|
| 163 | | - * It's invalid to call this with @i + @n > 6; we only support system calls |
|---|
| 164 | | - * taking up to 6 arguments. |
|---|
| 165 | 146 | */ |
|---|
| 166 | | -void syscall_set_arguments(struct task_struct *task, struct pt_regs *regs, |
|---|
| 167 | | - unsigned int i, unsigned int n, |
|---|
| 168 | | - const unsigned long *args) |
|---|
| 147 | +static inline void |
|---|
| 148 | +syscall_set_arguments(struct task_struct *task, struct pt_regs *regs, |
|---|
| 149 | + const unsigned long *args) |
|---|
| 169 | 150 | { |
|---|
| 170 | | - if (n == 0) |
|---|
| 171 | | - return; |
|---|
| 151 | + regs->orig_r0 = args[0]; |
|---|
| 152 | + args++; |
|---|
| 172 | 153 | |
|---|
| 173 | | - if (i + n > SYSCALL_MAX_ARGS) { |
|---|
| 174 | | - pr_warn("%s called with max args %d, handling only %d\n", |
|---|
| 175 | | - __func__, i + n, SYSCALL_MAX_ARGS); |
|---|
| 176 | | - n = SYSCALL_MAX_ARGS - i; |
|---|
| 177 | | - } |
|---|
| 178 | | - |
|---|
| 179 | | - if (i == 0) { |
|---|
| 180 | | - regs->orig_r0 = args[0]; |
|---|
| 181 | | - args++; |
|---|
| 182 | | - i++; |
|---|
| 183 | | - n--; |
|---|
| 184 | | - } |
|---|
| 185 | | - |
|---|
| 186 | | - memcpy(®s->uregs[0] + i, args, n * sizeof(args[0])); |
|---|
| 154 | + memcpy(®s->uregs[0] + 1, args, 5 * sizeof(args[0])); |
|---|
| 187 | 155 | } |
|---|
| 156 | + |
|---|
| 157 | +static inline int |
|---|
| 158 | +syscall_get_arch(struct task_struct *task) |
|---|
| 159 | +{ |
|---|
| 160 | + return IS_ENABLED(CONFIG_CPU_BIG_ENDIAN) |
|---|
| 161 | + ? AUDIT_ARCH_NDS32BE : AUDIT_ARCH_NDS32; |
|---|
| 162 | +} |
|---|
| 163 | + |
|---|
| 188 | 164 | #endif /* _ASM_NDS32_SYSCALL_H */ |
|---|