sys_ia32.c 27 KB

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