blob: 717c691ecd8e3acd03c51d9d8f42efc2ec489af9 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef _LINUX_COMPAT_H
2#define _LINUX_COMPAT_H
3/*
4 * These are the type definitions for the architecture specific
5 * syscall compatibility layer.
6 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07007
8#ifdef CONFIG_COMPAT
9
10#include <linux/stat.h>
11#include <linux/param.h> /* for HZ */
12#include <linux/sem.h>
Arnd Bergmann2dceba12009-11-06 08:09:03 +000013#include <linux/socket.h>
14#include <linux/if.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015
16#include <asm/compat.h>
17#include <asm/siginfo.h>
David Howells3f2e05e2006-10-02 14:12:31 +010018#include <asm/signal.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019
20#define compat_jiffies_to_clock_t(x) \
21 (((unsigned long)(x) * COMPAT_USER_HZ) / HZ)
22
Stephen Rothwell202e5972005-09-06 15:16:40 -070023typedef __compat_uid32_t compat_uid_t;
24typedef __compat_gid32_t compat_gid_t;
25
Christoph Hellwig5d0e5282010-03-10 15:21:13 -080026struct compat_sel_arg_struct;
Linus Torvalds1da177e2005-04-16 15:20:36 -070027struct rusage;
28
29struct compat_itimerspec {
30 struct compat_timespec it_interval;
31 struct compat_timespec it_value;
32};
33
34struct compat_utimbuf {
35 compat_time_t actime;
36 compat_time_t modtime;
37};
38
39struct compat_itimerval {
40 struct compat_timeval it_interval;
41 struct compat_timeval it_value;
42};
43
44struct compat_tms {
45 compat_clock_t tms_utime;
46 compat_clock_t tms_stime;
47 compat_clock_t tms_cutime;
48 compat_clock_t tms_cstime;
49};
50
Stephen Rothwell88959ea2006-03-26 01:37:27 -080051struct compat_timex {
52 compat_uint_t modes;
53 compat_long_t offset;
54 compat_long_t freq;
55 compat_long_t maxerror;
56 compat_long_t esterror;
57 compat_int_t status;
58 compat_long_t constant;
59 compat_long_t precision;
60 compat_long_t tolerance;
61 struct compat_timeval time;
62 compat_long_t tick;
63 compat_long_t ppsfreq;
64 compat_long_t jitter;
65 compat_int_t shift;
66 compat_long_t stabil;
67 compat_long_t jitcnt;
68 compat_long_t calcnt;
69 compat_long_t errcnt;
70 compat_long_t stbcnt;
Roman Zippel153b5d02008-05-01 04:34:37 -070071 compat_int_t tai;
Stephen Rothwell88959ea2006-03-26 01:37:27 -080072
73 compat_int_t :32; compat_int_t :32; compat_int_t :32; compat_int_t :32;
74 compat_int_t :32; compat_int_t :32; compat_int_t :32; compat_int_t :32;
Roman Zippel153b5d02008-05-01 04:34:37 -070075 compat_int_t :32; compat_int_t :32; compat_int_t :32;
Stephen Rothwell88959ea2006-03-26 01:37:27 -080076};
77
Linus Torvalds1da177e2005-04-16 15:20:36 -070078#define _COMPAT_NSIG_WORDS (_COMPAT_NSIG / _COMPAT_NSIG_BPW)
79
80typedef struct {
81 compat_sigset_word sig[_COMPAT_NSIG_WORDS];
82} compat_sigset_t;
83
Linus Torvalds1da177e2005-04-16 15:20:36 -070084extern int get_compat_timespec(struct timespec *, const struct compat_timespec __user *);
85extern int put_compat_timespec(const struct timespec *, struct compat_timespec __user *);
86
87struct compat_iovec {
88 compat_uptr_t iov_base;
89 compat_size_t iov_len;
90};
91
92struct compat_rlimit {
93 compat_ulong_t rlim_cur;
94 compat_ulong_t rlim_max;
95};
96
97struct compat_rusage {
98 struct compat_timeval ru_utime;
99 struct compat_timeval ru_stime;
100 compat_long_t ru_maxrss;
101 compat_long_t ru_ixrss;
102 compat_long_t ru_idrss;
103 compat_long_t ru_isrss;
104 compat_long_t ru_minflt;
105 compat_long_t ru_majflt;
106 compat_long_t ru_nswap;
107 compat_long_t ru_inblock;
108 compat_long_t ru_oublock;
109 compat_long_t ru_msgsnd;
110 compat_long_t ru_msgrcv;
111 compat_long_t ru_nsignals;
112 compat_long_t ru_nvcsw;
113 compat_long_t ru_nivcsw;
114};
115
116extern int put_compat_rusage(const struct rusage *, struct compat_rusage __user *);
117
118struct compat_siginfo;
119
120extern asmlinkage long compat_sys_waitid(int, compat_pid_t,
121 struct compat_siginfo __user *, int,
122 struct compat_rusage __user *);
123
124struct compat_dirent {
125 u32 d_ino;
126 compat_off_t d_off;
127 u16 d_reclen;
128 char d_name[256];
129};
130
Christoph Hellwig2b1c6bd2008-11-28 10:09:09 +0100131struct compat_ustat {
132 compat_daddr_t f_tfree;
133 compat_ino_t f_tinode;
134 char f_fname[6];
135 char f_fpack[6];
136};
137
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138typedef union compat_sigval {
139 compat_int_t sival_int;
140 compat_uptr_t sival_ptr;
141} compat_sigval_t;
142
143#define COMPAT_SIGEV_PAD_SIZE ((SIGEV_MAX_SIZE/sizeof(int)) - 3)
144
145typedef struct compat_sigevent {
146 compat_sigval_t sigev_value;
147 compat_int_t sigev_signo;
148 compat_int_t sigev_notify;
149 union {
150 compat_int_t _pad[COMPAT_SIGEV_PAD_SIZE];
151 compat_int_t _tid;
152
153 struct {
154 compat_uptr_t _function;
155 compat_uptr_t _attribute;
156 } _sigev_thread;
157 } _sigev_un;
158} compat_sigevent_t;
159
Arnd Bergmann2dceba12009-11-06 08:09:03 +0000160struct compat_ifmap {
161 compat_ulong_t mem_start;
162 compat_ulong_t mem_end;
163 unsigned short base_addr;
164 unsigned char irq;
165 unsigned char dma;
166 unsigned char port;
167};
168
Arnd Bergmann7a50a242009-11-08 20:57:03 -0800169struct compat_if_settings
170{
171 unsigned int type; /* Type of physical device or protocol */
172 unsigned int size; /* Size of the data allocated by the caller */
173 compat_uptr_t ifs_ifsu; /* union of pointers */
174};
175
Arnd Bergmann2dceba12009-11-06 08:09:03 +0000176struct compat_ifreq {
Arnd Bergmann7a50a242009-11-08 20:57:03 -0800177 union {
178 char ifrn_name[IFNAMSIZ]; /* if name, e.g. "en0" */
179 } ifr_ifrn;
180 union {
181 struct sockaddr ifru_addr;
182 struct sockaddr ifru_dstaddr;
183 struct sockaddr ifru_broadaddr;
184 struct sockaddr ifru_netmask;
185 struct sockaddr ifru_hwaddr;
186 short ifru_flags;
187 compat_int_t ifru_ivalue;
188 compat_int_t ifru_mtu;
189 struct compat_ifmap ifru_map;
190 char ifru_slave[IFNAMSIZ]; /* Just fits the size */
Arnd Bergmann2dceba12009-11-06 08:09:03 +0000191 char ifru_newname[IFNAMSIZ];
Arnd Bergmann7a50a242009-11-08 20:57:03 -0800192 compat_caddr_t ifru_data;
193 struct compat_if_settings ifru_settings;
194 } ifr_ifru;
Arnd Bergmann2dceba12009-11-06 08:09:03 +0000195};
196
197struct compat_ifconf {
198 compat_int_t ifc_len; /* size of buffer */
199 compat_caddr_t ifcbuf;
200};
201
Ingo Molnar34f192c2006-03-27 01:16:24 -0800202struct compat_robust_list {
203 compat_uptr_t next;
204};
205
206struct compat_robust_list_head {
207 struct compat_robust_list list;
208 compat_long_t futex_offset;
209 compat_uptr_t list_op_pending;
210};
211
212extern void compat_exit_robust_list(struct task_struct *curr);
213
214asmlinkage long
215compat_sys_set_robust_list(struct compat_robust_list_head __user *head,
216 compat_size_t len);
217asmlinkage long
Al Viroba46df92006-10-10 22:46:07 +0100218compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
Ingo Molnar34f192c2006-03-27 01:16:24 -0800219 compat_size_t __user *len_ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220
221long compat_sys_semctl(int first, int second, int third, void __user *uptr);
222long compat_sys_msgsnd(int first, int second, int third, void __user *uptr);
223long compat_sys_msgrcv(int first, int second, int msgtyp, int third,
224 int version, void __user *uptr);
225long compat_sys_msgctl(int first, int second, void __user *uptr);
226long compat_sys_shmat(int first, int second, compat_uptr_t third, int version,
227 void __user *uptr);
228long compat_sys_shmctl(int first, int second, void __user *uptr);
229long compat_sys_semtimedop(int semid, struct sembuf __user *tsems,
230 unsigned nsems, const struct compat_timespec __user *timeout);
231asmlinkage long compat_sys_keyctl(u32 option,
232 u32 arg2, u32 arg3, u32 arg4, u32 arg5);
Christoph Hellwig2b1c6bd2008-11-28 10:09:09 +0100233asmlinkage long compat_sys_ustat(unsigned dev, struct compat_ustat __user *u32);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234
235asmlinkage ssize_t compat_sys_readv(unsigned long fd,
236 const struct compat_iovec __user *vec, unsigned long vlen);
237asmlinkage ssize_t compat_sys_writev(unsigned long fd,
238 const struct compat_iovec __user *vec, unsigned long vlen);
Gerd Hoffmannf3554f42009-04-02 16:59:23 -0700239asmlinkage ssize_t compat_sys_preadv(unsigned long fd,
240 const struct compat_iovec __user *vec,
Linus Torvalds601cc112009-04-03 08:03:22 -0700241 unsigned long vlen, u32 pos_low, u32 pos_high);
Gerd Hoffmannf3554f42009-04-02 16:59:23 -0700242asmlinkage ssize_t compat_sys_pwritev(unsigned long fd,
243 const struct compat_iovec __user *vec,
Linus Torvalds601cc112009-04-03 08:03:22 -0700244 unsigned long vlen, u32 pos_low, u32 pos_high);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245
246int compat_do_execve(char * filename, compat_uptr_t __user *argv,
247 compat_uptr_t __user *envp, struct pt_regs * regs);
248
249asmlinkage long compat_sys_select(int n, compat_ulong_t __user *inp,
250 compat_ulong_t __user *outp, compat_ulong_t __user *exp,
251 struct compat_timeval __user *tvp);
252
Christoph Hellwig5d0e5282010-03-10 15:21:13 -0800253asmlinkage long compat_sys_old_select(struct compat_sel_arg_struct __user *arg);
254
Thomas Gleixnerc202f292008-01-30 13:30:08 +0100255asmlinkage long compat_sys_wait4(compat_pid_t pid,
Al Viro7d61c452008-03-29 03:09:28 +0000256 compat_uint_t __user *stat_addr, int options,
257 struct compat_rusage __user *ru);
Thomas Gleixnerc202f292008-01-30 13:30:08 +0100258
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259#define BITS_PER_COMPAT_LONG (8*sizeof(compat_long_t))
260
261#define BITS_TO_COMPAT_LONGS(bits) \
262 (((bits)+BITS_PER_COMPAT_LONG-1)/BITS_PER_COMPAT_LONG)
263
Stephen Rothwell5fa38392006-10-28 10:38:46 -0700264long compat_get_bitmap(unsigned long *mask, const compat_ulong_t __user *umask,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 unsigned long bitmap_size);
266long compat_put_bitmap(compat_ulong_t __user *umask, unsigned long *mask,
267 unsigned long bitmap_size);
268int copy_siginfo_from_user32(siginfo_t *to, struct compat_siginfo __user *from);
269int copy_siginfo_to_user32(struct compat_siginfo __user *to, siginfo_t *from);
270int get_compat_sigevent(struct sigevent *event,
271 const struct compat_sigevent __user *u_event);
Thomas Gleixner62ab4502009-04-04 21:01:06 +0000272long compat_sys_rt_tgsigqueueinfo(compat_pid_t tgid, compat_pid_t pid, int sig,
273 struct compat_siginfo __user *uinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274
Andrew Morton643a6542006-02-11 17:55:52 -0800275static inline int compat_timeval_compare(struct compat_timeval *lhs,
276 struct compat_timeval *rhs)
277{
278 if (lhs->tv_sec < rhs->tv_sec)
279 return -1;
280 if (lhs->tv_sec > rhs->tv_sec)
281 return 1;
282 return lhs->tv_usec - rhs->tv_usec;
283}
284
285static inline int compat_timespec_compare(struct compat_timespec *lhs,
286 struct compat_timespec *rhs)
287{
288 if (lhs->tv_sec < rhs->tv_sec)
289 return -1;
290 if (lhs->tv_sec > rhs->tv_sec)
291 return 1;
292 return lhs->tv_nsec - rhs->tv_nsec;
293}
294
Davide Libenzi83f5d122007-05-10 22:23:18 -0700295extern int get_compat_itimerspec(struct itimerspec *dst,
296 const struct compat_itimerspec __user *src);
297extern int put_compat_itimerspec(struct compat_itimerspec __user *dst,
298 const struct itimerspec *src);
299
Christoph Hellwigb418da12008-10-15 22:02:06 -0700300asmlinkage long compat_sys_gettimeofday(struct compat_timeval __user *tv,
301 struct timezone __user *tz);
302asmlinkage long compat_sys_settimeofday(struct compat_timeval __user *tv,
303 struct timezone __user *tz);
304
Stephen Rothwell3158e942006-03-26 01:37:29 -0800305asmlinkage long compat_sys_adjtimex(struct compat_timex __user *utp);
306
Andi Kleenbebfa102006-06-26 13:56:52 +0200307extern int compat_printk(const char *fmt, ...);
Linus Torvalds02354972006-10-02 14:05:20 -0700308extern void sigset_from_compat(sigset_t *set, compat_sigset_t *compat);
Andi Kleenbebfa102006-06-26 13:56:52 +0200309
Stephen Rothwell3fd59392006-11-02 22:07:24 -0800310asmlinkage long compat_sys_migrate_pages(compat_pid_t pid,
311 compat_ulong_t maxnode, const compat_ulong_t __user *old_nodes,
312 const compat_ulong_t __user *new_nodes);
313
Roland McGrath032d82d2008-01-30 13:31:47 +0100314extern int compat_ptrace_request(struct task_struct *child,
315 compat_long_t request,
316 compat_ulong_t addr, compat_ulong_t data);
317
Roland McGrathc269f192008-01-30 13:31:48 +0100318extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
319 compat_ulong_t addr, compat_ulong_t data);
320asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
321 compat_long_t addr, compat_long_t data);
Roland McGrathc269f192008-01-30 13:31:48 +0100322
Davide Libenzif6dfb4f2007-03-07 20:41:21 -0800323/*
324 * epoll (fs/eventpoll.c) compat bits follow ...
325 */
Davide Libenzif6dfb4f2007-03-07 20:41:21 -0800326struct epoll_event;
327#define compat_epoll_event epoll_event
Davide Libenzif6dfb4f2007-03-07 20:41:21 -0800328asmlinkage long compat_sys_epoll_pwait(int epfd,
329 struct compat_epoll_event __user *events,
330 int maxevents, int timeout,
331 const compat_sigset_t __user *sigmask,
332 compat_size_t sigsetsize);
333
Stephen Rothwell97416ce2007-05-09 02:32:35 -0700334asmlinkage long compat_sys_utimensat(unsigned int dfd, char __user *filename,
335 struct compat_timespec __user *t, int flags);
336
Stephen Rothwell140ff8b2007-05-14 13:47:47 +1000337asmlinkage long compat_sys_signalfd(int ufd,
338 const compat_sigset_t __user *sigmask,
339 compat_size_t sigsetsize);
Davide Libenzi4d672e72008-02-04 22:27:26 -0800340asmlinkage long compat_sys_timerfd_settime(int ufd, int flags,
341 const struct compat_itimerspec __user *utmr,
342 struct compat_itimerspec __user *otmr);
343asmlinkage long compat_sys_timerfd_gettime(int ufd,
344 struct compat_itimerspec __user *otmr);
Stephen Rothwell140ff8b2007-05-14 13:47:47 +1000345
Heiko Carstens4c696ba2009-01-14 14:13:53 +0100346asmlinkage long compat_sys_move_pages(pid_t pid, unsigned long nr_page,
347 __u32 __user *pages,
348 const int __user *nodes,
349 int __user *status,
350 int flags);
351asmlinkage long compat_sys_futimesat(unsigned int dfd, char __user *filename,
352 struct compat_timeval __user *t);
353asmlinkage long compat_sys_newfstatat(unsigned int dfd, char __user * filename,
354 struct compat_stat __user *statbuf,
355 int flag);
356asmlinkage long compat_sys_openat(unsigned int dfd, const char __user *filename,
357 int flags, int mode);
358
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359#endif /* CONFIG_COMPAT */
360#endif /* _LINUX_COMPAT_H */