sys_ia32.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917
  1. /*
  2. * sys_ia32.c: Conversion between 32bit and 64bit native syscalls. Based on
  3. * sys_sparc32
  4. *
  5. * Copyright (C) 2000 VA Linux Co
  6. * Copyright (C) 2000 Don Dugger <n0ano@valinux.com>
  7. * Copyright (C) 1999 Arun Sharma <arun.sharma@intel.com>
  8. * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
  9. * Copyright (C) 1997 David S. Miller (davem@caip.rutgers.edu)
  10. * Copyright (C) 2000 Hewlett-Packard Co.
  11. * Copyright (C) 2000 David Mosberger-Tang <davidm@hpl.hp.com>
  12. * Copyright (C) 2000,2001,2002 Andi Kleen, SuSE Labs (x86-64 port)
  13. *
  14. * These routines maintain argument size conversion between 32bit and 64bit
  15. * environment. In 2.5 most of this should be moved to a generic directory.
  16. *
  17. * This file assumes that there is a hole at the end of user address space.
  18. *
  19. * Some of the functions are LE specific currently. These are hopefully all marked.
  20. * This should be fixed.
  21. */
  22. #include <linux/kernel.h>
  23. #include <linux/sched.h>
  24. #include <linux/fs.h>
  25. #include <linux/file.h>
  26. #include <linux/signal.h>
  27. #include <linux/syscalls.h>
  28. #include <linux/resource.h>
  29. #include <linux/times.h>
  30. #include <linux/utsname.h>
  31. #include <linux/smp.h>
  32. #include <linux/smp_lock.h>
  33. #include <linux/sem.h>
  34. #include <linux/msg.h>
  35. #include <linux/mm.h>
  36. #include <linux/shm.h>
  37. #include <linux/slab.h>
  38. #include <linux/uio.h>
  39. #include <linux/nfs_fs.h>
  40. #include <linux/quota.h>
  41. #include <linux/module.h>
  42. #include <linux/sunrpc/svc.h>
  43. #include <linux/nfsd/nfsd.h>
  44. #include <linux/nfsd/cache.h>
  45. #include <linux/nfsd/xdr.h>
  46. #include <linux/nfsd/syscall.h>
  47. #include <linux/poll.h>
  48. #include <linux/personality.h>
  49. #include <linux/stat.h>
  50. #include <linux/ipc.h>
  51. #include <linux/rwsem.h>
  52. #include <linux/binfmts.h>
  53. #include <linux/init.h>
  54. #include <linux/aio_abi.h>
  55. #include <linux/aio.h>
  56. #include <linux/compat.h>
  57. #include <linux/vfs.h>
  58. #include <linux/ptrace.h>
  59. #include <linux/highuid.h>
  60. #include <linux/vmalloc.h>
  61. #include <linux/fsnotify.h>
  62. #include <asm/mman.h>
  63. #include <asm/types.h>
  64. #include <asm/uaccess.h>
  65. #include <asm/semaphore.h>
  66. #include <asm/atomic.h>
  67. #include <asm/ldt.h>
  68. #include <net/scm.h>
  69. #include <net/sock.h>
  70. #include <asm/ia32.h>
  71. #define AA(__x) ((unsigned long)(__x))
  72. int cp_compat_stat(struct kstat *kbuf, struct compat_stat __user *ubuf)
  73. {
  74. typeof(ubuf->st_uid) uid = 0;
  75. typeof(ubuf->st_gid) gid = 0;
  76. SET_UID(uid, kbuf->uid);
  77. SET_GID(gid, kbuf->gid);
  78. if (!old_valid_dev(kbuf->dev) || !old_valid_dev(kbuf->rdev))
  79. return -EOVERFLOW;
  80. if (kbuf->size >= 0x7fffffff)
  81. return -EOVERFLOW;
  82. if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct compat_stat)) ||
  83. __put_user (old_encode_dev(kbuf->dev), &ubuf->st_dev) ||
  84. __put_user (kbuf->ino, &ubuf->st_ino) ||
  85. __put_user (kbuf->mode, &ubuf->st_mode) ||
  86. __put_user (kbuf->nlink, &ubuf->st_nlink) ||
  87. __put_user (uid, &ubuf->st_uid) ||
  88. __put_user (gid, &ubuf->st_gid) ||
  89. __put_user (old_encode_dev(kbuf->rdev), &ubuf->st_rdev) ||
  90. __put_user (kbuf->size, &ubuf->st_size) ||
  91. __put_user (kbuf->atime.tv_sec, &ubuf->st_atime) ||
  92. __put_user (kbuf->atime.tv_nsec, &ubuf->st_atime_nsec) ||
  93. __put_user (kbuf->mtime.tv_sec, &ubuf->st_mtime) ||
  94. __put_user (kbuf->mtime.tv_nsec, &ubuf->st_mtime_nsec) ||
  95. __put_user (kbuf->ctime.tv_sec, &ubuf->st_ctime) ||
  96. __put_user (kbuf->ctime.tv_nsec, &ubuf->st_ctime_nsec) ||
  97. __put_user (kbuf->blksize, &ubuf->st_blksize) ||
  98. __put_user (kbuf->blocks, &ubuf->st_blocks))
  99. return -EFAULT;
  100. return 0;
  101. }
  102. asmlinkage long
  103. sys32_truncate64(char __user * filename, unsigned long offset_low, unsigned long offset_high)
  104. {
  105. return sys_truncate(filename, ((loff_t) offset_high << 32) | offset_low);
  106. }
  107. asmlinkage long
  108. sys32_ftruncate64(unsigned int fd, unsigned long offset_low, unsigned long offset_high)
  109. {
  110. return sys_ftruncate(fd, ((loff_t) offset_high << 32) | offset_low);
  111. }
  112. /* Another set for IA32/LFS -- x86_64 struct stat is different due to
  113. support for 64bit inode numbers. */
  114. static int
  115. cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
  116. {
  117. typeof(ubuf->st_uid) uid = 0;
  118. typeof(ubuf->st_gid) gid = 0;
  119. SET_UID(uid, stat->uid);
  120. SET_GID(gid, stat->gid);
  121. if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
  122. __put_user(huge_encode_dev(stat->dev), &ubuf->st_dev) ||
  123. __put_user (stat->ino, &ubuf->__st_ino) ||
  124. __put_user (stat->ino, &ubuf->st_ino) ||
  125. __put_user (stat->mode, &ubuf->st_mode) ||
  126. __put_user (stat->nlink, &ubuf->st_nlink) ||
  127. __put_user (uid, &ubuf->st_uid) ||
  128. __put_user (gid, &ubuf->st_gid) ||
  129. __put_user (huge_encode_dev(stat->rdev), &ubuf->st_rdev) ||
  130. __put_user (stat->size, &ubuf->st_size) ||
  131. __put_user (stat->atime.tv_sec, &ubuf->st_atime) ||
  132. __put_user (stat->atime.tv_nsec, &ubuf->st_atime_nsec) ||
  133. __put_user (stat->mtime.tv_sec, &ubuf->st_mtime) ||
  134. __put_user (stat->mtime.tv_nsec, &ubuf->st_mtime_nsec) ||
  135. __put_user (stat->ctime.tv_sec, &ubuf->st_ctime) ||
  136. __put_user (stat->ctime.tv_nsec, &ubuf->st_ctime_nsec) ||
  137. __put_user (stat->blksize, &ubuf->st_blksize) ||
  138. __put_user (stat->blocks, &ubuf->st_blocks))
  139. return -EFAULT;
  140. return 0;
  141. }
  142. asmlinkage long
  143. sys32_stat64(char __user * filename, struct stat64 __user *statbuf)
  144. {
  145. struct kstat stat;
  146. int ret = vfs_stat(filename, &stat);
  147. if (!ret)
  148. ret = cp_stat64(statbuf, &stat);
  149. return ret;
  150. }
  151. asmlinkage long
  152. sys32_lstat64(char __user * filename, struct stat64 __user *statbuf)
  153. {
  154. struct kstat stat;
  155. int ret = vfs_lstat(filename, &stat);
  156. if (!ret)
  157. ret = cp_stat64(statbuf, &stat);
  158. return ret;
  159. }
  160. asmlinkage long
  161. sys32_fstat64(unsigned int fd, struct stat64 __user *statbuf)
  162. {
  163. struct kstat stat;
  164. int ret = vfs_fstat(fd, &stat);
  165. if (!ret)
  166. ret = cp_stat64(statbuf, &stat);
  167. return ret;
  168. }
  169. asmlinkage long
  170. sys32_fstatat(unsigned int dfd, char __user *filename,
  171. struct stat64 __user* statbuf, int flag)
  172. {
  173. struct kstat stat;
  174. int error = -EINVAL;
  175. if ((flag & ~AT_SYMLINK_NOFOLLOW) != 0)
  176. goto out;
  177. if (flag & AT_SYMLINK_NOFOLLOW)
  178. error = vfs_lstat_fd(dfd, filename, &stat);
  179. else
  180. error = vfs_stat_fd(dfd, filename, &stat);
  181. if (!error)
  182. error = cp_stat64(statbuf, &stat);
  183. out:
  184. return error;
  185. }
  186. /*
  187. * Linux/i386 didn't use to be able to handle more than
  188. * 4 system call parameters, so these system calls used a memory
  189. * block for parameter passing..
  190. */
  191. struct mmap_arg_struct {
  192. unsigned int addr;
  193. unsigned int len;
  194. unsigned int prot;
  195. unsigned int flags;
  196. unsigned int fd;
  197. unsigned int offset;
  198. };
  199. asmlinkage long
  200. sys32_mmap(struct mmap_arg_struct __user *arg)
  201. {
  202. struct mmap_arg_struct a;
  203. struct file *file = NULL;
  204. unsigned long retval;
  205. struct mm_struct *mm ;
  206. if (copy_from_user(&a, arg, sizeof(a)))
  207. return -EFAULT;
  208. if (a.offset & ~PAGE_MASK)
  209. return -EINVAL;
  210. if (!(a.flags & MAP_ANONYMOUS)) {
  211. file = fget(a.fd);
  212. if (!file)
  213. return -EBADF;
  214. }
  215. mm = current->mm;
  216. down_write(&mm->mmap_sem);
  217. retval = do_mmap_pgoff(file, a.addr, a.len, a.prot, a.flags, a.offset>>PAGE_SHIFT);
  218. if (file)
  219. fput(file);
  220. up_write(&mm->mmap_sem);
  221. return retval;
  222. }
  223. asmlinkage long
  224. sys32_mprotect(unsigned long start, size_t len, unsigned long prot)
  225. {
  226. return sys_mprotect(start,len,prot);
  227. }
  228. asmlinkage long
  229. sys32_pipe(int __user *fd)
  230. {
  231. int retval;
  232. int fds[2];
  233. retval = do_pipe(fds);
  234. if (retval)
  235. goto out;
  236. if (copy_to_user(fd, fds, sizeof(fds)))
  237. retval = -EFAULT;
  238. out:
  239. return retval;
  240. }
  241. asmlinkage long
  242. sys32_rt_sigaction(int sig, struct sigaction32 __user *act,
  243. struct sigaction32 __user *oact, unsigned int sigsetsize)
  244. {
  245. struct k_sigaction new_ka, old_ka;
  246. int ret;
  247. compat_sigset_t set32;
  248. /* XXX: Don't preclude handling different sized sigset_t's. */
  249. if (sigsetsize != sizeof(compat_sigset_t))
  250. return -EINVAL;
  251. if (act) {
  252. compat_uptr_t handler, restorer;
  253. if (!access_ok(VERIFY_READ, act, sizeof(*act)) ||
  254. __get_user(handler, &act->sa_handler) ||
  255. __get_user(new_ka.sa.sa_flags, &act->sa_flags) ||
  256. __get_user(restorer, &act->sa_restorer)||
  257. __copy_from_user(&set32, &act->sa_mask, sizeof(compat_sigset_t)))
  258. return -EFAULT;
  259. new_ka.sa.sa_handler = compat_ptr(handler);
  260. new_ka.sa.sa_restorer = compat_ptr(restorer);
  261. /* FIXME: here we rely on _COMPAT_NSIG_WORS to be >= than _NSIG_WORDS << 1 */
  262. switch (_NSIG_WORDS) {
  263. case 4: new_ka.sa.sa_mask.sig[3] = set32.sig[6]
  264. | (((long)set32.sig[7]) << 32);
  265. case 3: new_ka.sa.sa_mask.sig[2] = set32.sig[4]
  266. | (((long)set32.sig[5]) << 32);
  267. case 2: new_ka.sa.sa_mask.sig[1] = set32.sig[2]
  268. | (((long)set32.sig[3]) << 32);
  269. case 1: new_ka.sa.sa_mask.sig[0] = set32.sig[0]
  270. | (((long)set32.sig[1]) << 32);
  271. }
  272. }
  273. ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
  274. if (!ret && oact) {
  275. /* FIXME: here we rely on _COMPAT_NSIG_WORS to be >= than _NSIG_WORDS << 1 */
  276. switch (_NSIG_WORDS) {
  277. case 4:
  278. set32.sig[7] = (old_ka.sa.sa_mask.sig[3] >> 32);
  279. set32.sig[6] = old_ka.sa.sa_mask.sig[3];
  280. case 3:
  281. set32.sig[5] = (old_ka.sa.sa_mask.sig[2] >> 32);
  282. set32.sig[4] = old_ka.sa.sa_mask.sig[2];
  283. case 2:
  284. set32.sig[3] = (old_ka.sa.sa_mask.sig[1] >> 32);
  285. set32.sig[2] = old_ka.sa.sa_mask.sig[1];
  286. case 1:
  287. set32.sig[1] = (old_ka.sa.sa_mask.sig[0] >> 32);
  288. set32.sig[0] = old_ka.sa.sa_mask.sig[0];
  289. }
  290. if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) ||
  291. __put_user(ptr_to_compat(old_ka.sa.sa_handler), &oact->sa_handler) ||
  292. __put_user(ptr_to_compat(old_ka.sa.sa_restorer), &oact->sa_restorer) ||
  293. __put_user(old_ka.sa.sa_flags, &oact->sa_flags) ||
  294. __copy_to_user(&oact->sa_mask, &set32, sizeof(compat_sigset_t)))
  295. return -EFAULT;
  296. }
  297. return ret;
  298. }
  299. asmlinkage long
  300. sys32_sigaction (int sig, struct old_sigaction32 __user *act, struct old_sigaction32 __user *oact)
  301. {
  302. struct k_sigaction new_ka, old_ka;
  303. int ret;
  304. if (act) {
  305. compat_old_sigset_t mask;
  306. compat_uptr_t handler, restorer;
  307. if (!access_ok(VERIFY_READ, act, sizeof(*act)) ||
  308. __get_user(handler, &act->sa_handler) ||
  309. __get_user(new_ka.sa.sa_flags, &act->sa_flags) ||
  310. __get_user(restorer, &act->sa_restorer) ||
  311. __get_user(mask, &act->sa_mask))
  312. return -EFAULT;
  313. new_ka.sa.sa_handler = compat_ptr(handler);
  314. new_ka.sa.sa_restorer = compat_ptr(restorer);
  315. siginitset(&new_ka.sa.sa_mask, mask);
  316. }
  317. ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
  318. if (!ret && oact) {
  319. if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) ||
  320. __put_user(ptr_to_compat(old_ka.sa.sa_handler), &oact->sa_handler) ||
  321. __put_user(ptr_to_compat(old_ka.sa.sa_restorer), &oact->sa_restorer) ||
  322. __put_user(old_ka.sa.sa_flags, &oact->sa_flags) ||
  323. __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask))
  324. return -EFAULT;
  325. }
  326. return ret;
  327. }
  328. asmlinkage long
  329. sys32_rt_sigprocmask(int how, compat_sigset_t __user *set,
  330. compat_sigset_t __user *oset, unsigned int sigsetsize)
  331. {
  332. sigset_t s;
  333. compat_sigset_t s32;
  334. int ret;
  335. mm_segment_t old_fs = get_fs();
  336. if (set) {
  337. if (copy_from_user (&s32, set, sizeof(compat_sigset_t)))
  338. return -EFAULT;
  339. switch (_NSIG_WORDS) {
  340. case 4: s.sig[3] = s32.sig[6] | (((long)s32.sig[7]) << 32);
  341. case 3: s.sig[2] = s32.sig[4] | (((long)s32.sig[5]) << 32);
  342. case 2: s.sig[1] = s32.sig[2] | (((long)s32.sig[3]) << 32);
  343. case 1: s.sig[0] = s32.sig[0] | (((long)s32.sig[1]) << 32);
  344. }
  345. }
  346. set_fs (KERNEL_DS);
  347. ret = sys_rt_sigprocmask(how, set ? &s : NULL, oset ? &s : NULL,
  348. sigsetsize);
  349. set_fs (old_fs);
  350. if (ret) return ret;
  351. if (oset) {
  352. switch (_NSIG_WORDS) {
  353. case 4: s32.sig[7] = (s.sig[3] >> 32); s32.sig[6] = s.sig[3];
  354. case 3: s32.sig[5] = (s.sig[2] >> 32); s32.sig[4] = s.sig[2];
  355. case 2: s32.sig[3] = (s.sig[1] >> 32); s32.sig[2] = s.sig[1];
  356. case 1: s32.sig[1] = (s.sig[0] >> 32); s32.sig[0] = s.sig[0];
  357. }
  358. if (copy_to_user (oset, &s32, sizeof(compat_sigset_t)))
  359. return -EFAULT;
  360. }
  361. return 0;
  362. }
  363. static inline long
  364. get_tv32(struct timeval *o, struct compat_timeval __user *i)
  365. {
  366. int err = -EFAULT;
  367. if (access_ok(VERIFY_READ, i, sizeof(*i))) {
  368. err = __get_user(o->tv_sec, &i->tv_sec);
  369. err |= __get_user(o->tv_usec, &i->tv_usec);
  370. }
  371. return err;
  372. }
  373. static inline long
  374. put_tv32(struct compat_timeval __user *o, struct timeval *i)
  375. {
  376. int err = -EFAULT;
  377. if (access_ok(VERIFY_WRITE, o, sizeof(*o))) {
  378. err = __put_user(i->tv_sec, &o->tv_sec);
  379. err |= __put_user(i->tv_usec, &o->tv_usec);
  380. }
  381. return err;
  382. }
  383. extern unsigned int alarm_setitimer(unsigned int seconds);
  384. asmlinkage long
  385. sys32_alarm(unsigned int seconds)
  386. {
  387. return alarm_setitimer(seconds);
  388. }
  389. /* Translations due to time_t size differences. Which affects all
  390. sorts of things, like timeval and itimerval. */
  391. extern struct timezone sys_tz;
  392. asmlinkage long
  393. sys32_gettimeofday(struct compat_timeval __user *tv, struct timezone __user *tz)
  394. {
  395. if (tv) {
  396. struct timeval ktv;
  397. do_gettimeofday(&ktv);
  398. if (put_tv32(tv, &ktv))
  399. return -EFAULT;
  400. }
  401. if (tz) {
  402. if (copy_to_user(tz, &sys_tz, sizeof(sys_tz)))
  403. return -EFAULT;
  404. }
  405. return 0;
  406. }
  407. asmlinkage long
  408. sys32_settimeofday(struct compat_timeval __user *tv, struct timezone __user *tz)
  409. {
  410. struct timeval ktv;
  411. struct timespec kts;
  412. struct timezone ktz;
  413. if (tv) {
  414. if (get_tv32(&ktv, tv))
  415. return -EFAULT;
  416. kts.tv_sec = ktv.tv_sec;
  417. kts.tv_nsec = ktv.tv_usec * NSEC_PER_USEC;
  418. }
  419. if (tz) {
  420. if (copy_from_user(&ktz, tz, sizeof(ktz)))
  421. return -EFAULT;
  422. }
  423. return do_sys_settimeofday(tv ? &kts : NULL, tz ? &ktz : NULL);
  424. }
  425. struct sel_arg_struct {
  426. unsigned int n;
  427. unsigned int inp;
  428. unsigned int outp;
  429. unsigned int exp;
  430. unsigned int tvp;
  431. };
  432. asmlinkage long
  433. sys32_old_select(struct sel_arg_struct __user *arg)
  434. {
  435. struct sel_arg_struct a;
  436. if (copy_from_user(&a, arg, sizeof(a)))
  437. return -EFAULT;
  438. return compat_sys_select(a.n, compat_ptr(a.inp), compat_ptr(a.outp),
  439. compat_ptr(a.exp), compat_ptr(a.tvp));
  440. }
  441. extern asmlinkage long
  442. compat_sys_wait4(compat_pid_t pid, compat_uint_t * stat_addr, int options,
  443. struct compat_rusage *ru);
  444. asmlinkage long
  445. sys32_waitpid(compat_pid_t pid, unsigned int *stat_addr, int options)
  446. {
  447. return compat_sys_wait4(pid, stat_addr, options, NULL);
  448. }
  449. /* 32-bit timeval and related flotsam. */
  450. asmlinkage long
  451. sys32_sysfs(int option, u32 arg1, u32 arg2)
  452. {
  453. return sys_sysfs(option, arg1, arg2);
  454. }
  455. struct sysinfo32 {
  456. s32 uptime;
  457. u32 loads[3];
  458. u32 totalram;
  459. u32 freeram;
  460. u32 sharedram;
  461. u32 bufferram;
  462. u32 totalswap;
  463. u32 freeswap;
  464. unsigned short procs;
  465. unsigned short pad;
  466. u32 totalhigh;
  467. u32 freehigh;
  468. u32 mem_unit;
  469. char _f[20-2*sizeof(u32)-sizeof(int)];
  470. };
  471. asmlinkage long
  472. sys32_sysinfo(struct sysinfo32 __user *info)
  473. {
  474. struct sysinfo s;
  475. int ret;
  476. mm_segment_t old_fs = get_fs ();
  477. int bitcount = 0;
  478. set_fs (KERNEL_DS);
  479. ret = sys_sysinfo(&s);
  480. set_fs (old_fs);
  481. /* Check to see if any memory value is too large for 32-bit and scale
  482. * down if needed
  483. */
  484. if ((s.totalram >> 32) || (s.totalswap >> 32)) {
  485. while (s.mem_unit < PAGE_SIZE) {
  486. s.mem_unit <<= 1;
  487. bitcount++;
  488. }
  489. s.totalram >>= bitcount;
  490. s.freeram >>= bitcount;
  491. s.sharedram >>= bitcount;
  492. s.bufferram >>= bitcount;
  493. s.totalswap >>= bitcount;
  494. s.freeswap >>= bitcount;
  495. s.totalhigh >>= bitcount;
  496. s.freehigh >>= bitcount;
  497. }
  498. if (!access_ok(VERIFY_WRITE, info, sizeof(struct sysinfo32)) ||
  499. __put_user (s.uptime, &info->uptime) ||
  500. __put_user (s.loads[0], &info->loads[0]) ||
  501. __put_user (s.loads[1], &info->loads[1]) ||
  502. __put_user (s.loads[2], &info->loads[2]) ||
  503. __put_user (s.totalram, &info->totalram) ||
  504. __put_user (s.freeram, &info->freeram) ||
  505. __put_user (s.sharedram, &info->sharedram) ||
  506. __put_user (s.bufferram, &info->bufferram) ||
  507. __put_user (s.totalswap, &info->totalswap) ||
  508. __put_user (s.freeswap, &info->freeswap) ||
  509. __put_user (s.procs, &info->procs) ||
  510. __put_user (s.totalhigh, &info->totalhigh) ||
  511. __put_user (s.freehigh, &info->freehigh) ||
  512. __put_user (s.mem_unit, &info->mem_unit))
  513. return -EFAULT;
  514. return 0;
  515. }
  516. asmlinkage long
  517. sys32_sched_rr_get_interval(compat_pid_t pid, struct compat_timespec __user *interval)
  518. {
  519. struct timespec t;
  520. int ret;
  521. mm_segment_t old_fs = get_fs ();
  522. set_fs (KERNEL_DS);
  523. ret = sys_sched_rr_get_interval(pid, &t);
  524. set_fs (old_fs);
  525. if (put_compat_timespec(&t, interval))
  526. return -EFAULT;
  527. return ret;
  528. }
  529. asmlinkage long
  530. sys32_rt_sigpending(compat_sigset_t __user *set, compat_size_t sigsetsize)
  531. {
  532. sigset_t s;
  533. compat_sigset_t s32;
  534. int ret;
  535. mm_segment_t old_fs = get_fs();
  536. set_fs (KERNEL_DS);
  537. ret = sys_rt_sigpending(&s, sigsetsize);
  538. set_fs (old_fs);
  539. if (!ret) {
  540. switch (_NSIG_WORDS) {
  541. case 4: s32.sig[7] = (s.sig[3] >> 32); s32.sig[6] = s.sig[3];
  542. case 3: s32.sig[5] = (s.sig[2] >> 32); s32.sig[4] = s.sig[2];
  543. case 2: s32.sig[3] = (s.sig[1] >> 32); s32.sig[2] = s.sig[1];
  544. case 1: s32.sig[1] = (s.sig[0] >> 32); s32.sig[0] = s.sig[0];
  545. }
  546. if (copy_to_user (set, &s32, sizeof(compat_sigset_t)))
  547. return -EFAULT;
  548. }
  549. return ret;
  550. }
  551. asmlinkage long
  552. sys32_rt_sigqueueinfo(int pid, int sig, compat_siginfo_t __user *uinfo)
  553. {
  554. siginfo_t info;
  555. int ret;
  556. mm_segment_t old_fs = get_fs();
  557. if (copy_siginfo_from_user32(&info, uinfo))
  558. return -EFAULT;
  559. set_fs (KERNEL_DS);
  560. ret = sys_rt_sigqueueinfo(pid, sig, &info);
  561. set_fs (old_fs);
  562. return ret;
  563. }
  564. /* These are here just in case some old ia32 binary calls it. */
  565. asmlinkage long
  566. sys32_pause(void)
  567. {
  568. current->state = TASK_INTERRUPTIBLE;
  569. schedule();
  570. return -ERESTARTNOHAND;
  571. }
  572. #ifdef CONFIG_SYSCTL
  573. struct sysctl_ia32 {
  574. unsigned int name;
  575. int nlen;
  576. unsigned int oldval;
  577. unsigned int oldlenp;
  578. unsigned int newval;
  579. unsigned int newlen;
  580. unsigned int __unused[4];
  581. };
  582. asmlinkage long
  583. sys32_sysctl(struct sysctl_ia32 __user *args32)
  584. {
  585. struct sysctl_ia32 a32;
  586. mm_segment_t old_fs = get_fs ();
  587. void __user *oldvalp, *newvalp;
  588. size_t oldlen;
  589. int __user *namep;
  590. long ret;
  591. extern int do_sysctl(int *name, int nlen, void *oldval, size_t *oldlenp,
  592. void *newval, size_t newlen);
  593. if (copy_from_user(&a32, args32, sizeof (a32)))
  594. return -EFAULT;
  595. /*
  596. * We need to pre-validate these because we have to disable address checking
  597. * before calling do_sysctl() because of OLDLEN but we can't run the risk of the
  598. * user specifying bad addresses here. Well, since we're dealing with 32 bit
  599. * addresses, we KNOW that access_ok() will always succeed, so this is an
  600. * expensive NOP, but so what...
  601. */
  602. namep = compat_ptr(a32.name);
  603. oldvalp = compat_ptr(a32.oldval);
  604. newvalp = compat_ptr(a32.newval);
  605. if ((oldvalp && get_user(oldlen, (int __user *)compat_ptr(a32.oldlenp)))
  606. || !access_ok(VERIFY_WRITE, namep, 0)
  607. || !access_ok(VERIFY_WRITE, oldvalp, 0)
  608. || !access_ok(VERIFY_WRITE, newvalp, 0))
  609. return -EFAULT;
  610. set_fs(KERNEL_DS);
  611. lock_kernel();
  612. ret = do_sysctl(namep, a32.nlen, oldvalp, &oldlen, newvalp, (size_t) a32.newlen);
  613. unlock_kernel();
  614. set_fs(old_fs);
  615. if (oldvalp && put_user (oldlen, (int __user *)compat_ptr(a32.oldlenp)))
  616. return -EFAULT;
  617. return ret;
  618. }
  619. #endif
  620. /* warning: next two assume little endian */
  621. asmlinkage long
  622. sys32_pread(unsigned int fd, char __user *ubuf, u32 count, u32 poslo, u32 poshi)
  623. {
  624. return sys_pread64(fd, ubuf, count,
  625. ((loff_t)AA(poshi) << 32) | AA(poslo));
  626. }
  627. asmlinkage long
  628. sys32_pwrite(unsigned int fd, char __user *ubuf, u32 count, u32 poslo, u32 poshi)
  629. {
  630. return sys_pwrite64(fd, ubuf, count,
  631. ((loff_t)AA(poshi) << 32) | AA(poslo));
  632. }
  633. asmlinkage long
  634. sys32_personality(unsigned long personality)
  635. {
  636. int ret;
  637. if (personality(current->personality) == PER_LINUX32 &&
  638. personality == PER_LINUX)
  639. personality = PER_LINUX32;
  640. ret = sys_personality(personality);
  641. if (ret == PER_LINUX32)
  642. ret = PER_LINUX;
  643. return ret;
  644. }
  645. asmlinkage long
  646. sys32_sendfile(int out_fd, int in_fd, compat_off_t __user *offset, s32 count)
  647. {
  648. mm_segment_t old_fs = get_fs();
  649. int ret;
  650. off_t of;
  651. if (offset && get_user(of, offset))
  652. return -EFAULT;
  653. set_fs(KERNEL_DS);
  654. ret = sys_sendfile(out_fd, in_fd, offset ? &of : NULL, count);
  655. set_fs(old_fs);
  656. if (offset && put_user(of, offset))
  657. return -EFAULT;
  658. return ret;
  659. }
  660. asmlinkage long sys32_mmap2(unsigned long addr, unsigned long len,
  661. unsigned long prot, unsigned long flags,
  662. unsigned long fd, unsigned long pgoff)
  663. {
  664. struct mm_struct *mm = current->mm;
  665. unsigned long error;
  666. struct file * file = NULL;
  667. flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
  668. if (!(flags & MAP_ANONYMOUS)) {
  669. file = fget(fd);
  670. if (!file)
  671. return -EBADF;
  672. }
  673. down_write(&mm->mmap_sem);
  674. error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
  675. up_write(&mm->mmap_sem);
  676. if (file)
  677. fput(file);
  678. return error;
  679. }
  680. asmlinkage long sys32_olduname(struct oldold_utsname __user * name)
  681. {
  682. int error;
  683. if (!name)
  684. return -EFAULT;
  685. if (!access_ok(VERIFY_WRITE,name,sizeof(struct oldold_utsname)))
  686. return -EFAULT;
  687. down_read(&uts_sem);
  688. error = __copy_to_user(&name->sysname,&system_utsname.sysname,__OLD_UTS_LEN);
  689. __put_user(0,name->sysname+__OLD_UTS_LEN);
  690. __copy_to_user(&name->nodename,&system_utsname.nodename,__OLD_UTS_LEN);
  691. __put_user(0,name->nodename+__OLD_UTS_LEN);
  692. __copy_to_user(&name->release,&system_utsname.release,__OLD_UTS_LEN);
  693. __put_user(0,name->release+__OLD_UTS_LEN);
  694. __copy_to_user(&name->version,&system_utsname.version,__OLD_UTS_LEN);
  695. __put_user(0,name->version+__OLD_UTS_LEN);
  696. {
  697. char *arch = "x86_64";
  698. if (personality(current->personality) == PER_LINUX32)
  699. arch = "i686";
  700. __copy_to_user(&name->machine,arch,strlen(arch)+1);
  701. }
  702. up_read(&uts_sem);
  703. error = error ? -EFAULT : 0;
  704. return error;
  705. }
  706. long sys32_uname(struct old_utsname __user * name)
  707. {
  708. int err;
  709. if (!name)
  710. return -EFAULT;
  711. down_read(&uts_sem);
  712. err=copy_to_user(name, &system_utsname, sizeof (*name));
  713. up_read(&uts_sem);
  714. if (personality(current->personality) == PER_LINUX32)
  715. err |= copy_to_user(&name->machine, "i686", 5);
  716. return err?-EFAULT:0;
  717. }
  718. long sys32_ustat(unsigned dev, struct ustat32 __user *u32p)
  719. {
  720. struct ustat u;
  721. mm_segment_t seg;
  722. int ret;
  723. seg = get_fs();
  724. set_fs(KERNEL_DS);
  725. ret = sys_ustat(dev,&u);
  726. set_fs(seg);
  727. if (ret >= 0) {
  728. if (!access_ok(VERIFY_WRITE,u32p,sizeof(struct ustat32)) ||
  729. __put_user((__u32) u.f_tfree, &u32p->f_tfree) ||
  730. __put_user((__u32) u.f_tinode, &u32p->f_tfree) ||
  731. __copy_to_user(&u32p->f_fname, u.f_fname, sizeof(u.f_fname)) ||
  732. __copy_to_user(&u32p->f_fpack, u.f_fpack, sizeof(u.f_fpack)))
  733. ret = -EFAULT;
  734. }
  735. return ret;
  736. }
  737. asmlinkage long sys32_execve(char __user *name, compat_uptr_t __user *argv,
  738. compat_uptr_t __user *envp, struct pt_regs *regs)
  739. {
  740. long error;
  741. char * filename;
  742. filename = getname(name);
  743. error = PTR_ERR(filename);
  744. if (IS_ERR(filename))
  745. return error;
  746. error = compat_do_execve(filename, argv, envp, regs);
  747. if (error == 0) {
  748. task_lock(current);
  749. current->ptrace &= ~PT_DTRACE;
  750. task_unlock(current);
  751. }
  752. putname(filename);
  753. return error;
  754. }
  755. asmlinkage long sys32_clone(unsigned int clone_flags, unsigned int newsp,
  756. struct pt_regs *regs)
  757. {
  758. void __user *parent_tid = (void __user *)regs->rdx;
  759. void __user *child_tid = (void __user *)regs->rdi;
  760. if (!newsp)
  761. newsp = regs->rsp;
  762. return do_fork(clone_flags, newsp, regs, 0, parent_tid, child_tid);
  763. }
  764. /*
  765. * Some system calls that need sign extended arguments. This could be done by a generic wrapper.
  766. */
  767. long sys32_lseek (unsigned int fd, int offset, unsigned int whence)
  768. {
  769. return sys_lseek(fd, offset, whence);
  770. }
  771. long sys32_kill(int pid, int sig)
  772. {
  773. return sys_kill(pid, sig);
  774. }
  775. long sys32_fadvise64_64(int fd, __u32 offset_low, __u32 offset_high,
  776. __u32 len_low, __u32 len_high, int advice)
  777. {
  778. return sys_fadvise64_64(fd,
  779. (((u64)offset_high)<<32) | offset_low,
  780. (((u64)len_high)<<32) | len_low,
  781. advice);
  782. }
  783. long sys32_vm86_warning(void)
  784. {
  785. struct task_struct *me = current;
  786. static char lastcomm[sizeof(me->comm)];
  787. if (strncmp(lastcomm, me->comm, sizeof(lastcomm))) {
  788. compat_printk(KERN_INFO "%s: vm86 mode not supported on 64 bit kernel\n",
  789. me->comm);
  790. strncpy(lastcomm, me->comm, sizeof(lastcomm));
  791. }
  792. return -ENOSYS;
  793. }
  794. long sys32_lookup_dcookie(u32 addr_low, u32 addr_high,
  795. char __user * buf, size_t len)
  796. {
  797. return sys_lookup_dcookie(((u64)addr_high << 32) | addr_low, buf, len);
  798. }