sys_ia32.c 23 KB

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