sys_sparc32.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  1. /* sys_sparc32.c: Conversion between 32bit and 64bit native syscalls.
  2. *
  3. * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
  4. * Copyright (C) 1997, 2007 David S. Miller (davem@davemloft.net)
  5. *
  6. * These routines maintain argument size conversion between 32bit and 64bit
  7. * environment.
  8. */
  9. #include <linux/kernel.h>
  10. #include <linux/sched.h>
  11. #include <linux/capability.h>
  12. #include <linux/fs.h>
  13. #include <linux/mm.h>
  14. #include <linux/file.h>
  15. #include <linux/signal.h>
  16. #include <linux/resource.h>
  17. #include <linux/times.h>
  18. #include <linux/smp.h>
  19. #include <linux/sem.h>
  20. #include <linux/msg.h>
  21. #include <linux/shm.h>
  22. #include <linux/uio.h>
  23. #include <linux/nfs_fs.h>
  24. #include <linux/quota.h>
  25. #include <linux/module.h>
  26. #include <linux/poll.h>
  27. #include <linux/personality.h>
  28. #include <linux/stat.h>
  29. #include <linux/filter.h>
  30. #include <linux/highmem.h>
  31. #include <linux/highuid.h>
  32. #include <linux/mman.h>
  33. #include <linux/ipv6.h>
  34. #include <linux/in.h>
  35. #include <linux/icmpv6.h>
  36. #include <linux/syscalls.h>
  37. #include <linux/sysctl.h>
  38. #include <linux/binfmts.h>
  39. #include <linux/dnotify.h>
  40. #include <linux/security.h>
  41. #include <linux/compat.h>
  42. #include <linux/vfs.h>
  43. #include <linux/ptrace.h>
  44. #include <linux/slab.h>
  45. #include <asm/types.h>
  46. #include <asm/uaccess.h>
  47. #include <asm/fpumacro.h>
  48. #include <asm/mmu_context.h>
  49. #include <asm/compat_signal.h>
  50. #ifdef CONFIG_SYSVIPC
  51. asmlinkage long compat_sys_ipc(u32 call, u32 first, u32 second, u32 third, compat_uptr_t ptr, u32 fifth)
  52. {
  53. int version;
  54. version = call >> 16; /* hack for backward compatibility */
  55. call &= 0xffff;
  56. switch (call) {
  57. case SEMTIMEDOP:
  58. if (fifth)
  59. /* sign extend semid */
  60. return compat_sys_semtimedop((int)first,
  61. compat_ptr(ptr), second,
  62. compat_ptr(fifth));
  63. /* else fall through for normal semop() */
  64. case SEMOP:
  65. /* struct sembuf is the same on 32 and 64bit :)) */
  66. /* sign extend semid */
  67. return sys_semtimedop((int)first, compat_ptr(ptr), second,
  68. NULL);
  69. case SEMGET:
  70. /* sign extend key, nsems */
  71. return sys_semget((int)first, (int)second, third);
  72. case SEMCTL:
  73. /* sign extend semid, semnum */
  74. return compat_sys_semctl((int)first, (int)second, third,
  75. compat_ptr(ptr));
  76. case MSGSND:
  77. /* sign extend msqid */
  78. return compat_sys_msgsnd((int)first, (int)second, third,
  79. compat_ptr(ptr));
  80. case MSGRCV:
  81. /* sign extend msqid, msgtyp */
  82. return compat_sys_msgrcv((int)first, second, (int)fifth,
  83. third, version, compat_ptr(ptr));
  84. case MSGGET:
  85. /* sign extend key */
  86. return sys_msgget((int)first, second);
  87. case MSGCTL:
  88. /* sign extend msqid */
  89. return compat_sys_msgctl((int)first, second, compat_ptr(ptr));
  90. case SHMAT:
  91. /* sign extend shmid */
  92. return compat_sys_shmat((int)first, second, third, version,
  93. compat_ptr(ptr));
  94. case SHMDT:
  95. return sys_shmdt(compat_ptr(ptr));
  96. case SHMGET:
  97. /* sign extend key_t */
  98. return sys_shmget((int)first, second, third);
  99. case SHMCTL:
  100. /* sign extend shmid */
  101. return compat_sys_shmctl((int)first, second, compat_ptr(ptr));
  102. default:
  103. return -ENOSYS;
  104. }
  105. return -ENOSYS;
  106. }
  107. #endif
  108. asmlinkage long sys32_truncate64(const char __user * path, unsigned long high, unsigned long low)
  109. {
  110. if ((int)high < 0)
  111. return -EINVAL;
  112. else
  113. return sys_truncate(path, (high << 32) | low);
  114. }
  115. asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long high, unsigned long low)
  116. {
  117. if ((int)high < 0)
  118. return -EINVAL;
  119. else
  120. return sys_ftruncate(fd, (high << 32) | low);
  121. }
  122. static int cp_compat_stat64(struct kstat *stat,
  123. struct compat_stat64 __user *statbuf)
  124. {
  125. int err;
  126. err = put_user(huge_encode_dev(stat->dev), &statbuf->st_dev);
  127. err |= put_user(stat->ino, &statbuf->st_ino);
  128. err |= put_user(stat->mode, &statbuf->st_mode);
  129. err |= put_user(stat->nlink, &statbuf->st_nlink);
  130. err |= put_user(stat->uid, &statbuf->st_uid);
  131. err |= put_user(stat->gid, &statbuf->st_gid);
  132. err |= put_user(huge_encode_dev(stat->rdev), &statbuf->st_rdev);
  133. err |= put_user(0, (unsigned long __user *) &statbuf->__pad3[0]);
  134. err |= put_user(stat->size, &statbuf->st_size);
  135. err |= put_user(stat->blksize, &statbuf->st_blksize);
  136. err |= put_user(0, (unsigned int __user *) &statbuf->__pad4[0]);
  137. err |= put_user(0, (unsigned int __user *) &statbuf->__pad4[4]);
  138. err |= put_user(stat->blocks, &statbuf->st_blocks);
  139. err |= put_user(stat->atime.tv_sec, &statbuf->st_atime);
  140. err |= put_user(stat->atime.tv_nsec, &statbuf->st_atime_nsec);
  141. err |= put_user(stat->mtime.tv_sec, &statbuf->st_mtime);
  142. err |= put_user(stat->mtime.tv_nsec, &statbuf->st_mtime_nsec);
  143. err |= put_user(stat->ctime.tv_sec, &statbuf->st_ctime);
  144. err |= put_user(stat->ctime.tv_nsec, &statbuf->st_ctime_nsec);
  145. err |= put_user(0, &statbuf->__unused4);
  146. err |= put_user(0, &statbuf->__unused5);
  147. return err;
  148. }
  149. asmlinkage long compat_sys_stat64(const char __user * filename,
  150. struct compat_stat64 __user *statbuf)
  151. {
  152. struct kstat stat;
  153. int error = vfs_stat(filename, &stat);
  154. if (!error)
  155. error = cp_compat_stat64(&stat, statbuf);
  156. return error;
  157. }
  158. asmlinkage long compat_sys_lstat64(const char __user * filename,
  159. struct compat_stat64 __user *statbuf)
  160. {
  161. struct kstat stat;
  162. int error = vfs_lstat(filename, &stat);
  163. if (!error)
  164. error = cp_compat_stat64(&stat, statbuf);
  165. return error;
  166. }
  167. asmlinkage long compat_sys_fstat64(unsigned int fd,
  168. struct compat_stat64 __user * statbuf)
  169. {
  170. struct kstat stat;
  171. int error = vfs_fstat(fd, &stat);
  172. if (!error)
  173. error = cp_compat_stat64(&stat, statbuf);
  174. return error;
  175. }
  176. asmlinkage long compat_sys_fstatat64(unsigned int dfd,
  177. const char __user *filename,
  178. struct compat_stat64 __user * statbuf, int flag)
  179. {
  180. struct kstat stat;
  181. int error;
  182. error = vfs_fstatat(dfd, filename, &stat, flag);
  183. if (error)
  184. return error;
  185. return cp_compat_stat64(&stat, statbuf);
  186. }
  187. asmlinkage long compat_sys_sysfs(int option, u32 arg1, u32 arg2)
  188. {
  189. return sys_sysfs(option, arg1, arg2);
  190. }
  191. asmlinkage long compat_sys_sched_rr_get_interval(compat_pid_t pid, struct compat_timespec __user *interval)
  192. {
  193. struct timespec t;
  194. int ret;
  195. mm_segment_t old_fs = get_fs ();
  196. set_fs (KERNEL_DS);
  197. ret = sys_sched_rr_get_interval(pid, (struct timespec __user *) &t);
  198. set_fs (old_fs);
  199. if (put_compat_timespec(&t, interval))
  200. return -EFAULT;
  201. return ret;
  202. }
  203. asmlinkage long compat_sys_rt_sigprocmask(int how,
  204. compat_sigset_t __user *set,
  205. compat_sigset_t __user *oset,
  206. compat_size_t sigsetsize)
  207. {
  208. sigset_t s;
  209. compat_sigset_t s32;
  210. int ret;
  211. mm_segment_t old_fs = get_fs();
  212. if (set) {
  213. if (copy_from_user (&s32, set, sizeof(compat_sigset_t)))
  214. return -EFAULT;
  215. switch (_NSIG_WORDS) {
  216. case 4: s.sig[3] = s32.sig[6] | (((long)s32.sig[7]) << 32);
  217. case 3: s.sig[2] = s32.sig[4] | (((long)s32.sig[5]) << 32);
  218. case 2: s.sig[1] = s32.sig[2] | (((long)s32.sig[3]) << 32);
  219. case 1: s.sig[0] = s32.sig[0] | (((long)s32.sig[1]) << 32);
  220. }
  221. }
  222. set_fs (KERNEL_DS);
  223. ret = sys_rt_sigprocmask(how,
  224. set ? (sigset_t __user *) &s : NULL,
  225. oset ? (sigset_t __user *) &s : NULL,
  226. sigsetsize);
  227. set_fs (old_fs);
  228. if (ret) return ret;
  229. if (oset) {
  230. switch (_NSIG_WORDS) {
  231. case 4: s32.sig[7] = (s.sig[3] >> 32); s32.sig[6] = s.sig[3];
  232. case 3: s32.sig[5] = (s.sig[2] >> 32); s32.sig[4] = s.sig[2];
  233. case 2: s32.sig[3] = (s.sig[1] >> 32); s32.sig[2] = s.sig[1];
  234. case 1: s32.sig[1] = (s.sig[0] >> 32); s32.sig[0] = s.sig[0];
  235. }
  236. if (copy_to_user (oset, &s32, sizeof(compat_sigset_t)))
  237. return -EFAULT;
  238. }
  239. return 0;
  240. }
  241. asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
  242. compat_size_t sigsetsize)
  243. {
  244. sigset_t s;
  245. compat_sigset_t s32;
  246. int ret;
  247. mm_segment_t old_fs = get_fs();
  248. set_fs (KERNEL_DS);
  249. ret = sys_rt_sigpending((sigset_t __user *) &s, sigsetsize);
  250. set_fs (old_fs);
  251. if (!ret) {
  252. switch (_NSIG_WORDS) {
  253. case 4: s32.sig[7] = (s.sig[3] >> 32); s32.sig[6] = s.sig[3];
  254. case 3: s32.sig[5] = (s.sig[2] >> 32); s32.sig[4] = s.sig[2];
  255. case 2: s32.sig[3] = (s.sig[1] >> 32); s32.sig[2] = s.sig[1];
  256. case 1: s32.sig[1] = (s.sig[0] >> 32); s32.sig[0] = s.sig[0];
  257. }
  258. if (copy_to_user (set, &s32, sizeof(compat_sigset_t)))
  259. return -EFAULT;
  260. }
  261. return ret;
  262. }
  263. asmlinkage long compat_sys_rt_sigqueueinfo(int pid, int sig,
  264. struct compat_siginfo __user *uinfo)
  265. {
  266. siginfo_t info;
  267. int ret;
  268. mm_segment_t old_fs = get_fs();
  269. if (copy_siginfo_from_user32(&info, uinfo))
  270. return -EFAULT;
  271. set_fs (KERNEL_DS);
  272. ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *) &info);
  273. set_fs (old_fs);
  274. return ret;
  275. }
  276. asmlinkage long compat_sys_sigaction(int sig, struct old_sigaction32 __user *act,
  277. struct old_sigaction32 __user *oact)
  278. {
  279. struct k_sigaction new_ka, old_ka;
  280. int ret;
  281. WARN_ON_ONCE(sig >= 0);
  282. sig = -sig;
  283. if (act) {
  284. compat_old_sigset_t mask;
  285. u32 u_handler, u_restorer;
  286. ret = get_user(u_handler, &act->sa_handler);
  287. new_ka.sa.sa_handler = compat_ptr(u_handler);
  288. ret |= __get_user(u_restorer, &act->sa_restorer);
  289. new_ka.sa.sa_restorer = compat_ptr(u_restorer);
  290. ret |= __get_user(new_ka.sa.sa_flags, &act->sa_flags);
  291. ret |= __get_user(mask, &act->sa_mask);
  292. if (ret)
  293. return ret;
  294. new_ka.ka_restorer = NULL;
  295. siginitset(&new_ka.sa.sa_mask, mask);
  296. }
  297. ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
  298. if (!ret && oact) {
  299. ret = put_user(ptr_to_compat(old_ka.sa.sa_handler), &oact->sa_handler);
  300. ret |= __put_user(ptr_to_compat(old_ka.sa.sa_restorer), &oact->sa_restorer);
  301. ret |= __put_user(old_ka.sa.sa_flags, &oact->sa_flags);
  302. ret |= __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask);
  303. }
  304. return ret;
  305. }
  306. asmlinkage long compat_sys_rt_sigaction(int sig,
  307. struct sigaction32 __user *act,
  308. struct sigaction32 __user *oact,
  309. void __user *restorer,
  310. compat_size_t sigsetsize)
  311. {
  312. struct k_sigaction new_ka, old_ka;
  313. int ret;
  314. compat_sigset_t set32;
  315. /* XXX: Don't preclude handling different sized sigset_t's. */
  316. if (sigsetsize != sizeof(compat_sigset_t))
  317. return -EINVAL;
  318. if (act) {
  319. u32 u_handler, u_restorer;
  320. new_ka.ka_restorer = restorer;
  321. ret = get_user(u_handler, &act->sa_handler);
  322. new_ka.sa.sa_handler = compat_ptr(u_handler);
  323. ret |= __copy_from_user(&set32, &act->sa_mask, sizeof(compat_sigset_t));
  324. switch (_NSIG_WORDS) {
  325. case 4: new_ka.sa.sa_mask.sig[3] = set32.sig[6] | (((long)set32.sig[7]) << 32);
  326. case 3: new_ka.sa.sa_mask.sig[2] = set32.sig[4] | (((long)set32.sig[5]) << 32);
  327. case 2: new_ka.sa.sa_mask.sig[1] = set32.sig[2] | (((long)set32.sig[3]) << 32);
  328. case 1: new_ka.sa.sa_mask.sig[0] = set32.sig[0] | (((long)set32.sig[1]) << 32);
  329. }
  330. ret |= __get_user(new_ka.sa.sa_flags, &act->sa_flags);
  331. ret |= __get_user(u_restorer, &act->sa_restorer);
  332. new_ka.sa.sa_restorer = compat_ptr(u_restorer);
  333. if (ret)
  334. return -EFAULT;
  335. }
  336. ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
  337. if (!ret && oact) {
  338. switch (_NSIG_WORDS) {
  339. case 4: set32.sig[7] = (old_ka.sa.sa_mask.sig[3] >> 32); set32.sig[6] = old_ka.sa.sa_mask.sig[3];
  340. case 3: set32.sig[5] = (old_ka.sa.sa_mask.sig[2] >> 32); set32.sig[4] = old_ka.sa.sa_mask.sig[2];
  341. case 2: set32.sig[3] = (old_ka.sa.sa_mask.sig[1] >> 32); set32.sig[2] = old_ka.sa.sa_mask.sig[1];
  342. case 1: set32.sig[1] = (old_ka.sa.sa_mask.sig[0] >> 32); set32.sig[0] = old_ka.sa.sa_mask.sig[0];
  343. }
  344. ret = put_user(ptr_to_compat(old_ka.sa.sa_handler), &oact->sa_handler);
  345. ret |= __copy_to_user(&oact->sa_mask, &set32, sizeof(compat_sigset_t));
  346. ret |= __put_user(old_ka.sa.sa_flags, &oact->sa_flags);
  347. ret |= __put_user(ptr_to_compat(old_ka.sa.sa_restorer), &oact->sa_restorer);
  348. if (ret)
  349. ret = -EFAULT;
  350. }
  351. return ret;
  352. }
  353. /*
  354. * sparc32_execve() executes a new program after the asm stub has set
  355. * things up for us. This should basically do what I want it to.
  356. */
  357. asmlinkage long sparc32_execve(struct pt_regs *regs)
  358. {
  359. int error, base = 0;
  360. char *filename;
  361. /* User register window flush is done by entry.S */
  362. /* Check for indirect call. */
  363. if ((u32)regs->u_regs[UREG_G1] == 0)
  364. base = 1;
  365. filename = getname(compat_ptr(regs->u_regs[base + UREG_I0]));
  366. error = PTR_ERR(filename);
  367. if (IS_ERR(filename))
  368. goto out;
  369. error = compat_do_execve(filename,
  370. compat_ptr(regs->u_regs[base + UREG_I1]),
  371. compat_ptr(regs->u_regs[base + UREG_I2]), regs);
  372. putname(filename);
  373. if (!error) {
  374. fprs_write(0);
  375. current_thread_info()->xfsr[0] = 0;
  376. current_thread_info()->fpsaved[0] = 0;
  377. regs->tstate &= ~TSTATE_PEF;
  378. }
  379. out:
  380. return error;
  381. }
  382. #ifdef CONFIG_MODULES
  383. asmlinkage long sys32_init_module(void __user *umod, u32 len,
  384. const char __user *uargs)
  385. {
  386. return sys_init_module(umod, len, uargs);
  387. }
  388. asmlinkage long sys32_delete_module(const char __user *name_user,
  389. unsigned int flags)
  390. {
  391. return sys_delete_module(name_user, flags);
  392. }
  393. #else /* CONFIG_MODULES */
  394. asmlinkage long sys32_init_module(const char __user *name_user,
  395. struct module __user *mod_user)
  396. {
  397. return -ENOSYS;
  398. }
  399. asmlinkage long sys32_delete_module(const char __user *name_user)
  400. {
  401. return -ENOSYS;
  402. }
  403. #endif /* CONFIG_MODULES */
  404. asmlinkage compat_ssize_t sys32_pread64(unsigned int fd,
  405. char __user *ubuf,
  406. compat_size_t count,
  407. unsigned long poshi,
  408. unsigned long poslo)
  409. {
  410. return sys_pread64(fd, ubuf, count, (poshi << 32) | poslo);
  411. }
  412. asmlinkage compat_ssize_t sys32_pwrite64(unsigned int fd,
  413. char __user *ubuf,
  414. compat_size_t count,
  415. unsigned long poshi,
  416. unsigned long poslo)
  417. {
  418. return sys_pwrite64(fd, ubuf, count, (poshi << 32) | poslo);
  419. }
  420. asmlinkage long compat_sys_readahead(int fd,
  421. unsigned long offhi,
  422. unsigned long offlo,
  423. compat_size_t count)
  424. {
  425. return sys_readahead(fd, (offhi << 32) | offlo, count);
  426. }
  427. long compat_sys_fadvise64(int fd,
  428. unsigned long offhi,
  429. unsigned long offlo,
  430. compat_size_t len, int advice)
  431. {
  432. return sys_fadvise64_64(fd, (offhi << 32) | offlo, len, advice);
  433. }
  434. long compat_sys_fadvise64_64(int fd,
  435. unsigned long offhi, unsigned long offlo,
  436. unsigned long lenhi, unsigned long lenlo,
  437. int advice)
  438. {
  439. return sys_fadvise64_64(fd,
  440. (offhi << 32) | offlo,
  441. (lenhi << 32) | lenlo,
  442. advice);
  443. }
  444. asmlinkage long compat_sys_sendfile(int out_fd, int in_fd,
  445. compat_off_t __user *offset,
  446. compat_size_t count)
  447. {
  448. mm_segment_t old_fs = get_fs();
  449. int ret;
  450. off_t of;
  451. if (offset && get_user(of, offset))
  452. return -EFAULT;
  453. set_fs(KERNEL_DS);
  454. ret = sys_sendfile(out_fd, in_fd,
  455. offset ? (off_t __user *) &of : NULL,
  456. count);
  457. set_fs(old_fs);
  458. if (offset && put_user(of, offset))
  459. return -EFAULT;
  460. return ret;
  461. }
  462. asmlinkage long compat_sys_sendfile64(int out_fd, int in_fd,
  463. compat_loff_t __user *offset,
  464. compat_size_t count)
  465. {
  466. mm_segment_t old_fs = get_fs();
  467. int ret;
  468. loff_t lof;
  469. if (offset && get_user(lof, offset))
  470. return -EFAULT;
  471. set_fs(KERNEL_DS);
  472. ret = sys_sendfile64(out_fd, in_fd,
  473. offset ? (loff_t __user *) &lof : NULL,
  474. count);
  475. set_fs(old_fs);
  476. if (offset && put_user(lof, offset))
  477. return -EFAULT;
  478. return ret;
  479. }
  480. /* This is just a version for 32-bit applications which does
  481. * not force O_LARGEFILE on.
  482. */
  483. asmlinkage long sparc32_open(const char __user *filename,
  484. int flags, int mode)
  485. {
  486. return do_sys_open(AT_FDCWD, filename, flags, mode);
  487. }
  488. long sys32_lookup_dcookie(unsigned long cookie_high,
  489. unsigned long cookie_low,
  490. char __user *buf, size_t len)
  491. {
  492. return sys_lookup_dcookie((cookie_high << 32) | cookie_low,
  493. buf, len);
  494. }
  495. long compat_sync_file_range(int fd, unsigned long off_high, unsigned long off_low, unsigned long nb_high, unsigned long nb_low, int flags)
  496. {
  497. return sys_sync_file_range(fd,
  498. (off_high << 32) | off_low,
  499. (nb_high << 32) | nb_low,
  500. flags);
  501. }
  502. asmlinkage long compat_sys_fallocate(int fd, int mode, u32 offhi, u32 offlo,
  503. u32 lenhi, u32 lenlo)
  504. {
  505. return sys_fallocate(fd, mode, ((loff_t)offhi << 32) | offlo,
  506. ((loff_t)lenhi << 32) | lenlo);
  507. }