blob: e0a73d3eb8371be3bb599413aa09cd65a7f7da56 [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
Heiko Carstens9bf12262009-06-12 10:26:47 +020015#include <linux/sched.h>
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +020016#include <asm/ptrace.h>
17
18static inline long syscall_get_nr(struct task_struct *task,
19 struct pt_regs *regs)
20{
Martin Schwidefsky59da2132008-11-27 11:05:55 +010021 return regs->svcnr ? regs->svcnr : -1;
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +020022}
23
24static inline void syscall_rollback(struct task_struct *task,
25 struct pt_regs *regs)
26{
27 regs->gprs[2] = regs->orig_gpr2;
28}
29
30static inline long syscall_get_error(struct task_struct *task,
31 struct pt_regs *regs)
32{
33 return (regs->gprs[2] >= -4096UL) ? -regs->gprs[2] : 0;
34}
35
36static inline long syscall_get_return_value(struct task_struct *task,
37 struct pt_regs *regs)
38{
39 return regs->gprs[2];
40}
41
42static inline void syscall_set_return_value(struct task_struct *task,
43 struct pt_regs *regs,
44 int error, long val)
45{
46 regs->gprs[2] = error ? -error : val;
47}
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{
Martin Schwidefsky59da2132008-11-27 11:05:55 +010054 unsigned long mask = -1UL;
55
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +020056 BUG_ON(i + n > 6);
57#ifdef CONFIG_COMPAT
Martin Schwidefsky59da2132008-11-27 11:05:55 +010058 if (test_tsk_thread_flag(task, TIF_31BIT))
59 mask = 0xffffffff;
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +020060#endif
61 if (i + n == 6)
Martin Schwidefsky59da2132008-11-27 11:05:55 +010062 args[--n] = regs->args[0] & mask;
63 while (n-- > 0)
64 if (i + n > 0)
65 args[n] = regs->gprs[2 + i + n] & mask;
66 if (i == 0)
67 args[0] = regs->orig_gpr2 & mask;
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +020068}
69
70static inline void syscall_set_arguments(struct task_struct *task,
71 struct pt_regs *regs,
72 unsigned int i, unsigned int n,
73 const unsigned long *args)
74{
75 BUG_ON(i + n > 6);
76 if (i + n == 6)
77 regs->args[0] = args[--n];
Martin Schwidefsky59da2132008-11-27 11:05:55 +010078 while (n-- > 0)
79 if (i + n > 0)
80 regs->gprs[2 + i + n] = args[n];
81 if (i == 0)
82 regs->orig_gpr2 = args[0];
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +020083}
84
85#endif /* _ASM_SYSCALL_H */