patch-2_6_7-vs1_9_1_12
[linux-2.6.git] / arch / parisc / kernel / sys_parisc32.c
1 /*
2  * sys_parisc32.c: Conversion between 32bit and 64bit native syscalls.
3  *
4  * Copyright (C) 2000-2001 Hewlett Packard Company
5  * Copyright (C) 2000 John Marvin
6  * Copyright (C) 2001 Matthew Wilcox
7  *
8  * These routines maintain argument size conversion between 32bit and 64bit
9  * environment. Based heavily on sys_ia32.c and sys_sparc32.c.
10  */
11
12 #include <linux/config.h>
13 #include <linux/compat.h>
14 #include <linux/kernel.h>
15 #include <linux/sched.h>
16 #include <linux/fs.h> 
17 #include <linux/mm.h> 
18 #include <linux/file.h> 
19 #include <linux/signal.h>
20 #include <linux/resource.h>
21 #include <linux/times.h>
22 #include <linux/utsname.h>
23 #include <linux/time.h>
24 #include <linux/timex.h>
25 #include <linux/smp.h>
26 #include <linux/smp_lock.h>
27 #include <linux/sem.h>
28 #include <linux/msg.h>
29 #include <linux/shm.h>
30 #include <linux/slab.h>
31 #include <linux/uio.h>
32 #include <linux/nfs_fs.h>
33 #include <linux/ncp_fs.h>
34 #include <linux/sunrpc/svc.h>
35 #include <linux/nfsd/nfsd.h>
36 #include <linux/nfsd/cache.h>
37 #include <linux/nfsd/xdr.h>
38 #include <linux/nfsd/syscall.h>
39 #include <linux/poll.h>
40 #include <linux/personality.h>
41 #include <linux/stat.h>
42 #include <linux/highmem.h>
43 #include <linux/highuid.h>
44 #include <linux/mman.h>
45 #include <linux/binfmts.h>
46 #include <linux/namei.h>
47 #include <linux/vfs.h>
48 #include <linux/ptrace.h>
49 #include <linux/swap.h>
50 #include <linux/syscalls.h>
51
52 #include <asm/types.h>
53 #include <asm/uaccess.h>
54 #include <asm/semaphore.h>
55 #include <asm/mmu_context.h>
56
57 #include "sys32.h"
58
59 #undef DEBUG
60
61 #ifdef DEBUG
62 #define DBG(x)  printk x
63 #else
64 #define DBG(x)
65 #endif
66
67 /*
68  * sys32_execve() executes a new program.
69  */
70
71 asmlinkage int sys32_execve(struct pt_regs *regs)
72 {
73         int error;
74         char *filename;
75
76         DBG(("sys32_execve(%p) r26 = 0x%lx\n", regs, regs->gr[26]));
77         filename = getname((char *) regs->gr[26]);
78         error = PTR_ERR(filename);
79         if (IS_ERR(filename))
80                 goto out;
81         error = compat_do_execve(filename, compat_ptr(regs->gr[25]),
82                                  compat_ptr(regs->gr[24]), regs);
83         if (error == 0)
84                 current->ptrace &= ~PT_DTRACE;
85         putname(filename);
86 out:
87
88         return error;
89 }
90
91 asmlinkage long sys32_unimplemented(int r26, int r25, int r24, int r23,
92         int r22, int r21, int r20)
93 {
94     printk(KERN_ERR "%s(%d): Unimplemented 32 on 64 syscall #%d!\n", 
95         current->comm, current->pid, r20);
96     return -ENOSYS;
97 }
98
99 #ifdef CONFIG_SYSCTL
100
101 struct __sysctl_args32 {
102         u32 name;
103         int nlen;
104         u32 oldval;
105         u32 oldlenp;
106         u32 newval;
107         u32 newlen;
108         u32 __unused[4];
109 };
110
111 asmlinkage long sys32_sysctl(struct __sysctl_args32 *args)
112 {
113         struct __sysctl_args32 tmp;
114         int error;
115         unsigned int oldlen32;
116         size_t oldlen, *oldlenp = NULL;
117         unsigned long addr = (((long)&args->__unused[0]) + 7) & ~7;
118         extern int do_sysctl(int *name, int nlen, void *oldval, size_t *oldlenp,
119                void *newval, size_t newlen);
120
121         DBG(("sysctl32(%p)\n", args));
122
123         if (copy_from_user(&tmp, args, sizeof(tmp)))
124                 return -EFAULT;
125
126         if (tmp.oldval && tmp.oldlenp) {
127                 /* Duh, this is ugly and might not work if sysctl_args
128                    is in read-only memory, but do_sysctl does indirectly
129                    a lot of uaccess in both directions and we'd have to
130                    basically copy the whole sysctl.c here, and
131                    glibc's __sysctl uses rw memory for the structure
132                    anyway.  */
133                 /* a possibly better hack than this, which will avoid the
134                  * problem if the struct is read only, is to push the
135                  * 'oldlen' value out to the user's stack instead. -PB
136                  */
137                 if (get_user(oldlen32, (u32 *)(u64)tmp.oldlenp))
138                         return -EFAULT;
139                 oldlen = oldlen32;
140                 if (put_user(oldlen, (size_t *)addr))
141                         return -EFAULT;
142                 oldlenp = (size_t *)addr;
143         }
144
145         lock_kernel();
146         error = do_sysctl((int *)(u64)tmp.name, tmp.nlen, (void *)(u64)tmp.oldval,
147                           oldlenp, (void *)(u64)tmp.newval, tmp.newlen);
148         unlock_kernel();
149         if (oldlenp) {
150                 if (!error) {
151                         if (get_user(oldlen, (size_t *)addr)) {
152                                 error = -EFAULT;
153                         } else {
154                                 oldlen32 = oldlen;
155                                 if (put_user(oldlen32, (u32 *)(u64)tmp.oldlenp))
156                                         error = -EFAULT;
157                         }
158                 }
159                 if (copy_to_user(args->__unused, tmp.__unused, sizeof(tmp.__unused)))
160                         error = -EFAULT;
161         }
162         return error;
163 }
164
165 #else /* CONFIG_SYSCTL */
166
167 asmlinkage long sys32_sysctl(struct __sysctl_args *args)
168 {
169         return -ENOSYS;
170 }
171 #endif /* CONFIG_SYSCTL */
172
173 asmlinkage long sys32_sched_rr_get_interval(pid_t pid,
174         struct compat_timespec *interval)
175 {
176         struct timespec t;
177         int ret;
178         
179         KERNEL_SYSCALL(ret, sys_sched_rr_get_interval, pid, &t);
180         if (put_compat_timespec(&t, interval))
181                 return -EFAULT;
182         return ret;
183 }
184
185 static int
186 put_compat_timeval(struct compat_timeval *u, struct timeval *t)
187 {
188         struct compat_timeval t32;
189         t32.tv_sec = t->tv_sec;
190         t32.tv_usec = t->tv_usec;
191         return copy_to_user(u, &t32, sizeof t32);
192 }
193
194 static inline long get_ts32(struct timespec *o, struct compat_timeval *i)
195 {
196         long usec;
197
198         if (__get_user(o->tv_sec, &i->tv_sec))
199                 return -EFAULT;
200         if (__get_user(usec, &i->tv_usec))
201                 return -EFAULT;
202         o->tv_nsec = usec * 1000;
203         return 0;
204 }
205
206 asmlinkage long sys32_time(compat_time_t *tloc)
207 {
208     struct timeval tv;
209
210         do_gettimeofday(&tv);
211         compat_time_t now32 = tv.tv_sec;
212
213         if (tloc)
214                 if (put_user(now32, tloc))
215                         now32 = -EFAULT;
216
217         return now32;
218 }
219
220 asmlinkage int
221 sys32_gettimeofday(struct compat_timeval *tv, struct timezone *tz)
222 {
223     extern void do_gettimeofday(struct timeval *tv);
224
225     if (tv) {
226             struct timeval ktv;
227             do_gettimeofday(&ktv);
228             if (put_compat_timeval(tv, &ktv))
229                     return -EFAULT;
230     }
231     if (tz) {
232             extern struct timezone sys_tz;
233             if (copy_to_user(tz, &sys_tz, sizeof(sys_tz)))
234                     return -EFAULT;
235     }
236     return 0;
237 }
238
239 asmlinkage 
240 int sys32_settimeofday(struct compat_timeval *tv, struct timezone *tz)
241 {
242         struct timespec kts;
243         struct timezone ktz;
244
245         if (tv) {
246                 if (get_ts32(&kts, tv))
247                         return -EFAULT;
248         }
249         if (tz) {
250                 if (copy_from_user(&ktz, tz, sizeof(ktz)))
251                         return -EFAULT;
252         }
253
254         return do_sys_settimeofday(tv ? &kts : NULL, tz ? &ktz : NULL);
255 }
256
257 int cp_compat_stat(struct kstat *stat, struct compat_stat *statbuf)
258 {
259         int err;
260
261         if (stat->size > MAX_NON_LFS || !new_valid_dev(stat->dev) ||
262             !new_valid_dev(stat->rdev))
263                 return -EOVERFLOW;
264
265         err  = put_user(new_encode_dev(stat->dev), &statbuf->st_dev);
266         err |= put_user(stat->ino, &statbuf->st_ino);
267         err |= put_user(stat->mode, &statbuf->st_mode);
268         err |= put_user(stat->nlink, &statbuf->st_nlink);
269         err |= put_user(0, &statbuf->st_reserved1);
270         err |= put_user(0, &statbuf->st_reserved2);
271         err |= put_user(new_encode_dev(stat->rdev), &statbuf->st_rdev);
272         err |= put_user(stat->size, &statbuf->st_size);
273         err |= put_user(stat->atime.tv_sec, &statbuf->st_atime);
274         err |= put_user(stat->atime.tv_nsec, &statbuf->st_atime_nsec);
275         err |= put_user(stat->mtime.tv_sec, &statbuf->st_mtime);
276         err |= put_user(stat->mtime.tv_nsec, &statbuf->st_mtime_nsec);
277         err |= put_user(stat->ctime.tv_sec, &statbuf->st_ctime);
278         err |= put_user(stat->ctime.tv_nsec, &statbuf->st_ctime_nsec);
279         err |= put_user(stat->blksize, &statbuf->st_blksize);
280         err |= put_user(stat->blocks, &statbuf->st_blocks);
281         err |= put_user(0, &statbuf->__unused1);
282         err |= put_user(0, &statbuf->__unused2);
283         err |= put_user(0, &statbuf->__unused3);
284         err |= put_user(0, &statbuf->__unused4);
285         err |= put_user(0, &statbuf->__unused5);
286         err |= put_user(0, &statbuf->st_fstype); /* not avail */
287         err |= put_user(0, &statbuf->st_realdev); /* not avail */
288         err |= put_user(0, &statbuf->st_basemode); /* not avail */
289         err |= put_user(0, &statbuf->st_spareshort);
290         err |= put_user(stat->uid, &statbuf->st_uid);
291         err |= put_user(stat->gid, &statbuf->st_gid);
292         err |= put_user(0, &statbuf->st_spare4[0]);
293         err |= put_user(0, &statbuf->st_spare4[1]);
294         err |= put_user(0, &statbuf->st_spare4[2]);
295
296         return err;
297 }
298
299 struct linux32_dirent {
300         u32             d_ino;
301         compat_off_t    d_off;
302         u16             d_reclen;
303         char            d_name[1];
304 };
305
306 struct old_linux32_dirent {
307         u32     d_ino;
308         u32     d_offset;
309         u16     d_namlen;
310         char    d_name[1];
311 };
312
313 struct getdents32_callback {
314         struct linux32_dirent * current_dir;
315         struct linux32_dirent * previous;
316         int count;
317         int error;
318 };
319
320 struct readdir32_callback {
321         struct old_linux32_dirent * dirent;
322         int count;
323 };
324
325 #define ROUND_UP(x,a)   ((__typeof__(x))(((unsigned long)(x) + ((a) - 1)) & ~((a) - 1)))
326 #define NAME_OFFSET(de) ((int) ((de)->d_name - (char *) (de)))
327 static int
328 filldir32 (void *__buf, const char *name, int namlen, loff_t offset, ino_t ino,
329            unsigned int d_type)
330 {
331         struct linux32_dirent * dirent;
332         struct getdents32_callback * buf = (struct getdents32_callback *) __buf;
333         int reclen = ROUND_UP(NAME_OFFSET(dirent) + namlen + 1, 4);
334
335         buf->error = -EINVAL;   /* only used if we fail.. */
336         if (reclen > buf->count)
337                 return -EINVAL;
338         dirent = buf->previous;
339         if (dirent)
340                 put_user(offset, &dirent->d_off);
341         dirent = buf->current_dir;
342         buf->previous = dirent;
343         put_user(ino, &dirent->d_ino);
344         put_user(reclen, &dirent->d_reclen);
345         copy_to_user(dirent->d_name, name, namlen);
346         put_user(0, dirent->d_name + namlen);
347         ((char *) dirent) += reclen;
348         buf->current_dir = dirent;
349         buf->count -= reclen;
350         return 0;
351 }
352
353 asmlinkage long
354 sys32_getdents (unsigned int fd, void * dirent, unsigned int count)
355 {
356         struct file * file;
357         struct linux32_dirent * lastdirent;
358         struct getdents32_callback buf;
359         int error;
360
361         error = -EBADF;
362         file = fget(fd);
363         if (!file)
364                 goto out;
365
366         buf.current_dir = (struct linux32_dirent *) dirent;
367         buf.previous = NULL;
368         buf.count = count;
369         buf.error = 0;
370
371         error = vfs_readdir(file, filldir32, &buf);
372         if (error < 0)
373                 goto out_putf;
374         error = buf.error;
375         lastdirent = buf.previous;
376         if (lastdirent) {
377                 put_user(file->f_pos, &lastdirent->d_off);
378                 error = count - buf.count;
379         }
380
381 out_putf:
382         fput(file);
383 out:
384         return error;
385 }
386
387 static int
388 fillonedir32 (void * __buf, const char * name, int namlen, loff_t offset, ino_t ino,
389               unsigned int d_type)
390 {
391         struct readdir32_callback * buf = (struct readdir32_callback *) __buf;
392         struct old_linux32_dirent * dirent;
393
394         if (buf->count)
395                 return -EINVAL;
396         buf->count++;
397         dirent = buf->dirent;
398         put_user(ino, &dirent->d_ino);
399         put_user(offset, &dirent->d_offset);
400         put_user(namlen, &dirent->d_namlen);
401         copy_to_user(dirent->d_name, name, namlen);
402         put_user(0, dirent->d_name + namlen);
403         return 0;
404 }
405
406 asmlinkage long
407 sys32_readdir (unsigned int fd, void * dirent, unsigned int count)
408 {
409         int error;
410         struct file * file;
411         struct readdir32_callback buf;
412
413         error = -EBADF;
414         file = fget(fd);
415         if (!file)
416                 goto out;
417
418         buf.count = 0;
419         buf.dirent = dirent;
420
421         error = vfs_readdir(file, fillonedir32, &buf);
422         if (error >= 0)
423                 error = buf.count;
424         fput(file);
425 out:
426         return error;
427 }
428
429 /*** copied from mips64 ***/
430 /*
431  * Ooo, nasty.  We need here to frob 32-bit unsigned longs to
432  * 64-bit unsigned longs.
433  */
434
435 static inline int
436 get_fd_set32(unsigned long n, u32 *ufdset, unsigned long *fdset)
437 {
438         n = (n + 8*sizeof(u32) - 1) / (8*sizeof(u32));
439         if (ufdset) {
440                 unsigned long odd;
441
442                 if (verify_area(VERIFY_WRITE, ufdset, n*sizeof(u32)))
443                         return -EFAULT;
444
445                 odd = n & 1UL;
446                 n &= ~1UL;
447                 while (n) {
448                         unsigned long h, l;
449                         __get_user(l, ufdset);
450                         __get_user(h, ufdset+1);
451                         ufdset += 2;
452                         *fdset++ = h << 32 | l;
453                         n -= 2;
454                 }
455                 if (odd)
456                         __get_user(*fdset, ufdset);
457         } else {
458                 /* Tricky, must clear full unsigned long in the
459                  * kernel fdset at the end, this makes sure that
460                  * actually happens.
461                  */
462                 memset(fdset, 0, ((n + 1) & ~1)*sizeof(u32));
463         }
464         return 0;
465 }
466
467 static inline void
468 set_fd_set32(unsigned long n, u32 *ufdset, unsigned long *fdset)
469 {
470         unsigned long odd;
471         n = (n + 8*sizeof(u32) - 1) / (8*sizeof(u32));
472
473         if (!ufdset)
474                 return;
475
476         odd = n & 1UL;
477         n &= ~1UL;
478         while (n) {
479                 unsigned long h, l;
480                 l = *fdset++;
481                 h = l >> 32;
482                 __put_user(l, ufdset);
483                 __put_user(h, ufdset+1);
484                 ufdset += 2;
485                 n -= 2;
486         }
487         if (odd)
488                 __put_user(*fdset, ufdset);
489 }
490
491 struct msgbuf32 {
492     int mtype;
493     char mtext[1];
494 };
495
496 asmlinkage long sys32_msgsnd(int msqid,
497                                 struct msgbuf32 *umsgp32,
498                                 size_t msgsz, int msgflg)
499 {
500         struct msgbuf *mb;
501         struct msgbuf32 mb32;
502         int err;
503
504         if ((mb = kmalloc(msgsz + sizeof *mb + 4, GFP_KERNEL)) == NULL)
505                 return -ENOMEM;
506
507         err = get_user(mb32.mtype, &umsgp32->mtype);
508         mb->mtype = mb32.mtype;
509         err |= copy_from_user(mb->mtext, &umsgp32->mtext, msgsz);
510
511         if (err)
512                 err = -EFAULT;
513         else
514                 KERNEL_SYSCALL(err, sys_msgsnd, msqid, mb, msgsz, msgflg);
515
516         kfree(mb);
517         return err;
518 }
519
520 asmlinkage long sys32_msgrcv(int msqid,
521                                 struct msgbuf32 *umsgp32,
522                                 size_t msgsz, long msgtyp, int msgflg)
523 {
524         struct msgbuf *mb;
525         struct msgbuf32 mb32;
526         int err, len;
527
528         if ((mb = kmalloc(msgsz + sizeof *mb + 4, GFP_KERNEL)) == NULL)
529                 return -ENOMEM;
530
531         KERNEL_SYSCALL(err, sys_msgrcv, msqid, mb, msgsz, msgtyp, msgflg);
532
533         if (err >= 0) {
534                 len = err;
535                 mb32.mtype = mb->mtype;
536                 err = put_user(mb32.mtype, &umsgp32->mtype);
537                 err |= copy_to_user(&umsgp32->mtext, mb->mtext, len);
538                 if (err)
539                         err = -EFAULT;
540                 else
541                         err = len;
542         }
543
544         kfree(mb);
545         return err;
546 }
547
548 asmlinkage int sys32_sendfile(int out_fd, int in_fd, compat_off_t *offset, s32 count)
549 {
550         mm_segment_t old_fs = get_fs();
551         int ret;
552         off_t of;
553
554         if (offset && get_user(of, offset))
555                 return -EFAULT;
556
557         set_fs(KERNEL_DS);
558         ret = sys_sendfile(out_fd, in_fd, offset ? &of : NULL, count);
559         set_fs(old_fs);
560
561         if (offset && put_user(of, offset))
562                 return -EFAULT;
563
564         return ret;
565 }
566
567 typedef long __kernel_loff_t32;         /* move this to asm/posix_types.h? */
568
569 asmlinkage int sys32_sendfile64(int out_fd, int in_fd, __kernel_loff_t32 *offset, s32 count)
570 {
571         mm_segment_t old_fs = get_fs();
572         int ret;
573         loff_t lof;
574         
575         if (offset && get_user(lof, offset))
576                 return -EFAULT;
577                 
578         set_fs(KERNEL_DS);
579         ret = sys_sendfile64(out_fd, in_fd, offset ? &lof : NULL, count);
580         set_fs(old_fs);
581         
582         if (offset && put_user(lof, offset))
583                 return -EFAULT;
584                 
585         return ret;
586 }
587
588
589 struct timex32 {
590         unsigned int modes;     /* mode selector */
591         int offset;             /* time offset (usec) */
592         int freq;               /* frequency offset (scaled ppm) */
593         int maxerror;           /* maximum error (usec) */
594         int esterror;           /* estimated error (usec) */
595         int status;             /* clock command/status */
596         int constant;           /* pll time constant */
597         int precision;          /* clock precision (usec) (read only) */
598         int tolerance;          /* clock frequency tolerance (ppm)
599                                  * (read only)
600                                  */
601         struct compat_timeval time;     /* (read only) */
602         int tick;               /* (modified) usecs between clock ticks */
603
604         int ppsfreq;           /* pps frequency (scaled ppm) (ro) */
605         int jitter;            /* pps jitter (us) (ro) */
606         int shift;              /* interval duration (s) (shift) (ro) */
607         int stabil;            /* pps stability (scaled ppm) (ro) */
608         int jitcnt;            /* jitter limit exceeded (ro) */
609         int calcnt;            /* calibration intervals (ro) */
610         int errcnt;            /* calibration errors (ro) */
611         int stbcnt;            /* stability limit exceeded (ro) */
612
613         int  :32; int  :32; int  :32; int  :32;
614         int  :32; int  :32; int  :32; int  :32;
615         int  :32; int  :32; int  :32; int  :32;
616 };
617
618 asmlinkage long sys32_adjtimex(struct timex32 *txc_p32)
619 {
620         struct timex txc;
621         struct timex32 t32;
622         int ret;
623         extern int do_adjtimex(struct timex *txc);
624
625         if(copy_from_user(&t32, txc_p32, sizeof(struct timex32)))
626                 return -EFAULT;
627 #undef CP
628 #define CP(x) txc.x = t32.x
629         CP(modes); CP(offset); CP(freq); CP(maxerror); CP(esterror);
630         CP(status); CP(constant); CP(precision); CP(tolerance);
631         CP(time.tv_sec); CP(time.tv_usec); CP(tick); CP(ppsfreq); CP(jitter);
632         CP(shift); CP(stabil); CP(jitcnt); CP(calcnt); CP(errcnt);
633         CP(stbcnt);
634         ret = do_adjtimex(&txc);
635 #undef CP
636 #define CP(x) t32.x = txc.x
637         CP(modes); CP(offset); CP(freq); CP(maxerror); CP(esterror);
638         CP(status); CP(constant); CP(precision); CP(tolerance);
639         CP(time.tv_sec); CP(time.tv_usec); CP(tick); CP(ppsfreq); CP(jitter);
640         CP(shift); CP(stabil); CP(jitcnt); CP(calcnt); CP(errcnt);
641         CP(stbcnt);
642         return copy_to_user(txc_p32, &t32, sizeof(struct timex32)) ? -EFAULT : ret;
643 }
644
645
646 struct sysinfo32 {
647         s32 uptime;
648         u32 loads[3];
649         u32 totalram;
650         u32 freeram;
651         u32 sharedram;
652         u32 bufferram;
653         u32 totalswap;
654         u32 freeswap;
655         unsigned short procs;
656         u32 totalhigh;
657         u32 freehigh;
658         u32 mem_unit;
659         char _f[12];
660 };
661
662 /* We used to call sys_sysinfo and translate the result.  But sys_sysinfo
663  * undoes the good work done elsewhere, and rather than undoing the
664  * damage, I decided to just duplicate the code from sys_sysinfo here.
665  */
666
667 asmlinkage int sys32_sysinfo(struct sysinfo32 *info)
668 {
669         struct sysinfo val;
670         int err;
671         unsigned long seq;
672
673         /* We don't need a memset here because we copy the
674          * struct to userspace once element at a time.
675          */
676
677         do {
678                 seq = read_seqbegin(&xtime_lock);
679                 /* requires vx virtualization */
680                 val.uptime = jiffies / HZ;
681
682                 val.loads[0] = avenrun[0] << (SI_LOAD_SHIFT - FSHIFT);
683                 val.loads[1] = avenrun[1] << (SI_LOAD_SHIFT - FSHIFT);
684                 val.loads[2] = avenrun[2] << (SI_LOAD_SHIFT - FSHIFT);
685
686                 val.procs = nr_threads;
687         } while (read_seqretry(&xtime_lock, seq));
688
689
690         si_meminfo(&val);
691         si_swapinfo(&val);
692         
693         err = put_user (val.uptime, &info->uptime);
694         err |= __put_user (val.loads[0], &info->loads[0]);
695         err |= __put_user (val.loads[1], &info->loads[1]);
696         err |= __put_user (val.loads[2], &info->loads[2]);
697         err |= __put_user (val.totalram, &info->totalram);
698         err |= __put_user (val.freeram, &info->freeram);
699         err |= __put_user (val.sharedram, &info->sharedram);
700         err |= __put_user (val.bufferram, &info->bufferram);
701         err |= __put_user (val.totalswap, &info->totalswap);
702         err |= __put_user (val.freeswap, &info->freeswap);
703         err |= __put_user (val.procs, &info->procs);
704         err |= __put_user (val.totalhigh, &info->totalhigh);
705         err |= __put_user (val.freehigh, &info->freehigh);
706         err |= __put_user (val.mem_unit, &info->mem_unit);
707         return err ? -EFAULT : 0;
708 }
709
710
711 /* lseek() needs a wrapper because 'offset' can be negative, but the top
712  * half of the argument has been zeroed by syscall.S.
713  */
714
715 asmlinkage int sys32_lseek(unsigned int fd, int offset, unsigned int origin)
716 {
717         return sys_lseek(fd, offset, origin);
718 }
719
720 asmlinkage long sys32_semctl(int semid, int semnum, int cmd, union semun arg)
721 {
722         union semun u;
723         
724         if (cmd == SETVAL) {
725                 /* Ugh.  arg is a union of int,ptr,ptr,ptr, so is 8 bytes.
726                  * The int should be in the first 4, but our argument
727                  * frobbing has left it in the last 4.
728                  */
729                 u.val = *((int *)&arg + 1);
730                 return sys_semctl (semid, semnum, cmd, u);
731         }
732         return sys_semctl (semid, semnum, cmd, arg);
733 }
734
735 long sys32_lookup_dcookie(u32 cookie_high, u32 cookie_low, char *buf,
736                           size_t len)
737 {
738         return sys_lookup_dcookie((u64)cookie_high << 32 | cookie_low,
739                                   buf, len);
740 }