blob: 78caff926737b532fc3216a8b5312d2be97375df [file] [log] [blame]
David S. Millerbc5a2e62007-07-18 14:28:59 -07001/* sys_sparc32.c: Conversion between 32bit and 64bit native syscalls.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 *
3 * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
David S. Millerbc5a2e62007-07-18 14:28:59 -07004 * Copyright (C) 1997, 2007 David S. Miller (davem@davemloft.net)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 *
6 * These routines maintain argument size conversion between 32bit and 64bit
7 * environment.
8 */
9
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#include <linux/kernel.h>
11#include <linux/sched.h>
Randy Dunlapa9415642006-01-11 12:17:48 -080012#include <linux/capability.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <linux/fs.h>
14#include <linux/mm.h>
15#include <linux/file.h>
16#include <linux/signal.h>
17#include <linux/resource.h>
18#include <linux/times.h>
19#include <linux/utsname.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <linux/smp.h>
21#include <linux/smp_lock.h>
22#include <linux/sem.h>
23#include <linux/msg.h>
24#include <linux/shm.h>
25#include <linux/slab.h>
26#include <linux/uio.h>
27#include <linux/nfs_fs.h>
28#include <linux/quota.h>
29#include <linux/module.h>
30#include <linux/sunrpc/svc.h>
31#include <linux/nfsd/nfsd.h>
32#include <linux/nfsd/cache.h>
33#include <linux/nfsd/xdr.h>
34#include <linux/nfsd/syscall.h>
35#include <linux/poll.h>
36#include <linux/personality.h>
37#include <linux/stat.h>
38#include <linux/filter.h>
39#include <linux/highmem.h>
40#include <linux/highuid.h>
41#include <linux/mman.h>
42#include <linux/ipv6.h>
43#include <linux/in.h>
44#include <linux/icmpv6.h>
45#include <linux/syscalls.h>
46#include <linux/sysctl.h>
47#include <linux/binfmts.h>
48#include <linux/dnotify.h>
49#include <linux/security.h>
50#include <linux/compat.h>
51#include <linux/vfs.h>
52#include <linux/netfilter_ipv4/ip_tables.h>
53#include <linux/ptrace.h>
54#include <linux/highuid.h>
55
56#include <asm/types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070057#include <asm/uaccess.h>
58#include <asm/fpumacro.h>
59#include <asm/semaphore.h>
60#include <asm/mmu_context.h>
David S. Millerd61e16d2006-03-17 17:33:56 -080061#include <asm/a.out.h>
David S. Miller14cc6ab2006-10-02 14:17:57 -070062#include <asm/compat_signal.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
64asmlinkage long sys32_chown16(const char __user * filename, u16 user, u16 group)
65{
66 return sys_chown(filename, low2highuid(user), low2highgid(group));
67}
68
69asmlinkage long sys32_lchown16(const char __user * filename, u16 user, u16 group)
70{
71 return sys_lchown(filename, low2highuid(user), low2highgid(group));
72}
73
74asmlinkage long sys32_fchown16(unsigned int fd, u16 user, u16 group)
75{
76 return sys_fchown(fd, low2highuid(user), low2highgid(group));
77}
78
79asmlinkage long sys32_setregid16(u16 rgid, u16 egid)
80{
81 return sys_setregid(low2highgid(rgid), low2highgid(egid));
82}
83
84asmlinkage long sys32_setgid16(u16 gid)
85{
86 return sys_setgid((gid_t)gid);
87}
88
89asmlinkage long sys32_setreuid16(u16 ruid, u16 euid)
90{
91 return sys_setreuid(low2highuid(ruid), low2highuid(euid));
92}
93
94asmlinkage long sys32_setuid16(u16 uid)
95{
96 return sys_setuid((uid_t)uid);
97}
98
99asmlinkage long sys32_setresuid16(u16 ruid, u16 euid, u16 suid)
100{
101 return sys_setresuid(low2highuid(ruid), low2highuid(euid),
102 low2highuid(suid));
103}
104
105asmlinkage long sys32_getresuid16(u16 __user *ruid, u16 __user *euid, u16 __user *suid)
106{
107 int retval;
108
109 if (!(retval = put_user(high2lowuid(current->uid), ruid)) &&
110 !(retval = put_user(high2lowuid(current->euid), euid)))
111 retval = put_user(high2lowuid(current->suid), suid);
112
113 return retval;
114}
115
116asmlinkage long sys32_setresgid16(u16 rgid, u16 egid, u16 sgid)
117{
118 return sys_setresgid(low2highgid(rgid), low2highgid(egid),
119 low2highgid(sgid));
120}
121
122asmlinkage long sys32_getresgid16(u16 __user *rgid, u16 __user *egid, u16 __user *sgid)
123{
124 int retval;
125
126 if (!(retval = put_user(high2lowgid(current->gid), rgid)) &&
127 !(retval = put_user(high2lowgid(current->egid), egid)))
128 retval = put_user(high2lowgid(current->sgid), sgid);
129
130 return retval;
131}
132
133asmlinkage long sys32_setfsuid16(u16 uid)
134{
135 return sys_setfsuid((uid_t)uid);
136}
137
138asmlinkage long sys32_setfsgid16(u16 gid)
139{
140 return sys_setfsgid((gid_t)gid);
141}
142
143static int groups16_to_user(u16 __user *grouplist, struct group_info *group_info)
144{
145 int i;
146 u16 group;
147
148 for (i = 0; i < group_info->ngroups; i++) {
149 group = (u16)GROUP_AT(group_info, i);
150 if (put_user(group, grouplist+i))
151 return -EFAULT;
152 }
153
154 return 0;
155}
156
157static int groups16_from_user(struct group_info *group_info, u16 __user *grouplist)
158{
159 int i;
160 u16 group;
161
162 for (i = 0; i < group_info->ngroups; i++) {
163 if (get_user(group, grouplist+i))
164 return -EFAULT;
165 GROUP_AT(group_info, i) = (gid_t)group;
166 }
167
168 return 0;
169}
170
171asmlinkage long sys32_getgroups16(int gidsetsize, u16 __user *grouplist)
172{
173 int i;
174
175 if (gidsetsize < 0)
176 return -EINVAL;
177
178 get_group_info(current->group_info);
179 i = current->group_info->ngroups;
180 if (gidsetsize) {
181 if (i > gidsetsize) {
182 i = -EINVAL;
183 goto out;
184 }
185 if (groups16_to_user(grouplist, current->group_info)) {
186 i = -EFAULT;
187 goto out;
188 }
189 }
190out:
191 put_group_info(current->group_info);
192 return i;
193}
194
195asmlinkage long sys32_setgroups16(int gidsetsize, u16 __user *grouplist)
196{
197 struct group_info *group_info;
198 int retval;
199
200 if (!capable(CAP_SETGID))
201 return -EPERM;
202 if ((unsigned)gidsetsize > NGROUPS_MAX)
203 return -EINVAL;
204
205 group_info = groups_alloc(gidsetsize);
206 if (!group_info)
207 return -ENOMEM;
208 retval = groups16_from_user(group_info, grouplist);
209 if (retval) {
210 put_group_info(group_info);
211 return retval;
212 }
213
214 retval = set_current_groups(group_info);
215 put_group_info(group_info);
216
217 return retval;
218}
219
220asmlinkage long sys32_getuid16(void)
221{
222 return high2lowuid(current->uid);
223}
224
225asmlinkage long sys32_geteuid16(void)
226{
227 return high2lowuid(current->euid);
228}
229
230asmlinkage long sys32_getgid16(void)
231{
232 return high2lowgid(current->gid);
233}
234
235asmlinkage long sys32_getegid16(void)
236{
237 return high2lowgid(current->egid);
238}
239
240/* 32-bit timeval and related flotsam. */
241
242static long get_tv32(struct timeval *o, struct compat_timeval __user *i)
243{
244 return (!access_ok(VERIFY_READ, i, sizeof(*i)) ||
245 (__get_user(o->tv_sec, &i->tv_sec) |
246 __get_user(o->tv_usec, &i->tv_usec)));
247}
248
249static inline long put_tv32(struct compat_timeval __user *o, struct timeval *i)
250{
251 return (!access_ok(VERIFY_WRITE, o, sizeof(*o)) ||
252 (__put_user(i->tv_sec, &o->tv_sec) |
253 __put_user(i->tv_usec, &o->tv_usec)));
254}
255
256#ifdef CONFIG_SYSVIPC
257asmlinkage long compat_sys_ipc(u32 call, u32 first, u32 second, u32 third, compat_uptr_t ptr, u32 fifth)
258{
259 int version;
260
261 version = call >> 16; /* hack for backward compatibility */
262 call &= 0xffff;
263
264 switch (call) {
265 case SEMTIMEDOP:
266 if (fifth)
267 /* sign extend semid */
268 return compat_sys_semtimedop((int)first,
269 compat_ptr(ptr), second,
270 compat_ptr(fifth));
271 /* else fall through for normal semop() */
272 case SEMOP:
273 /* struct sembuf is the same on 32 and 64bit :)) */
274 /* sign extend semid */
275 return sys_semtimedop((int)first, compat_ptr(ptr), second,
276 NULL);
277 case SEMGET:
278 /* sign extend key, nsems */
279 return sys_semget((int)first, (int)second, third);
280 case SEMCTL:
281 /* sign extend semid, semnum */
282 return compat_sys_semctl((int)first, (int)second, third,
283 compat_ptr(ptr));
284
285 case MSGSND:
286 /* sign extend msqid */
287 return compat_sys_msgsnd((int)first, (int)second, third,
288 compat_ptr(ptr));
289 case MSGRCV:
290 /* sign extend msqid, msgtyp */
291 return compat_sys_msgrcv((int)first, second, (int)fifth,
292 third, version, compat_ptr(ptr));
293 case MSGGET:
294 /* sign extend key */
295 return sys_msgget((int)first, second);
296 case MSGCTL:
297 /* sign extend msqid */
298 return compat_sys_msgctl((int)first, second, compat_ptr(ptr));
299
300 case SHMAT:
301 /* sign extend shmid */
302 return compat_sys_shmat((int)first, second, third, version,
303 compat_ptr(ptr));
304 case SHMDT:
305 return sys_shmdt(compat_ptr(ptr));
306 case SHMGET:
307 /* sign extend key_t */
308 return sys_shmget((int)first, second, third);
309 case SHMCTL:
310 /* sign extend shmid */
311 return compat_sys_shmctl((int)first, second, compat_ptr(ptr));
312
313 default:
314 return -ENOSYS;
315 };
316
317 return -ENOSYS;
318}
319#endif
320
321asmlinkage long sys32_truncate64(const char __user * path, unsigned long high, unsigned long low)
322{
323 if ((int)high < 0)
324 return -EINVAL;
325 else
326 return sys_truncate(path, (high << 32) | low);
327}
328
329asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long high, unsigned long low)
330{
331 if ((int)high < 0)
332 return -EINVAL;
333 else
334 return sys_ftruncate(fd, (high << 32) | low);
335}
336
337int cp_compat_stat(struct kstat *stat, struct compat_stat __user *statbuf)
338{
David Howellsafefdbb2006-10-03 01:13:46 -0700339 compat_ino_t ino;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 int err;
341
342 if (stat->size > MAX_NON_LFS || !old_valid_dev(stat->dev) ||
343 !old_valid_dev(stat->rdev))
344 return -EOVERFLOW;
345
David Howellsafefdbb2006-10-03 01:13:46 -0700346 ino = stat->ino;
347 if (sizeof(ino) < sizeof(stat->ino) && ino != stat->ino)
348 return -EOVERFLOW;
349
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 err = put_user(old_encode_dev(stat->dev), &statbuf->st_dev);
351 err |= put_user(stat->ino, &statbuf->st_ino);
352 err |= put_user(stat->mode, &statbuf->st_mode);
353 err |= put_user(stat->nlink, &statbuf->st_nlink);
354 err |= put_user(high2lowuid(stat->uid), &statbuf->st_uid);
355 err |= put_user(high2lowgid(stat->gid), &statbuf->st_gid);
356 err |= put_user(old_encode_dev(stat->rdev), &statbuf->st_rdev);
357 err |= put_user(stat->size, &statbuf->st_size);
358 err |= put_user(stat->atime.tv_sec, &statbuf->st_atime);
David S. Miller0ba4da02005-04-18 15:13:15 -0700359 err |= put_user(stat->atime.tv_nsec, &statbuf->st_atime_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 err |= put_user(stat->mtime.tv_sec, &statbuf->st_mtime);
David S. Miller0ba4da02005-04-18 15:13:15 -0700361 err |= put_user(stat->mtime.tv_nsec, &statbuf->st_mtime_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 err |= put_user(stat->ctime.tv_sec, &statbuf->st_ctime);
David S. Miller0ba4da02005-04-18 15:13:15 -0700363 err |= put_user(stat->ctime.tv_nsec, &statbuf->st_ctime_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 err |= put_user(stat->blksize, &statbuf->st_blksize);
365 err |= put_user(stat->blocks, &statbuf->st_blocks);
366 err |= put_user(0, &statbuf->__unused4[0]);
367 err |= put_user(0, &statbuf->__unused4[1]);
368
369 return err;
370}
371
David S. Miller0ba4da02005-04-18 15:13:15 -0700372int cp_compat_stat64(struct kstat *stat, struct compat_stat64 __user *statbuf)
373{
374 int err;
375
376 err = put_user(huge_encode_dev(stat->dev), &statbuf->st_dev);
377 err |= put_user(stat->ino, &statbuf->st_ino);
378 err |= put_user(stat->mode, &statbuf->st_mode);
379 err |= put_user(stat->nlink, &statbuf->st_nlink);
380 err |= put_user(stat->uid, &statbuf->st_uid);
381 err |= put_user(stat->gid, &statbuf->st_gid);
382 err |= put_user(huge_encode_dev(stat->rdev), &statbuf->st_rdev);
383 err |= put_user(0, (unsigned long __user *) &statbuf->__pad3[0]);
384 err |= put_user(stat->size, &statbuf->st_size);
385 err |= put_user(stat->blksize, &statbuf->st_blksize);
386 err |= put_user(0, (unsigned int __user *) &statbuf->__pad4[0]);
387 err |= put_user(0, (unsigned int __user *) &statbuf->__pad4[4]);
388 err |= put_user(stat->blocks, &statbuf->st_blocks);
389 err |= put_user(stat->atime.tv_sec, &statbuf->st_atime);
390 err |= put_user(stat->atime.tv_nsec, &statbuf->st_atime_nsec);
391 err |= put_user(stat->mtime.tv_sec, &statbuf->st_mtime);
392 err |= put_user(stat->mtime.tv_nsec, &statbuf->st_mtime_nsec);
393 err |= put_user(stat->ctime.tv_sec, &statbuf->st_ctime);
394 err |= put_user(stat->ctime.tv_nsec, &statbuf->st_ctime_nsec);
395 err |= put_user(0, &statbuf->__unused4);
396 err |= put_user(0, &statbuf->__unused5);
397
398 return err;
399}
400
401asmlinkage long compat_sys_stat64(char __user * filename,
402 struct compat_stat64 __user *statbuf)
403{
404 struct kstat stat;
405 int error = vfs_stat(filename, &stat);
406
407 if (!error)
408 error = cp_compat_stat64(&stat, statbuf);
409 return error;
410}
411
412asmlinkage long compat_sys_lstat64(char __user * filename,
413 struct compat_stat64 __user *statbuf)
414{
415 struct kstat stat;
416 int error = vfs_lstat(filename, &stat);
417
418 if (!error)
419 error = cp_compat_stat64(&stat, statbuf);
420 return error;
421}
422
423asmlinkage long compat_sys_fstat64(unsigned int fd,
424 struct compat_stat64 __user * statbuf)
425{
426 struct kstat stat;
427 int error = vfs_fstat(fd, &stat);
428
429 if (!error)
430 error = cp_compat_stat64(&stat, statbuf);
431 return error;
432}
433
David S. Miller40ad7a62006-02-12 23:30:11 -0800434asmlinkage long compat_sys_fstatat64(unsigned int dfd, char __user *filename,
435 struct compat_stat64 __user * statbuf, int flag)
436{
437 struct kstat stat;
438 int error = -EINVAL;
439
440 if ((flag & ~AT_SYMLINK_NOFOLLOW) != 0)
441 goto out;
442
443 if (flag & AT_SYMLINK_NOFOLLOW)
444 error = vfs_lstat_fd(dfd, filename, &stat);
445 else
446 error = vfs_stat_fd(dfd, filename, &stat);
447
448 if (!error)
449 error = cp_compat_stat64(&stat, statbuf);
450
451out:
452 return error;
453}
454
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455asmlinkage long compat_sys_sysfs(int option, u32 arg1, u32 arg2)
456{
457 return sys_sysfs(option, arg1, arg2);
458}
459
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460asmlinkage long compat_sys_sched_rr_get_interval(compat_pid_t pid, struct compat_timespec __user *interval)
461{
462 struct timespec t;
463 int ret;
464 mm_segment_t old_fs = get_fs ();
465
466 set_fs (KERNEL_DS);
467 ret = sys_sched_rr_get_interval(pid, (struct timespec __user *) &t);
468 set_fs (old_fs);
469 if (put_compat_timespec(&t, interval))
470 return -EFAULT;
471 return ret;
472}
473
474asmlinkage long compat_sys_rt_sigprocmask(int how,
475 compat_sigset_t __user *set,
476 compat_sigset_t __user *oset,
477 compat_size_t sigsetsize)
478{
479 sigset_t s;
480 compat_sigset_t s32;
481 int ret;
482 mm_segment_t old_fs = get_fs();
483
484 if (set) {
485 if (copy_from_user (&s32, set, sizeof(compat_sigset_t)))
486 return -EFAULT;
487 switch (_NSIG_WORDS) {
488 case 4: s.sig[3] = s32.sig[6] | (((long)s32.sig[7]) << 32);
489 case 3: s.sig[2] = s32.sig[4] | (((long)s32.sig[5]) << 32);
490 case 2: s.sig[1] = s32.sig[2] | (((long)s32.sig[3]) << 32);
491 case 1: s.sig[0] = s32.sig[0] | (((long)s32.sig[1]) << 32);
492 }
493 }
494 set_fs (KERNEL_DS);
495 ret = sys_rt_sigprocmask(how,
496 set ? (sigset_t __user *) &s : NULL,
497 oset ? (sigset_t __user *) &s : NULL,
498 sigsetsize);
499 set_fs (old_fs);
500 if (ret) return ret;
501 if (oset) {
502 switch (_NSIG_WORDS) {
503 case 4: s32.sig[7] = (s.sig[3] >> 32); s32.sig[6] = s.sig[3];
504 case 3: s32.sig[5] = (s.sig[2] >> 32); s32.sig[4] = s.sig[2];
505 case 2: s32.sig[3] = (s.sig[1] >> 32); s32.sig[2] = s.sig[1];
506 case 1: s32.sig[1] = (s.sig[0] >> 32); s32.sig[0] = s.sig[0];
507 }
508 if (copy_to_user (oset, &s32, sizeof(compat_sigset_t)))
509 return -EFAULT;
510 }
511 return 0;
512}
513
514asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
515 compat_size_t sigsetsize)
516{
517 sigset_t s;
518 compat_sigset_t s32;
519 int ret;
520 mm_segment_t old_fs = get_fs();
521
522 set_fs (KERNEL_DS);
523 ret = sys_rt_sigpending((sigset_t __user *) &s, sigsetsize);
524 set_fs (old_fs);
525 if (!ret) {
526 switch (_NSIG_WORDS) {
527 case 4: s32.sig[7] = (s.sig[3] >> 32); s32.sig[6] = s.sig[3];
528 case 3: s32.sig[5] = (s.sig[2] >> 32); s32.sig[4] = s.sig[2];
529 case 2: s32.sig[3] = (s.sig[1] >> 32); s32.sig[2] = s.sig[1];
530 case 1: s32.sig[1] = (s.sig[0] >> 32); s32.sig[0] = s.sig[0];
531 }
532 if (copy_to_user (set, &s32, sizeof(compat_sigset_t)))
533 return -EFAULT;
534 }
535 return ret;
536}
537
538asmlinkage long compat_sys_rt_sigqueueinfo(int pid, int sig,
539 struct compat_siginfo __user *uinfo)
540{
541 siginfo_t info;
542 int ret;
543 mm_segment_t old_fs = get_fs();
544
545 if (copy_siginfo_from_user32(&info, uinfo))
546 return -EFAULT;
547
548 set_fs (KERNEL_DS);
549 ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *) &info);
550 set_fs (old_fs);
551 return ret;
552}
553
554asmlinkage long compat_sys_sigaction(int sig, struct old_sigaction32 __user *act,
555 struct old_sigaction32 __user *oact)
556{
557 struct k_sigaction new_ka, old_ka;
558 int ret;
559
560 if (sig < 0) {
561 set_thread_flag(TIF_NEWSIGNALS);
562 sig = -sig;
563 }
564
565 if (act) {
566 compat_old_sigset_t mask;
567 u32 u_handler, u_restorer;
568
569 ret = get_user(u_handler, &act->sa_handler);
570 new_ka.sa.sa_handler = compat_ptr(u_handler);
571 ret |= __get_user(u_restorer, &act->sa_restorer);
572 new_ka.sa.sa_restorer = compat_ptr(u_restorer);
573 ret |= __get_user(new_ka.sa.sa_flags, &act->sa_flags);
574 ret |= __get_user(mask, &act->sa_mask);
575 if (ret)
576 return ret;
577 new_ka.ka_restorer = NULL;
578 siginitset(&new_ka.sa.sa_mask, mask);
579 }
580
581 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
582
583 if (!ret && oact) {
584 ret = put_user(ptr_to_compat(old_ka.sa.sa_handler), &oact->sa_handler);
585 ret |= __put_user(ptr_to_compat(old_ka.sa.sa_restorer), &oact->sa_restorer);
586 ret |= __put_user(old_ka.sa.sa_flags, &oact->sa_flags);
587 ret |= __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask);
588 }
589
590 return ret;
591}
592
593asmlinkage long compat_sys_rt_sigaction(int sig,
594 struct sigaction32 __user *act,
595 struct sigaction32 __user *oact,
596 void __user *restorer,
597 compat_size_t sigsetsize)
598{
599 struct k_sigaction new_ka, old_ka;
600 int ret;
601 compat_sigset_t set32;
602
603 /* XXX: Don't preclude handling different sized sigset_t's. */
604 if (sigsetsize != sizeof(compat_sigset_t))
605 return -EINVAL;
606
607 /* All tasks which use RT signals (effectively) use
608 * new style signals.
609 */
610 set_thread_flag(TIF_NEWSIGNALS);
611
612 if (act) {
613 u32 u_handler, u_restorer;
614
615 new_ka.ka_restorer = restorer;
616 ret = get_user(u_handler, &act->sa_handler);
617 new_ka.sa.sa_handler = compat_ptr(u_handler);
618 ret |= __copy_from_user(&set32, &act->sa_mask, sizeof(compat_sigset_t));
619 switch (_NSIG_WORDS) {
620 case 4: new_ka.sa.sa_mask.sig[3] = set32.sig[6] | (((long)set32.sig[7]) << 32);
621 case 3: new_ka.sa.sa_mask.sig[2] = set32.sig[4] | (((long)set32.sig[5]) << 32);
622 case 2: new_ka.sa.sa_mask.sig[1] = set32.sig[2] | (((long)set32.sig[3]) << 32);
623 case 1: new_ka.sa.sa_mask.sig[0] = set32.sig[0] | (((long)set32.sig[1]) << 32);
624 }
625 ret |= __get_user(new_ka.sa.sa_flags, &act->sa_flags);
626 ret |= __get_user(u_restorer, &act->sa_restorer);
627 new_ka.sa.sa_restorer = compat_ptr(u_restorer);
628 if (ret)
629 return -EFAULT;
630 }
631
632 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
633
634 if (!ret && oact) {
635 switch (_NSIG_WORDS) {
636 case 4: set32.sig[7] = (old_ka.sa.sa_mask.sig[3] >> 32); set32.sig[6] = old_ka.sa.sa_mask.sig[3];
637 case 3: set32.sig[5] = (old_ka.sa.sa_mask.sig[2] >> 32); set32.sig[4] = old_ka.sa.sa_mask.sig[2];
638 case 2: set32.sig[3] = (old_ka.sa.sa_mask.sig[1] >> 32); set32.sig[2] = old_ka.sa.sa_mask.sig[1];
639 case 1: set32.sig[1] = (old_ka.sa.sa_mask.sig[0] >> 32); set32.sig[0] = old_ka.sa.sa_mask.sig[0];
640 }
641 ret = put_user(ptr_to_compat(old_ka.sa.sa_handler), &oact->sa_handler);
642 ret |= __copy_to_user(&oact->sa_mask, &set32, sizeof(compat_sigset_t));
643 ret |= __put_user(old_ka.sa.sa_flags, &oact->sa_flags);
644 ret |= __put_user(ptr_to_compat(old_ka.sa.sa_restorer), &oact->sa_restorer);
645 if (ret)
646 ret = -EFAULT;
647 }
648
649 return ret;
650}
651
652/*
653 * sparc32_execve() executes a new program after the asm stub has set
654 * things up for us. This should basically do what I want it to.
655 */
656asmlinkage long sparc32_execve(struct pt_regs *regs)
657{
658 int error, base = 0;
659 char *filename;
660
661 /* User register window flush is done by entry.S */
662
663 /* Check for indirect call. */
664 if ((u32)regs->u_regs[UREG_G1] == 0)
665 base = 1;
666
667 filename = getname(compat_ptr(regs->u_regs[base + UREG_I0]));
668 error = PTR_ERR(filename);
669 if (IS_ERR(filename))
670 goto out;
671
672 error = compat_do_execve(filename,
673 compat_ptr(regs->u_regs[base + UREG_I1]),
674 compat_ptr(regs->u_regs[base + UREG_I2]), regs);
675
676 putname(filename);
677
678 if (!error) {
679 fprs_write(0);
680 current_thread_info()->xfsr[0] = 0;
681 current_thread_info()->fpsaved[0] = 0;
682 regs->tstate &= ~TSTATE_PEF;
683 task_lock(current);
684 current->ptrace &= ~PT_DTRACE;
685 task_unlock(current);
686 }
687out:
688 return error;
689}
690
691#ifdef CONFIG_MODULES
692
693asmlinkage long sys32_init_module(void __user *umod, u32 len,
694 const char __user *uargs)
695{
696 return sys_init_module(umod, len, uargs);
697}
698
699asmlinkage long sys32_delete_module(const char __user *name_user,
700 unsigned int flags)
701{
702 return sys_delete_module(name_user, flags);
703}
704
705#else /* CONFIG_MODULES */
706
707asmlinkage long sys32_init_module(const char __user *name_user,
708 struct module __user *mod_user)
709{
710 return -ENOSYS;
711}
712
713asmlinkage long sys32_delete_module(const char __user *name_user)
714{
715 return -ENOSYS;
716}
717
718#endif /* CONFIG_MODULES */
719
720/* Translations due to time_t size differences. Which affects all
721 sorts of things, like timeval and itimerval. */
722
723extern struct timezone sys_tz;
724
725asmlinkage long sys32_gettimeofday(struct compat_timeval __user *tv,
726 struct timezone __user *tz)
727{
728 if (tv) {
729 struct timeval ktv;
730 do_gettimeofday(&ktv);
731 if (put_tv32(tv, &ktv))
732 return -EFAULT;
733 }
734 if (tz) {
735 if (copy_to_user(tz, &sys_tz, sizeof(sys_tz)))
736 return -EFAULT;
737 }
738 return 0;
739}
740
741static inline long get_ts32(struct timespec *o, struct compat_timeval __user *i)
742{
743 long usec;
744
745 if (!access_ok(VERIFY_READ, i, sizeof(*i)))
746 return -EFAULT;
747 if (__get_user(o->tv_sec, &i->tv_sec))
748 return -EFAULT;
749 if (__get_user(usec, &i->tv_usec))
750 return -EFAULT;
751 o->tv_nsec = usec * 1000;
752 return 0;
753}
754
755asmlinkage long sys32_settimeofday(struct compat_timeval __user *tv,
756 struct timezone __user *tz)
757{
758 struct timespec kts;
759 struct timezone ktz;
760
761 if (tv) {
762 if (get_ts32(&kts, tv))
763 return -EFAULT;
764 }
765 if (tz) {
766 if (copy_from_user(&ktz, tz, sizeof(ktz)))
767 return -EFAULT;
768 }
769
770 return do_sys_settimeofday(tv ? &kts : NULL, tz ? &ktz : NULL);
771}
772
773asmlinkage long sys32_utimes(char __user *filename,
774 struct compat_timeval __user *tvs)
775{
Ulrich Drepper1c710c82007-05-08 00:33:25 -0700776 struct timespec tv[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777
778 if (tvs) {
Ulrich Drepper1c710c82007-05-08 00:33:25 -0700779 struct timeval ktvs[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780 if (get_tv32(&ktvs[0], tvs) ||
781 get_tv32(&ktvs[1], 1+tvs))
782 return -EFAULT;
Ulrich Drepper1c710c82007-05-08 00:33:25 -0700783
784 if (ktvs[0].tv_usec < 0 || ktvs[0].tv_usec >= 1000000 ||
785 ktvs[1].tv_usec < 0 || ktvs[1].tv_usec >= 1000000)
786 return -EINVAL;
787
788 tv[0].tv_sec = ktvs[0].tv_sec;
789 tv[0].tv_nsec = 1000 * ktvs[0].tv_usec;
790 tv[1].tv_sec = ktvs[1].tv_sec;
791 tv[1].tv_nsec = 1000 * ktvs[1].tv_usec;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 }
793
David S. Miller6c114262007-05-08 17:50:14 -0700794 return do_utimes(AT_FDCWD, filename, tvs ? tv : NULL, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795}
796
797/* These are here just in case some old sparc32 binary calls it. */
798asmlinkage long sys32_pause(void)
799{
800 current->state = TASK_INTERRUPTIBLE;
801 schedule();
802 return -ERESTARTNOHAND;
803}
804
805asmlinkage compat_ssize_t sys32_pread64(unsigned int fd,
806 char __user *ubuf,
807 compat_size_t count,
808 unsigned long poshi,
809 unsigned long poslo)
810{
811 return sys_pread64(fd, ubuf, count, (poshi << 32) | poslo);
812}
813
814asmlinkage compat_ssize_t sys32_pwrite64(unsigned int fd,
815 char __user *ubuf,
816 compat_size_t count,
817 unsigned long poshi,
818 unsigned long poslo)
819{
820 return sys_pwrite64(fd, ubuf, count, (poshi << 32) | poslo);
821}
822
823asmlinkage long compat_sys_readahead(int fd,
824 unsigned long offhi,
825 unsigned long offlo,
826 compat_size_t count)
827{
828 return sys_readahead(fd, (offhi << 32) | offlo, count);
829}
830
831long compat_sys_fadvise64(int fd,
832 unsigned long offhi,
833 unsigned long offlo,
834 compat_size_t len, int advice)
835{
836 return sys_fadvise64_64(fd, (offhi << 32) | offlo, len, advice);
837}
838
839long compat_sys_fadvise64_64(int fd,
840 unsigned long offhi, unsigned long offlo,
841 unsigned long lenhi, unsigned long lenlo,
842 int advice)
843{
844 return sys_fadvise64_64(fd,
845 (offhi << 32) | offlo,
846 (lenhi << 32) | lenlo,
847 advice);
848}
849
850asmlinkage long compat_sys_sendfile(int out_fd, int in_fd,
851 compat_off_t __user *offset,
852 compat_size_t count)
853{
854 mm_segment_t old_fs = get_fs();
855 int ret;
856 off_t of;
857
858 if (offset && get_user(of, offset))
859 return -EFAULT;
860
861 set_fs(KERNEL_DS);
862 ret = sys_sendfile(out_fd, in_fd,
863 offset ? (off_t __user *) &of : NULL,
864 count);
865 set_fs(old_fs);
866
867 if (offset && put_user(of, offset))
868 return -EFAULT;
869
870 return ret;
871}
872
873asmlinkage long compat_sys_sendfile64(int out_fd, int in_fd,
874 compat_loff_t __user *offset,
875 compat_size_t count)
876{
877 mm_segment_t old_fs = get_fs();
878 int ret;
879 loff_t lof;
880
881 if (offset && get_user(lof, offset))
882 return -EFAULT;
883
884 set_fs(KERNEL_DS);
885 ret = sys_sendfile64(out_fd, in_fd,
886 offset ? (loff_t __user *) &lof : NULL,
887 count);
888 set_fs(old_fs);
889
890 if (offset && put_user(lof, offset))
891 return -EFAULT;
892
893 return ret;
894}
895
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896/* This is just a version for 32-bit applications which does
897 * not force O_LARGEFILE on.
898 */
899
900asmlinkage long sparc32_open(const char __user *filename,
901 int flags, int mode)
902{
Ulrich Drepper5590ff02006-01-18 17:43:53 -0800903 return do_sys_open(AT_FDCWD, filename, flags, mode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904}
905
906extern unsigned long do_mremap(unsigned long addr,
907 unsigned long old_len, unsigned long new_len,
908 unsigned long flags, unsigned long new_addr);
909
910asmlinkage unsigned long sys32_mremap(unsigned long addr,
911 unsigned long old_len, unsigned long new_len,
912 unsigned long flags, u32 __new_addr)
913{
914 struct vm_area_struct *vma;
915 unsigned long ret = -EINVAL;
916 unsigned long new_addr = __new_addr;
917
David S. Millerd61e16d2006-03-17 17:33:56 -0800918 if (old_len > STACK_TOP32 || new_len > STACK_TOP32)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919 goto out;
David S. Millerd61e16d2006-03-17 17:33:56 -0800920 if (addr > STACK_TOP32 - old_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921 goto out;
922 down_write(&current->mm->mmap_sem);
923 if (flags & MREMAP_FIXED) {
David S. Millerd61e16d2006-03-17 17:33:56 -0800924 if (new_addr > STACK_TOP32 - new_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925 goto out_sem;
David S. Millerd61e16d2006-03-17 17:33:56 -0800926 } else if (addr > STACK_TOP32 - new_len) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927 unsigned long map_flags = 0;
928 struct file *file = NULL;
929
930 ret = -ENOMEM;
931 if (!(flags & MREMAP_MAYMOVE))
932 goto out_sem;
933
934 vma = find_vma(current->mm, addr);
935 if (vma) {
936 if (vma->vm_flags & VM_SHARED)
937 map_flags |= MAP_SHARED;
938 file = vma->vm_file;
939 }
940
941 /* MREMAP_FIXED checked above. */
942 new_addr = get_unmapped_area(file, addr, new_len,
943 vma ? vma->vm_pgoff : 0,
944 map_flags);
945 ret = new_addr;
946 if (new_addr & ~PAGE_MASK)
947 goto out_sem;
948 flags |= MREMAP_FIXED;
949 }
950 ret = do_mremap(addr, old_len, new_len, flags, new_addr);
951out_sem:
952 up_write(&current->mm->mmap_sem);
953out:
954 return ret;
955}
956
957struct __sysctl_args32 {
958 u32 name;
959 int nlen;
960 u32 oldval;
961 u32 oldlenp;
962 u32 newval;
963 u32 newlen;
964 u32 __unused[4];
965};
966
967asmlinkage long sys32_sysctl(struct __sysctl_args32 __user *args)
968{
Eric W. Biedermanb89a8172006-09-27 01:51:04 -0700969#ifndef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970 return -ENOSYS;
971#else
972 struct __sysctl_args32 tmp;
973 int error;
974 size_t oldlen, __user *oldlenp = NULL;
975 unsigned long addr = (((unsigned long)&args->__unused[0]) + 7UL) & ~7UL;
976
977 if (copy_from_user(&tmp, args, sizeof(tmp)))
978 return -EFAULT;
979
980 if (tmp.oldval && tmp.oldlenp) {
981 /* Duh, this is ugly and might not work if sysctl_args
982 is in read-only memory, but do_sysctl does indirectly
983 a lot of uaccess in both directions and we'd have to
984 basically copy the whole sysctl.c here, and
985 glibc's __sysctl uses rw memory for the structure
986 anyway. */
987 if (get_user(oldlen, (u32 __user *)(unsigned long)tmp.oldlenp) ||
988 put_user(oldlen, (size_t __user *)addr))
989 return -EFAULT;
990 oldlenp = (size_t __user *)addr;
991 }
992
993 lock_kernel();
994 error = do_sysctl((int __user *)(unsigned long) tmp.name,
995 tmp.nlen,
996 (void __user *)(unsigned long) tmp.oldval,
997 oldlenp,
998 (void __user *)(unsigned long) tmp.newval,
999 tmp.newlen);
1000 unlock_kernel();
1001 if (oldlenp) {
1002 if (!error) {
1003 if (get_user(oldlen, (size_t __user *)addr) ||
1004 put_user(oldlen, (u32 __user *)(unsigned long) tmp.oldlenp))
1005 error = -EFAULT;
1006 }
1007 if (copy_to_user(args->__unused, tmp.__unused, sizeof(tmp.__unused)))
1008 error = -EFAULT;
1009 }
1010 return error;
1011#endif
1012}
1013
1014long sys32_lookup_dcookie(unsigned long cookie_high,
1015 unsigned long cookie_low,
1016 char __user *buf, size_t len)
1017{
1018 return sys_lookup_dcookie((cookie_high << 32) | cookie_low,
1019 buf, len);
1020}
David S. Miller289eee62006-03-31 23:49:34 -08001021
1022long compat_sync_file_range(int fd, unsigned long off_high, unsigned long off_low, unsigned long nb_high, unsigned long nb_low, int flags)
1023{
1024 return sys_sync_file_range(fd,
1025 (off_high << 32) | off_low,
1026 (nb_high << 32) | nb_low,
1027 flags);
1028}
David S. Millerbc5a2e62007-07-18 14:28:59 -07001029
1030asmlinkage long compat_sys_fallocate(int fd, int mode, u32 offhi, u32 offlo,
1031 u32 lenhi, u32 lenlo)
1032{
1033 return sys_fallocate(fd, mode, ((loff_t)offhi << 32) | offlo,
1034 ((loff_t)lenhi << 32) | lenlo);
1035}