sys_sparc32.c 18 KB

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