]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame - arch/x86/include/asm/compat.h
x32: Handle the x32 system call flag
[mirror_ubuntu-zesty-kernel.git] / arch / x86 / include / asm / compat.h
CommitLineData
1965aae3
PA
1#ifndef _ASM_X86_COMPAT_H
2#define _ASM_X86_COMPAT_H
1da177e4
LT
3
4/*
5 * Architecture specific compatibility types
6 */
7#include <linux/types.h>
8#include <linux/sched.h>
95d1b8f9 9#include <asm/user32.h>
fca460f9 10#include <asm/unistd.h>
1da177e4 11
e28cbf22
CH
12#define COMPAT_USER_HZ 100
13#define COMPAT_UTS_MACHINE "i686\0\0"
1da177e4
LT
14
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;
202e5979
SR
20typedef u16 __compat_uid_t;
21typedef u16 __compat_gid_t;
22typedef u32 __compat_uid32_t;
23typedef u32 __compat_gid32_t;
1da177e4
LT
24typedef 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;
4b777587 39typedef s64 __attribute__((aligned(4))) compat_s64;
1da177e4
LT
40typedef u32 compat_uint_t;
41typedef u32 compat_ulong_t;
4b777587 42typedef u64 __attribute__((aligned(4))) compat_u64;
1da177e4
LT
43
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;
202e5979
SR
60 __compat_uid_t st_uid;
61 __compat_gid_t st_gid;
1da177e4
LT
62 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;
1448c721
EB
112 int f_flags;
113 int f_spare[4];
1da177e4
LT
114};
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;
202e5979
SR
131 __compat_uid32_t uid;
132 __compat_gid32_t gid;
133 __compat_uid32_t cuid;
134 __compat_gid32_t cgid;
1da177e4
LT
135 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
95d1b8f9
RM
187/*
188 * The type of struct elf_prstatus.pr_reg in compatible core dumps.
189 */
190typedef struct user_regs_struct32 compat_elf_gregset_t;
191
1da177e4
LT
192/*
193 * 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
8b3de0df 196 * appropriately converted them already.
1da177e4
LT
197 */
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
c41d68a5 210static inline void __user *arch_compat_alloc_user_space(long len)
1da177e4 211{
bb049232 212 struct pt_regs *regs = task_pt_regs(current);
65ea5b03 213 return (void __user *)regs->sp - len;
1da177e4
LT
214}
215
fca460f9 216static inline bool is_compat_task(void)
bf2fcc6f 217{
fca460f9
PA
218#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;
bf2fcc6f
AK
227}
228
1965aae3 229#endif /* _ASM_X86_COMPAT_H */