sys_ia32.c 27 KB

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