sys_ia32.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823
  1. /*
  2. * sys_ia32.c: Conversion between 32bit and 64bit native syscalls. Based on
  3. * sys_sparc32
  4. *
  5. * Copyright (C) 2000 VA Linux Co
  6. * Copyright (C) 2000 Don Dugger <n0ano@valinux.com>
  7. * Copyright (C) 1999 Arun Sharma <arun.sharma@intel.com>
  8. * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
  9. * Copyright (C) 1997 David S. Miller (davem@caip.rutgers.edu)
  10. * Copyright (C) 2000 Hewlett-Packard Co.
  11. * Copyright (C) 2000 David Mosberger-Tang <davidm@hpl.hp.com>
  12. * Copyright (C) 2000,2001,2002 Andi Kleen, SuSE Labs (x86-64 port)
  13. *
  14. * These routines maintain argument size conversion between 32bit and 64bit
  15. * environment. In 2.5 most of this should be moved to a generic directory.
  16. *
  17. * This file assumes that there is a hole at the end of user address space.
  18. *
  19. * Some of the functions are LE specific currently. These are
  20. * hopefully all marked. This should be fixed.
  21. */
  22. #include <linux/kernel.h>
  23. #include <linux/sched.h>
  24. #include <linux/fs.h>
  25. #include <linux/file.h>
  26. #include <linux/signal.h>
  27. #include <linux/syscalls.h>
  28. #include <linux/times.h>
  29. #include <linux/utsname.h>
  30. #include <linux/smp_lock.h>
  31. #include <linux/mm.h>
  32. #include <linux/uio.h>
  33. #include <linux/poll.h>
  34. #include <linux/personality.h>
  35. #include <linux/stat.h>
  36. #include <linux/rwsem.h>
  37. #include <linux/compat.h>
  38. #include <linux/vfs.h>
  39. #include <linux/ptrace.h>
  40. #include <linux/highuid.h>
  41. #include <linux/sysctl.h>
  42. #include <asm/mman.h>
  43. #include <asm/types.h>
  44. #include <asm/uaccess.h>
  45. #include <asm/atomic.h>
  46. #include <asm/ia32.h>
  47. #include <asm/vgtod.h>
  48. #define AA(__x) ((unsigned long)(__x))
  49. asmlinkage long sys32_truncate64(char __user *filename,
  50. unsigned long offset_low,
  51. unsigned long offset_high)
  52. {
  53. return sys_truncate(filename, ((loff_t) offset_high << 32) | offset_low);
  54. }
  55. asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
  56. unsigned long offset_high)
  57. {
  58. return sys_ftruncate(fd, ((loff_t) offset_high << 32) | offset_low);
  59. }
  60. /*
  61. * Another set for IA32/LFS -- x86_64 struct stat is different due to
  62. * support for 64bit inode numbers.
  63. */
  64. static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
  65. {
  66. typeof(ubuf->st_uid) uid = 0;
  67. typeof(ubuf->st_gid) gid = 0;
  68. SET_UID(uid, stat->uid);
  69. SET_GID(gid, stat->gid);
  70. if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
  71. __put_user(huge_encode_dev(stat->dev), &ubuf->st_dev) ||
  72. __put_user(stat->ino, &ubuf->__st_ino) ||
  73. __put_user(stat->ino, &ubuf->st_ino) ||
  74. __put_user(stat->mode, &ubuf->st_mode) ||
  75. __put_user(stat->nlink, &ubuf->st_nlink) ||
  76. __put_user(uid, &ubuf->st_uid) ||
  77. __put_user(gid, &ubuf->st_gid) ||
  78. __put_user(huge_encode_dev(stat->rdev), &ubuf->st_rdev) ||
  79. __put_user(stat->size, &ubuf->st_size) ||
  80. __put_user(stat->atime.tv_sec, &ubuf->st_atime) ||
  81. __put_user(stat->atime.tv_nsec, &ubuf->st_atime_nsec) ||
  82. __put_user(stat->mtime.tv_sec, &ubuf->st_mtime) ||
  83. __put_user(stat->mtime.tv_nsec, &ubuf->st_mtime_nsec) ||
  84. __put_user(stat->ctime.tv_sec, &ubuf->st_ctime) ||
  85. __put_user(stat->ctime.tv_nsec, &ubuf->st_ctime_nsec) ||
  86. __put_user(stat->blksize, &ubuf->st_blksize) ||
  87. __put_user(stat->blocks, &ubuf->st_blocks))
  88. return -EFAULT;
  89. return 0;
  90. }
  91. asmlinkage long sys32_stat64(char __user *filename,
  92. struct stat64 __user *statbuf)
  93. {
  94. struct kstat stat;
  95. int ret = vfs_stat(filename, &stat);
  96. if (!ret)
  97. ret = cp_stat64(statbuf, &stat);
  98. return ret;
  99. }
  100. asmlinkage long sys32_lstat64(char __user *filename,
  101. struct stat64 __user *statbuf)
  102. {
  103. struct kstat stat;
  104. int ret = vfs_lstat(filename, &stat);
  105. if (!ret)
  106. ret = cp_stat64(statbuf, &stat);
  107. return ret;
  108. }
  109. asmlinkage long sys32_fstat64(unsigned int fd, struct stat64 __user *statbuf)
  110. {
  111. struct kstat stat;
  112. int ret = vfs_fstat(fd, &stat);
  113. if (!ret)
  114. ret = cp_stat64(statbuf, &stat);
  115. return ret;
  116. }
  117. asmlinkage long sys32_fstatat(unsigned int dfd, char __user *filename,
  118. struct stat64 __user *statbuf, int flag)
  119. {
  120. struct kstat stat;
  121. int error = -EINVAL;
  122. if ((flag & ~AT_SYMLINK_NOFOLLOW) != 0)
  123. goto out;
  124. if (flag & AT_SYMLINK_NOFOLLOW)
  125. error = vfs_lstat_fd(dfd, filename, &stat);
  126. else
  127. error = vfs_stat_fd(dfd, filename, &stat);
  128. if (!error)
  129. error = cp_stat64(statbuf, &stat);
  130. out:
  131. return error;
  132. }
  133. /*
  134. * Linux/i386 didn't use to be able to handle more than
  135. * 4 system call parameters, so these system calls used a memory
  136. * block for parameter passing..
  137. */
  138. struct mmap_arg_struct {
  139. unsigned int addr;
  140. unsigned int len;
  141. unsigned int prot;
  142. unsigned int flags;
  143. unsigned int fd;
  144. unsigned int offset;
  145. };
  146. asmlinkage long sys32_mmap(struct mmap_arg_struct __user *arg)
  147. {
  148. struct mmap_arg_struct a;
  149. struct file *file = NULL;
  150. unsigned long retval;
  151. struct mm_struct *mm ;
  152. if (copy_from_user(&a, arg, sizeof(a)))
  153. return -EFAULT;
  154. if (a.offset & ~PAGE_MASK)
  155. return -EINVAL;
  156. if (!(a.flags & MAP_ANONYMOUS)) {
  157. file = fget(a.fd);
  158. if (!file)
  159. return -EBADF;
  160. }
  161. mm = current->mm;
  162. down_write(&mm->mmap_sem);
  163. retval = do_mmap_pgoff(file, a.addr, a.len, a.prot, a.flags,
  164. a.offset>>PAGE_SHIFT);
  165. if (file)
  166. fput(file);
  167. up_write(&mm->mmap_sem);
  168. return retval;
  169. }
  170. asmlinkage long sys32_mprotect(unsigned long start, size_t len,
  171. unsigned long prot)
  172. {
  173. return sys_mprotect(start, len, prot);
  174. }
  175. asmlinkage long sys32_pipe(int __user *fd)
  176. {
  177. int retval;
  178. int fds[2];
  179. retval = do_pipe_flags(fds, 0);
  180. if (retval)
  181. goto out;
  182. if (copy_to_user(fd, fds, sizeof(fds)))
  183. retval = -EFAULT;
  184. out:
  185. return retval;
  186. }
  187. asmlinkage long sys32_rt_sigaction(int sig, struct sigaction32 __user *act,
  188. struct sigaction32 __user *oact,
  189. unsigned int sigsetsize)
  190. {
  191. struct k_sigaction new_ka, old_ka;
  192. int ret;
  193. compat_sigset_t set32;
  194. /* XXX: Don't preclude handling different sized sigset_t's. */
  195. if (sigsetsize != sizeof(compat_sigset_t))
  196. return -EINVAL;
  197. if (act) {
  198. compat_uptr_t handler, restorer;
  199. if (!access_ok(VERIFY_READ, act, sizeof(*act)) ||
  200. __get_user(handler, &act->sa_handler) ||
  201. __get_user(new_ka.sa.sa_flags, &act->sa_flags) ||
  202. __get_user(restorer, &act->sa_restorer) ||
  203. __copy_from_user(&set32, &act->sa_mask,
  204. sizeof(compat_sigset_t)))
  205. return -EFAULT;
  206. new_ka.sa.sa_handler = compat_ptr(handler);
  207. new_ka.sa.sa_restorer = compat_ptr(restorer);
  208. /*
  209. * FIXME: here we rely on _COMPAT_NSIG_WORS to be >=
  210. * than _NSIG_WORDS << 1
  211. */
  212. switch (_NSIG_WORDS) {
  213. case 4: new_ka.sa.sa_mask.sig[3] = set32.sig[6]
  214. | (((long)set32.sig[7]) << 32);
  215. case 3: new_ka.sa.sa_mask.sig[2] = set32.sig[4]
  216. | (((long)set32.sig[5]) << 32);
  217. case 2: new_ka.sa.sa_mask.sig[1] = set32.sig[2]
  218. | (((long)set32.sig[3]) << 32);
  219. case 1: new_ka.sa.sa_mask.sig[0] = set32.sig[0]
  220. | (((long)set32.sig[1]) << 32);
  221. }
  222. }
  223. ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
  224. if (!ret && oact) {
  225. /*
  226. * FIXME: here we rely on _COMPAT_NSIG_WORS to be >=
  227. * than _NSIG_WORDS << 1
  228. */
  229. switch (_NSIG_WORDS) {
  230. case 4:
  231. set32.sig[7] = (old_ka.sa.sa_mask.sig[3] >> 32);
  232. set32.sig[6] = old_ka.sa.sa_mask.sig[3];
  233. case 3:
  234. set32.sig[5] = (old_ka.sa.sa_mask.sig[2] >> 32);
  235. set32.sig[4] = old_ka.sa.sa_mask.sig[2];
  236. case 2:
  237. set32.sig[3] = (old_ka.sa.sa_mask.sig[1] >> 32);
  238. set32.sig[2] = old_ka.sa.sa_mask.sig[1];
  239. case 1:
  240. set32.sig[1] = (old_ka.sa.sa_mask.sig[0] >> 32);
  241. set32.sig[0] = old_ka.sa.sa_mask.sig[0];
  242. }
  243. if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) ||
  244. __put_user(ptr_to_compat(old_ka.sa.sa_handler),
  245. &oact->sa_handler) ||
  246. __put_user(ptr_to_compat(old_ka.sa.sa_restorer),
  247. &oact->sa_restorer) ||
  248. __put_user(old_ka.sa.sa_flags, &oact->sa_flags) ||
  249. __copy_to_user(&oact->sa_mask, &set32,
  250. sizeof(compat_sigset_t)))
  251. return -EFAULT;
  252. }
  253. return ret;
  254. }
  255. asmlinkage long sys32_sigaction(int sig, struct old_sigaction32 __user *act,
  256. struct old_sigaction32 __user *oact)
  257. {
  258. struct k_sigaction new_ka, old_ka;
  259. int ret;
  260. if (act) {
  261. compat_old_sigset_t mask;
  262. compat_uptr_t handler, restorer;
  263. if (!access_ok(VERIFY_READ, act, sizeof(*act)) ||
  264. __get_user(handler, &act->sa_handler) ||
  265. __get_user(new_ka.sa.sa_flags, &act->sa_flags) ||
  266. __get_user(restorer, &act->sa_restorer) ||
  267. __get_user(mask, &act->sa_mask))
  268. return -EFAULT;
  269. new_ka.sa.sa_handler = compat_ptr(handler);
  270. new_ka.sa.sa_restorer = compat_ptr(restorer);
  271. siginitset(&new_ka.sa.sa_mask, mask);
  272. }
  273. ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
  274. if (!ret && oact) {
  275. if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) ||
  276. __put_user(ptr_to_compat(old_ka.sa.sa_handler),
  277. &oact->sa_handler) ||
  278. __put_user(ptr_to_compat(old_ka.sa.sa_restorer),
  279. &oact->sa_restorer) ||
  280. __put_user(old_ka.sa.sa_flags, &oact->sa_flags) ||
  281. __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask))
  282. return -EFAULT;
  283. }
  284. return ret;
  285. }
  286. asmlinkage long sys32_rt_sigprocmask(int how, compat_sigset_t __user *set,
  287. compat_sigset_t __user *oset,
  288. unsigned int sigsetsize)
  289. {
  290. sigset_t s;
  291. compat_sigset_t s32;
  292. int ret;
  293. mm_segment_t old_fs = get_fs();
  294. if (set) {
  295. if (copy_from_user(&s32, set, sizeof(compat_sigset_t)))
  296. return -EFAULT;
  297. switch (_NSIG_WORDS) {
  298. case 4: s.sig[3] = s32.sig[6] | (((long)s32.sig[7]) << 32);
  299. case 3: s.sig[2] = s32.sig[4] | (((long)s32.sig[5]) << 32);
  300. case 2: s.sig[1] = s32.sig[2] | (((long)s32.sig[3]) << 32);
  301. case 1: s.sig[0] = s32.sig[0] | (((long)s32.sig[1]) << 32);
  302. }
  303. }
  304. set_fs(KERNEL_DS);
  305. ret = sys_rt_sigprocmask(how,
  306. set ? (sigset_t __user *)&s : NULL,
  307. oset ? (sigset_t __user *)&s : NULL,
  308. sigsetsize);
  309. set_fs(old_fs);
  310. if (ret)
  311. return ret;
  312. if (oset) {
  313. switch (_NSIG_WORDS) {
  314. case 4: s32.sig[7] = (s.sig[3] >> 32); s32.sig[6] = s.sig[3];
  315. case 3: s32.sig[5] = (s.sig[2] >> 32); s32.sig[4] = s.sig[2];
  316. case 2: s32.sig[3] = (s.sig[1] >> 32); s32.sig[2] = s.sig[1];
  317. case 1: s32.sig[1] = (s.sig[0] >> 32); s32.sig[0] = s.sig[0];
  318. }
  319. if (copy_to_user(oset, &s32, sizeof(compat_sigset_t)))
  320. return -EFAULT;
  321. }
  322. return 0;
  323. }
  324. static inline long get_tv32(struct timeval *o, struct compat_timeval __user *i)
  325. {
  326. int err = -EFAULT;
  327. if (access_ok(VERIFY_READ, i, sizeof(*i))) {
  328. err = __get_user(o->tv_sec, &i->tv_sec);
  329. err |= __get_user(o->tv_usec, &i->tv_usec);
  330. }
  331. return err;
  332. }
  333. static inline long put_tv32(struct compat_timeval __user *o, struct timeval *i)
  334. {
  335. int err = -EFAULT;
  336. if (access_ok(VERIFY_WRITE, o, sizeof(*o))) {
  337. err = __put_user(i->tv_sec, &o->tv_sec);
  338. err |= __put_user(i->tv_usec, &o->tv_usec);
  339. }
  340. return err;
  341. }
  342. asmlinkage long sys32_alarm(unsigned int seconds)
  343. {
  344. return alarm_setitimer(seconds);
  345. }
  346. /*
  347. * Translations due to time_t size differences. Which affects all
  348. * sorts of things, like timeval and itimerval.
  349. */
  350. asmlinkage long sys32_gettimeofday(struct compat_timeval __user *tv,
  351. struct timezone __user *tz)
  352. {
  353. if (tv) {
  354. struct timeval ktv;
  355. do_gettimeofday(&ktv);
  356. if (put_tv32(tv, &ktv))
  357. return -EFAULT;
  358. }
  359. if (tz) {
  360. if (copy_to_user(tz, &sys_tz, sizeof(sys_tz)))
  361. return -EFAULT;
  362. }
  363. return 0;
  364. }
  365. asmlinkage long sys32_settimeofday(struct compat_timeval __user *tv,
  366. struct timezone __user *tz)
  367. {
  368. struct timeval ktv;
  369. struct timespec kts;
  370. struct timezone ktz;
  371. if (tv) {
  372. if (get_tv32(&ktv, tv))
  373. return -EFAULT;
  374. kts.tv_sec = ktv.tv_sec;
  375. kts.tv_nsec = ktv.tv_usec * NSEC_PER_USEC;
  376. }
  377. if (tz) {
  378. if (copy_from_user(&ktz, tz, sizeof(ktz)))
  379. return -EFAULT;
  380. }
  381. return do_sys_settimeofday(tv ? &kts : NULL, tz ? &ktz : NULL);
  382. }
  383. struct sel_arg_struct {
  384. unsigned int n;
  385. unsigned int inp;
  386. unsigned int outp;
  387. unsigned int exp;
  388. unsigned int tvp;
  389. };
  390. asmlinkage long sys32_old_select(struct sel_arg_struct __user *arg)
  391. {
  392. struct sel_arg_struct a;
  393. if (copy_from_user(&a, arg, sizeof(a)))
  394. return -EFAULT;
  395. return compat_sys_select(a.n, compat_ptr(a.inp), compat_ptr(a.outp),
  396. compat_ptr(a.exp), compat_ptr(a.tvp));
  397. }
  398. asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int *stat_addr,
  399. int options)
  400. {
  401. return compat_sys_wait4(pid, stat_addr, options, NULL);
  402. }
  403. /* 32-bit timeval and related flotsam. */
  404. asmlinkage long sys32_sysfs(int option, u32 arg1, u32 arg2)
  405. {
  406. return sys_sysfs(option, arg1, arg2);
  407. }
  408. asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
  409. struct compat_timespec __user *interval)
  410. {
  411. struct timespec t;
  412. int ret;
  413. mm_segment_t old_fs = get_fs();
  414. set_fs(KERNEL_DS);
  415. ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
  416. set_fs(old_fs);
  417. if (put_compat_timespec(&t, interval))
  418. return -EFAULT;
  419. return ret;
  420. }
  421. asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
  422. compat_size_t sigsetsize)
  423. {
  424. sigset_t s;
  425. compat_sigset_t s32;
  426. int ret;
  427. mm_segment_t old_fs = get_fs();
  428. set_fs(KERNEL_DS);
  429. ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
  430. set_fs(old_fs);
  431. if (!ret) {
  432. switch (_NSIG_WORDS) {
  433. case 4: s32.sig[7] = (s.sig[3] >> 32); s32.sig[6] = s.sig[3];
  434. case 3: s32.sig[5] = (s.sig[2] >> 32); s32.sig[4] = s.sig[2];
  435. case 2: s32.sig[3] = (s.sig[1] >> 32); s32.sig[2] = s.sig[1];
  436. case 1: s32.sig[1] = (s.sig[0] >> 32); s32.sig[0] = s.sig[0];
  437. }
  438. if (copy_to_user(set, &s32, sizeof(compat_sigset_t)))
  439. return -EFAULT;
  440. }
  441. return ret;
  442. }
  443. asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
  444. compat_siginfo_t __user *uinfo)
  445. {
  446. siginfo_t info;
  447. int ret;
  448. mm_segment_t old_fs = get_fs();
  449. if (copy_siginfo_from_user32(&info, uinfo))
  450. return -EFAULT;
  451. set_fs(KERNEL_DS);
  452. ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
  453. set_fs(old_fs);
  454. return ret;
  455. }
  456. #ifdef CONFIG_SYSCTL_SYSCALL
  457. struct sysctl_ia32 {
  458. unsigned int name;
  459. int nlen;
  460. unsigned int oldval;
  461. unsigned int oldlenp;
  462. unsigned int newval;
  463. unsigned int newlen;
  464. unsigned int __unused[4];
  465. };
  466. asmlinkage long sys32_sysctl(struct sysctl_ia32 __user *args32)
  467. {
  468. struct sysctl_ia32 a32;
  469. mm_segment_t old_fs = get_fs();
  470. void __user *oldvalp, *newvalp;
  471. size_t oldlen;
  472. int __user *namep;
  473. long ret;
  474. if (copy_from_user(&a32, args32, sizeof(a32)))
  475. return -EFAULT;
  476. /*
  477. * We need to pre-validate these because we have to disable
  478. * address checking before calling do_sysctl() because of
  479. * OLDLEN but we can't run the risk of the user specifying bad
  480. * addresses here. Well, since we're dealing with 32 bit
  481. * addresses, we KNOW that access_ok() will always succeed, so
  482. * this is an expensive NOP, but so what...
  483. */
  484. namep = compat_ptr(a32.name);
  485. oldvalp = compat_ptr(a32.oldval);
  486. newvalp = compat_ptr(a32.newval);
  487. if ((oldvalp && get_user(oldlen, (int __user *)compat_ptr(a32.oldlenp)))
  488. || !access_ok(VERIFY_WRITE, namep, 0)
  489. || !access_ok(VERIFY_WRITE, oldvalp, 0)
  490. || !access_ok(VERIFY_WRITE, newvalp, 0))
  491. return -EFAULT;
  492. set_fs(KERNEL_DS);
  493. lock_kernel();
  494. ret = do_sysctl(namep, a32.nlen, oldvalp, (size_t __user *)&oldlen,
  495. newvalp, (size_t) a32.newlen);
  496. unlock_kernel();
  497. set_fs(old_fs);
  498. if (oldvalp && put_user(oldlen, (int __user *)compat_ptr(a32.oldlenp)))
  499. return -EFAULT;
  500. return ret;
  501. }
  502. #endif
  503. /* warning: next two assume little endian */
  504. asmlinkage long sys32_pread(unsigned int fd, char __user *ubuf, u32 count,
  505. u32 poslo, u32 poshi)
  506. {
  507. return sys_pread64(fd, ubuf, count,
  508. ((loff_t)AA(poshi) << 32) | AA(poslo));
  509. }
  510. asmlinkage long sys32_pwrite(unsigned int fd, char __user *ubuf, u32 count,
  511. u32 poslo, u32 poshi)
  512. {
  513. return sys_pwrite64(fd, ubuf, count,
  514. ((loff_t)AA(poshi) << 32) | AA(poslo));
  515. }
  516. asmlinkage long sys32_personality(unsigned long personality)
  517. {
  518. int ret;
  519. if (personality(current->personality) == PER_LINUX32 &&
  520. personality == PER_LINUX)
  521. personality = PER_LINUX32;
  522. ret = sys_personality(personality);
  523. if (ret == PER_LINUX32)
  524. ret = PER_LINUX;
  525. return ret;
  526. }
  527. asmlinkage long sys32_sendfile(int out_fd, int in_fd,
  528. compat_off_t __user *offset, s32 count)
  529. {
  530. mm_segment_t old_fs = get_fs();
  531. int ret;
  532. off_t of;
  533. if (offset && get_user(of, offset))
  534. return -EFAULT;
  535. set_fs(KERNEL_DS);
  536. ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
  537. count);
  538. set_fs(old_fs);
  539. if (offset && put_user(of, offset))
  540. return -EFAULT;
  541. return ret;
  542. }
  543. asmlinkage long sys32_mmap2(unsigned long addr, unsigned long len,
  544. unsigned long prot, unsigned long flags,
  545. unsigned long fd, unsigned long pgoff)
  546. {
  547. struct mm_struct *mm = current->mm;
  548. unsigned long error;
  549. struct file *file = NULL;
  550. flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
  551. if (!(flags & MAP_ANONYMOUS)) {
  552. file = fget(fd);
  553. if (!file)
  554. return -EBADF;
  555. }
  556. down_write(&mm->mmap_sem);
  557. error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
  558. up_write(&mm->mmap_sem);
  559. if (file)
  560. fput(file);
  561. return error;
  562. }
  563. asmlinkage long sys32_olduname(struct oldold_utsname __user *name)
  564. {
  565. char *arch = "x86_64";
  566. int err;
  567. if (!name)
  568. return -EFAULT;
  569. if (!access_ok(VERIFY_WRITE, name, sizeof(struct oldold_utsname)))
  570. return -EFAULT;
  571. down_read(&uts_sem);
  572. err = __copy_to_user(&name->sysname, &utsname()->sysname,
  573. __OLD_UTS_LEN);
  574. err |= __put_user(0, name->sysname+__OLD_UTS_LEN);
  575. err |= __copy_to_user(&name->nodename, &utsname()->nodename,
  576. __OLD_UTS_LEN);
  577. err |= __put_user(0, name->nodename+__OLD_UTS_LEN);
  578. err |= __copy_to_user(&name->release, &utsname()->release,
  579. __OLD_UTS_LEN);
  580. err |= __put_user(0, name->release+__OLD_UTS_LEN);
  581. err |= __copy_to_user(&name->version, &utsname()->version,
  582. __OLD_UTS_LEN);
  583. err |= __put_user(0, name->version+__OLD_UTS_LEN);
  584. if (personality(current->personality) == PER_LINUX32)
  585. arch = "i686";
  586. err |= __copy_to_user(&name->machine, arch, strlen(arch) + 1);
  587. up_read(&uts_sem);
  588. err = err ? -EFAULT : 0;
  589. return err;
  590. }
  591. long sys32_uname(struct old_utsname __user *name)
  592. {
  593. int err;
  594. if (!name)
  595. return -EFAULT;
  596. down_read(&uts_sem);
  597. err = copy_to_user(name, utsname(), sizeof(*name));
  598. up_read(&uts_sem);
  599. if (personality(current->personality) == PER_LINUX32)
  600. err |= copy_to_user(&name->machine, "i686", 5);
  601. return err ? -EFAULT : 0;
  602. }
  603. long sys32_ustat(unsigned dev, struct ustat32 __user *u32p)
  604. {
  605. struct ustat u;
  606. mm_segment_t seg;
  607. int ret;
  608. seg = get_fs();
  609. set_fs(KERNEL_DS);
  610. ret = sys_ustat(dev, (struct ustat __user *)&u);
  611. set_fs(seg);
  612. if (ret < 0)
  613. return ret;
  614. if (!access_ok(VERIFY_WRITE, u32p, sizeof(struct ustat32)) ||
  615. __put_user((__u32) u.f_tfree, &u32p->f_tfree) ||
  616. __put_user((__u32) u.f_tinode, &u32p->f_tfree) ||
  617. __copy_to_user(&u32p->f_fname, u.f_fname, sizeof(u.f_fname)) ||
  618. __copy_to_user(&u32p->f_fpack, u.f_fpack, sizeof(u.f_fpack)))
  619. ret = -EFAULT;
  620. return ret;
  621. }
  622. asmlinkage long sys32_execve(char __user *name, compat_uptr_t __user *argv,
  623. compat_uptr_t __user *envp, struct pt_regs *regs)
  624. {
  625. long error;
  626. char *filename;
  627. filename = getname(name);
  628. error = PTR_ERR(filename);
  629. if (IS_ERR(filename))
  630. return error;
  631. error = compat_do_execve(filename, argv, envp, regs);
  632. putname(filename);
  633. return error;
  634. }
  635. asmlinkage long sys32_clone(unsigned int clone_flags, unsigned int newsp,
  636. struct pt_regs *regs)
  637. {
  638. void __user *parent_tid = (void __user *)regs->dx;
  639. void __user *child_tid = (void __user *)regs->di;
  640. if (!newsp)
  641. newsp = regs->sp;
  642. return do_fork(clone_flags, newsp, regs, 0, parent_tid, child_tid);
  643. }
  644. /*
  645. * Some system calls that need sign extended arguments. This could be
  646. * done by a generic wrapper.
  647. */
  648. long sys32_lseek(unsigned int fd, int offset, unsigned int whence)
  649. {
  650. return sys_lseek(fd, offset, whence);
  651. }
  652. long sys32_kill(int pid, int sig)
  653. {
  654. return sys_kill(pid, sig);
  655. }
  656. long sys32_fadvise64_64(int fd, __u32 offset_low, __u32 offset_high,
  657. __u32 len_low, __u32 len_high, int advice)
  658. {
  659. return sys_fadvise64_64(fd,
  660. (((u64)offset_high)<<32) | offset_low,
  661. (((u64)len_high)<<32) | len_low,
  662. advice);
  663. }
  664. long sys32_vm86_warning(void)
  665. {
  666. struct task_struct *me = current;
  667. static char lastcomm[sizeof(me->comm)];
  668. if (strncmp(lastcomm, me->comm, sizeof(lastcomm))) {
  669. compat_printk(KERN_INFO
  670. "%s: vm86 mode not supported on 64 bit kernel\n",
  671. me->comm);
  672. strncpy(lastcomm, me->comm, sizeof(lastcomm));
  673. }
  674. return -ENOSYS;
  675. }
  676. long sys32_lookup_dcookie(u32 addr_low, u32 addr_high,
  677. char __user *buf, size_t len)
  678. {
  679. return sys_lookup_dcookie(((u64)addr_high << 32) | addr_low, buf, len);
  680. }
  681. asmlinkage ssize_t sys32_readahead(int fd, unsigned off_lo, unsigned off_hi,
  682. size_t count)
  683. {
  684. return sys_readahead(fd, ((u64)off_hi << 32) | off_lo, count);
  685. }
  686. asmlinkage long sys32_sync_file_range(int fd, unsigned off_low, unsigned off_hi,
  687. unsigned n_low, unsigned n_hi, int flags)
  688. {
  689. return sys_sync_file_range(fd,
  690. ((u64)off_hi << 32) | off_low,
  691. ((u64)n_hi << 32) | n_low, flags);
  692. }
  693. asmlinkage long sys32_fadvise64(int fd, unsigned offset_lo, unsigned offset_hi,
  694. size_t len, int advice)
  695. {
  696. return sys_fadvise64_64(fd, ((u64)offset_hi << 32) | offset_lo,
  697. len, advice);
  698. }
  699. asmlinkage long sys32_fallocate(int fd, int mode, unsigned offset_lo,
  700. unsigned offset_hi, unsigned len_lo,
  701. unsigned len_hi)
  702. {
  703. return sys_fallocate(fd, mode, ((u64)offset_hi << 32) | offset_lo,
  704. ((u64)len_hi << 32) | len_lo);
  705. }