sys_sparc32.c 16 KB

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