blob: fce38a684e4493607cd0ad3c99381c56b22b7e33 [file] [log] [blame]
Wade Farnsworthbf2c9f92012-04-04 16:19:02 +01001/*
2 * Access to user system call parameters and results
3 *
4 * See asm-generic/syscall.h for descriptions of what we must do here.
5 */
6
7#ifndef _ASM_ARM_SYSCALL_H
8#define _ASM_ARM_SYSCALL_H
9
10#include <linux/err.h>
Wade Farnsworth8ef102c6b2012-10-02 17:08:30 +010011#include <linux/sched.h>
Wade Farnsworthbf2c9f92012-04-04 16:19:02 +010012
13extern const unsigned long sys_call_table[];
14
15static inline int syscall_get_nr(struct task_struct *task,
16 struct pt_regs *regs)
17{
18 return task_thread_info(task)->syscall;
19}
20
21static inline void syscall_rollback(struct task_struct *task,
22 struct pt_regs *regs)
23{
24 regs->ARM_r0 = regs->ARM_ORIG_r0;
25}
26
27static inline long syscall_get_error(struct task_struct *task,
28 struct pt_regs *regs)
29{
30 unsigned long error = regs->ARM_r0;
31 return IS_ERR_VALUE(error) ? error : 0;
32}
33
34static inline long syscall_get_return_value(struct task_struct *task,
35 struct pt_regs *regs)
36{
37 return regs->ARM_r0;
38}
39
40static inline void syscall_set_return_value(struct task_struct *task,
41 struct pt_regs *regs,
42 int error, long val)
43{
44 regs->ARM_r0 = (long) error ? error : val;
45}
46
47#define SYSCALL_MAX_ARGS 7
48
49static inline void syscall_get_arguments(struct task_struct *task,
50 struct pt_regs *regs,
51 unsigned int i, unsigned int n,
52 unsigned long *args)
53{
54 if (i + n > SYSCALL_MAX_ARGS) {
55 unsigned long *args_bad = args + SYSCALL_MAX_ARGS - i;
56 unsigned int n_bad = n + i - SYSCALL_MAX_ARGS;
57 pr_warning("%s called with max args %d, handling only %d\n",
58 __func__, i + n, SYSCALL_MAX_ARGS);
59 memset(args_bad, 0, n_bad * sizeof(args[0]));
60 n = SYSCALL_MAX_ARGS - i;
61 }
62
63 if (i == 0) {
64 args[0] = regs->ARM_ORIG_r0;
65 args++;
66 i++;
67 n--;
68 }
69
70 memcpy(args, &regs->ARM_r0 + i, n * sizeof(args[0]));
71}
72
73static inline void syscall_set_arguments(struct task_struct *task,
74 struct pt_regs *regs,
75 unsigned int i, unsigned int n,
76 const unsigned long *args)
77{
78 if (i + n > SYSCALL_MAX_ARGS) {
79 pr_warning("%s called with max args %d, handling only %d\n",
80 __func__, i + n, SYSCALL_MAX_ARGS);
81 n = SYSCALL_MAX_ARGS - i;
82 }
83
84 if (i == 0) {
85 regs->ARM_ORIG_r0 = args[0];
86 args++;
87 i++;
88 n--;
89 }
90
91 memcpy(&regs->ARM_r0 + i, args, n * sizeof(args[0]));
92}
93
94#endif /* _ASM_ARM_SYSCALL_H */