blob: 2429b87eb28d92c6fc6adf5a5887f2b29e062d70 [file] [log] [blame]
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +02001/*
2 * Access to user system call parameters and results
3 *
4 * Copyright IBM Corp. 2008
5 * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com)
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License (version 2 only)
9 * as published by the Free Software Foundation.
10 */
11
12#ifndef _ASM_SYSCALL_H
13#define _ASM_SYSCALL_H 1
14
15#include <asm/ptrace.h>
16
17static inline long syscall_get_nr(struct task_struct *task,
18 struct pt_regs *regs)
19{
Martin Schwidefsky59da2132008-11-27 11:05:55 +010020 return regs->svcnr ? regs->svcnr : -1;
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +020021}
22
23static inline void syscall_rollback(struct task_struct *task,
24 struct pt_regs *regs)
25{
26 regs->gprs[2] = regs->orig_gpr2;
27}
28
29static inline long syscall_get_error(struct task_struct *task,
30 struct pt_regs *regs)
31{
32 return (regs->gprs[2] >= -4096UL) ? -regs->gprs[2] : 0;
33}
34
35static inline long syscall_get_return_value(struct task_struct *task,
36 struct pt_regs *regs)
37{
38 return regs->gprs[2];
39}
40
41static inline void syscall_set_return_value(struct task_struct *task,
42 struct pt_regs *regs,
43 int error, long val)
44{
45 regs->gprs[2] = error ? -error : val;
46}
47
48static inline void syscall_get_arguments(struct task_struct *task,
49 struct pt_regs *regs,
50 unsigned int i, unsigned int n,
51 unsigned long *args)
52{
Martin Schwidefsky59da2132008-11-27 11:05:55 +010053 unsigned long mask = -1UL;
54
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +020055 BUG_ON(i + n > 6);
56#ifdef CONFIG_COMPAT
Martin Schwidefsky59da2132008-11-27 11:05:55 +010057 if (test_tsk_thread_flag(task, TIF_31BIT))
58 mask = 0xffffffff;
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +020059#endif
60 if (i + n == 6)
Martin Schwidefsky59da2132008-11-27 11:05:55 +010061 args[--n] = regs->args[0] & mask;
62 while (n-- > 0)
63 if (i + n > 0)
64 args[n] = regs->gprs[2 + i + n] & mask;
65 if (i == 0)
66 args[0] = regs->orig_gpr2 & mask;
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +020067}
68
69static inline void syscall_set_arguments(struct task_struct *task,
70 struct pt_regs *regs,
71 unsigned int i, unsigned int n,
72 const unsigned long *args)
73{
74 BUG_ON(i + n > 6);
75 if (i + n == 6)
76 regs->args[0] = args[--n];
Martin Schwidefsky59da2132008-11-27 11:05:55 +010077 while (n-- > 0)
78 if (i + n > 0)
79 regs->gprs[2 + i + n] = args[n];
80 if (i == 0)
81 regs->orig_gpr2 = args[0];
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +020082}
83
84#endif /* _ASM_SYSCALL_H */