2 * arch/arm/kernel/sys_oabi-compat.c
4 * Compatibility wrappers for syscalls that are used from
5 * old ABI user space binaries with an EABI kernel.
7 * Author: Nicolas Pitre
9 * Copyright: MontaVista Software, Inc.
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
17 * The legacy ABI and the new ARM EABI have different rules making some
18 * syscalls incompatible especially with structure arguments.
19 * Most notably, Eabi says 64-bit members should be 64-bit aligned instead of
20 * simply word aligned. EABI also pads structures to the size of the largest
21 * member it contains instead of the invariant 32-bit.
23 * The following syscalls are affected:
29 * struct stat64 has different sizes and some members are shifted
30 * Compatibility wrappers are needed for them and provided below.
34 * struct flock64 has different sizes and some members are shifted
35 * A compatibility wrapper is needed and provided below.
40 * struct statfs64 has extra padding with EABI growing its size from
41 * 84 to 88. This struct is now __attribute__((packed,aligned(4)))
42 * with a small assembly wrapper to force the sz argument to 84 if it is 88
43 * to avoid copying the extra padding over user space unexpecting it.
47 * struct new_utsname has no padding with EABI. No problem there.
52 * struct epoll_event has its second member shifted also affecting the
53 * structure size. Compatibility wrappers are needed and provided below.
59 * struct sembuf loses its padding with EABI. Since arrays of them are
60 * used they have to be copyed to remove the padding. Compatibility wrappers
64 #include <linux/syscalls.h>
65 #include <linux/errno.h>
67 #include <linux/fcntl.h>
68 #include <linux/eventpoll.h>
69 #include <linux/sem.h>
71 #include <asm/uaccess.h>
73 struct oldabi_stat64 {
74 unsigned long long st_dev;
76 unsigned long __st_ino;
78 unsigned int st_nlink;
83 unsigned long long st_rdev;
87 unsigned long st_blksize;
88 unsigned long long st_blocks;
90 unsigned long st_atime;
91 unsigned long st_atime_nsec;
93 unsigned long st_mtime;
94 unsigned long st_mtime_nsec;
96 unsigned long st_ctime;
97 unsigned long st_ctime_nsec;
99 unsigned long long st_ino;
100 } __attribute__ ((packed,aligned(4)));
102 static long cp_oldabi_stat64(struct kstat *stat,
103 struct oldabi_stat64 __user *statbuf)
105 struct oldabi_stat64 tmp;
107 tmp.st_dev = huge_encode_dev(stat->dev);
109 tmp.__st_ino = stat->ino;
110 tmp.st_mode = stat->mode;
111 tmp.st_nlink = stat->nlink;
112 tmp.st_uid = stat->uid;
113 tmp.st_gid = stat->gid;
114 tmp.st_rdev = huge_encode_dev(stat->rdev);
115 tmp.st_size = stat->size;
116 tmp.st_blocks = stat->blocks;
118 tmp.st_blksize = stat->blksize;
119 tmp.st_atime = stat->atime.tv_sec;
120 tmp.st_atime_nsec = stat->atime.tv_nsec;
121 tmp.st_mtime = stat->mtime.tv_sec;
122 tmp.st_mtime_nsec = stat->mtime.tv_nsec;
123 tmp.st_ctime = stat->ctime.tv_sec;
124 tmp.st_ctime_nsec = stat->ctime.tv_nsec;
125 tmp.st_ino = stat->ino;
126 return copy_to_user(statbuf,&tmp,sizeof(tmp)) ? -EFAULT : 0;
129 asmlinkage long sys_oabi_stat64(char __user * filename,
130 struct oldabi_stat64 __user * statbuf)
133 int error = vfs_stat(filename, &stat);
135 error = cp_oldabi_stat64(&stat, statbuf);
139 asmlinkage long sys_oabi_lstat64(char __user * filename,
140 struct oldabi_stat64 __user * statbuf)
143 int error = vfs_lstat(filename, &stat);
145 error = cp_oldabi_stat64(&stat, statbuf);
149 asmlinkage long sys_oabi_fstat64(unsigned long fd,
150 struct oldabi_stat64 __user * statbuf)
153 int error = vfs_fstat(fd, &stat);
155 error = cp_oldabi_stat64(&stat, statbuf);
159 struct oabi_flock64 {
165 } __attribute__ ((packed,aligned(4)));
167 asmlinkage long sys_oabi_fcntl64(unsigned int fd, unsigned int cmd,
170 struct oabi_flock64 user;
171 struct flock64 kernel;
172 mm_segment_t fs = USER_DS; /* initialized to kill a warning */
173 unsigned long local_arg = arg;
180 if (copy_from_user(&user, (struct oabi_flock64 __user *)arg,
183 kernel.l_type = user.l_type;
184 kernel.l_whence = user.l_whence;
185 kernel.l_start = user.l_start;
186 kernel.l_len = user.l_len;
187 kernel.l_pid = user.l_pid;
188 local_arg = (unsigned long)&kernel;
193 ret = sys_fcntl64(fd, cmd, local_arg);
198 user.l_type = kernel.l_type;
199 user.l_whence = kernel.l_whence;
200 user.l_start = kernel.l_start;
201 user.l_len = kernel.l_len;
202 user.l_pid = kernel.l_pid;
203 if (copy_to_user((struct oabi_flock64 __user *)arg,
204 &user, sizeof(user)))
215 struct oabi_epoll_event {
218 } __attribute__ ((packed,aligned(4)));
220 asmlinkage long sys_oabi_epoll_ctl(int epfd, int op, int fd,
221 struct oabi_epoll_event __user *event)
223 struct oabi_epoll_event user;
224 struct epoll_event kernel;
228 if (op == EPOLL_CTL_DEL)
229 return sys_epoll_ctl(epfd, op, fd, NULL);
230 if (copy_from_user(&user, event, sizeof(user)))
232 kernel.events = user.events;
233 kernel.data = user.data;
236 ret = sys_epoll_ctl(epfd, op, fd, &kernel);
241 asmlinkage long sys_oabi_epoll_wait(int epfd,
242 struct oabi_epoll_event __user *events,
243 int maxevents, int timeout)
245 struct epoll_event *kbuf;
249 if (maxevents <= 0 || maxevents > (INT_MAX/sizeof(struct epoll_event)))
251 kbuf = kmalloc(sizeof(*kbuf) * maxevents, GFP_KERNEL);
256 ret = sys_epoll_wait(epfd, kbuf, maxevents, timeout);
259 for (i = 0; i < ret; i++) {
260 __put_user_error(kbuf[i].events, &events->events, err);
261 __put_user_error(kbuf[i].data, &events->data, err);
265 return err ? -EFAULT : ret;
269 unsigned short sem_num;
272 unsigned short __pad;
275 asmlinkage long sys_oabi_semtimedop(int semid,
276 struct oabi_sembuf __user *tsops,
278 const struct timespec __user *timeout)
281 struct timespec local_timeout;
287 sops = kmalloc(sizeof(*sops) * nsops, GFP_KERNEL);
291 for (i = 0; i < nsops; i++) {
292 __get_user_error(sops[i].sem_num, &tsops->sem_num, err);
293 __get_user_error(sops[i].sem_op, &tsops->sem_op, err);
294 __get_user_error(sops[i].sem_flg, &tsops->sem_flg, err);
298 /* copy this as well before changing domain protection */
299 err |= copy_from_user(&local_timeout, timeout, sizeof(*timeout));
300 timeout = &local_timeout;
305 mm_segment_t fs = get_fs();
307 err = sys_semtimedop(semid, sops, nsops, timeout);
314 asmlinkage long sys_oabi_semop(int semid, struct oabi_sembuf __user *tsops,
317 return sys_oabi_semtimedop(semid, tsops, nsops, NULL);
320 extern asmlinkage int sys_ipc(uint call, int first, int second, int third,
321 void __user *ptr, long fifth);
323 asmlinkage int sys_oabi_ipc(uint call, int first, int second, int third,
324 void __user *ptr, long fifth)
326 switch (call & 0xffff) {
328 return sys_oabi_semtimedop(first,
329 (struct oabi_sembuf __user *)ptr,
332 return sys_oabi_semtimedop(first,
333 (struct oabi_sembuf __user *)ptr,
335 (const struct timespec __user *)fifth);
337 return sys_ipc(call, first, second, third, ptr, fifth);