blob: fe7b99759e12ffcdf5f2df9880f86f91df3c9800 [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 Carstensc63cb462012-07-31 15:37:13 +020015#include <linux/audit.h>
Heiko Carstens9bf12262009-06-12 10:26:47 +020016#include <linux/sched.h>
Martin Schwidefsky20b40a72011-10-30 15:16:47 +010017#include <linux/err.h>
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +020018#include <asm/ptrace.h>
19
Mike Frysingere7b8e672010-01-26 04:40:03 -050020/*
21 * The syscall table always contains 32 bit pointers since we know that the
22 * address of the function to be called is (way) below 4GB. So the "int"
23 * type here is what we want [need] for both 32 bit and 64 bit systems.
24 */
25extern const unsigned int sys_call_table[];
26
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +020027static inline long syscall_get_nr(struct task_struct *task,
28 struct pt_regs *regs)
29{
Martin Schwidefskyb6ef5bb2011-10-30 15:16:49 +010030 return test_tsk_thread_flag(task, TIF_SYSCALL) ?
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +010031 (regs->int_code & 0xffff) : -1;
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +020032}
33
34static inline void syscall_rollback(struct task_struct *task,
35 struct pt_regs *regs)
36{
37 regs->gprs[2] = regs->orig_gpr2;
38}
39
40static inline long syscall_get_error(struct task_struct *task,
41 struct pt_regs *regs)
42{
Martin Schwidefsky20b40a72011-10-30 15:16:47 +010043 return IS_ERR_VALUE(regs->gprs[2]) ? regs->gprs[2] : 0;
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +020044}
45
46static inline long syscall_get_return_value(struct task_struct *task,
47 struct pt_regs *regs)
48{
49 return regs->gprs[2];
50}
51
52static inline void syscall_set_return_value(struct task_struct *task,
53 struct pt_regs *regs,
54 int error, long val)
55{
56 regs->gprs[2] = error ? -error : val;
57}
58
59static inline void syscall_get_arguments(struct task_struct *task,
60 struct pt_regs *regs,
61 unsigned int i, unsigned int n,
62 unsigned long *args)
63{
Martin Schwidefsky59da2132008-11-27 11:05:55 +010064 unsigned long mask = -1UL;
65
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +020066 BUG_ON(i + n > 6);
67#ifdef CONFIG_COMPAT
Martin Schwidefsky59da2132008-11-27 11:05:55 +010068 if (test_tsk_thread_flag(task, TIF_31BIT))
69 mask = 0xffffffff;
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +020070#endif
Martin Schwidefsky59da2132008-11-27 11:05:55 +010071 while (n-- > 0)
72 if (i + n > 0)
73 args[n] = regs->gprs[2 + i + n] & mask;
74 if (i == 0)
75 args[0] = regs->orig_gpr2 & mask;
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +020076}
77
78static inline void syscall_set_arguments(struct task_struct *task,
79 struct pt_regs *regs,
80 unsigned int i, unsigned int n,
81 const unsigned long *args)
82{
83 BUG_ON(i + n > 6);
Martin Schwidefsky59da2132008-11-27 11:05:55 +010084 while (n-- > 0)
85 if (i + n > 0)
86 regs->gprs[2 + i + n] = args[n];
87 if (i == 0)
88 regs->orig_gpr2 = args[0];
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +020089}
90
Heiko Carstensc63cb462012-07-31 15:37:13 +020091static inline int syscall_get_arch(struct task_struct *task,
92 struct pt_regs *regs)
93{
94#ifdef CONFIG_COMPAT
95 if (test_tsk_thread_flag(task, TIF_31BIT))
96 return AUDIT_ARCH_S390;
97#endif
98 return sizeof(long) == 8 ? AUDIT_ARCH_S390X : AUDIT_ARCH_S390;
99}
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +0200100#endif /* _ASM_SYSCALL_H */