Martin Schwidefsky | 753c4dd | 2008-10-10 21:33:20 +0200 | [diff] [blame] | 1 | /* |
| 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 Paris | 579ec9e | 2014-03-11 12:55:42 -0400 | [diff] [blame] | 15 | #include <uapi/linux/audit.h> |
Heiko Carstens | 9bf1226 | 2009-06-12 10:26:47 +0200 | [diff] [blame] | 16 | #include <linux/sched.h> |
Martin Schwidefsky | 20b40a7 | 2011-10-30 15:16:47 +0100 | [diff] [blame] | 17 | #include <linux/err.h> |
Martin Schwidefsky | 753c4dd | 2008-10-10 21:33:20 +0200 | [diff] [blame] | 18 | #include <asm/ptrace.h> |
| 19 | |
Mike Frysinger | e7b8e67 | 2010-01-26 04:40:03 -0500 | [diff] [blame] | 20 | /* |
| 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 | */ |
| 25 | extern const unsigned int sys_call_table[]; |
Martin Schwidefsky | 6164988 | 2013-04-24 12:58:39 +0200 | [diff] [blame] | 26 | extern const unsigned int sys_call_table_emu[]; |
Mike Frysinger | e7b8e67 | 2010-01-26 04:40:03 -0500 | [diff] [blame] | 27 | |
Martin Schwidefsky | 753c4dd | 2008-10-10 21:33:20 +0200 | [diff] [blame] | 28 | static inline long syscall_get_nr(struct task_struct *task, |
| 29 | struct pt_regs *regs) |
| 30 | { |
Martin Schwidefsky | d3a73ac | 2014-04-15 12:55:07 +0200 | [diff] [blame] | 31 | return test_pt_regs_flag(regs, PIF_SYSCALL) ? |
Martin Schwidefsky | aa33c8c | 2011-12-27 11:27:18 +0100 | [diff] [blame] | 32 | (regs->int_code & 0xffff) : -1; |
Martin Schwidefsky | 753c4dd | 2008-10-10 21:33:20 +0200 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | static inline void syscall_rollback(struct task_struct *task, |
| 36 | struct pt_regs *regs) |
| 37 | { |
| 38 | regs->gprs[2] = regs->orig_gpr2; |
| 39 | } |
| 40 | |
| 41 | static inline long syscall_get_error(struct task_struct *task, |
| 42 | struct pt_regs *regs) |
| 43 | { |
Martin Schwidefsky | 20b40a7 | 2011-10-30 15:16:47 +0100 | [diff] [blame] | 44 | return IS_ERR_VALUE(regs->gprs[2]) ? regs->gprs[2] : 0; |
Martin Schwidefsky | 753c4dd | 2008-10-10 21:33:20 +0200 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | static inline long syscall_get_return_value(struct task_struct *task, |
| 48 | struct pt_regs *regs) |
| 49 | { |
| 50 | return regs->gprs[2]; |
| 51 | } |
| 52 | |
| 53 | static inline void syscall_set_return_value(struct task_struct *task, |
| 54 | struct pt_regs *regs, |
| 55 | int error, long val) |
| 56 | { |
Jan Willeke | dc29588 | 2014-07-22 16:50:57 +0200 | [diff] [blame] | 57 | regs->gprs[2] = error ? error : val; |
Martin Schwidefsky | 753c4dd | 2008-10-10 21:33:20 +0200 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | static 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 Schwidefsky | 59da213 | 2008-11-27 11:05:55 +0100 | [diff] [blame] | 65 | unsigned long mask = -1UL; |
| 66 | |
Martin Schwidefsky | 753c4dd | 2008-10-10 21:33:20 +0200 | [diff] [blame] | 67 | BUG_ON(i + n > 6); |
| 68 | #ifdef CONFIG_COMPAT |
Martin Schwidefsky | 59da213 | 2008-11-27 11:05:55 +0100 | [diff] [blame] | 69 | if (test_tsk_thread_flag(task, TIF_31BIT)) |
| 70 | mask = 0xffffffff; |
Martin Schwidefsky | 753c4dd | 2008-10-10 21:33:20 +0200 | [diff] [blame] | 71 | #endif |
Martin Schwidefsky | 59da213 | 2008-11-27 11:05:55 +0100 | [diff] [blame] | 72 | while (n-- > 0) |
| 73 | if (i + n > 0) |
| 74 | args[n] = regs->gprs[2 + i + n] & mask; |
| 75 | if (i == 0) |
| 76 | args[0] = regs->orig_gpr2 & mask; |
Martin Schwidefsky | 753c4dd | 2008-10-10 21:33:20 +0200 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | static inline void syscall_set_arguments(struct task_struct *task, |
| 80 | struct pt_regs *regs, |
| 81 | unsigned int i, unsigned int n, |
| 82 | const unsigned long *args) |
| 83 | { |
| 84 | BUG_ON(i + n > 6); |
Martin Schwidefsky | 59da213 | 2008-11-27 11:05:55 +0100 | [diff] [blame] | 85 | while (n-- > 0) |
| 86 | if (i + n > 0) |
| 87 | regs->gprs[2 + i + n] = args[n]; |
| 88 | if (i == 0) |
| 89 | regs->orig_gpr2 = args[0]; |
Martin Schwidefsky | 753c4dd | 2008-10-10 21:33:20 +0200 | [diff] [blame] | 90 | } |
| 91 | |
Eric Paris | 5e937a9 | 2014-03-11 12:48:43 -0400 | [diff] [blame] | 92 | static inline int syscall_get_arch(void) |
Heiko Carstens | c63cb46 | 2012-07-31 15:37:13 +0200 | [diff] [blame] | 93 | { |
| 94 | #ifdef CONFIG_COMPAT |
Eric Paris | 5e937a9 | 2014-03-11 12:48:43 -0400 | [diff] [blame] | 95 | if (test_tsk_thread_flag(current, TIF_31BIT)) |
Heiko Carstens | c63cb46 | 2012-07-31 15:37:13 +0200 | [diff] [blame] | 96 | return AUDIT_ARCH_S390; |
| 97 | #endif |
Heiko Carstens | 1a327ff | 2015-03-30 11:11:49 +0200 | [diff] [blame] | 98 | return AUDIT_ARCH_S390X; |
Heiko Carstens | c63cb46 | 2012-07-31 15:37:13 +0200 | [diff] [blame] | 99 | } |
Martin Schwidefsky | 753c4dd | 2008-10-10 21:33:20 +0200 | [diff] [blame] | 100 | #endif /* _ASM_SYSCALL_H */ |