blob: d962e5652a7352498bd9654315f7819fb7d9d86b [file] [log] [blame]
Roland McGrath68bd0f42008-04-18 17:08:44 -07001/*
2 * Access to user system call parameters and results
3 *
Roland McGrath18c1e2c2009-09-22 19:57:51 -07004 * Copyright (C) 2008-2009 Red Hat, Inc. All rights reserved.
Roland McGrath68bd0f42008-04-18 17:08:44 -07005 *
6 * This copyrighted material is made available to anyone wishing to use,
7 * modify, copy, or redistribute it subject to the terms and conditions
8 * of the GNU General Public License v.2.
9 *
10 * See asm-generic/syscall.h for descriptions of what we must do here.
11 */
12
H. Peter Anvin5e1b0072008-10-23 00:20:33 -070013#ifndef _ASM_X86_SYSCALL_H
14#define _ASM_X86_SYSCALL_H
Roland McGrath68bd0f42008-04-18 17:08:44 -070015
16#include <linux/sched.h>
Petr Tesarik4ab4ba32008-09-03 13:31:42 +020017#include <linux/err.h>
H. Peter Anvin72142fd2012-01-07 14:10:18 -080018#include <asm/asm-offsets.h> /* For NR_syscalls */
Roland McGrath68bd0f42008-04-18 17:08:44 -070019
Mike Frysingere7b8e672010-01-26 04:40:03 -050020extern const unsigned long sys_call_table[];
21
Roland McGrath18c1e2c2009-09-22 19:57:51 -070022/*
23 * Only the low 32 bits of orig_ax are meaningful, so we return int.
24 * This importantly ignores the high bits on 64-bit, so comparisons
25 * sign-extend the low 32 bits.
26 */
27static inline int syscall_get_nr(struct task_struct *task, struct pt_regs *regs)
Roland McGrath68bd0f42008-04-18 17:08:44 -070028{
Roland McGrath68bd0f42008-04-18 17:08:44 -070029 return regs->orig_ax;
30}
31
32static inline void syscall_rollback(struct task_struct *task,
33 struct pt_regs *regs)
34{
35 regs->ax = regs->orig_ax;
36}
37
38static inline long syscall_get_error(struct task_struct *task,
39 struct pt_regs *regs)
40{
41 unsigned long error = regs->ax;
42#ifdef CONFIG_IA32_EMULATION
43 /*
44 * TS_COMPAT is set for 32-bit syscall entries and then
45 * remains set until we return to user mode.
46 */
47 if (task_thread_info(task)->status & TS_COMPAT)
48 /*
49 * Sign-extend the value so (int)-EFOO becomes (long)-EFOO
50 * and will match correctly in comparisons.
51 */
52 error = (long) (int) error;
53#endif
Petr Tesarik4ab4ba32008-09-03 13:31:42 +020054 return IS_ERR_VALUE(error) ? error : 0;
Roland McGrath68bd0f42008-04-18 17:08:44 -070055}
56
57static inline long syscall_get_return_value(struct task_struct *task,
58 struct pt_regs *regs)
59{
60 return regs->ax;
61}
62
63static inline void syscall_set_return_value(struct task_struct *task,
64 struct pt_regs *regs,
65 int error, long val)
66{
67 regs->ax = (long) error ?: val;
68}
69
70#ifdef CONFIG_X86_32
71
72static inline void syscall_get_arguments(struct task_struct *task,
73 struct pt_regs *regs,
74 unsigned int i, unsigned int n,
75 unsigned long *args)
76{
77 BUG_ON(i + n > 6);
78 memcpy(args, &regs->bx + i, n * sizeof(args[0]));
79}
80
81static inline void syscall_set_arguments(struct task_struct *task,
82 struct pt_regs *regs,
83 unsigned int i, unsigned int n,
84 const unsigned long *args)
85{
86 BUG_ON(i + n > 6);
87 memcpy(&regs->bx + i, args, n * sizeof(args[0]));
88}
89
90#else /* CONFIG_X86_64 */
91
92static inline void syscall_get_arguments(struct task_struct *task,
93 struct pt_regs *regs,
94 unsigned int i, unsigned int n,
95 unsigned long *args)
96{
97# ifdef CONFIG_IA32_EMULATION
98 if (task_thread_info(task)->status & TS_COMPAT)
Linus Torvaldsc3c98972008-10-23 12:38:39 -070099 switch (i) {
100 case 0:
Roland McGrath68bd0f42008-04-18 17:08:44 -0700101 if (!n--) break;
102 *args++ = regs->bx;
Linus Torvaldsc3c98972008-10-23 12:38:39 -0700103 case 1:
104 if (!n--) break;
105 *args++ = regs->cx;
106 case 2:
107 if (!n--) break;
108 *args++ = regs->dx;
109 case 3:
110 if (!n--) break;
111 *args++ = regs->si;
112 case 4:
113 if (!n--) break;
114 *args++ = regs->di;
115 case 5:
116 if (!n--) break;
117 *args++ = regs->bp;
118 case 6:
Roland McGrath68bd0f42008-04-18 17:08:44 -0700119 if (!n--) break;
120 default:
121 BUG();
122 break;
123 }
124 else
125# endif
Linus Torvaldsc3c98972008-10-23 12:38:39 -0700126 switch (i) {
127 case 0:
Roland McGrath68bd0f42008-04-18 17:08:44 -0700128 if (!n--) break;
129 *args++ = regs->di;
Linus Torvaldsc3c98972008-10-23 12:38:39 -0700130 case 1:
131 if (!n--) break;
132 *args++ = regs->si;
133 case 2:
134 if (!n--) break;
135 *args++ = regs->dx;
136 case 3:
137 if (!n--) break;
138 *args++ = regs->r10;
139 case 4:
140 if (!n--) break;
141 *args++ = regs->r8;
142 case 5:
143 if (!n--) break;
144 *args++ = regs->r9;
145 case 6:
Roland McGrath68bd0f42008-04-18 17:08:44 -0700146 if (!n--) break;
147 default:
148 BUG();
149 break;
150 }
151}
152
153static inline void syscall_set_arguments(struct task_struct *task,
154 struct pt_regs *regs,
155 unsigned int i, unsigned int n,
156 const unsigned long *args)
157{
158# ifdef CONFIG_IA32_EMULATION
159 if (task_thread_info(task)->status & TS_COMPAT)
Linus Torvaldsc3c98972008-10-23 12:38:39 -0700160 switch (i) {
161 case 0:
Roland McGrath68bd0f42008-04-18 17:08:44 -0700162 if (!n--) break;
163 regs->bx = *args++;
Linus Torvaldsc3c98972008-10-23 12:38:39 -0700164 case 1:
165 if (!n--) break;
166 regs->cx = *args++;
167 case 2:
168 if (!n--) break;
169 regs->dx = *args++;
170 case 3:
171 if (!n--) break;
172 regs->si = *args++;
173 case 4:
174 if (!n--) break;
175 regs->di = *args++;
176 case 5:
177 if (!n--) break;
178 regs->bp = *args++;
179 case 6:
Roland McGrath68bd0f42008-04-18 17:08:44 -0700180 if (!n--) break;
181 default:
182 BUG();
Linus Torvaldsc3c98972008-10-23 12:38:39 -0700183 break;
Roland McGrath68bd0f42008-04-18 17:08:44 -0700184 }
185 else
186# endif
Linus Torvaldsc3c98972008-10-23 12:38:39 -0700187 switch (i) {
188 case 0:
Roland McGrath68bd0f42008-04-18 17:08:44 -0700189 if (!n--) break;
190 regs->di = *args++;
Linus Torvaldsc3c98972008-10-23 12:38:39 -0700191 case 1:
192 if (!n--) break;
193 regs->si = *args++;
194 case 2:
195 if (!n--) break;
196 regs->dx = *args++;
197 case 3:
198 if (!n--) break;
199 regs->r10 = *args++;
200 case 4:
201 if (!n--) break;
202 regs->r8 = *args++;
203 case 5:
204 if (!n--) break;
205 regs->r9 = *args++;
206 case 6:
Roland McGrath68bd0f42008-04-18 17:08:44 -0700207 if (!n--) break;
208 default:
209 BUG();
Linus Torvaldsc3c98972008-10-23 12:38:39 -0700210 break;
Roland McGrath68bd0f42008-04-18 17:08:44 -0700211 }
212}
213
214#endif /* CONFIG_X86_32 */
215
H. Peter Anvin5e1b0072008-10-23 00:20:33 -0700216#endif /* _ASM_X86_SYSCALL_H */