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