sys_parisc32.c 18 KB

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