sys_ia32.c 28 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027
  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. /*
  172. * Linux/i386 didn't use to be able to handle more than
  173. * 4 system call parameters, so these system calls used a memory
  174. * block for parameter passing..
  175. */
  176. struct mmap_arg_struct {
  177. unsigned int addr;
  178. unsigned int len;
  179. unsigned int prot;
  180. unsigned int flags;
  181. unsigned int fd;
  182. unsigned int offset;
  183. };
  184. asmlinkage long
  185. sys32_mmap(struct mmap_arg_struct __user *arg)
  186. {
  187. struct mmap_arg_struct a;
  188. struct file *file = NULL;
  189. unsigned long retval;
  190. struct mm_struct *mm ;
  191. if (copy_from_user(&a, arg, sizeof(a)))
  192. return -EFAULT;
  193. if (a.offset & ~PAGE_MASK)
  194. return -EINVAL;
  195. if (!(a.flags & MAP_ANONYMOUS)) {
  196. file = fget(a.fd);
  197. if (!file)
  198. return -EBADF;
  199. }
  200. mm = current->mm;
  201. down_write(&mm->mmap_sem);
  202. retval = do_mmap_pgoff(file, a.addr, a.len, a.prot, a.flags, a.offset>>PAGE_SHIFT);
  203. if (file)
  204. fput(file);
  205. up_write(&mm->mmap_sem);
  206. return retval;
  207. }
  208. asmlinkage long
  209. sys32_mprotect(unsigned long start, size_t len, unsigned long prot)
  210. {
  211. return sys_mprotect(start,len,prot);
  212. }
  213. asmlinkage long
  214. sys32_pipe(int __user *fd)
  215. {
  216. int retval;
  217. int fds[2];
  218. retval = do_pipe(fds);
  219. if (retval)
  220. goto out;
  221. if (copy_to_user(fd, fds, sizeof(fds)))
  222. retval = -EFAULT;
  223. out:
  224. return retval;
  225. }
  226. asmlinkage long
  227. sys32_rt_sigaction(int sig, struct sigaction32 __user *act,
  228. struct sigaction32 __user *oact, unsigned int sigsetsize)
  229. {
  230. struct k_sigaction new_ka, old_ka;
  231. int ret;
  232. compat_sigset_t set32;
  233. /* XXX: Don't preclude handling different sized sigset_t's. */
  234. if (sigsetsize != sizeof(compat_sigset_t))
  235. return -EINVAL;
  236. if (act) {
  237. compat_uptr_t handler, restorer;
  238. if (!access_ok(VERIFY_READ, act, sizeof(*act)) ||
  239. __get_user(handler, &act->sa_handler) ||
  240. __get_user(new_ka.sa.sa_flags, &act->sa_flags) ||
  241. __get_user(restorer, &act->sa_restorer)||
  242. __copy_from_user(&set32, &act->sa_mask, sizeof(compat_sigset_t)))
  243. return -EFAULT;
  244. new_ka.sa.sa_handler = compat_ptr(handler);
  245. new_ka.sa.sa_restorer = compat_ptr(restorer);
  246. /* FIXME: here we rely on _COMPAT_NSIG_WORS to be >= than _NSIG_WORDS << 1 */
  247. switch (_NSIG_WORDS) {
  248. case 4: new_ka.sa.sa_mask.sig[3] = set32.sig[6]
  249. | (((long)set32.sig[7]) << 32);
  250. case 3: new_ka.sa.sa_mask.sig[2] = set32.sig[4]
  251. | (((long)set32.sig[5]) << 32);
  252. case 2: new_ka.sa.sa_mask.sig[1] = set32.sig[2]
  253. | (((long)set32.sig[3]) << 32);
  254. case 1: new_ka.sa.sa_mask.sig[0] = set32.sig[0]
  255. | (((long)set32.sig[1]) << 32);
  256. }
  257. }
  258. ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
  259. if (!ret && oact) {
  260. /* FIXME: here we rely on _COMPAT_NSIG_WORS to be >= than _NSIG_WORDS << 1 */
  261. switch (_NSIG_WORDS) {
  262. case 4:
  263. set32.sig[7] = (old_ka.sa.sa_mask.sig[3] >> 32);
  264. set32.sig[6] = old_ka.sa.sa_mask.sig[3];
  265. case 3:
  266. set32.sig[5] = (old_ka.sa.sa_mask.sig[2] >> 32);
  267. set32.sig[4] = old_ka.sa.sa_mask.sig[2];
  268. case 2:
  269. set32.sig[3] = (old_ka.sa.sa_mask.sig[1] >> 32);
  270. set32.sig[2] = old_ka.sa.sa_mask.sig[1];
  271. case 1:
  272. set32.sig[1] = (old_ka.sa.sa_mask.sig[0] >> 32);
  273. set32.sig[0] = old_ka.sa.sa_mask.sig[0];
  274. }
  275. if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) ||
  276. __put_user(ptr_to_compat(old_ka.sa.sa_handler), &oact->sa_handler) ||
  277. __put_user(ptr_to_compat(old_ka.sa.sa_restorer), &oact->sa_restorer) ||
  278. __put_user(old_ka.sa.sa_flags, &oact->sa_flags) ||
  279. __copy_to_user(&oact->sa_mask, &set32, sizeof(compat_sigset_t)))
  280. return -EFAULT;
  281. }
  282. return ret;
  283. }
  284. asmlinkage long
  285. sys32_sigaction (int sig, struct old_sigaction32 __user *act, struct old_sigaction32 __user *oact)
  286. {
  287. struct k_sigaction new_ka, old_ka;
  288. int ret;
  289. if (act) {
  290. compat_old_sigset_t mask;
  291. compat_uptr_t handler, restorer;
  292. if (!access_ok(VERIFY_READ, act, sizeof(*act)) ||
  293. __get_user(handler, &act->sa_handler) ||
  294. __get_user(new_ka.sa.sa_flags, &act->sa_flags) ||
  295. __get_user(restorer, &act->sa_restorer) ||
  296. __get_user(mask, &act->sa_mask))
  297. return -EFAULT;
  298. new_ka.sa.sa_handler = compat_ptr(handler);
  299. new_ka.sa.sa_restorer = compat_ptr(restorer);
  300. siginitset(&new_ka.sa.sa_mask, mask);
  301. }
  302. ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
  303. if (!ret && oact) {
  304. if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) ||
  305. __put_user(ptr_to_compat(old_ka.sa.sa_handler), &oact->sa_handler) ||
  306. __put_user(ptr_to_compat(old_ka.sa.sa_restorer), &oact->sa_restorer) ||
  307. __put_user(old_ka.sa.sa_flags, &oact->sa_flags) ||
  308. __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask))
  309. return -EFAULT;
  310. }
  311. return ret;
  312. }
  313. asmlinkage long
  314. sys32_rt_sigprocmask(int how, compat_sigset_t __user *set,
  315. compat_sigset_t __user *oset, unsigned int sigsetsize)
  316. {
  317. sigset_t s;
  318. compat_sigset_t s32;
  319. int ret;
  320. mm_segment_t old_fs = get_fs();
  321. if (set) {
  322. if (copy_from_user (&s32, set, sizeof(compat_sigset_t)))
  323. return -EFAULT;
  324. switch (_NSIG_WORDS) {
  325. case 4: s.sig[3] = s32.sig[6] | (((long)s32.sig[7]) << 32);
  326. case 3: s.sig[2] = s32.sig[4] | (((long)s32.sig[5]) << 32);
  327. case 2: s.sig[1] = s32.sig[2] | (((long)s32.sig[3]) << 32);
  328. case 1: s.sig[0] = s32.sig[0] | (((long)s32.sig[1]) << 32);
  329. }
  330. }
  331. set_fs (KERNEL_DS);
  332. ret = sys_rt_sigprocmask(how, set ? &s : NULL, oset ? &s : NULL,
  333. sigsetsize);
  334. set_fs (old_fs);
  335. if (ret) return ret;
  336. if (oset) {
  337. switch (_NSIG_WORDS) {
  338. case 4: s32.sig[7] = (s.sig[3] >> 32); s32.sig[6] = s.sig[3];
  339. case 3: s32.sig[5] = (s.sig[2] >> 32); s32.sig[4] = s.sig[2];
  340. case 2: s32.sig[3] = (s.sig[1] >> 32); s32.sig[2] = s.sig[1];
  341. case 1: s32.sig[1] = (s.sig[0] >> 32); s32.sig[0] = s.sig[0];
  342. }
  343. if (copy_to_user (oset, &s32, sizeof(compat_sigset_t)))
  344. return -EFAULT;
  345. }
  346. return 0;
  347. }
  348. static inline long
  349. get_tv32(struct timeval *o, struct compat_timeval __user *i)
  350. {
  351. int err = -EFAULT;
  352. if (access_ok(VERIFY_READ, i, sizeof(*i))) {
  353. err = __get_user(o->tv_sec, &i->tv_sec);
  354. err |= __get_user(o->tv_usec, &i->tv_usec);
  355. }
  356. return err;
  357. }
  358. static inline long
  359. put_tv32(struct compat_timeval __user *o, struct timeval *i)
  360. {
  361. int err = -EFAULT;
  362. if (access_ok(VERIFY_WRITE, o, sizeof(*o))) {
  363. err = __put_user(i->tv_sec, &o->tv_sec);
  364. err |= __put_user(i->tv_usec, &o->tv_usec);
  365. }
  366. return err;
  367. }
  368. extern int do_setitimer(int which, struct itimerval *, struct itimerval *);
  369. asmlinkage long
  370. sys32_alarm(unsigned int seconds)
  371. {
  372. struct itimerval it_new, it_old;
  373. unsigned int oldalarm;
  374. it_new.it_interval.tv_sec = it_new.it_interval.tv_usec = 0;
  375. it_new.it_value.tv_sec = seconds;
  376. it_new.it_value.tv_usec = 0;
  377. do_setitimer(ITIMER_REAL, &it_new, &it_old);
  378. oldalarm = it_old.it_value.tv_sec;
  379. /* ehhh.. We can't return 0 if we have an alarm pending.. */
  380. /* And we'd better return too much than too little anyway */
  381. if (it_old.it_value.tv_usec)
  382. oldalarm++;
  383. return oldalarm;
  384. }
  385. /* Translations due to time_t size differences. Which affects all
  386. sorts of things, like timeval and itimerval. */
  387. extern struct timezone sys_tz;
  388. asmlinkage long
  389. sys32_gettimeofday(struct compat_timeval __user *tv, struct timezone __user *tz)
  390. {
  391. if (tv) {
  392. struct timeval ktv;
  393. do_gettimeofday(&ktv);
  394. if (put_tv32(tv, &ktv))
  395. return -EFAULT;
  396. }
  397. if (tz) {
  398. if (copy_to_user(tz, &sys_tz, sizeof(sys_tz)))
  399. return -EFAULT;
  400. }
  401. return 0;
  402. }
  403. asmlinkage long
  404. sys32_settimeofday(struct compat_timeval __user *tv, struct timezone __user *tz)
  405. {
  406. struct timeval ktv;
  407. struct timespec kts;
  408. struct timezone ktz;
  409. if (tv) {
  410. if (get_tv32(&ktv, tv))
  411. return -EFAULT;
  412. kts.tv_sec = ktv.tv_sec;
  413. kts.tv_nsec = ktv.tv_usec * NSEC_PER_USEC;
  414. }
  415. if (tz) {
  416. if (copy_from_user(&ktz, tz, sizeof(ktz)))
  417. return -EFAULT;
  418. }
  419. return do_sys_settimeofday(tv ? &kts : NULL, tz ? &ktz : NULL);
  420. }
  421. struct sel_arg_struct {
  422. unsigned int n;
  423. unsigned int inp;
  424. unsigned int outp;
  425. unsigned int exp;
  426. unsigned int tvp;
  427. };
  428. asmlinkage long
  429. sys32_old_select(struct sel_arg_struct __user *arg)
  430. {
  431. struct sel_arg_struct a;
  432. if (copy_from_user(&a, arg, sizeof(a)))
  433. return -EFAULT;
  434. return compat_sys_select(a.n, compat_ptr(a.inp), compat_ptr(a.outp),
  435. compat_ptr(a.exp), compat_ptr(a.tvp));
  436. }
  437. extern asmlinkage long
  438. compat_sys_wait4(compat_pid_t pid, compat_uint_t * stat_addr, int options,
  439. struct compat_rusage *ru);
  440. asmlinkage long
  441. sys32_waitpid(compat_pid_t pid, unsigned int *stat_addr, int options)
  442. {
  443. return compat_sys_wait4(pid, stat_addr, options, NULL);
  444. }
  445. int sys32_ni_syscall(int call)
  446. {
  447. struct task_struct *me = current;
  448. static char lastcomm[sizeof(me->comm)];
  449. if (strncmp(lastcomm, me->comm, sizeof(lastcomm))) {
  450. printk(KERN_INFO "IA32 syscall %d from %s not implemented\n",
  451. call, me->comm);
  452. strncpy(lastcomm, me->comm, sizeof(lastcomm));
  453. }
  454. return -ENOSYS;
  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(&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, &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(&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, &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
  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. extern int do_sysctl(int *name, int nlen, void *oldval, size_t *oldlenp,
  599. void *newval, size_t newlen);
  600. if (copy_from_user(&a32, args32, sizeof (a32)))
  601. return -EFAULT;
  602. /*
  603. * We need to pre-validate these because we have to disable address checking
  604. * before calling do_sysctl() because of OLDLEN but we can't run the risk of the
  605. * user specifying bad addresses here. Well, since we're dealing with 32 bit
  606. * addresses, we KNOW that access_ok() will always succeed, so this is an
  607. * expensive NOP, but so what...
  608. */
  609. namep = compat_ptr(a32.name);
  610. oldvalp = compat_ptr(a32.oldval);
  611. newvalp = compat_ptr(a32.newval);
  612. if ((oldvalp && get_user(oldlen, (int __user *)compat_ptr(a32.oldlenp)))
  613. || !access_ok(VERIFY_WRITE, namep, 0)
  614. || !access_ok(VERIFY_WRITE, oldvalp, 0)
  615. || !access_ok(VERIFY_WRITE, newvalp, 0))
  616. return -EFAULT;
  617. set_fs(KERNEL_DS);
  618. lock_kernel();
  619. ret = do_sysctl(namep, a32.nlen, oldvalp, &oldlen, newvalp, (size_t) a32.newlen);
  620. unlock_kernel();
  621. set_fs(old_fs);
  622. if (oldvalp && put_user (oldlen, (int __user *)compat_ptr(a32.oldlenp)))
  623. return -EFAULT;
  624. return ret;
  625. }
  626. #endif
  627. /* warning: next two assume little endian */
  628. asmlinkage long
  629. sys32_pread(unsigned int fd, char __user *ubuf, u32 count, u32 poslo, u32 poshi)
  630. {
  631. return sys_pread64(fd, ubuf, count,
  632. ((loff_t)AA(poshi) << 32) | AA(poslo));
  633. }
  634. asmlinkage long
  635. sys32_pwrite(unsigned int fd, char __user *ubuf, u32 count, u32 poslo, u32 poshi)
  636. {
  637. return sys_pwrite64(fd, ubuf, count,
  638. ((loff_t)AA(poshi) << 32) | AA(poslo));
  639. }
  640. asmlinkage long
  641. sys32_personality(unsigned long personality)
  642. {
  643. int ret;
  644. if (personality(current->personality) == PER_LINUX32 &&
  645. personality == PER_LINUX)
  646. personality = PER_LINUX32;
  647. ret = sys_personality(personality);
  648. if (ret == PER_LINUX32)
  649. ret = PER_LINUX;
  650. return ret;
  651. }
  652. asmlinkage long
  653. sys32_sendfile(int out_fd, int in_fd, compat_off_t __user *offset, s32 count)
  654. {
  655. mm_segment_t old_fs = get_fs();
  656. int ret;
  657. off_t of;
  658. if (offset && get_user(of, offset))
  659. return -EFAULT;
  660. set_fs(KERNEL_DS);
  661. ret = sys_sendfile(out_fd, in_fd, offset ? &of : NULL, count);
  662. set_fs(old_fs);
  663. if (!ret && offset && put_user(of, offset))
  664. return -EFAULT;
  665. return ret;
  666. }
  667. /* Handle adjtimex compatibility. */
  668. struct timex32 {
  669. u32 modes;
  670. s32 offset, freq, maxerror, esterror;
  671. s32 status, constant, precision, tolerance;
  672. struct compat_timeval time;
  673. s32 tick;
  674. s32 ppsfreq, jitter, shift, stabil;
  675. s32 jitcnt, calcnt, errcnt, stbcnt;
  676. s32 :32; s32 :32; s32 :32; s32 :32;
  677. s32 :32; s32 :32; s32 :32; s32 :32;
  678. s32 :32; s32 :32; s32 :32; s32 :32;
  679. };
  680. extern int do_adjtimex(struct timex *);
  681. asmlinkage long
  682. sys32_adjtimex(struct timex32 __user *utp)
  683. {
  684. struct timex txc;
  685. int ret;
  686. memset(&txc, 0, sizeof(struct timex));
  687. if (!access_ok(VERIFY_READ, utp, sizeof(struct timex32)) ||
  688. __get_user(txc.modes, &utp->modes) ||
  689. __get_user(txc.offset, &utp->offset) ||
  690. __get_user(txc.freq, &utp->freq) ||
  691. __get_user(txc.maxerror, &utp->maxerror) ||
  692. __get_user(txc.esterror, &utp->esterror) ||
  693. __get_user(txc.status, &utp->status) ||
  694. __get_user(txc.constant, &utp->constant) ||
  695. __get_user(txc.precision, &utp->precision) ||
  696. __get_user(txc.tolerance, &utp->tolerance) ||
  697. __get_user(txc.time.tv_sec, &utp->time.tv_sec) ||
  698. __get_user(txc.time.tv_usec, &utp->time.tv_usec) ||
  699. __get_user(txc.tick, &utp->tick) ||
  700. __get_user(txc.ppsfreq, &utp->ppsfreq) ||
  701. __get_user(txc.jitter, &utp->jitter) ||
  702. __get_user(txc.shift, &utp->shift) ||
  703. __get_user(txc.stabil, &utp->stabil) ||
  704. __get_user(txc.jitcnt, &utp->jitcnt) ||
  705. __get_user(txc.calcnt, &utp->calcnt) ||
  706. __get_user(txc.errcnt, &utp->errcnt) ||
  707. __get_user(txc.stbcnt, &utp->stbcnt))
  708. return -EFAULT;
  709. ret = do_adjtimex(&txc);
  710. if (!access_ok(VERIFY_WRITE, utp, sizeof(struct timex32)) ||
  711. __put_user(txc.modes, &utp->modes) ||
  712. __put_user(txc.offset, &utp->offset) ||
  713. __put_user(txc.freq, &utp->freq) ||
  714. __put_user(txc.maxerror, &utp->maxerror) ||
  715. __put_user(txc.esterror, &utp->esterror) ||
  716. __put_user(txc.status, &utp->status) ||
  717. __put_user(txc.constant, &utp->constant) ||
  718. __put_user(txc.precision, &utp->precision) ||
  719. __put_user(txc.tolerance, &utp->tolerance) ||
  720. __put_user(txc.time.tv_sec, &utp->time.tv_sec) ||
  721. __put_user(txc.time.tv_usec, &utp->time.tv_usec) ||
  722. __put_user(txc.tick, &utp->tick) ||
  723. __put_user(txc.ppsfreq, &utp->ppsfreq) ||
  724. __put_user(txc.jitter, &utp->jitter) ||
  725. __put_user(txc.shift, &utp->shift) ||
  726. __put_user(txc.stabil, &utp->stabil) ||
  727. __put_user(txc.jitcnt, &utp->jitcnt) ||
  728. __put_user(txc.calcnt, &utp->calcnt) ||
  729. __put_user(txc.errcnt, &utp->errcnt) ||
  730. __put_user(txc.stbcnt, &utp->stbcnt))
  731. ret = -EFAULT;
  732. return ret;
  733. }
  734. asmlinkage long sys32_mmap2(unsigned long addr, unsigned long len,
  735. unsigned long prot, unsigned long flags,
  736. unsigned long fd, unsigned long pgoff)
  737. {
  738. struct mm_struct *mm = current->mm;
  739. unsigned long error;
  740. struct file * file = NULL;
  741. flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
  742. if (!(flags & MAP_ANONYMOUS)) {
  743. file = fget(fd);
  744. if (!file)
  745. return -EBADF;
  746. }
  747. down_write(&mm->mmap_sem);
  748. error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
  749. up_write(&mm->mmap_sem);
  750. if (file)
  751. fput(file);
  752. return error;
  753. }
  754. asmlinkage long sys32_olduname(struct oldold_utsname __user * name)
  755. {
  756. int error;
  757. if (!name)
  758. return -EFAULT;
  759. if (!access_ok(VERIFY_WRITE,name,sizeof(struct oldold_utsname)))
  760. return -EFAULT;
  761. down_read(&uts_sem);
  762. error = __copy_to_user(&name->sysname,&system_utsname.sysname,__OLD_UTS_LEN);
  763. __put_user(0,name->sysname+__OLD_UTS_LEN);
  764. __copy_to_user(&name->nodename,&system_utsname.nodename,__OLD_UTS_LEN);
  765. __put_user(0,name->nodename+__OLD_UTS_LEN);
  766. __copy_to_user(&name->release,&system_utsname.release,__OLD_UTS_LEN);
  767. __put_user(0,name->release+__OLD_UTS_LEN);
  768. __copy_to_user(&name->version,&system_utsname.version,__OLD_UTS_LEN);
  769. __put_user(0,name->version+__OLD_UTS_LEN);
  770. {
  771. char *arch = "x86_64";
  772. if (personality(current->personality) == PER_LINUX32)
  773. arch = "i686";
  774. __copy_to_user(&name->machine,arch,strlen(arch)+1);
  775. }
  776. up_read(&uts_sem);
  777. error = error ? -EFAULT : 0;
  778. return error;
  779. }
  780. long sys32_uname(struct old_utsname __user * name)
  781. {
  782. int err;
  783. if (!name)
  784. return -EFAULT;
  785. down_read(&uts_sem);
  786. err=copy_to_user(name, &system_utsname, sizeof (*name));
  787. up_read(&uts_sem);
  788. if (personality(current->personality) == PER_LINUX32)
  789. err |= copy_to_user(&name->machine, "i686", 5);
  790. return err?-EFAULT:0;
  791. }
  792. long sys32_ustat(unsigned dev, struct ustat32 __user *u32p)
  793. {
  794. struct ustat u;
  795. mm_segment_t seg;
  796. int ret;
  797. seg = get_fs();
  798. set_fs(KERNEL_DS);
  799. ret = sys_ustat(dev,&u);
  800. set_fs(seg);
  801. if (ret >= 0) {
  802. if (!access_ok(VERIFY_WRITE,u32p,sizeof(struct ustat32)) ||
  803. __put_user((__u32) u.f_tfree, &u32p->f_tfree) ||
  804. __put_user((__u32) u.f_tinode, &u32p->f_tfree) ||
  805. __copy_to_user(&u32p->f_fname, u.f_fname, sizeof(u.f_fname)) ||
  806. __copy_to_user(&u32p->f_fpack, u.f_fpack, sizeof(u.f_fpack)))
  807. ret = -EFAULT;
  808. }
  809. return ret;
  810. }
  811. asmlinkage long sys32_execve(char __user *name, compat_uptr_t __user *argv,
  812. compat_uptr_t __user *envp, struct pt_regs *regs)
  813. {
  814. long error;
  815. char * filename;
  816. filename = getname(name);
  817. error = PTR_ERR(filename);
  818. if (IS_ERR(filename))
  819. return error;
  820. error = compat_do_execve(filename, argv, envp, regs);
  821. if (error == 0) {
  822. task_lock(current);
  823. current->ptrace &= ~PT_DTRACE;
  824. task_unlock(current);
  825. }
  826. putname(filename);
  827. return error;
  828. }
  829. asmlinkage long sys32_clone(unsigned int clone_flags, unsigned int newsp,
  830. struct pt_regs *regs)
  831. {
  832. void __user *parent_tid = (void __user *)regs->rdx;
  833. void __user *child_tid = (void __user *)regs->rdi;
  834. if (!newsp)
  835. newsp = regs->rsp;
  836. return do_fork(clone_flags, newsp, regs, 0, parent_tid, child_tid);
  837. }
  838. /*
  839. * Some system calls that need sign extended arguments. This could be done by a generic wrapper.
  840. */
  841. long sys32_lseek (unsigned int fd, int offset, unsigned int whence)
  842. {
  843. return sys_lseek(fd, offset, whence);
  844. }
  845. long sys32_kill(int pid, int sig)
  846. {
  847. return sys_kill(pid, sig);
  848. }
  849. extern asmlinkage long
  850. sys_timer_create(clockid_t which_clock,
  851. struct sigevent __user *timer_event_spec,
  852. timer_t __user * created_timer_id);
  853. long
  854. sys32_timer_create(u32 clock, struct compat_sigevent __user *se32, timer_t __user *timer_id)
  855. {
  856. struct sigevent __user *p = NULL;
  857. if (se32) {
  858. struct sigevent se;
  859. p = compat_alloc_user_space(sizeof(struct sigevent));
  860. if (get_compat_sigevent(&se, se32) ||
  861. copy_to_user(p, &se, sizeof(se)))
  862. return -EFAULT;
  863. }
  864. return sys_timer_create(clock, p, timer_id);
  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);