• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Access to user system call parameters and results
3  *
4  * Copyright (C) 2012 The Chromium OS Authors <chromium-os-dev@chromium.org>
5  *
6  * This copyrighted material is made available to anyone wishing to use,
7  * modify, copy, or redistribute it subject to the terms and conditions
8  * of the GNU General Public License v.2.
9  *
10  * See asm-generic/syscall.h for descriptions of what we must do here.
11  */
12 #ifndef _ASM_ARM_SYSCALL_H
13 #define _ASM_ARM_SYSCALL_H
14 
15 #include <linux/audit.h> /* for AUDIT_ARCH_* */
16 #include <linux/elf.h> /* for ELF_EM */
17 #include <linux/sched.h>
18 #include <linux/thread_info.h> /* for task_thread_info */
19 #include <linux/err.h>
20 
syscall_get_nr(struct task_struct * task,struct pt_regs * regs)21 static inline int syscall_get_nr(struct task_struct *task, struct pt_regs *regs)
22 {
23 	return task_thread_info(task)->syscall;
24 }
25 
syscall_rollback(struct task_struct * task,struct pt_regs * regs)26 static inline void syscall_rollback(struct task_struct *task,
27 				    struct pt_regs *regs)
28 {
29 	regs->ARM_r0 = regs->ARM_ORIG_r0;
30 }
31 
syscall_get_error(struct task_struct * task,struct pt_regs * regs)32 static inline long syscall_get_error(struct task_struct *task,
33 				     struct pt_regs *regs)
34 {
35 	unsigned long error = regs->ARM_r0;
36 	return IS_ERR_VALUE(error) ? error : 0;
37 }
38 
syscall_get_return_value(struct task_struct * task,struct pt_regs * regs)39 static inline long syscall_get_return_value(struct task_struct *task,
40 					    struct pt_regs *regs)
41 {
42 	return regs->ARM_r0;
43 }
44 
syscall_set_return_value(struct task_struct * task,struct pt_regs * regs,int error,long val)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->ARM_r0 = (long) error ?: val;
50 }
51 
syscall_get_arguments(struct task_struct * task,struct pt_regs * regs,unsigned int i,unsigned int n,unsigned long * args)52 static inline void syscall_get_arguments(struct task_struct *task,
53 					 struct pt_regs *regs,
54 					 unsigned int i, unsigned int n,
55 					 unsigned long *args)
56 {
57 	BUG_ON(i + n > 6);
58 	memcpy(args, &regs->ARM_r0 + i, n * sizeof(args[0]));
59 }
60 
syscall_set_arguments(struct task_struct * task,struct pt_regs * regs,unsigned int i,unsigned int n,const unsigned long * args)61 static inline void syscall_set_arguments(struct task_struct *task,
62 					 struct pt_regs *regs,
63 					 unsigned int i, unsigned int n,
64 					 const unsigned long *args)
65 {
66 	BUG_ON(i + n > 6);
67 	memcpy(&regs->ARM_r0 + i, args, n * sizeof(args[0]));
68 }
69 
syscall_get_arch(struct task_struct * task,struct pt_regs * regs)70 static inline int syscall_get_arch(struct task_struct *task,
71 				    struct pt_regs *regs)
72 {
73 	/* ARM tasks don't change audit architectures on the fly. */
74 #ifdef __ARMEB__
75 	return AUDIT_ARCH_ARMEB;
76 #else
77 	return AUDIT_ARCH_ARM;
78 #endif
79 }
80 #endif	/* _ASM_ARM_SYSCALL_H */
81