]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - arch/sparc64/kernel/sys_sparc32.c
compat: move cp_compat_stat to common code
[linux-2.6-omap-h63xx.git] / arch / sparc64 / kernel / sys_sparc32.c
1 /* sys_sparc32.c: Conversion between 32bit and 64bit native syscalls.
2  *
3  * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
4  * Copyright (C) 1997, 2007 David S. Miller (davem@davemloft.net)
5  *
6  * These routines maintain argument size conversion between 32bit and 64bit
7  * environment.
8  */
9
10 #include <linux/kernel.h>
11 #include <linux/sched.h>
12 #include <linux/capability.h>
13 #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>
20 #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
55 #include <asm/types.h>
56 #include <asm/uaccess.h>
57 #include <asm/fpumacro.h>
58 #include <asm/mmu_context.h>
59 #include <asm/compat_signal.h>
60
61 /* 32-bit timeval and related flotsam.  */
62
63 static inline long put_tv32(struct compat_timeval __user *o, struct timeval *i)
64 {
65         return (!access_ok(VERIFY_WRITE, o, sizeof(*o)) ||
66                 (__put_user(i->tv_sec, &o->tv_sec) |
67                  __put_user(i->tv_usec, &o->tv_usec)));
68 }
69
70 #ifdef CONFIG_SYSVIPC                                                        
71 asmlinkage long compat_sys_ipc(u32 call, u32 first, u32 second, u32 third, compat_uptr_t ptr, u32 fifth)
72 {
73         int version;
74
75         version = call >> 16; /* hack for backward compatibility */
76         call &= 0xffff;
77
78         switch (call) {
79         case SEMTIMEDOP:
80                 if (fifth)
81                         /* sign extend semid */
82                         return compat_sys_semtimedop((int)first,
83                                                      compat_ptr(ptr), second,
84                                                      compat_ptr(fifth));
85                 /* else fall through for normal semop() */
86         case SEMOP:
87                 /* struct sembuf is the same on 32 and 64bit :)) */
88                 /* sign extend semid */
89                 return sys_semtimedop((int)first, compat_ptr(ptr), second,
90                                       NULL);
91         case SEMGET:
92                 /* sign extend key, nsems */
93                 return sys_semget((int)first, (int)second, third);
94         case SEMCTL:
95                 /* sign extend semid, semnum */
96                 return compat_sys_semctl((int)first, (int)second, third,
97                                          compat_ptr(ptr));
98
99         case MSGSND:
100                 /* sign extend msqid */
101                 return compat_sys_msgsnd((int)first, (int)second, third,
102                                          compat_ptr(ptr));
103         case MSGRCV:
104                 /* sign extend msqid, msgtyp */
105                 return compat_sys_msgrcv((int)first, second, (int)fifth,
106                                          third, version, compat_ptr(ptr));
107         case MSGGET:
108                 /* sign extend key */
109                 return sys_msgget((int)first, second);
110         case MSGCTL:
111                 /* sign extend msqid */
112                 return compat_sys_msgctl((int)first, second, compat_ptr(ptr));
113
114         case SHMAT:
115                 /* sign extend shmid */
116                 return compat_sys_shmat((int)first, second, third, version,
117                                         compat_ptr(ptr));
118         case SHMDT:
119                 return sys_shmdt(compat_ptr(ptr));
120         case SHMGET:
121                 /* sign extend key_t */
122                 return sys_shmget((int)first, second, third);
123         case SHMCTL:
124                 /* sign extend shmid */
125                 return compat_sys_shmctl((int)first, second, compat_ptr(ptr));
126
127         default:
128                 return -ENOSYS;
129         };
130
131         return -ENOSYS;
132 }
133 #endif
134
135 asmlinkage long sys32_truncate64(const char __user * path, unsigned long high, unsigned long low)
136 {
137         if ((int)high < 0)
138                 return -EINVAL;
139         else
140                 return sys_truncate(path, (high << 32) | low);
141 }
142
143 asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long high, unsigned long low)
144 {
145         if ((int)high < 0)
146                 return -EINVAL;
147         else
148                 return sys_ftruncate(fd, (high << 32) | low);
149 }
150
151 static int cp_compat_stat64(struct kstat *stat,
152                             struct compat_stat64 __user *statbuf)
153 {
154         int err;
155
156         err  = put_user(huge_encode_dev(stat->dev), &statbuf->st_dev);
157         err |= put_user(stat->ino, &statbuf->st_ino);
158         err |= put_user(stat->mode, &statbuf->st_mode);
159         err |= put_user(stat->nlink, &statbuf->st_nlink);
160         err |= put_user(stat->uid, &statbuf->st_uid);
161         err |= put_user(stat->gid, &statbuf->st_gid);
162         err |= put_user(huge_encode_dev(stat->rdev), &statbuf->st_rdev);
163         err |= put_user(0, (unsigned long __user *) &statbuf->__pad3[0]);
164         err |= put_user(stat->size, &statbuf->st_size);
165         err |= put_user(stat->blksize, &statbuf->st_blksize);
166         err |= put_user(0, (unsigned int __user *) &statbuf->__pad4[0]);
167         err |= put_user(0, (unsigned int __user *) &statbuf->__pad4[4]);
168         err |= put_user(stat->blocks, &statbuf->st_blocks);
169         err |= put_user(stat->atime.tv_sec, &statbuf->st_atime);
170         err |= put_user(stat->atime.tv_nsec, &statbuf->st_atime_nsec);
171         err |= put_user(stat->mtime.tv_sec, &statbuf->st_mtime);
172         err |= put_user(stat->mtime.tv_nsec, &statbuf->st_mtime_nsec);
173         err |= put_user(stat->ctime.tv_sec, &statbuf->st_ctime);
174         err |= put_user(stat->ctime.tv_nsec, &statbuf->st_ctime_nsec);
175         err |= put_user(0, &statbuf->__unused4);
176         err |= put_user(0, &statbuf->__unused5);
177
178         return err;
179 }
180
181 asmlinkage long compat_sys_stat64(char __user * filename,
182                 struct compat_stat64 __user *statbuf)
183 {
184         struct kstat stat;
185         int error = vfs_stat(filename, &stat);
186
187         if (!error)
188                 error = cp_compat_stat64(&stat, statbuf);
189         return error;
190 }
191
192 asmlinkage long compat_sys_lstat64(char __user * filename,
193                 struct compat_stat64 __user *statbuf)
194 {
195         struct kstat stat;
196         int error = vfs_lstat(filename, &stat);
197
198         if (!error)
199                 error = cp_compat_stat64(&stat, statbuf);
200         return error;
201 }
202
203 asmlinkage long compat_sys_fstat64(unsigned int fd,
204                 struct compat_stat64 __user * statbuf)
205 {
206         struct kstat stat;
207         int error = vfs_fstat(fd, &stat);
208
209         if (!error)
210                 error = cp_compat_stat64(&stat, statbuf);
211         return error;
212 }
213
214 asmlinkage long compat_sys_fstatat64(unsigned int dfd, char __user *filename,
215                 struct compat_stat64 __user * statbuf, int flag)
216 {
217         struct kstat stat;
218         int error = -EINVAL;
219
220         if ((flag & ~AT_SYMLINK_NOFOLLOW) != 0)
221                 goto out;
222
223         if (flag & AT_SYMLINK_NOFOLLOW)
224                 error = vfs_lstat_fd(dfd, filename, &stat);
225         else
226                 error = vfs_stat_fd(dfd, filename, &stat);
227
228         if (!error)
229                 error = cp_compat_stat64(&stat, statbuf);
230
231 out:
232         return error;
233 }
234
235 asmlinkage long compat_sys_sysfs(int option, u32 arg1, u32 arg2)
236 {
237         return sys_sysfs(option, arg1, arg2);
238 }
239
240 asmlinkage long compat_sys_sched_rr_get_interval(compat_pid_t pid, struct compat_timespec __user *interval)
241 {
242         struct timespec t;
243         int ret;
244         mm_segment_t old_fs = get_fs ();
245         
246         set_fs (KERNEL_DS);
247         ret = sys_sched_rr_get_interval(pid, (struct timespec __user *) &t);
248         set_fs (old_fs);
249         if (put_compat_timespec(&t, interval))
250                 return -EFAULT;
251         return ret;
252 }
253
254 asmlinkage long compat_sys_rt_sigprocmask(int how,
255                                           compat_sigset_t __user *set,
256                                           compat_sigset_t __user *oset,
257                                           compat_size_t sigsetsize)
258 {
259         sigset_t s;
260         compat_sigset_t s32;
261         int ret;
262         mm_segment_t old_fs = get_fs();
263         
264         if (set) {
265                 if (copy_from_user (&s32, set, sizeof(compat_sigset_t)))
266                         return -EFAULT;
267                 switch (_NSIG_WORDS) {
268                 case 4: s.sig[3] = s32.sig[6] | (((long)s32.sig[7]) << 32);
269                 case 3: s.sig[2] = s32.sig[4] | (((long)s32.sig[5]) << 32);
270                 case 2: s.sig[1] = s32.sig[2] | (((long)s32.sig[3]) << 32);
271                 case 1: s.sig[0] = s32.sig[0] | (((long)s32.sig[1]) << 32);
272                 }
273         }
274         set_fs (KERNEL_DS);
275         ret = sys_rt_sigprocmask(how,
276                                  set ? (sigset_t __user *) &s : NULL,
277                                  oset ? (sigset_t __user *) &s : NULL,
278                                  sigsetsize);
279         set_fs (old_fs);
280         if (ret) return ret;
281         if (oset) {
282                 switch (_NSIG_WORDS) {
283                 case 4: s32.sig[7] = (s.sig[3] >> 32); s32.sig[6] = s.sig[3];
284                 case 3: s32.sig[5] = (s.sig[2] >> 32); s32.sig[4] = s.sig[2];
285                 case 2: s32.sig[3] = (s.sig[1] >> 32); s32.sig[2] = s.sig[1];
286                 case 1: s32.sig[1] = (s.sig[0] >> 32); s32.sig[0] = s.sig[0];
287                 }
288                 if (copy_to_user (oset, &s32, sizeof(compat_sigset_t)))
289                         return -EFAULT;
290         }
291         return 0;
292 }
293
294 asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
295                                     compat_size_t sigsetsize)
296 {
297         sigset_t s;
298         compat_sigset_t s32;
299         int ret;
300         mm_segment_t old_fs = get_fs();
301                 
302         set_fs (KERNEL_DS);
303         ret = sys_rt_sigpending((sigset_t __user *) &s, sigsetsize);
304         set_fs (old_fs);
305         if (!ret) {
306                 switch (_NSIG_WORDS) {
307                 case 4: s32.sig[7] = (s.sig[3] >> 32); s32.sig[6] = s.sig[3];
308                 case 3: s32.sig[5] = (s.sig[2] >> 32); s32.sig[4] = s.sig[2];
309                 case 2: s32.sig[3] = (s.sig[1] >> 32); s32.sig[2] = s.sig[1];
310                 case 1: s32.sig[1] = (s.sig[0] >> 32); s32.sig[0] = s.sig[0];
311                 }
312                 if (copy_to_user (set, &s32, sizeof(compat_sigset_t)))
313                         return -EFAULT;
314         }
315         return ret;
316 }
317
318 asmlinkage long compat_sys_rt_sigqueueinfo(int pid, int sig,
319                                            struct compat_siginfo __user *uinfo)
320 {
321         siginfo_t info;
322         int ret;
323         mm_segment_t old_fs = get_fs();
324         
325         if (copy_siginfo_from_user32(&info, uinfo))
326                 return -EFAULT;
327
328         set_fs (KERNEL_DS);
329         ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *) &info);
330         set_fs (old_fs);
331         return ret;
332 }
333
334 asmlinkage long compat_sys_sigaction(int sig, struct old_sigaction32 __user *act,
335                                      struct old_sigaction32 __user *oact)
336 {
337         struct k_sigaction new_ka, old_ka;
338         int ret;
339
340         WARN_ON_ONCE(sig >= 0);
341         sig = -sig;
342
343         if (act) {
344                 compat_old_sigset_t mask;
345                 u32 u_handler, u_restorer;
346                 
347                 ret = get_user(u_handler, &act->sa_handler);
348                 new_ka.sa.sa_handler =  compat_ptr(u_handler);
349                 ret |= __get_user(u_restorer, &act->sa_restorer);
350                 new_ka.sa.sa_restorer = compat_ptr(u_restorer);
351                 ret |= __get_user(new_ka.sa.sa_flags, &act->sa_flags);
352                 ret |= __get_user(mask, &act->sa_mask);
353                 if (ret)
354                         return ret;
355                 new_ka.ka_restorer = NULL;
356                 siginitset(&new_ka.sa.sa_mask, mask);
357         }
358
359         ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
360
361         if (!ret && oact) {
362                 ret = put_user(ptr_to_compat(old_ka.sa.sa_handler), &oact->sa_handler);
363                 ret |= __put_user(ptr_to_compat(old_ka.sa.sa_restorer), &oact->sa_restorer);
364                 ret |= __put_user(old_ka.sa.sa_flags, &oact->sa_flags);
365                 ret |= __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask);
366         }
367
368         return ret;
369 }
370
371 asmlinkage long compat_sys_rt_sigaction(int sig,
372                                         struct sigaction32 __user *act,
373                                         struct sigaction32 __user *oact,
374                                         void __user *restorer,
375                                         compat_size_t sigsetsize)
376 {
377         struct k_sigaction new_ka, old_ka;
378         int ret;
379         compat_sigset_t set32;
380
381         /* XXX: Don't preclude handling different sized sigset_t's.  */
382         if (sigsetsize != sizeof(compat_sigset_t))
383                 return -EINVAL;
384
385         if (act) {
386                 u32 u_handler, u_restorer;
387
388                 new_ka.ka_restorer = restorer;
389                 ret = get_user(u_handler, &act->sa_handler);
390                 new_ka.sa.sa_handler =  compat_ptr(u_handler);
391                 ret |= __copy_from_user(&set32, &act->sa_mask, sizeof(compat_sigset_t));
392                 switch (_NSIG_WORDS) {
393                 case 4: new_ka.sa.sa_mask.sig[3] = set32.sig[6] | (((long)set32.sig[7]) << 32);
394                 case 3: new_ka.sa.sa_mask.sig[2] = set32.sig[4] | (((long)set32.sig[5]) << 32);
395                 case 2: new_ka.sa.sa_mask.sig[1] = set32.sig[2] | (((long)set32.sig[3]) << 32);
396                 case 1: new_ka.sa.sa_mask.sig[0] = set32.sig[0] | (((long)set32.sig[1]) << 32);
397                 }
398                 ret |= __get_user(new_ka.sa.sa_flags, &act->sa_flags);
399                 ret |= __get_user(u_restorer, &act->sa_restorer);
400                 new_ka.sa.sa_restorer = compat_ptr(u_restorer);
401                 if (ret)
402                         return -EFAULT;
403         }
404
405         ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
406
407         if (!ret && oact) {
408                 switch (_NSIG_WORDS) {
409                 case 4: set32.sig[7] = (old_ka.sa.sa_mask.sig[3] >> 32); set32.sig[6] = old_ka.sa.sa_mask.sig[3];
410                 case 3: set32.sig[5] = (old_ka.sa.sa_mask.sig[2] >> 32); set32.sig[4] = old_ka.sa.sa_mask.sig[2];
411                 case 2: set32.sig[3] = (old_ka.sa.sa_mask.sig[1] >> 32); set32.sig[2] = old_ka.sa.sa_mask.sig[1];
412                 case 1: set32.sig[1] = (old_ka.sa.sa_mask.sig[0] >> 32); set32.sig[0] = old_ka.sa.sa_mask.sig[0];
413                 }
414                 ret = put_user(ptr_to_compat(old_ka.sa.sa_handler), &oact->sa_handler);
415                 ret |= __copy_to_user(&oact->sa_mask, &set32, sizeof(compat_sigset_t));
416                 ret |= __put_user(old_ka.sa.sa_flags, &oact->sa_flags);
417                 ret |= __put_user(ptr_to_compat(old_ka.sa.sa_restorer), &oact->sa_restorer);
418                 if (ret)
419                         ret = -EFAULT;
420         }
421
422         return ret;
423 }
424
425 /*
426  * sparc32_execve() executes a new program after the asm stub has set
427  * things up for us.  This should basically do what I want it to.
428  */
429 asmlinkage long sparc32_execve(struct pt_regs *regs)
430 {
431         int error, base = 0;
432         char *filename;
433
434         /* User register window flush is done by entry.S */
435
436         /* Check for indirect call. */
437         if ((u32)regs->u_regs[UREG_G1] == 0)
438                 base = 1;
439
440         filename = getname(compat_ptr(regs->u_regs[base + UREG_I0]));
441         error = PTR_ERR(filename);
442         if (IS_ERR(filename))
443                 goto out;
444
445         error = compat_do_execve(filename,
446                                  compat_ptr(regs->u_regs[base + UREG_I1]),
447                                  compat_ptr(regs->u_regs[base + UREG_I2]), regs);
448
449         putname(filename);
450
451         if (!error) {
452                 fprs_write(0);
453                 current_thread_info()->xfsr[0] = 0;
454                 current_thread_info()->fpsaved[0] = 0;
455                 regs->tstate &= ~TSTATE_PEF;
456         }
457 out:
458         return error;
459 }
460
461 #ifdef CONFIG_MODULES
462
463 asmlinkage long sys32_init_module(void __user *umod, u32 len,
464                                   const char __user *uargs)
465 {
466         return sys_init_module(umod, len, uargs);
467 }
468
469 asmlinkage long sys32_delete_module(const char __user *name_user,
470                                     unsigned int flags)
471 {
472         return sys_delete_module(name_user, flags);
473 }
474
475 #else /* CONFIG_MODULES */
476
477 asmlinkage long sys32_init_module(const char __user *name_user,
478                                   struct module __user *mod_user)
479 {
480         return -ENOSYS;
481 }
482
483 asmlinkage long sys32_delete_module(const char __user *name_user)
484 {
485         return -ENOSYS;
486 }
487
488 #endif  /* CONFIG_MODULES */
489
490 /* Translations due to time_t size differences.  Which affects all
491    sorts of things, like timeval and itimerval.  */
492
493 extern struct timezone sys_tz;
494
495 asmlinkage long sys32_gettimeofday(struct compat_timeval __user *tv,
496                                    struct timezone __user *tz)
497 {
498         if (tv) {
499                 struct timeval ktv;
500                 do_gettimeofday(&ktv);
501                 if (put_tv32(tv, &ktv))
502                         return -EFAULT;
503         }
504         if (tz) {
505                 if (copy_to_user(tz, &sys_tz, sizeof(sys_tz)))
506                         return -EFAULT;
507         }
508         return 0;
509 }
510
511 static inline long get_ts32(struct timespec *o, struct compat_timeval __user *i)
512 {
513         long usec;
514
515         if (!access_ok(VERIFY_READ, i, sizeof(*i)))
516                 return -EFAULT;
517         if (__get_user(o->tv_sec, &i->tv_sec))
518                 return -EFAULT;
519         if (__get_user(usec, &i->tv_usec))
520                 return -EFAULT;
521         o->tv_nsec = usec * 1000;
522         return 0;
523 }
524
525 asmlinkage long sys32_settimeofday(struct compat_timeval __user *tv,
526                                    struct timezone __user *tz)
527 {
528         struct timespec kts;
529         struct timezone ktz;
530
531         if (tv) {
532                 if (get_ts32(&kts, tv))
533                         return -EFAULT;
534         }
535         if (tz) {
536                 if (copy_from_user(&ktz, tz, sizeof(ktz)))
537                         return -EFAULT;
538         }
539
540         return do_sys_settimeofday(tv ? &kts : NULL, tz ? &ktz : NULL);
541 }
542
543 asmlinkage compat_ssize_t sys32_pread64(unsigned int fd,
544                                         char __user *ubuf,
545                                         compat_size_t count,
546                                         unsigned long poshi,
547                                         unsigned long poslo)
548 {
549         return sys_pread64(fd, ubuf, count, (poshi << 32) | poslo);
550 }
551
552 asmlinkage compat_ssize_t sys32_pwrite64(unsigned int fd,
553                                          char __user *ubuf,
554                                          compat_size_t count,
555                                          unsigned long poshi,
556                                          unsigned long poslo)
557 {
558         return sys_pwrite64(fd, ubuf, count, (poshi << 32) | poslo);
559 }
560
561 asmlinkage long compat_sys_readahead(int fd,
562                                      unsigned long offhi,
563                                      unsigned long offlo,
564                                      compat_size_t count)
565 {
566         return sys_readahead(fd, (offhi << 32) | offlo, count);
567 }
568
569 long compat_sys_fadvise64(int fd,
570                           unsigned long offhi,
571                           unsigned long offlo,
572                           compat_size_t len, int advice)
573 {
574         return sys_fadvise64_64(fd, (offhi << 32) | offlo, len, advice);
575 }
576
577 long compat_sys_fadvise64_64(int fd,
578                              unsigned long offhi, unsigned long offlo,
579                              unsigned long lenhi, unsigned long lenlo,
580                              int advice)
581 {
582         return sys_fadvise64_64(fd,
583                                 (offhi << 32) | offlo,
584                                 (lenhi << 32) | lenlo,
585                                 advice);
586 }
587
588 asmlinkage long compat_sys_sendfile(int out_fd, int in_fd,
589                                     compat_off_t __user *offset,
590                                     compat_size_t count)
591 {
592         mm_segment_t old_fs = get_fs();
593         int ret;
594         off_t of;
595         
596         if (offset && get_user(of, offset))
597                 return -EFAULT;
598                 
599         set_fs(KERNEL_DS);
600         ret = sys_sendfile(out_fd, in_fd,
601                            offset ? (off_t __user *) &of : NULL,
602                            count);
603         set_fs(old_fs);
604         
605         if (offset && put_user(of, offset))
606                 return -EFAULT;
607                 
608         return ret;
609 }
610
611 asmlinkage long compat_sys_sendfile64(int out_fd, int in_fd,
612                                       compat_loff_t __user *offset,
613                                       compat_size_t count)
614 {
615         mm_segment_t old_fs = get_fs();
616         int ret;
617         loff_t lof;
618         
619         if (offset && get_user(lof, offset))
620                 return -EFAULT;
621                 
622         set_fs(KERNEL_DS);
623         ret = sys_sendfile64(out_fd, in_fd,
624                              offset ? (loff_t __user *) &lof : NULL,
625                              count);
626         set_fs(old_fs);
627         
628         if (offset && put_user(lof, offset))
629                 return -EFAULT;
630                 
631         return ret;
632 }
633
634 /* This is just a version for 32-bit applications which does
635  * not force O_LARGEFILE on.
636  */
637
638 asmlinkage long sparc32_open(const char __user *filename,
639                              int flags, int mode)
640 {
641         return do_sys_open(AT_FDCWD, filename, flags, mode);
642 }
643
644 extern unsigned long do_mremap(unsigned long addr,
645         unsigned long old_len, unsigned long new_len,
646         unsigned long flags, unsigned long new_addr);
647                 
648 asmlinkage unsigned long sys32_mremap(unsigned long addr,
649         unsigned long old_len, unsigned long new_len,
650         unsigned long flags, u32 __new_addr)
651 {
652         unsigned long ret = -EINVAL;
653         unsigned long new_addr = __new_addr;
654
655         if (unlikely(sparc_mmap_check(addr, old_len)))
656                 goto out;
657         if (unlikely(sparc_mmap_check(new_addr, new_len)))
658                 goto out;
659         down_write(&current->mm->mmap_sem);
660         ret = do_mremap(addr, old_len, new_len, flags, new_addr);
661         up_write(&current->mm->mmap_sem);
662 out:
663         return ret;       
664 }
665
666 struct __sysctl_args32 {
667         u32 name;
668         int nlen;
669         u32 oldval;
670         u32 oldlenp;
671         u32 newval;
672         u32 newlen;
673         u32 __unused[4];
674 };
675
676 asmlinkage long sys32_sysctl(struct __sysctl_args32 __user *args)
677 {
678 #ifndef CONFIG_SYSCTL_SYSCALL
679         return -ENOSYS;
680 #else
681         struct __sysctl_args32 tmp;
682         int error;
683         size_t oldlen, __user *oldlenp = NULL;
684         unsigned long addr = (((unsigned long)&args->__unused[0]) + 7UL) & ~7UL;
685
686         if (copy_from_user(&tmp, args, sizeof(tmp)))
687                 return -EFAULT;
688
689         if (tmp.oldval && tmp.oldlenp) {
690                 /* Duh, this is ugly and might not work if sysctl_args
691                    is in read-only memory, but do_sysctl does indirectly
692                    a lot of uaccess in both directions and we'd have to
693                    basically copy the whole sysctl.c here, and
694                    glibc's __sysctl uses rw memory for the structure
695                    anyway.  */
696                 if (get_user(oldlen, (u32 __user *)(unsigned long)tmp.oldlenp) ||
697                     put_user(oldlen, (size_t __user *)addr))
698                         return -EFAULT;
699                 oldlenp = (size_t __user *)addr;
700         }
701
702         lock_kernel();
703         error = do_sysctl((int __user *)(unsigned long) tmp.name,
704                           tmp.nlen,
705                           (void __user *)(unsigned long) tmp.oldval,
706                           oldlenp,
707                           (void __user *)(unsigned long) tmp.newval,
708                           tmp.newlen);
709         unlock_kernel();
710         if (oldlenp) {
711                 if (!error) {
712                         if (get_user(oldlen, (size_t __user *)addr) ||
713                             put_user(oldlen, (u32 __user *)(unsigned long) tmp.oldlenp))
714                                 error = -EFAULT;
715                 }
716                 if (copy_to_user(args->__unused, tmp.__unused, sizeof(tmp.__unused)))
717                         error = -EFAULT;
718         }
719         return error;
720 #endif
721 }
722
723 long sys32_lookup_dcookie(unsigned long cookie_high,
724                           unsigned long cookie_low,
725                           char __user *buf, size_t len)
726 {
727         return sys_lookup_dcookie((cookie_high << 32) | cookie_low,
728                                   buf, len);
729 }
730
731 long compat_sync_file_range(int fd, unsigned long off_high, unsigned long off_low, unsigned long nb_high, unsigned long nb_low, int flags)
732 {
733         return sys_sync_file_range(fd,
734                                    (off_high << 32) | off_low,
735                                    (nb_high << 32) | nb_low,
736                                    flags);
737 }
738
739 asmlinkage long compat_sys_fallocate(int fd, int mode, u32 offhi, u32 offlo,
740                                      u32 lenhi, u32 lenlo)
741 {
742         return sys_fallocate(fd, mode, ((loff_t)offhi << 32) | offlo,
743                              ((loff_t)lenhi << 32) | lenlo);
744 }