blob: 5c0246b955d80e411250623c400c3387f23568b7 [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
Mike Frysingere7b8e672010-01-26 04:40:03 -050018/*
19 * The syscall table always contains 32 bit pointers since we know that the
20 * address of the function to be called is (way) below 4GB. So the "int"
21 * type here is what we want [need] for both 32 bit and 64 bit systems.
22 */
23extern const unsigned int sys_call_table[];
24
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +020025static inline long syscall_get_nr(struct task_struct *task,
26 struct pt_regs *regs)
27{
Martin Schwidefsky59da2132008-11-27 11:05:55 +010028 return regs->svcnr ? regs->svcnr : -1;
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +020029}
30
31static inline void syscall_rollback(struct task_struct *task,
32 struct pt_regs *regs)
33{
34 regs->gprs[2] = regs->orig_gpr2;
35}
36
37static inline long syscall_get_error(struct task_struct *task,
38 struct pt_regs *regs)
39{
40 return (regs->gprs[2] >= -4096UL) ? -regs->gprs[2] : 0;
41}
42
43static inline long syscall_get_return_value(struct task_struct *task,
44 struct pt_regs *regs)
45{
46 return regs->gprs[2];
47}
48
49static inline void syscall_set_return_value(struct task_struct *task,
50 struct pt_regs *regs,
51 int error, long val)
52{
53 regs->gprs[2] = error ? -error : val;
54}
55
56static inline void syscall_get_arguments(struct task_struct *task,
57 struct pt_regs *regs,
58 unsigned int i, unsigned int n,
59 unsigned long *args)
60{
Martin Schwidefsky59da2132008-11-27 11:05:55 +010061 unsigned long mask = -1UL;
62
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +020063 BUG_ON(i + n > 6);
64#ifdef CONFIG_COMPAT
Martin Schwidefsky59da2132008-11-27 11:05:55 +010065 if (test_tsk_thread_flag(task, TIF_31BIT))
66 mask = 0xffffffff;
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +020067#endif
Martin Schwidefsky59da2132008-11-27 11:05:55 +010068 while (n-- > 0)
69 if (i + n > 0)
70 args[n] = regs->gprs[2 + i + n] & mask;
71 if (i == 0)
72 args[0] = regs->orig_gpr2 & mask;
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +020073}
74
75static inline void syscall_set_arguments(struct task_struct *task,
76 struct pt_regs *regs,
77 unsigned int i, unsigned int n,
78 const unsigned long *args)
79{
80 BUG_ON(i + n > 6);
Martin Schwidefsky59da2132008-11-27 11:05:55 +010081 while (n-- > 0)
82 if (i + n > 0)
83 regs->gprs[2 + i + n] = args[n];
84 if (i == 0)
85 regs->orig_gpr2 = args[0];
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +020086}
87
88#endif /* _ASM_SYSCALL_H */