sys_ia32.c 22 KB

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