blob: 8311d2e29632d2029284333d07ef6fcf11b8e77b [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
Linus Torvalds1da177e2005-04-16 15:20:36 -070026struct rusage;
27
28struct compat_itimerspec {
29 struct compat_timespec it_interval;
30 struct compat_timespec it_value;
31};
32
33struct compat_utimbuf {
34 compat_time_t actime;
35 compat_time_t modtime;
36};
37
38struct compat_itimerval {
39 struct compat_timeval it_interval;
40 struct compat_timeval it_value;
41};
42
43struct compat_tms {
44 compat_clock_t tms_utime;
45 compat_clock_t tms_stime;
46 compat_clock_t tms_cutime;
47 compat_clock_t tms_cstime;
48};
49
Stephen Rothwell88959ea2006-03-26 01:37:27 -080050struct compat_timex {
51 compat_uint_t modes;
52 compat_long_t offset;
53 compat_long_t freq;
54 compat_long_t maxerror;
55 compat_long_t esterror;
56 compat_int_t status;
57 compat_long_t constant;
58 compat_long_t precision;
59 compat_long_t tolerance;
60 struct compat_timeval time;
61 compat_long_t tick;
62 compat_long_t ppsfreq;
63 compat_long_t jitter;
64 compat_int_t shift;
65 compat_long_t stabil;
66 compat_long_t jitcnt;
67 compat_long_t calcnt;
68 compat_long_t errcnt;
69 compat_long_t stbcnt;
Roman Zippel153b5d02008-05-01 04:34:37 -070070 compat_int_t tai;
Stephen Rothwell88959ea2006-03-26 01:37:27 -080071
72 compat_int_t :32; compat_int_t :32; compat_int_t :32; compat_int_t :32;
73 compat_int_t :32; compat_int_t :32; compat_int_t :32; compat_int_t :32;
Roman Zippel153b5d02008-05-01 04:34:37 -070074 compat_int_t :32; compat_int_t :32; compat_int_t :32;
Stephen Rothwell88959ea2006-03-26 01:37:27 -080075};
76
Linus Torvalds1da177e2005-04-16 15:20:36 -070077#define _COMPAT_NSIG_WORDS (_COMPAT_NSIG / _COMPAT_NSIG_BPW)
78
79typedef struct {
80 compat_sigset_word sig[_COMPAT_NSIG_WORDS];
81} compat_sigset_t;
82
Linus Torvalds1da177e2005-04-16 15:20:36 -070083extern int get_compat_timespec(struct timespec *, const struct compat_timespec __user *);
84extern int put_compat_timespec(const struct timespec *, struct compat_timespec __user *);
85
86struct compat_iovec {
87 compat_uptr_t iov_base;
88 compat_size_t iov_len;
89};
90
91struct compat_rlimit {
92 compat_ulong_t rlim_cur;
93 compat_ulong_t rlim_max;
94};
95
96struct compat_rusage {
97 struct compat_timeval ru_utime;
98 struct compat_timeval ru_stime;
99 compat_long_t ru_maxrss;
100 compat_long_t ru_ixrss;
101 compat_long_t ru_idrss;
102 compat_long_t ru_isrss;
103 compat_long_t ru_minflt;
104 compat_long_t ru_majflt;
105 compat_long_t ru_nswap;
106 compat_long_t ru_inblock;
107 compat_long_t ru_oublock;
108 compat_long_t ru_msgsnd;
109 compat_long_t ru_msgrcv;
110 compat_long_t ru_nsignals;
111 compat_long_t ru_nvcsw;
112 compat_long_t ru_nivcsw;
113};
114
115extern int put_compat_rusage(const struct rusage *, struct compat_rusage __user *);
116
117struct compat_siginfo;
118
119extern asmlinkage long compat_sys_waitid(int, compat_pid_t,
120 struct compat_siginfo __user *, int,
121 struct compat_rusage __user *);
122
123struct compat_dirent {
124 u32 d_ino;
125 compat_off_t d_off;
126 u16 d_reclen;
127 char d_name[256];
128};
129
Christoph Hellwig2b1c6bd2008-11-28 10:09:09 +0100130struct compat_ustat {
131 compat_daddr_t f_tfree;
132 compat_ino_t f_tinode;
133 char f_fname[6];
134 char f_fpack[6];
135};
136
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137typedef union compat_sigval {
138 compat_int_t sival_int;
139 compat_uptr_t sival_ptr;
140} compat_sigval_t;
141
142#define COMPAT_SIGEV_PAD_SIZE ((SIGEV_MAX_SIZE/sizeof(int)) - 3)
143
144typedef struct compat_sigevent {
145 compat_sigval_t sigev_value;
146 compat_int_t sigev_signo;
147 compat_int_t sigev_notify;
148 union {
149 compat_int_t _pad[COMPAT_SIGEV_PAD_SIZE];
150 compat_int_t _tid;
151
152 struct {
153 compat_uptr_t _function;
154 compat_uptr_t _attribute;
155 } _sigev_thread;
156 } _sigev_un;
157} compat_sigevent_t;
158
Arnd Bergmann2dceba12009-11-06 08:09:03 +0000159struct compat_ifmap {
160 compat_ulong_t mem_start;
161 compat_ulong_t mem_end;
162 unsigned short base_addr;
163 unsigned char irq;
164 unsigned char dma;
165 unsigned char port;
166};
167
168struct compat_ifreq {
169#define IFHWADDRLEN 6
170#define IFNAMSIZ 16
171 union {
172 char ifrn_name[IFNAMSIZ]; /* if name, e.g. "en0" */
173 } ifr_ifrn;
174 union {
175 struct sockaddr ifru_addr;
176 struct sockaddr ifru_dstaddr;
177 struct sockaddr ifru_broadaddr;
178 struct sockaddr ifru_netmask;
179 struct sockaddr ifru_hwaddr;
180 short ifru_flags;
181 compat_int_t ifru_ivalue;
182 compat_int_t ifru_mtu;
183 struct compat_ifmap ifru_map;
184 char ifru_slave[IFNAMSIZ]; /* Just fits the size */
185 char ifru_newname[IFNAMSIZ];
186 compat_caddr_t ifru_data;
187 /* XXXX? ifru_settings should be here */
188 } ifr_ifru;
189};
190
191struct compat_ifconf {
192 compat_int_t ifc_len; /* size of buffer */
193 compat_caddr_t ifcbuf;
194};
195
Ingo Molnar34f192c2006-03-27 01:16:24 -0800196struct compat_robust_list {
197 compat_uptr_t next;
198};
199
200struct compat_robust_list_head {
201 struct compat_robust_list list;
202 compat_long_t futex_offset;
203 compat_uptr_t list_op_pending;
204};
205
206extern void compat_exit_robust_list(struct task_struct *curr);
207
208asmlinkage long
209compat_sys_set_robust_list(struct compat_robust_list_head __user *head,
210 compat_size_t len);
211asmlinkage long
Al Viroba46df92006-10-10 22:46:07 +0100212compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
Ingo Molnar34f192c2006-03-27 01:16:24 -0800213 compat_size_t __user *len_ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214
215long compat_sys_semctl(int first, int second, int third, void __user *uptr);
216long compat_sys_msgsnd(int first, int second, int third, void __user *uptr);
217long compat_sys_msgrcv(int first, int second, int msgtyp, int third,
218 int version, void __user *uptr);
219long compat_sys_msgctl(int first, int second, void __user *uptr);
220long compat_sys_shmat(int first, int second, compat_uptr_t third, int version,
221 void __user *uptr);
222long compat_sys_shmctl(int first, int second, void __user *uptr);
223long compat_sys_semtimedop(int semid, struct sembuf __user *tsems,
224 unsigned nsems, const struct compat_timespec __user *timeout);
225asmlinkage long compat_sys_keyctl(u32 option,
226 u32 arg2, u32 arg3, u32 arg4, u32 arg5);
Christoph Hellwig2b1c6bd2008-11-28 10:09:09 +0100227asmlinkage long compat_sys_ustat(unsigned dev, struct compat_ustat __user *u32);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228
229asmlinkage ssize_t compat_sys_readv(unsigned long fd,
230 const struct compat_iovec __user *vec, unsigned long vlen);
231asmlinkage ssize_t compat_sys_writev(unsigned long fd,
232 const struct compat_iovec __user *vec, unsigned long vlen);
Gerd Hoffmannf3554f42009-04-02 16:59:23 -0700233asmlinkage ssize_t compat_sys_preadv(unsigned long fd,
234 const struct compat_iovec __user *vec,
Linus Torvalds601cc11d2009-04-03 08:03:22 -0700235 unsigned long vlen, u32 pos_low, u32 pos_high);
Gerd Hoffmannf3554f42009-04-02 16:59:23 -0700236asmlinkage ssize_t compat_sys_pwritev(unsigned long fd,
237 const struct compat_iovec __user *vec,
Linus Torvalds601cc11d2009-04-03 08:03:22 -0700238 unsigned long vlen, u32 pos_low, u32 pos_high);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239
240int compat_do_execve(char * filename, compat_uptr_t __user *argv,
241 compat_uptr_t __user *envp, struct pt_regs * regs);
242
243asmlinkage long compat_sys_select(int n, compat_ulong_t __user *inp,
244 compat_ulong_t __user *outp, compat_ulong_t __user *exp,
245 struct compat_timeval __user *tvp);
246
Thomas Gleixnerc202f292008-01-30 13:30:08 +0100247asmlinkage long compat_sys_wait4(compat_pid_t pid,
Al Viro7d61c452008-03-29 03:09:28 +0000248 compat_uint_t __user *stat_addr, int options,
249 struct compat_rusage __user *ru);
Thomas Gleixnerc202f292008-01-30 13:30:08 +0100250
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251#define BITS_PER_COMPAT_LONG (8*sizeof(compat_long_t))
252
253#define BITS_TO_COMPAT_LONGS(bits) \
254 (((bits)+BITS_PER_COMPAT_LONG-1)/BITS_PER_COMPAT_LONG)
255
Stephen Rothwell5fa38392006-10-28 10:38:46 -0700256long compat_get_bitmap(unsigned long *mask, const compat_ulong_t __user *umask,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 unsigned long bitmap_size);
258long compat_put_bitmap(compat_ulong_t __user *umask, unsigned long *mask,
259 unsigned long bitmap_size);
260int copy_siginfo_from_user32(siginfo_t *to, struct compat_siginfo __user *from);
261int copy_siginfo_to_user32(struct compat_siginfo __user *to, siginfo_t *from);
262int get_compat_sigevent(struct sigevent *event,
263 const struct compat_sigevent __user *u_event);
Thomas Gleixner62ab4502009-04-04 21:01:06 +0000264long compat_sys_rt_tgsigqueueinfo(compat_pid_t tgid, compat_pid_t pid, int sig,
265 struct compat_siginfo __user *uinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266
Andrew Morton643a6542006-02-11 17:55:52 -0800267static inline int compat_timeval_compare(struct compat_timeval *lhs,
268 struct compat_timeval *rhs)
269{
270 if (lhs->tv_sec < rhs->tv_sec)
271 return -1;
272 if (lhs->tv_sec > rhs->tv_sec)
273 return 1;
274 return lhs->tv_usec - rhs->tv_usec;
275}
276
277static inline int compat_timespec_compare(struct compat_timespec *lhs,
278 struct compat_timespec *rhs)
279{
280 if (lhs->tv_sec < rhs->tv_sec)
281 return -1;
282 if (lhs->tv_sec > rhs->tv_sec)
283 return 1;
284 return lhs->tv_nsec - rhs->tv_nsec;
285}
286
Davide Libenzi83f5d122007-05-10 22:23:18 -0700287extern int get_compat_itimerspec(struct itimerspec *dst,
288 const struct compat_itimerspec __user *src);
289extern int put_compat_itimerspec(struct compat_itimerspec __user *dst,
290 const struct itimerspec *src);
291
Christoph Hellwigb418da12008-10-15 22:02:06 -0700292asmlinkage long compat_sys_gettimeofday(struct compat_timeval __user *tv,
293 struct timezone __user *tz);
294asmlinkage long compat_sys_settimeofday(struct compat_timeval __user *tv,
295 struct timezone __user *tz);
296
Stephen Rothwell3158e942006-03-26 01:37:29 -0800297asmlinkage long compat_sys_adjtimex(struct compat_timex __user *utp);
298
Andi Kleenbebfa102006-06-26 13:56:52 +0200299extern int compat_printk(const char *fmt, ...);
Linus Torvalds02354972006-10-02 14:05:20 -0700300extern void sigset_from_compat(sigset_t *set, compat_sigset_t *compat);
Andi Kleenbebfa102006-06-26 13:56:52 +0200301
Stephen Rothwell3fd59392006-11-02 22:07:24 -0800302asmlinkage long compat_sys_migrate_pages(compat_pid_t pid,
303 compat_ulong_t maxnode, const compat_ulong_t __user *old_nodes,
304 const compat_ulong_t __user *new_nodes);
305
Roland McGrath032d82d2008-01-30 13:31:47 +0100306extern int compat_ptrace_request(struct task_struct *child,
307 compat_long_t request,
308 compat_ulong_t addr, compat_ulong_t data);
309
Roland McGrathc269f192008-01-30 13:31:48 +0100310extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
311 compat_ulong_t addr, compat_ulong_t data);
312asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
313 compat_long_t addr, compat_long_t data);
Roland McGrathc269f192008-01-30 13:31:48 +0100314
Davide Libenzif6dfb4f2007-03-07 20:41:21 -0800315/*
316 * epoll (fs/eventpoll.c) compat bits follow ...
317 */
Davide Libenzif6dfb4f2007-03-07 20:41:21 -0800318struct epoll_event;
319#define compat_epoll_event epoll_event
Davide Libenzif6dfb4f2007-03-07 20:41:21 -0800320asmlinkage long compat_sys_epoll_pwait(int epfd,
321 struct compat_epoll_event __user *events,
322 int maxevents, int timeout,
323 const compat_sigset_t __user *sigmask,
324 compat_size_t sigsetsize);
325
Stephen Rothwell97416ce2007-05-09 02:32:35 -0700326asmlinkage long compat_sys_utimensat(unsigned int dfd, char __user *filename,
327 struct compat_timespec __user *t, int flags);
328
Stephen Rothwell140ff8b2007-05-14 13:47:47 +1000329asmlinkage long compat_sys_signalfd(int ufd,
330 const compat_sigset_t __user *sigmask,
331 compat_size_t sigsetsize);
Davide Libenzi4d672e72008-02-04 22:27:26 -0800332asmlinkage long compat_sys_timerfd_settime(int ufd, int flags,
333 const struct compat_itimerspec __user *utmr,
334 struct compat_itimerspec __user *otmr);
335asmlinkage long compat_sys_timerfd_gettime(int ufd,
336 struct compat_itimerspec __user *otmr);
Stephen Rothwell140ff8b2007-05-14 13:47:47 +1000337
Heiko Carstens4c696ba2009-01-14 14:13:53 +0100338asmlinkage long compat_sys_move_pages(pid_t pid, unsigned long nr_page,
339 __u32 __user *pages,
340 const int __user *nodes,
341 int __user *status,
342 int flags);
343asmlinkage long compat_sys_futimesat(unsigned int dfd, char __user *filename,
344 struct compat_timeval __user *t);
345asmlinkage long compat_sys_newfstatat(unsigned int dfd, char __user * filename,
346 struct compat_stat __user *statbuf,
347 int flag);
348asmlinkage long compat_sys_openat(unsigned int dfd, const char __user *filename,
349 int flags, int mode);
350
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351#endif /* CONFIG_COMPAT */
352#endif /* _LINUX_COMPAT_H */