blob: 7938b84e4506200c7f6afde771334cbff684c5d6 [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>
Roland McGrath95d1b8f2007-10-19 20:35:02 +02009#include <asm/user32.h>
H. Peter Anvinfca460f2012-02-19 07:56:26 -080010#include <asm/unistd.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011
Christoph Hellwige28cbf22010-03-10 15:21:19 -080012#define COMPAT_USER_HZ 100
13#define COMPAT_UTS_MACHINE "i686\0\0"
Linus Torvalds1da177e2005-04-16 15:20:36 -070014
15typedef u32 compat_size_t;
16typedef s32 compat_ssize_t;
17typedef s32 compat_time_t;
18typedef s32 compat_clock_t;
19typedef s32 compat_pid_t;
Stephen Rothwell202e5972005-09-06 15:16:40 -070020typedef u16 __compat_uid_t;
21typedef u16 __compat_gid_t;
22typedef u32 __compat_uid32_t;
23typedef u32 __compat_gid32_t;
Linus Torvalds1da177e2005-04-16 15:20:36 -070024typedef u16 compat_mode_t;
25typedef u32 compat_ino_t;
26typedef u16 compat_dev_t;
27typedef s32 compat_off_t;
28typedef s64 compat_loff_t;
29typedef u16 compat_nlink_t;
30typedef u16 compat_ipc_pid_t;
31typedef s32 compat_daddr_t;
32typedef u32 compat_caddr_t;
33typedef __kernel_fsid_t compat_fsid_t;
34typedef s32 compat_timer_t;
35typedef s32 compat_key_t;
36
37typedef s32 compat_int_t;
38typedef s32 compat_long_t;
Arnd Bergmann4b777582007-07-15 23:41:11 -070039typedef s64 __attribute__((aligned(4))) compat_s64;
Linus Torvalds1da177e2005-04-16 15:20:36 -070040typedef u32 compat_uint_t;
41typedef u32 compat_ulong_t;
Arnd Bergmann4b777582007-07-15 23:41:11 -070042typedef u64 __attribute__((aligned(4))) compat_u64;
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
44struct compat_timespec {
45 compat_time_t tv_sec;
46 s32 tv_nsec;
47};
48
49struct compat_timeval {
50 compat_time_t tv_sec;
51 s32 tv_usec;
52};
53
54struct compat_stat {
55 compat_dev_t st_dev;
56 u16 __pad1;
57 compat_ino_t st_ino;
58 compat_mode_t st_mode;
59 compat_nlink_t st_nlink;
Stephen Rothwell202e5972005-09-06 15:16:40 -070060 __compat_uid_t st_uid;
61 __compat_gid_t st_gid;
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 compat_dev_t st_rdev;
63 u16 __pad2;
64 u32 st_size;
65 u32 st_blksize;
66 u32 st_blocks;
67 u32 st_atime;
68 u32 st_atime_nsec;
69 u32 st_mtime;
70 u32 st_mtime_nsec;
71 u32 st_ctime;
72 u32 st_ctime_nsec;
73 u32 __unused4;
74 u32 __unused5;
75};
76
77struct compat_flock {
78 short l_type;
79 short l_whence;
80 compat_off_t l_start;
81 compat_off_t l_len;
82 compat_pid_t l_pid;
83};
84
85#define F_GETLK64 12 /* using 'struct flock64' */
86#define F_SETLK64 13
87#define F_SETLKW64 14
88
89/*
90 * IA32 uses 4 byte alignment for 64 bit quantities,
91 * so we need to pack this structure.
92 */
93struct compat_flock64 {
94 short l_type;
95 short l_whence;
96 compat_loff_t l_start;
97 compat_loff_t l_len;
98 compat_pid_t l_pid;
99} __attribute__((packed));
100
101struct compat_statfs {
102 int f_type;
103 int f_bsize;
104 int f_blocks;
105 int f_bfree;
106 int f_bavail;
107 int f_files;
108 int f_ffree;
109 compat_fsid_t f_fsid;
110 int f_namelen; /* SunOS ignores this field. */
111 int f_frsize;
Eric W. Biederman1448c722011-10-17 13:40:02 -0700112 int f_flags;
113 int f_spare[4];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114};
115
116#define COMPAT_RLIM_OLD_INFINITY 0x7fffffff
117#define COMPAT_RLIM_INFINITY 0xffffffff
118
119typedef u32 compat_old_sigset_t; /* at least 32 bits */
120
121#define _COMPAT_NSIG 64
122#define _COMPAT_NSIG_BPW 32
123
124typedef u32 compat_sigset_word;
125
126#define COMPAT_OFF_T_MAX 0x7fffffff
127#define COMPAT_LOFF_T_MAX 0x7fffffffffffffffL
128
129struct compat_ipc64_perm {
130 compat_key_t key;
Stephen Rothwell202e5972005-09-06 15:16:40 -0700131 __compat_uid32_t uid;
132 __compat_gid32_t gid;
133 __compat_uid32_t cuid;
134 __compat_gid32_t cgid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 unsigned short mode;
136 unsigned short __pad1;
137 unsigned short seq;
138 unsigned short __pad2;
139 compat_ulong_t unused1;
140 compat_ulong_t unused2;
141};
142
143struct compat_semid64_ds {
144 struct compat_ipc64_perm sem_perm;
145 compat_time_t sem_otime;
146 compat_ulong_t __unused1;
147 compat_time_t sem_ctime;
148 compat_ulong_t __unused2;
149 compat_ulong_t sem_nsems;
150 compat_ulong_t __unused3;
151 compat_ulong_t __unused4;
152};
153
154struct compat_msqid64_ds {
155 struct compat_ipc64_perm msg_perm;
156 compat_time_t msg_stime;
157 compat_ulong_t __unused1;
158 compat_time_t msg_rtime;
159 compat_ulong_t __unused2;
160 compat_time_t msg_ctime;
161 compat_ulong_t __unused3;
162 compat_ulong_t msg_cbytes;
163 compat_ulong_t msg_qnum;
164 compat_ulong_t msg_qbytes;
165 compat_pid_t msg_lspid;
166 compat_pid_t msg_lrpid;
167 compat_ulong_t __unused4;
168 compat_ulong_t __unused5;
169};
170
171struct compat_shmid64_ds {
172 struct compat_ipc64_perm shm_perm;
173 compat_size_t shm_segsz;
174 compat_time_t shm_atime;
175 compat_ulong_t __unused1;
176 compat_time_t shm_dtime;
177 compat_ulong_t __unused2;
178 compat_time_t shm_ctime;
179 compat_ulong_t __unused3;
180 compat_pid_t shm_cpid;
181 compat_pid_t shm_lpid;
182 compat_ulong_t shm_nattch;
183 compat_ulong_t __unused4;
184 compat_ulong_t __unused5;
185};
186
187/*
Roland McGrath95d1b8f2007-10-19 20:35:02 +0200188 * The type of struct elf_prstatus.pr_reg in compatible core dumps.
189 */
190typedef struct user_regs_struct32 compat_elf_gregset_t;
191
192/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 * A pointer passed in from user mode. This should not
194 * be used for syscall parameters, just declare them
195 * as pointers because the syscall entry code will have
Marcin Ĺšlusarz8b3de0d2008-02-03 16:32:51 +0200196 * appropriately converted them already.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 */
198typedef u32 compat_uptr_t;
199
200static inline void __user *compat_ptr(compat_uptr_t uptr)
201{
202 return (void __user *)(unsigned long)uptr;
203}
204
205static inline compat_uptr_t ptr_to_compat(void __user *uptr)
206{
207 return (u32)(unsigned long)uptr;
208}
209
H. Peter Anvinc41d68a2010-09-07 16:16:18 -0700210static inline void __user *arch_compat_alloc_user_space(long len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211{
Al Virobb049232006-01-12 01:05:38 -0800212 struct pt_regs *regs = task_pt_regs(current);
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100213 return (void __user *)regs->sp - len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214}
215
H. Peter Anvinfca460f2012-02-19 07:56:26 -0800216static inline bool is_compat_task(void)
Andi Kleenbf2fcc62006-01-11 22:44:06 +0100217{
H. Peter Anvinfca460f2012-02-19 07:56:26 -0800218#ifdef CONFIG_IA32_EMULATION
219 if (current_thread_info()->status & TS_COMPAT)
220 return true;
221#endif
222#ifdef CONFIG_X86_X32_ABI
223 if (task_pt_regs(current)->orig_ax & __X32_SYSCALL_BIT)
224 return true;
225#endif
226 return false;
Andi Kleenbf2fcc62006-01-11 22:44:06 +0100227}
228
H. Peter Anvin1965aae2008-10-22 22:26:29 -0700229#endif /* _ASM_X86_COMPAT_H */