sys_ia32.c 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050
  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/config.h>
  23. #include <linux/kernel.h>
  24. #include <linux/sched.h>
  25. #include <linux/fs.h>
  26. #include <linux/file.h>
  27. #include <linux/signal.h>
  28. #include <linux/syscalls.h>
  29. #include <linux/resource.h>
  30. #include <linux/times.h>
  31. #include <linux/utsname.h>
  32. #include <linux/timex.h>
  33. #include <linux/smp.h>
  34. #include <linux/smp_lock.h>
  35. #include <linux/sem.h>
  36. #include <linux/msg.h>
  37. #include <linux/mm.h>
  38. #include <linux/shm.h>
  39. #include <linux/slab.h>
  40. #include <linux/uio.h>
  41. #include <linux/nfs_fs.h>
  42. #include <linux/quota.h>
  43. #include <linux/module.h>
  44. #include <linux/sunrpc/svc.h>
  45. #include <linux/nfsd/nfsd.h>
  46. #include <linux/nfsd/cache.h>
  47. #include <linux/nfsd/xdr.h>
  48. #include <linux/nfsd/syscall.h>
  49. #include <linux/poll.h>
  50. #include <linux/personality.h>
  51. #include <linux/stat.h>
  52. #include <linux/ipc.h>
  53. #include <linux/rwsem.h>
  54. #include <linux/binfmts.h>
  55. #include <linux/init.h>
  56. #include <linux/aio_abi.h>
  57. #include <linux/aio.h>
  58. #include <linux/compat.h>
  59. #include <linux/vfs.h>
  60. #include <linux/ptrace.h>
  61. #include <linux/highuid.h>
  62. #include <linux/vmalloc.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. typeof(ubuf->st_uid) uid = 0;
  76. typeof(ubuf->st_gid) gid = 0;
  77. SET_UID(uid, kbuf->uid);
  78. SET_GID(gid, kbuf->gid);
  79. if (!old_valid_dev(kbuf->dev) || !old_valid_dev(kbuf->rdev))
  80. return -EOVERFLOW;
  81. if (kbuf->size >= 0x7fffffff)
  82. return -EOVERFLOW;
  83. if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct compat_stat)) ||
  84. __put_user (old_encode_dev(kbuf->dev), &ubuf->st_dev) ||
  85. __put_user (kbuf->ino, &ubuf->st_ino) ||
  86. __put_user (kbuf->mode, &ubuf->st_mode) ||
  87. __put_user (kbuf->nlink, &ubuf->st_nlink) ||
  88. __put_user (uid, &ubuf->st_uid) ||
  89. __put_user (gid, &ubuf->st_gid) ||
  90. __put_user (old_encode_dev(kbuf->rdev), &ubuf->st_rdev) ||
  91. __put_user (kbuf->size, &ubuf->st_size) ||
  92. __put_user (kbuf->atime.tv_sec, &ubuf->st_atime) ||
  93. __put_user (kbuf->atime.tv_nsec, &ubuf->st_atime_nsec) ||
  94. __put_user (kbuf->mtime.tv_sec, &ubuf->st_mtime) ||
  95. __put_user (kbuf->mtime.tv_nsec, &ubuf->st_mtime_nsec) ||
  96. __put_user (kbuf->ctime.tv_sec, &ubuf->st_ctime) ||
  97. __put_user (kbuf->ctime.tv_nsec, &ubuf->st_ctime_nsec) ||
  98. __put_user (kbuf->blksize, &ubuf->st_blksize) ||
  99. __put_user (kbuf->blocks, &ubuf->st_blocks))
  100. return -EFAULT;
  101. return 0;
  102. }
  103. asmlinkage long
  104. sys32_truncate64(char __user * filename, unsigned long offset_low, unsigned long offset_high)
  105. {
  106. return sys_truncate(filename, ((loff_t) offset_high << 32) | offset_low);
  107. }
  108. asmlinkage long
  109. sys32_ftruncate64(unsigned int fd, unsigned long offset_low, unsigned long offset_high)
  110. {
  111. return sys_ftruncate(fd, ((loff_t) offset_high << 32) | offset_low);
  112. }
  113. /* Another set for IA32/LFS -- x86_64 struct stat is different due to
  114. support for 64bit inode numbers. */
  115. static int
  116. cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
  117. {
  118. typeof(ubuf->st_uid) uid = 0;
  119. typeof(ubuf->st_gid) gid = 0;
  120. SET_UID(uid, stat->uid);
  121. SET_GID(gid, stat->gid);
  122. if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
  123. __put_user(huge_encode_dev(stat->dev), &ubuf->st_dev) ||
  124. __put_user (stat->ino, &ubuf->__st_ino) ||
  125. __put_user (stat->ino, &ubuf->st_ino) ||
  126. __put_user (stat->mode, &ubuf->st_mode) ||
  127. __put_user (stat->nlink, &ubuf->st_nlink) ||
  128. __put_user (uid, &ubuf->st_uid) ||
  129. __put_user (gid, &ubuf->st_gid) ||
  130. __put_user (huge_encode_dev(stat->rdev), &ubuf->st_rdev) ||
  131. __put_user (stat->size, &ubuf->st_size) ||
  132. __put_user (stat->atime.tv_sec, &ubuf->st_atime) ||
  133. __put_user (stat->atime.tv_nsec, &ubuf->st_atime_nsec) ||
  134. __put_user (stat->mtime.tv_sec, &ubuf->st_mtime) ||
  135. __put_user (stat->mtime.tv_nsec, &ubuf->st_mtime_nsec) ||
  136. __put_user (stat->ctime.tv_sec, &ubuf->st_ctime) ||
  137. __put_user (stat->ctime.tv_nsec, &ubuf->st_ctime_nsec) ||
  138. __put_user (stat->blksize, &ubuf->st_blksize) ||
  139. __put_user (stat->blocks, &ubuf->st_blocks))
  140. return -EFAULT;
  141. return 0;
  142. }
  143. asmlinkage long
  144. sys32_stat64(char __user * filename, struct stat64 __user *statbuf)
  145. {
  146. struct kstat stat;
  147. int ret = vfs_stat(filename, &stat);
  148. if (!ret)
  149. ret = cp_stat64(statbuf, &stat);
  150. return ret;
  151. }
  152. asmlinkage long
  153. sys32_lstat64(char __user * filename, struct stat64 __user *statbuf)
  154. {
  155. struct kstat stat;
  156. int ret = vfs_lstat(filename, &stat);
  157. if (!ret)
  158. ret = cp_stat64(statbuf, &stat);
  159. return ret;
  160. }
  161. asmlinkage long
  162. sys32_fstat64(unsigned int fd, struct stat64 __user *statbuf)
  163. {
  164. struct kstat stat;
  165. int ret = vfs_fstat(fd, &stat);
  166. if (!ret)
  167. ret = cp_stat64(statbuf, &stat);
  168. return ret;
  169. }
  170. /*
  171. * Linux/i386 didn't use to be able to handle more than
  172. * 4 system call parameters, so these system calls used a memory
  173. * block for parameter passing..
  174. */
  175. struct mmap_arg_struct {
  176. unsigned int addr;
  177. unsigned int len;
  178. unsigned int prot;
  179. unsigned int flags;
  180. unsigned int fd;
  181. unsigned int offset;
  182. };
  183. asmlinkage long
  184. sys32_mmap(struct mmap_arg_struct __user *arg)
  185. {
  186. struct mmap_arg_struct a;
  187. struct file *file = NULL;
  188. unsigned long retval;
  189. struct mm_struct *mm ;
  190. if (copy_from_user(&a, arg, sizeof(a)))
  191. return -EFAULT;
  192. if (a.offset & ~PAGE_MASK)
  193. return -EINVAL;
  194. if (!(a.flags & MAP_ANONYMOUS)) {
  195. file = fget(a.fd);
  196. if (!file)
  197. return -EBADF;
  198. }
  199. mm = current->mm;
  200. down_write(&mm->mmap_sem);
  201. retval = do_mmap_pgoff(file, a.addr, a.len, a.prot, a.flags, a.offset>>PAGE_SHIFT);
  202. if (file)
  203. fput(file);
  204. up_write(&mm->mmap_sem);
  205. return retval;
  206. }
  207. asmlinkage long
  208. sys32_mprotect(unsigned long start, size_t len, unsigned long prot)
  209. {
  210. return sys_mprotect(start,len,prot);
  211. }
  212. asmlinkage long
  213. sys32_pipe(int __user *fd)
  214. {
  215. int retval;
  216. int fds[2];
  217. retval = do_pipe(fds);
  218. if (retval)
  219. goto out;
  220. if (copy_to_user(fd, fds, sizeof(fds)))
  221. retval = -EFAULT;
  222. out:
  223. return retval;
  224. }
  225. asmlinkage long
  226. sys32_rt_sigaction(int sig, struct sigaction32 __user *act,
  227. struct sigaction32 __user *oact, unsigned int sigsetsize)
  228. {
  229. struct k_sigaction new_ka, old_ka;
  230. int ret;
  231. compat_sigset_t set32;
  232. /* XXX: Don't preclude handling different sized sigset_t's. */
  233. if (sigsetsize != sizeof(compat_sigset_t))
  234. return -EINVAL;
  235. if (act) {
  236. compat_uptr_t handler, restorer;
  237. if (!access_ok(VERIFY_READ, act, sizeof(*act)) ||
  238. __get_user(handler, &act->sa_handler) ||
  239. __get_user(new_ka.sa.sa_flags, &act->sa_flags) ||
  240. __get_user(restorer, &act->sa_restorer)||
  241. __copy_from_user(&set32, &act->sa_mask, sizeof(compat_sigset_t)))
  242. return -EFAULT;
  243. new_ka.sa.sa_handler = compat_ptr(handler);
  244. new_ka.sa.sa_restorer = compat_ptr(restorer);
  245. /* FIXME: here we rely on _COMPAT_NSIG_WORS to be >= than _NSIG_WORDS << 1 */
  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. /* FIXME: here we rely on _COMPAT_NSIG_WORS to be >= than _NSIG_WORDS << 1 */
  260. switch (_NSIG_WORDS) {
  261. case 4:
  262. set32.sig[7] = (old_ka.sa.sa_mask.sig[3] >> 32);
  263. set32.sig[6] = old_ka.sa.sa_mask.sig[3];
  264. case 3:
  265. set32.sig[5] = (old_ka.sa.sa_mask.sig[2] >> 32);
  266. set32.sig[4] = old_ka.sa.sa_mask.sig[2];
  267. case 2:
  268. set32.sig[3] = (old_ka.sa.sa_mask.sig[1] >> 32);
  269. set32.sig[2] = old_ka.sa.sa_mask.sig[1];
  270. case 1:
  271. set32.sig[1] = (old_ka.sa.sa_mask.sig[0] >> 32);
  272. set32.sig[0] = old_ka.sa.sa_mask.sig[0];
  273. }
  274. if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) ||
  275. __put_user(ptr_to_compat(old_ka.sa.sa_handler), &oact->sa_handler) ||
  276. __put_user(ptr_to_compat(old_ka.sa.sa_restorer), &oact->sa_restorer) ||
  277. __put_user(old_ka.sa.sa_flags, &oact->sa_flags) ||
  278. __copy_to_user(&oact->sa_mask, &set32, sizeof(compat_sigset_t)))
  279. return -EFAULT;
  280. }
  281. return ret;
  282. }
  283. asmlinkage long
  284. sys32_sigaction (int sig, struct old_sigaction32 __user *act, struct old_sigaction32 __user *oact)
  285. {
  286. struct k_sigaction new_ka, old_ka;
  287. int ret;
  288. if (act) {
  289. compat_old_sigset_t mask;
  290. compat_uptr_t handler, restorer;
  291. if (!access_ok(VERIFY_READ, act, sizeof(*act)) ||
  292. __get_user(handler, &act->sa_handler) ||
  293. __get_user(new_ka.sa.sa_flags, &act->sa_flags) ||
  294. __get_user(restorer, &act->sa_restorer) ||
  295. __get_user(mask, &act->sa_mask))
  296. return -EFAULT;
  297. new_ka.sa.sa_handler = compat_ptr(handler);
  298. new_ka.sa.sa_restorer = compat_ptr(restorer);
  299. siginitset(&new_ka.sa.sa_mask, mask);
  300. }
  301. ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
  302. if (!ret && oact) {
  303. if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) ||
  304. __put_user(ptr_to_compat(old_ka.sa.sa_handler), &oact->sa_handler) ||
  305. __put_user(ptr_to_compat(old_ka.sa.sa_restorer), &oact->sa_restorer) ||
  306. __put_user(old_ka.sa.sa_flags, &oact->sa_flags) ||
  307. __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask))
  308. return -EFAULT;
  309. }
  310. return ret;
  311. }
  312. asmlinkage long
  313. sys32_rt_sigprocmask(int how, compat_sigset_t __user *set,
  314. compat_sigset_t __user *oset, unsigned int sigsetsize)
  315. {
  316. sigset_t s;
  317. compat_sigset_t s32;
  318. int ret;
  319. mm_segment_t old_fs = get_fs();
  320. if (set) {
  321. if (copy_from_user (&s32, set, sizeof(compat_sigset_t)))
  322. return -EFAULT;
  323. switch (_NSIG_WORDS) {
  324. case 4: s.sig[3] = s32.sig[6] | (((long)s32.sig[7]) << 32);
  325. case 3: s.sig[2] = s32.sig[4] | (((long)s32.sig[5]) << 32);
  326. case 2: s.sig[1] = s32.sig[2] | (((long)s32.sig[3]) << 32);
  327. case 1: s.sig[0] = s32.sig[0] | (((long)s32.sig[1]) << 32);
  328. }
  329. }
  330. set_fs (KERNEL_DS);
  331. ret = sys_rt_sigprocmask(how, set ? &s : NULL, oset ? &s : NULL,
  332. sigsetsize);
  333. set_fs (old_fs);
  334. if (ret) return ret;
  335. if (oset) {
  336. switch (_NSIG_WORDS) {
  337. case 4: s32.sig[7] = (s.sig[3] >> 32); s32.sig[6] = s.sig[3];
  338. case 3: s32.sig[5] = (s.sig[2] >> 32); s32.sig[4] = s.sig[2];
  339. case 2: s32.sig[3] = (s.sig[1] >> 32); s32.sig[2] = s.sig[1];
  340. case 1: s32.sig[1] = (s.sig[0] >> 32); s32.sig[0] = s.sig[0];
  341. }
  342. if (copy_to_user (oset, &s32, sizeof(compat_sigset_t)))
  343. return -EFAULT;
  344. }
  345. return 0;
  346. }
  347. static inline long
  348. get_tv32(struct timeval *o, struct compat_timeval __user *i)
  349. {
  350. int err = -EFAULT;
  351. if (access_ok(VERIFY_READ, i, sizeof(*i))) {
  352. err = __get_user(o->tv_sec, &i->tv_sec);
  353. err |= __get_user(o->tv_usec, &i->tv_usec);
  354. }
  355. return err;
  356. }
  357. static inline long
  358. put_tv32(struct compat_timeval __user *o, struct timeval *i)
  359. {
  360. int err = -EFAULT;
  361. if (access_ok(VERIFY_WRITE, o, sizeof(*o))) {
  362. err = __put_user(i->tv_sec, &o->tv_sec);
  363. err |= __put_user(i->tv_usec, &o->tv_usec);
  364. }
  365. return err;
  366. }
  367. extern int do_setitimer(int which, struct itimerval *, struct itimerval *);
  368. asmlinkage long
  369. sys32_alarm(unsigned int seconds)
  370. {
  371. struct itimerval it_new, it_old;
  372. unsigned int oldalarm;
  373. it_new.it_interval.tv_sec = it_new.it_interval.tv_usec = 0;
  374. it_new.it_value.tv_sec = seconds;
  375. it_new.it_value.tv_usec = 0;
  376. do_setitimer(ITIMER_REAL, &it_new, &it_old);
  377. oldalarm = it_old.it_value.tv_sec;
  378. /* ehhh.. We can't return 0 if we have an alarm pending.. */
  379. /* And we'd better return too much than too little anyway */
  380. if (it_old.it_value.tv_usec)
  381. oldalarm++;
  382. return oldalarm;
  383. }
  384. /* Translations due to time_t size differences. Which affects all
  385. sorts of things, like timeval and itimerval. */
  386. extern struct timezone sys_tz;
  387. asmlinkage long
  388. sys32_gettimeofday(struct compat_timeval __user *tv, struct timezone __user *tz)
  389. {
  390. if (tv) {
  391. struct timeval ktv;
  392. do_gettimeofday(&ktv);
  393. if (put_tv32(tv, &ktv))
  394. return -EFAULT;
  395. }
  396. if (tz) {
  397. if (copy_to_user(tz, &sys_tz, sizeof(sys_tz)))
  398. return -EFAULT;
  399. }
  400. return 0;
  401. }
  402. asmlinkage long
  403. sys32_settimeofday(struct compat_timeval __user *tv, struct timezone __user *tz)
  404. {
  405. struct timeval ktv;
  406. struct timespec kts;
  407. struct timezone ktz;
  408. if (tv) {
  409. if (get_tv32(&ktv, tv))
  410. return -EFAULT;
  411. kts.tv_sec = ktv.tv_sec;
  412. kts.tv_nsec = ktv.tv_usec * NSEC_PER_USEC;
  413. }
  414. if (tz) {
  415. if (copy_from_user(&ktz, tz, sizeof(ktz)))
  416. return -EFAULT;
  417. }
  418. return do_sys_settimeofday(tv ? &kts : NULL, tz ? &ktz : NULL);
  419. }
  420. struct sel_arg_struct {
  421. unsigned int n;
  422. unsigned int inp;
  423. unsigned int outp;
  424. unsigned int exp;
  425. unsigned int tvp;
  426. };
  427. asmlinkage long
  428. sys32_old_select(struct sel_arg_struct __user *arg)
  429. {
  430. struct sel_arg_struct a;
  431. if (copy_from_user(&a, arg, sizeof(a)))
  432. return -EFAULT;
  433. return compat_sys_select(a.n, compat_ptr(a.inp), compat_ptr(a.outp),
  434. compat_ptr(a.exp), compat_ptr(a.tvp));
  435. }
  436. extern asmlinkage long
  437. compat_sys_wait4(compat_pid_t pid, compat_uint_t * stat_addr, int options,
  438. struct compat_rusage *ru);
  439. asmlinkage long
  440. sys32_waitpid(compat_pid_t pid, unsigned int *stat_addr, int options)
  441. {
  442. return compat_sys_wait4(pid, stat_addr, options, NULL);
  443. }
  444. int sys32_ni_syscall(int call)
  445. {
  446. struct task_struct *me = current;
  447. static char lastcomm[sizeof(me->comm)];
  448. if (strncmp(lastcomm, me->comm, sizeof(lastcomm))) {
  449. printk(KERN_INFO "IA32 syscall %d from %s not implemented\n",
  450. call, me->comm);
  451. strncpy(lastcomm, me->comm, sizeof(lastcomm));
  452. }
  453. return -ENOSYS;
  454. }
  455. /* 32-bit timeval and related flotsam. */
  456. asmlinkage long
  457. sys32_sysfs(int option, u32 arg1, u32 arg2)
  458. {
  459. return sys_sysfs(option, arg1, arg2);
  460. }
  461. struct sysinfo32 {
  462. s32 uptime;
  463. u32 loads[3];
  464. u32 totalram;
  465. u32 freeram;
  466. u32 sharedram;
  467. u32 bufferram;
  468. u32 totalswap;
  469. u32 freeswap;
  470. unsigned short procs;
  471. unsigned short pad;
  472. u32 totalhigh;
  473. u32 freehigh;
  474. u32 mem_unit;
  475. char _f[20-2*sizeof(u32)-sizeof(int)];
  476. };
  477. asmlinkage long
  478. sys32_sysinfo(struct sysinfo32 __user *info)
  479. {
  480. struct sysinfo s;
  481. int ret;
  482. mm_segment_t old_fs = get_fs ();
  483. int bitcount = 0;
  484. set_fs (KERNEL_DS);
  485. ret = sys_sysinfo(&s);
  486. set_fs (old_fs);
  487. /* Check to see if any memory value is too large for 32-bit and scale
  488. * down if needed
  489. */
  490. if ((s.totalram >> 32) || (s.totalswap >> 32)) {
  491. while (s.mem_unit < PAGE_SIZE) {
  492. s.mem_unit <<= 1;
  493. bitcount++;
  494. }
  495. s.totalram >>= bitcount;
  496. s.freeram >>= bitcount;
  497. s.sharedram >>= bitcount;
  498. s.bufferram >>= bitcount;
  499. s.totalswap >>= bitcount;
  500. s.freeswap >>= bitcount;
  501. s.totalhigh >>= bitcount;
  502. s.freehigh >>= bitcount;
  503. }
  504. if (!access_ok(VERIFY_WRITE, info, sizeof(struct sysinfo32)) ||
  505. __put_user (s.uptime, &info->uptime) ||
  506. __put_user (s.loads[0], &info->loads[0]) ||
  507. __put_user (s.loads[1], &info->loads[1]) ||
  508. __put_user (s.loads[2], &info->loads[2]) ||
  509. __put_user (s.totalram, &info->totalram) ||
  510. __put_user (s.freeram, &info->freeram) ||
  511. __put_user (s.sharedram, &info->sharedram) ||
  512. __put_user (s.bufferram, &info->bufferram) ||
  513. __put_user (s.totalswap, &info->totalswap) ||
  514. __put_user (s.freeswap, &info->freeswap) ||
  515. __put_user (s.procs, &info->procs) ||
  516. __put_user (s.totalhigh, &info->totalhigh) ||
  517. __put_user (s.freehigh, &info->freehigh) ||
  518. __put_user (s.mem_unit, &info->mem_unit))
  519. return -EFAULT;
  520. return 0;
  521. }
  522. asmlinkage long
  523. sys32_sched_rr_get_interval(compat_pid_t pid, struct compat_timespec __user *interval)
  524. {
  525. struct timespec t;
  526. int ret;
  527. mm_segment_t old_fs = get_fs ();
  528. set_fs (KERNEL_DS);
  529. ret = sys_sched_rr_get_interval(pid, &t);
  530. set_fs (old_fs);
  531. if (put_compat_timespec(&t, interval))
  532. return -EFAULT;
  533. return ret;
  534. }
  535. asmlinkage long
  536. sys32_rt_sigpending(compat_sigset_t __user *set, compat_size_t sigsetsize)
  537. {
  538. sigset_t s;
  539. compat_sigset_t s32;
  540. int ret;
  541. mm_segment_t old_fs = get_fs();
  542. set_fs (KERNEL_DS);
  543. ret = sys_rt_sigpending(&s, sigsetsize);
  544. set_fs (old_fs);
  545. if (!ret) {
  546. switch (_NSIG_WORDS) {
  547. case 4: s32.sig[7] = (s.sig[3] >> 32); s32.sig[6] = s.sig[3];
  548. case 3: s32.sig[5] = (s.sig[2] >> 32); s32.sig[4] = s.sig[2];
  549. case 2: s32.sig[3] = (s.sig[1] >> 32); s32.sig[2] = s.sig[1];
  550. case 1: s32.sig[1] = (s.sig[0] >> 32); s32.sig[0] = s.sig[0];
  551. }
  552. if (copy_to_user (set, &s32, sizeof(compat_sigset_t)))
  553. return -EFAULT;
  554. }
  555. return ret;
  556. }
  557. asmlinkage long
  558. sys32_rt_sigqueueinfo(int pid, int sig, compat_siginfo_t __user *uinfo)
  559. {
  560. siginfo_t info;
  561. int ret;
  562. mm_segment_t old_fs = get_fs();
  563. if (copy_siginfo_from_user32(&info, uinfo))
  564. return -EFAULT;
  565. set_fs (KERNEL_DS);
  566. ret = sys_rt_sigqueueinfo(pid, sig, &info);
  567. set_fs (old_fs);
  568. return ret;
  569. }
  570. /* These are here just in case some old ia32 binary calls it. */
  571. asmlinkage long
  572. sys32_pause(void)
  573. {
  574. current->state = TASK_INTERRUPTIBLE;
  575. schedule();
  576. return -ERESTARTNOHAND;
  577. }
  578. #ifdef CONFIG_SYSCTL
  579. struct sysctl_ia32 {
  580. unsigned int name;
  581. int nlen;
  582. unsigned int oldval;
  583. unsigned int oldlenp;
  584. unsigned int newval;
  585. unsigned int newlen;
  586. unsigned int __unused[4];
  587. };
  588. asmlinkage long
  589. sys32_sysctl(struct sysctl_ia32 __user *args32)
  590. {
  591. struct sysctl_ia32 a32;
  592. mm_segment_t old_fs = get_fs ();
  593. void __user *oldvalp, *newvalp;
  594. size_t oldlen;
  595. int __user *namep;
  596. long ret;
  597. extern int do_sysctl(int *name, int nlen, void *oldval, size_t *oldlenp,
  598. void *newval, size_t newlen);
  599. if (copy_from_user(&a32, args32, sizeof (a32)))
  600. return -EFAULT;
  601. /*
  602. * We need to pre-validate these because we have to disable address checking
  603. * before calling do_sysctl() because of OLDLEN but we can't run the risk of the
  604. * user specifying bad addresses here. Well, since we're dealing with 32 bit
  605. * addresses, we KNOW that access_ok() will always succeed, so this is an
  606. * expensive NOP, but so what...
  607. */
  608. namep = compat_ptr(a32.name);
  609. oldvalp = compat_ptr(a32.oldval);
  610. newvalp = compat_ptr(a32.newval);
  611. if ((oldvalp && get_user(oldlen, (int __user *)compat_ptr(a32.oldlenp)))
  612. || !access_ok(VERIFY_WRITE, namep, 0)
  613. || !access_ok(VERIFY_WRITE, oldvalp, 0)
  614. || !access_ok(VERIFY_WRITE, newvalp, 0))
  615. return -EFAULT;
  616. set_fs(KERNEL_DS);
  617. lock_kernel();
  618. ret = do_sysctl(namep, a32.nlen, oldvalp, &oldlen, 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 ? &of : NULL, count);
  661. set_fs(old_fs);
  662. if (!ret && offset && put_user(of, offset))
  663. return -EFAULT;
  664. return ret;
  665. }
  666. /* Handle adjtimex compatibility. */
  667. struct timex32 {
  668. u32 modes;
  669. s32 offset, freq, maxerror, esterror;
  670. s32 status, constant, precision, tolerance;
  671. struct compat_timeval time;
  672. s32 tick;
  673. s32 ppsfreq, jitter, shift, stabil;
  674. s32 jitcnt, calcnt, errcnt, stbcnt;
  675. s32 :32; s32 :32; s32 :32; s32 :32;
  676. s32 :32; s32 :32; s32 :32; s32 :32;
  677. s32 :32; s32 :32; s32 :32; s32 :32;
  678. };
  679. extern int do_adjtimex(struct timex *);
  680. asmlinkage long
  681. sys32_adjtimex(struct timex32 __user *utp)
  682. {
  683. struct timex txc;
  684. int ret;
  685. memset(&txc, 0, sizeof(struct timex));
  686. if (!access_ok(VERIFY_READ, utp, sizeof(struct timex32)) ||
  687. __get_user(txc.modes, &utp->modes) ||
  688. __get_user(txc.offset, &utp->offset) ||
  689. __get_user(txc.freq, &utp->freq) ||
  690. __get_user(txc.maxerror, &utp->maxerror) ||
  691. __get_user(txc.esterror, &utp->esterror) ||
  692. __get_user(txc.status, &utp->status) ||
  693. __get_user(txc.constant, &utp->constant) ||
  694. __get_user(txc.precision, &utp->precision) ||
  695. __get_user(txc.tolerance, &utp->tolerance) ||
  696. __get_user(txc.time.tv_sec, &utp->time.tv_sec) ||
  697. __get_user(txc.time.tv_usec, &utp->time.tv_usec) ||
  698. __get_user(txc.tick, &utp->tick) ||
  699. __get_user(txc.ppsfreq, &utp->ppsfreq) ||
  700. __get_user(txc.jitter, &utp->jitter) ||
  701. __get_user(txc.shift, &utp->shift) ||
  702. __get_user(txc.stabil, &utp->stabil) ||
  703. __get_user(txc.jitcnt, &utp->jitcnt) ||
  704. __get_user(txc.calcnt, &utp->calcnt) ||
  705. __get_user(txc.errcnt, &utp->errcnt) ||
  706. __get_user(txc.stbcnt, &utp->stbcnt))
  707. return -EFAULT;
  708. ret = do_adjtimex(&txc);
  709. if (!access_ok(VERIFY_WRITE, utp, sizeof(struct timex32)) ||
  710. __put_user(txc.modes, &utp->modes) ||
  711. __put_user(txc.offset, &utp->offset) ||
  712. __put_user(txc.freq, &utp->freq) ||
  713. __put_user(txc.maxerror, &utp->maxerror) ||
  714. __put_user(txc.esterror, &utp->esterror) ||
  715. __put_user(txc.status, &utp->status) ||
  716. __put_user(txc.constant, &utp->constant) ||
  717. __put_user(txc.precision, &utp->precision) ||
  718. __put_user(txc.tolerance, &utp->tolerance) ||
  719. __put_user(txc.time.tv_sec, &utp->time.tv_sec) ||
  720. __put_user(txc.time.tv_usec, &utp->time.tv_usec) ||
  721. __put_user(txc.tick, &utp->tick) ||
  722. __put_user(txc.ppsfreq, &utp->ppsfreq) ||
  723. __put_user(txc.jitter, &utp->jitter) ||
  724. __put_user(txc.shift, &utp->shift) ||
  725. __put_user(txc.stabil, &utp->stabil) ||
  726. __put_user(txc.jitcnt, &utp->jitcnt) ||
  727. __put_user(txc.calcnt, &utp->calcnt) ||
  728. __put_user(txc.errcnt, &utp->errcnt) ||
  729. __put_user(txc.stbcnt, &utp->stbcnt))
  730. ret = -EFAULT;
  731. return ret;
  732. }
  733. asmlinkage long sys32_mmap2(unsigned long addr, unsigned long len,
  734. unsigned long prot, unsigned long flags,
  735. unsigned long fd, unsigned long pgoff)
  736. {
  737. struct mm_struct *mm = current->mm;
  738. unsigned long error;
  739. struct file * file = NULL;
  740. flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
  741. if (!(flags & MAP_ANONYMOUS)) {
  742. file = fget(fd);
  743. if (!file)
  744. return -EBADF;
  745. }
  746. down_write(&mm->mmap_sem);
  747. error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
  748. up_write(&mm->mmap_sem);
  749. if (file)
  750. fput(file);
  751. return error;
  752. }
  753. asmlinkage long sys32_olduname(struct oldold_utsname __user * name)
  754. {
  755. int error;
  756. if (!name)
  757. return -EFAULT;
  758. if (!access_ok(VERIFY_WRITE,name,sizeof(struct oldold_utsname)))
  759. return -EFAULT;
  760. down_read(&uts_sem);
  761. error = __copy_to_user(&name->sysname,&system_utsname.sysname,__OLD_UTS_LEN);
  762. __put_user(0,name->sysname+__OLD_UTS_LEN);
  763. __copy_to_user(&name->nodename,&system_utsname.nodename,__OLD_UTS_LEN);
  764. __put_user(0,name->nodename+__OLD_UTS_LEN);
  765. __copy_to_user(&name->release,&system_utsname.release,__OLD_UTS_LEN);
  766. __put_user(0,name->release+__OLD_UTS_LEN);
  767. __copy_to_user(&name->version,&system_utsname.version,__OLD_UTS_LEN);
  768. __put_user(0,name->version+__OLD_UTS_LEN);
  769. {
  770. char *arch = "x86_64";
  771. if (personality(current->personality) == PER_LINUX32)
  772. arch = "i686";
  773. __copy_to_user(&name->machine,arch,strlen(arch)+1);
  774. }
  775. up_read(&uts_sem);
  776. error = error ? -EFAULT : 0;
  777. return error;
  778. }
  779. long sys32_uname(struct old_utsname __user * name)
  780. {
  781. int err;
  782. if (!name)
  783. return -EFAULT;
  784. down_read(&uts_sem);
  785. err=copy_to_user(name, &system_utsname, sizeof (*name));
  786. up_read(&uts_sem);
  787. if (personality(current->personality) == PER_LINUX32)
  788. err |= copy_to_user(&name->machine, "i686", 5);
  789. return err?-EFAULT:0;
  790. }
  791. long sys32_ustat(unsigned dev, struct ustat32 __user *u32p)
  792. {
  793. struct ustat u;
  794. mm_segment_t seg;
  795. int ret;
  796. seg = get_fs();
  797. set_fs(KERNEL_DS);
  798. ret = sys_ustat(dev,&u);
  799. set_fs(seg);
  800. if (ret >= 0) {
  801. if (!access_ok(VERIFY_WRITE,u32p,sizeof(struct ustat32)) ||
  802. __put_user((__u32) u.f_tfree, &u32p->f_tfree) ||
  803. __put_user((__u32) u.f_tinode, &u32p->f_tfree) ||
  804. __copy_to_user(&u32p->f_fname, u.f_fname, sizeof(u.f_fname)) ||
  805. __copy_to_user(&u32p->f_fpack, u.f_fpack, sizeof(u.f_fpack)))
  806. ret = -EFAULT;
  807. }
  808. return ret;
  809. }
  810. asmlinkage long sys32_execve(char __user *name, compat_uptr_t __user *argv,
  811. compat_uptr_t __user *envp, struct pt_regs *regs)
  812. {
  813. long error;
  814. char * filename;
  815. filename = getname(name);
  816. error = PTR_ERR(filename);
  817. if (IS_ERR(filename))
  818. return error;
  819. error = compat_do_execve(filename, argv, envp, regs);
  820. if (error == 0) {
  821. task_lock(current);
  822. current->ptrace &= ~PT_DTRACE;
  823. task_unlock(current);
  824. }
  825. putname(filename);
  826. return error;
  827. }
  828. asmlinkage long sys32_clone(unsigned int clone_flags, unsigned int newsp,
  829. struct pt_regs *regs)
  830. {
  831. void __user *parent_tid = (void __user *)regs->rdx;
  832. void __user *child_tid = (void __user *)regs->rdi;
  833. if (!newsp)
  834. newsp = regs->rsp;
  835. return do_fork(clone_flags, newsp, regs, 0, parent_tid, child_tid);
  836. }
  837. /*
  838. * Some system calls that need sign extended arguments. This could be done by a generic wrapper.
  839. */
  840. long sys32_lseek (unsigned int fd, int offset, unsigned int whence)
  841. {
  842. return sys_lseek(fd, offset, whence);
  843. }
  844. long sys32_kill(int pid, int sig)
  845. {
  846. return sys_kill(pid, sig);
  847. }
  848. asmlinkage long sys32_open(const char __user * filename, int flags, int mode)
  849. {
  850. char * tmp;
  851. int fd, error;
  852. /* don't force O_LARGEFILE */
  853. tmp = getname(filename);
  854. fd = PTR_ERR(tmp);
  855. if (!IS_ERR(tmp)) {
  856. fd = get_unused_fd();
  857. if (fd >= 0) {
  858. struct file *f = filp_open(tmp, flags, mode);
  859. error = PTR_ERR(f);
  860. if (IS_ERR(f)) {
  861. put_unused_fd(fd);
  862. fd = error;
  863. } else
  864. fd_install(fd, f);
  865. }
  866. putname(tmp);
  867. }
  868. return fd;
  869. }
  870. extern asmlinkage long
  871. sys_timer_create(clockid_t which_clock,
  872. struct sigevent __user *timer_event_spec,
  873. timer_t __user * created_timer_id);
  874. long
  875. sys32_timer_create(u32 clock, struct compat_sigevent __user *se32, timer_t __user *timer_id)
  876. {
  877. struct sigevent __user *p = NULL;
  878. if (se32) {
  879. struct sigevent se;
  880. p = compat_alloc_user_space(sizeof(struct sigevent));
  881. if (get_compat_sigevent(&se, se32) ||
  882. copy_to_user(p, &se, sizeof(se)))
  883. return -EFAULT;
  884. }
  885. return sys_timer_create(clock, p, timer_id);
  886. }
  887. long sys32_fadvise64_64(int fd, __u32 offset_low, __u32 offset_high,
  888. __u32 len_low, __u32 len_high, int advice)
  889. {
  890. return sys_fadvise64_64(fd,
  891. (((u64)offset_high)<<32) | offset_low,
  892. (((u64)len_high)<<32) | len_low,
  893. advice);
  894. }
  895. long sys32_vm86_warning(void)
  896. {
  897. struct task_struct *me = current;
  898. static char lastcomm[sizeof(me->comm)];
  899. if (strncmp(lastcomm, me->comm, sizeof(lastcomm))) {
  900. printk(KERN_INFO "%s: vm86 mode not supported on 64 bit kernel\n",
  901. me->comm);
  902. strncpy(lastcomm, me->comm, sizeof(lastcomm));
  903. }
  904. return -ENOSYS;
  905. }
  906. long sys32_lookup_dcookie(u32 addr_low, u32 addr_high,
  907. char __user * buf, size_t len)
  908. {
  909. return sys_lookup_dcookie(((u64)addr_high << 32) | addr_low, buf, len);
  910. }
  911. static int __init ia32_init (void)
  912. {
  913. printk("IA32 emulation $Id: sys_ia32.c,v 1.32 2002/03/24 13:02:28 ak Exp $\n");
  914. return 0;
  915. }
  916. __initcall(ia32_init);
  917. extern unsigned long ia32_sys_call_table[];
  918. EXPORT_SYMBOL(ia32_sys_call_table);