Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | |
| 8 | #ifdef CONFIG_COMPAT |
| 9 | |
| 10 | #include <linux/stat.h> |
| 11 | #include <linux/param.h> /* for HZ */ |
| 12 | #include <linux/sem.h> |
Arnd Bergmann | 2dceba1 | 2009-11-06 08:09:03 +0000 | [diff] [blame] | 13 | #include <linux/socket.h> |
| 14 | #include <linux/if.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | |
| 16 | #include <asm/compat.h> |
| 17 | #include <asm/siginfo.h> |
David Howells | 3f2e05e | 2006-10-02 14:12:31 +0100 | [diff] [blame] | 18 | #include <asm/signal.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | |
| 20 | #define compat_jiffies_to_clock_t(x) \ |
| 21 | (((unsigned long)(x) * COMPAT_USER_HZ) / HZ) |
| 22 | |
Stephen Rothwell | 202e597 | 2005-09-06 15:16:40 -0700 | [diff] [blame] | 23 | typedef __compat_uid32_t compat_uid_t; |
| 24 | typedef __compat_gid32_t compat_gid_t; |
| 25 | |
Christoph Hellwig | 5d0e528 | 2010-03-10 15:21:13 -0800 | [diff] [blame^] | 26 | struct compat_sel_arg_struct; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | struct rusage; |
| 28 | |
| 29 | struct compat_itimerspec { |
| 30 | struct compat_timespec it_interval; |
| 31 | struct compat_timespec it_value; |
| 32 | }; |
| 33 | |
| 34 | struct compat_utimbuf { |
| 35 | compat_time_t actime; |
| 36 | compat_time_t modtime; |
| 37 | }; |
| 38 | |
| 39 | struct compat_itimerval { |
| 40 | struct compat_timeval it_interval; |
| 41 | struct compat_timeval it_value; |
| 42 | }; |
| 43 | |
| 44 | struct 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 Rothwell | 88959ea | 2006-03-26 01:37:27 -0800 | [diff] [blame] | 51 | struct 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 Zippel | 153b5d0 | 2008-05-01 04:34:37 -0700 | [diff] [blame] | 71 | compat_int_t tai; |
Stephen Rothwell | 88959ea | 2006-03-26 01:37:27 -0800 | [diff] [blame] | 72 | |
| 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 Zippel | 153b5d0 | 2008-05-01 04:34:37 -0700 | [diff] [blame] | 75 | compat_int_t :32; compat_int_t :32; compat_int_t :32; |
Stephen Rothwell | 88959ea | 2006-03-26 01:37:27 -0800 | [diff] [blame] | 76 | }; |
| 77 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | #define _COMPAT_NSIG_WORDS (_COMPAT_NSIG / _COMPAT_NSIG_BPW) |
| 79 | |
| 80 | typedef struct { |
| 81 | compat_sigset_word sig[_COMPAT_NSIG_WORDS]; |
| 82 | } compat_sigset_t; |
| 83 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | extern int get_compat_timespec(struct timespec *, const struct compat_timespec __user *); |
| 85 | extern int put_compat_timespec(const struct timespec *, struct compat_timespec __user *); |
| 86 | |
| 87 | struct compat_iovec { |
| 88 | compat_uptr_t iov_base; |
| 89 | compat_size_t iov_len; |
| 90 | }; |
| 91 | |
| 92 | struct compat_rlimit { |
| 93 | compat_ulong_t rlim_cur; |
| 94 | compat_ulong_t rlim_max; |
| 95 | }; |
| 96 | |
| 97 | struct 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 | |
| 116 | extern int put_compat_rusage(const struct rusage *, struct compat_rusage __user *); |
| 117 | |
| 118 | struct compat_siginfo; |
| 119 | |
| 120 | extern asmlinkage long compat_sys_waitid(int, compat_pid_t, |
| 121 | struct compat_siginfo __user *, int, |
| 122 | struct compat_rusage __user *); |
| 123 | |
| 124 | struct compat_dirent { |
| 125 | u32 d_ino; |
| 126 | compat_off_t d_off; |
| 127 | u16 d_reclen; |
| 128 | char d_name[256]; |
| 129 | }; |
| 130 | |
Christoph Hellwig | 2b1c6bd | 2008-11-28 10:09:09 +0100 | [diff] [blame] | 131 | struct 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | typedef 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 | |
| 145 | typedef 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 Bergmann | 2dceba1 | 2009-11-06 08:09:03 +0000 | [diff] [blame] | 160 | struct 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 Bergmann | 7a50a24 | 2009-11-08 20:57:03 -0800 | [diff] [blame] | 169 | struct 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 Bergmann | 2dceba1 | 2009-11-06 08:09:03 +0000 | [diff] [blame] | 176 | struct compat_ifreq { |
Arnd Bergmann | 7a50a24 | 2009-11-08 20:57:03 -0800 | [diff] [blame] | 177 | 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 Bergmann | 2dceba1 | 2009-11-06 08:09:03 +0000 | [diff] [blame] | 191 | char ifru_newname[IFNAMSIZ]; |
Arnd Bergmann | 7a50a24 | 2009-11-08 20:57:03 -0800 | [diff] [blame] | 192 | compat_caddr_t ifru_data; |
| 193 | struct compat_if_settings ifru_settings; |
| 194 | } ifr_ifru; |
Arnd Bergmann | 2dceba1 | 2009-11-06 08:09:03 +0000 | [diff] [blame] | 195 | }; |
| 196 | |
| 197 | struct compat_ifconf { |
| 198 | compat_int_t ifc_len; /* size of buffer */ |
| 199 | compat_caddr_t ifcbuf; |
| 200 | }; |
| 201 | |
Ingo Molnar | 34f192c | 2006-03-27 01:16:24 -0800 | [diff] [blame] | 202 | struct compat_robust_list { |
| 203 | compat_uptr_t next; |
| 204 | }; |
| 205 | |
| 206 | struct 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 | |
| 212 | extern void compat_exit_robust_list(struct task_struct *curr); |
| 213 | |
| 214 | asmlinkage long |
| 215 | compat_sys_set_robust_list(struct compat_robust_list_head __user *head, |
| 216 | compat_size_t len); |
| 217 | asmlinkage long |
Al Viro | ba46df9 | 2006-10-10 22:46:07 +0100 | [diff] [blame] | 218 | compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr, |
Ingo Molnar | 34f192c | 2006-03-27 01:16:24 -0800 | [diff] [blame] | 219 | compat_size_t __user *len_ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | |
| 221 | long compat_sys_semctl(int first, int second, int third, void __user *uptr); |
| 222 | long compat_sys_msgsnd(int first, int second, int third, void __user *uptr); |
| 223 | long compat_sys_msgrcv(int first, int second, int msgtyp, int third, |
| 224 | int version, void __user *uptr); |
| 225 | long compat_sys_msgctl(int first, int second, void __user *uptr); |
| 226 | long compat_sys_shmat(int first, int second, compat_uptr_t third, int version, |
| 227 | void __user *uptr); |
| 228 | long compat_sys_shmctl(int first, int second, void __user *uptr); |
| 229 | long compat_sys_semtimedop(int semid, struct sembuf __user *tsems, |
| 230 | unsigned nsems, const struct compat_timespec __user *timeout); |
| 231 | asmlinkage long compat_sys_keyctl(u32 option, |
| 232 | u32 arg2, u32 arg3, u32 arg4, u32 arg5); |
Christoph Hellwig | 2b1c6bd | 2008-11-28 10:09:09 +0100 | [diff] [blame] | 233 | asmlinkage long compat_sys_ustat(unsigned dev, struct compat_ustat __user *u32); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | |
| 235 | asmlinkage ssize_t compat_sys_readv(unsigned long fd, |
| 236 | const struct compat_iovec __user *vec, unsigned long vlen); |
| 237 | asmlinkage ssize_t compat_sys_writev(unsigned long fd, |
| 238 | const struct compat_iovec __user *vec, unsigned long vlen); |
Gerd Hoffmann | f3554f4 | 2009-04-02 16:59:23 -0700 | [diff] [blame] | 239 | asmlinkage ssize_t compat_sys_preadv(unsigned long fd, |
| 240 | const struct compat_iovec __user *vec, |
Linus Torvalds | 601cc11 | 2009-04-03 08:03:22 -0700 | [diff] [blame] | 241 | unsigned long vlen, u32 pos_low, u32 pos_high); |
Gerd Hoffmann | f3554f4 | 2009-04-02 16:59:23 -0700 | [diff] [blame] | 242 | asmlinkage ssize_t compat_sys_pwritev(unsigned long fd, |
| 243 | const struct compat_iovec __user *vec, |
Linus Torvalds | 601cc11 | 2009-04-03 08:03:22 -0700 | [diff] [blame] | 244 | unsigned long vlen, u32 pos_low, u32 pos_high); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | |
| 246 | int compat_do_execve(char * filename, compat_uptr_t __user *argv, |
| 247 | compat_uptr_t __user *envp, struct pt_regs * regs); |
| 248 | |
| 249 | asmlinkage 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 Hellwig | 5d0e528 | 2010-03-10 15:21:13 -0800 | [diff] [blame^] | 253 | asmlinkage long compat_sys_old_select(struct compat_sel_arg_struct __user *arg); |
| 254 | |
Thomas Gleixner | c202f29 | 2008-01-30 13:30:08 +0100 | [diff] [blame] | 255 | asmlinkage long compat_sys_wait4(compat_pid_t pid, |
Al Viro | 7d61c45 | 2008-03-29 03:09:28 +0000 | [diff] [blame] | 256 | compat_uint_t __user *stat_addr, int options, |
| 257 | struct compat_rusage __user *ru); |
Thomas Gleixner | c202f29 | 2008-01-30 13:30:08 +0100 | [diff] [blame] | 258 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | #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 Rothwell | 5fa3839 | 2006-10-28 10:38:46 -0700 | [diff] [blame] | 264 | long compat_get_bitmap(unsigned long *mask, const compat_ulong_t __user *umask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | unsigned long bitmap_size); |
| 266 | long compat_put_bitmap(compat_ulong_t __user *umask, unsigned long *mask, |
| 267 | unsigned long bitmap_size); |
| 268 | int copy_siginfo_from_user32(siginfo_t *to, struct compat_siginfo __user *from); |
| 269 | int copy_siginfo_to_user32(struct compat_siginfo __user *to, siginfo_t *from); |
| 270 | int get_compat_sigevent(struct sigevent *event, |
| 271 | const struct compat_sigevent __user *u_event); |
Thomas Gleixner | 62ab450 | 2009-04-04 21:01:06 +0000 | [diff] [blame] | 272 | long compat_sys_rt_tgsigqueueinfo(compat_pid_t tgid, compat_pid_t pid, int sig, |
| 273 | struct compat_siginfo __user *uinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | |
Andrew Morton | 643a654 | 2006-02-11 17:55:52 -0800 | [diff] [blame] | 275 | static 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 | |
| 285 | static 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 Libenzi | 83f5d12 | 2007-05-10 22:23:18 -0700 | [diff] [blame] | 295 | extern int get_compat_itimerspec(struct itimerspec *dst, |
| 296 | const struct compat_itimerspec __user *src); |
| 297 | extern int put_compat_itimerspec(struct compat_itimerspec __user *dst, |
| 298 | const struct itimerspec *src); |
| 299 | |
Christoph Hellwig | b418da1 | 2008-10-15 22:02:06 -0700 | [diff] [blame] | 300 | asmlinkage long compat_sys_gettimeofday(struct compat_timeval __user *tv, |
| 301 | struct timezone __user *tz); |
| 302 | asmlinkage long compat_sys_settimeofday(struct compat_timeval __user *tv, |
| 303 | struct timezone __user *tz); |
| 304 | |
Stephen Rothwell | 3158e94 | 2006-03-26 01:37:29 -0800 | [diff] [blame] | 305 | asmlinkage long compat_sys_adjtimex(struct compat_timex __user *utp); |
| 306 | |
Andi Kleen | bebfa10 | 2006-06-26 13:56:52 +0200 | [diff] [blame] | 307 | extern int compat_printk(const char *fmt, ...); |
Linus Torvalds | 0235497 | 2006-10-02 14:05:20 -0700 | [diff] [blame] | 308 | extern void sigset_from_compat(sigset_t *set, compat_sigset_t *compat); |
Andi Kleen | bebfa10 | 2006-06-26 13:56:52 +0200 | [diff] [blame] | 309 | |
Stephen Rothwell | 3fd5939 | 2006-11-02 22:07:24 -0800 | [diff] [blame] | 310 | asmlinkage 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 McGrath | 032d82d | 2008-01-30 13:31:47 +0100 | [diff] [blame] | 314 | extern int compat_ptrace_request(struct task_struct *child, |
| 315 | compat_long_t request, |
| 316 | compat_ulong_t addr, compat_ulong_t data); |
| 317 | |
Roland McGrath | c269f19 | 2008-01-30 13:31:48 +0100 | [diff] [blame] | 318 | extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request, |
| 319 | compat_ulong_t addr, compat_ulong_t data); |
| 320 | asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid, |
| 321 | compat_long_t addr, compat_long_t data); |
Roland McGrath | c269f19 | 2008-01-30 13:31:48 +0100 | [diff] [blame] | 322 | |
Davide Libenzi | f6dfb4f | 2007-03-07 20:41:21 -0800 | [diff] [blame] | 323 | /* |
| 324 | * epoll (fs/eventpoll.c) compat bits follow ... |
| 325 | */ |
Davide Libenzi | f6dfb4f | 2007-03-07 20:41:21 -0800 | [diff] [blame] | 326 | struct epoll_event; |
| 327 | #define compat_epoll_event epoll_event |
Davide Libenzi | f6dfb4f | 2007-03-07 20:41:21 -0800 | [diff] [blame] | 328 | asmlinkage 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 Rothwell | 97416ce | 2007-05-09 02:32:35 -0700 | [diff] [blame] | 334 | asmlinkage long compat_sys_utimensat(unsigned int dfd, char __user *filename, |
| 335 | struct compat_timespec __user *t, int flags); |
| 336 | |
Stephen Rothwell | 140ff8b | 2007-05-14 13:47:47 +1000 | [diff] [blame] | 337 | asmlinkage long compat_sys_signalfd(int ufd, |
| 338 | const compat_sigset_t __user *sigmask, |
| 339 | compat_size_t sigsetsize); |
Davide Libenzi | 4d672e7 | 2008-02-04 22:27:26 -0800 | [diff] [blame] | 340 | asmlinkage long compat_sys_timerfd_settime(int ufd, int flags, |
| 341 | const struct compat_itimerspec __user *utmr, |
| 342 | struct compat_itimerspec __user *otmr); |
| 343 | asmlinkage long compat_sys_timerfd_gettime(int ufd, |
| 344 | struct compat_itimerspec __user *otmr); |
Stephen Rothwell | 140ff8b | 2007-05-14 13:47:47 +1000 | [diff] [blame] | 345 | |
Heiko Carstens | 4c696ba | 2009-01-14 14:13:53 +0100 | [diff] [blame] | 346 | asmlinkage 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); |
| 351 | asmlinkage long compat_sys_futimesat(unsigned int dfd, char __user *filename, |
| 352 | struct compat_timeval __user *t); |
| 353 | asmlinkage long compat_sys_newfstatat(unsigned int dfd, char __user * filename, |
| 354 | struct compat_stat __user *statbuf, |
| 355 | int flag); |
| 356 | asmlinkage long compat_sys_openat(unsigned int dfd, const char __user *filename, |
| 357 | int flags, int mode); |
| 358 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | #endif /* CONFIG_COMPAT */ |
| 360 | #endif /* _LINUX_COMPAT_H */ |