sys_ia32.c 22 KB

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