blob: 6bc941be6921773f566efd701a213ef44793a793 [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
Eric Paris579ec9e2014-03-11 12:55:42 -040015#include <uapi/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[];
Martin Schwidefsky61649882013-04-24 12:58:39 +020026extern const unsigned int sys_call_table_emu[];
Mike Frysingere7b8e672010-01-26 04:40:03 -050027
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +020028static inline long syscall_get_nr(struct task_struct *task,
29 struct pt_regs *regs)
30{
Martin Schwidefskyd3a73ac2014-04-15 12:55:07 +020031 return test_pt_regs_flag(regs, PIF_SYSCALL) ?
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +010032 (regs->int_code & 0xffff) : -1;
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +020033}
34
35static inline void syscall_rollback(struct task_struct *task,
36 struct pt_regs *regs)
37{
38 regs->gprs[2] = regs->orig_gpr2;
39}
40
41static inline long syscall_get_error(struct task_struct *task,
42 struct pt_regs *regs)
43{
Martin Schwidefsky20b40a72011-10-30 15:16:47 +010044 return IS_ERR_VALUE(regs->gprs[2]) ? regs->gprs[2] : 0;
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +020045}
46
47static inline long syscall_get_return_value(struct task_struct *task,
48 struct pt_regs *regs)
49{
50 return regs->gprs[2];
51}
52
53static inline void syscall_set_return_value(struct task_struct *task,
54 struct pt_regs *regs,
55 int error, long val)
56{
Jan Willekedc295882014-07-22 16:50:57 +020057 regs->gprs[2] = error ? error : val;
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +020058}
59
60static inline void syscall_get_arguments(struct task_struct *task,
61 struct pt_regs *regs,
62 unsigned int i, unsigned int n,
63 unsigned long *args)
64{
Martin Schwidefsky59da2132008-11-27 11:05:55 +010065 unsigned long mask = -1UL;
66
Jiri Olsac46fc042017-06-29 11:38:11 +020067 /*
68 * No arguments for this syscall, there's nothing to do.
69 */
70 if (!n)
71 return;
72
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +020073 BUG_ON(i + n > 6);
74#ifdef CONFIG_COMPAT
Martin Schwidefsky59da2132008-11-27 11:05:55 +010075 if (test_tsk_thread_flag(task, TIF_31BIT))
76 mask = 0xffffffff;
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +020077#endif
Martin Schwidefsky59da2132008-11-27 11:05:55 +010078 while (n-- > 0)
79 if (i + n > 0)
80 args[n] = regs->gprs[2 + i + n] & mask;
81 if (i == 0)
82 args[0] = regs->orig_gpr2 & mask;
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +020083}
84
85static inline void syscall_set_arguments(struct task_struct *task,
86 struct pt_regs *regs,
87 unsigned int i, unsigned int n,
88 const unsigned long *args)
89{
90 BUG_ON(i + n > 6);
Martin Schwidefsky59da2132008-11-27 11:05:55 +010091 while (n-- > 0)
92 if (i + n > 0)
93 regs->gprs[2 + i + n] = args[n];
94 if (i == 0)
95 regs->orig_gpr2 = args[0];
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +020096}
97
Eric Paris5e937a92014-03-11 12:48:43 -040098static inline int syscall_get_arch(void)
Heiko Carstensc63cb462012-07-31 15:37:13 +020099{
100#ifdef CONFIG_COMPAT
Eric Paris5e937a92014-03-11 12:48:43 -0400101 if (test_tsk_thread_flag(current, TIF_31BIT))
Heiko Carstensc63cb462012-07-31 15:37:13 +0200102 return AUDIT_ARCH_S390;
103#endif
Heiko Carstens1a327ff2015-03-30 11:11:49 +0200104 return AUDIT_ARCH_S390X;
Heiko Carstensc63cb462012-07-31 15:37:13 +0200105}
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +0200106#endif /* _ASM_SYSCALL_H */