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