blob: fedf32b73e65d8e288fc1bd4ed209212bd2c5163 [file] [log] [blame]
H. Peter Anvin1965aae2008-10-22 22:26:29 -07001#ifndef _ASM_X86_COMPAT_H
2#define _ASM_X86_COMPAT_H
Linus Torvalds1da177e2005-04-16 15:20:36 -07003
4/*
5 * Architecture specific compatibility types
6 */
7#include <linux/types.h>
8#include <linux/sched.h>
H. Peter Anvind1a797f2012-02-19 10:06:34 -08009#include <asm/processor.h>
Roland McGrath95d1b8f2007-10-19 20:35:02 +020010#include <asm/user32.h>
H. Peter Anvinfca460f2012-02-19 07:56:26 -080011#include <asm/unistd.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012
Christoph Hellwige28cbf22010-03-10 15:21:19 -080013#define COMPAT_USER_HZ 100
14#define COMPAT_UTS_MACHINE "i686\0\0"
Linus Torvalds1da177e2005-04-16 15:20:36 -070015
16typedef u32 compat_size_t;
17typedef s32 compat_ssize_t;
18typedef s32 compat_time_t;
19typedef s32 compat_clock_t;
20typedef s32 compat_pid_t;
Stephen Rothwell202e5972005-09-06 15:16:40 -070021typedef u16 __compat_uid_t;
22typedef u16 __compat_gid_t;
23typedef u32 __compat_uid32_t;
24typedef u32 __compat_gid32_t;
Linus Torvalds1da177e2005-04-16 15:20:36 -070025typedef u16 compat_mode_t;
26typedef u32 compat_ino_t;
27typedef u16 compat_dev_t;
28typedef s32 compat_off_t;
29typedef s64 compat_loff_t;
30typedef u16 compat_nlink_t;
31typedef u16 compat_ipc_pid_t;
32typedef s32 compat_daddr_t;
33typedef u32 compat_caddr_t;
34typedef __kernel_fsid_t compat_fsid_t;
35typedef s32 compat_timer_t;
36typedef s32 compat_key_t;
37
38typedef s32 compat_int_t;
39typedef s32 compat_long_t;
Arnd Bergmann4b777582007-07-15 23:41:11 -070040typedef s64 __attribute__((aligned(4))) compat_s64;
Linus Torvalds1da177e2005-04-16 15:20:36 -070041typedef u32 compat_uint_t;
42typedef u32 compat_ulong_t;
Arnd Bergmann4b777582007-07-15 23:41:11 -070043typedef u64 __attribute__((aligned(4))) compat_u64;
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
45struct compat_timespec {
46 compat_time_t tv_sec;
47 s32 tv_nsec;
48};
49
50struct compat_timeval {
51 compat_time_t tv_sec;
52 s32 tv_usec;
53};
54
55struct compat_stat {
56 compat_dev_t st_dev;
57 u16 __pad1;
58 compat_ino_t st_ino;
59 compat_mode_t st_mode;
60 compat_nlink_t st_nlink;
Stephen Rothwell202e5972005-09-06 15:16:40 -070061 __compat_uid_t st_uid;
62 __compat_gid_t st_gid;
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 compat_dev_t st_rdev;
64 u16 __pad2;
65 u32 st_size;
66 u32 st_blksize;
67 u32 st_blocks;
68 u32 st_atime;
69 u32 st_atime_nsec;
70 u32 st_mtime;
71 u32 st_mtime_nsec;
72 u32 st_ctime;
73 u32 st_ctime_nsec;
74 u32 __unused4;
75 u32 __unused5;
76};
77
78struct compat_flock {
79 short l_type;
80 short l_whence;
81 compat_off_t l_start;
82 compat_off_t l_len;
83 compat_pid_t l_pid;
84};
85
86#define F_GETLK64 12 /* using 'struct flock64' */
87#define F_SETLK64 13
88#define F_SETLKW64 14
89
90/*
91 * IA32 uses 4 byte alignment for 64 bit quantities,
92 * so we need to pack this structure.
93 */
94struct compat_flock64 {
95 short l_type;
96 short l_whence;
97 compat_loff_t l_start;
98 compat_loff_t l_len;
99 compat_pid_t l_pid;
100} __attribute__((packed));
101
102struct compat_statfs {
103 int f_type;
104 int f_bsize;
105 int f_blocks;
106 int f_bfree;
107 int f_bavail;
108 int f_files;
109 int f_ffree;
110 compat_fsid_t f_fsid;
111 int f_namelen; /* SunOS ignores this field. */
112 int f_frsize;
Eric W. Biederman1448c722011-10-17 13:40:02 -0700113 int f_flags;
114 int f_spare[4];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115};
116
117#define COMPAT_RLIM_OLD_INFINITY 0x7fffffff
118#define COMPAT_RLIM_INFINITY 0xffffffff
119
120typedef u32 compat_old_sigset_t; /* at least 32 bits */
121
122#define _COMPAT_NSIG 64
123#define _COMPAT_NSIG_BPW 32
124
125typedef u32 compat_sigset_word;
126
127#define COMPAT_OFF_T_MAX 0x7fffffff
128#define COMPAT_LOFF_T_MAX 0x7fffffffffffffffL
129
130struct compat_ipc64_perm {
131 compat_key_t key;
Stephen Rothwell202e5972005-09-06 15:16:40 -0700132 __compat_uid32_t uid;
133 __compat_gid32_t gid;
134 __compat_uid32_t cuid;
135 __compat_gid32_t cgid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 unsigned short mode;
137 unsigned short __pad1;
138 unsigned short seq;
139 unsigned short __pad2;
140 compat_ulong_t unused1;
141 compat_ulong_t unused2;
142};
143
144struct compat_semid64_ds {
145 struct compat_ipc64_perm sem_perm;
146 compat_time_t sem_otime;
147 compat_ulong_t __unused1;
148 compat_time_t sem_ctime;
149 compat_ulong_t __unused2;
150 compat_ulong_t sem_nsems;
151 compat_ulong_t __unused3;
152 compat_ulong_t __unused4;
153};
154
155struct compat_msqid64_ds {
156 struct compat_ipc64_perm msg_perm;
157 compat_time_t msg_stime;
158 compat_ulong_t __unused1;
159 compat_time_t msg_rtime;
160 compat_ulong_t __unused2;
161 compat_time_t msg_ctime;
162 compat_ulong_t __unused3;
163 compat_ulong_t msg_cbytes;
164 compat_ulong_t msg_qnum;
165 compat_ulong_t msg_qbytes;
166 compat_pid_t msg_lspid;
167 compat_pid_t msg_lrpid;
168 compat_ulong_t __unused4;
169 compat_ulong_t __unused5;
170};
171
172struct compat_shmid64_ds {
173 struct compat_ipc64_perm shm_perm;
174 compat_size_t shm_segsz;
175 compat_time_t shm_atime;
176 compat_ulong_t __unused1;
177 compat_time_t shm_dtime;
178 compat_ulong_t __unused2;
179 compat_time_t shm_ctime;
180 compat_ulong_t __unused3;
181 compat_pid_t shm_cpid;
182 compat_pid_t shm_lpid;
183 compat_ulong_t shm_nattch;
184 compat_ulong_t __unused4;
185 compat_ulong_t __unused5;
186};
187
188/*
Roland McGrath95d1b8f2007-10-19 20:35:02 +0200189 * The type of struct elf_prstatus.pr_reg in compatible core dumps.
190 */
H. Peter Anvind1a797f2012-02-19 10:06:34 -0800191#ifdef CONFIG_X86_X32_ABI
192typedef struct user_regs_struct compat_elf_gregset_t;
193
194#define PR_REG_SIZE(S) (test_thread_flag(TIF_IA32) ? 68 : 216)
195#define PRSTATUS_SIZE(S) (test_thread_flag(TIF_IA32) ? 144 : 296)
196#define SET_PR_FPVALID(S,V) \
197 do { *(int *) (((void *) &((S)->pr_reg)) + PR_REG_SIZE(0)) = (V); } \
198 while (0)
199
200#define COMPAT_USE_64BIT_TIME \
201 (!!(task_pt_regs(current)->orig_ax & __X32_SYSCALL_BIT))
202#else
Roland McGrath95d1b8f2007-10-19 20:35:02 +0200203typedef struct user_regs_struct32 compat_elf_gregset_t;
H. Peter Anvind1a797f2012-02-19 10:06:34 -0800204#endif
Roland McGrath95d1b8f2007-10-19 20:35:02 +0200205
206/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 * A pointer passed in from user mode. This should not
208 * be used for syscall parameters, just declare them
209 * as pointers because the syscall entry code will have
Marcin Ĺšlusarz8b3de0d2008-02-03 16:32:51 +0200210 * appropriately converted them already.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 */
212typedef u32 compat_uptr_t;
213
214static inline void __user *compat_ptr(compat_uptr_t uptr)
215{
216 return (void __user *)(unsigned long)uptr;
217}
218
219static inline compat_uptr_t ptr_to_compat(void __user *uptr)
220{
221 return (u32)(unsigned long)uptr;
222}
223
H. Peter Anvinc41d68a2010-09-07 16:16:18 -0700224static inline void __user *arch_compat_alloc_user_space(long len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225{
H. Peter Anvind1a797f2012-02-19 10:06:34 -0800226 compat_uptr_t sp;
227
228 if (test_thread_flag(TIF_IA32)) {
229 sp = task_pt_regs(current)->sp;
230 } else {
231 /* -128 for the x32 ABI redzone */
Alex Shic6ae41e2012-05-11 15:35:27 +0800232 sp = this_cpu_read(old_rsp) - 128;
H. Peter Anvind1a797f2012-02-19 10:06:34 -0800233 }
234
235 return (void __user *)round_down(sp - len, 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236}
237
H. Peter Anvina628b682012-03-05 13:39:29 -0800238static inline bool is_x32_task(void)
239{
H. Peter Anvinfca460f2012-02-19 07:56:26 -0800240#ifdef CONFIG_X86_X32_ABI
241 if (task_pt_regs(current)->orig_ax & __X32_SYSCALL_BIT)
242 return true;
243#endif
244 return false;
Andi Kleenbf2fcc62006-01-11 22:44:06 +0100245}
246
H. Peter Anvina628b682012-03-05 13:39:29 -0800247static inline bool is_compat_task(void)
248{
249 return is_ia32_task() || is_x32_task();
250}
251
H. Peter Anvin1965aae2008-10-22 22:26:29 -0700252#endif /* _ASM_X86_COMPAT_H */