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 | |
Heiko Carstens | 9bf1226 | 2009-06-12 10:26:47 +0200 | [diff] [blame^] | 15 | #include <linux/sched.h> |
Martin Schwidefsky | 753c4dd | 2008-10-10 21:33:20 +0200 | [diff] [blame] | 16 | #include <asm/ptrace.h> |
| 17 | |
| 18 | static inline long syscall_get_nr(struct task_struct *task, |
| 19 | struct pt_regs *regs) |
| 20 | { |
Martin Schwidefsky | 59da213 | 2008-11-27 11:05:55 +0100 | [diff] [blame] | 21 | return regs->svcnr ? regs->svcnr : -1; |
Martin Schwidefsky | 753c4dd | 2008-10-10 21:33:20 +0200 | [diff] [blame] | 22 | } |
| 23 | |
| 24 | static inline void syscall_rollback(struct task_struct *task, |
| 25 | struct pt_regs *regs) |
| 26 | { |
| 27 | regs->gprs[2] = regs->orig_gpr2; |
| 28 | } |
| 29 | |
| 30 | static 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 | |
| 36 | static inline long syscall_get_return_value(struct task_struct *task, |
| 37 | struct pt_regs *regs) |
| 38 | { |
| 39 | return regs->gprs[2]; |
| 40 | } |
| 41 | |
| 42 | static 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 | |
| 49 | static 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 Schwidefsky | 59da213 | 2008-11-27 11:05:55 +0100 | [diff] [blame] | 54 | unsigned long mask = -1UL; |
| 55 | |
Martin Schwidefsky | 753c4dd | 2008-10-10 21:33:20 +0200 | [diff] [blame] | 56 | BUG_ON(i + n > 6); |
| 57 | #ifdef CONFIG_COMPAT |
Martin Schwidefsky | 59da213 | 2008-11-27 11:05:55 +0100 | [diff] [blame] | 58 | if (test_tsk_thread_flag(task, TIF_31BIT)) |
| 59 | mask = 0xffffffff; |
Martin Schwidefsky | 753c4dd | 2008-10-10 21:33:20 +0200 | [diff] [blame] | 60 | #endif |
| 61 | if (i + n == 6) |
Martin Schwidefsky | 59da213 | 2008-11-27 11:05:55 +0100 | [diff] [blame] | 62 | 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 Schwidefsky | 753c4dd | 2008-10-10 21:33:20 +0200 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | static 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 Schwidefsky | 59da213 | 2008-11-27 11:05:55 +0100 | [diff] [blame] | 78 | 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 Schwidefsky | 753c4dd | 2008-10-10 21:33:20 +0200 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | #endif /* _ASM_SYSCALL_H */ |