sys_ia32.c 24 KB

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