sys_ia32.c 24 KB

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